2011-02-12 00:22:29 -05:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <signal.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include "syscall.h"
|
|
|
|
#include "pthread_impl.h"
|
|
|
|
|
2011-02-13 19:01:43 -05:00
|
|
|
void __restore(), __restore_rt();
|
2011-02-12 00:22:29 -05:00
|
|
|
|
|
|
|
int __libc_sigaction(int sig, const struct sigaction *sa, struct sigaction *old)
|
|
|
|
{
|
|
|
|
struct {
|
|
|
|
void *handler;
|
|
|
|
unsigned long flags;
|
|
|
|
void (*restorer)(void);
|
|
|
|
sigset_t mask;
|
|
|
|
} ksa, kold;
|
|
|
|
long pksa=0, pkold=0;
|
|
|
|
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;
|
2011-02-12 00:22:29 -05:00
|
|
|
ksa.mask = sa->sa_mask;
|
|
|
|
pksa = (long)&ksa;
|
|
|
|
}
|
|
|
|
if (old) pkold = (long)&kold;
|
2011-03-20 00:16:43 -04:00
|
|
|
if (syscall(SYS_rt_sigaction, sig, pksa, pkold, 8))
|
2011-02-12 00:22:29 -05:00
|
|
|
return -1;
|
|
|
|
if (old) {
|
|
|
|
old->sa_handler = kold.handler;
|
|
|
|
old->sa_flags = kold.flags;
|
|
|
|
old->sa_mask = kold.mask;
|
|
|
|
}
|
|
|
|
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);
|