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