Replace FSF snail mail address by URL.
[glibc.git] / sysdeps / unix / sysv / linux / arm / sigaction.c
blob4f6e8bff9d7ab0ec4301057ca4a0f7dafabf079c
1 /* Copyright (C) 1997, 1998, 1999, 2000, 2002, 2003, 2005, 2006
2 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library. If not, see
17 <http://www.gnu.org/licenses/>. */
19 #include <errno.h>
20 #include <signal.h>
21 #include <string.h>
23 #include <sysdep.h>
24 #include <sys/syscall.h>
25 #include <kernel-features.h>
27 /* The difference here is that the sigaction structure used in the
28 kernel is not the same as we use in the libc. Therefore we must
29 translate it here. */
30 #include <kernel_sigaction.h>
32 /* The variable is shared between all wrappers around signal handling
33 functions which have RT equivalents. */
34 int __libc_missing_rt_sigs;
36 #define SA_RESTORER 0x04000000
38 #ifdef __ARM_EABI__
39 extern void __default_sa_restorer_v1(void);
40 extern void __default_sa_restorer_v2(void);
41 extern void __default_rt_sa_restorer_v1(void);
42 extern void __default_rt_sa_restorer_v2(void);
43 # ifdef __ASSUME_SIGFRAME_V2
44 # define __default_sa_restorer __default_sa_restorer_v2
45 # define __default_rt_sa_restorer __default_rt_sa_restorer_v2
46 # else
47 # include <ldsodefs.h>
48 # define __default_sa_restorer (GLRO(dl_osversion) >= 0x020612 \
49 ? __default_sa_restorer_v2 \
50 : __default_sa_restorer_v1)
51 # define __default_rt_sa_restorer (GLRO(dl_osversion) >= 0x020612 \
52 ? __default_rt_sa_restorer_v2 \
53 : __default_rt_sa_restorer_v1)
54 # endif
55 #else
56 extern void __default_sa_restorer(void);
57 extern void __default_rt_sa_restorer(void);
58 #endif
60 /* When RT signals are in use we need to use a different return stub. */
61 #ifdef __NR_rt_sigreturn
62 #define choose_restorer(flags) \
63 (flags & SA_SIGINFO) ? __default_rt_sa_restorer \
64 : __default_sa_restorer
65 #else
66 #define choose_restorer(flags) \
67 __default_sa_restorer
68 #endif
70 /* If ACT is not NULL, change the action for SIG to *ACT.
71 If OACT is not NULL, put the old action for SIG in *OACT. */
72 int
73 __libc_sigaction (sig, act, oact)
74 int sig;
75 const struct sigaction *act;
76 struct sigaction *oact;
78 #ifndef __ASSUME_REALTIME_SIGNALS
79 struct old_kernel_sigaction k_sigact, k_osigact;
80 #endif
81 int result;
83 #ifdef __NR_rt_sigaction
84 /* First try the RT signals. */
85 # ifndef __ASSUME_REALTIME_SIGNALS
86 if (!__libc_missing_rt_sigs)
87 # endif
89 struct kernel_sigaction kact, koact;
90 # ifndef __ASSUME_REALTIME_SIGNALS
91 int saved_errno = errno;
92 # endif
94 if (act)
96 kact.k_sa_handler = act->sa_handler;
97 memcpy (&kact.sa_mask, &act->sa_mask, sizeof (sigset_t));
98 kact.sa_flags = act->sa_flags;
99 # ifdef HAVE_SA_RESTORER
100 if (kact.sa_flags & SA_RESTORER)
101 kact.sa_restorer = act->sa_restorer;
102 else
104 kact.sa_restorer = choose_restorer (kact.sa_flags);
105 kact.sa_flags |= SA_RESTORER;
107 # endif
110 /* XXX The size argument hopefully will have to be changed to the
111 real size of the user-level sigset_t. */
112 result = INLINE_SYSCALL (rt_sigaction, 4, sig,
113 act ? __ptrvalue (&kact) : NULL,
114 oact ? __ptrvalue (&koact) : NULL, _NSIG / 8);
116 # ifndef __ASSUME_REALTIME_SIGNALS
117 if (result >= 0 || errno != ENOSYS)
118 # endif
120 if (oact && result >= 0)
122 oact->sa_handler = koact.k_sa_handler;
123 memcpy (&oact->sa_mask, &koact.sa_mask, sizeof (sigset_t));
124 oact->sa_flags = koact.sa_flags;
125 # ifdef HAVE_SA_RESTORER
126 oact->sa_restorer = koact.sa_restorer;
127 # endif
129 return result;
132 # ifndef __ASSUME_REALTIME_SIGNALS
133 __set_errno (saved_errno);
134 __libc_missing_rt_sigs = 1;
135 # endif
137 #endif
139 #ifndef __ASSUME_REALTIME_SIGNALS
140 if (act)
142 k_sigact.k_sa_handler = act->sa_handler;
143 k_sigact.sa_mask = act->sa_mask.__val[0];
144 k_sigact.sa_flags = act->sa_flags;
145 # ifdef HAVE_SA_RESTORER
146 if (k_sigact.sa_flags & SA_RESTORER)
147 k_sigact.sa_restorer = act->sa_restorer;
148 else
150 k_sigact.sa_restorer = choose_restorer (k_sigact.sa_flags);
151 k_sigact.sa_flags |= SA_RESTORER;
153 # endif
155 result = INLINE_SYSCALL (sigaction, 3, sig,
156 act ? __ptrvalue (&k_sigact) : NULL,
157 oact ? __ptrvalue (&k_osigact) : NULL);
158 if (oact && result >= 0)
160 oact->sa_handler = k_osigact.k_sa_handler;
161 oact->sa_mask.__val[0] = k_osigact.sa_mask;
162 oact->sa_flags = k_osigact.sa_flags;
163 # ifdef HAVE_SA_RESTORER
164 oact->sa_restorer = k_osigact.sa_restorer;
165 # endif
167 return result;
168 #endif
170 libc_hidden_def (__libc_sigaction)
172 #ifdef WRAPPER_INCLUDE
173 # include WRAPPER_INCLUDE
174 #endif
176 #ifndef LIBC_SIGACTION
177 weak_alias (__libc_sigaction, __sigaction)
178 libc_hidden_weak (__sigaction)
179 weak_alias (__libc_sigaction, sigaction)
180 #endif