1 /* $NetBSD: kern_sig_43.c,v 1.32 2008/04/28 20:23:41 martin Exp $ */
4 * Copyright (c) 1998 The NetBSD Foundation, Inc.
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
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"
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>
45 #include <sys/systm.h>
46 #include <sys/timeb.h>
47 #include <sys/times.h>
51 #include <sys/kernel.h>
53 #include <sys/ktrace.h>
54 #include <sys/syslog.h>
57 #include <sys/kauth.h>
59 #include <sys/mount.h>
60 #include <sys/syscallargs.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
*);
74 compat_43_sigmask_to_sigset(const int *sm
, sigset_t
*ss
)
84 compat_43_sigset_to_sigmask(const sigset_t
*ss
, int *sm
)
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
;
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
;
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 */
113 sa
->ss_flags
|= SS_ONSTACK
;
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
)
127 compat_43_sys_sigblock(struct lwp
*l
, const struct compat_43_sys_sigblock_args
*uap
, register_t
*retval
)
130 syscallarg(int) mask;
132 struct proc
*p
= l
->l_proc
;
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
);
144 compat_43_sigset_to_sigmask(&oss
, &osm
);
150 compat_43_sys_sigsetmask(struct lwp
*l
, const struct compat_43_sys_sigsetmask_args
*uap
, register_t
*retval
)
153 syscallarg(int) mask;
155 struct proc
*p
= l
->l_proc
;
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
);
167 compat_43_sigset_to_sigmask(&oss
, &osm
);
174 compat_43_sys_sigstack(struct lwp
*l
, const struct compat_43_sys_sigstack_args
*uap
, register_t
*retval
)
177 syscallarg(struct sigstack *) nss;
178 syscallarg(struct sigstack *) oss;
180 struct sigstack nss
, oss
;
181 struct sigaltstack nsa
, osa
;
184 if (SCARG(uap
, nss
)) {
185 error
= copyin(SCARG(uap
, nss
), &nss
, sizeof(nss
));
188 compat_43_sigstack_to_sigaltstack(&nss
, &nsa
);
190 error
= sigaltstack1(l
,
191 SCARG(uap
, nss
) ? &nsa
: 0, SCARG(uap
, oss
) ? &osa
: 0);
194 if (SCARG(uap
, oss
)) {
195 compat_43_sigaltstack_to_sigstack(&osa
, &oss
);
196 error
= copyout(&oss
, SCARG(uap
, oss
), sizeof(oss
));
204 * Generalized interface signal handler, 4.3-compatible.
208 compat_43_sys_sigvec(struct lwp
*l
, const struct compat_43_sys_sigvec_args
*uap
, register_t
*retval
)
211 syscallarg(int) signum;
212 syscallarg(const struct sigvec *) nsv;
213 syscallarg(struct sigvec *) osv;
215 struct sigvec nsv
, osv
;
216 struct sigaction nsa
, osa
;
219 if (SCARG(uap
, nsv
)) {
220 error
= copyin(SCARG(uap
, nsv
), &nsv
, sizeof(nsv
));
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,
230 if (SCARG(uap
, osv
)) {
231 compat_43_sigaction_to_sigvec(&osa
, &osv
);
232 error
= copyout(&osv
, SCARG(uap
, osv
), sizeof(osv
));
242 compat_43_sys_killpg(struct lwp
*l
, const struct compat_43_sys_killpg_args
*uap
, register_t
*retval
)
245 syscallarg(int) pgid;
246 syscallarg(int) signum;
249 int pgid
= SCARG(uap
, pgid
);
255 if ((u_int
)SCARG(uap
, signum
) >= NSIG
)
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);