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