xref: /netbsd-src/sys/compat/netbsd32/netbsd32_netbsd.c (revision 796c32c94f6e154afc9de0f63da35c91bb739b45)
1 /*	$NetBSD: netbsd32_netbsd.c,v 1.207 2017/07/31 15:38:01 maxv Exp $	*/
2 
3 /*
4  * Copyright (c) 1998, 2001, 2008 Matthew R. Green
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
21  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
23  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26  * SUCH DAMAGE.
27  */
28 
29 #include <sys/cdefs.h>
30 __KERNEL_RCSID(0, "$NetBSD: netbsd32_netbsd.c,v 1.207 2017/07/31 15:38:01 maxv Exp $");
31 
32 #if defined(_KERNEL_OPT)
33 #include "opt_ddb.h"
34 #include "opt_ntp.h"
35 #include "opt_ktrace.h"
36 #include "opt_compat_netbsd.h"
37 #include "opt_compat_43.h"
38 #include "opt_sysv.h"
39 #include "opt_syscall_debug.h"
40 #endif
41 
42 #include <sys/param.h>
43 #include <sys/systm.h>
44 #include <sys/kernel.h>
45 //#define msg __msg /* Don't ask me! */
46 #include <sys/mount.h>
47 #include <sys/socket.h>
48 #include <sys/sockio.h>
49 #include <sys/socketvar.h>
50 #include <sys/mbuf.h>
51 #include <sys/mman.h>
52 #include <sys/stat.h>
53 #include <sys/swap.h>
54 #include <sys/time.h>
55 #include <sys/signalvar.h>
56 #include <sys/ptrace.h>
57 #include <sys/ktrace.h>
58 #include <sys/trace.h>
59 #include <sys/resourcevar.h>
60 #include <sys/pool.h>
61 #include <sys/vnode.h>
62 #include <sys/file.h>
63 #include <sys/filedesc.h>
64 #include <sys/namei.h>
65 #include <sys/dirent.h>
66 #include <sys/quotactl.h>
67 #include <sys/kauth.h>
68 #include <sys/vfs_syscalls.h>
69 
70 #include <uvm/uvm_extern.h>
71 #include <uvm/uvm_swap.h>
72 
73 #include <sys/syscallargs.h>
74 #include <sys/proc.h>
75 #include <sys/acct.h>
76 #include <sys/exec.h>
77 
78 #include <net/if.h>
79 
80 #include <compat/netbsd32/netbsd32.h>
81 #include <compat/netbsd32/netbsd32_exec.h>
82 #include <compat/netbsd32/netbsd32_syscall.h>
83 #include <compat/netbsd32/netbsd32_syscallargs.h>
84 #include <compat/netbsd32/netbsd32_conv.h>
85 
86 #include <compat/sys/mman.h>
87 
88 #if defined(DDB)
89 #include <ddb/ddbvar.h>
90 #endif
91 
92 extern struct sysent netbsd32_sysent[];
93 #ifdef SYSCALL_DEBUG
94 extern const char * const netbsd32_syscallnames[];
95 #endif
96 #ifdef __HAVE_SYSCALL_INTERN
97 void netbsd32_syscall_intern(struct proc *);
98 #else
99 void syscall(void);
100 #endif
101 
102 #define LIMITCHECK(a, b) ((a) != RLIM_INFINITY && (a) > (b))
103 
104 #ifdef COMPAT_16
105 extern char netbsd32_sigcode[], netbsd32_esigcode[];
106 struct uvm_object *emul_netbsd32_object;
107 #endif
108 
109 extern struct sysctlnode netbsd32_sysctl_root;
110 
111 #ifdef MODULAR
112 #include <compat/netbsd32/netbsd32_syscalls_autoload.c>
113 #endif
114 
115 struct emul emul_netbsd32 = {
116 	.e_name =		"netbsd32",
117 	.e_path =		"/emul/netbsd32",
118 #ifndef __HAVE_MINIMAL_EMUL
119 	.e_flags =		0,
120 	.e_errno =		NULL,
121 	.e_nosys =		NETBSD32_SYS_netbsd32_syscall,
122 	.e_nsysent =		NETBSD32_SYS_NSYSENT,
123 #endif
124 	.e_sysent =		netbsd32_sysent,
125 #ifdef SYSCALL_DEBUG
126 	.e_syscallnames =	netbsd32_syscallnames,
127 #else
128 	.e_syscallnames =	NULL,
129 #endif
130 #ifdef MODULAR
131 	.e_sc_autoload =	netbsd32_syscalls_autoload,
132 #endif
133 	.e_sendsig =		netbsd32_sendsig,
134 	.e_trapsignal =		trapsignal,
135 	.e_tracesig =		NULL,
136 #ifdef COMPAT_16
137 	.e_sigcode =		netbsd32_sigcode,
138 	.e_esigcode =		netbsd32_esigcode,
139 	.e_sigobject =		&emul_netbsd32_object,
140 #else
141 	.e_sigcode =		NULL,
142 	.e_esigcode =		NULL,
143 	.e_sigobject =		NULL,
144 #endif
145 	.e_setregs =		netbsd32_setregs,
146 	.e_proc_exec =		NULL,
147 	.e_proc_fork =		NULL,
148 	.e_proc_exit =		NULL,
149 	.e_lwp_fork =		NULL,
150 	.e_lwp_exit =		NULL,
151 #ifdef __HAVE_SYSCALL_INTERN
152 	.e_syscall_intern =	netbsd32_syscall_intern,
153 #else
154 	.e_syscall =		syscall,
155 #endif
156 	.e_sysctlovly =		&netbsd32_sysctl_root,
157 	.e_fault =		NULL,
158 	.e_vm_default_addr =	netbsd32_vm_default_addr,
159 	.e_usertrap =		NULL,
160 	.e_ucsize =		sizeof(ucontext32_t),
161 	.e_startlwp =		startlwp32,
162 	.e_ktrpsig =		netbsd32_ktrpsig
163 };
164 
165 /*
166  * below are all the standard NetBSD system calls, in the 32bit
167  * environment, with the necessary conversions to 64bit before
168  * calling the real syscall.  anything that needs special
169  * attention is handled elsewhere.
170  */
171 
172 int
173 netbsd32_exit(struct lwp *l, const struct netbsd32_exit_args *uap, register_t *retval)
174 {
175 	/* {
176 		syscallarg(int) rval;
177 	} */
178 	struct sys_exit_args ua;
179 
180 	NETBSD32TO64_UAP(rval);
181 	return sys_exit(l, &ua, retval);
182 }
183 
184 int
185 netbsd32_read(struct lwp *l, const struct netbsd32_read_args *uap, register_t *retval)
186 {
187 	/* {
188 		syscallarg(int) fd;
189 		syscallarg(netbsd32_voidp) buf;
190 		syscallarg(netbsd32_size_t) nbyte;
191 	} */
192 	struct sys_read_args ua;
193 
194 	NETBSD32TO64_UAP(fd);
195 	NETBSD32TOP_UAP(buf, void *);
196 	NETBSD32TOX_UAP(nbyte, size_t);
197 	return sys_read(l, &ua, retval);
198 }
199 
200 int
201 netbsd32_write(struct lwp *l, const struct netbsd32_write_args *uap, register_t *retval)
202 {
203 	/* {
204 		syscallarg(int) fd;
205 		syscallarg(const netbsd32_voidp) buf;
206 		syscallarg(netbsd32_size_t) nbyte;
207 	} */
208 	struct sys_write_args ua;
209 
210 	NETBSD32TO64_UAP(fd);
211 	NETBSD32TOP_UAP(buf, void *);
212 	NETBSD32TOX_UAP(nbyte, size_t);
213 	return sys_write(l, &ua, retval);
214 }
215 
216 int
217 netbsd32_close(struct lwp *l, const struct netbsd32_close_args *uap, register_t *retval)
218 {
219 	/* {
220 		syscallarg(int) fd;
221 	} */
222 	struct sys_close_args ua;
223 
224 	NETBSD32TO64_UAP(fd);
225 	return sys_close(l, &ua, retval);
226 }
227 
228 int
229 netbsd32_open(struct lwp *l, const struct netbsd32_open_args *uap, register_t *retval)
230 {
231 	/* {
232 		syscallarg(const netbsd32_charp) path;
233 		syscallarg(int) flags;
234 		syscallarg(mode_t) mode;
235 	} */
236 	struct sys_open_args ua;
237 
238 	NETBSD32TOP_UAP(path, const char);
239 	NETBSD32TO64_UAP(flags);
240 	NETBSD32TO64_UAP(mode);
241 
242 	return sys_open(l, &ua, retval);
243 }
244 
245 int
246 netbsd32_link(struct lwp *l, const struct netbsd32_link_args *uap, register_t *retval)
247 {
248 	/* {
249 		syscallarg(const netbsd32_charp) path;
250 		syscallarg(const netbsd32_charp) link;
251 	} */
252 	struct sys_link_args ua;
253 
254 	NETBSD32TOP_UAP(path, const char);
255 	NETBSD32TOP_UAP(link, const char);
256 	return (sys_link(l, &ua, retval));
257 }
258 
259 int
260 netbsd32_unlink(struct lwp *l, const struct netbsd32_unlink_args *uap, register_t *retval)
261 {
262 	/* {
263 		syscallarg(const netbsd32_charp) path;
264 	} */
265 	struct sys_unlink_args ua;
266 
267 	NETBSD32TOP_UAP(path, const char);
268 
269 	return (sys_unlink(l, &ua, retval));
270 }
271 
272 int
273 netbsd32_chdir(struct lwp *l, const struct netbsd32_chdir_args *uap, register_t *retval)
274 {
275 	/* {
276 		syscallarg(const netbsd32_charp) path;
277 	} */
278 	struct sys_chdir_args ua;
279 
280 	NETBSD32TOP_UAP(path, const char);
281 
282 	return (sys_chdir(l, &ua, retval));
283 }
284 
285 int
286 netbsd32_fchdir(struct lwp *l, const struct netbsd32_fchdir_args *uap, register_t *retval)
287 {
288 	/* {
289 		syscallarg(int) fd;
290 	} */
291 	struct sys_fchdir_args ua;
292 
293 	NETBSD32TO64_UAP(fd);
294 
295 	return (sys_fchdir(l, &ua, retval));
296 }
297 
298 int
299 netbsd32___mknod50(struct lwp *l, const struct netbsd32___mknod50_args *uap, register_t *retval)
300 {
301 	/* {
302 		syscallarg(const netbsd32_charp) path;
303 		syscallarg(mode_t) mode;
304 		syscallarg(netbsd32_dev_t) dev;
305 	} */
306 
307 	return do_sys_mknod(l, SCARG_P32(uap, path), SCARG(uap, mode),
308 	    SCARG(uap, dev), retval, UIO_USERSPACE);
309 }
310 
311 int
312 netbsd32_chmod(struct lwp *l, const struct netbsd32_chmod_args *uap, register_t *retval)
313 {
314 	/* {
315 		syscallarg(const netbsd32_charp) path;
316 		syscallarg(mode_t) mode;
317 	} */
318 	struct sys_chmod_args ua;
319 
320 	NETBSD32TOP_UAP(path, const char);
321 	NETBSD32TO64_UAP(mode);
322 
323 	return (sys_chmod(l, &ua, retval));
324 }
325 
326 int
327 netbsd32_chown(struct lwp *l, const struct netbsd32_chown_args *uap, register_t *retval)
328 {
329 	/* {
330 		syscallarg(const netbsd32_charp) path;
331 		syscallarg(uid_t) uid;
332 		syscallarg(gid_t) gid;
333 	} */
334 	struct sys_chown_args ua;
335 
336 	NETBSD32TOP_UAP(path, const char);
337 	NETBSD32TO64_UAP(uid);
338 	NETBSD32TO64_UAP(gid);
339 
340 	return (sys_chown(l, &ua, retval));
341 }
342 
343 int
344 netbsd32_break(struct lwp *l, const struct netbsd32_break_args *uap, register_t *retval)
345 {
346 	/* {
347 		syscallarg(netbsd32_charp) nsize;
348 	} */
349 	struct sys_obreak_args ua;
350 
351 	NETBSD32TOP_UAP(nsize, char);
352 	return (sys_obreak(l, &ua, retval));
353 }
354 
355 int
356 netbsd32_mount(struct lwp *l, const struct netbsd32_mount_args *uap, register_t *retval)
357 {
358 #ifdef COMPAT_40
359 	/* {
360 		syscallarg(const netbsd32_charp) type;
361 		syscallarg(const netbsd32_charp) path;
362 		syscallarg(int) flags;
363 		syscallarg(netbsd32_voidp) data;
364 	} */
365 	struct compat_40_sys_mount_args ua;
366 
367 	NETBSD32TOP_UAP(type, const char);
368 	NETBSD32TOP_UAP(path, const char);
369 	NETBSD32TO64_UAP(flags);
370 	NETBSD32TOP_UAP(data, void);
371 	return (compat_40_sys_mount(l, &ua, retval));
372 #else
373 	return ENOSYS;
374 #endif
375 }
376 
377 int
378 netbsd32_unmount(struct lwp *l, const struct netbsd32_unmount_args *uap, register_t *retval)
379 {
380 	/* {
381 		syscallarg(const netbsd32_charp) path;
382 		syscallarg(int) flags;
383 	} */
384 	struct sys_unmount_args ua;
385 
386 	NETBSD32TOP_UAP(path, const char);
387 	NETBSD32TO64_UAP(flags);
388 	return (sys_unmount(l, &ua, retval));
389 }
390 
391 int
392 netbsd32_setuid(struct lwp *l, const struct netbsd32_setuid_args *uap, register_t *retval)
393 {
394 	/* {
395 		syscallarg(uid_t) uid;
396 	} */
397 	struct sys_setuid_args ua;
398 
399 	NETBSD32TO64_UAP(uid);
400 	return (sys_setuid(l, &ua, retval));
401 }
402 
403 int
404 netbsd32_accept(struct lwp *l, const struct netbsd32_accept_args *uap, register_t *retval)
405 {
406 	/* {
407 		syscallarg(int) s;
408 		syscallarg(netbsd32_sockaddrp_t) name;
409 		syscallarg(netbsd32_intp) anamelen;
410 	} */
411 	struct sys_accept_args ua;
412 
413 	NETBSD32TO64_UAP(s);
414 	NETBSD32TOP_UAP(name, struct sockaddr);
415 	NETBSD32TOP_UAP(anamelen, socklen_t);
416 	return (sys_accept(l, &ua, retval));
417 }
418 
419 int
420 netbsd32_getpeername(struct lwp *l, const struct netbsd32_getpeername_args *uap, register_t *retval)
421 {
422 	/* {
423 		syscallarg(int) fdes;
424 		syscallarg(netbsd32_sockaddrp_t) asa;
425 		syscallarg(netbsd32_intp) alen;
426 	} */
427 	struct sys_getpeername_args ua;
428 
429 	NETBSD32TO64_UAP(fdes);
430 	NETBSD32TOP_UAP(asa, struct sockaddr);
431 	NETBSD32TOP_UAP(alen, socklen_t);
432 /* NB: do the protocol specific sockaddrs need to be converted? */
433 	return (sys_getpeername(l, &ua, retval));
434 }
435 
436 int
437 netbsd32_getsockname(struct lwp *l, const struct netbsd32_getsockname_args *uap, register_t *retval)
438 {
439 	/* {
440 		syscallarg(int) fdes;
441 		syscallarg(netbsd32_sockaddrp_t) asa;
442 		syscallarg(netbsd32_intp) alen;
443 	} */
444 	struct sys_getsockname_args ua;
445 
446 	NETBSD32TO64_UAP(fdes);
447 	NETBSD32TOP_UAP(asa, struct sockaddr);
448 	NETBSD32TOP_UAP(alen, socklen_t);
449 	return (sys_getsockname(l, &ua, retval));
450 }
451 
452 int
453 netbsd32_access(struct lwp *l, const struct netbsd32_access_args *uap, register_t *retval)
454 {
455 	/* {
456 		syscallarg(const netbsd32_charp) path;
457 		syscallarg(int) flags;
458 	} */
459 	struct sys_access_args ua;
460 
461 	NETBSD32TOP_UAP(path, const char);
462 	NETBSD32TO64_UAP(flags);
463 
464 	return sys_access(l, &ua, retval);
465 }
466 
467 int
468 netbsd32_chflags(struct lwp *l, const struct netbsd32_chflags_args *uap, register_t *retval)
469 {
470 	/* {
471 		syscallarg(const netbsd32_charp) path;
472 		syscallarg(netbsd32_u_long) flags;
473 	} */
474 	struct sys_chflags_args ua;
475 
476 	NETBSD32TOP_UAP(path, const char);
477 	NETBSD32TO64_UAP(flags);
478 
479 	return (sys_chflags(l, &ua, retval));
480 }
481 
482 int
483 netbsd32_fchflags(struct lwp *l, const struct netbsd32_fchflags_args *uap, register_t *retval)
484 {
485 	/* {
486 		syscallarg(int) fd;
487 		syscallarg(netbsd32_u_long) flags;
488 	} */
489 	struct sys_fchflags_args ua;
490 
491 	NETBSD32TO64_UAP(fd);
492 	NETBSD32TO64_UAP(flags);
493 
494 	return (sys_fchflags(l, &ua, retval));
495 }
496 
497 int
498 netbsd32_lchflags(struct lwp *l, const struct netbsd32_lchflags_args *uap, register_t *retval)
499 {
500 	/* {
501 		syscallarg(const char *) path;
502 		syscallarg(netbsd32_u_long) flags;
503 	} */
504 	struct sys_lchflags_args ua;
505 
506 	NETBSD32TOP_UAP(path, const char);
507 	NETBSD32TO64_UAP(flags);
508 
509 	return (sys_lchflags(l, &ua, retval));
510 }
511 
512 int
513 netbsd32_kill(struct lwp *l, const struct netbsd32_kill_args *uap, register_t *retval)
514 {
515 	/* {
516 		syscallarg(int) pid;
517 		syscallarg(int) signum;
518 	} */
519 	struct sys_kill_args ua;
520 
521 	NETBSD32TO64_UAP(pid);
522 	NETBSD32TO64_UAP(signum);
523 
524 	return (sys_kill(l, &ua, retval));
525 }
526 
527 int
528 netbsd32_dup(struct lwp *l, const struct netbsd32_dup_args *uap, register_t *retval)
529 {
530 	/* {
531 		syscallarg(int) fd;
532 	} */
533 	struct sys_dup_args ua;
534 
535 	NETBSD32TO64_UAP(fd);
536 
537 	return (sys_dup(l, &ua, retval));
538 }
539 
540 int
541 netbsd32_profil(struct lwp *l, const struct netbsd32_profil_args *uap, register_t *retval)
542 {
543 	/* {
544 		syscallarg(netbsd32_voidp) samples;
545 		syscallarg(netbsd32_size_t) size;
546 		syscallarg(netbsd32_u_long) offset;
547 		syscallarg(u_int) scale;
548 	} */
549 	struct sys_profil_args ua;
550 
551 	NETBSD32TOP_UAP(samples, void *);
552 	NETBSD32TOX_UAP(size, size_t);
553 	NETBSD32TOX_UAP(offset, u_long);
554 	NETBSD32TO64_UAP(scale);
555 	return (sys_profil(l, &ua, retval));
556 }
557 
558 int
559 netbsd32_ktrace(struct lwp *l, const struct netbsd32_ktrace_args *uap, register_t *retval)
560 {
561 	/* {
562 		syscallarg(const netbsd32_charp) fname;
563 		syscallarg(int) ops;
564 		syscallarg(int) facs;
565 		syscallarg(int) pid;
566 	} */
567 	struct sys_ktrace_args ua;
568 
569 	NETBSD32TOP_UAP(fname, const char);
570 	NETBSD32TO64_UAP(ops);
571 	NETBSD32TO64_UAP(facs);
572 	NETBSD32TO64_UAP(pid);
573 	return (sys_ktrace(l, &ua, retval));
574 }
575 
576 int
577 netbsd32_utrace(struct lwp *l, const struct netbsd32_utrace_args *uap, register_t *retval)
578 {
579 	/* {
580 		syscallarg(const netbsd32_charp) label;
581 		syscallarg(netbsd32_voidp) addr;
582 		syscallarg(netbsd32_size_t) len;
583 	} */
584 	struct sys_utrace_args ua;
585 
586 	NETBSD32TOP_UAP(label, const char);
587 	NETBSD32TOP_UAP(addr, void);
588 	NETBSD32TO64_UAP(len);
589 	return (sys_utrace(l, &ua, retval));
590 }
591 
592 int
593 netbsd32___getlogin(struct lwp *l, const struct netbsd32___getlogin_args *uap, register_t *retval)
594 {
595 	/* {
596 		syscallarg(netbsd32_charp) namebuf;
597 		syscallarg(u_int) namelen;
598 	} */
599 	struct sys___getlogin_args ua;
600 
601 	NETBSD32TOP_UAP(namebuf, char);
602 	NETBSD32TO64_UAP(namelen);
603 	return (sys___getlogin(l, &ua, retval));
604 }
605 
606 int
607 netbsd32_setlogin(struct lwp *l, const struct netbsd32_setlogin_args *uap, register_t *retval)
608 {
609 	/* {
610 		syscallarg(const netbsd32_charp) namebuf;
611 	} */
612 	struct sys___setlogin_args ua;
613 
614 	NETBSD32TOP_UAP(namebuf, char);
615 	return (sys___setlogin(l, &ua, retval));
616 }
617 
618 int
619 netbsd32_acct(struct lwp *l, const struct netbsd32_acct_args *uap, register_t *retval)
620 {
621 	/* {
622 		syscallarg(const netbsd32_charp) path;
623 	} */
624 	struct sys_acct_args ua;
625 
626 	NETBSD32TOP_UAP(path, const char);
627 	return (sys_acct(l, &ua, retval));
628 }
629 
630 int
631 netbsd32_revoke(struct lwp *l, const struct netbsd32_revoke_args *uap, register_t *retval)
632 {
633 	/* {
634 		syscallarg(const netbsd32_charp) path;
635 	} */
636 	struct sys_revoke_args ua;
637 
638 	NETBSD32TOP_UAP(path, const char);
639 
640 	return (sys_revoke(l, &ua, retval));
641 }
642 
643 int
644 netbsd32_symlink(struct lwp *l, const struct netbsd32_symlink_args *uap, register_t *retval)
645 {
646 	/* {
647 		syscallarg(const netbsd32_charp) path;
648 		syscallarg(const netbsd32_charp) link;
649 	} */
650 	struct sys_symlink_args ua;
651 
652 	NETBSD32TOP_UAP(path, const char);
653 	NETBSD32TOP_UAP(link, const char);
654 
655 	return (sys_symlink(l, &ua, retval));
656 }
657 
658 int
659 netbsd32_readlink(struct lwp *l, const struct netbsd32_readlink_args *uap, register_t *retval)
660 {
661 	/* {
662 		syscallarg(const netbsd32_charp) path;
663 		syscallarg(netbsd32_charp) buf;
664 		syscallarg(netbsd32_size_t) count;
665 	} */
666 	struct sys_readlink_args ua;
667 
668 	NETBSD32TOP_UAP(path, const char);
669 	NETBSD32TOP_UAP(buf, char);
670 	NETBSD32TOX_UAP(count, size_t);
671 
672 	return (sys_readlink(l, &ua, retval));
673 }
674 
675 int
676 netbsd32_umask(struct lwp *l, const struct netbsd32_umask_args *uap, register_t *retval)
677 {
678 	/* {
679 		syscallarg(mode_t) newmask;
680 	} */
681 	struct sys_umask_args ua;
682 
683 	NETBSD32TO64_UAP(newmask);
684 	return (sys_umask(l, &ua, retval));
685 }
686 
687 int
688 netbsd32_chroot(struct lwp *l, const struct netbsd32_chroot_args *uap, register_t *retval)
689 {
690 	/* {
691 		syscallarg(const netbsd32_charp) path;
692 	} */
693 	struct sys_chroot_args ua;
694 
695 	NETBSD32TOP_UAP(path, const char);
696 	return (sys_chroot(l, &ua, retval));
697 }
698 
699 int
700 netbsd32_sbrk(struct lwp *l, const struct netbsd32_sbrk_args *uap, register_t *retval)
701 {
702 	/* {
703 		syscallarg(int) incr;
704 	} */
705 	struct sys_sbrk_args ua;
706 
707 	NETBSD32TO64_UAP(incr);
708 	return (sys_sbrk(l, &ua, retval));
709 }
710 
711 int
712 netbsd32_sstk(struct lwp *l, const struct netbsd32_sstk_args *uap, register_t *retval)
713 {
714 	/* {
715 		syscallarg(int) incr;
716 	} */
717 	struct sys_sstk_args ua;
718 
719 	NETBSD32TO64_UAP(incr);
720 	return (sys_sstk(l, &ua, retval));
721 }
722 
723 int
724 netbsd32_munmap(struct lwp *l, const struct netbsd32_munmap_args *uap, register_t *retval)
725 {
726 	/* {
727 		syscallarg(netbsd32_voidp) addr;
728 		syscallarg(netbsd32_size_t) len;
729 	} */
730 	struct sys_munmap_args ua;
731 
732 	NETBSD32TOP_UAP(addr, void);
733 	NETBSD32TOX_UAP(len, size_t);
734 	return (sys_munmap(l, &ua, retval));
735 }
736 
737 int
738 netbsd32_mprotect(struct lwp *l, const struct netbsd32_mprotect_args *uap, register_t *retval)
739 {
740 	/* {
741 		syscallarg(netbsd32_voidp) addr;
742 		syscallarg(netbsd32_size_t) len;
743 		syscallarg(int) prot;
744 	} */
745 	struct sys_mprotect_args ua;
746 
747 	NETBSD32TOP_UAP(addr, void);
748 	NETBSD32TOX_UAP(len, size_t);
749 	NETBSD32TO64_UAP(prot);
750 	return (sys_mprotect(l, &ua, retval));
751 }
752 
753 int
754 netbsd32_madvise(struct lwp *l, const struct netbsd32_madvise_args *uap, register_t *retval)
755 {
756 	/* {
757 		syscallarg(netbsd32_voidp) addr;
758 		syscallarg(netbsd32_size_t) len;
759 		syscallarg(int) behav;
760 	} */
761 	struct sys_madvise_args ua;
762 
763 	NETBSD32TOP_UAP(addr, void);
764 	NETBSD32TOX_UAP(len, size_t);
765 	NETBSD32TO64_UAP(behav);
766 	return (sys_madvise(l, &ua, retval));
767 }
768 
769 int
770 netbsd32_mincore(struct lwp *l, const struct netbsd32_mincore_args *uap, register_t *retval)
771 {
772 	/* {
773 		syscallarg(netbsd32_voidp) addr;
774 		syscallarg(netbsd32_size_t) len;
775 		syscallarg(netbsd32_charp) vec;
776 	} */
777 	struct sys_mincore_args ua;
778 
779 	NETBSD32TOP_UAP(addr, void *);
780 	NETBSD32TOX_UAP(len, size_t);
781 	NETBSD32TOP_UAP(vec, char);
782 	return (sys_mincore(l, &ua, retval));
783 }
784 
785 /* XXX MOVE ME XXX ? */
786 int
787 netbsd32_getgroups(struct lwp *l, const struct netbsd32_getgroups_args *uap, register_t *retval)
788 {
789 	/* {
790 		syscallarg(int) gidsetsize;
791 		syscallarg(netbsd32_gid_tp) gidset;
792 	} */
793 	struct sys_getgroups_args ua;
794 
795 	/* Since sizeof (gid_t) == sizeof (netbsd32_gid_t) ... */
796 
797 	NETBSD32TO64_UAP(gidsetsize);
798 	NETBSD32TOP_UAP(gidset, gid_t);
799 	return (sys_getgroups(l, &ua, retval));
800 }
801 
802 int
803 netbsd32_setgroups(struct lwp *l, const struct netbsd32_setgroups_args *uap, register_t *retval)
804 {
805 	/* {
806 		syscallarg(int) gidsetsize;
807 		syscallarg(const netbsd32_gid_tp) gidset;
808 	} */
809 	struct sys_setgroups_args ua;
810 
811 	NETBSD32TO64_UAP(gidsetsize);
812 	NETBSD32TOP_UAP(gidset, gid_t);
813 	return (sys_setgroups(l, &ua, retval));
814 }
815 
816 int
817 netbsd32_setpgid(struct lwp *l, const struct netbsd32_setpgid_args *uap, register_t *retval)
818 {
819 	/* {
820 		syscallarg(int) pid;
821 		syscallarg(int) pgid;
822 	} */
823 	struct sys_setpgid_args ua;
824 
825 	NETBSD32TO64_UAP(pid);
826 	NETBSD32TO64_UAP(pgid);
827 	return (sys_setpgid(l, &ua, retval));
828 }
829 
830 int
831 netbsd32_fcntl(struct lwp *l, const struct netbsd32_fcntl_args *uap, register_t *retval)
832 {
833 	/* {
834 		syscallarg(int) fd;
835 		syscallarg(int) cmd;
836 		syscallarg(netbsd32_voidp) arg;
837 	} */
838 	struct sys_fcntl_args ua;
839 
840 	NETBSD32TO64_UAP(fd);
841 	NETBSD32TO64_UAP(cmd);
842 	NETBSD32TOP_UAP(arg, void);
843 	/* we can do this because `struct flock' doesn't change */
844 	return (sys_fcntl(l, &ua, retval));
845 }
846 
847 int
848 netbsd32_dup2(struct lwp *l, const struct netbsd32_dup2_args *uap, register_t *retval)
849 {
850 	/* {
851 		syscallarg(int) from;
852 		syscallarg(int) to;
853 	} */
854 	struct sys_dup2_args ua;
855 
856 	NETBSD32TO64_UAP(from);
857 	NETBSD32TO64_UAP(to);
858 	return (sys_dup2(l, &ua, retval));
859 }
860 
861 int
862 netbsd32_fsync(struct lwp *l, const struct netbsd32_fsync_args *uap, register_t *retval)
863 {
864 	/* {
865 		syscallarg(int) fd;
866 	} */
867 	struct sys_fsync_args ua;
868 
869 	NETBSD32TO64_UAP(fd);
870 	return (sys_fsync(l, &ua, retval));
871 }
872 
873 int
874 netbsd32_setpriority(struct lwp *l, const struct netbsd32_setpriority_args *uap, register_t *retval)
875 {
876 	/* {
877 		syscallarg(int) which;
878 		syscallarg(int) who;
879 		syscallarg(int) prio;
880 	} */
881 	struct sys_setpriority_args ua;
882 
883 	NETBSD32TO64_UAP(which);
884 	NETBSD32TO64_UAP(who);
885 	NETBSD32TO64_UAP(prio);
886 	return (sys_setpriority(l, &ua, retval));
887 }
888 
889 int
890 netbsd32___socket30(struct lwp *l, const struct netbsd32___socket30_args *uap, register_t *retval)
891 {
892 	/* {
893 		syscallarg(int) domain;
894 		syscallarg(int) type;
895 		syscallarg(int) protocol;
896 	} */
897 	struct sys___socket30_args ua;
898 
899 	NETBSD32TO64_UAP(domain);
900 	NETBSD32TO64_UAP(type);
901 	NETBSD32TO64_UAP(protocol);
902 	return (sys___socket30(l, &ua, retval));
903 }
904 
905 int
906 netbsd32_connect(struct lwp *l, const struct netbsd32_connect_args *uap, register_t *retval)
907 {
908 	/* {
909 		syscallarg(int) s;
910 		syscallarg(const netbsd32_sockaddrp_t) name;
911 		syscallarg(int) namelen;
912 	} */
913 	struct sys_connect_args ua;
914 
915 	NETBSD32TO64_UAP(s);
916 	NETBSD32TOP_UAP(name, struct sockaddr);
917 	NETBSD32TO64_UAP(namelen);
918 	return (sys_connect(l, &ua, retval));
919 }
920 
921 int
922 netbsd32_getpriority(struct lwp *l, const struct netbsd32_getpriority_args *uap, register_t *retval)
923 {
924 	/* {
925 		syscallarg(int) which;
926 		syscallarg(int) who;
927 	} */
928 	struct sys_getpriority_args ua;
929 
930 	NETBSD32TO64_UAP(which);
931 	NETBSD32TO64_UAP(who);
932 	return (sys_getpriority(l, &ua, retval));
933 }
934 
935 int
936 netbsd32_bind(struct lwp *l, const struct netbsd32_bind_args *uap, register_t *retval)
937 {
938 	/* {
939 		syscallarg(int) s;
940 		syscallarg(const netbsd32_sockaddrp_t) name;
941 		syscallarg(int) namelen;
942 	} */
943 	struct sys_bind_args ua;
944 
945 	NETBSD32TO64_UAP(s);
946 	NETBSD32TOP_UAP(name, struct sockaddr);
947 	NETBSD32TO64_UAP(namelen);
948 	return (sys_bind(l, &ua, retval));
949 }
950 
951 int
952 netbsd32_setsockopt(struct lwp *l, const struct netbsd32_setsockopt_args *uap, register_t *retval)
953 {
954 	/* {
955 		syscallarg(int) s;
956 		syscallarg(int) level;
957 		syscallarg(int) name;
958 		syscallarg(const netbsd32_voidp) val;
959 		syscallarg(int) valsize;
960 	} */
961 	struct sys_setsockopt_args ua;
962 
963 	NETBSD32TO64_UAP(s);
964 	NETBSD32TO64_UAP(level);
965 	NETBSD32TO64_UAP(name);
966 	NETBSD32TOP_UAP(val, void);
967 	NETBSD32TO64_UAP(valsize);
968 	/* may be more efficient to do this inline. */
969 	return (sys_setsockopt(l, &ua, retval));
970 }
971 
972 int
973 netbsd32_listen(struct lwp *l, const struct netbsd32_listen_args *uap, register_t *retval)
974 {
975 	/* {
976 		syscallarg(int) s;
977 		syscallarg(int) backlog;
978 	} */
979 	struct sys_listen_args ua;
980 
981 	NETBSD32TO64_UAP(s);
982 	NETBSD32TO64_UAP(backlog);
983 	return (sys_listen(l, &ua, retval));
984 }
985 
986 int
987 netbsd32_fchown(struct lwp *l, const struct netbsd32_fchown_args *uap, register_t *retval)
988 {
989 	/* {
990 		syscallarg(int) fd;
991 		syscallarg(uid_t) uid;
992 		syscallarg(gid_t) gid;
993 	} */
994 	struct sys_fchown_args ua;
995 
996 	NETBSD32TO64_UAP(fd);
997 	NETBSD32TO64_UAP(uid);
998 	NETBSD32TO64_UAP(gid);
999 	return (sys_fchown(l, &ua, retval));
1000 }
1001 
1002 int
1003 netbsd32_fchmod(struct lwp *l, const struct netbsd32_fchmod_args *uap, register_t *retval)
1004 {
1005 	/* {
1006 		syscallarg(int) fd;
1007 		syscallarg(mode_t) mode;
1008 	} */
1009 	struct sys_fchmod_args ua;
1010 
1011 	NETBSD32TO64_UAP(fd);
1012 	NETBSD32TO64_UAP(mode);
1013 	return (sys_fchmod(l, &ua, retval));
1014 }
1015 
1016 int
1017 netbsd32_setreuid(struct lwp *l, const struct netbsd32_setreuid_args *uap, register_t *retval)
1018 {
1019 	/* {
1020 		syscallarg(uid_t) ruid;
1021 		syscallarg(uid_t) euid;
1022 	} */
1023 	struct sys_setreuid_args ua;
1024 
1025 	NETBSD32TO64_UAP(ruid);
1026 	NETBSD32TO64_UAP(euid);
1027 	return (sys_setreuid(l, &ua, retval));
1028 }
1029 
1030 int
1031 netbsd32_setregid(struct lwp *l, const struct netbsd32_setregid_args *uap, register_t *retval)
1032 {
1033 	/* {
1034 		syscallarg(gid_t) rgid;
1035 		syscallarg(gid_t) egid;
1036 	} */
1037 	struct sys_setregid_args ua;
1038 
1039 	NETBSD32TO64_UAP(rgid);
1040 	NETBSD32TO64_UAP(egid);
1041 	return (sys_setregid(l, &ua, retval));
1042 }
1043 
1044 int
1045 netbsd32_getsockopt(struct lwp *l, const struct netbsd32_getsockopt_args *uap, register_t *retval)
1046 {
1047 	/* {
1048 		syscallarg(int) s;
1049 		syscallarg(int) level;
1050 		syscallarg(int) name;
1051 		syscallarg(netbsd32_voidp) val;
1052 		syscallarg(netbsd32_intp) avalsize;
1053 	} */
1054 	struct sys_getsockopt_args ua;
1055 
1056 	NETBSD32TO64_UAP(s);
1057 	NETBSD32TO64_UAP(level);
1058 	NETBSD32TO64_UAP(name);
1059 	NETBSD32TOP_UAP(val, void);
1060 	NETBSD32TOP_UAP(avalsize, socklen_t);
1061 	return (sys_getsockopt(l, &ua, retval));
1062 }
1063 
1064 int
1065 netbsd32_rename(struct lwp *l, const struct netbsd32_rename_args *uap, register_t *retval)
1066 {
1067 	/* {
1068 		syscallarg(const netbsd32_charp) from;
1069 		syscallarg(const netbsd32_charp) to;
1070 	} */
1071 	struct sys_rename_args ua;
1072 
1073 	NETBSD32TOP_UAP(from, const char);
1074 	NETBSD32TOP_UAP(to, const char);
1075 
1076 	return (sys_rename(l, &ua, retval));
1077 }
1078 
1079 int
1080 netbsd32_flock(struct lwp *l, const struct netbsd32_flock_args *uap, register_t *retval)
1081 {
1082 	/* {
1083 		syscallarg(int) fd;
1084 		syscallarg(int) how;
1085 	} */
1086 	struct sys_flock_args ua;
1087 
1088 	NETBSD32TO64_UAP(fd);
1089 	NETBSD32TO64_UAP(how);
1090 
1091 	return (sys_flock(l, &ua, retval));
1092 }
1093 
1094 int
1095 netbsd32_mkfifo(struct lwp *l, const struct netbsd32_mkfifo_args *uap, register_t *retval)
1096 {
1097 	/* {
1098 		syscallarg(const netbsd32_charp) path;
1099 		syscallarg(mode_t) mode;
1100 	} */
1101 	struct sys_mkfifo_args ua;
1102 
1103 	NETBSD32TOP_UAP(path, const char);
1104 	NETBSD32TO64_UAP(mode);
1105 	return (sys_mkfifo(l, &ua, retval));
1106 }
1107 
1108 int
1109 netbsd32_shutdown(struct lwp *l, const struct netbsd32_shutdown_args *uap, register_t *retval)
1110 {
1111 	/* {
1112 		syscallarg(int) s;
1113 		syscallarg(int) how;
1114 	} */
1115 	struct sys_shutdown_args ua;
1116 
1117 	NETBSD32TO64_UAP(s);
1118 	NETBSD32TO64_UAP(how);
1119 	return (sys_shutdown(l, &ua, retval));
1120 }
1121 
1122 int
1123 netbsd32_socketpair(struct lwp *l, const struct netbsd32_socketpair_args *uap, register_t *retval)
1124 {
1125 	/* {
1126 		syscallarg(int) domain;
1127 		syscallarg(int) type;
1128 		syscallarg(int) protocol;
1129 		syscallarg(netbsd32_intp) rsv;
1130 	} */
1131 	struct sys_socketpair_args ua;
1132 
1133 	NETBSD32TO64_UAP(domain);
1134 	NETBSD32TO64_UAP(type);
1135 	NETBSD32TO64_UAP(protocol);
1136 	NETBSD32TOP_UAP(rsv, int);
1137 	/* Since we're just copying out two `int's we can do this */
1138 	return (sys_socketpair(l, &ua, retval));
1139 }
1140 
1141 int
1142 netbsd32_mkdir(struct lwp *l, const struct netbsd32_mkdir_args *uap, register_t *retval)
1143 {
1144 	/* {
1145 		syscallarg(const netbsd32_charp) path;
1146 		syscallarg(mode_t) mode;
1147 	} */
1148 	struct sys_mkdir_args ua;
1149 
1150 	NETBSD32TOP_UAP(path, const char);
1151 	NETBSD32TO64_UAP(mode);
1152 	return (sys_mkdir(l, &ua, retval));
1153 }
1154 
1155 int
1156 netbsd32_rmdir(struct lwp *l, const struct netbsd32_rmdir_args *uap, register_t *retval)
1157 {
1158 	/* {
1159 		syscallarg(const netbsd32_charp) path;
1160 	} */
1161 	struct sys_rmdir_args ua;
1162 
1163 	NETBSD32TOP_UAP(path, const char);
1164 	return (sys_rmdir(l, &ua, retval));
1165 }
1166 
1167 int
1168 netbsd32___quotactl(struct lwp *l, const struct netbsd32___quotactl_args *uap, register_t *retval)
1169 {
1170 	/* {
1171 		syscallarg(const netbsd32_charp) path;
1172 		syscallarg(netbsd32_voidp) args;
1173 	} */
1174 	struct netbsd32_quotactlargs args32;
1175 	struct quotactl_args args;
1176 	int error;
1177 
1178 	error = copyin(SCARG_P32(uap, args), &args32, sizeof(args32));
1179 	if (error) {
1180 		return error;
1181 	}
1182 
1183 	args.qc_op = args32.qc_op;
1184 	switch (args.qc_op) {
1185 	    case QUOTACTL_STAT:
1186 		args.u.stat.qc_info = NETBSD32PTR64(args32.u.stat.qc_info);
1187 		break;
1188 	    case QUOTACTL_IDTYPESTAT:
1189 		args.u.idtypestat.qc_idtype = args32.u.idtypestat.qc_idtype;
1190 		args.u.idtypestat.qc_info =
1191 			NETBSD32PTR64(args32.u.idtypestat.qc_info);
1192 		break;
1193 	    case QUOTACTL_OBJTYPESTAT:
1194 		args.u.objtypestat.qc_objtype =
1195 			args32.u.objtypestat.qc_objtype;
1196 		args.u.objtypestat.qc_info =
1197 			NETBSD32PTR64(args32.u.objtypestat.qc_info);
1198 		break;
1199 	    case QUOTACTL_GET:
1200 		args.u.get.qc_key = NETBSD32PTR64(args32.u.get.qc_key);
1201 		args.u.get.qc_val = NETBSD32PTR64(args32.u.get.qc_val);
1202 		break;
1203 	    case QUOTACTL_PUT:
1204 		args.u.put.qc_key = NETBSD32PTR64(args32.u.put.qc_key);
1205 		args.u.put.qc_val = NETBSD32PTR64(args32.u.put.qc_val);
1206 		break;
1207 	    case QUOTACTL_DEL:
1208 		args.u.del.qc_key = NETBSD32PTR64(args32.u.del.qc_key);
1209 		break;
1210 	    case QUOTACTL_CURSOROPEN:
1211 		args.u.cursoropen.qc_cursor =
1212 			NETBSD32PTR64(args32.u.cursoropen.qc_cursor);
1213 		break;
1214 	    case QUOTACTL_CURSORCLOSE:
1215 		args.u.cursorclose.qc_cursor =
1216 			NETBSD32PTR64(args32.u.cursorclose.qc_cursor);
1217 		break;
1218 	    case QUOTACTL_CURSORSKIPIDTYPE:
1219 		args.u.cursorskipidtype.qc_cursor =
1220 			NETBSD32PTR64(args32.u.cursorskipidtype.qc_cursor);
1221 		args.u.cursorskipidtype.qc_idtype =
1222 			args32.u.cursorskipidtype.qc_idtype;
1223 		break;
1224 	    case QUOTACTL_CURSORGET:
1225 		args.u.cursorget.qc_cursor =
1226 			NETBSD32PTR64(args32.u.cursorget.qc_cursor);
1227 		args.u.cursorget.qc_keys =
1228 			NETBSD32PTR64(args32.u.cursorget.qc_keys);
1229 		args.u.cursorget.qc_vals =
1230 			NETBSD32PTR64(args32.u.cursorget.qc_vals);
1231 		args.u.cursorget.qc_maxnum =
1232 			args32.u.cursorget.qc_maxnum;
1233 		args.u.cursorget.qc_ret =
1234 			NETBSD32PTR64(args32.u.cursorget.qc_ret);
1235 		break;
1236 	    case QUOTACTL_CURSORATEND:
1237 		args.u.cursoratend.qc_cursor =
1238 			NETBSD32PTR64(args32.u.cursoratend.qc_cursor);
1239 		args.u.cursoratend.qc_ret =
1240 			NETBSD32PTR64(args32.u.cursoratend.qc_ret);
1241 		break;
1242 	    case QUOTACTL_CURSORREWIND:
1243 		args.u.cursorrewind.qc_cursor =
1244 			NETBSD32PTR64(args32.u.cursorrewind.qc_cursor);
1245 		break;
1246 	    case QUOTACTL_QUOTAON:
1247 		args.u.quotaon.qc_idtype = args32.u.quotaon.qc_idtype;
1248 		args.u.quotaon.qc_quotafile =
1249 			NETBSD32PTR64(args32.u.quotaon.qc_quotafile);
1250 		break;
1251 	    case QUOTACTL_QUOTAOFF:
1252 		args.u.quotaoff.qc_idtype = args32.u.quotaoff.qc_idtype;
1253 		break;
1254 	    default:
1255 		return EINVAL;
1256 	}
1257 
1258 	return do_sys_quotactl(SCARG_P32(uap, path), &args);
1259 }
1260 
1261 int
1262 netbsd32___getfh30(struct lwp *l, const struct netbsd32___getfh30_args *uap, register_t *retval)
1263 {
1264 	/* {
1265 		syscallarg(const netbsd32_charp) fname;
1266 		syscallarg(netbsd32_fhandlep_t) fhp;
1267 		syscallarg(netbsd32_size_tp) fh_size;
1268 	} */
1269 	struct vnode *vp;
1270 	fhandle_t *fh;
1271 	int error;
1272 	struct pathbuf *pb;
1273 	struct nameidata nd;
1274 	netbsd32_size_t usz32, sz32;
1275 	size_t sz;
1276 
1277 	/*
1278 	 * Must be super user
1279 	 */
1280 	error = kauth_authorize_system(l->l_cred, KAUTH_SYSTEM_FILEHANDLE,
1281 	    0, NULL, NULL, NULL);
1282 	if (error)
1283 		return (error);
1284 
1285 	error = pathbuf_copyin(SCARG_P32(uap, fname), &pb);
1286 	if (error) {
1287 		return error;
1288 	}
1289 
1290 	NDINIT(&nd, LOOKUP, FOLLOW | LOCKLEAF | TRYEMULROOT, pb);
1291 	error = namei(&nd);
1292 	if (error) {
1293 		pathbuf_destroy(pb);
1294 		return error;
1295 	}
1296 	vp = nd.ni_vp;
1297 	pathbuf_destroy(pb);
1298 
1299 	error = vfs_composefh_alloc(vp, &fh);
1300 	vput(vp);
1301 	if (error != 0) {
1302 		return error;
1303 	}
1304 	error = copyin(SCARG_P32(uap, fh_size), &usz32, sizeof(usz32));
1305 	if (error != 0) {
1306 		goto out;
1307 	}
1308 	sz = FHANDLE_SIZE(fh);
1309 	sz32 = sz;
1310 
1311 	error = copyout(&sz32, SCARG_P32(uap, fh_size), sizeof(sz32));
1312 	if (error != 0) {
1313 		goto out;
1314 	}
1315 	if (usz32 >= sz32) {
1316 		error = copyout(fh, SCARG_P32(uap, fhp), sz);
1317 	} else {
1318 		error = E2BIG;
1319 	}
1320 out:
1321 	vfs_composefh_free(fh);
1322 	return (error);
1323 }
1324 
1325 int
1326 netbsd32_pread(struct lwp *l, const struct netbsd32_pread_args *uap, register_t *retval)
1327 {
1328 	/* {
1329 		syscallarg(int) fd;
1330 		syscallarg(netbsd32_voidp) buf;
1331 		syscallarg(netbsd32_size_t) nbyte;
1332 		syscallarg(int) PAD;
1333 		syscallarg(netbsd32_off_t) offset;
1334 	} */
1335 	struct sys_pread_args ua;
1336 
1337 	NETBSD32TO64_UAP(fd);
1338 	NETBSD32TOP_UAP(buf, void);
1339 	NETBSD32TOX_UAP(nbyte, size_t);
1340 	NETBSD32TO64_UAP(PAD);
1341 	NETBSD32TO64_UAP(offset);
1342 	return sys_pread(l, &ua, retval);
1343 }
1344 
1345 int
1346 netbsd32_pwrite(struct lwp *l, const struct netbsd32_pwrite_args *uap, register_t *retval)
1347 {
1348 	/* {
1349 		syscallarg(int) fd;
1350 		syscallarg(const netbsd32_voidp) buf;
1351 		syscallarg(netbsd32_size_t) nbyte;
1352 		syscallarg(int) PAD;
1353 		syscallarg(netbsd32_off_t) offset;
1354 	} */
1355 	struct sys_pwrite_args ua;
1356 
1357 	NETBSD32TO64_UAP(fd);
1358 	NETBSD32TOP_UAP(buf, void);
1359 	NETBSD32TOX_UAP(nbyte, size_t);
1360 	NETBSD32TO64_UAP(PAD);
1361 	NETBSD32TO64_UAP(offset);
1362 	return sys_pwrite(l, &ua, retval);
1363 }
1364 
1365 int
1366 netbsd32_setgid(struct lwp *l, const struct netbsd32_setgid_args *uap, register_t *retval)
1367 {
1368 	/* {
1369 		syscallarg(gid_t) gid;
1370 	} */
1371 	struct sys_setgid_args ua;
1372 
1373 	NETBSD32TO64_UAP(gid);
1374 	return (sys_setgid(l, &ua, retval));
1375 }
1376 
1377 int
1378 netbsd32_setegid(struct lwp *l, const struct netbsd32_setegid_args *uap, register_t *retval)
1379 {
1380 	/* {
1381 		syscallarg(gid_t) egid;
1382 	} */
1383 	struct sys_setegid_args ua;
1384 
1385 	NETBSD32TO64_UAP(egid);
1386 	return (sys_setegid(l, &ua, retval));
1387 }
1388 
1389 int
1390 netbsd32_seteuid(struct lwp *l, const struct netbsd32_seteuid_args *uap, register_t *retval)
1391 {
1392 	/* {
1393 		syscallarg(gid_t) euid;
1394 	} */
1395 	struct sys_seteuid_args ua;
1396 
1397 	NETBSD32TO64_UAP(euid);
1398 	return (sys_seteuid(l, &ua, retval));
1399 }
1400 
1401 int
1402 netbsd32_pathconf(struct lwp *l, const struct netbsd32_pathconf_args *uap, register_t *retval)
1403 {
1404 	/* {
1405 		syscallarg(netbsd32_charp) path;
1406 		syscallarg(int) name;
1407 	} */
1408 	struct sys_pathconf_args ua;
1409 
1410 	NETBSD32TOP_UAP(path, const char);
1411 	NETBSD32TO64_UAP(name);
1412 	return sys_pathconf(l, &ua, retval);
1413 }
1414 
1415 int
1416 netbsd32_fpathconf(struct lwp *l, const struct netbsd32_fpathconf_args *uap, register_t *retval)
1417 {
1418 	/* {
1419 		syscallarg(int) fd;
1420 		syscallarg(int) name;
1421 	} */
1422 	struct sys_fpathconf_args ua;
1423 
1424 	NETBSD32TO64_UAP(fd);
1425 	NETBSD32TO64_UAP(name);
1426 	return sys_fpathconf(l, &ua, retval);
1427 }
1428 
1429 static void
1430 fixlimit(int which, struct rlimit *alim)
1431 {
1432 	switch (which) {
1433 	case RLIMIT_DATA:
1434 		if (LIMITCHECK(alim->rlim_cur, MAXDSIZ32))
1435 			alim->rlim_cur = MAXDSIZ32;
1436 		if (LIMITCHECK(alim->rlim_max, MAXDSIZ32))
1437 			alim->rlim_max = MAXDSIZ32;
1438 		return;
1439 	case RLIMIT_STACK:
1440 		if (LIMITCHECK(alim->rlim_cur, MAXSSIZ32))
1441 			alim->rlim_cur = MAXSSIZ32;
1442 		if (LIMITCHECK(alim->rlim_max, MAXSSIZ32))
1443 			alim->rlim_max = MAXSSIZ32;
1444 		return;
1445 	default:
1446 		return;
1447 	}
1448 }
1449 
1450 int
1451 netbsd32_getrlimit(struct lwp *l, const struct netbsd32_getrlimit_args *uap,
1452     register_t *retval)
1453 {
1454 	/* {
1455 		syscallarg(int) which;
1456 		syscallarg(netbsd32_rlimitp_t) rlp;
1457 	} */
1458 	int which = SCARG(uap, which);
1459 	struct rlimit alim;
1460 
1461 	if ((u_int)which >= RLIM_NLIMITS)
1462 		return EINVAL;
1463 
1464 	alim = l->l_proc->p_rlimit[which];
1465 
1466 	fixlimit(which, &alim);
1467 
1468 	return copyout(&alim, SCARG_P32(uap, rlp), sizeof(alim));
1469 }
1470 
1471 int
1472 netbsd32_setrlimit(struct lwp *l, const struct netbsd32_setrlimit_args *uap,
1473     register_t *retval)
1474 {
1475 	/* {
1476 		syscallarg(int) which;
1477 		syscallarg(const netbsd32_rlimitp_t) rlp;
1478 	} */
1479 		int which = SCARG(uap, which);
1480 	struct rlimit alim;
1481 	int error;
1482 
1483 	if ((u_int)which >= RLIM_NLIMITS)
1484 		return EINVAL;
1485 
1486 	error = copyin(SCARG_P32(uap, rlp), &alim, sizeof(struct rlimit));
1487 	if (error)
1488 		return (error);
1489 
1490 	fixlimit(which, &alim);
1491 
1492 	return dosetrlimit(l, l->l_proc, which, &alim);
1493 }
1494 
1495 int
1496 netbsd32_mmap(struct lwp *l, const struct netbsd32_mmap_args *uap, register_t *retval)
1497 {
1498 	/* {
1499 		syscallarg(netbsd32_voidp) addr;
1500 		syscallarg(netbsd32_size_t) len;
1501 		syscallarg(int) prot;
1502 		syscallarg(int) flags;
1503 		syscallarg(int) fd;
1504 		syscallarg(netbsd32_long) PAD;
1505 		syscallarg(netbsd32_off_t) pos;
1506 	} */
1507 	struct sys_mmap_args ua;
1508 	int error;
1509 
1510 	NETBSD32TOP_UAP(addr, void);
1511 	NETBSD32TOX_UAP(len, size_t);
1512 	NETBSD32TO64_UAP(prot);
1513 	NETBSD32TO64_UAP(flags);
1514 #ifdef __x86_64__
1515 	/*
1516 	 * Ancient kernel on x86 did not obey PROT_EXEC on i386 at least
1517 	 * and ld.so did not turn it on!
1518 	 */
1519 	if (SCARG(&ua, flags) & COMPAT_MAP_COPY) {
1520 		SCARG(&ua, flags) = MAP_PRIVATE
1521 		    | (SCARG(&ua, flags) & ~COMPAT_MAP_COPY);
1522 		SCARG(&ua, prot) |= PROT_EXEC;
1523 	}
1524 #endif
1525 	NETBSD32TO64_UAP(fd);
1526 	NETBSD32TOX_UAP(PAD, long);
1527 	NETBSD32TOX_UAP(pos, off_t);
1528 #ifdef DEBUG_MMAP
1529 	printf("mmap(addr=0x%lx, len=0x%lx, prot=0x%lx, flags=0x%lx, "
1530 	    "fd=%ld, pos=0x%lx);\n",
1531 	    (long)SCARG(&ua, addr), (long)SCARG(&ua, len),
1532 	    (long)SCARG(&ua, prot), (long)SCARG(&ua, flags),
1533 	    (long)SCARG(&ua, fd), (long)SCARG(&ua, pos));
1534 #endif
1535 	error = sys_mmap(l, &ua, retval);
1536 	if ((u_long)*retval > (u_long)UINT_MAX) {
1537 		printf("netbsd32_mmap: retval out of range: 0x%lx\n",
1538 		    (u_long)*retval);
1539 		/* Should try to recover and return an error here. */
1540 	}
1541 	return (error);
1542 }
1543 
1544 int
1545 netbsd32_mremap(struct lwp *l, const struct netbsd32_mremap_args *uap, register_t *retval)
1546 {
1547 	/* {
1548 		syscallarg(void *) old_address;
1549 		syscallarg(size_t) old_size;
1550 		syscallarg(void *) new_address;
1551 		syscallarg(size_t) new_size;
1552 		syscallarg(int) flags;
1553 	} */
1554 	struct sys_mremap_args ua;
1555 
1556 	NETBSD32TOP_UAP(old_address, void);
1557 	NETBSD32TOX_UAP(old_size, size_t);
1558 	NETBSD32TOP_UAP(new_address, void);
1559 	NETBSD32TOX_UAP(new_size, size_t);
1560 	NETBSD32TO64_UAP(flags);
1561 
1562 	return sys_mremap(l, &ua, retval);
1563 }
1564 
1565 int
1566 netbsd32_lseek(struct lwp *l, const struct netbsd32_lseek_args *uap, register_t *retval)
1567 {
1568 	/* {
1569 		syscallarg(int) fd;
1570 		syscallarg(int) PAD;
1571 		syscallarg(netbsd32_off_t) offset;
1572 		syscallarg(int) whence;
1573 	} */
1574 	struct sys_lseek_args ua;
1575 	union {
1576 	    register_t retval64[2];
1577 	    register32_t retval32[4];
1578 	} newpos;
1579 	int rv;
1580 
1581 	NETBSD32TO64_UAP(fd);
1582 	NETBSD32TO64_UAP(PAD);
1583 	NETBSD32TO64_UAP(offset);
1584 	NETBSD32TO64_UAP(whence);
1585 	rv = sys_lseek(l, &ua, newpos.retval64);
1586 
1587 	/*
1588 	 * We have to split the 64 bit value into 2 halves which will
1589 	 * end up in separate 32 bit registers.
1590 	 * This should DTRT on big and little-endian systems provided that
1591 	 * gcc's 'strict aliasing' tests don't decide that the retval32[]
1592 	 * entries can't have been assigned to, so need not be read!
1593 	 */
1594 	retval[0] = newpos.retval32[0];
1595 	retval[1] = newpos.retval32[1];
1596 
1597 	return rv;
1598 }
1599 
1600 int
1601 netbsd32_truncate(struct lwp *l, const struct netbsd32_truncate_args *uap, register_t *retval)
1602 {
1603 	/* {
1604 		syscallarg(const netbsd32_charp) path;
1605 		syscallarg(int) PAD;
1606 		syscallarg(netbsd32_off_t) length;
1607 	} */
1608 	struct sys_truncate_args ua;
1609 
1610 	NETBSD32TOP_UAP(path, const char);
1611 	NETBSD32TO64_UAP(PAD);
1612 	NETBSD32TO64_UAP(length);
1613 	return (sys_truncate(l, &ua, retval));
1614 }
1615 
1616 int
1617 netbsd32_ftruncate(struct lwp *l, const struct netbsd32_ftruncate_args *uap, register_t *retval)
1618 {
1619 	/* {
1620 		syscallarg(int) fd;
1621 		syscallarg(int) PAD;
1622 		syscallarg(netbsd32_off_t) length;
1623 	} */
1624 	struct sys_ftruncate_args ua;
1625 
1626 	NETBSD32TO64_UAP(fd);
1627 	NETBSD32TO64_UAP(PAD);
1628 	NETBSD32TO64_UAP(length);
1629 	return (sys_ftruncate(l, &ua, retval));
1630 }
1631 
1632 int
1633 netbsd32_mlock(struct lwp *l, const struct netbsd32_mlock_args *uap, register_t *retval)
1634 {
1635 	/* {
1636 		syscallarg(const netbsd32_voidp) addr;
1637 		syscallarg(netbsd32_size_t) len;
1638 	} */
1639 	struct sys_mlock_args ua;
1640 
1641 	NETBSD32TOP_UAP(addr, const void);
1642 	NETBSD32TO64_UAP(len);
1643 	return (sys_mlock(l, &ua, retval));
1644 }
1645 
1646 int
1647 netbsd32_munlock(struct lwp *l, const struct netbsd32_munlock_args *uap, register_t *retval)
1648 {
1649 	/* {
1650 		syscallarg(const netbsd32_voidp) addr;
1651 		syscallarg(netbsd32_size_t) len;
1652 	} */
1653 	struct sys_munlock_args ua;
1654 
1655 	NETBSD32TOP_UAP(addr, const void);
1656 	NETBSD32TO64_UAP(len);
1657 	return (sys_munlock(l, &ua, retval));
1658 }
1659 
1660 int
1661 netbsd32_undelete(struct lwp *l, const struct netbsd32_undelete_args *uap, register_t *retval)
1662 {
1663 	/* {
1664 		syscallarg(const netbsd32_charp) path;
1665 	} */
1666 	struct sys_undelete_args ua;
1667 
1668 	NETBSD32TOP_UAP(path, const char);
1669 	return (sys_undelete(l, &ua, retval));
1670 }
1671 
1672 int
1673 netbsd32_getpgid(struct lwp *l, const struct netbsd32_getpgid_args *uap, register_t *retval)
1674 {
1675 	/* {
1676 		syscallarg(pid_t) pid;
1677 	} */
1678 	struct sys_getpgid_args ua;
1679 
1680 	NETBSD32TO64_UAP(pid);
1681 	return (sys_getpgid(l, &ua, retval));
1682 }
1683 
1684 int
1685 netbsd32_reboot(struct lwp *l, const struct netbsd32_reboot_args *uap, register_t *retval)
1686 {
1687 	/* {
1688 		syscallarg(int) opt;
1689 		syscallarg(netbsd32_charp) bootstr;
1690 	} */
1691 	struct sys_reboot_args ua;
1692 
1693 	NETBSD32TO64_UAP(opt);
1694 	NETBSD32TOP_UAP(bootstr, char);
1695 	return (sys_reboot(l, &ua, retval));
1696 }
1697 
1698 #include <sys/poll.h>
1699 int
1700 netbsd32_poll(struct lwp *l, const struct netbsd32_poll_args *uap, register_t *retval)
1701 {
1702 	/* {
1703 		syscallarg(netbsd32_pollfdp_t) fds;
1704 		syscallarg(u_int) nfds;
1705 		syscallarg(int) timeout;
1706 	} */
1707 	struct sys_poll_args ua;
1708 
1709 	NETBSD32TOP_UAP(fds, struct pollfd);
1710 	NETBSD32TO64_UAP(nfds);
1711 	NETBSD32TO64_UAP(timeout);
1712 
1713 	return (sys_poll(l, &ua, retval));
1714 }
1715 
1716 int
1717 netbsd32_fdatasync(struct lwp *l, const struct netbsd32_fdatasync_args *uap, register_t *retval)
1718 {
1719 	/* {
1720 		syscallarg(int) fd;
1721 	} */
1722 	struct sys_fdatasync_args ua;
1723 
1724 	NETBSD32TO64_UAP(fd);
1725 	return (sys_fdatasync(l, &ua, retval));
1726 }
1727 
1728 int
1729 netbsd32___posix_rename(struct lwp *l, const struct netbsd32___posix_rename_args *uap, register_t *retval)
1730 {
1731 	/* {
1732 		syscallarg(const netbsd32_charp) from;
1733 		syscallarg(const netbsd32_charp) to;
1734 	} */
1735 	struct sys___posix_rename_args ua;
1736 
1737 	NETBSD32TOP_UAP(from, const char);
1738 	NETBSD32TOP_UAP(to, const char);
1739 	return (sys___posix_rename(l, &ua, retval));
1740 }
1741 
1742 static int
1743 netbsd32_swapctl_stats(struct lwp *l, struct sys_swapctl_args *uap, register_t *retval)
1744 {
1745 	struct swapent *ksep;
1746 	struct netbsd32_swapent *usep32;
1747 	struct netbsd32_swapent se32;
1748 	int count = SCARG(uap, misc);
1749 	int i, error = 0;
1750 	size_t ksep_len;
1751 
1752 	if (count < 0)
1753 		return EINVAL;
1754 
1755 	swapsys_lock(RW_WRITER);
1756 
1757 	if ((size_t)count > (size_t)uvmexp.nswapdev)
1758 		count = uvmexp.nswapdev;
1759 	if (count == 0) {
1760 		/* No swap device */
1761 		swapsys_unlock();
1762 		return 0;
1763 	}
1764 
1765 	ksep_len = sizeof(*ksep) * count;
1766 	ksep = kmem_alloc(ksep_len, KM_SLEEP);
1767 	usep32 = (struct netbsd32_swapent *)SCARG(uap, arg);
1768 
1769 	uvm_swap_stats(SWAP_STATS, ksep, count, retval);
1770 	count = *retval;
1771 
1772 	swapsys_unlock();
1773 
1774 	for (i = 0; i < count; i++) {
1775 		se32.se_dev = ksep[i].se_dev;
1776 		se32.se_flags = ksep[i].se_flags;
1777 		se32.se_nblks = ksep[i].se_nblks;
1778 		se32.se_inuse = ksep[i].se_inuse;
1779 		se32.se_priority = ksep[i].se_priority;
1780 		memcpy(se32.se_path, ksep[i].se_path,
1781 			sizeof(se32.se_path));
1782 
1783 		error = copyout(&se32, usep32 + i, sizeof(se32));
1784 		if (error)
1785 			break;
1786 	}
1787 
1788 	kmem_free(ksep, ksep_len);
1789 
1790 	return error;
1791 }
1792 
1793 int
1794 netbsd32_swapctl(struct lwp *l, const struct netbsd32_swapctl_args *uap, register_t *retval)
1795 {
1796 	/* {
1797 		syscallarg(int) cmd;
1798 		syscallarg(const netbsd32_voidp) arg;
1799 		syscallarg(int) misc;
1800 	} */
1801 	struct sys_swapctl_args ua;
1802 
1803 	NETBSD32TO64_UAP(cmd);
1804 	NETBSD32TOP_UAP(arg, void);
1805 	NETBSD32TO64_UAP(misc);
1806 
1807 	/* SWAP_STATS50 and SWAP_STATS13 structures need no translation */
1808 	if (SCARG(&ua, cmd) == SWAP_STATS)
1809 		return netbsd32_swapctl_stats(l, &ua, retval);
1810 
1811 	return (sys_swapctl(l, &ua, retval));
1812 }
1813 
1814 int
1815 netbsd32_minherit(struct lwp *l, const struct netbsd32_minherit_args *uap, register_t *retval)
1816 {
1817 	/* {
1818 		syscallarg(netbsd32_voidp) addr;
1819 		syscallarg(netbsd32_size_t) len;
1820 		syscallarg(int) inherit;
1821 	} */
1822 	struct sys_minherit_args ua;
1823 
1824 	NETBSD32TOP_UAP(addr, void);
1825 	NETBSD32TOX_UAP(len, size_t);
1826 	NETBSD32TO64_UAP(inherit);
1827 	return (sys_minherit(l, &ua, retval));
1828 }
1829 
1830 int
1831 netbsd32_lchmod(struct lwp *l, const struct netbsd32_lchmod_args *uap, register_t *retval)
1832 {
1833 	/* {
1834 		syscallarg(const netbsd32_charp) path;
1835 		syscallarg(mode_t) mode;
1836 	} */
1837 	struct sys_lchmod_args ua;
1838 
1839 	NETBSD32TOP_UAP(path, const char);
1840 	NETBSD32TO64_UAP(mode);
1841 	return (sys_lchmod(l, &ua, retval));
1842 }
1843 
1844 int
1845 netbsd32_lchown(struct lwp *l, const struct netbsd32_lchown_args *uap, register_t *retval)
1846 {
1847 	/* {
1848 		syscallarg(const netbsd32_charp) path;
1849 		syscallarg(uid_t) uid;
1850 		syscallarg(gid_t) gid;
1851 	} */
1852 	struct sys_lchown_args ua;
1853 
1854 	NETBSD32TOP_UAP(path, const char);
1855 	NETBSD32TO64_UAP(uid);
1856 	NETBSD32TO64_UAP(gid);
1857 	return (sys_lchown(l, &ua, retval));
1858 }
1859 
1860 int
1861 netbsd32___msync13(struct lwp *l, const struct netbsd32___msync13_args *uap, register_t *retval)
1862 {
1863 	/* {
1864 		syscallarg(netbsd32_voidp) addr;
1865 		syscallarg(netbsd32_size_t) len;
1866 		syscallarg(int) flags;
1867 	} */
1868 	struct sys___msync13_args ua;
1869 
1870 	NETBSD32TOP_UAP(addr, void);
1871 	NETBSD32TOX_UAP(len, size_t);
1872 	NETBSD32TO64_UAP(flags);
1873 	return (sys___msync13(l, &ua, retval));
1874 }
1875 
1876 int
1877 netbsd32___posix_chown(struct lwp *l, const struct netbsd32___posix_chown_args *uap, register_t *retval)
1878 {
1879 	/* {
1880 		syscallarg(const netbsd32_charp) path;
1881 		syscallarg(uid_t) uid;
1882 		syscallarg(gid_t) gid;
1883 	} */
1884 	struct sys___posix_chown_args ua;
1885 
1886 	NETBSD32TOP_UAP(path, const char);
1887 	NETBSD32TO64_UAP(uid);
1888 	NETBSD32TO64_UAP(gid);
1889 	return (sys___posix_chown(l, &ua, retval));
1890 }
1891 
1892 int
1893 netbsd32___posix_fchown(struct lwp *l, const struct netbsd32___posix_fchown_args *uap, register_t *retval)
1894 {
1895 	/* {
1896 		syscallarg(int) fd;
1897 		syscallarg(uid_t) uid;
1898 		syscallarg(gid_t) gid;
1899 	} */
1900 	struct sys___posix_fchown_args ua;
1901 
1902 	NETBSD32TO64_UAP(fd);
1903 	NETBSD32TO64_UAP(uid);
1904 	NETBSD32TO64_UAP(gid);
1905 	return (sys___posix_fchown(l, &ua, retval));
1906 }
1907 
1908 int
1909 netbsd32___posix_lchown(struct lwp *l, const struct netbsd32___posix_lchown_args *uap, register_t *retval)
1910 {
1911 	/* {
1912 		syscallarg(const netbsd32_charp) path;
1913 		syscallarg(uid_t) uid;
1914 		syscallarg(gid_t) gid;
1915 	} */
1916 	struct sys___posix_lchown_args ua;
1917 
1918 	NETBSD32TOP_UAP(path, const char);
1919 	NETBSD32TO64_UAP(uid);
1920 	NETBSD32TO64_UAP(gid);
1921 	return (sys___posix_lchown(l, &ua, retval));
1922 }
1923 
1924 int
1925 netbsd32_getsid(struct lwp *l, const struct netbsd32_getsid_args *uap, register_t *retval)
1926 {
1927 	/* {
1928 		syscallarg(pid_t) pid;
1929 	} */
1930 	struct sys_getsid_args ua;
1931 
1932 	NETBSD32TO64_UAP(pid);
1933 	return (sys_getsid(l, &ua, retval));
1934 }
1935 
1936 int
1937 netbsd32_fktrace(struct lwp *l, const struct netbsd32_fktrace_args *uap, register_t *retval)
1938 {
1939 	/* {
1940 		syscallarg(int) fd;
1941 		syscallarg(int) ops;
1942 		syscallarg(int) facs;
1943 		syscallarg(int) pid;
1944 	} */
1945 	struct sys_fktrace_args ua;
1946 
1947 	NETBSD32TOX_UAP(fd, int);
1948 	NETBSD32TO64_UAP(ops);
1949 	NETBSD32TO64_UAP(facs);
1950 	NETBSD32TO64_UAP(pid);
1951 	return (sys_fktrace(l, &ua, retval));
1952 }
1953 
1954 int
1955 netbsd32___sigpending14(struct lwp *l, const struct netbsd32___sigpending14_args *uap, register_t *retval)
1956 {
1957 	/* {
1958 		syscallarg(sigset_t *) set;
1959 	} */
1960 	struct sys___sigpending14_args ua;
1961 
1962 	NETBSD32TOP_UAP(set, sigset_t);
1963 	return (sys___sigpending14(l, &ua, retval));
1964 }
1965 
1966 int
1967 netbsd32___sigprocmask14(struct lwp *l, const struct netbsd32___sigprocmask14_args *uap, register_t *retval)
1968 {
1969 	/* {
1970 		syscallarg(int) how;
1971 		syscallarg(const sigset_t *) set;
1972 		syscallarg(sigset_t *) oset;
1973 	} */
1974 	struct sys___sigprocmask14_args ua;
1975 
1976 	NETBSD32TO64_UAP(how);
1977 	NETBSD32TOP_UAP(set, sigset_t);
1978 	NETBSD32TOP_UAP(oset, sigset_t);
1979 	return (sys___sigprocmask14(l, &ua, retval));
1980 }
1981 
1982 int
1983 netbsd32___sigsuspend14(struct lwp *l, const struct netbsd32___sigsuspend14_args *uap, register_t *retval)
1984 {
1985 	/* {
1986 		syscallarg(const sigset_t *) set;
1987 	} */
1988 	struct sys___sigsuspend14_args ua;
1989 
1990 	NETBSD32TOP_UAP(set, sigset_t);
1991 	return (sys___sigsuspend14(l, &ua, retval));
1992 }
1993 
1994 int
1995 netbsd32_fchroot(struct lwp *l, const struct netbsd32_fchroot_args *uap, register_t *retval)
1996 {
1997 	/* {
1998 		syscallarg(int) fd;
1999 	} */
2000 	struct sys_fchroot_args ua;
2001 
2002 	NETBSD32TO64_UAP(fd);
2003 	return (sys_fchroot(l, &ua, retval));
2004 }
2005 
2006 /*
2007  * Open a file given a file handle.
2008  *
2009  * Check permissions, allocate an open file structure,
2010  * and call the device open routine if any.
2011  */
2012 int
2013 netbsd32___fhopen40(struct lwp *l, const struct netbsd32___fhopen40_args *uap, register_t *retval)
2014 {
2015 	/* {
2016 		syscallarg(const netbsd32_pointer_t *) fhp;
2017 		syscallarg(netbsd32_size_t) fh_size;
2018 		syscallarg(int) flags;
2019 	} */
2020 	struct sys___fhopen40_args ua;
2021 
2022 	NETBSD32TOP_UAP(fhp, fhandle_t);
2023 	NETBSD32TO64_UAP(fh_size);
2024 	NETBSD32TO64_UAP(flags);
2025 	return (sys___fhopen40(l, &ua, retval));
2026 }
2027 
2028 /* virtual memory syscalls */
2029 int
2030 netbsd32_ovadvise(struct lwp *l, const struct netbsd32_ovadvise_args *uap, register_t *retval)
2031 {
2032 	/* {
2033 		syscallarg(int) anom;
2034 	} */
2035 	struct sys_ovadvise_args ua;
2036 
2037 	NETBSD32TO64_UAP(anom);
2038 	return (sys_ovadvise(l, &ua, retval));
2039 }
2040 
2041 void
2042 netbsd32_adjust_limits(struct proc *p)
2043 {
2044 	static const struct {
2045 		int id;
2046 		rlim_t lim;
2047 	} lm[] = {
2048 		{ RLIMIT_DATA,	MAXDSIZ32 },
2049 		{ RLIMIT_STACK, MAXSSIZ32 },
2050 	};
2051 	size_t i;
2052 	struct plimit *lim;
2053 	struct rlimit *rlim;
2054 
2055 	/*
2056 	 * We can only reduce the current limits, we cannot stop external
2057 	 * processes from changing them (eg via sysctl) later on.
2058 	 * So there is no point trying to lock out such changes here.
2059 	 *
2060 	 * If we assume that rlim_cur/max are accessed using atomic
2061 	 * operations, we don't need to lock against any other updates
2062 	 * that might happen if the plimit structure is shared writable
2063 	 * between multiple processes.
2064 	 */
2065 
2066 	/* Scan to determine is any limits are out of range */
2067 	lim = p->p_limit;
2068 	for (i = 0; ; i++) {
2069 		if (i >= __arraycount(lm))
2070 			/* All in range */
2071 			return;
2072 		rlim = lim->pl_rlimit + lm[i].id;
2073 		if (LIMITCHECK(rlim->rlim_cur, lm[i].lim))
2074 			break;
2075 		if (LIMITCHECK(rlim->rlim_max, lm[i].lim))
2076 			break;
2077 	}
2078 
2079 	lim_privatise(p);
2080 
2081 	lim = p->p_limit;
2082 	for (i = 0; i < __arraycount(lm); i++) {
2083 		rlim = lim->pl_rlimit + lm[i].id;
2084 		if (LIMITCHECK(rlim->rlim_cur, lm[i].lim))
2085 			rlim->rlim_cur = lm[i].lim;
2086 		if (LIMITCHECK(rlim->rlim_max, lm[i].lim))
2087 			rlim->rlim_max = lm[i].lim;
2088 	}
2089 }
2090 
2091 int
2092 netbsd32_uuidgen(struct lwp *l, const struct netbsd32_uuidgen_args *uap, register_t *retval)
2093 {
2094 	/* {
2095 		syscallarg(netbsd32_uuidp_t) store;
2096 		syscallarg(int) count;
2097 	} */
2098 	struct sys_uuidgen_args ua;
2099 
2100 	NETBSD32TOP_UAP(store, struct uuid);
2101 	NETBSD32TO64_UAP(count);
2102 	return (sys_uuidgen(l, &ua, retval));
2103 }
2104 
2105 int
2106 netbsd32_extattrctl(struct lwp *l, const struct netbsd32_extattrctl_args *uap, register_t *retval)
2107 {
2108 	/* {
2109 		syscallarg(const netbsd32_charp) path;
2110 		syscallarg(int) cmd;
2111 		syscallarg(const netbsd32_charp) filename;
2112 		syscallarg(int) attrnamespace;
2113 		syscallarg(const netbsd32_charp) attrname;
2114 	} */
2115 	struct sys_extattrctl_args ua;
2116 
2117 	NETBSD32TOP_UAP(path, const char);
2118 	NETBSD32TO64_UAP(cmd);
2119 	NETBSD32TOP_UAP(filename, const char);
2120 	NETBSD32TO64_UAP(attrnamespace);
2121 	NETBSD32TOP_UAP(attrname, const char);
2122 	return sys_extattrctl(l, &ua, retval);
2123 }
2124 
2125 int
2126 netbsd32_extattr_set_fd(struct lwp *l, const struct netbsd32_extattr_set_fd_args *uap, register_t *retval)
2127 {
2128 	/* {
2129 		syscallarg(int) fd;
2130 		syscallarg(int) attrnamespace;
2131 		syscallarg(const netbsd32_charp) attrname;
2132 		syscallarg(const netbsd32_voidp) data;
2133 		syscallarg(netbsd32_size_t) nbytes;
2134 	} */
2135 	struct sys_extattr_set_fd_args ua;
2136 
2137 	NETBSD32TO64_UAP(fd);
2138 	NETBSD32TO64_UAP(attrnamespace);
2139 	NETBSD32TOP_UAP(attrname, const char);
2140 	NETBSD32TOP_UAP(data, const void);
2141 	NETBSD32TOX_UAP(nbytes, size_t);
2142 	return sys_extattr_set_fd(l, &ua, retval);
2143 }
2144 
2145 int
2146 netbsd32_extattr_set_file(struct lwp *l, const struct netbsd32_extattr_set_file_args *uap, register_t *retval)
2147 {
2148 	/* {
2149 		syscallarg(const netbsd32_charp) path;
2150 		syscallarg(int) attrnamespace;
2151 		syscallarg(const netbsd32_charp) attrname;
2152 		syscallarg(const netbsd32_voidp) data;
2153 		syscallarg(netbsd32_size_t) nbytes;
2154 	} */
2155 	struct sys_extattr_set_file_args ua;
2156 
2157 	NETBSD32TOP_UAP(path, const char);
2158 	NETBSD32TO64_UAP(attrnamespace);
2159 	NETBSD32TOP_UAP(attrname, const char);
2160 	NETBSD32TOP_UAP(data, const void);
2161 	NETBSD32TOX_UAP(nbytes, size_t);
2162 	return sys_extattr_set_file(l, &ua, retval);
2163 }
2164 
2165 int
2166 netbsd32_extattr_set_link(struct lwp *l, const struct netbsd32_extattr_set_link_args *uap, register_t *retval)
2167 {
2168 	/* {
2169 		syscallarg(const netbsd32_charp) path;
2170 		syscallarg(int) attrnamespace;
2171 		syscallarg(const netbsd32_charp) attrname;
2172 		syscallarg(const netbsd32_voidp) data;
2173 		syscallarg(netbsd32_size_t) nbytes;
2174 	} */
2175 	struct sys_extattr_set_link_args ua;
2176 
2177 	NETBSD32TOP_UAP(path, const char);
2178 	NETBSD32TO64_UAP(attrnamespace);
2179 	NETBSD32TOP_UAP(attrname, const char);
2180 	NETBSD32TOP_UAP(data, const void);
2181 	NETBSD32TOX_UAP(nbytes, size_t);
2182 	return sys_extattr_set_link(l, &ua, retval);
2183 }
2184 
2185 int
2186 netbsd32_extattr_get_fd(struct lwp *l, const struct netbsd32_extattr_get_fd_args *uap, register_t *retval)
2187 {
2188 	/* {
2189 		syscallarg(int) fd;
2190 		syscallarg(int) attrnamespace;
2191 		syscallarg(const netbsd32_charp) attrname;
2192 		syscallarg(netbsd32_voidp) data;
2193 		syscallarg(netbsd32_size_t) nbytes;
2194 	} */
2195 	struct sys_extattr_get_fd_args ua;
2196 
2197 	NETBSD32TO64_UAP(fd);
2198 	NETBSD32TO64_UAP(attrnamespace);
2199 	NETBSD32TOP_UAP(attrname, const char);
2200 	NETBSD32TOP_UAP(data, void);
2201 	NETBSD32TOX_UAP(nbytes, size_t);
2202 	return sys_extattr_get_fd(l, &ua, retval);
2203 }
2204 
2205 int
2206 netbsd32_extattr_get_file(struct lwp *l, const struct netbsd32_extattr_get_file_args *uap, register_t *retval)
2207 {
2208 	/* {
2209 		syscallarg(const netbsd32_charp) path;
2210 		syscallarg(int) attrnamespace;
2211 		syscallarg(const netbsd32_charp) attrname;
2212 		syscallarg(netbsd32_voidp) data;
2213 		syscallarg(netbsd32_size_t) nbytes;
2214 	} */
2215 	struct sys_extattr_get_file_args ua;
2216 
2217 	NETBSD32TOP_UAP(path, const char);
2218 	NETBSD32TO64_UAP(attrnamespace);
2219 	NETBSD32TOP_UAP(attrname, const char);
2220 	NETBSD32TOP_UAP(data, void);
2221 	NETBSD32TOX_UAP(nbytes, size_t);
2222 	return sys_extattr_get_file(l, &ua, retval);
2223 }
2224 
2225 int
2226 netbsd32_extattr_get_link(struct lwp *l, const struct netbsd32_extattr_get_link_args *uap, register_t *retval)
2227 {
2228 	/* {
2229 		syscallarg(const netbsd32_charp) path;
2230 		syscallarg(int) attrnamespace;
2231 		syscallarg(const netbsd32_charp) attrname;
2232 		syscallarg(netbsd32_voidp) data;
2233 		syscallarg(netbsd32_size_t) nbytes;
2234 	} */
2235 	struct sys_extattr_get_link_args ua;
2236 
2237 	NETBSD32TOP_UAP(path, const char);
2238 	NETBSD32TO64_UAP(attrnamespace);
2239 	NETBSD32TOP_UAP(attrname, const char);
2240 	NETBSD32TOP_UAP(data, void);
2241 	NETBSD32TOX_UAP(nbytes, size_t);
2242 	return sys_extattr_get_link(l, &ua, retval);
2243 }
2244 
2245 int
2246 netbsd32_extattr_delete_fd(struct lwp *l, const struct netbsd32_extattr_delete_fd_args *uap, register_t *retval)
2247 {
2248 	/* {
2249 		syscallarg(int) fd;
2250 		syscallarg(int) attrnamespace;
2251 		syscallarg(const netbsd32_charp) attrname;
2252 	} */
2253 	struct sys_extattr_delete_fd_args ua;
2254 
2255 	NETBSD32TO64_UAP(fd);
2256 	NETBSD32TO64_UAP(attrnamespace);
2257 	NETBSD32TOP_UAP(attrname, const char);
2258 	return sys_extattr_delete_fd(l, &ua, retval);
2259 }
2260 
2261 int
2262 netbsd32_extattr_delete_file(struct lwp *l, const struct netbsd32_extattr_delete_file_args *uap, register_t *retval)
2263 {
2264 	/* {
2265 		syscallarg(const netbsd32_charp) path;
2266 		syscallarg(int) attrnamespace;
2267 		syscallarg(const netbsd32_charp) attrname;
2268 	} */
2269 	struct sys_extattr_delete_file_args ua;
2270 
2271 	NETBSD32TOP_UAP(path, const char);
2272 	NETBSD32TO64_UAP(attrnamespace);
2273 	NETBSD32TOP_UAP(attrname, const char);
2274 	return sys_extattr_delete_file(l, &ua, retval);
2275 }
2276 
2277 int
2278 netbsd32_extattr_delete_link(struct lwp *l, const struct netbsd32_extattr_delete_link_args *uap, register_t *retval)
2279 {
2280 	/* {
2281 		syscallarg(const netbsd32_charp) path;
2282 		syscallarg(int) attrnamespace;
2283 		syscallarg(const netbsd32_charp) attrname;
2284 	} */
2285 	struct sys_extattr_delete_link_args ua;
2286 
2287 	NETBSD32TOP_UAP(path, const char);
2288 	NETBSD32TO64_UAP(attrnamespace);
2289 	NETBSD32TOP_UAP(attrname, const char);
2290 	return sys_extattr_delete_link(l, &ua, retval);
2291 }
2292 
2293 int
2294 netbsd32_extattr_list_fd(struct lwp *l, const struct netbsd32_extattr_list_fd_args *uap, register_t *retval)
2295 {
2296 	/* {
2297 		syscallarg(int) fd;
2298 		syscallarg(int) attrnamespace;
2299 		syscallarg(netbsd32_voidp) data;
2300 		syscallarg(netbsd32_size_t) nbytes;
2301 	} */
2302 	struct sys_extattr_list_fd_args ua;
2303 
2304 	NETBSD32TO64_UAP(fd);
2305 	NETBSD32TO64_UAP(attrnamespace);
2306 	NETBSD32TOP_UAP(data, void);
2307 	NETBSD32TOX_UAP(nbytes, size_t);
2308 	return sys_extattr_list_fd(l, &ua, retval);
2309 }
2310 
2311 int
2312 netbsd32_extattr_list_file(struct lwp *l, const struct netbsd32_extattr_list_file_args *uap, register_t *retval)
2313 {
2314 	/* {
2315 		syscallarg(const netbsd32_charp) path;
2316 		syscallarg(int) attrnamespace;
2317 		syscallarg(netbsd32_voidp) data;
2318 		syscallarg(netbsd32_size_t) nbytes;
2319 	} */
2320 	struct sys_extattr_list_file_args ua;
2321 
2322 	NETBSD32TOP_UAP(path, const char);
2323 	NETBSD32TO64_UAP(attrnamespace);
2324 	NETBSD32TOP_UAP(data, void);
2325 	NETBSD32TOX_UAP(nbytes, size_t);
2326 	return sys_extattr_list_file(l, &ua, retval);
2327 }
2328 
2329 int
2330 netbsd32_extattr_list_link(struct lwp *l, const struct netbsd32_extattr_list_link_args *uap, register_t *retval)
2331 {
2332 	/* {
2333 		syscallarg(const netbsd32_charp) path;
2334 		syscallarg(int) attrnamespace;
2335 		syscallarg(netbsd32_voidp) data;
2336 		syscallarg(netbsd32_size_t) nbytes;
2337 	} */
2338 	struct sys_extattr_list_link_args ua;
2339 
2340 	NETBSD32TOP_UAP(path, const char);
2341 	NETBSD32TO64_UAP(attrnamespace);
2342 	NETBSD32TOP_UAP(data, void);
2343 	NETBSD32TOX_UAP(nbytes, size_t);
2344 	return sys_extattr_list_link(l, &ua, retval);
2345 }
2346 
2347 int
2348 netbsd32_mlockall(struct lwp *l, const struct netbsd32_mlockall_args *uap, register_t *retval)
2349 {
2350 	/* {
2351 		syscallarg(int) flags;
2352 	} */
2353 	struct sys_mlockall_args ua;
2354 
2355 	NETBSD32TO64_UAP(flags);
2356 	return (sys_mlockall(l, &ua, retval));
2357 }
2358 
2359 int
2360 netbsd32___clone(struct lwp *l, const struct netbsd32___clone_args *uap, register_t *retval)
2361 {
2362 	/*  {
2363 		syscallarg(int) flags;
2364 		syscallarg(netbsd32_voidp) stack;
2365 	} */
2366 	struct sys___clone_args ua;
2367 
2368 	NETBSD32TO64_UAP(flags);
2369 	NETBSD32TOP_UAP(stack, void);
2370 	return sys___clone(l, &ua, retval);
2371 }
2372 
2373 int
2374 netbsd32_fsync_range(struct lwp *l, const struct netbsd32_fsync_range_args *uap, register_t *retval)
2375 {
2376 	/* {
2377 		syscallarg(int) fd;
2378 		syscallarg(int) flags;
2379 		syscallarg(off_t) start;
2380 		syscallarg(off_t) length;
2381 	} */
2382 	struct sys_fsync_range_args ua;
2383 
2384 	NETBSD32TO64_UAP(fd);
2385 	NETBSD32TO64_UAP(flags);
2386 	NETBSD32TO64_UAP(start);
2387 	NETBSD32TO64_UAP(length);
2388 	return (sys_fsync_range(l, &ua, retval));
2389 }
2390 
2391 int
2392 netbsd32_rasctl(struct lwp *l, const struct netbsd32_rasctl_args *uap, register_t *retval)
2393 {
2394 	/* {
2395 		syscallarg(netbsd32_voidp) addr;
2396 		syscallarg(netbsd32_size_t) len;
2397 		syscallarg(int) op;
2398 	} */
2399 	struct sys_rasctl_args ua;
2400 
2401 	NETBSD32TOP_UAP(addr, void *);
2402 	NETBSD32TOX_UAP(len, size_t);
2403 	NETBSD32TO64_UAP(op);
2404 	return sys_rasctl(l, &ua, retval);
2405 }
2406 
2407 int
2408 netbsd32_setxattr(struct lwp *l, const struct netbsd32_setxattr_args *uap, register_t *retval)
2409 {
2410 	/* {
2411 		syscallarg(const netbsd32_charp) path;
2412 		syscallarg(const netbsd32_charp) name;
2413 		syscallarg(netbsd32_voidp) value;
2414 		syscallarg(netbsd32_size_t) size;
2415 		syscallarg(int) flags;
2416 	} */
2417 	struct sys_setxattr_args ua;
2418 	NETBSD32TOP_UAP(path, const char);
2419 	NETBSD32TOP_UAP(name, const char);
2420 	NETBSD32TOP_UAP(value, void);
2421 	NETBSD32TOX_UAP(size, size_t);
2422 	NETBSD32TO64_UAP(flags);
2423 	return sys_setxattr(l, &ua, retval);
2424 }
2425 
2426 int
2427 netbsd32_lsetxattr(struct lwp *l, const struct netbsd32_lsetxattr_args *uap, register_t *retval)
2428 {
2429 	/* {
2430 		syscallarg(const netbsd32_charp) path;
2431 		syscallarg(const netbsd32_charp) name;
2432 		syscallarg(netbsd32_voidp) value;
2433 		syscallarg(netbsd32_size_t) size;
2434 		syscallarg(int) flags;
2435 	} */
2436 	struct sys_lsetxattr_args ua;
2437 	NETBSD32TOP_UAP(path, const char);
2438 	NETBSD32TOP_UAP(name, const char);
2439 	NETBSD32TOP_UAP(value, void);
2440 	NETBSD32TOX_UAP(size, size_t);
2441 	NETBSD32TO64_UAP(flags);
2442 	return sys_lsetxattr(l, &ua, retval);
2443 }
2444 
2445 int
2446 netbsd32_fsetxattr(struct lwp *l, const struct netbsd32_fsetxattr_args *uap, register_t *retval)
2447 {
2448 	/* {
2449 		syscallarg(int) fd;
2450 		syscallarg(const netbsd32_charp) name;
2451 		syscallarg(netbsd32_voidp) value;
2452 		syscallarg(netbsd32_size_t) size;
2453 		syscallarg(int) flags;
2454 	} */
2455 	struct sys_fsetxattr_args ua;
2456 	NETBSD32TO64_UAP(fd);
2457 	NETBSD32TOP_UAP(name, const char);
2458 	NETBSD32TOP_UAP(value, void);
2459 	NETBSD32TOX_UAP(size, size_t);
2460 	NETBSD32TO64_UAP(flags);
2461 	return sys_fsetxattr(l, &ua, retval);
2462 }
2463 
2464 int
2465 netbsd32_getxattr(struct lwp *l, const struct netbsd32_getxattr_args *uap, register_t *retval)
2466 {
2467 	/* {
2468 		syscallarg(const netbsd32_charp) path;
2469 		syscallarg(const netbsd32_charp) name;
2470 		syscallarg(netbsd32_voidp) value;
2471 		syscallarg(netbsd32_size_t) size;
2472 	} */
2473 	struct sys_getxattr_args ua;
2474 	NETBSD32TOP_UAP(path, const char);
2475 	NETBSD32TOP_UAP(name, const char);
2476 	NETBSD32TOP_UAP(value, void);
2477 	NETBSD32TOX_UAP(size, size_t);
2478 	return sys_getxattr(l, &ua, retval);
2479 }
2480 
2481 int
2482 netbsd32_lgetxattr(struct lwp *l, const struct netbsd32_lgetxattr_args *uap, register_t *retval)
2483 {
2484 	/* {
2485 		syscallarg(const netbsd32_charp) path;
2486 		syscallarg(const netbsd32_charp) name;
2487 		syscallarg(netbsd32_voidp) value;
2488 		syscallarg(netbsd32_size_t) size;
2489 	} */
2490 	struct sys_lgetxattr_args ua;
2491 	NETBSD32TOP_UAP(path, const char);
2492 	NETBSD32TOP_UAP(name, const char);
2493 	NETBSD32TOP_UAP(value, void);
2494 	NETBSD32TOX_UAP(size, size_t);
2495 	return sys_lgetxattr(l, &ua, retval);
2496 }
2497 
2498 int
2499 netbsd32_fgetxattr(struct lwp *l, const struct netbsd32_fgetxattr_args *uap, register_t *retval)
2500 {
2501 	/* {
2502 		syscallarg(int) fd;
2503 		syscallarg(const netbsd32_charp) name;
2504 		syscallarg(netbsd32_voidp) value;
2505 		syscallarg(netbsd32_size_t) size;
2506 	} */
2507 	struct sys_fgetxattr_args ua;
2508 	NETBSD32TO64_UAP(fd);
2509 	NETBSD32TOP_UAP(name, const char);
2510 	NETBSD32TOP_UAP(value, void);
2511 	NETBSD32TOX_UAP(size, size_t);
2512 	return sys_fgetxattr(l, &ua, retval);
2513 }
2514 
2515 int
2516 netbsd32_listxattr(struct lwp *l, const struct netbsd32_listxattr_args *uap, register_t *retval)
2517 {
2518 	/* {
2519 		syscallarg(const netbsd32_charp) path;
2520 		syscallarg(netbsd32_charp) list;
2521 		syscallarg(netbsd32_size_t) size;
2522 	} */
2523 	struct sys_listxattr_args ua;
2524 	NETBSD32TOP_UAP(path, const char);
2525 	NETBSD32TOP_UAP(list, char);
2526 	NETBSD32TOX_UAP(size, size_t);
2527 	return sys_listxattr(l, &ua, retval);
2528 }
2529 
2530 int
2531 netbsd32_llistxattr(struct lwp *l, const struct netbsd32_llistxattr_args *uap, register_t *retval)
2532 {
2533 	/* {
2534 		syscallarg(const netbsd32_charp) path;
2535 		syscallarg(netbsd32_charp) list;
2536 		syscallarg(netbsd32_size_t) size;
2537 	} */
2538 	struct sys_llistxattr_args ua;
2539 	NETBSD32TOP_UAP(path, const char);
2540 	NETBSD32TOP_UAP(list, char);
2541 	NETBSD32TOX_UAP(size, size_t);
2542 	return sys_llistxattr(l, &ua, retval);
2543 }
2544 
2545 int
2546 netbsd32_flistxattr(struct lwp *l, const struct netbsd32_flistxattr_args *uap, register_t *retval)
2547 {
2548 	/* {
2549 		syscallarg(int) fd;
2550 		syscallarg(netbsd32_charp) list;
2551 		syscallarg(netbsd32_size_t) size;
2552 	} */
2553 	struct sys_flistxattr_args ua;
2554 	NETBSD32TO64_UAP(fd);
2555 	NETBSD32TOP_UAP(list, char);
2556 	NETBSD32TOX_UAP(size, size_t);
2557 	return sys_flistxattr(l, &ua, retval);
2558 }
2559 
2560 int
2561 netbsd32_removexattr(struct lwp *l, const struct netbsd32_removexattr_args *uap, register_t *retval)
2562 {
2563 	/* {
2564 		syscallarg(const netbsd32_charp) path;
2565 		syscallarg(const netbsd32_charp) name;
2566 	} */
2567 	struct sys_removexattr_args ua;
2568 	NETBSD32TOP_UAP(path, const char);
2569 	NETBSD32TOP_UAP(name, const char);
2570 	return sys_removexattr(l, &ua, retval);
2571 }
2572 
2573 int
2574 netbsd32_lremovexattr(struct lwp *l, const struct netbsd32_lremovexattr_args *uap, register_t *retval)
2575 {
2576 	/* {
2577 		syscallarg(const netbsd32_charp) path;
2578 		syscallarg(const netbsd32_charp) name;
2579 	} */
2580 	struct sys_lremovexattr_args ua;
2581 	NETBSD32TOP_UAP(path, const char);
2582 	NETBSD32TOP_UAP(name, const char);
2583 	return sys_lremovexattr(l, &ua, retval);
2584 }
2585 
2586 int
2587 netbsd32_fremovexattr(struct lwp *l, const struct netbsd32_fremovexattr_args *uap, register_t *retval)
2588 {
2589 	/* {
2590 		syscallarg(int) fd;
2591 		syscallarg(const netbsd32_charp) name;
2592 	} */
2593 	struct sys_fremovexattr_args ua;
2594 	NETBSD32TO64_UAP(fd);
2595 	NETBSD32TOP_UAP(name, const char);
2596 	return sys_fremovexattr(l, &ua, retval);
2597 }
2598 
2599 int
2600 netbsd32___posix_fadvise50(struct lwp *l,
2601 	const struct netbsd32___posix_fadvise50_args *uap, register_t *retval)
2602 {
2603 	/* {
2604 		syscallarg(int) fd;
2605 		syscallarg(int) PAD;
2606 		syscallarg(netbsd32_off_t) offset;
2607 		syscallarg(netbsd32_off_t) len;
2608 		syscallarg(int) advice;
2609 	} */
2610 
2611 	*retval = do_posix_fadvise(SCARG(uap, fd), SCARG(uap, offset),
2612 	    SCARG(uap, len), SCARG(uap, advice));
2613 
2614 	return 0;
2615 }
2616 
2617 int
2618 netbsd32__sched_setparam(struct lwp *l,
2619 			 const struct netbsd32__sched_setparam_args *uap,
2620 			 register_t *retval)
2621 {
2622 	/* {
2623 		syscallarg(pid_t) pid;
2624 		syscallarg(lwpid_t) lid;
2625 		syscallarg(int) policy;
2626 		syscallarg(const netbsd32_sched_paramp_t) params;
2627 	} */
2628 	struct sys__sched_setparam_args ua;
2629 
2630 	NETBSD32TO64_UAP(pid);
2631 	NETBSD32TO64_UAP(lid);
2632 	NETBSD32TO64_UAP(policy);
2633 	NETBSD32TOP_UAP(params, const struct sched_param *);
2634 	return sys__sched_setparam(l, &ua, retval);
2635 }
2636 
2637 int
2638 netbsd32__sched_getparam(struct lwp *l,
2639 			 const struct netbsd32__sched_getparam_args *uap,
2640 			 register_t *retval)
2641 {
2642 	/* {
2643 		syscallarg(pid_t) pid;
2644 		syscallarg(lwpid_t) lid;
2645 		syscallarg(netbsd32_intp) policy;
2646 		syscallarg(netbsd32_sched_paramp_t) params;
2647 	} */
2648 	struct sys__sched_getparam_args ua;
2649 
2650 	NETBSD32TO64_UAP(pid);
2651 	NETBSD32TO64_UAP(lid);
2652 	NETBSD32TOP_UAP(policy, int *);
2653 	NETBSD32TOP_UAP(params, struct sched_param *);
2654 	return sys__sched_getparam(l, &ua, retval);
2655 }
2656 
2657 int
2658 netbsd32__sched_setaffinity(struct lwp *l,
2659 			    const struct netbsd32__sched_setaffinity_args *uap,
2660 			    register_t *retval)
2661 {
2662 	/* {
2663 		syscallarg(pid_t) pid;
2664 		syscallarg(lwpid_t) lid;
2665 		syscallarg(netbsd_size_t) size;
2666 		syscallarg(const netbsd32_cpusetp_t) cpuset;
2667 	} */
2668 	struct sys__sched_setaffinity_args ua;
2669 
2670 	NETBSD32TO64_UAP(pid);
2671 	NETBSD32TO64_UAP(lid);
2672 	NETBSD32TOX_UAP(size, size_t);
2673 	NETBSD32TOP_UAP(cpuset, const cpuset_t *);
2674 	return sys__sched_setaffinity(l, &ua, retval);
2675 }
2676 
2677 int
2678 netbsd32__sched_getaffinity(struct lwp *l,
2679 			    const struct netbsd32__sched_getaffinity_args *uap,
2680 			    register_t *retval)
2681 {
2682 	/* {
2683 		syscallarg(pid_t) pid;
2684 		syscallarg(lwpid_t) lid;
2685 		syscallarg(netbsd_size_t) size;
2686 		syscallarg(netbsd32_cpusetp_t) cpuset;
2687 	} */
2688 	struct sys__sched_getaffinity_args ua;
2689 
2690 	NETBSD32TO64_UAP(pid);
2691 	NETBSD32TO64_UAP(lid);
2692 	NETBSD32TOX_UAP(size, size_t);
2693 	NETBSD32TOP_UAP(cpuset, cpuset_t *);
2694 	return sys__sched_getaffinity(l, &ua, retval);
2695 }
2696 
2697 int
2698 netbsd32__sched_protect(struct lwp *l,
2699 			const struct netbsd32__sched_protect_args *uap,
2700 			register_t *retval)
2701 {
2702 	/* {
2703 		syscallarg(int) priority;
2704 	} */
2705 	struct sys__sched_protect_args ua;
2706 
2707 	NETBSD32TO64_UAP(priority);
2708 	return sys__sched_protect(l, &ua, retval);
2709 }
2710 
2711 int
2712 netbsd32_pipe2(struct lwp *l, const struct netbsd32_pipe2_args *uap,
2713 	       register_t *retval)
2714 {
2715 	/* {
2716 		syscallarg(netbsd32_intp) fildes;
2717 		syscallarg(int) flags;
2718 	} */
2719 	int fd[2], error;
2720 
2721 	error = pipe1(l, retval, SCARG(uap, flags));
2722 	if (error != 0)
2723 		return error;
2724 
2725 	fd[0] = retval[0];
2726 	fd[1] = retval[1];
2727 
2728 	error = copyout(fd, SCARG_P32(uap, fildes), sizeof(fd));
2729 	if (error != 0)
2730 		return error;
2731 
2732 	retval[0] = 0;
2733 	return 0;
2734 }
2735 
2736 int
2737 netbsd32_dup3(struct lwp *l, const struct netbsd32_dup3_args *uap,
2738 	      register_t *retval)
2739 {
2740 	/* {
2741 		syscallarg(int) from;
2742 		syscallarg(int) to;
2743 		syscallarg(int) flags;
2744 	} */
2745 	struct sys_dup3_args ua;
2746 
2747 	NETBSD32TO64_UAP(from);
2748 	NETBSD32TO64_UAP(to);
2749 	NETBSD32TO64_UAP(flags);
2750 
2751 	return sys_dup3(l, &ua, retval);
2752 }
2753 
2754 int
2755 netbsd32_kqueue1(struct lwp *l, const struct netbsd32_kqueue1_args *uap,
2756 		 register_t *retval)
2757 {
2758 	/* {
2759 		syscallarg(int) flags;
2760 	} */
2761 	struct sys_kqueue1_args ua;
2762 
2763 	NETBSD32TO64_UAP(flags);
2764 
2765 	return sys_kqueue1(l, &ua, retval);
2766 }
2767 
2768 int
2769 netbsd32_paccept(struct lwp *l, const struct netbsd32_paccept_args *uap,
2770 		 register_t *retval)
2771 {
2772 	/* {
2773 		syscallarg(int) s;
2774 		syscallarg(netbsd32_sockaddrp_t) name;
2775 		syscallarg(netbsd32_socklenp_t) anamelen;
2776 		syscallarg(const netbsd32_sigsetp_t) mask;
2777 		syscallarg(int) flags;
2778 	} */
2779 	struct sys_paccept_args ua;
2780 
2781 	NETBSD32TO64_UAP(s);
2782 	NETBSD32TOP_UAP(name, struct sockaddr *);
2783 	NETBSD32TOP_UAP(anamelen, socklen_t *);
2784 	NETBSD32TOP_UAP(mask, const sigset_t *);
2785 	NETBSD32TO64_UAP(flags);
2786 
2787 	return sys_paccept(l, &ua, retval);
2788 }
2789 
2790 int
2791 netbsd32_fdiscard(struct lwp *l, const struct netbsd32_fdiscard_args *uap,
2792 	register_t *retval)
2793 {
2794 	/* {
2795 		syscallarg(int) fd;
2796 		syscallarg(netbsd32_off_t) pos;
2797 		syscallarg(netbsd32_off_t) len;
2798 	} */
2799 	struct sys_fdiscard_args ua;
2800 
2801 	NETBSD32TO64_UAP(fd);
2802 	NETBSD32TO64_UAP(pos);
2803 	NETBSD32TO64_UAP(len);
2804 
2805 	return sys_fdiscard(l, &ua, retval);
2806 }
2807 
2808 int
2809 netbsd32_posix_fallocate(struct lwp *l, const struct netbsd32_posix_fallocate_args *uap,
2810 	register_t *retval)
2811 {
2812 	/* {
2813 		syscallarg(int) fd;
2814 		syscallarg(netbsd32_off_t) pos;
2815 		syscallarg(netbsd32_off_t) len;
2816 	} */
2817 	struct sys_posix_fallocate_args ua;
2818 
2819 	NETBSD32TO64_UAP(fd);
2820 	NETBSD32TO64_UAP(pos);
2821 	NETBSD32TO64_UAP(len);
2822 
2823 	return sys_posix_fallocate(l, &ua, retval);
2824 }
2825 
2826 int
2827 netbsd32_pset_create(struct lwp *l,
2828     const struct netbsd32_pset_create_args *uap, register_t *retval)
2829 {
2830 	/* {
2831 		syscallarg(netbsd32_psetidp_t) psid;
2832 	}; */
2833 
2834 	return sys_pset_create(l, (const void *)uap, retval);
2835 }
2836 
2837 int
2838 netbsd32_pset_destroy(struct lwp *l,
2839      const struct netbsd32_pset_destroy_args *uap, register_t *retval)
2840 {
2841 	/* {
2842 		syscallarg(psetid_t) psid;
2843 	}; */
2844 
2845 	return sys_pset_destroy(l, (const void *)uap, retval);
2846 }
2847 
2848 int
2849 netbsd32_pset_assign(struct lwp *l,
2850      const struct netbsd32_pset_assign_args *uap, register_t *retval)
2851 {
2852 	/* {
2853 		syscallarg(psetid_t) psid;
2854 		syscallarg(cpuid_t) cpuid;
2855 		syscallarg(netbsd32_psetidp_t) opsid;
2856 	}; */
2857 	struct sys_pset_assign_args ua;
2858 
2859 	SCARG(&ua, psid) = SCARG(uap, psid);
2860 	NETBSD32TO64_UAP(cpuid);
2861 	NETBSD32TOP_UAP(opsid, psetid_t);
2862 
2863 	return sys_pset_assign(l, &ua, retval);
2864 }
2865 
2866 int
2867 netbsd32__pset_bind(struct lwp *l,
2868      const struct netbsd32__pset_bind_args *uap, register_t *retval)
2869 {
2870 	/* {
2871 		syscallarg(idtype_t) idtype;
2872 		syscallarg(id_t) first_id;
2873 		syscallarg(id_t) second_id;
2874 		syscallarg(psetid_t) psid;
2875 		syscallarg(netbsd32_psetidp_t) opsid;
2876 	}; */
2877 	struct sys__pset_bind_args ua;
2878 
2879 	SCARG(&ua, idtype) = SCARG(uap, idtype);
2880 	SCARG(&ua, first_id) = SCARG(uap, first_id);
2881 	SCARG(&ua, second_id) = SCARG(uap, second_id);
2882 	SCARG(&ua, psid) = SCARG(uap, psid);
2883 	NETBSD32TOP_UAP(opsid, psetid_t);
2884 
2885 	return sys__pset_bind(l, &ua, retval);
2886 }
2887 
2888 
2889 /*
2890  * MI indirect system call support.
2891  * Only used if the MD netbsd32_syscall.c doesn't intercept the calls.
2892  */
2893 
2894 #define NETBSD32_SYSCALL
2895 #undef SYS_NSYSENT
2896 #define SYS_NSYSENT NETBSD32_SYS_NSYSENT
2897 
2898 #define SYS_SYSCALL netbsd32_syscall
2899 #include "../../kern/sys_syscall.c"
2900 #undef SYS_SYSCALL
2901 
2902 #define SYS_SYSCALL netbsd32____syscall
2903 #include "../../kern/sys_syscall.c"
2904 #undef SYS_SYSCALL
2905