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