Module Name: src Committed By: mrg Date: Mon Dec 24 21:27:06 UTC 2018
Modified Files: src/sys/compat/netbsd32: files.netbsd32 netbsd32_netbsd.c netbsd32_syscalls.c netbsd32_syscalls_autoload.c netbsd32_sysent.c netbsd32_systrace_args.c syscalls.master Added Files: src/sys/compat/netbsd32: netbsd32_compat_40.c netbsd32_fd.c netbsd32_vm.c Log Message: move mmap(), compat 40 mount(), pipe() and getfh() into their own files as the implementation is non trivial or is compat. mark old mount() properly instead of manually #if'ing ito to ENOSYS. To generate a diff of this commit: cvs rdiff -u -r1.40 -r1.41 src/sys/compat/netbsd32/files.netbsd32 cvs rdiff -u -r0 -r1.2 src/sys/compat/netbsd32/netbsd32_compat_40.c cvs rdiff -u -r0 -r1.1 src/sys/compat/netbsd32/netbsd32_fd.c \ src/sys/compat/netbsd32/netbsd32_vm.c cvs rdiff -u -r1.221 -r1.222 src/sys/compat/netbsd32/netbsd32_netbsd.c cvs rdiff -u -r1.136 -r1.137 src/sys/compat/netbsd32/netbsd32_syscalls.c cvs rdiff -u -r1.16 -r1.17 \ src/sys/compat/netbsd32/netbsd32_syscalls_autoload.c cvs rdiff -u -r1.135 -r1.136 src/sys/compat/netbsd32/netbsd32_sysent.c cvs rdiff -u -r1.27 -r1.28 src/sys/compat/netbsd32/netbsd32_systrace_args.c cvs rdiff -u -r1.123 -r1.124 src/sys/compat/netbsd32/syscalls.master Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/sys/compat/netbsd32/files.netbsd32 diff -u src/sys/compat/netbsd32/files.netbsd32:1.40 src/sys/compat/netbsd32/files.netbsd32:1.41 --- src/sys/compat/netbsd32/files.netbsd32:1.40 Mon Dec 24 20:44:39 2018 +++ src/sys/compat/netbsd32/files.netbsd32 Mon Dec 24 21:27:05 2018 @@ -1,4 +1,4 @@ -# $NetBSD: files.netbsd32,v 1.40 2018/12/24 20:44:39 mrg Exp $ +# $NetBSD: files.netbsd32,v 1.41 2018/12/24 21:27:05 mrg Exp $ # # config file description for machine-independent netbsd32 compat code. # included by ports that need it. @@ -13,6 +13,7 @@ file compat/netbsd32/netbsd32_exec_aout. file compat/netbsd32/netbsd32_netbsd.c compat_netbsd32 file compat/netbsd32/netbsd32_event.c compat_netbsd32 file compat/netbsd32/netbsd32_execve.c compat_netbsd32 +file compat/netbsd32/netbsd32_fd.c compat_netbsd32 file compat/netbsd32/netbsd32_fs.c compat_netbsd32 file compat/netbsd32/netbsd32_ioctl.c compat_netbsd32 file compat/netbsd32/netbsd32_ipc.c compat_netbsd32 @@ -31,6 +32,7 @@ file compat/netbsd32/netbsd32_socket.c c file compat/netbsd32/netbsd32_sysctl.c compat_netbsd32 file compat/netbsd32/netbsd32_time.c compat_netbsd32 file compat/netbsd32/netbsd32_wait.c compat_netbsd32 +file compat/netbsd32/netbsd32_vm.c compat_netbsd32 file compat/netbsd32/netbsd32_sysent.c compat_netbsd32 file compat/netbsd32/netbsd32_syscalls.c compat_netbsd32 & syscall_debug @@ -42,6 +44,7 @@ file compat/netbsd32/netbsd32_compat_14. file compat/netbsd32/netbsd32_compat_20.c compat_netbsd32 & compat_20 file compat/netbsd32/netbsd32_compat_30.c compat_netbsd32 & compat_30 file compat/netbsd32/netbsd32_compat_43.c compat_netbsd32 & (compat_43 | compat_sunos | compat_linux32) +file compat/netbsd32/netbsd32_compat_40.c compat_netbsd32 & compat_40 file compat/netbsd32/netbsd32_compat_50.c compat_netbsd32 & compat_50 file compat/netbsd32/netbsd32_compat_50_sysv.c compat_netbsd32 & compat_50 & (sysvmsg | sysvsem | sysvshm) Index: src/sys/compat/netbsd32/netbsd32_netbsd.c diff -u src/sys/compat/netbsd32/netbsd32_netbsd.c:1.221 src/sys/compat/netbsd32/netbsd32_netbsd.c:1.222 --- src/sys/compat/netbsd32/netbsd32_netbsd.c:1.221 Mon Dec 24 20:44:39 2018 +++ src/sys/compat/netbsd32/netbsd32_netbsd.c Mon Dec 24 21:27:05 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: netbsd32_netbsd.c,v 1.221 2018/12/24 20:44:39 mrg Exp $ */ +/* $NetBSD: netbsd32_netbsd.c,v 1.222 2018/12/24 21:27:05 mrg Exp $ */ /* * Copyright (c) 1998, 2001, 2008, 2018 Matthew R. Green @@ -27,15 +27,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: netbsd32_netbsd.c,v 1.221 2018/12/24 20:44:39 mrg Exp $"); - -/* - * below are all the standard NetBSD system calls, in the 32bit - * environment, with the necessary conversions to 64bit before calling - * the real syscall. anything that needs special attention is handled - * elsewhere - this file should only contain structure assignment and - * calls to the original function. - */ +__KERNEL_RCSID(0, "$NetBSD: netbsd32_netbsd.c,v 1.222 2018/12/24 21:27:05 mrg Exp $"); /* * below are all the standard NetBSD system calls, in the 32bit @@ -73,13 +65,11 @@ __KERNEL_RCSID(0, "$NetBSD: netbsd32_net #include <sys/trace.h> #include <sys/resourcevar.h> #include <sys/pool.h> -#include <sys/vnode.h> #include <sys/file.h> #include <sys/filedesc.h> #include <sys/namei.h> #include <sys/dirent.h> #include <sys/quotactl.h> -#include <sys/kauth.h> #include <sys/vfs_syscalls.h> #include <uvm/uvm_extern.h> @@ -365,30 +355,6 @@ netbsd32_break(struct lwp *l, const stru return sys_obreak(l, &ua, retval); } -// XXX move into compat_40 -int -netbsd32_mount(struct lwp *l, const struct netbsd32_mount_args *uap, register_t *retval) -{ -#ifdef COMPAT_40 - /* { - syscallarg(const netbsd32_charp) type; - syscallarg(const netbsd32_charp) path; - syscallarg(int) flags; - syscallarg(netbsd32_voidp) data; - } */ - struct compat_40_sys_mount_args ua; - - NETBSD32TOP_UAP(type, const char); - NETBSD32TOP_UAP(path, const char); - NETBSD32TO64_UAP(flags); - NETBSD32TOP_UAP(data, void); - - return compat_40_sys_mount(l, &ua, retval); -#else - return ENOSYS; -#endif -} - int netbsd32_unmount(struct lwp *l, const struct netbsd32_unmount_args *uap, register_t *retval) { @@ -1214,71 +1180,6 @@ netbsd32_rmdir(struct lwp *l, const stru return sys_rmdir(l, &ua, retval); } -// XXX new file -int -netbsd32___getfh30(struct lwp *l, const struct netbsd32___getfh30_args *uap, register_t *retval) -{ - /* { - syscallarg(const netbsd32_charp) fname; - syscallarg(netbsd32_fhandlep_t) fhp; - syscallarg(netbsd32_size_tp) fh_size; - } */ - struct vnode *vp; - fhandle_t *fh; - int error; - struct pathbuf *pb; - struct nameidata nd; - netbsd32_size_t usz32, sz32; - size_t sz; - - /* - * Must be super user - */ - error = kauth_authorize_system(l->l_cred, KAUTH_SYSTEM_FILEHANDLE, - 0, NULL, NULL, NULL); - if (error) - return error; - - error = pathbuf_copyin(SCARG_P32(uap, fname), &pb); - if (error) { - return error; - } - - NDINIT(&nd, LOOKUP, FOLLOW | LOCKLEAF | TRYEMULROOT, pb); - error = namei(&nd); - if (error) { - pathbuf_destroy(pb); - return error; - } - vp = nd.ni_vp; - pathbuf_destroy(pb); - - error = vfs_composefh_alloc(vp, &fh); - vput(vp); - if (error != 0) { - return error; - } - error = copyin(SCARG_P32(uap, fh_size), &usz32, sizeof(usz32)); - if (error != 0) { - goto out; - } - sz = FHANDLE_SIZE(fh); - sz32 = sz; - - error = copyout(&sz32, SCARG_P32(uap, fh_size), sizeof(sz32)); - if (error != 0) { - goto out; - } - if (usz32 >= sz32) { - error = copyout(fh, SCARG_P32(uap, fhp), sz); - } else { - error = E2BIG; - } -out: - vfs_composefh_free(fh); - return error; -} - int netbsd32_pread(struct lwp *l, const struct netbsd32_pread_args *uap, register_t *retval) { @@ -1390,57 +1291,6 @@ netbsd32_fpathconf(struct lwp *l, const return sys_fpathconf(l, &ua, retval); } -// XXX new file -int -netbsd32_mmap(struct lwp *l, const struct netbsd32_mmap_args *uap, register_t *retval) -{ - /* { - syscallarg(netbsd32_voidp) addr; - syscallarg(netbsd32_size_t) len; - syscallarg(int) prot; - syscallarg(int) flags; - syscallarg(int) fd; - syscallarg(netbsd32_long) PAD; - syscallarg(netbsd32_off_t) pos; - } */ - struct sys_mmap_args ua; - int error; - - NETBSD32TOP_UAP(addr, void); - NETBSD32TOX_UAP(len, size_t); - NETBSD32TO64_UAP(prot); - NETBSD32TO64_UAP(flags); -#ifdef __x86_64__ - /* - * Ancient kernel on x86 did not obey PROT_EXEC on i386 at least - * and ld.so did not turn it on! - */ - if (SCARG(&ua, flags) & COMPAT_MAP_COPY) { - SCARG(&ua, flags) = MAP_PRIVATE - | (SCARG(&ua, flags) & ~COMPAT_MAP_COPY); - SCARG(&ua, prot) |= PROT_EXEC; - } -#endif - NETBSD32TO64_UAP(fd); - NETBSD32TOX_UAP(PAD, long); - NETBSD32TOX_UAP(pos, off_t); -#ifdef DEBUG_MMAP - printf("mmap(addr=0x%lx, len=0x%lx, prot=0x%lx, flags=0x%lx, " - "fd=%ld, pos=0x%lx);\n", - (long)SCARG(&ua, addr), (long)SCARG(&ua, len), - (long)SCARG(&ua, prot), (long)SCARG(&ua, flags), - (long)SCARG(&ua, fd), (long)SCARG(&ua, pos)); -#endif - - error = sys_mmap(l, &ua, retval); - if ((u_long)*retval > (u_long)UINT_MAX) { - printf("netbsd32_mmap: retval out of range: 0x%lx\n", - (u_long)*retval); - /* Should try to recover and return an error here. */ - } - return error; -} - int netbsd32_mremap(struct lwp *l, const struct netbsd32_mremap_args *uap, register_t *retval) { @@ -2596,29 +2446,6 @@ netbsd32__sched_protect(struct lwp *l, return sys__sched_protect(l, &ua, retval); } -// XXX new file -int -netbsd32_pipe2(struct lwp *l, const struct netbsd32_pipe2_args *uap, - register_t *retval) -{ - /* { - syscallarg(netbsd32_intp) fildes; - syscallarg(int) flags; - } */ - int fd[2], error; - - error = pipe1(l, fd, SCARG(uap, flags)); - if (error != 0) - return error; - - error = copyout(fd, SCARG_P32(uap, fildes), sizeof(fd)); - if (error != 0) - return error; - - retval[0] = 0; - return 0; -} - int netbsd32_dup3(struct lwp *l, const struct netbsd32_dup3_args *uap, register_t *retval) Index: src/sys/compat/netbsd32/netbsd32_syscalls.c diff -u src/sys/compat/netbsd32/netbsd32_syscalls.c:1.136 src/sys/compat/netbsd32/netbsd32_syscalls.c:1.137 --- src/sys/compat/netbsd32/netbsd32_syscalls.c:1.136 Fri Aug 10 21:47:15 2018 +++ src/sys/compat/netbsd32/netbsd32_syscalls.c Mon Dec 24 21:27:06 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: netbsd32_syscalls.c,v 1.136 2018/08/10 21:47:15 pgoyette Exp $ */ +/* $NetBSD: netbsd32_syscalls.c,v 1.137 2018/12/24 21:27:06 mrg Exp $ */ /* * System call names. @@ -8,7 +8,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: netbsd32_syscalls.c,v 1.136 2018/08/10 21:47:15 pgoyette Exp $"); +__KERNEL_RCSID(0, "$NetBSD: netbsd32_syscalls.c,v 1.137 2018/12/24 21:27:06 mrg Exp $"); #if defined(_KERNEL_OPT) #if defined(_KERNEL_OPT) @@ -49,7 +49,7 @@ const char *const netbsd32_syscallnames[ /* 18 */ "compat_20_netbsd32_getfsstat", /* 19 */ "compat_43_netbsd32_olseek", /* 20 */ "getpid", - /* 21 */ "netbsd32_mount", + /* 21 */ "compat_40_netbsd32_mount", /* 22 */ "netbsd32_unmount", /* 23 */ "netbsd32_setuid", /* 24 */ "getuid", @@ -579,7 +579,7 @@ const char *const altnetbsd32_syscallnam /* 18 */ NULL, /* compat_20_netbsd32_getfsstat */ /* 19 */ NULL, /* compat_43_netbsd32_olseek */ /* 20 */ NULL, /* getpid */ - /* 21 */ "mount", + /* 21 */ NULL, /* compat_40_netbsd32_mount */ /* 22 */ "unmount", /* 23 */ "setuid", /* 24 */ NULL, /* getuid */ Index: src/sys/compat/netbsd32/netbsd32_syscalls_autoload.c diff -u src/sys/compat/netbsd32/netbsd32_syscalls_autoload.c:1.16 src/sys/compat/netbsd32/netbsd32_syscalls_autoload.c:1.17 --- src/sys/compat/netbsd32/netbsd32_syscalls_autoload.c:1.16 Fri Aug 10 21:47:15 2018 +++ src/sys/compat/netbsd32/netbsd32_syscalls_autoload.c Mon Dec 24 21:27:06 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: netbsd32_syscalls_autoload.c,v 1.16 2018/08/10 21:47:15 pgoyette Exp $ */ +/* $NetBSD: netbsd32_syscalls_autoload.c,v 1.17 2018/12/24 21:27:06 mrg Exp $ */ /* * System call autoload table. @@ -8,7 +8,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: netbsd32_syscalls_autoload.c,v 1.16 2018/08/10 21:47:15 pgoyette Exp $"); +__KERNEL_RCSID(0, "$NetBSD: netbsd32_syscalls_autoload.c,v 1.17 2018/12/24 21:27:06 mrg Exp $"); #include <sys/proc.h> static struct sc_autoload netbsd32_syscalls_autoload[] = { Index: src/sys/compat/netbsd32/netbsd32_sysent.c diff -u src/sys/compat/netbsd32/netbsd32_sysent.c:1.135 src/sys/compat/netbsd32/netbsd32_sysent.c:1.136 --- src/sys/compat/netbsd32/netbsd32_sysent.c:1.135 Fri Aug 10 21:47:15 2018 +++ src/sys/compat/netbsd32/netbsd32_sysent.c Mon Dec 24 21:27:06 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: netbsd32_sysent.c,v 1.135 2018/08/10 21:47:15 pgoyette Exp $ */ +/* $NetBSD: netbsd32_sysent.c,v 1.136 2018/12/24 21:27:06 mrg Exp $ */ /* * System call switch table. @@ -8,7 +8,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: netbsd32_sysent.c,v 1.135 2018/08/10 21:47:15 pgoyette Exp $"); +__KERNEL_RCSID(0, "$NetBSD: netbsd32_sysent.c,v 1.136 2018/12/24 21:27:06 mrg Exp $"); #if defined(_KERNEL_OPT) #include "opt_compat_netbsd.h" @@ -201,9 +201,9 @@ struct sysent netbsd32_sysent[] = { .sy_call = (sy_call_t *)sys_getpid }, /* 20 = getpid */ { - ns(struct netbsd32_mount_args), - .sy_call = (sy_call_t *)netbsd32_mount - }, /* 21 = netbsd32_mount */ + ns(struct compat_40_netbsd32_mount_args), + .sy_call = (sy_call_t *)compat_40(netbsd32_mount) + }, /* 21 = compat_40_netbsd32_mount */ { ns(struct netbsd32_unmount_args), .sy_call = (sy_call_t *)netbsd32_unmount Index: src/sys/compat/netbsd32/netbsd32_systrace_args.c diff -u src/sys/compat/netbsd32/netbsd32_systrace_args.c:1.27 src/sys/compat/netbsd32/netbsd32_systrace_args.c:1.28 --- src/sys/compat/netbsd32/netbsd32_systrace_args.c:1.27 Fri Aug 10 21:47:15 2018 +++ src/sys/compat/netbsd32/netbsd32_systrace_args.c Mon Dec 24 21:27:06 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: netbsd32_systrace_args.c,v 1.27 2018/08/10 21:47:15 pgoyette Exp $ */ +/* $NetBSD: netbsd32_systrace_args.c,v 1.28 2018/12/24 21:27:06 mrg Exp $ */ /* * System call argument to DTrace register array converstion. @@ -171,7 +171,7 @@ systrace_args(register_t sysnum, const v } /* netbsd32_mount */ case 21: { - const struct netbsd32_mount_args *p = params; + const struct compat_40_netbsd32_mount_args *p = params; uarg[0] = (intptr_t) SCARG(p, type).i32; /* netbsd32_charp */ uarg[1] = (intptr_t) SCARG(p, path).i32; /* netbsd32_charp */ iarg[2] = SCARG(p, flags); /* int */ Index: src/sys/compat/netbsd32/syscalls.master diff -u src/sys/compat/netbsd32/syscalls.master:1.123 src/sys/compat/netbsd32/syscalls.master:1.124 --- src/sys/compat/netbsd32/syscalls.master:1.123 Tue Jul 31 21:00:02 2018 +++ src/sys/compat/netbsd32/syscalls.master Mon Dec 24 21:27:06 2018 @@ -1,4 +1,4 @@ - $NetBSD: syscalls.master,v 1.123 2018/07/31 21:00:02 rjs Exp $ + $NetBSD: syscalls.master,v 1.124 2018/12/24 21:27:06 mrg Exp $ ; from: NetBSD: syscalls.master,v 1.81 1998/07/05 08:49:50 jonathan Exp ; @(#)syscalls.master 8.2 (Berkeley) 1/13/94 @@ -91,7 +91,7 @@ 19 COMPAT_43 { netbsd32_long|netbsd32||olseek(int fd, \ netbsd32_long offset, int whence); } 20 NOARGS { pid_t|sys||getpid(void); } -21 STD { int|netbsd32||mount(netbsd32_charp type, \ +21 COMPAT_40 { int|netbsd32||mount(netbsd32_charp type, \ netbsd32_charp path, int flags, \ netbsd32_voidp data); } 22 STD { int|netbsd32||unmount(netbsd32_charp path, \ Added files: Index: src/sys/compat/netbsd32/netbsd32_compat_40.c diff -u /dev/null src/sys/compat/netbsd32/netbsd32_compat_40.c:1.2 --- /dev/null Mon Dec 24 21:27:06 2018 +++ src/sys/compat/netbsd32/netbsd32_compat_40.c Mon Dec 24 21:27:05 2018 @@ -0,0 +1,63 @@ +/* $NetBSD: netbsd32_compat_40.c,v 1.2 2018/12/24 21:27:05 mrg Exp $ */ + +/* + * Copyright (c) 1998, 2001, 2008, 2018 Matthew R. Green + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * from: NetBSD: netbsd32_netbsd.c,v 1.221 2018/12/24 20:44:39 mrg Exp $ + */ + +#include <sys/cdefs.h> +__KERNEL_RCSID(0, "$NetBSD: netbsd32_compat_40.c,v 1.2 2018/12/24 21:27:05 mrg Exp $"); + +#include <sys/param.h> +#include <sys/systm.h> +#include <sys/mount.h> +#include <sys/syscallargs.h> + +#include <compat/netbsd32/netbsd32.h> +#include <compat/netbsd32/netbsd32_syscall.h> +#include <compat/netbsd32/netbsd32_syscallargs.h> +#include <compat/netbsd32/netbsd32_conv.h> + +int +compat_40_netbsd32_mount(struct lwp *l, + const struct compat_40_netbsd32_mount_args *uap, + register_t *retval) +{ + /* { + syscallarg(const netbsd32_charp) type; + syscallarg(const netbsd32_charp) path; + syscallarg(int) flags; + syscallarg(netbsd32_voidp) data; + } */ + struct compat_40_sys_mount_args ua; + + NETBSD32TOP_UAP(type, const char); + NETBSD32TOP_UAP(path, const char); + NETBSD32TO64_UAP(flags); + NETBSD32TOP_UAP(data, void); + + return compat_40_sys_mount(l, &ua, retval); +} Index: src/sys/compat/netbsd32/netbsd32_fd.c diff -u /dev/null src/sys/compat/netbsd32/netbsd32_fd.c:1.1 --- /dev/null Mon Dec 24 21:27:06 2018 +++ src/sys/compat/netbsd32/netbsd32_fd.c Mon Dec 24 21:27:05 2018 @@ -0,0 +1,132 @@ +/* $NetBSD: netbsd32_fd.c,v 1.1 2018/12/24 21:27:05 mrg Exp $ */ + +/* + * Copyright (c) 1998, 2001, 2008, 2018 Matthew R. Green + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * from: NetBSD: netbsd32_netbsd.c,v 1.221 2018/12/24 20:44:39 mrg Exp + */ + +#include <sys/cdefs.h> +__KERNEL_RCSID(0, "$NetBSD: netbsd32_fd.c,v 1.1 2018/12/24 21:27:05 mrg Exp $"); + +#include <sys/param.h> +#include <sys/systm.h> +#include <sys/filedesc.h> +#include <sys/namei.h> +#include <sys/vnode.h> +#include <sys/vfs_syscalls.h> +#include <sys/kauth.h> + +#include <compat/netbsd32/netbsd32.h> +#include <compat/netbsd32/netbsd32_syscall.h> +#include <compat/netbsd32/netbsd32_syscallargs.h> +#include <compat/netbsd32/netbsd32_conv.h> + + +int +netbsd32___getfh30(struct lwp *l, const struct netbsd32___getfh30_args *uap, register_t *retval) +{ + /* { + syscallarg(const netbsd32_charp) fname; + syscallarg(netbsd32_fhandlep_t) fhp; + syscallarg(netbsd32_size_tp) fh_size; + } */ + struct vnode *vp; + fhandle_t *fh; + int error; + struct pathbuf *pb; + struct nameidata nd; + netbsd32_size_t usz32, sz32; + size_t sz; + + /* + * Must be super user + */ + error = kauth_authorize_system(l->l_cred, KAUTH_SYSTEM_FILEHANDLE, + 0, NULL, NULL, NULL); + if (error) + return error; + + error = pathbuf_copyin(SCARG_P32(uap, fname), &pb); + if (error) { + return error; + } + + NDINIT(&nd, LOOKUP, FOLLOW | LOCKLEAF | TRYEMULROOT, pb); + error = namei(&nd); + if (error) { + pathbuf_destroy(pb); + return error; + } + vp = nd.ni_vp; + pathbuf_destroy(pb); + + error = vfs_composefh_alloc(vp, &fh); + vput(vp); + if (error != 0) { + return error; + } + error = copyin(SCARG_P32(uap, fh_size), &usz32, sizeof(usz32)); + if (error != 0) { + goto out; + } + sz = FHANDLE_SIZE(fh); + sz32 = sz; + + error = copyout(&sz32, SCARG_P32(uap, fh_size), sizeof(sz32)); + if (error != 0) { + goto out; + } + if (usz32 >= sz32) { + error = copyout(fh, SCARG_P32(uap, fhp), sz); + } else { + error = E2BIG; + } +out: + vfs_composefh_free(fh); + return error; +} + +int +netbsd32_pipe2(struct lwp *l, const struct netbsd32_pipe2_args *uap, + register_t *retval) +{ + /* { + syscallarg(netbsd32_intp) fildes; + syscallarg(int) flags; + } */ + int fd[2], error; + + error = pipe1(l, fd, SCARG(uap, flags)); + if (error != 0) + return error; + + error = copyout(fd, SCARG_P32(uap, fildes), sizeof(fd)); + if (error != 0) + return error; + + retval[0] = 0; + return 0; +} Index: src/sys/compat/netbsd32/netbsd32_vm.c diff -u /dev/null src/sys/compat/netbsd32/netbsd32_vm.c:1.1 --- /dev/null Mon Dec 24 21:27:06 2018 +++ src/sys/compat/netbsd32/netbsd32_vm.c Mon Dec 24 21:27:06 2018 @@ -0,0 +1,95 @@ +/* $NetBSD: netbsd32_vm.c,v 1.1 2018/12/24 21:27:06 mrg Exp $ */ + +/* + * Copyright (c) 1998, 2001, 2008, 2018 Matthew R. Green + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * from: NetBSD: netbsd32_netbsd.c,v 1.221 2018/12/24 20:44:39 mrg Exp + */ + +#include <sys/cdefs.h> +__KERNEL_RCSID(0, "$NetBSD: netbsd32_vm.c,v 1.1 2018/12/24 21:27:06 mrg Exp $"); + +#include <sys/param.h> +#include <sys/systm.h> +#include <sys/mman.h> +#include <sys/filedesc.h> +#include <sys/vfs_syscalls.h> + +#include <compat/sys/mman.h> +#include <compat/netbsd32/netbsd32.h> +#include <compat/netbsd32/netbsd32_syscall.h> +#include <compat/netbsd32/netbsd32_syscallargs.h> +#include <compat/netbsd32/netbsd32_conv.h> + + +int +netbsd32_mmap(struct lwp *l, const struct netbsd32_mmap_args *uap, register_t *retval) +{ + /* { + syscallarg(netbsd32_voidp) addr; + syscallarg(netbsd32_size_t) len; + syscallarg(int) prot; + syscallarg(int) flags; + syscallarg(int) fd; + syscallarg(netbsd32_long) PAD; + syscallarg(netbsd32_off_t) pos; + } */ + struct sys_mmap_args ua; + int error; + + NETBSD32TOP_UAP(addr, void); + NETBSD32TOX_UAP(len, size_t); + NETBSD32TO64_UAP(prot); + NETBSD32TO64_UAP(flags); +#ifdef __x86_64__ + /* + * Ancient kernel on x86 did not obey PROT_EXEC on i386 at least + * and ld.so did not turn it on! + */ + if (SCARG(&ua, flags) & COMPAT_MAP_COPY) { + SCARG(&ua, flags) = MAP_PRIVATE + | (SCARG(&ua, flags) & ~COMPAT_MAP_COPY); + SCARG(&ua, prot) |= PROT_EXEC; + } +#endif + NETBSD32TO64_UAP(fd); + NETBSD32TOX_UAP(PAD, long); + NETBSD32TOX_UAP(pos, off_t); +#ifdef DEBUG_MMAP + printf("mmap(addr=0x%lx, len=0x%lx, prot=0x%lx, flags=0x%lx, " + "fd=%ld, pos=0x%lx);\n", + (long)SCARG(&ua, addr), (long)SCARG(&ua, len), + (long)SCARG(&ua, prot), (long)SCARG(&ua, flags), + (long)SCARG(&ua, fd), (long)SCARG(&ua, pos)); +#endif + + error = sys_mmap(l, &ua, retval); + if ((u_long)*retval > (u_long)UINT_MAX) { + printf("netbsd32_mmap: retval out of range: 0x%lx\n", + (u_long)*retval); + /* Should try to recover and return an error here. */ + } + return error; +}