-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[cdac] Make DAC load and use cDAC when available (#100946)
- If `DOTNET_ENABLE_CDAC` environment variable is `1`, Look for `cdacreader` next to DAC and load it if found - Implement `ISOSDacInterface` in cDAC - currently returns `E_NOTIMPL` for everything - Make DAC delegate to cDAC (if available) for GetThreadStoreData and GetBreakingChangeVersion - Initialize cDAC with function for reading from the target
- Loading branch information
1 parent
e6f1fd8
commit e126f8f
Showing
15 changed files
with
753 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
#include "cdac.h" | ||
#include <sospriv.h> | ||
#include <sstring.h> | ||
#include "dbgutil.h" | ||
#include <cdac_reader.h> | ||
|
||
#define CDAC_LIB_NAME MAKEDLLNAME_W(W("cdacreader")) | ||
|
||
namespace | ||
{ | ||
bool TryLoadCDACLibrary(HMODULE *phCDAC) | ||
{ | ||
// Load cdacreader from next to DAC binary | ||
PathString path; | ||
if (FAILED(GetClrModuleDirectory(path))) | ||
return false; | ||
|
||
path.Append(CDAC_LIB_NAME); | ||
*phCDAC = CLRLoadLibrary(path.GetUnicode()); | ||
if (*phCDAC == NULL) | ||
return false; | ||
|
||
return true; | ||
} | ||
|
||
int ReadFromTargetCallback(uint64_t addr, uint8_t* dest, uint32_t count, void* context) | ||
{ | ||
CDAC* cdac = reinterpret_cast<CDAC*>(context); | ||
return cdac->ReadFromTarget(addr, dest, count); | ||
} | ||
} | ||
|
||
CDAC CDAC::Create(uint64_t descriptorAddr, ICorDebugDataTarget* target) | ||
{ | ||
HMODULE cdacLib; | ||
if (!TryLoadCDACLibrary(&cdacLib)) | ||
return CDAC::Invalid(); | ||
|
||
return CDAC{cdacLib, descriptorAddr, target}; | ||
} | ||
|
||
CDAC::CDAC(HMODULE module, uint64_t descriptorAddr, ICorDebugDataTarget* target) | ||
: m_module(module) | ||
, m_target{target} | ||
{ | ||
if (m_module == NULL) | ||
{ | ||
m_cdac_handle = NULL; | ||
return; | ||
} | ||
|
||
decltype(&cdac_reader_init) init = reinterpret_cast<decltype(&cdac_reader_init)>(::GetProcAddress(m_module, "cdac_reader_init")); | ||
decltype(&cdac_reader_get_sos_interface) getSosInterface = reinterpret_cast<decltype(&cdac_reader_get_sos_interface)>(::GetProcAddress(m_module, "cdac_reader_get_sos_interface")); | ||
_ASSERTE(init != nullptr && getSosInterface != nullptr); | ||
|
||
init(descriptorAddr, &ReadFromTargetCallback, this, &m_cdac_handle); | ||
getSosInterface(m_cdac_handle, &m_sos); | ||
} | ||
|
||
CDAC::~CDAC() | ||
{ | ||
if (m_cdac_handle != NULL) | ||
{ | ||
decltype(&cdac_reader_free) free = reinterpret_cast<decltype(&cdac_reader_free)>(::GetProcAddress(m_module, "cdac_reader_free")); | ||
_ASSERTE(free != nullptr); | ||
free(m_cdac_handle); | ||
} | ||
|
||
if (m_module != NULL) | ||
::FreeLibrary(m_module); | ||
} | ||
|
||
IUnknown* CDAC::SosInterface() | ||
{ | ||
return m_sos; | ||
} | ||
|
||
int CDAC::ReadFromTarget(uint64_t addr, uint8_t* dest, uint32_t count) | ||
{ | ||
HRESULT hr = ReadFromDataTarget(m_target, addr, dest, count); | ||
if (FAILED(hr)) | ||
return hr; | ||
|
||
return S_OK; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
#ifndef CDAC_H | ||
#define CDAC_H | ||
|
||
class CDAC final | ||
{ | ||
public: // static | ||
static CDAC Create(uint64_t descriptorAddr, ICorDebugDataTarget *pDataTarget); | ||
|
||
static CDAC Invalid() | ||
{ | ||
return CDAC{nullptr, 0, nullptr}; | ||
} | ||
|
||
public: | ||
CDAC(const CDAC&) = delete; | ||
CDAC& operator=(const CDAC&) = delete; | ||
|
||
CDAC(CDAC&& other) | ||
: m_module{ other.m_module } | ||
, m_cdac_handle{ other.m_cdac_handle } | ||
, m_target{ other.m_target } | ||
, m_sos{ other.m_sos.Extract() } | ||
{ | ||
other.m_module = NULL; | ||
other.m_cdac_handle = 0; | ||
other.m_target = NULL; | ||
other.m_sos = NULL; | ||
} | ||
|
||
CDAC& operator=(CDAC&& other) | ||
{ | ||
m_module = other.m_module; | ||
m_cdac_handle = other.m_cdac_handle; | ||
m_target = other.m_target; | ||
m_sos = other.m_sos.Extract(); | ||
|
||
other.m_module = NULL; | ||
other.m_cdac_handle = 0; | ||
other.m_target = NULL; | ||
other.m_sos = NULL; | ||
|
||
return *this; | ||
} | ||
|
||
~CDAC(); | ||
|
||
bool IsValid() const | ||
{ | ||
return m_module != NULL && m_cdac_handle != 0; | ||
} | ||
|
||
// This does not AddRef the returned interface | ||
IUnknown* SosInterface(); | ||
int ReadFromTarget(uint64_t addr, uint8_t* dest, uint32_t count); | ||
|
||
private: | ||
CDAC(HMODULE module, uint64_t descriptorAddr, ICorDebugDataTarget* target); | ||
|
||
private: | ||
HMODULE m_module; | ||
intptr_t m_cdac_handle; | ||
ICorDebugDataTarget* m_target; | ||
NonVMComHolder<IUnknown> m_sos; | ||
}; | ||
|
||
#endif // CDAC_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.