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