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@
26 #ifndef __DYLD_CLOSURE_BUFFER_H__
27 #define __DYLD_CLOSURE_BUFFER_H__
30 #include "LaunchCache.h"
31 #include "PathOverrides.h"
36 // simple class for packing typed content into a vm_allocated buffer
37 class VIS_HIDDEN TypedContentBuffer
41 TypedContentBuffer(size_t elementsCount
, size_t elementsTotalSize
);
42 void addItem(uint32_t k
, const void* content
, size_t len
);
44 vm_address_t
vmBuffer() const;
45 uint32_t vmBufferSize() const;
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;
58 uint32_t contentLength
;
61 const Element
* next() const;
71 class VIS_HIDDEN ClosureBuffer
: public TypedContentBuffer
77 uint8_t cacheUUID
[16];
78 uint64_t cacheAddress
;
79 uint64_t cacheMappedSize
;
83 ClosureBuffer(const CacheIdent
&, const char* path
, const launch_cache::ImageGroupList
& groups
, const PathOverrides
& envVars
);
86 ClosureBuffer(const char* errorMessage
);
87 ClosureBuffer(const launch_cache::BinaryImageGroupData
* imageGroupResult
);
88 ClosureBuffer(const launch_cache::BinaryClosureData
* closureResult
);
92 const char* errorMessage() const;
93 const launch_cache::BinaryClosureData
* closure() const;
94 const launch_cache::BinaryImageGroupData
* imageGroup() const;
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;
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
);
116 #endif // __DYLD_CLOSURE_BUFFER_H__