1 /* 2 * Copyright (c) 2009, 2012 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_OBJECT_H_ 29 #define _KXLD_OBJECT_H_ 30 31 #include <sys/types.h> 32 #if KERNEL 33 #include <libkern/kxld_types.h> 34 #else 35 #include "kxld_types.h" 36 #endif 37 38 struct kxld_array; 39 struct kxld_dict; 40 struct kxld_reloc; 41 struct kxld_relocator; 42 struct kxld_sect; 43 struct kxld_sym; 44 struct kxld_symtab; 45 46 typedef struct kxld_object KXLDObject; 47 48 /******************************************************************************* 49 * Constructors and destructors 50 *******************************************************************************/ 51 52 size_t kxld_object_sizeof(void) 53 __attribute__((const, visibility("hidden"))); 54 55 kern_return_t kxld_object_init_from_macho(KXLDObject *object, 56 u_char *file, u_long size, const char *name, 57 struct kxld_array *section_order, 58 cpu_type_t cputype, cpu_subtype_t cpusubtype, KXLDFlags flags) 59 __attribute__((nonnull(1, 2, 4), visibility("hidden"))); 60 61 void kxld_object_clear(KXLDObject *object) 62 __attribute__((nonnull, visibility("hidden"))); 63 64 void kxld_object_deinit(KXLDObject *object) 65 __attribute__((nonnull, visibility("hidden"))); 66 67 /******************************************************************************* 68 * Accessors 69 *******************************************************************************/ 70 71 const u_char * kxld_object_get_file(const KXLDObject *object) 72 __attribute__((pure, nonnull, visibility("hidden"))); 73 74 const char * kxld_object_get_name(const KXLDObject *object) 75 __attribute__((pure, nonnull, visibility("hidden"))); 76 77 boolean_t kxld_object_is_32_bit(const KXLDObject *object) 78 __attribute__((pure, nonnull, visibility("hidden"))); 79 80 boolean_t kxld_object_is_final_image(const KXLDObject *object) 81 __attribute__((pure, nonnull, visibility("hidden"))); 82 83 boolean_t kxld_object_is_kernel(const KXLDObject *object) 84 __attribute__((pure, nonnull, visibility("hidden"))); 85 86 boolean_t kxld_object_is_linked(const KXLDObject *object) 87 __attribute__((pure, nonnull, visibility("hidden"))); 88 89 boolean_t kxld_object_target_supports_strict_patching(const KXLDObject *object) 90 __attribute__((pure, nonnull, visibility("hidden"))); 91 92 boolean_t kxld_object_target_supports_common_symbols(const KXLDObject *object) 93 __attribute__((pure, nonnull, visibility("hidden"))); 94 95 const struct kxld_relocator * kxld_object_get_relocator( 96 const KXLDObject * object) 97 __attribute__((pure, nonnull, visibility("hidden"))); 98 99 const struct kxld_reloc * kxld_object_get_reloc_at_symbol( 100 const KXLDObject *object, const struct kxld_sym *sym) 101 __attribute__((pure, nonnull, visibility("hidden"))); 102 103 const struct kxld_sym * kxld_object_get_symbol_of_reloc( 104 const KXLDObject *object, const struct kxld_reloc *reloc, 105 const struct kxld_sect *sect) 106 __attribute__((pure, nonnull, visibility("hidden"))); 107 108 const struct kxld_sect * kxld_object_get_section_by_index( 109 const KXLDObject *object, u_int sectnum) 110 __attribute__((pure, nonnull, visibility("hidden"))); 111 112 const struct kxld_array * kxld_object_get_extrelocs( 113 const KXLDObject *object) 114 __attribute__((pure, nonnull, visibility("hidden"))); 115 116 const struct kxld_symtab * kxld_object_get_symtab(const KXLDObject *object) 117 __attribute__((pure, nonnull, visibility("hidden"))); 118 119 void kxld_object_get_vmsize(const KXLDObject *object, u_long *header_size, 120 u_long *vmsize) 121 __attribute__((nonnull, visibility("hidden"))); 122 123 void kxld_object_set_linked_object_size(KXLDObject *object, u_long vmsize) 124 __attribute__((nonnull, visibility("hidden"))); 125 126 void kxld_object_get_vmsize_for_seg_by_name(const KXLDObject *object, 127 const char *segname, 128 u_long *vmsize) 129 __attribute__((nonnull, visibility("hidden"))); 130 131 splitKextLinkInfo * kxld_object_get_link_info(KXLDObject *object) 132 __attribute__((nonnull, visibility("hidden"))); 133 134 void kxld_object_set_link_info(KXLDObject *object, 135 splitKextLinkInfo *link_info) 136 __attribute__((nonnull, visibility("hidden"))); 137 138 139 /* This will be the same size as kxld_kext_get_vmsize */ 140 kern_return_t kxld_object_export_linked_object(const KXLDObject *object, 141 void *linked_object 142 ) 143 __attribute__((nonnull, visibility("hidden"))); 144 145 146 /******************************************************************************* 147 * Modifiers 148 *******************************************************************************/ 149 150 kern_return_t kxld_object_index_symbols_by_name(KXLDObject *object) 151 __attribute__((nonnull, visibility("hidden"))); 152 153 kern_return_t kxld_object_index_cxx_symbols_by_value(KXLDObject *object) 154 __attribute__((nonnull, visibility("hidden"))); 155 156 kern_return_t kxld_object_relocate(KXLDObject *object, kxld_addr_t link_address) 157 __attribute__((nonnull, visibility("hidden"))); 158 159 kern_return_t kxld_object_resolve_symbol(KXLDObject *object, 160 const struct kxld_sym *sym, kxld_addr_t addr) 161 __attribute__((nonnull, visibility("hidden"))); 162 163 kern_return_t kxld_object_patch_symbol(KXLDObject *object, 164 const struct kxld_sym *sym) 165 __attribute__((nonnull, visibility("hidden"))); 166 167 kern_return_t kxld_object_add_symbol(KXLDObject *object, char *name, 168 kxld_addr_t link_addr, const struct kxld_sym **sym_out) 169 __attribute__((nonnull, visibility("hidden"))); 170 171 kern_return_t kxld_object_process_relocations(KXLDObject *object, 172 const struct kxld_dict *patched_vtables) 173 __attribute__((nonnull, visibility("hidden"))); 174 175 #endif /* _KXLD_OBJECT_H_ */ 176