xref: /netbsd-src/sys/compat/common/kern_sig_13.c (revision d48f14661dda8638fee055ba15d35bdfb29b9fa8)
1 /*	$NetBSD: kern_sig_13.c,v 1.11 2005/12/11 12:19:56 christos 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.11 2005/12/11 12:19:56 christos 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/sa.h>
50 #include <sys/syscallargs.h>
51 
52 #include <machine/limits.h>
53 
54 #include <compat/sys/signal.h>
55 #include <compat/sys/signalvar.h>
56 #include <compat/common/compat_util.h>
57 
58 void
59 native_sigset13_to_sigset(oss, ss)
60 	const sigset13_t *oss;
61 	sigset_t *ss;
62 {
63 
64 	ss->__bits[0] = *oss;
65 	ss->__bits[1] = 0;
66 	ss->__bits[2] = 0;
67 	ss->__bits[3] = 0;
68 }
69 
70 void
71 native_sigset_to_sigset13(ss, oss)
72 	const sigset_t *ss;
73 	sigset13_t *oss;
74 {
75 
76 	*oss = ss->__bits[0];
77 }
78 
79 void
80 native_sigaction13_to_sigaction(osa, sa)
81 	const struct sigaction13 *osa;
82 	struct sigaction *sa;
83 {
84 
85 	sa->sa_handler = osa->osa_handler;
86 	native_sigset13_to_sigset(&osa->osa_mask, &sa->sa_mask);
87 	sa->sa_flags = osa->osa_flags;
88 }
89 
90 void
91 native_sigaction_to_sigaction13(sa, osa)
92 	const struct sigaction *sa;
93 	struct sigaction13 *osa;
94 {
95 
96 	osa->osa_handler = sa->sa_handler;
97 	native_sigset_to_sigset13(&sa->sa_mask, &osa->osa_mask);
98 	osa->osa_flags = sa->sa_flags;
99 }
100 
101 void
102 native_sigaltstack13_to_sigaltstack(osa, sa)
103 	const struct sigaltstack13 *osa;
104 	struct sigaltstack *sa;
105 {
106 
107 	sa->ss_sp = osa->ss_sp;
108 	sa->ss_size = osa->ss_size;
109 	sa->ss_flags = osa->ss_flags;
110 }
111 
112 void
113 native_sigaltstack_to_sigaltstack13(sa, osa)
114 	const struct sigaltstack *sa;
115 	struct sigaltstack13 *osa;
116 {
117 
118 	osa->ss_sp = sa->ss_sp;
119 	osa->ss_size = sa->ss_size;
120 	osa->ss_flags = sa->ss_flags;
121 }
122 
123 int
124 compat_13_sys_sigaltstack(struct lwp *l, void *v, 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 proc *p = l->l_proc;
131 	struct sigaltstack13 ness, oess;
132 	struct sigaltstack nbss, obss;
133 	int error;
134 
135 	if (SCARG(uap, nss)) {
136 		error = copyin(SCARG(uap, nss), &ness, sizeof(ness));
137 		if (error)
138 			return (error);
139 		native_sigaltstack13_to_sigaltstack(&ness, &nbss);
140 	}
141 	error = sigaltstack1(p,
142 	    SCARG(uap, nss) ? &nbss : 0, SCARG(uap, oss) ? &obss : 0);
143 	if (error)
144 		return (error);
145 	if (SCARG(uap, oss)) {
146 		native_sigaltstack_to_sigaltstack13(&obss, &oess);
147 		error = copyout(&oess, SCARG(uap, oss), sizeof(oess));
148 		if (error)
149 			return (error);
150 	}
151 	return (0);
152 }
153 
154 int
155 compat_13_sys_sigaction(struct lwp *l, void *v, register_t *retval)
156 {
157 	struct compat_13_sys_sigaction_args /* {
158 		syscallarg(int) signum;
159 		syscallarg(const struct sigaction13 *) nsa;
160 		syscallarg(struct sigaction13 *) osa;
161 	} */ *uap = v;
162 	struct proc *p = l->l_proc;
163 	struct sigaction13 nesa, oesa;
164 	struct sigaction nbsa, obsa;
165 	int error;
166 
167 	if (SCARG(uap, nsa)) {
168 		error = copyin(SCARG(uap, nsa), &nesa, sizeof(nesa));
169 		if (error)
170 			return (error);
171 		native_sigaction13_to_sigaction(&nesa, &nbsa);
172 	}
173 	error = sigaction1(p, SCARG(uap, signum),
174 	    SCARG(uap, nsa) ? &nbsa : 0, SCARG(uap, osa) ? &obsa : 0,
175 	    NULL, 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 
187 int
188 compat_13_sys_sigprocmask(struct lwp *l, void *v, register_t *retval)
189 {
190 	struct compat_13_sys_sigprocmask_args /* {
191 		syscallarg(int) how;
192 		syscallarg(int) mask;
193 	} */ *uap = v;
194 	struct proc *p = l->l_proc;
195 	sigset13_t ness, oess;
196 	sigset_t nbss, obss;
197 	int error;
198 
199 	ness = SCARG(uap, mask);
200 	native_sigset13_to_sigset(&ness, &nbss);
201 	error = sigprocmask1(p, SCARG(uap, how), &nbss, &obss);
202 	if (error)
203 		return (error);
204 	native_sigset_to_sigset13(&obss, &oess);
205 	*retval = oess;
206 	return (0);
207 }
208 
209 int
210 compat_13_sys_sigpending(struct lwp *l, void *v, register_t *retval)
211 {
212 	struct proc *p = l->l_proc;
213 	sigset13_t ess;
214 	sigset_t bss;
215 
216 	sigpending1(p, &bss);
217 	native_sigset_to_sigset13(&bss, &ess);
218 	*retval = ess;
219 	return (0);
220 }
221 
222 int
223 compat_13_sys_sigsuspend(struct lwp *l, void *v, register_t *retval)
224 {
225 	struct compat_13_sys_sigsuspend_args /* {
226 		syscallarg(sigset13_t) mask;
227 	} */ *uap = v;
228 	struct proc *p = l->l_proc;
229 	sigset13_t ess;
230 	sigset_t bss;
231 
232 	ess = SCARG(uap, mask);
233 	native_sigset13_to_sigset(&ess, &bss);
234 	return (sigsuspend1(p, &bss));
235 }
236