]> git.saurik.com Git - apple/dyld.git/blob - dyld3/shared-cache/kernel_collection_builder.h
dyld-851.27.tar.gz
[apple/dyld.git] / dyld3 / shared-cache / kernel_collection_builder.h
1 /* -*- mode: C++; c-basic-offset: 4; indent-tabs-mode: nil -*-
2 *
3 * Copyright (c) 2017 Apple Inc. All rights reserved.
4 *
5 * @APPLE_LICENSE_HEADER_START@
6 *
7 * This file contains Original Code and/or Modifications of Original Code
8 * as defined in and that are subject to the Apple Public Source License
9 * Version 2.0 (the 'License'). You may not use this file except in
10 * compliance with the License. Please obtain a copy of the License at
11 * http://www.opensource.apple.com/apsl/ and read it before using this
12 * file.
13 *
14 * The Original Code and all software distributed under the License are
15 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
16 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
17 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
19 * Please see the License for the specific language governing rights and
20 * limitations under the License.
21 *
22 * @APPLE_LICENSE_HEADER_END@
23 */
24
25 #ifndef kernel_collection_builder_h
26 #define kernel_collection_builder_h
27
28 #include <Availability.h>
29
30 #include <CoreFoundation/CFArray.h>
31 #include <CoreFoundation/CFData.h>
32 #include <CoreFoundation/CFDictionary.h>
33 #include <CoreFoundation/CFString.h>
34
35 #include <stdint.h>
36 #include <sys/types.h>
37
38 #ifdef __cplusplus
39 extern "C" {
40 #endif
41
42 typedef CF_ENUM(uint32_t, CollectionKind) {
43 unknownKC = 0,
44 baseKC = 1,
45 auxKC = 2,
46 pageableKC = 3,
47 };
48
49 typedef CF_ENUM(uint32_t, FileResultKind) {
50 unknownFileResult = 0,
51 kernelCollection = 1,
52 };
53
54 typedef CF_ENUM(uint32_t, StripMode) {
55 unknownStripMode = 0,
56 stripNone = 1, // Don't strip any symbols
57 stripAll = 2, // Strip all symbols from all binaries
58 stripAllKexts = 3, // Don't strip xnu, but strip everything else
59 };
60
61 typedef CF_ENUM(uint32_t, BinaryStripMode) {
62 binaryUnknownStripMode = 0,
63 binaryStripNone = 1, // Don't strip any symbols
64 binaryStripExports = 2, // Strip all the exports, but leave the local symbols
65 binaryStripLocals = 3, // Strip all the locals, but leave the exported symbols
66 binaryStripAll = 4, // Strip all symbols
67 };
68
69 typedef CF_ENUM(uint32_t, ProgressKind) {
70 unknownProgress = 0,
71 layout = 1,
72 generateHeader = 2,
73 copyInputs = 3,
74 applySplitSeg = 4,
75 generatePrelinkInfo = 5,
76 processFixups = 6,
77 optimizeStubs = 7,
78 optimizeLinkedit = 8,
79 writeFixups = 9,
80 emitFile = 10
81 };
82
83 struct BuildOptions_v1
84 {
85 uint64_t version; // Future proofing, set to 1
86 CollectionKind collectionKind;
87 StripMode stripMode;
88 // Valid archs are one of: "arm64", "arm64e", "x86_64", "x86_64h"
89 const CFStringRef arch;
90 bool verboseDiagnostics;
91 };
92
93
94 struct CollectionFileResult_v1
95 {
96 uint64_t version; // Future proofing, set to 1
97 FileResultKind fileKind;
98 const CFDataRef data; // Owned by the cache builder. Destroyed by destroyKernelCollectionBuilder
99 const CFArrayRef warnings; // should this be per-result?
100 };
101
102 struct KextFileData_v1
103 {
104 uint64_t version; // Future proofing, set to 1
105 const CFStringRef kextpath;
106 const CFDataRef kextdata;
107 const CFArrayRef dependencies;
108 const CFStringRef bundleID;
109 const CFStringRef bundlePath;
110 CFDictionaryRef plist;
111 BinaryStripMode stripMode;
112 };
113
114 typedef void (*ProgressCallback)(const char* message, ProgressKind kind);
115
116 struct KernelCollectionBuilder;
117
118 // What is the version of this builder dylib. Can be used to determine what API is available.
119 __API_AVAILABLE(macos(10.14))
120 void getVersion(uint32_t *major, uint32_t *minor);
121
122 // Returns a valid object on success, or NULL on failure.
123 __API_AVAILABLE(macos(10.14))
124 struct KernelCollectionBuilder* createKernelCollectionBuilder(const struct BuildOptions_v1* options);
125
126 // Add a kernel static executable file. Returns true on success.
127 __API_AVAILABLE(macos(10.14))
128 bool addKernelFile(struct KernelCollectionBuilder* builder, const CFStringRef path, const CFDataRef data);
129
130 // Add kext mach-o and plist files. Returns true on success.
131 __API_AVAILABLE(macos(10.14))
132 bool addKextDataFile(struct KernelCollectionBuilder* builder, const struct KextFileData_v1* fileData);
133
134 // Add interface plist file. Returns true on success.
135 __API_AVAILABLE(macos(10.14))
136 bool addInterfaceFile(struct KernelCollectionBuilder* builder, const CFStringRef path, const CFDataRef data);
137
138 // Add collection file. Returns true on success.
139 __API_AVAILABLE(macos(10.14))
140 bool addCollectionFile(struct KernelCollectionBuilder* builder, const CFStringRef path, const CFDataRef data, CollectionKind kind);
141
142 // Add data to the given segment of the final file. Note the section can be null (or "") if desired
143 __API_AVAILABLE(macos(10.14))
144 bool addSegmentData(struct KernelCollectionBuilder* builder, const CFStringRef segmentName, const CFStringRef sectionName, const CFDataRef data);
145
146 // Add entries to the prelink info dictionary. Note this can only be used once at this time.
147 __API_AVAILABLE(macos(10.14))
148 bool addPrelinkInfo(struct KernelCollectionBuilder* builder, const CFDictionaryRef extraData);
149
150 // Set a handler to be called at various points during the build to notify the user of progress.
151 __API_AVAILABLE(macos(10.14))
152 void setProgressCallback(const ProgressCallback callback);
153
154 // Returns true on success.
155 __API_AVAILABLE(macos(10.14))
156 bool runKernelCollectionBuilder(struct KernelCollectionBuilder* builder);
157
158 // Gets the list of errors we have produced. These may be from incorrect input values, or failures in the build itself
159 __API_AVAILABLE(macos(10.14))
160 const char* const* getErrors(const struct KernelCollectionBuilder* builder, uint64_t* errorCount);
161
162 // Gets the errors on each kext. This returns null if there are no such errors.
163 // A non-null result is a dictionary where the keys are bundle-ids and the values are
164 // arrays of strings represeting error messages.
165 __API_AVAILABLE(macos(10.14))
166 CFDictionaryRef getKextErrors(const struct KernelCollectionBuilder* builder);
167
168 // Returns an array of the resulting files. These may be new collections, or other files required later
169 __API_AVAILABLE(macos(10.14))
170 const struct CollectionFileResult_v1* const* getCollectionFileResults(struct KernelCollectionBuilder* builder, uint64_t* resultCount);
171
172 __API_AVAILABLE(macos(10.14))
173 void destroyKernelCollectionBuilder(struct KernelCollectionBuilder* builder);
174
175 #ifdef __cplusplus
176 }
177 #endif
178
179 #endif /* kernel_collection_builder_h */