linux: place alternate signal stack in stack area

The alternate stack must use the stack area as, e.g., Thread::myself()
depends on this property. Hybrid components do not depend on this
property and, therefore, use a static stack buffer.

Fixes #1935
This commit is contained in:
Christian Helmuth
2016-06-22 16:14:18 +02:00
parent d8c34237bf
commit d7ddc83fa9
6 changed files with 36 additions and 23 deletions

View File

@ -46,19 +46,21 @@ static Lock &startup_lock()
static void thread_exit_signal_handler(int) { lx_exit(0); }
static char signal_stack[0x2000] __attribute__((aligned(0x1000)));
void Thread::_thread_start()
{
lx_sigaltstack(signal_stack, sizeof(signal_stack));
Thread * const thread = Thread::myself();
/* use primary stack as alternate stack for fatal signals (exceptions) */
void *stack_base = (void *)thread->_stack->base();
size_t stack_size = thread->_stack->top() - thread->_stack->base();
lx_sigaltstack(stack_base, stack_size);
/*
* Set signal handler such that canceled system calls get not
* transparently retried after a signal gets received.
*/
lx_sigaction(LX_SIGUSR1, empty_signal_handler);
Thread * const thread = Thread::myself();
lx_sigaction(LX_SIGUSR1, empty_signal_handler, false);
/* inform core about the new thread and process ID of the new thread */
Linux_native_cpu_client native_cpu(thread->_cpu_session->native_cpu());
@ -141,7 +143,7 @@ void Thread::start()
*/
static bool threadlib_initialized = false;
if (!threadlib_initialized) {
lx_sigaction(LX_SIGCANCEL, thread_exit_signal_handler);
lx_sigaction(LX_SIGCANCEL, thread_exit_signal_handler, false);
threadlib_initialized = true;
}