2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_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. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
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.
21 * @APPLE_LICENSE_HEADER_END@
23 #include <IOKit/IOLib.h>
24 #include <mach/kmod.h>
25 #include <libkern/c++/OSDictionary.h>
27 #include <libsa/kext.h>
28 #include <libsa/catalogue.h>
29 #include <libsa/malloc.h>
31 #include "kld_patch.h"
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
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
);
48 * IOCatalogue uses this variable to make a few decisions
49 * about loading and matching drivers.
51 extern int kernelLinkerPresent
;
61 static KLDBootstrap bootstrap_obj
;
64 /* The constructor creates a lock and puts entries into a dispatch
65 * table for functions used to record and load kmods.
67 KLDBootstrap::KLDBootstrap() {
71 kmod_load_function
= &load_kernel_extension
;
73 record_startup_extensions_function
= &recordStartupExtensions
;
74 add_from_mkext_function
= &addExtensionsFromArchive
;
75 remove_startup_extension_function
= &removeStartupExtension
;
77 kernelLinkerPresent
= 1;
80 /* The destructor frees all wired memory regions held
81 * by libsa's malloc package and disposes of the lock.
83 KLDBootstrap::~KLDBootstrap() {
85 kld_file_cleanup_all_resources();
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.
91 clearStartupExtensionsAndLoaderInfo();
93 /* Free all temporary malloc memory.