1 /* POSIX.1 `sigaction' call for Linux/x86-64.
2 Copyright (C) 2001, 2002, 2003 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/>. */
25 #include <sys/syscall.h>
27 #include <bits/kernel_sigaction.h>
29 /* We do not globally define the SA_RESTORER flag so do it here. */
30 #define SA_RESTORER 0x04000000
32 #ifdef __NR_rt_sigaction
34 /* Using the hidden attribute here does not change the code but it
35 helps to avoid warnings. */
36 extern void restore_rt(void) __asm__ ("__restore_rt") attribute_hidden;
37 extern void restore(void) __asm__ ("__restore") attribute_hidden;
39 /* If ACT is not NULL, change the action for SIG to *ACT.
40 If OACT is not NULL, put the old action for SIG in *OACT. */
42 __libc_sigaction(int sig, const struct sigaction *act, struct sigaction *oact)
44 struct sigaction kact;
47 memcpy(&kact, act, sizeof(kact));
48 kact.sa_flags |= SA_RESTORER;
49 kact.sa_restorer = &restore_rt;
52 /* NB: kernel (as of 2.6.25) will return EINVAL
53 * if sizeof(act->sa_mask) does not match kernel's sizeof(sigset_t) */
54 return INLINE_SYSCALL(rt_sigaction, 4, sig, act, oact, sizeof(act->sa_mask));
59 extern void restore(void) __asm__ ("__restore") attribute_hidden;
61 /* If ACT is not NULL, change the action for SIG to *ACT.
62 If OACT is not NULL, put the old action for SIG in *OACT. */
64 __libc_sigaction(int sig, const struct sigaction *act, struct sigaction *oact)
67 struct old_kernel_sigaction kact, koact;
70 kact.k_sa_handler = act->sa_handler;
71 kact.sa_mask = act->sa_mask.__val[0];
72 kact.sa_flags = act->sa_flags | SA_RESTORER;
73 kact.sa_restorer = &restore;
75 __asm__ __volatile__ (
78 : "0" (__NR_sigaction), "mr" (sig),
79 "c" (act ? &kact : NULL),
80 "d" (oact ? &koact : NULL));
86 oact->sa_handler = koact.k_sa_handler;
87 oact->sa_mask.__val[0] = koact.sa_mask;
88 oact->sa_flags = koact.sa_flags;
89 oact->sa_restorer = koact.sa_restorer;
97 #ifndef LIBC_SIGACTION
98 # ifndef __UCLIBC_HAS_THREADS__
99 strong_alias(__libc_sigaction,sigaction)
100 libc_hidden_def(sigaction)
102 weak_alias(__libc_sigaction,sigaction)
103 libc_hidden_weak(sigaction)
108 /* NOTE: Please think twice before making any changes to the bits of
109 code below. GDB needs some intimate knowledge about it to
110 recognize them as signal trampolines, and make backtraces through
111 signal handlers work right. Important are both the names
112 (__restore_rt) and the exact instruction sequence.
113 If you ever feel the need to make any changes, please notify the
114 appropriate GDB maintainer.
116 The unwind information starts a byte before __restore_rt, so that
117 it is found when unwinding, to get an address the unwinder assumes
118 will be in the middle of a call instruction. See the Linux kernel
119 (the i386 vsyscall, in particular) for an explanation of the complex
120 unwind information used here in order to get the traditional CFA.
123 #define RESTORE(name, syscall) RESTORE2(name, syscall)
124 #define RESTORE2(name, syscall) \
129 " movq $" #syscall ", %rax\n" \
133 #ifdef __NR_rt_sigaction
134 /* The return code for realtime-signals. */
135 RESTORE(restore_rt, __NR_rt_sigreturn)
137 #ifdef __NR_sigreturn
138 RESTORE(restore, __NR_sigreturn)