]>
Commit | Line | Data |
---|---|---|
1c79356b A |
1 | /* |
2 | * Copyright (c) 2000 Apple Computer, Inc. All rights reserved. | |
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 | #include <IOKit/IOLib.h> | |
29 | #include <mach/kmod.h> | |
30 | #include <libkern/c++/OSDictionary.h> | |
31 | ||
55e303ae | 32 | #include <libsa/kext.h> |
1c79356b | 33 | #include <libsa/catalogue.h> |
1c79356b | 34 | #include <libsa/malloc.h> |
1c79356b | 35 | |
0b4e3aa0 A |
36 | #include "kld_patch.h" |
37 | ||
1c79356b A |
38 | /***** |
39 | * This function is used by IOCatalogue to load a kernel | |
40 | * extension. libsa initially sets it to be a function | |
41 | * that uses libkld to load and link the extension from | |
42 | * within the kernel. Once the root filesystem is up, | |
43 | * this gets switch to the kmod_load_extension() function, | |
44 | * which merely queues the extension for loading by the | |
45 | * kmodload utility. | |
46 | */ | |
47 | extern kern_return_t (*kmod_load_function)(char *extension_name); | |
48 | extern bool (*record_startup_extensions_function)(void); | |
49 | extern bool (*add_from_mkext_function)(OSData * mkext); | |
50 | extern void (*remove_startup_extension_function)(const char * name); | |
51 | ||
52 | /**** | |
53 | * IOCatalogue uses this variable to make a few decisions | |
54 | * about loading and matching drivers. | |
55 | */ | |
56 | extern int kernelLinkerPresent; | |
1c79356b A |
57 | |
58 | ||
59 | class KLDBootstrap { | |
60 | public: | |
61 | KLDBootstrap(); | |
62 | ~KLDBootstrap(); | |
63 | }; | |
64 | ||
65 | ||
66 | static KLDBootstrap bootstrap_obj; | |
67 | ||
68 | ||
69 | /* The constructor creates a lock and puts entries into a dispatch | |
70 | * table for functions used to record and load kmods. | |
71 | */ | |
72 | KLDBootstrap::KLDBootstrap() { | |
73 | ||
55e303ae A |
74 | malloc_init(); |
75 | ||
1c79356b A |
76 | kmod_load_function = &load_kernel_extension; |
77 | ||
78 | record_startup_extensions_function = &recordStartupExtensions; | |
79 | add_from_mkext_function = &addExtensionsFromArchive; | |
80 | remove_startup_extension_function = &removeStartupExtension; | |
81 | ||
2d21ac55 | 82 | #ifndef CONFIG_NOKLD |
1c79356b | 83 | kernelLinkerPresent = 1; |
2d21ac55 | 84 | #endif |
1c79356b A |
85 | } |
86 | ||
87 | /* The destructor frees all wired memory regions held | |
88 | * by libsa's malloc package and disposes of the lock. | |
89 | */ | |
90 | KLDBootstrap::~KLDBootstrap() { | |
91 | ||
0b4e3aa0 | 92 | kld_file_cleanup_all_resources(); |
1c79356b | 93 | |
0b4e3aa0 A |
94 | /* Dump all device-tree entries for boot drivers, and all |
95 | * info on startup extensions. The IOCatalogue will now | |
96 | * get personalities from kextd. | |
97 | */ | |
98 | clearStartupExtensionsAndLoaderInfo(); | |
1c79356b | 99 | |
0b4e3aa0 A |
100 | /* Free all temporary malloc memory. |
101 | */ | |
1c79356b | 102 | malloc_reset(); |
1c79356b | 103 | } |