]> git.saurik.com Git - apple/objc4.git/blame - runtime/objc-abi.h
objc4-818.2.tar.gz
[apple/objc4.git] / runtime / objc-abi.h
CommitLineData
8972963c
A
1/*
2 * Copyright (c) 2009 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
24
25#ifndef _OBJC_ABI_H
26#define _OBJC_ABI_H
27
28/*
29 * WARNING DANGER HAZARD BEWARE EEK
30 *
31 * Everything in this file is for Apple Internal use only.
32 * These will change in arbitrary OS updates and in unpredictable ways.
33 * When your program breaks, you get to keep both pieces.
34 */
35
36/*
37 * objc-abi.h: Declarations for functions used by compiler codegen.
38 */
39
40#include <malloc/malloc.h>
c1e772c4 41#include <TargetConditionals.h>
8972963c
A
42#include <objc/objc.h>
43#include <objc/runtime.h>
44#include <objc/message.h>
45
66799735
A
46/* Linker metadata symbols */
47
48// NSObject was in Foundation/CF on macOS < 10.8.
34d5b5e8 49#if TARGET_OS_OSX && (__x86_64__ || __i386__)
66799735
A
50#if __OBJC2__
51
52OBJC_EXPORT const char __objc_nsobject_class_10_5
53 __asm__("$ld$hide$os10.5$_OBJC_CLASS_$_NSObject");
54OBJC_EXPORT const char __objc_nsobject_class_10_6
55 __asm__("$ld$hide$os10.6$_OBJC_CLASS_$_NSObject");
56OBJC_EXPORT const char __objc_nsobject_class_10_7
57 __asm__("$ld$hide$os10.7$_OBJC_CLASS_$_NSObject");
58
59OBJC_EXPORT const char __objc_nsobject_metaclass_10_5
60 __asm__("$ld$hide$os10.5$_OBJC_METACLASS_$_NSObject");
61OBJC_EXPORT const char __objc_nsobject_metaclass_10_6
62 __asm__("$ld$hide$os10.6$_OBJC_METACLASS_$_NSObject");
63OBJC_EXPORT const char __objc_nsobject_metaclass_10_7
64 __asm__("$ld$hide$os10.7$_OBJC_METACLASS_$_NSObject");
65
66OBJC_EXPORT const char __objc_nsobject_isa_10_5
67 __asm__("$ld$hide$os10.5$_OBJC_IVAR_$_NSObject.isa");
68OBJC_EXPORT const char __objc_nsobject_isa_10_6
69 __asm__("$ld$hide$os10.6$_OBJC_IVAR_$_NSObject.isa");
70OBJC_EXPORT const char __objc_nsobject_isa_10_7
71 __asm__("$ld$hide$os10.7$_OBJC_IVAR_$_NSObject.isa");
72
73#else
74
75OBJC_EXPORT const char __objc_nsobject_class_10_5
76 __asm__("$ld$hide$os10.5$.objc_class_name_NSObject");
77OBJC_EXPORT const char __objc_nsobject_class_10_6
78 __asm__("$ld$hide$os10.6$.objc_class_name_NSObject");
79OBJC_EXPORT const char __objc_nsobject_class_10_7
80 __asm__("$ld$hide$os10.7$.objc_class_name_NSObject");
81
82#endif
83#endif
84
8972963c
A
85/* Runtime startup. */
86
87// Old static initializer. Used by old crt1.o and old bug workarounds.
4a109af3
A
88OBJC_EXPORT void
89_objcInit(void)
90 OBJC_AVAILABLE(10.0, 2.0, 9.0, 1.0, 2.0);
8972963c 91
8070259c
A
92/* Images */
93
94// Description of an Objective-C image.
95// __DATA,__objc_imageinfo stores one of these.
96typedef struct objc_image_info {
97 uint32_t version; // currently 0
98 uint32_t flags;
c1e772c4
A
99
100#if __cplusplus >= 201103L
101 private:
102 enum : uint32_t {
13ba007e 103 // 1 byte assorted flags
c1e772c4
A
104 IsReplacement = 1<<0, // used for Fix&Continue, now ignored
105 SupportsGC = 1<<1, // image supports GC
106 RequiresGC = 1<<2, // image requires GC
107 OptimizedByDyld = 1<<3, // image is from an optimized shared cache
108 CorrectedSynthesize = 1<<4, // used for an old workaround, now ignored
109 IsSimulated = 1<<5, // image compiled for a simulator platform
110 HasCategoryClassProperties = 1<<6, // class properties in category_t
1807f628 111 OptimizedByDyldClosure = 1 << 7, // dyld (not the shared cache) optimized this.
c1e772c4 112
13ba007e
A
113 // 1 byte Swift unstable ABI version number
114 SwiftUnstableVersionMaskShift = 8,
115 SwiftUnstableVersionMask = 0xff << SwiftUnstableVersionMaskShift,
c1e772c4 116
13ba007e
A
117 // 2 byte Swift stable ABI version number
118 SwiftStableVersionMaskShift = 16,
119 SwiftStableVersionMask = 0xffffUL << SwiftStableVersionMaskShift
c1e772c4 120 };
13ba007e 121 public:
c1e772c4 122 enum : uint32_t {
13ba007e
A
123 // Values for SwiftUnstableVersion
124 // All stable ABIs store SwiftVersion5 here.
c1e772c4
A
125 SwiftVersion1 = 1,
126 SwiftVersion1_2 = 2,
127 SwiftVersion2 = 3,
13ba007e
A
128 SwiftVersion3 = 4,
129 SwiftVersion4 = 5,
130 SwiftVersion4_1 = 6,
131 SwiftVersion4_2 = 6, // [sic]
132 SwiftVersion5 = 7
c1e772c4
A
133 };
134
135 public:
136 bool isReplacement() const { return flags & IsReplacement; }
137 bool supportsGC() const { return flags & SupportsGC; }
138 bool requiresGC() const { return flags & RequiresGC; }
139 bool optimizedByDyld() const { return flags & OptimizedByDyld; }
140 bool hasCategoryClassProperties() const { return flags & HasCategoryClassProperties; }
1807f628 141 bool optimizedByDyldClosure() const { return flags & OptimizedByDyldClosure; }
13ba007e
A
142 bool containsSwift() const { return (flags & SwiftUnstableVersionMask) != 0; }
143 uint32_t swiftUnstableVersion() const { return (flags & SwiftUnstableVersionMask) >> SwiftUnstableVersionMaskShift; }
c1e772c4 144#endif
8070259c
A
145} objc_image_info;
146
c1e772c4
A
147/*
148IsReplacement:
149 Once used for Fix&Continue in old OS X object files (not final linked images)
150 Not currently used.
151
152SupportsGC:
153 App: GC is required. Framework: GC is supported but not required.
154
155RequiresGC:
156 Framework: GC is required.
157
158OptimizedByDyld:
159 Assorted metadata precooked in the dyld shared cache.
160 Never set for images outside the shared cache file itself.
161
162CorrectedSynthesize:
163 Once used on old iOS to mark images that did not have a particular
164 miscompile. Not used by the runtime.
165
166IsSimulated:
167 Image was compiled for a simulator platform. Not used by the runtime.
168
169HasClassProperties:
170 New ABI: category_t.classProperties fields are present.
171 Old ABI: Set by some compilers. Not used by the runtime.
172*/
8070259c 173
34d5b5e8
A
174// Description of an expected duplicate class name.
175// __DATA,__objc_dupclass stores one of these. Only the main image is
176// consulted for these purposes.
177typedef struct _objc_duplicate_class {
178 uint32_t version;
179 uint32_t flags;
180 const char name[64];
181} objc_duplicate_class;
182#define OBJC_HAS_DUPLICATE_CLASS 1
8972963c
A
183
184/* Properties */
185
186// Read or write an object property. Not all object properties use these.
4a109af3
A
187OBJC_EXPORT id _Nullable
188objc_getProperty(id _Nullable self, SEL _Nonnull _cmd,
189 ptrdiff_t offset, BOOL atomic)
190 OBJC_AVAILABLE(10.5, 2.0, 9.0, 1.0, 2.0);
8972963c 191
4a109af3
A
192OBJC_EXPORT void
193objc_setProperty(id _Nullable self, SEL _Nonnull _cmd, ptrdiff_t offset,
194 id _Nullable newValue, BOOL atomic, signed char shouldCopy)
195 OBJC_AVAILABLE(10.5, 2.0, 9.0, 1.0, 2.0);
196
197OBJC_EXPORT void
198objc_setProperty_atomic(id _Nullable self, SEL _Nonnull _cmd,
199 id _Nullable newValue, ptrdiff_t offset)
200 OBJC_AVAILABLE(10.8, 6.0, 9.0, 1.0, 2.0);
201
202OBJC_EXPORT void
203objc_setProperty_nonatomic(id _Nullable self, SEL _Nonnull _cmd,
204 id _Nullable newValue, ptrdiff_t offset)
205 OBJC_AVAILABLE(10.8, 6.0, 9.0, 1.0, 2.0);
206
207OBJC_EXPORT void
208objc_setProperty_atomic_copy(id _Nullable self, SEL _Nonnull _cmd,
209 id _Nullable newValue, ptrdiff_t offset)
210 OBJC_AVAILABLE(10.8, 6.0, 9.0, 1.0, 2.0);
211
212OBJC_EXPORT void
213objc_setProperty_nonatomic_copy(id _Nullable self, SEL _Nonnull _cmd,
214 id _Nullable newValue, ptrdiff_t offset)
215 OBJC_AVAILABLE(10.8, 6.0, 9.0, 1.0, 2.0);
cd5f04f5
A
216
217
8972963c
A
218// Read or write a non-object property. Not all uses are C structs,
219// and not all C struct properties use this.
4a109af3
A
220OBJC_EXPORT void
221objc_copyStruct(void * _Nonnull dest, const void * _Nonnull src,
222 ptrdiff_t size, BOOL atomic, BOOL hasStrong)
223 OBJC_AVAILABLE(10.5, 2.0, 9.0, 1.0, 2.0);
8972963c 224
cd5f04f5 225// Perform a copy of a C++ object using striped locks. Used by non-POD C++ typed atomic properties.
4a109af3
A
226OBJC_EXPORT void
227objc_copyCppObjectAtomic(void * _Nonnull dest, const void * _Nonnull src,
228 void (* _Nonnull copyHelper)
229 (void * _Nonnull dest, const void * _Nonnull source))
230 OBJC_AVAILABLE(10.8, 6.0, 9.0, 1.0, 2.0);
8972963c
A
231
232/* Classes. */
233#if __OBJC2__
4a109af3
A
234OBJC_EXPORT IMP _Nonnull _objc_empty_vtable
235 OBJC_AVAILABLE(10.5, 2.0, 9.0, 1.0, 2.0);
8972963c
A
236#endif
237OBJC_EXPORT struct objc_cache _objc_empty_cache
4a109af3 238 OBJC_AVAILABLE(10.0, 2.0, 9.0, 1.0, 2.0);
8972963c
A
239
240
241/* Messages */
242
243#if __OBJC2__
244// objc_msgSendSuper2() takes the current search class, not its superclass.
4a109af3
A
245OBJC_EXPORT id _Nullable
246objc_msgSendSuper2(struct objc_super * _Nonnull super, SEL _Nonnull op, ...)
247 OBJC_AVAILABLE(10.6, 2.0, 9.0, 1.0, 2.0);
248
249OBJC_EXPORT void
250objc_msgSendSuper2_stret(struct objc_super * _Nonnull super,
251 SEL _Nonnull op,...)
252 OBJC_AVAILABLE(10.6, 2.0, 9.0, 1.0, 2.0)
8070259c 253 OBJC_ARM64_UNAVAILABLE;
8972963c
A
254
255// objc_msgSend_noarg() may be faster for methods with no additional arguments.
4a109af3
A
256OBJC_EXPORT id _Nullable
257objc_msgSend_noarg(id _Nullable self, SEL _Nonnull _cmd)
258 OBJC_AVAILABLE(10.7, 5.0, 9.0, 1.0, 2.0);
8972963c
A
259#endif
260
261#if __OBJC2__
262// Debug messengers. Messengers used by the compiler have a debug flavor that
263// may perform extra sanity checking.
264// Old objc_msgSendSuper() does not have a debug version; this is OBJC2 only.
265// *_fixup() do not have debug versions; use non-fixup only for debug mode.
4a109af3
A
266OBJC_EXPORT id _Nullable
267objc_msgSend_debug(id _Nullable self, SEL _Nonnull op, ...)
268 OBJC_AVAILABLE(10.7, 5.0, 9.0, 1.0, 2.0);
269
270OBJC_EXPORT id _Nullable
271objc_msgSendSuper2_debug(struct objc_super * _Nonnull super,
272 SEL _Nonnull op, ...)
273 OBJC_AVAILABLE(10.7, 5.0, 9.0, 1.0, 2.0);
274
275OBJC_EXPORT void
276objc_msgSend_stret_debug(id _Nullable self, SEL _Nonnull op, ...)
277 OBJC_AVAILABLE(10.7, 5.0, 9.0, 1.0, 2.0)
8070259c 278 OBJC_ARM64_UNAVAILABLE;
4a109af3
A
279
280OBJC_EXPORT void
281objc_msgSendSuper2_stret_debug(struct objc_super * _Nonnull super,
282 SEL _Nonnull op,...)
283 OBJC_AVAILABLE(10.7, 5.0, 9.0, 1.0, 2.0)
8070259c 284 OBJC_ARM64_UNAVAILABLE;
8972963c
A
285
286# if defined(__i386__)
4a109af3
A
287OBJC_EXPORT double
288objc_msgSend_fpret_debug(id _Nullable self, SEL _Nonnull op, ...)
289 OBJC_AVAILABLE(10.7, 5.0, 9.0, 1.0, 2.0);
8972963c 290# elif defined(__x86_64__)
4a109af3
A
291OBJC_EXPORT long double
292objc_msgSend_fpret_debug(id _Nullable self, SEL _Nonnull op, ...)
293 OBJC_AVAILABLE(10.7, 5.0, 9.0, 1.0, 2.0);
8972963c 294# if __STDC_VERSION__ >= 199901L
4a109af3
A
295OBJC_EXPORT _Complex long double
296objc_msgSend_fp2ret_debug(id _Nullable self, SEL _Nonnull op, ...)
297 OBJC_AVAILABLE(10.7, 5.0, 9.0, 1.0, 2.0);
8972963c 298# else
4a109af3
A
299OBJC_EXPORT void
300objc_msgSend_fp2ret_debug(id _Nullable self, SEL _Nonnull op, ...)
301 OBJC_AVAILABLE(10.7, 5.0, 9.0, 1.0, 2.0);
8972963c
A
302# endif
303# endif
304
305#endif
306
c1e772c4
A
307#if __OBJC2__
308// Lookup messengers.
309// These are not callable C functions. Do not call them directly.
310// The caller should set the method parameters, call objc_msgLookup(),
311// then immediately call the returned IMP.
312//
313// Generic ABI:
314// - Callee-saved registers are preserved.
315// - Receiver and selector registers may be modified. These values must
316// be passed to the called IMP. Other parameter registers are preserved.
317// - Caller-saved non-parameter registers are not preserved. Some of
318// these registers are used to pass data from objc_msgLookup() to
319// the called IMP and must not be disturbed by the caller.
320// - Red zone is not preserved.
321// See each architecture's implementation for details.
322
4a109af3
A
323OBJC_EXPORT void
324objc_msgLookup(void)
325 OBJC_AVAILABLE(10.12, 10.0, 10.0, 3.0, 2.0);
326
327OBJC_EXPORT void
328objc_msgLookupSuper2(void)
329 OBJC_AVAILABLE(10.12, 10.0, 10.0, 3.0, 2.0);
330
331OBJC_EXPORT void
332objc_msgLookup_stret(void)
333 OBJC_AVAILABLE(10.12, 10.0, 10.0, 3.0, 2.0)
c1e772c4 334 OBJC_ARM64_UNAVAILABLE;
4a109af3
A
335
336OBJC_EXPORT void
337objc_msgLookupSuper2_stret(void)
338 OBJC_AVAILABLE(10.12, 10.0, 10.0, 3.0, 2.0)
c1e772c4
A
339 OBJC_ARM64_UNAVAILABLE;
340
341# if defined(__i386__)
4a109af3
A
342OBJC_EXPORT void
343objc_msgLookup_fpret(void)
344 OBJC_AVAILABLE(10.12, 10.0, 10.0, 3.0, 2.0);
345
c1e772c4 346# elif defined(__x86_64__)
4a109af3
A
347OBJC_EXPORT void
348objc_msgLookup_fpret(void)
349 OBJC_AVAILABLE(10.12, 10.0, 10.0, 3.0, 2.0);
350
351OBJC_EXPORT void
352objc_msgLookup_fp2ret(void)
353 OBJC_AVAILABLE(10.12, 10.0, 10.0, 3.0, 2.0);
c1e772c4
A
354# endif
355
356#endif
357
66799735
A
358#if (TARGET_OS_OSX || TARGET_OS_SIMULATOR) && defined(__x86_64__)
359// objc_msgSend_fixup() was used for vtable-dispatchable call sites.
360// The symbols remain exported on macOS for binary compatibility.
361// The symbols can probably be removed from iOS simulator but we haven't tried.
4a109af3
A
362OBJC_EXPORT void
363objc_msgSend_fixup(void)
66799735 364 __OSX_DEPRECATED(10.5, 10.8, "fixup dispatch is no longer optimized");
4a109af3
A
365
366OBJC_EXPORT void
367objc_msgSend_stret_fixup(void)
66799735 368 __OSX_DEPRECATED(10.5, 10.8, "fixup dispatch is no longer optimized");
4a109af3
A
369
370OBJC_EXPORT void
371objc_msgSendSuper2_fixup(void)
66799735 372 __OSX_DEPRECATED(10.5, 10.8, "fixup dispatch is no longer optimized");
4a109af3
A
373
374OBJC_EXPORT void
375objc_msgSendSuper2_stret_fixup(void)
66799735 376 __OSX_DEPRECATED(10.5, 10.8, "fixup dispatch is no longer optimized");
4a109af3
A
377
378OBJC_EXPORT void
379objc_msgSend_fpret_fixup(void)
66799735 380 __OSX_DEPRECATED(10.5, 10.8, "fixup dispatch is no longer optimized");
4a109af3
A
381
382OBJC_EXPORT void
383objc_msgSend_fp2ret_fixup(void)
66799735 384 __OSX_DEPRECATED(10.5, 10.8, "fixup dispatch is no longer optimized");
8972963c
A
385#endif
386
387/* C++-compatible exception handling. */
388#if __OBJC2__
389
8972963c 390// Vtable for C++ exception typeinfo for Objective-C types.
66799735 391OBJC_EXPORT const void * _Nullable objc_ehtype_vtable[]
4a109af3 392 OBJC_AVAILABLE(10.5, 2.0, 9.0, 1.0, 2.0);
8972963c
A
393
394// C++ exception typeinfo for type `id`.
395OBJC_EXPORT struct objc_typeinfo OBJC_EHTYPE_id
4a109af3 396 OBJC_AVAILABLE(10.5, 2.0, 9.0, 1.0, 2.0);
8972963c 397
8972963c
A
398// Exception personality function for Objective-C and Objective-C++ code.
399struct _Unwind_Exception;
400struct _Unwind_Context;
401OBJC_EXPORT int
402__objc_personality_v0(int version,
403 int actions,
404 uint64_t exceptionClass,
4a109af3
A
405 struct _Unwind_Exception * _Nonnull exceptionObject,
406 struct _Unwind_Context * _Nonnull context)
407 OBJC_AVAILABLE(10.5, 2.0, 9.0, 1.0, 2.0);
8972963c
A
408
409#endif
410
c1e772c4 411/* ARC */
8972963c 412
4a109af3
A
413OBJC_EXPORT id _Nullable
414objc_retainBlock(id _Nullable)
415 OBJC_AVAILABLE(10.7, 5.0, 9.0, 1.0, 2.0);
c1e772c4
A
416
417
418/* Non-pointer isa */
419
420#if __OBJC2__
421
422// Extract class pointer from an isa field.
423
34d5b5e8 424#if TARGET_OS_SIMULATOR && !TARGET_OS_MACCATALYST && !__arm64__
c1e772c4
A
425 // No simulators use nonpointer isa yet.
426
427#elif __LP64__
428# define OBJC_HAVE_NONPOINTER_ISA 1
429# define OBJC_HAVE_PACKED_NONPOINTER_ISA 1
430
431// Packed-isa version. This one is used directly by Swift code.
432// (Class)(isa & (uintptr_t)&objc_absolute_packed_isa_class_mask) == class ptr
433OBJC_EXPORT const struct { char c; } objc_absolute_packed_isa_class_mask
4a109af3 434 OBJC_AVAILABLE(10.12, 10.0, 10.0, 3.0, 2.0);
c1e772c4 435
66799735 436#elif (__ARM_ARCH_7K__ >= 2 || (__arm64__ && !__LP64__))
c1e772c4
A
437# define OBJC_HAVE_NONPOINTER_ISA 1
438# define OBJC_HAVE_INDEXED_NONPOINTER_ISA 1
439
440// Indexed-isa version.
441// if (isa & (uintptr_t)&objc_absolute_indexed_isa_magic_mask == (uintptr_t)&objc_absolute_indexed_isa_magic_value) {
442// uintptr_t index = (isa & (uintptr_t)&objc_absolute_indexed_isa_index_mask) >> (uintptr_t)&objc_absolute_indexed_isa_index_shift;
443// cls = objc_indexed_classes[index];
444// } else
445// cls = (Class)isa;
446// }
447OBJC_EXPORT const struct { char c; } objc_absolute_indexed_isa_magic_mask
4a109af3 448 OBJC_AVAILABLE(10.12, 10.0, 10.0, 3.0, 2.0);
c1e772c4 449OBJC_EXPORT const struct { char c; } objc_absolute_indexed_isa_magic_value
4a109af3 450 OBJC_AVAILABLE(10.12, 10.0, 10.0, 3.0, 2.0);
c1e772c4 451OBJC_EXPORT const struct { char c; } objc_absolute_indexed_isa_index_mask
4a109af3 452 OBJC_AVAILABLE(10.12, 10.0, 10.0, 3.0, 2.0);
c1e772c4 453OBJC_EXPORT const struct { char c; } objc_absolute_indexed_isa_index_shift
4a109af3 454 OBJC_AVAILABLE(10.12, 10.0, 10.0, 3.0, 2.0);
c1e772c4
A
455
456#endif
457
c1e772c4 458#endif
8972963c 459
66799735
A
460
461/* Object class */
462
463// This symbol might be required for binary compatibility, so we
464// declare it here where TAPI will see it.
465#if __OBJC__ && __OBJC2__
466#pragma clang diagnostic push
467#pragma clang diagnostic ignored "-Wobjc-interface-ivars"
468#if !defined(OBJC_DECLARE_SYMBOLS)
469__OSX_AVAILABLE(10.0)
470__IOS_UNAVAILABLE __TVOS_UNAVAILABLE
1807f628
A
471__WATCHOS_UNAVAILABLE
472# ifndef __APPLE_BLEACH_SDK__
473__BRIDGEOS_UNAVAILABLE
474# endif
66799735
A
475#endif
476OBJC_ROOT_CLASS
477@interface Object {
478 Class isa;
479}
480@end
481#pragma clang diagnostic pop
482#endif
483
484
c1e772c4 485// _OBJC_ABI_H
8972963c 486#endif