authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-11-08 19:51:30-08:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-11-08 20:21:29-08:00
log1213e26ba8b88bd18e9653b571d60a030dbe2a93
treeab43ee80e5a7bb0dd8021d5ae56c316536db0051
parent25e78bd0075bc9f3c08690baa5aeb7efb4b9d3ed

macOS libc headers: add mach-o/dyld.h

libcxx depends on it

7 files changed, 2824 insertions(+), 0 deletions(-)

lib/libc/include/x86_64-macos-gnu/architecture/byte_order.h created+381
...@@ -0,0 +1,381 @@
1/*
2 * Copyright (c) 1999-2008 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/*
24 * Copyright (c) 1992 NeXT Computer, Inc.
25 *
26 * Byte ordering conversion.
27 *
28 */
29
30#ifndef _ARCHITECTURE_BYTE_ORDER_H_
31#define _ARCHITECTURE_BYTE_ORDER_H_
32
33/*
34 * Please note that the byte ordering functions in this file are deprecated.
35 * A replacement API exists in libkern/OSByteOrder.h
36 */
37
38#include <libkern/OSByteOrder.h>
39
40typedef unsigned long NXSwappedFloat;
41typedef unsigned long long NXSwappedDouble;
42
43static __inline__ __attribute__((deprecated))
44unsigned short
45NXSwapShort(
46 unsigned short inv
47)
48{
49 return (unsigned short)OSSwapInt16((uint16_t)inv);
50}
51
52static __inline__ __attribute__((deprecated))
53unsigned int
54NXSwapInt(
55 unsigned int inv
56)
57{
58 return (unsigned int)OSSwapInt32((uint32_t)inv);
59}
60
61static __inline__ __attribute__((deprecated))
62unsigned long
63NXSwapLong(
64 unsigned long inv
65)
66{
67 return (unsigned long)OSSwapInt32((uint32_t)inv);
68}
69
70static __inline__ __attribute__((deprecated))
71unsigned long long
72NXSwapLongLong(
73 unsigned long long inv
74)
75{
76 return (unsigned long long)OSSwapInt64((uint64_t)inv);
77}
78
79static __inline__ __attribute__((deprecated))
80NXSwappedFloat
81NXConvertHostFloatToSwapped(float x)
82{
83 union fconv {
84 float number;
85 NXSwappedFloat sf;
86 } u;
87 u.number = x;
88 return u.sf;
89}
90
91static __inline__ __attribute__((deprecated))
92float
93NXConvertSwappedFloatToHost(NXSwappedFloat x)
94{
95 union fconv {
96 float number;
97 NXSwappedFloat sf;
98 } u;
99 u.sf = x;
100 return u.number;
101}
102
103static __inline__ __attribute__((deprecated))
104NXSwappedDouble
105NXConvertHostDoubleToSwapped(double x)
106{
107 union dconv {
108 double number;
109 NXSwappedDouble sd;
110 } u;
111 u.number = x;
112 return u.sd;
113}
114
115static __inline__ __attribute__((deprecated))
116double
117NXConvertSwappedDoubleToHost(NXSwappedDouble x)
118{
119 union dconv {
120 double number;
121 NXSwappedDouble sd;
122 } u;
123 u.sd = x;
124 return u.number;
125}
126
127static __inline__ __attribute__((deprecated))
128NXSwappedFloat
129NXSwapFloat(NXSwappedFloat x)
130{
131 return (NXSwappedFloat)OSSwapInt32((uint32_t)x);
132}
133
134static __inline__ __attribute__((deprecated))
135NXSwappedDouble
136NXSwapDouble(NXSwappedDouble x)
137{
138 return (NXSwappedDouble)OSSwapInt64((uint64_t)x);
139}
140
141/*
142 * Identify the byte order
143 * of the current host.
144 */
145
146enum NXByteOrder {
147 NX_UnknownByteOrder,
148 NX_LittleEndian,
149 NX_BigEndian
150};
151
152static __inline__
153enum NXByteOrder
154NXHostByteOrder(void)
155{
156#if defined(__LITTLE_ENDIAN__)
157 return NX_LittleEndian;
158#elif defined(__BIG_ENDIAN__)
159 return NX_BigEndian;
160#else
161 return NX_UnknownByteOrder;
162#endif
163}
164
165static __inline__ __attribute__((deprecated))
166unsigned short
167NXSwapBigShortToHost(
168 unsigned short x
169)
170{
171 return (unsigned short)OSSwapBigToHostInt16((uint16_t)x);
172}
173
174static __inline__ __attribute__((deprecated))
175unsigned int
176NXSwapBigIntToHost(
177 unsigned int x
178)
179{
180 return (unsigned int)OSSwapBigToHostInt32((uint32_t)x);
181}
182
183static __inline__ __attribute__((deprecated))
184unsigned long
185NXSwapBigLongToHost(
186 unsigned long x
187)
188{
189 return (unsigned long)OSSwapBigToHostInt32((uint32_t)x);
190}
191
192static __inline__ __attribute__((deprecated))
193unsigned long long
194NXSwapBigLongLongToHost(
195 unsigned long long x
196)
197{
198 return (unsigned long long)OSSwapBigToHostInt64((uint64_t)x);
199}
200
201static __inline__ __attribute__((deprecated))
202double
203NXSwapBigDoubleToHost(
204 NXSwappedDouble x
205)
206{
207 return NXConvertSwappedDoubleToHost((NXSwappedDouble)OSSwapBigToHostInt64((uint64_t)x));
208}
209
210static __inline__ __attribute__((deprecated))
211float
212NXSwapBigFloatToHost(
213 NXSwappedFloat x
214)
215{
216 return NXConvertSwappedFloatToHost((NXSwappedFloat)OSSwapBigToHostInt32((uint32_t)x));
217}
218
219static __inline__ __attribute__((deprecated))
220unsigned short
221NXSwapHostShortToBig(
222 unsigned short x
223)
224{
225 return (unsigned short)OSSwapHostToBigInt16((uint16_t)x);
226}
227
228static __inline__ __attribute__((deprecated))
229unsigned int
230NXSwapHostIntToBig(
231 unsigned int x
232)
233{
234 return (unsigned int)OSSwapHostToBigInt32((uint32_t)x);
235}
236
237static __inline__ __attribute__((deprecated))
238unsigned long
239NXSwapHostLongToBig(
240 unsigned long x
241)
242{
243 return (unsigned long)OSSwapHostToBigInt32((uint32_t)x);
244}
245
246static __inline__ __attribute__((deprecated))
247unsigned long long
248NXSwapHostLongLongToBig(
249 unsigned long long x
250)
251{
252 return (unsigned long long)OSSwapHostToBigInt64((uint64_t)x);
253}
254
255static __inline__ __attribute__((deprecated))
256NXSwappedDouble
257NXSwapHostDoubleToBig(
258 double x
259)
260{
261 return (NXSwappedDouble)OSSwapHostToBigInt64((uint64_t)NXConvertHostDoubleToSwapped(x));
262}
263
264static __inline__ __attribute__((deprecated))
265NXSwappedFloat
266NXSwapHostFloatToBig(
267 float x
268)
269{
270 return (NXSwappedFloat)OSSwapHostToBigInt32((uint32_t)NXConvertHostFloatToSwapped(x));
271}
272
273static __inline__ __attribute__((deprecated))
274unsigned short
275NXSwapLittleShortToHost(
276 unsigned short x
277)
278{
279 return (unsigned short)OSSwapLittleToHostInt16((uint16_t)x);
280}
281
282static __inline__ __attribute__((deprecated))
283unsigned int
284NXSwapLittleIntToHost(
285 unsigned int x
286)
287{
288 return (unsigned int)OSSwapLittleToHostInt32((uint32_t)x);
289}
290
291static __inline__ __attribute__((deprecated))
292unsigned long
293NXSwapLittleLongToHost(
294 unsigned long x
295)
296{
297 return (unsigned long)OSSwapLittleToHostInt32((uint32_t)x);
298}
299
300static __inline__ __attribute__((deprecated))
301unsigned long long
302NXSwapLittleLongLongToHost(
303 unsigned long long x
304)
305{
306 return (unsigned long long)OSSwapLittleToHostInt64((uint64_t)x);
307}
308
309static __inline__ __attribute__((deprecated))
310double
311NXSwapLittleDoubleToHost(
312 NXSwappedDouble x
313)
314{
315 return NXConvertSwappedDoubleToHost((NXSwappedDouble)OSSwapLittleToHostInt64((uint64_t)x));
316}
317
318static __inline__ __attribute__((deprecated))
319float
320NXSwapLittleFloatToHost(
321 NXSwappedFloat x
322)
323{
324 return NXConvertSwappedFloatToHost((NXSwappedFloat)OSSwapLittleToHostInt32((uint32_t)x));
325}
326
327static __inline__ __attribute__((deprecated))
328unsigned short
329NXSwapHostShortToLittle(
330 unsigned short x
331)
332{
333 return (unsigned short)OSSwapHostToLittleInt16((uint16_t)x);
334}
335
336static __inline__ __attribute__((deprecated))
337unsigned int
338NXSwapHostIntToLittle(
339 unsigned int x
340)
341{
342 return (unsigned int)OSSwapHostToLittleInt32((uint32_t)x);
343}
344
345static __inline__ __attribute__((deprecated))
346unsigned long
347NXSwapHostLongToLittle(
348 unsigned long x
349)
350{
351 return (unsigned long)OSSwapHostToLittleInt32((uint32_t)x);
352}
353
354static __inline__ __attribute__((deprecated))
355unsigned long long
356NXSwapHostLongLongToLittle(
357 unsigned long long x
358)
359{
360 return (unsigned long long)OSSwapHostToLittleInt64((uint64_t)x);
361}
362
363static __inline__ __attribute__((deprecated))
364NXSwappedDouble
365NXSwapHostDoubleToLittle(
366 double x
367)
368{
369 return (NXSwappedDouble)OSSwapHostToLittleInt64((uint64_t)NXConvertHostDoubleToSwapped(x));
370}
371
372static __inline__ __attribute__((deprecated))
373NXSwappedFloat
374NXSwapHostFloatToLittle(
375 float x
376)
377{
378 return (NXSwappedFloat)OSSwapHostToLittleInt32((uint32_t)NXConvertHostFloatToSwapped(x));
379}
380
381#endif /* _ARCHITECTURE_BYTE_ORDER_H_ */
lib/libc/include/x86_64-macos-gnu/libkern/OSByteOrder.h created+305
...@@ -0,0 +1,305 @@
1/*
2 * Copyright (c) 2000-2006 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
5 *
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. The rights granted to you under the License
10 * may not be used to create, or enable the creation or redistribution of,
11 * unlawful or unlicensed copies of an Apple operating system, or to
12 * circumvent, violate, or enable the circumvention or violation of, any
13 * terms of an Apple operating system software license agreement.
14 *
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
17 *
18 * The Original Code and all software distributed under the License are
19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
24 * limitations under the License.
25 *
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
27 */
28
29#ifndef _OS_OSBYTEORDER_H
30#define _OS_OSBYTEORDER_H
31
32#include <stdint.h>
33#include <libkern/_OSByteOrder.h>
34
35/* Macros for swapping constant values in the preprocessing stage. */
36#define OSSwapConstInt16(x) __DARWIN_OSSwapConstInt16(x)
37#define OSSwapConstInt32(x) __DARWIN_OSSwapConstInt32(x)
38#define OSSwapConstInt64(x) __DARWIN_OSSwapConstInt64(x)
39
40#if defined(__GNUC__)
41
42#if (defined(__i386__) || defined(__x86_64__))
43#include <libkern/i386/OSByteOrder.h>
44#else
45#include <libkern/machine/OSByteOrder.h>
46#endif
47
48#else /* ! __GNUC__ */
49
50#include <libkern/machine/OSByteOrder.h>
51
52#endif /* __GNUC__ */
53
54#define OSSwapInt16(x) __DARWIN_OSSwapInt16(x)
55#define OSSwapInt32(x) __DARWIN_OSSwapInt32(x)
56#define OSSwapInt64(x) __DARWIN_OSSwapInt64(x)
57
58enum {
59 OSUnknownByteOrder,
60 OSLittleEndian,
61 OSBigEndian
62};
63
64OS_INLINE
65int32_t
66OSHostByteOrder(void)
67{
68#if defined(__LITTLE_ENDIAN__)
69 return OSLittleEndian;
70#elif defined(__BIG_ENDIAN__)
71 return OSBigEndian;
72#else
73 return OSUnknownByteOrder;
74#endif
75}
76
77#define OSReadBigInt(x, y) OSReadBigInt32(x, y)
78#define OSWriteBigInt(x, y, z) OSWriteBigInt32(x, y, z)
79#define OSSwapBigToHostInt(x) OSSwapBigToHostInt32(x)
80#define OSSwapHostToBigInt(x) OSSwapHostToBigInt32(x)
81#define OSReadLittleInt(x, y) OSReadLittleInt32(x, y)
82#define OSWriteLittleInt(x, y, z) OSWriteLittleInt32(x, y, z)
83#define OSSwapHostToLittleInt(x) OSSwapHostToLittleInt32(x)
84#define OSSwapLittleToHostInt(x) OSSwapLittleToHostInt32(x)
85
86/* Functions for loading native endian values. */
87
88OS_INLINE
89uint16_t
90_OSReadInt16(
91 const volatile void * base,
92 uintptr_t byteOffset
93 )
94{
95 return *(volatile uint16_t *)((uintptr_t)base + byteOffset);
96}
97
98OS_INLINE
99uint32_t
100_OSReadInt32(
101 const volatile void * base,
102 uintptr_t byteOffset
103 )
104{
105 return *(volatile uint32_t *)((uintptr_t)base + byteOffset);
106}
107
108OS_INLINE
109uint64_t
110_OSReadInt64(
111 const volatile void * base,
112 uintptr_t byteOffset
113 )
114{
115 return *(volatile uint64_t *)((uintptr_t)base + byteOffset);
116}
117
118/* Functions for storing native endian values. */
119
120OS_INLINE
121void
122_OSWriteInt16(
123 volatile void * base,
124 uintptr_t byteOffset,
125 uint16_t data
126 )
127{
128 *(volatile uint16_t *)((uintptr_t)base + byteOffset) = data;
129}
130
131OS_INLINE
132void
133_OSWriteInt32(
134 volatile void * base,
135 uintptr_t byteOffset,
136 uint32_t data
137 )
138{
139 *(volatile uint32_t *)((uintptr_t)base + byteOffset) = data;
140}
141
142OS_INLINE
143void
144_OSWriteInt64(
145 volatile void * base,
146 uintptr_t byteOffset,
147 uint64_t data
148 )
149{
150 *(volatile uint64_t *)((uintptr_t)base + byteOffset) = data;
151}
152
153#if defined(__BIG_ENDIAN__)
154
155/* Functions for loading big endian to host endianess. */
156
157#define OSReadBigInt16(base, byteOffset) _OSReadInt16(base, byteOffset)
158#define OSReadBigInt32(base, byteOffset) _OSReadInt32(base, byteOffset)
159#define OSReadBigInt64(base, byteOffset) _OSReadInt64(base, byteOffset)
160
161/* Functions for storing host endianess to big endian. */
162
163#define OSWriteBigInt16(base, byteOffset, data) _OSWriteInt16(base, byteOffset, data)
164#define OSWriteBigInt32(base, byteOffset, data) _OSWriteInt32(base, byteOffset, data)
165#define OSWriteBigInt64(base, byteOffset, data) _OSWriteInt64(base, byteOffset, data)
166
167/* Functions for loading little endian to host endianess. */
168
169#define OSReadLittleInt16(base, byteOffset) OSReadSwapInt16(base, byteOffset)
170#define OSReadLittleInt32(base, byteOffset) OSReadSwapInt32(base, byteOffset)
171#define OSReadLittleInt64(base, byteOffset) OSReadSwapInt64(base, byteOffset)
172
173/* Functions for storing host endianess to little endian. */
174
175#define OSWriteLittleInt16(base, byteOffset, data) OSWriteSwapInt16(base, byteOffset, data)
176#define OSWriteLittleInt32(base, byteOffset, data) OSWriteSwapInt32(base, byteOffset, data)
177#define OSWriteLittleInt64(base, byteOffset, data) OSWriteSwapInt64(base, byteOffset, data)
178
179/* Host endianess to big endian byte swapping macros for constants. */
180
181#define OSSwapHostToBigConstInt16(x) ((uint16_t)(x))
182#define OSSwapHostToBigConstInt32(x) ((uint32_t)(x))
183#define OSSwapHostToBigConstInt64(x) ((uint64_t)(x))
184
185/* Generic host endianess to big endian byte swapping functions. */
186
187#define OSSwapHostToBigInt16(x) ((uint16_t)(x))
188#define OSSwapHostToBigInt32(x) ((uint32_t)(x))
189#define OSSwapHostToBigInt64(x) ((uint64_t)(x))
190
191/* Host endianess to little endian byte swapping macros for constants. */
192
193#define OSSwapHostToLittleConstInt16(x) OSSwapConstInt16(x)
194#define OSSwapHostToLittleConstInt32(x) OSSwapConstInt32(x)
195#define OSSwapHostToLittleConstInt64(x) OSSwapConstInt64(x)
196
197/* Generic host endianess to little endian byte swapping functions. */
198
199#define OSSwapHostToLittleInt16(x) OSSwapInt16(x)
200#define OSSwapHostToLittleInt32(x) OSSwapInt32(x)
201#define OSSwapHostToLittleInt64(x) OSSwapInt64(x)
202
203/* Big endian to host endianess byte swapping macros for constants. */
204
205#define OSSwapBigToHostConstInt16(x) ((uint16_t)(x))
206#define OSSwapBigToHostConstInt32(x) ((uint32_t)(x))
207#define OSSwapBigToHostConstInt64(x) ((uint64_t)(x))
208
209/* Generic big endian to host endianess byte swapping functions. */
210
211#define OSSwapBigToHostInt16(x) ((uint16_t)(x))
212#define OSSwapBigToHostInt32(x) ((uint32_t)(x))
213#define OSSwapBigToHostInt64(x) ((uint64_t)(x))
214
215/* Little endian to host endianess byte swapping macros for constants. */
216
217#define OSSwapLittleToHostConstInt16(x) OSSwapConstInt16(x)
218#define OSSwapLittleToHostConstInt32(x) OSSwapConstInt32(x)
219#define OSSwapLittleToHostConstInt64(x) OSSwapConstInt64(x)
220
221/* Generic little endian to host endianess byte swapping functions. */
222
223#define OSSwapLittleToHostInt16(x) OSSwapInt16(x)
224#define OSSwapLittleToHostInt32(x) OSSwapInt32(x)
225#define OSSwapLittleToHostInt64(x) OSSwapInt64(x)
226
227#elif defined(__LITTLE_ENDIAN__)
228
229/* Functions for loading big endian to host endianess. */
230
231#define OSReadBigInt16(base, byteOffset) OSReadSwapInt16(base, byteOffset)
232#define OSReadBigInt32(base, byteOffset) OSReadSwapInt32(base, byteOffset)
233#define OSReadBigInt64(base, byteOffset) OSReadSwapInt64(base, byteOffset)
234
235/* Functions for storing host endianess to big endian. */
236
237#define OSWriteBigInt16(base, byteOffset, data) OSWriteSwapInt16(base, byteOffset, data)
238#define OSWriteBigInt32(base, byteOffset, data) OSWriteSwapInt32(base, byteOffset, data)
239#define OSWriteBigInt64(base, byteOffset, data) OSWriteSwapInt64(base, byteOffset, data)
240
241/* Functions for loading little endian to host endianess. */
242
243#define OSReadLittleInt16(base, byteOffset) _OSReadInt16(base, byteOffset)
244#define OSReadLittleInt32(base, byteOffset) _OSReadInt32(base, byteOffset)
245#define OSReadLittleInt64(base, byteOffset) _OSReadInt64(base, byteOffset)
246
247/* Functions for storing host endianess to little endian. */
248
249#define OSWriteLittleInt16(base, byteOffset, data) _OSWriteInt16(base, byteOffset, data)
250#define OSWriteLittleInt32(base, byteOffset, data) _OSWriteInt32(base, byteOffset, data)
251#define OSWriteLittleInt64(base, byteOffset, data) _OSWriteInt64(base, byteOffset, data)
252
253/* Host endianess to big endian byte swapping macros for constants. */
254
255#define OSSwapHostToBigConstInt16(x) OSSwapConstInt16(x)
256#define OSSwapHostToBigConstInt32(x) OSSwapConstInt32(x)
257#define OSSwapHostToBigConstInt64(x) OSSwapConstInt64(x)
258
259/* Generic host endianess to big endian byte swapping functions. */
260
261#define OSSwapHostToBigInt16(x) OSSwapInt16(x)
262#define OSSwapHostToBigInt32(x) OSSwapInt32(x)
263#define OSSwapHostToBigInt64(x) OSSwapInt64(x)
264
265/* Host endianess to little endian byte swapping macros for constants. */
266
267#define OSSwapHostToLittleConstInt16(x) ((uint16_t)(x))
268#define OSSwapHostToLittleConstInt32(x) ((uint32_t)(x))
269#define OSSwapHostToLittleConstInt64(x) ((uint64_t)(x))
270
271/* Generic host endianess to little endian byte swapping functions. */
272
273#define OSSwapHostToLittleInt16(x) ((uint16_t)(x))
274#define OSSwapHostToLittleInt32(x) ((uint32_t)(x))
275#define OSSwapHostToLittleInt64(x) ((uint64_t)(x))
276
277/* Big endian to host endianess byte swapping macros for constants. */
278
279#define OSSwapBigToHostConstInt16(x) OSSwapConstInt16(x)
280#define OSSwapBigToHostConstInt32(x) OSSwapConstInt32(x)
281#define OSSwapBigToHostConstInt64(x) OSSwapConstInt64(x)
282
283/* Generic big endian to host endianess byte swapping functions. */
284
285#define OSSwapBigToHostInt16(x) OSSwapInt16(x)
286#define OSSwapBigToHostInt32(x) OSSwapInt32(x)
287#define OSSwapBigToHostInt64(x) OSSwapInt64(x)
288
289/* Little endian to host endianess byte swapping macros for constants. */
290
291#define OSSwapLittleToHostConstInt16(x) ((uint16_t)(x))
292#define OSSwapLittleToHostConstInt32(x) ((uint32_t)(x))
293#define OSSwapLittleToHostConstInt64(x) ((uint64_t)(x))
294
295/* Generic little endian to host endianess byte swapping functions. */
296
297#define OSSwapLittleToHostInt16(x) ((uint16_t)(x))
298#define OSSwapLittleToHostInt32(x) ((uint32_t)(x))
299#define OSSwapLittleToHostInt64(x) ((uint64_t)(x))
300
301#else
302#error Unknown endianess.
303#endif
304
305#endif /* ! _OS_OSBYTEORDER_H */
lib/libc/include/x86_64-macos-gnu/libkern/i386/OSByteOrder.h created+112
...@@ -0,0 +1,112 @@
1/*
2 * Copyright (c) 1999-2006 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
5 *
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. The rights granted to you under the License
10 * may not be used to create, or enable the creation or redistribution of,
11 * unlawful or unlicensed copies of an Apple operating system, or to
12 * circumvent, violate, or enable the circumvention or violation of, any
13 * terms of an Apple operating system software license agreement.
14 *
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
17 *
18 * The Original Code and all software distributed under the License are
19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
24 * limitations under the License.
25 *
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
27 */
28
29#ifndef _OS_OSBYTEORDERI386_H
30#define _OS_OSBYTEORDERI386_H
31
32#include <stdint.h>
33#include <libkern/i386/_OSByteOrder.h>
34#include <sys/_types/_os_inline.h>
35
36/* Functions for byte reversed loads. */
37
38OS_INLINE
39uint16_t
40OSReadSwapInt16(
41 const volatile void * base,
42 uintptr_t byteOffset
43 )
44{
45 uint16_t result;
46
47 result = *(volatile uint16_t *)((uintptr_t)base + byteOffset);
48 return _OSSwapInt16(result);
49}
50
51OS_INLINE
52uint32_t
53OSReadSwapInt32(
54 const volatile void * base,
55 uintptr_t byteOffset
56 )
57{
58 uint32_t result;
59
60 result = *(volatile uint32_t *)((uintptr_t)base + byteOffset);
61 return _OSSwapInt32(result);
62}
63
64OS_INLINE
65uint64_t
66OSReadSwapInt64(
67 const volatile void * base,
68 uintptr_t byteOffset
69 )
70{
71 uint64_t result;
72
73 result = *(volatile uint64_t *)((uintptr_t)base + byteOffset);
74 return _OSSwapInt64(result);
75}
76
77/* Functions for byte reversed stores. */
78
79OS_INLINE
80void
81OSWriteSwapInt16(
82 volatile void * base,
83 uintptr_t byteOffset,
84 uint16_t data
85 )
86{
87 *(volatile uint16_t *)((uintptr_t)base + byteOffset) = _OSSwapInt16(data);
88}
89
90OS_INLINE
91void
92OSWriteSwapInt32(
93 volatile void * base,
94 uintptr_t byteOffset,
95 uint32_t data
96 )
97{
98 *(volatile uint32_t *)((uintptr_t)base + byteOffset) = _OSSwapInt32(data);
99}
100
101OS_INLINE
102void
103OSWriteSwapInt64(
104 volatile void * base,
105 uintptr_t byteOffset,
106 uint64_t data
107 )
108{
109 *(volatile uint64_t *)((uintptr_t)base + byteOffset) = _OSSwapInt64(data);
110}
111
112#endif /* ! _OS_OSBYTEORDERI386_H */
lib/libc/include/x86_64-macos-gnu/mach-o/dyld.h created+263
...@@ -0,0 +1,263 @@
1/*
2 * Copyright (c) 1999-2008 Apple 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_DYLD_H_
24#define _MACH_O_DYLD_H_
25
26
27#include <stddef.h>
28#include <stdint.h>
29#include <stdbool.h>
30
31#include <mach-o/loader.h>
32#include <Availability.h>
33
34#if __cplusplus
35extern "C" {
36#endif
37
38#ifdef __DRIVERKIT_19_0
39 #define DYLD_DRIVERKIT_UNAVAILABLE __API_UNAVAILABLE(driverkit)
40#else
41 #define DYLD_DRIVERKIT_UNAVAILABLE
42#endif
43
44/*
45 * The following functions allow you to iterate through all loaded images.
46 * This is not a thread safe operation. Another thread can add or remove
47 * an image during the iteration.
48 *
49 * Many uses of these routines can be replace by a call to dladdr() which
50 * will return the mach_header and name of an image, given an address in
51 * the image. dladdr() is thread safe.
52 */
53extern uint32_t _dyld_image_count(void) __OSX_AVAILABLE_STARTING(__MAC_10_1, __IPHONE_2_0);
54extern const struct mach_header* _dyld_get_image_header(uint32_t image_index) __OSX_AVAILABLE_STARTING(__MAC_10_1, __IPHONE_2_0);
55extern intptr_t _dyld_get_image_vmaddr_slide(uint32_t image_index) __OSX_AVAILABLE_STARTING(__MAC_10_1, __IPHONE_2_0);
56extern const char* _dyld_get_image_name(uint32_t image_index) __OSX_AVAILABLE_STARTING(__MAC_10_1, __IPHONE_2_0);
57
58
59/*
60 * The following functions allow you to install callbacks which will be called
61 * by dyld whenever an image is loaded or unloaded. During a call to _dyld_register_func_for_add_image()
62 * the callback func is called for every existing image. Later, it is called as each new image
63 * is loaded and bound (but initializers not yet run). The callback registered with
64 * _dyld_register_func_for_remove_image() is called after any terminators in an image are run
65 * and before the image is un-memory-mapped.
66 */
67extern 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);
68extern 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);
69
70
71/*
72 * NSVersionOfRunTimeLibrary() returns the current_version number of the currently dylib
73 * specifed by the libraryName. The libraryName parameter would be "bar" for /path/libbar.3.dylib and
74 * "Foo" for /path/Foo.framework/Versions/A/Foo. It returns -1 if no such library is loaded.
75 */
76extern int32_t NSVersionOfRunTimeLibrary(const char* libraryName) __OSX_AVAILABLE_STARTING(__MAC_10_1, __IPHONE_2_0);
77
78
79/*
80 * NSVersionOfLinkTimeLibrary() returns the current_version number that the main executable was linked
81 * against at build time. The libraryName parameter would be "bar" for /path/libbar.3.dylib and
82 * "Foo" for /path/Foo.framework/Versions/A/Foo. It returns -1 if the main executable did not link
83 * against the specified library.
84 */
85extern int32_t NSVersionOfLinkTimeLibrary(const char* libraryName) __OSX_AVAILABLE_STARTING(__MAC_10_1, __IPHONE_2_0);
86
87
88/*
89 * _NSGetExecutablePath() copies the path of the main executable into the buffer. The bufsize parameter
90 * should initially be the size of the buffer. The function returns 0 if the path was successfully copied,
91 * and *bufsize is left unchanged. It returns -1 if the buffer is not large enough, and *bufsize is set
92 * to the size required.
93 *
94 * Note that _NSGetExecutablePath will return "a path" to the executable not a "real path" to the executable.
95 * That is the path may be a symbolic link and not the real file. With deep directories the total bufsize
96 * needed could be more than MAXPATHLEN.
97 */
98extern int _NSGetExecutablePath(char* buf, uint32_t* bufsize) __OSX_AVAILABLE_STARTING(__MAC_10_2, __IPHONE_2_0);
99
100
101
102/*
103 * Registers a function to be called when the current thread terminates.
104 * Called by c++ compiler to implement destructors on thread_local object variables.
105 */
106extern void _tlv_atexit(void (*termFunc)(void* objAddr), void* objAddr) __OSX_AVAILABLE_STARTING(__MAC_10_10, __IPHONE_8_0);
107
108
109/*
110 * Never called. On-disk thread local variables contain a pointer to this. Once
111 * the thread local is prepared, the pointer changes to a real handler such as tlv_get_addr.
112 */
113extern void _tlv_bootstrap(void) __OSX_AVAILABLE_STARTING(__MAC_10_10, __IPHONE_8_0) DYLD_DRIVERKIT_UNAVAILABLE ;
114
115/*
116 * The following dyld API's are deprecated as of Mac OS X 10.5. They are either
117 * no longer necessary or are superceeded by dlopen and friends in <dlfcn.h>.
118 * dlopen/dlsym/dlclose have been available since Mac OS X 10.3 and work with
119 * dylibs and bundles.
120 *
121 * NSAddImage -> dlopen
122 * NSLookupSymbolInImage -> dlsym
123 * NSCreateObjectFileImageFromFile -> dlopen
124 * NSDestroyObjectFileImage -> dlclose
125 * NSLinkModule -> not needed when dlopen used
126 * NSUnLinkModule -> not needed when dlclose used
127 * NSLookupSymbolInModule -> dlsym
128 * _dyld_image_containing_address -> dladdr
129 * NSLinkEditError -> dlerror
130 *
131 */
132
133#ifndef ENUM_DYLD_BOOL
134#define ENUM_DYLD_BOOL
135 #undef FALSE
136 #undef TRUE
137 enum DYLD_BOOL { FALSE, TRUE };
138#endif /* ENUM_DYLD_BOOL */
139
140
141/* Object file image API */
142typedef enum {
143 NSObjectFileImageFailure, /* for this a message is printed on stderr */
144 NSObjectFileImageSuccess,
145 NSObjectFileImageInappropriateFile,
146 NSObjectFileImageArch,
147 NSObjectFileImageFormat, /* for this a message is printed on stderr */
148 NSObjectFileImageAccess
149} NSObjectFileImageReturnCode;
150
151typedef struct __NSObjectFileImage* NSObjectFileImage;
152
153
154
155/* NSObjectFileImage can only be used with MH_BUNDLE files */
156extern NSObjectFileImageReturnCode NSCreateObjectFileImageFromFile(const char* pathName, NSObjectFileImage *objectFileImage) __API_UNAVAILABLE(ios, tvos, watchos) DYLD_DRIVERKIT_UNAVAILABLE __OSX_DEPRECATED(10.1, 10.5, "dlopen()");
157extern NSObjectFileImageReturnCode NSCreateObjectFileImageFromMemory(const void *address, size_t size, NSObjectFileImage *objectFileImage) __API_UNAVAILABLE(ios, tvos, watchos) DYLD_DRIVERKIT_UNAVAILABLE __OSX_DEPRECATED(10.1, 10.5, "");
158extern bool NSDestroyObjectFileImage(NSObjectFileImage objectFileImage) __API_UNAVAILABLE(ios, tvos, watchos) DYLD_DRIVERKIT_UNAVAILABLE __OSX_DEPRECATED(10.1, 10.5, "dlclose()");
159
160extern uint32_t NSSymbolDefinitionCountInObjectFileImage(NSObjectFileImage objectFileImage) __API_UNAVAILABLE(ios, tvos, watchos) DYLD_DRIVERKIT_UNAVAILABLE __OSX_DEPRECATED(10.1, 10.5, "");
161extern const char* NSSymbolDefinitionNameInObjectFileImage(NSObjectFileImage objectFileImage, uint32_t ordinal) __API_UNAVAILABLE(ios, tvos, watchos) DYLD_DRIVERKIT_UNAVAILABLE __OSX_DEPRECATED(10.1, 10.5, "");
162extern uint32_t NSSymbolReferenceCountInObjectFileImage(NSObjectFileImage objectFileImage) __API_UNAVAILABLE(ios, tvos, watchos) DYLD_DRIVERKIT_UNAVAILABLE __OSX_DEPRECATED(10.1, 10.5, "");
163extern const char* NSSymbolReferenceNameInObjectFileImage(NSObjectFileImage objectFileImage, uint32_t ordinal, bool *tentative_definition) __API_UNAVAILABLE(ios, tvos, watchos) DYLD_DRIVERKIT_UNAVAILABLE __OSX_DEPRECATED(10.1, 10.5, "");
164extern bool NSIsSymbolDefinedInObjectFileImage(NSObjectFileImage objectFileImage, const char* symbolName) __API_UNAVAILABLE(ios, tvos, watchos) DYLD_DRIVERKIT_UNAVAILABLE __OSX_DEPRECATED(10.1, 10.4, "dlsym()");
165extern void* NSGetSectionDataInObjectFileImage(NSObjectFileImage objectFileImage, const char* segmentName, const char* sectionName, size_t *size) __API_UNAVAILABLE(ios, tvos, watchos) DYLD_DRIVERKIT_UNAVAILABLE __OSX_DEPRECATED(10.1, 10.5, "getsectiondata()");
166
167typedef struct __NSModule* NSModule;
168extern const char* NSNameOfModule(NSModule m) __API_UNAVAILABLE(ios, tvos, watchos) DYLD_DRIVERKIT_UNAVAILABLE __OSX_DEPRECATED(10.1, 10.5, "");
169extern const char* NSLibraryNameForModule(NSModule m) __API_UNAVAILABLE(ios, tvos, watchos) DYLD_DRIVERKIT_UNAVAILABLE __OSX_DEPRECATED(10.1, 10.5, "");
170
171extern NSModule NSLinkModule(NSObjectFileImage objectFileImage, const char* moduleName, uint32_t options) __API_UNAVAILABLE(ios, tvos, watchos) DYLD_DRIVERKIT_UNAVAILABLE __OSX_DEPRECATED(10.1, 10.5, "dlopen()");
172#define NSLINKMODULE_OPTION_NONE 0x0
173#define NSLINKMODULE_OPTION_BINDNOW 0x1
174#define NSLINKMODULE_OPTION_PRIVATE 0x2
175#define NSLINKMODULE_OPTION_RETURN_ON_ERROR 0x4
176#define NSLINKMODULE_OPTION_DONT_CALL_MOD_INIT_ROUTINES 0x8
177#define NSLINKMODULE_OPTION_TRAILING_PHYS_NAME 0x10
178
179extern bool NSUnLinkModule(NSModule module, uint32_t options) __API_UNAVAILABLE(ios, tvos, watchos) DYLD_DRIVERKIT_UNAVAILABLE __OSX_DEPRECATED(10.1, 10.5, "");
180#define NSUNLINKMODULE_OPTION_NONE 0x0
181#define NSUNLINKMODULE_OPTION_KEEP_MEMORY_MAPPED 0x1
182#define NSUNLINKMODULE_OPTION_RESET_LAZY_REFERENCES 0x2
183
184/* symbol API */
185typedef struct __NSSymbol* NSSymbol;
186extern bool NSIsSymbolNameDefined(const char* symbolName) __API_UNAVAILABLE(ios, tvos, watchos) DYLD_DRIVERKIT_UNAVAILABLE __OSX_DEPRECATED(10.1, 10.4, "dlsym()");
187extern bool NSIsSymbolNameDefinedWithHint(const char* symbolName, const char* libraryNameHint) __API_UNAVAILABLE(ios, tvos, watchos) DYLD_DRIVERKIT_UNAVAILABLE __OSX_DEPRECATED(10.1, 10.4, "dlsym()");
188extern bool NSIsSymbolNameDefinedInImage(const struct mach_header* image, const char* symbolName) __API_UNAVAILABLE(ios, tvos, watchos) DYLD_DRIVERKIT_UNAVAILABLE __OSX_DEPRECATED(10.1, 10.4, "dlsym()");
189extern NSSymbol NSLookupAndBindSymbol(const char* symbolName) __API_UNAVAILABLE(ios, tvos, watchos) DYLD_DRIVERKIT_UNAVAILABLE __OSX_DEPRECATED(10.1, 10.4, "dlsym()");
190extern NSSymbol NSLookupAndBindSymbolWithHint(const char* symbolName, const char* libraryNameHint) __API_UNAVAILABLE(ios, tvos, watchos) DYLD_DRIVERKIT_UNAVAILABLE __OSX_DEPRECATED(10.1, 10.4, "dlsym()");
191extern NSSymbol NSLookupSymbolInModule(NSModule module, const char* symbolName) __API_UNAVAILABLE(ios, tvos, watchos) DYLD_DRIVERKIT_UNAVAILABLE __OSX_DEPRECATED(10.1, 10.5, "dlsym()");
192extern NSSymbol NSLookupSymbolInImage(const struct mach_header* image, const char* symbolName, uint32_t options) __API_UNAVAILABLE(ios, tvos, watchos) DYLD_DRIVERKIT_UNAVAILABLE __OSX_DEPRECATED(10.1, 10.5, "dlsym()");
193#define NSLOOKUPSYMBOLINIMAGE_OPTION_BIND 0x0
194#define NSLOOKUPSYMBOLINIMAGE_OPTION_BIND_NOW 0x1
195#define NSLOOKUPSYMBOLINIMAGE_OPTION_BIND_FULLY 0x2
196#define NSLOOKUPSYMBOLINIMAGE_OPTION_RETURN_ON_ERROR 0x4
197extern const char* NSNameOfSymbol(NSSymbol symbol) __API_UNAVAILABLE(ios, tvos, watchos) DYLD_DRIVERKIT_UNAVAILABLE __OSX_DEPRECATED(10.1, 10.5, "");
198extern void * NSAddressOfSymbol(NSSymbol symbol) __API_UNAVAILABLE(ios, tvos, watchos) DYLD_DRIVERKIT_UNAVAILABLE __OSX_DEPRECATED(10.1, 10.5, "dlsym()");
199extern NSModule NSModuleForSymbol(NSSymbol symbol) __API_UNAVAILABLE(ios, tvos, watchos) DYLD_DRIVERKIT_UNAVAILABLE __OSX_DEPRECATED(10.1, 10.5, "dladdr()");
200
201/* error handling API */
202typedef enum {
203 NSLinkEditFileAccessError,
204 NSLinkEditFileFormatError,
205 NSLinkEditMachResourceError,
206 NSLinkEditUnixResourceError,
207 NSLinkEditOtherError,
208 NSLinkEditWarningError,
209 NSLinkEditMultiplyDefinedError,
210 NSLinkEditUndefinedError
211} NSLinkEditErrors;
212
213/*
214 * For the NSLinkEditErrors value NSLinkEditOtherError these are the values
215 * passed to the link edit error handler as the errorNumber (what would be an
216 * errno value for NSLinkEditUnixResourceError or a kern_return_t value for
217 * NSLinkEditMachResourceError).
218 */
219typedef enum {
220 NSOtherErrorRelocation,
221 NSOtherErrorLazyBind,
222 NSOtherErrorIndrLoop,
223 NSOtherErrorLazyInit,
224 NSOtherErrorInvalidArgs
225} NSOtherErrorNumbers;
226
227extern void NSLinkEditError(NSLinkEditErrors *c, int *errorNumber, const char** fileName, const char** errorString) __API_UNAVAILABLE(ios, tvos, watchos) DYLD_DRIVERKIT_UNAVAILABLE __OSX_DEPRECATED(10.1, 10.5, "dlerror()");
228
229typedef struct {
230 void (*undefined)(const char* symbolName);
231 NSModule (*multiple)(NSSymbol s, NSModule oldModule, NSModule newModule);
232 void (*linkEdit)(NSLinkEditErrors errorClass, int errorNumber,
233 const char* fileName, const char* errorString);
234} NSLinkEditErrorHandlers;
235
236extern void NSInstallLinkEditErrorHandlers(const NSLinkEditErrorHandlers *handlers) __API_UNAVAILABLE(ios, tvos, watchos) DYLD_DRIVERKIT_UNAVAILABLE __OSX_DEPRECATED(10.1, 10.5, "");
237
238extern bool NSAddLibrary(const char* pathName) __API_UNAVAILABLE(ios, tvos, watchos) DYLD_DRIVERKIT_UNAVAILABLE __OSX_DEPRECATED(10.1, 10.4, "dlopen()");
239extern bool NSAddLibraryWithSearching(const char* pathName) __API_UNAVAILABLE(ios, tvos, watchos) DYLD_DRIVERKIT_UNAVAILABLE __OSX_DEPRECATED(10.1, 10.4, "dlopen()");
240extern const struct mach_header* NSAddImage(const char* image_name, uint32_t options) __API_UNAVAILABLE(ios, tvos, watchos) DYLD_DRIVERKIT_UNAVAILABLE __OSX_DEPRECATED(10.1, 10.5, "dlopen()");
241#define NSADDIMAGE_OPTION_NONE 0x0
242#define NSADDIMAGE_OPTION_RETURN_ON_ERROR 0x1
243#define NSADDIMAGE_OPTION_WITH_SEARCHING 0x2
244#define NSADDIMAGE_OPTION_RETURN_ONLY_IF_LOADED 0x4
245#define NSADDIMAGE_OPTION_MATCH_FILENAME_BY_INSTALLNAME 0x8
246
247extern bool _dyld_present(void) __API_UNAVAILABLE(ios, tvos, watchos) DYLD_DRIVERKIT_UNAVAILABLE __OSX_DEPRECATED(10.1, 10.5, "always true");
248extern bool _dyld_launched_prebound(void) __API_UNAVAILABLE(ios, tvos, watchos) DYLD_DRIVERKIT_UNAVAILABLE __OSX_DEPRECATED(10.1, 10.5, "moot");
249extern bool _dyld_all_twolevel_modules_prebound(void) __API_UNAVAILABLE(ios, tvos, watchos) DYLD_DRIVERKIT_UNAVAILABLE __OSX_DEPRECATED(10.3, 10.5, "moot");
250extern bool _dyld_bind_fully_image_containing_address(const void* address) __API_UNAVAILABLE(ios, tvos, watchos) DYLD_DRIVERKIT_UNAVAILABLE __OSX_DEPRECATED(10.1, 10.5, "dlopen(RTLD_NOW)");
251extern bool _dyld_image_containing_address(const void* address) __API_UNAVAILABLE(ios, tvos, watchos) DYLD_DRIVERKIT_UNAVAILABLE __OSX_DEPRECATED(10.3, 10.5, "dladdr()");
252extern void _dyld_lookup_and_bind(const char* symbol_name, void **address, NSModule* module) __API_UNAVAILABLE(ios, tvos, watchos) DYLD_DRIVERKIT_UNAVAILABLE __OSX_DEPRECATED(10.1, 10.4, "dlsym()");
253extern void _dyld_lookup_and_bind_with_hint(const char* symbol_name, const char* library_name_hint, void** address, NSModule* module) __API_UNAVAILABLE(ios, tvos, watchos) DYLD_DRIVERKIT_UNAVAILABLE __OSX_DEPRECATED(10.1, 10.4, "dlsym()");
254extern void _dyld_lookup_and_bind_fully(const char* symbol_name, void** address, NSModule* module) __API_UNAVAILABLE(ios, tvos, watchos) DYLD_DRIVERKIT_UNAVAILABLE __OSX_DEPRECATED(10.1, 10.5, "dlsym()");
255
256extern const struct mach_header* _dyld_get_image_header_containing_address(const void* address) __API_UNAVAILABLE(ios, tvos, watchos) DYLD_DRIVERKIT_UNAVAILABLE __OSX_DEPRECATED(10.3, 10.5, "dladdr()");
257
258
259#if __cplusplus
260}
261#endif
262
263#endif /* _MACH_O_DYLD_H_ */
lib/libc/include/x86_64-macos-gnu/mach-o/loader.h created+1577
...@@ -0,0 +1,1577 @@
1/*
2 * Copyright (c) 1999-2010 Apple 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 _MACHO_LOADER_H_
24#define _MACHO_LOADER_H_
25
26/*
27 * This file describes the format of mach object files.
28 */
29#include <stdint.h>
30
31/*
32 * <mach/machine.h> is needed here for the cpu_type_t and cpu_subtype_t types
33 * and contains the constants for the possible values of these types.
34 */
35#include <mach/machine.h>
36
37/*
38 * <mach/vm_prot.h> is needed here for the vm_prot_t type and contains the
39 * constants that are or'ed together for the possible values of this type.
40 */
41#include <mach/vm_prot.h>
42
43/*
44 * <machine/thread_status.h> is expected to define the flavors of the thread
45 * states and the structures of those flavors for each machine.
46 */
47#include <mach/machine/thread_status.h>
48#include <architecture/byte_order.h>
49
50/*
51 * The 32-bit mach header appears at the very beginning of the object file for
52 * 32-bit architectures.
53 */
54struct mach_header {
55 uint32_t magic; /* mach magic number identifier */
56 cpu_type_t cputype; /* cpu specifier */
57 cpu_subtype_t cpusubtype; /* machine specifier */
58 uint32_t filetype; /* type of file */
59 uint32_t ncmds; /* number of load commands */
60 uint32_t sizeofcmds; /* the size of all the load commands */
61 uint32_t flags; /* flags */
62};
63
64/* Constant for the magic field of the mach_header (32-bit architectures) */
65#define MH_MAGIC 0xfeedface /* the mach magic number */
66#define MH_CIGAM 0xcefaedfe /* NXSwapInt(MH_MAGIC) */
67
68/*
69 * The 64-bit mach header appears at the very beginning of object files for
70 * 64-bit architectures.
71 */
72struct mach_header_64 {
73 uint32_t magic; /* mach magic number identifier */
74 cpu_type_t cputype; /* cpu specifier */
75 cpu_subtype_t cpusubtype; /* machine specifier */
76 uint32_t filetype; /* type of file */
77 uint32_t ncmds; /* number of load commands */
78 uint32_t sizeofcmds; /* the size of all the load commands */
79 uint32_t flags; /* flags */
80 uint32_t reserved; /* reserved */
81};
82
83/* Constant for the magic field of the mach_header_64 (64-bit architectures) */
84#define MH_MAGIC_64 0xfeedfacf /* the 64-bit mach magic number */
85#define MH_CIGAM_64 0xcffaedfe /* NXSwapInt(MH_MAGIC_64) */
86
87/*
88 * The layout of the file depends on the filetype. For all but the MH_OBJECT
89 * file type the segments are padded out and aligned on a segment alignment
90 * boundary for efficient demand pageing. The MH_EXECUTE, MH_FVMLIB, MH_DYLIB,
91 * MH_DYLINKER and MH_BUNDLE file types also have the headers included as part
92 * of their first segment.
93 *
94 * The file type MH_OBJECT is a compact format intended as output of the
95 * assembler and input (and possibly output) of the link editor (the .o
96 * format). All sections are in one unnamed segment with no segment padding.
97 * This format is used as an executable format when the file is so small the
98 * segment padding greatly increases its size.
99 *
100 * The file type MH_PRELOAD is an executable format intended for things that
101 * are not executed under the kernel (proms, stand alones, kernels, etc). The
102 * format can be executed under the kernel but may demand paged it and not
103 * preload it before execution.
104 *
105 * A core file is in MH_CORE format and can be any in an arbritray legal
106 * Mach-O file.
107 *
108 * Constants for the filetype field of the mach_header
109 */
110#define MH_OBJECT 0x1 /* relocatable object file */
111#define MH_EXECUTE 0x2 /* demand paged executable file */
112#define MH_FVMLIB 0x3 /* fixed VM shared library file */
113#define MH_CORE 0x4 /* core file */
114#define MH_PRELOAD 0x5 /* preloaded executable file */
115#define MH_DYLIB 0x6 /* dynamically bound shared library */
116#define MH_DYLINKER 0x7 /* dynamic link editor */
117#define MH_BUNDLE 0x8 /* dynamically bound bundle file */
118#define MH_DYLIB_STUB 0x9 /* shared library stub for static */
119 /* linking only, no section contents */
120#define MH_DSYM 0xa /* companion file with only debug */
121 /* sections */
122#define MH_KEXT_BUNDLE 0xb /* x86_64 kexts */
123
124/* Constants for the flags field of the mach_header */
125#define MH_NOUNDEFS 0x1 /* the object file has no undefined
126 references */
127#define MH_INCRLINK 0x2 /* the object file is the output of an
128 incremental link against a base file
129 and can't be link edited again */
130#define MH_DYLDLINK 0x4 /* the object file is input for the
131 dynamic linker and can't be staticly
132 link edited again */
133#define MH_BINDATLOAD 0x8 /* the object file's undefined
134 references are bound by the dynamic
135 linker when loaded. */
136#define MH_PREBOUND 0x10 /* the file has its dynamic undefined
137 references prebound. */
138#define MH_SPLIT_SEGS 0x20 /* the file has its read-only and
139 read-write segments split */
140#define MH_LAZY_INIT 0x40 /* the shared library init routine is
141 to be run lazily via catching memory
142 faults to its writeable segments
143 (obsolete) */
144#define MH_TWOLEVEL 0x80 /* the image is using two-level name
145 space bindings */
146#define MH_FORCE_FLAT 0x100 /* the executable is forcing all images
147 to use flat name space bindings */
148#define MH_NOMULTIDEFS 0x200 /* this umbrella guarantees no multiple
149 defintions of symbols in its
150 sub-images so the two-level namespace
151 hints can always be used. */
152#define MH_NOFIXPREBINDING 0x400 /* do not have dyld notify the
153 prebinding agent about this
154 executable */
155#define MH_PREBINDABLE 0x800 /* the binary is not prebound but can
156 have its prebinding redone. only used
157 when MH_PREBOUND is not set. */
158#define MH_ALLMODSBOUND 0x1000 /* indicates that this binary binds to
159 all two-level namespace modules of
160 its dependent libraries. only used
161 when MH_PREBINDABLE and MH_TWOLEVEL
162 are both set. */
163#define MH_SUBSECTIONS_VIA_SYMBOLS 0x2000/* safe to divide up the sections into
164 sub-sections via symbols for dead
165 code stripping */
166#define MH_CANONICAL 0x4000 /* the binary has been canonicalized
167 via the unprebind operation */
168#define MH_WEAK_DEFINES 0x8000 /* the final linked image contains
169 external weak symbols */
170#define MH_BINDS_TO_WEAK 0x10000 /* the final linked image uses
171 weak symbols */
172
173#define MH_ALLOW_STACK_EXECUTION 0x20000/* When this bit is set, all stacks
174 in the task will be given stack
175 execution privilege. Only used in
176 MH_EXECUTE filetypes. */
177#define MH_ROOT_SAFE 0x40000 /* When this bit is set, the binary
178 declares it is safe for use in
179 processes with uid zero */
180
181#define MH_SETUID_SAFE 0x80000 /* When this bit is set, the binary
182 declares it is safe for use in
183 processes when issetugid() is true */
184
185#define MH_NO_REEXPORTED_DYLIBS 0x100000 /* When this bit is set on a dylib,
186 the static linker does not need to
187 examine dependent dylibs to see
188 if any are re-exported */
189#define MH_PIE 0x200000 /* When this bit is set, the OS will
190 load the main executable at a
191 random address. Only used in
192 MH_EXECUTE filetypes. */
193#define MH_DEAD_STRIPPABLE_DYLIB 0x400000 /* Only for use on dylibs. When
194 linking against a dylib that
195 has this bit set, the static linker
196 will automatically not create a
197 LC_LOAD_DYLIB load command to the
198 dylib if no symbols are being
199 referenced from the dylib. */
200#define MH_HAS_TLV_DESCRIPTORS 0x800000 /* Contains a section of type
201 S_THREAD_LOCAL_VARIABLES */
202
203#define MH_NO_HEAP_EXECUTION 0x1000000 /* When this bit is set, the OS will
204 run the main executable with
205 a non-executable heap even on
206 platforms (e.g. i386) that don't
207 require it. Only used in MH_EXECUTE
208 filetypes. */
209
210#define MH_APP_EXTENSION_SAFE 0x02000000 /* The code was linked for use in an
211 application extension. */
212
213#define MH_NLIST_OUTOFSYNC_WITH_DYLDINFO 0x04000000 /* The external symbols
214 listed in the nlist symbol table do
215 not include all the symbols listed in
216 the dyld info. */
217
218#define MH_SIM_SUPPORT 0x08000000 /* Allow LC_MIN_VERSION_MACOS and
219 LC_BUILD_VERSION load commands with
220 the platforms macOS, macCatalyst,
221 iOSSimulator, tvOSSimulator and
222 watchOSSimulator. */
223
224#define MH_DYLIB_IN_CACHE 0x80000000 /* Only for use on dylibs. When this bit
225 is set, the dylib is part of the dyld
226 shared cache, rather than loose in
227 the filesystem. */
228
229/*
230 * The load commands directly follow the mach_header. The total size of all
231 * of the commands is given by the sizeofcmds field in the mach_header. All
232 * load commands must have as their first two fields cmd and cmdsize. The cmd
233 * field is filled in with a constant for that command type. Each command type
234 * has a structure specifically for it. The cmdsize field is the size in bytes
235 * of the particular load command structure plus anything that follows it that
236 * is a part of the load command (i.e. section structures, strings, etc.). To
237 * advance to the next load command the cmdsize can be added to the offset or
238 * pointer of the current load command. The cmdsize for 32-bit architectures
239 * MUST be a multiple of 4 bytes and for 64-bit architectures MUST be a multiple
240 * of 8 bytes (these are forever the maximum alignment of any load commands).
241 * The padded bytes must be zero. All tables in the object file must also
242 * follow these rules so the file can be memory mapped. Otherwise the pointers
243 * to these tables will not work well or at all on some machines. With all
244 * padding zeroed like objects will compare byte for byte.
245 */
246struct load_command {
247 uint32_t cmd; /* type of load command */
248 uint32_t cmdsize; /* total size of command in bytes */
249};
250
251/*
252 * After MacOS X 10.1 when a new load command is added that is required to be
253 * understood by the dynamic linker for the image to execute properly the
254 * LC_REQ_DYLD bit will be or'ed into the load command constant. If the dynamic
255 * linker sees such a load command it it does not understand will issue a
256 * "unknown load command required for execution" error and refuse to use the
257 * image. Other load commands without this bit that are not understood will
258 * simply be ignored.
259 */
260#define LC_REQ_DYLD 0x80000000
261
262/* Constants for the cmd field of all load commands, the type */
263#define LC_SEGMENT 0x1 /* segment of this file to be mapped */
264#define LC_SYMTAB 0x2 /* link-edit stab symbol table info */
265#define LC_SYMSEG 0x3 /* link-edit gdb symbol table info (obsolete) */
266#define LC_THREAD 0x4 /* thread */
267#define LC_UNIXTHREAD 0x5 /* unix thread (includes a stack) */
268#define LC_LOADFVMLIB 0x6 /* load a specified fixed VM shared library */
269#define LC_IDFVMLIB 0x7 /* fixed VM shared library identification */
270#define LC_IDENT 0x8 /* object identification info (obsolete) */
271#define LC_FVMFILE 0x9 /* fixed VM file inclusion (internal use) */
272#define LC_PREPAGE 0xa /* prepage command (internal use) */
273#define LC_DYSYMTAB 0xb /* dynamic link-edit symbol table info */
274#define LC_LOAD_DYLIB 0xc /* load a dynamically linked shared library */
275#define LC_ID_DYLIB 0xd /* dynamically linked shared lib ident */
276#define LC_LOAD_DYLINKER 0xe /* load a dynamic linker */
277#define LC_ID_DYLINKER 0xf /* dynamic linker identification */
278#define LC_PREBOUND_DYLIB 0x10 /* modules prebound for a dynamically */
279 /* linked shared library */
280#define LC_ROUTINES 0x11 /* image routines */
281#define LC_SUB_FRAMEWORK 0x12 /* sub framework */
282#define LC_SUB_UMBRELLA 0x13 /* sub umbrella */
283#define LC_SUB_CLIENT 0x14 /* sub client */
284#define LC_SUB_LIBRARY 0x15 /* sub library */
285#define LC_TWOLEVEL_HINTS 0x16 /* two-level namespace lookup hints */
286#define LC_PREBIND_CKSUM 0x17 /* prebind checksum */
287
288/*
289 * load a dynamically linked shared library that is allowed to be missing
290 * (all symbols are weak imported).
291 */
292#define LC_LOAD_WEAK_DYLIB (0x18 | LC_REQ_DYLD)
293
294#define LC_SEGMENT_64 0x19 /* 64-bit segment of this file to be
295 mapped */
296#define LC_ROUTINES_64 0x1a /* 64-bit image routines */
297#define LC_UUID 0x1b /* the uuid */
298#define LC_RPATH (0x1c | LC_REQ_DYLD) /* runpath additions */
299#define LC_CODE_SIGNATURE 0x1d /* local of code signature */
300#define LC_SEGMENT_SPLIT_INFO 0x1e /* local of info to split segments */
301#define LC_REEXPORT_DYLIB (0x1f | LC_REQ_DYLD) /* load and re-export dylib */
302#define LC_LAZY_LOAD_DYLIB 0x20 /* delay load of dylib until first use */
303#define LC_ENCRYPTION_INFO 0x21 /* encrypted segment information */
304#define LC_DYLD_INFO 0x22 /* compressed dyld information */
305#define LC_DYLD_INFO_ONLY (0x22|LC_REQ_DYLD) /* compressed dyld information only */
306#define LC_LOAD_UPWARD_DYLIB (0x23 | LC_REQ_DYLD) /* load upward dylib */
307#define LC_VERSION_MIN_MACOSX 0x24 /* build for MacOSX min OS version */
308#define LC_VERSION_MIN_IPHONEOS 0x25 /* build for iPhoneOS min OS version */
309#define LC_FUNCTION_STARTS 0x26 /* compressed table of function start addresses */
310#define LC_DYLD_ENVIRONMENT 0x27 /* string for dyld to treat
311 like environment variable */
312#define LC_MAIN (0x28|LC_REQ_DYLD) /* replacement for LC_UNIXTHREAD */
313#define LC_DATA_IN_CODE 0x29 /* table of non-instructions in __text */
314#define LC_SOURCE_VERSION 0x2A /* source version used to build binary */
315#define LC_DYLIB_CODE_SIGN_DRS 0x2B /* Code signing DRs copied from linked dylibs */
316#define LC_ENCRYPTION_INFO_64 0x2C /* 64-bit encrypted segment information */
317#define LC_LINKER_OPTION 0x2D /* linker options in MH_OBJECT files */
318#define LC_LINKER_OPTIMIZATION_HINT 0x2E /* optimization hints in MH_OBJECT files */
319#define LC_VERSION_MIN_TVOS 0x2F /* build for AppleTV min OS version */
320#define LC_VERSION_MIN_WATCHOS 0x30 /* build for Watch min OS version */
321#define LC_NOTE 0x31 /* arbitrary data included within a Mach-O file */
322#define LC_BUILD_VERSION 0x32 /* build for platform min OS version */
323#define LC_DYLD_EXPORTS_TRIE (0x33 | LC_REQ_DYLD) /* used with linkedit_data_command, payload is trie */
324#define LC_DYLD_CHAINED_FIXUPS (0x34 | LC_REQ_DYLD) /* used with linkedit_data_command */
325
326/*
327 * A variable length string in a load command is represented by an lc_str
328 * union. The strings are stored just after the load command structure and
329 * the offset is from the start of the load command structure. The size
330 * of the string is reflected in the cmdsize field of the load command.
331 * Once again any padded bytes to bring the cmdsize field to a multiple
332 * of 4 bytes must be zero.
333 */
334union lc_str {
335 uint32_t offset; /* offset to the string */
336#ifndef __LP64__
337 char *ptr; /* pointer to the string */
338#endif
339};
340
341/*
342 * The segment load command indicates that a part of this file is to be
343 * mapped into the task's address space. The size of this segment in memory,
344 * vmsize, maybe equal to or larger than the amount to map from this file,
345 * filesize. The file is mapped starting at fileoff to the beginning of
346 * the segment in memory, vmaddr. The rest of the memory of the segment,
347 * if any, is allocated zero fill on demand. The segment's maximum virtual
348 * memory protection and initial virtual memory protection are specified
349 * by the maxprot and initprot fields. If the segment has sections then the
350 * section structures directly follow the segment command and their size is
351 * reflected in cmdsize.
352 */
353struct segment_command { /* for 32-bit architectures */
354 uint32_t cmd; /* LC_SEGMENT */
355 uint32_t cmdsize; /* includes sizeof section structs */
356 char segname[16]; /* segment name */
357 uint32_t vmaddr; /* memory address of this segment */
358 uint32_t vmsize; /* memory size of this segment */
359 uint32_t fileoff; /* file offset of this segment */
360 uint32_t filesize; /* amount to map from the file */
361 vm_prot_t maxprot; /* maximum VM protection */
362 vm_prot_t initprot; /* initial VM protection */
363 uint32_t nsects; /* number of sections in segment */
364 uint32_t flags; /* flags */
365};
366
367/*
368 * The 64-bit segment load command indicates that a part of this file is to be
369 * mapped into a 64-bit task's address space. If the 64-bit segment has
370 * sections then section_64 structures directly follow the 64-bit segment
371 * command and their size is reflected in cmdsize.
372 */
373struct segment_command_64 { /* for 64-bit architectures */
374 uint32_t cmd; /* LC_SEGMENT_64 */
375 uint32_t cmdsize; /* includes sizeof section_64 structs */
376 char segname[16]; /* segment name */
377 uint64_t vmaddr; /* memory address of this segment */
378 uint64_t vmsize; /* memory size of this segment */
379 uint64_t fileoff; /* file offset of this segment */
380 uint64_t filesize; /* amount to map from the file */
381 vm_prot_t maxprot; /* maximum VM protection */
382 vm_prot_t initprot; /* initial VM protection */
383 uint32_t nsects; /* number of sections in segment */
384 uint32_t flags; /* flags */
385};
386
387/* Constants for the flags field of the segment_command */
388#define SG_HIGHVM 0x1 /* the file contents for this segment is for
389 the high part of the VM space, the low part
390 is zero filled (for stacks in core files) */
391#define SG_FVMLIB 0x2 /* this segment is the VM that is allocated by
392 a fixed VM library, for overlap checking in
393 the link editor */
394#define SG_NORELOC 0x4 /* this segment has nothing that was relocated
395 in it and nothing relocated to it, that is
396 it maybe safely replaced without relocation*/
397#define SG_PROTECTED_VERSION_1 0x8 /* This segment is protected. If the
398 segment starts at file offset 0, the
399 first page of the segment is not
400 protected. All other pages of the
401 segment are protected. */
402#define SG_READ_ONLY 0x10 /* This segment is made read-only after fixups */
403
404
405
406/*
407 * A segment is made up of zero or more sections. Non-MH_OBJECT files have
408 * all of their segments with the proper sections in each, and padded to the
409 * specified segment alignment when produced by the link editor. The first
410 * segment of a MH_EXECUTE and MH_FVMLIB format file contains the mach_header
411 * and load commands of the object file before its first section. The zero
412 * fill sections are always last in their segment (in all formats). This
413 * allows the zeroed segment padding to be mapped into memory where zero fill
414 * sections might be. The gigabyte zero fill sections, those with the section
415 * type S_GB_ZEROFILL, can only be in a segment with sections of this type.
416 * These segments are then placed after all other segments.
417 *
418 * The MH_OBJECT format has all of its sections in one segment for
419 * compactness. There is no padding to a specified segment boundary and the
420 * mach_header and load commands are not part of the segment.
421 *
422 * Sections with the same section name, sectname, going into the same segment,
423 * segname, are combined by the link editor. The resulting section is aligned
424 * to the maximum alignment of the combined sections and is the new section's
425 * alignment. The combined sections are aligned to their original alignment in
426 * the combined section. Any padded bytes to get the specified alignment are
427 * zeroed.
428 *
429 * The format of the relocation entries referenced by the reloff and nreloc
430 * fields of the section structure for mach object files is described in the
431 * header file <reloc.h>.
432 */
433struct section { /* for 32-bit architectures */
434 char sectname[16]; /* name of this section */
435 char segname[16]; /* segment this section goes in */
436 uint32_t addr; /* memory address of this section */
437 uint32_t size; /* size in bytes of this section */
438 uint32_t offset; /* file offset of this section */
439 uint32_t align; /* section alignment (power of 2) */
440 uint32_t reloff; /* file offset of relocation entries */
441 uint32_t nreloc; /* number of relocation entries */
442 uint32_t flags; /* flags (section type and attributes)*/
443 uint32_t reserved1; /* reserved (for offset or index) */
444 uint32_t reserved2; /* reserved (for count or sizeof) */
445};
446
447struct section_64 { /* for 64-bit architectures */
448 char sectname[16]; /* name of this section */
449 char segname[16]; /* segment this section goes in */
450 uint64_t addr; /* memory address of this section */
451 uint64_t size; /* size in bytes of this section */
452 uint32_t offset; /* file offset of this section */
453 uint32_t align; /* section alignment (power of 2) */
454 uint32_t reloff; /* file offset of relocation entries */
455 uint32_t nreloc; /* number of relocation entries */
456 uint32_t flags; /* flags (section type and attributes)*/
457 uint32_t reserved1; /* reserved (for offset or index) */
458 uint32_t reserved2; /* reserved (for count or sizeof) */
459 uint32_t reserved3; /* reserved */
460};
461
462/*
463 * The flags field of a section structure is separated into two parts a section
464 * type and section attributes. The section types are mutually exclusive (it
465 * can only have one type) but the section attributes are not (it may have more
466 * than one attribute).
467 */
468#define SECTION_TYPE 0x000000ff /* 256 section types */
469#define SECTION_ATTRIBUTES 0xffffff00 /* 24 section attributes */
470
471/* Constants for the type of a section */
472#define S_REGULAR 0x0 /* regular section */
473#define S_ZEROFILL 0x1 /* zero fill on demand section */
474#define S_CSTRING_LITERALS 0x2 /* section with only literal C strings*/
475#define S_4BYTE_LITERALS 0x3 /* section with only 4 byte literals */
476#define S_8BYTE_LITERALS 0x4 /* section with only 8 byte literals */
477#define S_LITERAL_POINTERS 0x5 /* section with only pointers to */
478 /* literals */
479/*
480 * For the two types of symbol pointers sections and the symbol stubs section
481 * they have indirect symbol table entries. For each of the entries in the
482 * section the indirect symbol table entries, in corresponding order in the
483 * indirect symbol table, start at the index stored in the reserved1 field
484 * of the section structure. Since the indirect symbol table entries
485 * correspond to the entries in the section the number of indirect symbol table
486 * entries is inferred from the size of the section divided by the size of the
487 * entries in the section. For symbol pointers sections the size of the entries
488 * in the section is 4 bytes and for symbol stubs sections the byte size of the
489 * stubs is stored in the reserved2 field of the section structure.
490 */
491#define S_NON_LAZY_SYMBOL_POINTERS 0x6 /* section with only non-lazy
492 symbol pointers */
493#define S_LAZY_SYMBOL_POINTERS 0x7 /* section with only lazy symbol
494 pointers */
495#define S_SYMBOL_STUBS 0x8 /* section with only symbol
496 stubs, byte size of stub in
497 the reserved2 field */
498#define S_MOD_INIT_FUNC_POINTERS 0x9 /* section with only function
499 pointers for initialization*/
500#define S_MOD_TERM_FUNC_POINTERS 0xa /* section with only function
501 pointers for termination */
502#define S_COALESCED 0xb /* section contains symbols that
503 are to be coalesced */
504#define S_GB_ZEROFILL 0xc /* zero fill on demand section
505 (that can be larger than 4
506 gigabytes) */
507#define S_INTERPOSING 0xd /* section with only pairs of
508 function pointers for
509 interposing */
510#define S_16BYTE_LITERALS 0xe /* section with only 16 byte
511 literals */
512#define S_DTRACE_DOF 0xf /* section contains
513 DTrace Object Format */
514#define S_LAZY_DYLIB_SYMBOL_POINTERS 0x10 /* section with only lazy
515 symbol pointers to lazy
516 loaded dylibs */
517/*
518 * Section types to support thread local variables
519 */
520#define S_THREAD_LOCAL_REGULAR 0x11 /* template of initial
521 values for TLVs */
522#define S_THREAD_LOCAL_ZEROFILL 0x12 /* template of initial
523 values for TLVs */
524#define S_THREAD_LOCAL_VARIABLES 0x13 /* TLV descriptors */
525#define S_THREAD_LOCAL_VARIABLE_POINTERS 0x14 /* pointers to TLV
526 descriptors */
527#define S_THREAD_LOCAL_INIT_FUNCTION_POINTERS 0x15 /* functions to call
528 to initialize TLV
529 values */
530#define S_INIT_FUNC_OFFSETS 0x16 /* 32-bit offsets to
531 initializers */
532
533/*
534 * Constants for the section attributes part of the flags field of a section
535 * structure.
536 */
537#define SECTION_ATTRIBUTES_USR 0xff000000 /* User setable attributes */
538#define S_ATTR_PURE_INSTRUCTIONS 0x80000000 /* section contains only true
539 machine instructions */
540#define S_ATTR_NO_TOC 0x40000000 /* section contains coalesced
541 symbols that are not to be
542 in a ranlib table of
543 contents */
544#define S_ATTR_STRIP_STATIC_SYMS 0x20000000 /* ok to strip static symbols
545 in this section in files
546 with the MH_DYLDLINK flag */
547#define S_ATTR_NO_DEAD_STRIP 0x10000000 /* no dead stripping */
548#define S_ATTR_LIVE_SUPPORT 0x08000000 /* blocks are live if they
549 reference live blocks */
550#define S_ATTR_SELF_MODIFYING_CODE 0x04000000 /* Used with i386 code stubs
551 written on by dyld */
552/*
553 * If a segment contains any sections marked with S_ATTR_DEBUG then all
554 * sections in that segment must have this attribute. No section other than
555 * a section marked with this attribute may reference the contents of this
556 * section. A section with this attribute may contain no symbols and must have
557 * a section type S_REGULAR. The static linker will not copy section contents
558 * from sections with this attribute into its output file. These sections
559 * generally contain DWARF debugging info.
560 */
561#define S_ATTR_DEBUG 0x02000000 /* a debug section */
562#define SECTION_ATTRIBUTES_SYS 0x00ffff00 /* system setable attributes */
563#define S_ATTR_SOME_INSTRUCTIONS 0x00000400 /* section contains some
564 machine instructions */
565#define S_ATTR_EXT_RELOC 0x00000200 /* section has external
566 relocation entries */
567#define S_ATTR_LOC_RELOC 0x00000100 /* section has local
568 relocation entries */
569
570
571/*
572 * The names of segments and sections in them are mostly meaningless to the
573 * link-editor. But there are few things to support traditional UNIX
574 * executables that require the link-editor and assembler to use some names
575 * agreed upon by convention.
576 *
577 * The initial protection of the "__TEXT" segment has write protection turned
578 * off (not writeable).
579 *
580 * The link-editor will allocate common symbols at the end of the "__common"
581 * section in the "__DATA" segment. It will create the section and segment
582 * if needed.
583 */
584
585/* The currently known segment names and the section names in those segments */
586
587#define SEG_PAGEZERO "__PAGEZERO" /* the pagezero segment which has no */
588 /* protections and catches NULL */
589 /* references for MH_EXECUTE files */
590
591
592#define SEG_TEXT "__TEXT" /* the tradition UNIX text segment */
593#define SECT_TEXT "__text" /* the real text part of the text */
594 /* section no headers, and no padding */
595#define SECT_FVMLIB_INIT0 "__fvmlib_init0" /* the fvmlib initialization */
596 /* section */
597#define SECT_FVMLIB_INIT1 "__fvmlib_init1" /* the section following the */
598 /* fvmlib initialization */
599 /* section */
600
601#define SEG_DATA "__DATA" /* the tradition UNIX data segment */
602#define SECT_DATA "__data" /* the real initialized data section */
603 /* no padding, no bss overlap */
604#define SECT_BSS "__bss" /* the real uninitialized data section*/
605 /* no padding */
606#define SECT_COMMON "__common" /* the section common symbols are */
607 /* allocated in by the link editor */
608
609#define SEG_OBJC "__OBJC" /* objective-C runtime segment */
610#define SECT_OBJC_SYMBOLS "__symbol_table" /* symbol table */
611#define SECT_OBJC_MODULES "__module_info" /* module information */
612#define SECT_OBJC_STRINGS "__selector_strs" /* string table */
613#define SECT_OBJC_REFS "__selector_refs" /* string table */
614
615#define SEG_ICON "__ICON" /* the icon segment */
616#define SECT_ICON_HEADER "__header" /* the icon headers */
617#define SECT_ICON_TIFF "__tiff" /* the icons in tiff format */
618
619#define SEG_LINKEDIT "__LINKEDIT" /* the segment containing all structs */
620 /* created and maintained by the link */
621 /* editor. Created with -seglinkedit */
622 /* option to ld(1) for MH_EXECUTE and */
623 /* FVMLIB file types only */
624
625#define SEG_UNIXSTACK "__UNIXSTACK" /* the unix stack segment */
626
627#define SEG_IMPORT "__IMPORT" /* the segment for the self (dyld) */
628 /* modifing code stubs that has read, */
629 /* write and execute permissions */
630
631/*
632 * Fixed virtual memory shared libraries are identified by two things. The
633 * target pathname (the name of the library as found for execution), and the
634 * minor version number. The address of where the headers are loaded is in
635 * header_addr. (THIS IS OBSOLETE and no longer supported).
636 */
637struct fvmlib {
638 union lc_str name; /* library's target pathname */
639 uint32_t minor_version; /* library's minor version number */
640 uint32_t header_addr; /* library's header address */
641};
642
643/*
644 * A fixed virtual shared library (filetype == MH_FVMLIB in the mach header)
645 * contains a fvmlib_command (cmd == LC_IDFVMLIB) to identify the library.
646 * An object that uses a fixed virtual shared library also contains a
647 * fvmlib_command (cmd == LC_LOADFVMLIB) for each library it uses.
648 * (THIS IS OBSOLETE and no longer supported).
649 */
650struct fvmlib_command {
651 uint32_t cmd; /* LC_IDFVMLIB or LC_LOADFVMLIB */
652 uint32_t cmdsize; /* includes pathname string */
653 struct fvmlib fvmlib; /* the library identification */
654};
655
656/*
657 * Dynamicly linked shared libraries are identified by two things. The
658 * pathname (the name of the library as found for execution), and the
659 * compatibility version number. The pathname must match and the compatibility
660 * number in the user of the library must be greater than or equal to the
661 * library being used. The time stamp is used to record the time a library was
662 * built and copied into user so it can be use to determined if the library used
663 * at runtime is exactly the same as used to built the program.
664 */
665struct dylib {
666 union lc_str name; /* library's path name */
667 uint32_t timestamp; /* library's build time stamp */
668 uint32_t current_version; /* library's current version number */
669 uint32_t compatibility_version; /* library's compatibility vers number*/
670};
671
672/*
673 * A dynamically linked shared library (filetype == MH_DYLIB in the mach header)
674 * contains a dylib_command (cmd == LC_ID_DYLIB) to identify the library.
675 * An object that uses a dynamically linked shared library also contains a
676 * dylib_command (cmd == LC_LOAD_DYLIB, LC_LOAD_WEAK_DYLIB, or
677 * LC_REEXPORT_DYLIB) for each library it uses.
678 */
679struct dylib_command {
680 uint32_t cmd; /* LC_ID_DYLIB, LC_LOAD_{,WEAK_}DYLIB,
681 LC_REEXPORT_DYLIB */
682 uint32_t cmdsize; /* includes pathname string */
683 struct dylib dylib; /* the library identification */
684};
685
686/*
687 * A dynamically linked shared library may be a subframework of an umbrella
688 * framework. If so it will be linked with "-umbrella umbrella_name" where
689 * Where "umbrella_name" is the name of the umbrella framework. A subframework
690 * can only be linked against by its umbrella framework or other subframeworks
691 * that are part of the same umbrella framework. Otherwise the static link
692 * editor produces an error and states to link against the umbrella framework.
693 * The name of the umbrella framework for subframeworks is recorded in the
694 * following structure.
695 */
696struct sub_framework_command {
697 uint32_t cmd; /* LC_SUB_FRAMEWORK */
698 uint32_t cmdsize; /* includes umbrella string */
699 union lc_str umbrella; /* the umbrella framework name */
700};
701
702/*
703 * For dynamically linked shared libraries that are subframework of an umbrella
704 * framework they can allow clients other than the umbrella framework or other
705 * subframeworks in the same umbrella framework. To do this the subframework
706 * is built with "-allowable_client client_name" and an LC_SUB_CLIENT load
707 * command is created for each -allowable_client flag. The client_name is
708 * usually a framework name. It can also be a name used for bundles clients
709 * where the bundle is built with "-client_name client_name".
710 */
711struct sub_client_command {
712 uint32_t cmd; /* LC_SUB_CLIENT */
713 uint32_t cmdsize; /* includes client string */
714 union lc_str client; /* the client name */
715};
716
717/*
718 * A dynamically linked shared library may be a sub_umbrella of an umbrella
719 * framework. If so it will be linked with "-sub_umbrella umbrella_name" where
720 * Where "umbrella_name" is the name of the sub_umbrella framework. When
721 * staticly linking when -twolevel_namespace is in effect a twolevel namespace
722 * umbrella framework will only cause its subframeworks and those frameworks
723 * listed as sub_umbrella frameworks to be implicited linked in. Any other
724 * dependent dynamic libraries will not be linked it when -twolevel_namespace
725 * is in effect. The primary library recorded by the static linker when
726 * resolving a symbol in these libraries will be the umbrella framework.
727 * Zero or more sub_umbrella frameworks may be use by an umbrella framework.
728 * The name of a sub_umbrella framework is recorded in the following structure.
729 */
730struct sub_umbrella_command {
731 uint32_t cmd; /* LC_SUB_UMBRELLA */
732 uint32_t cmdsize; /* includes sub_umbrella string */
733 union lc_str sub_umbrella; /* the sub_umbrella framework name */
734};
735
736/*
737 * A dynamically linked shared library may be a sub_library of another shared
738 * library. If so it will be linked with "-sub_library library_name" where
739 * Where "library_name" is the name of the sub_library shared library. When
740 * staticly linking when -twolevel_namespace is in effect a twolevel namespace
741 * shared library will only cause its subframeworks and those frameworks
742 * listed as sub_umbrella frameworks and libraries listed as sub_libraries to
743 * be implicited linked in. Any other dependent dynamic libraries will not be
744 * linked it when -twolevel_namespace is in effect. The primary library
745 * recorded by the static linker when resolving a symbol in these libraries
746 * will be the umbrella framework (or dynamic library). Zero or more sub_library
747 * shared libraries may be use by an umbrella framework or (or dynamic library).
748 * The name of a sub_library framework is recorded in the following structure.
749 * For example /usr/lib/libobjc_profile.A.dylib would be recorded as "libobjc".
750 */
751struct sub_library_command {
752 uint32_t cmd; /* LC_SUB_LIBRARY */
753 uint32_t cmdsize; /* includes sub_library string */
754 union lc_str sub_library; /* the sub_library name */
755};
756
757/*
758 * A program (filetype == MH_EXECUTE) that is
759 * prebound to its dynamic libraries has one of these for each library that
760 * the static linker used in prebinding. It contains a bit vector for the
761 * modules in the library. The bits indicate which modules are bound (1) and
762 * which are not (0) from the library. The bit for module 0 is the low bit
763 * of the first byte. So the bit for the Nth module is:
764 * (linked_modules[N/8] >> N%8) & 1
765 */
766struct prebound_dylib_command {
767 uint32_t cmd; /* LC_PREBOUND_DYLIB */
768 uint32_t cmdsize; /* includes strings */
769 union lc_str name; /* library's path name */
770 uint32_t nmodules; /* number of modules in library */
771 union lc_str linked_modules; /* bit vector of linked modules */
772};
773
774/*
775 * A program that uses a dynamic linker contains a dylinker_command to identify
776 * the name of the dynamic linker (LC_LOAD_DYLINKER). And a dynamic linker
777 * contains a dylinker_command to identify the dynamic linker (LC_ID_DYLINKER).
778 * A file can have at most one of these.
779 * This struct is also used for the LC_DYLD_ENVIRONMENT load command and
780 * contains string for dyld to treat like environment variable.
781 */
782struct dylinker_command {
783 uint32_t cmd; /* LC_ID_DYLINKER, LC_LOAD_DYLINKER or
784 LC_DYLD_ENVIRONMENT */
785 uint32_t cmdsize; /* includes pathname string */
786 union lc_str name; /* dynamic linker's path name */
787};
788
789/*
790 * Thread commands contain machine-specific data structures suitable for
791 * use in the thread state primitives. The machine specific data structures
792 * follow the struct thread_command as follows.
793 * Each flavor of machine specific data structure is preceded by an uint32_t
794 * constant for the flavor of that data structure, an uint32_t that is the
795 * count of uint32_t's of the size of the state data structure and then
796 * the state data structure follows. This triple may be repeated for many
797 * flavors. The constants for the flavors, counts and state data structure
798 * definitions are expected to be in the header file <machine/thread_status.h>.
799 * These machine specific data structures sizes must be multiples of
800 * 4 bytes. The cmdsize reflects the total size of the thread_command
801 * and all of the sizes of the constants for the flavors, counts and state
802 * data structures.
803 *
804 * For executable objects that are unix processes there will be one
805 * thread_command (cmd == LC_UNIXTHREAD) created for it by the link-editor.
806 * This is the same as a LC_THREAD, except that a stack is automatically
807 * created (based on the shell's limit for the stack size). Command arguments
808 * and environment variables are copied onto that stack.
809 */
810struct thread_command {
811 uint32_t cmd; /* LC_THREAD or LC_UNIXTHREAD */
812 uint32_t cmdsize; /* total size of this command */
813 /* uint32_t flavor flavor of thread state */
814 /* uint32_t count count of uint32_t's in thread state */
815 /* struct XXX_thread_state state thread state for this flavor */
816 /* ... */
817};
818
819/*
820 * The routines command contains the address of the dynamic shared library
821 * initialization routine and an index into the module table for the module
822 * that defines the routine. Before any modules are used from the library the
823 * dynamic linker fully binds the module that defines the initialization routine
824 * and then calls it. This gets called before any module initialization
825 * routines (used for C++ static constructors) in the library.
826 */
827struct routines_command { /* for 32-bit architectures */
828 uint32_t cmd; /* LC_ROUTINES */
829 uint32_t cmdsize; /* total size of this command */
830 uint32_t init_address; /* address of initialization routine */
831 uint32_t init_module; /* index into the module table that */
832 /* the init routine is defined in */
833 uint32_t reserved1;
834 uint32_t reserved2;
835 uint32_t reserved3;
836 uint32_t reserved4;
837 uint32_t reserved5;
838 uint32_t reserved6;
839};
840
841/*
842 * The 64-bit routines command. Same use as above.
843 */
844struct routines_command_64 { /* for 64-bit architectures */
845 uint32_t cmd; /* LC_ROUTINES_64 */
846 uint32_t cmdsize; /* total size of this command */
847 uint64_t init_address; /* address of initialization routine */
848 uint64_t init_module; /* index into the module table that */
849 /* the init routine is defined in */
850 uint64_t reserved1;
851 uint64_t reserved2;
852 uint64_t reserved3;
853 uint64_t reserved4;
854 uint64_t reserved5;
855 uint64_t reserved6;
856};
857
858/*
859 * The symtab_command contains the offsets and sizes of the link-edit 4.3BSD
860 * "stab" style symbol table information as described in the header files
861 * <nlist.h> and <stab.h>.
862 */
863struct symtab_command {
864 uint32_t cmd; /* LC_SYMTAB */
865 uint32_t cmdsize; /* sizeof(struct symtab_command) */
866 uint32_t symoff; /* symbol table offset */
867 uint32_t nsyms; /* number of symbol table entries */
868 uint32_t stroff; /* string table offset */
869 uint32_t strsize; /* string table size in bytes */
870};
871
872/*
873 * This is the second set of the symbolic information which is used to support
874 * the data structures for the dynamically link editor.
875 *
876 * The original set of symbolic information in the symtab_command which contains
877 * the symbol and string tables must also be present when this load command is
878 * present. When this load command is present the symbol table is organized
879 * into three groups of symbols:
880 * local symbols (static and debugging symbols) - grouped by module
881 * defined external symbols - grouped by module (sorted by name if not lib)
882 * undefined external symbols (sorted by name if MH_BINDATLOAD is not set,
883 * and in order the were seen by the static
884 * linker if MH_BINDATLOAD is set)
885 * In this load command there are offsets and counts to each of the three groups
886 * of symbols.
887 *
888 * This load command contains a the offsets and sizes of the following new
889 * symbolic information tables:
890 * table of contents
891 * module table
892 * reference symbol table
893 * indirect symbol table
894 * The first three tables above (the table of contents, module table and
895 * reference symbol table) are only present if the file is a dynamically linked
896 * shared library. For executable and object modules, which are files
897 * containing only one module, the information that would be in these three
898 * tables is determined as follows:
899 * table of contents - the defined external symbols are sorted by name
900 * module table - the file contains only one module so everything in the
901 * file is part of the module.
902 * reference symbol table - is the defined and undefined external symbols
903 *
904 * For dynamically linked shared library files this load command also contains
905 * offsets and sizes to the pool of relocation entries for all sections
906 * separated into two groups:
907 * external relocation entries
908 * local relocation entries
909 * For executable and object modules the relocation entries continue to hang
910 * off the section structures.
911 */
912struct dysymtab_command {
913 uint32_t cmd; /* LC_DYSYMTAB */
914 uint32_t cmdsize; /* sizeof(struct dysymtab_command) */
915
916 /*
917 * The symbols indicated by symoff and nsyms of the LC_SYMTAB load command
918 * are grouped into the following three groups:
919 * local symbols (further grouped by the module they are from)
920 * defined external symbols (further grouped by the module they are from)
921 * undefined symbols
922 *
923 * The local symbols are used only for debugging. The dynamic binding
924 * process may have to use them to indicate to the debugger the local
925 * symbols for a module that is being bound.
926 *
927 * The last two groups are used by the dynamic binding process to do the
928 * binding (indirectly through the module table and the reference symbol
929 * table when this is a dynamically linked shared library file).
930 */
931 uint32_t ilocalsym; /* index to local symbols */
932 uint32_t nlocalsym; /* number of local symbols */
933
934 uint32_t iextdefsym;/* index to externally defined symbols */
935 uint32_t nextdefsym;/* number of externally defined symbols */
936
937 uint32_t iundefsym; /* index to undefined symbols */
938 uint32_t nundefsym; /* number of undefined symbols */
939
940 /*
941 * For the for the dynamic binding process to find which module a symbol
942 * is defined in the table of contents is used (analogous to the ranlib
943 * structure in an archive) which maps defined external symbols to modules
944 * they are defined in. This exists only in a dynamically linked shared
945 * library file. For executable and object modules the defined external
946 * symbols are sorted by name and is use as the table of contents.
947 */
948 uint32_t tocoff; /* file offset to table of contents */
949 uint32_t ntoc; /* number of entries in table of contents */
950
951 /*
952 * To support dynamic binding of "modules" (whole object files) the symbol
953 * table must reflect the modules that the file was created from. This is
954 * done by having a module table that has indexes and counts into the merged
955 * tables for each module. The module structure that these two entries
956 * refer to is described below. This exists only in a dynamically linked
957 * shared library file. For executable and object modules the file only
958 * contains one module so everything in the file belongs to the module.
959 */
960 uint32_t modtaboff; /* file offset to module table */
961 uint32_t nmodtab; /* number of module table entries */
962
963 /*
964 * To support dynamic module binding the module structure for each module
965 * indicates the external references (defined and undefined) each module
966 * makes. For each module there is an offset and a count into the
967 * reference symbol table for the symbols that the module references.
968 * This exists only in a dynamically linked shared library file. For
969 * executable and object modules the defined external symbols and the
970 * undefined external symbols indicates the external references.
971 */
972 uint32_t extrefsymoff; /* offset to referenced symbol table */
973 uint32_t nextrefsyms; /* number of referenced symbol table entries */
974
975 /*
976 * The sections that contain "symbol pointers" and "routine stubs" have
977 * indexes and (implied counts based on the size of the section and fixed
978 * size of the entry) into the "indirect symbol" table for each pointer
979 * and stub. For every section of these two types the index into the
980 * indirect symbol table is stored in the section header in the field
981 * reserved1. An indirect symbol table entry is simply a 32bit index into
982 * the symbol table to the symbol that the pointer or stub is referring to.
983 * The indirect symbol table is ordered to match the entries in the section.
984 */
985 uint32_t indirectsymoff; /* file offset to the indirect symbol table */
986 uint32_t nindirectsyms; /* number of indirect symbol table entries */
987
988 /*
989 * To support relocating an individual module in a library file quickly the
990 * external relocation entries for each module in the library need to be
991 * accessed efficiently. Since the relocation entries can't be accessed
992 * through the section headers for a library file they are separated into
993 * groups of local and external entries further grouped by module. In this
994 * case the presents of this load command who's extreloff, nextrel,
995 * locreloff and nlocrel fields are non-zero indicates that the relocation
996 * entries of non-merged sections are not referenced through the section
997 * structures (and the reloff and nreloc fields in the section headers are
998 * set to zero).
999 *
1000 * Since the relocation entries are not accessed through the section headers
1001 * this requires the r_address field to be something other than a section
1002 * offset to identify the item to be relocated. In this case r_address is
1003 * set to the offset from the vmaddr of the first LC_SEGMENT command.
1004 * For MH_SPLIT_SEGS images r_address is set to the the offset from the
1005 * vmaddr of the first read-write LC_SEGMENT command.
1006 *
1007 * The relocation entries are grouped by module and the module table
1008 * entries have indexes and counts into them for the group of external
1009 * relocation entries for that the module.
1010 *
1011 * For sections that are merged across modules there must not be any
1012 * remaining external relocation entries for them (for merged sections
1013 * remaining relocation entries must be local).
1014 */
1015 uint32_t extreloff; /* offset to external relocation entries */
1016 uint32_t nextrel; /* number of external relocation entries */
1017
1018 /*
1019 * All the local relocation entries are grouped together (they are not
1020 * grouped by their module since they are only used if the object is moved
1021 * from it staticly link edited address).
1022 */
1023 uint32_t locreloff; /* offset to local relocation entries */
1024 uint32_t nlocrel; /* number of local relocation entries */
1025
1026};
1027
1028/*
1029 * An indirect symbol table entry is simply a 32bit index into the symbol table
1030 * to the symbol that the pointer or stub is refering to. Unless it is for a
1031 * non-lazy symbol pointer section for a defined symbol which strip(1) as
1032 * removed. In which case it has the value INDIRECT_SYMBOL_LOCAL. If the
1033 * symbol was also absolute INDIRECT_SYMBOL_ABS is or'ed with that.
1034 */
1035#define INDIRECT_SYMBOL_LOCAL 0x80000000
1036#define INDIRECT_SYMBOL_ABS 0x40000000
1037
1038
1039/* a table of contents entry */
1040struct dylib_table_of_contents {
1041 uint32_t symbol_index; /* the defined external symbol
1042 (index into the symbol table) */
1043 uint32_t module_index; /* index into the module table this symbol
1044 is defined in */
1045};
1046
1047/* a module table entry */
1048struct dylib_module {
1049 uint32_t module_name; /* the module name (index into string table) */
1050
1051 uint32_t iextdefsym; /* index into externally defined symbols */
1052 uint32_t nextdefsym; /* number of externally defined symbols */
1053 uint32_t irefsym; /* index into reference symbol table */
1054 uint32_t nrefsym; /* number of reference symbol table entries */
1055 uint32_t ilocalsym; /* index into symbols for local symbols */
1056 uint32_t nlocalsym; /* number of local symbols */
1057
1058 uint32_t iextrel; /* index into external relocation entries */
1059 uint32_t nextrel; /* number of external relocation entries */
1060
1061 uint32_t iinit_iterm; /* low 16 bits are the index into the init
1062 section, high 16 bits are the index into
1063 the term section */
1064 uint32_t ninit_nterm; /* low 16 bits are the number of init section
1065 entries, high 16 bits are the number of
1066 term section entries */
1067
1068 uint32_t /* for this module address of the start of */
1069 objc_module_info_addr; /* the (__OBJC,__module_info) section */
1070 uint32_t /* for this module size of */
1071 objc_module_info_size; /* the (__OBJC,__module_info) section */
1072};
1073
1074/* a 64-bit module table entry */
1075struct dylib_module_64 {
1076 uint32_t module_name; /* the module name (index into string table) */
1077
1078 uint32_t iextdefsym; /* index into externally defined symbols */
1079 uint32_t nextdefsym; /* number of externally defined symbols */
1080 uint32_t irefsym; /* index into reference symbol table */
1081 uint32_t nrefsym; /* number of reference symbol table entries */
1082 uint32_t ilocalsym; /* index into symbols for local symbols */
1083 uint32_t nlocalsym; /* number of local symbols */
1084
1085 uint32_t iextrel; /* index into external relocation entries */
1086 uint32_t nextrel; /* number of external relocation entries */
1087
1088 uint32_t iinit_iterm; /* low 16 bits are the index into the init
1089 section, high 16 bits are the index into
1090 the term section */
1091 uint32_t ninit_nterm; /* low 16 bits are the number of init section
1092 entries, high 16 bits are the number of
1093 term section entries */
1094
1095 uint32_t /* for this module size of */
1096 objc_module_info_size; /* the (__OBJC,__module_info) section */
1097 uint64_t /* for this module address of the start of */
1098 objc_module_info_addr; /* the (__OBJC,__module_info) section */
1099};
1100
1101/*
1102 * The entries in the reference symbol table are used when loading the module
1103 * (both by the static and dynamic link editors) and if the module is unloaded
1104 * or replaced. Therefore all external symbols (defined and undefined) are
1105 * listed in the module's reference table. The flags describe the type of
1106 * reference that is being made. The constants for the flags are defined in
1107 * <mach-o/nlist.h> as they are also used for symbol table entries.
1108 */
1109struct dylib_reference {
1110 uint32_t isym:24, /* index into the symbol table */
1111 flags:8; /* flags to indicate the type of reference */
1112};
1113
1114/*
1115 * The twolevel_hints_command contains the offset and number of hints in the
1116 * two-level namespace lookup hints table.
1117 */
1118struct twolevel_hints_command {
1119 uint32_t cmd; /* LC_TWOLEVEL_HINTS */
1120 uint32_t cmdsize; /* sizeof(struct twolevel_hints_command) */
1121 uint32_t offset; /* offset to the hint table */
1122 uint32_t nhints; /* number of hints in the hint table */
1123};
1124
1125/*
1126 * The entries in the two-level namespace lookup hints table are twolevel_hint
1127 * structs. These provide hints to the dynamic link editor where to start
1128 * looking for an undefined symbol in a two-level namespace image. The
1129 * isub_image field is an index into the sub-images (sub-frameworks and
1130 * sub-umbrellas list) that made up the two-level image that the undefined
1131 * symbol was found in when it was built by the static link editor. If
1132 * isub-image is 0 the the symbol is expected to be defined in library and not
1133 * in the sub-images. If isub-image is non-zero it is an index into the array
1134 * of sub-images for the umbrella with the first index in the sub-images being
1135 * 1. The array of sub-images is the ordered list of sub-images of the umbrella
1136 * that would be searched for a symbol that has the umbrella recorded as its
1137 * primary library. The table of contents index is an index into the
1138 * library's table of contents. This is used as the starting point of the
1139 * binary search or a directed linear search.
1140 */
1141struct twolevel_hint {
1142 uint32_t
1143 isub_image:8, /* index into the sub images */
1144 itoc:24; /* index into the table of contents */
1145};
1146
1147/*
1148 * The prebind_cksum_command contains the value of the original check sum for
1149 * prebound files or zero. When a prebound file is first created or modified
1150 * for other than updating its prebinding information the value of the check sum
1151 * is set to zero. When the file has it prebinding re-done and if the value of
1152 * the check sum is zero the original check sum is calculated and stored in
1153 * cksum field of this load command in the output file. If when the prebinding
1154 * is re-done and the cksum field is non-zero it is left unchanged from the
1155 * input file.
1156 */
1157struct prebind_cksum_command {
1158 uint32_t cmd; /* LC_PREBIND_CKSUM */
1159 uint32_t cmdsize; /* sizeof(struct prebind_cksum_command) */
1160 uint32_t cksum; /* the check sum or zero */
1161};
1162
1163/*
1164 * The uuid load command contains a single 128-bit unique random number that
1165 * identifies an object produced by the static link editor.
1166 */
1167struct uuid_command {
1168 uint32_t cmd; /* LC_UUID */
1169 uint32_t cmdsize; /* sizeof(struct uuid_command) */
1170 uint8_t uuid[16]; /* the 128-bit uuid */
1171};
1172
1173/*
1174 * The rpath_command contains a path which at runtime should be added to
1175 * the current run path used to find @rpath prefixed dylibs.
1176 */
1177struct rpath_command {
1178 uint32_t cmd; /* LC_RPATH */
1179 uint32_t cmdsize; /* includes string */
1180 union lc_str path; /* path to add to run path */
1181};
1182
1183/*
1184 * The linkedit_data_command contains the offsets and sizes of a blob
1185 * of data in the __LINKEDIT segment.
1186 */
1187struct linkedit_data_command {
1188 uint32_t cmd; /* LC_CODE_SIGNATURE, LC_SEGMENT_SPLIT_INFO,
1189 LC_FUNCTION_STARTS, LC_DATA_IN_CODE,
1190 LC_DYLIB_CODE_SIGN_DRS,
1191 LC_LINKER_OPTIMIZATION_HINT,
1192 LC_DYLD_EXPORTS_TRIE, or
1193 LC_DYLD_CHAINED_FIXUPS. */
1194 uint32_t cmdsize; /* sizeof(struct linkedit_data_command) */
1195 uint32_t dataoff; /* file offset of data in __LINKEDIT segment */
1196 uint32_t datasize; /* file size of data in __LINKEDIT segment */
1197};
1198
1199/*
1200 * The encryption_info_command contains the file offset and size of an
1201 * of an encrypted segment.
1202 */
1203struct encryption_info_command {
1204 uint32_t cmd; /* LC_ENCRYPTION_INFO */
1205 uint32_t cmdsize; /* sizeof(struct encryption_info_command) */
1206 uint32_t cryptoff; /* file offset of encrypted range */
1207 uint32_t cryptsize; /* file size of encrypted range */
1208 uint32_t cryptid; /* which enryption system,
1209 0 means not-encrypted yet */
1210};
1211
1212/*
1213 * The encryption_info_command_64 contains the file offset and size of an
1214 * of an encrypted segment (for use in x86_64 targets).
1215 */
1216struct encryption_info_command_64 {
1217 uint32_t cmd; /* LC_ENCRYPTION_INFO_64 */
1218 uint32_t cmdsize; /* sizeof(struct encryption_info_command_64) */
1219 uint32_t cryptoff; /* file offset of encrypted range */
1220 uint32_t cryptsize; /* file size of encrypted range */
1221 uint32_t cryptid; /* which enryption system,
1222 0 means not-encrypted yet */
1223 uint32_t pad; /* padding to make this struct's size a multiple
1224 of 8 bytes */
1225};
1226
1227/*
1228 * The version_min_command contains the min OS version on which this
1229 * binary was built to run.
1230 */
1231struct version_min_command {
1232 uint32_t cmd; /* LC_VERSION_MIN_MACOSX or
1233 LC_VERSION_MIN_IPHONEOS or
1234 LC_VERSION_MIN_WATCHOS or
1235 LC_VERSION_MIN_TVOS */
1236 uint32_t cmdsize; /* sizeof(struct min_version_command) */
1237 uint32_t version; /* X.Y.Z is encoded in nibbles xxxx.yy.zz */
1238 uint32_t sdk; /* X.Y.Z is encoded in nibbles xxxx.yy.zz */
1239};
1240
1241/*
1242 * The build_version_command contains the min OS version on which this
1243 * binary was built to run for its platform. The list of known platforms and
1244 * tool values following it.
1245 */
1246struct build_version_command {
1247 uint32_t cmd; /* LC_BUILD_VERSION */
1248 uint32_t cmdsize; /* sizeof(struct build_version_command) plus */
1249 /* ntools * sizeof(struct build_tool_version) */
1250 uint32_t platform; /* platform */
1251 uint32_t minos; /* X.Y.Z is encoded in nibbles xxxx.yy.zz */
1252 uint32_t sdk; /* X.Y.Z is encoded in nibbles xxxx.yy.zz */
1253 uint32_t ntools; /* number of tool entries following this */
1254};
1255
1256struct build_tool_version {
1257 uint32_t tool; /* enum for the tool */
1258 uint32_t version; /* version number of the tool */
1259};
1260
1261/* Known values for the platform field above. */
1262#define PLATFORM_MACOS 1
1263#define PLATFORM_IOS 2
1264#define PLATFORM_TVOS 3
1265#define PLATFORM_WATCHOS 4
1266#define PLATFORM_BRIDGEOS 5
1267#define PLATFORM_MACCATALYST 6
1268#if (!defined(PLATFORM_MACCATALYST))
1269#define PLATFORM_MACCATALYST 6
1270#endif
1271#define PLATFORM_IOSSIMULATOR 7
1272#define PLATFORM_TVOSSIMULATOR 8
1273#define PLATFORM_WATCHOSSIMULATOR 9
1274#define PLATFORM_DRIVERKIT 10
1275
1276/* Known values for the tool field above. */
1277#define TOOL_CLANG 1
1278#define TOOL_SWIFT 2
1279#define TOOL_LD 3
1280
1281/*
1282 * The dyld_info_command contains the file offsets and sizes of
1283 * the new compressed form of the information dyld needs to
1284 * load the image. This information is used by dyld on Mac OS X
1285 * 10.6 and later. All information pointed to by this command
1286 * is encoded using byte streams, so no endian swapping is needed
1287 * to interpret it.
1288 */
1289struct dyld_info_command {
1290 uint32_t cmd; /* LC_DYLD_INFO or LC_DYLD_INFO_ONLY */
1291 uint32_t cmdsize; /* sizeof(struct dyld_info_command) */
1292
1293 /*
1294 * Dyld rebases an image whenever dyld loads it at an address different
1295 * from its preferred address. The rebase information is a stream
1296 * of byte sized opcodes whose symbolic names start with REBASE_OPCODE_.
1297 * Conceptually the rebase information is a table of tuples:
1298 * <seg-index, seg-offset, type>
1299 * The opcodes are a compressed way to encode the table by only
1300 * encoding when a column changes. In addition simple patterns
1301 * like "every n'th offset for m times" can be encoded in a few
1302 * bytes.
1303 */
1304 uint32_t rebase_off; /* file offset to rebase info */
1305 uint32_t rebase_size; /* size of rebase info */
1306
1307 /*
1308 * Dyld binds an image during the loading process, if the image
1309 * requires any pointers to be initialized to symbols in other images.
1310 * The bind information is a stream of byte sized
1311 * opcodes whose symbolic names start with BIND_OPCODE_.
1312 * Conceptually the bind information is a table of tuples:
1313 * <seg-index, seg-offset, type, symbol-library-ordinal, symbol-name, addend>
1314 * The opcodes are a compressed way to encode the table by only
1315 * encoding when a column changes. In addition simple patterns
1316 * like for runs of pointers initialzed to the same value can be
1317 * encoded in a few bytes.
1318 */
1319 uint32_t bind_off; /* file offset to binding info */
1320 uint32_t bind_size; /* size of binding info */
1321
1322 /*
1323 * Some C++ programs require dyld to unique symbols so that all
1324 * images in the process use the same copy of some code/data.
1325 * This step is done after binding. The content of the weak_bind
1326 * info is an opcode stream like the bind_info. But it is sorted
1327 * alphabetically by symbol name. This enable dyld to walk
1328 * all images with weak binding information in order and look
1329 * for collisions. If there are no collisions, dyld does
1330 * no updating. That means that some fixups are also encoded
1331 * in the bind_info. For instance, all calls to "operator new"
1332 * are first bound to libstdc++.dylib using the information
1333 * in bind_info. Then if some image overrides operator new
1334 * that is detected when the weak_bind information is processed
1335 * and the call to operator new is then rebound.
1336 */
1337 uint32_t weak_bind_off; /* file offset to weak binding info */
1338 uint32_t weak_bind_size; /* size of weak binding info */
1339
1340 /*
1341 * Some uses of external symbols do not need to be bound immediately.
1342 * Instead they can be lazily bound on first use. The lazy_bind
1343 * are contains a stream of BIND opcodes to bind all lazy symbols.
1344 * Normal use is that dyld ignores the lazy_bind section when
1345 * loading an image. Instead the static linker arranged for the
1346 * lazy pointer to initially point to a helper function which
1347 * pushes the offset into the lazy_bind area for the symbol
1348 * needing to be bound, then jumps to dyld which simply adds
1349 * the offset to lazy_bind_off to get the information on what
1350 * to bind.
1351 */
1352 uint32_t lazy_bind_off; /* file offset to lazy binding info */
1353 uint32_t lazy_bind_size; /* size of lazy binding infs */
1354
1355 /*
1356 * The symbols exported by a dylib are encoded in a trie. This
1357 * is a compact representation that factors out common prefixes.
1358 * It also reduces LINKEDIT pages in RAM because it encodes all
1359 * information (name, address, flags) in one small, contiguous range.
1360 * The export area is a stream of nodes. The first node sequentially
1361 * is the start node for the trie.
1362 *
1363 * Nodes for a symbol start with a uleb128 that is the length of
1364 * the exported symbol information for the string so far.
1365 * If there is no exported symbol, the node starts with a zero byte.
1366 * If there is exported info, it follows the length.
1367 *
1368 * First is a uleb128 containing flags. Normally, it is followed by
1369 * a uleb128 encoded offset which is location of the content named
1370 * by the symbol from the mach_header for the image. If the flags
1371 * is EXPORT_SYMBOL_FLAGS_REEXPORT, then following the flags is
1372 * a uleb128 encoded library ordinal, then a zero terminated
1373 * UTF8 string. If the string is zero length, then the symbol
1374 * is re-export from the specified dylib with the same name.
1375 * If the flags is EXPORT_SYMBOL_FLAGS_STUB_AND_RESOLVER, then following
1376 * the flags is two uleb128s: the stub offset and the resolver offset.
1377 * The stub is used by non-lazy pointers. The resolver is used
1378 * by lazy pointers and must be called to get the actual address to use.
1379 *
1380 * After the optional exported symbol information is a byte of
1381 * how many edges (0-255) that this node has leaving it,
1382 * followed by each edge.
1383 * Each edge is a zero terminated UTF8 of the addition chars
1384 * in the symbol, followed by a uleb128 offset for the node that
1385 * edge points to.
1386 *
1387 */
1388 uint32_t export_off; /* file offset to lazy binding info */
1389 uint32_t export_size; /* size of lazy binding infs */
1390};
1391
1392/*
1393 * The following are used to encode rebasing information
1394 */
1395#define REBASE_TYPE_POINTER 1
1396#define REBASE_TYPE_TEXT_ABSOLUTE32 2
1397#define REBASE_TYPE_TEXT_PCREL32 3
1398
1399#define REBASE_OPCODE_MASK 0xF0
1400#define REBASE_IMMEDIATE_MASK 0x0F
1401#define REBASE_OPCODE_DONE 0x00
1402#define REBASE_OPCODE_SET_TYPE_IMM 0x10
1403#define REBASE_OPCODE_SET_SEGMENT_AND_OFFSET_ULEB 0x20
1404#define REBASE_OPCODE_ADD_ADDR_ULEB 0x30
1405#define REBASE_OPCODE_ADD_ADDR_IMM_SCALED 0x40
1406#define REBASE_OPCODE_DO_REBASE_IMM_TIMES 0x50
1407#define REBASE_OPCODE_DO_REBASE_ULEB_TIMES 0x60
1408#define REBASE_OPCODE_DO_REBASE_ADD_ADDR_ULEB 0x70
1409#define REBASE_OPCODE_DO_REBASE_ULEB_TIMES_SKIPPING_ULEB 0x80
1410
1411
1412/*
1413 * The following are used to encode binding information
1414 */
1415#define BIND_TYPE_POINTER 1
1416#define BIND_TYPE_TEXT_ABSOLUTE32 2
1417#define BIND_TYPE_TEXT_PCREL32 3
1418
1419#define BIND_SPECIAL_DYLIB_SELF 0
1420#define BIND_SPECIAL_DYLIB_MAIN_EXECUTABLE -1
1421#define BIND_SPECIAL_DYLIB_FLAT_LOOKUP -2
1422#define BIND_SPECIAL_DYLIB_WEAK_LOOKUP -3
1423
1424#define BIND_SYMBOL_FLAGS_WEAK_IMPORT 0x1
1425#define BIND_SYMBOL_FLAGS_NON_WEAK_DEFINITION 0x8
1426
1427#define BIND_OPCODE_MASK 0xF0
1428#define BIND_IMMEDIATE_MASK 0x0F
1429#define BIND_OPCODE_DONE 0x00
1430#define BIND_OPCODE_SET_DYLIB_ORDINAL_IMM 0x10
1431#define BIND_OPCODE_SET_DYLIB_ORDINAL_ULEB 0x20
1432#define BIND_OPCODE_SET_DYLIB_SPECIAL_IMM 0x30
1433#define BIND_OPCODE_SET_SYMBOL_TRAILING_FLAGS_IMM 0x40
1434#define BIND_OPCODE_SET_TYPE_IMM 0x50
1435#define BIND_OPCODE_SET_ADDEND_SLEB 0x60
1436#define BIND_OPCODE_SET_SEGMENT_AND_OFFSET_ULEB 0x70
1437#define BIND_OPCODE_ADD_ADDR_ULEB 0x80
1438#define BIND_OPCODE_DO_BIND 0x90
1439#define BIND_OPCODE_DO_BIND_ADD_ADDR_ULEB 0xA0
1440#define BIND_OPCODE_DO_BIND_ADD_ADDR_IMM_SCALED 0xB0
1441#define BIND_OPCODE_DO_BIND_ULEB_TIMES_SKIPPING_ULEB 0xC0
1442#define BIND_OPCODE_THREADED 0xD0
1443#define BIND_SUBOPCODE_THREADED_SET_BIND_ORDINAL_TABLE_SIZE_ULEB 0x00
1444#define BIND_SUBOPCODE_THREADED_APPLY 0x01
1445
1446
1447/*
1448 * The following are used on the flags byte of a terminal node
1449 * in the export information.
1450 */
1451#define EXPORT_SYMBOL_FLAGS_KIND_MASK 0x03
1452#define EXPORT_SYMBOL_FLAGS_KIND_REGULAR 0x00
1453#define EXPORT_SYMBOL_FLAGS_KIND_THREAD_LOCAL 0x01
1454#define EXPORT_SYMBOL_FLAGS_KIND_ABSOLUTE 0x02
1455#define EXPORT_SYMBOL_FLAGS_WEAK_DEFINITION 0x04
1456#define EXPORT_SYMBOL_FLAGS_REEXPORT 0x08
1457#define EXPORT_SYMBOL_FLAGS_STUB_AND_RESOLVER 0x10
1458
1459/*
1460 * The linker_option_command contains linker options embedded in object files.
1461 */
1462struct linker_option_command {
1463 uint32_t cmd; /* LC_LINKER_OPTION only used in MH_OBJECT filetypes */
1464 uint32_t cmdsize;
1465 uint32_t count; /* number of strings */
1466 /* concatenation of zero terminated UTF8 strings.
1467 Zero filled at end to align */
1468};
1469
1470/*
1471 * The symseg_command contains the offset and size of the GNU style
1472 * symbol table information as described in the header file <symseg.h>.
1473 * The symbol roots of the symbol segments must also be aligned properly
1474 * in the file. So the requirement of keeping the offsets aligned to a
1475 * multiple of a 4 bytes translates to the length field of the symbol
1476 * roots also being a multiple of a long. Also the padding must again be
1477 * zeroed. (THIS IS OBSOLETE and no longer supported).
1478 */
1479struct symseg_command {
1480 uint32_t cmd; /* LC_SYMSEG */
1481 uint32_t cmdsize; /* sizeof(struct symseg_command) */
1482 uint32_t offset; /* symbol segment offset */
1483 uint32_t size; /* symbol segment size in bytes */
1484};
1485
1486/*
1487 * The ident_command contains a free format string table following the
1488 * ident_command structure. The strings are null terminated and the size of
1489 * the command is padded out with zero bytes to a multiple of 4 bytes/
1490 * (THIS IS OBSOLETE and no longer supported).
1491 */
1492struct ident_command {
1493 uint32_t cmd; /* LC_IDENT */
1494 uint32_t cmdsize; /* strings that follow this command */
1495};
1496
1497/*
1498 * The fvmfile_command contains a reference to a file to be loaded at the
1499 * specified virtual address. (Presently, this command is reserved for
1500 * internal use. The kernel ignores this command when loading a program into
1501 * memory).
1502 */
1503struct fvmfile_command {
1504 uint32_t cmd; /* LC_FVMFILE */
1505 uint32_t cmdsize; /* includes pathname string */
1506 union lc_str name; /* files pathname */
1507 uint32_t header_addr; /* files virtual address */
1508};
1509
1510
1511/*
1512 * The entry_point_command is a replacement for thread_command.
1513 * It is used for main executables to specify the location (file offset)
1514 * of main(). If -stack_size was used at link time, the stacksize
1515 * field will contain the stack size need for the main thread.
1516 */
1517struct entry_point_command {
1518 uint32_t cmd; /* LC_MAIN only used in MH_EXECUTE filetypes */
1519 uint32_t cmdsize; /* 24 */
1520 uint64_t entryoff; /* file (__TEXT) offset of main() */
1521 uint64_t stacksize;/* if not zero, initial stack size */
1522};
1523
1524
1525/*
1526 * The source_version_command is an optional load command containing
1527 * the version of the sources used to build the binary.
1528 */
1529struct source_version_command {
1530 uint32_t cmd; /* LC_SOURCE_VERSION */
1531 uint32_t cmdsize; /* 16 */
1532 uint64_t version; /* A.B.C.D.E packed as a24.b10.c10.d10.e10 */
1533};
1534
1535
1536/*
1537 * The LC_DATA_IN_CODE load commands uses a linkedit_data_command
1538 * to point to an array of data_in_code_entry entries. Each entry
1539 * describes a range of data in a code section.
1540 */
1541struct data_in_code_entry {
1542 uint32_t offset; /* from mach_header to start of data range*/
1543 uint16_t length; /* number of bytes in data range */
1544 uint16_t kind; /* a DICE_KIND_* value */
1545};
1546#define DICE_KIND_DATA 0x0001
1547#define DICE_KIND_JUMP_TABLE8 0x0002
1548#define DICE_KIND_JUMP_TABLE16 0x0003
1549#define DICE_KIND_JUMP_TABLE32 0x0004
1550#define DICE_KIND_ABS_JUMP_TABLE32 0x0005
1551
1552
1553
1554/*
1555 * Sections of type S_THREAD_LOCAL_VARIABLES contain an array
1556 * of tlv_descriptor structures.
1557 */
1558struct tlv_descriptor
1559{
1560 void* (*thunk)(struct tlv_descriptor*);
1561 unsigned long key;
1562 unsigned long offset;
1563};
1564
1565/*
1566 * LC_NOTE commands describe a region of arbitrary data included in a Mach-O
1567 * file. Its initial use is to record extra data in MH_CORE files.
1568 */
1569struct note_command {
1570 uint32_t cmd; /* LC_NOTE */
1571 uint32_t cmdsize; /* sizeof(struct note_command) */
1572 char data_owner[16]; /* owner name for this LC_NOTE */
1573 uint64_t offset; /* file offset of this data */
1574 uint64_t size; /* length of data region */
1575};
1576
1577#endif /* _MACHO_LOADER_H_ */
lib/libc/include/x86_64-macos-gnu/mach/vm_prot.h created+152
...@@ -0,0 +1,152 @@
1/*
2 * Copyright (c) 2000-2002 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
5 *
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. The rights granted to you under the License
10 * may not be used to create, or enable the creation or redistribution of,
11 * unlawful or unlicensed copies of an Apple operating system, or to
12 * circumvent, violate, or enable the circumvention or violation of, any
13 * terms of an Apple operating system software license agreement.
14 *
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
17 *
18 * The Original Code and all software distributed under the License are
19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
24 * limitations under the License.
25 *
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
27 */
28/*
29 * @OSF_COPYRIGHT@
30 */
31/*
32 * Mach Operating System
33 * Copyright (c) 1991,1990,1989,1988,1987 Carnegie Mellon University
34 * All Rights Reserved.
35 *
36 * Permission to use, copy, modify and distribute this software and its
37 * documentation is hereby granted, provided that both the copyright
38 * notice and this permission notice appear in all copies of the
39 * software, derivative works or modified versions, and any portions
40 * thereof, and that both notices appear in supporting documentation.
41 *
42 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
43 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
44 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
45 *
46 * Carnegie Mellon requests users of this software to return to
47 *
48 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
49 * School of Computer Science
50 * Carnegie Mellon University
51 * Pittsburgh PA 15213-3890
52 *
53 * any improvements or extensions that they make and grant Carnegie Mellon
54 * the rights to redistribute these changes.
55 */
56/*
57 */
58/*
59 * File: mach/vm_prot.h
60 * Author: Avadis Tevanian, Jr., Michael Wayne Young
61 *
62 * Virtual memory protection definitions.
63 *
64 */
65
66#ifndef _MACH_VM_PROT_H_
67#define _MACH_VM_PROT_H_
68
69/*
70 * Types defined:
71 *
72 * vm_prot_t VM protection values.
73 */
74
75typedef int vm_prot_t;
76
77/*
78 * Protection values, defined as bits within the vm_prot_t type
79 */
80
81#define VM_PROT_NONE ((vm_prot_t) 0x00)
82
83#define VM_PROT_READ ((vm_prot_t) 0x01) /* read permission */
84#define VM_PROT_WRITE ((vm_prot_t) 0x02) /* write permission */
85#define VM_PROT_EXECUTE ((vm_prot_t) 0x04) /* execute permission */
86
87/*
88 * The default protection for newly-created virtual memory
89 */
90
91#define VM_PROT_DEFAULT (VM_PROT_READ|VM_PROT_WRITE)
92
93/*
94 * The maximum privileges possible, for parameter checking.
95 */
96
97#define VM_PROT_ALL (VM_PROT_READ|VM_PROT_WRITE|VM_PROT_EXECUTE)
98
99/*
100 * An invalid protection value.
101 * Used only by memory_object_lock_request to indicate no change
102 * to page locks. Using -1 here is a bad idea because it
103 * looks like VM_PROT_ALL and then some.
104 */
105
106#define VM_PROT_NO_CHANGE ((vm_prot_t) 0x08)
107
108/*
109 * When a caller finds that he cannot obtain write permission on a
110 * mapped entry, the following flag can be used. The entry will
111 * be made "needs copy" effectively copying the object (using COW),
112 * and write permission will be added to the maximum protections
113 * for the associated entry.
114 */
115
116#define VM_PROT_COPY ((vm_prot_t) 0x10)
117
118
119/*
120 * Another invalid protection value.
121 * Used only by memory_object_data_request upon an object
122 * which has specified a copy_call copy strategy. It is used
123 * when the kernel wants a page belonging to a copy of the
124 * object, and is only asking the object as a result of
125 * following a shadow chain. This solves the race between pages
126 * being pushed up by the memory manager and the kernel
127 * walking down the shadow chain.
128 */
129
130#define VM_PROT_WANTS_COPY ((vm_prot_t) 0x10)
131
132
133/*
134 * Another invalid protection value.
135 * Indicates that the other protection bits are to be applied as a mask
136 * against the actual protection bits of the map entry.
137 */
138#define VM_PROT_IS_MASK ((vm_prot_t) 0x40)
139
140/*
141 * Another invalid protection value to support execute-only protection.
142 * VM_PROT_STRIP_READ is a special marker that tells mprotect to not
143 * set VM_PROT_READ. We have to do it this way because existing code
144 * expects the system to set VM_PROT_READ if VM_PROT_EXECUTE is set.
145 * VM_PROT_EXECUTE_ONLY is just a convenience value to indicate that
146 * the memory should be executable and explicitly not readable. It will
147 * be ignored on platforms that do not support this type of protection.
148 */
149#define VM_PROT_STRIP_READ ((vm_prot_t) 0x80)
150#define VM_PROT_EXECUTE_ONLY (VM_PROT_EXECUTE|VM_PROT_STRIP_READ)
151
152#endif /* _MACH_VM_PROT_H_ */
lib/libc/include/x86_64-macos-gnu/sys/_types/_os_inline.h created+34
...@@ -0,0 +1,34 @@
1/*
2 * Copyright (c) 2003-2012 Apple Inc. All rights reserved.
3 *
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
5 *
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. The rights granted to you under the License
10 * may not be used to create, or enable the creation or redistribution of,
11 * unlawful or unlicensed copies of an Apple operating system, or to
12 * circumvent, violate, or enable the circumvention or violation of, any
13 * terms of an Apple operating system software license agreement.
14 *
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
17 *
18 * The Original Code and all software distributed under the License are
19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
24 * limitations under the License.
25 *
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
27 */
28#if !defined(OS_INLINE)
29# if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
30# define OS_INLINE static inline
31# else
32# define OS_INLINE static __inline__
33# endif
34#endif /* OS_INLINE */