]> git.saurik.com Git - apple/xnu.git/blob - osfmk/vm/vm_shared_memory_server.h
31c6031fbf4f6532ffa5102b3f1e41e65ee068c7
[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 int flags;
59 vm_offset_t self;
60 };
61
62 #define SHARED_REGION_SYSTEM 0x1
63 #define SHARED_REGION_FULL 0x2
64
65 typedef struct shared_region_task_mappings *shared_region_task_mappings_t;
66 typedef struct shared_region_mapping *shared_region_mapping_t;
67
68
69 #ifdef MACH_KERNEL_PRIVATE
70
71 #include <kern/queue.h>
72 #include <vm/vm_object.h>
73 #include <vm/memory_object.h>
74
75 extern vm_offset_t shared_file_mapping_array;
76
77 struct loaded_mapping {
78 vm_offset_t mapping_offset;
79 vm_size_t size;
80 vm_offset_t file_offset;
81 vm_prot_t protection; /* read/write/execute/COW/ZF */
82
83 struct loaded_mapping *next;
84 };
85
86 typedef struct loaded_mapping loaded_mapping_t;
87
88 struct load_struct {
89 queue_chain_t links;
90 shared_region_mapping_t regions_instance;
91 int depth;
92 int file_object;
93 vm_offset_t base_address;
94 int mapping_cnt;
95 loaded_mapping_t *mappings;
96 };
97
98 typedef struct load_struct load_struct_t;
99 typedef struct load_struct *load_struct_ptr_t;
100
101 struct load_file_ele {
102 union {
103 sf_mapping_t mapping;
104 load_struct_t element;
105 } u;
106 };
107
108 struct shared_file_info {
109 mutex_t lock; /* lock for the structure */
110 queue_head_t *hash; /* for later perf enhance */
111 int hash_size;
112 boolean_t hash_init;
113 };
114
115 typedef struct shared_file_info shared_file_info_t;
116
117 struct shared_region_object_chain {
118 shared_region_mapping_t object_chain_region;
119 int depth;
120 struct shared_region_object_chain *next;
121 };
122 typedef struct shared_region_object_chain *shared_region_object_chain_t;
123
124 /* address space shared region descriptor */
125 struct shared_region_mapping {
126 decl_mutex_data(, Lock) /* Synchronization */
127 int ref_count;
128 mach_port_t text_region;
129 vm_size_t text_size;
130 mach_port_t data_region;
131 vm_size_t data_size;
132 vm_offset_t region_mappings;
133 vm_offset_t client_base;
134 vm_offset_t alternate_base;
135 vm_offset_t alternate_next;
136 int flags;
137 int depth;
138 shared_region_object_chain_t object_chain;
139 shared_region_mapping_t self;
140 shared_region_mapping_t next;
141 };
142
143 #define shared_region_mapping_lock_init(object) \
144 mutex_init(&(object)->Lock, ETAP_VM_OBJ)
145 #define shared_region_mapping_lock(object) mutex_lock(&(object)->Lock)
146 #define shared_region_mapping_unlock(object) mutex_unlock(&(object)->Lock)
147
148 #else /* !MACH_KERNEL_PRIVATE */
149
150 struct shared_region_mapping ;
151
152 #endif /* MACH_KERNEL_PRIVATE */
153
154 extern kern_return_t copyin_shared_file(
155 vm_offset_t mapped_file,
156 vm_size_t mapped_file_size,
157 vm_offset_t *base_address,
158 int map_cnt,
159 sf_mapping_t *mappings,
160 memory_object_control_t file_control,
161 shared_region_task_mappings_t shared_region,
162 int *flags);
163
164 extern kern_return_t shared_region_mapping_info(
165 shared_region_mapping_t shared_region,
166 mach_port_t *text_region,
167 vm_size_t *text_size,
168 mach_port_t *data_region,
169 vm_size_t *data_size,
170 vm_offset_t *region_mappings,
171 vm_offset_t *client_base,
172 vm_offset_t *alternate_base,
173 vm_offset_t *alternate_next,
174 int *flags,
175 shared_region_mapping_t *next);
176
177 extern kern_return_t shared_region_mapping_create(
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 shared_region_mapping_t *shared_region,
185 vm_offset_t alt_base,
186 vm_offset_t alt_next);
187
188 extern kern_return_t shared_region_mapping_ref(
189 shared_region_mapping_t shared_region);
190
191 extern kern_return_t shared_region_mapping_dealloc(
192 shared_region_mapping_t shared_region);
193
194 extern kern_return_t shared_region_object_chain_attach(
195 shared_region_mapping_t target_region,
196 shared_region_mapping_t object_chain);
197
198 extern kern_return_t vm_get_shared_region(
199 task_t task,
200 shared_region_mapping_t *shared_region);
201
202 extern kern_return_t vm_set_shared_region(
203 task_t task,
204 shared_region_mapping_t shared_region);
205
206 extern unsigned int lsf_mapping_pool_gauge();
207
208 #endif /* __APPLE_API_PRIVATE */
209
210 #endif /* _VM_SHARED_MEMORY_SERVER_H_ */