diff --git a/panda/src/pipeline/contextSwitch.c b/panda/src/pipeline/contextSwitch.c index 0de3b59a93..ba9f3042b2 100644 --- a/panda/src/pipeline/contextSwitch.c +++ b/panda/src/pipeline/contextSwitch.c @@ -15,6 +15,7 @@ #include "contextSwitch.h" #include +#include #ifdef THREAD_SIMPLE_IMPL @@ -31,7 +32,11 @@ void init_thread_context(struct ThreadContext *context, unsigned char *stack, size_t stack_size, ContextFunction *thread_func, void *data) { - getcontext(&context->_ucontext); + if (getcontext(&context->_ucontext) != 0) { + fprintf(stderr, "getcontext failed in init_thread_context!\n"); + // Too bad for you. + abort(); + } context->_ucontext.uc_stack.ss_sp = stack; context->_ucontext.uc_stack.ss_size = stack_size; @@ -49,7 +54,12 @@ save_thread_context(struct ThreadContext *context, (return from setcontext). */ volatile int context_return = 0; - getcontext(&context->_ucontext); + if (getcontext(&context->_ucontext) != 0) { + fprintf(stderr, "getcontext failed!\n"); + // Nothing to do here. + abort(); + } + if (context_return) { /* We have just returned from setcontext. In this case, return from the function. The stack is still good. */ diff --git a/panda/src/pipeline/contextSwitch.h b/panda/src/pipeline/contextSwitch.h index 2accef1461..23903c5360 100644 --- a/panda/src/pipeline/contextSwitch.h +++ b/panda/src/pipeline/contextSwitch.h @@ -38,6 +38,12 @@ struct ThreadContext { ucontext_t _ucontext; +#if defined(__APPLE__) + // Due to a bug in OSX 10.5, the system ucontext_t declaration + // doesn't reserve enough space, and we need to reserve some + // additional space to make room. + _STRUCT_MCONTEXT _extra_padding; +#endif }; #else /* HAVE_UCONTEXT_H */