X-Git-Url: http://repo.macrolet.net/gitweb/?a=blobdiff_plain;f=src%2Fruntime%2Fx86-64-darwin-os.c;h=6378d7b018d918d37617158b00980c5a2a656c5a;hb=dd54f9e004a0a83d1328e94648f48dcc27e0be5b;hp=7f24fb72c3cc31d47683a3822a134d931dcd77ec;hpb=d3af5593ffff1c39a2f8fa8113704803f347e22f;p=sbcl.git diff --git a/src/runtime/x86-64-darwin-os.c b/src/runtime/x86-64-darwin-os.c index 7f24fb7..6378d7b 100644 --- a/src/runtime/x86-64-darwin-os.c +++ b/src/runtime/x86-64-darwin-os.c @@ -49,6 +49,9 @@ typedef struct __darwin_mcontext64 darwin_mcontext; #define es __es #define fs __fs +#define fpu_fcw __fpu_fcw +#define fpu_mxcsr __fpu_mxcsr + #else typedef struct ucontext darwin_ucontext; @@ -62,8 +65,6 @@ pthread_mutex_t mach_exception_lock = PTHREAD_MUTEX_INITIALIZER; #ifdef LISP_FEATURE_MACH_EXCEPTION_HANDLER -kern_return_t mach_thread_init(mach_port_t thread_exception_port); - void sigill_handler(int signal, siginfo_t *siginfo, os_context_t *context); void sigtrap_handler(int signal, siginfo_t *siginfo, os_context_t *context); void memory_fault_handler(int signal, siginfo_t *siginfo, @@ -246,8 +247,8 @@ void signal_emulation_wrapper(x86_thread_state64_t *thread_state, os_invalidate((os_vm_address_t)regs, sizeof(darwin_mcontext)); /* Trap to restore the signal context. */ - asm volatile ("mov %0, %%rax; mov %1, %%rbx; .quad 0xffffffffffff0b0f" - : : "r" (thread_state), "r" (float_state)); + asm volatile (".quad 0xffffffffffff0b0f" + : : "a" (thread_state), "b" (float_state)); } #if defined DUMP_CONTEXT @@ -301,7 +302,7 @@ catch_exception_raise(mach_port_t exception_port, exception_data_t code_vector, mach_msg_type_number_t code_count) { - kern_return_t ret; + kern_return_t ret, dealloc_ret; int signal; siginfo_t* siginfo; @@ -324,9 +325,10 @@ catch_exception_raise(mach_port_t exception_port, os_vm_address_t addr; - struct thread *th = (struct thread*) exception_port; + struct thread *th; FSHOW((stderr,"/entering catch_exception_raise with exception: %d\n", exception)); + th = *(struct thread**)exception_port; switch (exception) { @@ -345,8 +347,6 @@ catch_exception_raise(mach_port_t exception_port, (thread_state_t)&exception_state, &exception_state_count); addr = (void*)exception_state.faultvaddr; - - /* note the os_context hackery here. When the signal handler returns, * it won't go back to what it was doing ... */ if(addr >= CONTROL_STACK_GUARD_PAGE(th) && @@ -574,11 +574,32 @@ catch_exception_raise(mach_port_t exception_port, ret = KERN_INVALID_RIGHT; } - mach_port_deallocate (current_mach_task, exception_port); - mach_port_deallocate (current_mach_task, thread); - mach_port_deallocate (current_mach_task, task); + dealloc_ret = mach_port_deallocate (current_mach_task, thread); + if (dealloc_ret) { + lose("mach_port_deallocate (thread) failed with return_code %d\n", dealloc_ret); + } + + dealloc_ret = mach_port_deallocate (current_mach_task, task); + if (dealloc_ret) { + lose("mach_port_deallocate (task) failed with return_code %d\n", dealloc_ret); + } return ret; } +void +os_restore_fp_control(os_context_t *context) +{ + /* KLUDGE: The x87 FPU control word is some nasty bitfield struct + * thing. Rather than deal with that, just grab it as a 16-bit + * integer. */ + unsigned short fpu_control_word = + *((unsigned short *)&context->uc_mcontext->fs.fpu_fcw); + /* reset exception flags and restore control flags on SSE2 FPU */ + unsigned int temp = (context->uc_mcontext->fs.fpu_mxcsr) & ~0x3F; + asm ("ldmxcsr %0" : : "m" (temp)); + /* same for x87 FPU. */ + asm ("fldcw %0" : : "m" (fpu_control_word)); +} + #endif