vm_43.c revision 1.9 1 1.9 agc /* $NetBSD: vm_43.c,v 1.9 2003/08/07 16:30:37 agc 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.9 agc * 3. Neither the name of the University nor the names of its contributors
20 1.9 agc * may be used to endorse or promote products derived from this software
21 1.9 agc * without specific prior written permission.
22 1.9 agc *
23 1.9 agc * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24 1.9 agc * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 1.9 agc * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 1.9 agc * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27 1.9 agc * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 1.9 agc * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 1.9 agc * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 1.9 agc * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 1.9 agc * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 1.9 agc * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 1.9 agc * SUCH DAMAGE.
34 1.9 agc *
35 1.9 agc * from: Utah $Hdr: vm_mmap.c 1.6 91/10/21$
36 1.9 agc *
37 1.9 agc * @(#)vm_mmap.c 8.5 (Berkeley) 5/19/94
38 1.9 agc */
39 1.9 agc
40 1.9 agc /*
41 1.9 agc * Copyright (c) 1988 University of Utah.
42 1.9 agc *
43 1.9 agc * This code is derived from software contributed to Berkeley by
44 1.9 agc * the Systems Programming Group of the University of Utah Computer
45 1.9 agc * Science Department.
46 1.9 agc *
47 1.9 agc * Redistribution and use in source and binary forms, with or without
48 1.9 agc * modification, are permitted provided that the following conditions
49 1.9 agc * are met:
50 1.9 agc * 1. Redistributions of source code must retain the above copyright
51 1.9 agc * notice, this list of conditions and the following disclaimer.
52 1.9 agc * 2. Redistributions in binary form must reproduce the above copyright
53 1.9 agc * notice, this list of conditions and the following disclaimer in the
54 1.9 agc * 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.9 agc __KERNEL_RCSID(0, "$NetBSD: vm_43.c,v 1.9 2003/08/07 16:30:37 agc 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