From: Cyrus H. <sl...@us...> - 2007-02-02 19:26:27
|
Update of /cvsroot/sbcl/sbcl/src/runtime In directory sc8-pr-cvs8.sourceforge.net:/tmp/cvs-serv6589/src/runtime Modified Files: thread.c x86-darwin-os.c Log Message: 1.0.2.7: Darwin/MacOS threading improvements * use LOCK_CREATE_THREAD on MacOS/Darwin too * add new mach_exception_lock and grab this lock when handling exceptions * fix signal mask restoring logic (I think...) * restore float state in addition to thread state when done handling an emulated signal Index: thread.c =================================================================== RCS file: /cvsroot/sbcl/sbcl/src/runtime/thread.c,v retrieving revision 1.72 retrieving revision 1.73 diff -u -d -r1.72 -r1.73 --- thread.c 26 Dec 2006 23:10:24 -0000 1.72 +++ thread.c 2 Feb 2007 19:26:23 -0000 1.73 @@ -55,6 +55,7 @@ #if defined(LISP_FEATURE_DARWIN) && defined(LISP_FEATURE_SB_THREAD) #define QUEUE_FREEABLE_THREAD_STACKS +#define LOCK_CREATE_THREAD #endif #ifdef LISP_FEATURE_FREEBSD Index: x86-darwin-os.c =================================================================== RCS file: /cvsroot/sbcl/sbcl/src/runtime/x86-darwin-os.c,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- x86-darwin-os.c 26 Dec 2006 23:10:25 -0000 1.3 +++ x86-darwin-os.c 2 Feb 2007 19:26:23 -0000 1.4 @@ -28,6 +28,7 @@ #ifdef LISP_FEATURE_SB_THREAD pthread_mutex_t modify_ldt_lock = PTHREAD_MUTEX_INITIALIZER; +pthread_mutex_t mach_exception_lock = PTHREAD_MUTEX_INITIALIZER; void set_data_desc_size(data_desc_t* desc, unsigned long size) { @@ -254,7 +255,6 @@ struct ucontext *context; struct mcontext *regs; - sigset_t sigmask; context = (struct ucontext*) os_validate(0, sizeof(struct ucontext)); regs = (struct mcontext*) os_validate(0, sizeof(struct mcontext)); @@ -268,22 +268,20 @@ 3) call the signal handler 4) restore the sigmask */ - pthread_sigmask(0, NULL, &sigmask); - block_blockable_signals(); - build_fake_signal_context(context, thread_state, float_state); + block_blockable_signals(); + handler(signal, siginfo, context); update_thread_state_from_context(thread_state, float_state, context); - pthread_sigmask(SIG_SETMASK, &sigmask, NULL); - os_invalidate((os_vm_address_t)context, sizeof(struct ucontext)); os_invalidate((os_vm_address_t)regs, sizeof(struct mcontext)); /* Trap to restore the signal context. */ - asm volatile ("movl %0, %%eax; .long 0xffff0b0f": : "r" (thread_state)); + asm volatile ("movl %0, %%eax; movl %1, %%ebx; .long 0xffff0b0f" + : : "r" (thread_state), "r" (float_state)); } #if defined DUMP_CONTEXT @@ -343,6 +341,8 @@ int signal; siginfo_t* siginfo; + thread_mutex_lock(&mach_exception_lock); + x86_thread_state32_t thread_state; mach_msg_type_number_t thread_state_count = x86_THREAD_STATE32_COUNT; @@ -429,7 +429,6 @@ * exhaustion instead. */ protect_control_stack_guard_page_thread(1, th); protect_control_stack_return_guard_page_thread(0, th); - } else if (addr >= undefined_alien_address && addr < undefined_alien_address + os_vm_page_size) { @@ -499,6 +498,7 @@ x86_FLOAT_STATE32, (thread_state_t)&float_state, float_state_count); + thread_mutex_unlock(&mach_exception_lock); return KERN_SUCCESS; case EXC_BAD_INSTRUCTION: @@ -527,6 +527,12 @@ (thread_state_t) thread_state.eax, /* &thread_state, */ thread_state_count); + + ret = thread_set_state(thread, + x86_FLOAT_STATE32, + (thread_state_t) thread_state.ebx, + /* &thread_state, */ + float_state_count); } else { backup_thread_state = thread_state; @@ -581,9 +587,11 @@ (thread_state_t)&float_state, float_state_count); } + thread_mutex_unlock(&mach_exception_lock); return KERN_SUCCESS; default: + thread_mutex_unlock(&mach_exception_lock); return KERN_INVALID_RIGHT; } } |