2 * Copyright (c) 2000-2004 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
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.
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
20 * @APPLE_LICENSE_HEADER_END@
24 * File: vm/vm_shared_memory_server.h
26 * protos and struct definitions for shared library
27 * server and interface
30 #ifndef _VM_SHARED_MEMORY_SERVER_H_
31 #define _VM_SHARED_MEMORY_SERVER_H_
35 #include <mach/vm_prot.h>
36 #include <mach/mach_types.h>
37 #include <mach/shared_memory_server.h>
39 #include <kern/kern_types.h>
42 extern int shared_region_debug
;
43 #define SHARED_REGION_DEBUG(args) \
45 if (shared_region_debug) { \
50 #define SHARED_REGION_DEBUG(args)
53 extern mach_port_t shared_text_region_handle
;
54 extern mach_port_t shared_data_region_handle
;
56 struct shared_region_task_mappings
{
57 mach_port_t text_region
;
59 mach_port_t data_region
;
61 vm_offset_t region_mappings
;
62 vm_offset_t client_base
;
63 vm_offset_t alternate_base
;
64 vm_offset_t alternate_next
;
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
74 #define SHARED_REGION_STANDALONE 0x10 // Shared region is not shared !
77 /* defines for default environment, and co-resident systems */
79 #define ENV_DEFAULT_ROOT 0
81 typedef struct shared_region_task_mappings
*shared_region_task_mappings_t
;
82 typedef struct shared_region_mapping
*shared_region_mapping_t
;
84 #ifdef MACH_KERNEL_PRIVATE
86 #include <kern/queue.h>
87 #include <vm/vm_object.h>
88 #include <vm/memory_object.h>
90 extern vm_offset_t shared_file_mapping_array
;
92 struct loaded_mapping
{
93 vm_offset_t mapping_offset
;
95 vm_offset_t file_offset
;
96 vm_prot_t protection
; /* read/write/execute/COW/ZF */
98 struct loaded_mapping
*next
;
101 typedef struct loaded_mapping loaded_mapping_t
;
105 shared_region_mapping_t regions_instance
;
108 vm_offset_t base_address
;
110 loaded_mapping_t
*mappings
;
111 vm_offset_t file_offset
; // start of file we mapped in
114 typedef struct load_struct load_struct_t
;
115 typedef struct load_struct
*load_struct_ptr_t
;
117 struct load_file_ele
{
119 sf_mapping_t mapping
;
120 load_struct_t element
;
124 struct shared_file_info
{
125 mutex_t lock
; /* lock for the structure */
126 queue_head_t
*hash
; /* for later perf enhance */
131 typedef struct shared_file_info shared_file_info_t
;
133 struct shared_region_object_chain
{
134 shared_region_mapping_t object_chain_region
;
136 struct shared_region_object_chain
*next
;
138 typedef struct shared_region_object_chain
*shared_region_object_chain_t
;
140 /* address space shared region descriptor */
141 struct shared_region_mapping
{
142 decl_mutex_data(, Lock
) /* Synchronization */
144 unsigned int fs_base
;
146 mach_port_t text_region
;
148 mach_port_t data_region
;
150 vm_offset_t region_mappings
;
151 vm_offset_t client_base
;
152 vm_offset_t alternate_base
;
153 vm_offset_t alternate_next
;
156 shared_region_mapping_t default_env_list
;
157 shared_region_object_chain_t object_chain
;
158 shared_region_mapping_t self
;
159 shared_region_mapping_t next
;
162 #define shared_region_mapping_lock_init(object) \
163 mutex_init(&(object)->Lock, 0)
164 #define shared_region_mapping_lock(object) mutex_lock(&(object)->Lock)
165 #define shared_region_mapping_unlock(object) mutex_unlock(&(object)->Lock)
167 #else /* !MACH_KERNEL_PRIVATE */
169 struct shared_region_mapping
;
171 #endif /* MACH_KERNEL_PRIVATE */
173 #define load_file_hash(file_object, size) \
174 ((((natural_t)file_object) & 0xffffff) % size)
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
,
181 sf_mapping_t
*mappings
,
182 memory_object_control_t file_control
,
183 shared_region_task_mappings_t shared_region
,
186 extern kern_return_t
map_shared_file(
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
);
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
);
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
,
213 shared_region_mapping_t
*next
);
215 extern kern_return_t
shared_region_mapping_create(
216 mach_port_t text_region
,
218 mach_port_t data_region
,
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
);
226 extern kern_return_t
shared_region_mapping_ref(
227 shared_region_mapping_t shared_region
);
229 extern kern_return_t
shared_region_mapping_dealloc(
230 shared_region_mapping_t shared_region
);
232 extern kern_return_t
shared_region_object_chain_attach(
233 shared_region_mapping_t target_region
,
234 shared_region_mapping_t object_chain
);
236 extern void shared_region_object_chain_detached(
237 shared_region_mapping_t target_region
);
239 extern kern_return_t
vm_get_shared_region(
241 shared_region_mapping_t
*shared_region
);
243 extern kern_return_t
vm_set_shared_region(
245 shared_region_mapping_t shared_region
);
247 extern shared_region_mapping_t
update_default_shared_region(
248 shared_region_mapping_t new_system_region
);
250 extern shared_region_mapping_t
lookup_default_shared_region(
251 unsigned int fs_base
,
252 unsigned int system
);
254 extern void remove_default_shared_region(
255 shared_region_mapping_t system_region
);
257 __private_extern__
void remove_default_shared_region_lock(
258 shared_region_mapping_t system_region
,
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
,
267 extern unsigned int lsf_mapping_pool_gauge(void);
269 extern kern_return_t
shared_file_create_system_region(
270 shared_region_mapping_t
*shared_region
);
272 extern void remove_all_shared_regions(void);
274 extern void shared_file_boot_time_init(
275 unsigned int fs_base
,
276 unsigned int system
);
278 extern struct load_struct
*lsf_remove_regions_mappings(
279 shared_region_mapping_t region
,
280 shared_region_task_mappings_t sm_info
);
282 extern kern_return_t
shared_region_mapping_set_alt_next(
283 shared_region_mapping_t shared_region
,
284 vm_offset_t alt_next
);
286 extern void mach_memory_entry_port_release(ipc_port_t port
);
287 extern void mach_destroy_memory_entry(ipc_port_t port
);
289 extern kern_return_t
mach_memory_entry_purgable_control(
290 ipc_port_t entry_port
,
291 vm_purgable_t control
,
294 #endif /* KERNEL_PRIVATE */
296 #endif /* _VM_SHARED_MEMORY_SERVER_H_ */