2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
8 * This file contains Original Code and/or Modifications of Original Code
9 * as defined in and that are subject to the Apple Public Source License
10 * Version 2.0 (the 'License'). You may not use this file except in
11 * compliance with the License. Please obtain a copy of the License at
12 * http://www.opensource.apple.com/apsl/ and read it before using this
15 * The Original Code and all software distributed under the License are
16 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
17 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
18 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
20 * Please see the License for the specific language governing rights and
21 * limitations under the License.
23 * @APPLE_LICENSE_HEADER_END@
29 * Mach Operating System
30 * Copyright (c) 1991,1990,1989 Carnegie Mellon University
31 * All Rights Reserved.
33 * Permission to use, copy, modify and distribute this software and its
34 * documentation is hereby granted, provided that both the copyright
35 * notice and this permission notice appear in all copies of the
36 * software, derivative works or modified versions, and any portions
37 * thereof, and that both notices appear in supporting documentation.
39 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
40 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
41 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
43 * Carnegie Mellon requests users of this software to return to
45 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
46 * School of Computer Science
47 * Carnegie Mellon University
48 * Pittsburgh PA 15213-3890
50 * any improvements or extensions that they make and grant Carnegie Mellon
51 * the rights to redistribute these changes.
56 * File: ipc/ipc_init.c
60 * Functions to initialize the IPC system.
63 #include <mach_debug.h>
66 #include <mach/kern_return.h>
67 #include <kern/mach_param.h>
68 #include <kern/ipc_host.h>
69 #include <kern/misc_protos.h>
70 #include <vm/vm_map.h>
71 #include <vm/vm_kern.h>
72 #include <ipc/ipc_entry.h>
73 #include <ipc/ipc_space.h>
74 #include <ipc/ipc_object.h>
75 #include <ipc/ipc_port.h>
76 #include <ipc/ipc_pset.h>
77 #include <ipc/ipc_notify.h>
78 #include <ipc/ipc_kmsg.h>
79 #include <ipc/ipc_hash.h>
80 #include <ipc/ipc_init.h>
81 #include <mach/machine/ndr_def.h> /* NDR_record */
83 vm_map_t ipc_kernel_map
;
84 vm_size_t ipc_kernel_map_size
= 1024 * 1024;
86 vm_map_t ipc_kernel_copy_map
;
87 #define IPC_KERNEL_COPY_MAP_SIZE (8 * 1024 * 1024)
88 vm_size_t ipc_kernel_copy_map_size
= IPC_KERNEL_COPY_MAP_SIZE
;
89 vm_size_t ipc_kmsg_max_vm_space
= (IPC_KERNEL_COPY_MAP_SIZE
* 7)/8;
91 int ipc_space_max
= SPACE_MAX
;
92 int ipc_tree_entry_max
= ITE_MAX
;
93 int ipc_port_max
= PORT_MAX
;
94 int ipc_pset_max
= SET_MAX
;
96 extern void mig_init(void);
97 extern void ikm_cache_init(void);
100 * Routine: ipc_bootstrap
102 * Initialization needed before the kernel task
111 ipc_port_multiple_lock_init();
113 ipc_port_timestamp_lock_init();
114 ipc_port_timestamp_data
= 0;
116 /* all IPC zones should be exhaustible */
118 ipc_space_zone
= zinit(sizeof(struct ipc_space
),
119 ipc_space_max
* sizeof(struct ipc_space
),
120 sizeof(struct ipc_space
),
123 /* make it exhaustible */
124 zone_change(ipc_space_zone
, Z_EXHAUST
, TRUE
);
127 ipc_tree_entry_zone
=
128 zinit(sizeof(struct ipc_tree_entry
),
129 ipc_tree_entry_max
* sizeof(struct ipc_tree_entry
),
130 sizeof(struct ipc_tree_entry
),
133 /* make it exhaustible */
134 zone_change(ipc_tree_entry_zone
, Z_EXHAUST
, TRUE
);
138 * populate all port(set) zones
140 ipc_object_zones
[IOT_PORT
] =
141 zinit(sizeof(struct ipc_port
),
142 ipc_port_max
* sizeof(struct ipc_port
),
143 sizeof(struct ipc_port
),
146 * XXX Can't make the port zone exhaustible because the kernel
147 * XXX panics when port allocation for an internal object fails.
148 *zone_change(ipc_object_zones[IOT_PORT], Z_EXHAUST, TRUE);
151 ipc_object_zones
[IOT_PORT_SET
] =
152 zinit(sizeof(struct ipc_pset
),
153 ipc_pset_max
* sizeof(struct ipc_pset
),
154 sizeof(struct ipc_pset
),
156 /* make it exhaustible */
157 zone_change(ipc_object_zones
[IOT_PORT_SET
], Z_EXHAUST
, TRUE
);
159 /* create special spaces */
161 kr
= ipc_space_create_special(&ipc_space_kernel
);
162 assert(kr
== KERN_SUCCESS
);
165 kr
= ipc_space_create_special(&ipc_space_reply
);
166 assert(kr
== KERN_SUCCESS
);
168 /* initialize modules with hidden data structures */
171 ipc_port_debug_init();
183 * XXX tunable, belongs in mach.message.h
185 #define MSG_OOL_SIZE_SMALL_MAX 4096
186 vm_size_t msg_ool_size_small
;
191 * Final initialization of the IPC system.
197 kern_return_t retval
;
198 vm_offset_t min
, max
;
199 extern vm_size_t kalloc_max_prerounded
;
201 retval
= kmem_suballoc(kernel_map
, &min
, ipc_kernel_map_size
,
202 TRUE
, TRUE
, &ipc_kernel_map
);
203 if (retval
!= KERN_SUCCESS
)
204 panic("ipc_init: kmem_suballoc of ipc_kernel_map failed");
206 retval
= kmem_suballoc(kernel_map
, &min
, ipc_kernel_copy_map_size
,
207 TRUE
, TRUE
, &ipc_kernel_copy_map
);
208 if (retval
!= KERN_SUCCESS
)
209 panic("ipc_init: kmem_suballoc of ipc_kernel_copy_map failed");
211 ipc_kernel_copy_map
->no_zero_fill
= TRUE
;
212 ipc_kernel_copy_map
->wait_for_space
= TRUE
;
215 * As an optimization, 'small' out of line data regions using a
216 * physical copy strategy are copied into kalloc'ed buffers.
217 * The value of 'small' is determined here. Requests kalloc()
218 * with sizes greater or equal to kalloc_max_prerounded may fail.
220 if (kalloc_max_prerounded
<= MSG_OOL_SIZE_SMALL_MAX
) {
221 msg_ool_size_small
= kalloc_max_prerounded
;
224 msg_ool_size_small
= MSG_OOL_SIZE_SMALL_MAX
;