Home | History | Annotate | Line # | Download | only in netbsd32
netbsd32_vm.c revision 1.1.6.3
      1  1.1.6.3    martin /*	$NetBSD: netbsd32_vm.c,v 1.1.6.3 2020/04/08 14:08:01 martin Exp $	*/
      2  1.1.6.2  christos 
      3  1.1.6.2  christos /*
      4  1.1.6.2  christos  * Copyright (c) 1998, 2001, 2008, 2018 Matthew R. Green
      5  1.1.6.2  christos  * All rights reserved.
      6  1.1.6.2  christos  *
      7  1.1.6.2  christos  * Redistribution and use in source and binary forms, with or without
      8  1.1.6.2  christos  * modification, are permitted provided that the following conditions
      9  1.1.6.2  christos  * are met:
     10  1.1.6.2  christos  * 1. Redistributions of source code must retain the above copyright
     11  1.1.6.2  christos  *    notice, this list of conditions and the following disclaimer.
     12  1.1.6.2  christos  * 2. Redistributions in binary form must reproduce the above copyright
     13  1.1.6.2  christos  *    notice, this list of conditions and the following disclaimer in the
     14  1.1.6.2  christos  *    documentation and/or other materials provided with the distribution.
     15  1.1.6.2  christos  *
     16  1.1.6.2  christos  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     17  1.1.6.2  christos  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     18  1.1.6.2  christos  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     19  1.1.6.2  christos  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     20  1.1.6.2  christos  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
     21  1.1.6.2  christos  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
     22  1.1.6.2  christos  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
     23  1.1.6.2  christos  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
     24  1.1.6.2  christos  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     25  1.1.6.2  christos  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     26  1.1.6.2  christos  * SUCH DAMAGE.
     27  1.1.6.2  christos  *
     28  1.1.6.2  christos  * from: NetBSD: netbsd32_netbsd.c,v 1.221 2018/12/24 20:44:39 mrg Exp
     29  1.1.6.2  christos  */
     30  1.1.6.2  christos 
     31  1.1.6.2  christos #include <sys/cdefs.h>
     32  1.1.6.3    martin __KERNEL_RCSID(0, "$NetBSD: netbsd32_vm.c,v 1.1.6.3 2020/04/08 14:08:01 martin Exp $");
     33  1.1.6.2  christos 
     34  1.1.6.2  christos #include <sys/param.h>
     35  1.1.6.2  christos #include <sys/systm.h>
     36  1.1.6.2  christos #include <sys/mman.h>
     37  1.1.6.2  christos #include <sys/filedesc.h>
     38  1.1.6.2  christos #include <sys/vfs_syscalls.h>
     39  1.1.6.2  christos 
     40  1.1.6.2  christos #include <compat/sys/mman.h>
     41  1.1.6.2  christos #include <compat/netbsd32/netbsd32.h>
     42  1.1.6.2  christos #include <compat/netbsd32/netbsd32_syscall.h>
     43  1.1.6.2  christos #include <compat/netbsd32/netbsd32_syscallargs.h>
     44  1.1.6.2  christos #include <compat/netbsd32/netbsd32_conv.h>
     45  1.1.6.2  christos 
     46  1.1.6.2  christos 
     47  1.1.6.2  christos int
     48  1.1.6.2  christos netbsd32_mmap(struct lwp *l, const struct netbsd32_mmap_args *uap, register_t *retval)
     49  1.1.6.2  christos {
     50  1.1.6.2  christos 	/* {
     51  1.1.6.2  christos 		syscallarg(netbsd32_voidp) addr;
     52  1.1.6.2  christos 		syscallarg(netbsd32_size_t) len;
     53  1.1.6.2  christos 		syscallarg(int) prot;
     54  1.1.6.2  christos 		syscallarg(int) flags;
     55  1.1.6.2  christos 		syscallarg(int) fd;
     56  1.1.6.2  christos 		syscallarg(netbsd32_long) PAD;
     57  1.1.6.2  christos 		syscallarg(netbsd32_off_t) pos;
     58  1.1.6.2  christos 	} */
     59  1.1.6.2  christos 	struct sys_mmap_args ua;
     60  1.1.6.2  christos 	int error;
     61  1.1.6.2  christos 
     62  1.1.6.2  christos 	NETBSD32TOP_UAP(addr, void);
     63  1.1.6.2  christos 	NETBSD32TOX_UAP(len, size_t);
     64  1.1.6.2  christos 	NETBSD32TO64_UAP(prot);
     65  1.1.6.2  christos 	NETBSD32TO64_UAP(flags);
     66  1.1.6.2  christos #ifdef __x86_64__
     67  1.1.6.2  christos 	/*
     68  1.1.6.2  christos 	 * Ancient kernel on x86 did not obey PROT_EXEC on i386 at least
     69  1.1.6.2  christos 	 * and ld.so did not turn it on!
     70  1.1.6.2  christos 	 */
     71  1.1.6.2  christos 	if (SCARG(&ua, flags) & COMPAT_MAP_COPY) {
     72  1.1.6.2  christos 		SCARG(&ua, flags) = MAP_PRIVATE
     73  1.1.6.2  christos 		    | (SCARG(&ua, flags) & ~COMPAT_MAP_COPY);
     74  1.1.6.2  christos 		SCARG(&ua, prot) |= PROT_EXEC;
     75  1.1.6.2  christos 	}
     76  1.1.6.2  christos #endif
     77  1.1.6.2  christos 	NETBSD32TO64_UAP(fd);
     78  1.1.6.2  christos 	NETBSD32TOX_UAP(PAD, long);
     79  1.1.6.2  christos 	NETBSD32TOX_UAP(pos, off_t);
     80  1.1.6.2  christos #ifdef DEBUG_MMAP
     81  1.1.6.2  christos 	printf("mmap(addr=0x%lx, len=0x%lx, prot=0x%lx, flags=0x%lx, "
     82  1.1.6.2  christos 	    "fd=%ld, pos=0x%lx);\n",
     83  1.1.6.2  christos 	    (long)SCARG(&ua, addr), (long)SCARG(&ua, len),
     84  1.1.6.2  christos 	    (long)SCARG(&ua, prot), (long)SCARG(&ua, flags),
     85  1.1.6.2  christos 	    (long)SCARG(&ua, fd), (long)SCARG(&ua, pos));
     86  1.1.6.2  christos #endif
     87  1.1.6.2  christos 
     88  1.1.6.2  christos 	error = sys_mmap(l, &ua, retval);
     89  1.1.6.3    martin 	if (error == 0 && (u_long)*retval > (u_long)UINT_MAX) {
     90  1.1.6.3    martin 		const char *name = curlwp->l_name;
     91  1.1.6.3    martin 
     92  1.1.6.3    martin 		if (name == NULL)
     93  1.1.6.3    martin 			name = curproc->p_comm;
     94  1.1.6.3    martin 		printf("netbsd32_mmap(%s:%u:%u): retval out of range: 0x%lx\n",
     95  1.1.6.3    martin 		    name, curproc->p_pid, curlwp->l_lid, (u_long)*retval);
     96  1.1.6.2  christos 		/* Should try to recover and return an error here. */
     97  1.1.6.2  christos 	}
     98  1.1.6.2  christos 	return error;
     99  1.1.6.2  christos }
    100