1 /* -*- mode: C++; c-basic-offset: 4; tab-width: 4 -*-
3 * Copyright (c) 2006 Apple Computer, Inc. All rights reserved.
5 * @APPLE_LICENSE_HEADER_START@
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
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.
22 * @APPLE_LICENSE_HEADER_END@
24 #ifndef __DYLD_CACHE_ABSTRACTION__
25 #define __DYLD_CACHE_ABSTRACTION__
27 #include "dyld_cache_format.h"
29 #include "FileAbstraction.hpp"
30 #include "Architectures.hpp"
33 class dyldCacheHeader {
35 const char* magic() const INLINE { return fields.magic; }
36 void set_magic(const char* value) INLINE { memcpy(fields.magic, value, 16); }
38 uint32_t mappingOffset() const INLINE { return E::get32(fields.mappingOffset); }
39 void set_mappingOffset(uint32_t value) INLINE { E::set32(fields.mappingOffset, value); }
41 uint32_t mappingCount() const INLINE { return E::get32(fields.mappingCount); }
42 void set_mappingCount(uint32_t value) INLINE { E::set32(fields.mappingCount, value); }
44 uint32_t imagesOffset() const INLINE { return E::get32(fields.imagesOffset); }
45 void set_imagesOffset(uint32_t value) INLINE { E::set32(fields.imagesOffset, value); }
47 uint32_t imagesCount() const INLINE { return E::get32(fields.imagesCount); }
48 void set_imagesCount(uint32_t value) INLINE { E::set32(fields.imagesCount, value); }
50 uint64_t dyldBaseAddress() const INLINE { return E::get64(fields.dyldBaseAddress); }
51 void set_dyldBaseAddress(uint64_t value) INLINE { E::set64(fields.dyldBaseAddress, value); }
53 uint64_t codeSignatureOffset() const INLINE { return E::get64(fields.codeSignatureOffset); }
54 void set_codeSignatureOffset(uint64_t value) INLINE { E::set64(fields.codeSignatureOffset, value); }
56 uint64_t codeSignatureSize() const INLINE { return E::get64(fields.codeSignatureSize); }
57 void set_codeSignatureSize(uint64_t value) INLINE { E::set64(fields.codeSignatureSize, value); }
59 uint64_t slideInfoOffset() const INLINE { return E::get64(fields.slideInfoOffset); }
60 void set_slideInfoOffset(uint64_t value) INLINE { E::set64(fields.slideInfoOffset, value); }
62 uint64_t slideInfoSize() const INLINE { return E::get64(fields.slideInfoSize); }
63 void set_slideInfoSize(uint64_t value) INLINE { E::set64(fields.slideInfoSize, value); }
65 uint64_t localSymbolsOffset() const INLINE { return E::get64(fields.localSymbolsOffset); }
66 void set_localSymbolsOffset(uint64_t value) INLINE { E::set64(fields.localSymbolsOffset, value); }
68 uint64_t localSymbolsSize() const INLINE { return E::get64(fields.localSymbolsSize); }
69 void set_localSymbolsSize(uint64_t value) INLINE { E::set64(fields.localSymbolsSize, value); }
71 const uint8_t* uuid() const INLINE { return fields.uuid; }
72 void set_uuid(const uint8_t value[16]) INLINE { memcpy(fields.uuid, value, 16); }
74 uint64_t cacheType() const INLINE { return E::get64(fields.cacheType); }
75 void set_cacheType(uint64_t value) INLINE { E::set64(fields.cacheType, value); }
77 uint32_t branchPoolsOffset() const INLINE { return E::get32(fields.branchPoolsOffset); }
78 void set_branchPoolsOffset(uint32_t value) INLINE { E::set32(fields.branchPoolsOffset, value); }
80 uint32_t branchPoolsCount() const INLINE { return E::get32(fields.branchPoolsCount); }
81 void set_branchPoolsCount(uint32_t value) INLINE { E::set32(fields.branchPoolsCount, value); }
83 uint64_t accelerateInfoAddr() const INLINE { return E::get64(fields.accelerateInfoAddr); }
84 void set_accelerateInfoAddr(uint64_t value) INLINE { E::set64(fields.accelerateInfoAddr, value); }
86 uint64_t accelerateInfoSize() const INLINE { return E::get64(fields.accelerateInfoSize); }
87 void set_accelerateInfoSize(uint64_t value) INLINE { E::set64(fields.accelerateInfoSize, value); }
89 uint64_t imagesTextOffset() const INLINE { return E::get64(fields.imagesTextOffset); }
90 void set_imagesTextOffset(uint64_t value) INLINE { E::set64(fields.imagesTextOffset, value); }
92 uint64_t imagesTextCount() const INLINE { return E::get64(fields.imagesTextCount); }
93 void set_imagesTextCount(uint64_t value) INLINE { E::set64(fields.imagesTextCount, value); }
96 dyld_cache_header fields;
100 template <typename E>
101 class dyldCacheFileMapping {
103 uint64_t address() const INLINE { return E::get64(fields.address); }
104 void set_address(uint64_t value) INLINE { E::set64(fields.address, value); }
106 uint64_t size() const INLINE { return E::get64(fields.size); }
107 void set_size(uint64_t value) INLINE { E::set64(fields.size, value); }
109 uint64_t file_offset() const INLINE { return E::get64(fields.fileOffset); }
110 void set_file_offset(uint64_t value) INLINE { E::set64(fields.fileOffset, value); }
112 uint32_t max_prot() const INLINE { return E::get32(fields.maxProt); }
113 void set_max_prot(uint32_t value) INLINE { E::set32((uint32_t&)fields.maxProt, value); }
115 uint32_t init_prot() const INLINE { return E::get32(fields.initProt); }
116 void set_init_prot(uint32_t value) INLINE { E::set32((uint32_t&)fields.initProt, value); }
119 dyld_cache_mapping_info fields;
123 template <typename E>
124 class dyldCacheImageInfo {
126 uint64_t address() const INLINE { return E::get64(fields.address); }
127 void set_address(uint64_t value) INLINE { E::set64(fields.address, value); }
129 uint64_t modTime() const INLINE { return E::get64(fields.modTime); }
130 void set_modTime(uint64_t value) INLINE { E::set64(fields.modTime, value); }
132 uint64_t inode() const INLINE { return E::get64(fields.inode); }
133 void set_inode(uint64_t value) INLINE { E::set64(fields.inode, value); }
135 uint32_t pathFileOffset() const INLINE { return E::get32(fields.pathFileOffset); }
136 void set_pathFileOffset(uint32_t value) INLINE { E::set32(fields.pathFileOffset, value); fields.pad=0; }
139 dyld_cache_image_info fields;
142 template <typename E>
143 class dyldCacheImageTextInfo {
145 const uint8_t* uuid() const INLINE { return fields.uuid; }
146 void set_uuid(const uint8_t value[16]) INLINE { memcpy(fields.uuid, value, 16); }
148 uint64_t loadAddress() const INLINE { return E::get64(fields.loadAddress); }
149 void set_loadAddress(uint64_t value) INLINE { E::set64(fields.loadAddress, value); }
151 uint32_t textSegmentSize() const INLINE { return E::get32(fields.textSegmentSize); }
152 void set_textSegmentSize(uint32_t value) INLINE { E::set32(fields.textSegmentSize, value); }
154 uint32_t pathOffset() const INLINE { return E::get32(fields.pathOffset); }
155 void set_pathOffset(uint32_t value) INLINE { E::set32(fields.pathOffset, value); }
158 dyld_cache_image_text_info fields;
163 template <typename E>
164 class dyldCacheImageInfoExtra {
166 uint64_t exportsTrieAddr() const INLINE { return E::get64(fields.exportsTrieAddr); }
167 void set_exportsTrieAddr(uint64_t value) INLINE { E::set64(fields.exportsTrieAddr, value); }
169 uint64_t weakBindingsAddr() const INLINE { return E::get64(fields.weakBindingsAddr); }
170 void set_weakBindingsAddr(uint64_t value) INLINE { E::set64(fields.weakBindingsAddr, value); }
172 uint32_t exportsTrieSize() const INLINE { return E::get32(fields.exportsTrieSize); }
173 void set_exportsTrieSize(uint32_t value) INLINE { E::set32(fields.exportsTrieSize, value); }
175 uint32_t weakBindingsSize() const INLINE { return E::get32(fields.weakBindingsSize); }
176 void set_weakBindingsSize(uint32_t value) INLINE { E::set32(fields.weakBindingsSize, value); }
178 uint32_t dependentsStartArrayIndex() const INLINE { return E::get32(fields.dependentsStartArrayIndex); }
179 void set_dependentsStartArrayIndex(uint32_t value) INLINE { E::set32(fields.dependentsStartArrayIndex, value); }
181 uint32_t reExportsStartArrayIndex() const INLINE { return E::get32(fields.reExportsStartArrayIndex); }
182 void set_reExportsStartArrayIndex(uint32_t value) INLINE { E::set32(fields.reExportsStartArrayIndex, value); }
185 dyld_cache_image_info_extra fields;
189 template <typename E>
190 class dyldCacheAcceleratorInfo {
192 uint32_t version() const INLINE { return E::get32(fields.version); }
193 void set_version(uint32_t value) INLINE { E::set32(fields.version, value); }
195 uint32_t imageExtrasCount() const INLINE { return E::get32(fields.imageExtrasCount); }
196 void set_imageExtrasCount(uint32_t value) INLINE { E::set32(fields.imageExtrasCount, value); }
198 uint32_t imagesExtrasOffset() const INLINE { return E::get32(fields.imagesExtrasOffset); }
199 void set_imagesExtrasOffset(uint32_t value) INLINE { E::set32(fields.imagesExtrasOffset, value); }
201 uint32_t bottomUpListOffset() const INLINE { return E::get32(fields.bottomUpListOffset); }
202 void set_bottomUpListOffset(uint32_t value) INLINE { E::set32(fields.bottomUpListOffset, value); }
204 uint32_t dylibTrieOffset() const INLINE { return E::get32(fields.dylibTrieOffset); }
205 void set_dylibTrieOffset(uint32_t value) INLINE { E::set32(fields.dylibTrieOffset, value); }
207 uint32_t dylibTrieSize() const INLINE { return E::get32(fields.dylibTrieSize); }
208 void set_dylibTrieSize(uint32_t value) INLINE { E::set32(fields.dylibTrieSize, value); }
210 uint32_t initializersOffset() const INLINE { return E::get32(fields.initializersOffset); }
211 void set_initializersOffset(uint32_t value) INLINE { E::set32(fields.initializersOffset, value); }
213 uint32_t initializersCount() const INLINE { return E::get32(fields.initializersCount); }
214 void set_initializersCount(uint32_t value) INLINE { E::set32(fields.initializersCount, value); }
216 uint32_t dofSectionsOffset() const INLINE { return E::get32(fields.dofSectionsOffset); }
217 void set_dofSectionsOffset(uint32_t value) INLINE { E::set32(fields.dofSectionsOffset, value); }
219 uint32_t dofSectionsCount() const INLINE { return E::get32(fields.dofSectionsCount); }
220 void set_dofSectionsCount(uint32_t value) INLINE { E::set32(fields.dofSectionsCount, value); }
222 uint32_t reExportListOffset() const INLINE { return E::get32(fields.reExportListOffset); }
223 void set_reExportListOffset(uint32_t value) INLINE { E::set32(fields.reExportListOffset, value); }
225 uint32_t reExportCount() const INLINE { return E::get32(fields.reExportCount); }
226 void set_reExportCount(uint32_t value) INLINE { E::set32(fields.reExportCount, value); }
228 uint32_t depListOffset() const INLINE { return E::get32(fields.depListOffset); }
229 void set_depListOffset(uint32_t value) INLINE { E::set32(fields.depListOffset, value); }
231 uint32_t depListCount() const INLINE { return E::get32(fields.depListCount); }
232 void set_depListCount(uint32_t value) INLINE { E::set32(fields.depListCount, value); }
234 uint32_t rangeTableOffset() const INLINE { return E::get32(fields.rangeTableOffset); }
235 void set_rangeTableOffset(uint32_t value) INLINE { E::set32(fields.rangeTableOffset, value); }
237 uint32_t rangeTableCount() const INLINE { return E::get32(fields.rangeTableCount); }
238 void set_rangeTableCount(uint32_t value) INLINE { E::set32(fields.rangeTableCount, value); }
240 uint64_t dyldSectionAddr() const INLINE { return E::get64(fields.dyldSectionAddr); }
241 void set_dyldSectionAddr(uint64_t value) INLINE { E::set64(fields.dyldSectionAddr, value); }
245 dyld_cache_accelerator_info fields;
249 template <typename E>
250 class dyldCacheAcceleratorInitializer {
252 uint32_t functionOffset() const INLINE { return E::get32(fields.functionOffset); }
253 void set_functionOffset(uint32_t value) INLINE { E::set32(fields.functionOffset, value); }
255 uint32_t imageIndex() const INLINE { return E::get32(fields.imageIndex); }
256 void set_imageIndex(uint32_t value) INLINE { E::set32(fields.imageIndex, value); }
259 dyld_cache_accelerator_initializer fields;
263 template <typename E>
264 class dyldCacheAcceleratorRangeEntry {
266 uint64_t startAddress() const INLINE { return E::get64(fields.startAddress); }
267 void set_startAddress(uint64_t value) INLINE { E::set64(fields.startAddress, value); }
269 uint32_t size() const INLINE { return E::get32(fields.size); }
270 void set_size(uint32_t value) INLINE { E::set32(fields.size, value); }
272 uint32_t imageIndex() const INLINE { return E::get32(fields.imageIndex); }
273 void set_imageIndex(uint32_t value) INLINE { E::set32(fields.imageIndex, value); }
276 dyld_cache_range_entry fields;
279 template <typename E>
280 class dyldCacheAcceleratorDOFEntry {
282 uint64_t sectionAddress() const INLINE { return E::get64(fields.sectionAddress); }
283 void set_sectionAddress(uint64_t value) INLINE { E::set64(fields.sectionAddress, value); }
285 uint32_t sectionSize() const INLINE { return E::get32(fields.sectionSize); }
286 void set_sectionSize(uint32_t value) INLINE { E::set32(fields.sectionSize, value); }
288 uint32_t imageIndex() const INLINE { return E::get32(fields.imageIndex); }
289 void set_imageIndex(uint32_t value) INLINE { E::set32(fields.imageIndex, value); }
292 dyld_cache_accelerator_dof fields;
295 template <typename E>
296 class dyldCacheSlideInfo {
298 uint32_t version() const INLINE { return E::get32(fields.version); }
299 void set_version(uint32_t value) INLINE { E::set32(fields.version, value); }
301 uint32_t toc_offset() const INLINE { return E::get32(fields.toc_offset); }
302 void set_toc_offset(uint32_t value) INLINE { E::set32(fields.toc_offset, value); }
304 uint32_t toc_count() const INLINE { return E::get32(fields.toc_count); }
305 void set_toc_count(uint32_t value) INLINE { E::set32(fields.toc_count, value); }
307 uint32_t entries_offset() const INLINE { return E::get32(fields.entries_offset); }
308 void set_entries_offset(uint32_t value) INLINE { E::set32(fields.entries_offset, value); }
310 uint32_t entries_count() const INLINE { return E::get32(fields.entries_count); }
311 void set_entries_count(uint32_t value) INLINE { E::set32(fields.entries_count, value); }
313 uint32_t entries_size() const INLINE { return E::get32(fields.entries_size); }
314 void set_entries_size(uint32_t value) INLINE { E::set32(fields.entries_size, value); }
316 uint16_t toc(unsigned index) const INLINE { return E::get16(((uint16_t*)(((uint8_t*)this)+E::get16(fields.toc_offset)))[index]); }
317 void set_toc(unsigned index, uint16_t value) INLINE { return E::set16(((uint16_t*)(((uint8_t*)this)+E::get16(fields.toc_offset)))[index], value); }
320 dyld_cache_slide_info fields;
324 struct dyldCacheSlideInfoEntry {
325 uint8_t bits[4096/(8*4)]; // 128-byte bitmap
329 template <typename E>
330 class dyldCacheSlideInfo2 {
332 uint32_t version() const INLINE { return E::get32(fields.version); }
333 void set_version(uint32_t value) INLINE { E::set32(fields.version, value); }
335 uint32_t page_starts_offset() const INLINE { return E::get32(fields.page_starts_offset); }
336 void set_page_starts_offset(uint32_t value) INLINE { E::set32(fields.page_starts_offset, value); }
338 uint32_t page_starts_count() const INLINE { return E::get32(fields.page_starts_count); }
339 void set_page_starts_count(uint32_t value) INLINE { E::set32(fields.page_starts_count, value); }
341 uint32_t page_extras_offset() const INLINE { return E::get32(fields.page_extras_offset); }
342 void set_page_extras_offset(uint32_t value) INLINE { E::set32(fields.page_extras_offset, value); }
344 uint32_t page_extras_count() const INLINE { return E::get32(fields.page_extras_count); }
345 void set_page_extras_count(uint32_t value) INLINE { E::set32(fields.page_extras_count, value); }
347 uint32_t page_size() const INLINE { return E::get32(fields.page_size); }
348 void set_page_size(uint32_t value) INLINE { E::set32(fields.page_size, value); }
350 uint64_t delta_mask() const INLINE { return E::get64(fields.delta_mask); }
351 void set_delta_mask(uint64_t value) INLINE { E::set64(fields.delta_mask, value); }
353 uint64_t value_add() const INLINE { return E::get64(fields.value_add); }
354 void set_value_add(uint64_t value) INLINE { E::set64(fields.value_add, value); }
356 uint16_t page_starts(unsigned index) const INLINE { return E::get16(((uint16_t*)(((uint8_t*)this)+E::get16(fields.page_starts_offset)))[index]); }
357 void set_page_starts(unsigned index, uint16_t value) INLINE { return E::set16(((uint16_t*)(((uint8_t*)this)+E::get16(fields.page_starts_offset)))[index], value); }
359 uint16_t page_extras(unsigned index) const INLINE { return E::get16(((uint16_t*)(((uint8_t*)this)+E::get16(fields.page_extras_offset)))[index]); }
360 void set_page_extras(unsigned index, uint16_t value) INLINE { return E::set16(((uint16_t*)(((uint8_t*)this)+E::get16(fields.page_extras_offset)))[index], value); }
364 dyld_cache_slide_info2 fields;
369 template <typename E>
370 class dyldCacheLocalSymbolsInfo {
372 uint32_t nlistOffset() const INLINE { return E::get32(fields.nlistOffset); }
373 void set_nlistOffset(uint32_t value) INLINE { E::set32(fields.nlistOffset, value); }
375 uint32_t nlistCount() const INLINE { return E::get32(fields.nlistCount); }
376 void set_nlistCount(uint32_t value) INLINE { E::set32(fields.nlistCount, value); }
378 uint32_t stringsOffset() const INLINE { return E::get32(fields.stringsOffset); }
379 void set_stringsOffset(uint32_t value) INLINE { E::set32(fields.stringsOffset, value); }
381 uint32_t stringsSize() const INLINE { return E::get32(fields.stringsSize); }
382 void set_stringsSize(uint32_t value) INLINE { E::set32(fields.stringsSize, value); }
384 uint32_t entriesOffset() const INLINE { return E::get32(fields.entriesOffset); }
385 void set_entriesOffset(uint32_t value) INLINE { E::set32(fields.entriesOffset, value); }
387 uint32_t entriesCount() const INLINE { return E::get32(fields.entriesCount); }
388 void set_entriesCount(uint32_t value) INLINE { E::set32(fields.entriesCount, value); }
391 dyld_cache_local_symbols_info fields;
395 template <typename E>
396 class dyldCacheLocalSymbolEntry {
398 uint32_t dylibOffset() const INLINE { return E::get32(fields.dylibOffset); }
399 void set_dylibOffset(uint32_t value) INLINE { E::set32(fields.dylibOffset, value); }
401 uint32_t nlistStartIndex() const INLINE { return E::get32(fields.nlistStartIndex); }
402 void set_nlistStartIndex(uint32_t value) INLINE { E::set32(fields.nlistStartIndex, value); }
404 uint32_t nlistCount() const INLINE { return E::get32(fields.nlistCount); }
405 void set_nlistCount(uint32_t value) INLINE { E::set32(fields.nlistCount, value); }
408 dyld_cache_local_symbols_entry fields;
414 #endif // __DYLD_CACHE_ABSTRACTION__