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