]> git.saurik.com Git - apple/xnu.git/blob - libsa/bootstrap.cpp
xnu-792.13.8.tar.gz
[apple/xnu.git] / libsa / bootstrap.cpp
1 /*
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_OSREFERENCE_HEADER_START@
5 *
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
10 * License may not be used to create, or enable the creation or
11 * redistribution of, unlawful or unlicensed copies of an Apple operating
12 * system, or to circumvent, violate, or enable the circumvention or
13 * violation of, any terms of an Apple operating system software license
14 * agreement.
15 *
16 * Please obtain a copy of the License at
17 * http://www.opensource.apple.com/apsl/ and read it before using this
18 * file.
19 *
20 * The Original Code and all software distributed under the License are
21 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
22 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
23 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
24 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
25 * Please see the License for the specific language governing rights and
26 * limitations under the License.
27 *
28 * @APPLE_LICENSE_OSREFERENCE_HEADER_END@
29 */
30 #include <IOKit/IOLib.h>
31 #include <mach/kmod.h>
32 #include <libkern/c++/OSDictionary.h>
33
34 #include <libsa/kext.h>
35 #include <libsa/catalogue.h>
36 #include <libsa/malloc.h>
37
38 #include "kld_patch.h"
39
40 /*****
41 * This function is used by IOCatalogue to load a kernel
42 * extension. libsa initially sets it to be a function
43 * that uses libkld to load and link the extension from
44 * within the kernel. Once the root filesystem is up,
45 * this gets switch to the kmod_load_extension() function,
46 * which merely queues the extension for loading by the
47 * kmodload utility.
48 */
49 extern kern_return_t (*kmod_load_function)(char *extension_name);
50 extern bool (*record_startup_extensions_function)(void);
51 extern bool (*add_from_mkext_function)(OSData * mkext);
52 extern void (*remove_startup_extension_function)(const char * name);
53
54 /****
55 * IOCatalogue uses this variable to make a few decisions
56 * about loading and matching drivers.
57 */
58 extern int kernelLinkerPresent;
59
60
61 class KLDBootstrap {
62 public:
63 KLDBootstrap();
64 ~KLDBootstrap();
65 };
66
67
68 static KLDBootstrap bootstrap_obj;
69
70
71 /* The constructor creates a lock and puts entries into a dispatch
72 * table for functions used to record and load kmods.
73 */
74 KLDBootstrap::KLDBootstrap() {
75
76 malloc_init();
77
78 kmod_load_function = &load_kernel_extension;
79
80 record_startup_extensions_function = &recordStartupExtensions;
81 add_from_mkext_function = &addExtensionsFromArchive;
82 remove_startup_extension_function = &removeStartupExtension;
83
84 kernelLinkerPresent = 1;
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
92 kld_file_cleanup_all_resources();
93
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();
99
100 /* Free all temporary malloc memory.
101 */
102 malloc_reset();
103 }