# HG changeset patch # User taiki # Date 1358779296 -32400 # Node ID 30ba02c504a05060f412989523fcc47f186af55a # Parent 479240de2d64496ebf153aec602170eeeeb46d6b delete .h files. diff -r 479240de2d64 -r 30ba02c504a0 boot/arch.h --- a/boot/arch.h Tue Jan 22 02:47:24 2013 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,105 +0,0 @@ -/* - * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. - * - * @APPLE_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. 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_LICENSE_HEADER_END@ - */ -#ifndef _MACH_O_ARCH_H_ -#define _MACH_O_ARCH_H_ -/* - * Copyright (c) 1997 Apple Computer, Inc. - * - * Functions that deal with information about architectures. - * - */ - -#include -#include -#include - -/* The NXArchInfo structs contain the architectures symbolic name - * (such as "ppc"), its CPU type and CPU subtype as defined in - * mach/machine.h, the byte order for the architecture, and a - * describing string (such as "PowerPC"). - * There will both be entries for specific CPUs (such as ppc604e) as - * well as generic "family" entries (such as ppc). - */ -typedef struct { - const char *name; - cpu_type_t cputype; - cpu_subtype_t cpusubtype; - enum NXByteOrder byteorder; - const char *description; -} NXArchInfo; - -#if __cplusplus -extern "C" { -#endif /* __cplusplus */ - -/* NXGetAllArchInfos() returns a pointer to an array of all known - * NXArchInfo structures. The last NXArchInfo is marked by a NULL name. - */ -extern const NXArchInfo *NXGetAllArchInfos(void); - -/* NXGetLocalArchInfo() returns the NXArchInfo for the local host, or NULL - * if none is known. - */ -extern const NXArchInfo *NXGetLocalArchInfo(void); - -/* NXGetArchInfoFromName() and NXGetArchInfoFromCpuType() return the - * NXArchInfo from the architecture's name or cputype/cpusubtype - * combination. A cpusubtype of CPU_SUBTYPE_MULTIPLE can be used - * to request the most general NXArchInfo known for the given cputype. - * NULL is returned if no matching NXArchInfo can be found. - */ -extern const NXArchInfo *NXGetArchInfoFromName(const char *name); -extern const NXArchInfo *NXGetArchInfoFromCpuType(cpu_type_t cputype, - cpu_subtype_t cpusubtype); - -/* NXFindBestFatArch() is passed a cputype and cpusubtype and a set of - * fat_arch structs and selects the best one that matches (if any) and returns - * a pointer to that fat_arch struct (or NULL). The fat_arch structs must be - * in the host byte order and correct such that the fat_archs really points to - * enough memory for nfat_arch structs. It is possible that this routine could - * fail if new cputypes or cpusubtypes are added and an old version of this - * routine is used. But if there is an exact match between the cputype and - * cpusubtype and one of the fat_arch structs this routine will always succeed. - */ -extern struct fat_arch *NXFindBestFatArch(cpu_type_t cputype, - cpu_subtype_t cpusubtype, - struct fat_arch *fat_archs, - uint32_t nfat_archs); - -/* NXCombineCpuSubtypes() returns the resulting cpusubtype when combining two - * different cpusubtypes for the specified cputype. If the two cpusubtypes - * can't be combined (the specific subtypes are mutually exclusive) -1 is - * returned indicating it is an error to combine them. This can also fail and - * return -1 if new cputypes or cpusubtypes are added and an old version of - * this routine is used. But if the cpusubtypes are the same they can always - * be combined and this routine will return the cpusubtype pass in. - */ -extern cpu_subtype_t NXCombineCpuSubtypes(cpu_type_t cputype, - cpu_subtype_t cpusubtype1, - cpu_subtype_t cpusubtype2); - -#if __cplusplus -} -#endif /* __cplusplus */ - -#endif /* _MACH_O_ARCH_H_ */ diff -r 479240de2d64 -r 30ba02c504a0 boot/compact_unwind_encoding.h --- a/boot/compact_unwind_encoding.h Tue Jan 22 02:47:24 2013 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,428 +0,0 @@ -/* -*- mode: C; c-basic-offset: 4; tab-width: 4 -*- - * - * Copyright (c) 2008-2011 Apple Inc. All rights reserved. - * - * @APPLE_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. 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_LICENSE_HEADER_END@ - */ - - -#ifndef __COMPACT_UNWIND_ENCODING__ -#define __COMPACT_UNWIND_ENCODING__ - -#include - - - -// -// Compilers can emit standard Dwarf FDEs in the __TEXT,__eh_frame section -// of object files. Or compilers can emit compact unwind information in -// the __LD,__compact_unwind section. -// -// When the linker creates a final linked image, it will create a -// __TEXT,__unwind_info section. This section is a small and fast way for the -// runtime to access unwind info for any given function. If the compiler emitted -// compact unwind info for the function, that compact unwind info will be encoded -// in the __TEXT,__unwind_info section. If the compiler emitted dwarf unwind info, -// the __TEXT,__unwind_info section will contain the offset of the FDE in the -// __TEXT,__eh_frame section in the final linked image. -// -// Note: Previously, the linker would transform some dwarf unwind infos into -// compact unwind info. But that is fragile and no longer done. - - -// -// The compact unwind endoding is a 32-bit value which encoded in an architecture -// specific way, which registers to restore from where, and how to unwind out -// of the function. -// -typedef uint32_t compact_unwind_encoding_t; - - -// architecture independent bits -enum { - UNWIND_IS_NOT_FUNCTION_START = 0x80000000, - UNWIND_HAS_LSDA = 0x40000000, - UNWIND_PERSONALITY_MASK = 0x30000000, -}; - - - - -// -// x86 -// -// 1-bit: start -// 1-bit: has lsda -// 2-bit: personality index -// -// 4-bits: 0=old, 1=ebp based, 2=stack-imm, 3=stack-ind, 4=dwarf -// ebp based: -// 15-bits (5*3-bits per reg) register permutation -// 8-bits for stack offset -// frameless: -// 8-bits stack size -// 3-bits stack adjust -// 3-bits register count -// 10-bits register permutation -// -enum { - UNWIND_X86_MODE_MASK = 0x0F000000, - UNWIND_X86_MODE_EBP_FRAME = 0x01000000, - UNWIND_X86_MODE_STACK_IMMD = 0x02000000, - UNWIND_X86_MODE_STACK_IND = 0x03000000, - UNWIND_X86_MODE_DWARF = 0x04000000, - - UNWIND_X86_EBP_FRAME_REGISTERS = 0x00007FFF, - UNWIND_X86_EBP_FRAME_OFFSET = 0x00FF0000, - - UNWIND_X86_FRAMELESS_STACK_SIZE = 0x00FF0000, - UNWIND_X86_FRAMELESS_STACK_ADJUST = 0x0000E000, - UNWIND_X86_FRAMELESS_STACK_REG_COUNT = 0x00001C00, - UNWIND_X86_FRAMELESS_STACK_REG_PERMUTATION = 0x000003FF, - - UNWIND_X86_DWARF_SECTION_OFFSET = 0x00FFFFFF, -}; - -enum { - UNWIND_X86_REG_NONE = 0, - UNWIND_X86_REG_EBX = 1, - UNWIND_X86_REG_ECX = 2, - UNWIND_X86_REG_EDX = 3, - UNWIND_X86_REG_EDI = 4, - UNWIND_X86_REG_ESI = 5, - UNWIND_X86_REG_EBP = 6, -}; - -// -// For x86 there are four modes for the compact unwind encoding: -// UNWIND_X86_MODE_EBP_FRAME: -// EBP based frame where EBP is push on stack immediately after return address, -// then ESP is moved to EBP. Thus, to unwind ESP is restored with the current -// EPB value, then EBP is restored by popping off the stack, and the return -// is done by popping the stack once more into the pc. -// All non-volatile registers that need to be restored must have been saved -// in a small range in the stack that starts EBP-4 to EBP-1020. The offset/4 -// is encoded in the UNWIND_X86_EBP_FRAME_OFFSET bits. The registers saved -// are encoded in the UNWIND_X86_EBP_FRAME_REGISTERS bits as five 3-bit entries. -// Each entry contains which register to restore. -// UNWIND_X86_MODE_STACK_IMMD: -// A "frameless" (EBP not used as frame pointer) function with a small -// constant stack size. To return, a constant (encoded in the compact -// unwind encoding) is added to the ESP. Then the return is done by -// popping the stack into the pc. -// All non-volatile registers that need to be restored must have been saved -// on the stack immediately after the return address. The stack_size/4 is -// encoded in the UNWIND_X86_FRAMELESS_STACK_SIZE (max stack size is 1024). -// The number of registers saved is encoded in UNWIND_X86_FRAMELESS_STACK_REG_COUNT. -// UNWIND_X86_FRAMELESS_STACK_REG_PERMUTATION constains which registers were -// saved and their order. -// UNWIND_X86_MODE_STACK_IND: -// A "frameless" (EBP not used as frame pointer) function large constant -// stack size. This case is like the previous, except the stack size is too -// large to encode in the compact unwind encoding. Instead it requires that -// the function contains "subl $nnnnnnnn,ESP" in its prolog. The compact -// encoding contains the offset to the nnnnnnnn value in the function in -// UNWIND_X86_FRAMELESS_STACK_SIZE. -// UNWIND_X86_MODE_DWARF: -// No compact unwind encoding is available. Instead the low 24-bits of the -// compact encoding is the offset of the dwarf FDE in the __eh_frame section. -// This mode is never used in object files. It is only generated by the -// linker in final linked images which have only dwarf unwind info for a -// function. -// -// The following is the algorithm used to create the permutation encoding used -// with frameless stacks. It is passed the number of registers to be saved and -// an array of the register numbers saved. -// -//uint32_t permute_encode(uint32_t registerCount, const uint32_t registers[6]) -//{ -// uint32_t renumregs[6]; -// for (int i=6-registerCount; i < 6; ++i) { -// int countless = 0; -// for (int j=6-registerCount; j < i; ++j) { -// if ( registers[j] < registers[i] ) -// ++countless; -// } -// renumregs[i] = registers[i] - countless -1; -// } -// uint32_t permutationEncoding = 0; -// switch ( registerCount ) { -// case 6: -// permutationEncoding |= (120*renumregs[0] + 24*renumregs[1] -// + 6*renumregs[2] + 2*renumregs[3] -// + renumregs[4]); -// break; -// case 5: -// permutationEncoding |= (120*renumregs[1] + 24*renumregs[2] -// + 6*renumregs[3] + 2*renumregs[4] -// + renumregs[5]); -// break; -// case 4: -// permutationEncoding |= (60*renumregs[2] + 12*renumregs[3] -// + 3*renumregs[4] + renumregs[5]); -// break; -// case 3: -// permutationEncoding |= (20*renumregs[3] + 4*renumregs[4] -// + renumregs[5]); -// break; -// case 2: -// permutationEncoding |= (5*renumregs[4] + renumregs[5]); -// break; -// case 1: -// permutationEncoding |= (renumregs[5]); -// break; -// } -// return permutationEncoding; -//} -// - - - - -// -// x86_64 -// -// 1-bit: start -// 1-bit: has lsda -// 2-bit: personality index -// -// 4-bits: 0=old, 1=rbp based, 2=stack-imm, 3=stack-ind, 4=dwarf -// rbp based: -// 15-bits (5*3-bits per reg) register permutation -// 8-bits for stack offset -// frameless: -// 8-bits stack size -// 3-bits stack adjust -// 3-bits register count -// 10-bits register permutation -// -enum { - UNWIND_X86_64_MODE_MASK = 0x0F000000, - UNWIND_X86_64_MODE_RBP_FRAME = 0x01000000, - UNWIND_X86_64_MODE_STACK_IMMD = 0x02000000, - UNWIND_X86_64_MODE_STACK_IND = 0x03000000, - UNWIND_X86_64_MODE_DWARF = 0x04000000, - - UNWIND_X86_64_RBP_FRAME_REGISTERS = 0x00007FFF, - UNWIND_X86_64_RBP_FRAME_OFFSET = 0x00FF0000, - - UNWIND_X86_64_FRAMELESS_STACK_SIZE = 0x00FF0000, - UNWIND_X86_64_FRAMELESS_STACK_ADJUST = 0x0000E000, - UNWIND_X86_64_FRAMELESS_STACK_REG_COUNT = 0x00001C00, - UNWIND_X86_64_FRAMELESS_STACK_REG_PERMUTATION = 0x000003FF, - - UNWIND_X86_64_DWARF_SECTION_OFFSET = 0x00FFFFFF, -}; - -enum { - UNWIND_X86_64_REG_NONE = 0, - UNWIND_X86_64_REG_RBX = 1, - UNWIND_X86_64_REG_R12 = 2, - UNWIND_X86_64_REG_R13 = 3, - UNWIND_X86_64_REG_R14 = 4, - UNWIND_X86_64_REG_R15 = 5, - UNWIND_X86_64_REG_RBP = 6, -}; -// -// For x86_64 there are four modes for the compact unwind encoding: -// UNWIND_X86_64_MODE_RBP_FRAME: -// RBP based frame where RBP is push on stack immediately after return address, -// then RSP is moved to RBP. Thus, to unwind RSP is restored with the current -// EPB value, then RBP is restored by popping off the stack, and the return -// is done by popping the stack once more into the pc. -// All non-volatile registers that need to be restored must have been saved -// in a small range in the stack that starts RBP-8 to RBP-1020. The offset/4 -// is encoded in the UNWIND_X86_64_RBP_FRAME_OFFSET bits. The registers saved -// are encoded in the UNWIND_X86_64_RBP_FRAME_REGISTERS bits as five 3-bit entries. -// Each entry contains which register to restore. -// UNWIND_X86_64_MODE_STACK_IMMD: -// A "frameless" (RBP not used as frame pointer) function with a small -// constant stack size. To return, a constant (encoded in the compact -// unwind encoding) is added to the RSP. Then the return is done by -// popping the stack into the pc. -// All non-volatile registers that need to be restored must have been saved -// on the stack immediately after the return address. The stack_size/4 is -// encoded in the UNWIND_X86_64_FRAMELESS_STACK_SIZE (max stack size is 1024). -// The number of registers saved is encoded in UNWIND_X86_64_FRAMELESS_STACK_REG_COUNT. -// UNWIND_X86_64_FRAMELESS_STACK_REG_PERMUTATION constains which registers were -// saved and their order. -// UNWIND_X86_64_MODE_STACK_IND: -// A "frameless" (RBP not used as frame pointer) function large constant -// stack size. This case is like the previous, except the stack size is too -// large to encode in the compact unwind encoding. Instead it requires that -// the function contains "subq $nnnnnnnn,RSP" in its prolog. The compact -// encoding contains the offset to the nnnnnnnn value in the function in -// UNWIND_X86_64_FRAMELESS_STACK_SIZE. -// UNWIND_X86_64_MODE_DWARF: -// No compact unwind encoding is available. Instead the low 24-bits of the -// compact encoding is the offset of the dwarf FDE in the __eh_frame section. -// This mode is never used in object files. It is only generated by the -// linker in final linked images which have only dwarf unwind info for a -// function. -// - - - -//////////////////////////////////////////////////////////////////////////////// -// -// Relocatable Object Files: __LD,__compact_unwind -// -//////////////////////////////////////////////////////////////////////////////// - -// -// A compiler can generated compact unwind information for a function by adding -// a "row" to the __LD,__compact_unwind section. This section has the -// S_ATTR_DEBUG bit set, so the section will be ignored by older linkers. -// It is removed by the new linker, so never ends up in final executables. -// This section is a table, initially with one row per function (that needs -// unwind info). The table columns and some conceptual entries are: -// -// range-start pointer to start of function/range -// range-length -// compact-unwind-encoding 32-bit encoding -// personality-function or zero if no personality function -// lsda or zero if no LSDA data -// -// The length and encoding fields are 32-bits. The other are all pointer sized. -// -// In x86_64 assembly, these entry would look like: -// -// .section __LD,__compact_unwind,regular,debug -// -// #compact unwind for _foo -// .quad _foo -// .set L1,LfooEnd-_foo -// .long L1 -// .long 0x01010001 -// .quad 0 -// .quad 0 -// -// #compact unwind for _bar -// .quad _bar -// .set L2,LbarEnd-_bar -// .long L2 -// .long 0x01020011 -// .quad __gxx_personality -// .quad except_tab1 -// -// -// Notes: There is no need for any labels in the the __compact_unwind section. -// The use of the .set directive is to force the evaluation of the -// range-length at assembly time, instead of generating relocations. -// -// To support future compiler optimizations where which non-volatile registers -// are saved changes within a function (e.g. delay saving non-volatiles until -// necessary), there can by multiple lines in the __compact_unwind table for one -// function, each with a different (non-overlapping) range and each with -// different compact unwind encodings that correspond to the non-volatiles -// saved at that range of the function. -// -// If a particular function is so wacky that there is no compact unwind way -// to encode it, then the compiler can emit traditional dwarf unwind info. -// The runtime will use which ever is available. -// -// Runtime support for compact unwind encodings are only available on 10.6 -// and later. So, the compiler should not generate it when targeting pre-10.6. - - - - -//////////////////////////////////////////////////////////////////////////////// -// -// Final Linked Images: __TEXT,__unwind_info -// -//////////////////////////////////////////////////////////////////////////////// - -// -// The __TEXT,__unwind_info section is laid out for an efficient two level lookup. -// The header of the section contains a coarse index that maps function address -// to the page (4096 byte block) containing the unwind info for that function. -// - -#define UNWIND_SECTION_VERSION 1 -struct unwind_info_section_header -{ - uint32_t version; // UNWIND_SECTION_VERSION - uint32_t commonEncodingsArraySectionOffset; - uint32_t commonEncodingsArrayCount; - uint32_t personalityArraySectionOffset; - uint32_t personalityArrayCount; - uint32_t indexSectionOffset; - uint32_t indexCount; - // compact_unwind_encoding_t[] - // uintptr_t personalities[] - // unwind_info_section_header_index_entry[] - // unwind_info_section_header_lsda_index_entry[] -}; - -struct unwind_info_section_header_index_entry -{ - uint32_t functionOffset; - uint32_t secondLevelPagesSectionOffset; // section offset to start of regular or compress page - uint32_t lsdaIndexArraySectionOffset; // section offset to start of lsda_index array for this range -}; - -struct unwind_info_section_header_lsda_index_entry -{ - uint32_t functionOffset; - uint32_t lsdaOffset; -}; - -// -// There are two kinds of second level index pages: regular and compressed. -// A compressed page can hold up to 1021 entries, but it cannot be used -// if too many different encoding types are used. The regular page holds -// 511 entries. -// - -struct unwind_info_regular_second_level_entry -{ - uint32_t functionOffset; - compact_unwind_encoding_t encoding; -}; - -#define UNWIND_SECOND_LEVEL_REGULAR 2 -struct unwind_info_regular_second_level_page_header -{ - uint32_t kind; // UNWIND_SECOND_LEVEL_REGULAR - uint16_t entryPageOffset; - uint16_t entryCount; - // entry array -}; - -#define UNWIND_SECOND_LEVEL_COMPRESSED 3 -struct unwind_info_compressed_second_level_page_header -{ - uint32_t kind; // UNWIND_SECOND_LEVEL_COMPRESSED - uint16_t entryPageOffset; - uint16_t entryCount; - uint16_t encodingsPageOffset; - uint16_t encodingsCount; - // 32-bit entry array - // encodings array -}; - -#define UNWIND_INFO_COMPRESSED_ENTRY_FUNC_OFFSET(entry) (entry & 0x00FFFFFF) -#define UNWIND_INFO_COMPRESSED_ENTRY_ENCODING_INDEX(entry) ((entry >> 24) & 0xFF) - - - -#endif - diff -r 479240de2d64 -r 30ba02c504a0 boot/dyld.h --- a/boot/dyld.h Tue Jan 22 02:47:24 2013 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,253 +0,0 @@ -/* - * Copyright (c) 1999-2008 Apple Inc. All rights reserved. - * - * @APPLE_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. 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_LICENSE_HEADER_END@ - */ -#ifndef _MACH_O_DYLD_H_ -#define _MACH_O_DYLD_H_ - - -#include -#include -#include - -#include -#include - -#if __cplusplus -extern "C" { -#endif - -/* - * The following functions allow you to iterate through all loaded images. - * This is not a thread safe operation. Another thread can add or remove - * an image during the iteration. - * - * Many uses of these routines can be replace by a call to dladdr() which - * will return the mach_header and name of an image, given an address in - * the image. dladdr() is thread safe. - */ -extern uint32_t _dyld_image_count(void) __OSX_AVAILABLE_STARTING(__MAC_10_1, __IPHONE_2_0); -extern const struct mach_header* _dyld_get_image_header(uint32_t image_index) __OSX_AVAILABLE_STARTING(__MAC_10_1, __IPHONE_2_0); -extern intptr_t _dyld_get_image_vmaddr_slide(uint32_t image_index) __OSX_AVAILABLE_STARTING(__MAC_10_1, __IPHONE_2_0); -extern const char* _dyld_get_image_name(uint32_t image_index) __OSX_AVAILABLE_STARTING(__MAC_10_1, __IPHONE_2_0); - - -/* - * The following functions allow you to install callbacks which will be called - * by dyld whenever an image is loaded or unloaded. During a call to _dyld_register_func_for_add_image() - * the callback func is called for every existing image. Later, it is called as each new image - * is loaded and bound (but initializers not yet run). The callback registered with - * _dyld_register_func_for_remove_image() is called after any terminators in an image are run - * and before the image is un-memory-mapped. - */ -extern void _dyld_register_func_for_add_image(void (*func)(const struct mach_header* mh, intptr_t vmaddr_slide)) __OSX_AVAILABLE_STARTING(__MAC_10_1, __IPHONE_2_0); -extern void _dyld_register_func_for_remove_image(void (*func)(const struct mach_header* mh, intptr_t vmaddr_slide)) __OSX_AVAILABLE_STARTING(__MAC_10_1, __IPHONE_2_0); - - -/* - * NSVersionOfRunTimeLibrary() returns the current_version number of the currently dylib - * specifed by the libraryName. The libraryName parameter would be "bar" for /path/libbar.3.dylib and - * "Foo" for /path/Foo.framework/Versions/A/Foo. It returns -1 if no such library is loaded. - */ -extern int32_t NSVersionOfRunTimeLibrary(const char* libraryName) __OSX_AVAILABLE_STARTING(__MAC_10_1, __IPHONE_2_0); - - -/* - * NSVersionOfRunTimeLibrary() returns the current_version number that the main executable was linked - * against at build time. The libraryName parameter would be "bar" for /path/libbar.3.dylib and - * "Foo" for /path/Foo.framework/Versions/A/Foo. It returns -1 if the main executable did not link - * against the specified library. - */ -extern int32_t NSVersionOfLinkTimeLibrary(const char* libraryName) __OSX_AVAILABLE_STARTING(__MAC_10_1, __IPHONE_2_0); - - -/* - * _NSGetExecutablePath() copies the path of the main executable into the buffer. The bufsize parameter - * should initially be the size of the buffer. The function returns 0 if the path was successfully copied, - * and *bufsize is left unchanged. It returns -1 if the buffer is not large enough, and *bufsize is set - * to the size required. - * - * Note that _NSGetExecutablePath will return "a path" to the executable not a "real path" to the executable. - * That is the path may be a symbolic link and not the real file. With deep directories the total bufsize - * needed could be more than MAXPATHLEN. - */ -extern int _NSGetExecutablePath(char* buf, uint32_t* bufsize) __OSX_AVAILABLE_STARTING(__MAC_10_2, __IPHONE_2_0); - - - -/* - * _dyld_moninit() is a private interface between dyld and libSystem. - */ -extern void _dyld_moninit(void (*monaddition)(char *lowpc, char *highpc)) __OSX_AVAILABLE_STARTING(__MAC_10_1, __IPHONE_2_0); - - - - - -/* - * The following dyld API's are deprecated as of Mac OS X 10.5. They are either - * no longer necessary or are superceeded by dlopen and friends in . - * dlopen/dlsym/dlclose have been available since Mac OS X 10.3 and work with - * dylibs and bundles. - * - * NSAddImage -> dlopen - * NSLookupSymbolInImage -> dlsym - * NSCreateObjectFileImageFromFile -> dlopen - * NSDestroyObjectFileImage -> dlclose - * NSLinkModule -> not needed when dlopen used - * NSUnLinkModule -> not needed when dlclose used - * NSLookupSymbolInModule -> dlsym - * _dyld_image_containing_address -> dladdr - * NSLinkEditError -> dlerror - * - */ - -#ifndef ENUM_DYLD_BOOL -#define ENUM_DYLD_BOOL - #undef FALSE - #undef TRUE - enum DYLD_BOOL { FALSE, TRUE }; -#endif /* ENUM_DYLD_BOOL */ - - -/* Object file image API */ -typedef enum { - NSObjectFileImageFailure, /* for this a message is printed on stderr */ - NSObjectFileImageSuccess, - NSObjectFileImageInappropriateFile, - NSObjectFileImageArch, - NSObjectFileImageFormat, /* for this a message is printed on stderr */ - NSObjectFileImageAccess -} NSObjectFileImageReturnCode; - -typedef struct __NSObjectFileImage* NSObjectFileImage; - -/* NSObjectFileImage can only be used with MH_BUNDLE files */ -extern NSObjectFileImageReturnCode NSCreateObjectFileImageFromFile(const char* pathName, NSObjectFileImage *objectFileImage) __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_1,__MAC_10_5,__IPHONE_NA,__IPHONE_NA); -extern NSObjectFileImageReturnCode NSCreateObjectFileImageFromMemory(const void *address, size_t size, NSObjectFileImage *objectFileImage) __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_1,__MAC_10_5,__IPHONE_NA,__IPHONE_NA); -extern bool NSDestroyObjectFileImage(NSObjectFileImage objectFileImage) __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_1,__MAC_10_5,__IPHONE_NA,__IPHONE_NA); - -extern uint32_t NSSymbolDefinitionCountInObjectFileImage(NSObjectFileImage objectFileImage) __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_1,__MAC_10_5,__IPHONE_NA,__IPHONE_NA); -extern const char* NSSymbolDefinitionNameInObjectFileImage(NSObjectFileImage objectFileImage, uint32_t ordinal) __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_1,__MAC_10_5,__IPHONE_NA,__IPHONE_NA); -extern uint32_t NSSymbolReferenceCountInObjectFileImage(NSObjectFileImage objectFileImage) __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_1,__MAC_10_5,__IPHONE_NA,__IPHONE_NA); -extern const char* NSSymbolReferenceNameInObjectFileImage(NSObjectFileImage objectFileImage, uint32_t ordinal, bool *tentative_definition) __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_1,__MAC_10_5,__IPHONE_NA,__IPHONE_NA); -extern bool NSIsSymbolDefinedInObjectFileImage(NSObjectFileImage objectFileImage, const char* symbolName) __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_1,__MAC_10_4,__IPHONE_NA,__IPHONE_NA); -extern void* NSGetSectionDataInObjectFileImage(NSObjectFileImage objectFileImage, const char* segmentName, const char* sectionName, size_t *size) __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_1,__MAC_10_5,__IPHONE_NA,__IPHONE_NA); -extern bool NSHasModInitObjectFileImage(NSObjectFileImage objectFileImage) __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_3,__MAC_10_5,__IPHONE_NA,__IPHONE_NA); - -typedef struct __NSModule* NSModule; -extern const char* NSNameOfModule(NSModule m) __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_1,__MAC_10_5,__IPHONE_NA,__IPHONE_NA); -extern const char* NSLibraryNameForModule(NSModule m) __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_1,__MAC_10_5,__IPHONE_NA,__IPHONE_NA); - -extern NSModule NSLinkModule(NSObjectFileImage objectFileImage, const char* moduleName, uint32_t options) __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_1,__MAC_10_5,__IPHONE_NA,__IPHONE_NA); -#define NSLINKMODULE_OPTION_NONE 0x0 -#define NSLINKMODULE_OPTION_BINDNOW 0x1 -#define NSLINKMODULE_OPTION_PRIVATE 0x2 -#define NSLINKMODULE_OPTION_RETURN_ON_ERROR 0x4 -#define NSLINKMODULE_OPTION_DONT_CALL_MOD_INIT_ROUTINES 0x8 -#define NSLINKMODULE_OPTION_TRAILING_PHYS_NAME 0x10 - -extern bool NSUnLinkModule(NSModule module, uint32_t options) __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_1,__MAC_10_5,__IPHONE_NA,__IPHONE_NA); -#define NSUNLINKMODULE_OPTION_NONE 0x0 -#define NSUNLINKMODULE_OPTION_KEEP_MEMORY_MAPPED 0x1 -#define NSUNLINKMODULE_OPTION_RESET_LAZY_REFERENCES 0x2 - -/* symbol API */ -typedef struct __NSSymbol* NSSymbol; -extern bool NSIsSymbolNameDefined(const char* symbolName) __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_1,__MAC_10_4,__IPHONE_NA,__IPHONE_NA); -extern bool NSIsSymbolNameDefinedWithHint(const char* symbolName, const char* libraryNameHint) __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_1,__MAC_10_4,__IPHONE_NA,__IPHONE_NA); -extern bool NSIsSymbolNameDefinedInImage(const struct mach_header* image, const char* symbolName) __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_1,__MAC_10_4,__IPHONE_NA,__IPHONE_NA); -extern NSSymbol NSLookupAndBindSymbol(const char* symbolName) __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_1,__MAC_10_4,__IPHONE_NA,__IPHONE_NA); -extern NSSymbol NSLookupAndBindSymbolWithHint(const char* symbolName, const char* libraryNameHint) __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_1,__MAC_10_4,__IPHONE_NA,__IPHONE_NA); -extern NSSymbol NSLookupSymbolInModule(NSModule module, const char* symbolName) __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_1,__MAC_10_5,__IPHONE_NA,__IPHONE_NA); -extern NSSymbol NSLookupSymbolInImage(const struct mach_header* image, const char* symbolName, uint32_t options) __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_1,__MAC_10_5,__IPHONE_NA,__IPHONE_NA); -#define NSLOOKUPSYMBOLINIMAGE_OPTION_BIND 0x0 -#define NSLOOKUPSYMBOLINIMAGE_OPTION_BIND_NOW 0x1 -#define NSLOOKUPSYMBOLINIMAGE_OPTION_BIND_FULLY 0x2 -#define NSLOOKUPSYMBOLINIMAGE_OPTION_RETURN_ON_ERROR 0x4 -extern const char* NSNameOfSymbol(NSSymbol symbol) __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_1,__MAC_10_5,__IPHONE_NA,__IPHONE_NA); -extern void * NSAddressOfSymbol(NSSymbol symbol) __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_1,__MAC_10_5,__IPHONE_NA,__IPHONE_NA); -extern NSModule NSModuleForSymbol(NSSymbol symbol) __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_1,__MAC_10_5,__IPHONE_NA,__IPHONE_NA); - -/* error handling API */ -typedef enum { - NSLinkEditFileAccessError, - NSLinkEditFileFormatError, - NSLinkEditMachResourceError, - NSLinkEditUnixResourceError, - NSLinkEditOtherError, - NSLinkEditWarningError, - NSLinkEditMultiplyDefinedError, - NSLinkEditUndefinedError -} NSLinkEditErrors; - -/* - * For the NSLinkEditErrors value NSLinkEditOtherError these are the values - * passed to the link edit error handler as the errorNumber (what would be an - * errno value for NSLinkEditUnixResourceError or a kern_return_t value for - * NSLinkEditMachResourceError). - */ -typedef enum { - NSOtherErrorRelocation, - NSOtherErrorLazyBind, - NSOtherErrorIndrLoop, - NSOtherErrorLazyInit, - NSOtherErrorInvalidArgs -} NSOtherErrorNumbers; - -extern void NSLinkEditError(NSLinkEditErrors *c, int *errorNumber, const char** fileName, const char** errorString) __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_1,__MAC_10_5,__IPHONE_NA,__IPHONE_NA); - -typedef struct { - void (*undefined)(const char* symbolName); - NSModule (*multiple)(NSSymbol s, NSModule oldModule, NSModule newModule); - void (*linkEdit)(NSLinkEditErrors errorClass, int errorNumber, - const char* fileName, const char* errorString); -} NSLinkEditErrorHandlers; - -extern void NSInstallLinkEditErrorHandlers(const NSLinkEditErrorHandlers *handlers) __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_1,__MAC_10_5,__IPHONE_NA,__IPHONE_NA); - -extern bool NSAddLibrary(const char* pathName) __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_1,__MAC_10_4,__IPHONE_NA,__IPHONE_NA); -extern bool NSAddLibraryWithSearching(const char* pathName) __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_1,__MAC_10_4,__IPHONE_NA,__IPHONE_NA); -extern const struct mach_header* NSAddImage(const char* image_name, uint32_t options) __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_1,__MAC_10_5,__IPHONE_NA,__IPHONE_NA); -#define NSADDIMAGE_OPTION_NONE 0x0 -#define NSADDIMAGE_OPTION_RETURN_ON_ERROR 0x1 -#define NSADDIMAGE_OPTION_WITH_SEARCHING 0x2 -#define NSADDIMAGE_OPTION_RETURN_ONLY_IF_LOADED 0x4 -#define NSADDIMAGE_OPTION_MATCH_FILENAME_BY_INSTALLNAME 0x8 - -extern bool _dyld_present(void) __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_1,__MAC_10_5,__IPHONE_NA,__IPHONE_NA); -extern bool _dyld_launched_prebound(void) __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_1,__MAC_10_5,__IPHONE_NA,__IPHONE_NA); -extern bool _dyld_all_twolevel_modules_prebound(void) __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_3,__MAC_10_5,__IPHONE_NA,__IPHONE_NA); -extern void _dyld_bind_objc_module(const void* objc_module) __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_1,__MAC_10_5,__IPHONE_NA,__IPHONE_NA); -extern bool _dyld_bind_fully_image_containing_address(const void* address) __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_1,__MAC_10_5,__IPHONE_NA,__IPHONE_NA); -extern bool _dyld_image_containing_address(const void* address) __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_3,__MAC_10_5,__IPHONE_NA,__IPHONE_NA); -extern void _dyld_lookup_and_bind(const char* symbol_name, void **address, NSModule* module) __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_1,__MAC_10_4,__IPHONE_NA,__IPHONE_NA); -extern void _dyld_lookup_and_bind_with_hint(const char* symbol_name, const char* library_name_hint, void** address, NSModule* module) __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_1,__MAC_10_4,__IPHONE_NA,__IPHONE_NA); -extern void _dyld_lookup_and_bind_fully(const char* symbol_name, void** address, NSModule* module) __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_1,__MAC_10_5,__IPHONE_NA,__IPHONE_NA); - -extern const struct mach_header* _dyld_get_image_header_containing_address(const void* address) __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_3,__MAC_10_5,__IPHONE_NA,__IPHONE_NA); - - -#if __cplusplus -} -#endif - -#endif /* _MACH_O_DYLD_H_ */ diff -r 479240de2d64 -r 30ba02c504a0 boot/dyld_images.h --- a/boot/dyld_images.h Tue Jan 22 02:47:24 2013 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,164 +0,0 @@ -/* - * Copyright (c) 2006-2010 Apple Inc. All rights reserved. - * - * @APPLE_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. 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_LICENSE_HEADER_END@ - */ -#ifndef _DYLD_IMAGES_ -#define _DYLD_IMAGES_ - -#include -#include -#include - -#ifdef __cplusplus -extern "C" { -#endif - - -/* - * Beginning in Mac OS X 10.4, this is how gdb discovers which mach-o images are loaded in a process. - * - * gdb looks for the symbol "_dyld_all_image_infos" in dyld. It contains the fields below. - * - * For a snashot of what images are currently loaded, the infoArray fields contain a pointer - * to an array of all images. If infoArray is NULL, it means it is being modified, come back later. - * - * To be notified of changes, gdb sets a break point on the address pointed to by the notificationn - * field. The function it points to is called by dyld with an array of information about what images - * have been added (dyld_image_adding) or are about to be removed (dyld_image_removing). - * - * The notification is called after infoArray is updated. This means that if gdb attaches to a process - * and infoArray is NULL, gdb can set a break point on notification and let the proccess continue to - * run until the break point. Then gdb can inspect the full infoArray. - * - * The dyldVersion field always points to a C string that contains the dyld version. For instance, - * in dyld-127.3, dyldVersion would contain a pointer to "127.3". - * - * The errorMessage and terminationFlags fields are normally zero. If dyld terminates a process - * (for instance because a required dylib or symbol is missing), then the errorMessage field will - * be set to point to a C string message buffer containing the reason dyld terminate the process. - * The low bit of the terminationFlags will be set if dyld terminated the process before any user - * code ran, in which case there is no need for the crash log to contain the backtrace. - * - * When dyld terminates a process because some required dylib or symbol cannot be bound, in - * addition to the errorMessage field, it now sets the errorKind field and the corresponding - * fields: errorClientOfDylibPath, errorTargetDylibPath, errorSymbol. - * - */ - -enum dyld_image_mode { dyld_image_adding=0, dyld_image_removing=1 }; - -struct dyld_image_info { - const struct mach_header* imageLoadAddress; /* base address image is mapped into */ - const char* imageFilePath; /* path dyld used to load the image */ - uintptr_t imageFileModDate; /* time_t of image file */ - /* if stat().st_mtime of imageFilePath does not match imageFileModDate, */ - /* then file has been modified since dyld loaded it */ -}; - -struct dyld_uuid_info { - const struct mach_header* imageLoadAddress; /* base address image is mapped into */ - uuid_t imageUUID; /* UUID of image */ -}; - -typedef void (*dyld_image_notifier)(enum dyld_image_mode mode, uint32_t infoCount, const struct dyld_image_info info[]); - -/* for use in dyld_all_image_infos.errorKind field */ -enum { dyld_error_kind_none=0, - dyld_error_kind_dylib_missing=1, - dyld_error_kind_dylib_wrong_arch=2, - dyld_error_kind_dylib_version=3, - dyld_error_kind_symbol_missing=4 - }; - - -struct dyld_all_image_infos { - uint32_t version; /* 1 in Mac OS X 10.4 and 10.5 */ - uint32_t infoArrayCount; - const struct dyld_image_info* infoArray; - dyld_image_notifier notification; - bool processDetachedFromSharedRegion; - /* the following fields are only in version 2 (Mac OS X 10.6, iPhoneOS 2.0) and later */ - bool libSystemInitialized; - const struct mach_header* dyldImageLoadAddress; - /* the following field is only in version 3 (Mac OS X 10.6, iPhoneOS 3.0) and later */ - void* jitInfo; - /* the following fields are only in version 5 (Mac OS X 10.6, iPhoneOS 3.0) and later */ - const char* dyldVersion; - const char* errorMessage; - uintptr_t terminationFlags; - /* the following field is only in version 6 (Mac OS X 10.6, iPhoneOS 3.1) and later */ - void* coreSymbolicationShmPage; - /* the following field is only in version 7 (Mac OS X 10.6, iPhoneOS 3.1) and later */ - uintptr_t systemOrderFlag; - /* the following field is only in version 8 (Mac OS X 10.7, iPhoneOS 3.1) and later */ - uintptr_t uuidArrayCount; - const struct dyld_uuid_info* uuidArray; /* only images not in dyld shared cache */ - /* the following field is only in version 9 (Mac OS X 10.7, iOS 4.0) and later */ - struct dyld_all_image_infos* dyldAllImageInfosAddress; - /* the following field is only in version 10 (Mac OS X 10.7, iOS 4.2) and later */ - uintptr_t initialImageCount; - /* the following field is only in version 11 (Mac OS X 10.7, iOS 4.2) and later */ - uintptr_t errorKind; - const char* errorClientOfDylibPath; - const char* errorTargetDylibPath; - const char* errorSymbol; - /* the following field is only in version 12 (Mac OS X 10.7, iOS 4.3) and later */ - uintptr_t sharedCacheSlide; -}; -extern struct dyld_all_image_infos dyld_all_image_infos; - -/* - * Beginning in Mac OS X 10.6, rather than looking up the symbol "_dyld_all_image_infos" - * in dyld's symbol table, you can add DYLD_ALL_IMAGE_INFOS_OFFSET_OFFSET to the mach_header - * for dyld and read the 32-bit unsigned int at that location. Adding that value to dyld's - * mach_header address gets you the address of dyld_all_image_infos in dyld. - */ -#define DYLD_ALL_IMAGE_INFOS_OFFSET_OFFSET 0x1010 - - - -/* - * Beginning in Mac OS X 10.5, this is how gdb discovers where the shared cache is in a process. - * Images that are in the shared cache have their segments rearranged, so when using imageFilePath - * to load the file from disk, you have to know to adjust addresses based on how their segment - * was rearranged. - * - * gdb looks for the symbol "_dyld_shared_region_ranges" in dyld. - * - * It contains information the count of shared regions used by the process. The count is - * the number of start/length pairs. - */ -struct dyld_shared_cache_ranges { - uintptr_t sharedRegionsCount; /* how many ranges follow */ - struct { - uintptr_t start; - uintptr_t length; - } ranges[4]; /* max regions */ -}; -extern struct dyld_shared_cache_ranges dyld_shared_cache_ranges; - - - -#ifdef __cplusplus -} -#endif - -#endif /* _DYLD_IMAGES_ */ diff -r 479240de2d64 -r 30ba02c504a0 boot/fat.h --- a/boot/fat.h Tue Jan 22 02:47:24 2013 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,64 +0,0 @@ -/* - * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. - * - * @APPLE_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. 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_LICENSE_HEADER_END@ - */ -#ifndef _MACH_O_FAT_H_ -#define _MACH_O_FAT_H_ -/* - * This header file describes the structures of the file format for "fat" - * architecture specific file (wrapper design). At the begining of the file - * there is one fat_header structure followed by a number of fat_arch - * structures. For each architecture in the file, specified by a pair of - * cputype and cpusubtype, the fat_header describes the file offset, file - * size and alignment in the file of the architecture specific member. - * The padded bytes in the file to place each member on it's specific alignment - * are defined to be read as zeros and can be left as "holes" if the file system - * can support them as long as they read as zeros. - * - * All structures defined here are always written and read to/from disk - * in big-endian order. - */ - -/* - * is needed here for the cpu_type_t and cpu_subtype_t types - * and contains the constants for the possible values of these types. - */ -#include -#include -#include - -#define FAT_MAGIC 0xcafebabe -#define FAT_CIGAM 0xbebafeca /* NXSwapLong(FAT_MAGIC) */ - -struct fat_header { - uint32_t magic; /* FAT_MAGIC */ - uint32_t nfat_arch; /* number of structs that follow */ -}; - -struct fat_arch { - cpu_type_t cputype; /* cpu specifier (int) */ - cpu_subtype_t cpusubtype; /* machine specifier (int) */ - uint32_t offset; /* file offset to this object file */ - uint32_t size; /* size of this object file */ - uint32_t align; /* alignment as a power of 2 */ -}; - -#endif /* _MACH_O_FAT_H_ */ diff -r 479240de2d64 -r 30ba02c504a0 boot/getsect.h --- a/boot/getsect.h Tue Jan 22 02:47:24 2013 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,131 +0,0 @@ -/* - * Copyright (c) 2004 Apple Computer, Inc. All rights reserved. - * - * @APPLE_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. 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_LICENSE_HEADER_END@ - */ -#ifndef _MACH_O_GETSECT_H_ -#define _MACH_O_GETSECT_H_ - -#include -#include - -#if __cplusplus -extern "C" { -#endif /* __cplusplus */ - -/* - * Runtime interfaces for Mach-O programs. For both 32-bit and 64-bit programs, - * where the sizes returned will be 32-bit or 64-bit based on the size of - * 'unsigned long'. - */ -extern char *getsectdata( - const char *segname, - const char *sectname, - unsigned long *size); - -extern char *getsectdatafromFramework( - const char *FrameworkName, - const char *segname, - const char *sectname, - unsigned long *size); - -extern unsigned long get_end(void); -extern unsigned long get_etext(void); -extern unsigned long get_edata(void); - -#ifndef __LP64__ -/* - * Runtime interfaces for 32-bit Mach-O programs. - */ -extern const struct section *getsectbyname( - const char *segname, - const char *sectname); - -extern uint8_t *getsectiondata( - const struct mach_header *mhp, - const char *segname, - const char *sectname, - unsigned long *size); - -extern const struct segment_command *getsegbyname( - const char *segname); - -extern uint8_t *getsegmentdata( - const struct mach_header *mhp, - const char *segname, - unsigned long *size); - -#else /* defined(__LP64__) */ -/* - * Runtime interfaces for 64-bit Mach-O programs. - */ -extern const struct section_64 *getsectbyname( - const char *segname, - const char *sectname); - -extern uint8_t *getsectiondata( - const struct mach_header_64 *mhp, - const char *segname, - const char *sectname, - unsigned long *size); - -extern const struct segment_command_64 *getsegbyname( - const char *segname); - -extern uint8_t *getsegmentdata( - const struct mach_header_64 *mhp, - const char *segname, - unsigned long *size); - -#endif /* defined(__LP64__) */ - -/* - * Interfaces for tools working with 32-bit Mach-O files. - */ -extern char *getsectdatafromheader( - const struct mach_header *mhp, - const char *segname, - const char *sectname, - uint32_t *size); - -extern const struct section *getsectbynamefromheader( - const struct mach_header *mhp, - const char *segname, - const char *sectname); - -/* - * Interfaces for tools working with 64-bit Mach-O files. - */ -extern char *getsectdatafromheader_64( - const struct mach_header_64 *mhp, - const char *segname, - const char *sectname, - uint64_t *size); - -extern const struct section_64 *getsectbynamefromheader_64( - const struct mach_header_64 *mhp, - const char *segname, - const char *sectname); - -#if __cplusplus -} -#endif /* __cplusplus */ - -#endif /* _MACH_O_GETSECT_H_ */ diff -r 479240de2d64 -r 30ba02c504a0 boot/i386/swap.h --- a/boot/i386/swap.h Tue Jan 22 02:47:24 2013 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,96 +0,0 @@ -/* - * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. - * - * @APPLE_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. 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_LICENSE_HEADER_END@ - */ -#include -#include - -extern void swap_i386_thread_state( - i386_thread_state_t *cpu, - enum NXByteOrder target_byte_order); - -/* current i386 thread states */ -#if i386_THREAD_STATE == 1 -extern void swap_i386_float_state( - struct i386_float_state *fpu, - enum NXByteOrder target_byte_order); - -extern void swap_i386_exception_state( - i386_exception_state_t *exc, - enum NXByteOrder target_byte_order); -#endif /* i386_THREAD_STATE == 1 */ - -/* i386 thread states on older releases */ -#if i386_THREAD_STATE == -1 -extern void swap_i386_thread_fpstate( - i386_thread_fpstate_t *fpu, - enum NXByteOrder target_byte_order); - -extern void swap_i386_thread_exceptstate( - i386_thread_exceptstate_t *exc, - enum NXByteOrder target_byte_order); - -extern void swap_i386_thread_cthreadstate( - i386_thread_cthreadstate_t *user, - enum NXByteOrder target_byte_order); -#endif /* i386_THREAD_STATE == -1 */ - -#ifdef x86_THREAD_STATE64 -extern void swap_x86_thread_state64( - x86_thread_state64_t *cpu, - enum NXByteOrder target_byte_order); - -extern void swap_x86_state_hdr( - x86_state_hdr_t *hdr, - enum NXByteOrder target_byte_order); - -extern void swap_x86_float_state64( - x86_float_state64_t *fpu, - enum NXByteOrder target_byte_order); - -extern void swap_x86_exception_state64( - x86_exception_state64_t *exc, - enum NXByteOrder target_byte_order); - -extern void swap_x86_thread_state( - x86_thread_state_t *cpu, - enum NXByteOrder target_byte_order); - -extern void swap_x86_float_state( - x86_float_state_t *fpu, - enum NXByteOrder target_byte_order); - -extern void swap_x86_exception_state( - x86_exception_state_t *exc, - enum NXByteOrder target_byte_order); - -extern void swap_x86_debug_state32( - x86_debug_state32_t *debug, - enum NXByteOrder target_byte_order); - -extern void swap_x86_debug_state64( - x86_debug_state64_t *debug, - enum NXByteOrder target_byte_order); - -extern void swap_x86_debug_state( - x86_debug_state_t *debug, - enum NXByteOrder target_byte_order); -#endif /* x86_THREAD_STATE64 */ diff -r 479240de2d64 -r 30ba02c504a0 boot/ldsyms.h --- a/boot/ldsyms.h Tue Jan 22 02:47:24 2013 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,133 +0,0 @@ -/* - * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. - * - * @APPLE_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. 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_LICENSE_HEADER_END@ - */ - -#ifndef _MACHO_LDSYMS_H_ -#define _MACHO_LDSYMS_H_ - -#include - -/* - * This file describes the link editor defined symbols. The semantics of a - * link editor symbol is that it is defined by the link editor only if it is - * referenced and it is an error for the user to define them (see the man page - * ld(1)). The standard UNIX link editor symbols: __end, __etext and __edata - * are not not supported by the Apple Mach-O link editor. These symbols are - * really not meaningful in a Mach-O object file and the link editor symbols - * that are supported (described here) replace them. In the case of the - * standard UNIX link editor symbols the program can use the symbol - * __mh_execute_header and walk the load commands of it's program to determine - * the ending (or beginning) of any section or segment in the program. Note - * that the compiler prepends an underbar to all external symbol names coded - * in a high level language. Thus in 'C' names are coded without an underbar - * and symbol names in the symbol table have an underbar. There are two cpp - * macros for each link editor defined name in this file. The macro with a - * leading underbar is the symbol name and the one without is the name as - * coded in 'C'. - */ - -/* - * The value of the link editor defined symbol _MH_EXECUTE_SYM is the address - * of the mach header in a Mach-O executable file type. It does not appear in - * any file type other than a MH_EXECUTE file type. The type of the symbol is - * absolute as the header is not part of any section. - */ -#define _MH_EXECUTE_SYM "__mh_execute_header" -#define MH_EXECUTE_SYM "_mh_execute_header" -extern const struct -#ifdef __LP64__ -mach_header_64 -#else -mach_header -#endif -_mh_execute_header; - -/* - * The value of the link editor defined symbol _MH_BUNDLE_SYM is the address - * of the mach header in a Mach-O bundle file type. It does not appear in - * any file type other than a MH_BUNDLE file type. The type of the symbol is - * an N_SECT symbol even thought the header is not part of any section. This - * symbol is private to the code in the bundle it is a part of. - */ -#define _MH_BUNDLE_SYM "__mh_bundle_header" -#define MH_BUNDLE_SYM "_mh_bundle_header" -extern const struct -#ifdef __LP64__ -mach_header_64 -#else -mach_header -#endif -_mh_bundle_header; - -/* - * The value of the link editor defined symbol _MH_DYLIB_SYM is the address - * of the mach header in a Mach-O dylib file type. It does not appear in - * any file type other than a MH_DYLIB file type. The type of the symbol is - * an N_SECT symbol even thought the header is not part of any section. This - * symbol is private to the code in the library it is a part of. - */ -#define _MH_DYLIB_SYM "__mh_dylib_header" -#define MH_DYLIB_SYM "_mh_dylib_header" -extern const struct -#ifdef __LP64__ -mach_header_64 -#else -mach_header -#endif -_mh_dylib_header; - -/* - * The value of the link editor defined symbol _MH_DYLINKER_SYM is the address - * of the mach header in a Mach-O dylinker file type. It does not appear in - * any file type other than a MH_DYLINKER file type. The type of the symbol is - * an N_SECT symbol even thought the header is not part of any section. This - * symbol is private to the code in the dynamic linker it is a part of. - */ -#define _MH_DYLINKER_SYM "__mh_dylinker_header" -#define MH_DYLINKER_SYM "_mh_dylinker_header" -extern const struct -#ifdef __LP64__ -mach_header_64 -#else -mach_header -#endif -_mh_dylinker_header; - -/* - * For the MH_PRELOAD file type the headers are not loaded as part of any - * segment so the link editor defines symbols defined for the beginning - * and ending of each segment and each section in each segment. The names for - * the symbols for a segment's beginning and end will have the form: - * __SEGNAME__begin and __SEGNAME__end where __SEGNAME is the name of the - * segment. The names for the symbols for a section's beginning and end will - * have the form: __SEGNAME__sectname__begin and __SEGNAME__sectname__end - * where __sectname is the name of the section and __SEGNAME is the segment it - * is in. - * - * The above symbols' types are those of the section they are referring to. - * This is true even for symbols who's values are end's of a section and - * that value is next address after that section and not really in that - * section. This results in these symbols having types referring to sections - * who's values are not in that section. - */ - -#endif /* _MACHO_LDSYMS_H_ */ diff -r 479240de2d64 -r 30ba02c504a0 boot/loader.h --- a/boot/loader.h Tue Jan 22 02:47:24 2013 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1458 +0,0 @@ -/* - * Copyright (c) 1999-2010 Apple Inc. All Rights Reserved. - * - * @APPLE_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. 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_LICENSE_HEADER_END@ - */ -#ifndef _MACHO_LOADER_H_ -#define _MACHO_LOADER_H_ - -/* - * This file describes the format of mach object files. - */ -#include - -/* - * is needed here for the cpu_type_t and cpu_subtype_t types - * and contains the constants for the possible values of these types. - */ -#include - -/* - * is needed here for the vm_prot_t type and contains the - * constants that are or'ed together for the possible values of this type. - */ -#include - -/* - * is expected to define the flavors of the thread - * states and the structures of those flavors for each machine. - */ -#include -#include - -/* - * The 32-bit mach header appears at the very beginning of the object file for - * 32-bit architectures. - */ -struct mach_header { - uint32_t magic; /* mach magic number identifier */ - cpu_type_t cputype; /* cpu specifier */ - cpu_subtype_t cpusubtype; /* machine specifier */ - uint32_t filetype; /* type of file */ - uint32_t ncmds; /* number of load commands */ - uint32_t sizeofcmds; /* the size of all the load commands */ - uint32_t flags; /* flags */ -}; - -/* Constant for the magic field of the mach_header (32-bit architectures) */ -#define MH_MAGIC 0xfeedface /* the mach magic number */ -#define MH_CIGAM 0xcefaedfe /* NXSwapInt(MH_MAGIC) */ - -/* - * The 64-bit mach header appears at the very beginning of object files for - * 64-bit architectures. - */ -struct mach_header_64 { - uint32_t magic; /* mach magic number identifier */ - cpu_type_t cputype; /* cpu specifier */ - cpu_subtype_t cpusubtype; /* machine specifier */ - uint32_t filetype; /* type of file */ - uint32_t ncmds; /* number of load commands */ - uint32_t sizeofcmds; /* the size of all the load commands */ - uint32_t flags; /* flags */ - uint32_t reserved; /* reserved */ -}; - -/* Constant for the magic field of the mach_header_64 (64-bit architectures) */ -#define MH_MAGIC_64 0xfeedfacf /* the 64-bit mach magic number */ -#define MH_CIGAM_64 0xcffaedfe /* NXSwapInt(MH_MAGIC_64) */ - -/* - * The layout of the file depends on the filetype. For all but the MH_OBJECT - * file type the segments are padded out and aligned on a segment alignment - * boundary for efficient demand pageing. The MH_EXECUTE, MH_FVMLIB, MH_DYLIB, - * MH_DYLINKER and MH_BUNDLE file types also have the headers included as part - * of their first segment. - * - * The file type MH_OBJECT is a compact format intended as output of the - * assembler and input (and possibly output) of the link editor (the .o - * format). All sections are in one unnamed segment with no segment padding. - * This format is used as an executable format when the file is so small the - * segment padding greatly increases its size. - * - * The file type MH_PRELOAD is an executable format intended for things that - * are not executed under the kernel (proms, stand alones, kernels, etc). The - * format can be executed under the kernel but may demand paged it and not - * preload it before execution. - * - * A core file is in MH_CORE format and can be any in an arbritray legal - * Mach-O file. - * - * Constants for the filetype field of the mach_header - */ -#define MH_OBJECT 0x1 /* relocatable object file */ -#define MH_EXECUTE 0x2 /* demand paged executable file */ -#define MH_FVMLIB 0x3 /* fixed VM shared library file */ -#define MH_CORE 0x4 /* core file */ -#define MH_PRELOAD 0x5 /* preloaded executable file */ -#define MH_DYLIB 0x6 /* dynamically bound shared library */ -#define MH_DYLINKER 0x7 /* dynamic link editor */ -#define MH_BUNDLE 0x8 /* dynamically bound bundle file */ -#define MH_DYLIB_STUB 0x9 /* shared library stub for static */ - /* linking only, no section contents */ -#define MH_DSYM 0xa /* companion file with only debug */ - /* sections */ -#define MH_KEXT_BUNDLE 0xb /* x86_64 kexts */ - -/* Constants for the flags field of the mach_header */ -#define MH_NOUNDEFS 0x1 /* the object file has no undefined - references */ -#define MH_INCRLINK 0x2 /* the object file is the output of an - incremental link against a base file - and can't be link edited again */ -#define MH_DYLDLINK 0x4 /* the object file is input for the - dynamic linker and can't be staticly - link edited again */ -#define MH_BINDATLOAD 0x8 /* the object file's undefined - references are bound by the dynamic - linker when loaded. */ -#define MH_PREBOUND 0x10 /* the file has its dynamic undefined - references prebound. */ -#define MH_SPLIT_SEGS 0x20 /* the file has its read-only and - read-write segments split */ -#define MH_LAZY_INIT 0x40 /* the shared library init routine is - to be run lazily via catching memory - faults to its writeable segments - (obsolete) */ -#define MH_TWOLEVEL 0x80 /* the image is using two-level name - space bindings */ -#define MH_FORCE_FLAT 0x100 /* the executable is forcing all images - to use flat name space bindings */ -#define MH_NOMULTIDEFS 0x200 /* this umbrella guarantees no multiple - defintions of symbols in its - sub-images so the two-level namespace - hints can always be used. */ -#define MH_NOFIXPREBINDING 0x400 /* do not have dyld notify the - prebinding agent about this - executable */ -#define MH_PREBINDABLE 0x800 /* the binary is not prebound but can - have its prebinding redone. only used - when MH_PREBOUND is not set. */ -#define MH_ALLMODSBOUND 0x1000 /* indicates that this binary binds to - all two-level namespace modules of - its dependent libraries. only used - when MH_PREBINDABLE and MH_TWOLEVEL - are both set. */ -#define MH_SUBSECTIONS_VIA_SYMBOLS 0x2000/* safe to divide up the sections into - sub-sections via symbols for dead - code stripping */ -#define MH_CANONICAL 0x4000 /* the binary has been canonicalized - via the unprebind operation */ -#define MH_WEAK_DEFINES 0x8000 /* the final linked image contains - external weak symbols */ -#define MH_BINDS_TO_WEAK 0x10000 /* the final linked image uses - weak symbols */ - -#define MH_ALLOW_STACK_EXECUTION 0x20000/* When this bit is set, all stacks - in the task will be given stack - execution privilege. Only used in - MH_EXECUTE filetypes. */ -#define MH_ROOT_SAFE 0x40000 /* When this bit is set, the binary - declares it is safe for use in - processes with uid zero */ - -#define MH_SETUID_SAFE 0x80000 /* When this bit is set, the binary - declares it is safe for use in - processes when issetugid() is true */ - -#define MH_NO_REEXPORTED_DYLIBS 0x100000 /* When this bit is set on a dylib, - the static linker does not need to - examine dependent dylibs to see - if any are re-exported */ -#define MH_PIE 0x200000 /* When this bit is set, the OS will - load the main executable at a - random address. Only used in - MH_EXECUTE filetypes. */ -#define MH_DEAD_STRIPPABLE_DYLIB 0x400000 /* Only for use on dylibs. When - linking against a dylib that - has this bit set, the static linker - will automatically not create a - LC_LOAD_DYLIB load command to the - dylib if no symbols are being - referenced from the dylib. */ -#define MH_HAS_TLV_DESCRIPTORS 0x800000 /* Contains a section of type - S_THREAD_LOCAL_VARIABLES */ - -#define MH_NO_HEAP_EXECUTION 0x1000000 /* When this bit is set, the OS will - run the main executable with - a non-executable heap even on - platforms (e.g. i386) that don't - require it. Only used in MH_EXECUTE - filetypes. */ - -/* - * The load commands directly follow the mach_header. The total size of all - * of the commands is given by the sizeofcmds field in the mach_header. All - * load commands must have as their first two fields cmd and cmdsize. The cmd - * field is filled in with a constant for that command type. Each command type - * has a structure specifically for it. The cmdsize field is the size in bytes - * of the particular load command structure plus anything that follows it that - * is a part of the load command (i.e. section structures, strings, etc.). To - * advance to the next load command the cmdsize can be added to the offset or - * pointer of the current load command. The cmdsize for 32-bit architectures - * MUST be a multiple of 4 bytes and for 64-bit architectures MUST be a multiple - * of 8 bytes (these are forever the maximum alignment of any load commands). - * The padded bytes must be zero. All tables in the object file must also - * follow these rules so the file can be memory mapped. Otherwise the pointers - * to these tables will not work well or at all on some machines. With all - * padding zeroed like objects will compare byte for byte. - */ -struct load_command { - uint32_t cmd; /* type of load command */ - uint32_t cmdsize; /* total size of command in bytes */ -}; - -/* - * After MacOS X 10.1 when a new load command is added that is required to be - * understood by the dynamic linker for the image to execute properly the - * LC_REQ_DYLD bit will be or'ed into the load command constant. If the dynamic - * linker sees such a load command it it does not understand will issue a - * "unknown load command required for execution" error and refuse to use the - * image. Other load commands without this bit that are not understood will - * simply be ignored. - */ -#define LC_REQ_DYLD 0x80000000 - -/* Constants for the cmd field of all load commands, the type */ -#define LC_SEGMENT 0x1 /* segment of this file to be mapped */ -#define LC_SYMTAB 0x2 /* link-edit stab symbol table info */ -#define LC_SYMSEG 0x3 /* link-edit gdb symbol table info (obsolete) */ -#define LC_THREAD 0x4 /* thread */ -#define LC_UNIXTHREAD 0x5 /* unix thread (includes a stack) */ -#define LC_LOADFVMLIB 0x6 /* load a specified fixed VM shared library */ -#define LC_IDFVMLIB 0x7 /* fixed VM shared library identification */ -#define LC_IDENT 0x8 /* object identification info (obsolete) */ -#define LC_FVMFILE 0x9 /* fixed VM file inclusion (internal use) */ -#define LC_PREPAGE 0xa /* prepage command (internal use) */ -#define LC_DYSYMTAB 0xb /* dynamic link-edit symbol table info */ -#define LC_LOAD_DYLIB 0xc /* load a dynamically linked shared library */ -#define LC_ID_DYLIB 0xd /* dynamically linked shared lib ident */ -#define LC_LOAD_DYLINKER 0xe /* load a dynamic linker */ -#define LC_ID_DYLINKER 0xf /* dynamic linker identification */ -#define LC_PREBOUND_DYLIB 0x10 /* modules prebound for a dynamically */ - /* linked shared library */ -#define LC_ROUTINES 0x11 /* image routines */ -#define LC_SUB_FRAMEWORK 0x12 /* sub framework */ -#define LC_SUB_UMBRELLA 0x13 /* sub umbrella */ -#define LC_SUB_CLIENT 0x14 /* sub client */ -#define LC_SUB_LIBRARY 0x15 /* sub library */ -#define LC_TWOLEVEL_HINTS 0x16 /* two-level namespace lookup hints */ -#define LC_PREBIND_CKSUM 0x17 /* prebind checksum */ - -/* - * load a dynamically linked shared library that is allowed to be missing - * (all symbols are weak imported). - */ -#define LC_LOAD_WEAK_DYLIB (0x18 | LC_REQ_DYLD) - -#define LC_SEGMENT_64 0x19 /* 64-bit segment of this file to be - mapped */ -#define LC_ROUTINES_64 0x1a /* 64-bit image routines */ -#define LC_UUID 0x1b /* the uuid */ -#define LC_RPATH (0x1c | LC_REQ_DYLD) /* runpath additions */ -#define LC_CODE_SIGNATURE 0x1d /* local of code signature */ -#define LC_SEGMENT_SPLIT_INFO 0x1e /* local of info to split segments */ -#define LC_REEXPORT_DYLIB (0x1f | LC_REQ_DYLD) /* load and re-export dylib */ -#define LC_LAZY_LOAD_DYLIB 0x20 /* delay load of dylib until first use */ -#define LC_ENCRYPTION_INFO 0x21 /* encrypted segment information */ -#define LC_DYLD_INFO 0x22 /* compressed dyld information */ -#define LC_DYLD_INFO_ONLY (0x22|LC_REQ_DYLD) /* compressed dyld information only */ -#define LC_LOAD_UPWARD_DYLIB (0x23 | LC_REQ_DYLD) /* load upward dylib */ -#define LC_VERSION_MIN_MACOSX 0x24 /* build for MacOSX min OS version */ -#define LC_VERSION_MIN_IPHONEOS 0x25 /* build for iPhoneOS min OS version */ -#define LC_FUNCTION_STARTS 0x26 /* compressed table of function start addresses */ -#define LC_DYLD_ENVIRONMENT 0x27 /* string for dyld to treat - like environment variable */ -#define LC_MAIN (0x28|LC_REQ_DYLD) /* replacement for LC_UNIXTHREAD */ -#define LC_DATA_IN_CODE 0x29 /* table of non-instructions in __text */ -#define LC_SOURCE_VERSION 0x2A /* source version used to build binary */ -#define LC_DYLIB_CODE_SIGN_DRS 0x2B /* Code signing DRs copied from linked dylibs */ - - -/* - * A variable length string in a load command is represented by an lc_str - * union. The strings are stored just after the load command structure and - * the offset is from the start of the load command structure. The size - * of the string is reflected in the cmdsize field of the load command. - * Once again any padded bytes to bring the cmdsize field to a multiple - * of 4 bytes must be zero. - */ -union lc_str { - uint32_t offset; /* offset to the string */ -#ifndef __LP64__ - char *ptr; /* pointer to the string */ -#endif -}; - -/* - * The segment load command indicates that a part of this file is to be - * mapped into the task's address space. The size of this segment in memory, - * vmsize, maybe equal to or larger than the amount to map from this file, - * filesize. The file is mapped starting at fileoff to the beginning of - * the segment in memory, vmaddr. The rest of the memory of the segment, - * if any, is allocated zero fill on demand. The segment's maximum virtual - * memory protection and initial virtual memory protection are specified - * by the maxprot and initprot fields. If the segment has sections then the - * section structures directly follow the segment command and their size is - * reflected in cmdsize. - */ -struct segment_command { /* for 32-bit architectures */ - uint32_t cmd; /* LC_SEGMENT */ - uint32_t cmdsize; /* includes sizeof section structs */ - char segname[16]; /* segment name */ - uint32_t vmaddr; /* memory address of this segment */ - uint32_t vmsize; /* memory size of this segment */ - uint32_t fileoff; /* file offset of this segment */ - uint32_t filesize; /* amount to map from the file */ - vm_prot_t maxprot; /* maximum VM protection */ - vm_prot_t initprot; /* initial VM protection */ - uint32_t nsects; /* number of sections in segment */ - uint32_t flags; /* flags */ -}; - -/* - * The 64-bit segment load command indicates that a part of this file is to be - * mapped into a 64-bit task's address space. If the 64-bit segment has - * sections then section_64 structures directly follow the 64-bit segment - * command and their size is reflected in cmdsize. - */ -struct segment_command_64 { /* for 64-bit architectures */ - uint32_t cmd; /* LC_SEGMENT_64 */ - uint32_t cmdsize; /* includes sizeof section_64 structs */ - char segname[16]; /* segment name */ - uint64_t vmaddr; /* memory address of this segment */ - uint64_t vmsize; /* memory size of this segment */ - uint64_t fileoff; /* file offset of this segment */ - uint64_t filesize; /* amount to map from the file */ - vm_prot_t maxprot; /* maximum VM protection */ - vm_prot_t initprot; /* initial VM protection */ - uint32_t nsects; /* number of sections in segment */ - uint32_t flags; /* flags */ -}; - -/* Constants for the flags field of the segment_command */ -#define SG_HIGHVM 0x1 /* the file contents for this segment is for - the high part of the VM space, the low part - is zero filled (for stacks in core files) */ -#define SG_FVMLIB 0x2 /* this segment is the VM that is allocated by - a fixed VM library, for overlap checking in - the link editor */ -#define SG_NORELOC 0x4 /* this segment has nothing that was relocated - in it and nothing relocated to it, that is - it maybe safely replaced without relocation*/ -#define SG_PROTECTED_VERSION_1 0x8 /* This segment is protected. If the - segment starts at file offset 0, the - first page of the segment is not - protected. All other pages of the - segment are protected. */ - -/* - * A segment is made up of zero or more sections. Non-MH_OBJECT files have - * all of their segments with the proper sections in each, and padded to the - * specified segment alignment when produced by the link editor. The first - * segment of a MH_EXECUTE and MH_FVMLIB format file contains the mach_header - * and load commands of the object file before its first section. The zero - * fill sections are always last in their segment (in all formats). This - * allows the zeroed segment padding to be mapped into memory where zero fill - * sections might be. The gigabyte zero fill sections, those with the section - * type S_GB_ZEROFILL, can only be in a segment with sections of this type. - * These segments are then placed after all other segments. - * - * The MH_OBJECT format has all of its sections in one segment for - * compactness. There is no padding to a specified segment boundary and the - * mach_header and load commands are not part of the segment. - * - * Sections with the same section name, sectname, going into the same segment, - * segname, are combined by the link editor. The resulting section is aligned - * to the maximum alignment of the combined sections and is the new section's - * alignment. The combined sections are aligned to their original alignment in - * the combined section. Any padded bytes to get the specified alignment are - * zeroed. - * - * The format of the relocation entries referenced by the reloff and nreloc - * fields of the section structure for mach object files is described in the - * header file . - */ -struct section { /* for 32-bit architectures */ - char sectname[16]; /* name of this section */ - char segname[16]; /* segment this section goes in */ - uint32_t addr; /* memory address of this section */ - uint32_t size; /* size in bytes of this section */ - uint32_t offset; /* file offset of this section */ - uint32_t align; /* section alignment (power of 2) */ - uint32_t reloff; /* file offset of relocation entries */ - uint32_t nreloc; /* number of relocation entries */ - uint32_t flags; /* flags (section type and attributes)*/ - uint32_t reserved1; /* reserved (for offset or index) */ - uint32_t reserved2; /* reserved (for count or sizeof) */ -}; - -struct section_64 { /* for 64-bit architectures */ - char sectname[16]; /* name of this section */ - char segname[16]; /* segment this section goes in */ - uint64_t addr; /* memory address of this section */ - uint64_t size; /* size in bytes of this section */ - uint32_t offset; /* file offset of this section */ - uint32_t align; /* section alignment (power of 2) */ - uint32_t reloff; /* file offset of relocation entries */ - uint32_t nreloc; /* number of relocation entries */ - uint32_t flags; /* flags (section type and attributes)*/ - uint32_t reserved1; /* reserved (for offset or index) */ - uint32_t reserved2; /* reserved (for count or sizeof) */ - uint32_t reserved3; /* reserved */ -}; - -/* - * The flags field of a section structure is separated into two parts a section - * type and section attributes. The section types are mutually exclusive (it - * can only have one type) but the section attributes are not (it may have more - * than one attribute). - */ -#define SECTION_TYPE 0x000000ff /* 256 section types */ -#define SECTION_ATTRIBUTES 0xffffff00 /* 24 section attributes */ - -/* Constants for the type of a section */ -#define S_REGULAR 0x0 /* regular section */ -#define S_ZEROFILL 0x1 /* zero fill on demand section */ -#define S_CSTRING_LITERALS 0x2 /* section with only literal C strings*/ -#define S_4BYTE_LITERALS 0x3 /* section with only 4 byte literals */ -#define S_8BYTE_LITERALS 0x4 /* section with only 8 byte literals */ -#define S_LITERAL_POINTERS 0x5 /* section with only pointers to */ - /* literals */ -/* - * For the two types of symbol pointers sections and the symbol stubs section - * they have indirect symbol table entries. For each of the entries in the - * section the indirect symbol table entries, in corresponding order in the - * indirect symbol table, start at the index stored in the reserved1 field - * of the section structure. Since the indirect symbol table entries - * correspond to the entries in the section the number of indirect symbol table - * entries is inferred from the size of the section divided by the size of the - * entries in the section. For symbol pointers sections the size of the entries - * in the section is 4 bytes and for symbol stubs sections the byte size of the - * stubs is stored in the reserved2 field of the section structure. - */ -#define S_NON_LAZY_SYMBOL_POINTERS 0x6 /* section with only non-lazy - symbol pointers */ -#define S_LAZY_SYMBOL_POINTERS 0x7 /* section with only lazy symbol - pointers */ -#define S_SYMBOL_STUBS 0x8 /* section with only symbol - stubs, byte size of stub in - the reserved2 field */ -#define S_MOD_INIT_FUNC_POINTERS 0x9 /* section with only function - pointers for initialization*/ -#define S_MOD_TERM_FUNC_POINTERS 0xa /* section with only function - pointers for termination */ -#define S_COALESCED 0xb /* section contains symbols that - are to be coalesced */ -#define S_GB_ZEROFILL 0xc /* zero fill on demand section - (that can be larger than 4 - gigabytes) */ -#define S_INTERPOSING 0xd /* section with only pairs of - function pointers for - interposing */ -#define S_16BYTE_LITERALS 0xe /* section with only 16 byte - literals */ -#define S_DTRACE_DOF 0xf /* section contains - DTrace Object Format */ -#define S_LAZY_DYLIB_SYMBOL_POINTERS 0x10 /* section with only lazy - symbol pointers to lazy - loaded dylibs */ -/* - * Section types to support thread local variables - */ -#define S_THREAD_LOCAL_REGULAR 0x11 /* template of initial - values for TLVs */ -#define S_THREAD_LOCAL_ZEROFILL 0x12 /* template of initial - values for TLVs */ -#define S_THREAD_LOCAL_VARIABLES 0x13 /* TLV descriptors */ -#define S_THREAD_LOCAL_VARIABLE_POINTERS 0x14 /* pointers to TLV - descriptors */ -#define S_THREAD_LOCAL_INIT_FUNCTION_POINTERS 0x15 /* functions to call - to initialize TLV - values */ - -/* - * Constants for the section attributes part of the flags field of a section - * structure. - */ -#define SECTION_ATTRIBUTES_USR 0xff000000 /* User setable attributes */ -#define S_ATTR_PURE_INSTRUCTIONS 0x80000000 /* section contains only true - machine instructions */ -#define S_ATTR_NO_TOC 0x40000000 /* section contains coalesced - symbols that are not to be - in a ranlib table of - contents */ -#define S_ATTR_STRIP_STATIC_SYMS 0x20000000 /* ok to strip static symbols - in this section in files - with the MH_DYLDLINK flag */ -#define S_ATTR_NO_DEAD_STRIP 0x10000000 /* no dead stripping */ -#define S_ATTR_LIVE_SUPPORT 0x08000000 /* blocks are live if they - reference live blocks */ -#define S_ATTR_SELF_MODIFYING_CODE 0x04000000 /* Used with i386 code stubs - written on by dyld */ -/* - * If a segment contains any sections marked with S_ATTR_DEBUG then all - * sections in that segment must have this attribute. No section other than - * a section marked with this attribute may reference the contents of this - * section. A section with this attribute may contain no symbols and must have - * a section type S_REGULAR. The static linker will not copy section contents - * from sections with this attribute into its output file. These sections - * generally contain DWARF debugging info. - */ -#define S_ATTR_DEBUG 0x02000000 /* a debug section */ -#define SECTION_ATTRIBUTES_SYS 0x00ffff00 /* system setable attributes */ -#define S_ATTR_SOME_INSTRUCTIONS 0x00000400 /* section contains some - machine instructions */ -#define S_ATTR_EXT_RELOC 0x00000200 /* section has external - relocation entries */ -#define S_ATTR_LOC_RELOC 0x00000100 /* section has local - relocation entries */ - - -/* - * The names of segments and sections in them are mostly meaningless to the - * link-editor. But there are few things to support traditional UNIX - * executables that require the link-editor and assembler to use some names - * agreed upon by convention. - * - * The initial protection of the "__TEXT" segment has write protection turned - * off (not writeable). - * - * The link-editor will allocate common symbols at the end of the "__common" - * section in the "__DATA" segment. It will create the section and segment - * if needed. - */ - -/* The currently known segment names and the section names in those segments */ - -#define SEG_PAGEZERO "__PAGEZERO" /* the pagezero segment which has no */ - /* protections and catches NULL */ - /* references for MH_EXECUTE files */ - - -#define SEG_TEXT "__TEXT" /* the tradition UNIX text segment */ -#define SECT_TEXT "__text" /* the real text part of the text */ - /* section no headers, and no padding */ -#define SECT_FVMLIB_INIT0 "__fvmlib_init0" /* the fvmlib initialization */ - /* section */ -#define SECT_FVMLIB_INIT1 "__fvmlib_init1" /* the section following the */ - /* fvmlib initialization */ - /* section */ - -#define SEG_DATA "__DATA" /* the tradition UNIX data segment */ -#define SECT_DATA "__data" /* the real initialized data section */ - /* no padding, no bss overlap */ -#define SECT_BSS "__bss" /* the real uninitialized data section*/ - /* no padding */ -#define SECT_COMMON "__common" /* the section common symbols are */ - /* allocated in by the link editor */ - -#define SEG_OBJC "__OBJC" /* objective-C runtime segment */ -#define SECT_OBJC_SYMBOLS "__symbol_table" /* symbol table */ -#define SECT_OBJC_MODULES "__module_info" /* module information */ -#define SECT_OBJC_STRINGS "__selector_strs" /* string table */ -#define SECT_OBJC_REFS "__selector_refs" /* string table */ - -#define SEG_ICON "__ICON" /* the icon segment */ -#define SECT_ICON_HEADER "__header" /* the icon headers */ -#define SECT_ICON_TIFF "__tiff" /* the icons in tiff format */ - -#define SEG_LINKEDIT "__LINKEDIT" /* the segment containing all structs */ - /* created and maintained by the link */ - /* editor. Created with -seglinkedit */ - /* option to ld(1) for MH_EXECUTE and */ - /* FVMLIB file types only */ - -#define SEG_UNIXSTACK "__UNIXSTACK" /* the unix stack segment */ - -#define SEG_IMPORT "__IMPORT" /* the segment for the self (dyld) */ - /* modifing code stubs that has read, */ - /* write and execute permissions */ - -/* - * Fixed virtual memory shared libraries are identified by two things. The - * target pathname (the name of the library as found for execution), and the - * minor version number. The address of where the headers are loaded is in - * header_addr. (THIS IS OBSOLETE and no longer supported). - */ -struct fvmlib { - union lc_str name; /* library's target pathname */ - uint32_t minor_version; /* library's minor version number */ - uint32_t header_addr; /* library's header address */ -}; - -/* - * A fixed virtual shared library (filetype == MH_FVMLIB in the mach header) - * contains a fvmlib_command (cmd == LC_IDFVMLIB) to identify the library. - * An object that uses a fixed virtual shared library also contains a - * fvmlib_command (cmd == LC_LOADFVMLIB) for each library it uses. - * (THIS IS OBSOLETE and no longer supported). - */ -struct fvmlib_command { - uint32_t cmd; /* LC_IDFVMLIB or LC_LOADFVMLIB */ - uint32_t cmdsize; /* includes pathname string */ - struct fvmlib fvmlib; /* the library identification */ -}; - -/* - * Dynamicly linked shared libraries are identified by two things. The - * pathname (the name of the library as found for execution), and the - * compatibility version number. The pathname must match and the compatibility - * number in the user of the library must be greater than or equal to the - * library being used. The time stamp is used to record the time a library was - * built and copied into user so it can be use to determined if the library used - * at runtime is exactly the same as used to built the program. - */ -struct dylib { - union lc_str name; /* library's path name */ - uint32_t timestamp; /* library's build time stamp */ - uint32_t current_version; /* library's current version number */ - uint32_t compatibility_version; /* library's compatibility vers number*/ -}; - -/* - * A dynamically linked shared library (filetype == MH_DYLIB in the mach header) - * contains a dylib_command (cmd == LC_ID_DYLIB) to identify the library. - * An object that uses a dynamically linked shared library also contains a - * dylib_command (cmd == LC_LOAD_DYLIB, LC_LOAD_WEAK_DYLIB, or - * LC_REEXPORT_DYLIB) for each library it uses. - */ -struct dylib_command { - uint32_t cmd; /* LC_ID_DYLIB, LC_LOAD_{,WEAK_}DYLIB, - LC_REEXPORT_DYLIB */ - uint32_t cmdsize; /* includes pathname string */ - struct dylib dylib; /* the library identification */ -}; - -/* - * A dynamically linked shared library may be a subframework of an umbrella - * framework. If so it will be linked with "-umbrella umbrella_name" where - * Where "umbrella_name" is the name of the umbrella framework. A subframework - * can only be linked against by its umbrella framework or other subframeworks - * that are part of the same umbrella framework. Otherwise the static link - * editor produces an error and states to link against the umbrella framework. - * The name of the umbrella framework for subframeworks is recorded in the - * following structure. - */ -struct sub_framework_command { - uint32_t cmd; /* LC_SUB_FRAMEWORK */ - uint32_t cmdsize; /* includes umbrella string */ - union lc_str umbrella; /* the umbrella framework name */ -}; - -/* - * For dynamically linked shared libraries that are subframework of an umbrella - * framework they can allow clients other than the umbrella framework or other - * subframeworks in the same umbrella framework. To do this the subframework - * is built with "-allowable_client client_name" and an LC_SUB_CLIENT load - * command is created for each -allowable_client flag. The client_name is - * usually a framework name. It can also be a name used for bundles clients - * where the bundle is built with "-client_name client_name". - */ -struct sub_client_command { - uint32_t cmd; /* LC_SUB_CLIENT */ - uint32_t cmdsize; /* includes client string */ - union lc_str client; /* the client name */ -}; - -/* - * A dynamically linked shared library may be a sub_umbrella of an umbrella - * framework. If so it will be linked with "-sub_umbrella umbrella_name" where - * Where "umbrella_name" is the name of the sub_umbrella framework. When - * staticly linking when -twolevel_namespace is in effect a twolevel namespace - * umbrella framework will only cause its subframeworks and those frameworks - * listed as sub_umbrella frameworks to be implicited linked in. Any other - * dependent dynamic libraries will not be linked it when -twolevel_namespace - * is in effect. The primary library recorded by the static linker when - * resolving a symbol in these libraries will be the umbrella framework. - * Zero or more sub_umbrella frameworks may be use by an umbrella framework. - * The name of a sub_umbrella framework is recorded in the following structure. - */ -struct sub_umbrella_command { - uint32_t cmd; /* LC_SUB_UMBRELLA */ - uint32_t cmdsize; /* includes sub_umbrella string */ - union lc_str sub_umbrella; /* the sub_umbrella framework name */ -}; - -/* - * A dynamically linked shared library may be a sub_library of another shared - * library. If so it will be linked with "-sub_library library_name" where - * Where "library_name" is the name of the sub_library shared library. When - * staticly linking when -twolevel_namespace is in effect a twolevel namespace - * shared library will only cause its subframeworks and those frameworks - * listed as sub_umbrella frameworks and libraries listed as sub_libraries to - * be implicited linked in. Any other dependent dynamic libraries will not be - * linked it when -twolevel_namespace is in effect. The primary library - * recorded by the static linker when resolving a symbol in these libraries - * will be the umbrella framework (or dynamic library). Zero or more sub_library - * shared libraries may be use by an umbrella framework or (or dynamic library). - * The name of a sub_library framework is recorded in the following structure. - * For example /usr/lib/libobjc_profile.A.dylib would be recorded as "libobjc". - */ -struct sub_library_command { - uint32_t cmd; /* LC_SUB_LIBRARY */ - uint32_t cmdsize; /* includes sub_library string */ - union lc_str sub_library; /* the sub_library name */ -}; - -/* - * A program (filetype == MH_EXECUTE) that is - * prebound to its dynamic libraries has one of these for each library that - * the static linker used in prebinding. It contains a bit vector for the - * modules in the library. The bits indicate which modules are bound (1) and - * which are not (0) from the library. The bit for module 0 is the low bit - * of the first byte. So the bit for the Nth module is: - * (linked_modules[N/8] >> N%8) & 1 - */ -struct prebound_dylib_command { - uint32_t cmd; /* LC_PREBOUND_DYLIB */ - uint32_t cmdsize; /* includes strings */ - union lc_str name; /* library's path name */ - uint32_t nmodules; /* number of modules in library */ - union lc_str linked_modules; /* bit vector of linked modules */ -}; - -/* - * A program that uses a dynamic linker contains a dylinker_command to identify - * the name of the dynamic linker (LC_LOAD_DYLINKER). And a dynamic linker - * contains a dylinker_command to identify the dynamic linker (LC_ID_DYLINKER). - * A file can have at most one of these. - * This struct is also used for the LC_DYLD_ENVIRONMENT load command and - * contains string for dyld to treat like environment variable. - */ -struct dylinker_command { - uint32_t cmd; /* LC_ID_DYLINKER, LC_LOAD_DYLINKER or - LC_DYLD_ENVIRONMENT */ - uint32_t cmdsize; /* includes pathname string */ - union lc_str name; /* dynamic linker's path name */ -}; - -/* - * Thread commands contain machine-specific data structures suitable for - * use in the thread state primitives. The machine specific data structures - * follow the struct thread_command as follows. - * Each flavor of machine specific data structure is preceded by an unsigned - * long constant for the flavor of that data structure, an uint32_t - * that is the count of longs of the size of the state data structure and then - * the state data structure follows. This triple may be repeated for many - * flavors. The constants for the flavors, counts and state data structure - * definitions are expected to be in the header file . - * These machine specific data structures sizes must be multiples of - * 4 bytes The cmdsize reflects the total size of the thread_command - * and all of the sizes of the constants for the flavors, counts and state - * data structures. - * - * For executable objects that are unix processes there will be one - * thread_command (cmd == LC_UNIXTHREAD) created for it by the link-editor. - * This is the same as a LC_THREAD, except that a stack is automatically - * created (based on the shell's limit for the stack size). Command arguments - * and environment variables are copied onto that stack. - */ -struct thread_command { - uint32_t cmd; /* LC_THREAD or LC_UNIXTHREAD */ - uint32_t cmdsize; /* total size of this command */ - /* uint32_t flavor flavor of thread state */ - /* uint32_t count count of longs in thread state */ - /* struct XXX_thread_state state thread state for this flavor */ - /* ... */ -}; - -/* - * The routines command contains the address of the dynamic shared library - * initialization routine and an index into the module table for the module - * that defines the routine. Before any modules are used from the library the - * dynamic linker fully binds the module that defines the initialization routine - * and then calls it. This gets called before any module initialization - * routines (used for C++ static constructors) in the library. - */ -struct routines_command { /* for 32-bit architectures */ - uint32_t cmd; /* LC_ROUTINES */ - uint32_t cmdsize; /* total size of this command */ - uint32_t init_address; /* address of initialization routine */ - uint32_t init_module; /* index into the module table that */ - /* the init routine is defined in */ - uint32_t reserved1; - uint32_t reserved2; - uint32_t reserved3; - uint32_t reserved4; - uint32_t reserved5; - uint32_t reserved6; -}; - -/* - * The 64-bit routines command. Same use as above. - */ -struct routines_command_64 { /* for 64-bit architectures */ - uint32_t cmd; /* LC_ROUTINES_64 */ - uint32_t cmdsize; /* total size of this command */ - uint64_t init_address; /* address of initialization routine */ - uint64_t init_module; /* index into the module table that */ - /* the init routine is defined in */ - uint64_t reserved1; - uint64_t reserved2; - uint64_t reserved3; - uint64_t reserved4; - uint64_t reserved5; - uint64_t reserved6; -}; - -/* - * The symtab_command contains the offsets and sizes of the link-edit 4.3BSD - * "stab" style symbol table information as described in the header files - * and . - */ -struct symtab_command { - uint32_t cmd; /* LC_SYMTAB */ - uint32_t cmdsize; /* sizeof(struct symtab_command) */ - uint32_t symoff; /* symbol table offset */ - uint32_t nsyms; /* number of symbol table entries */ - uint32_t stroff; /* string table offset */ - uint32_t strsize; /* string table size in bytes */ -}; - -/* - * This is the second set of the symbolic information which is used to support - * the data structures for the dynamically link editor. - * - * The original set of symbolic information in the symtab_command which contains - * the symbol and string tables must also be present when this load command is - * present. When this load command is present the symbol table is organized - * into three groups of symbols: - * local symbols (static and debugging symbols) - grouped by module - * defined external symbols - grouped by module (sorted by name if not lib) - * undefined external symbols (sorted by name if MH_BINDATLOAD is not set, - * and in order the were seen by the static - * linker if MH_BINDATLOAD is set) - * In this load command there are offsets and counts to each of the three groups - * of symbols. - * - * This load command contains a the offsets and sizes of the following new - * symbolic information tables: - * table of contents - * module table - * reference symbol table - * indirect symbol table - * The first three tables above (the table of contents, module table and - * reference symbol table) are only present if the file is a dynamically linked - * shared library. For executable and object modules, which are files - * containing only one module, the information that would be in these three - * tables is determined as follows: - * table of contents - the defined external symbols are sorted by name - * module table - the file contains only one module so everything in the - * file is part of the module. - * reference symbol table - is the defined and undefined external symbols - * - * For dynamically linked shared library files this load command also contains - * offsets and sizes to the pool of relocation entries for all sections - * separated into two groups: - * external relocation entries - * local relocation entries - * For executable and object modules the relocation entries continue to hang - * off the section structures. - */ -struct dysymtab_command { - uint32_t cmd; /* LC_DYSYMTAB */ - uint32_t cmdsize; /* sizeof(struct dysymtab_command) */ - - /* - * The symbols indicated by symoff and nsyms of the LC_SYMTAB load command - * are grouped into the following three groups: - * local symbols (further grouped by the module they are from) - * defined external symbols (further grouped by the module they are from) - * undefined symbols - * - * The local symbols are used only for debugging. The dynamic binding - * process may have to use them to indicate to the debugger the local - * symbols for a module that is being bound. - * - * The last two groups are used by the dynamic binding process to do the - * binding (indirectly through the module table and the reference symbol - * table when this is a dynamically linked shared library file). - */ - uint32_t ilocalsym; /* index to local symbols */ - uint32_t nlocalsym; /* number of local symbols */ - - uint32_t iextdefsym;/* index to externally defined symbols */ - uint32_t nextdefsym;/* number of externally defined symbols */ - - uint32_t iundefsym; /* index to undefined symbols */ - uint32_t nundefsym; /* number of undefined symbols */ - - /* - * For the for the dynamic binding process to find which module a symbol - * is defined in the table of contents is used (analogous to the ranlib - * structure in an archive) which maps defined external symbols to modules - * they are defined in. This exists only in a dynamically linked shared - * library file. For executable and object modules the defined external - * symbols are sorted by name and is use as the table of contents. - */ - uint32_t tocoff; /* file offset to table of contents */ - uint32_t ntoc; /* number of entries in table of contents */ - - /* - * To support dynamic binding of "modules" (whole object files) the symbol - * table must reflect the modules that the file was created from. This is - * done by having a module table that has indexes and counts into the merged - * tables for each module. The module structure that these two entries - * refer to is described below. This exists only in a dynamically linked - * shared library file. For executable and object modules the file only - * contains one module so everything in the file belongs to the module. - */ - uint32_t modtaboff; /* file offset to module table */ - uint32_t nmodtab; /* number of module table entries */ - - /* - * To support dynamic module binding the module structure for each module - * indicates the external references (defined and undefined) each module - * makes. For each module there is an offset and a count into the - * reference symbol table for the symbols that the module references. - * This exists only in a dynamically linked shared library file. For - * executable and object modules the defined external symbols and the - * undefined external symbols indicates the external references. - */ - uint32_t extrefsymoff; /* offset to referenced symbol table */ - uint32_t nextrefsyms; /* number of referenced symbol table entries */ - - /* - * The sections that contain "symbol pointers" and "routine stubs" have - * indexes and (implied counts based on the size of the section and fixed - * size of the entry) into the "indirect symbol" table for each pointer - * and stub. For every section of these two types the index into the - * indirect symbol table is stored in the section header in the field - * reserved1. An indirect symbol table entry is simply a 32bit index into - * the symbol table to the symbol that the pointer or stub is referring to. - * The indirect symbol table is ordered to match the entries in the section. - */ - uint32_t indirectsymoff; /* file offset to the indirect symbol table */ - uint32_t nindirectsyms; /* number of indirect symbol table entries */ - - /* - * To support relocating an individual module in a library file quickly the - * external relocation entries for each module in the library need to be - * accessed efficiently. Since the relocation entries can't be accessed - * through the section headers for a library file they are separated into - * groups of local and external entries further grouped by module. In this - * case the presents of this load command who's extreloff, nextrel, - * locreloff and nlocrel fields are non-zero indicates that the relocation - * entries of non-merged sections are not referenced through the section - * structures (and the reloff and nreloc fields in the section headers are - * set to zero). - * - * Since the relocation entries are not accessed through the section headers - * this requires the r_address field to be something other than a section - * offset to identify the item to be relocated. In this case r_address is - * set to the offset from the vmaddr of the first LC_SEGMENT command. - * For MH_SPLIT_SEGS images r_address is set to the the offset from the - * vmaddr of the first read-write LC_SEGMENT command. - * - * The relocation entries are grouped by module and the module table - * entries have indexes and counts into them for the group of external - * relocation entries for that the module. - * - * For sections that are merged across modules there must not be any - * remaining external relocation entries for them (for merged sections - * remaining relocation entries must be local). - */ - uint32_t extreloff; /* offset to external relocation entries */ - uint32_t nextrel; /* number of external relocation entries */ - - /* - * All the local relocation entries are grouped together (they are not - * grouped by their module since they are only used if the object is moved - * from it staticly link edited address). - */ - uint32_t locreloff; /* offset to local relocation entries */ - uint32_t nlocrel; /* number of local relocation entries */ - -}; - -/* - * An indirect symbol table entry is simply a 32bit index into the symbol table - * to the symbol that the pointer or stub is refering to. Unless it is for a - * non-lazy symbol pointer section for a defined symbol which strip(1) as - * removed. In which case it has the value INDIRECT_SYMBOL_LOCAL. If the - * symbol was also absolute INDIRECT_SYMBOL_ABS is or'ed with that. - */ -#define INDIRECT_SYMBOL_LOCAL 0x80000000 -#define INDIRECT_SYMBOL_ABS 0x40000000 - - -/* a table of contents entry */ -struct dylib_table_of_contents { - uint32_t symbol_index; /* the defined external symbol - (index into the symbol table) */ - uint32_t module_index; /* index into the module table this symbol - is defined in */ -}; - -/* a module table entry */ -struct dylib_module { - uint32_t module_name; /* the module name (index into string table) */ - - uint32_t iextdefsym; /* index into externally defined symbols */ - uint32_t nextdefsym; /* number of externally defined symbols */ - uint32_t irefsym; /* index into reference symbol table */ - uint32_t nrefsym; /* number of reference symbol table entries */ - uint32_t ilocalsym; /* index into symbols for local symbols */ - uint32_t nlocalsym; /* number of local symbols */ - - uint32_t iextrel; /* index into external relocation entries */ - uint32_t nextrel; /* number of external relocation entries */ - - uint32_t iinit_iterm; /* low 16 bits are the index into the init - section, high 16 bits are the index into - the term section */ - uint32_t ninit_nterm; /* low 16 bits are the number of init section - entries, high 16 bits are the number of - term section entries */ - - uint32_t /* for this module address of the start of */ - objc_module_info_addr; /* the (__OBJC,__module_info) section */ - uint32_t /* for this module size of */ - objc_module_info_size; /* the (__OBJC,__module_info) section */ -}; - -/* a 64-bit module table entry */ -struct dylib_module_64 { - uint32_t module_name; /* the module name (index into string table) */ - - uint32_t iextdefsym; /* index into externally defined symbols */ - uint32_t nextdefsym; /* number of externally defined symbols */ - uint32_t irefsym; /* index into reference symbol table */ - uint32_t nrefsym; /* number of reference symbol table entries */ - uint32_t ilocalsym; /* index into symbols for local symbols */ - uint32_t nlocalsym; /* number of local symbols */ - - uint32_t iextrel; /* index into external relocation entries */ - uint32_t nextrel; /* number of external relocation entries */ - - uint32_t iinit_iterm; /* low 16 bits are the index into the init - section, high 16 bits are the index into - the term section */ - uint32_t ninit_nterm; /* low 16 bits are the number of init section - entries, high 16 bits are the number of - term section entries */ - - uint32_t /* for this module size of */ - objc_module_info_size; /* the (__OBJC,__module_info) section */ - uint64_t /* for this module address of the start of */ - objc_module_info_addr; /* the (__OBJC,__module_info) section */ -}; - -/* - * The entries in the reference symbol table are used when loading the module - * (both by the static and dynamic link editors) and if the module is unloaded - * or replaced. Therefore all external symbols (defined and undefined) are - * listed in the module's reference table. The flags describe the type of - * reference that is being made. The constants for the flags are defined in - * as they are also used for symbol table entries. - */ -struct dylib_reference { - uint32_t isym:24, /* index into the symbol table */ - flags:8; /* flags to indicate the type of reference */ -}; - -/* - * The twolevel_hints_command contains the offset and number of hints in the - * two-level namespace lookup hints table. - */ -struct twolevel_hints_command { - uint32_t cmd; /* LC_TWOLEVEL_HINTS */ - uint32_t cmdsize; /* sizeof(struct twolevel_hints_command) */ - uint32_t offset; /* offset to the hint table */ - uint32_t nhints; /* number of hints in the hint table */ -}; - -/* - * The entries in the two-level namespace lookup hints table are twolevel_hint - * structs. These provide hints to the dynamic link editor where to start - * looking for an undefined symbol in a two-level namespace image. The - * isub_image field is an index into the sub-images (sub-frameworks and - * sub-umbrellas list) that made up the two-level image that the undefined - * symbol was found in when it was built by the static link editor. If - * isub-image is 0 the the symbol is expected to be defined in library and not - * in the sub-images. If isub-image is non-zero it is an index into the array - * of sub-images for the umbrella with the first index in the sub-images being - * 1. The array of sub-images is the ordered list of sub-images of the umbrella - * that would be searched for a symbol that has the umbrella recorded as its - * primary library. The table of contents index is an index into the - * library's table of contents. This is used as the starting point of the - * binary search or a directed linear search. - */ -struct twolevel_hint { - uint32_t - isub_image:8, /* index into the sub images */ - itoc:24; /* index into the table of contents */ -}; - -/* - * The prebind_cksum_command contains the value of the original check sum for - * prebound files or zero. When a prebound file is first created or modified - * for other than updating its prebinding information the value of the check sum - * is set to zero. When the file has it prebinding re-done and if the value of - * the check sum is zero the original check sum is calculated and stored in - * cksum field of this load command in the output file. If when the prebinding - * is re-done and the cksum field is non-zero it is left unchanged from the - * input file. - */ -struct prebind_cksum_command { - uint32_t cmd; /* LC_PREBIND_CKSUM */ - uint32_t cmdsize; /* sizeof(struct prebind_cksum_command) */ - uint32_t cksum; /* the check sum or zero */ -}; - -/* - * The uuid load command contains a single 128-bit unique random number that - * identifies an object produced by the static link editor. - */ -struct uuid_command { - uint32_t cmd; /* LC_UUID */ - uint32_t cmdsize; /* sizeof(struct uuid_command) */ - uint8_t uuid[16]; /* the 128-bit uuid */ -}; - -/* - * The rpath_command contains a path which at runtime should be added to - * the current run path used to find @rpath prefixed dylibs. - */ -struct rpath_command { - uint32_t cmd; /* LC_RPATH */ - uint32_t cmdsize; /* includes string */ - union lc_str path; /* path to add to run path */ -}; - -/* - * The linkedit_data_command contains the offsets and sizes of a blob - * of data in the __LINKEDIT segment. - */ -struct linkedit_data_command { - uint32_t cmd; /* LC_CODE_SIGNATURE, LC_SEGMENT_SPLIT_INFO, - LC_FUNCTION_STARTS, LC_DATA_IN_CODE, - or LC_DYLIB_CODE_SIGN_DRS */ - uint32_t cmdsize; /* sizeof(struct linkedit_data_command) */ - uint32_t dataoff; /* file offset of data in __LINKEDIT segment */ - uint32_t datasize; /* file size of data in __LINKEDIT segment */ -}; - -/* - * The encryption_info_command contains the file offset and size of an - * of an encrypted segment. - */ -struct encryption_info_command { - uint32_t cmd; /* LC_ENCRYPTION_INFO */ - uint32_t cmdsize; /* sizeof(struct encryption_info_command) */ - uint32_t cryptoff; /* file offset of encrypted range */ - uint32_t cryptsize; /* file size of encrypted range */ - uint32_t cryptid; /* which enryption system, - 0 means not-encrypted yet */ -}; - -/* - * The version_min_command contains the min OS version on which this - * binary was built to run. - */ -struct version_min_command { - uint32_t cmd; /* LC_VERSION_MIN_MACOSX or - LC_VERSION_MIN_IPHONEOS */ - uint32_t cmdsize; /* sizeof(struct min_version_command) */ - uint32_t version; /* X.Y.Z is encoded in nibbles xxxx.yy.zz */ - uint32_t sdk; /* X.Y.Z is encoded in nibbles xxxx.yy.zz */ -}; - -/* - * The dyld_info_command contains the file offsets and sizes of - * the new compressed form of the information dyld needs to - * load the image. This information is used by dyld on Mac OS X - * 10.6 and later. All information pointed to by this command - * is encoded using byte streams, so no endian swapping is needed - * to interpret it. - */ -struct dyld_info_command { - uint32_t cmd; /* LC_DYLD_INFO or LC_DYLD_INFO_ONLY */ - uint32_t cmdsize; /* sizeof(struct dyld_info_command) */ - - /* - * Dyld rebases an image whenever dyld loads it at an address different - * from its preferred address. The rebase information is a stream - * of byte sized opcodes whose symbolic names start with REBASE_OPCODE_. - * Conceptually the rebase information is a table of tuples: - * - * The opcodes are a compressed way to encode the table by only - * encoding when a column changes. In addition simple patterns - * like "every n'th offset for m times" can be encoded in a few - * bytes. - */ - uint32_t rebase_off; /* file offset to rebase info */ - uint32_t rebase_size; /* size of rebase info */ - - /* - * Dyld binds an image during the loading process, if the image - * requires any pointers to be initialized to symbols in other images. - * The bind information is a stream of byte sized - * opcodes whose symbolic names start with BIND_OPCODE_. - * Conceptually the bind information is a table of tuples: - * - * The opcodes are a compressed way to encode the table by only - * encoding when a column changes. In addition simple patterns - * like for runs of pointers initialzed to the same value can be - * encoded in a few bytes. - */ - uint32_t bind_off; /* file offset to binding info */ - uint32_t bind_size; /* size of binding info */ - - /* - * Some C++ programs require dyld to unique symbols so that all - * images in the process use the same copy of some code/data. - * This step is done after binding. The content of the weak_bind - * info is an opcode stream like the bind_info. But it is sorted - * alphabetically by symbol name. This enable dyld to walk - * all images with weak binding information in order and look - * for collisions. If there are no collisions, dyld does - * no updating. That means that some fixups are also encoded - * in the bind_info. For instance, all calls to "operator new" - * are first bound to libstdc++.dylib using the information - * in bind_info. Then if some image overrides operator new - * that is detected when the weak_bind information is processed - * and the call to operator new is then rebound. - */ - uint32_t weak_bind_off; /* file offset to weak binding info */ - uint32_t weak_bind_size; /* size of weak binding info */ - - /* - * Some uses of external symbols do not need to be bound immediately. - * Instead they can be lazily bound on first use. The lazy_bind - * are contains a stream of BIND opcodes to bind all lazy symbols. - * Normal use is that dyld ignores the lazy_bind section when - * loading an image. Instead the static linker arranged for the - * lazy pointer to initially point to a helper function which - * pushes the offset into the lazy_bind area for the symbol - * needing to be bound, then jumps to dyld which simply adds - * the offset to lazy_bind_off to get the information on what - * to bind. - */ - uint32_t lazy_bind_off; /* file offset to lazy binding info */ - uint32_t lazy_bind_size; /* size of lazy binding infs */ - - /* - * The symbols exported by a dylib are encoded in a trie. This - * is a compact representation that factors out common prefixes. - * It also reduces LINKEDIT pages in RAM because it encodes all - * information (name, address, flags) in one small, contiguous range. - * The export area is a stream of nodes. The first node sequentially - * is the start node for the trie. - * - * Nodes for a symbol start with a uleb128 that is the length of - * the exported symbol information for the string so far. - * If there is no exported symbol, the node starts with a zero byte. - * If there is exported info, it follows the length. - * - * First is a uleb128 containing flags. Normally, it is followed by - * a uleb128 encoded offset which is location of the content named - * by the symbol from the mach_header for the image. If the flags - * is EXPORT_SYMBOL_FLAGS_REEXPORT, then following the flags is - * a uleb128 encoded library ordinal, then a zero terminated - * UTF8 string. If the string is zero length, then the symbol - * is re-export from the specified dylib with the same name. - * If the flags is EXPORT_SYMBOL_FLAGS_STUB_AND_RESOLVER, then following - * the flags is two uleb128s: the stub offset and the resolver offset. - * The stub is used by non-lazy pointers. The resolver is used - * by lazy pointers and must be called to get the actual address to use. - * - * After the optional exported symbol information is a byte of - * how many edges (0-255) that this node has leaving it, - * followed by each edge. - * Each edge is a zero terminated UTF8 of the addition chars - * in the symbol, followed by a uleb128 offset for the node that - * edge points to. - * - */ - uint32_t export_off; /* file offset to lazy binding info */ - uint32_t export_size; /* size of lazy binding infs */ -}; - -/* - * The following are used to encode rebasing information - */ -#define REBASE_TYPE_POINTER 1 -#define REBASE_TYPE_TEXT_ABSOLUTE32 2 -#define REBASE_TYPE_TEXT_PCREL32 3 - -#define REBASE_OPCODE_MASK 0xF0 -#define REBASE_IMMEDIATE_MASK 0x0F -#define REBASE_OPCODE_DONE 0x00 -#define REBASE_OPCODE_SET_TYPE_IMM 0x10 -#define REBASE_OPCODE_SET_SEGMENT_AND_OFFSET_ULEB 0x20 -#define REBASE_OPCODE_ADD_ADDR_ULEB 0x30 -#define REBASE_OPCODE_ADD_ADDR_IMM_SCALED 0x40 -#define REBASE_OPCODE_DO_REBASE_IMM_TIMES 0x50 -#define REBASE_OPCODE_DO_REBASE_ULEB_TIMES 0x60 -#define REBASE_OPCODE_DO_REBASE_ADD_ADDR_ULEB 0x70 -#define REBASE_OPCODE_DO_REBASE_ULEB_TIMES_SKIPPING_ULEB 0x80 - - -/* - * The following are used to encode binding information - */ -#define BIND_TYPE_POINTER 1 -#define BIND_TYPE_TEXT_ABSOLUTE32 2 -#define BIND_TYPE_TEXT_PCREL32 3 - -#define BIND_SPECIAL_DYLIB_SELF 0 -#define BIND_SPECIAL_DYLIB_MAIN_EXECUTABLE -1 -#define BIND_SPECIAL_DYLIB_FLAT_LOOKUP -2 - -#define BIND_SYMBOL_FLAGS_WEAK_IMPORT 0x1 -#define BIND_SYMBOL_FLAGS_NON_WEAK_DEFINITION 0x8 - -#define BIND_OPCODE_MASK 0xF0 -#define BIND_IMMEDIATE_MASK 0x0F -#define BIND_OPCODE_DONE 0x00 -#define BIND_OPCODE_SET_DYLIB_ORDINAL_IMM 0x10 -#define BIND_OPCODE_SET_DYLIB_ORDINAL_ULEB 0x20 -#define BIND_OPCODE_SET_DYLIB_SPECIAL_IMM 0x30 -#define BIND_OPCODE_SET_SYMBOL_TRAILING_FLAGS_IMM 0x40 -#define BIND_OPCODE_SET_TYPE_IMM 0x50 -#define BIND_OPCODE_SET_ADDEND_SLEB 0x60 -#define BIND_OPCODE_SET_SEGMENT_AND_OFFSET_ULEB 0x70 -#define BIND_OPCODE_ADD_ADDR_ULEB 0x80 -#define BIND_OPCODE_DO_BIND 0x90 -#define BIND_OPCODE_DO_BIND_ADD_ADDR_ULEB 0xA0 -#define BIND_OPCODE_DO_BIND_ADD_ADDR_IMM_SCALED 0xB0 -#define BIND_OPCODE_DO_BIND_ULEB_TIMES_SKIPPING_ULEB 0xC0 - - -/* - * The following are used on the flags byte of a terminal node - * in the export information. - */ -#define EXPORT_SYMBOL_FLAGS_KIND_MASK 0x03 -#define EXPORT_SYMBOL_FLAGS_KIND_REGULAR 0x00 -#define EXPORT_SYMBOL_FLAGS_KIND_THREAD_LOCAL 0x01 -#define EXPORT_SYMBOL_FLAGS_WEAK_DEFINITION 0x04 -#define EXPORT_SYMBOL_FLAGS_REEXPORT 0x08 -#define EXPORT_SYMBOL_FLAGS_STUB_AND_RESOLVER 0x10 - -/* - * The symseg_command contains the offset and size of the GNU style - * symbol table information as described in the header file . - * The symbol roots of the symbol segments must also be aligned properly - * in the file. So the requirement of keeping the offsets aligned to a - * multiple of a 4 bytes translates to the length field of the symbol - * roots also being a multiple of a long. Also the padding must again be - * zeroed. (THIS IS OBSOLETE and no longer supported). - */ -struct symseg_command { - uint32_t cmd; /* LC_SYMSEG */ - uint32_t cmdsize; /* sizeof(struct symseg_command) */ - uint32_t offset; /* symbol segment offset */ - uint32_t size; /* symbol segment size in bytes */ -}; - -/* - * The ident_command contains a free format string table following the - * ident_command structure. The strings are null terminated and the size of - * the command is padded out with zero bytes to a multiple of 4 bytes/ - * (THIS IS OBSOLETE and no longer supported). - */ -struct ident_command { - uint32_t cmd; /* LC_IDENT */ - uint32_t cmdsize; /* strings that follow this command */ -}; - -/* - * The fvmfile_command contains a reference to a file to be loaded at the - * specified virtual address. (Presently, this command is reserved for - * internal use. The kernel ignores this command when loading a program into - * memory). - */ -struct fvmfile_command { - uint32_t cmd; /* LC_FVMFILE */ - uint32_t cmdsize; /* includes pathname string */ - union lc_str name; /* files pathname */ - uint32_t header_addr; /* files virtual address */ -}; - - -/* - * The entry_point_command is a replacement for thread_command. - * It is used for main executables to specify the location (file offset) - * of main(). If -stack_size was used at link time, the stacksize - * field will contain the stack size need for the main thread. - */ -struct entry_point_command { - uint32_t cmd; /* LC_MAIN only used in MH_EXECUTE filetypes */ - uint32_t cmdsize; /* 24 */ - uint64_t entryoff; /* file (__TEXT) offset of main() */ - uint64_t stacksize;/* if not zero, initial stack size */ -}; - - -/* - * The source_version_command is an optional load command containing - * the version of the sources used to build the binary. - */ -struct source_version_command { - uint32_t cmd; /* LC_SOURCE_VERSION */ - uint32_t cmdsize; /* 16 */ - uint64_t version; /* A.B.C.D.E packed as a24.b10.c10.d10.e10 */ -}; - - -/* - * The LC_DATA_IN_CODE load commands uses a linkedit_data_command - * to point to an array of data_in_code_entry entries. Each entry - * describes a range of data in a code section. This load command - * is only used in final linked images. - */ -struct data_in_code_entry { - uint32_t offset; /* from mach_header to start of data range*/ - uint16_t length; /* number of bytes in data range */ - uint16_t kind; /* a DICE_KIND_* value */ -}; -#define DICE_KIND_DATA 0x0001 /* L$start$data$... label */ -#define DICE_KIND_JUMP_TABLE8 0x0002 /* L$start$jt8$... label */ -#define DICE_KIND_JUMP_TABLE16 0x0003 /* L$start$jt16$... label */ -#define DICE_KIND_JUMP_TABLE32 0x0004 /* L$start$jt32$... label */ -#define DICE_KIND_ABS_JUMP_TABLE32 0x0005 /* L$start$jta32$... label */ - - - -/* - * Sections of type S_THREAD_LOCAL_VARIABLES contain an array - * of tlv_descriptor structures. - */ -struct tlv_descriptor -{ - void* (*thunk)(struct tlv_descriptor*); - unsigned long key; - unsigned long offset; -}; - -#endif /* _MACHO_LOADER_H_ */ diff -r 479240de2d64 -r 30ba02c504a0 boot/nlist.h --- a/boot/nlist.h Tue Jan 22 02:47:24 2013 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,312 +0,0 @@ -/* - * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. - * - * @APPLE_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. 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_LICENSE_HEADER_END@ - */ -#ifndef _MACHO_NLIST_H_ -#define _MACHO_NLIST_H_ -/* $NetBSD: nlist.h,v 1.5 1994/10/26 00:56:11 cgd Exp $ */ - -/*- - * Copyright (c) 1991, 1993 - * The Regents of the University of California. All rights reserved. - * (c) UNIX System Laboratories, Inc. - * All or some portions of this file are derived from material licensed - * to the University of California by American Telephone and Telegraph - * Co. or Unix System Laboratories, Inc. and are reproduced herein with - * the permission of UNIX System Laboratories, Inc. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * @(#)nlist.h 8.2 (Berkeley) 1/21/94 - */ -#include - -/* - * Format of a symbol table entry of a Mach-O file for 32-bit architectures. - * Modified from the BSD format. The modifications from the original format - * were changing n_other (an unused field) to n_sect and the addition of the - * N_SECT type. These modifications are required to support symbols in a larger - * number of sections not just the three sections (text, data and bss) in a BSD - * file. - */ -struct nlist { - union { -#ifndef __LP64__ - char *n_name; /* for use when in-core */ -#endif - uint32_t n_strx; /* index into the string table */ - } n_un; - uint8_t n_type; /* type flag, see below */ - uint8_t n_sect; /* section number or NO_SECT */ - int16_t n_desc; /* see */ - uint32_t n_value; /* value of this symbol (or stab offset) */ -}; - -/* - * This is the symbol table entry structure for 64-bit architectures. - */ -struct nlist_64 { - union { - uint32_t n_strx; /* index into the string table */ - } n_un; - uint8_t n_type; /* type flag, see below */ - uint8_t n_sect; /* section number or NO_SECT */ - uint16_t n_desc; /* see */ - uint64_t n_value; /* value of this symbol (or stab offset) */ -}; - -/* - * Symbols with a index into the string table of zero (n_un.n_strx == 0) are - * defined to have a null, "", name. Therefore all string indexes to non null - * names must not have a zero string index. This is bit historical information - * that has never been well documented. - */ - -/* - * The n_type field really contains four fields: - * unsigned char N_STAB:3, - * N_PEXT:1, - * N_TYPE:3, - * N_EXT:1; - * which are used via the following masks. - */ -#define N_STAB 0xe0 /* if any of these bits set, a symbolic debugging entry */ -#define N_PEXT 0x10 /* private external symbol bit */ -#define N_TYPE 0x0e /* mask for the type bits */ -#define N_EXT 0x01 /* external symbol bit, set for external symbols */ - -/* - * Only symbolic debugging entries have some of the N_STAB bits set and if any - * of these bits are set then it is a symbolic debugging entry (a stab). In - * which case then the values of the n_type field (the entire field) are given - * in - */ - -/* - * Values for N_TYPE bits of the n_type field. - */ -#define N_UNDF 0x0 /* undefined, n_sect == NO_SECT */ -#define N_ABS 0x2 /* absolute, n_sect == NO_SECT */ -#define N_SECT 0xe /* defined in section number n_sect */ -#define N_PBUD 0xc /* prebound undefined (defined in a dylib) */ -#define N_INDR 0xa /* indirect */ - -/* - * If the type is N_INDR then the symbol is defined to be the same as another - * symbol. In this case the n_value field is an index into the string table - * of the other symbol's name. When the other symbol is defined then they both - * take on the defined type and value. - */ - -/* - * If the type is N_SECT then the n_sect field contains an ordinal of the - * section the symbol is defined in. The sections are numbered from 1 and - * refer to sections in order they appear in the load commands for the file - * they are in. This means the same ordinal may very well refer to different - * sections in different files. - * - * The n_value field for all symbol table entries (including N_STAB's) gets - * updated by the link editor based on the value of it's n_sect field and where - * the section n_sect references gets relocated. If the value of the n_sect - * field is NO_SECT then it's n_value field is not changed by the link editor. - */ -#define NO_SECT 0 /* symbol is not in any section */ -#define MAX_SECT 255 /* 1 thru 255 inclusive */ - -/* - * Common symbols are represented by undefined (N_UNDF) external (N_EXT) types - * who's values (n_value) are non-zero. In which case the value of the n_value - * field is the size (in bytes) of the common symbol. The n_sect field is set - * to NO_SECT. The alignment of a common symbol may be set as a power of 2 - * between 2^1 and 2^15 as part of the n_desc field using the macros below. If - * the alignment is not set (a value of zero) then natural alignment based on - * the size is used. - */ -#define GET_COMM_ALIGN(n_desc) (((n_desc) >> 8) & 0x0f) -#define SET_COMM_ALIGN(n_desc,align) \ - (n_desc) = (((n_desc) & 0xf0ff) | (((align) & 0x0f) << 8)) - -/* - * To support the lazy binding of undefined symbols in the dynamic link-editor, - * the undefined symbols in the symbol table (the nlist structures) are marked - * with the indication if the undefined reference is a lazy reference or - * non-lazy reference. If both a non-lazy reference and a lazy reference is - * made to the same symbol the non-lazy reference takes precedence. A reference - * is lazy only when all references to that symbol are made through a symbol - * pointer in a lazy symbol pointer section. - * - * The implementation of marking nlist structures in the symbol table for - * undefined symbols will be to use some of the bits of the n_desc field as a - * reference type. The mask REFERENCE_TYPE will be applied to the n_desc field - * of an nlist structure for an undefined symbol to determine the type of - * undefined reference (lazy or non-lazy). - * - * The constants for the REFERENCE FLAGS are propagated to the reference table - * in a shared library file. In that case the constant for a defined symbol, - * REFERENCE_FLAG_DEFINED, is also used. - */ -/* Reference type bits of the n_desc field of undefined symbols */ -#define REFERENCE_TYPE 0x7 -/* types of references */ -#define REFERENCE_FLAG_UNDEFINED_NON_LAZY 0 -#define REFERENCE_FLAG_UNDEFINED_LAZY 1 -#define REFERENCE_FLAG_DEFINED 2 -#define REFERENCE_FLAG_PRIVATE_DEFINED 3 -#define REFERENCE_FLAG_PRIVATE_UNDEFINED_NON_LAZY 4 -#define REFERENCE_FLAG_PRIVATE_UNDEFINED_LAZY 5 - -/* - * To simplify stripping of objects that use are used with the dynamic link - * editor, the static link editor marks the symbols defined an object that are - * referenced by a dynamicly bound object (dynamic shared libraries, bundles). - * With this marking strip knows not to strip these symbols. - */ -#define REFERENCED_DYNAMICALLY 0x0010 - -/* - * For images created by the static link editor with the -twolevel_namespace - * option in effect the flags field of the mach header is marked with - * MH_TWOLEVEL. And the binding of the undefined references of the image are - * determined by the static link editor. Which library an undefined symbol is - * bound to is recorded by the static linker in the high 8 bits of the n_desc - * field using the SET_LIBRARY_ORDINAL macro below. The ordinal recorded - * references the libraries listed in the Mach-O's LC_LOAD_DYLIB, - * LC_LOAD_WEAK_DYLIB, LC_REEXPORT_DYLIB, LC_LOAD_UPWARD_DYLIB, and - * LC_LAZY_LOAD_DYLIB, etc. load commands in the order they appear in the - * headers. The library ordinals start from 1. - * For a dynamic library that is built as a two-level namespace image the - * undefined references from module defined in another use the same nlist struct - * an in that case SELF_LIBRARY_ORDINAL is used as the library ordinal. For - * defined symbols in all images they also must have the library ordinal set to - * SELF_LIBRARY_ORDINAL. The EXECUTABLE_ORDINAL refers to the executable - * image for references from plugins that refer to the executable that loads - * them. - * - * The DYNAMIC_LOOKUP_ORDINAL is for undefined symbols in a two-level namespace - * image that are looked up by the dynamic linker with flat namespace semantics. - * This ordinal was added as a feature in Mac OS X 10.3 by reducing the - * value of MAX_LIBRARY_ORDINAL by one. So it is legal for existing binaries - * or binaries built with older tools to have 0xfe (254) dynamic libraries. In - * this case the ordinal value 0xfe (254) must be treated as a library ordinal - * for compatibility. - */ -#define GET_LIBRARY_ORDINAL(n_desc) (((n_desc) >> 8) & 0xff) -#define SET_LIBRARY_ORDINAL(n_desc,ordinal) \ - (n_desc) = (((n_desc) & 0x00ff) | (((ordinal) & 0xff) << 8)) -#define SELF_LIBRARY_ORDINAL 0x0 -#define MAX_LIBRARY_ORDINAL 0xfd -#define DYNAMIC_LOOKUP_ORDINAL 0xfe -#define EXECUTABLE_ORDINAL 0xff - -/* - * The bit 0x0020 of the n_desc field is used for two non-overlapping purposes - * and has two different symbolic names, N_NO_DEAD_STRIP and N_DESC_DISCARDED. - */ - -/* - * The N_NO_DEAD_STRIP bit of the n_desc field only ever appears in a - * relocatable .o file (MH_OBJECT filetype). And is used to indicate to the - * static link editor it is never to dead strip the symbol. - */ -#define N_NO_DEAD_STRIP 0x0020 /* symbol is not to be dead stripped */ - -/* - * The N_DESC_DISCARDED bit of the n_desc field never appears in linked image. - * But is used in very rare cases by the dynamic link editor to mark an in - * memory symbol as discared and longer used for linking. - */ -#define N_DESC_DISCARDED 0x0020 /* symbol is discarded */ - -/* - * The N_WEAK_REF bit of the n_desc field indicates to the dynamic linker that - * the undefined symbol is allowed to be missing and is to have the address of - * zero when missing. - */ -#define N_WEAK_REF 0x0040 /* symbol is weak referenced */ - -/* - * The N_WEAK_DEF bit of the n_desc field indicates to the static and dynamic - * linkers that the symbol definition is weak, allowing a non-weak symbol to - * also be used which causes the weak definition to be discared. Currently this - * is only supported for symbols in coalesed sections. - */ -#define N_WEAK_DEF 0x0080 /* coalesed symbol is a weak definition */ - -/* - * The N_REF_TO_WEAK bit of the n_desc field indicates to the dynamic linker - * that the undefined symbol should be resolved using flat namespace searching. - */ -#define N_REF_TO_WEAK 0x0080 /* reference to a weak symbol */ - -/* - * The N_ARM_THUMB_DEF bit of the n_desc field indicates that the symbol is - * a defintion of a Thumb function. - */ -#define N_ARM_THUMB_DEF 0x0008 /* symbol is a Thumb function (ARM) */ - -/* - * The N_SYMBOL_RESOLVER bit of the n_desc field indicates that the - * that the function is actually a resolver function and should - * be called to get the address of the real function to use. - * This bit is only available in .o files (MH_OBJECT filetype) - */ -#define N_SYMBOL_RESOLVER 0x0100 - -#ifndef __STRICT_BSD__ -#if __cplusplus -extern "C" { -#endif /* __cplusplus */ -/* - * The function nlist(3) from the C library. - */ -extern int nlist (const char *filename, struct nlist *list); -#if __cplusplus -} -#endif /* __cplusplus */ -#endif /* __STRICT_BSD__ */ - -#endif /* _MACHO_LIST_H_ */ diff -r 479240de2d64 -r 30ba02c504a0 boot/ppc/reloc.h --- a/boot/ppc/reloc.h Tue Jan 22 02:47:24 2013 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,65 +0,0 @@ -/* - * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. - * - * @APPLE_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. 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_LICENSE_HEADER_END@ - */ -/* - * Relocation types used in the ppc implementation. Relocation entries for - * things other than instructions use the same generic relocation as discribed - * above and their r_type is RELOC_VANILLA. The rest of the relocation types - * are for instructions. Since they are for instructions the r_address field - * indicates the 32 bit instruction that the relocation is to be preformed on. - * The fields r_pcrel and r_length are ignored for non-RELOC_VANILLA r_types - * except for PPC_RELOC_BR14. - * - * For PPC_RELOC_BR14 if the r_length is the unused value 3, then the branch was - * statically predicted setting or clearing the Y-bit based on the sign of the - * displacement or the opcode. If this is the case the static linker must flip - * the value of the Y-bit if the sign of the displacement changes for non-branch - * always conditions. - */ -enum reloc_type_ppc -{ - PPC_RELOC_VANILLA, /* generic relocation as discribed above */ - PPC_RELOC_PAIR, /* the second relocation entry of a pair */ - PPC_RELOC_BR14, /* 14 bit branch displacement (to a word address) */ - PPC_RELOC_BR24, /* 24 bit branch displacement (to a word address) */ - PPC_RELOC_HI16, /* a PAIR follows with the low half */ - PPC_RELOC_LO16, /* a PAIR follows with the high half */ - PPC_RELOC_HA16, /* Same as the RELOC_HI16 except the low 16 bits and the - * high 16 bits are added together with the low 16 bits - * sign extened first. This means if bit 15 of the low - * 16 bits is set the high 16 bits stored in the - * instruction will be adjusted. - */ - PPC_RELOC_LO14, /* Same as the LO16 except that the low 2 bits are not - * stored in the instruction and are always zero. This - * is used in double word load/store instructions. - */ - PPC_RELOC_SECTDIFF, /* a PAIR follows with subtract symbol value */ - PPC_RELOC_PB_LA_PTR,/* prebound lazy pointer */ - PPC_RELOC_HI16_SECTDIFF, /* section difference forms of above. a PAIR */ - PPC_RELOC_LO16_SECTDIFF, /* follows these with subtract symbol value */ - PPC_RELOC_HA16_SECTDIFF, - PPC_RELOC_JBSR, - PPC_RELOC_LO14_SECTDIFF, - PPC_RELOC_LOCAL_SECTDIFF /* like PPC_RELOC_SECTDIFF, but the symbol - referenced was local. */ -}; diff -r 479240de2d64 -r 30ba02c504a0 boot/ppc/swap.h --- a/boot/ppc/swap.h Tue Jan 22 02:47:24 2013 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,36 +0,0 @@ -/* - * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. - * - * @APPLE_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. 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_LICENSE_HEADER_END@ - */ -#include -#include - -extern void swap_ppc_thread_state_t( - ppc_thread_state_t *cpu, - enum NXByteOrder target_byte_sex); - -extern void swap_ppc_float_state_t( - ppc_float_state_t *fpu, - enum NXByteOrder target_byte_sex); - -extern void swap_ppc_exception_state_t( - ppc_exception_state_t *state, - enum NXByteOrder target_byte_sex); diff -r 479240de2d64 -r 30ba02c504a0 boot/ranlib.h --- a/boot/ranlib.h Tue Jan 22 02:47:24 2013 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,67 +0,0 @@ -/* - * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. - * - * @APPLE_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. 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_LICENSE_HEADER_END@ - */ -/* ranlib.h 4.1 83/05/03 */ -#ifndef _MACH_O_RANLIB_H_ -#define _MACH_O_RANLIB_H_ - -#include -#include /* off_t */ - -/* - * There are two known orders of table of contents for archives. The first is - * the order ranlib(1) originally produced and still produces without any - * options. This table of contents has the archive member name "__.SYMDEF" - * This order has the ranlib structures in the order the objects appear in the - * archive and the symbol names of those objects in the order of symbol table. - * The second know order is sorted by symbol name and is produced with the -s - * option to ranlib(1). This table of contents has the archive member name - * "__.SYMDEF SORTED" and many programs (notably the 1.0 version of ld(1) can't - * tell the difference between names because of the imbedded blank in the name - * and works with either table of contents). This second order is used by the - * post 1.0 link editor to produce faster linking. The original 1.0 version of - * ranlib(1) gets confused when it is run on a archive with the second type of - * table of contents because it and ar(1) which it uses use different ways to - * determined the member name (ar(1) treats all blanks in the name as - * significant and ranlib(1) only checks for the first one). - */ -#define SYMDEF "__.SYMDEF" -#define SYMDEF_SORTED "__.SYMDEF SORTED" - -/* - * Structure of the __.SYMDEF table of contents for an archive. - * __.SYMDEF begins with a long giving the size in bytes of the ranlib - * structures which immediately follow, and then continues with a string - * table consisting of a long giving the number of bytes of strings which - * follow and then the strings themselves. The ran_strx fields index the - * string table whose first byte is numbered 0. - */ -struct ranlib { - union { - uint32_t ran_strx; /* string table index of */ -#ifndef __LP64__ - char *ran_name; /* symbol defined by */ -#endif - } ran_un; - uint32_t ran_off; /* library member at this offset */ -}; -#endif /* _MACH_O_RANLIB_H_ */ diff -r 479240de2d64 -r 30ba02c504a0 boot/reloc.h --- a/boot/reloc.h Tue Jan 22 02:47:24 2013 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,203 +0,0 @@ -/* - * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. - * - * @APPLE_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. 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_LICENSE_HEADER_END@ - */ -/* $NetBSD: exec.h,v 1.6 1994/10/27 04:16:05 cgd Exp $ */ - -/* - * Copyright (c) 1993 Christopher G. Demetriou - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef _MACHO_RELOC_H_ -#define _MACHO_RELOC_H_ -#include - -/* - * Format of a relocation entry of a Mach-O file. Modified from the 4.3BSD - * format. The modifications from the original format were changing the value - * of the r_symbolnum field for "local" (r_extern == 0) relocation entries. - * This modification is required to support symbols in an arbitrary number of - * sections not just the three sections (text, data and bss) in a 4.3BSD file. - * Also the last 4 bits have had the r_type tag added to them. - */ -struct relocation_info { - int32_t r_address; /* offset in the section to what is being - relocated */ - uint32_t r_symbolnum:24, /* symbol index if r_extern == 1 or section - ordinal if r_extern == 0 */ - r_pcrel:1, /* was relocated pc relative already */ - r_length:2, /* 0=byte, 1=word, 2=long, 3=quad */ - r_extern:1, /* does not include value of sym referenced */ - r_type:4; /* if not 0, machine specific relocation type */ -}; -#define R_ABS 0 /* absolute relocation type for Mach-O files */ - -/* - * The r_address is not really the address as it's name indicates but an offset. - * In 4.3BSD a.out objects this offset is from the start of the "segment" for - * which relocation entry is for (text or data). For Mach-O object files it is - * also an offset but from the start of the "section" for which the relocation - * entry is for. See comments in about the r_address feild - * in images for used with the dynamic linker. - * - * In 4.3BSD a.out objects if r_extern is zero then r_symbolnum is an ordinal - * for the segment the symbol being relocated is in. These ordinals are the - * symbol types N_TEXT, N_DATA, N_BSS or N_ABS. In Mach-O object files these - * ordinals refer to the sections in the object file in the order their section - * structures appear in the headers of the object file they are in. The first - * section has the ordinal 1, the second 2, and so on. This means that the - * same ordinal in two different object files could refer to two different - * sections. And further could have still different ordinals when combined - * by the link-editor. The value R_ABS is used for relocation entries for - * absolute symbols which need no further relocation. - */ - -/* - * For RISC machines some of the references are split across two instructions - * and the instruction does not contain the complete value of the reference. - * In these cases a second, or paired relocation entry, follows each of these - * relocation entries, using a PAIR r_type, which contains the other part of the - * reference not contained in the instruction. This other part is stored in the - * pair's r_address field. The exact number of bits of the other part of the - * reference store in the r_address field is dependent on the particular - * relocation type for the particular architecture. - */ - -/* - * To make scattered loading by the link editor work correctly "local" - * relocation entries can't be used when the item to be relocated is the value - * of a symbol plus an offset (where the resulting expresion is outside the - * block the link editor is moving, a blocks are divided at symbol addresses). - * In this case. where the item is a symbol value plus offset, the link editor - * needs to know more than just the section the symbol was defined. What is - * needed is the actual value of the symbol without the offset so it can do the - * relocation correctly based on where the value of the symbol got relocated to - * not the value of the expression (with the offset added to the symbol value). - * So for the NeXT 2.0 release no "local" relocation entries are ever used when - * there is a non-zero offset added to a symbol. The "external" and "local" - * relocation entries remain unchanged. - * - * The implemention is quite messy given the compatibility with the existing - * relocation entry format. The ASSUMPTION is that a section will never be - * bigger than 2**24 - 1 (0x00ffffff or 16,777,215) bytes. This assumption - * allows the r_address (which is really an offset) to fit in 24 bits and high - * bit of the r_address field in the relocation_info structure to indicate - * it is really a scattered_relocation_info structure. Since these are only - * used in places where "local" relocation entries are used and not where - * "external" relocation entries are used the r_extern field has been removed. - * - * For scattered loading to work on a RISC machine where some of the references - * are split across two instructions the link editor needs to be assured that - * each reference has a unique 32 bit reference (that more than one reference is - * NOT sharing the same high 16 bits for example) so it move each referenced - * item independent of each other. Some compilers guarantees this but the - * compilers don't so scattered loading can be done on those that do guarantee - * this. - */ -#if defined(__BIG_ENDIAN__) || defined(__LITTLE_ENDIAN__) -/* - * The reason for the ifdef's of __BIG_ENDIAN__ and __LITTLE_ENDIAN__ are that - * when stattered relocation entries were added the mistake of using a mask - * against a structure that is made up of bit fields was used. To make this - * design work this structure must be laid out in memory the same way so the - * mask can be applied can check the same bit each time (r_scattered). - */ -#endif /* defined(__BIG_ENDIAN__) || defined(__LITTLE_ENDIAN__) */ -#define R_SCATTERED 0x80000000 /* mask to be applied to the r_address field - of a relocation_info structure to tell that - is is really a scattered_relocation_info - stucture */ -struct scattered_relocation_info { -#ifdef __BIG_ENDIAN__ - uint32_t r_scattered:1, /* 1=scattered, 0=non-scattered (see above) */ - r_pcrel:1, /* was relocated pc relative already */ - r_length:2, /* 0=byte, 1=word, 2=long, 3=quad */ - r_type:4, /* if not 0, machine specific relocation type */ - r_address:24; /* offset in the section to what is being - relocated */ - int32_t r_value; /* the value the item to be relocated is - refering to (without any offset added) */ -#endif /* __BIG_ENDIAN__ */ -#ifdef __LITTLE_ENDIAN__ - uint32_t - r_address:24, /* offset in the section to what is being - relocated */ - r_type:4, /* if not 0, machine specific relocation type */ - r_length:2, /* 0=byte, 1=word, 2=long, 3=quad */ - r_pcrel:1, /* was relocated pc relative already */ - r_scattered:1; /* 1=scattered, 0=non-scattered (see above) */ - int32_t r_value; /* the value the item to be relocated is - refering to (without any offset added) */ -#endif /* __LITTLE_ENDIAN__ */ -}; - -/* - * Relocation types used in a generic implementation. Relocation entries for - * normal things use the generic relocation as discribed above and their r_type - * is GENERIC_RELOC_VANILLA (a value of zero). - * - * Another type of generic relocation, GENERIC_RELOC_SECTDIFF, is to support - * the difference of two symbols defined in different sections. That is the - * expression "symbol1 - symbol2 + constant" is a relocatable expression when - * both symbols are defined in some section. For this type of relocation the - * both relocations entries are scattered relocation entries. The value of - * symbol1 is stored in the first relocation entry's r_value field and the - * value of symbol2 is stored in the pair's r_value field. - * - * A special case for a prebound lazy pointer is needed to beable to set the - * value of the lazy pointer back to its non-prebound state. This is done - * using the GENERIC_RELOC_PB_LA_PTR r_type. This is a scattered relocation - * entry where the r_value feild is the value of the lazy pointer not prebound. - */ -enum reloc_type_generic -{ - GENERIC_RELOC_VANILLA, /* generic relocation as discribed above */ - GENERIC_RELOC_PAIR, /* Only follows a GENERIC_RELOC_SECTDIFF */ - GENERIC_RELOC_SECTDIFF, - GENERIC_RELOC_PB_LA_PTR, /* prebound lazy pointer */ - GENERIC_RELOC_LOCAL_SECTDIFF, - GENERIC_RELOC_TLV /* thread local variables */ -}; - -#endif /* _MACHO_RELOC_H_ */ diff -r 479240de2d64 -r 30ba02c504a0 boot/stab.h --- a/boot/stab.h Tue Jan 22 02:47:24 2013 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,122 +0,0 @@ -/* - * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. - * - * @APPLE_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. 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_LICENSE_HEADER_END@ - */ -#ifndef _MACHO_STAB_H_ -#define _MACHO_STAB_H_ -/* $NetBSD: stab.h,v 1.4 1994/10/26 00:56:25 cgd Exp $ */ - -/*- - * Copyright (c) 1991 The Regents of the University of California. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * @(#)stab.h 5.2 (Berkeley) 4/4/91 - */ - -/* - * This file gives definitions supplementing for permanent symbol - * table entries of Mach-O files. Modified from the BSD definitions. The - * modifications from the original definitions were changing what the values of - * what was the n_other field (an unused field) which is now the n_sect field. - * These modifications are required to support symbols in an arbitrary number of - * sections not just the three sections (text, data and bss) in a BSD file. - * The values of the defined constants have NOT been changed. - * - * These must have one of the N_STAB bits on. The n_value fields are subject - * to relocation according to the value of their n_sect field. So for types - * that refer to things in sections the n_sect field must be filled in with the - * proper section ordinal. For types that are not to have their n_value field - * relocatated the n_sect field must be NO_SECT. - */ - -/* - * Symbolic debugger symbols. The comments give the conventional use for - * - * .stabs "n_name", n_type, n_sect, n_desc, n_value - * - * where n_type is the defined constant and not listed in the comment. Other - * fields not listed are zero. n_sect is the section ordinal the entry is - * refering to. - */ -#define N_GSYM 0x20 /* global symbol: name,,NO_SECT,type,0 */ -#define N_FNAME 0x22 /* procedure name (f77 kludge): name,,NO_SECT,0,0 */ -#define N_FUN 0x24 /* procedure: name,,n_sect,linenumber,address */ -#define N_STSYM 0x26 /* static symbol: name,,n_sect,type,address */ -#define N_LCSYM 0x28 /* .lcomm symbol: name,,n_sect,type,address */ -#define N_BNSYM 0x2e /* begin nsect sym: 0,,n_sect,0,address */ -#define N_OPT 0x3c /* emitted with gcc2_compiled and in gcc source */ -#define N_RSYM 0x40 /* register sym: name,,NO_SECT,type,register */ -#define N_SLINE 0x44 /* src line: 0,,n_sect,linenumber,address */ -#define N_ENSYM 0x4e /* end nsect sym: 0,,n_sect,0,address */ -#define N_SSYM 0x60 /* structure elt: name,,NO_SECT,type,struct_offset */ -#define N_SO 0x64 /* source file name: name,,n_sect,0,address */ -#define N_OSO 0x66 /* object file name: name,,0,0,st_mtime */ -#define N_LSYM 0x80 /* local sym: name,,NO_SECT,type,offset */ -#define N_BINCL 0x82 /* include file beginning: name,,NO_SECT,0,sum */ -#define N_SOL 0x84 /* #included file name: name,,n_sect,0,address */ -#define N_PARAMS 0x86 /* compiler parameters: name,,NO_SECT,0,0 */ -#define N_VERSION 0x88 /* compiler version: name,,NO_SECT,0,0 */ -#define N_OLEVEL 0x8A /* compiler -O level: name,,NO_SECT,0,0 */ -#define N_PSYM 0xa0 /* parameter: name,,NO_SECT,type,offset */ -#define N_EINCL 0xa2 /* include file end: name,,NO_SECT,0,0 */ -#define N_ENTRY 0xa4 /* alternate entry: name,,n_sect,linenumber,address */ -#define N_LBRAC 0xc0 /* left bracket: 0,,NO_SECT,nesting level,address */ -#define N_EXCL 0xc2 /* deleted include file: name,,NO_SECT,0,sum */ -#define N_RBRAC 0xe0 /* right bracket: 0,,NO_SECT,nesting level,address */ -#define N_BCOMM 0xe2 /* begin common: name,,NO_SECT,0,0 */ -#define N_ECOMM 0xe4 /* end common: name,,n_sect,0,0 */ -#define N_ECOML 0xe8 /* end common (local name): 0,,n_sect,0,address */ -#define N_LENG 0xfe /* second stab entry with length information */ - -/* - * for the berkeley pascal compiler, pc(1): - */ -#define N_PC 0x30 /* global pascal symbol: name,,NO_SECT,subtype,line */ - -#endif /* _MACHO_STAB_H_ */ diff -r 479240de2d64 -r 30ba02c504a0 boot/swap.h --- a/boot/swap.h Tue Jan 22 02:47:24 2013 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,207 +0,0 @@ -/* - * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. - * - * @APPLE_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. 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_LICENSE_HEADER_END@ - */ -#ifndef _MACH_O_SWAP_H_ -#define _MACH_O_SWAP_H_ - -#include -#include -#include -#include -#include -#include -#include - -#if __cplusplus -extern "C" { -#endif /* __cplusplus */ - -extern void swap_fat_header( - struct fat_header *fat_header, - enum NXByteOrder target_byte_order); - -extern void swap_fat_arch( - struct fat_arch *fat_archs, - uint32_t nfat_arch, - enum NXByteOrder target_byte_order); - -extern void swap_mach_header( - struct mach_header *mh, - enum NXByteOrder target_byte_order); - -extern void swap_mach_header_64( - struct mach_header_64 *mh, - enum NXByteOrder target_byte_order); - -extern void swap_load_command( - struct load_command *lc, - enum NXByteOrder target_byte_order); - -extern void swap_segment_command( - struct segment_command *sg, - enum NXByteOrder target_byte_order); - -extern void swap_segment_command_64( - struct segment_command_64 *sg, - enum NXByteOrder target_byte_order); - -extern void swap_section( - struct section *s, - uint32_t nsects, - enum NXByteOrder target_byte_order); - -extern void swap_section_64( - struct section_64 *s, - uint32_t nsects, - enum NXByteOrder target_byte_order); - -extern void swap_symtab_command( - struct symtab_command *st, - enum NXByteOrder target_byte_order); - -extern void swap_dysymtab_command( - struct dysymtab_command *dyst, - enum NXByteOrder target_byte_sex); - -extern void swap_symseg_command( - struct symseg_command *ss, - enum NXByteOrder target_byte_order); - -extern void swap_fvmlib_command( - struct fvmlib_command *fl, - enum NXByteOrder target_byte_order); - -extern void swap_dylib_command( - struct dylib_command *dl, - enum NXByteOrder target_byte_sex); - -extern void swap_sub_framework_command( - struct sub_framework_command *sub, - enum NXByteOrder target_byte_sex); - -extern void swap_sub_umbrella_command( - struct sub_umbrella_command *usub, - enum NXByteOrder target_byte_sex); - -extern void swap_sub_library_command( - struct sub_library_command *lsub, - enum NXByteOrder target_byte_sex); - -extern void swap_sub_client_command( - struct sub_client_command *csub, - enum NXByteOrder target_byte_sex); - -extern void swap_prebound_dylib_command( - struct prebound_dylib_command *pbdylib, - enum NXByteOrder target_byte_sex); - -extern void swap_dylinker_command( - struct dylinker_command *dyld, - enum NXByteOrder target_byte_sex); - -extern void swap_fvmfile_command( - struct fvmfile_command *ff, - enum NXByteOrder target_byte_order); - -extern void swap_thread_command( - struct thread_command *ut, - enum NXByteOrder target_byte_order); - -extern void swap_ident_command( - struct ident_command *ident, - enum NXByteOrder target_byte_order); - -extern void swap_routines_command( - struct routines_command *r_cmd, - enum NXByteOrder target_byte_sex); - -extern void swap_routines_command_64( - struct routines_command_64 *r_cmd, - enum NXByteOrder target_byte_sex); - -extern void swap_twolevel_hints_command( - struct twolevel_hints_command *hints_cmd, - enum NXByteOrder target_byte_sex); - -extern void swap_prebind_cksum_command( - struct prebind_cksum_command *cksum_cmd, - enum NXByteOrder target_byte_sex); - -extern void swap_uuid_command( - struct uuid_command *uuid_cmd, - enum NXByteOrder target_byte_sex); - -extern void swap_twolevel_hint( - struct twolevel_hint *hints, - uint32_t nhints, - enum NXByteOrder target_byte_sex); - -extern void swap_nlist( - struct nlist *symbols, - uint32_t nsymbols, - enum NXByteOrder target_byte_order); - -extern void swap_nlist_64( - struct nlist_64 *symbols, - uint32_t nsymbols, - enum NXByteOrder target_byte_order); - -extern void swap_ranlib( - struct ranlib *ranlibs, - uint32_t nranlibs, - enum NXByteOrder target_byte_order); - -extern void swap_relocation_info( - struct relocation_info *relocs, - uint32_t nrelocs, - enum NXByteOrder target_byte_order); - -extern void swap_indirect_symbols( - uint32_t *indirect_symbols, - uint32_t nindirect_symbols, - enum NXByteOrder target_byte_sex); - -extern void swap_dylib_reference( - struct dylib_reference *refs, - uint32_t nrefs, - enum NXByteOrder target_byte_sex); - -extern void swap_dylib_module( - struct dylib_module *mods, - uint32_t nmods, - enum NXByteOrder target_byte_sex); - -extern void swap_dylib_module_64( - struct dylib_module_64 *mods, - uint32_t nmods, - enum NXByteOrder target_byte_sex); - -extern void swap_dylib_table_of_contents( - struct dylib_table_of_contents *tocs, - uint32_t ntocs, - enum NXByteOrder target_byte_sex); - -#if __cplusplus -} -#endif /* __cplusplus */ - -#endif /* _MACH_O_SWAP_H_ */ diff -r 479240de2d64 -r 30ba02c504a0 boot/x86_64/reloc.h --- a/boot/x86_64/reloc.h Tue Jan 22 02:47:24 2013 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,185 +0,0 @@ -/* - * Copyright (c) 2006 Apple Computer, Inc. All rights reserved. - * - * @APPLE_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. 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_LICENSE_HEADER_END@ - */ -/* - * Relocations for x86_64 are a bit different than for other architectures in - * Mach-O: Scattered relocations are not used. Almost all relocations produced - * by the compiler are external relocations. An external relocation has the - * r_extern bit set to 1 and the r_symbolnum field contains the symbol table - * index of the target label. - * - * When the assembler is generating relocations, if the target label is a local - * label (begins with 'L'), then the previous non-local label in the same - * section is used as the target of the external relocation. An addend is used - * with the distance from that non-local label to the target label. Only when - * there is no previous non-local label in the section is an internal - * relocation used. - * - * The addend (i.e. the 4 in _foo+4) is encoded in the instruction (Mach-O does - * not have RELA relocations). For PC-relative relocations, the addend is - * stored directly in the instruction. This is different from other Mach-O - * architectures, which encode the addend minus the current section offset. - * - * The relocation types are: - * - * X86_64_RELOC_UNSIGNED // for absolute addresses - * X86_64_RELOC_SIGNED // for signed 32-bit displacement - * X86_64_RELOC_BRANCH // a CALL/JMP instruction with 32-bit displacement - * X86_64_RELOC_GOT_LOAD // a MOVQ load of a GOT entry - * X86_64_RELOC_GOT // other GOT references - * X86_64_RELOC_SUBTRACTOR // must be followed by a X86_64_RELOC_UNSIGNED - * - * The following are sample assembly instructions, followed by the relocation - * and section content they generate in an object file: - * - * call _foo - * r_type=X86_64_RELOC_BRANCH, r_length=2, r_extern=1, r_pcrel=1, r_symbolnum=_foo - * E8 00 00 00 00 - * - * call _foo+4 - * r_type=X86_64_RELOC_BRANCH, r_length=2, r_extern=1, r_pcrel=1, r_symbolnum=_foo - * E8 04 00 00 00 - * - * movq _foo@GOTPCREL(%rip), %rax - * r_type=X86_64_RELOC_GOT_LOAD, r_length=2, r_extern=1, r_pcrel=1, r_symbolnum=_foo - * 48 8B 05 00 00 00 00 - * - * pushq _foo@GOTPCREL(%rip) - * r_type=X86_64_RELOC_GOT, r_length=2, r_extern=1, r_pcrel=1, r_symbolnum=_foo - * FF 35 00 00 00 00 - * - * movl _foo(%rip), %eax - * r_type=X86_64_RELOC_SIGNED, r_length=2, r_extern=1, r_pcrel=1, r_symbolnum=_foo - * 8B 05 00 00 00 00 - * - * movl _foo+4(%rip), %eax - * r_type=X86_64_RELOC_SIGNED, r_length=2, r_extern=1, r_pcrel=1, r_symbolnum=_foo - * 8B 05 04 00 00 00 - * - * movb $0x12, _foo(%rip) - * r_type=X86_64_RELOC_SIGNED, r_length=2, r_extern=1, r_pcrel=1, r_symbolnum=_foo - * C6 05 FF FF FF FF 12 - * - * movl $0x12345678, _foo(%rip) - * r_type=X86_64_RELOC_SIGNED, r_length=2, r_extern=1, r_pcrel=1, r_symbolnum=_foo - * C7 05 FC FF FF FF 78 56 34 12 - * - * .quad _foo - * r_type=X86_64_RELOC_UNSIGNED, r_length=3, r_extern=1, r_pcrel=0, r_symbolnum=_foo - * 00 00 00 00 00 00 00 00 - * - * .quad _foo+4 - * r_type=X86_64_RELOC_UNSIGNED, r_length=3, r_extern=1, r_pcrel=0, r_symbolnum=_foo - * 04 00 00 00 00 00 00 00 - * - * .quad _foo - _bar - * r_type=X86_64_RELOC_SUBTRACTOR, r_length=3, r_extern=1, r_pcrel=0, r_symbolnum=_bar - * r_type=X86_64_RELOC_UNSIGNED, r_length=3, r_extern=1, r_pcrel=0, r_symbolnum=_foo - * 00 00 00 00 00 00 00 00 - * - * .quad _foo - _bar + 4 - * r_type=X86_64_RELOC_SUBTRACTOR, r_length=3, r_extern=1, r_pcrel=0, r_symbolnum=_bar - * r_type=X86_64_RELOC_UNSIGNED, r_length=3, r_extern=1, r_pcrel=0, r_symbolnum=_foo - * 04 00 00 00 00 00 00 00 - * - * .long _foo - _bar - * r_type=X86_64_RELOC_SUBTRACTOR, r_length=2, r_extern=1, r_pcrel=0, r_symbolnum=_bar - * r_type=X86_64_RELOC_UNSIGNED, r_length=2, r_extern=1, r_pcrel=0, r_symbolnum=_foo - * 00 00 00 00 - * - * lea L1(%rip), %rax - * r_type=X86_64_RELOC_SIGNED, r_length=2, r_extern=1, r_pcrel=1, r_symbolnum=_prev - * 48 8d 05 12 00 00 00 - * // assumes _prev is the first non-local label 0x12 bytes before L1 - * - * lea L0(%rip), %rax - * r_type=X86_64_RELOC_SIGNED, r_length=2, r_extern=0, r_pcrel=1, r_symbolnum=3 - * 48 8d 05 56 00 00 00 - * // assumes L0 is in third section and there is no previous non-local label. - * // The rip-relative-offset of 0x00000056 is L0-address_of_next_instruction. - * // address_of_next_instruction is the address of the relocation + 4. - * - * add $6,L0(%rip) - * r_type=X86_64_RELOC_SIGNED_1, r_length=2, r_extern=0, r_pcrel=1, r_symbolnum=3 - * 83 05 18 00 00 00 06 - * // assumes L0 is in third section and there is no previous non-local label. - * // The rip-relative-offset of 0x00000018 is L0-address_of_next_instruction. - * // address_of_next_instruction is the address of the relocation + 4 + 1. - * // The +1 comes from SIGNED_1. This is used because the relocation is not - * // at the end of the instruction. - * - * .quad L1 - * r_type=X86_64_RELOC_UNSIGNED, r_length=3, r_extern=1, r_pcrel=0, r_symbolnum=_prev - * 12 00 00 00 00 00 00 00 - * // assumes _prev is the first non-local label 0x12 bytes before L1 - * - * .quad L0 - * r_type=X86_64_RELOC_UNSIGNED, r_length=3, r_extern=0, r_pcrel=0, r_symbolnum=3 - * 56 00 00 00 00 00 00 00 - * // assumes L0 is in third section, has an address of 0x00000056 in .o - * // file, and there is no previous non-local label - * - * .quad _foo - . - * r_type=X86_64_RELOC_SUBTRACTOR, r_length=3, r_extern=1, r_pcrel=0, r_symbolnum=_prev - * r_type=X86_64_RELOC_UNSIGNED, r_length=3, r_extern=1, r_pcrel=0, r_symbolnum=_foo - * EE FF FF FF FF FF FF FF - * // assumes _prev is the first non-local label 0x12 bytes before this - * // .quad - * - * .quad _foo - L1 - * r_type=X86_64_RELOC_SUBTRACTOR, r_length=3, r_extern=1, r_pcrel=0, r_symbolnum=_prev - * r_type=X86_64_RELOC_UNSIGNED, r_length=3, r_extern=1, r_pcrel=0, r_symbolnum=_foo - * EE FF FF FF FF FF FF FF - * // assumes _prev is the first non-local label 0x12 bytes before L1 - * - * .quad L1 - _prev - * // No relocations. This is an assembly time constant. - * 12 00 00 00 00 00 00 00 - * // assumes _prev is the first non-local label 0x12 bytes before L1 - * - * - * - * In final linked images, there are only two valid relocation kinds: - * - * r_type=X86_64_RELOC_UNSIGNED, r_length=3, r_pcrel=0, r_extern=1, r_symbolnum=sym_index - * This tells dyld to add the address of a symbol to a pointer sized (8-byte) - * piece of data (i.e on disk the 8-byte piece of data contains the addend). The - * r_symbolnum contains the index into the symbol table of the target symbol. - * - * r_type=X86_64_RELOC_UNSIGNED, r_length=3, r_pcrel=0, r_extern=0, r_symbolnum=0 - * This tells dyld to adjust the pointer sized (8-byte) piece of data by the amount - * the containing image was loaded from its base address (e.g. slide). - * - */ -enum reloc_type_x86_64 -{ - X86_64_RELOC_UNSIGNED, // for absolute addresses - X86_64_RELOC_SIGNED, // for signed 32-bit displacement - X86_64_RELOC_BRANCH, // a CALL/JMP instruction with 32-bit displacement - X86_64_RELOC_GOT_LOAD, // a MOVQ load of a GOT entry - X86_64_RELOC_GOT, // other GOT references - X86_64_RELOC_SUBTRACTOR, // must be followed by a X86_64_RELOC_UNSIGNED - X86_64_RELOC_SIGNED_1, // for signed 32-bit displacement with a -1 addend - X86_64_RELOC_SIGNED_2, // for signed 32-bit displacement with a -2 addend - X86_64_RELOC_SIGNED_4, // for signed 32-bit displacement with a -4 addend - X86_64_RELOC_TLV, // for thread local variables -};