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