]> git.saurik.com Git - apple/xnu.git/blame - osfmk/vm/vm_map_store.c
xnu-1699.22.73.tar.gz
[apple/xnu.git] / osfmk / vm / vm_map_store.c
CommitLineData
6d2010ae
A
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
32boolean_t
33first_free_is_valid_store( vm_map_t map )
34{
35 return(first_free_is_valid_ll( map ));
36}
37#endif
38
39void
40vm_map_store_init( struct vm_map_header *hdr )
41{
42 vm_map_store_init_ll( hdr );
43#ifdef VM_MAP_STORE_USE_RB
44 vm_map_store_init_rb( hdr );
45#endif
46}
47
48boolean_t
49vm_map_store_lookup_entry(
50 register vm_map_t map,
51 register vm_map_offset_t address,
52 vm_map_entry_t *entry) /* OUT */
53{
54#ifdef VM_MAP_STORE_USE_LL
55 return (vm_map_store_lookup_entry_ll( map, address, entry ));
56#elif defined VM_MAP_STORE_USE_RB
57 return (vm_map_store_lookup_entry_rb( map, address, entry ));
58#endif
59}
60
61void
62vm_map_store_update( vm_map_t map, vm_map_entry_t entry, int update_type )
63{
64 switch (update_type) {
65 case VM_MAP_ENTRY_CREATE:
66 break;
67 case VM_MAP_ENTRY_DELETE:
68 if((entry) == (map)->first_free) {
69 (map)->first_free = vm_map_to_entry(map);
70 }
71 if((entry) == (map)->hint) {
72 (map)->hint = vm_map_to_entry(map);
73 }
74 break;
75 default:
76 break;
77 }
78}
79
80void vm_map_store_copy_insert( vm_map_t map, vm_map_entry_t after_where, vm_map_copy_t copy)
81{
82 vm_map_store_copy_insert_ll(map, after_where, copy);
83#ifdef VM_MAP_STORE_USE_RB
84 vm_map_store_copy_insert_rb(map, after_where, copy);
85#endif
86}
87
88/*
89 * vm_map_entry_{un,}link:
90 *
91 * Insert/remove entries from maps (or map copies).
92 * The _vm_map_store_entry_{un,}link variants are used at
93 * some places where updating first_free is not needed &
94 * copy maps are being modified. Also note the first argument
95 * is the map header.
96 * Modifying the vm_map_store_entry_{un,}link functions to
97 * deal with these call sites made the interface confusing
98 * and clunky.
99 */
100
101void
102_vm_map_store_entry_link( struct vm_map_header * mapHdr, vm_map_entry_t after_where, vm_map_entry_t entry)
103{
104 vm_map_store_entry_link_ll(mapHdr, after_where, entry);
105#ifdef VM_MAP_STORE_USE_RB
106 vm_map_store_entry_link_rb(mapHdr, after_where, entry);
107#endif
108}
109
110void
111vm_map_store_entry_link( vm_map_t map, vm_map_entry_t after_where, vm_map_entry_t entry)
112{
113 vm_map_t VMEL_map;
114 vm_map_entry_t VMEL_entry;
115 VMEL_map = (map);
116 VMEL_entry = (entry);
117
118 _vm_map_store_entry_link(&VMEL_map->hdr, after_where, VMEL_entry);
119 if( VMEL_map->disable_vmentry_reuse == TRUE ) {
120 UPDATE_HIGHEST_ENTRY_END( VMEL_map, VMEL_entry);
121 } else {
122 update_first_free_ll(VMEL_map, VMEL_map->first_free);
123#ifdef VM_MAP_STORE_USE_RB
124 update_first_free_rb(VMEL_map, VMEL_map->first_free);
125#endif
126 }
127}
128
129void
130_vm_map_store_entry_unlink( struct vm_map_header * mapHdr, vm_map_entry_t entry)
131{
132 vm_map_store_entry_unlink_ll(mapHdr, entry);
133#ifdef VM_MAP_STORE_USE_RB
134 vm_map_store_entry_unlink_rb(mapHdr, entry);
135#endif
136}
137
138void
139vm_map_store_entry_unlink( vm_map_t map, vm_map_entry_t entry)
140{
141 vm_map_t VMEU_map;
142 vm_map_entry_t VMEU_entry;
143 vm_map_entry_t VMEU_first_free;
144 VMEU_map = (map);
145 VMEU_entry = (entry);
146 if (VMEU_entry->vme_start <= VMEU_map->first_free->vme_start){
147 VMEU_first_free = VMEU_entry->vme_prev;
148 } else {
149 VMEU_first_free = VMEU_map->first_free;
150 }
151
152 _vm_map_store_entry_unlink(&VMEU_map->hdr, VMEU_entry);
153 update_first_free_ll(VMEU_map, VMEU_first_free);
154#ifdef VM_MAP_STORE_USE_RB
155 update_first_free_rb(VMEU_map, VMEU_first_free);
156#endif
157}
158
159void
160vm_map_store_copy_reset( vm_map_copy_t copy,vm_map_entry_t entry)
161{
162 int nentries = copy->cpy_hdr.nentries;
163 vm_map_store_copy_reset_ll(copy, entry, nentries);
164#ifdef VM_MAP_STORE_USE_RB
165 vm_map_store_copy_reset_rb(copy, entry, nentries);
166#endif
167}
168
169void
170vm_map_store_update_first_free( vm_map_t map, vm_map_entry_t first_free)
171{
172 update_first_free_ll(map, first_free);
173#ifdef VM_MAP_STORE_USE_RB
174 update_first_free_rb(map, first_free);
175#endif
176}