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