diff --git a/src/coreclr/jit/codegen.h b/src/coreclr/jit/codegen.h index 8676dd22aaff..1def454ab95e 100644 --- a/src/coreclr/jit/codegen.h +++ b/src/coreclr/jit/codegen.h @@ -522,9 +522,9 @@ class CodeGen final : public CodeGenInterface void genReserveProlog(BasicBlock* block); // currently unused void genReserveEpilog(BasicBlock* block); -#if defined(TARGET_AMD64) +#if defined(WINDOWS_AMD64_ABI) void genFnPreProlog(); -#endif // defined(TARGET_AMD64) +#endif // defined(WINDOWS_AMD64_ABI) void genFnProlog(); void genFnEpilog(BasicBlock* block); diff --git a/src/coreclr/jit/codegencommon.cpp b/src/coreclr/jit/codegencommon.cpp index be481b46b8f5..6b8ad1a7843f 100644 --- a/src/coreclr/jit/codegencommon.cpp +++ b/src/coreclr/jit/codegencommon.cpp @@ -5483,11 +5483,11 @@ void CodeGen::genFinalizeFrame() * genFnPreProlog is optional (currently only on for x64 but eventually * some frames will likely skip it). * - * Although currently only being used for TARGET_AMD64, this is eventually + * Although currently only being used for WINDOWS_AMD64_ABI, this is eventually * intended for all architectures, so it is not in codegenxarch.cpp. */ -#if defined(TARGET_AMD64) +#if defined(WINDOWS_AMD64_ABI) void CodeGen::genFnPreProlog() { ScopedSetVariable _setGeneratingPreProlog(&compiler->compGeneratingPreProlog, true); @@ -5545,7 +5545,7 @@ void CodeGen::genFnPreProlog() emit->emitEndPreProlog(); } -#endif // defined(TARGET_AMD64) +#endif // defined(WINDOWS_AMD64_ABI) /***************************************************************************** * diff --git a/src/coreclr/jit/emit.cpp b/src/coreclr/jit/emit.cpp index 751525a3ba38..41d44bb470e0 100644 --- a/src/coreclr/jit/emit.cpp +++ b/src/coreclr/jit/emit.cpp @@ -1641,7 +1641,7 @@ void emitter::emitCheckIGoffsets() #endif // DEBUG -#if defined(TARGET_AMD64) +#if defined(WINDOWS_AMD64_ABI) void emitter::emitBegPreProlog() { @@ -1666,27 +1666,13 @@ void emitter::emitBegPreProlog() int UnwindCodeNodeSize(UNWIND_CODE code) { - int unwindCodeNodeSize = 1; - switch (code.UnwindOp) + if (code.UnwindOp == UWOP_ALLOC_LARGE) { - case UWOP_ALLOC_LARGE: - if (code.OpInfo == 0) - unwindCodeNodeSize = 2; - else - unwindCodeNodeSize = 3; - break; - - case UWOP_SAVE_XMM128: - case UWOP_SAVE_NONVOL: - unwindCodeNodeSize = 2; - break; - - case UWOP_SAVE_NONVOL_FAR: - case UWOP_SAVE_XMM128_FAR: - unwindCodeNodeSize = 3; - break; + return (code.OpInfo == 0) ? 2 : 3; } - return unwindCodeNodeSize; + + // Since table gives -extra- slots, we add one for the actual size + return UnwindOpExtraSlotTable[code.UnwindOp] + 1; } void emitter::emitEndPreProlog() @@ -1697,12 +1683,12 @@ void emitter::emitEndPreProlog() FuncInfoDsc* func = emitComp->funCurrentFunc(); assert(func->unwindHeader.CountOfUnwindCodes == 0); // Can't call this after unwindReserve - auto unwindCodeStart = (UNWIND_CODE*)&func->unwindCodes[func->unwindCodeSlot]; - auto unwindCodeEnd = (UNWIND_CODE*)&func->unwindCodes[sizeof(func->unwindCodes)]; + auto unwindCodeStart = reinterpret_cast(&func->unwindCodes[func->unwindCodeSlot]); + auto unwindCodeEnd = reinterpret_cast(&func->unwindCodes[sizeof(func->unwindCodes)]); - int unwindCodeNodeSize = 1; for (auto unwindCodeCurrent = unwindCodeStart; unwindCodeCurrent != unwindCodeEnd; unwindCodeCurrent += UnwindCodeNodeSize(*unwindCodeCurrent)) { + assert(unwindCodeCurrent < unwindCodeEnd); // Avoid a corrupted size leading to overrun by skipping the end uint8_t oldCodeOffset = unwindCodeCurrent->CodeOffset; uint8_t newCodeOffset = (uint8_t)(oldCodeOffset + prePrologSize); assert(newCodeOffset > oldCodeOffset); // I'm not sure if we can overflow here, but an assert should help @@ -1710,7 +1696,7 @@ void emitter::emitEndPreProlog() } } -#endif // defined(TARGET_AMD64) +#endif // defined(WINDOWS_AMD64_ABI) /***************************************************************************** diff --git a/src/coreclr/jit/emitpub.h b/src/coreclr/jit/emitpub.h index c6e9ca41d370..f2818b5f34da 100644 --- a/src/coreclr/jit/emitpub.h +++ b/src/coreclr/jit/emitpub.h @@ -43,10 +43,10 @@ unsigned emitGetEpilogCnt(); template bool emitGenNoGCLst(Callback& cb); -#if defined(TARGET_AMD64) +#if defined(WINDOWS_AMD64_ABI) void emitBegPreProlog(); void emitEndPreProlog(); -#endif // defined(TARGET_AMD64) +#endif // defined(WINDOWS_AMD64_ABI) void emitBegProlog(); unsigned emitGetPrologOffsetEstimate(); void emitMarkPrologEnd();