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