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