5 #include "pthread_impl.h"
7 #include "ksigaction.h"
9 static int unmask_done;
10 static unsigned long handler_set[_NSIG/(8*sizeof(long))];
12 void __get_handler_set(sigset_t *set)
14 memcpy(set, handler_set, sizeof handler_set);
17 int __libc_sigaction(int sig, const struct sigaction *restrict sa, struct sigaction *restrict old)
19 struct k_sigaction ksa, ksa_old;
20 if (sig >= (unsigned)_NSIG) {
25 if ((uintptr_t)sa->sa_handler > 1UL) {
26 a_or_l(handler_set+(sig-1)/(8*sizeof(long)),
27 1UL<<(sig-1)%(8*sizeof(long)));
29 /* If pthread_create has not yet been called,
30 * implementation-internal signals might not
31 * yet have been unblocked. They must be
32 * unblocked before any signal handler is
33 * installed, so that an application cannot
34 * receive an illegal sigset_t (with them
35 * blocked) as part of the ucontext_t passed
36 * to the signal handler. */
37 if (!libc.threaded && !unmask_done) {
38 __syscall(SYS_rt_sigprocmask, SIG_UNBLOCK,
39 SIGPT_SET, 0, _NSIG/8);
43 ksa.handler = sa->sa_handler;
44 ksa.flags = sa->sa_flags | SA_RESTORER;
45 ksa.restorer = (sa->sa_flags & SA_SIGINFO) ? __restore_rt : __restore;
46 memcpy(&ksa.mask, &sa->sa_mask, sizeof ksa.mask);
48 if (syscall(SYS_rt_sigaction, sig, sa?&ksa:0, old?&ksa_old:0, sizeof ksa.mask))
51 old->sa_handler = ksa_old.handler;
52 old->sa_flags = ksa_old.flags;
53 memcpy(&old->sa_mask, &ksa_old.mask, sizeof ksa_old.mask);
58 int __sigaction(int sig, const struct sigaction *restrict sa, struct sigaction *restrict old)
64 return __libc_sigaction(sig, sa, old);
67 weak_alias(__sigaction, sigaction);