Update copyright notices with scripts/update-copyrights.
[jlayton/glibc.git] / ports / sysdeps / unix / sysv / linux / aarch64 / sigaction.c
1 /* Copyright (C) 1997-2013 Free Software Foundation, Inc.
2
3    This file is part of the GNU C Library.
4
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 License as
7    published by the Free Software Foundation; either version 2.1 of the
8    License, or (at your option) any later version.
9
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.
14
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/>.  */
18
19 #include <errno.h>
20 #include <signal.h>
21 #include <string.h>
22
23 #include <sysdep.h>
24 #include <sys/syscall.h>
25
26 #include <kernel-features.h>
27
28 #define SA_RESTORER     0x04000000
29
30 /* The difference here is that the sigaction structure used in the
31    kernel is not the same as we use in the libc.  Therefore we must
32    translate it here.  */
33 #include <kernel_sigaction.h>
34
35 int
36 __libc_sigaction (int sig, const struct sigaction *act, struct sigaction *oact)
37 {
38   int result;
39   struct kernel_sigaction kact;
40   struct kernel_sigaction koact;
41
42   if (act)
43     {
44       kact.k_sa_handler = act->sa_handler;
45       memcpy (&kact.sa_mask, &act->sa_mask, sizeof (sigset_t));
46       kact.sa_flags = act->sa_flags;
47 #ifdef HAVE_SA_RESTORER
48       if (kact.sa_flags & SA_RESTORER)
49         kact.sa_restorer = act->sa_restorer;
50 #endif
51     }
52
53   result = INLINE_SYSCALL (rt_sigaction, 4, sig,
54                            act ? __ptrvalue (&kact) : NULL,
55                            oact ? __ptrvalue (&koact) : NULL, _NSIG / 8);
56   if (result >= 0 || errno != ENOSYS)
57     {
58       if (oact && result >= 0)
59         {
60           oact->sa_handler = koact.k_sa_handler;
61           memcpy (&oact->sa_mask, &koact.sa_mask, sizeof (sigset_t));
62           oact->sa_flags = koact.sa_flags;
63 #ifdef HAVE_SA_RESTORER
64           oact->sa_restorer = koact.sa_restorer;
65 #endif
66         }
67     }
68   return result;
69 }
70 libc_hidden_def (__libc_sigaction)
71
72 #ifdef WRAPPER_INCLUDE
73 # include WRAPPER_INCLUDE
74 #endif
75
76 #ifndef LIBC_SIGACTION
77 weak_alias (__libc_sigaction, __sigaction)
78 libc_hidden_weak (__sigaction)
79 weak_alias (__libc_sigaction, sigaction)
80 #endif