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