2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
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.
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
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
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
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.
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
28 #include <IOKit/IOLib.h>
29 #include <mach/kmod.h>
30 #include <libkern/c++/OSDictionary.h>
32 #include <libsa/kext.h>
33 #include <libsa/catalogue.h>
34 #include <libsa/malloc.h>
36 #include "kld_patch.h"
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
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
);
53 * IOCatalogue uses this variable to make a few decisions
54 * about loading and matching drivers.
56 extern int kernelLinkerPresent
;
66 static KLDBootstrap bootstrap_obj
;
69 /* The constructor creates a lock and puts entries into a dispatch
70 * table for functions used to record and load kmods.
72 KLDBootstrap::KLDBootstrap() {
76 kmod_load_function
= &load_kernel_extension
;
78 record_startup_extensions_function
= &recordStartupExtensions
;
79 add_from_mkext_function
= &addExtensionsFromArchive
;
80 remove_startup_extension_function
= &removeStartupExtension
;
82 kernelLinkerPresent
= 1;
85 /* The destructor frees all wired memory regions held
86 * by libsa's malloc package and disposes of the lock.
88 KLDBootstrap::~KLDBootstrap() {
90 kld_file_cleanup_all_resources();
92 /* Dump all device-tree entries for boot drivers, and all
93 * info on startup extensions. The IOCatalogue will now
94 * get personalities from kextd.
96 clearStartupExtensionsAndLoaderInfo();
98 /* Free all temporary malloc memory.