]> git.saurik.com Git - apple/xnu.git/blob - osfmk/mach/shared_memory_server.h
8d324489e1b451d9ad14fccda3e02ab1656d21dd
[apple/xnu.git] / osfmk / mach / shared_memory_server.h
1 /*
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
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.
11 *
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
18 * under the License.
19 *
20 * @APPLE_LICENSE_HEADER_END@
21 */
22 /*
23 *
24 * File: kern/shared_memory_server.h
25 *
26 * protos and struct definitions for shared library
27 * server and interface
28 */
29 #ifndef _SHARED_MEMORY_SERVER_H_
30 #define _SHARED_MEMORY_SERVER_H_
31
32 #define SHARED_TEXT_REGION_SIZE 0x10000000
33 #define SHARED_DATA_REGION_SIZE 0x10000000
34 /*
35 * Note: the two masks below are useful because the assumption is
36 * made that these shared regions will always be mapped on natural boundaries
37 * i.e. if the size is 0x10000000 the object can be mapped at
38 * 0x20000000, or 0x30000000, but not 0x1000000
39 */
40 #define SHARED_TEXT_REGION_MASK 0xFFFFFFF
41 #define SHARED_DATA_REGION_MASK 0xFFFFFFF
42
43 #define SHARED_ALTERNATE_LOAD_BASE 0x9000000
44
45 #include <mach/vm_prot.h>
46 #ifndef MACH_KERNEL
47 #include <mach/mach.h>
48 #else
49 #include <vm/vm_map.h>
50 #endif
51
52 #ifdef MACH_KERNEL_PRIVATE
53
54 #include <kern/queue.h>
55 #include <vm/vm_object.h>
56
57 extern ipc_port_t shared_text_region_handle;
58 extern ipc_port_t shared_data_region_handle;
59 #else /* MACH_KERNEL_PRIVATE */
60
61 #ifdef KERNEL_PRIVATE
62 extern mach_port_t shared_text_region_handle;
63 extern mach_port_t shared_data_region_handle;
64 #endif
65 #endif /* MACH_KERNEL_PRIVATE*/
66
67 #ifdef KERNEL_PRIVATE
68
69 extern vm_offset_t shared_file_mapping_array;
70
71
72 struct shared_region_task_mappings {
73 ipc_port_t text_region;
74 vm_size_t text_size;
75 ipc_port_t data_region;
76 vm_size_t data_size;
77 vm_offset_t region_mappings;
78 vm_offset_t client_base;
79 vm_offset_t alternate_base;
80 vm_offset_t alternate_next;
81 int flags;
82 vm_offset_t self;
83 };
84
85 #define SHARED_REGION_SYSTEM 0x1
86 #define SHARED_REGION_FULL 0x2
87
88 typedef struct shared_region_task_mappings *shared_region_task_mappings_t;
89 #endif /* KERNEL_PRIVATE */
90
91
92 #define SHARED_LIB_ALIAS 0x10
93
94
95 /* flags field aliases for copyin_shared_file and load_shared_file */
96
97 /* IN */
98 #define ALTERNATE_LOAD_SITE 0x1
99 #define NEW_LOCAL_SHARED_REGIONS 0x2
100
101 /* OUT */
102 #define SF_PREV_LOADED 0x1
103
104
105 #define load_file_hash(file_object, size) \
106 ((((natural_t)file_object) & 0xffffff) % size)
107
108 #define VM_PROT_COW 0x8 /* must not interfere with normal prot assignments */
109 #define VM_PROT_ZF 0x10 /* must not interfere with normal prot assignments */
110
111 struct sf_mapping {
112 vm_offset_t mapping_offset;
113 vm_size_t size;
114 vm_offset_t file_offset;
115 vm_prot_t protection; /* read/write/execute/COW/ZF */
116 vm_offset_t cksum;
117 };
118
119 typedef struct sf_mapping sf_mapping_t;
120
121
122 #ifdef MACH_KERNEL_PRIVATE
123
124 struct loaded_mapping {
125 vm_offset_t mapping_offset;
126 vm_size_t size;
127 vm_offset_t file_offset;
128 vm_prot_t protection; /* read/write/execute/COW/ZF */
129
130 struct loaded_mapping *next;
131 };
132
133 typedef struct loaded_mapping loaded_mapping_t;
134
135 struct load_struct {
136 queue_chain_t links;
137 shared_region_mapping_t regions_instance;
138 int depth;
139 int file_object;
140 vm_offset_t base_address;
141 int mapping_cnt;
142 loaded_mapping_t *mappings;
143 };
144
145 #endif /* MACH_KERNEL_PRIVATE */
146
147 typedef struct load_struct load_struct_t;
148 typedef struct load_struct *load_struct_ptr_t;
149
150 #ifdef MACH_KERNEL_PRIVATE
151
152 struct load_file_ele {
153 union {
154 sf_mapping_t mapping;
155 load_struct_t element;
156 } u;
157 };
158
159 struct shared_file_info {
160 mutex_t lock; /* lock for the structure */
161 queue_head_t *hash; /* for later perf enhance */
162 int hash_size;
163 boolean_t hash_init;
164 };
165
166 typedef struct shared_file_info shared_file_info_t;
167
168 extern kern_return_t
169 copyin_shared_file(
170 vm_offset_t mapped_file,
171 vm_size_t mapped_file_size,
172 vm_offset_t *base_address,
173 int map_cnt,
174 sf_mapping_t *mappings,
175 vm_object_t file_object,
176 shared_region_task_mappings_t shared_region,
177 int *flags);
178
179 extern kern_return_t
180 shared_file_init(
181 ipc_port_t *shared_text_region_handle,
182 vm_size_t text_region_size,
183 ipc_port_t *shared_data_region_handle,
184 vm_size_t data_region_size,
185 vm_offset_t *shared_file_mapping_array);
186
187 extern load_struct_t *
188 lsf_hash_lookup(
189 queue_head_t *hash_table,
190 void *file_object,
191 int size,
192 boolean_t alternate,
193 shared_region_task_mappings_t sm_info);
194
195 extern load_struct_t *
196 lsf_hash_delete(
197 void *file_object,
198 vm_offset_t base_offset,
199 shared_region_task_mappings_t sm_info);
200
201 extern void
202 lsf_hash_insert(
203 load_struct_t *entry,
204 shared_region_task_mappings_t sm_info);
205
206 extern kern_return_t
207 lsf_load(
208 vm_offset_t mapped_file,
209 vm_size_t mapped_file_size,
210 vm_offset_t *base_address,
211 sf_mapping_t *mappings,
212 int map_cnt,
213 void *file_object,
214 int flags,
215 shared_region_task_mappings_t sm_info);
216
217 extern void
218 lsf_unload(
219 void *file_object,
220 vm_offset_t base_offset,
221 shared_region_task_mappings_t sm_info);
222
223 #endif /* MACH_KERNEL_PRIVATE */
224 #endif /* _SHARED_MEMORY_SERVER_H_ */