]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/uclibc/lib/contrib/uclibc/libc/sysdeps/linux/c6x/sigaction.c
update
[l4.git] / l4 / pkg / uclibc / lib / contrib / uclibc / libc / sysdeps / linux / c6x / sigaction.c
1 /*
2    Copyright (C) 2010 Texas Instruments Incorporated
3    Adapted from i386 version by Mark Salter <msalter@redhat.com>
4
5    Copyright (C) 1997, 1998, 1999, 2000 Free Software Foundation, Inc.
6    This file is part of the GNU C Library.
7
8    The GNU C Library is free software; you can redistribute it and/or
9    modify it under the terms of the GNU Library General Public License as
10    published by the Free Software Foundation; either version 2 of the
11    License, or (at your option) any later version.
12
13    The GNU C Library is distributed in the hope that it will be useful,
14    but WITHOUT ANY WARRANTY; without even the implied warranty of
15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16    Library General Public License for more details.
17
18    You should have received a copy of the GNU Library General Public
19    License along with the GNU C Library; see the file COPYING.LIB.  If not,
20    see <http://www.gnu.org/licenses/>.
21
22    Totally hacked up for uClibc by Erik Andersen <andersen@codepoet.org>
23    */
24
25 #include <errno.h>
26 #include <signal.h>
27 #include <string.h>
28 #include <sys/syscall.h>
29 #include <bits/kernel_sigaction.h>
30 #ifdef __UCLIBC_HAS_THREADS_NATIVE__
31 # include <pthreadP.h>  /* SIGCANCEL */
32 #endif
33
34 #define SA_RESTORER     0x04000000
35
36 extern void restore_rt(void) __asm__ ("__restore_rt") attribute_hidden;
37 extern void restore(void) __asm__ ("__restore") attribute_hidden;
38
39 /* If ACT is not NULL, change the action for SIG to *ACT.
40    If OACT is not NULL, put the old action for SIG in *OACT.  */
41 int __libc_sigaction (int sig, const struct sigaction *act, struct sigaction *oact)
42 {
43     int result;
44     struct kernel_sigaction kact, koact;
45
46 #ifdef SIGCANCEL
47     if (sig == SIGCANCEL) {
48         __set_errno (EINVAL);
49         return -1;
50     }
51 #endif
52
53     if (act) {
54         kact.k_sa_handler = act->sa_handler;
55         memcpy (&kact.sa_mask, &act->sa_mask, sizeof (kact.sa_mask));
56         kact.sa_flags = act->sa_flags;
57
58         kact.sa_flags = act->sa_flags | SA_RESTORER;
59         kact.sa_restorer = ((act->sa_flags & SA_SIGINFO)
60                 ? &restore_rt : &restore);
61     }
62
63     /* XXX The size argument hopefully will have to be changed to the
64        real size of the user-level sigset_t.  */
65     result = __syscall_rt_sigaction(sig, act ? __ptrvalue (&kact) : NULL,
66             oact ? __ptrvalue (&koact) : NULL, _NSIG / 8);
67
68     if (oact && result >= 0) {
69         oact->sa_handler = koact.k_sa_handler;
70         memcpy (&oact->sa_mask, &koact.sa_mask, sizeof (oact->sa_mask));
71         oact->sa_flags = koact.sa_flags;
72         oact->sa_restorer = koact.sa_restorer;
73     }
74     return result;
75 }
76
77 #ifndef LIBC_SIGACTION
78 # ifndef __UCLIBC_HAS_THREADS__
79 strong_alias(__libc_sigaction,sigaction)
80 libc_hidden_def(sigaction)
81 # else
82 weak_alias(__libc_sigaction,sigaction)
83 libc_hidden_weak(sigaction)
84 # endif
85 #endif
86
87
88 /* NOTE: Please think twice before making any changes to the bits of
89    code below.  GDB needs some intimate knowledge about it to
90    recognize them as signal trampolines, and make backtraces through
91    signal handlers work right.  Important are both the names
92    (__restore and __restore_rt) and the exact instruction sequence.
93    If you ever feel the need to make any changes, please notify the
94    appropriate GDB maintainer.  */
95
96 #define RESTORE(name, syscall) RESTORE2 (name, syscall)
97 #define RESTORE2(name, syscall) \
98 __asm__                                         \
99   (                                             \
100    "    .text\n"                                \
101    "    .global " #name "\n"                    \
102    "__" #name ":\n"                             \
103    "    MVK " #syscall ",B0\n"                  \
104    "    SWE\n"                                  \
105    "    NOP\n"                                  \
106    "    NOP\n"                                  \
107    "    NOP\n"                                  \
108    "    NOP\n"                                  \
109    "    NOP\n"                                  \
110    "    NOP\n"                                  \
111    );
112
113 #ifdef __NR_rt_sigaction
114 /* The return code for realtime-signals.  */
115 RESTORE (restore_rt, __NR_rt_sigreturn)
116 #endif
117
118 #ifdef __NR_sigreturn
119 /* For the boring old signals.  */
120 RESTORE (restore, __NR_sigreturn)
121 #endif