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