Skip to content

Commit 3861bf8

Browse files
committed
Fix for NativeCodeData that some fields references the middle of another chunk
1 parent 65976f5 commit 3861bf8

File tree

5 files changed

+33
-8
lines changed

5 files changed

+33
-8
lines changed

lib/Backend/BailOut.h

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,12 @@ class BailOutRecord
176176
FixupNativeDataPointer(ehBailoutData, chunkList);
177177
FixupNativeDataPointer(stackLiteralBailOutRecord, chunkList);
178178
#ifdef _M_IX86
179-
FixupNativeDataPointer(startCallArgRestoreAdjustCounts, chunkList);
179+
// special handling for startCallOutParamCounts and outParamOffsets, becuase it points to middle of the allocation
180+
if (argOutOffsetInfo)
181+
{
182+
uint* startCallArgRestoreAdjustCountsStart = startCallArgRestoreAdjustCounts - argOutOffsetInfo->startCallIndex;
183+
NativeCodeData::AddFixupEntry(startCallArgRestoreAdjustCounts, startCallArgRestoreAdjustCountsStart, &this->startCallArgRestoreAdjustCounts, this, chunkList);
184+
}
180185
#endif
181186
}
182187

@@ -262,14 +267,21 @@ class BailOutRecord
262267
int * outParamOffsets;
263268
uint startCallCount;
264269
uint argOutSymStart;
270+
uint startCallIndex;
265271
void Fixup(NativeCodeData::DataChunk* chunkList)
266272
{
267273
FixupNativeDataPointer(argOutFloat64Syms, chunkList);
268274
FixupNativeDataPointer(argOutLosslessInt32Syms, chunkList);
269275
FixupNativeDataPointer(argOutSimd128F4Syms, chunkList);
270276
FixupNativeDataPointer(argOutSimd128I4Syms, chunkList);
271-
FixupNativeDataPointer(startCallOutParamCounts, chunkList);
272-
FixupNativeDataPointer(outParamOffsets, chunkList);
277+
278+
// special handling for startCallOutParamCounts and outParamOffsets, becuase it points to middle of the allocation
279+
uint* startCallOutParamCountsStart = startCallOutParamCounts - startCallIndex;
280+
NativeCodeData::AddFixupEntry(startCallOutParamCounts, startCallOutParamCountsStart, &this->startCallOutParamCounts, this, chunkList);
281+
282+
int* outParamOffsetsStart = outParamOffsets - argOutSymStart;
283+
NativeCodeData::AddFixupEntry(outParamOffsets, outParamOffsetsStart, &this->outParamOffsets, this, chunkList);
284+
273285
}
274286
};
275287

lib/Backend/LinearScan.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1649,6 +1649,7 @@ LinearScan::FillBailOutRecord(IR::Instr * instr)
16491649
if (currentBailOutRecord->argOutOffsetInfo->outParamOffsets == nullptr)
16501650
{
16511651
Assert(currentBailOutRecord->argOutOffsetInfo->startCallOutParamCounts == nullptr);
1652+
currentBailOutRecord->argOutOffsetInfo->startCallIndex = i;
16521653
currentBailOutRecord->argOutOffsetInfo->startCallOutParamCounts = &startCallOutParamCounts[i];
16531654
#ifdef _M_IX86
16541655
currentBailOutRecord->startCallArgRestoreAdjustCounts = &startCallArgRestoreAdjustCounts[i];

lib/Backend/NativeCodeData.cpp

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,18 @@ NativeCodeData::~NativeCodeData()
1818
PERF_COUNTER_SUB(Code, TotalNativeCodeDataSize, this->size);
1919
}
2020

21+
void
22+
NativeCodeData::AddFixupEntry(void* targetAddr, void* addrToFixup, void* startAddress, DataChunk * chunkList)
23+
{
24+
return NativeCodeData::AddFixupEntry(targetAddr, targetAddr, addrToFixup, startAddress, chunkList);
25+
}
26+
2127
// targetAddr: target address
28+
// targetStartAddr: target start address, some fied might reference to middle of another data chunk, like outParamOffsets
2229
// startAddress: current data start address
2330
// addrToFixup: address that currently pointing to dataAddr, which need to be updated
2431
void
25-
NativeCodeData::AddFixupEntry(void* targetAddr, void* addrToFixup, void* startAddress, DataChunk * chunkList)
32+
NativeCodeData::AddFixupEntry(void* targetAddr, void* targetStartAddr, void* addrToFixup, void* startAddress, DataChunk * chunkList)
2633
{
2734
Assert(addrToFixup >= startAddress);
2835
Assert(((__int64)addrToFixup) % sizeof(void*) == 0);
@@ -32,7 +39,11 @@ NativeCodeData::AddFixupEntry(void* targetAddr, void* addrToFixup, void* startAd
3239
return;
3340
}
3441

35-
DataChunk* targetChunk = NativeCodeData::GetDataChunk(targetAddr);
42+
Assert(targetStartAddr);
43+
44+
unsigned int inDataOffset = (unsigned int)((char*)targetAddr - (char*)targetStartAddr);
45+
DataChunk* targetChunk = NativeCodeData::GetDataChunk(targetStartAddr);
46+
Assert(targetChunk->len >= inDataOffset);
3647

3748
#if DBG
3849
bool foundTargetChunk = false;
@@ -42,15 +53,15 @@ NativeCodeData::AddFixupEntry(void* targetAddr, void* addrToFixup, void* startAd
4253
chunkList = chunkList->next;
4354
}
4455
AssertMsg(foundTargetChunk, "current pointer is not allocated with NativeCodeData allocator?"); // change to valid check instead of assertion?
45-
#endif
56+
#endif
4657

4758
DataChunk* chunk = NativeCodeData::GetDataChunk(startAddress);
4859

4960
NativeDataFixupEntry* entry = (NativeDataFixupEntry*)midl_user_allocate(sizeof(NativeDataFixupEntry));
5061
entry->addrOffset = (unsigned int)((__int64)addrToFixup - (__int64)startAddress);
5162
Assert(entry->addrOffset <= chunk->len - sizeof(void*));
5263

53-
entry->targetTotalOffset = targetChunk->offset;
64+
entry->targetTotalOffset = targetChunk->offset + inDataOffset;
5465
entry->next = chunk->fixupList;
5566
chunk->fixupList = entry;
5667

lib/Backend/NativeCodeData.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ class NativeCodeData
6262

6363
static void VerifyExistFixupEntry(void* targetAddr, void* addrToFixup, void* startAddress);
6464
static void AddFixupEntry(void* targetAddr, void* addrToFixup, void* startAddress, DataChunk * chunkList);
65+
static void AddFixupEntry(void* targetAddr, void* targetStartAddr, void* addrToFixup, void* startAddress, DataChunk * chunkList);
6566
static void AddFixupEntryForPointerArray(void* startAddress, DataChunk * chunkList);
6667
static void DeleteChunkList(DataChunk * chunkList);
6768
public:

lib/Backend/NativeCodeGenerator.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -916,7 +916,7 @@ NativeCodeGenerator::CodeGen(PageAllocator * pageAllocator, CodeGenWorkItem* wor
916916

917917
if (PHASE_TRACE1(Js::NativeCodeDataPhase))
918918
{
919-
Output::Print(L"\t NativeCodeData Fixup Entry: +%p(%p) ==> %p:\n", addrToFixup, *(void**)(addrToFixup), targetAddr);
919+
Output::Print(L"\tEntry: +%x %p(%p) ==> %p\n", updateList->addrOffset, addrToFixup, *(void**)(addrToFixup), targetAddr);
920920
}
921921

922922
*(void**)(addrToFixup) = targetAddr;

0 commit comments

Comments
 (0)