]>
Commit | Line | Data |
---|---|---|
b0d623f7 A |
1 | /* |
2 | * Copyright (c) 2007-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_RELOC_H | |
29 | #define _KXLD_RELOC_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_array; | |
6d2010ae A |
40 | struct kxld_dict; |
41 | struct kxld_sect; | |
42 | struct kxld_seg; | |
b0d623f7 A |
43 | struct kxld_sym; |
44 | struct kxld_symtab; | |
6d2010ae A |
45 | struct kxld_vtable; |
46 | struct relocation_info; | |
47 | ||
b0d623f7 A |
48 | typedef struct kxld_relocator KXLDRelocator; |
49 | typedef struct kxld_reloc KXLDReloc; | |
50 | ||
51 | typedef boolean_t (*RelocHasPair)(u_int r_type); | |
316670eb | 52 | typedef u_int (*RelocGetPairType)(u_int prev_r_type); |
b0d623f7 | 53 | typedef boolean_t (*RelocHasGot)(u_int r_type); |
0a7de745 A |
54 | typedef kern_return_t (*ProcessReloc)(const KXLDRelocator *relocator, |
55 | u_char *instruction, u_int length, u_int pcrel, kxld_addr_t base_pc, | |
56 | kxld_addr_t link_pc, kxld_addr_t link_disp, u_int type, | |
b0d623f7 A |
57 | kxld_addr_t target, kxld_addr_t pair_target, boolean_t swap); |
58 | ||
59 | struct kxld_relocator { | |
0a7de745 A |
60 | RelocHasPair reloc_has_pair; |
61 | RelocGetPairType reloc_get_pair_type; | |
62 | RelocHasGot reloc_has_got; | |
63 | ProcessReloc process_reloc; | |
64 | const struct kxld_symtab *symtab; | |
65 | const struct kxld_array *sectarray; | |
66 | const struct kxld_dict *vtables; | |
67 | const struct kxld_vtable *current_vtable; | |
68 | u_char *file; | |
69 | u_int function_align; /* Power of two alignment of functions */ | |
70 | boolean_t is_32_bit; | |
71 | boolean_t swap; | |
72 | boolean_t may_scatter; | |
b0d623f7 A |
73 | }; |
74 | ||
75 | struct kxld_reloc { | |
0a7de745 A |
76 | u_int address; |
77 | u_int pair_address; | |
78 | u_int target; | |
79 | u_int pair_target; | |
80 | u_int target_type:3; | |
81 | u_int pair_target_type:3; | |
82 | u_int reloc_type:4; | |
83 | u_int length:2; | |
84 | u_int pcrel:1; | |
b0d623f7 A |
85 | }; |
86 | ||
b0d623f7 A |
87 | /******************************************************************************* |
88 | * Constructors and Destructors | |
89 | *******************************************************************************/ | |
6d2010ae | 90 | kern_return_t kxld_relocator_init(KXLDRelocator *relocator, u_char *file, |
0a7de745 | 91 | const struct kxld_symtab *symtab, const struct kxld_array *sectarray, |
6d2010ae | 92 | cpu_type_t cputype, cpu_subtype_t cpusubtype, boolean_t swap) |
0a7de745 | 93 | __attribute__((nonnull, visibility("hidden"))); |
b0d623f7 A |
94 | |
95 | kern_return_t kxld_reloc_create_macho(struct kxld_array *relocarray, | |
0a7de745 | 96 | const KXLDRelocator *relocator, const struct relocation_info *srcs, |
b0d623f7 A |
97 | u_int nsrcs) __attribute__((nonnull, visibility("hidden"))); |
98 | ||
99 | void kxld_relocator_clear(KXLDRelocator *relocator) | |
0a7de745 | 100 | __attribute__((nonnull, visibility("hidden"))); |
b0d623f7 A |
101 | |
102 | /******************************************************************************* | |
103 | * Accessors | |
104 | *******************************************************************************/ | |
105 | ||
106 | boolean_t kxld_relocator_has_pair(const KXLDRelocator *relocator, u_int r_type) | |
0a7de745 | 107 | __attribute__((pure, nonnull, visibility("hidden"))); |
b0d623f7 | 108 | |
316670eb | 109 | u_int kxld_relocator_get_pair_type(const KXLDRelocator *relocator, |
b0d623f7 | 110 | u_int last_r_type) |
0a7de745 | 111 | __attribute__((pure, nonnull, visibility("hidden"))); |
b0d623f7 A |
112 | |
113 | boolean_t kxld_relocator_has_got(const KXLDRelocator *relocator, u_int r_type) | |
0a7de745 | 114 | __attribute__((pure, nonnull, visibility("hidden"))); |
b0d623f7 | 115 | |
6d2010ae A |
116 | kxld_addr_t kxld_relocator_get_pointer_at_addr(const KXLDRelocator *relocator, |
117 | const u_char *data, u_long offset) | |
0a7de745 | 118 | __attribute__((pure, nonnull, visibility("hidden"))); |
6d2010ae | 119 | |
b0d623f7 | 120 | struct kxld_sym * kxld_reloc_get_symbol(const KXLDRelocator *relocator, |
6d2010ae | 121 | const KXLDReloc *reloc, const u_char *data) |
0a7de745 | 122 | __attribute__((pure, nonnull(1, 2), visibility("hidden"))); |
b0d623f7 | 123 | |
0a7de745 | 124 | kern_return_t kxld_reloc_get_reloc_index_by_offset(const struct kxld_array *relocs, |
b0d623f7 | 125 | kxld_size_t offset, u_int *idx) |
0a7de745 | 126 | __attribute__((nonnull, visibility("hidden"))); |
b0d623f7 | 127 | |
0a7de745 | 128 | KXLDReloc * kxld_reloc_get_reloc_by_offset(const struct kxld_array *relocs, |
b0d623f7 | 129 | kxld_addr_t offset) |
0a7de745 | 130 | __attribute__((pure, nonnull, visibility("hidden"))); |
b0d623f7 | 131 | |
316670eb A |
132 | #if KXLD_PIC_KEXTS |
133 | u_long kxld_reloc_get_macho_header_size(void) | |
0a7de745 | 134 | __attribute__((pure, visibility("hidden"))); |
316670eb A |
135 | |
136 | u_long kxld_reloc_get_macho_data_size(const struct kxld_array *locrelocs, | |
137 | const struct kxld_array *extrelocs) | |
0a7de745 | 138 | __attribute__((pure, nonnull, visibility("hidden"))); |
316670eb A |
139 | |
140 | kern_return_t kxld_reloc_export_macho(const KXLDRelocator *relocator, | |
141 | const struct kxld_array *locrelocs, const struct kxld_array *extrelocs, | |
0a7de745 | 142 | u_char *buf, u_long *header_offset, u_long header_size, |
316670eb | 143 | u_long *data_offset, u_long size) |
0a7de745 | 144 | __attribute__((nonnull, visibility("hidden"))); |
316670eb A |
145 | #endif /* KXLD_PIC_KEXTS */ |
146 | ||
b0d623f7 A |
147 | /******************************************************************************* |
148 | * Modifiers | |
149 | *******************************************************************************/ | |
150 | ||
151 | kern_return_t kxld_reloc_update_symindex(KXLDReloc *reloc, u_int symindex) | |
0a7de745 | 152 | __attribute__((nonnull, visibility("hidden"))); |
b0d623f7 | 153 | |
0a7de745 | 154 | void kxld_relocator_set_vtables(KXLDRelocator *relocator, |
6d2010ae | 155 | const struct kxld_dict *vtables) |
0a7de745 | 156 | __attribute__((nonnull, visibility("hidden"))); |
6d2010ae A |
157 | |
158 | kern_return_t kxld_relocator_process_sect_reloc(KXLDRelocator *relocator, | |
159 | const KXLDReloc *reloc, const struct kxld_sect *sect) | |
0a7de745 | 160 | __attribute__((nonnull, visibility("hidden"))); |
b0d623f7 | 161 | |
6d2010ae | 162 | kern_return_t kxld_relocator_process_table_reloc(KXLDRelocator *relocator, |
0a7de745 A |
163 | const KXLDReloc *reloc, |
164 | const struct kxld_seg *seg, | |
165 | kxld_addr_t link_addr) | |
166 | __attribute__((nonnull, visibility("hidden"))); | |
b0d623f7 A |
167 | |
168 | #endif /* _KXLD_RELOC_H */ |