2 * Copyright (c) 2009 Apple Inc. All rights reserved.
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
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.
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
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.
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
29 #ifndef _VM_VM_MAP_STORE_H
30 #define _VM_VM_MAP_STORE_H
33 #ifndef VM_MAP_STORE_USE_LL
34 #define VM_MAP_STORE_USE_LL
37 #ifndef VM_MAP_STORE_USE_RB
38 #define VM_MAP_STORE_USE_RB
41 #include <libkern/tree.h>
49 #ifdef VM_MAP_STORE_USE_RB
50 RB_ENTRY(vm_map_store
) entry
;
54 #ifdef VM_MAP_STORE_USE_RB
55 RB_HEAD( rb_head
, vm_map_store
);
58 #include <vm/vm_map.h>
59 #include <vm/vm_map_store_ll.h>
60 #include <vm/vm_map_store_rb.h>
62 #define UPDATE_HIGHEST_ENTRY_END(map, highest_entry) \
64 struct _vm_map* UHEE_map; \
65 struct vm_map_entry* UHEE_entry; \
67 assert(UHEE_map->disable_vmentry_reuse); \
68 assert(!UHEE_map->is_nested_map); \
69 UHEE_entry = (highest_entry); \
70 if( UHEE_map->highest_entry_end < UHEE_entry->vme_end) { \
71 UHEE_map->highest_entry_end = UHEE_entry->vme_end; \
75 #define VM_MAP_HIGHEST_ENTRY(map, entry, start) \
77 struct _vm_map* VMHE_map; \
78 struct vm_map_entry* tmp_entry; \
79 vm_map_offset_t VMHE_start; \
81 assert(VMHE_map->disable_vmentry_reuse); \
82 assert(!VMHE_map->is_nested_map); \
83 VMHE_start= VMHE_map->highest_entry_end + PAGE_SIZE_64; \
84 while(vm_map_lookup_entry(VMHE_map, VMHE_start, &tmp_entry)){ \
85 VMHE_map->highest_entry_end = tmp_entry->vme_end; \
86 VMHE_start = VMHE_map->highest_entry_end + PAGE_SIZE_64; \
95 * Saves the specified entry as the hint for
96 * future lookups. only a read lock is held on map,
97 * so make sure the store is atomic... OSCompareAndSwap
98 * guarantees this... also, we don't care if we collide
99 * and someone else wins and stores their 'hint'
101 #define SAVE_HINT_MAP_READ(map, value) \
103 OSCompareAndSwapPtr((map)->hint, value, &(map)->hint); \
108 * SAVE_HINT_MAP_WRITE:
110 * Saves the specified entry as the hint for
111 * future lookups. write lock held on map,
112 * so no one else can be writing or looking
113 * until the lock is dropped, so it's safe
114 * to just do an assignment
116 #define SAVE_HINT_MAP_WRITE(map, value) \
118 (map)->hint = (value); \
121 #define SAVE_HINT_HOLE_WRITE(map, value) \
123 (map)->hole_hint = (value); \
126 #define SKIP_RB_TREE 0xBAADC0D1
128 #define VM_MAP_ENTRY_CREATE 1
129 #define VM_MAP_ENTRY_DELETE 2
131 void vm_map_store_init( struct vm_map_header
* );
132 boolean_t
vm_map_store_lookup_entry( struct _vm_map
*, vm_map_offset_t
, struct vm_map_entry
**);
133 void vm_map_store_update( struct _vm_map
*, struct vm_map_entry
*, int);
134 void _vm_map_store_entry_link( struct vm_map_header
*, struct vm_map_entry
*, struct vm_map_entry
*);
135 void vm_map_store_entry_link( struct _vm_map
*, struct vm_map_entry
*, struct vm_map_entry
*, vm_map_kernel_flags_t
);
136 void _vm_map_store_entry_unlink( struct vm_map_header
*, struct vm_map_entry
*);
137 void vm_map_store_entry_unlink( struct _vm_map
*, struct vm_map_entry
*);
138 void vm_map_store_update_first_free( struct _vm_map
*, struct vm_map_entry
*, boolean_t new_entry_creation
);
139 void vm_map_store_copy_reset( struct vm_map_copy
*, struct vm_map_entry
*);
141 boolean_t
first_free_is_valid_store( struct _vm_map
*);
143 boolean_t
vm_map_store_has_RB_support( struct vm_map_header
*hdr
);
145 #endif /* _VM_VM_MAP_STORE_H */