OSDN Git Service

22d4248f34069e8105bbae6a8592d406e5091239
[uclinux-h8/uClibc.git] / libc / sysdeps / linux / arm / sigaction.c
1 /* Copyright (C) 1997,1998,1999,2000,2002,2003 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    Totally hacked up for uClibc by Erik Andersen <andersen@codepoet.org>
19    */
20
21 #include <errno.h>
22 #include <signal.h>
23 #include <string.h>
24 #include <sys/syscall.h>
25 #include <bits/kernel_sigaction.h>
26
27 #define SA_RESTORER     0x04000000
28 extern void __default_sa_restorer(void);
29 extern void __default_rt_sa_restorer(void);
30
31 /* When RT signals are in use we need to use a different return stub.  */
32 #ifdef __NR_rt_sigreturn
33 #define choose_restorer(flags)                                  \
34         (flags & SA_SIGINFO) ? __default_rt_sa_restorer         \
35         : __default_sa_restorer
36 #else
37 #define choose_restorer(flags)                                  \
38         __default_sa_restorer
39 #endif
40
41
42 #ifdef __NR_rt_sigaction
43
44 /* If ACT is not NULL, change the action for SIG to *ACT.
45    If OACT is not NULL, put the old action for SIG in *OACT.  */
46 int __libc_sigaction(int sig, const struct sigaction *act, struct sigaction *oact)
47 {
48         struct sigaction kact;
49         if (act && !(act->sa_flags & SA_RESTORER)) {
50                 memcpy(&kact, act, sizeof(kact));
51                 kact.sa_restorer = choose_restorer(kact.sa_flags);
52                 kact.sa_flags |= SA_RESTORER;
53                 act = &kact;
54         }
55         /* NB: kernel (as of 2.6.25) will return EINVAL
56          * if sizeof(act->sa_mask) does not match kernel's sizeof(sigset_t) */
57         return __syscall_rt_sigaction(sig, act, oact, sizeof(act->sa_mask));
58 }
59
60 #else
61
62 /* If ACT is not NULL, change the action for SIG to *ACT.
63    If OACT is not NULL, put the old action for SIG in *OACT.  */
64 int __libc_sigaction(int sig, const struct sigaction *act, struct sigaction *oact)
65 {
66         int result;
67         struct old_kernel_sigaction kact, koact;
68
69         if (act) {
70                 kact.k_sa_handler = act->sa_handler;
71                 kact.sa_mask = act->sa_mask.__val[0];
72                 kact.sa_flags = act->sa_flags;
73                 if (kact.sa_flags & SA_RESTORER) {
74                         kact.sa_restorer = act->sa_restorer;
75                 } else {
76                         kact.sa_restorer = choose_restorer(kact.sa_flags);
77                         kact.sa_flags |= SA_RESTORER;
78                 }
79         }
80         result = __syscall_sigaction(sig,
81                         act ? &kact : NULL,
82                         oact ? &koact : NULL);
83         if (oact && result >= 0) {
84                 oact->sa_handler = koact.k_sa_handler;
85                 oact->sa_mask.__val[0] = koact.sa_mask;
86                 oact->sa_flags = koact.sa_flags;
87                 oact->sa_restorer = koact.sa_restorer;
88         }
89         return result;
90 }
91
92 #endif
93
94
95 #ifndef LIBC_SIGACTION
96 # ifndef __UCLIBC_HAS_THREADS__
97 strong_alias(__libc_sigaction,sigaction)
98 libc_hidden_def(sigaction)
99 # else
100 weak_alias(__libc_sigaction,sigaction)
101 libc_hidden_weak(sigaction)
102 # endif
103 #endif