dyld-732.8.tar.gz
[apple/dyld.git] / include / mach-o / fixup-chains.h
1 /* -*- mode: C++; c-basic-offset: 4; tab-width: 4 -*-
2 *
3 * Copyright (c) 2018 Apple 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
25 #ifndef __MACH_O_FIXUP_CHAINS__
26 #define __MACH_O_FIXUP_CHAINS__
27
28
29 #include <stdint.h>
30
31
32 //#define LC_DYLD_EXPORTS_TRIE 0x80000033 // used with linkedit_data_command
33 //#define LC_DYLD_CHAINED_FIXUPS 0x80000034 // used with linkedit_data_command, payload is dyld_chained_fixups_header
34
35
36 // header of the LC_DYLD_CHAINED_FIXUPS payload
37 struct dyld_chained_fixups_header
38 {
39 uint32_t fixups_version; // 0
40 uint32_t starts_offset; // offset of dyld_chained_starts_in_image in chain_data
41 uint32_t imports_offset; // offset of imports table in chain_data
42 uint32_t symbols_offset; // offset of symbol strings in chain_data
43 uint32_t imports_count; // number of imported symbol names
44 uint32_t imports_format; // DYLD_CHAINED_IMPORT*
45 uint32_t symbols_format; // 0 => uncompressed, 1 => zlib compressed
46 };
47
48 // This struct is embedded in LC_DYLD_CHAINED_FIXUPS payload
49 struct dyld_chained_starts_in_image
50 {
51 uint32_t seg_count;
52 uint32_t seg_info_offset[1]; // each entry is offset into this struct for that segment
53 // followed by pool of dyld_chain_starts_in_segment data
54 };
55
56 // This struct is embedded in dyld_chain_starts_in_image
57 // and passed down to the kernel for page-in linking
58 struct dyld_chained_starts_in_segment
59 {
60 uint32_t size; // size of this (amount kernel needs to copy)
61 uint16_t page_size; // 0x1000 or 0x4000
62 uint16_t pointer_format; // DYLD_CHAINED_PTR_*
63 uint64_t segment_offset; // offset in memory to start of segment
64 uint32_t max_valid_pointer; // for 32-bit OS, any value beyond this is not a pointer
65 uint16_t page_count; // how many pages are in array
66 uint16_t page_start[1]; // each entry is offset in each page of first element in chain
67 // or DYLD_CHAINED_PTR_START_NONE if no fixups on page
68 // uint16_t chain_starts[1]; // some 32-bit formats may require multiple starts per page.
69 // for those, if high bit is set in page_starts[], then it
70 // is index into chain_starts[] which is a list of starts
71 // the last of which has the high bit set
72 };
73
74 enum {
75 DYLD_CHAINED_PTR_START_NONE = 0xFFFF, // used in page_start[] to denote a page with no fixups
76 DYLD_CHAINED_PTR_START_MULTI = 0x8000, // used in page_start[] to denote a page which has multiple starts
77 DYLD_CHAINED_PTR_START_LAST = 0x8000, // used in chain_starts[] to denote last start in list for page
78 };
79
80 // This struct is embedded in __TEXT,__chain_starts section in firmware
81 struct dyld_chained_starts_offsets
82 {
83 uint32_t pointer_format; // DYLD_CHAINED_PTR_32_FIRMWARE
84 uint32_t starts_count; // number of starts in array
85 uint32_t chain_starts[1]; // array chain start offsets
86 };
87
88
89 // values for dyld_chained_starts_in_segment.pointer_format
90 enum {
91 DYLD_CHAINED_PTR_ARM64E = 1,
92 DYLD_CHAINED_PTR_64 = 2,
93 DYLD_CHAINED_PTR_32 = 3,
94 DYLD_CHAINED_PTR_32_CACHE = 4,
95 DYLD_CHAINED_PTR_32_FIRMWARE = 5,
96 };
97
98
99 // DYLD_CHAINED_PTR_ARM64E
100 struct dyld_chained_ptr_arm64e_rebase
101 {
102 uint64_t target : 43, // vmaddr
103 high8 : 8,
104 next : 11, // 8-byte stide
105 bind : 1, // == 0
106 auth : 1; // == 0
107 };
108
109 // DYLD_CHAINED_PTR_ARM64E
110 struct dyld_chained_ptr_arm64e_bind
111 {
112 uint64_t ordinal : 16,
113 zero : 16,
114 addend : 19,
115 next : 11, // 8-byte stide
116 bind : 1, // == 1
117 auth : 1; // == 0
118 };
119
120 // DYLD_CHAINED_PTR_ARM64E
121 struct dyld_chained_ptr_arm64e_auth_rebase
122 {
123 uint64_t target : 32, // runtimeOffset
124 diversity : 16,
125 addrDiv : 1,
126 key : 2,
127 next : 11, // 8-byte stide
128 bind : 1, // == 0
129 auth : 1; // == 1
130 };
131
132 // DYLD_CHAINED_PTR_ARM64E
133 struct dyld_chained_ptr_arm64e_auth_bind
134 {
135 uint64_t ordinal : 16,
136 zero : 16,
137 diversity : 16,
138 addrDiv : 1,
139 key : 2,
140 next : 11, // 8-byte stide
141 bind : 1, // == 1
142 auth : 1; // == 1
143 };
144
145 // DYLD_CHAINED_PTR_64
146 struct dyld_chained_ptr_64_rebase
147 {
148 uint64_t target : 36, // vmaddr, 64GB max image size
149 high8 : 8, // top 8 bits set to this after slide added
150 reserved : 7, // all zeros
151 next : 12, // 4-byte stride
152 bind : 1; // == 0
153 };
154
155 // DYLD_CHAINED_PTR_64
156 struct dyld_chained_ptr_64_bind
157 {
158 uint64_t ordinal : 24,
159 addend : 8, // 0 thru 255
160 reserved : 19, // all zeros
161 next : 12, // 4-byte stride
162 bind : 1; // == 1
163 };
164
165 // DYLD_CHAINED_PTR_32
166 // Note: for DYLD_CHAINED_PTR_32 some non-pointer values are co-opted into the chain
167 // as out of range rebases. If an entry in the chain is > max_valid_pointer, then it
168 // is not a pointer. To restore the value, subtract off the bias, which is
169 // (64MB+max_valid_pointer)/2.
170 struct dyld_chained_ptr_32_rebase
171 {
172 uint32_t target : 26, // vmaddr, 64MB max image size
173 next : 5, // 4-byte stride
174 bind : 1; // == 0
175 };
176
177 // DYLD_CHAINED_PTR_32
178 struct dyld_chained_ptr_32_bind
179 {
180 uint32_t ordinal : 20,
181 addend : 6, // 0 thru 63
182 next : 5, // 4-byte stride
183 bind : 1; // == 1
184 };
185
186 // DYLD_CHAINED_PTR_32_CACHE
187 struct dyld_chained_ptr_32_cache_rebase
188 {
189 uint32_t target : 30, // 1GB max dyld cache TEXT and DATA
190 next : 2; // 4-byte stride
191 };
192
193
194 // DYLD_CHAINED_PTR_32_FIRMWARE
195 struct dyld_chained_ptr_32_firmware_rebase
196 {
197 uint32_t target : 26, // 64MB max firmware TEXT and DATA
198 next : 6; // 4-byte stride
199 };
200
201
202
203 // values for dyld_chained_fixups_header.imports_format
204 enum {
205 DYLD_CHAINED_IMPORT = 1,
206 DYLD_CHAINED_IMPORT_ADDEND = 2,
207 DYLD_CHAINED_IMPORT_ADDEND64 = 3,
208 };
209
210 // DYLD_CHAINED_IMPORT
211 struct dyld_chained_import
212 {
213 uint32_t lib_ordinal : 8,
214 weak_import : 1,
215 name_offset : 23;
216 };
217
218 // DYLD_CHAINED_IMPORT_ADDEND
219 struct dyld_chained_import_addend
220 {
221 uint32_t lib_ordinal : 8,
222 weak_import : 1,
223 name_offset : 23;
224 int32_t addend;
225 };
226
227 // DYLD_CHAINED_IMPORT_ADDEND64
228 struct dyld_chained_import_addend64
229 {
230 uint64_t lib_ordinal : 16,
231 weak_import : 1,
232 reserved : 15,
233 name_offset : 32;
234 uint64_t addend;
235 };
236
237 #endif // __MACH_O_FIXUP_CHAINS__
238