Fix mysterious unremovable file part 2 ?
[cacao.git] / src / vm / jit / i386 / linux / md-os.c
index de50d8115332e588a0ebd814d09b5aa5b89b7ad1..0e7d70d7b11dad5f045a1b7903a4559f21992aee 100644 (file)
 #include "threads/thread.h"
 
 #include "vm/builtin.h"
-#include "vm/exceptions.h"
 #include "vm/signallocal.h"
 #include "vm/stringlocal.h"
 
 #include "vm/jit/asmpart.h"
+#include "vm/jit/executionstate.h"
 #include "vm/jit/stacktrace.h"
+#include "vm/jit/trap.h"
 
 
 /* md_signal_handler_sigsegv ***************************************************
@@ -103,7 +104,7 @@ void md_signal_handler_sigsegv(int sig, siginfo_t *siginfo, void *_p)
 
                val = _mc->gregs[REG_EAX - d];
 
-               if (type == EXCEPTION_HARDWARE_COMPILER) {
+               if (type == TRAP_COMPILER) {
                        /* The PV from the compiler stub is equal to the XPC. */
 
                        pv = xpc;
@@ -126,17 +127,17 @@ void md_signal_handler_sigsegv(int sig, siginfo_t *siginfo, void *_p)
        else {
                /* this was a normal NPE */
 
-               type = EXCEPTION_HARDWARE_NULLPOINTER;
+               type = TRAP_NullPointerException;
                val  = 0;
        }
 
-       /* Handle the type. */
+       /* Handle the trap. */
 
-       p = signal_handle(type, val, pv, sp, ra, xpc, _p);
+       p = trap_handle(type, val, pv, sp, ra, xpc, _p);
 
        /* Set registers. */
 
-       if (type == EXCEPTION_HARDWARE_COMPILER) {
+       if (type == TRAP_COMPILER) {
                if (p == NULL) {
                        o = builtin_retrieve_exception();
 
@@ -150,10 +151,15 @@ void md_signal_handler_sigsegv(int sig, siginfo_t *siginfo, void *_p)
                        _mc->gregs[REG_EIP] = (uintptr_t) p;
                }
        }
+#if defined(ENABLE_REPLACEMENT)
+       else if (type == TRAP_COUNTDOWN) {
+               /* context has been written by md_replace_executionstate_write */
+       }
+#endif
        else {
-               _mc->gregs[REG_EAX] = (intptr_t) p;
-               _mc->gregs[REG_ECX] = (intptr_t) xpc;                /* REG_ITMP2_XPC */
-               _mc->gregs[REG_EIP] = (intptr_t) asm_handle_exception;
+               _mc->gregs[REG_EAX] = (uintptr_t) p;
+               _mc->gregs[REG_ECX] = (uintptr_t) xpc;               /* REG_ITMP2_XPC */
+               _mc->gregs[REG_EIP] = (uintptr_t) asm_handle_exception;
        }
 }
 
@@ -185,20 +191,20 @@ void md_signal_handler_sigfpe(int sig, siginfo_t *siginfo, void *_p)
        xpc = (u1 *) _mc->gregs[REG_EIP];
        ra  = xpc;                          /* return address is equal to xpc     */
 
-       /* this is an ArithmeticException */
+       /* This is an ArithmeticException. */
 
-       type = EXCEPTION_HARDWARE_ARITHMETIC;
+       type = TRAP_ArithmeticException;
        val  = 0;
 
-       /* Handle the type. */
+       /* Handle the trap. */
 
-       p = signal_handle(type, val, pv, sp, ra, xpc, _p);
+       p = trap_handle(type, val, pv, sp, ra, xpc, _p);
 
-       /* set registers */
+       /* Set registers. */
 
-       _mc->gregs[REG_EAX] = (intptr_t) p;
-       _mc->gregs[REG_ECX] = (intptr_t) xpc;                    /* REG_ITMP2_XPC */
-       _mc->gregs[REG_EIP] = (intptr_t) asm_handle_exception;
+       _mc->gregs[REG_EAX] = (uintptr_t) p;
+       _mc->gregs[REG_ECX] = (uintptr_t) xpc;                   /* REG_ITMP2_XPC */
+       _mc->gregs[REG_EIP] = (uintptr_t) asm_handle_exception;
 }
 
 
@@ -228,21 +234,19 @@ void md_signal_handler_sigill(int sig, siginfo_t *siginfo, void *_p)
        xpc = (u1 *) _mc->gregs[REG_EIP];
        ra  = xpc;                            /* return address is equal to xpc   */
 
-       /* this is an ArithmeticException */
-
-       type = EXCEPTION_HARDWARE_PATCHER;
+       type = TRAP_PATCHER;
        val  = 0;
 
-       /* generate appropriate exception */
+       /* Handle the trap. */
 
-       p = signal_handle(type, val, pv, sp, ra, xpc, _p);
+       p = trap_handle(type, val, pv, sp, ra, xpc, _p);
 
-       /* set registers (only if exception object ready) */
+       /* Set registers. */
 
        if (p != NULL) {
-               _mc->gregs[REG_EAX] = (ptrint) p;
-               _mc->gregs[REG_ECX] = (ptrint) xpc;                      /* REG_ITMP2_XPC */
-               _mc->gregs[REG_EIP] = (ptrint) asm_handle_exception;
+               _mc->gregs[REG_EAX] = (uintptr_t) p;
+               _mc->gregs[REG_ECX] = (uintptr_t) xpc;               /* REG_ITMP2_XPC */
+               _mc->gregs[REG_EIP] = (uintptr_t) asm_handle_exception;
        }
 }
 
@@ -300,14 +304,13 @@ void md_signal_handler_sigusr2(int sig, siginfo_t *siginfo, void *_p)
 #endif
 
 
-/* md_replace_executionstate_read **********************************************
+/* md_executionstate_read ******************************************************
 
    Read the given context into an executionstate for Replacement.
 
 *******************************************************************************/
 
-#if defined(ENABLE_REPLACEMENT)
-void md_replace_executionstate_read(executionstate_t *es, void *context)
+void md_executionstate_read(executionstate_t *es, void *context)
 {
        ucontext_t *_uc;
        mcontext_t *_mc;
@@ -329,17 +332,15 @@ void md_replace_executionstate_read(executionstate_t *es, void *context)
        for (i = 0; i < FLT_REG_CNT; i++)
                es->fltregs[i] = 0xdeadbeefdeadbeefULL;
 }
-#endif
 
 
-/* md_replace_executionstate_write *********************************************
+/* md_executionstate_write *****************************************************
 
    Write the given executionstate back to the context for Replacement.
 
 *******************************************************************************/
 
-#if defined(ENABLE_REPLACEMENT)
-void md_replace_executionstate_write(executionstate_t *es, void *context)
+void md_executionstate_write(executionstate_t *es, void *context)
 {
        ucontext_t *_uc;
        mcontext_t *_mc;
@@ -356,7 +357,6 @@ void md_replace_executionstate_write(executionstate_t *es, void *context)
        _mc->gregs[REG_EIP] = (ptrint) es->pc;
        _mc->gregs[REG_ESP] = (ptrint) es->sp;
 }
-#endif
 
 
 /* md_critical_section_restart *************************************************