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 see <http://www.gnu.org/licenses/>.
18 Totally hacked up for uClibc by Erik Andersen <andersen@codepoet.org>
24 #include <sys/syscall.h>
25 #include <bits/kernel_sigaction.h>
27 #define SA_RESTORER 0x04000000
29 #if defined __NR_rt_sigaction
31 extern void restore_rt(void) __asm__ ("__restore_rt") attribute_hidden;
32 extern void restore(void) __asm__ ("__restore") attribute_hidden;
34 /* If ACT is not NULL, change the action for SIG to *ACT.
35 If OACT is not NULL, put the old action for SIG in *OACT. */
36 int __libc_sigaction(int sig, const struct sigaction *act, struct sigaction *oact)
38 struct sigaction kact;
41 memcpy(&kact, act, sizeof(kact));
42 kact.sa_flags |= SA_RESTORER;
43 kact.sa_restorer = (act->sa_flags & SA_SIGINFO) ? &restore_rt : &restore;
46 /* NB: kernel (as of 2.6.25) will return EINVAL
47 * if sizeof(act->sa_mask) does not match kernel's sizeof(sigset_t) */
48 return __syscall_rt_sigaction(sig, act, oact, sizeof(act->sa_mask));
53 extern void restore(void) __asm__ ("__restore") attribute_hidden;
55 /* If ACT is not NULL, change the action for SIG to *ACT.
56 If OACT is not NULL, put the old action for SIG in *OACT. */
57 int __libc_sigaction(int sig, const struct sigaction *act, struct sigaction *oact)
60 struct old_kernel_sigaction kact, koact;
63 kact.k_sa_handler = act->sa_handler;
64 kact.sa_mask = act->sa_mask.__val[0];
65 kact.sa_flags = act->sa_flags | SA_RESTORER;
66 kact.sa_restorer = &restore;
68 __asm__ __volatile__ (
73 : "=a" (result), "=m" (koact)
74 : "0" (__NR_sigaction), "r" (sig), "m" (kact),
75 "c" (act ? &kact : NULL),
76 "d" (oact ? &koact : NULL));
82 oact->sa_handler = koact.k_sa_handler;
83 oact->sa_mask.__val[0] = koact.sa_mask;
84 oact->sa_flags = koact.sa_flags;
85 oact->sa_restorer = koact.sa_restorer;
93 #ifndef LIBC_SIGACTION
94 # ifndef __UCLIBC_HAS_THREADS__
95 strong_alias(__libc_sigaction,sigaction)
96 libc_hidden_def(sigaction)
98 weak_alias(__libc_sigaction,sigaction)
99 libc_hidden_weak(sigaction)
104 /* NOTE: Please think twice before making any changes to the bits of
105 code below. GDB needs some intimate knowledge about it to
106 recognize them as signal trampolines, and make backtraces through
107 signal handlers work right. Important are both the names
108 (__restore and __restore_rt) and the exact instruction sequence.
109 If you ever feel the need to make any changes, please notify the
110 appropriate GDB maintainer. */
112 #define RESTORE(name, syscall) RESTORE2(name, syscall)
114 #ifdef __NR_rt_sigaction
115 /* The return code for realtime-signals. */
116 # define RESTORE2(name, syscall) \
120 " movl $" #syscall ", %eax\n" \
123 RESTORE(restore_rt, __NR_rt_sigreturn)
126 #ifdef __NR_sigreturn
127 /* For the boring old signals. */
129 # define RESTORE2(name, syscall) \
134 " movl $" #syscall ", %eax\n" \
137 RESTORE(restore, __NR_sigreturn)