(CFLAGS-tst-align.c): Add -mpreferred-stack-boundary=4.
[glibc.git] / sysdeps / unix / sysv / linux / x86_64 / sigaction.c
blob91230470925690490169497ce550bdaedebd9cdb
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
18 02111-1307 USA. */
20 #include <sysdep.h>
21 #include <errno.h>
22 #include <stddef.h>
23 #include <signal.h>
24 #include <string.h>
26 #include <sysdep.h>
27 #include <sys/syscall.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
39 /* Using the hidden attribute here does not change the code but it
40 helps to avoid warnings. */
41 #if defined HAVE_HIDDEN && defined HAVE_VISIBILITY_ATTRIBUTE \
42 && !defined HAVE_BROKEN_VISIBILITY_ATTRIBUTE
43 extern void restore_rt (void) asm ("__restore_rt") attribute_hidden;
44 #else
45 static void restore_rt (void) asm ("__restore_rt");
46 #endif
49 /* If ACT is not NULL, change the action for SIG to *ACT.
50 If OACT is not NULL, put the old action for SIG in *OACT. */
51 int
52 __libc_sigaction (int sig, const struct sigaction *act, struct sigaction *oact)
54 int result;
55 struct kernel_sigaction kact, koact;
57 if (act)
59 kact.k_sa_handler = act->sa_handler;
60 memcpy (&kact.sa_mask, &act->sa_mask, sizeof (sigset_t));
61 kact.sa_flags = act->sa_flags | SA_RESTORER;
63 kact.sa_restorer = &restore_rt;
66 /* XXX The size argument hopefully will have to be changed to the
67 real size of the user-level sigset_t. */
68 result = INLINE_SYSCALL (rt_sigaction, 4,
69 sig, act ? __ptrvalue (&kact) : NULL,
70 oact ? __ptrvalue (&koact) : NULL, _NSIG / 8);
71 if (oact && result >= 0)
73 oact->sa_handler = koact.k_sa_handler;
74 memcpy (&oact->sa_mask, &koact.sa_mask, sizeof (sigset_t));
75 oact->sa_flags = koact.sa_flags;
76 oact->sa_restorer = koact.sa_restorer;
78 return result;
80 libc_hidden_def (__libc_sigaction)
82 #ifndef LIBC_SIGACTION
83 weak_alias (__libc_sigaction, __sigaction)
84 libc_hidden_weak (__sigaction)
85 weak_alias (__libc_sigaction, sigaction)
86 #endif
88 /* NOTE: Please think twice before making any changes to the bits of
89 code below. GDB needs some intimate knowledge about it to
90 recognize them as signal trampolines, and make backtraces through
91 signal handlers work right. Important are both the names
92 (__restore_rt) and the exact instruction sequence.
93 If you ever feel the need to make any changes, please notify the
94 appropriate GDB maintainer. */
96 #define RESTORE(name, syscall) RESTORE2 (name, syscall)
97 # define RESTORE2(name, syscall) \
98 asm \
99 ( \
100 ".align 16\n" \
101 CFI_STARTPROC "\n" \
102 "__" #name ":\n" \
103 " movq $" #syscall ", %rax\n" \
104 " syscall\n" \
105 CFI_ENDPROC "\n" \
107 /* The return code for realtime-signals. */
108 RESTORE (restore_rt, __NR_rt_sigreturn)