OSDN Git Service

* gnu/java/net/natPlainDatagramSocketImplWin32.cc:
[pf3gnuchains/gcc-fork.git] / libjava / include / mips-signal.h
1 // mips-signal.h - Catch runtime signals and turn them into exceptions
2 // on an mips based Linux system. 
3
4 /* Copyright (C) 1998, 1999, 2001, 2002, 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 /* Adapted from sparc-signal.h and powerpc-signal.h
13    by David Daney <ddaney@avtrex.com> */
14
15 #ifndef JAVA_SIGNAL_H
16 #define JAVA_SIGNAL_H 1
17
18 #include <signal.h>
19 #include <unistd.h>
20 #include <sys/syscall.h>
21 /* #include <asm/ucontext.h> structures we use are here but clash with
22    sys/ucontext.h included by java-signal.h from prims.cc */
23
24 #define HANDLE_SEGV 1
25 #undef HANDLE_FPE
26
27 /* The third parameter to the signal handler points to something with
28  * this structure defined in asm/ucontext.h, but the name clashes with
29  * struct ucontext from sys/ucontext.h so this private copy is used. */
30 typedef struct _sig_ucontext {
31     unsigned long         uc_flags;
32     struct _sig_ucontext  *uc_link;
33     stack_t               uc_stack;
34     struct sigcontext uc_mcontext;
35     sigset_t      uc_sigmask;
36 } sig_ucontext_t;
37
38 /* We use kernel_sigaction here because we're calling the kernel
39    directly rather than via glibc. The sigaction structure that the
40    syscall uses is a different shape from the one in userland and not
41    visible to us in a header file so we define it here.
42    Additionally we want a proper prototype for the handler function
43    with the struct sigcontext pointer passed by the kernel as the 2nd
44    argument, which isn't there in userland headers. */
45
46 struct kernel_sigaction {
47     unsigned int k_sa_flags;
48     void       (*k_sa_handler) (int, siginfo_t *, sig_ucontext_t *);
49     sigset_t     k_sa_mask;
50     void       (*k_sa_restorer)(void);
51     int          k_sa_resv[1];  /* reserved */
52 };
53
54
55
56 #define SIGNAL_HANDLER(_name) \
57 static void _name (int _dummy, siginfo_t *_info, sig_ucontext_t *_arg)
58
59 /*
60  *  MIPS leaves pc pointing at the faulting instruction, but the
61  *  unwinder expects it to point to the following instruction
62  */
63
64 #define MAKE_THROW_FRAME(_exception) \
65 do                                   \
66 {                                    \
67   _arg->uc_mcontext.sc_pc += 4;      \
68   (void)_dummy;                      \
69   (void)_info;                       \
70 }                                    \
71 while (0)
72
73 /* For an explanation why we cannot simply use sigaction to
74    install the handlers, see i386-signal.h.  */
75
76 #define INIT_SEGV                                    \
77 do                                                   \
78   {                                                  \
79     struct kernel_sigaction kact;                    \
80     kact.k_sa_handler = catch_segv;                  \
81     kact.k_sa_flags = SA_SIGINFO | SA_NODEFER;       \
82     sigemptyset (&kact.k_sa_mask);                   \
83     syscall (SYS_sigaction, SIGSEGV, &kact, NULL);   \
84   }                                                  \
85 while (0)
86                                                                 
87
88 #endif /* JAVA_SIGNAL_H */
89