Update copyright notices with scripts/update-copyrights
[glibc.git] / sysdeps / unix / sysv / linux / i386 / sigaction.c
bloba901bc6bcee74af29b9f319199873d209a0ee592
1 /* POSIX.1 `sigaction' call for Linux/i386.
2 Copyright (C) 1991-2014 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, see
17 <http://www.gnu.org/licenses/>. */
19 #include <sysdep.h>
20 #include <errno.h>
21 #include <stddef.h>
22 #include <signal.h>
23 #include <string.h>
25 #include <sysdep.h>
26 #include <sys/syscall.h>
27 #include <ldsodefs.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
33 translate it here. */
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 /* Using the hidden attribute here does not change the code but it
41 helps to avoid warnings. */
42 #ifdef __NR_rt_sigaction
43 extern void restore_rt (void) asm ("__restore_rt") attribute_hidden;
44 #endif
45 extern void restore (void) asm ("__restore") attribute_hidden;
48 /* If ACT is not NULL, change the action for SIG to *ACT.
49 If OACT is not NULL, put the old action for SIG in *OACT. */
50 int
51 __libc_sigaction (int sig, const struct sigaction *act, struct sigaction *oact)
53 int result;
55 struct kernel_sigaction kact, koact;
57 if (act)
59 kact.k_sa_handler = act->sa_handler;
60 kact.sa_flags = act->sa_flags;
61 memcpy (&kact.sa_mask, &act->sa_mask, sizeof (sigset_t));
63 if (GLRO(dl_sysinfo_dso) == NULL)
65 kact.sa_flags |= SA_RESTORER;
67 kact.sa_restorer = ((act->sa_flags & SA_SIGINFO)
68 ? &restore_rt : &restore);
72 /* XXX The size argument hopefully will have to be changed to the
73 real size of the user-level sigset_t. */
74 result = INLINE_SYSCALL (rt_sigaction, 4,
75 sig, act ? &kact : NULL,
76 oact ? &koact : NULL, _NSIG / 8);
78 if (oact && result >= 0)
80 oact->sa_handler = koact.k_sa_handler;
81 memcpy (&oact->sa_mask, &koact.sa_mask, sizeof (sigset_t));
82 oact->sa_flags = koact.sa_flags;
83 oact->sa_restorer = koact.sa_restorer;
85 return result;
87 libc_hidden_def (__libc_sigaction)
89 #ifdef WRAPPER_INCLUDE
90 # include WRAPPER_INCLUDE
91 #endif
93 #ifndef LIBC_SIGACTION
94 weak_alias (__libc_sigaction, __sigaction)
95 libc_hidden_weak (__sigaction)
96 weak_alias (__libc_sigaction, sigaction)
97 #endif
99 /* NOTE: Please think twice before making any changes to the bits of
100 code below. GDB needs some intimate knowledge about it to
101 recognize them as signal trampolines, and make backtraces through
102 signal handlers work right. Important are both the names
103 (__restore and __restore_rt) and the exact instruction sequence.
104 If you ever feel the need to make any changes, please notify the
105 appropriate GDB maintainer. */
107 #define RESTORE(name, syscall) RESTORE2 (name, syscall)
108 #define RESTORE2(name, syscall) \
109 asm \
111 ".text\n" \
112 " .align 16\n" \
113 "__" #name ":\n" \
114 " movl $" #syscall ", %eax\n" \
115 " int $0x80" \
118 #ifdef __NR_rt_sigaction
119 /* The return code for realtime-signals. */
120 RESTORE (restore_rt, __NR_rt_sigreturn)
121 #endif
123 /* For the boring old signals. */
124 #undef RESTORE2
125 #define RESTORE2(name, syscall) \
126 asm \
128 ".text\n" \
129 " .align 8\n" \
130 "__" #name ":\n" \
131 " popl %eax\n" \
132 " movl $" #syscall ", %eax\n" \
133 " int $0x80" \
136 RESTORE (restore, __NR_sigreturn)