]> git.saurik.com Git - apple/xnu.git/blob - osfmk/kern/ipc_kobject.c
5eaef10b7c87ab3b3380e049ae26e7b4b45c31c5
[apple/xnu.git] / osfmk / kern / ipc_kobject.c
1 /*
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.1 (the
8 * "License"). You may not use this file except in compliance with the
9 * License. Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
11 *
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
18 * under the License.
19 *
20 * @APPLE_LICENSE_HEADER_END@
21 */
22 /*
23 * @OSF_COPYRIGHT@
24 */
25 /*
26 * Mach Operating System
27 * Copyright (c) 1991,1990,1989 Carnegie Mellon University
28 * All Rights Reserved.
29 *
30 * Permission to use, copy, modify and distribute this software and its
31 * documentation is hereby granted, provided that both the copyright
32 * notice and this permission notice appear in all copies of the
33 * software, derivative works or modified versions, and any portions
34 * thereof, and that both notices appear in supporting documentation.
35 *
36 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
37 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
38 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
39 *
40 * Carnegie Mellon requests users of this software to return to
41 *
42 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
43 * School of Computer Science
44 * Carnegie Mellon University
45 * Pittsburgh PA 15213-3890
46 *
47 * any improvements or extensions that they make and grant Carnegie Mellon
48 * the rights to redistribute these changes.
49 */
50 /*
51 */
52 /*
53 * File: kern/ipc_kobject.c
54 * Author: Rich Draves
55 * Date: 1989
56 *
57 * Functions for letting a port represent a kernel object.
58 */
59
60 #include <mach_debug.h>
61 #include <mach_ipc_test.h>
62 #include <mach_machine_routines.h>
63 #include <norma_task.h>
64 #include <mach_rt.h>
65 #include <platforms.h>
66
67 #include <kern/ast.h>
68 #include <mach/port.h>
69 #include <mach/kern_return.h>
70 #include <mach/message.h>
71 #include <mach/mig_errors.h>
72 #include <mach/notify.h>
73 #include <kern/etap_macros.h>
74 #include <kern/ipc_mig.h>
75 #include <kern/ipc_kobject.h>
76 #include <kern/misc_protos.h>
77 #include <kern/mk_timer.h>
78 #include <ipc/ipc_object.h>
79 #include <ipc/ipc_kmsg.h>
80 #include <ipc/ipc_port.h>
81 #include <kern/counters.h>
82
83
84 void
85 def_pager_hash_insert(
86 ipc_port_t name_port);
87 void pager_mux_hash_insert(
88 ipc_port_t port,
89 rpc_subsystem_t rec);
90 void pager_mux_hash_delete(
91 ipc_port_t port);
92 rpc_subsystem_t pager_mux_hash_lookup(
93 ipc_port_t port);
94
95
96 /*
97 * Routine: ipc_kobject_notify
98 * Purpose:
99 * Deliver notifications to kobjects that care about them.
100 */
101 boolean_t
102 ipc_kobject_notify(
103 mach_msg_header_t *request_header,
104 mach_msg_header_t *reply_header);
105
106 #include <mach/ndr.h>
107
108 typedef struct {
109 mach_msg_id_t num;
110 mig_routine_t routine;
111 int size;
112 #if MACH_COUNTERS
113 mach_counter_t callcount;
114 #endif
115 } mig_hash_t;
116
117 #define MAX_MIG_ENTRIES 1024
118 #define MIG_HASH(x) (x)
119
120 #ifndef max
121 #define max(a,b) (((a) > (b)) ? (a) : (b))
122 #endif /* max */
123
124 mig_hash_t mig_buckets[MAX_MIG_ENTRIES];
125 int mig_table_max_displ;
126 mach_msg_size_t mig_reply_size;
127
128
129 #include <mach/mach_port_server.h>
130 #include <mach/mach_host_server.h>
131 #include <mach/host_priv_server.h>
132 #include <mach/host_security_server.h>
133 #include <mach/clock_server.h>
134 #include <mach/clock_priv_server.h>
135 #include <mach/ledger_server.h>
136 #include <mach/lock_set_server.h>
137 #include <default_pager/default_pager_object_server.h>
138 #include <mach/memory_object_server.h>
139 #include <mach/memory_object_control_server.h>
140 #include <mach/memory_object_default_server.h>
141 #include <mach/memory_object_name_server.h>
142 #include <mach/processor_server.h>
143 #include <mach/processor_set_server.h>
144 #include <mach/semaphore_server.h>
145 #include <mach/task_server.h>
146 #include <mach/vm_map_server.h>
147 #include <mach/thread_act_server.h>
148 #include <device/device_server.h>
149 #include <UserNotification/UNDReplyServer.h>
150
151 #if MACH_MACHINE_ROUTINES
152 #include <machine/machine_routines.h>
153 #endif /* MACH_MACHINE_ROUTINES */
154 #if XK_PROXY
155 #include <uk_xkern/xk_uproxy_server.h>
156 #endif /* XK_PROXY */
157
158
159 rpc_subsystem_t mig_e[] = {
160 (rpc_subsystem_t)&mach_port_subsystem,
161 (rpc_subsystem_t)&mach_host_subsystem,
162 (rpc_subsystem_t)&host_priv_subsystem,
163 (rpc_subsystem_t)&host_security_subsystem,
164 (rpc_subsystem_t)&clock_subsystem,
165 (rpc_subsystem_t)&clock_priv_subsystem,
166 (rpc_subsystem_t)&processor_subsystem,
167 (rpc_subsystem_t)&processor_set_subsystem,
168 (rpc_subsystem_t)&is_iokit_subsystem,
169 (rpc_subsystem_t)&dp_memory_object_subsystem,
170 (rpc_subsystem_t)&dp_memory_object_default_subsystem,
171 (rpc_subsystem_t)&memory_object_name_subsystem,
172 (rpc_subsystem_t)&default_pager_object_subsystem,
173 (rpc_subsystem_t)&lock_set_subsystem,
174 (rpc_subsystem_t)&ledger_subsystem,
175 (rpc_subsystem_t)&semaphore_subsystem,
176 (rpc_subsystem_t)&task_subsystem,
177 (rpc_subsystem_t)&thread_act_subsystem,
178 (rpc_subsystem_t)&vm_map_subsystem,
179 (rpc_subsystem_t)&UNDReply_subsystem,
180
181 #if XK_PROXY
182 (rpc_subsystem_t)&do_uproxy_xk_uproxy_subsystem,
183 #endif /* XK_PROXY */
184 #if MACH_MACHINE_ROUTINES
185 (rpc_subsystem_t)&MACHINE_SUBSYSTEM,
186 #endif /* MACH_MACHINE_ROUTINES */
187 #if MCMSG && iPSC860
188 (rpc_subsystem_t)&mcmsg_info_subsystem,
189 #endif /* MCMSG && iPSC860 */
190 };
191
192 void
193 mig_init(void)
194 {
195 register unsigned int i, n = sizeof(mig_e)/sizeof(rpc_subsystem_t);
196 register unsigned int howmany;
197 register mach_msg_id_t j, pos, nentry, range;
198
199 for (i = 0; i < n; i++) {
200 range = mig_e[i]->end - mig_e[i]->start;
201 if (!mig_e[i]->start || range < 0)
202 panic("the msgh_ids in mig_e[] aren't valid!");
203 mig_reply_size = max(mig_reply_size, mig_e[i]->maxsize);
204
205 for (j = 0; j < range; j++) {
206 if (mig_e[i]->routine[j].stub_routine) {
207 /* Only put real entries in the table */
208 nentry = j + mig_e[i]->start;
209 for (pos = MIG_HASH(nentry) % MAX_MIG_ENTRIES, howmany = 1;
210 mig_buckets[pos].num;
211 pos = ++pos % MAX_MIG_ENTRIES, howmany++) {
212 if (mig_buckets[pos].num == nentry) {
213 printf("message id = %d\n", nentry);
214 panic("multiple entries with the same msgh_id");
215 }
216 if (howmany == MAX_MIG_ENTRIES)
217 panic("the mig dispatch table is too small");
218 }
219
220 mig_buckets[pos].num = nentry;
221 mig_buckets[pos].routine = mig_e[i]->routine[j].stub_routine;
222 if (mig_e[i]->routine[j].max_reply_msg)
223 mig_buckets[pos].size = mig_e[i]->routine[j].max_reply_msg;
224 else
225 mig_buckets[pos].size = mig_e[i]->maxsize;
226
227 mig_table_max_displ = max(howmany, mig_table_max_displ);
228 }
229 }
230 }
231 }
232
233
234 #define PAGER_MUX_HASH_COUNT 127
235
236
237 struct pager_mux_entry {
238 queue_chain_t links;
239 ipc_port_t name;
240 rpc_subsystem_t pager_object;
241 };
242 typedef struct pager_mux_entry *pager_mux_entry_t;
243
244 queue_head_t pager_mux_hashtable[PAGER_MUX_HASH_COUNT];
245 zone_t pager_mux_hash_zone;
246
247 decl_mutex_data(,pager_mux_hash_lock)
248
249 #define pager_mux_hash(name_port) \
250 (((natural_t)(name_port) & 0xffffff) % PAGER_MUX_HASH_COUNT)
251
252
253 rpc_subsystem_t
254 pager_mux_hash_lookup(
255 ipc_port_t name_port)
256 {
257 register queue_t bucket;
258 register pager_mux_entry_t entry;
259 register rpc_subsystem_t pager_object;
260
261 bucket = &pager_mux_hashtable[pager_mux_hash(name_port)];
262
263 mutex_lock(&pager_mux_hash_lock);
264 for (entry = (pager_mux_entry_t)queue_first(bucket);
265 !queue_end(bucket, &entry->links);
266 entry = (pager_mux_entry_t)queue_next(&entry->links)) {
267 if (entry->name == name_port) {
268 pager_object = entry->pager_object;
269 /* don't need to reference the object, it can't disappear */
270 /* pager_mux_reference(pager_object); */
271 mutex_unlock(&pager_mux_hash_lock);
272 return (pager_object);
273 }
274 }
275 mutex_unlock(&pager_mux_hash_lock);
276 return (rpc_subsystem_t)0;
277 }
278
279
280 void
281 pager_mux_hash_init(void)
282 {
283 register int i;
284 register vm_size_t size;
285
286 size = sizeof(struct pager_mux_entry);
287 pager_mux_hash_zone = zinit(
288 size,
289 size * 2000,
290 PAGE_SIZE,
291 "pager mux port hash");
292 for (i = 0; i < PAGER_MUX_HASH_COUNT; i++)
293 queue_init(&pager_mux_hashtable[i]);
294 mutex_init(&pager_mux_hash_lock, ETAP_IO_DEV_PAGEH);
295 }
296
297
298 void
299 pager_mux_hash_insert(
300 ipc_port_t name_port,
301 rpc_subsystem_t pager_object)
302 {
303 register pager_mux_entry_t new_entry;
304
305 new_entry = (pager_mux_entry_t) zalloc(pager_mux_hash_zone);
306 new_entry->links.prev = (queue_entry_t) 0;
307 new_entry->links.next = (queue_entry_t) 0;
308 new_entry->name = name_port;
309 new_entry->pager_object = pager_object;
310
311 mutex_lock(&pager_mux_hash_lock);
312 queue_enter((&pager_mux_hashtable[pager_mux_hash(name_port)]),
313 new_entry, pager_mux_entry_t, links);
314 mutex_unlock(&pager_mux_hash_lock);
315 }
316
317 void
318 pager_mux_hash_delete(
319 ipc_port_t name_port)
320 {
321 register queue_t bucket;
322 register pager_mux_entry_t entry;
323
324 bucket = &pager_mux_hashtable[pager_mux_hash(name_port)];
325
326 mutex_lock(&pager_mux_hash_lock);
327 for (entry = (pager_mux_entry_t)queue_first(bucket);
328 !queue_end(bucket, &entry->links);
329 entry = (pager_mux_entry_t)queue_next(&entry->links)) {
330 if (entry->name == name_port) {
331 queue_remove(bucket, entry, pager_mux_entry_t, links);
332 zfree(pager_mux_hash_zone, (vm_offset_t)entry);
333 break;
334 }
335 }
336 mutex_unlock(&pager_mux_hash_lock);
337 }
338
339
340 /*
341 * Routine: ipc_kobject_server
342 * Purpose:
343 * Handle a message sent to the kernel.
344 * Generates a reply message.
345 * Version for Untyped IPC.
346 * Conditions:
347 * Nothing locked.
348 */
349
350 ipc_kmsg_t
351 ipc_kobject_server(
352 ipc_kmsg_t request)
353 {
354 mach_msg_size_t reply_size;
355 ipc_kmsg_t reply;
356 kern_return_t kr;
357 mig_routine_t routine;
358 ipc_port_t *destp;
359 mach_msg_format_0_trailer_t *trailer;
360 register mig_hash_t *ptr;
361 unsigned int th;
362
363 /* Only fetch current thread if ETAP is configured */
364 ETAP_DATA_LOAD(th, current_thread());
365 ETAP_PROBE_DATA(ETAP_P_SYSCALL_MACH,
366 EVENT_BEGIN,
367 ((thread_t) th),
368 &request->ikm_header.msgh_id,
369 sizeof(int));
370 /*
371 * Find out corresponding mig_hash entry if any
372 */
373 {
374 register int key = request->ikm_header.msgh_id;
375 register int i = MIG_HASH(key);
376 register int max_iter = mig_table_max_displ;
377
378 do
379 ptr = &mig_buckets[i++ % MAX_MIG_ENTRIES];
380 while (key != ptr->num && ptr->num && --max_iter);
381
382 if (!ptr->routine || key != ptr->num) {
383 ptr = (mig_hash_t *)0;
384 reply_size = mig_reply_size;
385 } else {
386 reply_size = ptr->size;
387 #if MACH_COUNTER
388 ptr->callcount++;
389 #endif
390 }
391 }
392
393 /* round up for trailer size */
394 reply_size += MAX_TRAILER_SIZE;
395 reply = ipc_kmsg_alloc(reply_size);
396
397 if (reply == IKM_NULL) {
398 printf("ipc_kobject_server: dropping request\n");
399 ipc_kmsg_destroy(request);
400 return IKM_NULL;
401 }
402
403 /*
404 * Initialize reply message.
405 */
406 {
407 #define InP ((mach_msg_header_t *) &request->ikm_header)
408 #define OutP ((mig_reply_error_t *) &reply->ikm_header)
409
410 OutP->NDR = NDR_record;
411 OutP->Head.msgh_size = sizeof(mig_reply_error_t);
412
413 OutP->Head.msgh_bits =
414 MACH_MSGH_BITS(MACH_MSGH_BITS_LOCAL(InP->msgh_bits), 0);
415 OutP->Head.msgh_remote_port = InP->msgh_local_port;
416 OutP->Head.msgh_local_port = MACH_PORT_NULL;
417 OutP->Head.msgh_id = InP->msgh_id + 100;
418
419 #undef InP
420 #undef OutP
421 }
422
423 /*
424 * Find the routine to call, and call it
425 * to perform the kernel function
426 */
427 {
428 if (ptr) {
429 (*ptr->routine)(&request->ikm_header, &reply->ikm_header);
430 kernel_task->messages_received++;
431 }
432 else {
433 if (!ipc_kobject_notify(&request->ikm_header, &reply->ikm_header)){
434 #if MACH_IPC_TEST
435 printf("ipc_kobject_server: bogus kernel message, id=%d\n",
436 request->ikm_header.msgh_id);
437 #endif /* MACH_IPC_TEST */
438 _MIG_MSGID_INVALID(request->ikm_header.msgh_id);
439
440 ((mig_reply_error_t *) &reply->ikm_header)->RetCode
441 = MIG_BAD_ID;
442 }
443 else
444 kernel_task->messages_received++;
445 }
446 kernel_task->messages_sent++;
447 }
448
449 /*
450 * Destroy destination. The following code differs from
451 * ipc_object_destroy in that we release the send-once
452 * right instead of generating a send-once notification
453 * (which would bring us here again, creating a loop).
454 * It also differs in that we only expect send or
455 * send-once rights, never receive rights.
456 *
457 * We set msgh_remote_port to IP_NULL so that the kmsg
458 * destroy routines don't try to destroy the port twice.
459 */
460 destp = (ipc_port_t *) &request->ikm_header.msgh_remote_port;
461 switch (MACH_MSGH_BITS_REMOTE(request->ikm_header.msgh_bits)) {
462 case MACH_MSG_TYPE_PORT_SEND:
463 ipc_port_release_send(*destp);
464 break;
465
466 case MACH_MSG_TYPE_PORT_SEND_ONCE:
467 ipc_port_release_sonce(*destp);
468 break;
469
470 default:
471 panic("ipc_object_destroy: strange destination rights");
472 }
473 *destp = IP_NULL;
474
475 if (!(reply->ikm_header.msgh_bits & MACH_MSGH_BITS_COMPLEX) &&
476 ((mig_reply_error_t *) &reply->ikm_header)->RetCode != KERN_SUCCESS)
477 kr = ((mig_reply_error_t *) &reply->ikm_header)->RetCode;
478 else
479 kr = KERN_SUCCESS;
480
481 if ((kr == KERN_SUCCESS) || (kr == MIG_NO_REPLY)) {
482 /*
483 * The server function is responsible for the contents
484 * of the message. The reply port right is moved
485 * to the reply message, and we have deallocated
486 * the destination port right, so we just need
487 * to free the kmsg.
488 */
489 ipc_kmsg_free(request);
490
491 } else {
492 /*
493 * The message contents of the request are intact.
494 * Destroy everthing except the reply port right,
495 * which is needed in the reply message.
496 */
497 request->ikm_header.msgh_local_port = MACH_PORT_NULL;
498 ipc_kmsg_destroy(request);
499 }
500
501 if (kr == MIG_NO_REPLY) {
502 /*
503 * The server function will send a reply message
504 * using the reply port right, which it has saved.
505 */
506
507 ipc_kmsg_free(reply);
508
509 ETAP_PROBE_DATA(ETAP_P_SYSCALL_MACH,
510 EVENT_END,
511 ((thread_t) th),
512 &request->ikm_header.msgh_id,
513 sizeof(int));
514
515 return IKM_NULL;
516 } else if (!IP_VALID((ipc_port_t)reply->ikm_header.msgh_remote_port)) {
517 /*
518 * Can't queue the reply message if the destination
519 * (the reply port) isn't valid.
520 */
521
522 ipc_kmsg_destroy(reply);
523
524 ETAP_PROBE_DATA(ETAP_P_SYSCALL_MACH,
525 EVENT_END,
526 ((thread_t) th),
527 &request->ikm_header.msgh_id,
528 sizeof(int));
529
530 return IKM_NULL;
531 }
532
533 trailer = (mach_msg_format_0_trailer_t *)
534 ((vm_offset_t)&reply->ikm_header + (int)reply->ikm_header.msgh_size);
535 trailer->msgh_sender = KERNEL_SECURITY_TOKEN;
536 trailer->msgh_trailer_type = MACH_MSG_TRAILER_FORMAT_0;
537 trailer->msgh_trailer_size = MACH_MSG_TRAILER_MINIMUM_SIZE;
538
539 ETAP_PROBE_DATA(ETAP_P_SYSCALL_MACH,
540 EVENT_END,
541 ((thread_t) th),
542 &request->ikm_header.msgh_id,
543 sizeof(int));
544
545 return reply;
546 }
547
548 /*
549 * Routine: ipc_kobject_set
550 * Purpose:
551 * Make a port represent a kernel object of the given type.
552 * The caller is responsible for handling refs for the
553 * kernel object, if necessary.
554 * Conditions:
555 * Nothing locked. The port must be active if setting
556 * a kobject linkage. Clearing a linkage is OK on an
557 * inactive port.
558 */
559 void
560 ipc_kobject_set(
561 ipc_port_t port,
562 ipc_kobject_t kobject,
563 ipc_kobject_type_t type)
564 {
565 ip_lock(port);
566 ipc_kobject_set_atomically(port, kobject, type);
567 ip_unlock(port);
568 }
569
570 void
571 ipc_kobject_set_atomically(
572 ipc_port_t port,
573 ipc_kobject_t kobject,
574 ipc_kobject_type_t type)
575 {
576 assert(type == IKOT_NONE || ip_active(port));
577 #if MACH_ASSERT
578 port->ip_spares[2] = (port->ip_bits & IO_BITS_KOTYPE);
579 #endif /* MACH_ASSERT */
580 port->ip_bits = (port->ip_bits &~ IO_BITS_KOTYPE) | type;
581 port->ip_kobject = kobject;
582 }
583
584 /*
585 * Routine: ipc_kobject_destroy
586 * Purpose:
587 * Release any kernel object resources associated
588 * with the port, which is being destroyed.
589 *
590 * This should only be needed when resources are
591 * associated with a user's port. In the normal case,
592 * when the kernel is the receiver, the code calling
593 * ipc_port_dealloc_kernel should clean up the resources.
594 * Conditions:
595 * The port is not locked, but it is dead.
596 */
597
598 void
599 ipc_kobject_destroy(
600 ipc_port_t port)
601 {
602 switch (ip_kotype(port)) {
603
604 case IKOT_TIMER:
605 mk_timer_port_destroy(port);
606 break;
607
608 case IKOT_NAMED_ENTRY:
609 mach_destroy_memory_entry(port);
610 break;
611
612 case IKOT_UPL:
613 mach_destroy_upl(port);
614 break;
615
616 default: /* XXX (bogon) */
617 vm_object_destroy(port);
618 break;
619 }
620 }
621
622
623 extern int vnode_pager_workaround;
624
625 boolean_t
626 ipc_kobject_notify(
627 mach_msg_header_t *request_header,
628 mach_msg_header_t *reply_header)
629 {
630 ipc_port_t port = (ipc_port_t) request_header->msgh_remote_port;
631 rpc_subsystem_t paging_subsystem_object;
632 mach_port_seqno_t seqno;
633
634 ((mig_reply_error_t *) reply_header)->RetCode = MIG_NO_REPLY;
635 switch (request_header->msgh_id) {
636 case MACH_NOTIFY_NO_SENDERS:
637 if(ip_kotype(port) == IKOT_NAMED_ENTRY) {
638 ip_lock(port);
639
640 /*
641 * Bring the sequence number and mscount in
642 * line with ipc_port_destroy assertion.
643 */
644 port->ip_mscount = 0;
645 port->ip_messages.imq_seqno = 0;
646 ipc_port_destroy(port); /* releases lock */
647 return TRUE;
648 }
649 paging_subsystem_object = pager_mux_hash_lookup(
650 (ipc_port_t)request_header->msgh_remote_port);
651 if(paging_subsystem_object == (rpc_subsystem_t)
652 &dp_memory_object_subsystem) {
653 default_pager_no_senders(
654 (ipc_port_t)request_header->msgh_remote_port,
655 seqno,
656 (mach_port_mscount_t)
657 ((mach_no_senders_notification_t *)
658 request_header)->not_count);
659 (ipc_port_t)reply_header->msgh_remote_port
660 = MACH_PORT_NULL;
661 return TRUE;
662 }
663 if(paging_subsystem_object == (rpc_subsystem_t)
664 &vnode_pager_workaround) {
665 vnode_pager_no_senders(
666 (ipc_port_t)request_header->msgh_remote_port,
667 (mach_port_mscount_t)
668 ((mach_no_senders_notification_t *)
669 request_header)->not_count);
670 (ipc_port_t)reply_header->msgh_remote_port
671 = MACH_PORT_NULL;
672 return TRUE;
673 }
674 break;
675 case MACH_NOTIFY_PORT_DELETED:
676 case MACH_NOTIFY_PORT_DESTROYED:
677 case MACH_NOTIFY_SEND_ONCE:
678 case MACH_NOTIFY_DEAD_NAME:
679 break;
680
681 default:
682 return FALSE;
683 }
684 switch (ip_kotype(port)) {
685
686 #ifdef IOKIT
687 case IKOT_IOKIT_OBJECT:
688 case IKOT_IOKIT_CONNECT:
689 case IKOT_IOKIT_SPARE:
690 {
691 extern boolean_t iokit_notify( mach_msg_header_t *msg);
692
693 return iokit_notify(request_header);
694 }
695 #endif
696 default:
697 return FALSE;
698 }
699 }
700
701
702
703 #include <mach_kdb.h>
704 #if MACH_COUNTERS && MACH_KDB
705
706 #include <ddb/db_output.h>
707 #include <ddb/db_sym.h>
708
709 #define printf kdbprintf
710
711 extern void kobjserver_stats(void);
712 extern void bucket_stats_print(mig_hash_t *bucket);
713
714 extern void kobjserver_stats_clear(void);
715
716
717 void
718 kobjserver_stats_clear(void)
719 {
720 int i;
721 for (i = 0; i < MAX_MIG_ENTRIES; i++) {
722 mig_buckets[i].callcount = 0;
723 }
724 }
725
726 void
727 kobjserver_stats(void)
728 {
729 register unsigned int i, n = sizeof(mig_e)/sizeof(rpc_subsystem_t);
730 register unsigned int howmany;
731 register mach_msg_id_t j, pos, nentry, range;
732
733 db_printf("Kobject server call counts:\n");
734 for (i = 0; i < n; i++) {
735 db_printf(" ");
736 db_printsym((vm_offset_t)mig_e[i], DB_STGY_ANY);
737 db_printf(":\n");
738 range = mig_e[i]->end - mig_e[i]->start;
739 if (!mig_e[i]->start || range < 0) continue;
740
741 for (j = 0; j < range; j++) {
742 nentry = j + mig_e[i]->start;
743 for (pos = MIG_HASH(nentry) % MAX_MIG_ENTRIES, howmany = 1;
744 mig_buckets[pos].num;
745 pos = ++pos % MAX_MIG_ENTRIES, howmany++) {
746 if (mig_buckets[pos].num == nentry)
747 bucket_stats_print(&mig_buckets[pos]);
748 }
749 }
750 }
751 }
752
753 void
754 bucket_stats_print(mig_hash_t *bucket)
755 {
756 if (bucket->callcount) {
757 db_printf(" ");
758 db_printsym((vm_offset_t)bucket->routine, DB_STGY_ANY);
759 db_printf(" (%d):\t%d\n", bucket->num, bucket->callcount);
760 }
761 }
762
763
764 #endif /* MACH_COUNTERS && MACH_KDB */