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