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