]>
Commit | Line | Data |
---|---|---|
b0d623f7 A |
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_SEG_H_ | |
29 | #define _KXLD_SEG_H_ | |
30 | ||
31 | #include <mach/vm_prot.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 | #include "kxld_array.h" | |
40 | ||
41 | struct kxld_sect; | |
6d2010ae | 42 | struct kxld_symtab; |
b0d623f7 A |
43 | struct segment_command; |
44 | struct segment_command_64; | |
45 | typedef struct kxld_seg KXLDSeg; | |
46 | ||
47 | struct kxld_seg { | |
48 | char segname[16]; | |
49 | kxld_addr_t base_addr; | |
50 | kxld_addr_t link_addr; | |
51 | kxld_size_t vmsize; | |
52 | kxld_size_t fileoff; | |
53 | KXLDArray sects; | |
54 | u_int flags; | |
55 | vm_prot_t maxprot; | |
56 | vm_prot_t initprot; | |
57 | }; | |
58 | ||
59 | /******************************************************************************* | |
60 | * Constructors and Destructors | |
61 | *******************************************************************************/ | |
62 | ||
63 | #if KXLD_USER_OR_ILP32 | |
64 | kern_return_t kxld_seg_init_from_macho_32(KXLDSeg *seg, struct segment_command *src) | |
65 | __attribute__((nonnull, visibility("hidden"))); | |
66 | #endif /* KXLD_USER_OR_ILP32 */ | |
67 | ||
68 | #if KXLD_USER_OR_LP64 | |
69 | kern_return_t kxld_seg_init_from_macho_64(KXLDSeg *seg, struct segment_command_64 *src) | |
70 | __attribute__((nonnull, visibility("hidden"))); | |
71 | #endif /* KXLD_USER_OR_LP64 */ | |
72 | ||
73 | #if KXLD_USER_OR_OBJECT | |
74 | kern_return_t kxld_seg_create_seg_from_sections(KXLDArray *segarray, | |
75 | KXLDArray *sectarray) | |
76 | __attribute__((nonnull, visibility("hidden"))); | |
77 | ||
78 | kern_return_t kxld_seg_finalize_object_segment(KXLDArray *segarray, | |
79 | KXLDArray *section_order, u_long hdrsize) | |
80 | __attribute__((nonnull, visibility("hidden"))); | |
6d2010ae A |
81 | |
82 | kern_return_t kxld_seg_init_linkedit(KXLDArray *segs) | |
83 | __attribute__((nonnull, visibility("hidden"))); | |
b0d623f7 A |
84 | #endif /* KXLD_USER_OR_OBJECT */ |
85 | ||
86 | void kxld_seg_clear(KXLDSeg *seg) | |
87 | __attribute__((nonnull, visibility("hidden"))); | |
88 | ||
89 | void kxld_seg_deinit(KXLDSeg *seg) | |
90 | __attribute__((nonnull, visibility("hidden"))); | |
91 | ||
92 | ||
93 | /******************************************************************************* | |
94 | * Accessors | |
95 | *******************************************************************************/ | |
96 | ||
97 | kxld_size_t kxld_seg_get_vmsize(const KXLDSeg *seg) | |
98 | __attribute__((pure, nonnull, visibility("hidden"))); | |
99 | ||
100 | u_long kxld_seg_get_macho_header_size(const KXLDSeg *seg, boolean_t is_32_bit) | |
101 | __attribute__((pure, nonnull, visibility("hidden"))); | |
102 | ||
316670eb A |
103 | #if 0 |
104 | /* This is no longer used, but may be useful some day... */ | |
b0d623f7 A |
105 | u_long kxld_seg_get_macho_data_size(const KXLDSeg *seg) |
106 | __attribute__((pure, nonnull, visibility("hidden"))); | |
316670eb | 107 | #endif |
b0d623f7 A |
108 | |
109 | kern_return_t | |
110 | kxld_seg_export_macho_to_file_buffer(const KXLDSeg *seg, u_char *buf, | |
111 | u_long *header_offset, u_long header_size, | |
112 | u_long *data_offset, u_long data_size, | |
113 | boolean_t is_32_bit) | |
114 | __attribute__((nonnull, visibility("hidden"))); | |
115 | ||
116 | kern_return_t | |
39037602 A |
117 | kxld_seg_export_macho_to_vm(const KXLDSeg *seg, |
118 | u_char *buf, | |
119 | u_long *header_offset, | |
120 | u_long header_size, | |
121 | u_long data_size, | |
122 | kxld_addr_t file_link_addr, | |
123 | boolean_t is_32_bit) | |
124 | __attribute__((nonnull, visibility("hidden"))); | |
b0d623f7 A |
125 | |
126 | /******************************************************************************* | |
127 | * Modifiers | |
128 | *******************************************************************************/ | |
129 | ||
130 | kern_return_t kxld_seg_add_section(KXLDSeg *seg, struct kxld_sect *sect) | |
131 | __attribute__((nonnull, visibility("hidden"))); | |
132 | ||
133 | /* To be called after all sections are added */ | |
134 | kern_return_t kxld_seg_finish_init(KXLDSeg *seg) | |
135 | __attribute__((nonnull, visibility("hidden"))); | |
136 | ||
137 | void kxld_seg_set_vm_protections(KXLDSeg *seg, boolean_t strict_protections) | |
138 | __attribute__((nonnull, visibility("hidden"))); | |
139 | ||
6d2010ae | 140 | void kxld_seg_relocate(KXLDSeg *seg, kxld_addr_t link_addr) |
39037602 | 141 | __attribute__((nonnull, visibility("hidden"))); |
6d2010ae | 142 | |
316670eb A |
143 | void kxld_seg_populate_linkedit(KXLDSeg *seg, const struct kxld_symtab *symtab, |
144 | boolean_t is_32_bit | |
145 | #if KXLD_PIC_KEXTS | |
146 | , const struct kxld_array *locrelocs | |
147 | , const struct kxld_array *extrelocs | |
148 | , boolean_t target_supports_slideable_kexts | |
149 | #endif /* KXLD_PIC_KEXTS */ | |
39037602 | 150 | , uint32_t splitinfolc_size |
316670eb | 151 | ) |
b0d623f7 A |
152 | __attribute__((nonnull, visibility("hidden"))); |
153 | ||
39037602 A |
154 | boolean_t kxld_seg_is_split_seg(const KXLDSeg *seg) |
155 | __attribute__((pure, nonnull, visibility("hidden"))); | |
156 | ||
157 | boolean_t kxld_seg_is_text_seg(const KXLDSeg *seg) | |
158 | __attribute__((pure, nonnull, visibility("hidden"))); | |
159 | ||
160 | boolean_t kxld_seg_is_text_exec_seg(const KXLDSeg *seg) | |
161 | __attribute__((pure, nonnull, visibility("hidden"))); | |
162 | ||
163 | boolean_t kxld_seg_is_data_seg(const KXLDSeg *seg) | |
164 | __attribute__((pure, nonnull, visibility("hidden"))); | |
165 | ||
166 | boolean_t kxld_seg_is_data_const_seg(const KXLDSeg *seg) | |
167 | __attribute__((pure, nonnull, visibility("hidden"))); | |
168 | ||
169 | boolean_t kxld_seg_is_linkedit_seg(const KXLDSeg *seg) | |
170 | __attribute__((pure, nonnull, visibility("hidden"))); | |
171 | ||
813fb2f6 A |
172 | boolean_t kxld_seg_is_llvm_cov_seg(const KXLDSeg *seg) |
173 | __attribute__((pure, nonnull, visibility("hidden"))); | |
39037602 | 174 | |
b0d623f7 A |
175 | #endif /* _KXLD_SEG_H_ */ |
176 |