* Removed all Id tags.
[cacao.git] / src / vm / jit / x86_64 / linux / md-os.c
index c8ec58b42ea59aa505851de338839cb9ff30be89..84ad05b1367091e7c0a1d5fa9f1b0cb9f258600d 100644 (file)
@@ -22,8 +22,6 @@
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
    02110-1301, USA.
 
-   $Id: md.c 7249 2007-01-29 19:32:52Z twisti $
-
 */
 
 
@@ -32,6 +30,7 @@
 #include "config.h"
 
 #include <assert.h>
+#include <stdint.h>
 #include <stdlib.h>
 #include <ucontext.h>
 
 
 void md_signal_handler_sigsegv(int sig, siginfo_t *siginfo, void *_p)
 {
-       ucontext_t        *_uc;
-       mcontext_t        *_mc;
-       u1                *sp;
-       u1                *ra;
-       u1                *xpc;
-       u1                 opc;
-       u1                 mod;
-       u1                 rm;
-       s4                 d;
-       s4                 disp;
-       ptrint             val;
-       s4                 type;
-       java_objectheader *o;
+       stackframeinfo  sfi;
+       ucontext_t     *_uc;
+       mcontext_t     *_mc;
+       u1             *sp;
+       u1             *ra;
+       u1             *xpc;
+       u1              opc;
+       u1              mod;
+       u1              rm;
+       s4              d;
+       s4              disp;
+       int             type;
+       intptr_t        val;
+       void           *p;
 
        _uc = (ucontext_t *) _p;
        _mc = &_uc->uc_mcontext;
@@ -155,17 +155,26 @@ void md_signal_handler_sigsegv(int sig, siginfo_t *siginfo, void *_p)
                /* this was a normal NPE */
 
                type = EXCEPTION_HARDWARE_NULLPOINTER;
+               val  = 0;
        }
 
-       /* generate appropriate exception */
+       /* create stackframeinfo */
+
+       stacktrace_create_extern_stackframeinfo(&sfi, NULL, sp, ra, xpc);
+
+       /* Handle the type. */
 
-       o = exceptions_new_hardware_exception(NULL, sp, ra, xpc, type, val);
+       p = signal_handle(xpc, type, val);
+
+       /* remove stackframeinfo */
+
+       stacktrace_remove_stackframeinfo(&sfi);
 
        /* set registers */
 
-       _mc->gregs[REG_RAX] = (ptrint) o;
-       _mc->gregs[REG_R10] = (ptrint) xpc;                      /* REG_ITMP2_XPC */
-       _mc->gregs[REG_RIP] = (ptrint) asm_handle_exception;
+       _mc->gregs[REG_RAX] = (intptr_t) p;
+       _mc->gregs[REG_R10] = (intptr_t) xpc;                    /* REG_ITMP2_XPC */
+       _mc->gregs[REG_RIP] = (intptr_t) asm_handle_exception;
 }
 
 
@@ -178,11 +187,16 @@ void md_signal_handler_sigsegv(int sig, siginfo_t *siginfo, void *_p)
 
 void md_signal_handler_sigfpe(int sig, siginfo_t *siginfo, void *_p)
 {
-       ucontext_t  *_uc;
-       mcontext_t  *_mc;
-       u1          *sp;
-       u1          *ra;
-       u1          *xpc;
+       stackframeinfo  sfi;
+       ucontext_t     *_uc;
+       mcontext_t     *_mc;
+       u1             *pv;
+       u1             *sp;
+       u1             *ra;
+       u1             *xpc;
+       int             type;
+       intptr_t        val;
+       void           *p;
 
        _uc = (ucontext_t *) _p;
        _mc = &_uc->uc_mcontext;
@@ -190,15 +204,33 @@ void md_signal_handler_sigfpe(int sig, siginfo_t *siginfo, void *_p)
        /* ATTENTION: Don't use CACAO's internal REG_* defines as they are
           different to the ones in <ucontext.h>. */
 
+       pv  = NULL;
        sp  = (u1 *) _mc->gregs[REG_RSP];
        xpc = (u1 *) _mc->gregs[REG_RIP];
        ra  = xpc;                          /* return address is equal to xpc     */
 
-       _mc->gregs[REG_RAX] =
-               (ptrint) stacktrace_hardware_arithmeticexception(NULL, sp, ra, xpc);
+       /* this is an ArithmeticException */
+
+       type = EXCEPTION_HARDWARE_ARITHMETIC;
+       val  = 0;
+
+       /* create stackframeinfo */
+
+       stacktrace_create_extern_stackframeinfo(&sfi, pv, sp, ra, xpc);
+
+       /* Handle the type. */
+
+       p = signal_handle(xpc, type, val);
+
+       /* remove stackframeinfo */
 
-       _mc->gregs[REG_R10] = (ptrint) xpc;                      /* REG_ITMP2_XPC */
-       _mc->gregs[REG_RIP] = (ptrint) asm_handle_exception;
+       stacktrace_remove_stackframeinfo(&sfi);
+
+       /* set registers */
+
+       _mc->gregs[REG_RAX] = (intptr_t) p;
+       _mc->gregs[REG_R10] = (intptr_t) xpc;                    /* REG_ITMP2_XPC */
+       _mc->gregs[REG_RIP] = (intptr_t) asm_handle_exception;
 }
 
 
@@ -231,21 +263,31 @@ void md_signal_handler_sigusr2(int sig, siginfo_t *siginfo, void *_p)
 #endif
 
 
+/* md_critical_section_restart *************************************************
+
+   Search the critical sections tree for a matching section and set
+   the PC to the restart point, if necessary.
+
+*******************************************************************************/
+
 #if defined(ENABLE_THREADS)
-void thread_restartcriticalsection(ucontext_t *_uc)
+void md_critical_section_restart(ucontext_t *_uc)
 {
        mcontext_t *_mc;
        u1         *pc;
-       void       *critical;
+       u1         *npc;
 
        _mc = &_uc->uc_mcontext;
 
+       /* ATTENTION: Don't use CACAO's internal REG_* defines as they are
+          different to the ones in <ucontext.h>. */
+
        pc = (u1 *) _mc->gregs[REG_RIP];
 
-       critical = critical_find_restart_point(pc);
+       npc = critical_find_restart_point(pc);
 
-       if (critical != NULL)
-               _mc->gregs[REG_RIP] = (ptrint) critical;
+       if (npc != NULL)
+               _mc->gregs[REG_RIP] = (ptrint) npc;
 }
 #endif