#include "config.h"
#include "JITExceptions.h"
#include "CallFrame.h"
#include "CatchScope.h"
#include "CodeBlock.h"
#include "Disassembler.h"
#include "EntryFrame.h"
#include "Interpreter.h"
#include "JSCInlines.h"
#include "JSCJSValue.h"
#include "LLIntData.h"
#include "LLIntOpcode.h"
#include "LLIntThunks.h"
#include "Opcode.h"
#include "ShadowChicken.h"
#include "VMInlines.h"
namespace JSC {
void genericUnwind(VM* vm, ExecState* callFrame)
{
auto scope = DECLARE_CATCH_SCOPE(*vm);
CallFrame* topJSCallFrame = vm->topJSCallFrame();
if (Options::breakOnThrow()) {
CodeBlock* codeBlock = topJSCallFrame->codeBlock();
dataLog("In call frame ", RawPointer(topJSCallFrame), " for code block ", codeBlock, "\n");
CRASH();
}
vm->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
catchRoutine = catchPCForInterpreter->isWide()
? LLInt::getWideCodePtr(catchPCForInterpreter->opcodeID())
: 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);
}
}