1 /* POSIX.1 `sigaction' call for Linux/i386.
2 Copyright (C) 1991,95,96,97,98,99,2000,02 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
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
*__unbounded
,
41 struct kernel_sigaction
*__unbounded
, 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 /* Using the hidden attribute here does not change the code but it
50 helps to avoid warnings. */
51 #if defined HAVE_HIDDEN && !defined HAVE_BROKEN_VISIBILITY_ATTRIBUTE
52 # ifdef __NR_rt_sigaction
53 extern void restore_rt (void) asm ("__restore_rt") attribute_hidden
;
55 extern void restore (void) asm ("__restore") attribute_hidden
;
57 # ifdef __NR_rt_sigaction
58 static void restore_rt (void) asm ("__restore_rt");
60 static void restore (void) asm ("__restore");
64 /* If ACT is not NULL, change the action for SIG to *ACT.
65 If OACT is not NULL, put the old action for SIG in *OACT. */
67 __libc_sigaction (int sig
, const struct sigaction
*act
, struct sigaction
*oact
)
69 #if __ASSUME_REALTIME_SIGNALS == 0
70 struct old_kernel_sigaction k_newact
, k_oldact
;
74 #ifdef __NR_rt_sigaction
76 /* First try the RT signals. */
77 # if __ASSUME_REALTIME_SIGNALS == 0
78 if (!__libc_missing_rt_sigs
)
81 struct kernel_sigaction kact
, koact
;
82 # if __ASSUME_REALTIME_SIGNALS == 0
83 int saved_errno
= errno
;
88 kact
.k_sa_handler
= act
->sa_handler
;
89 memcpy (&kact
.sa_mask
, &act
->sa_mask
, sizeof (sigset_t
));
90 kact
.sa_flags
= act
->sa_flags
| SA_RESTORER
;
92 kact
.sa_restorer
= ((act
->sa_flags
& SA_SIGINFO
)
93 ? &restore_rt
: &restore
);
96 /* XXX The size argument hopefully will have to be changed to the
97 real size of the user-level sigset_t. */
98 result
= INLINE_SYSCALL (rt_sigaction
, 4,
99 sig
, act
? __ptrvalue (&kact
) : NULL
,
100 oact
? __ptrvalue (&koact
) : NULL
, _NSIG
/ 8);
102 # if __ASSUME_REALTIME_SIGNALS == 0
103 if (result
>= 0 || errno
!= ENOSYS
)
106 if (oact
&& result
>= 0)
108 oact
->sa_handler
= koact
.k_sa_handler
;
109 memcpy (&oact
->sa_mask
, &koact
.sa_mask
, sizeof (sigset_t
));
110 oact
->sa_flags
= koact
.sa_flags
;
111 oact
->sa_restorer
= koact
.sa_restorer
;
116 # if __ASSUME_REALTIME_SIGNALS == 0
117 __set_errno (saved_errno
);
118 __libc_missing_rt_sigs
= 1;
123 #if __ASSUME_REALTIME_SIGNALS == 0
126 k_newact
.k_sa_handler
= act
->sa_handler
;
127 k_newact
.sa_mask
= act
->sa_mask
.__val
[0];
128 k_newact
.sa_flags
= act
->sa_flags
| SA_RESTORER
;
130 k_newact
.sa_restorer
= &restore
;
133 asm volatile ("pushl %%ebx\n"
138 : "0" (SYS_ify (sigaction
)), "mr" (sig
),
139 "c" (act
? __ptrvalue (&k_newact
) : 0),
140 "d" (oact
? __ptrvalue (&k_oldact
) : 0));
144 __set_errno (-result
);
150 oact
->sa_handler
= k_oldact
.k_sa_handler
;
151 oact
->sa_mask
.__val
[0] = k_oldact
.sa_mask
;
152 oact
->sa_flags
= k_oldact
.sa_flags
;
153 oact
->sa_restorer
= k_oldact
.sa_restorer
;
160 weak_alias (__libc_sigaction
, __sigaction
)
161 libc_hidden_weak (__sigaction
)
162 weak_alias (__libc_sigaction
, sigaction
)
164 /* NOTE: Please think twice before making any changes to the bits of
165 code below. GDB needs some intimate knowledge about it to
166 recognize them as signal trampolines, and make backtraces through
167 signal handlers work right. Important are both the names
168 (__restore and __restore_rt) and the exact instruction sequence.
169 If you ever feel the need to make any changes, please notify the
170 appropriate GDB maintainer. */
172 #define RESTORE(name, syscall) RESTORE2 (name, syscall)
173 #define RESTORE2(name, syscall) \
179 " movl $" #syscall ", %eax\n" \
183 #ifdef __NR_rt_sigaction
184 /* The return code for realtime-signals. */
185 RESTORE (restore_rt
, __NR_rt_sigreturn
)
188 /* For the boring old signals. */
190 # define RESTORE2(name, syscall) \
197 " movl $" #syscall ", %eax\n" \
201 RESTORE (restore
, __NR_sigreturn
)