OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [linux/] [uClibc/] [libc/] [sysdeps/] [linux/] [i386/] [sigaction.c] - Blame information for rev 1765

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 1325 phoenix
/* 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
   write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17
   Boston, MA 02111-1307, USA.
18
 
19
   Totally hacked up for uClibc by Erik Andersen <andersen@codepoet.org>
20
   */
21
 
22
#include <errno.h>
23
#include <signal.h>
24
#include <string.h>
25
#include <sys/syscall.h>
26
#include <bits/kernel_sigaction.h>
27
 
28
#define SA_RESTORER     0x04000000
29
 
30
 
31
#if defined __NR_rt_sigaction
32
#warning "Yes there are two warnings here.  Don't worry about it."
33
static void restore_rt (void) asm ("__restore_rt");
34
static void restore (void) asm ("__restore");
35
 
36
/* If ACT is not NULL, change the action for SIG to *ACT.
37
   If OACT is not NULL, put the old action for SIG in *OACT.  */
38
int __libc_sigaction (int sig, const struct sigaction *act, struct sigaction *oact)
39
{
40
    int result;
41
    struct kernel_sigaction kact, koact;
42
 
43
#ifdef SIGCANCEL
44
    if (sig == SIGCANCEL) {
45
        __set_errno (EINVAL);
46
        return -1;
47
    }
48
#endif
49
 
50
    if (act) {
51
        kact.k_sa_handler = act->sa_handler;
52
        memcpy (&kact.sa_mask, &act->sa_mask, sizeof (kact.sa_mask));
53
        kact.sa_flags = act->sa_flags;
54
 
55
        kact.sa_flags = act->sa_flags | SA_RESTORER;
56
        kact.sa_restorer = ((act->sa_flags & SA_SIGINFO)
57
                ? &restore_rt : &restore);
58
    }
59
 
60
    /* XXX The size argument hopefully will have to be changed to the
61
       real size of the user-level sigset_t.  */
62
    result = __syscall_rt_sigaction(sig, act ? __ptrvalue (&kact) : NULL,
63
            oact ? __ptrvalue (&koact) : NULL, _NSIG / 8);
64
 
65
    if (oact && result >= 0) {
66
        oact->sa_handler = koact.k_sa_handler;
67
        memcpy (&oact->sa_mask, &koact.sa_mask, sizeof (oact->sa_mask));
68
        oact->sa_flags = koact.sa_flags;
69
        oact->sa_restorer = koact.sa_restorer;
70
    }
71
    return result;
72
}
73
 
74
 
75
#else
76
#warning "Yes there is a warning here.  Don't worry about it."
77
static void restore (void) asm ("__restore");
78
 
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)
82
{
83
    int result;
84
    struct old_kernel_sigaction kact, koact;
85
 
86
#ifdef SIGCANCEL
87
    if (sig == SIGCANCEL) {
88
        __set_errno (EINVAL);
89
        return -1;
90
    }
91
#endif
92
 
93
    if (act) {
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;
98
    }
99
 
100
    asm volatile ("pushl %%ebx\n"
101
            "movl %2, %%ebx\n"
102
            "int $0x80\n"
103
            "popl %%ebx"
104
            : "=a" (result)
105
            : "0" (__NR_sigaction), "mr" (sig),
106
            "c" (act ? __ptrvalue (&kact) : 0),
107
            "d" (oact ? __ptrvalue (&koact) : 0));
108
 
109
    if (result < 0) {
110
        __set_errno(-result);
111
        return -1;
112
    }
113
 
114
    if (oact) {
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;
119
    }
120
    return result;
121
}
122
 
123
#endif
124
weak_alias (__libc_sigaction, sigaction)
125
 
126
 
127
 
128
 
129
/* NOTE: Please think twice before making any changes to the bits of
130
   code below.  GDB needs some intimate knowledge about it to
131
   recognize them as signal trampolines, and make backtraces through
132
   signal handlers work right.  Important are both the names
133
   (__restore and __restore_rt) and the exact instruction sequence.
134
   If you ever feel the need to make any changes, please notify the
135
   appropriate GDB maintainer.  */
136
 
137
#define RESTORE(name, syscall) RESTORE2 (name, syscall)
138
#define RESTORE2(name, syscall) \
139
asm                                             \
140
  (                                             \
141
   ".text\n"                                    \
142
   "    .align 16\n"                            \
143
   "__" #name ":\n"                             \
144
   "    movl $" #syscall ", %eax\n"             \
145
   "    int  $0x80"                             \
146
   );
147
 
148
#ifdef __NR_rt_sigaction
149
/* The return code for realtime-signals.  */
150
RESTORE (restore_rt, __NR_rt_sigreturn)
151
#endif
152
 
153
/* For the boring old signals.  */
154
# undef RESTORE2
155
# define RESTORE2(name, syscall) \
156
asm                                             \
157
  (                                             \
158
   ".text\n"                                    \
159
   "    .align 8\n"                             \
160
   "__" #name ":\n"                             \
161
   "    popl %eax\n"                            \
162
   "    movl $" #syscall ", %eax\n"             \
163
   "    int  $0x80"                             \
164
   );
165
 
166
RESTORE (restore, __NR_sigreturn)
167
 

powered by: WebSVN 2.1.0

© copyright 1999-2025 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.