1 /* Copyright (C) 1997-2000,2002,2003,2005,2006 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>
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
;
40 /* If ACT is not NULL, change the action for SIG to *ACT.
41 If OACT is not NULL, put the old action for SIG in *OACT. */
43 __libc_sigaction (sig
, act
, oact
)
45 const struct sigaction
*act
;
46 struct sigaction
*oact
;
48 #if __ASSUME_REALTIME_SIGNALS == 0
49 struct old_kernel_sigaction k_sigact
, k_osigact
;
53 #if defined __NR_rt_sigaction || __ASSUME_REALTIME_SIGNALS > 0
54 /* First try the RT signals. */
55 # if __ASSUME_REALTIME_SIGNALS == 0
56 if (!__libc_missing_rt_sigs
)
59 struct kernel_sigaction kact
, koact
;
60 /* Save the current error value for later. We need not do this
61 if we are guaranteed to have realtime signals. */
62 # if __ASSUME_REALTIME_SIGNALS == 0
63 int saved_errno
= errno
;
68 kact
.k_sa_handler
= act
->sa_handler
;
69 memcpy (&kact
.sa_mask
, &act
->sa_mask
, sizeof (sigset_t
));
70 kact
.sa_flags
= act
->sa_flags
;
71 # ifdef HAVE_SA_RESTORER
72 kact
.sa_restorer
= act
->sa_restorer
;
76 /* XXX The size argument hopefully will have to be changed to the
77 real size of the user-level sigset_t. */
78 result
= INLINE_SYSCALL (rt_sigaction
, 4, sig
,
79 act
? __ptrvalue (&kact
) : NULL
,
80 oact
? __ptrvalue (&koact
) : NULL
, _NSIG
/ 8);
82 # if __ASSUME_REALTIME_SIGNALS == 0
83 if (result
>= 0 || errno
!= ENOSYS
)
86 if (oact
&& result
>= 0)
88 oact
->sa_handler
= koact
.k_sa_handler
;
89 memcpy (&oact
->sa_mask
, &koact
.sa_mask
, sizeof (sigset_t
));
90 oact
->sa_flags
= koact
.sa_flags
;
91 # ifdef HAVE_SA_RESTORER
92 oact
->sa_restorer
= koact
.sa_restorer
;
98 # if __ASSUME_REALTIME_SIGNALS == 0
99 __set_errno (saved_errno
);
100 __libc_missing_rt_sigs
= 1;
105 #if __ASSUME_REALTIME_SIGNALS == 0
108 k_sigact
.k_sa_handler
= act
->sa_handler
;
109 k_sigact
.sa_mask
= act
->sa_mask
.__val
[0];
110 k_sigact
.sa_flags
= act
->sa_flags
;
111 # ifdef HAVE_SA_RESTORER
112 k_sigact
.sa_restorer
= act
->sa_restorer
;
115 result
= INLINE_SYSCALL (sigaction
, 3, sig
,
116 act
? __ptrvalue (&k_sigact
) : NULL
,
117 oact
? __ptrvalue (&k_osigact
) : NULL
);
118 if (oact
&& result
>= 0)
120 oact
->sa_handler
= k_osigact
.k_sa_handler
;
121 oact
->sa_mask
.__val
[0] = k_osigact
.sa_mask
;
122 oact
->sa_flags
= k_osigact
.sa_flags
;
123 # ifdef HAVE_SA_RESTORER
124 oact
->sa_restorer
= k_osigact
.sa_restorer
;
130 libc_hidden_def (__libc_sigaction
)
132 #ifdef WRAPPER_INCLUDE
133 # include WRAPPER_INCLUDE
136 #ifndef LIBC_SIGACTION
137 weak_alias (__libc_sigaction
, __sigaction
)
138 libc_hidden_weak (__sigaction
)
139 weak_alias (__libc_sigaction
, sigaction
)