#include "config.h"
#include "JITExceptions.h"
#include "CallFrame.h"
#include "CatchScope.h"
#include "CodeBlock.h"
#include "Interpreter.h"
#include "JSCJSValueInlines.h"
#include "LLIntData.h"
#include "Opcode.h"
#include "ShadowChicken.h"
#include "VMInlines.h"
namespace JSC {
void genericUnwind(VM& vm, CallFrame* callFrame)
{
auto scope = DECLARE_CATCH_SCOPE(vm);
CallFrame* topJSCallFrame = vm.topJSCallFrame();
if (UNLIKELY(Options::breakOnThrow())) {
CodeBlock* codeBlock = topJSCallFrame->codeBlock();
dataLog("In call frame ", RawPointer(topJSCallFrame), " for code block ", codeBlock, "\n");
WTFBreakpointTrap();
}
if (auto* shadowChicken = vm.shadowChicken())
shadowChicken->log(vm, topJSCallFrame, ShadowChicken::Packet::throwPacket());
Exception* exception = scope.exception();
RELEASE_ASSERT(exception);
HandlerInfo* handler = vm.interpreter->unwind(vm, callFrame, exception);
void* catchRoutine;
const Instruction* catchPCForInterpreter = nullptr;
if (handler) {
if (!JITCode::isOptimizingJIT(callFrame->codeBlock()->jitType()))
catchPCForInterpreter = callFrame->codeBlock()->instructions().at(handler->target).ptr();
#if ENABLE(JIT)
catchRoutine = handler->nativeCode.executableAddress();
#else
if (catchPCForInterpreter->isWide32())
catchRoutine = LLInt::getWide32CodePtr(catchPCForInterpreter->opcodeID());
else if (catchPCForInterpreter->isWide16())
catchRoutine = LLInt::getWide16CodePtr(catchPCForInterpreter->opcodeID());
else
catchRoutine = LLInt::getCodePtr(catchPCForInterpreter->opcodeID());
#endif
} else
catchRoutine = LLInt::getCodePtr<ExceptionHandlerPtrTag>(handleUncaughtException).executableAddress();
ASSERT(bitwise_cast<uintptr_t>(callFrame) < bitwise_cast<uintptr_t>(vm.topEntryFrame));
assertIsTaggedWith(catchRoutine, ExceptionHandlerPtrTag);
vm.callFrameForCatch = callFrame;
vm.targetMachinePCForThrow = catchRoutine;
vm.targetInterpreterPCForThrow = catchPCForInterpreter;
RELEASE_ASSERT(catchRoutine);
}
}