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