1 /* Copyright (C) 1997, 1998, 1999, 2000 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 Library General Public License as
6 published by the Free Software Foundation; either version 2 of the
7 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 Library General Public License for more details.
14 You should have received a copy of the GNU Library General Public
15 License along with the GNU C Library; see the file COPYING.LIB. If not,
16 write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 Boston, MA 02111-1307, USA. */
24 #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 #if __ASSUME_REALTIME_SIGNALS == 0
34 /* The variable is shared between all wrappers around signal handling
35 functions which have RT equivalents. This is the definition. */
36 int __libc_missing_rt_sigs
;
38 extern int __syscall_sigaction (int, const struct old_kernel_sigaction
*,
39 struct old_kernel_sigaction
*);
41 extern int __syscall_rt_sigaction (int, const struct kernel_sigaction
*,
42 struct kernel_sigaction
*, size_t);
45 /* If ACT is not NULL, change the action for SIG to *ACT.
46 If OACT is not NULL, put the old action for SIG in *OACT. */
48 __libc_sigaction (sig
, act
, oact
)
50 const struct sigaction
*act
;
51 struct sigaction
*oact
;
53 #if __ASSUME_REALTIME_SIGNALS == 0
54 struct old_kernel_sigaction k_sigact
, k_osigact
;
58 #if defined __NR_rt_sigaction || __ASSUME_REALTIME_SIGNALS > 0
59 /* First try the RT signals. */
60 # if __ASSUME_REALTIME_SIGNALS == 0
61 if (!__libc_missing_rt_sigs
)
64 struct kernel_sigaction kact
, koact
;
65 /* Save the current error value for later. We need not do this
66 if we are guaranteed to have realtime signals. */
67 # if __ASSUME_REALTIME_SIGNALS == 0
68 int saved_errno
= errno
;
73 kact
.k_sa_handler
= act
->sa_handler
;
74 memcpy (&kact
.sa_mask
, &act
->sa_mask
, sizeof (sigset_t
));
75 kact
.sa_flags
= act
->sa_flags
;
76 # ifdef HAVE_SA_RESTORER
77 kact
.sa_restorer
= act
->sa_restorer
;
81 /* XXX The size argument hopefully will have to be changed to the
82 real size of the user-level sigset_t. */
83 result
= INLINE_SYSCALL (rt_sigaction
, 4, sig
, act
? &kact
: NULL
,
84 oact
? &koact
: NULL
, _NSIG
/ 8);
86 # if __ASSUME_REALTIME_SIGNALS == 0
87 if (result
>= 0 || errno
!= ENOSYS
)
90 if (oact
&& result
>= 0)
92 oact
->sa_handler
= koact
.k_sa_handler
;
93 memcpy (&oact
->sa_mask
, &koact
.sa_mask
, sizeof (sigset_t
));
94 oact
->sa_flags
= koact
.sa_flags
;
95 # ifdef HAVE_SA_RESTORER
96 oact
->sa_restorer
= koact
.sa_restorer
;
102 # if __ASSUME_REALTIME_SIGNALS == 0
103 __set_errno (saved_errno
);
104 __libc_missing_rt_sigs
= 1;
109 #if __ASSUME_REALTIME_SIGNALS == 0
112 k_sigact
.k_sa_handler
= act
->sa_handler
;
113 k_sigact
.sa_mask
= act
->sa_mask
.__val
[0];
114 k_sigact
.sa_flags
= act
->sa_flags
;
115 # ifdef HAVE_SA_RESTORER
116 k_sigact
.sa_restorer
= act
->sa_restorer
;
119 result
= INLINE_SYSCALL (sigaction
, 3, sig
, act
? &k_sigact
: NULL
,
120 oact
? &k_osigact
: NULL
);
121 if (oact
&& result
>= 0)
123 oact
->sa_handler
= k_osigact
.k_sa_handler
;
124 oact
->sa_mask
.__val
[0] = k_osigact
.sa_mask
;
125 oact
->sa_flags
= k_osigact
.sa_flags
;
126 # ifdef HAVE_SA_RESTORER
127 oact
->sa_restorer
= k_osigact
.sa_restorer
;
134 string_alias (__libc_sigaction
, __sigaction
)
135 weak_alias (__libc_sigaction
, sigaction
)