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