* src/vm/jit/arm/linux/md-os.c (md_signal_handler_sigsegv): Use
[cacao.git] / src / vm / jit / arm / linux / md-os.c
1 /* src/vm/jit/arm/linux/md.c - machine dependent arm linux functions
2
3    Copyright (C) 1996-2005, 2006 R. Grafl, A. Krall, C. Kruegel,
4    C. Oates, R. Obermaisser, M. Platter, M. Probst, S. Ring,
5    E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich,
6    J. Wenninger, Institut f. Computersprachen - TU Wien
7
8    This file is part of CACAO.
9
10    This program is free software; you can redistribute it and/or
11    modify it under the terms of the GNU General Public License as
12    published by the Free Software Foundation; either version 2, or (at
13    your option) any later version.
14
15    This program is distributed in the hope that it will be useful, but
16    WITHOUT ANY WARRANTY; without even the implied warranty of
17    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18    General Public License for more details.
19
20    You should have received a copy of the GNU General Public License
21    along with this program; if not, write to the Free Software
22    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
23    02110-1301, USA.
24
25    Contact: cacao@cacaojvm.org
26
27    Authors: Michael Starzinger
28             Christian Thalinger
29
30    $Id: md.c 166 2006-01-22 23:38:44Z twisti $
31
32 */
33
34
35 #include "config.h"
36
37 #include <assert.h>
38
39 #include "vm/types.h"
40
41 #include "vm/jit/arm/md-abi.h"
42
43 #define ucontext broken_glibc_ucontext
44 #define ucontext_t broken_glibc_ucontext_t
45 #include <ucontext.h>
46 #undef ucontext
47 #undef ucontext_t
48
49 typedef struct ucontext {
50    unsigned long     uc_flags;
51    struct ucontext  *uc_link;
52    stack_t           uc_stack;
53    struct sigcontext uc_mcontext;
54    sigset_t          uc_sigmask;
55 } ucontext_t;
56
57 #define scontext_t struct sigcontext
58
59 #include "mm/memory.h"
60 #include "vm/exceptions.h"
61 #include "vm/signallocal.h"
62 #include "vm/stringlocal.h"
63 #include "vm/jit/asmpart.h"
64 #include "vm/jit/stacktrace.h"
65
66
67 /* md_signal_handler_sigsegv ***************************************************
68
69    NullPointerException signal handler for hardware null pointer
70    check.
71
72 *******************************************************************************/
73
74 void md_signal_handler_sigsegv(int sig, siginfo_t *siginfo, void *_p)
75 {
76         ucontext_t *_uc;
77         /*mcontext_t *_mc;*/
78         scontext_t *_sc;
79         u4          instr;
80         ptrint      addr;
81         ptrint      base;
82         u1          *pv;
83         u1          *sp;
84         u1          *ra;
85         u1          *xpc;
86
87         _uc = (ucontext_t*) _p;
88         _sc = &_uc->uc_mcontext;
89
90         /* ATTENTION: glibc included messed up kernel headers */
91         /* we needed a workaround for the ucontext structure */
92
93         addr = (ptrint) siginfo->si_addr;
94         /*xpc = (u1*) _mc->gregs[REG_PC];*/
95         xpc = (u1*) _sc->arm_pc;
96
97         instr = *((s4*) xpc);
98         base = *((s4*) _sc + OFFSET(scontext_t, arm_r0)/4 + ((instr >> 16) & 0x0f));
99
100         if (base == 0) {
101                 pv  = (u1*) _sc->arm_ip;
102                 sp  = (u1*) _sc->arm_sp;
103                 ra  = (u1*) _sc->arm_lr; /* this is correct for leafs */
104
105                 _sc->arm_r10 = (ptrint) stacktrace_hardware_nullpointerexception(pv, sp, ra, xpc);
106                 _sc->arm_fp = (ptrint) xpc;
107                 _sc->arm_pc = (ptrint) asm_handle_exception;
108         }
109         else {
110                 codegen_get_pv_from_pc(xpc);
111
112                 /* this should not happen */
113
114                 assert(0);
115         }
116 }
117
118
119 /* thread_restartcriticalsection ***********************************************
120
121    TODO: document me
122
123 *******************************************************************************/
124
125 #if defined(ENABLE_THREADS)
126 void thread_restartcriticalsection(ucontext_t *_uc)
127 {
128         scontext_t *_sc;
129         void       *critical;
130
131         _sc = &_uc->uc_mcontext;
132
133         critical = critical_find_restart_point((void *) _sc->arm_pc);
134
135         if (critical)
136                 _sc->arm_pc = (ptrint) critical;
137 }
138 #endif
139
140
141 /*
142  * These are local overrides for various environment variables in Emacs.
143  * Please do not remove this and leave it at the end of the file, where
144  * Emacs will automagically detect them.
145  * ---------------------------------------------------------------------
146  * Local variables:
147  * mode: c
148  * indent-tabs-mode: t
149  * c-basic-offset: 4
150  * tab-width: 4
151  * End:
152  */
153