]> git.saurik.com Git - apple/xnu.git/blob - osfmk/vm/vm_shared_memory_server.h
fcf2622be30b4c194074281d8f3fa9d3cac4f18b
[apple/xnu.git] / osfmk / vm / vm_shared_memory_server.h
1 /*
2 * Copyright (c) 2000-2004 Apple Computer, 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_memory_server.h
26 *
27 * protos and struct definitions for shared library
28 * server and interface
29 */
30
31 #ifndef _VM_SHARED_MEMORY_SERVER_H_
32 #define _VM_SHARED_MEMORY_SERVER_H_
33
34 #ifdef KERNEL_PRIVATE
35
36 #include <mach/vm_prot.h>
37 #include <mach/mach_types.h>
38 #include <mach/shared_memory_server.h>
39
40 #include <kern/kern_types.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 mach_port_t shared_text_region_handle;
55 extern mach_port_t shared_data_region_handle;
56
57 struct shared_region_task_mappings {
58 mach_port_t text_region;
59 vm_size_t text_size;
60 mach_port_t data_region;
61 vm_size_t data_size;
62 vm_offset_t region_mappings;
63 vm_offset_t client_base;
64 vm_offset_t alternate_base;
65 vm_offset_t alternate_next;
66 unsigned int fs_base;
67 unsigned int system;
68 int flags;
69 vm_offset_t self;
70 };
71
72 #define SHARED_REGION_SYSTEM 0x1 // Default env for system and fs_root
73 #define SHARED_REGION_FULL 0x2 // Shared regions are full
74 #define SHARED_REGION_STALE 0x4 // Indicates no longer in default list
75 #define SHARED_REGION_STANDALONE 0x10 // Shared region is not shared !
76
77
78 /* defines for default environment, and co-resident systems */
79
80 #define ENV_DEFAULT_ROOT 0
81
82 typedef struct shared_region_task_mappings *shared_region_task_mappings_t;
83 typedef struct shared_region_mapping *shared_region_mapping_t;
84
85 #ifdef MACH_KERNEL_PRIVATE
86
87 #include <kern/queue.h>
88 #include <vm/vm_object.h>
89 #include <vm/memory_object.h>
90
91 extern vm_offset_t shared_file_mapping_array;
92
93 struct loaded_mapping {
94 vm_offset_t mapping_offset;
95 vm_size_t size;
96 vm_offset_t file_offset;
97 vm_prot_t protection; /* read/write/execute/COW/ZF */
98
99 struct loaded_mapping *next;
100 };
101
102 typedef struct loaded_mapping loaded_mapping_t;
103
104 struct load_struct {
105 queue_chain_t links;
106 shared_region_mapping_t regions_instance;
107 int depth;
108 int file_object;
109 vm_offset_t base_address;
110 int mapping_cnt;
111 loaded_mapping_t *mappings;
112 vm_offset_t file_offset; // start of file we mapped in
113 };
114
115 typedef struct load_struct load_struct_t;
116 typedef struct load_struct *load_struct_ptr_t;
117
118 struct load_file_ele {
119 union {
120 sf_mapping_t mapping;
121 load_struct_t element;
122 } u;
123 };
124
125 struct shared_file_info {
126 mutex_t lock; /* lock for the structure */
127 queue_head_t *hash; /* for later perf enhance */
128 int hash_size;
129 boolean_t hash_init;
130 };
131
132 typedef struct shared_file_info shared_file_info_t;
133
134 struct shared_region_object_chain {
135 shared_region_mapping_t object_chain_region;
136 int depth;
137 struct shared_region_object_chain *next;
138 };
139 typedef struct shared_region_object_chain *shared_region_object_chain_t;
140
141 /* address space shared region descriptor */
142 struct shared_region_mapping {
143 decl_mutex_data(, Lock) /* Synchronization */
144 int ref_count;
145 unsigned int fs_base;
146 unsigned int system;
147 mach_port_t text_region;
148 vm_size_t text_size;
149 mach_port_t data_region;
150 vm_size_t data_size;
151 vm_offset_t region_mappings;
152 vm_offset_t client_base;
153 vm_offset_t alternate_base;
154 vm_offset_t alternate_next;
155 int flags;
156 int depth;
157 shared_region_mapping_t default_env_list;
158 shared_region_object_chain_t object_chain;
159 shared_region_mapping_t self;
160 shared_region_mapping_t next;
161 };
162
163 #define shared_region_mapping_lock_init(object) \
164 mutex_init(&(object)->Lock, 0)
165 #define shared_region_mapping_lock(object) mutex_lock(&(object)->Lock)
166 #define shared_region_mapping_unlock(object) mutex_unlock(&(object)->Lock)
167
168 #else /* !MACH_KERNEL_PRIVATE */
169
170 struct shared_region_mapping ;
171
172 #endif /* MACH_KERNEL_PRIVATE */
173
174 #define load_file_hash(file_object, size) \
175 ((((natural_t)file_object) & 0xffffff) % size)
176
177 extern kern_return_t copyin_shared_file(
178 vm_offset_t mapped_file,
179 vm_size_t mapped_file_size,
180 vm_offset_t *base_address,
181 int map_cnt,
182 sf_mapping_t *mappings,
183 memory_object_control_t file_control,
184 shared_region_task_mappings_t shared_region,
185 int *flags);
186
187 extern kern_return_t map_shared_file(
188 int map_cnt,
189 struct shared_file_mapping_np *mappings,
190 memory_object_control_t file_control,
191 memory_object_size_t file_size,
192 shared_region_task_mappings_t sm_info,
193 mach_vm_offset_t base_offset,
194 mach_vm_offset_t *slide_p);
195
196 extern kern_return_t shared_region_cleanup(
197 unsigned int range_count,
198 struct shared_region_range_np *ranges,
199 shared_region_task_mappings_t sm_info);
200
201 extern kern_return_t shared_region_mapping_info(
202 shared_region_mapping_t shared_region,
203 mach_port_t *text_region,
204 vm_size_t *text_size,
205 mach_port_t *data_region,
206 vm_size_t *data_size,
207 vm_offset_t *region_mappings,
208 vm_offset_t *client_base,
209 vm_offset_t *alternate_base,
210 vm_offset_t *alternate_next,
211 unsigned int *fs_base,
212 unsigned int *system,
213 int *flags,
214 shared_region_mapping_t *next);
215
216 extern kern_return_t shared_region_mapping_create(
217 mach_port_t text_region,
218 vm_size_t text_size,
219 mach_port_t data_region,
220 vm_size_t data_size,
221 vm_offset_t region_mappings,
222 vm_offset_t client_base,
223 shared_region_mapping_t *shared_region,
224 vm_offset_t alt_base,
225 vm_offset_t alt_next);
226
227 extern kern_return_t shared_region_mapping_ref(
228 shared_region_mapping_t shared_region);
229
230 extern kern_return_t shared_region_mapping_dealloc(
231 shared_region_mapping_t shared_region);
232
233 extern kern_return_t shared_region_object_chain_attach(
234 shared_region_mapping_t target_region,
235 shared_region_mapping_t object_chain);
236
237 extern void shared_region_object_chain_detached(
238 shared_region_mapping_t target_region);
239
240 extern kern_return_t vm_get_shared_region(
241 task_t task,
242 shared_region_mapping_t *shared_region);
243
244 extern kern_return_t vm_set_shared_region(
245 task_t task,
246 shared_region_mapping_t shared_region);
247
248 extern shared_region_mapping_t update_default_shared_region(
249 shared_region_mapping_t new_system_region);
250
251 extern shared_region_mapping_t lookup_default_shared_region(
252 unsigned int fs_base,
253 unsigned int system);
254
255 extern void remove_default_shared_region(
256 shared_region_mapping_t system_region);
257
258 __private_extern__ void remove_default_shared_region_lock(
259 shared_region_mapping_t system_region,
260 int need_sfh_lock,
261 int need_drl_lock);
262
263 __private_extern__ struct load_struct *lsf_remove_regions_mappings_lock(
264 shared_region_mapping_t region,
265 shared_region_task_mappings_t sm_info,
266 int need_lock);
267
268 extern unsigned int lsf_mapping_pool_gauge(void);
269
270 extern kern_return_t shared_file_create_system_region(
271 shared_region_mapping_t *shared_region);
272
273 extern void remove_all_shared_regions(void);
274
275 extern void shared_file_boot_time_init(
276 unsigned int fs_base,
277 unsigned int system);
278
279 extern struct load_struct *lsf_remove_regions_mappings(
280 shared_region_mapping_t region,
281 shared_region_task_mappings_t sm_info);
282
283 extern kern_return_t shared_region_mapping_set_alt_next(
284 shared_region_mapping_t shared_region,
285 vm_offset_t alt_next);
286
287 extern void mach_memory_entry_port_release(ipc_port_t port);
288 extern void mach_destroy_memory_entry(ipc_port_t port);
289
290 extern kern_return_t mach_memory_entry_purgable_control(
291 ipc_port_t entry_port,
292 vm_purgable_t control,
293 int *state);
294
295 #endif /* KERNEL_PRIVATE */
296
297 #endif /* _VM_SHARED_MEMORY_SERVER_H_ */