Sync usage with man page.
[netbsd-mini2440.git] / sys / compat / common / kern_sig_43.c
blob4da470683032d448804739b390909d1c7caa7b6c
1 /* $NetBSD: kern_sig_43.c,v 1.32 2008/04/28 20:23:41 martin Exp $ */
3 /*-
4 * Copyright (c) 1998 The NetBSD Foundation, Inc.
5 * All rights reserved.
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Charles M. Hannum.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
32 #include <sys/cdefs.h>
33 __KERNEL_RCSID(0, "$NetBSD: kern_sig_43.c,v 1.32 2008/04/28 20:23:41 martin Exp $");
35 #if defined(_KERNEL_OPT)
36 #include "opt_compat_netbsd.h"
37 #endif
39 #include <sys/param.h>
40 #include <sys/signalvar.h>
41 #include <sys/resourcevar.h>
42 #include <sys/namei.h>
43 #include <sys/vnode.h>
44 #include <sys/proc.h>
45 #include <sys/systm.h>
46 #include <sys/timeb.h>
47 #include <sys/times.h>
48 #include <sys/buf.h>
49 #include <sys/acct.h>
50 #include <sys/file.h>
51 #include <sys/kernel.h>
52 #include <sys/wait.h>
53 #include <sys/ktrace.h>
54 #include <sys/syslog.h>
55 #include <sys/stat.h>
56 #include <sys/core.h>
57 #include <sys/kauth.h>
59 #include <sys/mount.h>
60 #include <sys/syscallargs.h>
62 #include <sys/cpu.h>
64 #include <compat/sys/signal.h>
66 void compat_43_sigmask_to_sigset(const int *, sigset_t *);
67 void compat_43_sigset_to_sigmask(const sigset_t *, int *);
68 void compat_43_sigvec_to_sigaction(const struct sigvec *, struct sigaction *);
69 void compat_43_sigaction_to_sigvec(const struct sigaction *, struct sigvec *);
70 void compat_43_sigstack_to_sigaltstack(const struct sigstack *, struct sigaltstack *);
71 void compat_43_sigaltstack_to_sigstack(const struct sigaltstack *, struct sigstack *);
73 void
74 compat_43_sigmask_to_sigset(const int *sm, sigset_t *ss)
77 ss->__bits[0] = *sm;
78 ss->__bits[1] = 0;
79 ss->__bits[2] = 0;
80 ss->__bits[3] = 0;
83 void
84 compat_43_sigset_to_sigmask(const sigset_t *ss, int *sm)
87 *sm = ss->__bits[0];
90 void
91 compat_43_sigvec_to_sigaction(const struct sigvec *sv, struct sigaction *sa)
93 sa->sa_handler = sv->sv_handler;
94 compat_43_sigmask_to_sigset(&sv->sv_mask, &sa->sa_mask);
95 sa->sa_flags = sv->sv_flags ^ SA_RESTART;
98 void
99 compat_43_sigaction_to_sigvec(const struct sigaction *sa, struct sigvec *sv)
101 sv->sv_handler = sa->sa_handler;
102 compat_43_sigset_to_sigmask(&sa->sa_mask, &sv->sv_mask);
103 sv->sv_flags = sa->sa_flags ^ SA_RESTART;
106 void
107 compat_43_sigstack_to_sigaltstack(const struct sigstack *ss, struct sigaltstack *sa)
109 sa->ss_sp = ss->ss_sp;
110 sa->ss_size = SIGSTKSZ; /* Use the recommended size */
111 sa->ss_flags = 0;
112 if (ss->ss_onstack)
113 sa->ss_flags |= SS_ONSTACK;
116 void
117 compat_43_sigaltstack_to_sigstack(const struct sigaltstack *sa, struct sigstack *ss)
119 ss->ss_sp = sa->ss_sp;
120 if (sa->ss_flags & SS_ONSTACK)
121 ss->ss_onstack = 1;
122 else
123 ss->ss_onstack = 0;
127 compat_43_sys_sigblock(struct lwp *l, const struct compat_43_sys_sigblock_args *uap, register_t *retval)
129 /* {
130 syscallarg(int) mask;
131 } */
132 struct proc *p = l->l_proc;
133 int nsm, osm;
134 sigset_t nss, oss;
135 int error;
137 nsm = SCARG(uap, mask);
138 compat_43_sigmask_to_sigset(&nsm, &nss);
139 mutex_enter(p->p_lock);
140 error = sigprocmask1(l, SIG_BLOCK, &nss, &oss);
141 mutex_exit(p->p_lock);
142 if (error)
143 return (error);
144 compat_43_sigset_to_sigmask(&oss, &osm);
145 *retval = osm;
146 return (0);
150 compat_43_sys_sigsetmask(struct lwp *l, const struct compat_43_sys_sigsetmask_args *uap, register_t *retval)
152 /* {
153 syscallarg(int) mask;
154 } */
155 struct proc *p = l->l_proc;
156 int nsm, osm;
157 sigset_t nss, oss;
158 int error;
160 nsm = SCARG(uap, mask);
161 compat_43_sigmask_to_sigset(&nsm, &nss);
162 mutex_enter(p->p_lock);
163 error = sigprocmask1(l, SIG_SETMASK, &nss, &oss);
164 mutex_exit(p->p_lock);
165 if (error)
166 return (error);
167 compat_43_sigset_to_sigmask(&oss, &osm);
168 *retval = osm;
169 return (0);
172 /* ARGSUSED */
174 compat_43_sys_sigstack(struct lwp *l, const struct compat_43_sys_sigstack_args *uap, register_t *retval)
176 /* {
177 syscallarg(struct sigstack *) nss;
178 syscallarg(struct sigstack *) oss;
179 } */
180 struct sigstack nss, oss;
181 struct sigaltstack nsa, osa;
182 int error;
184 if (SCARG(uap, nss)) {
185 error = copyin(SCARG(uap, nss), &nss, sizeof(nss));
186 if (error)
187 return (error);
188 compat_43_sigstack_to_sigaltstack(&nss, &nsa);
190 error = sigaltstack1(l,
191 SCARG(uap, nss) ? &nsa : 0, SCARG(uap, oss) ? &osa : 0);
192 if (error)
193 return (error);
194 if (SCARG(uap, oss)) {
195 compat_43_sigaltstack_to_sigstack(&osa, &oss);
196 error = copyout(&oss, SCARG(uap, oss), sizeof(oss));
197 if (error)
198 return (error);
200 return (0);
204 * Generalized interface signal handler, 4.3-compatible.
206 /* ARGSUSED */
208 compat_43_sys_sigvec(struct lwp *l, const struct compat_43_sys_sigvec_args *uap, register_t *retval)
210 /* {
211 syscallarg(int) signum;
212 syscallarg(const struct sigvec *) nsv;
213 syscallarg(struct sigvec *) osv;
214 } */
215 struct sigvec nsv, osv;
216 struct sigaction nsa, osa;
217 int error;
219 if (SCARG(uap, nsv)) {
220 error = copyin(SCARG(uap, nsv), &nsv, sizeof(nsv));
221 if (error)
222 return (error);
223 compat_43_sigvec_to_sigaction(&nsv, &nsa);
225 error = sigaction1(l, SCARG(uap, signum),
226 SCARG(uap, nsv) ? &nsa : 0, SCARG(uap, osv) ? &osa : 0,
227 NULL, 0);
228 if (error)
229 return (error);
230 if (SCARG(uap, osv)) {
231 compat_43_sigaction_to_sigvec(&osa, &osv);
232 error = copyout(&osv, SCARG(uap, osv), sizeof(osv));
233 if (error)
234 return (error);
236 return (0);
240 /* ARGSUSED */
242 compat_43_sys_killpg(struct lwp *l, const struct compat_43_sys_killpg_args *uap, register_t *retval)
244 /* {
245 syscallarg(int) pgid;
246 syscallarg(int) signum;
247 } */
248 ksiginfo_t ksi;
249 int pgid = SCARG(uap, pgid);
251 #ifdef COMPAT_09
252 pgid &= 0xffff;
253 #endif
255 if ((u_int)SCARG(uap, signum) >= NSIG)
256 return (EINVAL);
257 memset(&ksi, 0, sizeof(ksi));
258 ksi.ksi_signo = SCARG(uap, signum);
259 ksi.ksi_code = SI_USER;
260 ksi.ksi_pid = l->l_proc->p_pid;
261 ksi.ksi_uid = kauth_cred_geteuid(l->l_cred);
262 return killpg1(l, &ksi, pgid, 0);