CACAO
md-os.cpp
Go to the documentation of this file.
1 /* src/vm/jit/alpha/freebsd/md-os.cpp - machine dependent Alpha FreeBSD functions
2 
3  Copyright (C) 1996-2013
4  CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
5 
6  This file is part of CACAO.
7 
8  This program is free software; you can redistribute it and/or
9  modify it under the terms of the GNU General Public License as
10  published by the Free Software Foundation; either version 2, or (at
11  your option) any later version.
12 
13  This program is distributed in the hope that it will be useful, but
14  WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  General Public License for more details.
17 
18  You should have received a copy of the GNU General Public License
19  along with this program; if not, write to the Free Software
20  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21  02110-1301, USA.
22 
23 */
24 
25 
26 #include "config.h"
27 
28 #include <cassert>
29 #include <ucontext.h>
30 #include <sys/types.h> /* required by <machine/reg.h> */
31 #include <machine/reg.h>
32 
33 #include "vm/types.hpp"
34 
35 #include "vm/jit/alpha/md-abi.hpp"
36 
37 #include "vm/global.hpp"
38 #include "vm/signallocal.hpp"
39 #include "vm/jit/asmpart.hpp"
40 
41 
42 /* md_signal_handler_sigsegv ***************************************************
43 
44  NullPointerException signal handler for hardware null pointer
45  check.
46 
47 *******************************************************************************/
48 
49 void md_signal_handler_sigsegv(int sig, siginfo_t *siginfo, void *_p)
50 {
51  ucontext_t *_uc;
52  mcontext_t *_mc;
53  u4 instr;
54  ptrint addr;
55  u1 *pv;
56  u1 *sp;
57  u1 *ra;
58  u1 *xpc;
59 
60  _uc = (ucontext_t *) _p;
61  _mc = &_uc->uc_mcontext;
62 
63  instr = *((s4 *) (_mc->mc_regs[R_PC]));
64  addr = _mc->mc_regs[(instr >> 16) & 0x1f];
65 
66  if (addr == 0) {
67  pv = (u1 *) _mc->mc_regs[REG_PV];
68  sp = (u1 *) _mc->mc_regs[REG_SP];
69  ra = (u1 *) _mc->mc_regs[REG_RA]; /* this is correct for leafs */
70  xpc = (u1 *) _mc->mc_regs[R_PC];
71 
72  _mc->mc_regs[REG_ITMP1_XPTR] =
73  (ptrint) stacktrace_hardware_nullpointerexception(pv, sp, ra, xpc);
74 
75  _mc->mc_regs[REG_ITMP2_XPC] = (ptrint) xpc;
76  _mc->mc_regs[R_PC] = (ptrint) asm_handle_exception;
77 
78  } else {
79  addr += (long) ((instr << 16) >> 16);
80 
81  throw_cacao_exception_exit(string_java_lang_InternalError,
82  "Segmentation fault: 0x%016lx at 0x%016lx\n",
83  addr, _mc->mc_regs[R_PC]);
84  }
85 }
86 
87 
88 /*
89  * These are local overrides for various environment variables in Emacs.
90  * Please do not remove this and leave it at the end of the file, where
91  * Emacs will automagically detect them.
92  * ---------------------------------------------------------------------
93  * Local variables:
94  * mode: c++
95  * indent-tabs-mode: t
96  * c-basic-offset: 4
97  * tab-width: 4
98  * End:
99  */
#define REG_SP
Definition: md-abi.hpp:53
#define pv
Definition: md-asm.hpp:65
#define REG_PV
Definition: md-abi.hpp:42
#define ra
Definition: md-asm.hpp:62
void md_signal_handler_sigsegv(int sig, siginfo_t *siginfo, void *_p)
NullPointerException signal handler for hardware null pointer check.
Definition: md-os.cpp:50
const char * string_java_lang_InternalError
struct sigcontext uc_mcontext
Definition: md-os.cpp:42
#define REG_ITMP1_XPTR
Definition: md-abi.hpp:50
uint8_t u1
Definition: types.hpp:40
#define REG_ITMP2_XPC
Definition: md-abi.hpp:51
#define xpc
Definition: md-asm.hpp:51
int32_t s4
Definition: types.hpp:45
#define REG_RA
Definition: md-abi.hpp:41
void asm_handle_exception(void)
uint32_t u4
Definition: types.hpp:46
CONTEXT mcontext_t
Definition: ucontext.h:27
#define sp
Definition: md-asm.hpp:81
uintptr_t ptrint
Definition: types.hpp:54