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
27 #include <sys/syscall.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
34 #include <bits/kernel_sigaction.h>
36 /* We do not globally define the SA_RESTORER flag so do it here. */
37 #define SA_RESTORER 0x04000000
39 #if defined __NR_rt_sigaction
40 /* Using the hidden attribute here does not change the code but it
41 helps to avoid warnings. */
42 extern void restore_rt (void) asm ("__restore_rt") attribute_hidden;
43 extern void restore (void) asm ("__restore") attribute_hidden;
45 /* If ACT is not NULL, change the action for SIG to *ACT.
46 If OACT is not NULL, put the old action for SIG in *OACT. */
47 /* psm: couldn't use __sigaction, if building w/ disabled hidden,
48 * it will conflict w/ the one in libpthread */
50 __sigaction_internal (int sig, const struct sigaction *act, struct sigaction *oact)
53 struct kernel_sigaction kact, koact;
56 kact.k_sa_handler = act->sa_handler;
57 __memcpy (&kact.sa_mask, &act->sa_mask, sizeof (sigset_t));
58 kact.sa_flags = act->sa_flags | SA_RESTORER;
60 kact.sa_restorer = &restore_rt;
63 /* XXX The size argument hopefully will have to be changed to the
64 real size of the user-level sigset_t. */
65 result = INLINE_SYSCALL (rt_sigaction, 4,
66 sig, act ? __ptrvalue (&kact) : NULL,
67 oact ? __ptrvalue (&koact) : NULL, _NSIG / 8);
68 if (oact && result >= 0) {
69 oact->sa_handler = koact.k_sa_handler;
70 __memcpy (&oact->sa_mask, &koact.sa_mask, sizeof (sigset_t));
71 oact->sa_flags = koact.sa_flags;
72 oact->sa_restorer = koact.sa_restorer;
78 extern void restore (void) asm ("__restore") attribute_hidden;
80 /* If ACT is not NULL, change the action for SIG to *ACT.
81 If OACT is not NULL, put the old action for SIG in *OACT. */
83 __sigaction_internal (int sig, const struct sigaction *act, struct sigaction *oact)
86 struct old_kernel_sigaction kact, koact;
89 if (sig == SIGCANCEL) {
96 kact.k_sa_handler = act->sa_handler;
97 kact.sa_mask = act->sa_mask.__val[0];
98 kact.sa_flags = act->sa_flags | SA_RESTORER;
99 kact.sa_restorer = &restore;
102 asm volatile ("syscall\n"
104 : "0" (__NR_sigaction), "mr" (sig),
105 "c" (act ? __ptrvalue (&kact) : 0),
106 "d" (oact ? __ptrvalue (&koact) : 0));
109 __set_errno(-result);
114 oact->sa_handler = koact.k_sa_handler;
115 oact->sa_mask.__val[0] = koact.sa_mask;
116 oact->sa_flags = koact.sa_flags;
117 oact->sa_restorer = koact.sa_restorer;
122 strong_alias(__sigaction_internal,__libc_sigaction)
123 weak_alias(__sigaction_internal,sigaction)
125 /* NOTE: Please think twice before making any changes to the bits of
126 code below. GDB needs some intimate knowledge about it to
127 recognize them as signal trampolines, and make backtraces through
128 signal handlers work right. Important are both the names
129 (__restore_rt) and the exact instruction sequence.
130 If you ever feel the need to make any changes, please notify the
131 appropriate GDB maintainer. */
133 #define RESTORE(name, syscall) RESTORE2 (name, syscall)
134 # define RESTORE2(name, syscall) \
140 " movq $" #syscall ", %rax\n" \
143 #ifdef __NR_rt_sigaction
144 /* The return code for realtime-signals. */
145 RESTORE (restore_rt, __NR_rt_sigreturn)
147 #ifdef __NR_sigreturn
148 RESTORE (restore, __NR_sigreturn)