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
1 change: 1 addition & 0 deletions src/coreclr/debug/createdump/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ target_link_libraries(createdump_static PRIVATE minipal)
PRIVATE
createdump_static
corguids
coreclrpal_dac
dbgutil
${CMAKE_DL_LIBS}
)
Expand Down
132 changes: 14 additions & 118 deletions src/coreclr/debug/createdump/createdumppal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,102 +2,21 @@
// The .NET Foundation licenses this file to you under the MIT license.

#include "createdump.h"
#include <time.h>
#include <sys/time.h>

#define INITGUID
#include <guiddef.h>

// Used by the ICLRDataTarget and ICLRDataEnumMemoryRegionsCallback implementations.
DEFINE_GUID(IID_IUnknown, 0x00000000, 0x0000, 0x0000, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46);

#if defined(__linux__)
#define PAL_FUNCTION_PREFIX "DAC_"
#else
#define PAL_FUNCTION_PREFIX
#if defined(HOST_ARM64)
// Used by the PAL interlocked helpers.
bool g_arm64_atomics_present = false;
#endif

typedef int (*PFN_PAL_InitializeDLL)();
typedef void (*PFN_PAL_TerminateEx)(int);

typedef BOOL (*PFN_PAL_VirtualUnwindOutOfProc)(
CONTEXT *context,
PULONG64 functionStart,
SIZE_T baseAddress,
UnwindReadMemoryCallback readMemoryCallback,
bool *isSignalFrame);

typedef BOOL (*PFN_PAL_GetUnwindInfoSize)(
SIZE_T baseAddress,
ULONG64 ehFrameHdrAddr,
UnwindReadMemoryCallback readMemoryCallback,
PULONG64 ehFrameStart,
PULONG64 ehFrameSize);

bool g_initialized = false;
PFN_PAL_InitializeDLL g_PAL_InitializeDLL = nullptr;
PFN_PAL_TerminateEx g_PAL_TerminateEx = nullptr;
PFN_PAL_VirtualUnwindOutOfProc g_PAL_VirtualUnwindOutOfProc = nullptr;
PFN_PAL_GetUnwindInfoSize g_PAL_GetUnwindInfoSize = nullptr;

bool
InitializePAL()
{
if (g_initialized)
{
return true;
}
g_initialized = true;

// Get createdump's path and load the DAC next to it.
Dl_info info;
if (dladdr((PVOID)&InitializePAL, &info) == 0)
{
printf_error("InitializePAL: dladdr(&InitializePAL) FAILED %s\n", dlerror());
return false;
}
std::string dacPath;
dacPath.append(info.dli_fname);
dacPath = GetDirectory(dacPath);
dacPath.append(MAKEDLLNAME_A("mscordaccore"));

// Load the DAC next to createdump
void* dacModule = dlopen(dacPath.c_str(), RTLD_LAZY);
if (dacModule == nullptr)
{
printf_error("InitializePAL: dlopen(%s) FAILED %s\n", dacPath.c_str(), dlerror());
return false;
}

// Get the PAL entry points needed by createdump
g_PAL_InitializeDLL = (PFN_PAL_InitializeDLL)dlsym(dacModule, PAL_FUNCTION_PREFIX "PAL_InitializeDLL");
if (g_PAL_InitializeDLL == nullptr)
{
printf_error("InitializePAL: dlsym(PAL_InitializeDLL) FAILED %s\n", dlerror());
return false;
}
if (g_PAL_InitializeDLL() != 0)
{
printf_error("InitializePAL: PAL initialization FAILED\n");
return false;
}
g_PAL_TerminateEx = (PFN_PAL_TerminateEx)dlsym(dacModule, PAL_FUNCTION_PREFIX "PAL_TerminateEx");
g_PAL_VirtualUnwindOutOfProc = (PFN_PAL_VirtualUnwindOutOfProc)dlsym(dacModule, PAL_FUNCTION_PREFIX "PAL_VirtualUnwindOutOfProc");
g_PAL_GetUnwindInfoSize = (PFN_PAL_GetUnwindInfoSize)dlsym(dacModule, PAL_FUNCTION_PREFIX "PAL_GetUnwindInfoSize");
return true;
}

void
UninitializePAL(
int exitCode)
{
if (g_PAL_TerminateEx != nullptr)
{
g_PAL_TerminateEx(exitCode);
}
}

#define TEMP_DIRECTORY_PATH "/tmp/"

// Used to construct the default dump path.
DWORD
PALAPI
GetTempPathA(
Expand All @@ -124,38 +43,6 @@ GetTempPathA(
return dwPathLen;
}

BOOL
PALAPI
PAL_VirtualUnwindOutOfProc(
CONTEXT *context,
PULONG64 functionStart,
SIZE_T baseAddress,
UnwindReadMemoryCallback readMemoryCallback,
bool *isSignalFrame)
{
if (!InitializePAL() || g_PAL_VirtualUnwindOutOfProc == nullptr)
{
return FALSE;
}
return g_PAL_VirtualUnwindOutOfProc(context, functionStart, baseAddress, readMemoryCallback, isSignalFrame);
}

BOOL
PALAPI
PAL_GetUnwindInfoSize(
SIZE_T baseAddress,
ULONG64 ehFrameHdrAddr,
UnwindReadMemoryCallback readMemoryCallback,
PULONG64 ehFrameStart,
PULONG64 ehFrameSize)
{
if (!InitializePAL() || g_PAL_GetUnwindInfoSize == nullptr)
{
return FALSE;
}
return g_PAL_GetUnwindInfoSize(baseAddress, ehFrameHdrAddr, readMemoryCallback, ehFrameStart, ehFrameSize);
}

//
// Used in pal\inc\rt\safecrt.h's _invalid_parameter handler
Comment thread
max-charlamb marked this conversation as resolved.
//
Expand Down Expand Up @@ -192,3 +79,12 @@ DebugBreak()

#endif // DEBUG

// createdump_static registers this callback when embedded in a host that owns a PAL.
// The standalone createdump executable calls createdump_main directly.
PALIMPORT
VOID
PALAPI
PAL_SetCreateDumpCallback(
IN PCREATEDUMP_CALLBACK callback)
{
}
25 changes: 1 addition & 24 deletions src/coreclr/debug/createdump/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,34 +4,11 @@
#include "createdump.h"

extern int createdump_main(const int argc, const char* argv[]);
extern void UninitializePAL(int exitCode);

#if defined(HOST_ARM64)
// Flag to check if atomics feature is available on
// the machine
bool g_arm64_atomics_present = false;
#endif

//
// Main entry point
//
int __cdecl main(const int argc, const char* argv[])
{
int exitCode = createdump_main(argc, argv);
#ifdef HOST_UNIX
UninitializePAL(exitCode);
#endif
return exitCode;
}

#ifdef HOST_UNIX

PALIMPORT
VOID
PALAPI
PAL_SetCreateDumpCallback(
IN PCREATEDUMP_CALLBACK callback)
{
return createdump_main(argc, argv);
}

#endif
5 changes: 5 additions & 0 deletions src/coreclr/pal/src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,12 @@ else()
if(NOT FEATURE_CROSSBITNESS AND NOT CLR_CMAKE_TARGET_ARCH_WASM)
add_library(coreclrpal_dac STATIC
exception/remote-unwind.cpp
${LIBUNWIND_OBJECTS}
)

if(CLR_CMAKE_USE_SYSTEM_LIBUNWIND)
target_link_libraries(coreclrpal_dac PUBLIC ${UNWIND_LIBS})
endif(CLR_CMAKE_USE_SYSTEM_LIBUNWIND)
endif(NOT FEATURE_CROSSBITNESS AND NOT CLR_CMAKE_TARGET_ARCH_WASM)
endif(CLR_CMAKE_TARGET_APPLE)

Expand Down
Loading
Loading