]>
Commit | Line | Data |
---|---|---|
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 | ||
44 | extern int shared_region_version; | |
45 | extern int shared_region_persistence; | |
46 | ||
47 | #if DEBUG | |
48 | extern 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 | ||
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) \ | |
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 | ||
87 | typedef 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 | ||
95 | typedef struct vm_shared_region_slide_info_entry *vm_shared_region_slide_info_entry_t; | |
96 | struct vm_shared_region_slide_info_entry { | |
97 | uint32_t version; | |
98 | uint32_t toc_offset; // offset from start of header to table-of-contents | |
99 | uint32_t toc_count; // number of entries in toc (same as number of pages in r/w mapping) | |
100 | uint32_t entry_offset; | |
101 | uint32_t entry_count; | |
102 | }; | |
103 | ||
104 | #define NBBY 8 | |
105 | #define NUM_SLIDING_BITMAPS_PER_PAGE (0x1000/sizeof(int)/NBBY) /*128*/ | |
106 | typedef struct slide_info_entry_toc *slide_info_entry_toc_t; | |
107 | struct slide_info_entry_toc { | |
108 | uint8_t entry[NUM_SLIDING_BITMAPS_PER_PAGE]; | |
109 | }; | |
110 | ||
111 | typedef struct vm_shared_region_slide_info *vm_shared_region_slide_info_t; | |
112 | struct vm_shared_region_slide_info { | |
113 | mach_vm_offset_t start; | |
114 | mach_vm_offset_t end; | |
115 | uint32_t slide; | |
116 | vm_object_t slide_object; | |
117 | mach_vm_size_t slide_info_size; | |
118 | vm_shared_region_slide_info_entry_t slide_info_entry; | |
119 | }; | |
120 | ||
121 | /* address space shared region descriptor */ | |
122 | struct vm_shared_region { | |
123 | uint32_t sr_ref_count; | |
124 | queue_chain_t sr_q; | |
125 | void *sr_root_dir; | |
126 | cpu_type_t sr_cpu_type; | |
127 | boolean_t sr_64bit; | |
128 | boolean_t sr_mapping_in_progress; | |
129 | boolean_t sr_slide_in_progress; | |
130 | boolean_t sr_persists; | |
131 | boolean_t sr_slid; | |
132 | ipc_port_t sr_mem_entry; | |
133 | mach_vm_offset_t sr_first_mapping; | |
134 | mach_vm_offset_t sr_base_address; | |
135 | mach_vm_size_t sr_size; | |
136 | mach_vm_offset_t sr_pmap_nesting_start; | |
137 | mach_vm_size_t sr_pmap_nesting_size; | |
138 | thread_call_t sr_timer_call; | |
139 | struct vm_shared_region_slide_info sr_slide_info; | |
140 | }; | |
141 | ||
142 | extern kern_return_t vm_shared_region_slide_page(vm_shared_region_slide_info_t si, | |
143 | vm_offset_t vaddr, | |
144 | uint32_t pageIndex); | |
145 | extern vm_shared_region_slide_info_t vm_shared_region_get_slide_info(vm_shared_region_t sr); | |
146 | #else /* !MACH_KERNEL_PRIVATE */ | |
147 | ||
148 | struct vm_shared_region; | |
149 | struct vm_shared_region_slide_info; | |
150 | struct vm_shared_region_slide_info_entry; | |
151 | struct slide_info_entry_toc; | |
152 | ||
153 | #endif /* MACH_KERNEL_PRIVATE */ | |
154 | ||
155 | extern void vm_shared_region_init(void); | |
156 | extern kern_return_t vm_shared_region_enter( | |
157 | struct _vm_map *map, | |
158 | struct task *task, | |
159 | void *fsroot, | |
160 | cpu_type_t cpu); | |
161 | extern kern_return_t vm_shared_region_remove( | |
162 | struct _vm_map *map, | |
163 | struct task *task); | |
164 | extern vm_shared_region_t vm_shared_region_get( | |
165 | struct task *task); | |
166 | extern void vm_shared_region_deallocate( | |
167 | struct vm_shared_region *shared_region); | |
168 | extern mach_vm_offset_t vm_shared_region_base_address( | |
169 | struct vm_shared_region *shared_region); | |
170 | extern mach_vm_size_t vm_shared_region_size( | |
171 | struct vm_shared_region *shared_region); | |
172 | extern ipc_port_t vm_shared_region_mem_entry( | |
173 | struct vm_shared_region *shared_region); | |
174 | extern uint32_t vm_shared_region_get_slide( | |
175 | vm_shared_region_t shared_region); | |
176 | extern void vm_shared_region_set( | |
177 | struct task *task, | |
178 | struct vm_shared_region *new_shared_region); | |
179 | extern vm_shared_region_t vm_shared_region_lookup( | |
180 | void *root_dir, | |
181 | cpu_type_t cpu, | |
182 | boolean_t is_64bit); | |
183 | extern kern_return_t vm_shared_region_start_address( | |
184 | struct vm_shared_region *shared_region, | |
185 | mach_vm_offset_t *start_address); | |
186 | extern void vm_shared_region_undo_mappings( | |
187 | vm_map_t sr_map, | |
188 | mach_vm_offset_t sr_base_address, | |
189 | struct shared_file_mapping_np *mappings, | |
190 | unsigned int mappings_count); | |
191 | extern kern_return_t vm_shared_region_map_file( | |
192 | struct vm_shared_region *shared_region, | |
193 | unsigned int mappings_count, | |
194 | struct shared_file_mapping_np *mappings, | |
195 | memory_object_control_t file_control, | |
196 | memory_object_size_t file_size, | |
197 | void *root_dir, | |
198 | uint32_t slide, | |
199 | user_addr_t slide_start, | |
200 | user_addr_t slide_size); | |
201 | extern kern_return_t vm_shared_region_sliding_valid(uint32_t slide); | |
202 | extern kern_return_t vm_shared_region_slide_sanity_check(vm_shared_region_t sr); | |
203 | extern kern_return_t vm_shared_region_slide_init(vm_shared_region_t sr, | |
204 | mach_vm_size_t slide_info_size, | |
205 | mach_vm_offset_t start, | |
206 | mach_vm_size_t size, | |
207 | uint32_t slide, | |
208 | memory_object_control_t); | |
209 | extern void* vm_shared_region_get_slide_info_entry(vm_shared_region_t sr); | |
210 | extern void vm_commpage_init(void); | |
211 | extern void vm_commpage_text_init(void); | |
212 | extern kern_return_t vm_commpage_enter( | |
213 | struct _vm_map *map, | |
214 | struct task *task); | |
215 | extern kern_return_t vm_commpage_remove( | |
216 | struct _vm_map *map, | |
217 | struct task *task); | |
218 | int vm_shared_region_slide(uint32_t, | |
219 | mach_vm_offset_t, | |
220 | mach_vm_size_t, | |
221 | mach_vm_offset_t, | |
222 | mach_vm_size_t, | |
223 | memory_object_control_t); | |
224 | ||
225 | #endif /* KERNEL_PRIVATE */ | |
226 | ||
227 | #endif /* _VM_SHARED_REGION_H_ */ |