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