1 /* -*- mode: C++; c-basic-offset: 4; indent-tabs-mode: nil -*-
3 * Copyright (c) 2017 Apple Inc. All rights reserved.
5 * @APPLE_LICENSE_HEADER_START@
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
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.
22 * @APPLE_LICENSE_HEADER_END@
25 #ifndef kernel_collection_builder_h
26 #define kernel_collection_builder_h
28 #include <Availability.h>
30 #include <CoreFoundation/CFArray.h>
31 #include <CoreFoundation/CFData.h>
32 #include <CoreFoundation/CFDictionary.h>
33 #include <CoreFoundation/CFString.h>
36 #include <sys/types.h>
42 typedef CF_ENUM(uint32_t, CollectionKind
) {
49 typedef CF_ENUM(uint32_t, FileResultKind
) {
50 unknownFileResult
= 0,
54 typedef CF_ENUM(uint32_t, StripMode
) {
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
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
69 typedef CF_ENUM(uint32_t, ProgressKind
) {
75 generatePrelinkInfo
= 5,
83 struct BuildOptions_v1
85 uint64_t version
; // Future proofing, set to 1
86 CollectionKind collectionKind
;
88 // Valid archs are one of: "arm64", "arm64e", "x86_64", "x86_64h"
89 const CFStringRef arch
;
90 bool verboseDiagnostics
;
94 struct CollectionFileResult_v1
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?
102 struct KextFileData_v1
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
;
114 typedef void (*ProgressCallback
)(const char* message
, ProgressKind kind
);
116 struct KernelCollectionBuilder
;
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
);
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
);
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
);
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
);
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
);
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
);
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
);
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
);
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
);
154 // Returns true on success.
155 __API_AVAILABLE(macos(10.14))
156 bool runKernelCollectionBuilder(struct KernelCollectionBuilder
* builder
);
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
);
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
);
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
);
172 __API_AVAILABLE(macos(10.14))
173 void destroyKernelCollectionBuilder(struct KernelCollectionBuilder
* builder
);
179 #endif /* kernel_collection_builder_h */