]> git.ipfire.org Git - thirdparty/glibc.git/blame - sysdeps/unix/sysv/linux/i386/sigaction.c
Update copyright dates with scripts/update-copyrights.
[thirdparty/glibc.git] / sysdeps / unix / sysv / linux / i386 / sigaction.c
CommitLineData
efc755b2 1/* POSIX.1 `sigaction' call for Linux/i386.
b168057a 2 Copyright (C) 1991-2015 Free Software Foundation, Inc.
4cca6b86 3 This file is part of the GNU C Library.
efc755b2 4
4cca6b86 5 The GNU C Library is free software; you can redistribute it and/or
41bdb6e2
AJ
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.
efc755b2 9
4cca6b86
UD
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
41bdb6e2 13 Lesser General Public License for more details.
efc755b2 14
41bdb6e2 15 You should have received a copy of the GNU Lesser General Public
59ba27a6
PE
16 License along with the GNU C Library; if not, see
17 <http://www.gnu.org/licenses/>. */
efc755b2
RM
18
19#include <sysdep.h>
20#include <errno.h>
21#include <stddef.h>
22#include <signal.h>
ef52edfc 23#include <string.h>
efc755b2 24
adcb550c
UD
25#include <sysdep.h>
26#include <sys/syscall.h>
8e4f5035 27#include <ldsodefs.h>
adcb550c 28
4cca6b86
UD
29/* The difference here is that the sigaction structure used in the
30 kernel is not the same as we use in the libc. Therefore we must
31 translate it here. */
32#include <kernel_sigaction.h>
33
25ee8743
UD
34/* We do not globally define the SA_RESTORER flag so do it here. */
35#define SA_RESTORER 0x04000000
36
efc755b2 37
40e15c4d
UD
38/* Using the hidden attribute here does not change the code but it
39 helps to avoid warnings. */
11bf311e 40#ifdef __NR_rt_sigaction
40e15c4d 41extern void restore_rt (void) asm ("__restore_rt") attribute_hidden;
32c075e1 42#endif
11bf311e 43extern void restore (void) asm ("__restore") attribute_hidden;
e0082312 44
cbdee279 45
efc755b2
RM
46/* If ACT is not NULL, change the action for SIG to *ACT.
47 If OACT is not NULL, put the old action for SIG in *OACT. */
48int
c0f53cdd 49__libc_sigaction (int sig, const struct sigaction *act, struct sigaction *oact)
efc755b2 50{
efc755b2
RM
51 int result;
52
ffb7875d 53 struct kernel_sigaction kact, koact;
ea6710d3 54
ffb7875d 55 if (act)
cbdee279 56 {
ffb7875d
JM
57 kact.k_sa_handler = act->sa_handler;
58 kact.sa_flags = act->sa_flags;
59 memcpy (&kact.sa_mask, &act->sa_mask, sizeof (sigset_t));
cbdee279 60
ffb7875d 61 if (GLRO(dl_sysinfo_dso) == NULL)
d71b808a 62 {
ffb7875d 63 kact.sa_flags |= SA_RESTORER;
7cc1894c 64
ffb7875d
JM
65 kact.sa_restorer = ((act->sa_flags & SA_SIGINFO)
66 ? &restore_rt : &restore);
14e9dd67 67 }
efc755b2
RM
68 }
69
ffb7875d
JM
70 /* XXX The size argument hopefully will have to be changed to the
71 real size of the user-level sigset_t. */
72 result = INLINE_SYSCALL (rt_sigaction, 4,
70d9946a
JM
73 sig, act ? &kact : NULL,
74 oact ? &koact : NULL, _NSIG / 8);
4cca6b86 75
ffb7875d 76 if (oact && result >= 0)
4cca6b86 77 {
ffb7875d
JM
78 oact->sa_handler = koact.k_sa_handler;
79 memcpy (&oact->sa_mask, &koact.sa_mask, sizeof (sigset_t));
80 oact->sa_flags = koact.sa_flags;
81 oact->sa_restorer = koact.sa_restorer;
4cca6b86 82 }
ffb7875d 83 return result;
efc755b2 84}
5ec5c857 85libc_hidden_def (__libc_sigaction)
efc755b2 86
08192659 87#include <nptl/sigaction.c>
e0082312 88
adcf0e4a
UD
89/* NOTE: Please think twice before making any changes to the bits of
90 code below. GDB needs some intimate knowledge about it to
91 recognize them as signal trampolines, and make backtraces through
92 signal handlers work right. Important are both the names
93 (__restore and __restore_rt) and the exact instruction sequence.
94 If you ever feel the need to make any changes, please notify the
95 appropriate GDB maintainer. */
96
8e4f5035
UD
97#define RESTORE(name, syscall) RESTORE2 (name, syscall)
98#define RESTORE2(name, syscall) \
e0082312
UD
99asm \
100 ( \
4dbb6417
UD
101 ".text\n" \
102 " .align 16\n" \
adcf0e4a 103 "__" #name ":\n" \
e0082312
UD
104 " movl $" #syscall ", %eax\n" \
105 " int $0x80" \
106 );
107
8e4f5035 108#ifdef __NR_rt_sigaction
e0082312
UD
109/* The return code for realtime-signals. */
110RESTORE (restore_rt, __NR_rt_sigreturn)
8e4f5035 111#endif
e0082312
UD
112
113/* For the boring old signals. */
8e4f5035
UD
114#undef RESTORE2
115#define RESTORE2(name, syscall) \
e0082312
UD
116asm \
117 ( \
4dbb6417
UD
118 ".text\n" \
119 " .align 8\n" \
adcf0e4a 120 "__" #name ":\n" \
e0082312
UD
121 " popl %eax\n" \
122 " movl $" #syscall ", %eax\n" \
123 " int $0x80" \
124 );
125
126RESTORE (restore, __NR_sigreturn)