]> git.saurik.com Git - apple/dyld.git/blob - dyld3/shared-cache/mrm_shared_cache_builder.h
33c4a69cbd80999db54819441f6b0eb1efe17c64
[apple/dyld.git] / dyld3 / shared-cache / mrm_shared_cache_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 mrm_shared_cache_builder_hpp
26 #define mrm_shared_cache_builder_hpp
27
28 #include <Availability.h>
29
30 #include <stdint.h>
31 #include <sys/types.h>
32
33 #ifdef __cplusplus
34 extern "C" {
35 #endif
36
37 // Note, this should match PLATFORM_* values in <mach-o/loader.h>
38 enum Platform {
39 unknown = 0,
40 macOS = 1, // PLATFORM_MACOS
41 iOS = 2, // PLATFORM_IOS
42 tvOS = 3, // PLATFORM_TVOS
43 watchOS = 4, // PLATFORM_WATCHOS
44 bridgeOS = 5, // PLATFORM_BRIDGEOS
45 iOSMac = 6, // PLATFORM_IOSMAC
46 iOS_simulator = 7, // PLATFORM_IOSIMULATOR
47 tvOS_simulator = 8, // PLATFORM_TVOSSIMULATOR
48 watchOS_simulator = 9 // PLATFORM_WATCHOSSIMULATOR
49 };
50
51 enum Disposition
52 {
53 Unknown = 0,
54 InternalDevelopment = 1,
55 Customer = 2,
56 InternalMinDevelopment = 3
57 };
58
59 enum FileFlags
60 {
61 // Note these are for macho inputs
62 NoFlags = 0,
63 MustBeInCache = 1,
64 ShouldBeExcludedFromCacheIfUnusedLeaf = 2,
65 RequiredClosure = 3,
66
67 // These are for the order files
68 DylibOrderFile = 100,
69 DirtyDataOrderFile = 101
70 };
71
72 struct BuildOptions_v1
73 {
74 uint64_t version; // Future proofing, set to 1
75 const char * updateName; // BuildTrain+UpdateNumber
76 const char * deviceName;
77 enum Disposition disposition; // Internal, Customer, etc.
78 enum Platform platform; // Enum: unknown, macOS, iOS, ...
79 const char ** archs;
80 uint64_t numArchs;
81 bool verboseDiagnostics;
82 bool isLocallyBuiltCache;
83 };
84
85 enum FileBehavior
86 {
87 AddFile = 0, // New file: uid, gid, mode, data, cdhash fields must be set
88 ChangeFile = 1, // Change the data of file: data, size, and cdhash fields must be set
89 };
90
91 struct FileResult
92 {
93 uint64_t version; // Future proofing, set to 1
94 const char* path;
95 enum FileBehavior behavior;
96 const uint8_t* data; // Owned by the cache builder. Destroyed by destroySharedCacheBuilder
97 uint64_t size;
98 // CDHash, must be set for new or modified files
99 const char* hashArch;
100 const char* hashType;
101 const char* hash;
102 };
103
104
105 struct CacheResult
106 {
107 uint64_t version; // Future proofing, set to 1
108 const char* loggingPrefix; // needed?
109 const char* deviceConfiguration;
110 const char ** warnings; // should this be per-result?
111 uint64_t numWarnings;
112 const char ** errors; // should this be per-result?
113 uint64_t numErrors;
114 const char* uuidString;
115 const char* mapJSON;
116 };
117
118 struct SharedCacheBuilder;
119
120 __API_AVAILABLE(macos(10.12))
121 void getVersion(uint32_t *major, uint32_t *minor);
122
123 __API_AVAILABLE(macos(10.12))
124 struct SharedCacheBuilder* createSharedCacheBuilder(const struct BuildOptions_v1* options);
125
126 // Add a file. Returns true on success.
127 __API_AVAILABLE(macos(10.12))
128 bool addFile(struct SharedCacheBuilder* builder, const char* path, uint8_t* data, uint64_t size, enum FileFlags fileFlags);
129
130 __API_AVAILABLE(macos(10.12))
131 bool addSymlink(struct SharedCacheBuilder* builder, const char* fromPath, const char* toPath);
132
133 __API_AVAILABLE(macos(10.12))
134 bool runSharedCacheBuilder(struct SharedCacheBuilder* builder);
135
136 __API_AVAILABLE(macos(10.12))
137 const char* const* getErrors(const struct SharedCacheBuilder* builder, uint64_t* errorCount);
138
139 __API_AVAILABLE(macos(10.12))
140 const struct FileResult* const* getFileResults(struct SharedCacheBuilder* builder, uint64_t* resultCount);
141
142 __API_AVAILABLE(macos(10.12))
143 const struct CacheResult* const* getCacheResults(struct SharedCacheBuilder* builder, uint64_t* resultCount);
144
145 __API_AVAILABLE(macos(10.12))
146 const char* const* getFilesToRemove(const struct SharedCacheBuilder* builder, uint64_t* fileCount);
147
148 __API_AVAILABLE(macos(10.12))
149 void destroySharedCacheBuilder(struct SharedCacheBuilder* builder);
150
151 #ifdef __cplusplus
152 }
153 #endif
154
155 #endif /* mrm_shared_cache_builder_hpp */