OLD | NEW |
1 #include <signal.h> | 1 #include <signal.h> |
2 #include <errno.h> | 2 #include <errno.h> |
3 #include <string.h> | 3 #include <string.h> |
4 #include "syscall.h" | 4 #include "syscall.h" |
5 #include "pthread_impl.h" | 5 #include "pthread_impl.h" |
6 #include "libc.h" | 6 #include "libc.h" |
7 #include "ksigaction.h" | 7 #include "ksigaction.h" |
8 | 8 |
9 static int unmask_done; | 9 static int unmask_done; |
10 static unsigned long handler_set[_NSIG/(8*sizeof(long))]; | 10 static unsigned long handler_set[_NSIG / (8 * sizeof(long))]; |
11 | 11 |
12 void __get_handler_set(sigset_t *set) | 12 void __get_handler_set(sigset_t* set) { |
13 { | 13 memcpy(set, handler_set, sizeof handler_set); |
14 » memcpy(set, handler_set, sizeof handler_set); | |
15 } | 14 } |
16 | 15 |
17 int __libc_sigaction(int sig, const struct sigaction *restrict sa, struct sigact
ion *restrict old) | 16 int __libc_sigaction(int sig, |
18 { | 17 const struct sigaction* restrict sa, |
19 » struct k_sigaction ksa, ksa_old; | 18 struct sigaction* restrict old) { |
20 » if (sa) { | 19 struct k_sigaction ksa, ksa_old; |
21 » » if ((uintptr_t)sa->sa_handler > 1UL) { | 20 if (sa) { |
22 » » » a_or_l(handler_set+(sig-1)/(8*sizeof(long)), | 21 if ((uintptr_t)sa->sa_handler > 1UL) { |
23 » » » » 1UL<<(sig-1)%(8*sizeof(long))); | 22 a_or_l(handler_set + (sig - 1) / (8 * sizeof(long)), |
| 23 1UL << (sig - 1) % (8 * sizeof(long))); |
24 | 24 |
25 » » » /* If pthread_create has not yet been called, | 25 /* If pthread_create has not yet been called, |
26 » » » * implementation-internal signals might not | 26 * implementation-internal signals might not |
27 » » » * yet have been unblocked. They must be | 27 * yet have been unblocked. They must be |
28 » » » * unblocked before any signal handler is | 28 * unblocked before any signal handler is |
29 » » » * installed, so that an application cannot | 29 * installed, so that an application cannot |
30 » » » * receive an illegal sigset_t (with them | 30 * receive an illegal sigset_t (with them |
31 » » » * blocked) as part of the ucontext_t passed | 31 * blocked) as part of the ucontext_t passed |
32 » » » * to the signal handler. */ | 32 * to the signal handler. */ |
33 » » » if (!libc.threaded && !unmask_done) { | 33 if (!libc.threaded && !unmask_done) { |
34 » » » » __syscall(SYS_rt_sigprocmask, SIG_UNBLOCK, | 34 __syscall(SYS_rt_sigprocmask, SIG_UNBLOCK, SIGPT_SET, 0, _NSIG / 8); |
35 » » » » » SIGPT_SET, 0, _NSIG/8); | 35 unmask_done = 1; |
36 » » » » unmask_done = 1; | 36 } |
37 » » » } | 37 } |
38 » » } | 38 ksa.handler = sa->sa_handler; |
39 » » ksa.handler = sa->sa_handler; | 39 ksa.flags = sa->sa_flags | SA_RESTORER; |
40 » » ksa.flags = sa->sa_flags | SA_RESTORER; | 40 ksa.restorer = (sa->sa_flags & SA_SIGINFO) ? __restore_rt : __restore; |
41 » » ksa.restorer = (sa->sa_flags & SA_SIGINFO) ? __restore_rt : __re
store; | 41 memcpy(&ksa.mask, &sa->sa_mask, sizeof ksa.mask); |
42 » » memcpy(&ksa.mask, &sa->sa_mask, sizeof ksa.mask); | 42 } |
43 » } | 43 if (syscall(SYS_rt_sigaction, sig, sa ? &ksa : 0, old ? &ksa_old : 0, |
44 » if (syscall(SYS_rt_sigaction, sig, sa?&ksa:0, old?&ksa_old:0, sizeof ksa
.mask)) | 44 sizeof ksa.mask)) |
45 » » return -1; | 45 return -1; |
46 » if (old) { | 46 if (old) { |
47 » » old->sa_handler = ksa_old.handler; | 47 old->sa_handler = ksa_old.handler; |
48 » » old->sa_flags = ksa_old.flags; | 48 old->sa_flags = ksa_old.flags; |
49 » » memcpy(&old->sa_mask, &ksa_old.mask, sizeof ksa_old.mask); | 49 memcpy(&old->sa_mask, &ksa_old.mask, sizeof ksa_old.mask); |
50 » } | 50 } |
51 » return 0; | 51 return 0; |
52 } | 52 } |
53 | 53 |
54 int __sigaction(int sig, const struct sigaction *restrict sa, struct sigaction *
restrict old) | 54 int __sigaction(int sig, |
55 { | 55 const struct sigaction* restrict sa, |
56 » if (sig-32U < 3 || sig-1U >= _NSIG-1) { | 56 struct sigaction* restrict old) { |
57 » » errno = EINVAL; | 57 if (sig - 32U < 3 || sig - 1U >= _NSIG - 1) { |
58 » » return -1; | 58 errno = EINVAL; |
59 » } | 59 return -1; |
60 » return __libc_sigaction(sig, sa, old); | 60 } |
| 61 return __libc_sigaction(sig, sa, old); |
61 } | 62 } |
62 | 63 |
63 weak_alias(__sigaction, sigaction); | 64 weak_alias(__sigaction, sigaction); |
OLD | NEW |