]>
Commit | Line | Data |
---|---|---|
1 | /* | |
2 | * Copyright (c) 2000-2004 Apple Computer, Inc. All rights reserved. | |
3 | * | |
4 | * @APPLE_LICENSE_HEADER_START@ | |
5 | * | |
6 | * The contents of this file constitute Original Code as defined in and | |
7 | * are subject to the Apple Public Source License Version 1.1 (the | |
8 | * "License"). You may not use this file except in compliance with the | |
9 | * License. Please obtain a copy of the License at | |
10 | * http://www.apple.com/publicsource and read it before using this file. | |
11 | * | |
12 | * This Original Code and all software distributed under the License are | |
13 | * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER | |
14 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, | |
15 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, | |
16 | * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the | |
17 | * License for the specific language governing rights and limitations | |
18 | * under the License. | |
19 | * | |
20 | * @APPLE_LICENSE_HEADER_END@ | |
21 | */ | |
22 | /* | |
23 | * | |
24 | * File: vm/vm_shared_memory_server.h | |
25 | * | |
26 | * protos and struct definitions for shared library | |
27 | * server and interface | |
28 | */ | |
29 | ||
30 | #ifndef _VM_SHARED_MEMORY_SERVER_H_ | |
31 | #define _VM_SHARED_MEMORY_SERVER_H_ | |
32 | ||
33 | #ifdef KERNEL_PRIVATE | |
34 | ||
35 | #include <mach/vm_prot.h> | |
36 | #include <mach/mach_types.h> | |
37 | #include <mach/shared_memory_server.h> | |
38 | ||
39 | #include <kern/kern_types.h> | |
40 | #include <kern/macro_help.h> | |
41 | ||
42 | #if DEBUG | |
43 | extern int shared_region_debug; | |
44 | #define SHARED_REGION_DEBUG(args) \ | |
45 | MACRO_BEGIN \ | |
46 | if (shared_region_debug) { \ | |
47 | kprintf args; \ | |
48 | } \ | |
49 | MACRO_END | |
50 | #else /* DEBUG */ | |
51 | #define SHARED_REGION_DEBUG(args) | |
52 | #endif /* DEBUG */ | |
53 | ||
54 | extern int shared_region_trace_level; | |
55 | #define SHARED_REGION_TRACE_NONE 0 /* no trace */ | |
56 | #define SHARED_REGION_TRACE_ERROR 1 /* trace abnormal events */ | |
57 | #define SHARED_REGION_TRACE_CONFLICT 2 /* trace library conflicts */ | |
58 | #define SHARED_REGION_TRACE_INFO 3 /* trace all events */ | |
59 | #define SHARED_REGION_TRACE(level, args) \ | |
60 | MACRO_BEGIN \ | |
61 | if (level <= shared_region_trace_level) { \ | |
62 | printf args; \ | |
63 | } \ | |
64 | MACRO_END | |
65 | ||
66 | struct shared_region_task_mappings { | |
67 | mach_port_t text_region; | |
68 | vm_size_t text_size; | |
69 | mach_port_t data_region; | |
70 | vm_size_t data_size; | |
71 | vm_offset_t region_mappings; | |
72 | vm_offset_t client_base; | |
73 | vm_offset_t alternate_base; | |
74 | vm_offset_t alternate_next; | |
75 | unsigned int fs_base; | |
76 | unsigned int system; | |
77 | int flags; | |
78 | vm_offset_t self; | |
79 | }; | |
80 | ||
81 | #define SHARED_REGION_SYSTEM 0x1 // Default env for system and fs_root | |
82 | #define SHARED_REGION_FULL 0x2 // Shared regions are full | |
83 | #define SHARED_REGION_STALE 0x4 // Indicates no longer in default list | |
84 | #define SHARED_REGION_STANDALONE 0x10 // Shared region is not shared ! | |
85 | ||
86 | ||
87 | /* defines for default environment, and co-resident systems */ | |
88 | ||
89 | #define ENV_DEFAULT_ROOT 0 | |
90 | ||
91 | typedef struct shared_region_task_mappings *shared_region_task_mappings_t; | |
92 | typedef struct shared_region_mapping *shared_region_mapping_t; | |
93 | ||
94 | #ifdef MACH_KERNEL_PRIVATE | |
95 | ||
96 | #include <kern/queue.h> | |
97 | #include <vm/vm_object.h> | |
98 | #include <vm/memory_object.h> | |
99 | ||
100 | extern vm_offset_t shared_file_mapping_array; | |
101 | ||
102 | struct loaded_mapping { | |
103 | vm_offset_t mapping_offset; | |
104 | vm_size_t size; | |
105 | vm_offset_t file_offset; | |
106 | vm_prot_t protection; /* read/write/execute/COW/ZF */ | |
107 | ||
108 | struct loaded_mapping *next; | |
109 | }; | |
110 | ||
111 | typedef struct loaded_mapping loaded_mapping_t; | |
112 | ||
113 | struct load_struct { | |
114 | queue_chain_t links; | |
115 | shared_region_mapping_t regions_instance; | |
116 | int depth; | |
117 | int file_object; | |
118 | vm_offset_t base_address; | |
119 | int mapping_cnt; | |
120 | loaded_mapping_t *mappings; | |
121 | vm_offset_t file_offset; // start of file we mapped in | |
122 | }; | |
123 | ||
124 | typedef struct load_struct load_struct_t; | |
125 | typedef struct load_struct *load_struct_ptr_t; | |
126 | ||
127 | struct load_file_ele { | |
128 | union { | |
129 | sf_mapping_t mapping; | |
130 | load_struct_t element; | |
131 | } u; | |
132 | }; | |
133 | ||
134 | struct shared_file_info { | |
135 | mutex_t lock; /* lock for the structure */ | |
136 | queue_head_t *hash; /* for later perf enhance */ | |
137 | int hash_size; | |
138 | boolean_t hash_init; | |
139 | }; | |
140 | ||
141 | typedef struct shared_file_info shared_file_info_t; | |
142 | ||
143 | struct shared_region_object_chain { | |
144 | shared_region_mapping_t object_chain_region; | |
145 | int depth; | |
146 | struct shared_region_object_chain *next; | |
147 | }; | |
148 | typedef struct shared_region_object_chain *shared_region_object_chain_t; | |
149 | ||
150 | /* address space shared region descriptor */ | |
151 | struct shared_region_mapping { | |
152 | decl_mutex_data(, Lock) /* Synchronization */ | |
153 | unsigned int ref_count; | |
154 | unsigned int fs_base; | |
155 | unsigned int system; | |
156 | mach_port_t text_region; | |
157 | vm_size_t text_size; | |
158 | mach_port_t data_region; | |
159 | vm_size_t data_size; | |
160 | vm_offset_t region_mappings; | |
161 | vm_offset_t client_base; | |
162 | vm_offset_t alternate_base; | |
163 | vm_offset_t alternate_next; | |
164 | int flags; | |
165 | int depth; | |
166 | shared_region_mapping_t default_env_list; | |
167 | shared_region_object_chain_t object_chain; | |
168 | shared_region_mapping_t self; | |
169 | shared_region_mapping_t next; | |
170 | }; | |
171 | ||
172 | #define shared_region_mapping_lock_init(object) \ | |
173 | mutex_init(&(object)->Lock, 0) | |
174 | #define shared_region_mapping_lock(object) mutex_lock(&(object)->Lock) | |
175 | #define shared_region_mapping_unlock(object) mutex_unlock(&(object)->Lock) | |
176 | ||
177 | #else /* !MACH_KERNEL_PRIVATE */ | |
178 | ||
179 | struct shared_region_mapping ; | |
180 | ||
181 | #endif /* MACH_KERNEL_PRIVATE */ | |
182 | ||
183 | #define load_file_hash(file_object, size) \ | |
184 | ((((natural_t)file_object) & 0xffffff) % size) | |
185 | ||
186 | extern kern_return_t map_shared_file( | |
187 | int map_cnt, | |
188 | struct shared_file_mapping_np *mappings, | |
189 | memory_object_control_t file_control, | |
190 | memory_object_size_t file_size, | |
191 | shared_region_task_mappings_t sm_info, | |
192 | mach_vm_offset_t base_offset, | |
193 | mach_vm_offset_t *slide_p); | |
194 | ||
195 | extern kern_return_t shared_region_cleanup( | |
196 | unsigned int range_count, | |
197 | struct shared_region_range_np *ranges, | |
198 | shared_region_task_mappings_t sm_info); | |
199 | ||
200 | extern kern_return_t shared_region_mapping_info( | |
201 | shared_region_mapping_t shared_region, | |
202 | mach_port_t *text_region, | |
203 | vm_size_t *text_size, | |
204 | mach_port_t *data_region, | |
205 | vm_size_t *data_size, | |
206 | vm_offset_t *region_mappings, | |
207 | vm_offset_t *client_base, | |
208 | vm_offset_t *alternate_base, | |
209 | vm_offset_t *alternate_next, | |
210 | unsigned int *fs_base, | |
211 | unsigned int *system, | |
212 | int *flags, | |
213 | shared_region_mapping_t *next); | |
214 | ||
215 | extern kern_return_t shared_region_mapping_create( | |
216 | mach_port_t text_region, | |
217 | vm_size_t text_size, | |
218 | mach_port_t data_region, | |
219 | vm_size_t data_size, | |
220 | vm_offset_t region_mappings, | |
221 | vm_offset_t client_base, | |
222 | shared_region_mapping_t *shared_region, | |
223 | vm_offset_t alt_base, | |
224 | vm_offset_t alt_next, | |
225 | int fs_base, | |
226 | int system); | |
227 | ||
228 | extern kern_return_t shared_region_mapping_ref( | |
229 | shared_region_mapping_t shared_region); | |
230 | ||
231 | extern kern_return_t shared_region_mapping_dealloc( | |
232 | shared_region_mapping_t shared_region); | |
233 | ||
234 | extern kern_return_t shared_region_object_chain_attach( | |
235 | shared_region_mapping_t target_region, | |
236 | shared_region_mapping_t object_chain); | |
237 | ||
238 | extern void shared_region_object_chain_detached( | |
239 | shared_region_mapping_t target_region); | |
240 | ||
241 | extern kern_return_t vm_get_shared_region( | |
242 | task_t task, | |
243 | shared_region_mapping_t *shared_region); | |
244 | ||
245 | extern kern_return_t vm_set_shared_region( | |
246 | task_t task, | |
247 | shared_region_mapping_t shared_region); | |
248 | ||
249 | extern shared_region_mapping_t update_default_shared_region( | |
250 | shared_region_mapping_t new_system_region); | |
251 | ||
252 | extern shared_region_mapping_t lookup_default_shared_region( | |
253 | unsigned int fs_base, | |
254 | unsigned int system); | |
255 | ||
256 | extern void remove_default_shared_region( | |
257 | shared_region_mapping_t system_region); | |
258 | ||
259 | __private_extern__ void remove_default_shared_region_lock( | |
260 | shared_region_mapping_t system_region, | |
261 | int need_sfh_lock, | |
262 | int need_drl_lock); | |
263 | ||
264 | __private_extern__ struct load_struct *lsf_remove_regions_mappings_lock( | |
265 | shared_region_mapping_t region, | |
266 | shared_region_task_mappings_t sm_info, | |
267 | int need_lock); | |
268 | ||
269 | extern unsigned int lsf_mapping_pool_gauge(void); | |
270 | ||
271 | extern kern_return_t shared_file_create_system_region( | |
272 | shared_region_mapping_t *shared_region, | |
273 | int fs_base, | |
274 | int system); | |
275 | ||
276 | extern void remove_all_shared_regions(void); | |
277 | ||
278 | extern void shared_file_boot_time_init( | |
279 | unsigned int fs_base, | |
280 | unsigned int system); | |
281 | ||
282 | extern struct load_struct *lsf_remove_regions_mappings( | |
283 | shared_region_mapping_t region, | |
284 | shared_region_task_mappings_t sm_info); | |
285 | ||
286 | extern void mach_memory_entry_port_release(ipc_port_t port); | |
287 | extern void mach_destroy_memory_entry(ipc_port_t port); | |
288 | ||
289 | extern kern_return_t mach_memory_entry_purgable_control( | |
290 | ipc_port_t entry_port, | |
291 | vm_purgable_t control, | |
292 | int *state); | |
293 | ||
294 | extern kern_return_t mach_memory_entry_page_op( | |
295 | ipc_port_t entry_port, | |
296 | vm_object_offset_t offset, | |
297 | int ops, | |
298 | ppnum_t *phys_entry, | |
299 | int *flags); | |
300 | ||
301 | extern kern_return_t mach_memory_entry_range_op( | |
302 | ipc_port_t entry_port, | |
303 | vm_object_offset_t offset_beg, | |
304 | vm_object_offset_t offset_end, | |
305 | int ops, | |
306 | int *range); | |
307 | ||
308 | #endif /* KERNEL_PRIVATE */ | |
309 | ||
310 | #endif /* _VM_SHARED_MEMORY_SERVER_H_ */ |