From a1fc0ae12cd52532ea19311528d95c9f20c0ae21 Mon Sep 17 00:00:00 2001 From: Rajat Dua Date: Tue, 24 Jul 2018 17:34:57 -0700 Subject: [PATCH] Fix field types in InlineeCallInfo. OS #15566165 --- lib/Backend/InlineeFrameInfo.cpp | 4 ++++ lib/Backend/amd64/EncoderMD.cpp | 6 +++--- lib/Backend/i386/EncoderMD.cpp | 6 +++--- lib/Runtime/Base/CallInfo.h | 20 ++++++++++++++----- .../Language/JavascriptStackWalker.cpp | 7 +------ 5 files changed, 26 insertions(+), 17 deletions(-) diff --git a/lib/Backend/InlineeFrameInfo.cpp b/lib/Backend/InlineeFrameInfo.cpp index a214f3bc561..4ac71f94bc3 100644 --- a/lib/Backend/InlineeFrameInfo.cpp +++ b/lib/Backend/InlineeFrameInfo.cpp @@ -172,6 +172,10 @@ void InlineeFrameRecord::PopulateParent(Func* func) void InlineeFrameRecord::Finalize(Func* inlinee, uint32 currentOffset) { this->PopulateParent(inlinee); +#if TARGET_32 + const uint32 offsetMask = (~(uint32)0) >> (sizeof(uint) * CHAR_BIT - Js::InlineeCallInfo::ksizeofInlineeStartOffset); + AssertOrFailFast(currentOffset == (currentOffset & offsetMask)); +#endif this->inlineeStartOffset = currentOffset; this->inlineDepth = inlinee->inlineDepth; diff --git a/lib/Backend/amd64/EncoderMD.cpp b/lib/Backend/amd64/EncoderMD.cpp index 76fc2985d96..2a79a16ae1a 100644 --- a/lib/Backend/amd64/EncoderMD.cpp +++ b/lib/Backend/amd64/EncoderMD.cpp @@ -1518,11 +1518,11 @@ EncoderMD::FixRelocListEntry(uint32 index, int totalBytesSaved, BYTE *buffStart, // ptr points to imm32 offset of the instruction that needs to be adjusted // offset is in top 28-bits, arg count in bottom 4 size_t field = *((size_t*) relocRecord.m_origPtr); - size_t offset = field >> 4; + size_t offset = field >> Js::InlineeCallInfo::inlineeStartOffsetShiftCount; uint32 count = field & 0xf; AssertMsg(offset < (size_t)(buffEnd - buffStart), "Inlinee entry offset out of range"); - relocRecord.SetInlineOffset(((offset - totalBytesSaved) << 4) | count); + relocRecord.SetInlineOffset(((offset - totalBytesSaved) << Js::InlineeCallInfo::inlineeStartOffsetShiftCount) | count); } // adjust the ptr to the buffer itself relocRecord.m_ptr = (BYTE*) relocRecord.m_ptr - totalBytesSaved; @@ -1777,7 +1777,7 @@ EncoderMD::EncodeInlineeCallInfo(IR::Instr *instr, uint32 codeOffset) // than can fit in as many bits. const bool encodeResult = Js::InlineeCallInfo::Encode(inlineeCallInfo, instr->GetSrc1()->AsIntConstOpnd()->GetValue(), codeOffset); - Assert(encodeResult); + AssertOrFailFast(encodeResult); instr->GetSrc1()->AsIntConstOpnd()->SetValue(inlineeCallInfo); } diff --git a/lib/Backend/i386/EncoderMD.cpp b/lib/Backend/i386/EncoderMD.cpp index f0243e7607f..ff346b071f1 100644 --- a/lib/Backend/i386/EncoderMD.cpp +++ b/lib/Backend/i386/EncoderMD.cpp @@ -1354,11 +1354,11 @@ EncoderMD::FixRelocListEntry(uint32 index, int32 totalBytesSaved, BYTE *buffStar // ptr points to imm32 offset of the instruction that needs to be adjusted // offset is in top 28-bits, arg count in bottom 4 uint32 field = *((uint32*) relocRecord.m_origPtr); - uint32 offset = field >> 4; + uint32 offset = field >> Js::InlineeCallInfo::inlineeStartOffsetShiftCount; uint32 count = field & 0xf; AssertMsg(offset < (uint32)(buffEnd - buffStart), "Inlinee entry offset out of range"); - relocRecord.SetInlineOffset(((offset - totalBytesSaved) << 4) | count); + relocRecord.SetInlineOffset(((offset - totalBytesSaved) << Js::InlineeCallInfo::inlineeStartOffsetShiftCount) | count); } // adjust the ptr to the buffer itself relocRecord.m_ptr = (BYTE*) relocRecord.m_ptr - totalBytesSaved; @@ -1588,7 +1588,7 @@ EncoderMD::EncodeInlineeCallInfo(IR::Instr *instr, uint32 codeOffset) // offset of the start of the inlinee. We shouldn't have gotten here with more arguments // than can fit in as many bits. const bool encodeResult = Js::InlineeCallInfo::Encode(inlineeCallInfo, (uint32)instr->GetSrc1()->AsIntConstOpnd()->GetValue(), codeOffset); - Assert(encodeResult); + AssertOrFailFast(encodeResult); instr->GetSrc1()->AsIntConstOpnd()->SetValue(inlineeCallInfo); } diff --git a/lib/Runtime/Base/CallInfo.h b/lib/Runtime/Base/CallInfo.h index c750ef53472..e07f58a5c46 100644 --- a/lib/Runtime/Base/CallInfo.h +++ b/lib/Runtime/Base/CallInfo.h @@ -145,13 +145,24 @@ namespace Js struct InlineeCallInfo { // Assumes big-endian layout. - size_t Count: 4; - size_t InlineeStartOffset: sizeof(void*) * CHAR_BIT - 4; + uint Count : 4; +#if TARGET_32 + uint InlineeStartOffset : 28; +#else + uint unused : 28; + uint InlineeStartOffset; +#endif static size_t const MaxInlineeArgoutCount = 0xF; +#if TARGET_32 + static uint const ksizeofInlineeStartOffset = 28; +#else + static uint const ksizeofInlineeStartOffset = 32; +#endif + static uint const inlineeStartOffsetShiftCount = (sizeof(void*) * CHAR_BIT - Js::InlineeCallInfo::ksizeofInlineeStartOffset); static bool Encode(intptr_t &callInfo, size_t count, size_t offset) { - const size_t offsetMask = (~(size_t)0) >> 4; + const size_t offsetMask = ~(uint)0 >> (sizeof(uint) * CHAR_BIT - ksizeofInlineeStartOffset); const size_t countMask = 0x0000000F; if (count != (count & countMask)) { @@ -163,8 +174,7 @@ namespace Js return false; } - callInfo = (offset << 4) | count; - + callInfo = (offset << inlineeStartOffsetShiftCount) | count; return true; } diff --git a/lib/Runtime/Language/JavascriptStackWalker.cpp b/lib/Runtime/Language/JavascriptStackWalker.cpp index b4fbf10dd81..b91d1e6fd3a 100644 --- a/lib/Runtime/Language/JavascriptStackWalker.cpp +++ b/lib/Runtime/Language/JavascriptStackWalker.cpp @@ -1461,20 +1461,15 @@ namespace Js { Assert(!IsTopMostFrame()); Assert(currentIndex); -#pragma warning(push) -#pragma warning(disable: 4254) + return GetFrameAtIndex(currentIndex - 1)->callInfo.InlineeStartOffset; -#pragma warning(pop) } uint32 InlinedFrameWalker::GetBottomMostInlineeOffset() const { Assert(frameCount); -#pragma warning(push) -#pragma warning(disable: 4254) return GetFrameAtIndex(frameCount - 1)->callInfo.InlineeStartOffset; -#pragma warning(pop) } Js::JavascriptFunction *InlinedFrameWalker::GetBottomMostFunctionObject() const