workaround for broken OSX ucontext

This commit is contained in:
David Rose 2009-05-09 00:47:45 +00:00
parent b40450ccb2
commit d001c75524
2 changed files with 18 additions and 2 deletions

View File

@ -15,6 +15,7 @@
#include "contextSwitch.h"
#include <stdlib.h>
#include <stdio.h>
#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. */

View File

@ -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 */