kern_sig_13.c revision 1.6
1/*	$NetBSD: kern_sig_13.c,v 1.6 2001/11/13 02:08:01 lukem Exp $	*/
2
3/*-
4 * Copyright (c) 1998 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Charles M. Hannum.
9 *
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.
18 * 3. All advertising materials mentioning features or use of this software
19 *    must display the following acknowledgement:
20 *        This product includes software developed by the NetBSD
21 *        Foundation, Inc. and its contributors.
22 * 4. Neither the name of The NetBSD Foundation nor the names of its
23 *    contributors may be used to endorse or promote products derived
24 *    from this software without specific prior written permission.
25 *
26 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 * POSSIBILITY OF SUCH DAMAGE.
37 */
38
39#include <sys/cdefs.h>
40__KERNEL_RCSID(0, "$NetBSD: kern_sig_13.c,v 1.6 2001/11/13 02:08:01 lukem Exp $");
41
42#include <sys/param.h>
43#include <sys/proc.h>
44#include <sys/signal.h>
45#include <sys/signalvar.h>
46#include <sys/systm.h>
47
48#include <sys/mount.h>
49#include <sys/syscallargs.h>
50
51#include <machine/limits.h>
52
53#include <compat/common/compat_util.h>
54
55void
56native_sigset13_to_sigset(oss, ss)
57	const sigset13_t *oss;
58	sigset_t *ss;
59{
60
61	ss->__bits[0] = *oss;
62	ss->__bits[1] = 0;
63	ss->__bits[2] = 0;
64	ss->__bits[3] = 0;
65}
66
67void
68native_sigset_to_sigset13(ss, oss)
69	const sigset_t *ss;
70	sigset13_t *oss;
71{
72
73	*oss = ss->__bits[0];
74}
75
76void
77native_sigaction13_to_sigaction(osa, sa)
78	const struct sigaction13 *osa;
79	struct sigaction *sa;
80{
81
82	sa->sa_handler = osa->sa_handler;
83	native_sigset13_to_sigset(&osa->sa_mask, &sa->sa_mask);
84	sa->sa_flags = osa->sa_flags;
85}
86
87void
88native_sigaction_to_sigaction13(sa, osa)
89	const struct sigaction *sa;
90	struct sigaction13 *osa;
91{
92
93	osa->sa_handler = sa->sa_handler;
94	native_sigset_to_sigset13(&sa->sa_mask, &osa->sa_mask);
95	osa->sa_flags = sa->sa_flags;
96}
97
98void
99native_sigaltstack13_to_sigaltstack(osa, sa)
100	const struct sigaltstack13 *osa;
101	struct sigaltstack *sa;
102{
103
104	sa->ss_sp = osa->ss_sp;
105	sa->ss_size = osa->ss_size;
106	sa->ss_flags = osa->ss_flags;
107}
108
109void
110native_sigaltstack_to_sigaltstack13(sa, osa)
111	const struct sigaltstack *sa;
112	struct sigaltstack13 *osa;
113{
114
115	osa->ss_sp = sa->ss_sp;
116	osa->ss_size = sa->ss_size;
117	osa->ss_flags = sa->ss_flags;
118}
119
120int
121compat_13_sys_sigaltstack(p, v, retval)
122	struct proc *p;
123	void *v;
124	register_t *retval;
125{
126	struct compat_13_sys_sigaltstack_args /* {
127		syscallarg(const struct sigaltstack13 *) nss;
128		syscallarg(struct sigaltstack13 *) oss;
129	} */ *uap = v;
130	struct sigaltstack13 ness, oess;
131	struct sigaltstack nbss, obss;
132	int error;
133
134	if (SCARG(uap, nss)) {
135		error = copyin(SCARG(uap, nss), &ness, sizeof(ness));
136		if (error)
137			return (error);
138		native_sigaltstack13_to_sigaltstack(&ness, &nbss);
139	}
140	error = sigaltstack1(p,
141	    SCARG(uap, nss) ? &nbss : 0, SCARG(uap, oss) ? &obss : 0);
142	if (error)
143		return (error);
144	if (SCARG(uap, oss)) {
145		native_sigaltstack_to_sigaltstack13(&obss, &oess);
146		error = copyout(&oess, SCARG(uap, oss), sizeof(oess));
147		if (error)
148			return (error);
149	}
150	return (0);
151}
152
153int
154compat_13_sys_sigaction(p, v, retval)
155	struct proc *p;
156	void *v;
157	register_t *retval;
158{
159	struct compat_13_sys_sigaction_args /* {
160		syscallarg(int) signum;
161		syscallarg(const struct sigaction13 *) nsa;
162		syscallarg(struct sigaction13 *) osa;
163	} */ *uap = v;
164	struct sigaction13 nesa, oesa;
165	struct sigaction nbsa, obsa;
166	int error;
167
168	if (SCARG(uap, nsa)) {
169		error = copyin(SCARG(uap, nsa), &nesa, sizeof(nesa));
170		if (error)
171			return (error);
172		native_sigaction13_to_sigaction(&nesa, &nbsa);
173	}
174	error = sigaction1(p, SCARG(uap, signum),
175	    SCARG(uap, nsa) ? &nbsa : 0, SCARG(uap, osa) ? &obsa : 0);
176	if (error)
177		return (error);
178	if (SCARG(uap, osa)) {
179		native_sigaction_to_sigaction13(&obsa, &oesa);
180		error = copyout(&oesa, SCARG(uap, osa), sizeof(oesa));
181		if (error)
182			return (error);
183	}
184	return (0);
185}
186
187int
188compat_13_sys_sigprocmask(p, v, retval)
189	struct proc *p;
190	void *v;
191	register_t *retval;
192{
193	struct compat_13_sys_sigprocmask_args /* {
194		syscallarg(int) how;
195		syscallarg(int) mask;
196	} */ *uap = v;
197	sigset13_t ness, oess;
198	sigset_t nbss, obss;
199	int error;
200
201	ness = SCARG(uap, mask);
202	native_sigset13_to_sigset(&ness, &nbss);
203	error = sigprocmask1(p, SCARG(uap, how), &nbss, &obss);
204	if (error)
205		return (error);
206	native_sigset_to_sigset13(&obss, &oess);
207	*retval = oess;
208	return (0);
209}
210
211int
212compat_13_sys_sigpending(p, v, retval)
213	struct proc *p;
214	void *v;
215	register_t *retval;
216{
217	sigset13_t ess;
218	sigset_t bss;
219
220	sigpending1(p, &bss);
221	native_sigset_to_sigset13(&bss, &ess);
222	*retval = ess;
223	return (0);
224}
225
226int
227compat_13_sys_sigsuspend(p, v, retval)
228	struct proc *p;
229	void *v;
230	register_t *retval;
231{
232	struct compat_13_sys_sigsuspend_args /* {
233		syscallarg(sigset13_t) mask;
234	} */ *uap = v;
235	sigset13_t ess;
236	sigset_t bss;
237
238	ess = SCARG(uap, mask);
239	native_sigset13_to_sigset(&ess, &bss);
240	return (sigsuspend1(p, &bss));
241}
242