1 /* $OpenBSD: kern_sig_43.c,v 1.7 2003/06/02 23:27:59 millert Exp $ */
2 /* $NetBSD: kern_sig_43.c,v 1.7 1996/03/14 19:31:47 christos Exp $ */
3
4 /*
5 * Copyright (c) 1982, 1986, 1989, 1991, 1993
6 * The Regents of the University of California. All rights reserved.
7 * (c) UNIX System Laboratories, Inc.
8 * All or some portions of this file are derived from material licensed
9 * to the University of California by American Telephone and Telegraph
10 * Co. or Unix System Laboratories, Inc. and are reproduced herein with
11 * the permission of UNIX System Laboratories, Inc.
12 *
13 * Redistribution and use in source and binary forms, with or without
14 * modification, are permitted provided that the following conditions
15 * are met:
16 * 1. Redistributions of source code must retain the above copyright
17 * notice, this list of conditions and the following disclaimer.
18 * 2. Redistributions in binary form must reproduce the above copyright
19 * notice, this list of conditions and the following disclaimer in the
20 * documentation and/or other materials provided with the distribution.
21 * 3. Neither the name of the University nor the names of its contributors
22 * may be used to endorse or promote products derived from this software
23 * without specific prior written permission.
24 *
25 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
26 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
29 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
30 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
31 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
32 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
34 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35 * SUCH DAMAGE.
36 *
37 * @(#)kern_sig.c 8.7 (Berkeley) 4/18/94
38 */
39
40 #include <sys/param.h>
41 #include <sys/signalvar.h>
42 #include <sys/resourcevar.h>
43 #include <sys/namei.h>
44 #include <sys/vnode.h>
45 #include <sys/proc.h>
46 #include <sys/systm.h>
47 #include <sys/timeb.h>
48 #include <sys/times.h>
49 #include <sys/buf.h>
50 #include <sys/acct.h>
51 #include <sys/file.h>
52 #include <sys/kernel.h>
53 #include <sys/wait.h>
54 #include <sys/ktrace.h>
55 #include <sys/syslog.h>
56 #include <sys/stat.h>
57 #include <sys/core.h>
58
59 #include <sys/mount.h>
60 #include <sys/syscallargs.h>
61
62 #include <machine/cpu.h>
63
64 #include <uvm/uvm_extern.h>
65 #include <sys/user.h> /* for coredump */
66
67 int
68 compat_43_sys_sigblock(p, v, retval)
69 register struct proc *p;
70 void *v;
71 register_t *retval;
72 {
73 struct compat_43_sys_sigblock_args /* {
74 syscallarg(int) mask;
75 } */ *uap = v;
76 int s;
77
78 s = splhigh();
79 *retval = p->p_sigmask;
80 p->p_sigmask |= SCARG(uap, mask) &~ sigcantmask;
81 splx(s);
82 return (0);
83 }
84
85
86 int
87 compat_43_sys_sigsetmask(p, v, retval)
88 struct proc *p;
89 void *v;
90 register_t *retval;
91 {
92 struct compat_43_sys_sigsetmask_args /* {
93 syscallarg(int) mask;
94 } */ *uap = v;
95 int s;
96
97 s = splhigh();
98 *retval = p->p_sigmask;
99 p->p_sigmask = SCARG(uap, mask) &~ sigcantmask;
100 splx(s);
101 return (0);
102 }
103
104
105 /* ARGSUSED */
106 int
107 compat_43_sys_sigstack(p, v, retval)
108 struct proc *p;
109 void *v;
110 register_t *retval;
111 {
112 register struct compat_43_sys_sigstack_args /* {
113 syscallarg(struct sigstack *) nss;
114 syscallarg(struct sigstack *) oss;
115 } */ *uap = v;
116 struct sigstack ss;
117 struct sigacts *psp;
118 int error = 0;
119
120 psp = p->p_sigacts;
121 ss.ss_sp = psp->ps_sigstk.ss_sp;
122 ss.ss_onstack = psp->ps_sigstk.ss_flags & SS_ONSTACK;
123 if (SCARG(uap, oss) && (error = copyout((caddr_t)&ss,
124 (caddr_t)SCARG(uap, oss), sizeof (struct sigstack))))
125 return (error);
126 if (SCARG(uap, nss) == 0)
127 return (0);
128 error = copyin((caddr_t)SCARG(uap, nss), (caddr_t)&ss,
129 sizeof (ss));
130 if (error)
131 return (error);
132 psp->ps_flags |= SAS_ALTSTACK;
133 psp->ps_sigstk.ss_sp = 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_sys_sigvec(p, v, retval)
145 struct proc *p;
146 void *v;
147 register_t *retval;
148 {
149 register struct compat_43_sys_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 error = copyout((caddr_t)sv, (caddr_t)SCARG(uap, osv),
180 sizeof (vec));
181 if (error)
182 return (error);
183 }
184 if (SCARG(uap, nsv)) {
185 error = copyin((caddr_t)SCARG(uap, nsv), (caddr_t)sv,
186 sizeof (vec));
187 if (error)
188 return (error);
189 sv->sv_flags ^= SA_RESTART; /* opposite of SV_INTERRUPT */
190 setsigvec(p, signum, (struct sigaction *)sv);
191 }
192 return (0);
193 }
194
195
196 /* ARGSUSED */
197 int
198 compat_43_sys_killpg(p, v, retval)
199 struct proc *p;
200 void *v;
201 register_t *retval;
202 {
203 register struct compat_43_sys_killpg_args /* {
204 syscallarg(int) pgid;
205 syscallarg(int) signum;
206 } */ *uap = v;
207
208 if ((u_int)SCARG(uap, signum) >= NSIG)
209 return (EINVAL);
210 return (killpg1(p, SCARG(uap, signum), SCARG(uap, pgid), 0));
211 }