]> git.ipfire.org Git - thirdparty/glibc.git/blob - sysdeps/unix/sysv/linux/mips/sigaction.c
Update copyright dates with scripts/update-copyrights.
[thirdparty/glibc.git] / sysdeps / unix / sysv / linux / mips / sigaction.c
1 /* Copyright (C) 1997-2018 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3
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.
8
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.
13
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/>. */
17
18 #include <errno.h>
19 #include <sgidefs.h>
20 #include <signal.h>
21 #include <string.h>
22
23 #include <sysdep.h>
24 #include <sys/syscall.h>
25
26 #include <sgidefs.h>
27
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>
32
33 #if _MIPS_SIM != _ABIO32
34
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
42
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 (int sig, const struct sigaction *act, struct sigaction *oact)
47 {
48 int result;
49
50 struct kernel_sigaction kact, koact;
51
52 if (act)
53 {
54 kact.k_sa_handler = act->sa_handler;
55 memcpy (&kact.sa_mask, &act->sa_mask, sizeof (kernel_sigset_t));
56 kact.sa_flags = act->sa_flags;
57 #ifdef HAVE_SA_RESTORER
58 # if _MIPS_SIM == _ABIO32
59 kact.sa_restorer = act->sa_restorer;
60 # else
61 kact.sa_restorer = &restore_rt;
62 # endif
63 #endif
64 }
65
66 /* XXX The size argument hopefully will have to be changed to the
67 real size of the user-level sigset_t. */
68 result = INLINE_SYSCALL (rt_sigaction, 4, sig,
69 act ? &kact : NULL,
70 oact ? &koact : NULL,
71 sizeof (kernel_sigset_t));
72
73 if (oact && result >= 0)
74 {
75 oact->sa_handler = koact.k_sa_handler;
76 memcpy (&oact->sa_mask, &koact.sa_mask,
77 sizeof (kernel_sigset_t));
78 oact->sa_flags = koact.sa_flags;
79 #ifdef HAVE_SA_RESTORER
80 oact->sa_restorer = koact.sa_restorer;
81 #endif
82 }
83 return result;
84 }
85 libc_hidden_def (__libc_sigaction)
86
87 #include <nptl/sigaction.c>
88
89
90 /* NOTE: Please think twice before making any changes to the bits of
91 code below. GDB needs some intimate knowledge about it to
92 recognize them as signal trampolines, and make backtraces through
93 signal handlers work right. Important are both the names
94 (__restore_rt) and the exact instruction sequence.
95 If you ever feel the need to make any changes, please notify the
96 appropriate GDB maintainer. */
97
98 #define RESTORE(name, syscall) RESTORE2 (name, syscall)
99 #define RESTORE2(name, syscall) \
100 asm \
101 ( \
102 ".align 4\n" \
103 "__" #name ":\n" \
104 " li $2, " #syscall "\n" \
105 " syscall\n" \
106 );
107
108 /* The return code for realtime-signals. */
109 #if _MIPS_SIM != _ABIO32
110 # ifdef __NR_rt_sigreturn
111 RESTORE (restore_rt, __NR_rt_sigreturn)
112 # endif
113 # ifdef __NR_sigreturn
114 RESTORE (restore, __NR_sigreturn)
115 # endif
116 #endif