]>
Commit | Line | Data |
---|---|---|
1c79356b | 1 | /* |
b0d623f7 | 2 | * Copyright (c) 2000-2008 Apple Inc. All rights reserved. |
1c79356b | 3 | * |
2d21ac55 | 4 | * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ |
1c79356b | 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. | |
8f6c56a5 | 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. | |
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 | |
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. | |
8f6c56a5 | 25 | * |
2d21ac55 | 26 | * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ |
1c79356b A |
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 | */ | |
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: kern/ipc_kobject.c | |
67 | * Author: Rich Draves | |
68 | * Date: 1989 | |
69 | * | |
70 | * Functions for letting a port represent a kernel object. | |
71 | */ | |
72 | ||
73 | #include <mach_debug.h> | |
74 | #include <mach_ipc_test.h> | |
75 | #include <mach_machine_routines.h> | |
76 | #include <norma_task.h> | |
77 | #include <mach_rt.h> | |
78 | #include <platforms.h> | |
79 | ||
9bccf70c | 80 | #include <mach/mig.h> |
1c79356b A |
81 | #include <mach/port.h> |
82 | #include <mach/kern_return.h> | |
83 | #include <mach/message.h> | |
84 | #include <mach/mig_errors.h> | |
85 | #include <mach/notify.h> | |
91447636 | 86 | #include <mach/ndr.h> |
b0d623f7 | 87 | #include <mach/vm_param.h> |
91447636 A |
88 | |
89 | #include <mach/mach_vm_server.h> | |
90 | #include <mach/mach_port_server.h> | |
91 | #include <mach/mach_host_server.h> | |
92 | #include <mach/host_priv_server.h> | |
93 | #include <mach/host_security_server.h> | |
94 | #include <mach/clock_server.h> | |
95 | #include <mach/clock_priv_server.h> | |
96 | #include <mach/ledger_server.h> | |
97 | #include <mach/lock_set_server.h> | |
98 | #include <default_pager/default_pager_object_server.h> | |
99 | #include <mach/memory_object_server.h> | |
100 | #include <mach/memory_object_control_server.h> | |
101 | #include <mach/memory_object_default_server.h> | |
102 | #include <mach/memory_object_name_server.h> | |
103 | #include <mach/processor_server.h> | |
104 | #include <mach/processor_set_server.h> | |
91447636 | 105 | #include <mach/task_server.h> |
b0d623f7 A |
106 | #if VM32_SUPPORT |
107 | #include <mach/vm32_map_server.h> | |
108 | #endif | |
91447636 A |
109 | #include <mach/thread_act_server.h> |
110 | ||
111 | #include <device/device_types.h> | |
112 | #include <device/device_server.h> | |
113 | ||
114 | #include <UserNotification/UNDReplyServer.h> | |
115 | ||
b0d623f7 A |
116 | #if CONFIG_AUDIT |
117 | #include <kern/audit_sessionport.h> | |
118 | #endif | |
119 | ||
91447636 A |
120 | #if MACH_MACHINE_ROUTINES |
121 | #include <machine/machine_routines.h> | |
122 | #endif /* MACH_MACHINE_ROUTINES */ | |
123 | #if XK_PROXY | |
124 | #include <uk_xkern/xk_uproxy_server.h> | |
125 | #endif /* XK_PROXY */ | |
9bccf70c | 126 | |
91447636 | 127 | #include <kern/ipc_tt.h> |
1c79356b A |
128 | #include <kern/ipc_mig.h> |
129 | #include <kern/ipc_kobject.h> | |
55e303ae | 130 | #include <kern/host_notify.h> |
1c79356b | 131 | #include <kern/mk_timer.h> |
55e303ae | 132 | #include <kern/misc_protos.h> |
1c79356b A |
133 | #include <ipc/ipc_kmsg.h> |
134 | #include <ipc/ipc_port.h> | |
2d21ac55 | 135 | #include <ipc/ipc_labelh.h> |
1c79356b A |
136 | #include <kern/counters.h> |
137 | ||
91447636 | 138 | #include <vm/vm_protos.h> |
1c79356b | 139 | |
2d21ac55 A |
140 | #include <security/mac_mach_internal.h> |
141 | ||
1c79356b A |
142 | /* |
143 | * Routine: ipc_kobject_notify | |
144 | * Purpose: | |
145 | * Deliver notifications to kobjects that care about them. | |
146 | */ | |
147 | boolean_t | |
148 | ipc_kobject_notify( | |
149 | mach_msg_header_t *request_header, | |
150 | mach_msg_header_t *reply_header); | |
151 | ||
1c79356b A |
152 | typedef struct { |
153 | mach_msg_id_t num; | |
154 | mig_routine_t routine; | |
155 | int size; | |
156 | #if MACH_COUNTERS | |
157 | mach_counter_t callcount; | |
158 | #endif | |
159 | } mig_hash_t; | |
160 | ||
161 | #define MAX_MIG_ENTRIES 1024 | |
162 | #define MIG_HASH(x) (x) | |
163 | ||
164 | #ifndef max | |
165 | #define max(a,b) (((a) > (b)) ? (a) : (b)) | |
166 | #endif /* max */ | |
167 | ||
168 | mig_hash_t mig_buckets[MAX_MIG_ENTRIES]; | |
169 | int mig_table_max_displ; | |
170 | mach_msg_size_t mig_reply_size; | |
171 | ||
2d21ac55 A |
172 | #if CONFIG_MACF |
173 | #include <mach/security_server.h> | |
174 | #endif | |
1c79356b | 175 | |
1c79356b A |
176 | |
177 | ||
91447636 A |
178 | const struct mig_subsystem *mig_e[] = { |
179 | (const struct mig_subsystem *)&mach_vm_subsystem, | |
180 | (const struct mig_subsystem *)&mach_port_subsystem, | |
181 | (const struct mig_subsystem *)&mach_host_subsystem, | |
182 | (const struct mig_subsystem *)&host_priv_subsystem, | |
183 | (const struct mig_subsystem *)&host_security_subsystem, | |
184 | (const struct mig_subsystem *)&clock_subsystem, | |
185 | (const struct mig_subsystem *)&clock_priv_subsystem, | |
186 | (const struct mig_subsystem *)&processor_subsystem, | |
187 | (const struct mig_subsystem *)&processor_set_subsystem, | |
188 | (const struct mig_subsystem *)&is_iokit_subsystem, | |
189 | (const struct mig_subsystem *)&memory_object_name_subsystem, | |
190 | (const struct mig_subsystem *)&lock_set_subsystem, | |
191 | (const struct mig_subsystem *)&ledger_subsystem, | |
91447636 A |
192 | (const struct mig_subsystem *)&task_subsystem, |
193 | (const struct mig_subsystem *)&thread_act_subsystem, | |
b0d623f7 A |
194 | #if VM32_SUPPORT |
195 | (const struct mig_subsystem *)&vm32_map_subsystem, | |
196 | #endif | |
91447636 A |
197 | (const struct mig_subsystem *)&UNDReply_subsystem, |
198 | (const struct mig_subsystem *)&default_pager_object_subsystem, | |
1c79356b A |
199 | |
200 | #if XK_PROXY | |
91447636 | 201 | (const struct mig_subsystem *)&do_uproxy_xk_uproxy_subsystem, |
1c79356b A |
202 | #endif /* XK_PROXY */ |
203 | #if MACH_MACHINE_ROUTINES | |
91447636 | 204 | (const struct mig_subsystem *)&MACHINE_SUBSYSTEM, |
1c79356b A |
205 | #endif /* MACH_MACHINE_ROUTINES */ |
206 | #if MCMSG && iPSC860 | |
91447636 | 207 | (const struct mig_subsystem *)&mcmsg_info_subsystem, |
1c79356b | 208 | #endif /* MCMSG && iPSC860 */ |
2d21ac55 A |
209 | |
210 | #if CONFIG_MACF | |
211 | (const struct mig_subsystem *)&security_subsystem, | |
212 | #endif | |
1c79356b A |
213 | }; |
214 | ||
215 | void | |
216 | mig_init(void) | |
217 | { | |
91447636 A |
218 | unsigned int i, n = sizeof(mig_e)/sizeof(const struct mig_subsystem *); |
219 | int howmany; | |
220 | mach_msg_id_t j, pos, nentry, range; | |
1c79356b A |
221 | |
222 | for (i = 0; i < n; i++) { | |
223 | range = mig_e[i]->end - mig_e[i]->start; | |
224 | if (!mig_e[i]->start || range < 0) | |
225 | panic("the msgh_ids in mig_e[] aren't valid!"); | |
226 | mig_reply_size = max(mig_reply_size, mig_e[i]->maxsize); | |
227 | ||
228 | for (j = 0; j < range; j++) { | |
229 | if (mig_e[i]->routine[j].stub_routine) { | |
230 | /* Only put real entries in the table */ | |
231 | nentry = j + mig_e[i]->start; | |
232 | for (pos = MIG_HASH(nentry) % MAX_MIG_ENTRIES, howmany = 1; | |
233 | mig_buckets[pos].num; | |
2d21ac55 | 234 | pos++, pos = pos % MAX_MIG_ENTRIES, howmany++) { |
1c79356b A |
235 | if (mig_buckets[pos].num == nentry) { |
236 | printf("message id = %d\n", nentry); | |
237 | panic("multiple entries with the same msgh_id"); | |
238 | } | |
239 | if (howmany == MAX_MIG_ENTRIES) | |
240 | panic("the mig dispatch table is too small"); | |
241 | } | |
242 | ||
243 | mig_buckets[pos].num = nentry; | |
244 | mig_buckets[pos].routine = mig_e[i]->routine[j].stub_routine; | |
245 | if (mig_e[i]->routine[j].max_reply_msg) | |
246 | mig_buckets[pos].size = mig_e[i]->routine[j].max_reply_msg; | |
247 | else | |
248 | mig_buckets[pos].size = mig_e[i]->maxsize; | |
249 | ||
250 | mig_table_max_displ = max(howmany, mig_table_max_displ); | |
251 | } | |
252 | } | |
253 | } | |
0b4e3aa0 | 254 | printf("mig_table_max_displ = %d\n", mig_table_max_displ); |
1c79356b A |
255 | } |
256 | ||
257 | ||
258 | /* | |
259 | * Routine: ipc_kobject_server | |
260 | * Purpose: | |
261 | * Handle a message sent to the kernel. | |
262 | * Generates a reply message. | |
263 | * Version for Untyped IPC. | |
264 | * Conditions: | |
265 | * Nothing locked. | |
266 | */ | |
267 | ||
268 | ipc_kmsg_t | |
269 | ipc_kobject_server( | |
270 | ipc_kmsg_t request) | |
271 | { | |
272 | mach_msg_size_t reply_size; | |
273 | ipc_kmsg_t reply; | |
274 | kern_return_t kr; | |
1c79356b A |
275 | ipc_port_t *destp; |
276 | mach_msg_format_0_trailer_t *trailer; | |
277 | register mig_hash_t *ptr; | |
91447636 | 278 | |
1c79356b | 279 | /* |
91447636 A |
280 | * Find out corresponding mig_hash entry if any |
281 | */ | |
1c79356b | 282 | { |
91447636 | 283 | register int key = request->ikm_header->msgh_id; |
1c79356b A |
284 | register int i = MIG_HASH(key); |
285 | register int max_iter = mig_table_max_displ; | |
286 | ||
287 | do | |
288 | ptr = &mig_buckets[i++ % MAX_MIG_ENTRIES]; | |
289 | while (key != ptr->num && ptr->num && --max_iter); | |
290 | ||
291 | if (!ptr->routine || key != ptr->num) { | |
292 | ptr = (mig_hash_t *)0; | |
293 | reply_size = mig_reply_size; | |
294 | } else { | |
295 | reply_size = ptr->size; | |
296 | #if MACH_COUNTER | |
297 | ptr->callcount++; | |
298 | #endif | |
299 | } | |
300 | } | |
301 | ||
302 | /* round up for trailer size */ | |
303 | reply_size += MAX_TRAILER_SIZE; | |
304 | reply = ipc_kmsg_alloc(reply_size); | |
305 | ||
306 | if (reply == IKM_NULL) { | |
307 | printf("ipc_kobject_server: dropping request\n"); | |
308 | ipc_kmsg_destroy(request); | |
309 | return IKM_NULL; | |
310 | } | |
311 | ||
312 | /* | |
313 | * Initialize reply message. | |
314 | */ | |
315 | { | |
91447636 A |
316 | #define InP ((mach_msg_header_t *) request->ikm_header) |
317 | #define OutP ((mig_reply_error_t *) reply->ikm_header) | |
1c79356b A |
318 | |
319 | OutP->NDR = NDR_record; | |
320 | OutP->Head.msgh_size = sizeof(mig_reply_error_t); | |
321 | ||
322 | OutP->Head.msgh_bits = | |
323 | MACH_MSGH_BITS(MACH_MSGH_BITS_LOCAL(InP->msgh_bits), 0); | |
324 | OutP->Head.msgh_remote_port = InP->msgh_local_port; | |
325 | OutP->Head.msgh_local_port = MACH_PORT_NULL; | |
326 | OutP->Head.msgh_id = InP->msgh_id + 100; | |
327 | ||
328 | #undef InP | |
329 | #undef OutP | |
330 | } | |
331 | ||
332 | /* | |
333 | * Find the routine to call, and call it | |
334 | * to perform the kernel function | |
335 | */ | |
336 | { | |
337 | if (ptr) { | |
91447636 | 338 | (*ptr->routine)(request->ikm_header, reply->ikm_header); |
1c79356b A |
339 | kernel_task->messages_received++; |
340 | } | |
341 | else { | |
91447636 | 342 | if (!ipc_kobject_notify(request->ikm_header, reply->ikm_header)){ |
1c79356b A |
343 | #if MACH_IPC_TEST |
344 | printf("ipc_kobject_server: bogus kernel message, id=%d\n", | |
91447636 | 345 | request->ikm_header->msgh_id); |
1c79356b | 346 | #endif /* MACH_IPC_TEST */ |
91447636 | 347 | _MIG_MSGID_INVALID(request->ikm_header->msgh_id); |
1c79356b | 348 | |
91447636 | 349 | ((mig_reply_error_t *) reply->ikm_header)->RetCode |
1c79356b A |
350 | = MIG_BAD_ID; |
351 | } | |
352 | else | |
353 | kernel_task->messages_received++; | |
354 | } | |
355 | kernel_task->messages_sent++; | |
356 | } | |
357 | ||
358 | /* | |
359 | * Destroy destination. The following code differs from | |
360 | * ipc_object_destroy in that we release the send-once | |
361 | * right instead of generating a send-once notification | |
362 | * (which would bring us here again, creating a loop). | |
363 | * It also differs in that we only expect send or | |
364 | * send-once rights, never receive rights. | |
365 | * | |
366 | * We set msgh_remote_port to IP_NULL so that the kmsg | |
367 | * destroy routines don't try to destroy the port twice. | |
368 | */ | |
91447636 A |
369 | destp = (ipc_port_t *) &request->ikm_header->msgh_remote_port; |
370 | switch (MACH_MSGH_BITS_REMOTE(request->ikm_header->msgh_bits)) { | |
1c79356b A |
371 | case MACH_MSG_TYPE_PORT_SEND: |
372 | ipc_port_release_send(*destp); | |
373 | break; | |
374 | ||
375 | case MACH_MSG_TYPE_PORT_SEND_ONCE: | |
376 | ipc_port_release_sonce(*destp); | |
377 | break; | |
378 | ||
379 | default: | |
9bccf70c | 380 | panic("ipc_kobject_server: strange destination rights"); |
1c79356b A |
381 | } |
382 | *destp = IP_NULL; | |
383 | ||
91447636 A |
384 | if (!(reply->ikm_header->msgh_bits & MACH_MSGH_BITS_COMPLEX) && |
385 | ((mig_reply_error_t *) reply->ikm_header)->RetCode != KERN_SUCCESS) | |
386 | kr = ((mig_reply_error_t *) reply->ikm_header)->RetCode; | |
1c79356b A |
387 | else |
388 | kr = KERN_SUCCESS; | |
389 | ||
390 | if ((kr == KERN_SUCCESS) || (kr == MIG_NO_REPLY)) { | |
391 | /* | |
392 | * The server function is responsible for the contents | |
393 | * of the message. The reply port right is moved | |
394 | * to the reply message, and we have deallocated | |
395 | * the destination port right, so we just need | |
396 | * to free the kmsg. | |
397 | */ | |
398 | ipc_kmsg_free(request); | |
399 | ||
400 | } else { | |
401 | /* | |
402 | * The message contents of the request are intact. | |
403 | * Destroy everthing except the reply port right, | |
404 | * which is needed in the reply message. | |
405 | */ | |
91447636 | 406 | request->ikm_header->msgh_local_port = MACH_PORT_NULL; |
1c79356b A |
407 | ipc_kmsg_destroy(request); |
408 | } | |
409 | ||
410 | if (kr == MIG_NO_REPLY) { | |
411 | /* | |
412 | * The server function will send a reply message | |
413 | * using the reply port right, which it has saved. | |
414 | */ | |
415 | ||
416 | ipc_kmsg_free(reply); | |
417 | ||
1c79356b | 418 | return IKM_NULL; |
91447636 | 419 | } else if (!IP_VALID((ipc_port_t)reply->ikm_header->msgh_remote_port)) { |
1c79356b A |
420 | /* |
421 | * Can't queue the reply message if the destination | |
422 | * (the reply port) isn't valid. | |
423 | */ | |
424 | ||
425 | ipc_kmsg_destroy(reply); | |
426 | ||
1c79356b A |
427 | return IKM_NULL; |
428 | } | |
429 | ||
430 | trailer = (mach_msg_format_0_trailer_t *) | |
91447636 A |
431 | ((vm_offset_t)reply->ikm_header + (int)reply->ikm_header->msgh_size); |
432 | ||
1c79356b A |
433 | trailer->msgh_sender = KERNEL_SECURITY_TOKEN; |
434 | trailer->msgh_trailer_type = MACH_MSG_TRAILER_FORMAT_0; | |
435 | trailer->msgh_trailer_size = MACH_MSG_TRAILER_MINIMUM_SIZE; | |
436 | ||
1c79356b A |
437 | return reply; |
438 | } | |
439 | ||
440 | /* | |
441 | * Routine: ipc_kobject_set | |
442 | * Purpose: | |
443 | * Make a port represent a kernel object of the given type. | |
444 | * The caller is responsible for handling refs for the | |
445 | * kernel object, if necessary. | |
446 | * Conditions: | |
447 | * Nothing locked. The port must be active if setting | |
448 | * a kobject linkage. Clearing a linkage is OK on an | |
449 | * inactive port. | |
450 | */ | |
451 | void | |
452 | ipc_kobject_set( | |
453 | ipc_port_t port, | |
454 | ipc_kobject_t kobject, | |
455 | ipc_kobject_type_t type) | |
456 | { | |
457 | ip_lock(port); | |
458 | ipc_kobject_set_atomically(port, kobject, type); | |
2d21ac55 A |
459 | |
460 | #if CONFIG_MACF_MACH | |
461 | mac_port_label_update_kobject (&port->ip_label, type); | |
462 | #endif | |
463 | ||
1c79356b A |
464 | ip_unlock(port); |
465 | } | |
466 | ||
467 | void | |
468 | ipc_kobject_set_atomically( | |
469 | ipc_port_t port, | |
470 | ipc_kobject_t kobject, | |
471 | ipc_kobject_type_t type) | |
472 | { | |
473 | assert(type == IKOT_NONE || ip_active(port)); | |
474 | #if MACH_ASSERT | |
475 | port->ip_spares[2] = (port->ip_bits & IO_BITS_KOTYPE); | |
476 | #endif /* MACH_ASSERT */ | |
477 | port->ip_bits = (port->ip_bits &~ IO_BITS_KOTYPE) | type; | |
478 | port->ip_kobject = kobject; | |
479 | } | |
480 | ||
481 | /* | |
482 | * Routine: ipc_kobject_destroy | |
483 | * Purpose: | |
484 | * Release any kernel object resources associated | |
485 | * with the port, which is being destroyed. | |
486 | * | |
487 | * This should only be needed when resources are | |
488 | * associated with a user's port. In the normal case, | |
489 | * when the kernel is the receiver, the code calling | |
490 | * ipc_port_dealloc_kernel should clean up the resources. | |
491 | * Conditions: | |
492 | * The port is not locked, but it is dead. | |
493 | */ | |
494 | ||
495 | void | |
496 | ipc_kobject_destroy( | |
497 | ipc_port_t port) | |
498 | { | |
499 | switch (ip_kotype(port)) { | |
500 | ||
501 | case IKOT_TIMER: | |
502 | mk_timer_port_destroy(port); | |
503 | break; | |
504 | ||
505 | case IKOT_NAMED_ENTRY: | |
506 | mach_destroy_memory_entry(port); | |
507 | break; | |
508 | ||
55e303ae A |
509 | case IKOT_HOST_NOTIFY: |
510 | host_notify_port_destroy(port); | |
511 | break; | |
512 | ||
2d21ac55 A |
513 | #if CONFIG_MACF_MACH |
514 | case IKOT_LABELH: | |
515 | labelh_destroy(port); | |
516 | break; | |
517 | #endif | |
518 | ||
55e303ae | 519 | default: |
1c79356b A |
520 | break; |
521 | } | |
522 | } | |
523 | ||
524 | ||
1c79356b A |
525 | boolean_t |
526 | ipc_kobject_notify( | |
527 | mach_msg_header_t *request_header, | |
528 | mach_msg_header_t *reply_header) | |
529 | { | |
530 | ipc_port_t port = (ipc_port_t) request_header->msgh_remote_port; | |
1c79356b A |
531 | |
532 | ((mig_reply_error_t *) reply_header)->RetCode = MIG_NO_REPLY; | |
533 | switch (request_header->msgh_id) { | |
534 | case MACH_NOTIFY_NO_SENDERS: | |
535 | if(ip_kotype(port) == IKOT_NAMED_ENTRY) { | |
536 | ip_lock(port); | |
537 | ||
538 | /* | |
539 | * Bring the sequence number and mscount in | |
540 | * line with ipc_port_destroy assertion. | |
541 | */ | |
542 | port->ip_mscount = 0; | |
543 | port->ip_messages.imq_seqno = 0; | |
544 | ipc_port_destroy(port); /* releases lock */ | |
545 | return TRUE; | |
546 | } | |
0b4e3aa0 A |
547 | if (ip_kotype(port) == IKOT_UPL) { |
548 | upl_no_senders( | |
91447636 | 549 | request_header->msgh_remote_port, |
0b4e3aa0 A |
550 | (mach_port_mscount_t) |
551 | ((mach_no_senders_notification_t *) | |
552 | request_header)->not_count); | |
2d21ac55 | 553 | reply_header->msgh_remote_port = MACH_PORT_NULL; |
0b4e3aa0 | 554 | return TRUE; |
1c79356b | 555 | } |
b0d623f7 A |
556 | #if CONFIG_AUDIT |
557 | if (ip_kotype(port) == IKOT_AU_SESSIONPORT) { | |
558 | audit_session_nosenders(request_header); | |
559 | return TRUE; | |
560 | } | |
561 | #endif | |
562 | ||
1c79356b | 563 | break; |
0b4e3aa0 | 564 | |
1c79356b A |
565 | case MACH_NOTIFY_PORT_DELETED: |
566 | case MACH_NOTIFY_PORT_DESTROYED: | |
567 | case MACH_NOTIFY_SEND_ONCE: | |
568 | case MACH_NOTIFY_DEAD_NAME: | |
569 | break; | |
570 | ||
571 | default: | |
572 | return FALSE; | |
573 | } | |
574 | switch (ip_kotype(port)) { | |
575 | ||
576 | #ifdef IOKIT | |
577 | case IKOT_IOKIT_OBJECT: | |
578 | case IKOT_IOKIT_CONNECT: | |
579 | case IKOT_IOKIT_SPARE: | |
580 | { | |
1c79356b A |
581 | return iokit_notify(request_header); |
582 | } | |
583 | #endif | |
584 | default: | |
585 | return FALSE; | |
586 | } | |
587 | } | |
588 | ||
589 | ||
590 | ||
591 | #include <mach_kdb.h> | |
592 | #if MACH_COUNTERS && MACH_KDB | |
593 | ||
594 | #include <ddb/db_output.h> | |
595 | #include <ddb/db_sym.h> | |
596 | ||
597 | #define printf kdbprintf | |
598 | ||
599 | extern void kobjserver_stats(void); | |
600 | extern void bucket_stats_print(mig_hash_t *bucket); | |
601 | ||
602 | extern void kobjserver_stats_clear(void); | |
603 | ||
604 | ||
605 | void | |
606 | kobjserver_stats_clear(void) | |
607 | { | |
608 | int i; | |
609 | for (i = 0; i < MAX_MIG_ENTRIES; i++) { | |
610 | mig_buckets[i].callcount = 0; | |
611 | } | |
612 | } | |
613 | ||
614 | void | |
615 | kobjserver_stats(void) | |
616 | { | |
91447636 | 617 | register unsigned int i, n = sizeof(mig_e)/sizeof(struct mig_subsystem); |
1c79356b A |
618 | register unsigned int howmany; |
619 | register mach_msg_id_t j, pos, nentry, range; | |
620 | ||
621 | db_printf("Kobject server call counts:\n"); | |
622 | for (i = 0; i < n; i++) { | |
623 | db_printf(" "); | |
624 | db_printsym((vm_offset_t)mig_e[i], DB_STGY_ANY); | |
625 | db_printf(":\n"); | |
626 | range = mig_e[i]->end - mig_e[i]->start; | |
627 | if (!mig_e[i]->start || range < 0) continue; | |
628 | ||
629 | for (j = 0; j < range; j++) { | |
630 | nentry = j + mig_e[i]->start; | |
631 | for (pos = MIG_HASH(nentry) % MAX_MIG_ENTRIES, howmany = 1; | |
632 | mig_buckets[pos].num; | |
2d21ac55 | 633 | pos++, pos = pos % MAX_MIG_ENTRIES, howmany++) { |
1c79356b A |
634 | if (mig_buckets[pos].num == nentry) |
635 | bucket_stats_print(&mig_buckets[pos]); | |
636 | } | |
637 | } | |
638 | } | |
639 | } | |
640 | ||
641 | void | |
642 | bucket_stats_print(mig_hash_t *bucket) | |
643 | { | |
644 | if (bucket->callcount) { | |
645 | db_printf(" "); | |
646 | db_printsym((vm_offset_t)bucket->routine, DB_STGY_ANY); | |
647 | db_printf(" (%d):\t%d\n", bucket->num, bucket->callcount); | |
648 | } | |
649 | } | |
650 | ||
651 | ||
652 | #endif /* MACH_COUNTERS && MACH_KDB */ |