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