kern_sig_43.c revision 1.2 1 /* $NetBSD: kern_sig_43.c,v 1.2 1995/08/15 16:52:30 mycroft Exp $ */
2
3 /*
4 * Copyright (c) 1982, 1986, 1989, 1991, 1993
5 * The Regents of the University of California. All rights reserved.
6 * (c) UNIX System Laboratories, Inc.
7 * All or some portions of this file are derived from material licensed
8 * to the University of California by American Telephone and Telegraph
9 * Co. or Unix System Laboratories, Inc. and are reproduced herein with
10 * the permission of UNIX System Laboratories, Inc.
11 *
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
14 * are met:
15 * 1. Redistributions of source code must retain the above copyright
16 * notice, this list of conditions and the following disclaimer.
17 * 2. Redistributions in binary form must reproduce the above copyright
18 * notice, this list of conditions and the following disclaimer in the
19 * documentation and/or other materials provided with the distribution.
20 * 3. All advertising materials mentioning features or use of this software
21 * must display the following acknowledgement:
22 * This product includes software developed by the University of
23 * California, Berkeley and its contributors.
24 * 4. Neither the name of the University nor the names of its contributors
25 * may be used to endorse or promote products derived from this software
26 * without specific prior written permission.
27 *
28 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
29 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
30 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
31 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
32 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
33 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
34 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
35 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
36 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
37 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
38 * SUCH DAMAGE.
39 *
40 * @(#)kern_sig.c 8.7 (Berkeley) 4/18/94
41 */
42
43 #include <sys/param.h>
44 #include <sys/signalvar.h>
45 #include <sys/resourcevar.h>
46 #include <sys/namei.h>
47 #include <sys/vnode.h>
48 #include <sys/proc.h>
49 #include <sys/systm.h>
50 #include <sys/timeb.h>
51 #include <sys/times.h>
52 #include <sys/buf.h>
53 #include <sys/acct.h>
54 #include <sys/file.h>
55 #include <sys/kernel.h>
56 #include <sys/wait.h>
57 #include <sys/ktrace.h>
58 #include <sys/syslog.h>
59 #include <sys/stat.h>
60 #include <sys/core.h>
61
62 #include <sys/mount.h>
63 #include <sys/syscallargs.h>
64
65 #include <machine/cpu.h>
66
67 #include <vm/vm.h>
68 #include <sys/user.h> /* for coredump */
69
70 int
71 compat_43_sigblock(p, uap, retval)
72 register struct proc *p;
73 struct compat_43_sigblock_args /* {
74 syscallarg(int) mask;
75 } */ *uap;
76 register_t *retval;
77 {
78
79 (void) splhigh();
80 *retval = p->p_sigmask;
81 p->p_sigmask |= SCARG(uap, mask) &~ sigcantmask;
82 (void) spl0();
83 return (0);
84 }
85
86
87 int
88 compat_43_sigsetmask(p, uap, retval)
89 struct proc *p;
90 struct compat_43_sigsetmask_args /* {
91 syscallarg(int) mask;
92 } */ *uap;
93 register_t *retval;
94 {
95
96 (void) splhigh();
97 *retval = p->p_sigmask;
98 p->p_sigmask = SCARG(uap, mask) &~ sigcantmask;
99 (void) spl0();
100 return (0);
101 }
102
103
104 /* ARGSUSED */
105 int
106 compat_43_sigstack(p, uap, retval)
107 struct proc *p;
108 register struct compat_43_sigstack_args /* {
109 syscallarg(struct sigstack *) nss;
110 syscallarg(struct sigstack *) oss;
111 } */ *uap;
112 register_t *retval;
113 {
114 struct sigstack ss;
115 struct sigacts *psp;
116 int error = 0;
117
118 psp = p->p_sigacts;
119 ss.ss_sp = psp->ps_sigstk.ss_base;
120 ss.ss_onstack = psp->ps_sigstk.ss_flags & SS_ONSTACK;
121 if (SCARG(uap, oss) && (error = copyout((caddr_t)&ss,
122 (caddr_t)SCARG(uap, oss), sizeof (struct sigstack))))
123 return (error);
124 if (SCARG(uap, nss) && (error = copyin((caddr_t)SCARG(uap, nss),
125 (caddr_t)&ss, sizeof (ss))) == 0) {
126 psp->ps_sigstk.ss_base = ss.ss_sp;
127 psp->ps_sigstk.ss_size = 0;
128 psp->ps_sigstk.ss_flags |= ss.ss_onstack & SS_ONSTACK;
129 psp->ps_flags |= SAS_ALTSTACK;
130 }
131 return (error);
132 }
133
134 /*
135 * Generalized interface signal handler, 4.3-compatible.
136 */
137 /* ARGSUSED */
138 int
139 compat_43_sigvec(p, uap, retval)
140 struct proc *p;
141 register struct compat_43_sigvec_args /* {
142 syscallarg(int) signum;
143 syscallarg(struct sigvec *) nsv;
144 syscallarg(struct sigvec *) osv;
145 } */ *uap;
146 register_t *retval;
147 {
148 struct sigvec vec;
149 register struct sigacts *ps = p->p_sigacts;
150 register struct sigvec *sv;
151 register int signum;
152 int bit, error;
153
154 signum = SCARG(uap, signum);
155 if (signum <= 0 || signum >= NSIG ||
156 signum == SIGKILL || signum == SIGSTOP)
157 return (EINVAL);
158 sv = &vec;
159 if (SCARG(uap, osv)) {
160 *(sig_t *)&sv->sv_handler = ps->ps_sigact[signum];
161 sv->sv_mask = ps->ps_catchmask[signum];
162 bit = sigmask(signum);
163 sv->sv_flags = 0;
164 if ((ps->ps_sigonstack & bit) != 0)
165 sv->sv_flags |= SV_ONSTACK;
166 if ((ps->ps_sigintr & bit) != 0)
167 sv->sv_flags |= SV_INTERRUPT;
168 if (p->p_flag & P_NOCLDSTOP)
169 sv->sv_flags |= SA_NOCLDSTOP;
170 if (error = copyout((caddr_t)sv, (caddr_t)SCARG(uap, osv),
171 sizeof (vec)))
172 return (error);
173 }
174 if (SCARG(uap, nsv)) {
175 if (error = copyin((caddr_t)SCARG(uap, nsv), (caddr_t)sv,
176 sizeof (vec)))
177 return (error);
178 sv->sv_flags ^= SA_RESTART; /* opposite of SV_INTERRUPT */
179 setsigvec(p, signum, (struct sigaction *)sv);
180 }
181 return (0);
182 }
183
184
185 /* ARGSUSED */
186 int
187 compat_43_killpg(p, uap, retval)
188 struct proc *p;
189 register struct compat_43_killpg_args /* {
190 syscallarg(int) pgid;
191 syscallarg(int) signum;
192 } */ *uap;
193 register_t *retval;
194 {
195
196 #ifdef COMPAT_09
197 SCARG(uap, pgid) = (short) SCARG(uap, pgid);
198 #endif
199
200 if ((u_int)SCARG(uap, signum) >= NSIG)
201 return (EINVAL);
202 return (killpg1(p, SCARG(uap, signum), SCARG(uap, pgid), 0));
203 }
204