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 | 36 | * from: @(#)vm_map.h 7.3 (Berkeley) 4/21/91 |
ce619eaa | 37 | * $Id: vm_map.h,v 1.4 1994/01/14 16:27:21 davidg Exp $ |
1284e777 RG |
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 | * | |
15637ed4 RG |
66 | */ |
67 | ||
68 | /* | |
69 | * Virtual memory map module definitions. | |
70 | */ | |
71 | ||
72 | #ifndef _VM_MAP_ | |
73 | #define _VM_MAP_ | |
74 | ||
75 | /* | |
76 | * Types defined: | |
77 | * | |
78 | * vm_map_t the high-level address map data structure. | |
79 | * vm_map_entry_t an entry in an address map. | |
80 | * vm_map_version_t a timestamp of a map, for use with vm_map_lookup | |
81 | */ | |
82 | ||
83 | /* | |
84 | * Objects which live in maps may be either VM objects, or | |
85 | * another map (called a "sharing map") which denotes read-write | |
86 | * sharing with other maps. | |
87 | */ | |
88 | ||
89 | union vm_map_object { | |
90 | struct vm_object *vm_object; /* object object */ | |
91 | struct vm_map *share_map; /* share map */ | |
92 | struct vm_map *sub_map; /* belongs to another map */ | |
93 | }; | |
94 | ||
95 | typedef union vm_map_object vm_map_object_t; | |
96 | ||
97 | /* | |
98 | * Address map entries consist of start and end addresses, | |
99 | * a VM object (or sharing map) and offset into that object, | |
100 | * and user-exported inheritance and protection information. | |
101 | * Also included is control information for virtual copy operations. | |
102 | */ | |
ce619eaa | 103 | |
15637ed4 RG |
104 | struct vm_map_entry { |
105 | struct vm_map_entry *prev; /* previous entry */ | |
106 | struct vm_map_entry *next; /* next entry */ | |
107 | vm_offset_t start; /* start address */ | |
108 | vm_offset_t end; /* end address */ | |
109 | union vm_map_object object; /* object I point to */ | |
110 | vm_offset_t offset; /* offset into object */ | |
ce619eaa DG |
111 | unsigned char is_a_map:1, /* Is "object" a map? */ |
112 | is_sub_map:1, /* Is "object" a submap? */ | |
15637ed4 | 113 | /* Only in sharing maps: */ |
ce619eaa DG |
114 | copy_on_write:1,/* is data copy-on-write */ |
115 | needs_copy:1;/* does object need to be copied */ | |
15637ed4 RG |
116 | /* Only in task maps: */ |
117 | vm_prot_t protection; /* protection code */ | |
118 | vm_prot_t max_protection; /* maximum protection */ | |
119 | vm_inherit_t inheritance; /* inheritance */ | |
120 | int wired_count; /* can be paged if = 0 */ | |
121 | }; | |
122 | ||
123 | typedef struct vm_map_entry *vm_map_entry_t; | |
124 | ||
125 | /* | |
126 | * Maps are doubly-linked lists of map entries, kept sorted | |
127 | * by address. A single hint is provided to start | |
128 | * searches again from the last successful search, | |
129 | * insertion, or removal. | |
130 | */ | |
131 | struct vm_map { | |
132 | struct pmap * pmap; /* Physical map */ | |
133 | lock_data_t lock; /* Lock for map data */ | |
134 | struct vm_map_entry header; /* List of entries */ | |
135 | int nentries; /* Number of entries */ | |
136 | vm_size_t size; /* virtual size */ | |
137 | boolean_t is_main_map; /* Am I a main map? */ | |
138 | int ref_count; /* Reference count */ | |
139 | simple_lock_data_t ref_lock; /* Lock for ref_count field */ | |
140 | vm_map_entry_t hint; /* hint for quick lookups */ | |
141 | simple_lock_data_t hint_lock; /* lock for hint storage */ | |
142 | vm_map_entry_t first_free; /* First free space hint */ | |
143 | boolean_t entries_pageable; /* map entries pageable?? */ | |
144 | unsigned int timestamp; /* Version number */ | |
145 | #define min_offset header.start | |
146 | #define max_offset header.end | |
147 | }; | |
148 | ||
149 | typedef struct vm_map *vm_map_t; | |
150 | ||
151 | /* | |
152 | * Map versions are used to validate a previous lookup attempt. | |
153 | * | |
154 | * Since lookup operations may involve both a main map and | |
155 | * a sharing map, it is necessary to have a timestamp from each. | |
156 | * [If the main map timestamp has changed, the share_map and | |
157 | * associated timestamp are no longer valid; the map version | |
158 | * does not include a reference for the imbedded share_map.] | |
159 | */ | |
160 | typedef struct { | |
161 | int main_timestamp; | |
162 | vm_map_t share_map; | |
163 | int share_timestamp; | |
164 | } vm_map_version_t; | |
165 | ||
166 | /* | |
167 | * Macros: vm_map_lock, etc. | |
168 | * Function: | |
169 | * Perform locking on the data portion of a map. | |
170 | */ | |
171 | ||
172 | #define vm_map_lock(map) { lock_write(&(map)->lock); (map)->timestamp++; } | |
173 | #define vm_map_unlock(map) lock_write_done(&(map)->lock) | |
174 | #define vm_map_lock_read(map) lock_read(&(map)->lock) | |
175 | #define vm_map_unlock_read(map) lock_read_done(&(map)->lock) | |
176 | ||
177 | /* | |
178 | * Exported procedures that operate on vm_map_t. | |
179 | */ | |
fde1aeb2 GW |
180 | extern int vm_map_pageable(vm_map_t, vm_offset_t, vm_offset_t, boolean_t); |
181 | extern void vm_map_startup(void); | |
182 | struct pmap; struct vm_object; | |
183 | extern vm_map_t vm_map_create(struct pmap *, vm_offset_t, vm_offset_t, | |
184 | boolean_t); | |
185 | extern void vm_map_init(struct vm_map *, vm_offset_t, vm_offset_t, boolean_t); | |
186 | extern vm_map_entry_t vm_map_entry_create(vm_map_t); | |
187 | extern void vm_map_entry_dispose(vm_map_t, vm_map_entry_t); | |
188 | extern void vm_map_reference(vm_map_t); | |
189 | extern void vm_map_deallocate(vm_map_t); | |
190 | extern int vm_map_insert(vm_map_t, struct vm_object *, vm_offset_t, vm_offset_t, | |
191 | vm_offset_t); | |
192 | extern boolean_t vm_map_lookup_entry(vm_map_t, vm_offset_t, vm_map_entry_t *); | |
193 | extern int vm_map_find(vm_map_t, struct vm_object *, vm_offset_t, vm_offset_t*, | |
194 | vm_size_t, boolean_t); | |
195 | extern void vm_map_simplify_entry(vm_map_t, vm_map_entry_t); | |
196 | extern int vm_map_submap(vm_map_t, vm_offset_t, vm_offset_t, vm_map_t); | |
197 | extern int vm_map_protect(vm_map_t, vm_offset_t, vm_offset_t, vm_prot_t, | |
198 | boolean_t); | |
199 | extern int vm_map_inherit(vm_map_t, vm_offset_t, vm_offset_t, vm_inherit_t); | |
200 | extern int vm_map_pageable(vm_map_t, vm_offset_t, vm_offset_t, boolean_t); | |
201 | extern void vm_map_entry_unwire(vm_map_t, vm_map_entry_t); | |
202 | extern void vm_map_entry_delete(vm_map_t, vm_map_entry_t); | |
203 | extern int vm_map_delete(vm_map_t, vm_offset_t, vm_offset_t); | |
204 | extern int vm_map_remove(vm_map_t, vm_offset_t, vm_offset_t); | |
205 | extern boolean_t vm_map_check_protection(vm_map_t, vm_offset_t, vm_offset_t, | |
206 | vm_prot_t); | |
207 | extern void vm_map_copy_entry(vm_map_t, vm_map_t, vm_map_entry_t, | |
208 | vm_map_entry_t); | |
209 | extern int vm_map_copy(vm_map_t, vm_map_t, vm_offset_t, vm_size_t, vm_offset_t, | |
210 | boolean_t, boolean_t); | |
211 | extern int vm_map_lookup(vm_map_t *, vm_offset_t, vm_prot_t, | |
212 | vm_map_entry_t *, struct vm_object **, vm_offset_t *, | |
213 | vm_prot_t *, boolean_t *, boolean_t *); | |
214 | extern void vm_map_lookup_done(vm_map_t, vm_map_entry_t); | |
215 | extern void vm_map_simplify(vm_map_t, vm_offset_t); | |
216 | extern void vm_map_print(vm_map_t, boolean_t); /* f defined(DEBUG) || NDDB>0 */ | |
217 | ||
218 | extern int vm_fault(struct vm_map *, vm_offset_t, vm_prot_t, boolean_t); | |
219 | extern void vm_fault_wire(struct vm_map *, vm_offset_t, vm_offset_t); | |
220 | extern void vm_fault_unwire(struct vm_map *, vm_offset_t, vm_offset_t); | |
221 | extern void vm_fault_copy_entry(vm_map_t, vm_map_t, vm_map_entry_t, | |
222 | vm_map_entry_t); | |
15637ed4 | 223 | |
15637ed4 RG |
224 | |
225 | /* | |
226 | * Functions implemented as macros | |
227 | */ | |
228 | #define vm_map_min(map) ((map)->min_offset) | |
229 | #define vm_map_max(map) ((map)->max_offset) | |
230 | #define vm_map_pmap(map) ((map)->pmap) | |
231 | ||
232 | /* XXX: number of kernel maps and entries to statically allocate */ | |
233 | #define MAX_KMAP 10 | |
234 | ||
55768178 | 235 | #define MAX_KMAPENT 128 |
15637ed4 RG |
236 | |
237 | #endif _VM_MAP_ |