1 /*
2 * Copyright 1991-1998 by Open Software Foundation, Inc.
3 * All Rights Reserved
4 *
5 * Permission to use, copy, modify, and distribute this software and
6 * its documentation for any purpose and without fee is hereby granted,
7 * provided that the above copyright notice appears in all copies and
8 * that both the copyright notice and this permission notice appear in
9 * supporting documentation.
10 *
11 * OSF DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE
12 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
13 * FOR A PARTICULAR PURPOSE.
14 *
15 * IN NO EVENT SHALL OSF BE LIABLE FOR ANY SPECIAL, INDIRECT, OR
16 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
17 * LOSS OF USE, DATA OR PROFITS, WHETHER IN ACTION OF CONTRACT,
18 * NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
19 * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
20 */
21 /*
22 * MkLinux
23 */
24 /* CMU_HIST */
25 /*
26 * Revision 2.12.2.2 92/03/03 16:18:29 jeffreyh
27 * 19-Feb-92 David L. Black (dlb) at Open Software Foundation
28 * Don't make port zone exhaustible. Kernel panics when
29 * it fails to allocate an internal port after exhaustion.
30 * [92/02/26 11:41:12 jeffreyh]
31 *
32 * Revision 2.12.2.1 92/01/03 16:34:52 jsb
33 * Corrected log.
34 * [91/12/24 14:18:23 jsb]
35 *
36 * Revision 2.12 91/12/10 13:25:41 jsb
37 * Removed reference counting bug workaround.
38 * [91/12/10 11:17:21 jsb]
39 *
40 * Revision 2.11 91/11/19 09:54:12 rvb
41 * Added reference counting bug workaround.
42 * [91/11/00 jsb]
43 *
44 * Revision 2.10 91/08/03 18:18:12 jsb
45 * Removed call to ipc_clport_init.
46 * [91/07/24 22:11:04 jsb]
47 *
48 * Revision 2.9 91/06/17 15:46:00 jsb
49 * Renamed NORMA conditionals.
50 * [91/06/17 10:45:48 jsb]
51 *
52 * Revision 2.8 91/06/06 17:05:46 jsb
53 * Added call to ipc_clport_init.
54 * [91/05/13 17:17:10 jsb]
55 *
56 * Revision 2.7 91/05/14 16:32:33 mrt
57 * Correcting copyright
58 *
59 * Revision 2.6 91/02/05 17:21:37 mrt
60 * Changed to new Mach copyright
61 * [91/02/01 15:45:02 mrt]
62 *
63 * Revision 2.5 91/01/08 15:13:40 rpd
64 * Changed zchange calls to make the IPC zones non-collectable.
65 * [90/12/29 rpd]
66 *
67 * Revision 2.4 90/12/20 16:38:41 jeffreyh
68 * Changes to zchange to account for new collectable field. Made all
69 * ipc zones collectable.
70 * [90/12/11 jeffreyh]
71 *
72 * Revision 2.3 90/09/28 16:54:44 jsb
73 * Added NORMA_IPC support.
74 * [90/09/28 14:02:05 jsb]
75 *
76 * Revision 2.2 90/06/02 14:49:55 rpd
77 * Created for new IPC.
78 * [90/03/26 20:55:13 rpd]
79 *
80 */
81 /* CMU_ENDHIST */
82 /*
83 * Mach Operating System
84 * Copyright (c) 1991,1990,1989 Carnegie Mellon University
85 * All Rights Reserved.
86 *
87 * Permission to use, copy, modify and distribute this software and its
88 * documentation is hereby granted, provided that both the copyright
89 * notice and this permission notice appear in all copies of the
90 * software, derivative works or modified versions, and any portions
91 * thereof, and that both notices appear in supporting documentation.
92 *
93 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
94 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
95 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
96 *
97 * Carnegie Mellon requests users of this software to return to
98 *
99 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
100 * School of Computer Science
101 * Carnegie Mellon University
102 * Pittsburgh PA 15213-3890
103 *
104 * any improvements or extensions that they make and grant Carnegie Mellon
105 * the rights to redistribute these changes.
106 */
107 /*
108 */
109 /*
110 * File: ipc/ipc_init.c
111 * Author: Rich Draves
112 * Date: 1989
113 *
114 * Functions to initialize the IPC system.
115 */
116
117 #include <sys/types.h>
118 #include <sys/param.h>
119 #include <sys/kernel.h>
120 #include <sys/lock.h>
121 #include <sys/mutex.h>
122
123 #include <sys/mach/kern_return.h>
124 #include <sys/mach/mach_param.h>
125 #include <sys/mach/mach_types.h>
126
127 #include <sys/mach/ipc/ipc_entry.h>
128 #include <sys/mach/ipc/ipc_space.h>
129 #include <sys/mach/ipc/ipc_object.h>
130 #include <sys/mach/ipc/ipc_port.h>
131 #include <sys/mach/ipc/ipc_pset.h>
132 #include <sys/mach/ipc/ipc_notify.h>
133 #include <sys/mach/ipc/ipc_kmsg.h>
134 #include <sys/mach/ipc/ipc_hash.h>
135 #include <sys/mach/ipc/ipc_init.h>
136 #include <sys/mach/ndr_def.h> /* NDR_record */
137
138 vm_map_t ipc_kernel_map;
139 vm_size_t ipc_kernel_map_size = 1024 * 1024;
140
141 vm_map_t ipc_kernel_copy_map;
142 #define IPC_KERNEL_COPY_MAP_SIZE (8 * 1024 * 1024)
143 vm_size_t ipc_kernel_copy_map_size = IPC_KERNEL_COPY_MAP_SIZE;
144 vm_size_t ipc_kmsg_max_vm_space = (IPC_KERNEL_COPY_MAP_SIZE * 7)/8;
145
146 uma_zone_t ipc_kmsg_zone;
147
148
149 /*
150 * values to limit inline message body handling
151 * avoid copyin/out limits - even after accounting for maximum descriptor expansion.
152 */
153 #define IPC_KMSG_MAX_SPACE (64 * 1024 * 1024) /* keep in sync with COPYSIZELIMIT_PANIC */
154 vm_size_t ipc_kmsg_max_body_space = ((IPC_KMSG_MAX_SPACE * 3)/4 - MAX_TRAILER_SIZE);
155
156 int ipc_space_max = SPACE_MAX;
157 int ipc_port_max = PORT_MAX;
158 int ipc_pset_max = SET_MAX;
159
160
161 #define MSG_OOL_SIZE_SMALL 16385
162 vm_size_t msg_ool_size_small;
163
164
165 extern void mig_init(void);
166
167 /*
168 * Routine: ipc_bootstrap
169 * Purpose:
170 * Initialization needed before the kernel task
171 * can be created.
172 */
173
174 static void
ipc_bootstrap_sysinit(void * arg __unused)175 ipc_bootstrap_sysinit(void *arg __unused)
176 {
177 kern_return_t kr;
178
179 ipc_port_multiple_lock_init();
180
181 ipc_port_timestamp_lock_init();
182 ipc_port_timestamp_data = 0;
183
184 /* all IPC zones should be exhaustible */
185
186 ipc_space_zone = uma_zcreate("ipc_space_zone", sizeof(struct ipc_space),
187 NULL, NULL, NULL, NULL, 1, 0);
188 ipc_kmsg_zone = uma_zcreate("ipc_kmsg_zone", IKM_SAVED_MSG_SIZE,
189 NULL, NULL, NULL, NULL, 1, 0);
190 /*
191 * populate all port(set) zones
192 */
193 ipc_object_zones[IOT_PORT] =
194 zinit(sizeof(struct ipc_port),
195 ipc_port_max * sizeof(struct ipc_port),
196 sizeof(struct ipc_port),
197 "ipc ports");
198 /*
199 * XXX Can't make the port zone exhaustible because the kernel
200 * XXX panics when port allocation for an internal object fails.
201 *zone_change(ipc_object_zones[IOT_PORT], Z_EXHAUST, TRUE);
202 */
203
204 ipc_object_zones[IOT_PORT_SET] =
205 zinit(sizeof(struct ipc_pset),
206 ipc_pset_max * sizeof(struct ipc_pset),
207 sizeof(struct ipc_pset),
208 "ipc port sets");
209 /* make it exhaustible */
210 zone_change(ipc_object_zones[IOT_PORT_SET], Z_EXHAUST, TRUE);
211
212 /* create special spaces */
213
214 kr = ipc_space_create_special(&ipc_space_kernel);
215 assert(kr == KERN_SUCCESS);
216
217
218 kr = ipc_space_create_special(&ipc_space_reply);
219 assert(kr == KERN_SUCCESS);
220
221 /* initialize modules with hidden data structures */
222
223 mig_init();
224 ipc_table_init();
225 ipc_notify_init();
226 ipc_hash_init();
227 msg_ool_size_small = MSG_OOL_SIZE_SMALL;
228 }
229
230
231 /*
232 * Routine: ipc_init
233 * Purpose:
234 * Final initialization of the IPC system.
235 */
236
237 void
ipc_init(void)238 ipc_init(void)
239 {
240 #if 0
241 kern_return_t retval;
242 vm_offset_t min, max;
243 extern vm_size_t kalloc_max_prerounded;
244
245 retval = kmem_suballoc(kernel_map, &min, ipc_kernel_map_size,
246 TRUE, TRUE, &ipc_kernel_map);
247 if (retval != KERN_SUCCESS)
248 panic("ipc_init: kmem_suballoc of ipc_kernel_map failed");
249
250 retval = kmem_suballoc(kernel_map, &min, ipc_kernel_copy_map_size,
251 TRUE, TRUE, &ipc_kernel_copy_map);
252 if (retval != KERN_SUCCESS)
253 panic("ipc_init: kmem_suballoc of ipc_kernel_copy_map failed");
254
255 ipc_kernel_copy_map->no_zero_fill = TRUE;
256 ipc_kernel_copy_map->wait_for_space = TRUE;
257
258 /*
259 * As an optimization, 'small' out of line data regions using a
260 * physical copy strategy are copied into kalloc'ed buffers.
261 * The value of 'small' is determined here. Requests kalloc()
262 * with sizes greater or equal to kalloc_max_prerounded may fail.
263 */
264 if (kalloc_max_prerounded <= MSG_OOL_SIZE_SMALL) {
265 msg_ool_size_small = kalloc_max_prerounded;
266 }
267 else {
268 }
269 #endif
270
271 }
272
273 /* before SI_SUB_INTRINSIC and after SI_SUB_EVENTHANDLER */
274 SYSINIT(ipc_space, SI_SUB_KLD, SI_ORDER_ANY, ipc_bootstrap_sysinit, NULL);
275