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;
101 template <typename E>
102 class dyldCacheFileMapping {
104 uint64_t address() const INLINE { return E::get64(fields.address); }
105 void set_address(uint64_t value) INLINE { E::set64(fields.address, value); }
107 uint64_t size() const INLINE { return E::get64(fields.size); }
108 void set_size(uint64_t value) INLINE { E::set64(fields.size, value); }
110 uint64_t file_offset() const INLINE { return E::get64(fields.fileOffset); }
111 void set_file_offset(uint64_t value) INLINE { E::set64(fields.fileOffset, value); }
113 uint32_t max_prot() const INLINE { return E::get32(fields.maxProt); }
114 void set_max_prot(uint32_t value) INLINE { E::set32((uint32_t&)fields.maxProt, value); }
116 uint32_t init_prot() const INLINE { return E::get32(fields.initProt); }
117 void set_init_prot(uint32_t value) INLINE { E::set32((uint32_t&)fields.initProt, value); }
120 dyld_cache_mapping_info fields;
124 template <typename E>
125 class dyldCacheImageInfo {
127 uint64_t address() const INLINE { return E::get64(fields.address); }
128 void set_address(uint64_t value) INLINE { E::set64(fields.address, value); }
130 uint64_t modTime() const INLINE { return E::get64(fields.modTime); }
131 void set_modTime(uint64_t value) INLINE { E::set64(fields.modTime, value); }
133 uint64_t inode() const INLINE { return E::get64(fields.inode); }
134 void set_inode(uint64_t value) INLINE { E::set64(fields.inode, value); }
136 uint32_t pathFileOffset() const INLINE { return E::get32(fields.pathFileOffset); }
137 void set_pathFileOffset(uint32_t value) INLINE { E::set32(fields.pathFileOffset, value); fields.pad=0; }
140 dyld_cache_image_info fields;
143 template <typename E>
144 class dyldCacheImageTextInfo {
146 const uint8_t* uuid() const INLINE { return fields.uuid; }
147 void set_uuid(const uint8_t value[16]) INLINE { memcpy(fields.uuid, value, 16); }
149 uint64_t loadAddress() const INLINE { return E::get64(fields.loadAddress); }
150 void set_loadAddress(uint64_t value) INLINE { E::set64(fields.loadAddress, value); }
152 uint32_t textSegmentSize() const INLINE { return E::get32(fields.textSegmentSize); }
153 void set_textSegmentSize(uint32_t value) INLINE { E::set32(fields.textSegmentSize, value); }
155 uint32_t pathOffset() const INLINE { return E::get32(fields.pathOffset); }
156 void set_pathOffset(uint32_t value) INLINE { E::set32(fields.pathOffset, value); }
159 dyld_cache_image_text_info fields;
164 template <typename E>
165 class dyldCacheImageInfoExtra {
167 uint64_t exportsTrieAddr() const INLINE { return E::get64(fields.exportsTrieAddr); }
168 void set_exportsTrieAddr(uint64_t value) INLINE { E::set64(fields.exportsTrieAddr, value); }
170 uint64_t weakBindingsAddr() const INLINE { return E::get64(fields.weakBindingsAddr); }
171 void set_weakBindingsAddr(uint64_t value) INLINE { E::set64(fields.weakBindingsAddr, value); }
173 uint32_t exportsTrieSize() const INLINE { return E::get32(fields.exportsTrieSize); }
174 void set_exportsTrieSize(uint32_t value) INLINE { E::set32(fields.exportsTrieSize, value); }
176 uint32_t weakBindingsSize() const INLINE { return E::get32(fields.weakBindingsSize); }
177 void set_weakBindingsSize(uint32_t value) INLINE { E::set32(fields.weakBindingsSize, value); }
179 uint32_t dependentsStartArrayIndex() const INLINE { return E::get32(fields.dependentsStartArrayIndex); }
180 void set_dependentsStartArrayIndex(uint32_t value) INLINE { E::set32(fields.dependentsStartArrayIndex, value); }
182 uint32_t reExportsStartArrayIndex() const INLINE { return E::get32(fields.reExportsStartArrayIndex); }
183 void set_reExportsStartArrayIndex(uint32_t value) INLINE { E::set32(fields.reExportsStartArrayIndex, value); }
186 dyld_cache_image_info_extra fields;
190 template <typename E>
191 class dyldCacheAcceleratorInfo {
193 uint32_t version() const INLINE { return E::get32(fields.version); }
194 void set_version(uint32_t value) INLINE { E::set32(fields.version, value); }
196 uint32_t imageExtrasCount() const INLINE { return E::get32(fields.imageExtrasCount); }
197 void set_imageExtrasCount(uint32_t value) INLINE { E::set32(fields.imageExtrasCount, value); }
199 uint32_t imagesExtrasOffset() const INLINE { return E::get32(fields.imagesExtrasOffset); }
200 void set_imagesExtrasOffset(uint32_t value) INLINE { E::set32(fields.imagesExtrasOffset, value); }
202 uint32_t bottomUpListOffset() const INLINE { return E::get32(fields.bottomUpListOffset); }
203 void set_bottomUpListOffset(uint32_t value) INLINE { E::set32(fields.bottomUpListOffset, value); }
205 uint32_t dylibTrieOffset() const INLINE { return E::get32(fields.dylibTrieOffset); }
206 void set_dylibTrieOffset(uint32_t value) INLINE { E::set32(fields.dylibTrieOffset, value); }
208 uint32_t dylibTrieSize() const INLINE { return E::get32(fields.dylibTrieSize); }
209 void set_dylibTrieSize(uint32_t value) INLINE { E::set32(fields.dylibTrieSize, value); }
211 uint32_t initializersOffset() const INLINE { return E::get32(fields.initializersOffset); }
212 void set_initializersOffset(uint32_t value) INLINE { E::set32(fields.initializersOffset, value); }
214 uint32_t initializersCount() const INLINE { return E::get32(fields.initializersCount); }
215 void set_initializersCount(uint32_t value) INLINE { E::set32(fields.initializersCount, value); }
217 uint32_t dofSectionsOffset() const INLINE { return E::get32(fields.dofSectionsOffset); }
218 void set_dofSectionsOffset(uint32_t value) INLINE { E::set32(fields.dofSectionsOffset, value); }
220 uint32_t dofSectionsCount() const INLINE { return E::get32(fields.dofSectionsCount); }
221 void set_dofSectionsCount(uint32_t value) INLINE { E::set32(fields.dofSectionsCount, value); }
223 uint32_t reExportListOffset() const INLINE { return E::get32(fields.reExportListOffset); }
224 void set_reExportListOffset(uint32_t value) INLINE { E::set32(fields.reExportListOffset, value); }
226 uint32_t reExportCount() const INLINE { return E::get32(fields.reExportCount); }
227 void set_reExportCount(uint32_t value) INLINE { E::set32(fields.reExportCount, value); }
229 uint32_t depListOffset() const INLINE { return E::get32(fields.depListOffset); }
230 void set_depListOffset(uint32_t value) INLINE { E::set32(fields.depListOffset, value); }
232 uint32_t depListCount() const INLINE { return E::get32(fields.depListCount); }
233 void set_depListCount(uint32_t value) INLINE { E::set32(fields.depListCount, value); }
235 uint32_t rangeTableOffset() const INLINE { return E::get32(fields.rangeTableOffset); }
236 void set_rangeTableOffset(uint32_t value) INLINE { E::set32(fields.rangeTableOffset, value); }
238 uint32_t rangeTableCount() const INLINE { return E::get32(fields.rangeTableCount); }
239 void set_rangeTableCount(uint32_t value) INLINE { E::set32(fields.rangeTableCount, value); }
241 uint64_t dyldSectionAddr() const INLINE { return E::get64(fields.dyldSectionAddr); }
242 void set_dyldSectionAddr(uint64_t value) INLINE { E::set64(fields.dyldSectionAddr, value); }
246 dyld_cache_accelerator_info fields;
250 template <typename E>
251 class dyldCacheAcceleratorInitializer {
253 uint32_t functionOffset() const INLINE { return E::get32(fields.functionOffset); }
254 void set_functionOffset(uint32_t value) INLINE { E::set32(fields.functionOffset, value); }
256 uint32_t imageIndex() const INLINE { return E::get32(fields.imageIndex); }
257 void set_imageIndex(uint32_t value) INLINE { E::set32(fields.imageIndex, value); }
260 dyld_cache_accelerator_initializer fields;
264 template <typename E>
265 class dyldCacheAcceleratorRangeEntry {
267 uint64_t startAddress() const INLINE { return E::get64(fields.startAddress); }
268 void set_startAddress(uint64_t value) INLINE { E::set64(fields.startAddress, value); }
270 uint32_t size() const INLINE { return E::get32(fields.size); }
271 void set_size(uint32_t value) INLINE { E::set32(fields.size, value); }
273 uint32_t imageIndex() const INLINE { return E::get32(fields.imageIndex); }
274 void set_imageIndex(uint32_t value) INLINE { E::set32(fields.imageIndex, value); }
277 dyld_cache_range_entry fields;
280 template <typename E>
281 class dyldCacheAcceleratorDOFEntry {
283 uint64_t sectionAddress() const INLINE { return E::get64(fields.sectionAddress); }
284 void set_sectionAddress(uint64_t value) INLINE { E::set64(fields.sectionAddress, value); }
286 uint32_t sectionSize() const INLINE { return E::get32(fields.sectionSize); }
287 void set_sectionSize(uint32_t value) INLINE { E::set32(fields.sectionSize, value); }
289 uint32_t imageIndex() const INLINE { return E::get32(fields.imageIndex); }
290 void set_imageIndex(uint32_t value) INLINE { E::set32(fields.imageIndex, value); }
293 dyld_cache_accelerator_dof fields;
297 template <typename E>
298 class dyldCacheSlideInfo {
300 uint32_t version() const INLINE { return E::get32(fields.version); }
301 void set_version(uint32_t value) INLINE { E::set32(fields.version, value); }
303 uint32_t toc_offset() const INLINE { return E::get32(fields.toc_offset); }
304 void set_toc_offset(uint32_t value) INLINE { E::set32(fields.toc_offset, value); }
306 uint32_t toc_count() const INLINE { return E::get32(fields.toc_count); }
307 void set_toc_count(uint32_t value) INLINE { E::set32(fields.toc_count, value); }
309 uint32_t entries_offset() const INLINE { return E::get32(fields.entries_offset); }
310 void set_entries_offset(uint32_t value) INLINE { E::set32(fields.entries_offset, value); }
312 uint32_t entries_count() const INLINE { return E::get32(fields.entries_count); }
313 void set_entries_count(uint32_t value) INLINE { E::set32(fields.entries_count, value); }
315 uint32_t entries_size() const INLINE { return E::get32(fields.entries_size); }
316 void set_entries_size(uint32_t value) INLINE { E::set32(fields.entries_size, value); }
318 uint16_t toc(unsigned index) const INLINE { return E::get16(((uint16_t*)(((uint8_t*)this)+E::get16(fields.toc_offset)))[index]); }
319 void set_toc(unsigned index, uint16_t value) INLINE { return E::set16(((uint16_t*)(((uint8_t*)this)+E::get16(fields.toc_offset)))[index], value); }
322 dyld_cache_slide_info fields;
326 struct dyldCacheSlideInfoEntry {
327 uint8_t bits[4096/(8*4)]; // 128-byte bitmap
331 template <typename E>
332 class dyldCacheSlideInfo2 {
334 uint32_t version() const INLINE { return E::get32(fields.version); }
335 void set_version(uint32_t value) INLINE { E::set32(fields.version, value); }
337 uint32_t page_starts_offset() const INLINE { return E::get32(fields.page_starts_offset); }
338 void set_page_starts_offset(uint32_t value) INLINE { E::set32(fields.page_starts_offset, value); }
340 uint32_t page_starts_count() const INLINE { return E::get32(fields.page_starts_count); }
341 void set_page_starts_count(uint32_t value) INLINE { E::set32(fields.page_starts_count, value); }
343 uint32_t page_extras_offset() const INLINE { return E::get32(fields.page_extras_offset); }
344 void set_page_extras_offset(uint32_t value) INLINE { E::set32(fields.page_extras_offset, value); }
346 uint32_t page_extras_count() const INLINE { return E::get32(fields.page_extras_count); }
347 void set_page_extras_count(uint32_t value) INLINE { E::set32(fields.page_extras_count, value); }
349 uint32_t page_size() const INLINE { return E::get32(fields.page_size); }
350 void set_page_size(uint32_t value) INLINE { E::set32(fields.page_size, value); }
352 uint64_t delta_mask() const INLINE { return E::get64(fields.delta_mask); }
353 void set_delta_mask(uint64_t value) INLINE { E::set64(fields.delta_mask, value); }
355 uint64_t value_add() const INLINE { return E::get64(fields.value_add); }
356 void set_value_add(uint64_t value) INLINE { E::set64(fields.value_add, value); }
358 uint16_t page_starts(unsigned index) const INLINE { return E::get16(((uint16_t*)(((uint8_t*)this)+E::get16(fields.page_starts_offset)))[index]); }
359 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); }
361 uint16_t page_extras(unsigned index) const INLINE { return E::get16(((uint16_t*)(((uint8_t*)this)+E::get16(fields.page_extras_offset)))[index]); }
362 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); }
366 dyld_cache_slide_info2 fields;
371 template <typename E>
372 class dyldCacheLocalSymbolsInfo {
374 uint32_t nlistOffset() const INLINE { return E::get32(fields.nlistOffset); }
375 void set_nlistOffset(uint32_t value) INLINE { E::set32(fields.nlistOffset, value); }
377 uint32_t nlistCount() const INLINE { return E::get32(fields.nlistCount); }
378 void set_nlistCount(uint32_t value) INLINE { E::set32(fields.nlistCount, value); }
380 uint32_t stringsOffset() const INLINE { return E::get32(fields.stringsOffset); }
381 void set_stringsOffset(uint32_t value) INLINE { E::set32(fields.stringsOffset, value); }
383 uint32_t stringsSize() const INLINE { return E::get32(fields.stringsSize); }
384 void set_stringsSize(uint32_t value) INLINE { E::set32(fields.stringsSize, value); }
386 uint32_t entriesOffset() const INLINE { return E::get32(fields.entriesOffset); }
387 void set_entriesOffset(uint32_t value) INLINE { E::set32(fields.entriesOffset, value); }
389 uint32_t entriesCount() const INLINE { return E::get32(fields.entriesCount); }
390 void set_entriesCount(uint32_t value) INLINE { E::set32(fields.entriesCount, value); }
393 dyld_cache_local_symbols_info fields;
397 template <typename E>
398 class dyldCacheLocalSymbolEntry {
400 uint32_t dylibOffset() const INLINE { return E::get32(fields.dylibOffset); }
401 void set_dylibOffset(uint32_t value) INLINE { E::set32(fields.dylibOffset, value); }
403 uint32_t nlistStartIndex() const INLINE { return E::get32(fields.nlistStartIndex); }
404 void set_nlistStartIndex(uint32_t value) INLINE { E::set32(fields.nlistStartIndex, value); }
406 uint32_t nlistCount() const INLINE { return E::get32(fields.nlistCount); }
407 void set_nlistCount(uint32_t value) INLINE { E::set32(fields.nlistCount, value); }
410 dyld_cache_local_symbols_entry fields;
416 #endif // __DYLD_CACHE_ABSTRACTION__