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, write to the Free
17 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
26 #include <sys/syscall.h>
28 #include <bits/kernel_sigaction.h>
30 /* We do not globally define the SA_RESTORER flag so do it here. */
31 #define SA_RESTORER 0x04000000
33 extern __typeof(sigaction) __libc_sigaction;
36 #ifdef __NR_rt_sigaction
38 /* Using the hidden attribute here does not change the code but it
39 helps to avoid warnings. */
40 extern void restore_rt(void) __asm__ ("__restore_rt") attribute_hidden;
41 extern void restore(void) __asm__ ("__restore") attribute_hidden;
43 /* If ACT is not NULL, change the action for SIG to *ACT.
44 If OACT is not NULL, put the old action for SIG in *OACT. */
46 __libc_sigaction(int sig, const struct sigaction *act, struct sigaction *oact)
48 struct sigaction kact;
51 memcpy(&kact, act, sizeof(kact));
52 kact.sa_flags |= SA_RESTORER;
53 kact.sa_restorer = &restore_rt;
56 /* NB: kernel (as of 2.6.25) will return EINVAL
57 * if sizeof(act->sa_mask) does not match kernel's sizeof(sigset_t) */
58 return INLINE_SYSCALL(rt_sigaction, 4, sig, act, oact, sizeof(act->sa_mask));
63 extern void restore(void) __asm__ ("__restore") attribute_hidden;
65 /* If ACT is not NULL, change the action for SIG to *ACT.
66 If OACT is not NULL, put the old action for SIG in *OACT. */
68 __libc_sigaction(int sig, const struct sigaction *act, struct sigaction *oact)
71 struct old_kernel_sigaction kact, koact;
74 if (sig == SIGCANCEL) {
81 kact.k_sa_handler = act->sa_handler;
82 kact.sa_mask = act->sa_mask.__val[0];
83 kact.sa_flags = act->sa_flags | SA_RESTORER;
84 kact.sa_restorer = &restore;
86 __asm__ __volatile__ (
89 : "0" (__NR_sigaction), "mr" (sig),
90 "c" (act ? &kact : NULL),
91 "d" (oact ? &koact : NULL));
97 oact->sa_handler = koact.k_sa_handler;
98 oact->sa_mask.__val[0] = koact.sa_mask;
99 oact->sa_flags = koact.sa_flags;
100 oact->sa_restorer = koact.sa_restorer;
108 #ifndef LIBC_SIGACTION
109 weak_alias(__libc_sigaction,sigaction)
110 libc_hidden_weak(sigaction)
114 /* NOTE: Please think twice before making any changes to the bits of
115 code below. GDB needs some intimate knowledge about it to
116 recognize them as signal trampolines, and make backtraces through
117 signal handlers work right. Important are both the names
118 (__restore_rt) and the exact instruction sequence.
119 If you ever feel the need to make any changes, please notify the
120 appropriate GDB maintainer. */
122 #define RESTORE(name, syscall) RESTORE2(name, syscall)
123 #define RESTORE2(name, syscall) \
127 " movq $" #syscall ", %rax\n" \
131 #ifdef __NR_rt_sigaction
132 /* The return code for realtime-signals. */
133 RESTORE(restore_rt, __NR_rt_sigreturn)
135 #ifdef __NR_sigreturn
136 RESTORE(restore, __NR_sigreturn)