Commit | Line | Data |
---|---|---|
15637ed4 RG |
1 | /* |
2 | * Copyright (c) 1991 Regents of the University of California. | |
3 | * All rights reserved. | |
4 | * | |
5 | * This code is derived from software contributed to Berkeley by | |
6 | * The Mach Operating System project at Carnegie-Mellon University. | |
7 | * | |
8 | * Redistribution and use in source and binary forms, with or without | |
9 | * modification, are permitted provided that the following conditions | |
10 | * are met: | |
11 | * 1. Redistributions of source code must retain the above copyright | |
12 | * notice, this list of conditions and the following disclaimer. | |
13 | * 2. Redistributions in binary form must reproduce the above copyright | |
14 | * notice, this list of conditions and the following disclaimer in the | |
15 | * documentation and/or other materials provided with the distribution. | |
16 | * 3. All advertising materials mentioning features or use of this software | |
17 | * must display the following acknowledgement: | |
18 | * This product includes software developed by the University of | |
19 | * California, Berkeley and its contributors. | |
20 | * 4. Neither the name of the University nor the names of its contributors | |
21 | * may be used to endorse or promote products derived from this software | |
22 | * without specific prior written permission. | |
23 | * | |
24 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND | |
25 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
26 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
27 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | |
28 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
29 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |
30 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
31 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
32 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
33 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
34 | * SUCH DAMAGE. | |
35 | * | |
1284e777 RG |
36 | * from: @(#)vm_user.c 7.3 (Berkeley) 4/21/91 |
37 | * $Id$ | |
38 | */ | |
39 | ||
40 | /* | |
15637ed4 RG |
41 | * Copyright (c) 1987, 1990 Carnegie-Mellon University. |
42 | * All rights reserved. | |
43 | * | |
44 | * Authors: Avadis Tevanian, Jr., Michael Wayne Young | |
45 | * | |
46 | * Permission to use, copy, modify and distribute this software and | |
47 | * its documentation is hereby granted, provided that both the copyright | |
48 | * notice and this permission notice appear in all copies of the | |
49 | * software, derivative works or modified versions, and any portions | |
50 | * thereof, and that both notices appear in supporting documentation. | |
51 | * | |
52 | * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" | |
53 | * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND | |
54 | * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. | |
55 | * | |
56 | * Carnegie Mellon requests users of this software to return to | |
57 | * | |
58 | * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU | |
59 | * School of Computer Science | |
60 | * Carnegie Mellon University | |
61 | * Pittsburgh PA 15213-3890 | |
62 | * | |
63 | * any improvements or extensions that they make and grant Carnegie the | |
64 | * rights to redistribute these changes. | |
65 | */ | |
66 | ||
67 | /* | |
68 | * User-exported virtual memory functions. | |
69 | */ | |
70 | ||
71 | #include "param.h" | |
72 | #include "systm.h" | |
73 | #include "proc.h" | |
74 | ||
75 | #include "vm.h" | |
76 | #include "vm_page.h" | |
77 | ||
78 | simple_lock_data_t vm_alloc_lock; /* XXX */ | |
79 | ||
80 | #ifdef MACHVMCOMPAT | |
81 | /* | |
82 | * BSD style syscall interfaces to MACH calls | |
83 | * All return MACH return values. | |
84 | */ | |
3c7eb27c DG |
85 | |
86 | struct svm_allocate_args { | |
87 | vm_map_t map; | |
88 | vm_offset_t *addr; | |
89 | vm_size_t size; | |
90 | boolean_t anywhere; | |
91 | }; | |
92 | ||
15637ed4 RG |
93 | /* ARGSUSED */ |
94 | svm_allocate(p, uap, retval) | |
95 | struct proc *p; | |
3c7eb27c | 96 | struct svm_allocate_args *uap; |
15637ed4 RG |
97 | int *retval; |
98 | { | |
99 | vm_offset_t addr; | |
100 | int rv; | |
101 | ||
102 | uap->map = p->p_map; /* XXX */ | |
103 | ||
104 | if (copyin((caddr_t)uap->addr, (caddr_t)&addr, sizeof (addr))) | |
105 | rv = KERN_INVALID_ARGUMENT; | |
106 | else | |
107 | rv = vm_allocate(uap->map, &addr, uap->size, uap->anywhere); | |
108 | if (rv == KERN_SUCCESS) { | |
109 | if (copyout((caddr_t)&addr, (caddr_t)uap->addr, sizeof(addr))) | |
110 | rv = KERN_INVALID_ARGUMENT; | |
111 | } | |
112 | return((int)rv); | |
113 | } | |
114 | ||
3c7eb27c DG |
115 | struct svm_deallocate_args { |
116 | vm_map_t map; | |
117 | vm_offset_t addr; | |
118 | vm_size_t size; | |
119 | }; | |
120 | ||
15637ed4 RG |
121 | /* ARGSUSED */ |
122 | svm_deallocate(p, uap, retval) | |
123 | struct proc *p; | |
3c7eb27c | 124 | struct svm_deallocate_args *uap; |
15637ed4 RG |
125 | int *retval; |
126 | { | |
127 | int rv; | |
128 | ||
129 | uap->map = p->p_map; /* XXX */ | |
130 | rv = vm_deallocate(uap->map, uap->addr, uap->size); | |
131 | return((int)rv); | |
132 | } | |
133 | ||
3c7eb27c DG |
134 | struct svm_inherit_args { |
135 | vm_map_t map; | |
136 | vm_offset_t addr; | |
137 | vm_size_t size; | |
138 | vm_inherit_t inherit; | |
139 | }; | |
140 | ||
15637ed4 RG |
141 | /* ARGSUSED */ |
142 | svm_inherit(p, uap, retval) | |
143 | struct proc *p; | |
3c7eb27c | 144 | struct svm_inherit_args *uap; |
15637ed4 RG |
145 | int *retval; |
146 | { | |
147 | int rv; | |
148 | ||
149 | uap->map = p->p_map; /* XXX */ | |
150 | rv = vm_inherit(uap->map, uap->addr, uap->size, uap->inherit); | |
151 | return((int)rv); | |
152 | } | |
153 | ||
3c7eb27c DG |
154 | struct svm_protect_args { |
155 | vm_map_t map; | |
156 | vm_offset_t addr; | |
157 | vm_size_t size; | |
158 | boolean_t setmax; | |
159 | vm_prot_t prot; | |
160 | }; | |
161 | ||
15637ed4 RG |
162 | /* ARGSUSED */ |
163 | svm_protect(p, uap, retval) | |
164 | struct proc *p; | |
3c7eb27c | 165 | struct svm_protect_args *uap; |
15637ed4 RG |
166 | int *retval; |
167 | { | |
168 | int rv; | |
169 | ||
170 | uap->map = p->p_map; /* XXX */ | |
171 | rv = vm_protect(uap->map, uap->addr, uap->size, uap->setmax, uap->prot); | |
172 | return((int)rv); | |
173 | } | |
174 | #endif | |
175 | ||
176 | /* | |
177 | * vm_allocate allocates "zero fill" memory in the specfied | |
178 | * map. | |
179 | */ | |
180 | vm_allocate(map, addr, size, anywhere) | |
181 | register vm_map_t map; | |
182 | register vm_offset_t *addr; | |
183 | register vm_size_t size; | |
184 | boolean_t anywhere; | |
185 | { | |
186 | int result; | |
187 | ||
188 | if (map == NULL) | |
189 | return(KERN_INVALID_ARGUMENT); | |
190 | if (size == 0) { | |
191 | *addr = 0; | |
192 | return(KERN_SUCCESS); | |
193 | } | |
194 | ||
195 | if (anywhere) | |
196 | *addr = vm_map_min(map); | |
197 | else | |
198 | *addr = trunc_page(*addr); | |
199 | size = round_page(size); | |
200 | ||
201 | result = vm_map_find(map, NULL, (vm_offset_t) 0, addr, | |
202 | size, anywhere); | |
203 | ||
204 | return(result); | |
205 | } | |
206 | ||
207 | /* | |
208 | * vm_deallocate deallocates the specified range of addresses in the | |
209 | * specified address map. | |
210 | */ | |
211 | vm_deallocate(map, start, size) | |
212 | register vm_map_t map; | |
213 | vm_offset_t start; | |
214 | vm_size_t size; | |
215 | { | |
216 | if (map == NULL) | |
217 | return(KERN_INVALID_ARGUMENT); | |
218 | ||
219 | if (size == (vm_offset_t) 0) | |
220 | return(KERN_SUCCESS); | |
221 | ||
222 | return(vm_map_remove(map, trunc_page(start), round_page(start+size))); | |
223 | } | |
224 | ||
225 | /* | |
226 | * vm_inherit sets the inheritence of the specified range in the | |
227 | * specified map. | |
228 | */ | |
229 | vm_inherit(map, start, size, new_inheritance) | |
230 | register vm_map_t map; | |
231 | vm_offset_t start; | |
232 | vm_size_t size; | |
233 | vm_inherit_t new_inheritance; | |
234 | { | |
235 | if (map == NULL) | |
236 | return(KERN_INVALID_ARGUMENT); | |
237 | ||
238 | return(vm_map_inherit(map, trunc_page(start), round_page(start+size), new_inheritance)); | |
239 | } | |
240 | ||
241 | /* | |
242 | * vm_protect sets the protection of the specified range in the | |
243 | * specified map. | |
244 | */ | |
245 | ||
246 | vm_protect(map, start, size, set_maximum, new_protection) | |
247 | register vm_map_t map; | |
248 | vm_offset_t start; | |
249 | vm_size_t size; | |
250 | boolean_t set_maximum; | |
251 | vm_prot_t new_protection; | |
252 | { | |
253 | if (map == NULL) | |
254 | return(KERN_INVALID_ARGUMENT); | |
255 | ||
256 | return(vm_map_protect(map, trunc_page(start), round_page(start+size), new_protection, set_maximum)); | |
257 | } |