]> git.saurik.com Git - apple/dyld.git/blob - launch-cache/CacheFileAbstraction.hpp
b2dddbce498d93df61555b3bccb1d10394d5eeb9
[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 template <typename E>
101 class dyldCacheFileMapping {
102 public:
103 uint64_t address() const INLINE { return E::get64(fields.address); }
104 void set_address(uint64_t value) INLINE { E::set64(fields.address, value); }
105
106 uint64_t size() const INLINE { return E::get64(fields.size); }
107 void set_size(uint64_t value) INLINE { E::set64(fields.size, value); }
108
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); }
111
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); }
114
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); }
117
118 private:
119 dyld_cache_mapping_info fields;
120 };
121
122
123 template <typename E>
124 class dyldCacheImageInfo {
125 public:
126 uint64_t address() const INLINE { return E::get64(fields.address); }
127 void set_address(uint64_t value) INLINE { E::set64(fields.address, value); }
128
129 uint64_t modTime() const INLINE { return E::get64(fields.modTime); }
130 void set_modTime(uint64_t value) INLINE { E::set64(fields.modTime, value); }
131
132 uint64_t inode() const INLINE { return E::get64(fields.inode); }
133 void set_inode(uint64_t value) INLINE { E::set64(fields.inode, value); }
134
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; }
137
138 private:
139 dyld_cache_image_info fields;
140 };
141
142 template <typename E>
143 class dyldCacheImageTextInfo {
144 public:
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); }
147
148 uint64_t loadAddress() const INLINE { return E::get64(fields.loadAddress); }
149 void set_loadAddress(uint64_t value) INLINE { E::set64(fields.loadAddress, value); }
150
151 uint32_t textSegmentSize() const INLINE { return E::get32(fields.textSegmentSize); }
152 void set_textSegmentSize(uint32_t value) INLINE { E::set32(fields.textSegmentSize, value); }
153
154 uint32_t pathOffset() const INLINE { return E::get32(fields.pathOffset); }
155 void set_pathOffset(uint32_t value) INLINE { E::set32(fields.pathOffset, value); }
156
157 private:
158 dyld_cache_image_text_info fields;
159 };
160
161
162
163 template <typename E>
164 class dyldCacheImageInfoExtra {
165 public:
166 uint64_t exportsTrieAddr() const INLINE { return E::get64(fields.exportsTrieAddr); }
167 void set_exportsTrieAddr(uint64_t value) INLINE { E::set64(fields.exportsTrieAddr, value); }
168
169 uint64_t weakBindingsAddr() const INLINE { return E::get64(fields.weakBindingsAddr); }
170 void set_weakBindingsAddr(uint64_t value) INLINE { E::set64(fields.weakBindingsAddr, value); }
171
172 uint32_t exportsTrieSize() const INLINE { return E::get32(fields.exportsTrieSize); }
173 void set_exportsTrieSize(uint32_t value) INLINE { E::set32(fields.exportsTrieSize, value); }
174
175 uint32_t weakBindingsSize() const INLINE { return E::get32(fields.weakBindingsSize); }
176 void set_weakBindingsSize(uint32_t value) INLINE { E::set32(fields.weakBindingsSize, value); }
177
178 uint32_t dependentsStartArrayIndex() const INLINE { return E::get32(fields.dependentsStartArrayIndex); }
179 void set_dependentsStartArrayIndex(uint32_t value) INLINE { E::set32(fields.dependentsStartArrayIndex, value); }
180
181 uint32_t reExportsStartArrayIndex() const INLINE { return E::get32(fields.reExportsStartArrayIndex); }
182 void set_reExportsStartArrayIndex(uint32_t value) INLINE { E::set32(fields.reExportsStartArrayIndex, value); }
183
184 private:
185 dyld_cache_image_info_extra fields;
186 };
187
188
189 template <typename E>
190 class dyldCacheAcceleratorInfo {
191 public:
192 uint32_t version() const INLINE { return E::get32(fields.version); }
193 void set_version(uint32_t value) INLINE { E::set32(fields.version, value); }
194
195 uint32_t imageExtrasCount() const INLINE { return E::get32(fields.imageExtrasCount); }
196 void set_imageExtrasCount(uint32_t value) INLINE { E::set32(fields.imageExtrasCount, value); }
197
198 uint32_t imagesExtrasOffset() const INLINE { return E::get32(fields.imagesExtrasOffset); }
199 void set_imagesExtrasOffset(uint32_t value) INLINE { E::set32(fields.imagesExtrasOffset, value); }
200
201 uint32_t bottomUpListOffset() const INLINE { return E::get32(fields.bottomUpListOffset); }
202 void set_bottomUpListOffset(uint32_t value) INLINE { E::set32(fields.bottomUpListOffset, value); }
203
204 uint32_t dylibTrieOffset() const INLINE { return E::get32(fields.dylibTrieOffset); }
205 void set_dylibTrieOffset(uint32_t value) INLINE { E::set32(fields.dylibTrieOffset, value); }
206
207 uint32_t dylibTrieSize() const INLINE { return E::get32(fields.dylibTrieSize); }
208 void set_dylibTrieSize(uint32_t value) INLINE { E::set32(fields.dylibTrieSize, value); }
209
210 uint32_t initializersOffset() const INLINE { return E::get32(fields.initializersOffset); }
211 void set_initializersOffset(uint32_t value) INLINE { E::set32(fields.initializersOffset, value); }
212
213 uint32_t initializersCount() const INLINE { return E::get32(fields.initializersCount); }
214 void set_initializersCount(uint32_t value) INLINE { E::set32(fields.initializersCount, value); }
215
216 uint32_t dofSectionsOffset() const INLINE { return E::get32(fields.dofSectionsOffset); }
217 void set_dofSectionsOffset(uint32_t value) INLINE { E::set32(fields.dofSectionsOffset, value); }
218
219 uint32_t dofSectionsCount() const INLINE { return E::get32(fields.dofSectionsCount); }
220 void set_dofSectionsCount(uint32_t value) INLINE { E::set32(fields.dofSectionsCount, value); }
221
222 uint32_t reExportListOffset() const INLINE { return E::get32(fields.reExportListOffset); }
223 void set_reExportListOffset(uint32_t value) INLINE { E::set32(fields.reExportListOffset, value); }
224
225 uint32_t reExportCount() const INLINE { return E::get32(fields.reExportCount); }
226 void set_reExportCount(uint32_t value) INLINE { E::set32(fields.reExportCount, value); }
227
228 uint32_t depListOffset() const INLINE { return E::get32(fields.depListOffset); }
229 void set_depListOffset(uint32_t value) INLINE { E::set32(fields.depListOffset, value); }
230
231 uint32_t depListCount() const INLINE { return E::get32(fields.depListCount); }
232 void set_depListCount(uint32_t value) INLINE { E::set32(fields.depListCount, value); }
233
234 uint32_t rangeTableOffset() const INLINE { return E::get32(fields.rangeTableOffset); }
235 void set_rangeTableOffset(uint32_t value) INLINE { E::set32(fields.rangeTableOffset, value); }
236
237 uint32_t rangeTableCount() const INLINE { return E::get32(fields.rangeTableCount); }
238 void set_rangeTableCount(uint32_t value) INLINE { E::set32(fields.rangeTableCount, value); }
239
240 uint64_t dyldSectionAddr() const INLINE { return E::get64(fields.dyldSectionAddr); }
241 void set_dyldSectionAddr(uint64_t value) INLINE { E::set64(fields.dyldSectionAddr, value); }
242
243
244 private:
245 dyld_cache_accelerator_info fields;
246 };
247
248
249 template <typename E>
250 class dyldCacheAcceleratorInitializer {
251 public:
252 uint32_t functionOffset() const INLINE { return E::get32(fields.functionOffset); }
253 void set_functionOffset(uint32_t value) INLINE { E::set32(fields.functionOffset, value); }
254
255 uint32_t imageIndex() const INLINE { return E::get32(fields.imageIndex); }
256 void set_imageIndex(uint32_t value) INLINE { E::set32(fields.imageIndex, value); }
257
258 private:
259 dyld_cache_accelerator_initializer fields;
260 };
261
262
263 template <typename E>
264 class dyldCacheAcceleratorRangeEntry {
265 public:
266 uint64_t startAddress() const INLINE { return E::get64(fields.startAddress); }
267 void set_startAddress(uint64_t value) INLINE { E::set64(fields.startAddress, value); }
268
269 uint32_t size() const INLINE { return E::get32(fields.size); }
270 void set_size(uint32_t value) INLINE { E::set32(fields.size, value); }
271
272 uint32_t imageIndex() const INLINE { return E::get32(fields.imageIndex); }
273 void set_imageIndex(uint32_t value) INLINE { E::set32(fields.imageIndex, value); }
274
275 private:
276 dyld_cache_range_entry fields;
277 };
278
279 template <typename E>
280 class dyldCacheAcceleratorDOFEntry {
281 public:
282 uint64_t sectionAddress() const INLINE { return E::get64(fields.sectionAddress); }
283 void set_sectionAddress(uint64_t value) INLINE { E::set64(fields.sectionAddress, value); }
284
285 uint32_t sectionSize() const INLINE { return E::get32(fields.sectionSize); }
286 void set_sectionSize(uint32_t value) INLINE { E::set32(fields.sectionSize, value); }
287
288 uint32_t imageIndex() const INLINE { return E::get32(fields.imageIndex); }
289 void set_imageIndex(uint32_t value) INLINE { E::set32(fields.imageIndex, value); }
290
291 private:
292 dyld_cache_accelerator_dof fields;
293 };
294
295 template <typename E>
296 class dyldCacheSlideInfo {
297 public:
298 uint32_t version() const INLINE { return E::get32(fields.version); }
299 void set_version(uint32_t value) INLINE { E::set32(fields.version, value); }
300
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); }
303
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); }
306
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); }
309
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); }
312
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); }
315
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); }
318
319 private:
320 dyld_cache_slide_info fields;
321 };
322
323
324 struct dyldCacheSlideInfoEntry {
325 uint8_t bits[4096/(8*4)]; // 128-byte bitmap
326 };
327
328
329 template <typename E>
330 class dyldCacheSlideInfo2 {
331 public:
332 uint32_t version() const INLINE { return E::get32(fields.version); }
333 void set_version(uint32_t value) INLINE { E::set32(fields.version, value); }
334
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); }
337
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); }
340
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); }
343
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); }
346
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); }
349
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); }
352
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); }
355
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); }
358
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); }
361
362
363 private:
364 dyld_cache_slide_info2 fields;
365 };
366
367
368
369 template <typename E>
370 class dyldCacheLocalSymbolsInfo {
371 public:
372 uint32_t nlistOffset() const INLINE { return E::get32(fields.nlistOffset); }
373 void set_nlistOffset(uint32_t value) INLINE { E::set32(fields.nlistOffset, value); }
374
375 uint32_t nlistCount() const INLINE { return E::get32(fields.nlistCount); }
376 void set_nlistCount(uint32_t value) INLINE { E::set32(fields.nlistCount, value); }
377
378 uint32_t stringsOffset() const INLINE { return E::get32(fields.stringsOffset); }
379 void set_stringsOffset(uint32_t value) INLINE { E::set32(fields.stringsOffset, value); }
380
381 uint32_t stringsSize() const INLINE { return E::get32(fields.stringsSize); }
382 void set_stringsSize(uint32_t value) INLINE { E::set32(fields.stringsSize, value); }
383
384 uint32_t entriesOffset() const INLINE { return E::get32(fields.entriesOffset); }
385 void set_entriesOffset(uint32_t value) INLINE { E::set32(fields.entriesOffset, value); }
386
387 uint32_t entriesCount() const INLINE { return E::get32(fields.entriesCount); }
388 void set_entriesCount(uint32_t value) INLINE { E::set32(fields.entriesCount, value); }
389
390 private:
391 dyld_cache_local_symbols_info fields;
392 };
393
394
395 template <typename E>
396 class dyldCacheLocalSymbolEntry {
397 public:
398 uint32_t dylibOffset() const INLINE { return E::get32(fields.dylibOffset); }
399 void set_dylibOffset(uint32_t value) INLINE { E::set32(fields.dylibOffset, value); }
400
401 uint32_t nlistStartIndex() const INLINE { return E::get32(fields.nlistStartIndex); }
402 void set_nlistStartIndex(uint32_t value) INLINE { E::set32(fields.nlistStartIndex, value); }
403
404 uint32_t nlistCount() const INLINE { return E::get32(fields.nlistCount); }
405 void set_nlistCount(uint32_t value) INLINE { E::set32(fields.nlistCount, value); }
406
407 private:
408 dyld_cache_local_symbols_entry fields;
409 };
410
411
412
413
414 #endif // __DYLD_CACHE_ABSTRACTION__
415
416