| 1 | /* |
| 2 | * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. |
| 3 | * |
| 4 | * @APPLE_LICENSE_HEADER_START@ |
| 5 | * |
| 6 | * This file contains Original Code and/or Modifications of Original Code |
| 7 | * as defined in and that are subject to the Apple Public Source License |
| 8 | * Version 2.0 (the 'License'). You may not use this file except in |
| 9 | * compliance with the License. Please obtain a copy of the License at |
| 10 | * http://www.opensource.apple.com/apsl/ and read it before using this |
| 11 | * file. |
| 12 | * |
| 13 | * The Original Code and all software distributed under the License are |
| 14 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER |
| 15 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, |
| 16 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, |
| 17 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. |
| 18 | * Please see the License for the specific language governing rights and |
| 19 | * limitations under the License. |
| 20 | * |
| 21 | * @APPLE_LICENSE_HEADER_END@ |
| 22 | */ |
| 23 | #ifndef _MACH_O_ARCH_H_ |
| 24 | #define _MACH_O_ARCH_H_ |
| 25 | /* |
| 26 | * Copyright (c) 1997 Apple Computer, Inc. |
| 27 | * |
| 28 | * Functions that deal with information about architectures. |
| 29 | * |
| 30 | */ |
| 31 | |
| 32 | #include <stdint.h> |
| 33 | #include <mach/machine.h> |
| 34 | #include <architecture/byte_order.h> |
| 35 | #include <Availability.h> |
| 36 | #include <TargetConditionals.h> |
| 37 | |
| 38 | #ifndef __CCTOOLS_DEPRECATED |
| 39 | #define __CCTOOLS_DEPRECATED __API_DEPRECATED("No longer supported", macos(10.0, 13.0), ios(1.0, 16.0), watchos(1.0, 8.0), tvos(1.0, 16.0)) |
| 40 | #define __CCTOOLS_DEPRECATED_MSG(_msg) __API_DEPRECATED_WITH_REPLACEMENT(_msg, macos(10.0, 13.0), ios(1.0, 16.0), watchos(1.0, 8.0), tvos(1.0, 16.0)) |
| 41 | #endif |
| 42 | |
| 43 | /* The NXArchInfo structs contain the architectures symbolic name |
| 44 | * (such as "ppc"), its CPU type and CPU subtype as defined in |
| 45 | * mach/machine.h, the byte order for the architecture, and a |
| 46 | * describing string (such as "PowerPC"). |
| 47 | * There will both be entries for specific CPUs (such as ppc604e) as |
| 48 | * well as generic "family" entries (such as ppc). |
| 49 | */ |
| 50 | |
| 51 | struct NXArchInfo { |
| 52 | const char *name; |
| 53 | cpu_type_t cputype; |
| 54 | cpu_subtype_t cpusubtype; |
| 55 | enum NXByteOrder byteorder; |
| 56 | const char *description; |
| 57 | } __CCTOOLS_DEPRECATED; |
| 58 | typedef struct NXArchInfo NXArchInfo __CCTOOLS_DEPRECATED; |
| 59 | |
| 60 | #ifdef __cplusplus |
| 61 | extern "C" { |
| 62 | #endif /* __cplusplus */ |
| 63 | |
| 64 | /* NXGetAllArchInfos() returns a pointer to an array of all known |
| 65 | * NXArchInfo structures. The last NXArchInfo is marked by a NULL name. |
| 66 | */ |
| 67 | extern const NXArchInfo *NXGetAllArchInfos(void) __CCTOOLS_DEPRECATED; |
| 68 | |
| 69 | /* NXGetLocalArchInfo() returns the NXArchInfo for the local host, or NULL |
| 70 | * if none is known. |
| 71 | */ |
| 72 | extern const NXArchInfo *NXGetLocalArchInfo(void) __CCTOOLS_DEPRECATED_MSG("use macho_arch_name_for_mach_header()"); |
| 73 | |
| 74 | /* NXGetArchInfoFromName() and NXGetArchInfoFromCpuType() return the |
| 75 | * NXArchInfo from the architecture's name or cputype/cpusubtype |
| 76 | * combination. A cpusubtype of CPU_SUBTYPE_MULTIPLE can be used |
| 77 | * to request the most general NXArchInfo known for the given cputype. |
| 78 | * NULL is returned if no matching NXArchInfo can be found. |
| 79 | */ |
| 80 | extern const NXArchInfo *NXGetArchInfoFromName(const char *name) __CCTOOLS_DEPRECATED_MSG("use macho_cpu_type_for_arch_name()"); |
| 81 | extern const NXArchInfo *NXGetArchInfoFromCpuType(cpu_type_t cputype, |
| 82 | 						 cpu_subtype_t cpusubtype) __CCTOOLS_DEPRECATED_MSG("use macho_arch_name_for_cpu_type()"); |
| 83 | |
| 84 | /* The above interfaces that return pointers to NXArchInfo structs in normal |
| 85 | * cases returns a pointer from the array returned in NXGetAllArchInfos(). |
| 86 | * In some cases when the cputype is CPU_TYPE_I386 or CPU_TYPE_POWERPC it will |
| 87 | * retun malloc(3)'ed NXArchInfo struct which contains a string in the |
| 88 | * description field also a malloc(3)'ed pointer. To allow programs not to |
| 89 | * leak memory they can call NXFreeArchInfo() on pointers returned from the |
| 90 | * above interfaces. Since this is a new API on older systems can use the |
| 91 | * code below. Going forward the above interfaces will only return pointers |
| 92 | * from the array returned in NXGetAllArchInfos(). |
| 93 | */ |
| 94 | extern void NXFreeArchInfo(const NXArchInfo *x) __CCTOOLS_DEPRECATED_MSG("NXArchInfo is deprecated"); |
| 95 | |
| 96 | /* The code that can be used for NXFreeArchInfo() when it is not available is: |
| 97 | * |
| 98 | *	static void NXFreeArchInfo( |
| 99 | *	const NXArchInfo *x) |
| 100 | *	{ |
| 101 | *	 const NXArchInfo *p; |
| 102 | *	 |
| 103 | *	 p = NXGetAllArchInfos(); |
| 104 | *	 while(p->name != NULL){ |
| 105 | *	 if(x == p) |
| 106 | *	 return; |
| 107 | *	 p++; |
| 108 | *	 } |
| 109 | *	 free((char *)x->description); |
| 110 | *	 free((NXArchInfo *)x); |
| 111 | *	} |
| 112 | */ |
| 113 | |
| 114 | /* NXFindBestFatArch() is passed a cputype and cpusubtype and a set of |
| 115 | * fat_arch structs and selects the best one that matches (if any) and returns |
| 116 | * a pointer to that fat_arch struct (or NULL). The fat_arch structs must be |
| 117 | * in the host byte order and correct such that the fat_archs really points to |
| 118 | * enough memory for nfat_arch structs. It is possible that this routine could |
| 119 | * fail if new cputypes or cpusubtypes are added and an old version of this |
| 120 | * routine is used. But if there is an exact match between the cputype and |
| 121 | * cpusubtype and one of the fat_arch structs this routine will always succeed. |
| 122 | */ |
| 123 | extern struct fat_arch *NXFindBestFatArch(cpu_type_t cputype, |
| 124 | 					 cpu_subtype_t cpusubtype, |
| 125 | 					 struct fat_arch *fat_archs, |
| 126 | 					 uint32_t nfat_archs) __CCTOOLS_DEPRECATED_MSG("use macho_best_slice()"); |
| 127 | |
| 128 | /* NXFindBestFatArch_64() is passed a cputype and cpusubtype and a set of |
| 129 | * fat_arch_64 structs and selects the best one that matches (if any) and |
| 130 | * returns a pointer to that fat_arch_64 struct (or NULL). The fat_arch_64 |
| 131 | * structs must be in the host byte order and correct such that the fat_archs64 |
| 132 | * really points to enough memory for nfat_arch structs. It is possible that |
| 133 | * this routine could fail if new cputypes or cpusubtypes are added and an old |
| 134 | * version of this routine is used. But if there is an exact match between the |
| 135 | * cputype and cpusubtype and one of the fat_arch_64 structs this routine will |
| 136 | * always succeed. |
| 137 | */ |
| 138 | extern struct fat_arch_64 *NXFindBestFatArch_64(cpu_type_t cputype, |
| 139 | 					 cpu_subtype_t cpusubtype, |
| 140 | 					 struct fat_arch_64 *fat_archs64, |
| 141 | 					 uint32_t nfat_archs) __CCTOOLS_DEPRECATED_MSG("use macho_best_slice()"); |
| 142 | |
| 143 | /* NXCombineCpuSubtypes() returns the resulting cpusubtype when combining two |
| 144 | * different cpusubtypes for the specified cputype. If the two cpusubtypes |
| 145 | * can't be combined (the specific subtypes are mutually exclusive) -1 is |
| 146 | * returned indicating it is an error to combine them. This can also fail and |
| 147 | * return -1 if new cputypes or cpusubtypes are added and an old version of |
| 148 | * this routine is used. But if the cpusubtypes are the same they can always |
| 149 | * be combined and this routine will return the cpusubtype pass in. |
| 150 | */ |
| 151 | extern cpu_subtype_t NXCombineCpuSubtypes(cpu_type_t cputype, |
| 152 | 					 cpu_subtype_t cpusubtype1, |
| 153 | 					 cpu_subtype_t cpusubtype2) __CCTOOLS_DEPRECATED_MSG("cpu subtypes are no longer combinable"); |
| 154 | |
| 155 | #ifdef __cplusplus |
| 156 | } |
| 157 | #endif /* __cplusplus */ |
| 158 | |
| 159 | #endif /* _MACH_O_ARCH_H_ */ |