Update.
[glibc.git] / sysdeps / unix / sysv / linux / sparc / sparc32 / sigaction.c
blobe18ffa818d082c1b32f66c560d6d91ca0e0379c4
1 /* POSIX.1 sigaction call for Linux/SPARC.
2 Copyright (C) 1997, 1998 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 <string.h>
22 #include <syscall.h>
23 #include <sys/signal.h>
24 #include <errno.h>
25 #include <kernel_sigaction.h>
27 extern int __syscall_rt_sigaction (int, const struct kernel_sigaction *,
28 struct kernel_sigaction *, unsigned long,
29 size_t);
31 static void __rt_sigreturn_stub (void);
32 static void __sigreturn_stub (void);
34 /* The variable is shared between all wrappers around signal handling
35 functions which have RT equivalents. */
36 int __libc_missing_rt_sigs;
38 int
39 __sigaction (int sig, __const struct sigaction *act, struct sigaction *oact)
41 struct old_kernel_sigaction k_sigact, k_osigact;
42 int ret;
44 /* First try the RT signals. */
45 if (!__libc_missing_rt_sigs)
47 struct kernel_sigaction kact, koact;
48 unsigned long stub = 0;
49 int saved_errno = errno;
51 if (act)
53 kact.k_sa_handler = act->sa_handler;
54 memcpy (&kact.sa_mask, &act->sa_mask, sizeof (sigset_t));
55 if (((kact.sa_flags = act->sa_flags) & SA_SIGINFO) != 0)
56 stub = (unsigned long) &__rt_sigreturn_stub;
57 else
58 stub = (unsigned long) &__sigreturn_stub;
59 stub -= 8;
60 kact.sa_restorer = NULL;
63 /* XXX The size argument hopefully will have to be changed to the
64 real size of the user-level sigset_t. */
65 ret = __syscall_rt_sigaction (sig, act ? &kact : 0,
66 oact ? &koact : 0,
67 stub, _NSIG / 8);
69 if (ret >= 0 || errno != ENOSYS)
71 if (oact && ret >= 0)
73 oact->sa_handler = koact.k_sa_handler;
74 memcpy (&oact->sa_mask, &koact.sa_mask, sizeof (sigset_t));
75 oact->sa_flags = koact.sa_flags;
76 oact->sa_restorer = koact.sa_restorer;
78 return ret;
81 __set_errno (saved_errno);
82 __libc_missing_rt_sigs = 1;
85 /* Magic to tell the kernel we are using "new-style" signals, in that
86 the signal table is not kept in userspace. Not the same as the
87 really-new-style rt signals. */
88 sig = -sig;
90 if (act)
92 k_sigact.k_sa_handler = act->sa_handler;
93 k_sigact.sa_mask = act->sa_mask.__val[0];
94 k_sigact.sa_flags = act->sa_flags;
95 k_sigact.sa_restorer = NULL;
99 register int r_syscallnr __asm__("%g1") = __NR_sigaction;
100 register int r_sig __asm__("%o0") = sig;
101 register struct old_kernel_sigaction *r_act __asm__("%o1");
102 register struct old_kernel_sigaction *r_oact __asm__("%o2");
104 r_act = act ? &k_sigact : NULL;
105 r_oact = oact ? &k_osigact : NULL;
107 __asm__ __volatile__("t 0x10\n\t"
108 "bcc 1f\n\t"
109 " nop\n\t"
110 "sub %%g0,%%o0,%%o0\n"
111 "1:"
112 : "=r"(r_sig)
113 : "r"(r_syscallnr), "r"(r_act), "r"(r_oact),
114 "0"(r_sig));
116 ret = r_sig;
119 if (oact && ret >= 0)
121 oact->sa_handler = k_osigact.k_sa_handler;
122 oact->sa_mask.__val[0] = k_osigact.sa_mask;
123 oact->sa_flags = k_osigact.sa_flags;
124 oact->sa_restorer = NULL;
125 return ret;
128 __set_errno (-ret);
129 return -1;
132 weak_alias (__sigaction, sigaction);
134 static void
135 __rt_sigreturn_stub (void)
137 __asm__ ("mov %0, %%g1\n\t"
138 "ta 0x10\n\t"
139 : /* no outputs */
140 : "i" (__NR_rt_sigreturn));
143 static void
144 __sigreturn_stub (void)
146 __asm__ ("mov %0, %%g1\n\t"
147 "ta 0x10\n\t"
148 : /* no outputs */
149 : "i" (__NR_sigreturn));