1 /* Copyright (C) 1997,1998,1999,2000,2002,2003 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
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.
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.
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
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
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 extern void __default_sa_restorer(void);
39 extern void __default_rt_sa_restorer(void);
41 /* When RT signals are in use we need to use a different return stub. */
42 #ifdef __NR_rt_sigreturn
43 #define choose_restorer(flags) \
44 (flags & SA_SIGINFO) ? __default_rt_sa_restorer \
45 : __default_sa_restorer
47 #define choose_restorer(flags) \
51 /* If ACT is not NULL, change the action for SIG to *ACT.
52 If OACT is not NULL, put the old action for SIG in *OACT. */
54 __libc_sigaction (sig
, act
, oact
)
56 const struct sigaction
*act
;
57 struct sigaction
*oact
;
59 #ifndef __ASSUME_REALTIME_SIGNALS
60 struct old_kernel_sigaction k_sigact
, k_osigact
;
64 #ifdef __NR_rt_sigaction
65 /* First try the RT signals. */
66 # ifndef __ASSUME_REALTIME_SIGNALS
67 if (!__libc_missing_rt_sigs
)
70 struct kernel_sigaction kact
, koact
;
71 # ifndef __ASSUME_REALTIME_SIGNALS
72 int saved_errno
= errno
;
77 kact
.k_sa_handler
= act
->sa_handler
;
78 memcpy (&kact
.sa_mask
, &act
->sa_mask
, sizeof (sigset_t
));
79 kact
.sa_flags
= act
->sa_flags
;
80 # ifdef HAVE_SA_RESTORER
81 /* If the user specified SA_ONSTACK this means she is trying to
82 use the old-style stack switching. Unfortunately this
83 requires the sa_restorer field so we cannot install our own
84 handler. (In fact the user is likely to be out of luck anyway
85 since the kernel currently only supports stack switching via
86 the X/Open sigaltstack interface, but we allow for the
87 possibility that this might change in the future.) */
88 if (kact
.sa_flags
& (SA_RESTORER
| SA_ONSTACK
))
89 kact
.sa_restorer
= act
->sa_restorer
;
92 kact
.sa_restorer
= choose_restorer (kact
.sa_flags
);
93 kact
.sa_flags
|= SA_RESTORER
;
98 /* XXX The size argument hopefully will have to be changed to the
99 real size of the user-level sigset_t. */
100 result
= INLINE_SYSCALL (rt_sigaction
, 4, sig
,
101 act
? __ptrvalue (&kact
) : NULL
,
102 oact
? __ptrvalue (&koact
) : NULL
, _NSIG
/ 8);
104 # ifndef __ASSUME_REALTIME_SIGNALS
105 if (result
>= 0 || errno
!= ENOSYS
)
108 if (oact
&& result
>= 0)
110 oact
->sa_handler
= koact
.k_sa_handler
;
111 memcpy (&oact
->sa_mask
, &koact
.sa_mask
, sizeof (sigset_t
));
112 oact
->sa_flags
= koact
.sa_flags
;
113 # ifdef HAVE_SA_RESTORER
114 oact
->sa_restorer
= koact
.sa_restorer
;
120 # ifndef __ASSUME_REALTIME_SIGNALS
121 __set_errno (saved_errno
);
122 __libc_missing_rt_sigs
= 1;
127 #ifndef __ASSUME_REALTIME_SIGNALS
130 k_sigact
.k_sa_handler
= act
->sa_handler
;
131 k_sigact
.sa_mask
= act
->sa_mask
.__val
[0];
132 k_sigact
.sa_flags
= act
->sa_flags
;
133 # ifdef HAVE_SA_RESTORER
134 /* See the comments above for why we test SA_ONSTACK. */
135 if (k_sigact
.sa_flags
& (SA_RESTORER
| SA_ONSTACK
))
136 k_sigact
.sa_restorer
= act
->sa_restorer
;
139 k_sigact
.sa_restorer
= choose_restorer (k_sigact
.sa_flags
);
140 k_sigact
.sa_flags
|= SA_RESTORER
;
144 result
= INLINE_SYSCALL (sigaction
, 3, sig
,
145 act
? __ptrvalue (&k_sigact
) : NULL
,
146 oact
? __ptrvalue (&k_osigact
) : NULL
);
147 if (oact
&& result
>= 0)
149 oact
->sa_handler
= k_osigact
.k_sa_handler
;
150 oact
->sa_mask
.__val
[0] = k_osigact
.sa_mask
;
151 oact
->sa_flags
= k_osigact
.sa_flags
;
152 # ifdef HAVE_SA_RESTORER
153 oact
->sa_restorer
= k_osigact
.sa_restorer
;
159 libc_hidden_def (__libc_sigaction
)
161 #ifndef LIBC_SIGACTION
162 weak_alias (__libc_sigaction
, __sigaction
)
163 libc_hidden_weak (__sigaction
)
164 weak_alias (__libc_sigaction
, sigaction
)