1 /* Copyright (C) 1997, 1998, 1999, 2000 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 Library General Public License as
6 published by the Free Software Foundation; either version 2 of the
7 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 Library General Public License for more details.
14 You should have received a copy of the GNU Library General Public
15 License along with the GNU C Library; see the file COPYING.LIB. If not,
16 write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 Boston, MA 02111-1307, USA.
19 Totally hacked up for uClibc by Erik Andersen <andersen@codepoet.org>
25 #include <sys/syscall.h>
26 #include <bits/kernel_sigaction.h>
28 #define SA_RESTORER 0x04000000
31 #if defined __NR_rt_sigaction
32 libc_hidden_proto(memcpy)
34 extern void restore_rt (void) asm ("__restore_rt") attribute_hidden;
35 extern void restore (void) asm ("__restore") attribute_hidden;
37 /* If ACT is not NULL, change the action for SIG to *ACT.
38 If OACT is not NULL, put the old action for SIG in *OACT. */
39 int __libc_sigaction (int sig, const struct sigaction *act, struct sigaction *oact)
42 struct kernel_sigaction kact, koact;
45 if (sig == SIGCANCEL) {
52 kact.k_sa_handler = act->sa_handler;
53 memcpy (&kact.sa_mask, &act->sa_mask, sizeof (kact.sa_mask));
54 kact.sa_flags = act->sa_flags;
56 kact.sa_flags = act->sa_flags | SA_RESTORER;
57 kact.sa_restorer = ((act->sa_flags & SA_SIGINFO)
58 ? &restore_rt : &restore);
61 /* XXX The size argument hopefully will have to be changed to the
62 real size of the user-level sigset_t. */
63 result = __syscall_rt_sigaction(sig, act ? __ptrvalue (&kact) : NULL,
64 oact ? __ptrvalue (&koact) : NULL, _NSIG / 8);
66 if (oact && result >= 0) {
67 oact->sa_handler = koact.k_sa_handler;
68 memcpy (&oact->sa_mask, &koact.sa_mask, sizeof (oact->sa_mask));
69 oact->sa_flags = koact.sa_flags;
70 oact->sa_restorer = koact.sa_restorer;
77 extern void restore (void) asm ("__restore") attribute_hidden;
79 /* If ACT is not NULL, change the action for SIG to *ACT.
80 If OACT is not NULL, put the old action for SIG in *OACT. */
81 int __libc_sigaction (int sig, const struct sigaction *act, struct sigaction *oact)
84 struct old_kernel_sigaction kact, koact;
87 if (sig == SIGCANCEL) {
94 kact.k_sa_handler = act->sa_handler;
95 kact.sa_mask = act->sa_mask.__val[0];
96 kact.sa_flags = act->sa_flags | SA_RESTORER;
97 kact.sa_restorer = &restore;
100 asm volatile ("pushl %%ebx\n"
105 : "0" (__NR_sigaction), "mr" (sig),
106 "c" (act ? __ptrvalue (&kact) : 0),
107 "d" (oact ? __ptrvalue (&koact) : 0));
110 __set_errno(-result);
115 oact->sa_handler = koact.k_sa_handler;
116 oact->sa_mask.__val[0] = koact.sa_mask;
117 oact->sa_flags = koact.sa_flags;
118 oact->sa_restorer = koact.sa_restorer;
125 #ifndef LIBC_SIGACTION
126 strong_alias(__libc_sigaction,sigaction)
127 libc_hidden_proto(sigaction)
128 libc_hidden_def(sigaction)
134 /* NOTE: Please think twice before making any changes to the bits of
135 code below. GDB needs some intimate knowledge about it to
136 recognize them as signal trampolines, and make backtraces through
137 signal handlers work right. Important are both the names
138 (__restore and __restore_rt) and the exact instruction sequence.
139 If you ever feel the need to make any changes, please notify the
140 appropriate GDB maintainer. */
142 #define RESTORE(name, syscall) RESTORE2 (name, syscall)
143 #define RESTORE2(name, syscall) \
149 " movl $" #syscall ", %eax\n" \
153 #ifdef __NR_rt_sigaction
154 /* The return code for realtime-signals. */
155 RESTORE (restore_rt, __NR_rt_sigreturn)
158 /* For the boring old signals. */
160 # define RESTORE2(name, syscall) \
167 " movl $" #syscall ", %eax\n" \
171 RESTORE (restore, __NR_sigreturn)