]> git.saurik.com Git - apple/xnu.git/blob - libkern/kxld/kxld_sect.h
xnu-1456.1.26.tar.gz
[apple/xnu.git] / libkern / kxld / kxld_sect.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_SECT_H_
29 #define _KXLD_SECT_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 #include "kxld_array.h"
40
41 struct kxld_array;
42 struct kxld_relocator;
43 struct kxld_reloc;
44 struct kxld_seg;
45 struct kxld_symtab;
46 struct relocation_info;
47 struct section;
48 struct section_64;
49 typedef struct kxld_sect KXLDSect;
50
51 struct kxld_sect {
52 char sectname[16]; // The name of the section
53 char segname[16]; // The segment to which the section belongs
54 u_char *data; // The start of the section in memory
55 KXLDArray relocs; // The section's relocation entries
56 kxld_addr_t base_addr; // The base address of the section
57 kxld_addr_t link_addr; // The relocated address of the section
58 kxld_size_t size; // The size of the section
59 u_int sectnum; // The number of the section (for relocation)
60 u_int flags; // Flags describing the section
61 u_int align; // The section's alignment as a power of 2
62 u_int reserved1; // Dependent on the section type
63 u_int reserved2; // Dependent on the section type
64 boolean_t allocated; // This section's data is allocated internally
65 };
66
67 /*******************************************************************************
68 * Constructors and destructors
69 *******************************************************************************/
70
71 #if KXLD_USER_OR_ILP32
72 /* Initializes a section object from a Mach-O section header and modifies the
73 * section offset to point to the next section header.
74 */
75 kern_return_t kxld_sect_init_from_macho_32(KXLDSect *sect, u_char *macho,
76 u_long *sect_offset, u_int sectnum, const struct kxld_relocator *relocator)
77 __attribute__((nonnull, visibility("hidden")));
78 #endif /* KXLD_USER_OR_ILP32 */
79
80 #if KXLD_USER_OR_LP64
81 /* Initializes a section object from a Mach-O64 section header and modifies the
82 * section offset to point to the next section header.
83 */
84 kern_return_t kxld_sect_init_from_macho_64(KXLDSect *sect, u_char *macho,
85 u_long *sect_offset, u_int sectnum, const struct kxld_relocator *relocator)
86 __attribute__((nonnull, visibility("hidden")));
87 #endif /* KXLD_USER_OR_LP64 */
88
89 #if KXLD_USER_OR_GOT
90 /* Initializes a GOT section from the number of entries that the section should
91 * have.
92 */
93 kern_return_t kxld_sect_init_got(KXLDSect *sect, u_int ngots)
94 __attribute__((nonnull, visibility("hidden")));
95 #endif /* KXLD_USER_OR_GOT */
96
97 #if KXLD_USER_OR_COMMON
98 /* Initializes a zerofill section of the specified size and alignment */
99 void kxld_sect_init_zerofill(KXLDSect *sect, const char *segname,
100 const char *sectname, kxld_size_t size, u_int align)
101 __attribute__((nonnull, visibility("hidden")));
102 #endif /* KXLD_USER_OR_COMMON */
103
104 /* Clears the section object */
105 void kxld_sect_clear(KXLDSect *sect)
106 __attribute__((nonnull, visibility("hidden")));
107
108 /* Denitializes the section object and frees its array of relocs */
109 void kxld_sect_deinit(KXLDSect *sect)
110 __attribute__((nonnull, visibility("hidden")));
111
112 /*******************************************************************************
113 * Accessors
114 *******************************************************************************/
115
116 /* Gets the number of relocation entries in the section */
117 u_int kxld_sect_get_num_relocs(const KXLDSect *sect)
118 __attribute__((pure, nonnull, visibility("hidden")));
119
120 /* Returns the address parameter adjusted to the minimum alignment required by
121 * the section.
122 */
123 kxld_addr_t kxld_sect_align_address(const KXLDSect *sect, kxld_addr_t address)
124 __attribute__((pure, nonnull, visibility("hidden")));
125
126 /* Returns the space required by the exported Mach-O header */
127 u_long kxld_sect_get_macho_header_size(boolean_t is_32_bit)
128 __attribute__((const, nonnull, visibility("hidden")));
129
130 /* Returns the space required by the exported Mach-O data */
131 u_long kxld_sect_get_macho_data_size(const KXLDSect *sect)
132 __attribute__((pure, nonnull, visibility("hidden")));
133
134 #if KXLD_USER_OR_LP64
135 /* Returns the number of GOT entries required by relocation entries in the
136 * given section.
137 */
138 u_int kxld_sect_get_ngots(const KXLDSect *sect,
139 const struct kxld_relocator *relocator, const struct kxld_symtab *symtab)
140 __attribute__((pure, nonnull, visibility("hidden")));
141 #endif /* KXLD_USER_OR_LP64 */
142
143 kern_return_t kxld_sect_export_macho_to_file_buffer(const KXLDSect *sect, u_char *buf,
144 u_long *header_offset, u_long header_size, u_long *data_offset,
145 u_long data_size, boolean_t is_32_bit)
146 __attribute__((nonnull, visibility("hidden")));
147
148 kern_return_t kxld_sect_export_macho_to_vm(const KXLDSect *sect, u_char *buf,
149 u_long *header_offset, u_long header_size,
150 kxld_addr_t link_addr, u_long data_size,
151 boolean_t is_32_bit)
152 __attribute__((nonnull, visibility("hidden")));
153
154 /*******************************************************************************
155 * Mutators
156 *******************************************************************************/
157
158 /* Relocates the section to the given link address */
159 void kxld_sect_relocate(KXLDSect *sect, kxld_addr_t link_addr)
160 __attribute__((nonnull, visibility("hidden")));
161
162 #if KXLD_USER_OR_COMMON
163 /* Adds a number of bytes to the section's size. Returns the size of the
164 * section before it was grown.
165 */
166 kxld_size_t kxld_sect_grow(KXLDSect *sect, kxld_size_t nbytes, u_int align)
167 __attribute__((nonnull, visibility("hidden")));
168 #endif /* KXLD_USER_OR_COMMON */
169
170 #if KXLD_USER_OR_GOT
171 /* Popluates the entries of a GOT section */
172 kern_return_t kxld_sect_populate_got(KXLDSect *sect, struct kxld_symtab *symtab,
173 boolean_t swap)
174 __attribute__((nonnull, visibility("hidden")));
175 #endif /* KXLD_USER_OR_GOT */
176
177 /* Processes all of a section's relocation entries */
178 kern_return_t kxld_sect_process_relocs(KXLDSect *sect,
179 const struct kxld_relocator *relocator, const KXLDArray *sectarray,
180 const struct kxld_symtab *symtab)
181 __attribute__((nonnull, visibility("hidden")));
182
183 #endif /* _KXLD_SECT_H_ */
184