2 * Copyright (c) 2007 Apple Inc. All rights reserved.
4 * @APPLE_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. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
21 * @APPLE_LICENSE_HEADER_END@
25 * File: vm/vm_shared_region.h
27 * protos and struct definitions for shared region
30 #ifndef _VM_SHARED_REGION_H_
31 #define _VM_SHARED_REGION_H_
35 #include <mach/vm_prot.h>
36 #include <mach/mach_types.h>
37 #include <mach/shared_region.h>
39 #include <kern/kern_types.h>
40 #include <kern/macro_help.h>
42 #include <vm/vm_map.h>
44 extern int shared_region_version
;
45 extern int shared_region_persistence
;
48 extern int shared_region_debug
;
49 #define SHARED_REGION_DEBUG(args) \
51 if (shared_region_debug) { \
56 #define SHARED_REGION_DEBUG(args)
59 extern int shared_region_trace_level
;
60 #define SHARED_REGION_TRACE_NONE_LVL 0 /* no trace */
61 #define SHARED_REGION_TRACE_ERROR_LVL 1 /* trace abnormal events */
62 #define SHARED_REGION_TRACE_INFO_LVL 2 /* trace all events */
63 #define SHARED_REGION_TRACE_DEBUG_LVL 3 /* extra traces for debug */
64 #define SHARED_REGION_TRACE(level, args) \
66 if (shared_region_trace_level >= level) { \
70 #define SHARED_REGION_TRACE_NONE(args)
71 #define SHARED_REGION_TRACE_ERROR(args) \
73 SHARED_REGION_TRACE(SHARED_REGION_TRACE_ERROR_LVL, \
76 #define SHARED_REGION_TRACE_INFO(args) \
78 SHARED_REGION_TRACE(SHARED_REGION_TRACE_INFO_LVL, \
81 #define SHARED_REGION_TRACE_DEBUG(args) \
83 SHARED_REGION_TRACE(SHARED_REGION_TRACE_DEBUG_LVL, \
87 typedef struct vm_shared_region
*vm_shared_region_t
;
89 #ifdef MACH_KERNEL_PRIVATE
91 #include <kern/queue.h>
92 #include <vm/vm_object.h>
93 #include <vm/memory_object.h>
95 #define PAGE_SIZE_FOR_SR_SLIDE 4096
97 /* Documentation for the slide info format can be found in the dyld project in
98 * the file 'launch-cache/dyld_cache_format.h'. */
100 typedef struct vm_shared_region_slide_info_entry_v1
*vm_shared_region_slide_info_entry_v1_t
;
101 struct vm_shared_region_slide_info_entry_v1
{
103 uint32_t toc_offset
; // offset from start of header to table-of-contents
104 uint32_t toc_count
; // number of entries in toc (same as number of pages in r/w mapping)
105 uint32_t entry_offset
;
106 uint32_t entry_count
;
107 // uint16_t toc[toc_count];
108 // entrybitmap entries[entries_count];
112 #define NUM_SLIDING_BITMAPS_PER_PAGE (0x1000/sizeof(int)/NBBY) /*128*/
113 typedef struct slide_info_entry_toc
*slide_info_entry_toc_t
;
114 struct slide_info_entry_toc
{
115 uint8_t entry
[NUM_SLIDING_BITMAPS_PER_PAGE
];
118 typedef struct vm_shared_region_slide_info_entry_v2
*vm_shared_region_slide_info_entry_v2_t
;
119 struct vm_shared_region_slide_info_entry_v2
{
122 uint32_t page_starts_offset
;
123 uint32_t page_starts_count
;
124 uint32_t page_extras_offset
;
125 uint32_t page_extras_count
;
126 uint64_t delta_mask
; // which (contiguous) set of bits contains the delta to the next rebase location
128 // uint16_t page_starts[page_starts_count];
129 // uint16_t page_extras[page_extras_count];
132 #define DYLD_CACHE_SLIDE_PAGE_ATTRS 0xC000 // high bits of uint16_t are flags
133 #define DYLD_CACHE_SLIDE_PAGE_ATTR_EXTRA 0x8000 // index is into extras array (not starts array)
134 #define DYLD_CACHE_SLIDE_PAGE_ATTR_NO_REBASE 0x4000 // page has no rebasing
135 #define DYLD_CACHE_SLIDE_PAGE_ATTR_END 0x8000 // last chain entry for page
136 #define DYLD_CACHE_SLIDE_PAGE_VALUE 0x3FFF // bitwise negation of DYLD_CACHE_SLIDE_PAGE_ATTRS
137 #define DYLD_CACHE_SLIDE_PAGE_OFFSET_SHIFT 2
139 typedef union vm_shared_region_slide_info_entry
*vm_shared_region_slide_info_entry_t
;
140 union vm_shared_region_slide_info_entry
{
142 struct vm_shared_region_slide_info_entry_v1 v1
;
143 struct vm_shared_region_slide_info_entry_v2 v2
;
146 typedef struct vm_shared_region_slide_info
*vm_shared_region_slide_info_t
;
147 struct vm_shared_region_slide_info
{
148 mach_vm_offset_t start
;
149 mach_vm_offset_t end
;
151 vm_object_t slide_object
;
152 mach_vm_size_t slide_info_size
;
153 vm_shared_region_slide_info_entry_t slide_info_entry
;
156 /* address space shared region descriptor */
157 struct vm_shared_region
{
158 uint32_t sr_ref_count
;
161 cpu_type_t sr_cpu_type
;
163 boolean_t sr_mapping_in_progress
;
164 boolean_t sr_slide_in_progress
;
165 boolean_t sr_persists
;
167 ipc_port_t sr_mem_entry
;
168 mach_vm_offset_t sr_first_mapping
;
169 mach_vm_offset_t sr_base_address
;
170 mach_vm_size_t sr_size
;
171 mach_vm_offset_t sr_pmap_nesting_start
;
172 mach_vm_size_t sr_pmap_nesting_size
;
173 thread_call_t sr_timer_call
;
174 struct vm_shared_region_slide_info sr_slide_info
;
176 boolean_t sr_uuid_copied
;
179 extern kern_return_t
vm_shared_region_slide_page(vm_shared_region_slide_info_t si
,
182 extern vm_shared_region_slide_info_t
vm_shared_region_get_slide_info(vm_shared_region_t sr
);
183 #else /* !MACH_KERNEL_PRIVATE */
185 struct vm_shared_region
;
186 struct vm_shared_region_slide_info
;
187 struct vm_shared_region_slide_info_entry
;
188 struct slide_info_entry_toc
;
190 #endif /* MACH_KERNEL_PRIVATE */
192 extern void vm_shared_region_init(void);
193 extern kern_return_t
vm_shared_region_enter(
199 extern kern_return_t
vm_shared_region_remove(
202 extern vm_shared_region_t
vm_shared_region_get(
204 extern void vm_shared_region_deallocate(
205 struct vm_shared_region
*shared_region
);
206 extern mach_vm_offset_t
vm_shared_region_base_address(
207 struct vm_shared_region
*shared_region
);
208 extern mach_vm_size_t
vm_shared_region_size(
209 struct vm_shared_region
*shared_region
);
210 extern ipc_port_t
vm_shared_region_mem_entry(
211 struct vm_shared_region
*shared_region
);
212 extern uint32_t vm_shared_region_get_slide(
213 vm_shared_region_t shared_region
);
214 extern void vm_shared_region_set(
216 struct vm_shared_region
*new_shared_region
);
217 extern vm_shared_region_t
vm_shared_region_lookup(
221 extern kern_return_t
vm_shared_region_start_address(
222 struct vm_shared_region
*shared_region
,
223 mach_vm_offset_t
*start_address
);
224 extern void vm_shared_region_undo_mappings(
226 mach_vm_offset_t sr_base_address
,
227 struct shared_file_mapping_np
*mappings
,
228 unsigned int mappings_count
);
229 extern kern_return_t
vm_shared_region_map_file(
230 struct vm_shared_region
*shared_region
,
231 unsigned int mappings_count
,
232 struct shared_file_mapping_np
*mappings
,
233 memory_object_control_t file_control
,
234 memory_object_size_t file_size
,
237 user_addr_t slide_start
,
238 user_addr_t slide_size
);
239 extern kern_return_t
vm_shared_region_sliding_valid(uint32_t slide
);
240 extern kern_return_t
vm_shared_region_slide_sanity_check(vm_shared_region_t sr
);
241 extern kern_return_t
vm_shared_region_slide_init(vm_shared_region_t sr
,
242 mach_vm_size_t slide_info_size
,
243 mach_vm_offset_t start
,
246 memory_object_control_t
);
247 extern void* vm_shared_region_get_slide_info_entry(vm_shared_region_t sr
);
248 extern void vm_commpage_init(void);
249 extern void vm_commpage_text_init(void);
250 extern kern_return_t
vm_commpage_enter(
254 extern kern_return_t
vm_commpage_remove(
257 int vm_shared_region_slide(uint32_t,
262 memory_object_control_t
);
264 #endif /* KERNEL_PRIVATE */
266 #endif /* _VM_SHARED_REGION_H_ */