Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix BackoutJitData #54711

Merged
merged 2 commits into from
Jun 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/coreclr/vm/codeman.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2685,7 +2685,11 @@ void EEJitManager::allocCode(MethodDesc* pMD, size_t blockSize, size_t reserveFo
pCodeHdr = ((CodeHeader *)pCode) - 1;

*pAllocatedSize = sizeof(CodeHeader) + totalSize;
#define FEATURE_WXORX

#if defined(HOST_OSX) && defined(HOST_ARM64)
#define FEATURE_WXORX
#endif

#ifdef FEATURE_WXORX
pCodeHdrRW = (CodeHeader *)new BYTE[*pAllocatedSize];
#else
Expand Down
40 changes: 26 additions & 14 deletions src/coreclr/vm/jitinterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11211,6 +11211,27 @@ void CEEJitInfo::GetProfilingHandle(bool *pbHookFunction,
*pbIndirectedHandles = false;
}

/*********************************************************************/
void CEEJitInfo::WriteCodeBytes()
{
LIMITED_METHOD_CONTRACT;

#ifdef USE_INDIRECT_CODEHEADER
if (m_pRealCodeHeader != NULL)
{
// Restore the read only version of the real code header
m_CodeHeaderRW->SetRealCodeHeader(m_pRealCodeHeader);
m_pRealCodeHeader = NULL;
}
#endif // USE_INDIRECT_CODEHEADER

if (m_CodeHeaderRW != m_CodeHeader)
{
ExecutableWriterHolder<void> codeWriterHolder((void *)m_CodeHeader, m_codeWriteBufferSize);
memcpy(codeWriterHolder.GetRW(), m_CodeHeaderRW, m_codeWriteBufferSize);
}
}

/*********************************************************************/
void CEEJitInfo::BackoutJitData(EEJitManager * jitMgr)
{
Expand All @@ -11219,6 +11240,10 @@ void CEEJitInfo::BackoutJitData(EEJitManager * jitMgr)
GC_TRIGGERS;
} CONTRACTL_END;

// The RemoveJitData call below requires the m_CodeHeader to be valid, so we need to write
// the code bytes to the target memory location.
WriteCodeBytes();

CodeHeader* pCodeHeader = m_CodeHeader;
if (pCodeHeader)
jitMgr->RemoveJitData(pCodeHeader, m_GCinfo_len, m_EHinfo_len);
Expand All @@ -11232,20 +11257,7 @@ void CEEJitInfo::WriteCode(EEJitManager * jitMgr)
GC_TRIGGERS;
} CONTRACTL_END;

#ifdef USE_INDIRECT_CODEHEADER
if (m_pRealCodeHeader != NULL)
{
// Restore the read only version of the real code header
m_CodeHeaderRW->SetRealCodeHeader(m_pRealCodeHeader);
m_pRealCodeHeader = NULL;
}
#endif // USE_INDIRECT_CODEHEADER

if (m_CodeHeaderRW != m_CodeHeader)
{
ExecutableWriterHolder<void> codeWriterHolder((void *)m_CodeHeader, m_codeWriteBufferSize);
memcpy(codeWriterHolder.GetRW(), m_CodeHeaderRW, m_codeWriteBufferSize);
}
WriteCodeBytes();

// Now that the code header was written to the final location, publish the code via the nibble map
jitMgr->NibbleMapSet(m_pCodeHeap, m_CodeHeader->GetCodeStartAddress(), TRUE);
Expand Down
2 changes: 2 additions & 0 deletions src/coreclr/vm/jitinterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -941,6 +941,8 @@ class CEEJitInfo : public CEEInfo

protected :

void WriteCodeBytes();

#ifdef FEATURE_PGO
// PGO data
struct ComputedPgoData
Expand Down