]> git.saurik.com Git - apple/dyld.git/blob - dyld3/ClosureBuffer.h
dyld-551.4.tar.gz
[apple/dyld.git] / dyld3 / ClosureBuffer.h
1 /*
2 * Copyright (c) 2017 Apple Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
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
11 * file.
12 *
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.
20 *
21 * @APPLE_LICENSE_HEADER_END@
22 */
23
24
25
26 #ifndef __DYLD_CLOSURE_BUFFER_H__
27 #define __DYLD_CLOSURE_BUFFER_H__
28
29 #include "Logging.h"
30 #include "LaunchCache.h"
31 #include "PathOverrides.h"
32
33 namespace dyld3 {
34
35
36 // simple class for packing typed content into a vm_allocated buffer
37 class VIS_HIDDEN TypedContentBuffer
38 {
39 public:
40 // buffer creation
41 TypedContentBuffer(size_t elementsCount, size_t elementsTotalSize);
42 void addItem(uint32_t k, const void* content, size_t len);
43 void doneBuilding();
44 vm_address_t vmBuffer() const;
45 uint32_t vmBufferSize() const;
46
47 // buffer parsing
48 TypedContentBuffer(const void* buff, size_t buffSize);
49 unsigned count(uint32_t) const;
50 void forEach(uint32_t, void (^callback)(const void* content, size_t length)) const;
51
52 void free();
53
54 private:
55 struct Element
56 {
57 uint32_t kind;
58 uint32_t contentLength;
59 uint8_t content[];
60
61 const Element* next() const;
62 };
63
64 size_t _size;
65 Element* _buffer;
66 Element* _currentEnd;
67 bool _readOnly;
68 };
69
70
71 class VIS_HIDDEN ClosureBuffer : public TypedContentBuffer
72 {
73 public:
74
75 struct CacheIdent
76 {
77 uint8_t cacheUUID[16];
78 uint64_t cacheAddress;
79 uint64_t cacheMappedSize;
80 };
81
82 // client creation
83 ClosureBuffer(const CacheIdent&, const char* path, const launch_cache::ImageGroupList& groups, const PathOverrides& envVars);
84
85 // closured creation
86 ClosureBuffer(const char* errorMessage);
87 ClosureBuffer(const launch_cache::BinaryImageGroupData* imageGroupResult);
88 ClosureBuffer(const launch_cache::BinaryClosureData* closureResult);
89
90 // client extraction
91 bool isError() const;
92 const char* errorMessage() const;
93 const launch_cache::BinaryClosureData* closure() const;
94 const launch_cache::BinaryImageGroupData* imageGroup() const;
95
96 // closure builder usage
97 ClosureBuffer(const void* buff, size_t buffSize);
98 const CacheIdent& cacheIndent() const;
99 const char* targetPath() const;
100 uint32_t envVarCount() const;
101 void copyImageGroups(const char* envVars[]) const;
102 uint32_t imageGroupCount() const;
103 void copyImageGroups(const launch_cache::BinaryImageGroupData* imageGroups[]) const;
104
105 private:
106 enum { kindEnd=0, kindCacheIdent, kindTargetPath, kindEnvVar, kindImageGroup, kindClosure, kindErrorMessage };
107 static size_t computeSize(const char* path, const launch_cache::ImageGroupList& groups, const PathOverrides& envVars);
108
109 };
110
111
112
113
114 } // namespace dyld3
115
116 #endif // __DYLD_CLOSURE_BUFFER_H__