]> git.saurik.com Git - apple/xnu.git/blame - libkern/kxld/kxld_reloc.h
xnu-1504.7.4.tar.gz
[apple/xnu.git] / libkern / kxld / kxld_reloc.h
CommitLineData
b0d623f7
A
1/*
2 * Copyright (c) 2007-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_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
39struct kxld_array;
40struct kxld_sym;
41struct kxld_symtab;
42typedef struct kxld_relocator KXLDRelocator;
43typedef struct kxld_reloc KXLDReloc;
44
45typedef boolean_t (*RelocHasPair)(u_int r_type);
46typedef boolean_t (*RelocIsPair)(u_int r_type, u_int prev_r_type);
47typedef boolean_t (*RelocHasGot)(u_int r_type);
48typedef kern_return_t(*ProcessReloc)(u_char *instruction, u_int length, u_int pcrel,
49 kxld_addr_t base_pc, kxld_addr_t link_pc, kxld_addr_t link_disp, u_int type,
50 kxld_addr_t target, kxld_addr_t pair_target, boolean_t swap);
51
52struct kxld_relocator {
53 RelocHasPair reloc_has_pair;
54 RelocIsPair reloc_is_pair;
55 RelocHasGot reloc_has_got;
56 ProcessReloc process_reloc;
57 boolean_t is_32_bit;
58 boolean_t swap;
59};
60
61struct kxld_reloc {
62 u_int address;
63 u_int target;
64 u_int pair_target;
65 u_int target_type:3;
66 u_int pair_target_type:3;
67 u_int reloc_type:4;
68 u_int length:2;
69 u_int pcrel:1;
70};
71
72struct kxld_array;
73struct kxld_sect;
74struct kxld_seg;
75struct kxld_symtab;
76struct relocation_info;
77
78/*******************************************************************************
79* Constructors and Destructors
80*******************************************************************************/
81
82kern_return_t kxld_relocator_init(KXLDRelocator *relocator, cpu_type_t cputype,
83 cpu_subtype_t cpusubtype, boolean_t swap)
84 __attribute__((nonnull,visibility("hidden")));
85
86kern_return_t kxld_reloc_create_macho(struct kxld_array *relocarray,
87 const KXLDRelocator *relocator, const struct relocation_info *srcs,
88 u_int nsrcs) __attribute__((nonnull, visibility("hidden")));
89
90void kxld_relocator_clear(KXLDRelocator *relocator)
91 __attribute__((nonnull, visibility("hidden")));
92
93/*******************************************************************************
94* Accessors
95*******************************************************************************/
96
97boolean_t kxld_relocator_has_pair(const KXLDRelocator *relocator, u_int r_type)
98 __attribute__((pure, nonnull,visibility("hidden")));
99
100boolean_t kxld_relocator_is_pair(const KXLDRelocator *relocator, u_int r_type,
101 u_int last_r_type)
102 __attribute__((pure, nonnull,visibility("hidden")));
103
104boolean_t kxld_relocator_has_got(const KXLDRelocator *relocator, u_int r_type)
105 __attribute__((pure, nonnull,visibility("hidden")));
106
107struct kxld_sym * kxld_reloc_get_symbol(const KXLDRelocator *relocator,
108 const KXLDReloc *reloc, u_char *data,
109 const struct kxld_symtab *symtab)
110 __attribute__((pure, nonnull(1,2,4), visibility("hidden")));
111
112kern_return_t kxld_reloc_get_reloc_index_by_offset(const struct kxld_array *relocs,
113 kxld_size_t offset, u_int *idx)
114 __attribute__((nonnull, visibility("hidden")));
115
116KXLDReloc * kxld_reloc_get_reloc_by_offset(const struct kxld_array *relocs,
117 kxld_addr_t offset)
118 __attribute__((pure, nonnull, visibility("hidden")));
119
120/*******************************************************************************
121* Modifiers
122*******************************************************************************/
123
124kern_return_t kxld_reloc_update_symindex(KXLDReloc *reloc, u_int symindex)
125 __attribute__((nonnull,visibility("hidden")));
126
127kern_return_t kxld_relocator_process_sect_reloc(const KXLDRelocator *relocator,
128 const KXLDReloc *reloc, const struct kxld_sect *sect,
129 const struct kxld_array *sectarray, const struct kxld_symtab *symtab)
130 __attribute__((nonnull,visibility("hidden")));
131
132kern_return_t kxld_relocator_process_table_reloc(const KXLDRelocator *relocator,
133 const KXLDReloc *reloc, const struct kxld_seg *seg, u_char *file,
134 const struct kxld_array *sectarray,
135 const struct kxld_symtab *symtab)
136 __attribute__((nonnull,visibility("hidden")));
137
138#endif /* _KXLD_RELOC_H */
139