]> git.saurik.com Git - apple/dyld.git/blame - launch-cache/CacheFileAbstraction.hpp
dyld-239.4.tar.gz
[apple/dyld.git] / launch-cache / CacheFileAbstraction.hpp
CommitLineData
bac542e6
A
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
32template <typename E>
33class dyldCacheHeader {
34public:
35 const char* magic() const INLINE { return fields.magic; }
36 void set_magic(const char* value) INLINE { memcpy(fields.magic, value, 16); }
37
bac542e6
A
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
412ebb8e
A
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); }
bac542e6 61
412ebb8e
A
62 uint64_t slideInfoSize() const INLINE { return E::get64(fields.slideInfoSize); }
63 void set_slideInfoSize(uint64_t value) INLINE { E::set64(fields.slideInfoSize, value); }
bac542e6 64
2fd3f4e8
A
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
bac542e6
A
74private:
75 dyld_cache_header fields;
76};
77
78
79template <typename E>
80class dyldCacheFileMapping {
81public:
412ebb8e
A
82 uint64_t address() const INLINE { return E::get64(fields.address); }
83 void set_address(uint64_t value) INLINE { E::set64(fields.address, value); }
bac542e6 84
412ebb8e
A
85 uint64_t size() const INLINE { return E::get64(fields.size); }
86 void set_size(uint64_t value) INLINE { E::set64(fields.size, value); }
bac542e6 87
412ebb8e
A
88 uint64_t file_offset() const INLINE { return E::get64(fields.fileOffset); }
89 void set_file_offset(uint64_t value) INLINE { E::set64(fields.fileOffset, value); }
bac542e6 90
412ebb8e
A
91 uint32_t max_prot() const INLINE { return E::get32(fields.maxProt); }
92 void set_max_prot(uint32_t value) INLINE { E::set32((uint32_t&)fields.maxProt, value); }
bac542e6 93
412ebb8e
A
94 uint32_t init_prot() const INLINE { return E::get32(fields.initProt); }
95 void set_init_prot(uint32_t value) INLINE { E::set32((uint32_t&)fields.initProt, value); }
bac542e6
A
96
97private:
412ebb8e 98 dyld_cache_mapping_info fields;
bac542e6
A
99};
100
101
102template <typename E>
103class dyldCacheImageInfo {
104public:
105 uint64_t address() const INLINE { return E::get64(fields.address); }
106 void set_address(uint64_t value) INLINE { E::set64(fields.address, value); }
107
108 uint64_t modTime() const INLINE { return E::get64(fields.modTime); }
109 void set_modTime(uint64_t value) INLINE { E::set64(fields.modTime, value); }
110
111 uint64_t inode() const INLINE { return E::get64(fields.inode); }
112 void set_inode(uint64_t value) INLINE { E::set64(fields.inode, value); }
113
114 uint32_t pathFileOffset() const INLINE { return E::get32(fields.pathFileOffset); }
115 void set_pathFileOffset(uint32_t value) INLINE { E::set32(fields.pathFileOffset, value); fields.pad=0; }
116
bac542e6
A
117private:
118 dyld_cache_image_info fields;
119};
120
412ebb8e
A
121template <typename E>
122class dyldCacheSlideInfo {
123public:
124 uint32_t version() const INLINE { return E::get32(fields.version); }
125 void set_version(uint32_t value) INLINE { E::set32(fields.version, value); }
126
127 uint32_t toc_offset() const INLINE { return E::get32(fields.toc_offset); }
128 void set_toc_offset(uint32_t value) INLINE { E::set32(fields.toc_offset, value); }
129
130 uint32_t toc_count() const INLINE { return E::get32(fields.toc_count); }
131 void set_toc_count(uint32_t value) INLINE { E::set32(fields.toc_count, value); }
132
133 uint32_t entries_offset() const INLINE { return E::get32(fields.entries_offset); }
134 void set_entries_offset(uint32_t value) INLINE { E::set32(fields.entries_offset, value); }
135
136 uint32_t entries_count() const INLINE { return E::get32(fields.entries_count); }
137 void set_entries_count(uint32_t value) INLINE { E::set32(fields.entries_count, value); }
138
139 uint32_t entries_size() const INLINE { return E::get32(fields.entries_size); }
140 void set_entries_size(uint32_t value) INLINE { E::set32(fields.entries_size, value); }
141
142 uint16_t toc(unsigned index) const INLINE { return E::get16(((uint16_t*)(((uint8_t*)this)+E::get16(fields.toc_offset)))[index]); }
143 void set_toc(unsigned index, uint16_t value) INLINE { return E::set16(((uint16_t*)(((uint8_t*)this)+E::get16(fields.toc_offset)))[index], value); }
144
145private:
146 dyld_cache_slide_info fields;
147};
148
149
150struct dyldCacheSlideInfoEntry {
151 uint8_t bits[4096/(8*4)]; // 128-byte bitmap
152};
153
bac542e6
A
154
155
2fd3f4e8
A
156template <typename E>
157class dyldCacheLocalSymbolsInfo {
158public:
159 uint32_t nlistOffset() const INLINE { return E::get32(fields.nlistOffset); }
160 void set_nlistOffset(uint32_t value) INLINE { E::set32(fields.nlistOffset, value); }
161
162 uint32_t nlistCount() const INLINE { return E::get32(fields.nlistCount); }
163 void set_nlistCount(uint32_t value) INLINE { E::set32(fields.nlistCount, value); }
164
165 uint32_t stringsOffset() const INLINE { return E::get32(fields.stringsOffset); }
166 void set_stringsOffset(uint32_t value) INLINE { E::set32(fields.stringsOffset, value); }
167
168 uint32_t stringsSize() const INLINE { return E::get32(fields.stringsSize); }
169 void set_stringsSize(uint32_t value) INLINE { E::set32(fields.stringsSize, value); }
170
171 uint32_t entriesOffset() const INLINE { return E::get32(fields.entriesOffset); }
172 void set_entriesOffset(uint32_t value) INLINE { E::set32(fields.entriesOffset, value); }
173
174 uint32_t entriesCount() const INLINE { return E::get32(fields.entriesCount); }
175 void set_entriesCount(uint32_t value) INLINE { E::set32(fields.entriesCount, value); }
176
177private:
178 dyld_cache_local_symbols_info fields;
179};
180
181
182template <typename E>
183class dyldCacheLocalSymbolEntry {
184public:
185 uint32_t dylibOffset() const INLINE { return E::get32(fields.dylibOffset); }
186 void set_dylibOffset(uint32_t value) INLINE { E::set32(fields.dylibOffset, value); }
187
188 uint32_t nlistStartIndex() const INLINE { return E::get32(fields.nlistStartIndex); }
189 void set_nlistStartIndex(uint32_t value) INLINE { E::set32(fields.nlistStartIndex, value); }
190
191 uint32_t nlistCount() const INLINE { return E::get32(fields.nlistCount); }
192 void set_nlistCount(uint32_t value) INLINE { E::set32(fields.nlistCount, value); }
193
194private:
195 dyld_cache_local_symbols_entry fields;
196};
197
198
199
200
bac542e6
A
201#endif // __DYLD_CACHE_ABSTRACTION__
202
203