.macro PROLOG_STACK_ALLOC Size
sub sp, sp, \Size
- .cfi_adjust_cfa_offset \Size
.endm
.macro EPILOG_STACK_FREE Size
*--sp = fakeFrameReturnAddress;
// Switch the current context to the signal_handler_worker and the original stack
- ucontext_t ucontext2;
- getcontext(&ucontext2);
+ CONTEXT context2;
+ RtlCaptureContext(&context2);
// We don't care about the other registers state since the stack unwinding restores
// them for the target frame directly from the signal context.
- MCREG_Rsp(ucontext2.uc_mcontext) = (size_t)sp;
- MCREG_Rbx(ucontext2.uc_mcontext) = (size_t)faultSp;
- MCREG_Rbp(ucontext2.uc_mcontext) = (size_t)fp;
- MCREG_Rip(ucontext2.uc_mcontext) = (size_t)signal_handler_worker;
- MCREG_Rdi(ucontext2.uc_mcontext) = code;
- MCREG_Rsi(ucontext2.uc_mcontext) = (size_t)siginfo;
- MCREG_Rdx(ucontext2.uc_mcontext) = (size_t)context;
- MCREG_Rcx(ucontext2.uc_mcontext) = (size_t)returnPoint;
+ context2.Rsp = (size_t)sp;
+ context2.Rbx = (size_t)faultSp;
+ context2.Rbp = (size_t)fp;
+ context2.Rip = (size_t)signal_handler_worker;
+ context2.Rdi = code;
+ context2.Rsi = (size_t)siginfo;
+ context2.Rdx = (size_t)context;
+ context2.Rcx = (size_t)returnPoint;
- setcontext(&ucontext2);
+ RtlRestoreContext(&context2, NULL);
}
*--sp = (size_t)MCREG_R7(ucontext->uc_mcontext);
// Switch the current context to the signal_handler_worker and the original stack
- ucontext_t ucontext2;
- getcontext(&ucontext2);
+ CONTEXT context2;
+ RtlCaptureContext(&context2);
// We don't care about the other registers state since the stack unwinding restores
// them for the target frame directly from the signal context.
- MCREG_Sp(ucontext2.uc_mcontext) = (size_t)sp;
- MCREG_R7(ucontext2.uc_mcontext) = (size_t)sp; // Fp and Sp are the same
- MCREG_Lr(ucontext2.uc_mcontext) = fakeFrameReturnAddress;
- MCREG_Pc(ucontext2.uc_mcontext) = (size_t)signal_handler_worker;
- MCREG_R0(ucontext2.uc_mcontext) = code;
- MCREG_R1(ucontext2.uc_mcontext) = (size_t)siginfo;
- MCREG_R2(ucontext2.uc_mcontext) = (size_t)context;
- MCREG_R3(ucontext2.uc_mcontext) = (size_t)returnPoint;
+ context2.Sp = (size_t)sp;
+ context2.R7 = (size_t)sp; // Fp and Sp are the same
+ context2.Lr = fakeFrameReturnAddress;
+ context2.Pc = (size_t)signal_handler_worker;
+ context2.R0 = code;
+ context2.R1 = (size_t)siginfo;
+ context2.R2 = (size_t)context;
+ context2.R3 = (size_t)returnPoint;
- setcontext(&ucontext2);
+ RtlRestoreContext(&context2, NULL);
}
// address set to SignalHandlerWorkerReturn during SIGSEGV handling.
// It enables the unwinder to unwind stack from the handling code to the actual failure site.
NESTED_ENTRY CallSignalHandlerWrapper\Alignment, _TEXT, NoHandler
- PROLOG_STACK_ALLOC (128 + 8 + 8 + \Alignment) // red zone + fp + lr + alignment
+__StackAllocationSize = (128 + 8 + 8 + \Alignment) // red zone + fp + lr + alignment
+ PROLOG_STACK_ALLOC __StackAllocationSize
+ .cfi_adjust_cfa_offset __StackAllocationSize
PROLOG_SAVE_REG_PAIR fp, lr, 0
bl EXTERNAL_C_FUNC(signal_handler_worker)
LOCAL_LABEL(SignalHandlerWorkerReturn\Alignment):
EPILOG_RESTORE_REG_PAIR fp, lr, 0
- EPILOG_STACK_FREE (128 + 8 + 8 + \Alignment)
+ EPILOG_STACK_FREE __StackAllocationSize
ret
NESTED_END CallSignalHandlerWrapper\Alignment, _TEXT
*--sp = (size_t)MCREG_Fp(ucontext->uc_mcontext);
// Switch the current context to the signal_handler_worker and the original stack
- ucontext_t ucontext2;
- getcontext(&ucontext2);
+ CONTEXT context2;
+ RtlCaptureContext(&context2);
- // We don't care about the other registers state since the stack unwinding restores
- // them for the target frame directly from the signal context.
- MCREG_Sp(ucontext2.uc_mcontext) = (size_t)sp;
- MCREG_Fp(ucontext2.uc_mcontext) = (size_t)sp; // Fp and Sp are the same
- MCREG_Lr(ucontext2.uc_mcontext) = fakeFrameReturnAddress;
- MCREG_Pc(ucontext2.uc_mcontext) = (size_t)signal_handler_worker;
- MCREG_X0(ucontext2.uc_mcontext) = code;
- MCREG_X1(ucontext2.uc_mcontext) = (size_t)siginfo;
- MCREG_X2(ucontext2.uc_mcontext) = (size_t)context;
- MCREG_X3(ucontext2.uc_mcontext) = (size_t)returnPoint;
+ context2.Sp = (size_t)sp;
+ context2.Fp = (size_t)sp;
+ context2.Lr = fakeFrameReturnAddress;
+ context2.Pc = (size_t)signal_handler_worker;
+ context2.X0 = code;
+ context2.X1 = (size_t)siginfo;
+ context2.X2 = (size_t)context;
+ context2.X3 = (size_t)returnPoint;
- setcontext(&ucontext2);
+ RtlRestoreContext(&context2, NULL);
}
*--sp = fakeFrameReturnAddress;
// Switch the current context to the signal_handler_worker and the original stack
- ucontext_t ucontext2;
- getcontext(&ucontext2);
+ CONTEXT context2;
+ RtlCaptureContext(&context2);
// We don't care about the other registers state since the stack unwinding restores
// them for the target frame directly from the signal context.
- MCREG_Esp(ucontext2.uc_mcontext) = (size_t)sp;
- MCREG_Ebp(ucontext2.uc_mcontext) = (size_t)fp;
- MCREG_Eip(ucontext2.uc_mcontext) = (size_t)signal_handler_worker;
+ context2.Esp = (size_t)sp;
+ context2.ResumeEsp = (size_t)sp;
+ context2.Ebp = (size_t)fp;
+ context2.Eip = (size_t)signal_handler_worker;
- setcontext(&ucontext2);
+ RtlRestoreContext(&context2, NULL);
}
#include "pal/context.h"
-#ifdef __ANDROID__
-// getcontext and setcontext are not available natively on Android
-int getcontext(ucontext_t *ucp)
-{
- CONTEXT context;
- RtlCaptureContext(&context);
- CONTEXTToNativeContext(&context, ucp);
-
- return 0;
-}
-
-int setcontext(const ucontext_t *ucp)
-{
- CONTEXT context;
- ULONG contextFlags = CONTEXT_CONTROL | CONTEXT_INTEGER | CONTEXT_FLOATING_POINT;
-
-#if defined(_AMD64_)
- contextFlags |= CONTEXT_XSTATE;
-#endif
-
- CONTEXTFromNativeContext(ucp, &context, contextFlags);
- RtlRestoreContext(&context, NULL);
-
- return 0;
-}
-#endif
-
using namespace CorUnix;
#ifdef SIGRTMIN
struct SignalHandlerWorkerReturnPoint
{
bool returnFromHandler;
- ucontext_t context;
+ CONTEXT context;
};
/* internal function declarations *********************************************/
// fault. We must disassemble the instruction at record.ExceptionAddress
// to correctly fill in this value.
returnPoint->returnFromHandler = common_signal_handler(code, siginfo, context, 2, (size_t)0, (size_t)siginfo->si_addr);
- setcontext(&returnPoint->context);
+ RtlRestoreContext(&returnPoint->context, NULL);
}
/*++
volatile bool contextInitialization = true;
SignalHandlerWorkerReturnPoint returnPoint;
- getcontext(&returnPoint.context);
+ RtlCaptureContext(&returnPoint.context);
// When the signal handler worker completes, it uses setcontext to return to this point
#include <signal.h>
#include <pthread.h>
-#ifdef __ANDROID__
-// getcontext and setcontext are not available natively on Android
-int setcontext(const ucontext_t *ucp);
-int getcontext(ucontext_t* ucp);
-#endif
-
#if !HAVE_MACH_EXCEPTIONS
/* A type to wrap the native context type, which is ucontext_t on some
* platforms and another type elsewhere. */