Skip to content
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
22 changes: 9 additions & 13 deletions src/coreclr/debug/di/module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -928,7 +928,7 @@ void CordbModule::InitPublicMetaData(TargetBuffer buffer)
// copy it over from the remote process

CoTaskMemHolder<VOID> pMetaDataCopy;
CopyRemoteMetaData(buffer, pMetaDataCopy.GetAddr());
CopyRemoteMetaData(buffer, &pMetaDataCopy);


//
Expand All @@ -955,7 +955,7 @@ void CordbModule::InitPublicMetaData(TargetBuffer buffer)
reinterpret_cast<IUnknown**>( &m_pIMImport ));

// MetaData has taken ownership -don't free the memory
pMetaDataCopy.SuppressRelease();
pMetaDataCopy.Detach();

// Immediately restore the old setting.
HRESULT hrRestore = pDisp->SetOption(MetaDataSetUpdate, &valueOld);
Expand Down Expand Up @@ -1009,7 +1009,7 @@ void CordbModule::UpdatePublicMetaDataFromRemote(TargetBuffer bufferRemoteMetaDa

// First copy it from the remote process
CoTaskMemHolder<VOID> pLocalMetaDataPtr;
CopyRemoteMetaData(bufferRemoteMetaData, pLocalMetaDataPtr.GetAddr());
CopyRemoteMetaData(bufferRemoteMetaData, &pLocalMetaDataPtr);

IMetaDataDispenserEx * pDisp = GetProcess()->GetDispenser();
_ASSERTE(pDisp != NULL); // throws on error.
Expand Down Expand Up @@ -1037,7 +1037,7 @@ void CordbModule::UpdatePublicMetaDataFromRemote(TargetBuffer bufferRemoteMetaDa
IfFailThrow(hr);

// Success. MetaData now owns the metadata memory
pLocalMetaDataPtr.SuppressRelease();
pLocalMetaDataPtr.Detach();
}

//---------------------------------------------------------------------------------------
Expand All @@ -1058,7 +1058,7 @@ void CordbModule::UpdatePublicMetaDataFromRemote(TargetBuffer bufferRemoteMetaDa
// Uses an allocator (CoTaskMemHolder) that lets us hand off the memory to the metadata.
void CordbModule::CopyRemoteMetaData(
TargetBuffer buffer,
CoTaskMemHolder<VOID> * pLocalBuffer)
VOID** pLocalBuffer)
{
Comment thread
AaronRobinsonMSFT marked this conversation as resolved.
CONTRACTL
{
Expand All @@ -1071,20 +1071,16 @@ void CordbModule::CopyRemoteMetaData(

// Allocate space for the local copy of the metadata
// No need to zero out the memory since we'll fill it all here.
LPVOID pRawBuffer = CoTaskMemAlloc(buffer.cbSize);
if (pRawBuffer == NULL)
CoTaskMemHolder<BYTE> pBuffer{ (BYTE*)CoTaskMemAlloc(buffer.cbSize) };
if (pBuffer == NULL)
{
ThrowOutOfMemory();
}

pLocalBuffer->Assign(pRawBuffer);



// Copy the metadata from the left side
GetProcess()->SafeReadBuffer(buffer, (BYTE *)pRawBuffer);
GetProcess()->SafeReadBuffer(buffer, pBuffer);

return;
*pLocalBuffer = pBuffer.Detach();
}

HRESULT CordbModule::QueryInterface(REFIID id, void **pInterface)
Expand Down
4 changes: 2 additions & 2 deletions src/coreclr/debug/di/process.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -665,7 +665,7 @@ CordbProcess::CreateDacDbiInterface()
// same directory as DBI
if (m_hDacModule == NULL)
{
m_hDacModule.Assign(ShimProcess::GetDacModule(m_cordb->GetDacModulePath()));
m_hDacModule = ShimProcess::GetDacModule(m_cordb->GetDacModulePath());
}

//
Expand Down Expand Up @@ -1541,7 +1541,7 @@ void CordbProcess::FreeDac()
if (m_hDacModule != NULL)
{
LOG((LF_CORDB, LL_INFO1000, "Unloading DAC\n"));
m_hDacModule.Clear();
m_hDacModule.Free();
}
}

Expand Down
8 changes: 4 additions & 4 deletions src/coreclr/debug/di/rspriv.h
Original file line number Diff line number Diff line change
Expand Up @@ -4298,7 +4298,7 @@ class CordbModule : public CordbBase,
BOOL IsFileMetaDataValid();

// Helper to copy metadata buffer from the Target to the host.
void CopyRemoteMetaData(TargetBuffer buffer, CoTaskMemHolder<VOID> * pLocalBuffer);
void CopyRemoteMetaData(TargetBuffer buffer, VOID** pLocalBuffer);


CordbAssembly * ResolveAssemblyInternal(mdToken tkAssemblyRef);
Expand Down Expand Up @@ -6752,11 +6752,11 @@ typedef std::function<HRESULT(DWORD index, ICorDebugValue** ppValue)> ValueGette
class CordbValueEnum : public CordbBase, public ICorDebugValueEnum
{
public:
CordbValueEnum(CordbProcess* pProcess,
UINT maxCount,
CordbValueEnum(CordbProcess* pProcess,
UINT maxCount,
ValueGetter valueGetter,
NeuterList* pNeuterList);

virtual ~CordbValueEnum();
virtual void Neuter();

Expand Down
87 changes: 10 additions & 77 deletions src/coreclr/inc/ex.h
Original file line number Diff line number Diff line change
Expand Up @@ -281,85 +281,18 @@ class Exception
virtual Exception *DomainBoundCloneHelper() { return CloneHelper(); }
};

#if 1

inline void Exception__Delete(Exception* pvMemory)
struct ExceptionTraits final
{
Exception::Delete(pvMemory);
}

using ExceptionHolder = SpecializedWrapper<Exception, Exception__Delete>;
#else

//------------------------------------------------------------------------------
// class ExceptionHolder
//
// This is a very lightweight holder class for use inside the EX_TRY family
// of macros. It is based on the standard Holder classes, but has been
// highly specialized for this one function, so that extra code can be
// removed, and the resulting code can be simple enough for all of the
// non-exceptional-case code to be inlined.
class ExceptionHolder
{
private:
Exception *m_value;
BOOL m_acquired;

public:
FORCEINLINE ExceptionHolder(Exception *pException = NULL, BOOL take = TRUE)
: m_value(pException)
{
m_acquired = pException && take;
}

FORCEINLINE ~ExceptionHolder()
{
if (m_acquired)
{
Exception::Delete(m_value);
}
}

Exception* operator->() { return m_value; }

void operator=(Exception *p)
using Type = Exception*;
static constexpr Type Default() { return NULL; }
static void Free(Type value)
{
Release();
m_value = p;
Acquire();
STATIC_CONTRACT_WRAPPER;
Exception::Delete(value);
}

BOOL IsNull() { return m_value == NULL; }

operator Exception*() { return m_value; }

Exception* GetValue() { return m_value; }

void SuppressRelease() { m_acquired = FALSE; }

private:
void Acquire()
{
_ASSERTE(!m_acquired);

if (!IsNull())
{
m_acquired = TRUE;
}
}
void Release()
{
if (m_acquired)
{
_ASSERTE(!IsNull());
Exception::Delete(m_value);
m_acquired = FALSE;
}
}

};

#endif
using ExceptionHolder = LifetimeHolder<ExceptionTraits>;

// ---------------------------------------------------------------------------
// HRException class. Implements exception API for exceptions generated from HRESULTs
Expand Down Expand Up @@ -934,13 +867,13 @@ Exception *ExThrowWithInnerHelper(Exception *inner);

#define EX_RETHROW \
{ \
__pException.SuppressRelease(); \
__pException.Detach(); \
PAL_CPP_RETHROW; \
} \

// Define a copy of GET_EXCEPTION() that will not be redefined by clrex.h
#define GET_EXCEPTION() (__pException == NULL ? &__defaultException : __pException.GetValue())
#define EXTRACT_EXCEPTION() (__pException.Extract())
#define GET_EXCEPTION() (__pException == NULL ? &__defaultException : static_cast<Exception*>(__pException))
#define EXTRACT_EXCEPTION() (__pException.Detach())


//==============================================================================
Expand Down
Loading
Loading