]> gitweb.factorcode.org Git - factor.git/commitdiff
put mach call_fault_handler in the vm
authorPhil Dawes <phil@phildawes.net>
Mon, 14 Sep 2009 07:00:28 +0000 (08:00 +0100)
committerPhil Dawes <phil@phildawes.net>
Wed, 16 Sep 2009 07:22:18 +0000 (08:22 +0100)
vm/mach_signal.cpp
vm/vm.hpp

index 03a6ca2b7247d60af6e1b91cd595b8a6117a33e0..08b0d00f1cf031e8a13d965fa0e03439f90e1f91 100644 (file)
@@ -28,7 +28,7 @@ http://www.wodeveloper.com/omniLists/macosx-dev/2000/June/msg00137.html */
 /* Modify a suspended thread's thread_state so that when the thread resumes
 executing, the call frame of the current C primitive (if any) is rewound, and
 the appropriate Factor error is thrown from the top-most Factor frame. */
-static void call_fault_handler(
+void factorvm::call_fault_handler(
     exception_type_t exception,
     exception_data_type_t code,
        MACH_EXC_STATE_TYPE *exc_state,
@@ -41,33 +41,42 @@ static void call_fault_handler(
        a divide by zero or stack underflow in the listener */
 
        /* Are we in compiled Factor code? Then use the current stack pointer */
-       if(SIGNAL_VM_PTR()->in_code_heap_p(MACH_PROGRAM_COUNTER(thread_state)))
-               SIGNAL_VM_PTR()->signal_callstack_top = (stack_frame *)MACH_STACK_POINTER(thread_state);
+       if(in_code_heap_p(MACH_PROGRAM_COUNTER(thread_state)))
+               signal_callstack_top = (stack_frame *)MACH_STACK_POINTER(thread_state);
        /* Are we in C? Then use the saved callstack top */
        else
-               SIGNAL_VM_PTR()->signal_callstack_top = NULL;
+               signal_callstack_top = NULL;
 
        MACH_STACK_POINTER(thread_state) = fix_stack_pointer(MACH_STACK_POINTER(thread_state));
 
        /* Now we point the program counter at the right handler function. */
        if(exception == EXC_BAD_ACCESS)
        {
-               SIGNAL_VM_PTR()->signal_fault_addr = MACH_EXC_STATE_FAULT(exc_state);
-               MACH_PROGRAM_COUNTER(thread_state) = (cell)memory_signal_handler_impl;
+               signal_fault_addr = MACH_EXC_STATE_FAULT(exc_state);
+               MACH_PROGRAM_COUNTER(thread_state) = (cell)factor::memory_signal_handler_impl;
        }
        else if(exception == EXC_ARITHMETIC && code != MACH_EXC_INTEGER_DIV)
        {
-                signal_fpu_status = fpu_status(mach_fpu_status(float_state));
-                mach_clear_fpu_status(float_state);
-               MACH_PROGRAM_COUNTER(thread_state) = (cell)fp_signal_handler_impl;
+               signal_fpu_status = fpu_status(mach_fpu_status(float_state));
+               mach_clear_fpu_status(float_state);
+               MACH_PROGRAM_COUNTER(thread_state) = (cell)factor::fp_signal_handler_impl;
        }
        else
        {
-               SIGNAL_VM_PTR()->signal_number = (exception == EXC_ARITHMETIC ? SIGFPE : SIGABRT);
-               MACH_PROGRAM_COUNTER(thread_state) = (cell)misc_signal_handler_impl;
+               signal_number = (exception == EXC_ARITHMETIC ? SIGFPE : SIGABRT);
+               MACH_PROGRAM_COUNTER(thread_state) = (cell)factor::misc_signal_handler_impl;
        }
 }
 
+static void call_fault_handler(exception_type_t exception,
+                                                          exception_data_type_t code,
+                                                          MACH_EXC_STATE_TYPE *exc_state,
+                                                          MACH_THREAD_STATE_TYPE *thread_state,
+                                                          MACH_FLOAT_STATE_TYPE *float_state)
+{
+       SIGNAL_VM_PTR()->call_fault_handler(exception,code,exc_state,thread_state,float_state);
+}
+
 /* Handle an exception by invoking the user's fault handler and/or forwarding
 the duty to the previously installed handlers.  */
 extern "C"
index b426ff67d8f1c64ac2c4bcc8baae5ea9311b5178..76a2adb9c6197589721878b632e93b2d56ec7ac1 100644 (file)
--- a/vm/vm.hpp
+++ b/vm/vm.hpp
@@ -607,6 +607,10 @@ struct factorvm : factorvmdata {
 
   #endif
 
+  #ifdef __APPLE__
+       void call_fault_handler(exception_type_t exception, exception_data_type_t code, MACH_EXC_STATE_TYPE *exc_state, MACH_THREAD_STATE_TYPE *thread_state, MACH_FLOAT_STATE_TYPE *float_state);
+  #endif
+       
        void print_vm_data();
 };