]> git.saurik.com Git - apple/xnu.git/blob - osfmk/vm/vm_map_store.c
xnu-2782.20.48.tar.gz
[apple/xnu.git] / osfmk / vm / vm_map_store.c
1 /*
2 * Copyright (c) 2009 Apple Inc. All rights reserved.
3 *
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
5 *
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. The rights granted to you under the License
10 * may not be used to create, or enable the creation or redistribution of,
11 * unlawful or unlicensed copies of an Apple operating system, or to
12 * circumvent, violate, or enable the circumvention or violation of, any
13 * terms of an Apple operating system software license agreement.
14 *
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
17 *
18 * The Original Code and all software distributed under the License are
19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
24 * limitations under the License.
25 *
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
27 */
28
29 #include <vm/vm_map_store.h>
30
31 #if MACH_ASSERT
32 boolean_t
33 first_free_is_valid_store( vm_map_t map )
34 {
35 return(first_free_is_valid_ll( map ));
36 }
37 #endif
38
39 boolean_t
40 vm_map_store_has_RB_support( struct vm_map_header *hdr )
41 {
42 if ((void*)hdr->rb_head_store.rbh_root == (void*)(int)SKIP_RB_TREE) {
43 return FALSE;
44 }
45 return TRUE;
46 }
47
48 void
49 vm_map_store_init( struct vm_map_header *hdr )
50 {
51 vm_map_store_init_ll( hdr );
52 #ifdef VM_MAP_STORE_USE_RB
53 if (vm_map_store_has_RB_support( hdr )) {
54 vm_map_store_init_rb( hdr );
55 }
56 #endif
57 }
58
59 boolean_t
60 vm_map_store_lookup_entry(
61 register vm_map_t map,
62 register vm_map_offset_t address,
63 vm_map_entry_t *entry) /* OUT */
64 {
65 #ifdef VM_MAP_STORE_USE_LL
66 return (vm_map_store_lookup_entry_ll( map, address, entry ));
67 #elif defined VM_MAP_STORE_USE_RB
68 if (vm_map_store_has_RB_support( &map->hdr )) {
69 return (vm_map_store_lookup_entry_rb( map, address, entry ));
70 } else {
71 panic("VM map lookups need RB tree support.\n");
72 return FALSE; /* For compiler warning.*/
73 }
74 #endif
75 }
76
77 void
78 vm_map_store_update( vm_map_t map, vm_map_entry_t entry, int update_type )
79 {
80 switch (update_type) {
81 case VM_MAP_ENTRY_CREATE:
82 break;
83 case VM_MAP_ENTRY_DELETE:
84 if((entry) == (map)->first_free) {
85 (map)->first_free = vm_map_to_entry(map);
86 }
87 if((entry) == (map)->hint) {
88 (map)->hint = vm_map_to_entry(map);
89 }
90 break;
91 default:
92 break;
93 }
94 }
95
96 void vm_map_store_copy_insert( vm_map_t map, vm_map_entry_t after_where, vm_map_copy_t copy)
97 {
98 vm_map_store_copy_insert_ll(map, after_where, copy);
99 #ifdef VM_MAP_STORE_USE_RB
100 if (vm_map_store_has_RB_support( &map->hdr )) {
101 vm_map_store_copy_insert_rb(map, after_where, copy);
102 }
103 #endif
104 }
105
106 /*
107 * vm_map_entry_{un,}link:
108 *
109 * Insert/remove entries from maps (or map copies).
110 * The _vm_map_store_entry_{un,}link variants are used at
111 * some places where updating first_free is not needed &
112 * copy maps are being modified. Also note the first argument
113 * is the map header.
114 * Modifying the vm_map_store_entry_{un,}link functions to
115 * deal with these call sites made the interface confusing
116 * and clunky.
117 */
118
119 void
120 _vm_map_store_entry_link( struct vm_map_header * mapHdr, vm_map_entry_t after_where, vm_map_entry_t entry)
121 {
122 assert(entry->vme_start < entry->vme_end);
123 vm_map_store_entry_link_ll(mapHdr, after_where, entry);
124 #ifdef VM_MAP_STORE_USE_RB
125 if (vm_map_store_has_RB_support( mapHdr )) {
126 vm_map_store_entry_link_rb(mapHdr, after_where, entry);
127 }
128 #endif
129 #if MAP_ENTRY_INSERTION_DEBUG
130 fastbacktrace(&entry->vme_insertion_bt[0],
131 (sizeof (entry->vme_insertion_bt) / sizeof (uintptr_t)));
132 #endif
133 }
134
135 void
136 vm_map_store_entry_link( vm_map_t map, vm_map_entry_t after_where, vm_map_entry_t entry)
137 {
138 vm_map_t VMEL_map;
139 vm_map_entry_t VMEL_entry;
140 VMEL_map = (map);
141 VMEL_entry = (entry);
142
143 _vm_map_store_entry_link(&VMEL_map->hdr, after_where, VMEL_entry);
144 if( VMEL_map->disable_vmentry_reuse == TRUE ) {
145 UPDATE_HIGHEST_ENTRY_END( VMEL_map, VMEL_entry);
146 } else {
147 update_first_free_ll(VMEL_map, VMEL_map->first_free);
148 #ifdef VM_MAP_STORE_USE_RB
149 if (vm_map_store_has_RB_support( &VMEL_map->hdr )) {
150 update_first_free_rb(VMEL_map, VMEL_map->first_free);
151 }
152 #endif
153 }
154 }
155
156 void
157 _vm_map_store_entry_unlink( struct vm_map_header * mapHdr, vm_map_entry_t entry)
158 {
159 vm_map_store_entry_unlink_ll(mapHdr, entry);
160 #ifdef VM_MAP_STORE_USE_RB
161 if (vm_map_store_has_RB_support( mapHdr )) {
162 vm_map_store_entry_unlink_rb(mapHdr, entry);
163 }
164 #endif
165 }
166
167 void
168 vm_map_store_entry_unlink( vm_map_t map, vm_map_entry_t entry)
169 {
170 vm_map_t VMEU_map;
171 vm_map_entry_t VMEU_entry;
172 vm_map_entry_t VMEU_first_free;
173 VMEU_map = (map);
174 VMEU_entry = (entry);
175 if (VMEU_entry->vme_start <= VMEU_map->first_free->vme_start){
176 VMEU_first_free = VMEU_entry->vme_prev;
177 } else {
178 VMEU_first_free = VMEU_map->first_free;
179 }
180
181 _vm_map_store_entry_unlink(&VMEU_map->hdr, VMEU_entry);
182 vm_map_store_update( map, entry, VM_MAP_ENTRY_DELETE);
183 update_first_free_ll(VMEU_map, VMEU_first_free);
184 #ifdef VM_MAP_STORE_USE_RB
185 if (vm_map_store_has_RB_support( &VMEU_map->hdr )) {
186 update_first_free_rb(VMEU_map, VMEU_first_free);
187 }
188 #endif
189 }
190
191 void
192 vm_map_store_copy_reset( vm_map_copy_t copy,vm_map_entry_t entry)
193 {
194 int nentries = copy->cpy_hdr.nentries;
195 vm_map_store_copy_reset_ll(copy, entry, nentries);
196 #ifdef VM_MAP_STORE_USE_RB
197 if (vm_map_store_has_RB_support( &copy->c_u.hdr )) {
198 vm_map_store_copy_reset_rb(copy, entry, nentries);
199 }
200 #endif
201 }
202
203 void
204 vm_map_store_update_first_free( vm_map_t map, vm_map_entry_t first_free)
205 {
206 update_first_free_ll(map, first_free);
207 #ifdef VM_MAP_STORE_USE_RB
208 if (vm_map_store_has_RB_support( &map->hdr )) {
209 update_first_free_rb(map, first_free);
210 }
211 #endif
212 }