Fix original stack when running signal handler on alternate stack

* autoload.cc (SetThreadStackGuarantee): Import.
        * cygtls.h (struct _cygtls): Replace thread_context with a ucontext_t
        called context.
        * exceptions.cc (exception::handle): Exit from process via signal_exit
        in case sig_send returns from handling a stack overflow SIGSEGV.
        Explain why.
        (dumpstack_overflow_wrapper): Thread wrapper to create a stackdump
        from another thread.
        (signal_exit): Fix argument list to reflect three-arg signal handler.
        In case we have to create a stackdump for a stack overflow condition,
        do so from a separate thread.  Explain why.
        (sigpacket::process): Don't run signal_exit on alternate stack.
        (altstack_wrapper): Wrapper function to do stack correction when
        calling the signal handler on an alternate stack to handle a stack
        overflow.  Make sure to have lots of comments.
        (_cygtls::call_signal_handler): Drop local context variable to reduce
        stack pressure.  Use this->context instead.  Change inline assembler
        to call altstack_wrapper.
        (_cygtls::signal_debugger): Accommodate aforementioned change to
        struct _cygtls.
        * tlsoffset.h: Regenerate.
        * tlsoffset64.h: Regenerate.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
This commit is contained in:
Corinna Vinschen
2015-07-04 22:49:30 +02:00
parent 757c0871f7
commit 2cd7eb7f60
8 changed files with 291 additions and 134 deletions

View File

@@ -14,6 +14,7 @@ details. */
struct wincaps
{
DWORD def_guard_pages;
DWORD max_sys_priv;
unsigned is_server : 1;
unsigned has_mandatory_integrity_control : 1;
@@ -39,6 +40,7 @@ struct wincaps
unsigned terminate_thread_frees_stack : 1;
unsigned has_precise_system_time : 1;
unsigned has_microsoft_accounts : 1;
unsigned has_set_thread_stack_guarantee : 1;
};
class wincapc
@@ -64,6 +66,10 @@ public:
#define IMPLEMENT(cap) cap() const { return ((wincaps *) this->caps)->cap; }
DWORD def_guard_page_size () const
{
return ((wincaps *) this->caps)->def_guard_pages * page_size ();
}
DWORD IMPLEMENT (max_sys_priv)
bool IMPLEMENT (is_server)
bool IMPLEMENT (has_mandatory_integrity_control)
@@ -89,6 +95,7 @@ public:
bool IMPLEMENT (terminate_thread_frees_stack)
bool IMPLEMENT (has_precise_system_time)
bool IMPLEMENT (has_microsoft_accounts)
bool IMPLEMENT (has_set_thread_stack_guarantee)
#undef IMPLEMENT
};