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