]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/uclibc/lib/contrib/uclibc/libc/sysdeps/linux/i386/sigaction.c
update
[l4.git] / l4 / pkg / uclibc / lib / contrib / uclibc / libc / sysdeps / linux / i386 / sigaction.c
1 /* Copyright (C) 1997, 1998, 1999, 2000 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 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.
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    Library General Public License for more details.
13
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/>.
17
18    Totally hacked up for uClibc by Erik Andersen <andersen@codepoet.org>
19    */
20
21 #include <errno.h>
22 #include <signal.h>
23 #include <string.h>
24 #include <sys/syscall.h>
25 #include <bits/kernel_sigaction.h>
26
27 #define SA_RESTORER     0x04000000
28
29 #if defined __NR_rt_sigaction
30
31 extern void restore_rt(void) __asm__ ("__restore_rt") attribute_hidden;
32 extern void restore(void) __asm__ ("__restore") attribute_hidden;
33
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)
37 {
38         struct sigaction kact;
39
40         if (act) {
41                 memcpy(&kact, act, sizeof(kact));
42                 kact.sa_flags |= SA_RESTORER;
43                 kact.sa_restorer = (act->sa_flags & SA_SIGINFO) ? &restore_rt : &restore;
44                 act = &kact;
45         }
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));
49 }
50
51 #else
52
53 extern void restore(void) __asm__ ("__restore") attribute_hidden;
54
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)
58 {
59         int result;
60         struct old_kernel_sigaction kact, koact;
61
62         if (act) {
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;
67         }
68         __asm__ __volatile__ (
69                 "       pushl   %%ebx\n"
70                 "       movl    %3, %%ebx\n"
71                 "       int     $0x80\n"
72                 "       popl    %%ebx\n"
73                 : "=a" (result), "=m" (koact)
74                 : "0" (__NR_sigaction), "r" (sig), "m" (kact),
75                   "c" (act ? &kact : NULL),
76                   "d" (oact ? &koact : NULL));
77         if (result < 0) {
78                 __set_errno(-result);
79                 return -1;
80         }
81         if (oact) {
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;
86         }
87         return result;
88 }
89
90 #endif
91
92
93 #ifndef LIBC_SIGACTION
94 # ifndef __UCLIBC_HAS_THREADS__
95 strong_alias(__libc_sigaction,sigaction)
96 libc_hidden_def(sigaction)
97 # else
98 weak_alias(__libc_sigaction,sigaction)
99 libc_hidden_weak(sigaction)
100 # endif
101 #endif
102
103
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.  */
111
112 #define RESTORE(name, syscall) RESTORE2(name, syscall)
113
114 #ifdef __NR_rt_sigaction
115 /* The return code for realtime-signals.  */
116 # define RESTORE2(name, syscall) \
117 __asm__ (                                               \
118         ".text\n"                                       \
119         "__" #name ":\n"                                \
120         "       movl    $" #syscall ", %eax\n"          \
121         "       int     $0x80\n"                        \
122 );
123 RESTORE(restore_rt, __NR_rt_sigreturn)
124 #endif
125
126 #ifdef __NR_sigreturn
127 /* For the boring old signals.  */
128 # undef RESTORE2
129 # define RESTORE2(name, syscall) \
130 __asm__ (                                               \
131         ".text\n"                                       \
132         "__" #name ":\n"                                \
133         "       popl    %eax\n"                         \
134         "       movl    $" #syscall ", %eax\n"          \
135         "       int     $0x80\n"                        \
136 );
137 RESTORE(restore, __NR_sigreturn)
138 #endif