Loading...
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 | /* * Copyright (c) 2008 Apple Inc. All rights reserved. * * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ * * This file contains Original Code and/or Modifications of Original Code * as defined in and that are subject to the Apple Public Source License * Version 2.0 (the 'License'). You may not use this file except in * compliance with the License. The rights granted to you under the License * may not be used to create, or enable the creation or redistribution of, * unlawful or unlicensed copies of an Apple operating system, or to * circumvent, violate, or enable the circumvention or violation of, any * terms of an Apple operating system software license agreement. * * Please obtain a copy of the License at * http://www.opensource.apple.com/apsl/ and read it before using this file. * * The Original Code and all software distributed under the License are * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. * Please see the License for the specific language governing rights and * limitations under the License. * * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ */ #ifndef _KXLD_SECT_H_ #define _KXLD_SECT_H_ #include <sys/types.h> #if KERNEL #include <libkern/kxld_types.h> #else #include "kxld_types.h" #endif #include "kxld_array.h" struct kxld_array; struct kxld_relocator; struct kxld_reloc; struct kxld_seg; struct kxld_symtab; struct relocation_info; struct section; struct section_64; typedef struct kxld_sect KXLDSect; struct kxld_sect { char sectname[16]; // The name of the section char segname[16]; // The segment to which the section belongs u_char *data; // The start of the section in memory KXLDArray relocs; // The section's relocation entries kxld_addr_t base_addr; // The base address of the section kxld_addr_t link_addr; // The relocated address of the section kxld_size_t size; // The size of the section u_int sectnum; // The number of the section (for relocation) u_int flags; // Flags describing the section u_int align; // The section's alignment as a power of 2 u_int reserved1; // Dependent on the section type u_int reserved2; // Dependent on the section type boolean_t allocated; // This section's data is allocated internally }; /******************************************************************************* * Constructors and destructors *******************************************************************************/ #if KXLD_USER_OR_ILP32 /* Initializes a section object from a Mach-O section header and modifies the * section offset to point to the next section header. */ kern_return_t kxld_sect_init_from_macho_32(KXLDSect *sect, u_char *macho, u_long *sect_offset, u_int sectnum, const struct kxld_relocator *relocator) __attribute__((nonnull, visibility("hidden"))); #endif /* KXLD_USER_OR_ILP32 */ #if KXLD_USER_OR_LP64 /* Initializes a section object from a Mach-O64 section header and modifies the * section offset to point to the next section header. */ kern_return_t kxld_sect_init_from_macho_64(KXLDSect *sect, u_char *macho, u_long *sect_offset, u_int sectnum, const struct kxld_relocator *relocator) __attribute__((nonnull, visibility("hidden"))); #endif /* KXLD_USER_OR_LP64 */ #if KXLD_USER_OR_GOT /* Initializes a GOT section from the number of entries that the section should * have. */ kern_return_t kxld_sect_init_got(KXLDSect *sect, u_int ngots) __attribute__((nonnull, visibility("hidden"))); #endif /* KXLD_USER_OR_GOT */ #if KXLD_USER_OR_COMMON /* Initializes a zerofill section of the specified size and alignment */ void kxld_sect_init_zerofill(KXLDSect *sect, const char *segname, const char *sectname, kxld_size_t size, u_int align) __attribute__((nonnull, visibility("hidden"))); #endif /* KXLD_USER_OR_COMMON */ /* Clears the section object */ void kxld_sect_clear(KXLDSect *sect) __attribute__((nonnull, visibility("hidden"))); /* Denitializes the section object and frees its array of relocs */ void kxld_sect_deinit(KXLDSect *sect) __attribute__((nonnull, visibility("hidden"))); /******************************************************************************* * Accessors *******************************************************************************/ /* Gets the number of relocation entries in the section */ u_int kxld_sect_get_num_relocs(const KXLDSect *sect) __attribute__((pure, nonnull, visibility("hidden"))); /* Returns the address parameter adjusted to the minimum alignment required by * the section. */ kxld_addr_t kxld_sect_align_address(const KXLDSect *sect, kxld_addr_t address) __attribute__((pure, nonnull, visibility("hidden"))); /* Returns the space required by the exported Mach-O header */ u_long kxld_sect_get_macho_header_size(boolean_t is_32_bit) __attribute__((const, visibility("hidden"))); /* Returns the space required by the exported Mach-O data */ u_long kxld_sect_get_macho_data_size(const KXLDSect *sect) __attribute__((pure, nonnull, visibility("hidden"))); #if KXLD_USER_OR_LP64 /* Returns the number of GOT entries required by relocation entries in the * given section. */ u_int kxld_sect_get_ngots(const KXLDSect *sect, const struct kxld_relocator *relocator, const struct kxld_symtab *symtab) __attribute__((pure, nonnull, visibility("hidden"))); #endif /* KXLD_USER_OR_LP64 */ kern_return_t kxld_sect_export_macho_to_file_buffer(const KXLDSect *sect, u_char *buf, u_long *header_offset, u_long header_size, u_long *data_offset, u_long data_size, boolean_t is_32_bit) __attribute__((nonnull, visibility("hidden"))); kern_return_t kxld_sect_export_macho_to_vm(const KXLDSect *sect, u_char *buf, u_long *header_offset, u_long header_size, kxld_addr_t link_addr, u_long data_size, boolean_t is_32_bit) __attribute__((nonnull, visibility("hidden"))); /******************************************************************************* * Mutators *******************************************************************************/ /* Relocates the section to the given link address */ void kxld_sect_relocate(KXLDSect *sect, kxld_addr_t link_addr) __attribute__((nonnull, visibility("hidden"))); #if KXLD_USER_OR_COMMON /* Adds a number of bytes to the section's size. Returns the size of the * section before it was grown. */ kxld_size_t kxld_sect_grow(KXLDSect *sect, kxld_size_t nbytes, u_int align) __attribute__((nonnull, visibility("hidden"))); #endif /* KXLD_USER_OR_COMMON */ #if KXLD_USER_OR_GOT /* Popluates the entries of a GOT section */ kern_return_t kxld_sect_populate_got(KXLDSect *sect, struct kxld_symtab *symtab, boolean_t swap) __attribute__((nonnull, visibility("hidden"))); #endif /* KXLD_USER_OR_GOT */ /* Processes all of a section's relocation entries */ kern_return_t kxld_sect_process_relocs(KXLDSect *sect, struct kxld_relocator *relocator) __attribute__((nonnull, visibility("hidden"))); #endif /* _KXLD_SECT_H_ */ |