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