]> git.saurik.com Git - apple/xnu.git/blob - osfmk/vm/vm_shared_memory_server.h
xnu-517.3.15.tar.gz
[apple/xnu.git] / osfmk / vm / vm_shared_memory_server.h
1 /*
2 * Copyright (c) 2002,2000 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
7 *
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
13 * file.
14 *
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.
22 *
23 * @APPLE_LICENSE_HEADER_END@
24 */
25 /*
26 *
27 * File: vm/vm_shared_memory_server.h
28 *
29 * protos and struct definitions for shared library
30 * server and interface
31 */
32
33 #ifndef _VM_SHARED_MEMORY_SERVER_H_
34 #define _VM_SHARED_MEMORY_SERVER_H_
35
36 #include <sys/appleapiopts.h>
37
38 #ifdef __APPLE_API_PRIVATE
39
40 #include <mach/vm_prot.h>
41 #include <mach/mach_types.h>
42 #include <mach/shared_memory_server.h>
43
44 #include <kern/kern_types.h>
45
46 extern mach_port_t shared_text_region_handle;
47 extern mach_port_t shared_data_region_handle;
48
49 struct shared_region_task_mappings {
50 mach_port_t text_region;
51 vm_size_t text_size;
52 mach_port_t data_region;
53 vm_size_t data_size;
54 vm_offset_t region_mappings;
55 vm_offset_t client_base;
56 vm_offset_t alternate_base;
57 vm_offset_t alternate_next;
58 unsigned int fs_base;
59 unsigned int system;
60 int flags;
61 vm_offset_t self;
62 };
63
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
67
68
69 /* defines for default environment, and co-resident systems */
70
71 #define ENV_DEFAULT_ROOT 0
72
73 typedef struct shared_region_task_mappings *shared_region_task_mappings_t;
74 typedef struct shared_region_mapping *shared_region_mapping_t;
75
76
77 #ifdef MACH_KERNEL_PRIVATE
78
79 #include <kern/queue.h>
80 #include <vm/vm_object.h>
81 #include <vm/memory_object.h>
82
83 extern vm_offset_t shared_file_mapping_array;
84
85 struct loaded_mapping {
86 vm_offset_t mapping_offset;
87 vm_size_t size;
88 vm_offset_t file_offset;
89 vm_prot_t protection; /* read/write/execute/COW/ZF */
90
91 struct loaded_mapping *next;
92 };
93
94 typedef struct loaded_mapping loaded_mapping_t;
95
96 struct load_struct {
97 queue_chain_t links;
98 shared_region_mapping_t regions_instance;
99 int depth;
100 int file_object;
101 vm_offset_t base_address;
102 int mapping_cnt;
103 loaded_mapping_t *mappings;
104 vm_offset_t file_offset; // start of file we mapped in
105 };
106
107 typedef struct load_struct load_struct_t;
108 typedef struct load_struct *load_struct_ptr_t;
109
110 struct load_file_ele {
111 union {
112 sf_mapping_t mapping;
113 load_struct_t element;
114 } u;
115 };
116
117 struct shared_file_info {
118 mutex_t lock; /* lock for the structure */
119 queue_head_t *hash; /* for later perf enhance */
120 int hash_size;
121 boolean_t hash_init;
122 };
123
124 typedef struct shared_file_info shared_file_info_t;
125
126 struct shared_region_object_chain {
127 shared_region_mapping_t object_chain_region;
128 int depth;
129 struct shared_region_object_chain *next;
130 };
131 typedef struct shared_region_object_chain *shared_region_object_chain_t;
132
133 /* address space shared region descriptor */
134 struct shared_region_mapping {
135 decl_mutex_data(, Lock) /* Synchronization */
136 int ref_count;
137 unsigned int fs_base;
138 unsigned int system;
139 mach_port_t text_region;
140 vm_size_t text_size;
141 mach_port_t data_region;
142 vm_size_t data_size;
143 vm_offset_t region_mappings;
144 vm_offset_t client_base;
145 vm_offset_t alternate_base;
146 vm_offset_t alternate_next;
147 int flags;
148 int depth;
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;
153 };
154
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)
159
160 #else /* !MACH_KERNEL_PRIVATE */
161
162 struct shared_region_mapping ;
163
164 #endif /* MACH_KERNEL_PRIVATE */
165
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,
170 int map_cnt,
171 sf_mapping_t *mappings,
172 memory_object_control_t file_control,
173 shared_region_task_mappings_t shared_region,
174 int *flags);
175
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,
188 int *flags,
189 shared_region_mapping_t *next);
190
191 extern kern_return_t shared_region_mapping_create(
192 mach_port_t text_region,
193 vm_size_t text_size,
194 mach_port_t data_region,
195 vm_size_t data_size,
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);
201
202 extern kern_return_t shared_region_mapping_ref(
203 shared_region_mapping_t shared_region);
204
205 extern kern_return_t shared_region_mapping_dealloc(
206 shared_region_mapping_t shared_region);
207
208 __private_extern__ kern_return_t shared_region_mapping_dealloc_lock(
209 shared_region_mapping_t shared_region,
210 int need_lock);
211
212 extern kern_return_t shared_region_object_chain_attach(
213 shared_region_mapping_t target_region,
214 shared_region_mapping_t object_chain);
215
216 extern kern_return_t vm_get_shared_region(
217 task_t task,
218 shared_region_mapping_t *shared_region);
219
220 extern kern_return_t vm_set_shared_region(
221 task_t task,
222 shared_region_mapping_t shared_region);
223
224 extern shared_region_mapping_t update_default_shared_region(
225 shared_region_mapping_t new_system_region);
226
227 extern shared_region_mapping_t lookup_default_shared_region(
228 unsigned int fs_base,
229 unsigned int system);
230
231 extern void remove_default_shared_region(
232 shared_region_mapping_t system_region);
233
234 __private_extern__ void remove_default_shared_region_lock(
235 shared_region_mapping_t system_region,
236 int need_lock);
237
238 extern unsigned int lsf_mapping_pool_gauge();
239
240 #endif /* __APPLE_API_PRIVATE */
241
242 #endif /* _VM_SHARED_MEMORY_SERVER_H_ */