OSDN Git Service

e2da4f87c5f6cb85e769e8ddeb84ad46663d481a
[uclinux-h8/uClibc.git] / libc / sysdeps / linux / arm / sigaction.c
1 /* Copyright (C) 1997,1998,1999,2000,2002,2003 Free Software Foundation, Inc.
2    This file is part of the GNU C Library.
3
4    The GNU C Library is free software; you can redistribute it and/or
5    modify it under the terms of the GNU Lesser General Public
6    License as published by the Free Software Foundation; either
7    version 2.1 of the License, or (at your option) any later version.
8
9    The GNU C Library is distributed in the hope that it will be useful,
10    but WITHOUT ANY WARRANTY; without even the implied warranty of
11    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12    Lesser General Public License for more details.
13
14    You should have received a copy of the GNU Lesser General Public
15    License along with the GNU C Library; if not, write to the Free
16    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
17    02111-1307 USA.
18
19    Totally hacked up for uClibc by Erik Andersen <andersen@codepoet.org>
20    */
21
22 #include <errno.h>
23 #include <signal.h>
24 #include <string.h>
25 #include <sys/syscall.h>
26 #include <bits/kernel_sigaction.h>
27
28 #define SA_RESTORER     0x04000000
29 extern void __default_sa_restorer(void);
30 extern void __default_rt_sa_restorer(void);
31
32 /* When RT signals are in use we need to use a different return stub.  */
33 #ifdef __NR_rt_sigreturn
34 #define choose_restorer(flags)                                  \
35   (flags & SA_SIGINFO) ? __default_rt_sa_restorer               \
36   : __default_sa_restorer
37 #else
38 #define choose_restorer(flags)                                  \
39   __default_sa_restorer
40 #endif
41
42
43
44 #ifdef __NR_rt_sigaction
45
46
47 /* If ACT is not NULL, change the action for SIG to *ACT.
48    If OACT is not NULL, put the old action for SIG in *OACT.  */
49 int attribute_hidden __sigaction_internal (int sig, const struct sigaction *act, struct sigaction *oact)
50 {
51     int result;
52     struct kernel_sigaction kact, koact;
53
54     if (act) {
55         kact.k_sa_handler = act->sa_handler;
56         __memcpy (&kact.sa_mask, &act->sa_mask, sizeof (sigset_t));
57         kact.sa_flags = act->sa_flags;
58 # ifdef HAVE_SA_RESTORER
59         /* If the user specified SA_ONSTACK this means she is trying to
60            use the old-style stack switching.  Unfortunately this
61            requires the sa_restorer field so we cannot install our own
62            handler.  (In fact the user is likely to be out of luck anyway
63            since the kernel currently only supports stack switching via
64            the X/Open sigaltstack interface, but we allow for the
65            possibility that this might change in the future.)  */
66         if (kact.sa_flags & (SA_RESTORER | SA_ONSTACK)) {
67             kact.sa_restorer = act->sa_restorer;
68         } else {
69             kact.sa_restorer = choose_restorer (kact.sa_flags);
70             kact.sa_flags |= SA_RESTORER;
71         }
72 # endif
73     }
74
75     /* XXX The size argument hopefully will have to be changed to the
76        real size of the user-level sigset_t.  */
77     result = __syscall_rt_sigaction(sig, act ? __ptrvalue (&kact) : NULL,
78             oact ? __ptrvalue (&koact) : NULL, _NSIG / 8);
79     if (oact && result >= 0) {
80         oact->sa_handler = koact.k_sa_handler;
81         __memcpy (&oact->sa_mask, &koact.sa_mask, sizeof (sigset_t));
82         oact->sa_flags = koact.sa_flags;
83 # ifdef HAVE_SA_RESTORER
84         oact->sa_restorer = koact.sa_restorer;
85 # endif
86     }
87     return result;
88 }
89
90
91 #else
92
93
94
95 /* If ACT is not NULL, change the action for SIG to *ACT.
96    If OACT is not NULL, put the old action for SIG in *OACT.  */
97 int __sigaction_internal (int sig, const struct sigaction *act, struct sigaction *oact)
98 {
99     int result;
100     struct old_kernel_sigaction kact, koact;
101
102     if (act) {
103         kact.k_sa_handler = act->sa_handler;
104         kact.sa_mask = act->sa_mask.__val[0];
105         kact.sa_flags = act->sa_flags;
106 # ifdef HAVE_SA_RESTORER
107         /* See the comments above for why we test SA_ONSTACK.  */
108         if (kact.sa_flags & (SA_RESTORER | SA_ONSTACK)) {
109             kact.sa_restorer = act->sa_restorer;
110         } else {
111             kact.sa_restorer = choose_restorer (kact.sa_flags);
112             kact.sa_flags |= SA_RESTORER;
113         }
114 # endif
115     }
116     result = __syscall_sigaction(sig, act ? __ptrvalue (&kact) : NULL,
117             oact ? __ptrvalue (&koact) : NULL);
118     if (oact && result >= 0) {
119         oact->sa_handler = koact.k_sa_handler;
120         oact->sa_mask.__val[0] = koact.sa_mask;
121         oact->sa_flags = koact.sa_flags;
122 # ifdef HAVE_SA_RESTORER
123         oact->sa_restorer = koact.sa_restorer;
124 # endif
125     }
126     return result;
127 }
128
129 #endif
130 strong_alias(__sigaction_internal,__libc_sigaction)
131 weak_alias(__sigaction_internal, sigaction)
132