]>
Commit | Line | Data |
---|---|---|
9bccf70c | 1 | /* |
91447636 | 2 | * Copyright (c) 2000-2004 Apple Computer, Inc. All rights reserved. |
9bccf70c A |
3 | * |
4 | * @APPLE_LICENSE_HEADER_START@ | |
5 | * | |
e5568f75 A |
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. | |
9bccf70c | 11 | * |
e5568f75 A |
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 | |
9bccf70c A |
14 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, |
15 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, | |
e5568f75 A |
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. | |
9bccf70c A |
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 | ||
91447636 | 33 | #ifdef KERNEL_PRIVATE |
9bccf70c A |
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 | ||
91447636 A |
41 | #if DEBUG |
42 | extern int shared_region_debug; | |
43 | #define SHARED_REGION_DEBUG(args) \ | |
44 | MACRO_BEGIN \ | |
45 | if (shared_region_debug) { \ | |
46 | kprintf args; \ | |
47 | } \ | |
48 | MACRO_END | |
49 | #else /* DEBUG */ | |
50 | #define SHARED_REGION_DEBUG(args) | |
51 | #endif /* DEBUG */ | |
52 | ||
9bccf70c A |
53 | extern mach_port_t shared_text_region_handle; |
54 | extern mach_port_t shared_data_region_handle; | |
55 | ||
56 | struct shared_region_task_mappings { | |
57 | mach_port_t text_region; | |
58 | vm_size_t text_size; | |
59 | mach_port_t data_region; | |
60 | vm_size_t data_size; | |
61 | vm_offset_t region_mappings; | |
62 | vm_offset_t client_base; | |
63 | vm_offset_t alternate_base; | |
64 | vm_offset_t alternate_next; | |
55e303ae A |
65 | unsigned int fs_base; |
66 | unsigned int system; | |
9bccf70c A |
67 | int flags; |
68 | vm_offset_t self; | |
69 | }; | |
70 | ||
55e303ae A |
71 | #define SHARED_REGION_SYSTEM 0x1 // Default env for system and fs_root |
72 | #define SHARED_REGION_FULL 0x2 // Shared regions are full | |
73 | #define SHARED_REGION_STALE 0x4 // Indicates no longer in default list | |
91447636 | 74 | #define SHARED_REGION_STANDALONE 0x10 // Shared region is not shared ! |
55e303ae A |
75 | |
76 | ||
77 | /* defines for default environment, and co-resident systems */ | |
78 | ||
79 | #define ENV_DEFAULT_ROOT 0 | |
9bccf70c A |
80 | |
81 | typedef struct shared_region_task_mappings *shared_region_task_mappings_t; | |
82 | typedef struct shared_region_mapping *shared_region_mapping_t; | |
83 | ||
9bccf70c A |
84 | #ifdef MACH_KERNEL_PRIVATE |
85 | ||
86 | #include <kern/queue.h> | |
87 | #include <vm/vm_object.h> | |
88 | #include <vm/memory_object.h> | |
89 | ||
90 | extern vm_offset_t shared_file_mapping_array; | |
91 | ||
92 | struct loaded_mapping { | |
93 | vm_offset_t mapping_offset; | |
94 | vm_size_t size; | |
95 | vm_offset_t file_offset; | |
96 | vm_prot_t protection; /* read/write/execute/COW/ZF */ | |
97 | ||
98 | struct loaded_mapping *next; | |
99 | }; | |
100 | ||
101 | typedef struct loaded_mapping loaded_mapping_t; | |
102 | ||
103 | struct load_struct { | |
104 | queue_chain_t links; | |
105 | shared_region_mapping_t regions_instance; | |
106 | int depth; | |
107 | int file_object; | |
108 | vm_offset_t base_address; | |
109 | int mapping_cnt; | |
110 | loaded_mapping_t *mappings; | |
55e303ae | 111 | vm_offset_t file_offset; // start of file we mapped in |
9bccf70c A |
112 | }; |
113 | ||
114 | typedef struct load_struct load_struct_t; | |
115 | typedef struct load_struct *load_struct_ptr_t; | |
116 | ||
117 | struct load_file_ele { | |
118 | union { | |
119 | sf_mapping_t mapping; | |
120 | load_struct_t element; | |
121 | } u; | |
122 | }; | |
123 | ||
124 | struct shared_file_info { | |
125 | mutex_t lock; /* lock for the structure */ | |
126 | queue_head_t *hash; /* for later perf enhance */ | |
127 | int hash_size; | |
128 | boolean_t hash_init; | |
129 | }; | |
130 | ||
131 | typedef struct shared_file_info shared_file_info_t; | |
132 | ||
133 | struct shared_region_object_chain { | |
134 | shared_region_mapping_t object_chain_region; | |
135 | int depth; | |
136 | struct shared_region_object_chain *next; | |
137 | }; | |
138 | typedef struct shared_region_object_chain *shared_region_object_chain_t; | |
139 | ||
140 | /* address space shared region descriptor */ | |
141 | struct shared_region_mapping { | |
142 | decl_mutex_data(, Lock) /* Synchronization */ | |
143 | int ref_count; | |
55e303ae A |
144 | unsigned int fs_base; |
145 | unsigned int system; | |
9bccf70c A |
146 | mach_port_t text_region; |
147 | vm_size_t text_size; | |
148 | mach_port_t data_region; | |
149 | vm_size_t data_size; | |
150 | vm_offset_t region_mappings; | |
151 | vm_offset_t client_base; | |
152 | vm_offset_t alternate_base; | |
153 | vm_offset_t alternate_next; | |
154 | int flags; | |
155 | int depth; | |
55e303ae | 156 | shared_region_mapping_t default_env_list; |
9bccf70c A |
157 | shared_region_object_chain_t object_chain; |
158 | shared_region_mapping_t self; | |
159 | shared_region_mapping_t next; | |
160 | }; | |
161 | ||
162 | #define shared_region_mapping_lock_init(object) \ | |
91447636 | 163 | mutex_init(&(object)->Lock, 0) |
9bccf70c A |
164 | #define shared_region_mapping_lock(object) mutex_lock(&(object)->Lock) |
165 | #define shared_region_mapping_unlock(object) mutex_unlock(&(object)->Lock) | |
166 | ||
167 | #else /* !MACH_KERNEL_PRIVATE */ | |
168 | ||
169 | struct shared_region_mapping ; | |
170 | ||
171 | #endif /* MACH_KERNEL_PRIVATE */ | |
172 | ||
91447636 A |
173 | #define load_file_hash(file_object, size) \ |
174 | ((((natural_t)file_object) & 0xffffff) % size) | |
175 | ||
9bccf70c A |
176 | extern kern_return_t copyin_shared_file( |
177 | vm_offset_t mapped_file, | |
178 | vm_size_t mapped_file_size, | |
179 | vm_offset_t *base_address, | |
180 | int map_cnt, | |
181 | sf_mapping_t *mappings, | |
182 | memory_object_control_t file_control, | |
183 | shared_region_task_mappings_t shared_region, | |
184 | int *flags); | |
185 | ||
91447636 A |
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 | ||
9bccf70c A |
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, | |
55e303ae A |
210 | unsigned int *fs_base, |
211 | unsigned int *system, | |
9bccf70c A |
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 | ||
226 | extern kern_return_t shared_region_mapping_ref( | |
227 | shared_region_mapping_t shared_region); | |
228 | ||
229 | extern kern_return_t shared_region_mapping_dealloc( | |
230 | shared_region_mapping_t shared_region); | |
231 | ||
232 | extern kern_return_t shared_region_object_chain_attach( | |
233 | shared_region_mapping_t target_region, | |
234 | shared_region_mapping_t object_chain); | |
235 | ||
91447636 A |
236 | extern void shared_region_object_chain_detached( |
237 | shared_region_mapping_t target_region); | |
238 | ||
9bccf70c A |
239 | extern kern_return_t vm_get_shared_region( |
240 | task_t task, | |
241 | shared_region_mapping_t *shared_region); | |
242 | ||
243 | extern kern_return_t vm_set_shared_region( | |
244 | task_t task, | |
245 | shared_region_mapping_t shared_region); | |
246 | ||
55e303ae A |
247 | extern shared_region_mapping_t update_default_shared_region( |
248 | shared_region_mapping_t new_system_region); | |
249 | ||
250 | extern shared_region_mapping_t lookup_default_shared_region( | |
251 | unsigned int fs_base, | |
252 | unsigned int system); | |
253 | ||
254 | extern void remove_default_shared_region( | |
255 | shared_region_mapping_t system_region); | |
256 | ||
257 | __private_extern__ void remove_default_shared_region_lock( | |
258 | shared_region_mapping_t system_region, | |
91447636 A |
259 | int need_sfh_lock, |
260 | int need_drl_lock); | |
261 | ||
262 | __private_extern__ struct load_struct *lsf_remove_regions_mappings_lock( | |
263 | shared_region_mapping_t region, | |
264 | shared_region_task_mappings_t sm_info, | |
55e303ae A |
265 | int need_lock); |
266 | ||
91447636 A |
267 | extern unsigned int lsf_mapping_pool_gauge(void); |
268 | ||
269 | extern kern_return_t shared_file_create_system_region( | |
270 | shared_region_mapping_t *shared_region); | |
271 | ||
272 | extern void remove_all_shared_regions(void); | |
273 | ||
274 | extern void shared_file_boot_time_init( | |
275 | unsigned int fs_base, | |
276 | unsigned int system); | |
277 | ||
278 | extern struct load_struct *lsf_remove_regions_mappings( | |
279 | shared_region_mapping_t region, | |
280 | shared_region_task_mappings_t sm_info); | |
281 | ||
282 | extern kern_return_t shared_region_mapping_set_alt_next( | |
283 | shared_region_mapping_t shared_region, | |
284 | vm_offset_t alt_next); | |
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); | |
9bccf70c | 293 | |
91447636 | 294 | #endif /* KERNEL_PRIVATE */ |
9bccf70c | 295 | |
91447636 | 296 | #endif /* _VM_SHARED_MEMORY_SERVER_H_ */ |