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

Subversion Repositories or1k

[/] [or1k/] [trunk/] [uclinux/] [uClinux-2.0.x/] [kernel/] [signal.c] - Blame information for rev 1775

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 199 simons
/*
2
 *  linux/kernel/signal.c
3
 *
4
 *  Copyright (C) 1991, 1992  Linus Torvalds
5
 */
6
 
7
#include <linux/sched.h>
8
#include <linux/kernel.h>
9
#include <linux/signal.h>
10
#include <linux/errno.h>
11
#include <linux/wait.h>
12
#include <linux/ptrace.h>
13
#include <linux/unistd.h>
14
#include <linux/mm.h>
15
 
16
#include <asm/segment.h>
17
 
18
#define _S(nr) (1<<((nr)-1))
19
 
20
#define _BLOCKABLE (~(_S(SIGKILL) | _S(SIGSTOP)))
21
 
22
#ifndef __alpha__
23
 
24
/*
25
 * This call isn't used by all ports, in particular, the Alpha
26
 * uses osf_sigprocmask instead.  Maybe it should be moved into
27
 * arch-dependent dir?
28
 */
29
asmlinkage int sys_sigprocmask(int how, sigset_t *set, sigset_t *oset)
30
{
31
        sigset_t new_set, old_set = current->blocked;
32
        int error;
33
 
34
        if (set) {
35
                error = verify_area(VERIFY_READ, set, sizeof(sigset_t));
36
                if (error)
37
                        return error;
38
                new_set = get_user(set) & _BLOCKABLE;
39
                switch (how) {
40
                case SIG_BLOCK:
41
                        current->blocked |= new_set;
42
                        break;
43
                case SIG_UNBLOCK:
44
                        current->blocked &= ~new_set;
45
                        break;
46
                case SIG_SETMASK:
47
                        current->blocked = new_set;
48
                        break;
49
                default:
50
                        return -EINVAL;
51
                }
52
        }
53
        if (oset) {
54
                error = verify_area(VERIFY_WRITE, oset, sizeof(sigset_t));
55
                if (error)
56
                        return error;
57
                put_user(old_set, oset);
58
        }
59
        return 0;
60
}
61
 
62
/*
63
 * For backwards compatibility?  Functionality superseded by sigprocmask.
64
 */
65
asmlinkage int sys_sgetmask(void)
66
{
67
        return current->blocked;
68
}
69
 
70
asmlinkage int sys_ssetmask(int newmask)
71
{
72
        int old=current->blocked;
73
 
74
        current->blocked = newmask & _BLOCKABLE;
75
        return old;
76
}
77
 
78
#endif
79
 
80
asmlinkage int sys_sigpending(sigset_t *set)
81
{
82
        int error;
83
        /* fill in "set" with signals pending but blocked. */
84
        error = verify_area(VERIFY_WRITE, set, sizeof(sigset_t));
85
        if (!error)
86
                put_user(current->blocked & current->signal, set);
87
        return error;
88
}
89
 
90
/*
91
 * POSIX 3.3.1.3:
92
 *  "Setting a signal action to SIG_IGN for a signal that is pending
93
 *   shall cause the pending signal to be discarded, whether or not
94
 *   it is blocked."
95
 *
96
 *  "Setting a signal action to SIG_DFL for a signal that is pending
97
 *   and whose default action is to ignore the signal (for example,
98
 *   SIGCHLD), shall cause the pending signal to be discarded, whether
99
 *   or not it is blocked"
100
 *
101
 * Note the silly behaviour of SIGCHLD: SIG_IGN means that the signal
102
 * isn't actually ignored, but does automatic child reaping, while
103
 * SIG_DFL is explicitly said by POSIX to force the signal to be ignored..
104
 */
105
static inline void check_pending(int signum)
106
{
107
        struct sigaction *p;
108
 
109
        p = signum - 1 + current->sig->action;
110
        if (p->sa_handler == SIG_IGN) {
111
                current->signal &= ~_S(signum);
112
                return;
113
        }
114
        if (p->sa_handler == SIG_DFL) {
115
                if (signum != SIGCONT && signum != SIGCHLD && signum != SIGWINCH)
116
                        return;
117
                current->signal &= ~_S(signum);
118
                return;
119
        }
120
}
121
 
122
#ifndef __alpha__
123
/*
124
 * For backwards compatibility?  Functionality superseded by sigaction.
125
 */
126
asmlinkage unsigned long sys_signal(int signum, __sighandler_t handler)
127
{
128
        int err;
129
        struct sigaction tmp;
130
 
131
        if (signum<1 || signum>32)
132
                return -EINVAL;
133
        if (signum==SIGKILL || signum==SIGSTOP)
134
                return -EINVAL;
135
        if (handler != SIG_DFL && handler != SIG_IGN) {
136
                err = verify_area(VERIFY_READ, handler, 1);
137
                if (err)
138
                        return err;
139
        }
140
        memset(&tmp, 0, sizeof(tmp));
141
        tmp.sa_handler = handler;
142
        tmp.sa_flags = SA_ONESHOT | SA_NOMASK;
143
        handler = current->sig->action[signum-1].sa_handler;
144
        current->sig->action[signum-1] = tmp;
145
        check_pending(signum);
146
        return (unsigned long) handler;
147
}
148
#endif
149
 
150
asmlinkage int sys_sigaction(int signum, const struct sigaction * action,
151
        struct sigaction * oldaction)
152
{
153
        struct sigaction new_sa, *p;
154
 
155
        if (signum<1 || signum>32)
156
                return -EINVAL;
157
        p = signum - 1 + current->sig->action;
158
        if (action) {
159
                int err = verify_area(VERIFY_READ, action, sizeof(*action));
160
                if (err)
161
                        return err;
162
                if (signum==SIGKILL || signum==SIGSTOP)
163
                        return -EINVAL;
164
                memcpy_fromfs(&new_sa, action, sizeof(struct sigaction));
165
                if (new_sa.sa_handler != SIG_DFL && new_sa.sa_handler != SIG_IGN) {
166
                        err = verify_area(VERIFY_READ, new_sa.sa_handler, 1);
167
                        if (err)
168
                                return err;
169
                }
170
        }
171
        if (oldaction) {
172
                int err = verify_area(VERIFY_WRITE, oldaction, sizeof(*oldaction));
173
                if (err)
174
                        return err;
175
                memcpy_tofs(oldaction, p, sizeof(struct sigaction));
176
        }
177
        if (action) {
178
                *p = new_sa;
179
                check_pending(signum);
180
        }
181
        return 0;
182
}

powered by: WebSVN 2.1.0

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