re PR other/26208 (Serious problem with unwinding through signal frames)
[gcc.git] / libjava / include / x86_64-signal.h
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, 2006 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 #ifdef __x86_64__
14
15 #ifndef JAVA_SIGNAL_H
16 #define JAVA_SIGNAL_H 1
17
18 #include <signal.h>
19 #include <sys/syscall.h>
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
39 #define RESTORE(name, syscall) RESTORE2 (name, syscall)
40 #define RESTORE2(name, syscall) \
41 asm \
42 ( \
43 ".text\n" \
44 ".byte 0 # Yes, this really is necessary\n" \
45 ".align 16\n" \
46 "__" #name ":\n" \
47 " movq $" #syscall ", %rax\n" \
48 " syscall\n" \
49 );
50
51 /* The return code for realtime-signals. */
52 RESTORE (restore_rt, __NR_rt_sigreturn)
53 void restore_rt (void) asm ("__restore_rt")
54 __attribute__ ((visibility ("hidden")));
55
56 #define INIT_SEGV \
57 do \
58 { \
59 struct kernel_sigaction act; \
60 act.k_sa_sigaction = _Jv_catch_segv; \
61 sigemptyset (&act.k_sa_mask); \
62 act.k_sa_flags = SA_SIGINFO|0x4000000; \
63 act.k_sa_restorer = restore_rt; \
64 syscall (SYS_rt_sigaction, SIGSEGV, &act, NULL, _NSIG / 8); \
65 } \
66 while (0)
67
68 /* We use syscall(SYS_rt_sigaction) in INIT_SEGV instead of
69 * sigaction() because on some systems the pthreads wrappers for
70 * signal handlers are not compiled with unwind information, so it's
71 * not possible to unwind through them. This is a problem that will
72 * go away if all systems ever have pthreads libraries that are
73 * compiled with unwind info. */
74
75 #endif /* JAVA_SIGNAL_H */
76
77 #else /* __x86_64__ */
78
79 /* This is for the 32-bit subsystem on x86-64. */
80
81 #define sigcontext_struct sigcontext
82 #include <java-signal-aux.h>
83
84 #endif /* __x86_64__ */