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