2 * Copyright (c) 2017 Apple Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
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
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
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
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.
21 * @APPLE_LICENSE_HEADER_END@
25 #ifndef ClosureWriter_h
26 #define ClosureWriter_h
32 #include <uuid/uuid.h>
33 #include <mach/mach.h>
34 #include <mach-o/loader.h>
35 #include <uuid/uuid.h>
46 class VIS_HIDDEN ContainerTypedBytesWriter
52 void setContainerType(TypedBytes::Type containerType
);
53 void* append(TypedBytes::Type t
, const void* payload
, uint32_t payloadSize
);
55 const void* currentTypedBytes();
56 const void* finalizeContainer();
58 void* _vmAllocationStart
= nullptr;
59 size_t _vmAllocationSize
= 0;
60 TypedBytes
* _containerTypedBytes
= nullptr;
65 class VIS_HIDDEN ImageWriter
: public ContainerTypedBytesWriter
69 void setImageNum(ImageNum num
);
70 void addPath(const char* path
); // first is canonical, others are aliases
72 void setInDyldCache(bool);
73 void setHasPrecomputedObjC(bool);
75 void setHasObjC(bool);
76 void setHasPlusLoads(bool);
77 void setIsBundle(bool);
78 void setIsDylib(bool);
79 void setIsExecutable(bool);
80 void setIsRestricted(bool);
81 void setHasWeakDefs(bool);
82 void setUses16KPages(bool);
83 void setOverridableDylib(bool);
84 void setNeverUnload(bool);
85 void setHasTerminators(bool);
86 void setUUID(const uuid_t uuid
);
87 void addCDHash(const uint8_t cdHash
[20]);
88 void setDependents(const Array
<Image::LinkedImage
>& deps
);
89 void setDofOffsets(const Array
<uint32_t>& dofSectionOffsets
);
90 void setInitOffsets(const uint32_t initOffsets
[], uint32_t count
);
91 void setInitSectRange(uint32_t sectionOffset
, uint32_t sectionSize
);
92 void setTermOffsets(const uint32_t termOffsets
[], uint32_t count
);
93 void setDiskSegments(const Image::DiskSegment segs
[], uint32_t count
);
94 void setCachedSegments(const Image::DyldCacheSegment segs
[], uint32_t count
);
95 void setCodeSignatureLocation(uint32_t fileOffset
, uint32_t size
);
96 void setFairPlayEncryptionRange(uint32_t fileOffset
, uint32_t size
);
97 void setMappingInfo(uint64_t sliceOffset
, uint64_t vmSize
);
98 void setFileInfo(uint64_t inode
, uint64_t modTime
);
99 void setRebaseInfo(const Array
<Image::RebasePattern
>&);
100 void setTextRebaseInfo(const Array
<Image::TextFixupPattern
>&);
101 void setBindInfo(const Array
<Image::BindPattern
>&);
102 void setObjCFixupInfo(const Image::ResolvedSymbolTarget
& objcProtocolClassTarget
,
103 uint64_t objcImageInfoVMOffset
,
104 const Array
<Image::ProtocolISAFixup
>& protocolISAFixups
,
105 const Array
<Image::SelectorReferenceFixup
>& selRefFixups
,
106 const Array
<Image::ClassStableSwiftFixup
>& classStableSwiftFixups
,
107 const Array
<Image::MethodListFixup
>& methodListFixups
);
108 void setAsOverrideOf(ImageNum
);
109 void setInitsOrder(const ImageNum images
[], uint32_t count
);
110 void setChainedFixups(uint64_t runtimeStartsStructOffset
, const Array
<Image::ResolvedSymbolTarget
>& targets
);
112 const Image
* currentImage();
114 const Image
* finalize();
117 Image::Flags
& getFlags();
119 int _flagsOffset
= -1;
123 class VIS_HIDDEN ImageArrayWriter
: public ContainerTypedBytesWriter
126 ImageArrayWriter(ImageNum startImageNum
, unsigned count
, bool hasRoots
);
128 void appendImage(const Image
*);
129 const ImageArray
* finalize();
134 class VIS_HIDDEN ClosureWriter
: public ContainerTypedBytesWriter
137 void setTopImageNum(ImageNum imageNum
);
138 void addCachePatches(const Array
<Closure::PatchEntry
>&);
139 void applyInterposing(const LaunchClosure
* launchClosure
);
140 void addWarning(Closure::Warning::Type type
, const char* warning
);
143 class VIS_HIDDEN LaunchClosureWriter
: public ClosureWriter
145 friend class ClosureBuilder
;
147 LaunchClosureWriter(const ImageArray
* images
);
149 const LaunchClosure
* finalize();
150 void setLibSystemImageNum(ImageNum imageNum
);
151 void setInitImageCount(uint32_t count
);
152 void setLibDyldEntry(Image::ResolvedSymbolTarget dyldEntry
);
153 void setMainEntry(Image::ResolvedSymbolTarget main
);
154 void setStartEntry(Image::ResolvedSymbolTarget start
);
155 void setUsedFallbackPaths(bool);
156 void setUsedAtPaths(bool);
157 void setUsedInterposing(bool);
158 void setHasInsertedLibraries(bool);
159 void setMustBeMissingFiles(const Array
<const char*>& paths
);
160 void setMustExistFiles(const Array
<LaunchClosure::SkippedFile
>& files
);
161 void addInterposingTuples(const Array
<InterposingTuple
>& tuples
);
162 void setDyldCacheUUID(const uuid_t
);
163 void setBootUUID(const char* uuid
);
164 void addEnvVar(const char* envVar
);
165 void setObjCSelectorInfo(const Array
<uint8_t>& hashTable
, const Array
<Image::ObjCSelectorImage
>& hashTableImages
);
166 void setObjCClassAndProtocolInfo(const Array
<uint8_t>& classHashTable
, const Array
<uint8_t>& protocolHashTable
,
167 const Array
<Image::ObjCClassImage
>& hashTableImages
);
168 void setObjCDuplicateClassesInfo(const Array
<uint8_t>& hashTable
);
171 LaunchClosure::Flags
& getFlags();
173 int _flagsOffset
= -1;
177 class VIS_HIDDEN DlopenClosureWriter
: public ClosureWriter
180 DlopenClosureWriter(const ImageArray
* images
);
182 const DlopenClosure
* finalize();
187 } // namespace closure
191 #endif // ClosureWriter_h