1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103
|
/* Signal handling code for Linux/SPARC */
/* Miguel de Icaza -- miguel@nuclecu.unam.mx */
#include <syscall.h>
#include <sys/signal.h>
#include <errno.h>
extern void ____sparc_signal_trampoline (int);
long ____sig_table [NSIG];
int
__trampoline_sigaction(int sig,struct sigaction * new, struct sigaction * old)
{
int ret;
int need_to_hide_trick = 0;
__sighandler_t old_sh;
if (new){
if (new->sa_handler != SIG_DFL && new->sa_handler != SIG_IGN){
old_sh = ____sig_table [sig];
____sig_table [sig] = (long) new->sa_handler;
new->sa_handler = ____sparc_signal_trampoline;
need_to_hide_trick = 1;
}
}
__asm__("or %%g0,%0,%%g1\n\t"
"or %%g0,%1,%%o0\n\t"
"or %%g0,%2,%%o1\n\t"
"or %%g0,%3,%%o2\n\t"
"t 0x10\n\t"
"bcc 1f\n\t"
"or %%o0, %%g0, %0\n\t"
"sub %%g0, %%o0, %0\n\t"
"1:"
: "=r" (ret), "=r" ((long)sig), "=r" ((long) new), "=r" ((long)old)
: "0" (SYS_sigaction), "1" (sig), "2" (new), "3" (old)
: "g1", "o0", "o1", "o2");
if (ret >= 0){
if (old && old->sa_handler == ____sparc_signal_trampoline){
if (need_to_hide_trick)
old->sa_handler = old_sh;
else
old->sa_handler = ____sig_table [sig];
}
if (need_to_hide_trick)
new->sa_handler = ____sig_table [sig];
return 0;
}
errno = -ret;
return -1;
}
int
__new_sigaction (int sig, struct sigaction *new, struct sigaction *old)
{
int ret;
sig = -sig;
__asm__("or %%g0,%0,%%g1\n\t"
"or %%g0,%1,%%o0\n\t"
"or %%g0,%2,%%o1\n\t"
"or %%g0,%3,%%o2\n\t"
"t 0x10\n\t"
"bcc 1f\n\t"
"or %%o0, %%g0, %0\n\t"
"sub %%g0,%%o0,%0\n\t"
"1:"
: "=r" (ret), "=r" ((long)sig), "=r" ((long) new), "=r" ((long)old)
: "0" (SYS_sigaction), "1" (sig), "2" (new), "3" (old)
: "g1", "o0", "o1", "o2");
if (ret >= 0)
return 0;
errno = -ret;
return -1;
}
int
__sigaction (int sig, struct sigaction *new, struct sigaction *old)
{
static (*sigact_routine)(int, struct sigaction *, struct sigaction *);
int ret;
if (sigact_routine)
return (*sigact_routine)(sig, new, old);
{
struct sigaction sa;
ret = __new_sigaction (1, NULL, &sa);
if (ret == -1)
sigact_routine = __trampoline_sigaction;
else
sigact_routine = __new_sigaction;
}
return __sigaction (sig, new, old);
}
#include <gnu-stabs.h>
#ifdef weak_alias
weak_alias (__sigaction, sigaction);
#endif
|