Add Changelog ...
[glibc.git] / sysdeps / unix / sysv / linux / mips / sigaction.c
blobd646af3f22928ef790d6623ee90329b1b419bd8f
1 /* Copyright (C) 1997-2012 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 #include <kernel-features.h>
30 /* The difference here is that the sigaction structure used in the
31 kernel is not the same as we use in the libc. Therefore we must
32 translate it here. */
33 #include <kernel_sigaction.h>
35 #if _MIPS_SIM != _ABIO32
37 # ifdef __NR_rt_sigreturn
38 static void restore_rt (void) asm ("__restore_rt");
39 # endif
40 # ifdef __NR_sigreturn
41 static void restore (void) asm ("__restore");
42 # endif
43 #endif
45 /* If ACT is not NULL, change the action for SIG to *ACT.
46 If OACT is not NULL, put the old action for SIG in *OACT. */
47 int
48 __libc_sigaction (sig, act, oact)
49 int sig;
50 const struct sigaction *act;
51 struct sigaction *oact;
53 int result;
55 struct kernel_sigaction kact, koact;
57 if (act)
59 kact.k_sa_handler = act->sa_handler;
60 memcpy (&kact.sa_mask, &act->sa_mask, sizeof (kernel_sigset_t));
61 kact.sa_flags = act->sa_flags;
62 #ifdef HAVE_SA_RESTORER
63 # if _MIPS_SIM == _ABIO32
64 kact.sa_restorer = act->sa_restorer;
65 # else
66 kact.sa_restorer = &restore_rt;
67 # endif
68 #endif
71 /* XXX The size argument hopefully will have to be changed to the
72 real size of the user-level sigset_t. */
73 result = INLINE_SYSCALL (rt_sigaction, 4, sig,
74 act ? __ptrvalue (&kact) : NULL,
75 oact ? __ptrvalue (&koact) : NULL,
76 sizeof (kernel_sigset_t));
78 if (oact && result >= 0)
80 oact->sa_handler = koact.k_sa_handler;
81 memcpy (&oact->sa_mask, &koact.sa_mask,
82 sizeof (kernel_sigset_t));
83 oact->sa_flags = koact.sa_flags;
84 #ifdef HAVE_SA_RESTORER
85 oact->sa_restorer = koact.sa_restorer;
86 #endif
88 return result;
90 libc_hidden_def (__libc_sigaction)
92 #ifdef WRAPPER_INCLUDE
93 # include WRAPPER_INCLUDE
94 #endif
96 #ifndef LIBC_SIGACTION
97 weak_alias (__libc_sigaction, __sigaction)
98 libc_hidden_weak (__sigaction)
99 weak_alias (__libc_sigaction, sigaction)
100 #endif
102 /* NOTE: Please think twice before making any changes to the bits of
103 code below. GDB needs some intimate knowledge about it to
104 recognize them as signal trampolines, and make backtraces through
105 signal handlers work right. Important are both the names
106 (__restore_rt) and the exact instruction sequence.
107 If you ever feel the need to make any changes, please notify the
108 appropriate GDB maintainer. */
110 #define RESTORE(name, syscall) RESTORE2 (name, syscall)
111 #define RESTORE2(name, syscall) \
112 asm \
114 ".align 4\n" \
115 "__" #name ":\n" \
116 " li $2, " #syscall "\n" \
117 " syscall\n" \
120 /* The return code for realtime-signals. */
121 #if _MIPS_SIM != _ABIO32
122 # ifdef __NR_rt_sigreturn
123 RESTORE (restore_rt, __NR_rt_sigreturn)
124 # endif
125 # ifdef __NR_sigreturn
126 RESTORE (restore, __NR_sigreturn)
127 # endif
128 #endif