Skip to content

Commit 828f201

Browse files
committed
fix arm xdata for oopjit
1 parent b45eaf8 commit 828f201

File tree

9 files changed

+67
-18
lines changed

9 files changed

+67
-18
lines changed

lib/Backend/Encoder.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,8 +324,20 @@ Encoder::Encode()
324324
#elif _M_ARM
325325
m_func->m_unwindInfo.EmitUnwindInfo(m_func->GetJITOutput(), alloc);
326326
m_func->GetJITOutput()->SetCodeAddress(m_func->GetJITOutput()->GetCodeAddress() | 0x1); // Set thumb mode
327-
#endif
328327

328+
if (m_func->IsOOPJIT())
329+
{
330+
size_t allocSize = XDataAllocator::GetAllocSize(alloc->allocation->xdata.pdataCount, alloc->allocation->xdata.xdataSize);
331+
BYTE * xprocXdata = NativeCodeDataNewArrayNoFixup(m_func->GetNativeCodeDataAllocator(), BYTE, allocSize);
332+
memcpy_s(xprocXdata, allocSize, alloc->allocation->xdata.address, allocSize);
333+
m_func->GetJITOutput()->RecordXData(xprocXdata);
334+
}
335+
else
336+
{
337+
XDataAllocator::Register(&alloc->allocation->xdata, m_func->GetJITOutput()->GetCodeAddress(), m_func->GetJITOutput()->GetCodeSize());
338+
m_func->GetInProcJITEntryPointInfo()->SetXDataInfo(&alloc->allocation->xdata);
339+
}
340+
#endif
329341
const bool isSimpleJit = m_func->IsSimpleJit();
330342

331343
if (this->m_inlineeFrameMap->Count() > 0 &&

lib/Backend/JITOutput.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,14 +161,19 @@ size_t
161161
JITOutput::RecordUnwindInfo(size_t offset, BYTE *unwindInfo, size_t size, BYTE * xdataAddr, HANDLE processHandle)
162162
{
163163
BYTE *xdataFinal = xdataAddr + offset;
164-
m_outputData->xdataAddr = (intptr_t)xdataAddr;
165164

166165
Assert(xdataFinal);
167166
Assert(((DWORD)xdataFinal & 0x3) == 0); // 4 byte aligned
168-
ChakraMemCopy(xdataFinal, size, unwindInfo, size, processHandle);
167+
memcpy_s(xdataFinal, size, unwindInfo, size);
169168

170169
return (size_t)xdataFinal;
171170
}
171+
172+
void
173+
JITOutput::RecordXData(BYTE * xdata)
174+
{
175+
m_outputData->xdataOffset = NativeCodeData::GetDataTotalOffset(xdata);
176+
}
172177
#endif
173178

174179
void

lib/Backend/JITOutput.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ class JITOutput
1818
void SetArgUsedForBranch(uint8 param);
1919
void SetFrameHeight(uint val);
2020
void RecordThrowMap(Js::ThrowMapEntry * throwMap, uint mapCount);
21-
21+
#ifdef _M_ARM
22+
void RecordXData(BYTE * xdata);
23+
#endif
2224
uint16 GetArgUsedForBranch() const;
2325
intptr_t GetCodeAddress() const;
2426
size_t GetCodeSize() const;

lib/Backend/NativeCodeGenerator.cpp

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1056,16 +1056,34 @@ NativeCodeGenerator::CodeGen(PageAllocator * pageAllocator, CodeGenWorkItem* wor
10561056
workItem->GetEntryPoint()->GetJitTransferData()->SetIsReady();
10571057
}
10581058

1059-
#if defined(_M_X64) || defined(_M_ARM32_OR_ARM64)
1059+
#if defined(_M_X64)
10601060
XDataAllocation * xdataInfo = HeapNewZ(XDataAllocation);
10611061
xdataInfo->address = (byte*)jitWriteData.xdataAddr;
1062-
#if defined(_M_ARM32_OR_ARM64)
1063-
xdataInfo->pdataCount = jitWriteData.pdataCount;
1064-
xdataInfo->xdataSize = jitWriteData.xdataSize;
1065-
#endif
10661062
XDataAllocator::Register(xdataInfo, jitWriteData.codeAddress, jitWriteData.codeSize);
10671063
epInfo->SetXDataInfo(xdataInfo);
10681064
#endif
1065+
1066+
1067+
#if defined(_M_ARM32_OR_ARM64)
1068+
// for in-proc jit we do registration in encoder
1069+
if (JITManager::GetJITManager()->IsOOPJITEnabled())
1070+
{
1071+
XDataAllocation * xdataInfo = HeapNewZ(XDataAllocation);
1072+
xdataInfo->pdataCount = jitWriteData.pdataCount;
1073+
xdataInfo->xdataSize = jitWriteData.xdataSize;
1074+
if (jitWriteData.buffer)
1075+
{
1076+
xdataInfo->address = jitWriteData.buffer->data + jitWriteData.xdataOffset;
1077+
}
1078+
else
1079+
{
1080+
xdataInfo->address = nullptr;
1081+
}
1082+
XDataAllocator::Register(xdataInfo, jitWriteData.codeAddress, jitWriteData.codeSize);
1083+
epInfo->SetXDataInfo(xdataInfo);
1084+
}
1085+
#endif
1086+
10691087
scriptContext->GetThreadContext()->SetValidCallTargetForCFG((PVOID)jitWriteData.codeAddress);
10701088
workItem->SetCodeAddress((size_t)jitWriteData.codeAddress);
10711089

lib/Backend/arm/UnwindInfoManager.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -540,10 +540,8 @@ DWORD UnwindInfoManager::EmitXdataStackAlloc(BYTE xData[], DWORD byte, DWORD sta
540540
void UnwindInfoManager::RecordPdataEntry(DWORD beginAddress, DWORD unwindData)
541541
{
542542
RUNTIME_FUNCTION *function = this->alloc->allocation->xdata.GetPdataArray() + this->pdataIndex;
543-
RUNTIME_FUNCTION localFunc;
544-
localFunc.BeginAddress = beginAddress;
545-
localFunc.UnwindData = unwindData;
546-
ChakraMemCopy(function, sizeof(RUNTIME_FUNCTION), &localFunc, sizeof(RUNTIME_FUNCTION), this->processHandle);
543+
function->BeginAddress = beginAddress;
544+
function->UnwindData = unwindData;
547545
}
548546

549547
DWORD UnwindInfoManager::EmitXdataHomeParams(BYTE xData[], DWORD byte)

lib/Common/Memory/PageAllocator.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,15 +125,15 @@ SegmentBase<T>::Initialize(DWORD allocFlags, bool excludeGuardPages)
125125

126126
if (!allocator->CreateSecondaryAllocator(this, committed, &this->secondaryAllocator))
127127
{
128-
GetAllocator()->GetVirtualAllocator()->Free(originalAddress, GetPageCount() * AutoSystemInfo::PageSize, MEM_RELEASE);
128+
GetAllocator()->GetVirtualAllocator()->Free(originalAddress, GetPageCount() * AutoSystemInfo::PageSize, MEM_RELEASE, this->allocator->processHandle);
129129
this->allocator->ReportFailure(GetPageCount() * AutoSystemInfo::PageSize);
130130
this->address = nullptr;
131131
return false;
132132
}
133133
#if defined(_M_X64_OR_ARM64) && defined(RECYCLER_WRITE_BARRIER_BYTE)
134134
else if (!RecyclerWriteBarrierManager::OnSegmentAlloc(this->address, this->segmentPageCount))
135135
{
136-
GetAllocator()->GetVirtualAllocator()->Free(originalAddress, GetPageCount() * AutoSystemInfo::PageSize, MEM_RELEASE);
136+
GetAllocator()->GetVirtualAllocator()->Free(originalAddress, GetPageCount() * AutoSystemInfo::PageSize, MEM_RELEASE, this->allocator->processHandle);
137137
this->allocator->ReportFailure(GetPageCount() * AutoSystemInfo::PageSize);
138138
this->address = nullptr;
139139
return false;

lib/Common/Memory/arm/XDataAllocator.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ class XDataAllocator sealed : public SecondaryAllocator
5858
bool Alloc(ULONG_PTR functionStart, DWORD functionSize, ushort pdataCount, ushort xdataSize, SecondaryAllocation* allocation);
5959
void Release(const SecondaryAllocation& address);
6060
bool CanAllocate();
61-
DWORD GetAllocSize(ushort pdataCount, ushort xdataSize)
61+
static DWORD GetAllocSize(ushort pdataCount, ushort xdataSize)
6262
{
6363
return sizeof(RUNTIME_FUNCTION) * pdataCount + xdataSize;
6464
}

lib/JITIDL/JITTypes.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -783,8 +783,12 @@ typedef struct JITOutputIDL
783783
unsigned int propertyGuardCount;
784784
unsigned int ctorCachesCount;
785785

786-
CHAKRA_PTR codeAddress;
786+
#if defined(_M_X64)
787787
CHAKRA_PTR xdataAddr;
788+
#elif defined(_M_ARM) || defined(_M_ARM64)
789+
unsigned int xdataOffset;
790+
#endif
791+
CHAKRA_PTR codeAddress;
788792
TypeGuardTransferEntryIDL* typeGuardEntries;
789793

790794
IDL_DEF([size_is(ctorCachesCount)]) CtorCacheTransferEntryIDL ** ctorCacheEntries;

lib/Runtime/Base/FunctionBody.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8701,13 +8701,23 @@ namespace Js
87018701
this->constructorCaches->Clear();
87028702
}
87038703

8704-
#if defined(_M_X64) || defined(_M_ARM32_OR_ARM64)
8704+
#if defined(_M_X64)
87058705
if (this->xdataInfo != nullptr)
87068706
{
87078707
XDataAllocator::Unregister(this->xdataInfo);
87088708
HeapDelete(this->xdataInfo);
87098709
this->xdataInfo = nullptr;
87108710
}
8711+
#elif defined(_M_ARM32_OR_ARM64)
8712+
if (this->xdataInfo != nullptr)
8713+
{
8714+
XDataAllocator::Unregister(this->xdataInfo);
8715+
if (JITManager::GetJITManager()->IsOOPJITEnabled())
8716+
{
8717+
HeapDelete(this->xdataInfo);
8718+
}
8719+
this->xdataInfo = nullptr;
8720+
}
87118721
#endif
87128722
#endif
87138723

0 commit comments

Comments
 (0)