]> git.saurik.com Git - apple/xnu.git/blame - osfmk/ipc/ipc_init.c
xnu-7195.101.1.tar.gz
[apple/xnu.git] / osfmk / ipc / ipc_init.c
CommitLineData
1c79356b 1/*
f427ee49 2 * Copyright (c) 2000-2020 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>
f427ee49 109#include <ipc/ipc_eventlink.h>
91447636 110
1c79356b
A
111#include <mach/machine/ndr_def.h> /* NDR_record */
112
c3c9b80d 113#define IPC_KERNEL_MAP_SIZE (CONFIG_IPC_KERNEL_MAP_SIZE * 1024 * 1024)
f427ee49 114SECURITY_READ_ONLY_LATE(vm_map_t) ipc_kernel_map;
1c79356b 115
316670eb 116/* values to limit physical copy out-of-line memory descriptors */
f427ee49 117SECURITY_READ_ONLY_LATE(vm_map_t) ipc_kernel_copy_map;
1c79356b 118#define IPC_KERNEL_COPY_MAP_SIZE (8 * 1024 * 1024)
f427ee49 119const vm_size_t ipc_kmsg_max_vm_space = ((IPC_KERNEL_COPY_MAP_SIZE * 7) / 8);
316670eb 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 */
f427ee49 126const vm_size_t ipc_kmsg_max_body_space = ((IPC_KMSG_MAX_SPACE * 3) / 4 - MAX_TRAILER_SIZE);
1c79356b 127
c3c9b80d
A
128#if XNU_TARGET_OS_OSX
129#define IPC_CONTROL_PORT_OPTIONS_DEFAULT IPC_CONTROL_PORT_OPTIONS_NONE
130#else
131#define IPC_CONTROL_PORT_OPTIONS_DEFAULT (IPC_CONTROL_PORT_OPTIONS_IMMOVABLE_HARD | IPC_CONTROL_PORT_OPTIONS_PINNED_SOFT)
132#endif
133
134TUNABLE(ipc_control_port_options_t, ipc_control_port_options,
135 "ipc_control_port_options", IPC_CONTROL_PORT_OPTIONS_DEFAULT);
136
137SECURITY_READ_ONLY_LATE(bool) pinned_control_port_enabled;
138SECURITY_READ_ONLY_LATE(bool) immovable_control_port_enabled;
139
140
f427ee49
A
141LCK_GRP_DECLARE(ipc_lck_grp, "ipc");
142LCK_ATTR_DECLARE(ipc_lck_attr, 0, 0);
b0d623f7 143
f427ee49
A
144/*
145 * XXX tunable, belongs in mach.message.h
146 */
147#define MSG_OOL_SIZE_SMALL_MAX (2*PAGE_SIZE)
148SECURITY_READ_ONLY_LATE(vm_size_t) msg_ool_size_small;
1c79356b 149
1c79356b 150/*
f427ee49 151 * Routine: ipc_init
1c79356b 152 * Purpose:
f427ee49 153 * Final initialization
1c79356b 154 */
f427ee49
A
155__startup_func
156static void
157ipc_init(void)
1c79356b
A
158{
159 kern_return_t kr;
f427ee49 160 vm_offset_t min;
91447636 161
1c79356b
A
162 /* create special spaces */
163
164 kr = ipc_space_create_special(&ipc_space_kernel);
165 assert(kr == KERN_SUCCESS);
166
1c79356b
A
167 kr = ipc_space_create_special(&ipc_space_reply);
168 assert(kr == KERN_SUCCESS);
169
170 /* initialize modules with hidden data structures */
171
fe8ab488
A
172#if IMPORTANCE_INHERITANCE
173 ipc_importance_init();
174#endif
cb323159
A
175#if CONFIG_ARCADE
176 arcade_init();
177#endif
178
c3c9b80d
A
179 pinned_control_port_enabled = !!(ipc_control_port_options & (IPC_CONTROL_PORT_OPTIONS_PINNED_SOFT | IPC_CONTROL_PORT_OPTIONS_PINNED_HARD));
180 immovable_control_port_enabled = !!(ipc_control_port_options & (IPC_CONTROL_PORT_OPTIONS_IMMOVABLE_SOFT | IPC_CONTROL_PORT_OPTIONS_IMMOVABLE_HARD));
181
182 if (pinned_control_port_enabled && !immovable_control_port_enabled) {
183 kprintf("Invalid ipc_control_port_options boot-arg: pinned control port cannot be enabled without immovability enforcement. Ignoring pinning boot-arg.");
184 pinned_control_port_enabled = false;
185 ipc_control_port_options &= ~(IPC_CONTROL_PORT_OPTIONS_PINNED_SOFT | IPC_CONTROL_PORT_OPTIONS_PINNED_HARD);
186 }
187
f427ee49 188 kr = kmem_suballoc(kernel_map, &min, IPC_KERNEL_MAP_SIZE,
0a7de745
A
189 TRUE,
190 (VM_FLAGS_ANYWHERE),
191 VM_MAP_KERNEL_FLAGS_NONE,
192 VM_KERN_MEMORY_IPC,
193 &ipc_kernel_map);
91447636 194
f427ee49 195 if (kr != KERN_SUCCESS) {
1c79356b 196 panic("ipc_init: kmem_suballoc of ipc_kernel_map failed");
0a7de745 197 }
1c79356b 198
f427ee49 199 kr = kmem_suballoc(kernel_map, &min, IPC_KERNEL_COPY_MAP_SIZE,
0a7de745
A
200 TRUE,
201 (VM_FLAGS_ANYWHERE),
202 VM_MAP_KERNEL_FLAGS_NONE,
203 VM_KERN_MEMORY_IPC,
204 &ipc_kernel_copy_map);
91447636 205
f427ee49 206 if (kr != KERN_SUCCESS) {
1c79356b 207 panic("ipc_init: kmem_suballoc of ipc_kernel_copy_map failed");
0a7de745 208 }
1c79356b
A
209
210 ipc_kernel_copy_map->no_zero_fill = TRUE;
211 ipc_kernel_copy_map->wait_for_space = TRUE;
212
213 /*
0a7de745 214 * As an optimization, 'small' out of line data regions using a
1c79356b
A
215 * physical copy strategy are copied into kalloc'ed buffers.
216 * The value of 'small' is determined here. Requests kalloc()
217 * with sizes greater or equal to kalloc_max_prerounded may fail.
218 */
0a7de745 219 if (kalloc_max_prerounded <= MSG_OOL_SIZE_SMALL_MAX) {
1c79356b 220 msg_ool_size_small = kalloc_max_prerounded;
0a7de745 221 } else {
1c79356b
A
222 msg_ool_size_small = MSG_OOL_SIZE_SMALL_MAX;
223 }
224
225 ipc_host_init();
d9a64523 226 ux_handler_init();
fe8ab488 227}
f427ee49 228STARTUP(MACH_IPC, STARTUP_RANK_LAST, ipc_init);
fe8ab488
A
229
230
231/*
232 * Routine: ipc_thread_call_init
233 * Purpose:
234 * Initialize IPC logic that needs thread call support
235 */
236
237void
238ipc_thread_call_init(void)
239{
240#if IMPORTANCE_INHERITANCE
241 ipc_importance_thread_call_init();
242#endif
1c79356b 243}