]> git.saurik.com Git - apple/xnu.git/blob - osfmk/ipc/ipc_init.c
b6ff1fc9efaeabd5401d2946cb815c7e5f12587c
[apple/xnu.git] / osfmk / ipc / ipc_init.c
1 /*
2 * Copyright (c) 2000-2020 Apple Inc. All rights reserved.
3 *
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
5 *
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.
14 *
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
17 *
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
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
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.
25 *
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
27 */
28 /*
29 * @OSF_COPYRIGHT@
30 */
31 /*
32 * Mach Operating System
33 * Copyright (c) 1991,1990,1989 Carnegie Mellon University
34 * All Rights Reserved.
35 *
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.
41 *
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.
45 *
46 * Carnegie Mellon requests users of this software to return to
47 *
48 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
49 * School of Computer Science
50 * Carnegie Mellon University
51 * Pittsburgh PA 15213-3890
52 *
53 * any improvements or extensions that they make and grant Carnegie Mellon
54 * the rights to redistribute these changes.
55 */
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 */
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>
74
75 #include <mach/port.h>
76 #include <mach/message.h>
77 #include <mach/kern_return.h>
78
79 #include <kern/kern_types.h>
80 #include <kern/arcade.h>
81 #include <kern/kalloc.h>
82 #include <kern/simple_lock.h>
83 #include <kern/mach_param.h>
84 #include <kern/ipc_host.h>
85 #include <kern/ipc_kobject.h>
86 #include <kern/ipc_mig.h>
87 #include <kern/host_notify.h>
88 #include <kern/mk_timer.h>
89 #include <kern/misc_protos.h>
90 #include <kern/suid_cred.h>
91 #include <kern/sync_lock.h>
92 #include <kern/sync_sema.h>
93 #include <kern/ux_handler.h>
94 #include <vm/vm_map.h>
95 #include <vm/vm_kern.h>
96
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>
106 #include <ipc/ipc_table.h>
107 #include <ipc/ipc_voucher.h>
108 #include <ipc/ipc_importance.h>
109 #include <ipc/ipc_eventlink.h>
110
111 #include <mach/machine/ndr_def.h> /* NDR_record */
112
113 #define IPC_KERNEL_MAP_SIZE (1024 * 1024)
114 SECURITY_READ_ONLY_LATE(vm_map_t) ipc_kernel_map;
115
116 /* values to limit physical copy out-of-line memory descriptors */
117 SECURITY_READ_ONLY_LATE(vm_map_t) ipc_kernel_copy_map;
118 #define IPC_KERNEL_COPY_MAP_SIZE (8 * 1024 * 1024)
119 const vm_size_t ipc_kmsg_max_vm_space = ((IPC_KERNEL_COPY_MAP_SIZE * 7) / 8);
120
121 /*
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 */
126 const vm_size_t ipc_kmsg_max_body_space = ((IPC_KMSG_MAX_SPACE * 3) / 4 - MAX_TRAILER_SIZE);
127
128 LCK_GRP_DECLARE(ipc_lck_grp, "ipc");
129 LCK_ATTR_DECLARE(ipc_lck_attr, 0, 0);
130
131 /*
132 * XXX tunable, belongs in mach.message.h
133 */
134 #define MSG_OOL_SIZE_SMALL_MAX (2*PAGE_SIZE)
135 SECURITY_READ_ONLY_LATE(vm_size_t) msg_ool_size_small;
136
137 /*
138 * Routine: ipc_init
139 * Purpose:
140 * Final initialization
141 */
142 __startup_func
143 static void
144 ipc_init(void)
145 {
146 kern_return_t kr;
147 vm_offset_t min;
148
149 /* create special spaces */
150
151 kr = ipc_space_create_special(&ipc_space_kernel);
152 assert(kr == KERN_SUCCESS);
153
154 kr = ipc_space_create_special(&ipc_space_reply);
155 assert(kr == KERN_SUCCESS);
156
157 /* initialize modules with hidden data structures */
158
159 #if IMPORTANCE_INHERITANCE
160 ipc_importance_init();
161 #endif
162 #if CONFIG_ARCADE
163 arcade_init();
164 #endif
165
166 kr = kmem_suballoc(kernel_map, &min, IPC_KERNEL_MAP_SIZE,
167 TRUE,
168 (VM_FLAGS_ANYWHERE),
169 VM_MAP_KERNEL_FLAGS_NONE,
170 VM_KERN_MEMORY_IPC,
171 &ipc_kernel_map);
172
173 if (kr != KERN_SUCCESS) {
174 panic("ipc_init: kmem_suballoc of ipc_kernel_map failed");
175 }
176
177 kr = kmem_suballoc(kernel_map, &min, IPC_KERNEL_COPY_MAP_SIZE,
178 TRUE,
179 (VM_FLAGS_ANYWHERE),
180 VM_MAP_KERNEL_FLAGS_NONE,
181 VM_KERN_MEMORY_IPC,
182 &ipc_kernel_copy_map);
183
184 if (kr != KERN_SUCCESS) {
185 panic("ipc_init: kmem_suballoc of ipc_kernel_copy_map failed");
186 }
187
188 ipc_kernel_copy_map->no_zero_fill = TRUE;
189 ipc_kernel_copy_map->wait_for_space = TRUE;
190
191 /*
192 * As an optimization, 'small' out of line data regions using a
193 * physical copy strategy are copied into kalloc'ed buffers.
194 * The value of 'small' is determined here. Requests kalloc()
195 * with sizes greater or equal to kalloc_max_prerounded may fail.
196 */
197 if (kalloc_max_prerounded <= MSG_OOL_SIZE_SMALL_MAX) {
198 msg_ool_size_small = kalloc_max_prerounded;
199 } else {
200 msg_ool_size_small = MSG_OOL_SIZE_SMALL_MAX;
201 }
202
203 ipc_host_init();
204 ux_handler_init();
205 }
206 STARTUP(MACH_IPC, STARTUP_RANK_LAST, ipc_init);
207
208
209 /*
210 * Routine: ipc_thread_call_init
211 * Purpose:
212 * Initialize IPC logic that needs thread call support
213 */
214
215 void
216 ipc_thread_call_init(void)
217 {
218 #if IMPORTANCE_INHERITANCE
219 ipc_importance_thread_call_init();
220 #endif
221 }