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