1 /*
2  * Copyright (C) 2013 Synopsys, Inc. (www.synopsys.com)
3  *
4  * Licensed under the LGPL v2.1 or later, see the file COPYING.LIB in this tarball.
5  */
6 
7 #include <errno.h>
8 #include <signal.h>
9 #include <string.h>
10 #include <sys/syscall.h>
11 #include <bits/kernel_sigaction.h>
12 
13 /*
14  * Default sigretrun stub if user doesn't specify SA_RESTORER
15  */
16 extern void __default_rt_sa_restorer(void);
17 
18 #define SA_RESTORER	0x04000000
19 
20 /* If @act is not NULL, change the action for @sig to @act.
21    If @oact is not NULL, put the old action for @sig in @oact.  */
22 int
__libc_sigaction(int sig,const struct sigaction * act,struct sigaction * oact)23 __libc_sigaction (int sig, const struct sigaction *act, struct sigaction *oact)
24 {
25 	struct sigaction kact;
26 
27 	/*
28 	 * SA_RESTORER is only relevant for act != NULL case
29 	 * (!act means caller only wants to know @oact)
30 	 */
31 	if (act && !(act->sa_flags & SA_RESTORER)) {
32 		kact.sa_restorer = __default_rt_sa_restorer;
33 		kact.sa_flags = act->sa_flags | SA_RESTORER;
34 
35 		kact.sa_handler = act->sa_handler;
36 		kact.sa_mask = act->sa_mask;
37 
38 		act = &kact;
39 	}
40 
41 	return INLINE_SYSCALL(rt_sigaction, 4,
42 			sig, act, oact, sizeof(act->sa_mask));
43 }
44 
45 #ifndef LIBC_SIGACTION
46 # ifndef __UCLIBC_HAS_THREADS__
47 strong_alias(__libc_sigaction,sigaction)
48 libc_hidden_def(sigaction)
49 # else
50 weak_alias(__libc_sigaction,sigaction)
51 libc_hidden_weak(sigaction)
52 # endif
53 #endif
54