2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.1 (the
8 * "License"). You may not use this file except in compliance with the
9 * License. Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
20 * @APPLE_LICENSE_HEADER_END@
22 #include <IOKit/IOLib.h>
23 #include <mach/kmod.h>
24 #include <libkern/c++/OSDictionary.h>
26 #include <libsa/kmod.h>
27 #include <libsa/catalogue.h>
29 #include <libsa/malloc.h>
32 #include "kld_patch.h"
36 * This function is used by IOCatalogue to load a kernel
37 * extension. libsa initially sets it to be a function
38 * that uses libkld to load and link the extension from
39 * within the kernel. Once the root filesystem is up,
40 * this gets switch to the kmod_load_extension() function,
41 * which merely queues the extension for loading by the
44 extern kern_return_t (*kmod_load_function
)(char *extension_name
);
45 extern bool (*record_startup_extensions_function
)(void);
46 extern bool (*add_from_mkext_function
)(OSData
* mkext
);
47 extern void (*remove_startup_extension_function
)(const char * name
);
50 * IOCatalogue uses this variable to make a few decisions
51 * about loading and matching drivers.
53 extern int kernelLinkerPresent
;
64 static KLDBootstrap bootstrap_obj
;
67 /* The constructor creates a lock and puts entries into a dispatch
68 * table for functions used to record and load kmods.
70 KLDBootstrap::KLDBootstrap() {
72 kmod_load_function
= &load_kernel_extension
;
74 record_startup_extensions_function
= &recordStartupExtensions
;
75 add_from_mkext_function
= &addExtensionsFromArchive
;
76 remove_startup_extension_function
= &removeStartupExtension
;
78 kernelLinkerPresent
= 1;
81 /* The destructor frees all wired memory regions held
82 * by libsa's malloc package and disposes of the lock.
84 KLDBootstrap::~KLDBootstrap() {
86 kld_file_cleanup_all_resources();
88 /* Dump all device-tree entries for boot drivers, and all
89 * info on startup extensions. The IOCatalogue will now
90 * get personalities from kextd.
92 clearStartupExtensionsAndLoaderInfo();
94 /* Free all temporary malloc memory.