]> git.saurik.com Git - apple/xnu.git/blob - osfmk/kern/kmod.c
xnu-344.49.tar.gz
[apple/xnu.git] / osfmk / kern / kmod.c
1 /*
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
7 *
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
13 * file.
14 *
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.
22 *
23 * @APPLE_LICENSE_HEADER_END@
24 */
25 /*
26 * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
27 *
28 * HISTORY
29 *
30 * 1999 Mar 29 rsulack created.
31 */
32
33 #include <mach/mach_types.h>
34 #include <mach/vm_types.h>
35 #include <mach/kern_return.h>
36 #include <kern/kern_types.h>
37 #include <vm/vm_kern.h>
38 #include <kern/thread.h>
39 #include <mach-o/mach_header.h>
40
41 #include <mach_host.h>
42
43 #define WRITE_PROTECT_MODULE_TEXT (0)
44
45 kmod_info_t *kmod = 0;
46 static int kmod_index = 1;
47
48 decl_simple_lock_data(,kmod_lock)
49 decl_simple_lock_data(,kmod_queue_lock)
50
51 typedef struct cmd_queue_entry {
52 queue_chain_t links;
53 vm_address_t data;
54 vm_size_t size;
55 } cmd_queue_entry_t;
56
57 queue_head_t kmod_cmd_queue;
58
59 void
60 kmod_init()
61 {
62 simple_lock_init(&kmod_lock, ETAP_MISC_Q);
63 simple_lock_init(&kmod_queue_lock, ETAP_MISC_Q);
64 queue_init(&kmod_cmd_queue);
65 }
66
67 kmod_info_t *
68 kmod_lookupbyid(kmod_t id)
69 {
70 kmod_info_t *k = 0;
71
72 k = kmod;
73 while (k) {
74 if (k->id == id) break;
75 k = k->next;
76 }
77
78 return k;
79 }
80
81 kmod_info_t *
82 kmod_lookupbyname(const char * name)
83 {
84 kmod_info_t *k = 0;
85
86 k = kmod;
87 while (k) {
88 if (!strcmp(k->name, name)) break;
89 k = k->next;
90 }
91
92 return k;
93 }
94
95 kmod_info_t *
96 kmod_lookupbyid_locked(kmod_t id)
97 {
98 kmod_info_t *k = 0;
99 kmod_info_t *kc = 0;
100
101 kc = (kmod_info_t *)kalloc(sizeof(kmod_info_t));
102 if (!kc) return kc;
103
104 simple_lock(&kmod_queue_lock);
105 k = kmod_lookupbyid(id);
106 if (k) {
107 bcopy((char*)k, (char *)kc, sizeof(kmod_info_t));
108 }
109 finish:
110 simple_unlock(&kmod_queue_lock);
111
112 if (k == 0) {
113 kfree((vm_offset_t)kc, sizeof(kmod_info_t));
114 kc = 0;
115 }
116 return kc;
117 }
118
119 kmod_info_t *
120 kmod_lookupbyname_locked(const char * name)
121 {
122 kmod_info_t *k = 0;
123 kmod_info_t *kc = 0;
124
125 kc = (kmod_info_t *)kalloc(sizeof(kmod_info_t));
126 if (!kc) return kc;
127
128 simple_lock(&kmod_queue_lock);
129 k = kmod_lookupbyname(name);
130 if (k) {
131 bcopy((char *)k, (char *)kc, sizeof(kmod_info_t));
132 }
133 finish:
134 simple_unlock(&kmod_queue_lock);
135
136 if (k == 0) {
137 kfree((vm_offset_t)kc, sizeof(kmod_info_t));
138 kc = 0;
139 }
140 return kc;
141 }
142
143 // XXX add a nocopy flag??
144
145 kern_return_t
146 kmod_queue_cmd(vm_address_t data, vm_size_t size)
147 {
148 kern_return_t rc;
149 cmd_queue_entry_t *e = (cmd_queue_entry_t *)kalloc(sizeof(struct cmd_queue_entry));
150 if (!e) return KERN_RESOURCE_SHORTAGE;
151
152 rc = kmem_alloc(kernel_map, &e->data, size);
153 if (rc != KERN_SUCCESS) {
154 kfree((vm_offset_t)e, sizeof(struct cmd_queue_entry));
155 return rc;
156 }
157 e->size = size;
158 bcopy((void *)data, (void *)e->data, size);
159
160 simple_lock(&kmod_queue_lock);
161 enqueue_tail(&kmod_cmd_queue, (queue_entry_t)e);
162 simple_unlock(&kmod_queue_lock);
163
164 thread_wakeup_one((event_t)&kmod_cmd_queue);
165
166 return KERN_SUCCESS;
167 }
168
169 kern_return_t
170 kmod_load_extension(char *name)
171 {
172 kmod_load_extension_cmd_t *data;
173 vm_size_t size;
174
175 size = sizeof(kmod_load_extension_cmd_t);
176 data = (kmod_load_extension_cmd_t *)kalloc(size);
177 if (!data) return KERN_RESOURCE_SHORTAGE;
178
179 data->type = KMOD_LOAD_EXTENSION_PACKET;
180 strncpy(data->name, name, KMOD_MAX_NAME);
181
182 return kmod_queue_cmd((vm_address_t)data, size);
183 }
184
185 kern_return_t
186 kmod_load_extension_with_dependencies(char *name, char **dependencies)
187 {
188 kmod_load_with_dependencies_cmd_t *data;
189 vm_size_t size;
190 char **c;
191 int i, count = 0;
192
193 c = dependencies;
194 if (c) {
195 while (*c) {
196 count++; c++;
197 }
198 }
199 size = sizeof(int) + KMOD_MAX_NAME * (count + 1) + 1;
200 data = (kmod_load_with_dependencies_cmd_t *)kalloc(size);
201 if (!data) return KERN_RESOURCE_SHORTAGE;
202
203 data->type = KMOD_LOAD_WITH_DEPENDENCIES_PACKET;
204 strncpy(data->name, name, KMOD_MAX_NAME);
205
206 c = dependencies;
207 for (i=0; i < count; i++) {
208 strncpy(data->dependencies[i], *c, KMOD_MAX_NAME);
209 c++;
210 }
211 data->dependencies[count][0] = 0;
212
213 return kmod_queue_cmd((vm_address_t)data, size);
214 }
215 kern_return_t
216 kmod_send_generic(int type, void *generic_data, int size)
217 {
218 kmod_generic_cmd_t *data;
219
220 data = (kmod_generic_cmd_t *)kalloc(size + sizeof(int));
221 if (!data) return KERN_RESOURCE_SHORTAGE;
222
223 data->type = type;
224 bcopy(data->data, generic_data, size);
225
226 return kmod_queue_cmd((vm_address_t)data, size + sizeof(int));
227 }
228
229 kern_return_t
230 kmod_create_internal(kmod_info_t *info, kmod_t *id)
231 {
232 kern_return_t rc;
233
234 if (!info) return KERN_INVALID_ADDRESS;
235
236 // double check for page alignment
237 if ((info->address | info->hdr_size) & (PAGE_SIZE - 1)) {
238 return KERN_INVALID_ADDRESS;
239 }
240
241 rc = vm_map_wire(kernel_map, info->address + info->hdr_size,
242 info->address + info->size, VM_PROT_DEFAULT, FALSE);
243 if (rc != KERN_SUCCESS) {
244 return rc;
245 }
246 #if WRITE_PROTECT_MODULE_TEXT
247 {
248 struct section * sect = getsectbynamefromheader(
249 (struct mach_header*) info->address, "__TEXT", "__text");
250
251 if(sect) {
252 (void) vm_map_protect(kernel_map, round_page(sect->addr), trunc_page(sect->addr + sect->size),
253 VM_PROT_READ|VM_PROT_EXECUTE, TRUE);
254 }
255 }
256 #endif
257
258 simple_lock(&kmod_lock);
259
260 // check to see if already loaded
261 if (kmod_lookupbyname(info->name)) {
262 simple_unlock(&kmod_lock);
263 rc = vm_map_unwire(kernel_map, info->address + info->hdr_size,
264 info->address + info->size, FALSE);
265 assert(rc == KERN_SUCCESS);
266 return KERN_INVALID_ARGUMENT;
267 }
268
269 info->id = kmod_index++;
270 info->reference_count = 0;
271
272 info->next = kmod;
273 kmod = info;
274
275 *id = info->id;
276
277 simple_unlock(&kmod_lock);
278
279 #if DEBUG
280 printf("kmod_create: %s (id %d), %d pages loaded at 0x%x, header size 0x%x\n",
281 info->name, info->id, info->size / PAGE_SIZE, info->address, info->hdr_size);
282 #endif DEBUG
283
284 return KERN_SUCCESS;
285 }
286
287
288 kern_return_t
289 kmod_create(host_priv_t host_priv,
290 kmod_info_t *info,
291 kmod_t *id)
292 {
293 if (host_priv == HOST_PRIV_NULL) return KERN_INVALID_HOST;
294 return kmod_create_internal(info, id);
295 }
296
297 kern_return_t
298 kmod_create_fake(const char *name, const char *version)
299 {
300 kmod_info_t *info;
301
302 if (!name || ! version ||
303 (1 + strlen(name) > KMOD_MAX_NAME) ||
304 (1 + strlen(version) > KMOD_MAX_NAME)) {
305
306 return KERN_INVALID_ARGUMENT;
307 }
308
309 info = (kmod_info_t *)kalloc(sizeof(kmod_info_t));
310 if (!info) {
311 return KERN_RESOURCE_SHORTAGE;
312 }
313
314 // make de fake
315 info->info_version = KMOD_INFO_VERSION;
316 bcopy(name, info->name, 1 + strlen(name));
317 bcopy(version, info->version, 1 + strlen(version)); //NIK fixed this part
318 info->reference_count = 1; // keep it from unloading, starting, stopping
319 info->reference_list = 0;
320 info->address = info->size = info->hdr_size = 0;
321 info->start = info->stop = 0;
322
323 simple_lock(&kmod_lock);
324
325 // check to see if already "loaded"
326 if (kmod_lookupbyname(info->name)) {
327 simple_unlock(&kmod_lock);
328 return KERN_INVALID_ARGUMENT;
329 }
330
331 info->id = kmod_index++;
332
333 info->next = kmod;
334 kmod = info;
335
336 simple_unlock(&kmod_lock);
337
338 return KERN_SUCCESS;
339 }
340
341 kern_return_t
342 kmod_destroy_internal(kmod_t id)
343 {
344 kern_return_t rc;
345 kmod_info_t *k;
346 kmod_info_t *p;
347
348 simple_lock(&kmod_lock);
349
350 k = p = kmod;
351 while (k) {
352 if (k->id == id) {
353 kmod_reference_t *r, *t;
354
355 if (k->reference_count != 0) {
356 simple_unlock(&kmod_lock);
357 return KERN_INVALID_ARGUMENT;
358 }
359
360 if (k == p) { // first element
361 kmod = k->next;
362 } else {
363 p->next = k->next;
364 }
365 simple_unlock(&kmod_lock);
366
367 r = k->reference_list;
368 while (r) {
369 r->info->reference_count--;
370 t = r;
371 r = r->next;
372 kfree((vm_offset_t)t, sizeof(struct kmod_reference));
373 }
374
375 #if DEBUG
376 printf("kmod_destroy: %s (id %d), deallocating %d pages starting at 0x%x\n",
377 k->name, k->id, k->size / PAGE_SIZE, k->address);
378 #endif DEBUG
379
380 rc = vm_map_unwire(kernel_map, k->address + k->hdr_size,
381 k->address + k->size, FALSE);
382 assert(rc == KERN_SUCCESS);
383
384 rc = vm_deallocate(kernel_map, k->address, k->size);
385 assert(rc == KERN_SUCCESS);
386
387 return KERN_SUCCESS;
388 }
389 p = k;
390 k = k->next;
391 }
392
393 simple_unlock(&kmod_lock);
394
395 return KERN_INVALID_ARGUMENT;
396 }
397
398
399 kern_return_t
400 kmod_destroy(host_priv_t host_priv,
401 kmod_t id)
402 {
403 if (host_priv == HOST_PRIV_NULL) return KERN_INVALID_HOST;
404 return kmod_destroy_internal(id);
405 }
406
407
408 kern_return_t
409 kmod_start_or_stop(
410 kmod_t id,
411 int start,
412 kmod_args_t *data,
413 mach_msg_type_number_t *dataCount)
414 {
415 kern_return_t rc = KERN_SUCCESS;
416 void * user_data = 0;
417 kern_return_t (*func)();
418 kmod_info_t *k;
419
420 simple_lock(&kmod_lock);
421
422 k = kmod_lookupbyid(id);
423 if (!k || k->reference_count) {
424 simple_unlock(&kmod_lock);
425 rc = KERN_INVALID_ARGUMENT;
426 goto finish;
427 }
428
429 if (start) {
430 func = (void *)k->start;
431 } else {
432 func = (void *)k->stop;
433 }
434
435 simple_unlock(&kmod_lock);
436
437 //
438 // call kmod entry point
439 //
440 if (data && dataCount && *data && *dataCount) {
441 vm_map_copyout(kernel_map, (vm_offset_t *)&user_data, (vm_map_copy_t)*data);
442 }
443
444 rc = (*func)(k, user_data);
445
446 finish:
447
448 if (user_data) {
449 (void) vm_deallocate(kernel_map, (vm_offset_t)user_data, *dataCount);
450 }
451 if (data) *data = 0;
452 if (dataCount) *dataCount = 0;
453
454 return rc;
455 }
456
457
458 /*
459 * The retain and release calls take no user data, but the caller
460 * may have sent some in error (the MIG definition allows it).
461 * If this is the case, they will just return that same data
462 * right back to the caller (since they never touch the *data and
463 * *dataCount fields).
464 */
465 kern_return_t
466 kmod_retain(kmod_t id)
467 {
468 kern_return_t rc = KERN_SUCCESS;
469
470 kmod_info_t *t; // reference to
471 kmod_info_t *f; // reference from
472 kmod_reference_t *r = 0;
473
474 r = (kmod_reference_t *)kalloc(sizeof(struct kmod_reference));
475 if (!r) {
476 rc = KERN_RESOURCE_SHORTAGE;
477 goto finish;
478 }
479
480 simple_lock(&kmod_lock);
481
482 t = kmod_lookupbyid(KMOD_UNPACK_TO_ID(id));
483 f = kmod_lookupbyid(KMOD_UNPACK_FROM_ID(id));
484 if (!t || !f) {
485 simple_unlock(&kmod_lock);
486 if (r) kfree((vm_offset_t)r, sizeof(struct kmod_reference));
487 rc = KERN_INVALID_ARGUMENT;
488 goto finish;
489 }
490
491 r->next = f->reference_list;
492 r->info = t;
493 f->reference_list = r;
494 t->reference_count++;
495
496 simple_unlock(&kmod_lock);
497
498 finish:
499
500 return rc;
501 }
502
503
504 kern_return_t
505 kmod_release(kmod_t id)
506 {
507 kern_return_t rc = KERN_INVALID_ARGUMENT;
508
509 kmod_info_t *t; // reference to
510 kmod_info_t *f; // reference from
511 kmod_reference_t *r = 0;
512 kmod_reference_t * p;
513
514 simple_lock(&kmod_lock);
515
516 t = kmod_lookupbyid(KMOD_UNPACK_TO_ID(id));
517 f = kmod_lookupbyid(KMOD_UNPACK_FROM_ID(id));
518 if (!t || !f) {
519 rc = KERN_INVALID_ARGUMENT;
520 goto finish;
521 }
522
523 p = r = f->reference_list;
524 while (r) {
525 if (r->info == t) {
526 if (p == r) { // first element
527 f->reference_list = r->next;
528 } else {
529 p->next = r->next;
530 }
531 r->info->reference_count--;
532
533 simple_unlock(&kmod_lock);
534 kfree((vm_offset_t)r, sizeof(struct kmod_reference));
535 rc = KERN_SUCCESS;
536 goto finish;
537 }
538 p = r;
539 r = r->next;
540 }
541
542 simple_unlock(&kmod_lock);
543
544 finish:
545
546 return rc;
547 }
548
549
550 kern_return_t
551 kmod_control(host_priv_t host_priv,
552 kmod_t id,
553 kmod_control_flavor_t flavor,
554 kmod_args_t *data,
555 mach_msg_type_number_t *dataCount)
556 {
557 kern_return_t rc = KERN_SUCCESS;
558
559 if (host_priv == HOST_PRIV_NULL) return KERN_INVALID_HOST;
560
561 switch (flavor) {
562
563 case KMOD_CNTL_START:
564 case KMOD_CNTL_STOP:
565 {
566 rc = kmod_start_or_stop(id, (flavor == KMOD_CNTL_START),
567 data, dataCount);
568 break;
569 }
570
571 case KMOD_CNTL_RETAIN:
572 {
573 rc = kmod_retain(id);
574 break;
575 }
576
577 case KMOD_CNTL_RELEASE:
578 {
579 rc = kmod_release(id);
580 break;
581 }
582
583 case KMOD_CNTL_GET_CMD:
584 {
585
586 cmd_queue_entry_t *e;
587
588 /*
589 * Throw away any data the user may have sent in error.
590 * We must do this, because we are likely to return to
591 * some data for these commands (thus causing a leak of
592 * whatever data the user sent us in error).
593 */
594 if (*data && *dataCount) {
595 vm_map_copy_discard(*data);
596 *data = 0;
597 *dataCount = 0;
598 }
599
600 simple_lock(&kmod_queue_lock);
601
602 if (queue_empty(&kmod_cmd_queue)) {
603 wait_result_t res;
604
605 res = thread_sleep_simple_lock((event_t)&kmod_cmd_queue,
606 &kmod_queue_lock,
607 THREAD_ABORTSAFE);
608 if (queue_empty(&kmod_cmd_queue)) {
609 // we must have been interrupted!
610 simple_unlock(&kmod_queue_lock);
611 assert(res == THREAD_INTERRUPTED);
612 return KERN_ABORTED;
613 }
614 }
615 e = (cmd_queue_entry_t *)dequeue_head(&kmod_cmd_queue);
616
617 simple_unlock(&kmod_queue_lock);
618
619 rc = vm_map_copyin(kernel_map, e->data, e->size, TRUE, (vm_map_copy_t *)data);
620 if (rc) {
621 simple_lock(&kmod_queue_lock);
622 enqueue_head(&kmod_cmd_queue, (queue_entry_t)e);
623 simple_unlock(&kmod_queue_lock);
624 *data = 0;
625 *dataCount = 0;
626 return rc;
627 }
628 *dataCount = e->size;
629
630 kfree((vm_offset_t)e, sizeof(struct cmd_queue_entry));
631
632 break;
633 }
634
635 default:
636 rc = KERN_INVALID_ARGUMENT;
637 }
638
639 return rc;
640 };
641
642
643 kern_return_t
644 kmod_get_info(host_t host,
645 kmod_info_array_t *kmods,
646 mach_msg_type_number_t *kmodCount)
647 {
648 vm_offset_t data;
649 kmod_info_t *k, *p1;
650 kmod_reference_t *r, *p2;
651 int ref_count;
652 unsigned size = 0;
653 kern_return_t rc = KERN_SUCCESS;
654
655 *kmods = (void *)0;
656 *kmodCount = 0;
657
658 retry:
659 simple_lock(&kmod_lock);
660 size = 0;
661 k = kmod;
662 while (k) {
663 size += sizeof(kmod_info_t);
664 r = k->reference_list;
665 while (r) {
666 size +=sizeof(kmod_reference_t);
667 r = r->next;
668 }
669 k = k->next;
670 }
671 simple_unlock(&kmod_lock);
672 if (!size) return KERN_SUCCESS;
673
674 rc = kmem_alloc(kernel_map, &data, size);
675 if (rc) return rc;
676
677 // copy kmod into data, retry if kmod's size has changed (grown)
678 // the copied out data is tweeked to figure what's what at user level
679 // change the copied out k->next pointers to point to themselves
680 // change the k->reference into a count, tack the references on
681 // the end of the data packet in the order they are found
682
683 simple_lock(&kmod_lock);
684 k = kmod; p1 = (kmod_info_t *)data;
685 while (k) {
686 if ((p1 + 1) > (kmod_info_t *)(data + size)) {
687 simple_unlock(&kmod_lock);
688 kmem_free(kernel_map, data, size);
689 goto retry;
690 }
691
692 *p1 = *k;
693 if (k->next) p1->next = k;
694 p1++; k = k->next;
695 }
696
697 p2 = (kmod_reference_t *)p1;
698 k = kmod; p1 = (kmod_info_t *)data;
699 while (k) {
700 r = k->reference_list; ref_count = 0;
701 while (r) {
702 if ((p2 + 1) > (kmod_reference_t *)(data + size)) {
703 simple_unlock(&kmod_lock);
704 kmem_free(kernel_map, data, size);
705 goto retry;
706 }
707 // note the last 'k' in the chain has its next == 0
708 // since there can only be one like that,
709 // this case is handled by the caller
710 *p2 = *r;
711 p2++; r = r->next; ref_count++;
712 }
713 p1->reference_list = (kmod_reference_t *)ref_count;
714 p1++; k = k->next;
715 }
716 simple_unlock(&kmod_lock);
717
718 rc = vm_map_copyin(kernel_map, data, size, TRUE, (vm_map_copy_t *)kmods);
719 if (rc) {
720 kmem_free(kernel_map, data, size);
721 *kmods = 0;
722 *kmodCount = 0;
723 return rc;
724 }
725 *kmodCount = size;
726
727 return KERN_SUCCESS;
728 }
729
730 static kern_return_t
731 kmod_call_funcs_in_section(struct mach_header *header, const char *sectName)
732 {
733 typedef void (*Routine)(void);
734 Routine * routines;
735 int size, i;
736
737 if (header->magic != MH_MAGIC) {
738 return KERN_INVALID_ARGUMENT;
739 }
740
741 routines = (Routine *) getsectdatafromheader(header, SEG_TEXT, (char *) sectName, &size);
742 if (!routines) return KERN_SUCCESS;
743
744 size /= sizeof(Routine);
745 for (i = 0; i < size; i++) {
746 (*routines[i])();
747 }
748
749 return KERN_SUCCESS;
750 }
751
752 kern_return_t
753 kmod_initialize_cpp(kmod_info_t *info)
754 {
755 return kmod_call_funcs_in_section((struct mach_header *)info->address, "__constructor");
756 }
757
758 kern_return_t
759 kmod_finalize_cpp(kmod_info_t *info)
760 {
761 return kmod_call_funcs_in_section((struct mach_header *)info->address, "__destructor");
762 }
763
764 kern_return_t
765 kmod_default_start(struct kmod_info *ki, void *data)
766 {
767 return KMOD_RETURN_SUCCESS;
768 }
769
770 kern_return_t
771 kmod_default_stop(struct kmod_info *ki, void *data)
772 {
773 return KMOD_RETURN_SUCCESS;
774 }
775
776 void
777 kmod_dump(vm_offset_t *addr, unsigned int cnt)
778 {
779 vm_offset_t * kscan_addr = 0;
780 vm_offset_t * rscan_addr = 0;
781 kmod_info_t * k;
782 kmod_reference_t * r;
783 int i, j;
784 int found_kmod = 0;
785 int kmod_scan_stopped = 0;
786 kmod_info_t * stop_kmod = 0;
787 int ref_scan_stopped = 0;
788 kmod_reference_t * stop_ref = 0;
789
790 for (k = kmod; k; k = k->next) {
791 if (!k->address) {
792 continue; // skip fake entries for built-in kernel components
793 }
794 if (pmap_extract(kernel_pmap, (vm_offset_t)k) == 0) {
795 kdb_printf(" kmod scan stopped due to missing "
796 "kmod page: %08x\n", stop_kmod);
797 break;
798 }
799 for (i = 0, kscan_addr = addr; i < cnt; i++, kscan_addr++) {
800 if ((*kscan_addr >= k->address) &&
801 (*kscan_addr < (k->address + k->size))) {
802
803 if (!found_kmod) {
804 kdb_printf(" Kernel loadable modules in backtrace "
805 "(with dependencies):\n");
806 }
807 found_kmod = 1;
808 kdb_printf(" %s(%s)@0x%x\n",
809 k->name, k->version, k->address);
810
811 for (r = k->reference_list; r; r = r->next) {
812 kmod_info_t * rinfo;
813
814 if (pmap_extract(kernel_pmap, (vm_offset_t)r) == 0) {
815 kdb_printf(" kmod dependency scan stopped "
816 "due to missing dependency page: %08x\n", r);
817 break;
818 }
819
820 rinfo = r->info;
821
822 if (!rinfo->address) {
823 continue; // skip fake entries for built-ins
824 }
825
826 if (pmap_extract(kernel_pmap, (vm_offset_t)rinfo) == 0) {
827 kdb_printf(" kmod dependency scan stopped "
828 "due to missing kmod page: %08x\n", rinfo);
829 break;
830 }
831
832 kdb_printf(" dependency: %s(%s)@0x%x\n",
833 rinfo->name, rinfo->version, rinfo->address);
834 }
835
836 break; // only report this kmod for one backtrace address
837 }
838 }
839 }
840
841 return;
842 }