kern_sig_43.c revision 1.4 1 1.4 thorpej /* $NetBSD: kern_sig_43.c,v 1.4 1995/09/19 22:02:03 thorpej 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.1 christos
43 1.1 christos #include <sys/param.h>
44 1.1 christos #include <sys/signalvar.h>
45 1.1 christos #include <sys/resourcevar.h>
46 1.1 christos #include <sys/namei.h>
47 1.1 christos #include <sys/vnode.h>
48 1.1 christos #include <sys/proc.h>
49 1.1 christos #include <sys/systm.h>
50 1.1 christos #include <sys/timeb.h>
51 1.1 christos #include <sys/times.h>
52 1.1 christos #include <sys/buf.h>
53 1.1 christos #include <sys/acct.h>
54 1.1 christos #include <sys/file.h>
55 1.1 christos #include <sys/kernel.h>
56 1.1 christos #include <sys/wait.h>
57 1.1 christos #include <sys/ktrace.h>
58 1.1 christos #include <sys/syslog.h>
59 1.1 christos #include <sys/stat.h>
60 1.1 christos #include <sys/core.h>
61 1.1 christos
62 1.1 christos #include <sys/mount.h>
63 1.1 christos #include <sys/syscallargs.h>
64 1.1 christos
65 1.1 christos #include <machine/cpu.h>
66 1.1 christos
67 1.1 christos #include <vm/vm.h>
68 1.1 christos #include <sys/user.h> /* for coredump */
69 1.1 christos
70 1.1 christos int
71 1.4 thorpej compat_43_sigblock(p, v, retval)
72 1.1 christos register struct proc *p;
73 1.4 thorpej void *v;
74 1.4 thorpej register_t *retval;
75 1.4 thorpej {
76 1.1 christos struct compat_43_sigblock_args /* {
77 1.1 christos syscallarg(int) mask;
78 1.4 thorpej } */ *uap = v;
79 1.1 christos
80 1.1 christos (void) splhigh();
81 1.1 christos *retval = p->p_sigmask;
82 1.1 christos p->p_sigmask |= SCARG(uap, mask) &~ sigcantmask;
83 1.1 christos (void) spl0();
84 1.1 christos return (0);
85 1.1 christos }
86 1.1 christos
87 1.1 christos
88 1.1 christos int
89 1.4 thorpej compat_43_sigsetmask(p, v, retval)
90 1.1 christos struct proc *p;
91 1.4 thorpej void *v;
92 1.4 thorpej register_t *retval;
93 1.4 thorpej {
94 1.1 christos struct compat_43_sigsetmask_args /* {
95 1.1 christos syscallarg(int) mask;
96 1.4 thorpej } */ *uap = v;
97 1.1 christos
98 1.1 christos (void) splhigh();
99 1.1 christos *retval = p->p_sigmask;
100 1.1 christos p->p_sigmask = SCARG(uap, mask) &~ sigcantmask;
101 1.1 christos (void) spl0();
102 1.1 christos return (0);
103 1.1 christos }
104 1.1 christos
105 1.1 christos
106 1.1 christos /* ARGSUSED */
107 1.1 christos int
108 1.4 thorpej compat_43_sigstack(p, v, retval)
109 1.1 christos struct proc *p;
110 1.4 thorpej void *v;
111 1.4 thorpej register_t *retval;
112 1.4 thorpej {
113 1.1 christos register struct compat_43_sigstack_args /* {
114 1.1 christos syscallarg(struct sigstack *) nss;
115 1.1 christos syscallarg(struct sigstack *) oss;
116 1.4 thorpej } */ *uap = v;
117 1.1 christos struct sigstack ss;
118 1.1 christos struct sigacts *psp;
119 1.1 christos int error = 0;
120 1.1 christos
121 1.1 christos psp = p->p_sigacts;
122 1.1 christos ss.ss_sp = psp->ps_sigstk.ss_base;
123 1.2 mycroft ss.ss_onstack = psp->ps_sigstk.ss_flags & SS_ONSTACK;
124 1.1 christos if (SCARG(uap, oss) && (error = copyout((caddr_t)&ss,
125 1.1 christos (caddr_t)SCARG(uap, oss), sizeof (struct sigstack))))
126 1.1 christos return (error);
127 1.3 mycroft if (SCARG(uap, nss) == 0)
128 1.3 mycroft return (0);
129 1.3 mycroft if (error = copyin((caddr_t)SCARG(uap, nss), (caddr_t)&ss,
130 1.3 mycroft sizeof (ss)))
131 1.3 mycroft return (error);
132 1.3 mycroft psp->ps_flags |= SAS_ALTSTACK;
133 1.3 mycroft psp->ps_sigstk.ss_base = ss.ss_sp;
134 1.3 mycroft psp->ps_sigstk.ss_size = 0;
135 1.3 mycroft psp->ps_sigstk.ss_flags |= ss.ss_onstack & SS_ONSTACK;
136 1.3 mycroft return (0);
137 1.1 christos }
138 1.1 christos
139 1.1 christos /*
140 1.1 christos * Generalized interface signal handler, 4.3-compatible.
141 1.1 christos */
142 1.1 christos /* ARGSUSED */
143 1.1 christos int
144 1.4 thorpej compat_43_sigvec(p, v, retval)
145 1.1 christos struct proc *p;
146 1.4 thorpej void *v;
147 1.4 thorpej register_t *retval;
148 1.4 thorpej {
149 1.1 christos register struct compat_43_sigvec_args /* {
150 1.1 christos syscallarg(int) signum;
151 1.1 christos syscallarg(struct sigvec *) nsv;
152 1.1 christos syscallarg(struct sigvec *) osv;
153 1.4 thorpej } */ *uap = v;
154 1.1 christos struct sigvec vec;
155 1.1 christos register struct sigacts *ps = p->p_sigacts;
156 1.1 christos register struct sigvec *sv;
157 1.1 christos register int signum;
158 1.1 christos int bit, error;
159 1.1 christos
160 1.1 christos signum = SCARG(uap, signum);
161 1.1 christos if (signum <= 0 || signum >= NSIG ||
162 1.1 christos signum == SIGKILL || signum == SIGSTOP)
163 1.1 christos return (EINVAL);
164 1.1 christos sv = &vec;
165 1.1 christos if (SCARG(uap, osv)) {
166 1.1 christos *(sig_t *)&sv->sv_handler = ps->ps_sigact[signum];
167 1.1 christos sv->sv_mask = ps->ps_catchmask[signum];
168 1.1 christos bit = sigmask(signum);
169 1.1 christos sv->sv_flags = 0;
170 1.1 christos if ((ps->ps_sigonstack & bit) != 0)
171 1.1 christos sv->sv_flags |= SV_ONSTACK;
172 1.1 christos if ((ps->ps_sigintr & bit) != 0)
173 1.1 christos sv->sv_flags |= SV_INTERRUPT;
174 1.3 mycroft if ((ps->ps_sigreset & bit) != 0)
175 1.3 mycroft sv->sv_flags |= SV_RESETHAND;
176 1.1 christos if (p->p_flag & P_NOCLDSTOP)
177 1.1 christos sv->sv_flags |= SA_NOCLDSTOP;
178 1.3 mycroft sv->sv_mask &= ~bit;
179 1.1 christos if (error = copyout((caddr_t)sv, (caddr_t)SCARG(uap, osv),
180 1.1 christos sizeof (vec)))
181 1.1 christos return (error);
182 1.1 christos }
183 1.1 christos if (SCARG(uap, nsv)) {
184 1.1 christos if (error = copyin((caddr_t)SCARG(uap, nsv), (caddr_t)sv,
185 1.1 christos sizeof (vec)))
186 1.1 christos return (error);
187 1.1 christos sv->sv_flags ^= SA_RESTART; /* opposite of SV_INTERRUPT */
188 1.1 christos setsigvec(p, signum, (struct sigaction *)sv);
189 1.1 christos }
190 1.1 christos return (0);
191 1.1 christos }
192 1.1 christos
193 1.1 christos
194 1.1 christos /* ARGSUSED */
195 1.1 christos int
196 1.4 thorpej compat_43_killpg(p, v, retval)
197 1.1 christos struct proc *p;
198 1.4 thorpej void *v;
199 1.4 thorpej register_t *retval;
200 1.4 thorpej {
201 1.1 christos register struct compat_43_killpg_args /* {
202 1.1 christos syscallarg(int) pgid;
203 1.1 christos syscallarg(int) signum;
204 1.4 thorpej } */ *uap = v;
205 1.1 christos
206 1.1 christos #ifdef COMPAT_09
207 1.1 christos SCARG(uap, pgid) = (short) SCARG(uap, pgid);
208 1.1 christos #endif
209 1.1 christos
210 1.1 christos if ((u_int)SCARG(uap, signum) >= NSIG)
211 1.1 christos return (EINVAL);
212 1.1 christos return (killpg1(p, SCARG(uap, signum), SCARG(uap, pgid), 0));
213 1.1 christos }
214