]>
git.saurik.com Git - apple/xnu.git/blob - libkern/kxld/kxld_sect.h
2 * Copyright (c) 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 <sys/types.h>
33 #include <libkern/kxld_types.h>
35 #include "kxld_types.h"
38 #include "kxld_array.h"
41 struct kxld_relocator
;
45 struct relocation_info
;
48 typedef struct kxld_sect KXLDSect
;
51 char sectname
[16]; // The name of the section
52 char segname
[16]; // The segment to which the section belongs
53 u_char
*data
; // The start of the section in memory
54 KXLDArray relocs
; // The section's relocation entries
55 kxld_addr_t base_addr
; // The base address of the section
56 kxld_addr_t link_addr
; // The relocated address of the section
57 kxld_size_t size
; // The size of the section
58 u_int sectnum
; // The number of the section (for relocation)
59 u_int flags
; // Flags describing the section
60 u_int align
; // The section's alignment as a power of 2
61 u_int reserved1
; // Dependent on the section type
62 u_int reserved2
; // Dependent on the section type
63 boolean_t allocated
; // This section's data is allocated internally
66 /*******************************************************************************
67 * Constructors and destructors
68 *******************************************************************************/
70 #if KXLD_USER_OR_ILP32
71 /* Initializes a section object from a Mach-O section header and modifies the
72 * section offset to point to the next section header.
74 kern_return_t
kxld_sect_init_from_macho_32(KXLDSect
*sect
, u_char
*macho
,
75 u_long
*sect_offset
, u_int sectnum
, const struct kxld_relocator
*relocator
)
76 __attribute__((nonnull
, visibility("hidden")));
77 #endif /* KXLD_USER_OR_ILP32 */
80 /* Initializes a section object from a Mach-O64 section header and modifies the
81 * section offset to point to the next section header.
83 kern_return_t
kxld_sect_init_from_macho_64(KXLDSect
*sect
, u_char
*macho
,
84 u_long
*sect_offset
, u_int sectnum
, const struct kxld_relocator
*relocator
)
85 __attribute__((nonnull
, visibility("hidden")));
86 #endif /* KXLD_USER_OR_LP64 */
89 /* Initializes a GOT section from the number of entries that the section should
92 kern_return_t
kxld_sect_init_got(KXLDSect
*sect
, u_int ngots
)
93 __attribute__((nonnull
, visibility("hidden")));
94 #endif /* KXLD_USER_OR_GOT */
96 #if KXLD_USER_OR_COMMON
97 /* Initializes a zerofill section of the specified size and alignment */
98 void kxld_sect_init_zerofill(KXLDSect
*sect
, const char *segname
,
99 const char *sectname
, kxld_size_t size
, u_int align
)
100 __attribute__((nonnull
, visibility("hidden")));
101 #endif /* KXLD_USER_OR_COMMON */
103 /* Clears the section object */
104 void kxld_sect_clear(KXLDSect
*sect
)
105 __attribute__((nonnull
, visibility("hidden")));
107 /* Denitializes the section object and frees its array of relocs */
108 void kxld_sect_deinit(KXLDSect
*sect
)
109 __attribute__((nonnull
, visibility("hidden")));
111 /*******************************************************************************
113 *******************************************************************************/
115 /* Gets the number of relocation entries in the section */
116 u_int
kxld_sect_get_num_relocs(const KXLDSect
*sect
)
117 __attribute__((pure
, nonnull
, visibility("hidden")));
119 /* Returns the address parameter adjusted to the minimum alignment required by
122 kxld_addr_t
kxld_sect_align_address(const KXLDSect
*sect
, kxld_addr_t address
)
123 __attribute__((pure
, nonnull
, visibility("hidden")));
125 /* Returns the space required by the exported Mach-O header */
126 u_long
kxld_sect_get_macho_header_size(boolean_t is_32_bit
)
127 __attribute__((const, visibility("hidden")));
129 /* Returns the space required by the exported Mach-O data */
130 u_long
kxld_sect_get_macho_data_size(const KXLDSect
*sect
)
131 __attribute__((pure
, nonnull
, visibility("hidden")));
133 #if KXLD_USER_OR_LP64
134 /* Returns the number of GOT entries required by relocation entries in the
137 u_int
kxld_sect_get_ngots(const KXLDSect
*sect
,
138 const struct kxld_relocator
*relocator
, const struct kxld_symtab
*symtab
)
139 __attribute__((pure
, nonnull
, visibility("hidden")));
140 #endif /* KXLD_USER_OR_LP64 */
142 kern_return_t
kxld_sect_export_macho_to_file_buffer(const KXLDSect
*sect
, u_char
*buf
,
143 u_long
*header_offset
, u_long header_size
, u_long
*data_offset
,
144 u_long data_size
, boolean_t is_32_bit
)
145 __attribute__((nonnull
, visibility("hidden")));
147 kern_return_t
kxld_sect_export_macho_to_vm(const KXLDSect
*sect
, u_char
*buf
,
148 u_long
*header_offset
,
150 kxld_addr_t link_addr
,
153 __attribute__((nonnull
, visibility("hidden")));
155 /*******************************************************************************
157 *******************************************************************************/
159 /* Relocates the section to the given link address */
160 void kxld_sect_relocate(KXLDSect
*sect
, kxld_addr_t link_addr
)
161 __attribute__((nonnull
, visibility("hidden")));
163 #if KXLD_USER_OR_COMMON
164 /* Adds a number of bytes to the section's size. Returns the size of the
165 * section before it was grown.
167 kxld_size_t
kxld_sect_grow(KXLDSect
*sect
, kxld_size_t nbytes
, u_int align
)
168 __attribute__((nonnull
, visibility("hidden")));
169 #endif /* KXLD_USER_OR_COMMON */
172 /* Popluates the entries of a GOT section */
173 kern_return_t
kxld_sect_populate_got(KXLDSect
*sect
, struct kxld_symtab
*symtab
,
175 __attribute__((nonnull
, visibility("hidden")));
176 #endif /* KXLD_USER_OR_GOT */
178 /* Processes all of a section's relocation entries */
179 kern_return_t
kxld_sect_process_relocs(KXLDSect
*sect
,
180 struct kxld_relocator
*relocator
)
181 __attribute__((nonnull
, visibility("hidden")));
183 #endif /* _KXLD_SECT_H_ */