netbsd32_compat_43.c revision 1.41 1 1.41 dsl /* $NetBSD: netbsd32_compat_43.c,v 1.41 2007/04/30 14:05:47 dsl Exp $ */
2 1.1 mrg
3 1.1 mrg /*
4 1.19 mrg * Copyright (c) 1998, 2001 Matthew R. Green
5 1.1 mrg * All rights reserved.
6 1.1 mrg *
7 1.1 mrg * Redistribution and use in source and binary forms, with or without
8 1.1 mrg * modification, are permitted provided that the following conditions
9 1.1 mrg * are met:
10 1.1 mrg * 1. Redistributions of source code must retain the above copyright
11 1.1 mrg * notice, this list of conditions and the following disclaimer.
12 1.1 mrg * 2. Redistributions in binary form must reproduce the above copyright
13 1.1 mrg * notice, this list of conditions and the following disclaimer in the
14 1.1 mrg * documentation and/or other materials provided with the distribution.
15 1.1 mrg * 3. The name of the author may not be used to endorse or promote products
16 1.1 mrg * derived from this software without specific prior written permission.
17 1.1 mrg *
18 1.1 mrg * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19 1.1 mrg * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20 1.1 mrg * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 1.1 mrg * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22 1.7 mrg * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
23 1.1 mrg * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24 1.1 mrg * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
25 1.1 mrg * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
26 1.7 mrg * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 1.1 mrg * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 1.1 mrg * SUCH DAMAGE.
29 1.1 mrg */
30 1.20 lukem
31 1.20 lukem #include <sys/cdefs.h>
32 1.41 dsl __KERNEL_RCSID(0, "$NetBSD: netbsd32_compat_43.c,v 1.41 2007/04/30 14:05:47 dsl Exp $");
33 1.13 fvdl
34 1.17 mrg #if defined(_KERNEL_OPT)
35 1.13 fvdl #include "opt_compat_43.h"
36 1.13 fvdl #endif
37 1.1 mrg
38 1.1 mrg #include <sys/param.h>
39 1.1 mrg #include <sys/systm.h>
40 1.1 mrg #include <sys/fcntl.h>
41 1.41 dsl #include <sys/filedesc.h>
42 1.1 mrg #include <sys/malloc.h>
43 1.1 mrg #include <sys/mount.h>
44 1.41 dsl #include <sys/namei.h>
45 1.32 chs #include <sys/socket.h>
46 1.1 mrg #include <sys/proc.h>
47 1.1 mrg #include <sys/stat.h>
48 1.1 mrg #include <sys/syscallargs.h>
49 1.1 mrg #include <sys/time.h>
50 1.1 mrg #include <sys/ucred.h>
51 1.41 dsl #include <sys/vfs_syscalls.h>
52 1.10 mrg #include <uvm/uvm_extern.h>
53 1.1 mrg #include <sys/sysctl.h>
54 1.3 mrg #include <sys/swap.h>
55 1.1 mrg
56 1.5 mrg #include <compat/netbsd32/netbsd32.h>
57 1.5 mrg #include <compat/netbsd32/netbsd32_syscallargs.h>
58 1.1 mrg
59 1.31 christos #include <compat/sys/stat.h>
60 1.31 christos #include <compat/sys/signal.h>
61 1.31 christos #include <compat/sys/signalvar.h>
62 1.33 christos #include <compat/sys/socket.h>
63 1.31 christos
64 1.24 thorpej int compat_43_netbsd32_sethostid __P((struct lwp *, void *, register_t *));
65 1.24 thorpej int compat_43_netbsd32_killpg __P((struct lwp *, void *, register_t *retval));
66 1.24 thorpej int compat_43_netbsd32_sigblock __P((struct lwp *, void *, register_t *retval));
67 1.24 thorpej int compat_43_netbsd32_sigblock __P((struct lwp *, void *, register_t *retval));
68 1.24 thorpej int compat_43_netbsd32_sigsetmask __P((struct lwp *, void *, register_t *retval));
69 1.9 eeh
70 1.41 dsl static void
71 1.41 dsl netbsd32_from_stat(const struct stat *sb, struct netbsd32_stat43 *sp32)
72 1.41 dsl {
73 1.41 dsl
74 1.41 dsl sp32->st_dev = sb->st_dev;
75 1.41 dsl sp32->st_ino = sb->st_ino;
76 1.41 dsl sp32->st_mode = sb->st_mode;
77 1.41 dsl sp32->st_nlink = sb->st_nlink;
78 1.41 dsl sp32->st_uid = sb->st_uid;
79 1.41 dsl sp32->st_gid = sb->st_gid;
80 1.41 dsl sp32->st_rdev = sb->st_rdev;
81 1.41 dsl sp32->st_size = sb->st_size < (quad_t)1 << 32 ? sb->st_size : -2;
82 1.41 dsl sp32->st_atimespec.tv_sec = sb->st_atimespec.tv_sec;
83 1.41 dsl sp32->st_atimespec.tv_nsec = sb->st_atimespec.tv_nsec;
84 1.41 dsl sp32->st_mtimespec.tv_sec = sb->st_mtimespec.tv_sec;
85 1.41 dsl sp32->st_mtimespec.tv_nsec = sb->st_mtimespec.tv_nsec;
86 1.41 dsl sp32->st_ctimespec.tv_sec = sb->st_ctimespec.tv_sec;
87 1.41 dsl sp32->st_ctimespec.tv_nsec = sb->st_ctimespec.tv_nsec;
88 1.41 dsl sp32->st_blksize = sb->st_blksize;
89 1.41 dsl sp32->st_blocks = sb->st_blocks;
90 1.41 dsl sp32->st_flags = sb->st_flags;
91 1.41 dsl sp32->st_gen = sb->st_gen;
92 1.1 mrg }
93 1.1 mrg
94 1.1 mrg /* file system syscalls */
95 1.1 mrg int
96 1.24 thorpej compat_43_netbsd32_ocreat(l, v, retval)
97 1.24 thorpej struct lwp *l;
98 1.1 mrg void *v;
99 1.1 mrg register_t *retval;
100 1.1 mrg {
101 1.8 eeh struct compat_43_netbsd32_ocreat_args /* {
102 1.5 mrg syscallarg(const netbsd32_charp) path;
103 1.1 mrg syscallarg(mode_t) mode;
104 1.1 mrg } */ *uap = v;
105 1.1 mrg struct sys_open_args ua;
106 1.1 mrg
107 1.6 mrg NETBSD32TOP_UAP(path, const char);
108 1.6 mrg NETBSD32TO64_UAP(mode);
109 1.1 mrg SCARG(&ua, flags) = O_WRONLY | O_CREAT | O_TRUNC;
110 1.1 mrg
111 1.24 thorpej return (sys_open(l, &ua, retval));
112 1.1 mrg }
113 1.1 mrg
114 1.1 mrg int
115 1.24 thorpej compat_43_netbsd32_olseek(l, v, retval)
116 1.24 thorpej struct lwp *l;
117 1.1 mrg void *v;
118 1.1 mrg register_t *retval;
119 1.1 mrg {
120 1.8 eeh struct compat_43_netbsd32_olseek_args /* {
121 1.1 mrg syscallarg(int) fd;
122 1.5 mrg syscallarg(netbsd32_long) offset;
123 1.1 mrg syscallarg(int) whence;
124 1.1 mrg } */ *uap = v;
125 1.1 mrg struct sys_lseek_args ua;
126 1.1 mrg int rv;
127 1.1 mrg off_t rt;
128 1.1 mrg
129 1.1 mrg SCARG(&ua, fd) = SCARG(uap, fd);
130 1.6 mrg NETBSD32TOX_UAP(offset, long);
131 1.6 mrg NETBSD32TO64_UAP(whence);
132 1.24 thorpej rv = sys_lseek(l, &ua, (register_t *)&rt);
133 1.18 eeh *retval = rt;
134 1.1 mrg
135 1.1 mrg return (rv);
136 1.1 mrg }
137 1.1 mrg
138 1.1 mrg int
139 1.24 thorpej compat_43_netbsd32_stat43(l, v, retval)
140 1.24 thorpej struct lwp *l;
141 1.1 mrg void *v;
142 1.1 mrg register_t *retval;
143 1.1 mrg {
144 1.8 eeh struct compat_43_netbsd32_stat43_args /* {
145 1.5 mrg syscallarg(const netbsd32_charp) path;
146 1.5 mrg syscallarg(netbsd32_stat43p_t) ub;
147 1.1 mrg } */ *uap = v;
148 1.41 dsl struct stat sb;
149 1.15 mrg struct netbsd32_stat43 sb32;
150 1.41 dsl int error;
151 1.1 mrg
152 1.41 dsl error = do_sys_stat(l, SCARG_P32(uap, path), FOLLOW, &sb);
153 1.41 dsl if (error == 0) {
154 1.41 dsl netbsd32_from_stat(&sb, &sb32);
155 1.41 dsl error = copyout(&sb32, SCARG_P32(uap, ub), sizeof(sb32));
156 1.41 dsl }
157 1.41 dsl return error;
158 1.1 mrg }
159 1.1 mrg
160 1.1 mrg int
161 1.24 thorpej compat_43_netbsd32_lstat43(l, v, retval)
162 1.24 thorpej struct lwp *l;
163 1.1 mrg void *v;
164 1.1 mrg register_t *retval;
165 1.1 mrg {
166 1.8 eeh struct compat_43_netbsd32_lstat43_args /* {
167 1.5 mrg syscallarg(const netbsd32_charp) path;
168 1.5 mrg syscallarg(netbsd32_stat43p_t) ub;
169 1.1 mrg } */ *uap = v;
170 1.41 dsl struct stat sb;
171 1.15 mrg struct netbsd32_stat43 sb32;
172 1.41 dsl int error;
173 1.1 mrg
174 1.41 dsl error = do_sys_stat(l, SCARG_P32(uap, path), NOFOLLOW, &sb);
175 1.41 dsl if (error == 0) {
176 1.41 dsl netbsd32_from_stat(&sb, &sb32);
177 1.41 dsl error = copyout(&sb32, SCARG_P32(uap, ub), sizeof(sb32));
178 1.41 dsl }
179 1.41 dsl return error;
180 1.1 mrg }
181 1.1 mrg
182 1.1 mrg int
183 1.24 thorpej compat_43_netbsd32_fstat43(l, v, retval)
184 1.24 thorpej struct lwp *l;
185 1.1 mrg void *v;
186 1.1 mrg register_t *retval;
187 1.1 mrg {
188 1.8 eeh struct compat_43_netbsd32_fstat43_args /* {
189 1.1 mrg syscallarg(int) fd;
190 1.5 mrg syscallarg(netbsd32_stat43p_t) sb;
191 1.1 mrg } */ *uap = v;
192 1.41 dsl struct stat sb;
193 1.15 mrg struct netbsd32_stat43 sb32;
194 1.41 dsl int error;
195 1.1 mrg
196 1.41 dsl error = do_sys_fstat(l, SCARG(uap, fd), &sb);
197 1.41 dsl if (error == 0) {
198 1.41 dsl netbsd32_from_stat(&sb, &sb32);
199 1.41 dsl error = copyout(&sb32, SCARG_P32(uap, sb), sizeof(sb32));
200 1.41 dsl }
201 1.41 dsl return error;
202 1.1 mrg }
203 1.1 mrg
204 1.1 mrg int
205 1.24 thorpej compat_43_netbsd32_otruncate(l, v, retval)
206 1.24 thorpej struct lwp *l;
207 1.1 mrg void *v;
208 1.1 mrg register_t *retval;
209 1.1 mrg {
210 1.8 eeh struct compat_43_netbsd32_otruncate_args /* {
211 1.5 mrg syscallarg(const netbsd32_charp) path;
212 1.5 mrg syscallarg(netbsd32_long) length;
213 1.1 mrg } */ *uap = v;
214 1.1 mrg struct sys_truncate_args ua;
215 1.1 mrg
216 1.6 mrg NETBSD32TOP_UAP(path, const char);
217 1.6 mrg NETBSD32TO64_UAP(length);
218 1.24 thorpej return (sys_ftruncate(l, &ua, retval));
219 1.1 mrg }
220 1.1 mrg
221 1.1 mrg int
222 1.24 thorpej compat_43_netbsd32_oftruncate(l, v, retval)
223 1.24 thorpej struct lwp *l;
224 1.1 mrg void *v;
225 1.1 mrg register_t *retval;
226 1.1 mrg {
227 1.8 eeh struct compat_43_netbsd32_oftruncate_args /* {
228 1.1 mrg syscallarg(int) fd;
229 1.5 mrg syscallarg(netbsd32_long) length;
230 1.1 mrg } */ *uap = v;
231 1.1 mrg struct sys_ftruncate_args ua;
232 1.1 mrg
233 1.6 mrg NETBSD32TO64_UAP(fd);
234 1.6 mrg NETBSD32TO64_UAP(length);
235 1.24 thorpej return (sys_ftruncate(l, &ua, retval));
236 1.1 mrg }
237 1.1 mrg
238 1.1 mrg int
239 1.24 thorpej compat_43_netbsd32_ogetdirentries(l, v, retval)
240 1.24 thorpej struct lwp *l;
241 1.1 mrg void *v;
242 1.1 mrg register_t *retval;
243 1.1 mrg {
244 1.8 eeh struct compat_43_netbsd32_ogetdirentries_args /* {
245 1.1 mrg syscallarg(int) fd;
246 1.5 mrg syscallarg(netbsd32_charp) buf;
247 1.1 mrg syscallarg(u_int) count;
248 1.5 mrg syscallarg(netbsd32_longp) basep;
249 1.1 mrg } */ *uap = v;
250 1.1 mrg struct compat_43_sys_getdirentries_args ua;
251 1.1 mrg
252 1.6 mrg NETBSD32TO64_UAP(fd);
253 1.6 mrg NETBSD32TOP_UAP(buf, char);
254 1.6 mrg NETBSD32TO64_UAP(count);
255 1.6 mrg NETBSD32TOP_UAP(basep, long);
256 1.24 thorpej return (compat_43_sys_getdirentries(l, &ua, retval));
257 1.1 mrg }
258 1.1 mrg
259 1.1 mrg /* kernel syscalls */
260 1.1 mrg int
261 1.24 thorpej compat_43_netbsd32_ogetkerninfo(l, v, retval)
262 1.24 thorpej struct lwp *l;
263 1.1 mrg void *v;
264 1.1 mrg register_t *retval;
265 1.1 mrg {
266 1.8 eeh struct compat_43_netbsd32_ogetkerninfo_args /* {
267 1.1 mrg syscallarg(int) op;
268 1.5 mrg syscallarg(netbsd32_charp) where;
269 1.5 mrg syscallarg(netbsd32_intp) size;
270 1.1 mrg syscallarg(int) arg;
271 1.1 mrg } */ *uap = v;
272 1.1 mrg struct compat_43_sys_getkerninfo_args ua;
273 1.1 mrg
274 1.6 mrg NETBSD32TO64_UAP(op);
275 1.6 mrg NETBSD32TOP_UAP(where, char);
276 1.6 mrg NETBSD32TOP_UAP(size, int);
277 1.6 mrg NETBSD32TO64_UAP(arg);
278 1.24 thorpej return (compat_43_sys_getkerninfo(l, &ua, retval));
279 1.1 mrg }
280 1.1 mrg
281 1.1 mrg int
282 1.24 thorpej compat_43_netbsd32_ogethostname(l, v, retval)
283 1.24 thorpej struct lwp* l;
284 1.1 mrg void *v;
285 1.1 mrg register_t *retval;
286 1.1 mrg {
287 1.8 eeh struct compat_43_netbsd32_ogethostname_args /* {
288 1.5 mrg syscallarg(netbsd32_charp) hostname;
289 1.1 mrg syscallarg(u_int) len;
290 1.1 mrg } */ *uap = v;
291 1.29 atatat int name[2];
292 1.1 mrg size_t sz;
293 1.1 mrg
294 1.29 atatat name[0] = CTL_KERN;
295 1.29 atatat name[1] = KERN_HOSTNAME;
296 1.1 mrg sz = SCARG(uap, len);
297 1.29 atatat return (old_sysctl(&name[0], 2,
298 1.39 dsl SCARG_P32(uap, hostname), &sz, 0, 0, l));
299 1.1 mrg }
300 1.1 mrg
301 1.1 mrg int
302 1.24 thorpej compat_43_netbsd32_osethostname(l, v, retval)
303 1.24 thorpej struct lwp* l;
304 1.1 mrg void *v;
305 1.1 mrg register_t *retval;
306 1.1 mrg {
307 1.8 eeh struct compat_43_netbsd32_osethostname_args /* {
308 1.5 mrg syscallarg(netbsd32_charp) hostname;
309 1.1 mrg syscallarg(u_int) len;
310 1.1 mrg } */ *uap = v;
311 1.29 atatat int name[2];
312 1.1 mrg
313 1.29 atatat name[0] = CTL_KERN;
314 1.29 atatat name[1] = KERN_HOSTNAME;
315 1.39 dsl return old_sysctl(&name[0], 2, 0, 0, (char *)SCARG_P32(uap,
316 1.39 dsl hostname), SCARG(uap, len), l);
317 1.1 mrg }
318 1.1 mrg
319 1.1 mrg int
320 1.24 thorpej compat_43_netbsd32_sethostid(l, v, retval)
321 1.24 thorpej struct lwp* l;
322 1.4 eeh void *v;
323 1.4 eeh register_t *retval;
324 1.4 eeh {
325 1.8 eeh struct compat_43_netbsd32_sethostid_args /* {
326 1.4 eeh syscallarg(int32_t) hostid;
327 1.4 eeh } */ *uap = v;
328 1.4 eeh struct compat_43_sys_sethostid_args ua;
329 1.4 eeh
330 1.6 mrg NETBSD32TO64_UAP(hostid);
331 1.24 thorpej return (compat_43_sys_sethostid(l, &ua, retval));
332 1.4 eeh }
333 1.4 eeh
334 1.4 eeh int
335 1.24 thorpej compat_43_netbsd32_ogetrlimit(l, v, retval)
336 1.24 thorpej struct lwp* l;
337 1.1 mrg void *v;
338 1.1 mrg register_t *retval;
339 1.1 mrg {
340 1.8 eeh struct compat_43_netbsd32_ogetrlimit_args /* {
341 1.1 mrg syscallarg(int) which;
342 1.5 mrg syscallarg(netbsd32_orlimitp_t) rlp;
343 1.1 mrg } */ *uap = v;
344 1.1 mrg struct compat_43_sys_getrlimit_args ua;
345 1.1 mrg
346 1.6 mrg NETBSD32TO64_UAP(which);
347 1.6 mrg NETBSD32TOP_UAP(rlp, struct orlimit);
348 1.24 thorpej return (compat_43_sys_getrlimit(l, &ua, retval));
349 1.1 mrg }
350 1.1 mrg
351 1.1 mrg int
352 1.24 thorpej compat_43_netbsd32_osetrlimit(l, v, retval)
353 1.24 thorpej struct lwp* l;
354 1.1 mrg void *v;
355 1.1 mrg register_t *retval;
356 1.1 mrg {
357 1.8 eeh struct compat_43_netbsd32_osetrlimit_args /* {
358 1.1 mrg syscallarg(int) which;
359 1.5 mrg syscallarg(netbsd32_orlimitp_t) rlp;
360 1.1 mrg } */ *uap = v;
361 1.1 mrg struct compat_43_sys_setrlimit_args ua;
362 1.1 mrg
363 1.6 mrg NETBSD32TO64_UAP(which);
364 1.6 mrg NETBSD32TOP_UAP(rlp, struct orlimit);
365 1.24 thorpej return (compat_43_sys_setrlimit(l, &ua, retval));
366 1.1 mrg }
367 1.1 mrg
368 1.4 eeh int
369 1.24 thorpej compat_43_netbsd32_killpg(l, v, retval)
370 1.24 thorpej struct lwp* l;
371 1.4 eeh void *v;
372 1.4 eeh register_t *retval;
373 1.4 eeh {
374 1.8 eeh struct compat_43_netbsd32_killpg_args /* {
375 1.4 eeh syscallarg(int) pgid;
376 1.4 eeh syscallarg(int) signum;
377 1.4 eeh } */ *uap = v;
378 1.4 eeh struct compat_43_sys_killpg_args ua;
379 1.4 eeh
380 1.6 mrg NETBSD32TO64_UAP(pgid);
381 1.6 mrg NETBSD32TO64_UAP(signum);
382 1.24 thorpej return (compat_43_sys_killpg(l, &ua, retval));
383 1.4 eeh }
384 1.4 eeh
385 1.1 mrg /* virtual memory syscalls */
386 1.1 mrg int
387 1.24 thorpej compat_43_netbsd32_ommap(l, v, retval)
388 1.24 thorpej struct lwp* l;
389 1.1 mrg void *v;
390 1.1 mrg register_t *retval;
391 1.1 mrg {
392 1.8 eeh struct compat_43_netbsd32_ommap_args /* {
393 1.37 christos syscallarg(netbsd32_caddr_t) addr;
394 1.5 mrg syscallarg(netbsd32_size_t) len;
395 1.1 mrg syscallarg(int) prot;
396 1.1 mrg syscallarg(int) flags;
397 1.1 mrg syscallarg(int) fd;
398 1.5 mrg syscallarg(netbsd32_long) pos;
399 1.1 mrg } */ *uap = v;
400 1.1 mrg struct compat_43_sys_mmap_args ua;
401 1.1 mrg
402 1.38 dsl NETBSD32TOP_UAP(addr, void *);
403 1.6 mrg NETBSD32TOX_UAP(len, size_t);
404 1.6 mrg NETBSD32TO64_UAP(prot);
405 1.6 mrg NETBSD32TO64_UAP(flags);
406 1.6 mrg NETBSD32TO64_UAP(fd);
407 1.6 mrg NETBSD32TOX_UAP(pos, long);
408 1.24 thorpej return (compat_43_sys_mmap(l, &ua, retval));
409 1.4 eeh }
410 1.4 eeh
411 1.1 mrg /* network syscalls */
412 1.1 mrg int
413 1.24 thorpej compat_43_netbsd32_oaccept(l, v, retval)
414 1.24 thorpej struct lwp* l;
415 1.1 mrg void *v;
416 1.1 mrg register_t *retval;
417 1.1 mrg {
418 1.8 eeh struct compat_43_netbsd32_oaccept_args /* {
419 1.1 mrg syscallarg(int) s;
420 1.37 christos syscallarg(netbsd32_caddr_t) name;
421 1.5 mrg syscallarg(netbsd32_intp) anamelen;
422 1.1 mrg } */ *uap = v;
423 1.1 mrg struct compat_43_sys_accept_args ua;
424 1.1 mrg
425 1.6 mrg NETBSD32TOX_UAP(s, int);
426 1.38 dsl NETBSD32TOP_UAP(name, void *);
427 1.6 mrg NETBSD32TOP_UAP(anamelen, int);
428 1.24 thorpej return (compat_43_sys_accept(l, &ua, retval));
429 1.1 mrg }
430 1.1 mrg
431 1.1 mrg int
432 1.24 thorpej compat_43_netbsd32_osend(l, v, retval)
433 1.24 thorpej struct lwp* l;
434 1.1 mrg void *v;
435 1.1 mrg register_t *retval;
436 1.1 mrg {
437 1.8 eeh struct compat_43_netbsd32_osend_args /* {
438 1.1 mrg syscallarg(int) s;
439 1.37 christos syscallarg(netbsd32_caddr_t) buf;
440 1.1 mrg syscallarg(int) len;
441 1.1 mrg syscallarg(int) flags;
442 1.1 mrg } */ *uap = v;
443 1.1 mrg struct compat_43_sys_send_args ua;
444 1.1 mrg
445 1.6 mrg NETBSD32TO64_UAP(s);
446 1.38 dsl NETBSD32TOP_UAP(buf, void *);
447 1.6 mrg NETBSD32TO64_UAP(len);
448 1.6 mrg NETBSD32TO64_UAP(flags);
449 1.24 thorpej return (compat_43_sys_send(l, &ua, retval));
450 1.1 mrg }
451 1.1 mrg
452 1.1 mrg int
453 1.24 thorpej compat_43_netbsd32_orecv(l, v, retval)
454 1.24 thorpej struct lwp* l;
455 1.1 mrg void *v;
456 1.1 mrg register_t *retval;
457 1.1 mrg {
458 1.8 eeh struct compat_43_netbsd32_orecv_args /* {
459 1.1 mrg syscallarg(int) s;
460 1.37 christos syscallarg(netbsd32_caddr_t) buf;
461 1.1 mrg syscallarg(int) len;
462 1.1 mrg syscallarg(int) flags;
463 1.1 mrg } */ *uap = v;
464 1.1 mrg struct compat_43_sys_recv_args ua;
465 1.1 mrg
466 1.6 mrg NETBSD32TO64_UAP(s);
467 1.38 dsl NETBSD32TOP_UAP(buf, void *);
468 1.6 mrg NETBSD32TO64_UAP(len);
469 1.6 mrg NETBSD32TO64_UAP(flags);
470 1.24 thorpej return (compat_43_sys_recv(l, &ua, retval));
471 1.1 mrg }
472 1.1 mrg
473 1.1 mrg /*
474 1.1 mrg * XXX convert these to use a common iovec code to the native
475 1.1 mrg * netbsd call.
476 1.1 mrg */
477 1.1 mrg int
478 1.24 thorpej compat_43_netbsd32_orecvmsg(l, v, retval)
479 1.24 thorpej struct lwp* l;
480 1.1 mrg void *v;
481 1.1 mrg register_t *retval;
482 1.1 mrg {
483 1.24 thorpej struct proc *p = l->l_proc;
484 1.8 eeh struct compat_43_netbsd32_orecvmsg_args /* {
485 1.1 mrg syscallarg(int) s;
486 1.5 mrg syscallarg(netbsd32_omsghdrp_t) msg;
487 1.1 mrg syscallarg(int) flags;
488 1.1 mrg } */ *uap = v;
489 1.1 mrg struct compat_43_sys_recvmsg_args ua;
490 1.16 mrg struct omsghdr omh, *sgsbp;
491 1.16 mrg struct netbsd32_omsghdr omh32;
492 1.16 mrg struct iovec iov, *sgsbp2;
493 1.16 mrg struct netbsd32_iovec iov32, *iovec32p;
494 1.36 christos void *sg = stackgap_init(p, 0);
495 1.16 mrg int i, error, rv;
496 1.1 mrg
497 1.6 mrg NETBSD32TO64_UAP(s);
498 1.6 mrg NETBSD32TO64_UAP(flags);
499 1.1 mrg
500 1.16 mrg /*
501 1.16 mrg * this is annoying:
502 1.16 mrg * - copyin the msghdr32 struct
503 1.16 mrg * - stackgap_alloc a msghdr struct
504 1.16 mrg * - convert msghdr32 to msghdr:
505 1.16 mrg * - stackgap_alloc enough space for iovec's
506 1.16 mrg * - copy in each iov32, and convert to iov
507 1.16 mrg * - copyout converted iov
508 1.16 mrg * - copyout converted msghdr
509 1.16 mrg * - do real syscall
510 1.16 mrg * - copyin the msghdr struct
511 1.16 mrg * - convert msghdr to msghdr32
512 1.16 mrg * - copyin each iov and convert to iov32
513 1.16 mrg * - copyout converted iov32
514 1.16 mrg * - copyout converted msghdr32
515 1.16 mrg */
516 1.39 dsl error = copyin(SCARG_P32(uap, msg), &omh32, sizeof(omh32));
517 1.16 mrg if (error)
518 1.16 mrg return (error);
519 1.16 mrg
520 1.21 christos SCARG(&ua, msg) = sgsbp = stackgap_alloc(p, &sg, sizeof(omh));
521 1.36 christos omh.msg_name = (void *)NETBSD32PTR64(omh32.msg_name);
522 1.16 mrg omh.msg_namelen = omh32.msg_namelen;
523 1.16 mrg omh.msg_iovlen = (size_t)omh32.msg_iovlen;
524 1.21 christos omh.msg_iov = sgsbp2 = stackgap_alloc(p, &sg, sizeof(struct iovec) * omh.msg_iovlen);
525 1.23 scw iovec32p = (struct netbsd32_iovec *)NETBSD32PTR64(omh32.msg_iov);
526 1.16 mrg for (i = 0; i < omh.msg_iovlen; i++, sgsbp2++, iovec32p++) {
527 1.16 mrg error = copyin(iovec32p, &iov32, sizeof(iov32));
528 1.16 mrg if (error)
529 1.16 mrg return (error);
530 1.23 scw iov.iov_base =
531 1.23 scw (struct iovec *)NETBSD32PTR64(iovec32p->iov_base);
532 1.16 mrg iov.iov_len = (size_t)iovec32p->iov_len;
533 1.16 mrg error = copyout(&iov, sgsbp2, sizeof(iov));
534 1.16 mrg if (error)
535 1.16 mrg return (error);
536 1.1 mrg }
537 1.36 christos omh.msg_accrights = (void *)NETBSD32PTR64(omh32.msg_accrights);
538 1.16 mrg omh.msg_accrightslen = omh32.msg_accrightslen;
539 1.16 mrg error = copyout(&omh, sgsbp, sizeof(omh));
540 1.16 mrg if (error)
541 1.16 mrg return (error);
542 1.1 mrg
543 1.24 thorpej rv = compat_43_sys_recvmsg(l, &ua, retval);
544 1.1 mrg
545 1.16 mrg error = copyin(sgsbp, &omh, sizeof(omh));
546 1.16 mrg if (error)
547 1.16 mrg return error;
548 1.38 dsl NETBSD32PTR32(omh32.msg_name, omh.msg_name);
549 1.16 mrg omh32.msg_namelen = omh.msg_namelen;
550 1.16 mrg omh32.msg_iovlen = (netbsd32_size_t)omh.msg_iovlen;
551 1.38 dsl iovec32p = NETBSD32PTR64(omh32.msg_iov);
552 1.16 mrg sgsbp2 = omh.msg_iov;
553 1.16 mrg for (i = 0; i < omh.msg_iovlen; i++, sgsbp2++, iovec32p++) {
554 1.16 mrg error = copyin(sgsbp2, &iov, sizeof(iov));
555 1.16 mrg if (error)
556 1.16 mrg return (error);
557 1.38 dsl NETBSD32PTR32(iov32.iov_base, iov.iov_base);
558 1.16 mrg iov32.iov_len = (netbsd32_size_t)iov.iov_len;
559 1.16 mrg error = copyout(&iov32, iovec32p, sizeof(iov32));
560 1.16 mrg if (error)
561 1.16 mrg return (error);
562 1.16 mrg }
563 1.38 dsl NETBSD32PTR32(omh32.msg_accrights, omh.msg_accrights);
564 1.16 mrg omh32.msg_accrightslen = omh.msg_accrightslen;
565 1.16 mrg
566 1.39 dsl error = copyout(&omh32, SCARG_P32(uap, msg), sizeof(omh32));
567 1.16 mrg if (error)
568 1.16 mrg return error;
569 1.16 mrg
570 1.16 mrg return (rv);
571 1.1 mrg }
572 1.1 mrg
573 1.1 mrg int
574 1.24 thorpej compat_43_netbsd32_osendmsg(l, v, retval)
575 1.24 thorpej struct lwp* l;
576 1.1 mrg void *v;
577 1.1 mrg register_t *retval;
578 1.1 mrg {
579 1.24 thorpej struct proc *p = l->l_proc;
580 1.8 eeh struct compat_43_netbsd32_osendmsg_args /* {
581 1.1 mrg syscallarg(int) s;
582 1.37 christos syscallarg(netbsd32_caddr_t) msg;
583 1.1 mrg syscallarg(int) flags;
584 1.1 mrg } */ *uap = v;
585 1.16 mrg struct compat_43_sys_recvmsg_args ua;
586 1.16 mrg struct omsghdr omh, *sgsbp;
587 1.16 mrg struct netbsd32_omsghdr omh32;
588 1.16 mrg struct iovec iov, *sgsbp2;
589 1.16 mrg struct netbsd32_iovec iov32, *iovec32p;
590 1.36 christos void *sg = stackgap_init(p, 0);
591 1.16 mrg int i, error, rv;
592 1.1 mrg
593 1.6 mrg NETBSD32TO64_UAP(s);
594 1.6 mrg NETBSD32TO64_UAP(flags);
595 1.1 mrg
596 1.16 mrg /*
597 1.16 mrg * this is annoying:
598 1.16 mrg * - copyin the msghdr32 struct
599 1.16 mrg * - stackgap_alloc a msghdr struct
600 1.16 mrg * - convert msghdr32 to msghdr:
601 1.16 mrg * - stackgap_alloc enough space for iovec's
602 1.16 mrg * - copy in each iov32, and convert to iov
603 1.16 mrg * - copyout converted iov
604 1.16 mrg * - copyout converted msghdr
605 1.16 mrg * - do real syscall
606 1.16 mrg * - copyin the msghdr struct
607 1.16 mrg * - convert msghdr to msghdr32
608 1.16 mrg * - copyin each iov and convert to iov32
609 1.16 mrg * - copyout converted iov32
610 1.16 mrg * - copyout converted msghdr32
611 1.16 mrg */
612 1.39 dsl error = copyin(SCARG_P32(uap, msg), &omh32, sizeof(omh32));
613 1.16 mrg if (error)
614 1.16 mrg return (error);
615 1.16 mrg
616 1.21 christos SCARG(&ua, msg) = sgsbp = stackgap_alloc(p, &sg, sizeof(omh));
617 1.38 dsl omh.msg_name = NETBSD32PTR64(omh32.msg_name);
618 1.16 mrg omh.msg_namelen = omh32.msg_namelen;
619 1.16 mrg omh.msg_iovlen = (size_t)omh32.msg_iovlen;
620 1.21 christos omh.msg_iov = sgsbp2 = stackgap_alloc(p, &sg, sizeof(struct iovec) * omh.msg_iovlen);
621 1.38 dsl iovec32p = NETBSD32PTR64(omh32.msg_iov);
622 1.16 mrg for (i = 0; i < omh.msg_iovlen; i++, sgsbp2++, iovec32p++) {
623 1.16 mrg error = copyin(iovec32p, &iov32, sizeof(iov32));
624 1.16 mrg if (error)
625 1.16 mrg return (error);
626 1.38 dsl iov.iov_base = NETBSD32PTR64(iovec32p->iov_base);
627 1.16 mrg iov.iov_len = (size_t)iovec32p->iov_len;
628 1.16 mrg error = copyout(&iov, sgsbp2, sizeof(iov));
629 1.16 mrg if (error)
630 1.16 mrg return (error);
631 1.1 mrg }
632 1.38 dsl omh.msg_accrights = NETBSD32PTR64(omh32.msg_accrights);
633 1.16 mrg omh.msg_accrightslen = omh32.msg_accrightslen;
634 1.16 mrg error = copyout(&omh, sgsbp, sizeof(omh));
635 1.16 mrg if (error)
636 1.16 mrg return (error);
637 1.1 mrg
638 1.24 thorpej rv = compat_43_sys_sendmsg(l, &ua, retval);
639 1.1 mrg
640 1.16 mrg error = copyin(sgsbp, &omh, sizeof(omh));
641 1.16 mrg if (error)
642 1.16 mrg return error;
643 1.38 dsl NETBSD32PTR32(omh32.msg_name, omh.msg_name);
644 1.16 mrg omh32.msg_namelen = omh.msg_namelen;
645 1.16 mrg omh32.msg_iovlen = (netbsd32_size_t)omh.msg_iovlen;
646 1.38 dsl iovec32p = NETBSD32PTR64(omh32.msg_iov);
647 1.16 mrg sgsbp2 = omh.msg_iov;
648 1.16 mrg for (i = 0; i < omh.msg_iovlen; i++, sgsbp2++, iovec32p++) {
649 1.16 mrg error = copyin(sgsbp2, &iov, sizeof(iov));
650 1.16 mrg if (error)
651 1.16 mrg return (error);
652 1.38 dsl NETBSD32PTR32(iov32.iov_base, iov.iov_base);
653 1.16 mrg iov32.iov_len = (netbsd32_size_t)iov.iov_len;
654 1.16 mrg error = copyout(&iov32, iovec32p, sizeof(iov32));
655 1.16 mrg if (error)
656 1.16 mrg return (error);
657 1.16 mrg }
658 1.38 dsl NETBSD32PTR32(omh32.msg_accrights, omh.msg_accrights);
659 1.16 mrg omh32.msg_accrightslen = omh.msg_accrightslen;
660 1.16 mrg
661 1.39 dsl error = copyout(&omh32, SCARG_P32(uap, msg), sizeof(omh32));
662 1.16 mrg if (error)
663 1.16 mrg return error;
664 1.16 mrg
665 1.16 mrg return (rv);
666 1.1 mrg }
667 1.1 mrg
668 1.1 mrg int
669 1.24 thorpej compat_43_netbsd32_orecvfrom(l, v, retval)
670 1.24 thorpej struct lwp* l;
671 1.1 mrg void *v;
672 1.1 mrg register_t *retval;
673 1.1 mrg {
674 1.8 eeh struct compat_43_netbsd32_orecvfrom_args /* {
675 1.1 mrg syscallarg(int) s;
676 1.37 christos syscallarg(netbsd32_caddr_t) buf;
677 1.5 mrg syscallarg(netbsd32_size_t) len;
678 1.1 mrg syscallarg(int) flags;
679 1.37 christos syscallarg(netbsd32_caddr_t) from;
680 1.5 mrg syscallarg(netbsd32_intp) fromlenaddr;
681 1.1 mrg } */ *uap = v;
682 1.1 mrg struct compat_43_sys_recvfrom_args ua;
683 1.1 mrg
684 1.6 mrg NETBSD32TO64_UAP(s);
685 1.38 dsl NETBSD32TOP_UAP(buf, void *);
686 1.6 mrg NETBSD32TOX_UAP(len, size_t);
687 1.6 mrg NETBSD32TO64_UAP(flags);
688 1.38 dsl NETBSD32TOP_UAP(from, void *);
689 1.6 mrg NETBSD32TOP_UAP(fromlenaddr, int);
690 1.24 thorpej return (compat_43_sys_recvfrom(l, &ua, retval));
691 1.1 mrg }
692 1.1 mrg
693 1.1 mrg int
694 1.24 thorpej compat_43_netbsd32_ogetsockname(l, v, retval)
695 1.24 thorpej struct lwp* l;
696 1.1 mrg void *v;
697 1.1 mrg register_t *retval;
698 1.1 mrg {
699 1.8 eeh struct compat_43_netbsd32_ogetsockname_args /* {
700 1.1 mrg syscallarg(int) fdec;
701 1.37 christos syscallarg(netbsd32_caddr_t) asa;
702 1.5 mrg syscallarg(netbsd32_intp) alen;
703 1.1 mrg } */ *uap = v;
704 1.1 mrg struct compat_43_sys_getsockname_args ua;
705 1.1 mrg
706 1.6 mrg NETBSD32TO64_UAP(fdec);
707 1.38 dsl NETBSD32TOP_UAP(asa, void *);
708 1.38 dsl NETBSD32TOP_UAP(alen, int *);
709 1.24 thorpej return (compat_43_sys_getsockname(l, &ua, retval));
710 1.1 mrg }
711 1.1 mrg
712 1.1 mrg int
713 1.24 thorpej compat_43_netbsd32_ogetpeername(l, v, retval)
714 1.24 thorpej struct lwp* l;
715 1.1 mrg void *v;
716 1.1 mrg register_t *retval;
717 1.1 mrg {
718 1.8 eeh struct compat_43_netbsd32_ogetpeername_args /* {
719 1.1 mrg syscallarg(int) fdes;
720 1.37 christos syscallarg(netbsd32_caddr_t) asa;
721 1.5 mrg syscallarg(netbsd32_intp) alen;
722 1.1 mrg } */ *uap = v;
723 1.1 mrg struct compat_43_sys_getpeername_args ua;
724 1.1 mrg
725 1.6 mrg NETBSD32TO64_UAP(fdes);
726 1.38 dsl NETBSD32TOP_UAP(asa, void *);
727 1.38 dsl NETBSD32TOP_UAP(alen, int *);
728 1.24 thorpej return (compat_43_sys_getpeername(l, &ua, retval));
729 1.1 mrg }
730 1.1 mrg
731 1.1 mrg /* signal syscalls */
732 1.1 mrg int
733 1.24 thorpej compat_43_netbsd32_osigvec(l, v, retval)
734 1.24 thorpej struct lwp* l;
735 1.1 mrg void *v;
736 1.1 mrg register_t *retval;
737 1.1 mrg {
738 1.24 thorpej struct proc *p = l->l_proc;
739 1.8 eeh struct compat_43_netbsd32_osigvec_args /* {
740 1.1 mrg syscallarg(int) signum;
741 1.5 mrg syscallarg(netbsd32_sigvecp_t) nsv;
742 1.5 mrg syscallarg(netbsd32_sigvecp_t) osv;
743 1.1 mrg } */ *uap = v;
744 1.1 mrg struct compat_43_sys_sigvec_args ua;
745 1.16 mrg struct netbsd32_sigvec sv32;
746 1.28 christos struct sigvec sv;
747 1.36 christos void *sg = stackgap_init(p, 0);
748 1.16 mrg int rv, error;
749 1.1 mrg
750 1.6 mrg NETBSD32TO64_UAP(signum);
751 1.39 dsl if (SCARG_P32(uap, osv))
752 1.28 christos SCARG(&ua, osv) = stackgap_alloc(p, &sg, sizeof(sv));
753 1.1 mrg else
754 1.1 mrg SCARG(&ua, osv) = NULL;
755 1.39 dsl if (SCARG_P32(uap, nsv)) {
756 1.28 christos SCARG(&ua, nsv) = stackgap_alloc(p, &sg, sizeof(sv));
757 1.39 dsl error = copyin(SCARG_P32(uap, nsv), &sv32, sizeof(sv32));
758 1.16 mrg if (error)
759 1.16 mrg return (error);
760 1.23 scw sv.sv_handler = (void *)NETBSD32PTR64(sv32.sv_handler);
761 1.16 mrg sv.sv_mask = sv32.sv_mask;
762 1.16 mrg sv.sv_flags = sv32.sv_flags;
763 1.28 christos error = copyout(&sv, SCARG(&ua, nsv), sizeof(sv));
764 1.16 mrg if (error)
765 1.16 mrg return (error);
766 1.1 mrg } else
767 1.1 mrg SCARG(&ua, nsv) = NULL;
768 1.24 thorpej rv = compat_43_sys_sigvec(l, &ua, retval);
769 1.1 mrg if (rv)
770 1.1 mrg return (rv);
771 1.1 mrg
772 1.39 dsl if (SCARG_P32(uap, osv)) {
773 1.28 christos error = copyin(SCARG(&ua, osv), &sv, sizeof(sv));
774 1.16 mrg if (error)
775 1.16 mrg return (error);
776 1.38 dsl NETBSD32PTR32(sv32.sv_handler, sv.sv_handler);
777 1.16 mrg sv32.sv_mask = sv.sv_mask;
778 1.16 mrg sv32.sv_flags = sv.sv_flags;
779 1.39 dsl error = copyout(&sv32, SCARG_P32(uap, osv), sizeof(sv32));
780 1.16 mrg if (error)
781 1.16 mrg return (error);
782 1.1 mrg }
783 1.1 mrg
784 1.1 mrg return (0);
785 1.4 eeh }
786 1.4 eeh
787 1.4 eeh int
788 1.24 thorpej compat_43_netbsd32_sigblock(l, v, retval)
789 1.24 thorpej struct lwp* l;
790 1.4 eeh void *v;
791 1.4 eeh register_t *retval;
792 1.4 eeh {
793 1.8 eeh struct compat_43_netbsd32_sigblock_args /* {
794 1.4 eeh syscallarg(int) mask;
795 1.4 eeh } */ *uap = v;
796 1.4 eeh struct compat_43_sys_sigblock_args ua;
797 1.4 eeh
798 1.6 mrg NETBSD32TO64_UAP(mask);
799 1.24 thorpej return (compat_43_sys_sigblock(l, &ua, retval));
800 1.4 eeh }
801 1.4 eeh
802 1.4 eeh int
803 1.24 thorpej compat_43_netbsd32_sigsetmask(l, v, retval)
804 1.24 thorpej struct lwp* l;
805 1.4 eeh void *v;
806 1.4 eeh register_t *retval;
807 1.4 eeh {
808 1.8 eeh struct compat_43_netbsd32_sigsetmask_args /* {
809 1.4 eeh syscallarg(int) mask;
810 1.4 eeh } */ *uap = v;
811 1.4 eeh struct compat_43_sys_sigsetmask_args ua;
812 1.4 eeh
813 1.6 mrg NETBSD32TO64_UAP(mask);
814 1.24 thorpej return (compat_43_sys_sigsetmask(l, &ua, retval));
815 1.1 mrg }
816 1.1 mrg
817 1.1 mrg int
818 1.24 thorpej compat_43_netbsd32_osigstack(l, v, retval)
819 1.24 thorpej struct lwp* l;
820 1.1 mrg void *v;
821 1.1 mrg register_t *retval;
822 1.1 mrg {
823 1.24 thorpej struct proc *p = l->l_proc;
824 1.8 eeh struct compat_43_netbsd32_osigstack_args /* {
825 1.5 mrg syscallarg(netbsd32_sigstackp_t) nss;
826 1.5 mrg syscallarg(netbsd32_sigstackp_t) oss;
827 1.1 mrg } */ *uap = v;
828 1.1 mrg struct compat_43_sys_sigstack_args ua;
829 1.16 mrg struct netbsd32_sigstack ss32;
830 1.28 christos struct sigstack ss;
831 1.36 christos void *sg = stackgap_init(p, 0);
832 1.16 mrg int error, rv;
833 1.1 mrg
834 1.39 dsl if (SCARG_P32(uap, oss))
835 1.28 christos SCARG(&ua, oss) = stackgap_alloc(p, &sg, sizeof(ss));
836 1.1 mrg else
837 1.1 mrg SCARG(&ua, oss) = NULL;
838 1.39 dsl if (SCARG_P32(uap, nss)) {
839 1.28 christos SCARG(&ua, nss) = stackgap_alloc(p, &sg, sizeof(ss));
840 1.39 dsl error = copyin(SCARG_P32(uap, nss), &ss32, sizeof(ss32));
841 1.16 mrg if (error)
842 1.16 mrg return (error);
843 1.38 dsl ss.ss_sp = NETBSD32PTR64(ss32.ss_sp);
844 1.16 mrg ss.ss_onstack = ss32.ss_onstack;
845 1.28 christos error = copyout(&ss, SCARG(&ua, nss), sizeof(ss));
846 1.16 mrg if (error)
847 1.16 mrg return (error);
848 1.1 mrg } else
849 1.1 mrg SCARG(&ua, nss) = NULL;
850 1.1 mrg
851 1.24 thorpej rv = compat_43_sys_sigstack(l, &ua, retval);
852 1.1 mrg if (rv)
853 1.1 mrg return (rv);
854 1.1 mrg
855 1.39 dsl if (SCARG_P32(uap, oss)) {
856 1.28 christos error = copyin(SCARG(&ua, oss), &ss, sizeof(ss));
857 1.16 mrg if (error)
858 1.16 mrg return (error);
859 1.38 dsl NETBSD32PTR32(ss32.ss_sp, ss.ss_sp);
860 1.16 mrg ss32.ss_onstack = ss.ss_onstack;
861 1.39 dsl error = copyout(&ss32, SCARG_P32(uap, oss), sizeof(ss32));
862 1.16 mrg if (error)
863 1.16 mrg return (error);
864 1.1 mrg }
865 1.1 mrg
866 1.1 mrg return (0);
867 1.1 mrg }
868