2 * Copyright (c) 2007-2008 Apple Inc. All rights reserved.
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
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.
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
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.
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
31 #include <mach/machine.h>
32 #include <sys/types.h>
34 #include <libkern/kxld_types.h>
36 #include "kxld_types.h"
46 struct relocation_info
;
48 typedef struct kxld_relocator KXLDRelocator
;
49 typedef struct kxld_reloc KXLDReloc
;
51 typedef boolean_t (*RelocHasPair
)(u_int r_type
);
52 typedef boolean_t (*RelocIsPair
)(u_int r_type
, u_int prev_r_type
);
53 typedef boolean_t (*RelocHasGot
)(u_int r_type
);
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
,
57 kxld_addr_t target
, kxld_addr_t pair_target
, boolean_t swap
);
59 struct kxld_relocator
{
60 RelocHasPair reloc_has_pair
;
61 RelocIsPair reloc_is_pair
;
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
;
69 u_int function_align
; /* Power of two alignment of functions */
79 u_int pair_target_type
:3;
85 /*******************************************************************************
86 * Constructors and Destructors
87 *******************************************************************************/
88 kern_return_t
kxld_relocator_init(KXLDRelocator
*relocator
, u_char
*file
,
89 const struct kxld_symtab
*symtab
, const struct kxld_array
*sectarray
,
90 cpu_type_t cputype
, cpu_subtype_t cpusubtype
, boolean_t swap
)
91 __attribute__((nonnull
,visibility("hidden")));
93 kern_return_t
kxld_reloc_create_macho(struct kxld_array
*relocarray
,
94 const KXLDRelocator
*relocator
, const struct relocation_info
*srcs
,
95 u_int nsrcs
) __attribute__((nonnull
, visibility("hidden")));
97 void kxld_relocator_clear(KXLDRelocator
*relocator
)
98 __attribute__((nonnull
, visibility("hidden")));
100 /*******************************************************************************
102 *******************************************************************************/
104 boolean_t
kxld_relocator_has_pair(const KXLDRelocator
*relocator
, u_int r_type
)
105 __attribute__((pure
, nonnull
,visibility("hidden")));
107 boolean_t
kxld_relocator_is_pair(const KXLDRelocator
*relocator
, u_int r_type
,
109 __attribute__((pure
, nonnull
,visibility("hidden")));
111 boolean_t
kxld_relocator_has_got(const KXLDRelocator
*relocator
, u_int r_type
)
112 __attribute__((pure
, nonnull
,visibility("hidden")));
114 kxld_addr_t
kxld_relocator_get_pointer_at_addr(const KXLDRelocator
*relocator
,
115 const u_char
*data
, u_long offset
)
116 __attribute__((pure
, nonnull
,visibility("hidden")));
118 struct kxld_sym
* kxld_reloc_get_symbol(const KXLDRelocator
*relocator
,
119 const KXLDReloc
*reloc
, const u_char
*data
)
120 __attribute__((pure
, nonnull(1,2), visibility("hidden")));
122 kern_return_t
kxld_reloc_get_reloc_index_by_offset(const struct kxld_array
*relocs
,
123 kxld_size_t offset
, u_int
*idx
)
124 __attribute__((nonnull
, visibility("hidden")));
126 KXLDReloc
* kxld_reloc_get_reloc_by_offset(const struct kxld_array
*relocs
,
128 __attribute__((pure
, nonnull
, visibility("hidden")));
130 /*******************************************************************************
132 *******************************************************************************/
134 kern_return_t
kxld_reloc_update_symindex(KXLDReloc
*reloc
, u_int symindex
)
135 __attribute__((nonnull
,visibility("hidden")));
137 void kxld_relocator_set_vtables(KXLDRelocator
*relocator
,
138 const struct kxld_dict
*vtables
)
139 __attribute__((nonnull
,visibility("hidden")));
141 kern_return_t
kxld_relocator_process_sect_reloc(KXLDRelocator
*relocator
,
142 const KXLDReloc
*reloc
, const struct kxld_sect
*sect
)
143 __attribute__((nonnull
,visibility("hidden")));
145 kern_return_t
kxld_relocator_process_table_reloc(KXLDRelocator
*relocator
,
146 const KXLDReloc
*reloc
, const struct kxld_seg
*seg
, kxld_addr_t link_addr
)
147 __attribute__((nonnull
,visibility("hidden")));
149 #endif /* _KXLD_RELOC_H */