Home | History | Annotate | Line # | Download | only in common
vm_43.c revision 1.15
      1 /*	$NetBSD: vm_43.c,v 1.15 2007/03/04 06:01:13 christos Exp $	*/
      2 
      3 /*
      4  * Copyright (c) 1991, 1993
      5  *	The Regents of the University of California.  All rights reserved.
      6  *
      7  * This code is derived from software contributed to Berkeley by
      8  * the Systems Programming Group of the University of Utah Computer
      9  * Science Department.
     10  *
     11  * Redistribution and use in source and binary forms, with or without
     12  * modification, are permitted provided that the following conditions
     13  * are met:
     14  * 1. Redistributions of source code must retain the above copyright
     15  *    notice, this list of conditions and the following disclaimer.
     16  * 2. Redistributions in binary form must reproduce the above copyright
     17  *    notice, this list of conditions and the following disclaimer in the
     18  *    documentation and/or other materials provided with the distribution.
     19  * 3. Neither the name of the University nor the names of its contributors
     20  *    may be used to endorse or promote products derived from this software
     21  *    without specific prior written permission.
     22  *
     23  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     24  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     25  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     26  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     27  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     28  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     29  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     30  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     31  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     32  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     33  * SUCH DAMAGE.
     34  *
     35  * from: Utah $Hdr: vm_mmap.c 1.6 91/10/21$
     36  *
     37  *	@(#)vm_mmap.c	8.5 (Berkeley) 5/19/94
     38  */
     39 
     40 /*
     41  * Copyright (c) 1988 University of Utah.
     42  *
     43  * This code is derived from software contributed to Berkeley by
     44  * the Systems Programming Group of the University of Utah Computer
     45  * Science Department.
     46  *
     47  * Redistribution and use in source and binary forms, with or without
     48  * modification, are permitted provided that the following conditions
     49  * are met:
     50  * 1. Redistributions of source code must retain the above copyright
     51  *    notice, this list of conditions and the following disclaimer.
     52  * 2. Redistributions in binary form must reproduce the above copyright
     53  *    notice, this list of conditions and the following disclaimer in the
     54  *    documentation and/or other materials provided with the distribution.
     55  * 3. All advertising materials mentioning features or use of this software
     56  *    must display the following acknowledgement:
     57  *	This product includes software developed by the University of
     58  *	California, Berkeley and its contributors.
     59  * 4. Neither the name of the University nor the names of its contributors
     60  *    may be used to endorse or promote products derived from this software
     61  *    without specific prior written permission.
     62  *
     63  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     64  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     65  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     66  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     67  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     68  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     69  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     70  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     71  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     72  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     73  * SUCH DAMAGE.
     74  *
     75  * from: Utah $Hdr: vm_mmap.c 1.6 91/10/21$
     76  *
     77  *	@(#)vm_mmap.c	8.5 (Berkeley) 5/19/94
     78  */
     79 
     80 /*
     81  * Mapped file (mmap) interface to VM
     82  */
     83 
     84 #include <sys/cdefs.h>
     85 __KERNEL_RCSID(0, "$NetBSD: vm_43.c,v 1.15 2007/03/04 06:01:13 christos Exp $");
     86 
     87 #include <sys/param.h>
     88 #include <sys/systm.h>
     89 #include <sys/filedesc.h>
     90 #include <sys/resourcevar.h>
     91 #include <sys/proc.h>
     92 #include <sys/vnode.h>
     93 #include <sys/file.h>
     94 #include <sys/mman.h>
     95 
     96 #include <sys/mount.h>
     97 #include <sys/syscallargs.h>
     98 
     99 #include <miscfs/specfs/specdev.h>
    100 
    101 /* ARGSUSED */
    102 int
    103 compat_43_sys_getpagesize(struct lwp *l, void *v,
    104     register_t *retval)
    105 {
    106 
    107 	*retval = PAGE_SIZE;
    108 	return (0);
    109 }
    110 
    111 int
    112 compat_43_sys_mmap(struct lwp *l, void *v, register_t *retval)
    113 {
    114 	struct compat_43_sys_mmap_args /* {
    115 		syscallarg(void *) addr;
    116 		syscallarg(size_t) len;
    117 		syscallarg(int) prot;
    118 		syscallarg(int) flags;
    119 		syscallarg(int) fd;
    120 		syscallarg(long) pos;
    121 	} */ *uap = v;
    122 	struct sys_mmap_args /* {
    123 		syscallarg(void *) addr;
    124 		syscallarg(size_t) len;
    125 		syscallarg(int) prot;
    126 		syscallarg(int) flags;
    127 		syscallarg(int) fd;
    128 		syscallarg(long) pad;
    129 		syscallarg(off_t) pos;
    130 	} */ nargs;
    131 	static const char cvtbsdprot[8] = {
    132 		0,
    133 		PROT_EXEC,
    134 		PROT_WRITE,
    135 		PROT_EXEC|PROT_WRITE,
    136 		PROT_READ,
    137 		PROT_EXEC|PROT_READ,
    138 		PROT_WRITE|PROT_READ,
    139 		PROT_EXEC|PROT_WRITE|PROT_READ,
    140 	};
    141 #define	OMAP_ANON	0x0002
    142 #define	OMAP_COPY	0x0020
    143 #define	OMAP_SHARED	0x0010
    144 #define	OMAP_FIXED	0x0100
    145 #define	OMAP_INHERIT	0x0800
    146 
    147 	SCARG(&nargs, addr) = SCARG(uap, addr);
    148 	SCARG(&nargs, len) = SCARG(uap, len);
    149 	/* Note: index using prot is sign-safe due to mask */
    150 	SCARG(&nargs, prot) = cvtbsdprot[SCARG(uap, prot)&0x7];
    151 	SCARG(&nargs, flags) = 0;
    152 	if (SCARG(uap, flags) & OMAP_ANON)
    153 		SCARG(&nargs, flags) |= MAP_ANON;
    154 	if (SCARG(uap, flags) & OMAP_COPY)
    155 		SCARG(&nargs, flags) |= MAP_COPY;
    156 	if (SCARG(uap, flags) & OMAP_SHARED)
    157 		SCARG(&nargs, flags) |= MAP_SHARED;
    158 	else
    159 		SCARG(&nargs, flags) |= MAP_PRIVATE;
    160 	if (SCARG(uap, flags) & OMAP_FIXED)
    161 		SCARG(&nargs, flags) |= MAP_FIXED;
    162 	if (SCARG(uap, flags) & OMAP_INHERIT)
    163 		SCARG(&nargs, flags) |= MAP_INHERIT;
    164 	SCARG(&nargs, fd) = SCARG(uap, fd);
    165 	SCARG(&nargs, pos) = SCARG(uap, pos);
    166 	return (sys_mmap(l, &nargs, retval));
    167 }
    168