xref: /aosp_15_r20/external/google-breakpad/src/third_party/mac_headers/mach-o/arch.h (revision 9712c20fc9bbfbac4935993a2ca0b3958c5adad2)
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 
36 /* The NXArchInfo structs contain the architectures symbolic name
37  * (such as "ppc"), its CPU type and CPU subtype as defined in
38  * mach/machine.h, the byte order for the architecture, and a
39  * describing string (such as "PowerPC").
40  * There will both be entries for specific CPUs (such as ppc604e) as
41  * well as generic "family" entries (such as ppc).
42  */
43 typedef struct {
44     const char *name;
45     cpu_type_t cputype;
46     cpu_subtype_t cpusubtype;
47     enum NXByteOrder byteorder;
48     const char *description;
49 } NXArchInfo;
50 
51 #ifdef __cplusplus
52 extern "C" {
53 #endif /* __cplusplus */
54 
55 /* NXGetAllArchInfos() returns a pointer to an array of all known
56  * NXArchInfo structures.  The last NXArchInfo is marked by a NULL name.
57  */
58 extern const NXArchInfo *NXGetAllArchInfos(void);
59 
60 /* NXGetLocalArchInfo() returns the NXArchInfo for the local host, or NULL
61  * if none is known.
62  */
63 extern const NXArchInfo *NXGetLocalArchInfo(void);
64 
65 /* NXGetArchInfoFromName() and NXGetArchInfoFromCpuType() return the
66  * NXArchInfo from the architecture's name or cputype/cpusubtype
67  * combination.  A cpusubtype of CPU_SUBTYPE_MULTIPLE can be used
68  * to request the most general NXArchInfo known for the given cputype.
69  * NULL is returned if no matching NXArchInfo can be found.
70  */
71 extern const NXArchInfo *NXGetArchInfoFromName(const char *name);
72 extern const NXArchInfo *NXGetArchInfoFromCpuType(cpu_type_t cputype,
73 						  cpu_subtype_t cpusubtype);
74 
75 /* The above interfaces that return pointers to NXArchInfo structs in normal
76  * cases returns a pointer from the array returned in NXGetAllArchInfos().
77  * In some cases when the cputype is CPU_TYPE_I386 or CPU_TYPE_POWERPC it will
78  * retun malloc(3)'ed NXArchInfo struct which contains a string in the
79  * description field also a malloc(3)'ed pointer.  To allow programs not to
80  * leak memory they can call NXFreeArchInfo() on pointers returned from the
81  * above interfaces.  Since this is a new API on older systems can use the
82  * code below.  Going forward the above interfaces will only return pointers
83  * from the array returned in NXGetAllArchInfos().
84  */
85 extern void NXFreeArchInfo(const NXArchInfo *x);
86 
87 /* The code that can be used for NXFreeArchInfo() when it is not available is:
88  *
89  *	static void NXFreeArchInfo(
90  *	const NXArchInfo *x)
91  *	{
92  *	    const NXArchInfo *p;
93  *
94  *	        p = NXGetAllArchInfos();
95  *	        while(p->name != NULL){
96  *	            if(x == p)
97  *	                return;
98  *	            p++;
99  *	        }
100  *	        free((char *)x->description);
101  *	        free((NXArchInfo *)x);
102  *	}
103  */
104 
105 /* NXFindBestFatArch() is passed a cputype and cpusubtype and a set of
106  * fat_arch structs and selects the best one that matches (if any) and returns
107  * a pointer to that fat_arch struct (or NULL).  The fat_arch structs must be
108  * in the host byte order and correct such that the fat_archs really points to
109  * enough memory for nfat_arch structs.  It is possible that this routine could
110  * fail if new cputypes or cpusubtypes are added and an old version of this
111  * routine is used.  But if there is an exact match between the cputype and
112  * cpusubtype and one of the fat_arch structs this routine will always succeed.
113  */
114 extern struct fat_arch *NXFindBestFatArch(cpu_type_t cputype,
115 					  cpu_subtype_t cpusubtype,
116 					  struct fat_arch *fat_archs,
117 					  uint32_t nfat_archs);
118 
119 /* NXFindBestFatArch_64() is passed a cputype and cpusubtype and a set of
120  * fat_arch_64 structs and selects the best one that matches (if any) and
121  * returns a pointer to that fat_arch_64 struct (or NULL).  The fat_arch_64
122  * structs must be in the host byte order and correct such that the fat_archs64
123  * really points to enough memory for nfat_arch structs.  It is possible that
124  * this routine could fail if new cputypes or cpusubtypes are added and an old
125  * version of this routine is used.  But if there is an exact match between the
126  * cputype and cpusubtype and one of the fat_arch_64 structs this routine will
127  * always succeed.
128  */
129 extern struct fat_arch_64 *NXFindBestFatArch_64(cpu_type_t cputype,
130 					        cpu_subtype_t cpusubtype,
131 					        struct fat_arch_64 *fat_archs64,
132 					        uint32_t nfat_archs);
133 
134 /* NXCombineCpuSubtypes() returns the resulting cpusubtype when combining two
135  * different cpusubtypes for the specified cputype.  If the two cpusubtypes
136  * can't be combined (the specific subtypes are mutually exclusive) -1 is
137  * returned indicating it is an error to combine them.  This can also fail and
138  * return -1 if new cputypes or cpusubtypes are added and an old version of
139  * this routine is used.  But if the cpusubtypes are the same they can always
140  * be combined and this routine will return the cpusubtype pass in.
141  */
142 extern cpu_subtype_t NXCombineCpuSubtypes(cpu_type_t cputype,
143 					  cpu_subtype_t cpusubtype1,
144 					  cpu_subtype_t cpusubtype2);
145 
146 #ifdef __cplusplus
147 }
148 #endif /* __cplusplus */
149 
150 #endif /* _MACH_O_ARCH_H_ */