1 /* POSIX.1 sigaction call for Linux/SPARC.
2    Copyright (C) 1997-2000,2002,2003,2005 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, see
18    <http://www.gnu.org/licenses/>.
19 
20        Ported to uClibc from glibc: 090520:
21                Jan Buchholz, KIP, Uni Heidelberg <jan.buchholz@kip.uni-heidelberg.de>
22                Austin Foxley, Ceton Corporation <austinf@cetoncorp.com>
23 */
24 
25 #include <errno.h>
26 #include <signal.h>
27 #include <string.h>
28 #include <sys/syscall.h>
29 #include <bits/kernel_sigaction.h>
30 
31 
32 _syscall5(int, rt_sigaction, int, a, int, b, int, c, int, d, int, e)
33 void __rt_sigreturn_stub(void);
34 void __sigreturn_stub(void);
35 
__libc_sigaction(int sig,const struct sigaction * act,struct sigaction * oact)36 int __libc_sigaction(int sig, const struct sigaction *act, struct sigaction *oact)
37 {
38 	int ret;
39 	struct sigaction kact, koact;
40 	unsigned long stub = 0;
41 
42 	if (act) {
43 		kact.sa_handler = act->sa_handler;
44 		memcpy (&kact.sa_mask, &act->sa_mask, sizeof (sigset_t));
45 		if (((kact.sa_flags = act->sa_flags) & SA_SIGINFO) != 0)
46 			stub = (unsigned long) &__rt_sigreturn_stub;
47 		else
48 			stub = (unsigned long) &__sigreturn_stub;
49 		stub -= 8;
50 		kact.sa_restorer = NULL;
51 	}
52 
53 	/* XXX The size argument hopefully will have to be changed to the
54 	 * real size of the user-level sigset_t.  */
55 	ret = INLINE_SYSCALL (rt_sigaction, 5, sig, act ? &kact : 0,
56 			oact ? &koact : 0, stub, _NSIG / 8);
57 
58 	if (oact && ret >= 0) {
59 		oact->sa_handler = koact.sa_handler;
60 		memcpy (&oact->sa_mask, &koact.sa_mask, sizeof (sigset_t));
61 		oact->sa_flags = koact.sa_flags;
62 		oact->sa_restorer = koact.sa_restorer;
63 	}
64 	return ret;
65 }
66 
67 
68 #ifndef LIBC_SIGACTION
69 # ifndef __UCLIBC_HAS_THREADS__
70 strong_alias(__libc_sigaction,sigaction)
71 libc_hidden_def(sigaction)
72 # else
73 weak_alias(__libc_sigaction,sigaction)
74 libc_hidden_weak(sigaction)
75 # endif
76 #endif
77 
78