]> git.saurik.com Git - apple/xnu.git/blame - libsa/bootstrap.cpp
xnu-344.49.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 *
43866e37 6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
1c79356b 7 *
43866e37
A
8 * This file contains Original Code and/or Modifications of Original Code
9 * as defined in and that are subject to the Apple Public Source License
10 * Version 2.0 (the 'License'). You may not use this file except in
11 * compliance with the License. Please obtain a copy of the License at
12 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * file.
14 *
15 * The Original Code and all software distributed under the License are
16 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
1c79356b
A
17 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
18 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
43866e37
A
19 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
20 * Please see the License for the specific language governing rights and
21 * limitations under the License.
1c79356b
A
22 *
23 * @APPLE_LICENSE_HEADER_END@
24 */
25#include <IOKit/IOLib.h>
26#include <mach/kmod.h>
27#include <libkern/c++/OSDictionary.h>
28
29#include <libsa/kmod.h>
30#include <libsa/catalogue.h>
de355530 31extern "C" {
1c79356b 32#include <libsa/malloc.h>
de355530 33};
1c79356b 34
0b4e3aa0
A
35#include "kld_patch.h"
36
de355530 37extern "C" {
1c79356b
A
38/*****
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
45 * kmodload utility.
46 */
47extern kern_return_t (*kmod_load_function)(char *extension_name);
48extern bool (*record_startup_extensions_function)(void);
49extern bool (*add_from_mkext_function)(OSData * mkext);
50extern void (*remove_startup_extension_function)(const char * name);
51
52/****
53 * IOCatalogue uses this variable to make a few decisions
54 * about loading and matching drivers.
55 */
56extern int kernelLinkerPresent;
de355530 57};
1c79356b
A
58
59
60class KLDBootstrap {
61public:
62 KLDBootstrap();
63 ~KLDBootstrap();
64};
65
66
67static KLDBootstrap bootstrap_obj;
68
69
70/* The constructor creates a lock and puts entries into a dispatch
71 * table for functions used to record and load kmods.
72 */
73KLDBootstrap::KLDBootstrap() {
74
1c79356b
A
75 kmod_load_function = &load_kernel_extension;
76
77 record_startup_extensions_function = &recordStartupExtensions;
78 add_from_mkext_function = &addExtensionsFromArchive;
79 remove_startup_extension_function = &removeStartupExtension;
80
81 kernelLinkerPresent = 1;
1c79356b
A
82}
83
84/* The destructor frees all wired memory regions held
85 * by libsa's malloc package and disposes of the lock.
86 */
87KLDBootstrap::~KLDBootstrap() {
88
0b4e3aa0 89 kld_file_cleanup_all_resources();
1c79356b 90
0b4e3aa0
A
91 /* Dump all device-tree entries for boot drivers, and all
92 * info on startup extensions. The IOCatalogue will now
93 * get personalities from kextd.
94 */
95 clearStartupExtensionsAndLoaderInfo();
1c79356b 96
0b4e3aa0
A
97 /* Free all temporary malloc memory.
98 */
1c79356b 99 malloc_reset();
1c79356b 100}