5 #include "pthread_impl.h"
7 #include "ksigaction.h"
9 volatile int dummy_lock[1] = { 0 };
11 extern hidden volatile int __abort_lock[1];
13 weak_alias(dummy_lock, __abort_lock);
15 static int unmask_done;
16 static unsigned long handler_set[_NSIG/(8*sizeof(long))];
18 void __get_handler_set(sigset_t *set)
20 memcpy(set, handler_set, sizeof handler_set);
23 int __libc_sigaction(int sig, const struct sigaction *restrict sa, struct sigaction *restrict old)
25 struct k_sigaction ksa, ksa_old;
26 unsigned long set[_NSIG/(8*sizeof(long))];
28 if ((uintptr_t)sa->sa_handler > 1UL) {
29 a_or_l(handler_set+(sig-1)/(8*sizeof(long)),
30 1UL<<(sig-1)%(8*sizeof(long)));
32 /* If pthread_create has not yet been called,
33 * implementation-internal signals might not
34 * yet have been unblocked. They must be
35 * unblocked before any signal handler is
36 * installed, so that an application cannot
37 * receive an illegal sigset_t (with them
38 * blocked) as part of the ucontext_t passed
39 * to the signal handler. */
40 if (!libc.threaded && !unmask_done) {
41 __syscall(SYS_rt_sigprocmask, SIG_UNBLOCK,
42 SIGPT_SET, 0, _NSIG/8);
46 /* Changing the disposition of SIGABRT to anything but
47 * SIG_DFL requires a lock, so that it cannot be changed
48 * while abort is terminating the process after simply
49 * calling raise(SIGABRT) failed to do so. */
50 if (sa->sa_handler != SIG_DFL && sig == SIGABRT) {
51 __block_all_sigs(&set);
54 ksa.handler = sa->sa_handler;
55 ksa.flags = sa->sa_flags | SA_RESTORER;
56 ksa.restorer = (sa->sa_flags & SA_SIGINFO) ? __restore_rt : __restore;
57 memcpy(&ksa.mask, &sa->sa_mask, _NSIG/8);
59 int r = __syscall(SYS_rt_sigaction, sig, sa?&ksa:0, old?&ksa_old:0, _NSIG/8);
60 if (sig == SIGABRT && sa && sa->sa_handler != SIG_DFL) {
65 old->sa_handler = ksa_old.handler;
66 old->sa_flags = ksa_old.flags;
67 memcpy(&old->sa_mask, &ksa_old.mask, _NSIG/8);
69 return __syscall_ret(r);
72 int __sigaction(int sig, const struct sigaction *restrict sa, struct sigaction *restrict old)
74 if (sig-32U < 3 || sig-1U >= _NSIG-1) {
78 return __libc_sigaction(sig, sa, old);
81 weak_alias(__sigaction, sigaction);