x86_64: Handle myfault exceptions when running on alternate signal stack
x86_64 only: * cygtls.cc (san::leave): Restore _my_tls.andreas. * cygtls.h (class san): Add _clemente as in 32 bit case. Add ret and frame members. (san::san): Handle _my_tls.andreas as on 32 bit. Take parameter and write it to new member ret. Store current stack pointer in frame. (san::~san): New destructor to restore _my_tls.andreas. (__try): Use __l_except address as parameter to san::san. * dcrt0.cc (dll_crt0_0): Add myfault_altstack_handler as vectored continuation handler. * exception.h (myfault_altstack_handler): Declare. * exceptions.cc (myfault_altstack_handler): New function. Explain what it's good for. Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
This commit is contained in:
@@ -301,11 +301,26 @@ extern _cygtls *_sig_tls;
|
||||
#ifdef __x86_64__
|
||||
class san
|
||||
{
|
||||
san *_clemente;
|
||||
uint64_t _cnt;
|
||||
public:
|
||||
san () __attribute__ ((always_inline))
|
||||
DWORD64 ret;
|
||||
DWORD64 frame;
|
||||
|
||||
san (PVOID _ret) __attribute__ ((always_inline))
|
||||
{
|
||||
_clemente = _my_tls.andreas;
|
||||
_my_tls.andreas = this;
|
||||
_cnt = _my_tls.locals.pathbufs._counters;
|
||||
/* myfault_altstack_handler needs the current stack pointer and the
|
||||
address of the _except block to restore the context correctly.
|
||||
See comment preceeding myfault_altstack_handler in exception.cc. */
|
||||
ret = (DWORD64) _ret;
|
||||
__asm__ volatile ("movq %%rsp,%0": "=o" (frame));
|
||||
}
|
||||
~san () __attribute__ ((always_inline))
|
||||
{
|
||||
_my_tls.andreas = _clemente;
|
||||
}
|
||||
/* This is the first thing called in the __except handler. The attribute
|
||||
"returns_twice" makes sure that GCC disregards any register value set
|
||||
@@ -363,7 +378,7 @@ public:
|
||||
{ \
|
||||
__label__ __l_try, __l_except, __l_endtry; \
|
||||
__mem_barrier; \
|
||||
san __sebastian; \
|
||||
san __sebastian (&&__l_except); \
|
||||
__asm__ goto ("\n" \
|
||||
" .seh_handler _ZN9exception7myfaultEP17_EXCEPTION_RECORDPvP8_CONTEXTP19_DISPATCHER_CONTEXT, @except \n" \
|
||||
" .seh_handlerdata \n" \
|
||||
|
Reference in New Issue
Block a user