]> git.saurik.com Git - apple/xnu.git/blame - libsa/bootstrap.cpp
xnu-792.6.56.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 *
ff6e181a
A
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.
1c79356b 12 *
ff6e181a
A
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
1c79356b
A
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
ff6e181a
A
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.
1c79356b
A
20 *
21 * @APPLE_LICENSE_HEADER_END@
22 */
23#include <IOKit/IOLib.h>
24#include <mach/kmod.h>
25#include <libkern/c++/OSDictionary.h>
26
55e303ae 27#include <libsa/kext.h>
1c79356b 28#include <libsa/catalogue.h>
1c79356b 29#include <libsa/malloc.h>
1c79356b 30
0b4e3aa0
A
31#include "kld_patch.h"
32
1c79356b
A
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 */
42extern kern_return_t (*kmod_load_function)(char *extension_name);
43extern bool (*record_startup_extensions_function)(void);
44extern bool (*add_from_mkext_function)(OSData * mkext);
45extern 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 */
51extern int kernelLinkerPresent;
1c79356b
A
52
53
54class KLDBootstrap {
55public:
56 KLDBootstrap();
57 ~KLDBootstrap();
58};
59
60
61static 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 */
67KLDBootstrap::KLDBootstrap() {
68
55e303ae
A
69 malloc_init();
70
1c79356b
A
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;
1c79356b
A
78}
79
80/* The destructor frees all wired memory regions held
81 * by libsa's malloc package and disposes of the lock.
82 */
83KLDBootstrap::~KLDBootstrap() {
84
0b4e3aa0 85 kld_file_cleanup_all_resources();
1c79356b 86
0b4e3aa0
A
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();
1c79356b 92
0b4e3aa0
A
93 /* Free all temporary malloc memory.
94 */
1c79356b 95 malloc_reset();
1c79356b 96}