]> git.saurik.com Git - apple/dyld.git/blob - launch-cache/CacheFileAbstraction.hpp
dyld-519.2.2.tar.gz
[apple/dyld.git] / launch-cache / CacheFileAbstraction.hpp
1 /* -*- mode: C++; c-basic-offset: 4; tab-width: 4 -*-
2 *
3 * Copyright (c) 2006 Apple Computer, Inc. All rights reserved.
4 *
5 * @APPLE_LICENSE_HEADER_START@
6 *
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
12 * file.
13 *
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.
21 *
22 * @APPLE_LICENSE_HEADER_END@
23 */
24 #ifndef __DYLD_CACHE_ABSTRACTION__
25 #define __DYLD_CACHE_ABSTRACTION__
26
27 #include "dyld_cache_format.h"
28
29 #include "FileAbstraction.hpp"
30 #include "Architectures.hpp"
31
32 template <typename E>
33 class dyldCacheHeader {
34 public:
35 const char* magic() const INLINE { return fields.magic; }
36 void set_magic(const char* value) INLINE { memcpy(fields.magic, value, 16); }
37
38 uint32_t mappingOffset() const INLINE { return E::get32(fields.mappingOffset); }
39 void set_mappingOffset(uint32_t value) INLINE { E::set32(fields.mappingOffset, value); }
40
41 uint32_t mappingCount() const INLINE { return E::get32(fields.mappingCount); }
42 void set_mappingCount(uint32_t value) INLINE { E::set32(fields.mappingCount, value); }
43
44 uint32_t imagesOffset() const INLINE { return E::get32(fields.imagesOffset); }
45 void set_imagesOffset(uint32_t value) INLINE { E::set32(fields.imagesOffset, value); }
46
47 uint32_t imagesCount() const INLINE { return E::get32(fields.imagesCount); }
48 void set_imagesCount(uint32_t value) INLINE { E::set32(fields.imagesCount, value); }
49
50 uint64_t dyldBaseAddress() const INLINE { return E::get64(fields.dyldBaseAddress); }
51 void set_dyldBaseAddress(uint64_t value) INLINE { E::set64(fields.dyldBaseAddress, value); }
52
53 uint64_t codeSignatureOffset() const INLINE { return E::get64(fields.codeSignatureOffset); }
54 void set_codeSignatureOffset(uint64_t value) INLINE { E::set64(fields.codeSignatureOffset, value); }
55
56 uint64_t codeSignatureSize() const INLINE { return E::get64(fields.codeSignatureSize); }
57 void set_codeSignatureSize(uint64_t value) INLINE { E::set64(fields.codeSignatureSize, value); }
58
59 uint64_t slideInfoOffset() const INLINE { return E::get64(fields.slideInfoOffset); }
60 void set_slideInfoOffset(uint64_t value) INLINE { E::set64(fields.slideInfoOffset, value); }
61
62 uint64_t slideInfoSize() const INLINE { return E::get64(fields.slideInfoSize); }
63 void set_slideInfoSize(uint64_t value) INLINE { E::set64(fields.slideInfoSize, value); }
64
65 uint64_t localSymbolsOffset() const INLINE { return E::get64(fields.localSymbolsOffset); }
66 void set_localSymbolsOffset(uint64_t value) INLINE { E::set64(fields.localSymbolsOffset, value); }
67
68 uint64_t localSymbolsSize() const INLINE { return E::get64(fields.localSymbolsSize); }
69 void set_localSymbolsSize(uint64_t value) INLINE { E::set64(fields.localSymbolsSize, value); }
70
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); }
73
74 uint64_t cacheType() const INLINE { return E::get64(fields.cacheType); }
75 void set_cacheType(uint64_t value) INLINE { E::set64(fields.cacheType, value); }
76
77 uint32_t branchPoolsOffset() const INLINE { return E::get32(fields.branchPoolsOffset); }
78 void set_branchPoolsOffset(uint32_t value) INLINE { E::set32(fields.branchPoolsOffset, value); }
79
80 uint32_t branchPoolsCount() const INLINE { return E::get32(fields.branchPoolsCount); }
81 void set_branchPoolsCount(uint32_t value) INLINE { E::set32(fields.branchPoolsCount, value); }
82
83 uint64_t accelerateInfoAddr() const INLINE { return E::get64(fields.accelerateInfoAddr); }
84 void set_accelerateInfoAddr(uint64_t value) INLINE { E::set64(fields.accelerateInfoAddr, value); }
85
86 uint64_t accelerateInfoSize() const INLINE { return E::get64(fields.accelerateInfoSize); }
87 void set_accelerateInfoSize(uint64_t value) INLINE { E::set64(fields.accelerateInfoSize, value); }
88
89 uint64_t imagesTextOffset() const INLINE { return E::get64(fields.imagesTextOffset); }
90 void set_imagesTextOffset(uint64_t value) INLINE { E::set64(fields.imagesTextOffset, value); }
91
92 uint64_t imagesTextCount() const INLINE { return E::get64(fields.imagesTextCount); }
93 void set_imagesTextCount(uint64_t value) INLINE { E::set64(fields.imagesTextCount, value); }
94
95 private:
96 dyld_cache_header fields;
97 };
98
99
100
101 template <typename E>
102 class dyldCacheFileMapping {
103 public:
104 uint64_t address() const INLINE { return E::get64(fields.address); }
105 void set_address(uint64_t value) INLINE { E::set64(fields.address, value); }
106
107 uint64_t size() const INLINE { return E::get64(fields.size); }
108 void set_size(uint64_t value) INLINE { E::set64(fields.size, value); }
109
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); }
112
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); }
115
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); }
118
119 private:
120 dyld_cache_mapping_info fields;
121 };
122
123
124 template <typename E>
125 class dyldCacheImageInfo {
126 public:
127 uint64_t address() const INLINE { return E::get64(fields.address); }
128 void set_address(uint64_t value) INLINE { E::set64(fields.address, value); }
129
130 uint64_t modTime() const INLINE { return E::get64(fields.modTime); }
131 void set_modTime(uint64_t value) INLINE { E::set64(fields.modTime, value); }
132
133 uint64_t inode() const INLINE { return E::get64(fields.inode); }
134 void set_inode(uint64_t value) INLINE { E::set64(fields.inode, value); }
135
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; }
138
139 private:
140 dyld_cache_image_info fields;
141 };
142
143 template <typename E>
144 class dyldCacheImageTextInfo {
145 public:
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); }
148
149 uint64_t loadAddress() const INLINE { return E::get64(fields.loadAddress); }
150 void set_loadAddress(uint64_t value) INLINE { E::set64(fields.loadAddress, value); }
151
152 uint32_t textSegmentSize() const INLINE { return E::get32(fields.textSegmentSize); }
153 void set_textSegmentSize(uint32_t value) INLINE { E::set32(fields.textSegmentSize, value); }
154
155 uint32_t pathOffset() const INLINE { return E::get32(fields.pathOffset); }
156 void set_pathOffset(uint32_t value) INLINE { E::set32(fields.pathOffset, value); }
157
158 private:
159 dyld_cache_image_text_info fields;
160 };
161
162
163
164 template <typename E>
165 class dyldCacheImageInfoExtra {
166 public:
167 uint64_t exportsTrieAddr() const INLINE { return E::get64(fields.exportsTrieAddr); }
168 void set_exportsTrieAddr(uint64_t value) INLINE { E::set64(fields.exportsTrieAddr, value); }
169
170 uint64_t weakBindingsAddr() const INLINE { return E::get64(fields.weakBindingsAddr); }
171 void set_weakBindingsAddr(uint64_t value) INLINE { E::set64(fields.weakBindingsAddr, value); }
172
173 uint32_t exportsTrieSize() const INLINE { return E::get32(fields.exportsTrieSize); }
174 void set_exportsTrieSize(uint32_t value) INLINE { E::set32(fields.exportsTrieSize, value); }
175
176 uint32_t weakBindingsSize() const INLINE { return E::get32(fields.weakBindingsSize); }
177 void set_weakBindingsSize(uint32_t value) INLINE { E::set32(fields.weakBindingsSize, value); }
178
179 uint32_t dependentsStartArrayIndex() const INLINE { return E::get32(fields.dependentsStartArrayIndex); }
180 void set_dependentsStartArrayIndex(uint32_t value) INLINE { E::set32(fields.dependentsStartArrayIndex, value); }
181
182 uint32_t reExportsStartArrayIndex() const INLINE { return E::get32(fields.reExportsStartArrayIndex); }
183 void set_reExportsStartArrayIndex(uint32_t value) INLINE { E::set32(fields.reExportsStartArrayIndex, value); }
184
185 private:
186 dyld_cache_image_info_extra fields;
187 };
188
189
190 template <typename E>
191 class dyldCacheAcceleratorInfo {
192 public:
193 uint32_t version() const INLINE { return E::get32(fields.version); }
194 void set_version(uint32_t value) INLINE { E::set32(fields.version, value); }
195
196 uint32_t imageExtrasCount() const INLINE { return E::get32(fields.imageExtrasCount); }
197 void set_imageExtrasCount(uint32_t value) INLINE { E::set32(fields.imageExtrasCount, value); }
198
199 uint32_t imagesExtrasOffset() const INLINE { return E::get32(fields.imagesExtrasOffset); }
200 void set_imagesExtrasOffset(uint32_t value) INLINE { E::set32(fields.imagesExtrasOffset, value); }
201
202 uint32_t bottomUpListOffset() const INLINE { return E::get32(fields.bottomUpListOffset); }
203 void set_bottomUpListOffset(uint32_t value) INLINE { E::set32(fields.bottomUpListOffset, value); }
204
205 uint32_t dylibTrieOffset() const INLINE { return E::get32(fields.dylibTrieOffset); }
206 void set_dylibTrieOffset(uint32_t value) INLINE { E::set32(fields.dylibTrieOffset, value); }
207
208 uint32_t dylibTrieSize() const INLINE { return E::get32(fields.dylibTrieSize); }
209 void set_dylibTrieSize(uint32_t value) INLINE { E::set32(fields.dylibTrieSize, value); }
210
211 uint32_t initializersOffset() const INLINE { return E::get32(fields.initializersOffset); }
212 void set_initializersOffset(uint32_t value) INLINE { E::set32(fields.initializersOffset, value); }
213
214 uint32_t initializersCount() const INLINE { return E::get32(fields.initializersCount); }
215 void set_initializersCount(uint32_t value) INLINE { E::set32(fields.initializersCount, value); }
216
217 uint32_t dofSectionsOffset() const INLINE { return E::get32(fields.dofSectionsOffset); }
218 void set_dofSectionsOffset(uint32_t value) INLINE { E::set32(fields.dofSectionsOffset, value); }
219
220 uint32_t dofSectionsCount() const INLINE { return E::get32(fields.dofSectionsCount); }
221 void set_dofSectionsCount(uint32_t value) INLINE { E::set32(fields.dofSectionsCount, value); }
222
223 uint32_t reExportListOffset() const INLINE { return E::get32(fields.reExportListOffset); }
224 void set_reExportListOffset(uint32_t value) INLINE { E::set32(fields.reExportListOffset, value); }
225
226 uint32_t reExportCount() const INLINE { return E::get32(fields.reExportCount); }
227 void set_reExportCount(uint32_t value) INLINE { E::set32(fields.reExportCount, value); }
228
229 uint32_t depListOffset() const INLINE { return E::get32(fields.depListOffset); }
230 void set_depListOffset(uint32_t value) INLINE { E::set32(fields.depListOffset, value); }
231
232 uint32_t depListCount() const INLINE { return E::get32(fields.depListCount); }
233 void set_depListCount(uint32_t value) INLINE { E::set32(fields.depListCount, value); }
234
235 uint32_t rangeTableOffset() const INLINE { return E::get32(fields.rangeTableOffset); }
236 void set_rangeTableOffset(uint32_t value) INLINE { E::set32(fields.rangeTableOffset, value); }
237
238 uint32_t rangeTableCount() const INLINE { return E::get32(fields.rangeTableCount); }
239 void set_rangeTableCount(uint32_t value) INLINE { E::set32(fields.rangeTableCount, value); }
240
241 uint64_t dyldSectionAddr() const INLINE { return E::get64(fields.dyldSectionAddr); }
242 void set_dyldSectionAddr(uint64_t value) INLINE { E::set64(fields.dyldSectionAddr, value); }
243
244
245 private:
246 dyld_cache_accelerator_info fields;
247 };
248
249
250 template <typename E>
251 class dyldCacheAcceleratorInitializer {
252 public:
253 uint32_t functionOffset() const INLINE { return E::get32(fields.functionOffset); }
254 void set_functionOffset(uint32_t value) INLINE { E::set32(fields.functionOffset, value); }
255
256 uint32_t imageIndex() const INLINE { return E::get32(fields.imageIndex); }
257 void set_imageIndex(uint32_t value) INLINE { E::set32(fields.imageIndex, value); }
258
259 private:
260 dyld_cache_accelerator_initializer fields;
261 };
262
263
264 template <typename E>
265 class dyldCacheAcceleratorRangeEntry {
266 public:
267 uint64_t startAddress() const INLINE { return E::get64(fields.startAddress); }
268 void set_startAddress(uint64_t value) INLINE { E::set64(fields.startAddress, value); }
269
270 uint32_t size() const INLINE { return E::get32(fields.size); }
271 void set_size(uint32_t value) INLINE { E::set32(fields.size, value); }
272
273 uint32_t imageIndex() const INLINE { return E::get32(fields.imageIndex); }
274 void set_imageIndex(uint32_t value) INLINE { E::set32(fields.imageIndex, value); }
275
276 private:
277 dyld_cache_range_entry fields;
278 };
279
280 template <typename E>
281 class dyldCacheAcceleratorDOFEntry {
282 public:
283 uint64_t sectionAddress() const INLINE { return E::get64(fields.sectionAddress); }
284 void set_sectionAddress(uint64_t value) INLINE { E::set64(fields.sectionAddress, value); }
285
286 uint32_t sectionSize() const INLINE { return E::get32(fields.sectionSize); }
287 void set_sectionSize(uint32_t value) INLINE { E::set32(fields.sectionSize, value); }
288
289 uint32_t imageIndex() const INLINE { return E::get32(fields.imageIndex); }
290 void set_imageIndex(uint32_t value) INLINE { E::set32(fields.imageIndex, value); }
291
292 private:
293 dyld_cache_accelerator_dof fields;
294 };
295
296
297 template <typename E>
298 class dyldCacheSlideInfo {
299 public:
300 uint32_t version() const INLINE { return E::get32(fields.version); }
301 void set_version(uint32_t value) INLINE { E::set32(fields.version, value); }
302
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); }
305
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); }
308
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); }
311
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); }
314
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); }
317
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); }
320
321 private:
322 dyld_cache_slide_info fields;
323 };
324
325
326 struct dyldCacheSlideInfoEntry {
327 uint8_t bits[4096/(8*4)]; // 128-byte bitmap
328 };
329
330
331 template <typename E>
332 class dyldCacheSlideInfo2 {
333 public:
334 uint32_t version() const INLINE { return E::get32(fields.version); }
335 void set_version(uint32_t value) INLINE { E::set32(fields.version, value); }
336
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); }
339
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); }
342
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); }
345
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); }
348
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); }
351
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); }
354
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); }
357
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); }
360
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); }
363
364
365 private:
366 dyld_cache_slide_info2 fields;
367 };
368
369
370
371 template <typename E>
372 class dyldCacheLocalSymbolsInfo {
373 public:
374 uint32_t nlistOffset() const INLINE { return E::get32(fields.nlistOffset); }
375 void set_nlistOffset(uint32_t value) INLINE { E::set32(fields.nlistOffset, value); }
376
377 uint32_t nlistCount() const INLINE { return E::get32(fields.nlistCount); }
378 void set_nlistCount(uint32_t value) INLINE { E::set32(fields.nlistCount, value); }
379
380 uint32_t stringsOffset() const INLINE { return E::get32(fields.stringsOffset); }
381 void set_stringsOffset(uint32_t value) INLINE { E::set32(fields.stringsOffset, value); }
382
383 uint32_t stringsSize() const INLINE { return E::get32(fields.stringsSize); }
384 void set_stringsSize(uint32_t value) INLINE { E::set32(fields.stringsSize, value); }
385
386 uint32_t entriesOffset() const INLINE { return E::get32(fields.entriesOffset); }
387 void set_entriesOffset(uint32_t value) INLINE { E::set32(fields.entriesOffset, value); }
388
389 uint32_t entriesCount() const INLINE { return E::get32(fields.entriesCount); }
390 void set_entriesCount(uint32_t value) INLINE { E::set32(fields.entriesCount, value); }
391
392 private:
393 dyld_cache_local_symbols_info fields;
394 };
395
396
397 template <typename E>
398 class dyldCacheLocalSymbolEntry {
399 public:
400 uint32_t dylibOffset() const INLINE { return E::get32(fields.dylibOffset); }
401 void set_dylibOffset(uint32_t value) INLINE { E::set32(fields.dylibOffset, value); }
402
403 uint32_t nlistStartIndex() const INLINE { return E::get32(fields.nlistStartIndex); }
404 void set_nlistStartIndex(uint32_t value) INLINE { E::set32(fields.nlistStartIndex, value); }
405
406 uint32_t nlistCount() const INLINE { return E::get32(fields.nlistCount); }
407 void set_nlistCount(uint32_t value) INLINE { E::set32(fields.nlistCount, value); }
408
409 private:
410 dyld_cache_local_symbols_entry fields;
411 };
412
413
414
415
416 #endif // __DYLD_CACHE_ABSTRACTION__
417
418