1 /* POSIX.1 `sigaction' call for Linux/i386.
2 Copyright (C) 1991, 95, 96, 97, 98, 99, 2000 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 Library General Public License as
7 published by the Free Software Foundation; either version 2 of the
8 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 Library General Public License for more details.
15 You should have received a copy of the GNU Library General Public
16 License along with the GNU C Library; see the file COPYING.LIB. If not,
17 write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. */
27 #include <sys/syscall.h>
29 #include <kernel-features.h>
31 /* The difference here is that the sigaction structure used in the
32 kernel is not the same as we use in the libc. Therefore we must
34 #include <kernel_sigaction.h>
36 /* We do not globally define the SA_RESTORER flag so do it here. */
37 #define SA_RESTORER 0x04000000
40 extern int __syscall_rt_sigaction (int, const struct kernel_sigaction
*,
41 struct kernel_sigaction
*, size_t);
43 #if __ASSUME_REALTIME_SIGNALS == 0
44 /* The variable is shared between all wrappers around signal handling
45 functions which have RT equivalents. */
46 int __libc_missing_rt_sigs
;
49 #ifdef __NR_rt_sigaction
50 static void restore_rt (void) asm ("__restore_rt");
52 static void restore (void) asm ("__restore");
55 /* If ACT is not NULL, change the action for SIG to *ACT.
56 If OACT is not NULL, put the old action for SIG in *OACT. */
58 __libc_sigaction (int sig
, const struct sigaction
*act
, struct sigaction
*oact
)
60 #if __ASSUME_REALTIME_SIGNALS == 0
61 struct old_kernel_sigaction k_newact
, k_oldact
;
65 #ifdef __NR_rt_sigaction
67 /* First try the RT signals. */
68 # if __ASSUME_REALTIME_SIGNALS == 0
69 if (!__libc_missing_rt_sigs
)
72 struct kernel_sigaction kact
, koact
;
73 # if __ASSUME_REALTIME_SIGNALS == 0
74 int saved_errno
= errno
;
79 kact
.k_sa_handler
= act
->sa_handler
;
80 memcpy (&kact
.sa_mask
, &act
->sa_mask
, sizeof (sigset_t
));
81 kact
.sa_flags
= act
->sa_flags
| SA_RESTORER
;
83 kact
.sa_restorer
= ((act
->sa_flags
& SA_SIGINFO
)
84 ? &restore_rt
: &restore
);
87 /* XXX The size argument hopefully will have to be changed to the
88 real size of the user-level sigset_t. */
89 result
= INLINE_SYSCALL (rt_sigaction
, 4, sig
, act
? &kact
: NULL
,
90 oact
? &koact
: NULL
, _NSIG
/ 8);
92 # if __ASSUME_REALTIME_SIGNALS == 0
93 if (result
>= 0 || errno
!= ENOSYS
)
96 if (oact
&& result
>= 0)
98 oact
->sa_handler
= koact
.k_sa_handler
;
99 memcpy (&oact
->sa_mask
, &koact
.sa_mask
, sizeof (sigset_t
));
100 oact
->sa_flags
= koact
.sa_flags
;
101 oact
->sa_restorer
= koact
.sa_restorer
;
106 # if __ASSUME_REALTIME_SIGNALS == 0
107 __set_errno (saved_errno
);
108 __libc_missing_rt_sigs
= 1;
113 #if __ASSUME_REALTIME_SIGNALS == 0
116 k_newact
.k_sa_handler
= act
->sa_handler
;
117 k_newact
.sa_mask
= act
->sa_mask
.__val
[0];
118 k_newact
.sa_flags
= act
->sa_flags
| SA_RESTORER
;
120 k_newact
.sa_restorer
= &restore
;
123 asm volatile ("pushl %%ebx\n"
128 : "0" (SYS_ify (sigaction
)), "r" (sig
),
129 "c" (act
? &k_newact
: 0), "d" (oact
? &k_oldact
: 0));
133 __set_errno (-result
);
139 oact
->sa_handler
= k_oldact
.k_sa_handler
;
140 oact
->sa_mask
.__val
[0] = k_oldact
.sa_mask
;
141 oact
->sa_flags
= k_oldact
.sa_flags
;
142 oact
->sa_restorer
= k_oldact
.sa_restorer
;
149 strong_alias (__libc_sigaction
, __sigaction
)
150 weak_alias (__libc_sigaction
, sigaction
)
152 /* NOTE: Please think twice before making any changes to the bits of
153 code below. GDB needs some intimate knowledge about it to
154 recognize them as signal trampolines, and make backtraces through
155 signal handlers work right. Important are both the names
156 (__restore and __restore_rt) and the exact instruction sequence.
157 If you ever feel the need to make any changes, please notify the
158 appropriate GDB maintainer. */
160 #define RESTORE(name, syscall) RESTORE2 (name, syscall)
161 #define RESTORE2(name, syscall) \
166 " movl $" #syscall ", %eax\n" \
170 #ifdef __NR_rt_sigaction
171 /* The return code for realtime-signals. */
172 RESTORE (restore_rt
, __NR_rt_sigreturn
)
175 /* For the boring old signals. */
177 # define RESTORE2(name, syscall) \
183 " movl $" #syscall ", %eax\n" \
187 RESTORE (restore
, __NR_sigreturn
)