]>
Commit | Line | Data |
---|---|---|
b0d623f7 A |
1 | /* |
2 | * Copyright (c) 2008 Apple Inc. All rights reserved. | |
3 | * | |
4 | * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ | |
0a7de745 | 5 | * |
b0d623f7 A |
6 | * This file contains Original Code and/or Modifications of Original Code |
7 | * as defined in and that are subject to the Apple Public Source License | |
8 | * Version 2.0 (the 'License'). You may not use this file except in | |
9 | * compliance with the License. The rights granted to you under the License | |
10 | * may not be used to create, or enable the creation or redistribution of, | |
11 | * unlawful or unlicensed copies of an Apple operating system, or to | |
12 | * circumvent, violate, or enable the circumvention or violation of, any | |
13 | * terms of an Apple operating system software license agreement. | |
0a7de745 | 14 | * |
b0d623f7 A |
15 | * Please obtain a copy of the License at |
16 | * http://www.opensource.apple.com/apsl/ and read it before using this file. | |
0a7de745 | 17 | * |
b0d623f7 A |
18 | * The Original Code and all software distributed under the License are |
19 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER | |
20 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, | |
21 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, | |
22 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. | |
23 | * Please see the License for the specific language governing rights and | |
24 | * limitations under the License. | |
0a7de745 | 25 | * |
b0d623f7 A |
26 | * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ |
27 | */ | |
28 | #ifndef _KXLD_SYMBOL_H_ | |
29 | #define _KXLD_SYMBOL_H_ | |
30 | ||
b0d623f7 A |
31 | #include <sys/types.h> |
32 | #if KERNEL | |
33 | #include <libkern/kxld_types.h> | |
34 | #else | |
35 | #include "kxld_types.h" | |
36 | #endif | |
37 | ||
38 | struct kxld_sect; | |
39 | struct nlist; | |
40 | struct nlist_64; | |
41 | typedef struct kxld_sym KXLDSym; | |
42 | typedef boolean_t (*KXLDSymPredicateTest)(const KXLDSym *sym); | |
43 | ||
44 | struct kxld_sym { | |
0a7de745 A |
45 | char *name; // The symbol's name |
46 | char *alias; // The indirect symbol's alias name | |
47 | kxld_addr_t base_addr; // The symbol's base address | |
48 | kxld_addr_t link_addr; // The relocated address | |
49 | kxld_addr_t got_addr; // The address of this symbol's GOT entry | |
50 | uint16_t desc; | |
51 | uint8_t type; | |
52 | uint8_t sectnum; // The symbol's section number | |
53 | uint8_t relocated_sectnum; | |
54 | u_int is_absolute:1, // Set for absolute symbols | |
55 | is_section:1, // Set for section symbols | |
56 | is_undefined:1, // Set for undefined symbols | |
57 | is_indirect:1, // Set for indirect symbols | |
58 | is_common:1, // Set for common symbols | |
59 | is_external:1, // Set for external symbols | |
60 | is_stab:1, // Set for stab symbols | |
61 | is_weak:1, // Set for weak definition symbols | |
62 | is_resolved:1, // For symbols that have been resolved | |
63 | // externally and should not be exported | |
64 | is_obsolete:1, // For symbols marked as obsolete | |
65 | is_replaced:1, // Set for symbols replaced by patching | |
66 | is_got:1, // Has an entry in the GOT | |
67 | is_cxx:1, // Set for C++ symbols | |
68 | is_pure_virtual:1, // Set for pure virtual symbols | |
69 | is_class_vtable:1, // Set for vtable symbols of classes | |
70 | is_meta_vtable:1, // Set for vtable symbols of MetaClasses | |
71 | is_padslot:1, // Set for pad slot symbols | |
72 | is_metaclass:1, // Set for metaclass symbols | |
73 | is_super_metaclass_pointer:1, // Set for super metaclass pointer syms | |
74 | is_thumb:1; // Set for thumb symbols (ARM only) | |
b0d623f7 A |
75 | }; |
76 | ||
77 | /******************************************************************************* | |
78 | * Constructors and destructors | |
79 | *******************************************************************************/ | |
80 | ||
81 | #if KXLD_USER_OR_ILP32 | |
0a7de745 | 82 | kern_return_t kxld_sym_init_from_macho32(KXLDSym *sym, char *strtab, |
b0d623f7 A |
83 | const struct nlist *src) __attribute__((nonnull, visibility("hidden"))); |
84 | #endif | |
85 | ||
86 | #if KXLD_USER_OR_LP64 | |
0a7de745 | 87 | kern_return_t kxld_sym_init_from_macho64(KXLDSym *sym, char *strtab, |
b0d623f7 A |
88 | const struct nlist_64 *src) __attribute__((nonnull, visibility("hidden"))); |
89 | #endif | |
90 | ||
91 | void kxld_sym_init_absolute(KXLDSym *sym, char *name, kxld_addr_t link_addr) | |
0a7de745 | 92 | __attribute__((nonnull, visibility("hidden"))); |
b0d623f7 A |
93 | |
94 | void kxld_sym_deinit(KXLDSym *sym) | |
0a7de745 | 95 | __attribute__((nonnull, visibility("hidden"))); |
b0d623f7 A |
96 | |
97 | void kxld_sym_destroy(KXLDSym *sym) | |
0a7de745 | 98 | __attribute__((nonnull, visibility("hidden"))); |
b0d623f7 A |
99 | |
100 | /******************************************************************************* | |
101 | * Accessors | |
102 | *******************************************************************************/ | |
103 | ||
104 | boolean_t kxld_sym_is_absolute(const KXLDSym *sym) | |
0a7de745 | 105 | __attribute__((pure, nonnull, visibility("hidden"))); |
b0d623f7 | 106 | |
0a7de745 A |
107 | boolean_t kxld_sym_is_section(const KXLDSym *sym) |
108 | __attribute__((pure, nonnull, visibility("hidden"))); | |
b0d623f7 A |
109 | |
110 | boolean_t kxld_sym_is_defined(const KXLDSym *sym) | |
0a7de745 | 111 | __attribute__((pure, nonnull, visibility("hidden"))); |
b0d623f7 A |
112 | |
113 | boolean_t kxld_sym_is_defined_locally(const KXLDSym *sym) | |
0a7de745 | 114 | __attribute__((pure, nonnull, visibility("hidden"))); |
b0d623f7 A |
115 | |
116 | boolean_t kxld_sym_is_external(const KXLDSym *sym) | |
0a7de745 | 117 | __attribute__((pure, nonnull, visibility("hidden"))); |
b0d623f7 A |
118 | |
119 | boolean_t kxld_sym_is_exported(const KXLDSym *sym) | |
0a7de745 | 120 | __attribute__((pure, nonnull, visibility("hidden"))); |
b0d623f7 A |
121 | |
122 | boolean_t kxld_sym_is_undefined(const KXLDSym *sym) | |
0a7de745 | 123 | __attribute__((pure, nonnull, visibility("hidden"))); |
b0d623f7 A |
124 | |
125 | boolean_t kxld_sym_is_indirect(const KXLDSym *sym) | |
0a7de745 | 126 | __attribute__((pure, nonnull, visibility("hidden"))); |
b0d623f7 | 127 | |
6d2010ae | 128 | boolean_t kxld_sym_is_replaced(const KXLDSym *sym) |
0a7de745 | 129 | __attribute__((pure, nonnull, visibility("hidden"))); |
6d2010ae | 130 | |
b0d623f7 A |
131 | /* We don't wrap this in KXLD_USER_OR_COMMON because even though common symbols |
132 | * aren't always supported, we always need to be able to detect them. | |
133 | */ | |
134 | boolean_t kxld_sym_is_common(const KXLDSym *sym) | |
0a7de745 | 135 | __attribute__((pure, nonnull, visibility("hidden"))); |
b0d623f7 A |
136 | |
137 | boolean_t kxld_sym_is_unresolved(const KXLDSym *sym) | |
0a7de745 | 138 | __attribute__((pure, nonnull, visibility("hidden"))); |
b0d623f7 A |
139 | |
140 | boolean_t kxld_sym_is_obsolete(const KXLDSym *sym) | |
0a7de745 | 141 | __attribute__((pure, nonnull, visibility("hidden"))); |
b0d623f7 A |
142 | |
143 | #if KXLD_USER_OR_GOT | |
144 | boolean_t kxld_sym_is_got(const KXLDSym *sym) | |
0a7de745 | 145 | __attribute__((pure, nonnull, visibility("hidden"))); |
b0d623f7 A |
146 | #endif /* KXLD_USER_OR_GOT */ |
147 | ||
148 | boolean_t kxld_sym_is_stab(const KXLDSym *sym) | |
0a7de745 | 149 | __attribute__((pure, nonnull, visibility("hidden"))); |
b0d623f7 A |
150 | |
151 | boolean_t kxld_sym_is_weak(const KXLDSym *sym) | |
0a7de745 | 152 | __attribute__((pure, nonnull, visibility("hidden"))); |
b0d623f7 A |
153 | |
154 | boolean_t kxld_sym_is_cxx(const KXLDSym *sym) | |
0a7de745 | 155 | __attribute__((pure, nonnull, visibility("hidden"))); |
b0d623f7 A |
156 | |
157 | boolean_t kxld_sym_is_pure_virtual(const KXLDSym *sym) | |
0a7de745 | 158 | __attribute__((pure, nonnull, visibility("hidden"))); |
b0d623f7 A |
159 | |
160 | boolean_t kxld_sym_is_vtable(const KXLDSym *sym) | |
0a7de745 | 161 | __attribute__((pure, nonnull, visibility("hidden"))); |
b0d623f7 A |
162 | |
163 | boolean_t kxld_sym_is_class_vtable(const KXLDSym *sym) | |
0a7de745 | 164 | __attribute__((pure, nonnull, visibility("hidden"))); |
b0d623f7 A |
165 | |
166 | boolean_t kxld_sym_is_metaclass_vtable(const KXLDSym *sym) | |
0a7de745 | 167 | __attribute__((pure, nonnull, visibility("hidden"))); |
b0d623f7 A |
168 | |
169 | boolean_t kxld_sym_is_padslot(const KXLDSym *sym) | |
0a7de745 | 170 | __attribute__((pure, nonnull, visibility("hidden"))); |
b0d623f7 A |
171 | |
172 | boolean_t kxld_sym_is_metaclass(const KXLDSym *sym) | |
0a7de745 | 173 | __attribute__((pure, nonnull, visibility("hidden"))); |
b0d623f7 A |
174 | |
175 | boolean_t kxld_sym_is_super_metaclass_pointer(const KXLDSym *sym) | |
0a7de745 | 176 | __attribute__((pure, nonnull, visibility("hidden"))); |
b0d623f7 | 177 | |
6d2010ae | 178 | boolean_t kxld_sym_name_is_pure_virtual(const char *name) |
0a7de745 | 179 | __attribute__((pure, nonnull, visibility("hidden"))); |
6d2010ae | 180 | |
b0d623f7 | 181 | boolean_t kxld_sym_name_is_padslot(const char *name) |
0a7de745 | 182 | __attribute__((pure, nonnull, visibility("hidden"))); |
b0d623f7 | 183 | |
0a7de745 | 184 | u_int kxld_sym_get_section_offset(const KXLDSym *sym, |
b0d623f7 | 185 | const struct kxld_sect *sect) |
0a7de745 | 186 | __attribute__((pure, nonnull, visibility("hidden"))); |
b0d623f7 A |
187 | |
188 | #if KXLD_USER_OR_COMMON | |
189 | kxld_size_t kxld_sym_get_common_size(const KXLDSym *sym) | |
0a7de745 | 190 | __attribute__((pure, nonnull, visibility("hidden"))); |
b0d623f7 A |
191 | |
192 | u_int kxld_sym_get_common_align(const KXLDSym *sym) | |
0a7de745 | 193 | __attribute__((pure, nonnull, visibility("hidden"))); |
b0d623f7 A |
194 | #endif /* KXLD_USER_OR_COMMON */ |
195 | ||
196 | kern_return_t kxld_sym_get_class_name_from_metaclass(const KXLDSym *sym, | |
197 | char class_name[], u_long class_name_len) | |
0a7de745 | 198 | __attribute__((nonnull, visibility("hidden"))); |
b0d623f7 A |
199 | |
200 | kern_return_t kxld_sym_get_class_name_from_super_metaclass_pointer( | |
0a7de745 A |
201 | const KXLDSym *sym, char class_name[], u_long class_name_len) |
202 | __attribute__((nonnull, visibility("hidden"))); | |
b0d623f7 A |
203 | |
204 | kern_return_t kxld_sym_get_class_name_from_vtable(const KXLDSym *sym, | |
205 | char class_name[], u_long class_name_len) | |
0a7de745 | 206 | __attribute__((nonnull, visibility("hidden"))); |
b0d623f7 A |
207 | |
208 | kern_return_t kxld_sym_get_class_name_from_vtable_name(const char *vtable_name, | |
209 | char class_name[], u_long class_name_len) | |
0a7de745 | 210 | __attribute__((nonnull, visibility("hidden"))); |
b0d623f7 | 211 | |
0a7de745 | 212 | kern_return_t kxld_sym_get_vtable_name_from_class_name(const char *class_name, |
b0d623f7 | 213 | char vtable_name[], u_long vtable_name_len) |
0a7de745 | 214 | __attribute__((nonnull, visibility("hidden"))); |
b0d623f7 | 215 | |
0a7de745 | 216 | kern_return_t kxld_sym_get_meta_vtable_name_from_class_name(const char *class_name, |
b0d623f7 | 217 | char meta_vtable_name[], u_long meta_vtable_name_len) |
0a7de745 | 218 | __attribute__((nonnull, visibility("hidden"))); |
b0d623f7 | 219 | |
0a7de745 | 220 | kern_return_t kxld_sym_get_final_sym_name_from_class_name(const char *class_name, |
b0d623f7 | 221 | char final_sym_name[], u_long final_sym_name_len) |
0a7de745 | 222 | __attribute__((nonnull, visibility("hidden"))); |
b0d623f7 A |
223 | |
224 | u_long kxld_sym_get_function_prefix_from_class_name(const char *class_name, | |
225 | char function_prefix[], u_long function_prefix_len) | |
0a7de745 | 226 | __attribute__((nonnull, visibility("hidden"))); |
b0d623f7 A |
227 | |
228 | #if KXLD_USER_OR_ILP32 | |
0a7de745 | 229 | kern_return_t kxld_sym_export_macho_32(const KXLDSym *sym, u_char *nl, |
6d2010ae | 230 | char *strtab, u_long *stroff, u_long strsize) |
0a7de745 | 231 | __attribute__((nonnull, visibility("hidden"))); |
b0d623f7 A |
232 | #endif |
233 | ||
234 | #if KXLD_USER_OR_LP64 | |
0a7de745 | 235 | kern_return_t kxld_sym_export_macho_64(const KXLDSym *sym, u_char *nl, |
6d2010ae | 236 | char *strtab, u_long *stroff, u_long strsize) |
0a7de745 | 237 | __attribute__((nonnull, visibility("hidden"))); |
b0d623f7 A |
238 | #endif |
239 | ||
240 | /******************************************************************************* | |
241 | * Mutators | |
242 | *******************************************************************************/ | |
243 | ||
244 | void kxld_sym_relocate(KXLDSym *sym, const struct kxld_sect *sect) | |
0a7de745 | 245 | __attribute__((nonnull, visibility("hidden"))); |
b0d623f7 A |
246 | |
247 | #if KXLD_USER_OR_GOT | |
248 | void kxld_sym_set_got(KXLDSym *sym) | |
0a7de745 | 249 | __attribute__((nonnull, visibility("hidden"))); |
b0d623f7 A |
250 | #endif /* KXLD_USER_OR_GOT */ |
251 | ||
6d2010ae | 252 | kern_return_t kxld_sym_resolve(KXLDSym *sym, const kxld_addr_t addr) |
0a7de745 | 253 | __attribute__((nonnull, visibility("hidden"))); |
b0d623f7 A |
254 | |
255 | #if KXLD_USER_OR_COMMON | |
0a7de745 | 256 | kern_return_t kxld_sym_resolve_common(KXLDSym *sym, u_int sectnum, |
b0d623f7 | 257 | kxld_addr_t base_addr) |
0a7de745 | 258 | __attribute__((nonnull, visibility("hidden"))); |
b0d623f7 A |
259 | #endif /* KXLD_USER_OR_COMMON */ |
260 | ||
261 | void kxld_sym_delete(KXLDSym *sym) | |
0a7de745 A |
262 | __attribute__((nonnull, visibility("hidden"))); |
263 | ||
b0d623f7 | 264 | void kxld_sym_patch(KXLDSym *sym) |
0a7de745 | 265 | __attribute__((nonnull, visibility("hidden"))); |
b0d623f7 A |
266 | |
267 | void kxld_sym_mark_private(KXLDSym *sym) | |
0a7de745 | 268 | __attribute__((nonnull, visibility("hidden"))); |
b0d623f7 A |
269 | |
270 | #endif /* _KXLD_SYMBOL_H_ */ |