Copyright (C) 1996-2005, 2006, 2007, 2008
CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
- Copyright (C) 2008 Theobroma Systems Ltd.
+ Copyright (C) 2008, 2009 Theobroma Systems Ltd.
This file is part of CACAO.
#include "threads/thread.hpp"
-#include "vm/os.hpp"
-#include "vm/signallocal.h"
-#include "vm/vm.hpp"
+#include "vm/signallocal.hpp"
#include "vm/jit/asmpart.h"
-#include "vm/jit/disass.h"
#include "vm/jit/executionstate.h"
-#include "vm/jit/patcher-common.hpp"
-#include "vm/jit/trap.h"
+#include "vm/jit/trap.hpp"
-/* md_signal_handler_sigsegv ***************************************************
-
- Signal handler for hardware exceptions.
-
-*******************************************************************************/
-
+/**
+ * Signal handler for hardware exceptions.
+ */
void md_signal_handler_sigsegv(int sig, siginfo_t *siginfo, void *_p)
{
- ucontext_t *_uc;
- scontext_t *_sc;
- u1 *pv;
- u1 *sp;
- u1 *ra;
- u1 *xpc;
- u4 mcode;
- intptr_t addr;
- int type;
- intptr_t val;
-
- _uc = (ucontext_t*) _p;
- _sc = &_uc->uc_mcontext;
+ ucontext_t* _uc = (ucontext_t*) _p;
+ scontext_t* _sc = &_uc->uc_mcontext;
/* ATTENTION: glibc included messed up kernel headers we needed a
workaround for the ucontext structure. */
- pv = (u1 *) _sc->arm_ip;
- sp = (u1 *) _sc->arm_sp;
- ra = (u1 *) _sc->arm_lr; /* this is correct for leafs */
- xpc = (u1 *) _sc->arm_pc;
-
- /* get exception-throwing instruction */
+ void* xpc = (u1 *) _sc->arm_pc;
- if (xpc == NULL)
- vm_abort("md_signal_handler_sigsegv: the program counter is NULL");
-
- mcode = *((s4 *) xpc);
-
- /* This is a NullPointerException. */
-
- addr = *((s4 *) _sc + OFFSET(scontext_t, arm_r0)/4 + ((mcode >> 16) & 0x0f));
- type = addr;
- val = 0;
-
- /* Handle the trap. */
-
- trap_handle(type, val, pv, sp, ra, xpc, _p);
+ // Handle the trap.
+ trap_handle(TRAP_SIGSEGV, xpc, _p);
}
-/* md_signal_handler_sigill ****************************************************
-
- Illegal Instruction signal handler for hardware exception checks.
-
-*******************************************************************************/
-
+/**
+ * Illegal instruction signal handler for hardware exception checks.
+ */
void md_signal_handler_sigill(int sig, siginfo_t *siginfo, void *_p)
{
ucontext_t* _uc = (ucontext_t*) _p;
/* ATTENTION: glibc included messed up kernel headers we needed a
workaround for the ucontext structure. */
- void* pv = (void*) _sc->arm_ip;
- void* sp = (void*) _sc->arm_sp;
- void* ra = (void*) _sc->arm_lr; // The RA is correct for leaf methods.
void* xpc = (void*) _sc->arm_pc;
- // Get the exception-throwing instruction.
- uint32_t mcode = *((uint32_t*) xpc);
-
- // Check if the trap instruction is valid.
- // TODO Move this into patcher_handler.
- if (patcher_is_valid_trap_instruction_at(xpc) == false) {
- // Check if the PC has been patched during our way to this
- // signal handler (see PR85).
- // NOTE: ARM uses SIGILL for other traps too, but it's OK to
- // do this check anyway because it will fail.
- if (patcher_is_patched_at(xpc) == true)
- return;
-
- // We have a problem...
- log_println("md_signal_handler_sigill: Unknown illegal instruction 0x%x at 0x%x", mcode, xpc);
-#if defined(ENABLE_DISASSEMBLER)
- (void) disassinstr(xpc);
-#endif
- vm_abort("Aborting...");
- }
-
- int type = (mcode >> 8) & 0x0fff;
- intptr_t val = *((int32_t*) _sc + OFFSET(scontext_t, arm_r0)/4 + (mcode & 0x0f));
-
- if (type == TRAP_COMPILER) {
- /* The XPC is the RA minus 4, because the RA points to the
- instruction after the call. */
-
- xpc = (void*) (((uintptr_t) ra) - 4);
- }
-
// Handle the trap.
- trap_handle(type, val, pv, sp, ra, xpc, _p);
-}
-
-
-/* md_signal_handler_sigusr1 ***************************************************
-
- Signal handler for suspending threads.
-
-*******************************************************************************/
-
-#if defined(ENABLE_THREADS) && defined(ENABLE_GC_CACAO)
-void md_signal_handler_sigusr1(int sig, siginfo_t *siginfo, void *_p)
-{
- ucontext_t *_uc;
- scontext_t *_sc;
- u1 *pc;
- u1 *sp;
-
- _uc = (ucontext_t *) _p;
- _sc = &_uc->uc_mcontext;
-
- /* get the PC and SP for this thread */
- pc = (u1 *) _sc->arm_pc;
- sp = (u1 *) _sc->arm_sp;
-
- /* now suspend the current thread */
- threads_suspend_ack(pc, sp);
+ trap_handle(TRAP_SIGILL, xpc, _p);
}
-#endif
/* md_signal_handler_sigusr2 ***************************************************