2 * Copyright (c) 2000-2004 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
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
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.
21 * @APPLE_LICENSE_HEADER_END@
25 * File: vm/vm_shared_memory_server.h
27 * protos and struct definitions for shared library
28 * server and interface
31 #ifndef _VM_SHARED_MEMORY_SERVER_H_
32 #define _VM_SHARED_MEMORY_SERVER_H_
36 #include <mach/vm_prot.h>
37 #include <mach/mach_types.h>
38 #include <mach/shared_memory_server.h>
40 #include <kern/kern_types.h>
43 extern int shared_region_debug
;
44 #define SHARED_REGION_DEBUG(args) \
46 if (shared_region_debug) { \
51 #define SHARED_REGION_DEBUG(args)
54 extern mach_port_t shared_text_region_handle
;
55 extern mach_port_t shared_data_region_handle
;
57 struct shared_region_task_mappings
{
58 mach_port_t text_region
;
60 mach_port_t data_region
;
62 vm_offset_t region_mappings
;
63 vm_offset_t client_base
;
64 vm_offset_t alternate_base
;
65 vm_offset_t alternate_next
;
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 !
78 /* defines for default environment, and co-resident systems */
80 #define ENV_DEFAULT_ROOT 0
82 typedef struct shared_region_task_mappings
*shared_region_task_mappings_t
;
83 typedef struct shared_region_mapping
*shared_region_mapping_t
;
85 #ifdef MACH_KERNEL_PRIVATE
87 #include <kern/queue.h>
88 #include <vm/vm_object.h>
89 #include <vm/memory_object.h>
91 extern vm_offset_t shared_file_mapping_array
;
93 struct loaded_mapping
{
94 vm_offset_t mapping_offset
;
96 vm_offset_t file_offset
;
97 vm_prot_t protection
; /* read/write/execute/COW/ZF */
99 struct loaded_mapping
*next
;
102 typedef struct loaded_mapping loaded_mapping_t
;
106 shared_region_mapping_t regions_instance
;
109 vm_offset_t base_address
;
111 loaded_mapping_t
*mappings
;
112 vm_offset_t file_offset
; // start of file we mapped in
115 typedef struct load_struct load_struct_t
;
116 typedef struct load_struct
*load_struct_ptr_t
;
118 struct load_file_ele
{
120 sf_mapping_t mapping
;
121 load_struct_t element
;
125 struct shared_file_info
{
126 mutex_t lock
; /* lock for the structure */
127 queue_head_t
*hash
; /* for later perf enhance */
132 typedef struct shared_file_info shared_file_info_t
;
134 struct shared_region_object_chain
{
135 shared_region_mapping_t object_chain_region
;
137 struct shared_region_object_chain
*next
;
139 typedef struct shared_region_object_chain
*shared_region_object_chain_t
;
141 /* address space shared region descriptor */
142 struct shared_region_mapping
{
143 decl_mutex_data(, Lock
) /* Synchronization */
145 unsigned int fs_base
;
147 mach_port_t text_region
;
149 mach_port_t data_region
;
151 vm_offset_t region_mappings
;
152 vm_offset_t client_base
;
153 vm_offset_t alternate_base
;
154 vm_offset_t alternate_next
;
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
;
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)
168 #else /* !MACH_KERNEL_PRIVATE */
170 struct shared_region_mapping
;
172 #endif /* MACH_KERNEL_PRIVATE */
174 #define load_file_hash(file_object, size) \
175 ((((natural_t)file_object) & 0xffffff) % size)
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
,
182 sf_mapping_t
*mappings
,
183 memory_object_control_t file_control
,
184 shared_region_task_mappings_t shared_region
,
187 extern kern_return_t
map_shared_file(
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
);
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
);
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
,
214 shared_region_mapping_t
*next
);
216 extern kern_return_t
shared_region_mapping_create(
217 mach_port_t text_region
,
219 mach_port_t data_region
,
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
);
227 extern kern_return_t
shared_region_mapping_ref(
228 shared_region_mapping_t shared_region
);
230 extern kern_return_t
shared_region_mapping_dealloc(
231 shared_region_mapping_t shared_region
);
233 extern kern_return_t
shared_region_object_chain_attach(
234 shared_region_mapping_t target_region
,
235 shared_region_mapping_t object_chain
);
237 extern void shared_region_object_chain_detached(
238 shared_region_mapping_t target_region
);
240 extern kern_return_t
vm_get_shared_region(
242 shared_region_mapping_t
*shared_region
);
244 extern kern_return_t
vm_set_shared_region(
246 shared_region_mapping_t shared_region
);
248 extern shared_region_mapping_t
update_default_shared_region(
249 shared_region_mapping_t new_system_region
);
251 extern shared_region_mapping_t
lookup_default_shared_region(
252 unsigned int fs_base
,
253 unsigned int system
);
255 extern void remove_default_shared_region(
256 shared_region_mapping_t system_region
);
258 __private_extern__
void remove_default_shared_region_lock(
259 shared_region_mapping_t system_region
,
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
,
268 extern unsigned int lsf_mapping_pool_gauge(void);
270 extern kern_return_t
shared_file_create_system_region(
271 shared_region_mapping_t
*shared_region
);
273 extern void remove_all_shared_regions(void);
275 extern void shared_file_boot_time_init(
276 unsigned int fs_base
,
277 unsigned int system
);
279 extern struct load_struct
*lsf_remove_regions_mappings(
280 shared_region_mapping_t region
,
281 shared_region_task_mappings_t sm_info
);
283 extern kern_return_t
shared_region_mapping_set_alt_next(
284 shared_region_mapping_t shared_region
,
285 vm_offset_t alt_next
);
287 extern void mach_memory_entry_port_release(ipc_port_t port
);
288 extern void mach_destroy_memory_entry(ipc_port_t port
);
290 extern kern_return_t
mach_memory_entry_purgable_control(
291 ipc_port_t entry_port
,
292 vm_purgable_t control
,
295 #endif /* KERNEL_PRIVATE */
297 #endif /* _VM_SHARED_MEMORY_SERVER_H_ */