2 * Copyright (c) 2002,2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
8 * This file contains Original Code and/or Modifications of Original Code
9 * as defined in and that are subject to the Apple Public Source License
10 * Version 2.0 (the 'License'). You may not use this file except in
11 * compliance with the License. Please obtain a copy of the License at
12 * http://www.opensource.apple.com/apsl/ and read it before using this
15 * The Original Code and all software distributed under the License are
16 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
17 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
18 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
20 * Please see the License for the specific language governing rights and
21 * limitations under the License.
23 * @APPLE_LICENSE_HEADER_END@
27 * File: vm/vm_shared_memory_server.h
29 * protos and struct definitions for shared library
30 * server and interface
33 #ifndef _VM_SHARED_MEMORY_SERVER_H_
34 #define _VM_SHARED_MEMORY_SERVER_H_
36 #include <sys/appleapiopts.h>
38 #ifdef __APPLE_API_PRIVATE
40 #include <mach/vm_prot.h>
41 #include <mach/mach_types.h>
42 #include <mach/shared_memory_server.h>
44 #include <kern/kern_types.h>
46 extern mach_port_t shared_text_region_handle
;
47 extern mach_port_t shared_data_region_handle
;
49 struct shared_region_task_mappings
{
50 mach_port_t text_region
;
52 mach_port_t data_region
;
54 vm_offset_t region_mappings
;
55 vm_offset_t client_base
;
56 vm_offset_t alternate_base
;
57 vm_offset_t alternate_next
;
64 #define SHARED_REGION_SYSTEM 0x1 // Default env for system and fs_root
65 #define SHARED_REGION_FULL 0x2 // Shared regions are full
66 #define SHARED_REGION_STALE 0x4 // Indicates no longer in default list
69 /* defines for default environment, and co-resident systems */
71 #define ENV_DEFAULT_ROOT 0
73 typedef struct shared_region_task_mappings
*shared_region_task_mappings_t
;
74 typedef struct shared_region_mapping
*shared_region_mapping_t
;
77 #ifdef MACH_KERNEL_PRIVATE
79 #include <kern/queue.h>
80 #include <vm/vm_object.h>
81 #include <vm/memory_object.h>
83 extern vm_offset_t shared_file_mapping_array
;
85 struct loaded_mapping
{
86 vm_offset_t mapping_offset
;
88 vm_offset_t file_offset
;
89 vm_prot_t protection
; /* read/write/execute/COW/ZF */
91 struct loaded_mapping
*next
;
94 typedef struct loaded_mapping loaded_mapping_t
;
98 shared_region_mapping_t regions_instance
;
101 vm_offset_t base_address
;
103 loaded_mapping_t
*mappings
;
104 vm_offset_t file_offset
; // start of file we mapped in
107 typedef struct load_struct load_struct_t
;
108 typedef struct load_struct
*load_struct_ptr_t
;
110 struct load_file_ele
{
112 sf_mapping_t mapping
;
113 load_struct_t element
;
117 struct shared_file_info
{
118 mutex_t lock
; /* lock for the structure */
119 queue_head_t
*hash
; /* for later perf enhance */
124 typedef struct shared_file_info shared_file_info_t
;
126 struct shared_region_object_chain
{
127 shared_region_mapping_t object_chain_region
;
129 struct shared_region_object_chain
*next
;
131 typedef struct shared_region_object_chain
*shared_region_object_chain_t
;
133 /* address space shared region descriptor */
134 struct shared_region_mapping
{
135 decl_mutex_data(, Lock
) /* Synchronization */
137 unsigned int fs_base
;
139 mach_port_t text_region
;
141 mach_port_t data_region
;
143 vm_offset_t region_mappings
;
144 vm_offset_t client_base
;
145 vm_offset_t alternate_base
;
146 vm_offset_t alternate_next
;
149 shared_region_mapping_t default_env_list
;
150 shared_region_object_chain_t object_chain
;
151 shared_region_mapping_t self
;
152 shared_region_mapping_t next
;
155 #define shared_region_mapping_lock_init(object) \
156 mutex_init(&(object)->Lock, ETAP_VM_OBJ)
157 #define shared_region_mapping_lock(object) mutex_lock(&(object)->Lock)
158 #define shared_region_mapping_unlock(object) mutex_unlock(&(object)->Lock)
160 #else /* !MACH_KERNEL_PRIVATE */
162 struct shared_region_mapping
;
164 #endif /* MACH_KERNEL_PRIVATE */
166 extern kern_return_t
copyin_shared_file(
167 vm_offset_t mapped_file
,
168 vm_size_t mapped_file_size
,
169 vm_offset_t
*base_address
,
171 sf_mapping_t
*mappings
,
172 memory_object_control_t file_control
,
173 shared_region_task_mappings_t shared_region
,
176 extern kern_return_t
shared_region_mapping_info(
177 shared_region_mapping_t shared_region
,
178 mach_port_t
*text_region
,
179 vm_size_t
*text_size
,
180 mach_port_t
*data_region
,
181 vm_size_t
*data_size
,
182 vm_offset_t
*region_mappings
,
183 vm_offset_t
*client_base
,
184 vm_offset_t
*alternate_base
,
185 vm_offset_t
*alternate_next
,
186 unsigned int *fs_base
,
187 unsigned int *system
,
189 shared_region_mapping_t
*next
);
191 extern kern_return_t
shared_region_mapping_create(
192 mach_port_t text_region
,
194 mach_port_t data_region
,
196 vm_offset_t region_mappings
,
197 vm_offset_t client_base
,
198 shared_region_mapping_t
*shared_region
,
199 vm_offset_t alt_base
,
200 vm_offset_t alt_next
);
202 extern kern_return_t
shared_region_mapping_ref(
203 shared_region_mapping_t shared_region
);
205 extern kern_return_t
shared_region_mapping_dealloc(
206 shared_region_mapping_t shared_region
);
208 __private_extern__ kern_return_t
shared_region_mapping_dealloc_lock(
209 shared_region_mapping_t shared_region
,
212 extern kern_return_t
shared_region_object_chain_attach(
213 shared_region_mapping_t target_region
,
214 shared_region_mapping_t object_chain
);
216 extern kern_return_t
vm_get_shared_region(
218 shared_region_mapping_t
*shared_region
);
220 extern kern_return_t
vm_set_shared_region(
222 shared_region_mapping_t shared_region
);
224 extern shared_region_mapping_t
update_default_shared_region(
225 shared_region_mapping_t new_system_region
);
227 extern shared_region_mapping_t
lookup_default_shared_region(
228 unsigned int fs_base
,
229 unsigned int system
);
231 extern void remove_default_shared_region(
232 shared_region_mapping_t system_region
);
234 __private_extern__
void remove_default_shared_region_lock(
235 shared_region_mapping_t system_region
,
238 extern unsigned int lsf_mapping_pool_gauge();
240 #endif /* __APPLE_API_PRIVATE */
242 #endif /* _VM_SHARED_MEMORY_SERVER_H_ */