]> git.saurik.com Git - apple/xnu.git/blame - osfmk/vm/vm_shared_region.h
xnu-3789.1.32.tar.gz
[apple/xnu.git] / osfmk / vm / vm_shared_region.h
CommitLineData
2d21ac55
A
1/*
2 * Copyright (c) 2007 Apple Inc. All rights reserved.
3 *
4 * @APPLE_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. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
11 * file.
12 *
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.
20 *
21 * @APPLE_LICENSE_HEADER_END@
22 */
23/*
24 *
25 * File: vm/vm_shared_region.h
26 *
27 * protos and struct definitions for shared region
28 */
29
30#ifndef _VM_SHARED_REGION_H_
31#define _VM_SHARED_REGION_H_
32
33#ifdef KERNEL_PRIVATE
34
35#include <mach/vm_prot.h>
36#include <mach/mach_types.h>
37#include <mach/shared_region.h>
38
39#include <kern/kern_types.h>
40#include <kern/macro_help.h>
41
42#include <vm/vm_map.h>
43
44extern int shared_region_version;
45extern int shared_region_persistence;
46
47#if DEBUG
48extern int shared_region_debug;
49#define SHARED_REGION_DEBUG(args) \
50 MACRO_BEGIN \
51 if (shared_region_debug) { \
52 kprintf args; \
53 } \
54 MACRO_END
55#else /* DEBUG */
56#define SHARED_REGION_DEBUG(args)
57#endif /* DEBUG */
58
59extern 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) \
65 MACRO_BEGIN \
66 if (shared_region_trace_level >= level) { \
67 printf args; \
68 } \
69 MACRO_END
70#define SHARED_REGION_TRACE_NONE(args)
71#define SHARED_REGION_TRACE_ERROR(args) \
72 MACRO_BEGIN \
73 SHARED_REGION_TRACE(SHARED_REGION_TRACE_ERROR_LVL, \
74 args); \
75 MACRO_END
76#define SHARED_REGION_TRACE_INFO(args) \
77 MACRO_BEGIN \
78 SHARED_REGION_TRACE(SHARED_REGION_TRACE_INFO_LVL, \
79 args); \
80 MACRO_END
81#define SHARED_REGION_TRACE_DEBUG(args) \
82 MACRO_BEGIN \
83 SHARED_REGION_TRACE(SHARED_REGION_TRACE_DEBUG_LVL, \
84 args); \
85 MACRO_END
86
87typedef struct vm_shared_region *vm_shared_region_t;
88
89#ifdef MACH_KERNEL_PRIVATE
90
91#include <kern/queue.h>
92#include <vm/vm_object.h>
93#include <vm/memory_object.h>
94
39037602
A
95#define PAGE_SIZE_FOR_SR_SLIDE 4096
96
97/* Documentation for the slide info format can be found in the dyld project in
98 * the file 'launch-cache/dyld_cache_format.h'. */
99
100typedef struct vm_shared_region_slide_info_entry_v1 *vm_shared_region_slide_info_entry_v1_t;
101struct vm_shared_region_slide_info_entry_v1 {
6d2010ae
A
102 uint32_t version;
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;
39037602
A
107 // uint16_t toc[toc_count];
108 // entrybitmap entries[entries_count];
6d2010ae
A
109};
110
111#define NBBY 8
fe8ab488 112#define NUM_SLIDING_BITMAPS_PER_PAGE (0x1000/sizeof(int)/NBBY) /*128*/
6d2010ae
A
113typedef struct slide_info_entry_toc *slide_info_entry_toc_t;
114struct slide_info_entry_toc {
115 uint8_t entry[NUM_SLIDING_BITMAPS_PER_PAGE];
116};
117
39037602
A
118typedef struct vm_shared_region_slide_info_entry_v2 *vm_shared_region_slide_info_entry_v2_t;
119struct vm_shared_region_slide_info_entry_v2 {
120 uint32_t version;
121 uint32_t page_size;
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
127 uint64_t value_add;
128 // uint16_t page_starts[page_starts_count];
129 // uint16_t page_extras[page_extras_count];
130};
131
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
138
139typedef union vm_shared_region_slide_info_entry *vm_shared_region_slide_info_entry_t;
140union vm_shared_region_slide_info_entry {
141 uint32_t version;
142 struct vm_shared_region_slide_info_entry_v1 v1;
143 struct vm_shared_region_slide_info_entry_v2 v2;
144};
145
39236c6e 146typedef struct vm_shared_region_slide_info *vm_shared_region_slide_info_t;
6d2010ae
A
147struct vm_shared_region_slide_info {
148 mach_vm_offset_t start;
149 mach_vm_offset_t end;
150 uint32_t slide;
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;
6d2010ae
A
154};
155
39236c6e
A
156/* address space shared region descriptor */
157struct vm_shared_region {
158 uint32_t sr_ref_count;
159 queue_chain_t sr_q;
160 void *sr_root_dir;
161 cpu_type_t sr_cpu_type;
162 boolean_t sr_64bit;
163 boolean_t sr_mapping_in_progress;
164 boolean_t sr_slide_in_progress;
165 boolean_t sr_persists;
166 boolean_t sr_slid;
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;
175};
6d2010ae 176
39236c6e
A
177extern kern_return_t vm_shared_region_slide_page(vm_shared_region_slide_info_t si,
178 vm_offset_t vaddr,
179 uint32_t pageIndex);
180extern vm_shared_region_slide_info_t vm_shared_region_get_slide_info(vm_shared_region_t sr);
2d21ac55
A
181#else /* !MACH_KERNEL_PRIVATE */
182
183struct vm_shared_region;
6d2010ae
A
184struct vm_shared_region_slide_info;
185struct vm_shared_region_slide_info_entry;
186struct slide_info_entry_toc;
2d21ac55
A
187
188#endif /* MACH_KERNEL_PRIVATE */
189
190extern void vm_shared_region_init(void);
191extern kern_return_t vm_shared_region_enter(
192 struct _vm_map *map,
193 struct task *task,
39037602 194 boolean_t is_64bit,
2d21ac55
A
195 void *fsroot,
196 cpu_type_t cpu);
197extern kern_return_t vm_shared_region_remove(
198 struct _vm_map *map,
199 struct task *task);
200extern vm_shared_region_t vm_shared_region_get(
201 struct task *task);
202extern void vm_shared_region_deallocate(
203 struct vm_shared_region *shared_region);
204extern mach_vm_offset_t vm_shared_region_base_address(
205 struct vm_shared_region *shared_region);
206extern mach_vm_size_t vm_shared_region_size(
207 struct vm_shared_region *shared_region);
208extern ipc_port_t vm_shared_region_mem_entry(
209 struct vm_shared_region *shared_region);
39236c6e
A
210extern uint32_t vm_shared_region_get_slide(
211 vm_shared_region_t shared_region);
2d21ac55
A
212extern void vm_shared_region_set(
213 struct task *task,
214 struct vm_shared_region *new_shared_region);
215extern vm_shared_region_t vm_shared_region_lookup(
216 void *root_dir,
217 cpu_type_t cpu,
218 boolean_t is_64bit);
219extern kern_return_t vm_shared_region_start_address(
220 struct vm_shared_region *shared_region,
221 mach_vm_offset_t *start_address);
6d2010ae
A
222extern void vm_shared_region_undo_mappings(
223 vm_map_t sr_map,
224 mach_vm_offset_t sr_base_address,
225 struct shared_file_mapping_np *mappings,
226 unsigned int mappings_count);
2d21ac55
A
227extern kern_return_t vm_shared_region_map_file(
228 struct vm_shared_region *shared_region,
229 unsigned int mappings_count,
230 struct shared_file_mapping_np *mappings,
231 memory_object_control_t file_control,
232 memory_object_size_t file_size,
6d2010ae 233 void *root_dir,
15129b1c
A
234 uint32_t slide,
235 user_addr_t slide_start,
236 user_addr_t slide_size);
6d2010ae 237extern kern_return_t vm_shared_region_sliding_valid(uint32_t slide);
39236c6e
A
238extern kern_return_t vm_shared_region_slide_sanity_check(vm_shared_region_t sr);
239extern kern_return_t vm_shared_region_slide_init(vm_shared_region_t sr,
240 mach_vm_size_t slide_info_size,
6d2010ae
A
241 mach_vm_offset_t start,
242 mach_vm_size_t size,
243 uint32_t slide,
244 memory_object_control_t);
39236c6e 245extern void* vm_shared_region_get_slide_info_entry(vm_shared_region_t sr);
2d21ac55 246extern void vm_commpage_init(void);
316670eb 247extern void vm_commpage_text_init(void);
2d21ac55
A
248extern kern_return_t vm_commpage_enter(
249 struct _vm_map *map,
39037602
A
250 struct task *task,
251 boolean_t is64bit);
2d21ac55
A
252extern kern_return_t vm_commpage_remove(
253 struct _vm_map *map,
254 struct task *task);
39236c6e
A
255int vm_shared_region_slide(uint32_t,
256 mach_vm_offset_t,
257 mach_vm_size_t,
258 mach_vm_offset_t,
259 mach_vm_size_t,
260 memory_object_control_t);
2d21ac55
A
261
262#endif /* KERNEL_PRIVATE */
263
264#endif /* _VM_SHARED_REGION_H_ */