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