1 | // x86_64-signal.h - Catch runtime signals and turn them into exceptions
|
---|
2 | // on an x86_64 based GNU/Linux system.
|
---|
3 |
|
---|
4 | /* Copyright (C) 2003 Free Software Foundation
|
---|
5 |
|
---|
6 | This file is part of libgcj.
|
---|
7 |
|
---|
8 | This software is copyrighted work licensed under the terms of the
|
---|
9 | Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
|
---|
10 | details. */
|
---|
11 |
|
---|
12 |
|
---|
13 | #ifndef JAVA_SIGNAL_H
|
---|
14 | #define JAVA_SIGNAL_H 1
|
---|
15 |
|
---|
16 | #include <signal.h>
|
---|
17 | #include <sys/syscall.h>
|
---|
18 |
|
---|
19 | #ifdef __x86_64__
|
---|
20 |
|
---|
21 | #define HANDLE_SEGV 1
|
---|
22 |
|
---|
23 | #define SIGNAL_HANDLER(_name) \
|
---|
24 | static void _Jv_##_name (int, siginfo_t *, void *_p)
|
---|
25 |
|
---|
26 | extern "C"
|
---|
27 | {
|
---|
28 | struct kernel_sigaction
|
---|
29 | {
|
---|
30 | void (*k_sa_sigaction)(int,siginfo_t *,void *);
|
---|
31 | unsigned long k_sa_flags;
|
---|
32 | void (*k_sa_restorer) (void);
|
---|
33 | sigset_t k_sa_mask;
|
---|
34 | };
|
---|
35 | }
|
---|
36 |
|
---|
37 | #define MAKE_THROW_FRAME(_exception) \
|
---|
38 | do \
|
---|
39 | { \
|
---|
40 | /* Advance the program counter so that it is after the start of the \
|
---|
41 | instruction: the x86_64 exception handler expects \
|
---|
42 | the PC to point to the instruction after a call. */ \
|
---|
43 | struct ucontext *_uc = (struct ucontext *)_p; \
|
---|
44 | volatile struct sigcontext *_sc = (struct sigcontext *) &_uc->uc_mcontext; \
|
---|
45 | _sc->rip += 2; \
|
---|
46 | } \
|
---|
47 | while (0)
|
---|
48 |
|
---|
49 | #define RESTORE(name, syscall) RESTORE2 (name, syscall)
|
---|
50 | #define RESTORE2(name, syscall) \
|
---|
51 | asm \
|
---|
52 | ( \
|
---|
53 | ".byte 0 # Yes, this really is necessary\n" \
|
---|
54 | ".align 16\n" \
|
---|
55 | "__" #name ":\n" \
|
---|
56 | " movq $" #syscall ", %rax\n" \
|
---|
57 | " syscall\n" \
|
---|
58 | );
|
---|
59 |
|
---|
60 | /* The return code for realtime-signals. */
|
---|
61 | RESTORE (restore_rt, __NR_rt_sigreturn)
|
---|
62 | static void restore_rt (void) asm ("__restore_rt");
|
---|
63 |
|
---|
64 | #define INIT_SEGV \
|
---|
65 | do \
|
---|
66 | { \
|
---|
67 | nullp = new java::lang::NullPointerException (); \
|
---|
68 | struct kernel_sigaction act; \
|
---|
69 | act.k_sa_sigaction = _Jv_catch_segv; \
|
---|
70 | sigemptyset (&act.k_sa_mask); \
|
---|
71 | act.k_sa_flags = SA_SIGINFO|0x4000000; \
|
---|
72 | act.k_sa_restorer = restore_rt; \
|
---|
73 | syscall (SYS_rt_sigaction, SIGSEGV, &act, NULL, _NSIG / 8); \
|
---|
74 | } \
|
---|
75 | while (0)
|
---|
76 |
|
---|
77 | /* We use syscall(SYS_rt_sigaction) in INIT_SEGV instead of
|
---|
78 | * sigaction() because on some systems the pthreads wrappers for
|
---|
79 | * signal handlers are not compiled with unwind information, so it's
|
---|
80 | * not possible to unwind through them. This is a problem that will
|
---|
81 | * go away if all systems ever have pthreads libraries that are
|
---|
82 | * compiled with unwind info. */
|
---|
83 |
|
---|
84 | #else /* __x86_64__ */
|
---|
85 |
|
---|
86 | /* This is for the 32-bit subsystem on on x86-64. Catching signals
|
---|
87 | doesn't yet work on that target. */
|
---|
88 |
|
---|
89 | #undef HANDLE_SEGV
|
---|
90 | #undef HANDLE_FPE
|
---|
91 |
|
---|
92 | #define INIT_SEGV do {} while (0)
|
---|
93 | #define INIT_FPE do {} while (0)
|
---|
94 |
|
---|
95 | #endif /* __x86_64__ */
|
---|
96 | #endif /* JAVA_SIGNAL_H */
|
---|