1 /* POSIX.1 `sigaction' call for Linux/i386.
2 Copyright (C) 1991,1995-2000,2002-2005,2006 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>
30 #include <kernel-features.h>
32 /* The difference here is that the sigaction structure used in the
33 kernel is not the same as we use in the libc. Therefore we must
35 #include <kernel_sigaction.h>
37 /* We do not globally define the SA_RESTORER flag so do it here. */
38 #define SA_RESTORER 0x04000000
41 #if __ASSUME_REALTIME_SIGNALS == 0
42 /* The variable is shared between all wrappers around signal handling
43 functions which have RT equivalents. */
44 int __libc_missing_rt_sigs
;
47 /* Using the hidden attribute here does not change the code but it
48 helps to avoid warnings. */
49 #ifdef __NR_rt_sigaction
50 extern void restore_rt (void) asm ("__restore_rt") attribute_hidden
;
52 extern void restore (void) asm ("__restore") attribute_hidden
;
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 kact
.sa_flags
= act
->sa_flags
;
81 memcpy (&kact
.sa_mask
, &act
->sa_mask
, sizeof (sigset_t
));
83 if (GLRO(dl_sysinfo_dso
) == NULL
)
85 kact
.sa_flags
|= SA_RESTORER
;
87 kact
.sa_restorer
= ((act
->sa_flags
& SA_SIGINFO
)
88 ? &restore_rt
: &restore
);
92 /* XXX The size argument hopefully will have to be changed to the
93 real size of the user-level sigset_t. */
94 result
= INLINE_SYSCALL (rt_sigaction
, 4,
95 sig
, act
? __ptrvalue (&kact
) : NULL
,
96 oact
? __ptrvalue (&koact
) : NULL
, _NSIG
/ 8);
98 # if __ASSUME_REALTIME_SIGNALS == 0
99 if (result
>= 0 || errno
!= ENOSYS
)
102 if (oact
&& result
>= 0)
104 oact
->sa_handler
= koact
.k_sa_handler
;
105 memcpy (&oact
->sa_mask
, &koact
.sa_mask
, sizeof (sigset_t
));
106 oact
->sa_flags
= koact
.sa_flags
;
107 oact
->sa_restorer
= koact
.sa_restorer
;
112 # if __ASSUME_REALTIME_SIGNALS == 0
113 __set_errno (saved_errno
);
114 __libc_missing_rt_sigs
= 1;
119 #if __ASSUME_REALTIME_SIGNALS == 0
122 k_newact
.k_sa_handler
= act
->sa_handler
;
123 k_newact
.sa_mask
= act
->sa_mask
.__val
[0];
124 k_newact
.sa_flags
= act
->sa_flags
| SA_RESTORER
;
126 k_newact
.sa_restorer
= &restore
;
129 result
= INLINE_SYSCALL (sigaction
, 3, sig
,
130 act
? __ptrvalue (&k_newact
) : 0,
131 oact
? __ptrvalue (&k_oldact
) : 0);
138 oact
->sa_handler
= k_oldact
.k_sa_handler
;
139 oact
->sa_mask
.__val
[0] = k_oldact
.sa_mask
;
140 oact
->sa_flags
= k_oldact
.sa_flags
;
141 oact
->sa_restorer
= k_oldact
.sa_restorer
;
147 libc_hidden_def (__libc_sigaction
)
149 #ifdef WRAPPER_INCLUDE
150 # include WRAPPER_INCLUDE
153 #ifndef LIBC_SIGACTION
154 weak_alias (__libc_sigaction
, __sigaction
)
155 libc_hidden_weak (__sigaction
)
156 weak_alias (__libc_sigaction
, sigaction
)
159 /* NOTE: Please think twice before making any changes to the bits of
160 code below. GDB needs some intimate knowledge about it to
161 recognize them as signal trampolines, and make backtraces through
162 signal handlers work right. Important are both the names
163 (__restore and __restore_rt) and the exact instruction sequence.
164 If you ever feel the need to make any changes, please notify the
165 appropriate GDB maintainer. */
167 #define RESTORE(name, syscall) RESTORE2 (name, syscall)
168 #define RESTORE2(name, syscall) \
174 " movl $" #syscall ", %eax\n" \
178 #ifdef __NR_rt_sigaction
179 /* The return code for realtime-signals. */
180 RESTORE (restore_rt
, __NR_rt_sigreturn
)
183 /* For the boring old signals. */
185 #define RESTORE2(name, syscall) \
192 " movl $" #syscall ", %eax\n" \
196 RESTORE (restore
, __NR_sigreturn
)