Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
wiktork committed Oct 22, 2021
1 parent b84613b commit c259b82
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ HRESULT MicrosoftInstrumentationEngine::CCorProfilerFunctionInfoWrapper::SetILFu
{
HRESULT hr = S_OK;

IfFailRet(m_pMethodInfo->SetFinalRenderedFunctionBody(pbNewILMethodHeader, cbNewILMethodHeader, FALSE));
IfFailRet(m_pMethodInfo->SetFinalRenderedFunctionBody(pbNewILMethodHeader, cbNewILMethodHeader));

return S_OK;
}
Expand Down
25 changes: 14 additions & 11 deletions src/InstrumentationEngine/CorProfilerInfoWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -449,8 +449,6 @@ HRESULT MicrosoftInstrumentationEngine::CCorProfilerInfoWrapper::SetILFunctionBo
hr = pModuleInfo->GetMethodInfoByToken(methodToken, &pMethodInfo);

bool userBufferEnabled = InstrumentationEngineFeatures::UserBufferEnabled();
BYTE* pBuffer = nullptr;
ULONG cbBuffer = 0;
if (SUCCEEDED(hr))
{
if (!userBufferEnabled)
Expand All @@ -460,6 +458,8 @@ HRESULT MicrosoftInstrumentationEngine::CCorProfilerInfoWrapper::SetILFunctionBo
CLogging::LogError(_T("Incorrect buffer passed to SetFunctionBodyMalloc"));
return E_FAIL;
}
BYTE* pBuffer;
ULONG cbBuffer = 0;
IfFailRet(m_pMethodMalloc->GetCurrentBufferAndLen(&pBuffer, &cbBuffer));

if (pbNewILMethodHeader != pBuffer)
Expand All @@ -471,22 +471,23 @@ HRESULT MicrosoftInstrumentationEngine::CCorProfilerInfoWrapper::SetILFunctionBo
// NOTE: Relying on the size of the buffer that was handed out by the IMethodMalloc.
// this relies on the serialization of jit events by the profiler manager.
// Calculating the actual method size would require a fourth parse of header.
IfFailRet(pMethodInfo->SetFinalRenderedFunctionBody(pbNewILMethodHeader, cbBuffer, FALSE));
IfFailRet(pMethodInfo->SetFinalRenderedFunctionBody(pbNewILMethodHeader, cbBuffer));
}
else
{
BOOL userBufferMode = FALSE;
if (m_pMethodMalloc == nullptr)
{
userBufferMode = TRUE;
}
else
ULONG methodIlSize = 0;
if (m_pMethodMalloc != nullptr)
{
BYTE* pBuffer = nullptr;
ULONG cbBuffer = 0;
IfFailRet(m_pMethodMalloc->GetCurrentBufferAndLen(&pBuffer, &cbBuffer));
userBufferMode = pbNewILMethodHeader != pBuffer ? TRUE : FALSE;
if (pbNewILMethodHeader == pBuffer)
{
methodIlSize = cbBuffer;
}
}

IfFailRet(pMethodInfo->SetFinalRenderedFunctionBody(pbNewILMethodHeader, cbBuffer, userBufferMode));
IfFailRet(pMethodInfo->SetFinalRenderedFunctionBody(pbNewILMethodHeader, methodIlSize));
}
}
else if (userBufferEnabled)
Expand All @@ -497,6 +498,8 @@ HRESULT MicrosoftInstrumentationEngine::CCorProfilerInfoWrapper::SetILFunctionBo
//Method was possibly allocated using GetILFunctionBodyAllocator
if (m_pMethodMalloc != nullptr)
{
BYTE* pBuffer;
ULONG cbBuffer = 0;
IfFailRet(m_pMethodMalloc->GetCurrentBufferAndLen(&pBuffer, &cbBuffer));
if (pbNewILMethodHeader == pBuffer)
{
Expand Down
11 changes: 4 additions & 7 deletions src/InstrumentationEngine/MethodInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@ MicrosoftInstrumentationEngine::CMethodInfo::CMethodInfo(
m_bIsCreateBaselineEnabled(true),
m_bIsHeaderInitialized(false),
m_bIsRejit(false),
m_userDefinedBuffer(nullptr),
m_userBufferSize(0)
m_userDefinedBuffer(nullptr)
{
DEFINE_REFCOUNT_NAME(CMethodInfo);

Expand Down Expand Up @@ -1204,8 +1203,7 @@ HRESULT MicrosoftInstrumentationEngine::CMethodInfo::GetIntermediateRenderedFunc
// Called by the profiler info wrapper when a raw callback sets a function's il
HRESULT MicrosoftInstrumentationEngine::CMethodInfo::SetFinalRenderedFunctionBody(
_In_reads_bytes_(cbMethodSize) LPCBYTE pMethodHeader,
_In_ ULONG cbMethodSize,
_In_ BOOL userAddress
_In_ ULONG cbMethodSize
)
{
HRESULT hr = S_OK;
Expand All @@ -1214,7 +1212,7 @@ HRESULT MicrosoftInstrumentationEngine::CMethodInfo::SetFinalRenderedFunctionBod

m_bIsInstrumented = true;

if (!userAddress)
if (cbMethodSize > 0)
{
if (!m_pFinalRenderedMethod.empty())
{
Expand All @@ -1230,7 +1228,6 @@ HRESULT MicrosoftInstrumentationEngine::CMethodInfo::SetFinalRenderedFunctionBod
{
m_pModuleInfo->SetMethodIsTransformed(m_tkFunction, true);
m_userDefinedBuffer = pMethodHeader;
m_userBufferSize = cbMethodSize;
}

return hr;
Expand Down Expand Up @@ -1824,7 +1821,7 @@ HRESULT MicrosoftInstrumentationEngine::CMethodInfo::GetFinalInstrumentation(_Ou
}
else
{
*pcbMethodBody = m_userBufferSize;
*pcbMethodBody = 0;
*ppMethodBody = m_userDefinedBuffer;
}
}
Expand Down
5 changes: 1 addition & 4 deletions src/InstrumentationEngine/MethodInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@ namespace MicrosoftInstrumentationEngine
// - The user allocates the buffer, skipping GetILFunctionBodyAllocator (in newer runtimes, RVA's do not have any specific memory location requirements)
// - Raw profiler hook calls SetILFunctionBody right after DefineMethod
LPCBYTE m_userDefinedBuffer;
DWORD m_userBufferSize;

// Set to true if any client has instrumented the method.
bool m_bIsInstrumented;
Expand Down Expand Up @@ -176,9 +175,7 @@ namespace MicrosoftInstrumentationEngine
// status of this method to true.
HRESULT SetFinalRenderedFunctionBody(
_In_reads_bytes_(cbMethodSize) LPCBYTE pMethodHeader,
_In_ ULONG cbMethodSize,
_In_ BOOL userBuffer
);
_In_ ULONG cbMethodSize);

bool IsInstrumented() const
{
Expand Down

0 comments on commit c259b82

Please sign in to comment.