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