2011-02-12 00:22:29 -05:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <signal.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include "syscall.h"
|
|
|
|
#include "pthread_impl.h"
|
2012-02-27 18:51:02 -05:00
|
|
|
#include "libc.h"
|
2012-07-11 02:44:14 -04:00
|
|
|
#include "ksigaction.h"
|
2011-02-12 00:22:29 -05:00
|
|
|
|
2011-02-13 19:01:43 -05:00
|
|
|
void __restore(), __restore_rt();
|
2011-02-12 00:22:29 -05:00
|
|
|
|
2012-02-27 18:51:02 -05:00
|
|
|
static pthread_t dummy(void) { return 0; }
|
|
|
|
weak_alias(dummy, __pthread_self_def);
|
|
|
|
|
2011-02-12 00:22:29 -05:00
|
|
|
int __libc_sigaction(int sig, const struct sigaction *sa, struct sigaction *old)
|
|
|
|
{
|
2012-07-11 03:20:43 -04:00
|
|
|
struct k_sigaction ksa;
|
2011-02-12 00:22:29 -05:00
|
|
|
if (sa) {
|
|
|
|
ksa.handler = sa->sa_handler;
|
2011-02-13 16:46:33 -05:00
|
|
|
ksa.flags = sa->sa_flags | SA_RESTORER;
|
2011-02-13 19:01:43 -05:00
|
|
|
ksa.restorer = (sa->sa_flags & SA_SIGINFO) ? __restore_rt : __restore;
|
2012-07-11 02:44:14 -04:00
|
|
|
memcpy(&ksa.mask, &sa->sa_mask, sizeof ksa.mask);
|
2011-02-12 00:22:29 -05:00
|
|
|
}
|
2012-02-27 18:51:02 -05:00
|
|
|
__pthread_self_def();
|
2012-07-11 02:44:14 -04:00
|
|
|
if (syscall(SYS_rt_sigaction, sig, sa?&ksa:0, old?&ksa:0, sizeof ksa.mask))
|
2011-02-12 00:22:29 -05:00
|
|
|
return -1;
|
|
|
|
if (old) {
|
2012-07-11 02:44:14 -04:00
|
|
|
old->sa_handler = ksa.handler;
|
|
|
|
old->sa_flags = ksa.flags;
|
|
|
|
memcpy(&old->sa_mask, &ksa.mask, sizeof ksa.mask);
|
2011-02-12 00:22:29 -05:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int __sigaction(int sig, const struct sigaction *sa, struct sigaction *old)
|
|
|
|
{
|
overhaul implementation-internal signal protections
the new approach relies on the fact that the only ways to create
sigset_t objects without invoking UB are to use the sig*set()
functions, or from the masks returned by sigprocmask, sigaction, etc.
or in the ucontext_t argument to a signal handler. thus, as long as
sigfillset and sigaddset avoid adding the "protected" signals, there
is no way the application will ever obtain a sigset_t including these
bits, and thus no need to add the overhead of checking/clearing them
when sigprocmask or sigaction is called.
note that the old code actually *failed* to remove the bits from
sa_mask when sigaction was called.
the new implementations are also significantly smaller, simpler, and
faster due to ignoring the useless "GNU HURD signals" 65-1024, which
are not used and, if there's any sanity in the world, never will be
used.
2011-05-07 23:23:58 -04:00
|
|
|
if (sig-32U < 3) {
|
2011-02-12 00:22:29 -05:00
|
|
|
errno = EINVAL;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
return __libc_sigaction(sig, sa, old);
|
|
|
|
}
|
|
|
|
|
|
|
|
weak_alias(__sigaction, sigaction);
|