kern_sig_43.c revision 1.3 1 /* $NetBSD: kern_sig_43.c,v 1.3 1995/08/17 03:07:47 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) == 0)
125 return (0);
126 if (error = copyin((caddr_t)SCARG(uap, nss), (caddr_t)&ss,
127 sizeof (ss)))
128 return (error);
129 psp->ps_flags |= SAS_ALTSTACK;
130 psp->ps_sigstk.ss_base = ss.ss_sp;
131 psp->ps_sigstk.ss_size = 0;
132 psp->ps_sigstk.ss_flags |= ss.ss_onstack & SS_ONSTACK;
133 return (0);
134 }
135
136 /*
137 * Generalized interface signal handler, 4.3-compatible.
138 */
139 /* ARGSUSED */
140 int
141 compat_43_sigvec(p, uap, retval)
142 struct proc *p;
143 register struct compat_43_sigvec_args /* {
144 syscallarg(int) signum;
145 syscallarg(struct sigvec *) nsv;
146 syscallarg(struct sigvec *) osv;
147 } */ *uap;
148 register_t *retval;
149 {
150 struct sigvec vec;
151 register struct sigacts *ps = p->p_sigacts;
152 register struct sigvec *sv;
153 register int signum;
154 int bit, error;
155
156 signum = SCARG(uap, signum);
157 if (signum <= 0 || signum >= NSIG ||
158 signum == SIGKILL || signum == SIGSTOP)
159 return (EINVAL);
160 sv = &vec;
161 if (SCARG(uap, osv)) {
162 *(sig_t *)&sv->sv_handler = ps->ps_sigact[signum];
163 sv->sv_mask = ps->ps_catchmask[signum];
164 bit = sigmask(signum);
165 sv->sv_flags = 0;
166 if ((ps->ps_sigonstack & bit) != 0)
167 sv->sv_flags |= SV_ONSTACK;
168 if ((ps->ps_sigintr & bit) != 0)
169 sv->sv_flags |= SV_INTERRUPT;
170 if ((ps->ps_sigreset & bit) != 0)
171 sv->sv_flags |= SV_RESETHAND;
172 if (p->p_flag & P_NOCLDSTOP)
173 sv->sv_flags |= SA_NOCLDSTOP;
174 sv->sv_mask &= ~bit;
175 if (error = copyout((caddr_t)sv, (caddr_t)SCARG(uap, osv),
176 sizeof (vec)))
177 return (error);
178 }
179 if (SCARG(uap, nsv)) {
180 if (error = copyin((caddr_t)SCARG(uap, nsv), (caddr_t)sv,
181 sizeof (vec)))
182 return (error);
183 sv->sv_flags ^= SA_RESTART; /* opposite of SV_INTERRUPT */
184 setsigvec(p, signum, (struct sigaction *)sv);
185 }
186 return (0);
187 }
188
189
190 /* ARGSUSED */
191 int
192 compat_43_killpg(p, uap, retval)
193 struct proc *p;
194 register struct compat_43_killpg_args /* {
195 syscallarg(int) pgid;
196 syscallarg(int) signum;
197 } */ *uap;
198 register_t *retval;
199 {
200
201 #ifdef COMPAT_09
202 SCARG(uap, pgid) = (short) SCARG(uap, pgid);
203 #endif
204
205 if ((u_int)SCARG(uap, signum) >= NSIG)
206 return (EINVAL);
207 return (killpg1(p, SCARG(uap, signum), SCARG(uap, pgid), 0));
208 }
209