OSDN Git Service

signal.h: provide prototype for __libc_sigaction and remove all others
[uclinux-h8/uClibc.git] / 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    write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21    Boston, MA 02111-1307, USA.
22
23    Totally hacked up for uClibc by Erik Andersen <andersen@codepoet.org>
24    */
25
26 #include <errno.h>
27 #include <signal.h>
28 #include <string.h>
29 #include <sys/syscall.h>
30 #include <bits/kernel_sigaction.h>
31
32 #define SA_RESTORER     0x04000000
33
34 extern void restore_rt(void) __asm__ ("__restore_rt") attribute_hidden;
35 extern void restore(void) __asm__ ("__restore") attribute_hidden;
36
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)
40 {
41     int result;
42     struct kernel_sigaction kact, koact;
43
44 #ifdef SIGCANCEL
45     if (sig == SIGCANCEL) {
46         __set_errno (EINVAL);
47         return -1;
48     }
49 #endif
50
51     if (act) {
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;
55
56         kact.sa_flags = act->sa_flags | SA_RESTORER;
57         kact.sa_restorer = ((act->sa_flags & SA_SIGINFO)
58                 ? &restore_rt : &restore);
59     }
60
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);
65
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;
71     }
72     return result;
73 }
74
75 #ifndef LIBC_SIGACTION
76 # ifndef __UCLIBC_HAS_THREADS__
77 strong_alias(__libc_sigaction,sigaction)
78 libc_hidden_def(sigaction)
79 # else
80 weak_alias(__libc_sigaction,sigaction)
81 libc_hidden_weak(sigaction)
82 # endif
83 #endif
84
85
86 /* NOTE: Please think twice before making any changes to the bits of
87    code below.  GDB needs some intimate knowledge about it to
88    recognize them as signal trampolines, and make backtraces through
89    signal handlers work right.  Important are both the names
90    (__restore and __restore_rt) and the exact instruction sequence.
91    If you ever feel the need to make any changes, please notify the
92    appropriate GDB maintainer.  */
93
94 #define RESTORE(name, syscall) RESTORE2 (name, syscall)
95 #define RESTORE2(name, syscall) \
96 __asm__                                         \
97   (                                             \
98    "    .text\n"                                \
99    "    .global " #name "\n"                    \
100    "__" #name ":\n"                             \
101    "    MVK " #syscall ",B0\n"                  \
102    "    SWE\n"                                  \
103    "    NOP\n"                                  \
104    "    NOP\n"                                  \
105    "    NOP\n"                                  \
106    "    NOP\n"                                  \
107    "    NOP\n"                                  \
108    "    NOP\n"                                  \
109    );
110
111 #ifdef __NR_rt_sigaction
112 /* The return code for realtime-signals.  */
113 RESTORE (restore_rt, __NR_rt_sigreturn)
114 #endif
115
116 #ifdef __NR_sigreturn
117 /* For the boring old signals.  */
118 RESTORE (restore, __NR_sigreturn)
119 #endif