Update copyright notices with scripts/update-copyrights.
[jlayton/glibc.git] / ports / sysdeps / unix / sysv / linux / arm / sigaction.c
1 /* Copyright (C) 1997-2013 Free Software Foundation, Inc.
2    This file is part of the GNU C Library.
3
4    The GNU C Library is free software; you can redistribute it and/or
5    modify it under the terms of the GNU Lesser General Public
6    License as published by the Free Software Foundation; either
7    version 2.1 of the License, or (at your option) any later version.
8
9    The GNU C Library is distributed in the hope that it will be useful,
10    but WITHOUT ANY WARRANTY; without even the implied warranty of
11    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12    Lesser General Public License for more details.
13
14    You should have received a copy of the GNU Lesser General Public
15    License along with the GNU C Library.  If not, see
16    <http://www.gnu.org/licenses/>.  */
17
18 #include <errno.h>
19 #include <signal.h>
20 #include <string.h>
21
22 #include <sysdep.h>
23 #include <sys/syscall.h>
24 #include <kernel-features.h>
25
26 /* The difference here is that the sigaction structure used in the
27    kernel is not the same as we use in the libc.  Therefore we must
28    translate it here.  */
29 #include <kernel_sigaction.h>
30
31 #define SA_RESTORER     0x04000000
32
33 extern void __default_sa_restorer_v1(void);
34 extern void __default_sa_restorer_v2(void);
35 extern void __default_rt_sa_restorer_v1(void);
36 extern void __default_rt_sa_restorer_v2(void);
37 #ifdef __ASSUME_SIGFRAME_V2
38 # define __default_sa_restorer __default_sa_restorer_v2
39 # define __default_rt_sa_restorer __default_rt_sa_restorer_v2
40 #else
41 # include <ldsodefs.h>
42 # define __default_sa_restorer (GLRO(dl_osversion) >= 0x020612  \
43                                  ? __default_sa_restorer_v2     \
44                                  : __default_sa_restorer_v1)
45 # define __default_rt_sa_restorer (GLRO(dl_osversion) >= 0x020612       \
46                                     ? __default_rt_sa_restorer_v2       \
47                                     : __default_rt_sa_restorer_v1)
48 #endif
49
50 /* When RT signals are in use we need to use a different return stub.  */
51 #define choose_restorer(flags)                                  \
52   (flags & SA_SIGINFO) ? __default_rt_sa_restorer               \
53   : __default_sa_restorer
54
55 /* If ACT is not NULL, change the action for SIG to *ACT.
56    If OACT is not NULL, put the old action for SIG in *OACT.  */
57 int
58 __libc_sigaction (sig, act, oact)
59      int sig;
60      const struct sigaction *act;
61      struct sigaction *oact;
62 {
63   int result;
64
65   struct kernel_sigaction kact, koact;
66
67   if (act)
68     {
69       kact.k_sa_handler = act->sa_handler;
70       memcpy (&kact.sa_mask, &act->sa_mask, sizeof (sigset_t));
71       kact.sa_flags = act->sa_flags;
72 #ifdef HAVE_SA_RESTORER
73       if (kact.sa_flags & SA_RESTORER)
74         kact.sa_restorer = act->sa_restorer;
75       else
76         {
77           kact.sa_restorer = choose_restorer (kact.sa_flags);
78           kact.sa_flags |= SA_RESTORER;
79         }
80 #endif
81     }
82
83   /* XXX The size argument hopefully will have to be changed to the
84      real size of the user-level sigset_t.  */
85   result = INLINE_SYSCALL (rt_sigaction, 4, sig,
86                            act ? __ptrvalue (&kact) : NULL,
87                            oact ? __ptrvalue (&koact) : NULL, _NSIG / 8);
88
89   if (oact && result >= 0)
90     {
91       oact->sa_handler = koact.k_sa_handler;
92       memcpy (&oact->sa_mask, &koact.sa_mask, sizeof (sigset_t));
93       oact->sa_flags = koact.sa_flags;
94 #ifdef HAVE_SA_RESTORER
95       oact->sa_restorer = koact.sa_restorer;
96 #endif
97     }
98   return result;
99 }
100 libc_hidden_def (__libc_sigaction)
101
102 #ifdef WRAPPER_INCLUDE
103 # include WRAPPER_INCLUDE
104 #endif
105
106 #ifndef LIBC_SIGACTION
107 weak_alias (__libc_sigaction, __sigaction)
108 libc_hidden_weak (__sigaction)
109 weak_alias (__libc_sigaction, sigaction)
110 #endif