update from main archive 970226
[glibc.git] / sysdeps / unix / sysv / linux / sparc / sigaction.c
blobd39eb7cc762d50a63dcac340c6a9f5594462c576
1 /* POSIX.1 sigaction call for Linux/SPARC.
2 Copyright (C) 1997 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4 Contributed by Miguel de Icaza (miguel@nuclecu.unam.mx), 1997.
6 The GNU C Library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Library General Public License as
8 published by the Free Software Foundation; either version 2 of the
9 License, or (at your option) any later version.
11 The GNU C Library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Library General Public License for more details.
16 You should have received a copy of the GNU Library General Public
17 License along with the GNU C Library; see the file COPYING.LIB. If not,
18 write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
21 #include <syscall.h>
22 #include <sys/signal.h>
23 #include <errno.h>
25 /* Commented out while I figure out what the fuck goes on */
26 long ____sig_table [NSIG];
27 #if 0
29 /* The kernel will deliver signals in the old way if the signal
30 number is a positive number. The kernel will deliver a signal
31 with the new stack layout if the signal number is a negative number.
33 Our sigaction code takes care of selecting the type of kernel we are
34 using at runtime. */
36 extern void ____sparc_signal_trampoline (int);
38 int
39 __trampoline_sigaction (int sig, struct sigaction *new, struct sigaction *old)
41 int ret;
42 int need_to_hide_trick = 0;
43 __sighandler_t old_sh;
45 if (new)
47 if (new->sa_handler != SIG_DFL && new->sa_handler != SIG_IGN)
49 old_sh = ____sig_table[sig];
50 ____sig_table[sig] = (long int) new->sa_handler;
51 new->sa_handler = ____sparc_signal_trampoline;
52 need_to_hide_trick = 1;
55 __asm__("or %%g0,%0,%%g1\n\t"
56 "or %%g0,%1,%%o0\n\t"
57 "or %%g0,%2,%%o1\n\t"
58 "or %%g0,%3,%%o2\n\t"
59 "t 0x10\n\t"
60 "bcc 1f\n\t"
61 "or %%o0, %%g0, %0\n\t"
62 "sub %%g0, %%o0, %0\n\t"
63 "1:"
64 : "=r" (ret), "=r" ((long int) sig), "=r" ((long int) new),
65 "=r" ((long int) old)
66 : "0" (__NR_sigaction), "1" (sig), "2" (new), "3" (old)
67 : "g1", "o0", "o1", "o2");
69 if (ret >= 0)
71 if (old && old->sa_handler == ____sparc_signal_trampoline)
73 if (need_to_hide_trick)
74 old->sa_handler = old_sh;
75 else
76 old->sa_handler = ____sig_table[sig];
78 if (need_to_hide_trick)
79 new->sa_handler = ____sig_table[sig];
80 return 0;
82 __set_errno (-ret);
83 return -1;
85 #else
86 # define __new_sigaction __sigaction
87 #endif
89 int
90 __new_sigaction (int sig, __const struct sigaction *new, struct sigaction *old)
92 int ret;
94 sig = -sig;
96 __asm__("or %%g0,%0,%%g1\n\t"
97 "or %%g0,%1,%%o0\n\t"
98 "or %%g0,%2,%%o1\n\t"
99 "or %%g0,%3,%%o2\n\t"
100 "t 0x10\n\t"
101 "bcc 1f\n\t"
102 "or %%o0, %%g0, %0\n\t"
103 "sub %%g0,%%o0,%0\n\t"
104 "1:"
105 : "=r" (ret), "=r" ((long int) sig), "=r" ((long int) new),
106 "=r" ((long int) old)
107 : "0" (__NR_sigaction), "1" (sig), "2" (new), "3" (old)
108 : "g1", "o0", "o1", "o2");
109 if (ret >= 0)
110 return 0;
111 __set_errno (-ret);
112 return -1;
115 #if 0
117 __sigaction (int sig, __const struct sigaction *new, struct sigaction *old)
119 static (*sigact_routine) (int, __const struct sigaction *, struct sigaction *);
120 int ret;
121 struct sigaction sa;
123 if (sigact_routine)
124 return (*sigact_routine) (sig, new, old);
126 ret = __new_sigaction (1, NULL, &sa);
127 if (ret == -1)
128 sigact_routine = __trampoline_sigaction;
129 else
130 sigact_routine = __new_sigaction;
132 return __sigaction (sig, new, old);
134 #endif
136 weak_alias (__sigaction, sigaction);