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);
74 void setHasObjC(bool);
75 void setHasPlusLoads(bool);
76 void setIsBundle(bool);
77 void setIsDylib(bool);
78 void setIsExecutable(bool);
79 void setIsRestricted(bool);
80 void setHasWeakDefs(bool);
81 void setUses16KPages(bool);
82 void setOverridableDylib(bool);
83 void setNeverUnload(bool);
84 void setUUID(const uuid_t uuid
);
85 void setCDHash(const uint8_t cdHash
[20]);
86 void setDependents(const Array
<Image::LinkedImage
>& deps
);
87 void setDofOffsets(const Array
<uint32_t>& dofSectionOffsets
);
88 void setInitOffsets(const uint32_t initOffsets
[], uint32_t count
);
89 void setDiskSegments(const Image::DiskSegment segs
[], uint32_t count
);
90 void setCachedSegments(const Image::DyldCacheSegment segs
[], uint32_t count
);
91 void setCodeSignatureLocation(uint32_t fileOffset
, uint32_t size
);
92 void setFairPlayEncryptionRange(uint32_t fileOffset
, uint32_t size
);
93 void setMappingInfo(uint64_t sliceOffset
, uint64_t vmSize
);
94 void setFileInfo(uint64_t inode
, uint64_t modTime
);
95 void setRebaseInfo(const Array
<Image::RebasePattern
>&);
96 void setTextRebaseInfo(const Array
<Image::TextFixupPattern
>&);
97 void setBindInfo(const Array
<Image::BindPattern
>&);
98 void setAsOverrideOf(ImageNum
);
99 void addExportPatchInfo(uint32_t implOff
, const char* name
, uint32_t locCount
, const Image::PatchableExport::PatchLocation
* locs
);
100 void setInitsOrder(const ImageNum images
[], uint32_t count
);
101 void setChainedFixups(const Array
<uint64_t>& starts
, const Array
<Image::ResolvedSymbolTarget
>& targets
);
103 const Image
* currentImage();
105 const Image
* finalize();
108 Image::Flags
& getFlags();
110 int _flagsOffset
= -1;
114 class VIS_HIDDEN ImageArrayWriter
: public ContainerTypedBytesWriter
117 ImageArrayWriter(ImageNum startImageNum
, unsigned count
);
119 void appendImage(const Image
*);
120 const ImageArray
* finalize();
125 class VIS_HIDDEN ClosureWriter
: public ContainerTypedBytesWriter
128 void setTopImageNum(ImageNum imageNum
);
129 void addCachePatches(const Array
<Closure::PatchEntry
>&);
132 class VIS_HIDDEN LaunchClosureWriter
: public ClosureWriter
135 LaunchClosureWriter(const ImageArray
* images
);
137 const LaunchClosure
* finalize();
138 void setLibSystemImageNum(ImageNum imageNum
);
139 void setInitImageCount(uint32_t count
);
140 void setLibDyldEntry(Image::ResolvedSymbolTarget dyldEntry
);
141 void setMainEntry(Image::ResolvedSymbolTarget main
);
142 void setStartEntry(Image::ResolvedSymbolTarget start
);
143 void setUsedFallbackPaths(bool);
144 void setUsedAtPaths(bool);
145 void setMustBeMissingFiles(const Array
<const char*>& paths
);
146 void addInterposingTuples(const Array
<InterposingTuple
>& tuples
);
147 void setDyldCacheUUID(const uuid_t
);
148 void setBootUUID(const char* uuid
);
149 void applyInterposing();
150 void addEnvVar(const char* envVar
);
153 LaunchClosure::Flags
& getFlags();
155 int _flagsOffset
= -1;
159 class VIS_HIDDEN DlopenClosureWriter
: public ClosureWriter
162 DlopenClosureWriter(const ImageArray
* images
);
164 const DlopenClosure
* finalize();
169 } // namespace closure
173 #endif // ClosureWriter_h