chiark / gitweb /
eglibc (2.11.3-4+deb6u3) squeeze-lts; urgency=medium
[eglibc.git] / ports / sysdeps / unix / sysv / linux / arm / sigaction.c
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.
4
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.
9
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.
14
15    You should have received a copy of the GNU Lesser General Public
16    License along with the GNU C Library; if not, write to the Free
17    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
18    02111-1307 USA.  */
19
20 #include <errno.h>
21 #include <signal.h>
22 #include <string.h>
23
24 #include <sysdep.h>
25 #include <sys/syscall.h>
26 #include <kernel-features.h>
27
28 /* The difference here is that the sigaction structure used in the
29    kernel is not the same as we use in the libc.  Therefore we must
30    translate it here.  */
31 #include <kernel_sigaction.h>
32
33 /* The variable is shared between all wrappers around signal handling
34    functions which have RT equivalents.  */
35 int __libc_missing_rt_sigs;
36
37 #define SA_RESTORER     0x04000000
38
39 #ifdef __ARM_EABI__
40 extern void __default_sa_restorer_v1(void);
41 extern void __default_sa_restorer_v2(void);
42 extern void __default_rt_sa_restorer_v1(void);
43 extern void __default_rt_sa_restorer_v2(void);
44 # ifdef __ASSUME_SIGFRAME_V2
45 #  define __default_sa_restorer __default_sa_restorer_v2
46 #  define __default_rt_sa_restorer __default_rt_sa_restorer_v2
47 # else
48 #  include <ldsodefs.h>
49 #  define __default_sa_restorer (GLRO(dl_osversion) >= 0x020612 \
50                                  ? __default_sa_restorer_v2     \
51                                  : __default_sa_restorer_v1)
52 #  define __default_rt_sa_restorer (GLRO(dl_osversion) >= 0x020612      \
53                                     ? __default_rt_sa_restorer_v2       \
54                                     : __default_rt_sa_restorer_v1)
55 # endif
56 #else
57 extern void __default_sa_restorer(void);
58 extern void __default_rt_sa_restorer(void);
59 #endif
60
61 /* When RT signals are in use we need to use a different return stub.  */
62 #ifdef __NR_rt_sigreturn
63 #define choose_restorer(flags)                                  \
64   (flags & SA_SIGINFO) ? __default_rt_sa_restorer               \
65   : __default_sa_restorer
66 #else
67 #define choose_restorer(flags)                                  \
68   __default_sa_restorer
69 #endif
70
71 /* If ACT is not NULL, change the action for SIG to *ACT.
72    If OACT is not NULL, put the old action for SIG in *OACT.  */
73 int
74 __libc_sigaction (sig, act, oact)
75      int sig;
76      const struct sigaction *act;
77      struct sigaction *oact;
78 {
79 #ifndef __ASSUME_REALTIME_SIGNALS
80   struct old_kernel_sigaction k_sigact, k_osigact;
81 #endif
82   int result;
83
84 #ifdef __NR_rt_sigaction
85   /* First try the RT signals.  */
86 # ifndef __ASSUME_REALTIME_SIGNALS
87   if (!__libc_missing_rt_sigs)
88 # endif
89     {
90       struct kernel_sigaction kact, koact;
91 # ifndef __ASSUME_REALTIME_SIGNALS
92       int saved_errno = errno;
93 # endif
94
95       if (act)
96         {
97           kact.k_sa_handler = act->sa_handler;
98           memcpy (&kact.sa_mask, &act->sa_mask, sizeof (sigset_t));
99           kact.sa_flags = act->sa_flags;
100 # ifdef HAVE_SA_RESTORER
101           if (kact.sa_flags & SA_RESTORER)
102             kact.sa_restorer = act->sa_restorer;
103           else
104             {
105               kact.sa_restorer = choose_restorer (kact.sa_flags);
106               kact.sa_flags |= SA_RESTORER;
107             }
108 # endif
109         }
110
111       /* XXX The size argument hopefully will have to be changed to the
112          real size of the user-level sigset_t.  */
113       result = INLINE_SYSCALL (rt_sigaction, 4, sig,
114                                act ? __ptrvalue (&kact) : NULL,
115                                oact ? __ptrvalue (&koact) : NULL, _NSIG / 8);
116
117 # ifndef __ASSUME_REALTIME_SIGNALS
118       if (result >= 0 || errno != ENOSYS)
119 # endif
120         {
121           if (oact && result >= 0)
122             {
123               oact->sa_handler = koact.k_sa_handler;
124               memcpy (&oact->sa_mask, &koact.sa_mask, sizeof (sigset_t));
125               oact->sa_flags = koact.sa_flags;
126 # ifdef HAVE_SA_RESTORER
127               oact->sa_restorer = koact.sa_restorer;
128 # endif
129             }
130           return result;
131         }
132
133 # ifndef __ASSUME_REALTIME_SIGNALS
134       __set_errno (saved_errno);
135       __libc_missing_rt_sigs = 1;
136 # endif
137     }
138 #endif
139
140 #ifndef __ASSUME_REALTIME_SIGNALS
141   if (act)
142     {
143       k_sigact.k_sa_handler = act->sa_handler;
144       k_sigact.sa_mask = act->sa_mask.__val[0];
145       k_sigact.sa_flags = act->sa_flags;
146 # ifdef HAVE_SA_RESTORER
147       if (k_sigact.sa_flags & SA_RESTORER)
148         k_sigact.sa_restorer = act->sa_restorer;
149       else
150         {
151           k_sigact.sa_restorer = choose_restorer (k_sigact.sa_flags);
152           k_sigact.sa_flags |= SA_RESTORER;
153         }
154 # endif
155     }
156   result = INLINE_SYSCALL (sigaction, 3, sig,
157                            act ? __ptrvalue (&k_sigact) : NULL,
158                            oact ? __ptrvalue (&k_osigact) : NULL);
159   if (oact && result >= 0)
160     {
161       oact->sa_handler = k_osigact.k_sa_handler;
162       oact->sa_mask.__val[0] = k_osigact.sa_mask;
163       oact->sa_flags = k_osigact.sa_flags;
164 # ifdef HAVE_SA_RESTORER
165       oact->sa_restorer = k_osigact.sa_restorer;
166 # endif
167     }
168   return result;
169 #endif
170 }
171 libc_hidden_def (__libc_sigaction)
172
173 #ifdef WRAPPER_INCLUDE
174 # include WRAPPER_INCLUDE
175 #endif
176
177 #ifndef LIBC_SIGACTION
178 weak_alias (__libc_sigaction, __sigaction)
179 libc_hidden_weak (__sigaction)
180 weak_alias (__libc_sigaction, sigaction)
181 #endif