From f8d142148b52922de0fc03d37b71ec01ed248d9a Mon Sep 17 00:00:00 2001 From: Christian Scheuer Date: Tue, 8 Nov 2016 13:40:37 +0100 Subject: [PATCH 01/10] RegDisplay saves FP --- src/Native/Runtime/amd64/AsmOffsetsCpu.h | 8 ++++---- src/Native/Runtime/regdisplay.h | 10 ++++++++++ src/Native/Runtime/unix/UnixContext.cpp | 9 +++++++++ 3 files changed, 23 insertions(+), 4 deletions(-) diff --git a/src/Native/Runtime/amd64/AsmOffsetsCpu.h b/src/Native/Runtime/amd64/AsmOffsetsCpu.h index 5dd0c02ff7e..d2495c36767 100644 --- a/src/Native/Runtime/amd64/AsmOffsetsCpu.h +++ b/src/Native/Runtime/amd64/AsmOffsetsCpu.h @@ -70,7 +70,7 @@ PLAT_ASM_OFFSET(90, REGDISPLAY, Xmm) #else // !UNIX_AMD64_ABI -PLAT_ASM_SIZEOF(198, ExInfo) +PLAT_ASM_SIZEOF(1a0, ExInfo) PLAT_ASM_OFFSET(0, ExInfo, m_pPrevExInfo) PLAT_ASM_OFFSET(8, ExInfo, m_pExContext) PLAT_ASM_OFFSET(10, ExInfo, m_exception) @@ -78,7 +78,7 @@ PLAT_ASM_OFFSET(18, ExInfo, m_kind) PLAT_ASM_OFFSET(19, ExInfo, m_passNumber) PLAT_ASM_OFFSET(1c, ExInfo, m_idxCurClause) PLAT_ASM_OFFSET(20, ExInfo, m_frameIter) -PLAT_ASM_OFFSET(190, ExInfo, m_notifyDebuggerSP) +PLAT_ASM_OFFSET(198, ExInfo, m_notifyDebuggerSP) PLAT_ASM_OFFSET(0, PInvokeTransitionFrame, m_RIP) PLAT_ASM_OFFSET(8, PInvokeTransitionFrame, m_FramePointer) @@ -86,7 +86,7 @@ PLAT_ASM_OFFSET(10, PInvokeTransitionFrame, m_pThread) PLAT_ASM_OFFSET(18, PInvokeTransitionFrame, m_dwFlags) PLAT_ASM_OFFSET(20, PInvokeTransitionFrame, m_PreservedRegs) -PLAT_ASM_SIZEOF(170, StackFrameIterator) +PLAT_ASM_SIZEOF(178, StackFrameIterator) PLAT_ASM_OFFSET(10, StackFrameIterator, m_FramePointer) PLAT_ASM_OFFSET(18, StackFrameIterator, m_ControlPC) PLAT_ASM_OFFSET(20, StackFrameIterator, m_RegDisplay) @@ -105,7 +105,7 @@ PLAT_ASM_OFFSET(38, PAL_LIMITED_CONTEXT, R13) PLAT_ASM_OFFSET(40, PAL_LIMITED_CONTEXT, R14) PLAT_ASM_OFFSET(48, PAL_LIMITED_CONTEXT, R15) -PLAT_ASM_SIZEOF(90, REGDISPLAY) +PLAT_ASM_SIZEOF(98, REGDISPLAY) PLAT_ASM_OFFSET(78, REGDISPLAY, SP) PLAT_ASM_OFFSET(18, REGDISPLAY, pRbx) diff --git a/src/Native/Runtime/regdisplay.h b/src/Native/Runtime/regdisplay.h index 098286b2e0c..2f2b780e940 100644 --- a/src/Native/Runtime/regdisplay.h +++ b/src/Native/Runtime/regdisplay.h @@ -29,6 +29,10 @@ struct REGDISPLAY PTR_PCODE pIP; PCODE IP; +#if defined(__APPLE__) + UIntNative FP; +#endif + #if defined(_TARGET_AMD64_) && !defined(UNIX_AMD64_ABI) Fp128 Xmm[16-6]; // preserved xmm6..xmm15 regs for EH stackwalk // these need to be unwound during a stack walk @@ -39,7 +43,13 @@ struct REGDISPLAY inline PCODE GetIP() { return IP; } inline PTR_PCODE GetAddrOfIP() { return pIP; } inline UIntNative GetSP() { return SP; } + +#if defined(__APPLE__) + inline UIntNative GetFP() { return FP; } +#else inline UIntNative GetFP() { return *pRbp; } +#endif + inline UIntNative GetPP() { return *pRbx; } inline void SetIP(PCODE IP) { this->IP = IP; } diff --git a/src/Native/Runtime/unix/UnixContext.cpp b/src/Native/Runtime/unix/UnixContext.cpp index 493a27e54ad..0ca273e743f 100644 --- a/src/Native/Runtime/unix/UnixContext.cpp +++ b/src/Native/Runtime/unix/UnixContext.cpp @@ -298,7 +298,11 @@ static void RegDisplayToUnwindCursor(REGDISPLAY* regDisplay, unw_cursor_t *curso ASSIGN_REG(UNW_REG_IP, IP) ASSIGN_REG(UNW_REG_SP, SP) +#if defined(__APPLE__) + ASSIGN_REG(UNW_X86_64_RBP, FP) +#else ASSIGN_REG_PTR(UNW_X86_64_RBP, Rbp) +#endif ASSIGN_REG_PTR(UNW_X86_64_RBX, Rbx) ASSIGN_REG_PTR(UNW_X86_64_R12, R12) ASSIGN_REG_PTR(UNW_X86_64_R13, R13) @@ -403,6 +407,11 @@ void UnwindCursorToRegDisplay(unw_cursor_t *cursor, unw_context_t *unwContext, R unw_get_reg(cursor, UNW_REG_IP, (unw_word_t *) ®Display->IP); unw_get_reg(cursor, UNW_REG_SP, (unw_word_t *) ®Display->SP); +//WORKAROUND for exception unwind on OSX. Issue #1867 +#if defined(__APPLE__) && (defined(_TARGET_X86_) || defined(_TARGET_AMD64_)) + unw_get_reg(cursor, UNW_X86_64_RBP, (unw_word_t *) ®Display->FP); +#endif + #if defined(_AMD64_) regDisplay->pIP = PTR_PCODE(regDisplay->SP - sizeof(TADDR)); #endif From 6185860ee5a796e92ea80325800dcdb17bdc5a09 Mon Sep 17 00:00:00 2001 From: Christian Scheuer Date: Tue, 8 Nov 2016 14:14:52 +0100 Subject: [PATCH 02/10] Clean up --- src/Native/Runtime/amd64/AsmOffsetsCpu.h | 5 +++-- src/Native/Runtime/regdisplay.h | 8 -------- src/Native/Runtime/unix/UnixContext.cpp | 4 ---- 3 files changed, 3 insertions(+), 14 deletions(-) diff --git a/src/Native/Runtime/amd64/AsmOffsetsCpu.h b/src/Native/Runtime/amd64/AsmOffsetsCpu.h index d2495c36767..fced91857da 100644 --- a/src/Native/Runtime/amd64/AsmOffsetsCpu.h +++ b/src/Native/Runtime/amd64/AsmOffsetsCpu.h @@ -55,7 +55,7 @@ PLAT_ASM_OFFSET(0d0, PAL_LIMITED_CONTEXT, Xmm13) PLAT_ASM_OFFSET(0e0, PAL_LIMITED_CONTEXT, Xmm14) PLAT_ASM_OFFSET(0f0, PAL_LIMITED_CONTEXT, Xmm15) -PLAT_ASM_SIZEOF(130, REGDISPLAY) +PLAT_ASM_SIZEOF(138, REGDISPLAY) PLAT_ASM_OFFSET(78, REGDISPLAY, SP) PLAT_ASM_OFFSET(18, REGDISPLAY, pRbx) @@ -66,7 +66,7 @@ PLAT_ASM_OFFSET(58, REGDISPLAY, pR12) PLAT_ASM_OFFSET(60, REGDISPLAY, pR13) PLAT_ASM_OFFSET(68, REGDISPLAY, pR14) PLAT_ASM_OFFSET(70, REGDISPLAY, pR15) -PLAT_ASM_OFFSET(90, REGDISPLAY, Xmm) +PLAT_ASM_OFFSET(98, REGDISPLAY, Xmm) #else // !UNIX_AMD64_ABI @@ -107,6 +107,7 @@ PLAT_ASM_OFFSET(48, PAL_LIMITED_CONTEXT, R15) PLAT_ASM_SIZEOF(98, REGDISPLAY) PLAT_ASM_OFFSET(78, REGDISPLAY, SP) +PLAT_ASM_OFFSET(90, REGDISPLAY, FP) PLAT_ASM_OFFSET(18, REGDISPLAY, pRbx) PLAT_ASM_OFFSET(20, REGDISPLAY, pRbp) diff --git a/src/Native/Runtime/regdisplay.h b/src/Native/Runtime/regdisplay.h index 2f2b780e940..5b75cb1a9ba 100644 --- a/src/Native/Runtime/regdisplay.h +++ b/src/Native/Runtime/regdisplay.h @@ -28,10 +28,7 @@ struct REGDISPLAY UIntNative SP; PTR_PCODE pIP; PCODE IP; - -#if defined(__APPLE__) UIntNative FP; -#endif #if defined(_TARGET_AMD64_) && !defined(UNIX_AMD64_ABI) Fp128 Xmm[16-6]; // preserved xmm6..xmm15 regs for EH stackwalk @@ -43,12 +40,7 @@ struct REGDISPLAY inline PCODE GetIP() { return IP; } inline PTR_PCODE GetAddrOfIP() { return pIP; } inline UIntNative GetSP() { return SP; } - -#if defined(__APPLE__) inline UIntNative GetFP() { return FP; } -#else - inline UIntNative GetFP() { return *pRbp; } -#endif inline UIntNative GetPP() { return *pRbx; } diff --git a/src/Native/Runtime/unix/UnixContext.cpp b/src/Native/Runtime/unix/UnixContext.cpp index 0ca273e743f..040c03542ed 100644 --- a/src/Native/Runtime/unix/UnixContext.cpp +++ b/src/Native/Runtime/unix/UnixContext.cpp @@ -298,11 +298,7 @@ static void RegDisplayToUnwindCursor(REGDISPLAY* regDisplay, unw_cursor_t *curso ASSIGN_REG(UNW_REG_IP, IP) ASSIGN_REG(UNW_REG_SP, SP) -#if defined(__APPLE__) ASSIGN_REG(UNW_X86_64_RBP, FP) -#else - ASSIGN_REG_PTR(UNW_X86_64_RBP, Rbp) -#endif ASSIGN_REG_PTR(UNW_X86_64_RBX, Rbx) ASSIGN_REG_PTR(UNW_X86_64_R12, R12) ASSIGN_REG_PTR(UNW_X86_64_R13, R13) From 710bd0ffa647a39a1ed33970a6c8b4fc061eb314 Mon Sep 17 00:00:00 2001 From: Christian Scheuer Date: Tue, 8 Nov 2016 16:29:47 +0100 Subject: [PATCH 03/10] Fix for Windows build --- src/Native/Runtime/amd64/AsmOffsetsCpu.h | 4 ++-- src/Native/Runtime/regdisplay.h | 7 +++++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/Native/Runtime/amd64/AsmOffsetsCpu.h b/src/Native/Runtime/amd64/AsmOffsetsCpu.h index fced91857da..85bf0c99abe 100644 --- a/src/Native/Runtime/amd64/AsmOffsetsCpu.h +++ b/src/Native/Runtime/amd64/AsmOffsetsCpu.h @@ -55,7 +55,7 @@ PLAT_ASM_OFFSET(0d0, PAL_LIMITED_CONTEXT, Xmm13) PLAT_ASM_OFFSET(0e0, PAL_LIMITED_CONTEXT, Xmm14) PLAT_ASM_OFFSET(0f0, PAL_LIMITED_CONTEXT, Xmm15) -PLAT_ASM_SIZEOF(138, REGDISPLAY) +PLAT_ASM_SIZEOF(130, REGDISPLAY) PLAT_ASM_OFFSET(78, REGDISPLAY, SP) PLAT_ASM_OFFSET(18, REGDISPLAY, pRbx) @@ -66,7 +66,7 @@ PLAT_ASM_OFFSET(58, REGDISPLAY, pR12) PLAT_ASM_OFFSET(60, REGDISPLAY, pR13) PLAT_ASM_OFFSET(68, REGDISPLAY, pR14) PLAT_ASM_OFFSET(70, REGDISPLAY, pR15) -PLAT_ASM_OFFSET(98, REGDISPLAY, Xmm) +PLAT_ASM_OFFSET(90, REGDISPLAY, Xmm) #else // !UNIX_AMD64_ABI diff --git a/src/Native/Runtime/regdisplay.h b/src/Native/Runtime/regdisplay.h index 5b75cb1a9ba..f495377b57c 100644 --- a/src/Native/Runtime/regdisplay.h +++ b/src/Native/Runtime/regdisplay.h @@ -28,7 +28,9 @@ struct REGDISPLAY UIntNative SP; PTR_PCODE pIP; PCODE IP; +#if defined(UNIX_AMD64_ABI) UIntNative FP; +#endif #if defined(_TARGET_AMD64_) && !defined(UNIX_AMD64_ABI) Fp128 Xmm[16-6]; // preserved xmm6..xmm15 regs for EH stackwalk @@ -40,7 +42,12 @@ struct REGDISPLAY inline PCODE GetIP() { return IP; } inline PTR_PCODE GetAddrOfIP() { return pIP; } inline UIntNative GetSP() { return SP; } + +#if defined(UNIX_AMD64_ABI) inline UIntNative GetFP() { return FP; } +#else + inline UIntNative GetFP() { return *pRbp; } +#endif inline UIntNative GetPP() { return *pRbx; } From 16f9662151084044abc226bec24c8c7f36ab50ba Mon Sep 17 00:00:00 2001 From: Christian Scheuer Date: Wed, 9 Nov 2016 17:30:55 +0100 Subject: [PATCH 04/10] Undo changes in this PR --- src/Native/Runtime/amd64/AsmOffsetsCpu.h | 9 ++++----- src/Native/Runtime/regdisplay.h | 9 --------- src/Native/Runtime/unix/UnixContext.cpp | 7 +------ 3 files changed, 5 insertions(+), 20 deletions(-) diff --git a/src/Native/Runtime/amd64/AsmOffsetsCpu.h b/src/Native/Runtime/amd64/AsmOffsetsCpu.h index 85bf0c99abe..5dd0c02ff7e 100644 --- a/src/Native/Runtime/amd64/AsmOffsetsCpu.h +++ b/src/Native/Runtime/amd64/AsmOffsetsCpu.h @@ -70,7 +70,7 @@ PLAT_ASM_OFFSET(90, REGDISPLAY, Xmm) #else // !UNIX_AMD64_ABI -PLAT_ASM_SIZEOF(1a0, ExInfo) +PLAT_ASM_SIZEOF(198, ExInfo) PLAT_ASM_OFFSET(0, ExInfo, m_pPrevExInfo) PLAT_ASM_OFFSET(8, ExInfo, m_pExContext) PLAT_ASM_OFFSET(10, ExInfo, m_exception) @@ -78,7 +78,7 @@ PLAT_ASM_OFFSET(18, ExInfo, m_kind) PLAT_ASM_OFFSET(19, ExInfo, m_passNumber) PLAT_ASM_OFFSET(1c, ExInfo, m_idxCurClause) PLAT_ASM_OFFSET(20, ExInfo, m_frameIter) -PLAT_ASM_OFFSET(198, ExInfo, m_notifyDebuggerSP) +PLAT_ASM_OFFSET(190, ExInfo, m_notifyDebuggerSP) PLAT_ASM_OFFSET(0, PInvokeTransitionFrame, m_RIP) PLAT_ASM_OFFSET(8, PInvokeTransitionFrame, m_FramePointer) @@ -86,7 +86,7 @@ PLAT_ASM_OFFSET(10, PInvokeTransitionFrame, m_pThread) PLAT_ASM_OFFSET(18, PInvokeTransitionFrame, m_dwFlags) PLAT_ASM_OFFSET(20, PInvokeTransitionFrame, m_PreservedRegs) -PLAT_ASM_SIZEOF(178, StackFrameIterator) +PLAT_ASM_SIZEOF(170, StackFrameIterator) PLAT_ASM_OFFSET(10, StackFrameIterator, m_FramePointer) PLAT_ASM_OFFSET(18, StackFrameIterator, m_ControlPC) PLAT_ASM_OFFSET(20, StackFrameIterator, m_RegDisplay) @@ -105,9 +105,8 @@ PLAT_ASM_OFFSET(38, PAL_LIMITED_CONTEXT, R13) PLAT_ASM_OFFSET(40, PAL_LIMITED_CONTEXT, R14) PLAT_ASM_OFFSET(48, PAL_LIMITED_CONTEXT, R15) -PLAT_ASM_SIZEOF(98, REGDISPLAY) +PLAT_ASM_SIZEOF(90, REGDISPLAY) PLAT_ASM_OFFSET(78, REGDISPLAY, SP) -PLAT_ASM_OFFSET(90, REGDISPLAY, FP) PLAT_ASM_OFFSET(18, REGDISPLAY, pRbx) PLAT_ASM_OFFSET(20, REGDISPLAY, pRbp) diff --git a/src/Native/Runtime/regdisplay.h b/src/Native/Runtime/regdisplay.h index f495377b57c..098286b2e0c 100644 --- a/src/Native/Runtime/regdisplay.h +++ b/src/Native/Runtime/regdisplay.h @@ -28,9 +28,6 @@ struct REGDISPLAY UIntNative SP; PTR_PCODE pIP; PCODE IP; -#if defined(UNIX_AMD64_ABI) - UIntNative FP; -#endif #if defined(_TARGET_AMD64_) && !defined(UNIX_AMD64_ABI) Fp128 Xmm[16-6]; // preserved xmm6..xmm15 regs for EH stackwalk @@ -42,13 +39,7 @@ struct REGDISPLAY inline PCODE GetIP() { return IP; } inline PTR_PCODE GetAddrOfIP() { return pIP; } inline UIntNative GetSP() { return SP; } - -#if defined(UNIX_AMD64_ABI) - inline UIntNative GetFP() { return FP; } -#else inline UIntNative GetFP() { return *pRbp; } -#endif - inline UIntNative GetPP() { return *pRbx; } inline void SetIP(PCODE IP) { this->IP = IP; } diff --git a/src/Native/Runtime/unix/UnixContext.cpp b/src/Native/Runtime/unix/UnixContext.cpp index 040c03542ed..493a27e54ad 100644 --- a/src/Native/Runtime/unix/UnixContext.cpp +++ b/src/Native/Runtime/unix/UnixContext.cpp @@ -298,7 +298,7 @@ static void RegDisplayToUnwindCursor(REGDISPLAY* regDisplay, unw_cursor_t *curso ASSIGN_REG(UNW_REG_IP, IP) ASSIGN_REG(UNW_REG_SP, SP) - ASSIGN_REG(UNW_X86_64_RBP, FP) + ASSIGN_REG_PTR(UNW_X86_64_RBP, Rbp) ASSIGN_REG_PTR(UNW_X86_64_RBX, Rbx) ASSIGN_REG_PTR(UNW_X86_64_R12, R12) ASSIGN_REG_PTR(UNW_X86_64_R13, R13) @@ -403,11 +403,6 @@ void UnwindCursorToRegDisplay(unw_cursor_t *cursor, unw_context_t *unwContext, R unw_get_reg(cursor, UNW_REG_IP, (unw_word_t *) ®Display->IP); unw_get_reg(cursor, UNW_REG_SP, (unw_word_t *) ®Display->SP); -//WORKAROUND for exception unwind on OSX. Issue #1867 -#if defined(__APPLE__) && (defined(_TARGET_X86_) || defined(_TARGET_AMD64_)) - unw_get_reg(cursor, UNW_X86_64_RBP, (unw_word_t *) ®Display->FP); -#endif - #if defined(_AMD64_) regDisplay->pIP = PTR_PCODE(regDisplay->SP - sizeof(TADDR)); #endif From 0a07b56190190ab99f8f00c53f754f1f2fe29449 Mon Sep 17 00:00:00 2001 From: Christian Scheuer Date: Wed, 9 Nov 2016 17:40:34 +0100 Subject: [PATCH 05/10] impl PAL_LIMITED_CONTEXT in REG --- src/Native/Runtime/amd64/AsmOffsetsCpu.h | 16 ++++++++++++++++ src/Native/Runtime/regdisplay.h | 4 ++++ 2 files changed, 20 insertions(+) diff --git a/src/Native/Runtime/amd64/AsmOffsetsCpu.h b/src/Native/Runtime/amd64/AsmOffsetsCpu.h index 5dd0c02ff7e..06fd7e850ee 100644 --- a/src/Native/Runtime/amd64/AsmOffsetsCpu.h +++ b/src/Native/Runtime/amd64/AsmOffsetsCpu.h @@ -70,7 +70,11 @@ PLAT_ASM_OFFSET(90, REGDISPLAY, Xmm) #else // !UNIX_AMD64_ABI +#if defined(__APPLE__) +PLAT_ASM_SIZEOF(1e8, ExInfo) +#else PLAT_ASM_SIZEOF(198, ExInfo) +#endif PLAT_ASM_OFFSET(0, ExInfo, m_pPrevExInfo) PLAT_ASM_OFFSET(8, ExInfo, m_pExContext) PLAT_ASM_OFFSET(10, ExInfo, m_exception) @@ -78,7 +82,11 @@ PLAT_ASM_OFFSET(18, ExInfo, m_kind) PLAT_ASM_OFFSET(19, ExInfo, m_passNumber) PLAT_ASM_OFFSET(1c, ExInfo, m_idxCurClause) PLAT_ASM_OFFSET(20, ExInfo, m_frameIter) +#if defined(__APPLE__) +PLAT_ASM_OFFSET(1e0, ExInfo, m_notifyDebuggerSP) +#else PLAT_ASM_OFFSET(190, ExInfo, m_notifyDebuggerSP) +#endif PLAT_ASM_OFFSET(0, PInvokeTransitionFrame, m_RIP) PLAT_ASM_OFFSET(8, PInvokeTransitionFrame, m_FramePointer) @@ -86,7 +94,11 @@ PLAT_ASM_OFFSET(10, PInvokeTransitionFrame, m_pThread) PLAT_ASM_OFFSET(18, PInvokeTransitionFrame, m_dwFlags) PLAT_ASM_OFFSET(20, PInvokeTransitionFrame, m_PreservedRegs) +#if defined(__APPLE__) +PLAT_ASM_SIZEOF(1c0, StackFrameIterator) +#else PLAT_ASM_SIZEOF(170, StackFrameIterator) +#endif PLAT_ASM_OFFSET(10, StackFrameIterator, m_FramePointer) PLAT_ASM_OFFSET(18, StackFrameIterator, m_ControlPC) PLAT_ASM_OFFSET(20, StackFrameIterator, m_RegDisplay) @@ -105,7 +117,11 @@ PLAT_ASM_OFFSET(38, PAL_LIMITED_CONTEXT, R13) PLAT_ASM_OFFSET(40, PAL_LIMITED_CONTEXT, R14) PLAT_ASM_OFFSET(48, PAL_LIMITED_CONTEXT, R15) +#if defined(__APPLE__) +PLAT_ASM_SIZEOF(d0, REGDISPLAY) +#else PLAT_ASM_SIZEOF(90, REGDISPLAY) +#endif PLAT_ASM_OFFSET(78, REGDISPLAY, SP) PLAT_ASM_OFFSET(18, REGDISPLAY, pRbx) diff --git a/src/Native/Runtime/regdisplay.h b/src/Native/Runtime/regdisplay.h index 098286b2e0c..20472f196ea 100644 --- a/src/Native/Runtime/regdisplay.h +++ b/src/Native/Runtime/regdisplay.h @@ -29,6 +29,10 @@ struct REGDISPLAY PTR_PCODE pIP; PCODE IP; +#if defined(__APPLE__) + PAL_LIMITED_CONTEXT PalLimitedContext; +#endif + #if defined(_TARGET_AMD64_) && !defined(UNIX_AMD64_ABI) Fp128 Xmm[16-6]; // preserved xmm6..xmm15 regs for EH stackwalk // these need to be unwound during a stack walk From b2c1a2d2e6ab676a67f37ca490001c0f186bf3a1 Mon Sep 17 00:00:00 2001 From: Christian Scheuer Date: Wed, 9 Nov 2016 18:07:45 +0100 Subject: [PATCH 06/10] Impl. pointer assignments in UnwindCursorToRegDisplay --- src/Native/Runtime/amd64/AsmOffsetsCpu.h | 2 +- src/Native/Runtime/unix/UnixContext.cpp | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/src/Native/Runtime/amd64/AsmOffsetsCpu.h b/src/Native/Runtime/amd64/AsmOffsetsCpu.h index 06fd7e850ee..8d259101293 100644 --- a/src/Native/Runtime/amd64/AsmOffsetsCpu.h +++ b/src/Native/Runtime/amd64/AsmOffsetsCpu.h @@ -118,7 +118,7 @@ PLAT_ASM_OFFSET(40, PAL_LIMITED_CONTEXT, R14) PLAT_ASM_OFFSET(48, PAL_LIMITED_CONTEXT, R15) #if defined(__APPLE__) -PLAT_ASM_SIZEOF(d0, REGDISPLAY) +PLAT_ASM_SIZEOF(e0, REGDISPLAY) #else PLAT_ASM_SIZEOF(90, REGDISPLAY) #endif diff --git a/src/Native/Runtime/unix/UnixContext.cpp b/src/Native/Runtime/unix/UnixContext.cpp index 493a27e54ad..648585e5609 100644 --- a/src/Native/Runtime/unix/UnixContext.cpp +++ b/src/Native/Runtime/unix/UnixContext.cpp @@ -410,6 +410,29 @@ void UnwindCursorToRegDisplay(unw_cursor_t *cursor, unw_context_t *unwContext, R #if defined(_ARM_) || defined(_ARM64_) regDisplay->IP |= 1; #endif + +#if defined(__APPLE__) + regDisplay->pRax = ®Display->PalLimitedContext.Rax; + regDisplay->pRdx = ®Display->PalLimitedContext.Rdx; + regDisplay->pRbx = ®Display->PalLimitedContext.Rbx; + regDisplay->pRbp = ®Display->PalLimitedContext.Rbp; + + regDisplay->pR12 = ®Display->PalLimitedContext.R12; + regDisplay->pR13 = ®Display->PalLimitedContext.R13; + regDisplay->pR14 = ®Display->PalLimitedContext.R14; + regDisplay->pR15 = ®Display->PalLimitedContext.R15; + + unw_get_reg(cursor, UNW_X86_64_RAX, (unw_word_t *) ®Display->pRax); + unw_get_reg(cursor, UNW_X86_64_RDX, (unw_word_t *) ®Display->pRdx); + unw_get_reg(cursor, UNW_X86_64_RBX, (unw_word_t *) ®Display->pRbx); + unw_get_reg(cursor, UNW_X86_64_RBP, (unw_word_t *) ®Display->pRbp); + + unw_get_reg(cursor, UNW_X86_64_R12, (unw_word_t *) ®Display->pR12); + unw_get_reg(cursor, UNW_X86_64_R13, (unw_word_t *) ®Display->pR13); + unw_get_reg(cursor, UNW_X86_64_R14, (unw_word_t *) ®Display->pR14); + unw_get_reg(cursor, UNW_X86_64_R15, (unw_word_t *) ®Display->pR15); +#endif + } #if defined(_AMD64_) From a2fb7c06e29699c5ecbe133f016c7fc139d7b655 Mon Sep 17 00:00:00 2001 From: Christian Scheuer Date: Wed, 9 Nov 2016 19:08:13 +0100 Subject: [PATCH 07/10] Rollback changes --- src/Native/Runtime/amd64/AsmOffsetsCpu.h | 16 ---------------- src/Native/Runtime/regdisplay.h | 4 ---- src/Native/Runtime/unix/UnixContext.cpp | 23 ----------------------- 3 files changed, 43 deletions(-) diff --git a/src/Native/Runtime/amd64/AsmOffsetsCpu.h b/src/Native/Runtime/amd64/AsmOffsetsCpu.h index 8d259101293..5dd0c02ff7e 100644 --- a/src/Native/Runtime/amd64/AsmOffsetsCpu.h +++ b/src/Native/Runtime/amd64/AsmOffsetsCpu.h @@ -70,11 +70,7 @@ PLAT_ASM_OFFSET(90, REGDISPLAY, Xmm) #else // !UNIX_AMD64_ABI -#if defined(__APPLE__) -PLAT_ASM_SIZEOF(1e8, ExInfo) -#else PLAT_ASM_SIZEOF(198, ExInfo) -#endif PLAT_ASM_OFFSET(0, ExInfo, m_pPrevExInfo) PLAT_ASM_OFFSET(8, ExInfo, m_pExContext) PLAT_ASM_OFFSET(10, ExInfo, m_exception) @@ -82,11 +78,7 @@ PLAT_ASM_OFFSET(18, ExInfo, m_kind) PLAT_ASM_OFFSET(19, ExInfo, m_passNumber) PLAT_ASM_OFFSET(1c, ExInfo, m_idxCurClause) PLAT_ASM_OFFSET(20, ExInfo, m_frameIter) -#if defined(__APPLE__) -PLAT_ASM_OFFSET(1e0, ExInfo, m_notifyDebuggerSP) -#else PLAT_ASM_OFFSET(190, ExInfo, m_notifyDebuggerSP) -#endif PLAT_ASM_OFFSET(0, PInvokeTransitionFrame, m_RIP) PLAT_ASM_OFFSET(8, PInvokeTransitionFrame, m_FramePointer) @@ -94,11 +86,7 @@ PLAT_ASM_OFFSET(10, PInvokeTransitionFrame, m_pThread) PLAT_ASM_OFFSET(18, PInvokeTransitionFrame, m_dwFlags) PLAT_ASM_OFFSET(20, PInvokeTransitionFrame, m_PreservedRegs) -#if defined(__APPLE__) -PLAT_ASM_SIZEOF(1c0, StackFrameIterator) -#else PLAT_ASM_SIZEOF(170, StackFrameIterator) -#endif PLAT_ASM_OFFSET(10, StackFrameIterator, m_FramePointer) PLAT_ASM_OFFSET(18, StackFrameIterator, m_ControlPC) PLAT_ASM_OFFSET(20, StackFrameIterator, m_RegDisplay) @@ -117,11 +105,7 @@ PLAT_ASM_OFFSET(38, PAL_LIMITED_CONTEXT, R13) PLAT_ASM_OFFSET(40, PAL_LIMITED_CONTEXT, R14) PLAT_ASM_OFFSET(48, PAL_LIMITED_CONTEXT, R15) -#if defined(__APPLE__) -PLAT_ASM_SIZEOF(e0, REGDISPLAY) -#else PLAT_ASM_SIZEOF(90, REGDISPLAY) -#endif PLAT_ASM_OFFSET(78, REGDISPLAY, SP) PLAT_ASM_OFFSET(18, REGDISPLAY, pRbx) diff --git a/src/Native/Runtime/regdisplay.h b/src/Native/Runtime/regdisplay.h index 20472f196ea..098286b2e0c 100644 --- a/src/Native/Runtime/regdisplay.h +++ b/src/Native/Runtime/regdisplay.h @@ -29,10 +29,6 @@ struct REGDISPLAY PTR_PCODE pIP; PCODE IP; -#if defined(__APPLE__) - PAL_LIMITED_CONTEXT PalLimitedContext; -#endif - #if defined(_TARGET_AMD64_) && !defined(UNIX_AMD64_ABI) Fp128 Xmm[16-6]; // preserved xmm6..xmm15 regs for EH stackwalk // these need to be unwound during a stack walk diff --git a/src/Native/Runtime/unix/UnixContext.cpp b/src/Native/Runtime/unix/UnixContext.cpp index 648585e5609..493a27e54ad 100644 --- a/src/Native/Runtime/unix/UnixContext.cpp +++ b/src/Native/Runtime/unix/UnixContext.cpp @@ -410,29 +410,6 @@ void UnwindCursorToRegDisplay(unw_cursor_t *cursor, unw_context_t *unwContext, R #if defined(_ARM_) || defined(_ARM64_) regDisplay->IP |= 1; #endif - -#if defined(__APPLE__) - regDisplay->pRax = ®Display->PalLimitedContext.Rax; - regDisplay->pRdx = ®Display->PalLimitedContext.Rdx; - regDisplay->pRbx = ®Display->PalLimitedContext.Rbx; - regDisplay->pRbp = ®Display->PalLimitedContext.Rbp; - - regDisplay->pR12 = ®Display->PalLimitedContext.R12; - regDisplay->pR13 = ®Display->PalLimitedContext.R13; - regDisplay->pR14 = ®Display->PalLimitedContext.R14; - regDisplay->pR15 = ®Display->PalLimitedContext.R15; - - unw_get_reg(cursor, UNW_X86_64_RAX, (unw_word_t *) ®Display->pRax); - unw_get_reg(cursor, UNW_X86_64_RDX, (unw_word_t *) ®Display->pRdx); - unw_get_reg(cursor, UNW_X86_64_RBX, (unw_word_t *) ®Display->pRbx); - unw_get_reg(cursor, UNW_X86_64_RBP, (unw_word_t *) ®Display->pRbp); - - unw_get_reg(cursor, UNW_X86_64_R12, (unw_word_t *) ®Display->pR12); - unw_get_reg(cursor, UNW_X86_64_R13, (unw_word_t *) ®Display->pR13); - unw_get_reg(cursor, UNW_X86_64_R14, (unw_word_t *) ®Display->pR14); - unw_get_reg(cursor, UNW_X86_64_R15, (unw_word_t *) ®Display->pR15); -#endif - } #if defined(_AMD64_) From d5366a82df244e219e9e446e3e47071affc25df1 Mon Sep 17 00:00:00 2001 From: Christian Scheuer Date: Wed, 9 Nov 2016 19:08:25 +0100 Subject: [PATCH 08/10] Add UNWIND_WORKAROUND define to CMakeLists.txt --- src/Native/CMakeLists.txt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/Native/CMakeLists.txt b/src/Native/CMakeLists.txt index 401318c8f9a..e30381405b4 100644 --- a/src/Native/CMakeLists.txt +++ b/src/Native/CMakeLists.txt @@ -104,6 +104,10 @@ if (CLR_CMAKE_PLATFORM_UNIX) add_compile_options(-fPIC) add_compile_options(-fvisibility=hidden) + if(CLR_CMAKE_PLATFORM_DARWIN) + add_definitions(-DUNWIND_WORKAROUND) + endif(CLR_CMAKE_PLATFORM_DARWIN) + if(CLR_CMAKE_PLATFORM_DARWIN) # We cannot enable "stack-protector-strong" on OS X due to a bug in clang compiler (current version 7.0.2) add_compile_options(-fstack-protector) From b510d3031b63e92ec6bff65a1eb6b718d8936d08 Mon Sep 17 00:00:00 2001 From: Christian Scheuer Date: Wed, 9 Nov 2016 19:16:58 +0100 Subject: [PATCH 09/10] ifdef around GET_CONTEXT_POINTER --- src/Native/Runtime/unix/UnixContext.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/Native/Runtime/unix/UnixContext.cpp b/src/Native/Runtime/unix/UnixContext.cpp index 493a27e54ad..f4f301acb2e 100644 --- a/src/Native/Runtime/unix/UnixContext.cpp +++ b/src/Native/Runtime/unix/UnixContext.cpp @@ -396,9 +396,12 @@ static void GetContextPointer(unw_cursor_t *cursor, unw_context_t *unwContext, i // Update REGDISPLAY from the unw_cursor_t and unw_context_t void UnwindCursorToRegDisplay(unw_cursor_t *cursor, unw_context_t *unwContext, REGDISPLAY *regDisplay) { -#define GET_CONTEXT_POINTER(unwReg, rdReg) GetContextPointer(cursor, unwContext, unwReg, ®Display->p##rdReg); - GET_CONTEXT_POINTERS -#undef GET_CONTEXT_POINTER + //TODO: Workaround for unwind on OSX: See https://github.com/dotnet/corert/pull/2166 +#if !defined(UNWIND_WORKAROUND) + #define GET_CONTEXT_POINTER(unwReg, rdReg) GetContextPointer(cursor, unwContext, unwReg, ®Display->p##rdReg); + GET_CONTEXT_POINTERS + #undef GET_CONTEXT_POINTER +#endif unw_get_reg(cursor, UNW_REG_IP, (unw_word_t *) ®Display->IP); unw_get_reg(cursor, UNW_REG_SP, (unw_word_t *) ®Display->SP); From bdeb6b76a8330dd733552b4560e531f5d7292fee Mon Sep 17 00:00:00 2001 From: Christian Scheuer Date: Sat, 26 Nov 2016 12:59:11 -0500 Subject: [PATCH 10/10] Revert to simpler ifdef for workaround --- src/Native/CMakeLists.txt | 4 ---- src/Native/Runtime/unix/UnixContext.cpp | 2 +- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/src/Native/CMakeLists.txt b/src/Native/CMakeLists.txt index e30381405b4..401318c8f9a 100644 --- a/src/Native/CMakeLists.txt +++ b/src/Native/CMakeLists.txt @@ -104,10 +104,6 @@ if (CLR_CMAKE_PLATFORM_UNIX) add_compile_options(-fPIC) add_compile_options(-fvisibility=hidden) - if(CLR_CMAKE_PLATFORM_DARWIN) - add_definitions(-DUNWIND_WORKAROUND) - endif(CLR_CMAKE_PLATFORM_DARWIN) - if(CLR_CMAKE_PLATFORM_DARWIN) # We cannot enable "stack-protector-strong" on OS X due to a bug in clang compiler (current version 7.0.2) add_compile_options(-fstack-protector) diff --git a/src/Native/Runtime/unix/UnixContext.cpp b/src/Native/Runtime/unix/UnixContext.cpp index f4f301acb2e..3ca321f12c6 100644 --- a/src/Native/Runtime/unix/UnixContext.cpp +++ b/src/Native/Runtime/unix/UnixContext.cpp @@ -397,7 +397,7 @@ static void GetContextPointer(unw_cursor_t *cursor, unw_context_t *unwContext, i void UnwindCursorToRegDisplay(unw_cursor_t *cursor, unw_context_t *unwContext, REGDISPLAY *regDisplay) { //TODO: Workaround for unwind on OSX: See https://github.com/dotnet/corert/pull/2166 -#if !defined(UNWIND_WORKAROUND) +#if !defined(__APPLE__) #define GET_CONTEXT_POINTER(unwReg, rdReg) GetContextPointer(cursor, unwContext, unwReg, ®Display->p##rdReg); GET_CONTEXT_POINTERS #undef GET_CONTEXT_POINTER