Skip to content
Closed
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
4 changes: 4 additions & 0 deletions src/coreclr/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@ if(CLR_CMAKE_HOST_UNIX)

add_subdirectory(src/pal)
add_subdirectory(src/hosts)
else(CLR_CMAKE_HOST_UNIX)
if(CLR_CMAKE_TARGET_UNIX)
add_subdirectory(src/pal/src/libunwind)
endif(CLR_CMAKE_TARGET_UNIX)
endif(CLR_CMAKE_HOST_UNIX)

# Add this subdir. We install the headers for the jit.
Expand Down
12 changes: 10 additions & 2 deletions src/coreclr/src/debug/daccess/dacfn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,16 @@ static BOOL DacReadAllAdapter(PVOID address, PVOID buffer, SIZE_T size)
return TRUE;
}

#ifdef HOST_WINDOWS
// For the cross OS dac, we don't have the full pal layer
// Use these minimal prototypes instead of the full pal header
typedef BOOL(*UnwindReadMemoryCallback)(PVOID address, PVOID buffer, SIZE_T size);

extern
BOOL
PAL_VirtualUnwindOutOfProc(PT_CONTEXT context, PT_KNONVOLATILE_CONTEXT_POINTERS contextPointers, SIZE_T baseAddress, UnwindReadMemoryCallback readMemoryCallback);
#endif

HRESULT
DacVirtualUnwind(ULONG32 threadId, PT_CONTEXT context, PT_KNONVOLATILE_CONTEXT_POINTERS contextPointers)
{
Expand Down Expand Up @@ -273,9 +283,7 @@ DacVirtualUnwind(ULONG32 threadId, PT_CONTEXT context, PT_KNONVOLATILE_CONTEXT_P
#endif
{
SIZE_T baseAddress = DacGlobalBase();
#ifdef HOST_UNIX
if (baseAddress == 0 || !PAL_VirtualUnwindOutOfProc(context, contextPointers, baseAddress, DacReadAllAdapter))
#endif
{
hr = E_FAIL;
}
Expand Down
6 changes: 6 additions & 0 deletions src/coreclr/src/dlls/mscordac/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,12 @@ if(CLR_CMAKE_TARGET_WIN32)
)
endif(CLR_CMAKE_TARGET_WIN32)

if(CLR_CMAKE_HOST_WIN32 AND CLR_CMAKE_TARGET_UNIX)
list(APPEND COREDAC_LIBRARIES
libunwind_xdac
)
endif(CLR_CMAKE_HOST_WIN32 AND CLR_CMAKE_TARGET_UNIX)

if(CLR_CMAKE_HOST_WIN32)
# mscordac.def should be generated before mscordaccore.dll is built
add_dependencies(mscordaccore mscordaccore_def)
Expand Down
75 changes: 56 additions & 19 deletions src/coreclr/src/pal/src/exception/remote-unwind.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

--*/

#ifdef HOST_UNIX
#include "config.h"
#include "pal/palinternal.h"
#include "pal/dbgmsg.h"
Expand All @@ -64,33 +65,69 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

SET_DEFAULT_DEBUG_CHANNEL(EXCEPT);

#ifndef ElfW
#define ElfW(foo) Elf_ ## foo
#endif
#define Ehdr ElfW(Ehdr)
#define Phdr ElfW(Phdr)
#define Shdr ElfW(Shdr)
#define Nhdr ElfW(Nhdr)
#define Dyn ElfW(Dyn)

#else // HOST_UNIX

#include <windows.h>
#define __STDC_FORMAT_MACROS
#include <inttypes.h>
#include <libunwind.h>
#include "debugmacros.h"
#include "crosscomp.h"

#define KNONVOLATILE_CONTEXT_POINTERS T_KNONVOLATILE_CONTEXT_POINTERS
#define CONTEXT T_CONTEXT

typedef BOOL(*UnwindReadMemoryCallback)(PVOID address, PVOID buffer, SIZE_T size);

#define ASSERT(x, ...)
#define TRACE(x, ...)

#ifndef ElfW
#ifdef TARGET_64BIT
#define ElfW(foo) Elf64_ ## foo
#else // TARGET_64BIT
#define ElfW(foo) Elf32_ ## foo
#endif // TARGET_64BIT
#endif // ElfW

#define Ehdr ElfW(Ehdr)
#define Phdr ElfW(Phdr)
#define Shdr ElfW(Shdr)
#define Nhdr ElfW(Nhdr)
#define Dyn ElfW(Dyn)

#define PALAPI

#endif // HOST_UNIX

#if defined(HAVE_UNW_GET_ACCESSORS)

#include <elf.h>
#include <link.h>

#if defined(HOST_X86) || defined(HOST_ARM)
#if defined(TARGET_X86) || defined(TARGET_ARM)
#define PRIx PRIx32
#define PRIu PRIu32
#define PRId PRId32
#define PRIA "08"
#define PRIxA PRIA PRIx
#elif defined(HOST_AMD64) || defined(HOST_ARM64)
#elif defined(TARGET_AMD64) || defined(TARGET_ARM64)
#define PRIx PRIx64
#define PRIu PRIu64
#define PRId PRId64
#define PRIA "016"
#define PRIxA PRIA PRIx
#endif

#ifndef ElfW
#define ElfW(foo) Elf_ ## foo
#endif
#define Ehdr ElfW(Ehdr)
#define Phdr ElfW(Phdr)
#define Shdr ElfW(Shdr)
#define Nhdr ElfW(Nhdr)
#define Dyn ElfW(Dyn)

extern "C" int
_OOP_find_proc_info(
Expand Down Expand Up @@ -120,7 +157,7 @@ typedef struct _libunwindInfo

static void UnwindContextToContext(unw_cursor_t *cursor, CONTEXT *winContext)
{
#if defined(HOST_AMD64)
#if defined(TARGET_AMD64)
unw_get_reg(cursor, UNW_REG_IP, (unw_word_t *) &winContext->Rip);
unw_get_reg(cursor, UNW_REG_SP, (unw_word_t *) &winContext->Rsp);
unw_get_reg(cursor, UNW_X86_64_RBP, (unw_word_t *) &winContext->Rbp);
Expand All @@ -129,14 +166,14 @@ static void UnwindContextToContext(unw_cursor_t *cursor, CONTEXT *winContext)
unw_get_reg(cursor, UNW_X86_64_R13, (unw_word_t *) &winContext->R13);
unw_get_reg(cursor, UNW_X86_64_R14, (unw_word_t *) &winContext->R14);
unw_get_reg(cursor, UNW_X86_64_R15, (unw_word_t *) &winContext->R15);
#elif defined(HOST_X86)
#elif defined(TARGET_X86)
unw_get_reg(cursor, UNW_REG_IP, (unw_word_t *) &winContext->Eip);
unw_get_reg(cursor, UNW_REG_SP, (unw_word_t *) &winContext->Esp);
unw_get_reg(cursor, UNW_X86_EBP, (unw_word_t *) &winContext->Ebp);
unw_get_reg(cursor, UNW_X86_EBX, (unw_word_t *) &winContext->Ebx);
unw_get_reg(cursor, UNW_X86_ESI, (unw_word_t *) &winContext->Esi);
unw_get_reg(cursor, UNW_X86_EDI, (unw_word_t *) &winContext->Edi);
#elif defined(HOST_ARM)
#elif defined(TARGET_ARM)
unw_get_reg(cursor, UNW_REG_IP, (unw_word_t *) &winContext->Pc);
unw_get_reg(cursor, UNW_REG_SP, (unw_word_t *) &winContext->Sp);
unw_get_reg(cursor, UNW_ARM_R4, (unw_word_t *) &winContext->R4);
Expand All @@ -149,7 +186,7 @@ static void UnwindContextToContext(unw_cursor_t *cursor, CONTEXT *winContext)
unw_get_reg(cursor, UNW_ARM_R11, (unw_word_t *) &winContext->R11);
unw_get_reg(cursor, UNW_ARM_R14, (unw_word_t *) &winContext->Lr);
TRACE("sp %p pc %p lr %p\n", winContext->Sp, winContext->Pc, winContext->Lr);
#elif defined(HOST_ARM64)
#elif defined(TARGET_ARM64)
unw_get_reg(cursor, UNW_REG_IP, (unw_word_t *) &winContext->Pc);
unw_get_reg(cursor, UNW_REG_SP, (unw_word_t *) &winContext->Sp);
unw_get_reg(cursor, UNW_AARCH64_X19, (unw_word_t *) &winContext->X19);
Expand Down Expand Up @@ -210,7 +247,7 @@ access_reg(unw_addr_space_t as, unw_regnum_t regnum, unw_word_t *valp, int write

switch (regnum)
{
#if defined(HOST_AMD64)
#if defined(TARGET_AMD64)
case UNW_REG_IP: *valp = (unw_word_t)winContext->Rip; break;
case UNW_REG_SP: *valp = (unw_word_t)winContext->Rsp; break;
case UNW_X86_64_RBP: *valp = (unw_word_t)winContext->Rbp; break;
Expand All @@ -219,14 +256,14 @@ access_reg(unw_addr_space_t as, unw_regnum_t regnum, unw_word_t *valp, int write
case UNW_X86_64_R13: *valp = (unw_word_t)winContext->R13; break;
case UNW_X86_64_R14: *valp = (unw_word_t)winContext->R14; break;
case UNW_X86_64_R15: *valp = (unw_word_t)winContext->R15; break;
#elif defined(HOST_X86)
#elif defined(TARGET_X86)
case UNW_REG_IP: *valp = (unw_word_t)winContext->Eip; break;
case UNW_REG_SP: *valp = (unw_word_t)winContext->Esp; break;
case UNW_X86_EBX: *valp = (unw_word_t)winContext->Ebx; break;
case UNW_X86_ESI: *valp = (unw_word_t)winContext->Esi; break;
case UNW_X86_EDI: *valp = (unw_word_t)winContext->Edi; break;
case UNW_X86_EBP: *valp = (unw_word_t)winContext->Ebp; break;
#elif defined(HOST_ARM)
#elif defined(TARGET_ARM)
case UNW_ARM_R4: *valp = (unw_word_t)winContext->R4; break;
case UNW_ARM_R5: *valp = (unw_word_t)winContext->R5; break;
case UNW_ARM_R6: *valp = (unw_word_t)winContext->R6; break;
Expand All @@ -238,7 +275,7 @@ access_reg(unw_addr_space_t as, unw_regnum_t regnum, unw_word_t *valp, int write
case UNW_ARM_R13: *valp = (unw_word_t)winContext->Sp; break;
case UNW_ARM_R14: *valp = (unw_word_t)winContext->Lr; break;
case UNW_ARM_R15: *valp = (unw_word_t)winContext->Pc; break;
#elif defined(HOST_ARM64)
#elif defined(TARGET_ARM64)
case UNW_AARCH64_X19: *valp = (unw_word_t)winContext->X19; break;
case UNW_AARCH64_X20: *valp = (unw_word_t)winContext->X20; break;
case UNW_AARCH64_X21: *valp = (unw_word_t)winContext->X21; break;
Expand Down Expand Up @@ -479,4 +516,4 @@ PAL_VirtualUnwindOutOfProc(CONTEXT *context, KNONVOLATILE_CONTEXT_POINTERS *cont
return FALSE;
}

#endif // defined(HOST_AMD64) && defined(HAVE_UNW_GET_ACCESSORS)
#endif // defined(HAVE_UNW_GET_ACCESSORS)
Loading