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, write to the Free
17 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
25 #include <sys/syscall.h>
26 #include <kernel-features.h>
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
31 #include <kernel_sigaction.h>
33 /* The variable is shared between all wrappers around signal handling
34 functions which have RT equivalents. */
35 int __libc_missing_rt_sigs
;
37 #define SA_RESTORER 0x04000000
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
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)
57 extern void __default_sa_restorer(void);
58 extern void __default_rt_sa_restorer(void);
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
67 #define choose_restorer(flags) \
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. */
74 __libc_sigaction (sig
, act
, oact
)
76 const struct sigaction
*act
;
77 struct sigaction
*oact
;
79 #ifndef __ASSUME_REALTIME_SIGNALS
80 struct old_kernel_sigaction k_sigact
, k_osigact
;
84 #ifdef __NR_rt_sigaction
85 /* First try the RT signals. */
86 # ifndef __ASSUME_REALTIME_SIGNALS
87 if (!__libc_missing_rt_sigs
)
90 struct kernel_sigaction kact
, koact
;
91 # ifndef __ASSUME_REALTIME_SIGNALS
92 int saved_errno
= errno
;
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
;
105 kact
.sa_restorer
= choose_restorer (kact
.sa_flags
);
106 kact
.sa_flags
|= SA_RESTORER
;
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);
117 # ifndef __ASSUME_REALTIME_SIGNALS
118 if (result
>= 0 || errno
!= ENOSYS
)
121 if (oact
&& result
>= 0)
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
;
133 # ifndef __ASSUME_REALTIME_SIGNALS
134 __set_errno (saved_errno
);
135 __libc_missing_rt_sigs
= 1;
140 #ifndef __ASSUME_REALTIME_SIGNALS
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
;
151 k_sigact
.sa_restorer
= choose_restorer (k_sigact
.sa_flags
);
152 k_sigact
.sa_flags
|= SA_RESTORER
;
156 result
= INLINE_SYSCALL (sigaction
, 3, sig
,
157 act
? __ptrvalue (&k_sigact
) : NULL
,
158 oact
? __ptrvalue (&k_osigact
) : NULL
);
159 if (oact
&& result
>= 0)
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
;
171 libc_hidden_def (__libc_sigaction
)
173 #ifdef WRAPPER_INCLUDE
174 # include WRAPPER_INCLUDE
177 #ifndef LIBC_SIGACTION
178 weak_alias (__libc_sigaction
, __sigaction
)
179 libc_hidden_weak (__sigaction
)
180 weak_alias (__libc_sigaction
, sigaction
)