]>
Commit | Line | Data |
---|---|---|
1c79356b | 1 | /* |
316670eb | 2 | * Copyright (c) 2000-2012 Apple Inc. All rights reserved. |
1c79356b | 3 | * |
2d21ac55 | 4 | * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ |
0a7de745 | 5 | * |
2d21ac55 A |
6 | * This file contains Original Code and/or Modifications of Original Code |
7 | * as defined in and that are subject to the Apple Public Source License | |
8 | * Version 2.0 (the 'License'). You may not use this file except in | |
9 | * compliance with the License. The rights granted to you under the License | |
10 | * may not be used to create, or enable the creation or redistribution of, | |
11 | * unlawful or unlicensed copies of an Apple operating system, or to | |
12 | * circumvent, violate, or enable the circumvention or violation of, any | |
13 | * terms of an Apple operating system software license agreement. | |
0a7de745 | 14 | * |
2d21ac55 A |
15 | * Please obtain a copy of the License at |
16 | * http://www.opensource.apple.com/apsl/ and read it before using this file. | |
0a7de745 | 17 | * |
2d21ac55 A |
18 | * The Original Code and all software distributed under the License are |
19 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER | |
8f6c56a5 A |
20 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, |
21 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, | |
2d21ac55 A |
22 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. |
23 | * Please see the License for the specific language governing rights and | |
24 | * limitations under the License. | |
0a7de745 | 25 | * |
2d21ac55 | 26 | * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ |
1c79356b A |
27 | */ |
28 | /* | |
29 | * @OSF_COPYRIGHT@ | |
30 | */ | |
0a7de745 | 31 | /* |
1c79356b A |
32 | * Mach Operating System |
33 | * Copyright (c) 1991,1990,1989 Carnegie Mellon University | |
34 | * All Rights Reserved. | |
0a7de745 | 35 | * |
1c79356b A |
36 | * Permission to use, copy, modify and distribute this software and its |
37 | * documentation is hereby granted, provided that both the copyright | |
38 | * notice and this permission notice appear in all copies of the | |
39 | * software, derivative works or modified versions, and any portions | |
40 | * thereof, and that both notices appear in supporting documentation. | |
0a7de745 | 41 | * |
1c79356b A |
42 | * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" |
43 | * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR | |
44 | * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. | |
0a7de745 | 45 | * |
1c79356b | 46 | * Carnegie Mellon requests users of this software to return to |
0a7de745 | 47 | * |
1c79356b A |
48 | * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU |
49 | * School of Computer Science | |
50 | * Carnegie Mellon University | |
51 | * Pittsburgh PA 15213-3890 | |
0a7de745 | 52 | * |
1c79356b A |
53 | * any improvements or extensions that they make and grant Carnegie Mellon |
54 | * the rights to redistribute these changes. | |
55 | */ | |
2d21ac55 A |
56 | /* |
57 | * NOTICE: This file was modified by McAfee Research in 2004 to introduce | |
58 | * support for mandatory and extensible security protections. This notice | |
59 | * is included in support of clause 2.2 (b) of the Apple Public License, | |
60 | * Version 2.0. | |
61 | * Copyright (c) 2005 SPARTA, Inc. | |
62 | */ | |
1c79356b A |
63 | /* |
64 | */ | |
65 | /* | |
66 | * File: ipc/ipc_init.c | |
67 | * Author: Rich Draves | |
68 | * Date: 1989 | |
69 | * | |
70 | * Functions to initialize the IPC system. | |
71 | */ | |
72 | ||
73 | #include <mach_debug.h> | |
1c79356b | 74 | |
91447636 | 75 | #include <mach/port.h> |
316670eb | 76 | #include <mach/message.h> |
1c79356b | 77 | #include <mach/kern_return.h> |
91447636 A |
78 | |
79 | #include <kern/kern_types.h> | |
cb323159 | 80 | #include <kern/arcade.h> |
91447636 | 81 | #include <kern/kalloc.h> |
fe8ab488 | 82 | #include <kern/simple_lock.h> |
1c79356b A |
83 | #include <kern/mach_param.h> |
84 | #include <kern/ipc_host.h> | |
ea3f0419 | 85 | #include <kern/ipc_kobject.h> |
91447636 | 86 | #include <kern/ipc_mig.h> |
55e303ae A |
87 | #include <kern/host_notify.h> |
88 | #include <kern/mk_timer.h> | |
1c79356b | 89 | #include <kern/misc_protos.h> |
ea3f0419 | 90 | #include <kern/suid_cred.h> |
91447636 A |
91 | #include <kern/sync_lock.h> |
92 | #include <kern/sync_sema.h> | |
d9a64523 | 93 | #include <kern/ux_handler.h> |
1c79356b A |
94 | #include <vm/vm_map.h> |
95 | #include <vm/vm_kern.h> | |
91447636 | 96 | |
1c79356b A |
97 | #include <ipc/ipc_entry.h> |
98 | #include <ipc/ipc_space.h> | |
99 | #include <ipc/ipc_object.h> | |
100 | #include <ipc/ipc_port.h> | |
101 | #include <ipc/ipc_pset.h> | |
102 | #include <ipc/ipc_notify.h> | |
103 | #include <ipc/ipc_kmsg.h> | |
104 | #include <ipc/ipc_hash.h> | |
105 | #include <ipc/ipc_init.h> | |
91447636 | 106 | #include <ipc/ipc_table.h> |
fe8ab488 A |
107 | #include <ipc/ipc_voucher.h> |
108 | #include <ipc/ipc_importance.h> | |
91447636 | 109 | |
1c79356b A |
110 | #include <mach/machine/ndr_def.h> /* NDR_record */ |
111 | ||
112 | vm_map_t ipc_kernel_map; | |
113 | vm_size_t ipc_kernel_map_size = 1024 * 1024; | |
114 | ||
316670eb | 115 | /* values to limit physical copy out-of-line memory descriptors */ |
1c79356b A |
116 | vm_map_t ipc_kernel_copy_map; |
117 | #define IPC_KERNEL_COPY_MAP_SIZE (8 * 1024 * 1024) | |
118 | vm_size_t ipc_kernel_copy_map_size = IPC_KERNEL_COPY_MAP_SIZE; | |
316670eb A |
119 | vm_size_t ipc_kmsg_max_vm_space = ((IPC_KERNEL_COPY_MAP_SIZE * 7) / 8); |
120 | ||
0a7de745 | 121 | /* |
316670eb A |
122 | * values to limit inline message body handling |
123 | * avoid copyin/out limits - even after accounting for maximum descriptor expansion. | |
124 | */ | |
125 | #define IPC_KMSG_MAX_SPACE (64 * 1024 * 1024) /* keep in sync with COPYSIZELIMIT_PANIC */ | |
0a7de745 | 126 | vm_size_t ipc_kmsg_max_body_space = ((IPC_KMSG_MAX_SPACE * 3) / 4 - MAX_TRAILER_SIZE); |
1c79356b | 127 | |
b0d623f7 | 128 | int ipc_space_max; |
b0d623f7 A |
129 | int ipc_port_max; |
130 | int ipc_pset_max; | |
cb323159 A |
131 | int prioritize_launch = 1; |
132 | int enforce_strict_reply = 0; | |
b0d623f7 A |
133 | |
134 | ||
0a7de745 A |
135 | lck_grp_t ipc_lck_grp; |
136 | lck_attr_t ipc_lck_attr; | |
b0d623f7 | 137 | |
0a7de745 | 138 | static lck_grp_attr_t ipc_lck_grp_attr; |
1c79356b | 139 | |
1c79356b A |
140 | /* |
141 | * Routine: ipc_bootstrap | |
142 | * Purpose: | |
143 | * Initialization needed before the kernel task | |
144 | * can be created. | |
145 | */ | |
146 | ||
147 | void | |
148 | ipc_bootstrap(void) | |
149 | { | |
150 | kern_return_t kr; | |
cb323159 A |
151 | int prioritize_launch_bootarg; |
152 | int strict_reply_bootarg; | |
0a7de745 | 153 | |
b0d623f7 A |
154 | lck_grp_attr_setdefault(&ipc_lck_grp_attr); |
155 | lck_grp_init(&ipc_lck_grp, "ipc", &ipc_lck_grp_attr); | |
156 | lck_attr_setdefault(&ipc_lck_attr); | |
0a7de745 | 157 | |
1c79356b A |
158 | ipc_port_multiple_lock_init(); |
159 | ||
1c79356b A |
160 | ipc_port_timestamp_data = 0; |
161 | ||
162 | /* all IPC zones should be exhaustible */ | |
163 | ||
164 | ipc_space_zone = zinit(sizeof(struct ipc_space), | |
0a7de745 A |
165 | ipc_space_max * sizeof(struct ipc_space), |
166 | sizeof(struct ipc_space), | |
167 | "ipc spaces"); | |
0b4c1975 | 168 | zone_change(ipc_space_zone, Z_NOENCRYPT, TRUE); |
1c79356b | 169 | |
1c79356b A |
170 | /* |
171 | * populate all port(set) zones | |
172 | */ | |
173 | ipc_object_zones[IOT_PORT] = | |
0a7de745 A |
174 | zinit(sizeof(struct ipc_port), |
175 | ipc_port_max * sizeof(struct ipc_port), | |
176 | sizeof(struct ipc_port), | |
177 | "ipc ports"); | |
6d2010ae A |
178 | /* cant charge callers for port allocations (references passed) */ |
179 | zone_change(ipc_object_zones[IOT_PORT], Z_CALLERACCT, FALSE); | |
0b4c1975 | 180 | zone_change(ipc_object_zones[IOT_PORT], Z_NOENCRYPT, TRUE); |
cb323159 | 181 | zone_change(ipc_object_zones[IOT_PORT], Z_CLEARMEMORY, TRUE); |
1c79356b A |
182 | |
183 | ipc_object_zones[IOT_PORT_SET] = | |
0a7de745 A |
184 | zinit(sizeof(struct ipc_pset), |
185 | ipc_pset_max * sizeof(struct ipc_pset), | |
186 | sizeof(struct ipc_pset), | |
187 | "ipc port sets"); | |
0b4c1975 | 188 | zone_change(ipc_object_zones[IOT_PORT_SET], Z_NOENCRYPT, TRUE); |
cb323159 | 189 | zone_change(ipc_object_zones[IOT_PORT_SET], Z_CLEARMEMORY, TRUE); |
1c79356b | 190 | |
91447636 A |
191 | /* |
192 | * Create the basic ipc_kmsg_t zone (the one we also cache) | |
193 | * elements at the processor-level to avoid the locking. | |
194 | */ | |
195 | ipc_kmsg_zone = zinit(IKM_SAVED_KMSG_SIZE, | |
0a7de745 A |
196 | ipc_port_max * MACH_PORT_QLIMIT_DEFAULT * |
197 | IKM_SAVED_KMSG_SIZE, | |
198 | IKM_SAVED_KMSG_SIZE, | |
199 | "ipc kmsgs"); | |
6d2010ae | 200 | zone_change(ipc_kmsg_zone, Z_CALLERACCT, FALSE); |
d9a64523 | 201 | zone_change(ipc_kmsg_zone, Z_CACHING_ENABLED, TRUE); |
91447636 | 202 | |
1c79356b A |
203 | /* create special spaces */ |
204 | ||
205 | kr = ipc_space_create_special(&ipc_space_kernel); | |
206 | assert(kr == KERN_SUCCESS); | |
207 | ||
208 | ||
209 | kr = ipc_space_create_special(&ipc_space_reply); | |
210 | assert(kr == KERN_SUCCESS); | |
211 | ||
212 | /* initialize modules with hidden data structures */ | |
213 | ||
0a7de745 | 214 | #if MACH_ASSERT |
1c79356b A |
215 | ipc_port_debug_init(); |
216 | #endif | |
ea3f0419 | 217 | ipc_kobject_init(); |
1c79356b | 218 | ipc_table_init(); |
fe8ab488 A |
219 | ipc_voucher_init(); |
220 | ||
221 | #if IMPORTANCE_INHERITANCE | |
222 | ipc_importance_init(); | |
223 | #endif | |
316670eb | 224 | |
1c79356b | 225 | semaphore_init(); |
55e303ae A |
226 | mk_timer_init(); |
227 | host_notify_init(); | |
cb323159 A |
228 | |
229 | #if CONFIG_ARCADE | |
230 | arcade_init(); | |
231 | #endif | |
232 | ||
ea3f0419 A |
233 | suid_cred_init(); |
234 | ||
cb323159 A |
235 | if (PE_parse_boot_argn("prioritize_launch", &prioritize_launch_bootarg, sizeof(prioritize_launch_bootarg))) { |
236 | prioritize_launch = !!prioritize_launch_bootarg; | |
237 | } | |
238 | if (PE_parse_boot_argn("ipc_strict_reply", &strict_reply_bootarg, sizeof(strict_reply_bootarg))) { | |
239 | enforce_strict_reply = !!strict_reply_bootarg; | |
240 | } | |
1c79356b A |
241 | } |
242 | ||
0a7de745 A |
243 | /* |
244 | * XXX tunable, belongs in mach.message.h | |
1c79356b | 245 | */ |
3e170ce0 | 246 | #define MSG_OOL_SIZE_SMALL_MAX (2*PAGE_SIZE) |
1c79356b A |
247 | vm_size_t msg_ool_size_small; |
248 | ||
249 | /* | |
250 | * Routine: ipc_init | |
251 | * Purpose: | |
252 | * Final initialization of the IPC system. | |
253 | */ | |
254 | ||
255 | void | |
256 | ipc_init(void) | |
257 | { | |
258 | kern_return_t retval; | |
91447636 | 259 | vm_offset_t min; |
1c79356b A |
260 | |
261 | retval = kmem_suballoc(kernel_map, &min, ipc_kernel_map_size, | |
0a7de745 A |
262 | TRUE, |
263 | (VM_FLAGS_ANYWHERE), | |
264 | VM_MAP_KERNEL_FLAGS_NONE, | |
265 | VM_KERN_MEMORY_IPC, | |
266 | &ipc_kernel_map); | |
91447636 | 267 | |
0a7de745 | 268 | if (retval != KERN_SUCCESS) { |
1c79356b | 269 | panic("ipc_init: kmem_suballoc of ipc_kernel_map failed"); |
0a7de745 | 270 | } |
1c79356b A |
271 | |
272 | retval = kmem_suballoc(kernel_map, &min, ipc_kernel_copy_map_size, | |
0a7de745 A |
273 | TRUE, |
274 | (VM_FLAGS_ANYWHERE), | |
275 | VM_MAP_KERNEL_FLAGS_NONE, | |
276 | VM_KERN_MEMORY_IPC, | |
277 | &ipc_kernel_copy_map); | |
91447636 | 278 | |
0a7de745 | 279 | if (retval != KERN_SUCCESS) { |
1c79356b | 280 | panic("ipc_init: kmem_suballoc of ipc_kernel_copy_map failed"); |
0a7de745 | 281 | } |
1c79356b A |
282 | |
283 | ipc_kernel_copy_map->no_zero_fill = TRUE; | |
284 | ipc_kernel_copy_map->wait_for_space = TRUE; | |
285 | ||
286 | /* | |
0a7de745 | 287 | * As an optimization, 'small' out of line data regions using a |
1c79356b A |
288 | * physical copy strategy are copied into kalloc'ed buffers. |
289 | * The value of 'small' is determined here. Requests kalloc() | |
290 | * with sizes greater or equal to kalloc_max_prerounded may fail. | |
291 | */ | |
0a7de745 | 292 | if (kalloc_max_prerounded <= MSG_OOL_SIZE_SMALL_MAX) { |
1c79356b | 293 | msg_ool_size_small = kalloc_max_prerounded; |
0a7de745 | 294 | } else { |
1c79356b A |
295 | msg_ool_size_small = MSG_OOL_SIZE_SMALL_MAX; |
296 | } | |
3e170ce0 A |
297 | /* account for overhead to avoid spilling over a page */ |
298 | msg_ool_size_small -= cpy_kdata_hdr_sz; | |
1c79356b A |
299 | |
300 | ipc_host_init(); | |
d9a64523 | 301 | ux_handler_init(); |
fe8ab488 A |
302 | } |
303 | ||
304 | ||
305 | /* | |
306 | * Routine: ipc_thread_call_init | |
307 | * Purpose: | |
308 | * Initialize IPC logic that needs thread call support | |
309 | */ | |
310 | ||
311 | void | |
312 | ipc_thread_call_init(void) | |
313 | { | |
314 | #if IMPORTANCE_INHERITANCE | |
315 | ipc_importance_thread_call_init(); | |
316 | #endif | |
1c79356b | 317 | } |