]> git.ipfire.org Git - thirdparty/glibc.git/blob - sysdeps/unix/sysv/linux/sparc/sparc32/sigaction.c
Remove pre-ISO C support
[thirdparty/glibc.git] / sysdeps / unix / sysv / linux / sparc / sparc32 / sigaction.c
1 /* POSIX.1 sigaction call for Linux/SPARC.
2 Copyright (C) 1997-2000,2002,2003,2005,2012 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.
5
6 The GNU C Library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Lesser General Public
8 License as published by the Free Software Foundation; either
9 version 2.1 of the License, or (at your option) any later version.
10
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 Lesser General Public License for more details.
15
16 You should have received a copy of the GNU Lesser General Public
17 License along with the GNU C Library; if not, write to the Free
18 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
19 02111-1307 USA. */
20
21 #include <string.h>
22 #include <syscall.h>
23 #include <sys/signal.h>
24 #include <errno.h>
25 #include <kernel_sigaction.h>
26 #include <sysdep.h>
27
28 static void __rt_sigreturn_stub (void);
29 static void __sigreturn_stub (void);
30
31 /* The variable is shared between all wrappers around signal handling
32 functions which have RT equivalents. */
33 int __libc_missing_rt_sigs;
34
35 int
36 __libc_sigaction (int sig, const struct sigaction *act, struct sigaction *oact)
37 {
38 struct old_kernel_sigaction k_sigact, k_osigact;
39 int ret;
40
41 #ifdef __NR_rt_sigaction
42 /* First try the RT signals. */
43 if (!__libc_missing_rt_sigs)
44 {
45 struct kernel_sigaction kact, koact;
46 unsigned long stub = 0;
47 int saved_errno = errno;
48
49 if (act)
50 {
51 kact.k_sa_handler = act->sa_handler;
52 memcpy (&kact.sa_mask, &act->sa_mask, sizeof (sigset_t));
53 if (((kact.sa_flags = act->sa_flags) & SA_SIGINFO) != 0)
54 stub = (unsigned long) &__rt_sigreturn_stub;
55 else
56 stub = (unsigned long) &__sigreturn_stub;
57 stub -= 8;
58 kact.sa_restorer = NULL;
59 }
60
61 /* XXX The size argument hopefully will have to be changed to the
62 real size of the user-level sigset_t. */
63 ret = INLINE_SYSCALL (rt_sigaction, 5, sig, act ? &kact : 0,
64 oact ? &koact : 0, stub, _NSIG / 8);
65
66 if (ret >= 0 || errno != ENOSYS)
67 {
68 if (oact && ret >= 0)
69 {
70 oact->sa_handler = koact.k_sa_handler;
71 memcpy (&oact->sa_mask, &koact.sa_mask, sizeof (sigset_t));
72 oact->sa_flags = koact.sa_flags;
73 oact->sa_restorer = koact.sa_restorer;
74 }
75 return ret;
76 }
77
78 __set_errno (saved_errno);
79 __libc_missing_rt_sigs = 1;
80 }
81 #endif
82
83 /* Magic to tell the kernel we are using "new-style" signals, in that
84 the signal table is not kept in userspace. Not the same as the
85 really-new-style rt signals. */
86 sig = -sig;
87
88 if (act)
89 {
90 k_sigact.k_sa_handler = act->sa_handler;
91 k_sigact.sa_mask = act->sa_mask.__val[0];
92 k_sigact.sa_flags = act->sa_flags;
93 k_sigact.sa_restorer = NULL;
94 }
95
96 {
97 register int r_syscallnr __asm__("%g1") = __NR_sigaction;
98 register int r_sig __asm__("%o0") = sig;
99 register struct old_kernel_sigaction *r_act __asm__("%o1");
100 register struct old_kernel_sigaction *r_oact __asm__("%o2");
101
102 r_act = act ? &k_sigact : NULL;
103 r_oact = oact ? &k_osigact : NULL;
104
105 __asm__ __volatile__("t 0x10\n\t"
106 "bcc 1f\n\t"
107 " nop\n\t"
108 "sub %%g0,%%o0,%%o0\n"
109 "1:"
110 : "=r"(r_sig)
111 : "r"(r_syscallnr), "r"(r_act), "r"(r_oact),
112 "0"(r_sig));
113
114 ret = r_sig;
115 }
116
117 if (ret >= 0)
118 {
119 if (oact)
120 {
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 }
126 return ret;
127 }
128
129 __set_errno (-ret);
130 return -1;
131 }
132 libc_hidden_def (__libc_sigaction)
133
134 #ifdef WRAPPER_INCLUDE
135 # include WRAPPER_INCLUDE
136 #endif
137
138 #ifndef LIBC_SIGACTION
139 weak_alias (__libc_sigaction, __sigaction);
140 libc_hidden_weak (__sigaction)
141 weak_alias (__libc_sigaction, sigaction);
142 #endif
143
144 static void
145 __rt_sigreturn_stub (void)
146 {
147 __asm__ ("mov %0, %%g1\n\t"
148 "ta 0x10\n\t"
149 : /* no outputs */
150 : "i" (__NR_rt_sigreturn));
151 }
152
153 static void
154 __sigreturn_stub (void)
155 {
156 __asm__ ("mov %0, %%g1\n\t"
157 "ta 0x10\n\t"
158 : /* no outputs */
159 : "i" (__NR_sigreturn));
160 }