Update copyright dates with scripts/update-copyrights.
[glibc.git] / sysdeps / unix / sysv / linux / mips / sigaction.c
bloba7d811f04dc55aca6117b7c8c0d1bcf444fe11f9
1 /* Copyright (C) 1997-2015 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
4 The GNU C Library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
9 The GNU C Library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
14 You should have received a copy of the GNU Lesser General Public
15 License along with the GNU C Library. If not, see
16 <http://www.gnu.org/licenses/>. */
18 #include <errno.h>
19 #include <sgidefs.h>
20 #include <signal.h>
21 #include <string.h>
23 #include <sysdep.h>
24 #include <sys/syscall.h>
26 #include <sgidefs.h>
28 /* The difference here is that the sigaction structure used in the
29 kernel is not the same as we use in the libc. Therefore we must
30 translate it here. */
31 #include <kernel_sigaction.h>
33 #if _MIPS_SIM != _ABIO32
35 # ifdef __NR_rt_sigreturn
36 static void restore_rt (void) asm ("__restore_rt");
37 # endif
38 # ifdef __NR_sigreturn
39 static void restore (void) asm ("__restore");
40 # endif
41 #endif
43 /* If ACT is not NULL, change the action for SIG to *ACT.
44 If OACT is not NULL, put the old action for SIG in *OACT. */
45 int
46 __libc_sigaction (sig, act, oact)
47 int sig;
48 const struct sigaction *act;
49 struct sigaction *oact;
51 int result;
53 struct kernel_sigaction kact, koact;
55 if (act)
57 kact.k_sa_handler = act->sa_handler;
58 memcpy (&kact.sa_mask, &act->sa_mask, sizeof (kernel_sigset_t));
59 kact.sa_flags = act->sa_flags;
60 #ifdef HAVE_SA_RESTORER
61 # if _MIPS_SIM == _ABIO32
62 kact.sa_restorer = act->sa_restorer;
63 # else
64 kact.sa_restorer = &restore_rt;
65 # endif
66 #endif
69 /* XXX The size argument hopefully will have to be changed to the
70 real size of the user-level sigset_t. */
71 result = INLINE_SYSCALL (rt_sigaction, 4, sig,
72 act ? &kact : NULL,
73 oact ? &koact : NULL,
74 sizeof (kernel_sigset_t));
76 if (oact && result >= 0)
78 oact->sa_handler = koact.k_sa_handler;
79 memcpy (&oact->sa_mask, &koact.sa_mask,
80 sizeof (kernel_sigset_t));
81 oact->sa_flags = koact.sa_flags;
82 #ifdef HAVE_SA_RESTORER
83 oact->sa_restorer = koact.sa_restorer;
84 #endif
86 return result;
88 libc_hidden_def (__libc_sigaction)
90 #include <nptl/sigaction.c>
93 /* NOTE: Please think twice before making any changes to the bits of
94 code below. GDB needs some intimate knowledge about it to
95 recognize them as signal trampolines, and make backtraces through
96 signal handlers work right. Important are both the names
97 (__restore_rt) and the exact instruction sequence.
98 If you ever feel the need to make any changes, please notify the
99 appropriate GDB maintainer. */
101 #define RESTORE(name, syscall) RESTORE2 (name, syscall)
102 #define RESTORE2(name, syscall) \
103 asm \
105 ".align 4\n" \
106 "__" #name ":\n" \
107 " li $2, " #syscall "\n" \
108 " syscall\n" \
111 /* The return code for realtime-signals. */
112 #if _MIPS_SIM != _ABIO32
113 # ifdef __NR_rt_sigreturn
114 RESTORE (restore_rt, __NR_rt_sigreturn)
115 # endif
116 # ifdef __NR_sigreturn
117 RESTORE (restore, __NR_sigreturn)
118 # endif
119 #endif