2 * Copyright (c) 2009 Apple Inc. All Rights Reserved.
4 * @APPLE_LICENSE_HEADER_START@
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
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.
21 * @APPLE_LICENSE_HEADER_END@
29 * WARNING DANGER HAZARD BEWARE EEK
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.
37 * objc-abi.h: Declarations for functions used by compiler codegen.
40 #include <malloc/malloc.h>
41 #include <TargetConditionals.h>
42 #include <objc/objc.h>
43 #include <objc/runtime.h>
44 #include <objc/message.h>
46 /* Linker metadata symbols */
48 // NSObject was in Foundation/CF on macOS < 10.8.
52 OBJC_EXPORT
const char __objc_nsobject_class_10_5
53 __asm__("$ld$hide$os10.5$_OBJC_CLASS_$_NSObject");
54 OBJC_EXPORT
const char __objc_nsobject_class_10_6
55 __asm__("$ld$hide$os10.6$_OBJC_CLASS_$_NSObject");
56 OBJC_EXPORT
const char __objc_nsobject_class_10_7
57 __asm__("$ld$hide$os10.7$_OBJC_CLASS_$_NSObject");
59 OBJC_EXPORT
const char __objc_nsobject_metaclass_10_5
60 __asm__("$ld$hide$os10.5$_OBJC_METACLASS_$_NSObject");
61 OBJC_EXPORT
const char __objc_nsobject_metaclass_10_6
62 __asm__("$ld$hide$os10.6$_OBJC_METACLASS_$_NSObject");
63 OBJC_EXPORT
const char __objc_nsobject_metaclass_10_7
64 __asm__("$ld$hide$os10.7$_OBJC_METACLASS_$_NSObject");
66 OBJC_EXPORT
const char __objc_nsobject_isa_10_5
67 __asm__("$ld$hide$os10.5$_OBJC_IVAR_$_NSObject.isa");
68 OBJC_EXPORT
const char __objc_nsobject_isa_10_6
69 __asm__("$ld$hide$os10.6$_OBJC_IVAR_$_NSObject.isa");
70 OBJC_EXPORT
const char __objc_nsobject_isa_10_7
71 __asm__("$ld$hide$os10.7$_OBJC_IVAR_$_NSObject.isa");
75 OBJC_EXPORT
const char __objc_nsobject_class_10_5
76 __asm__("$ld$hide$os10.5$.objc_class_name_NSObject");
77 OBJC_EXPORT
const char __objc_nsobject_class_10_6
78 __asm__("$ld$hide$os10.6$.objc_class_name_NSObject");
79 OBJC_EXPORT
const char __objc_nsobject_class_10_7
80 __asm__("$ld$hide$os10.7$.objc_class_name_NSObject");
85 /* Runtime startup. */
87 // Old static initializer. Used by old crt1.o and old bug workarounds.
90 OBJC_AVAILABLE(10.0, 2.0, 9.0, 1.0, 2.0);
94 // Description of an Objective-C image.
95 // __DATA,__objc_imageinfo stores one of these.
96 typedef struct objc_image_info
{
97 uint32_t version
; // currently 0
100 #if __cplusplus >= 201103L
103 // 1 byte assorted flags
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
111 OptimizedByDyldClosure
= 1 << 7, // dyld (not the shared cache) optimized this.
113 // 1 byte Swift unstable ABI version number
114 SwiftUnstableVersionMaskShift
= 8,
115 SwiftUnstableVersionMask
= 0xff << SwiftUnstableVersionMaskShift
,
117 // 2 byte Swift stable ABI version number
118 SwiftStableVersionMaskShift
= 16,
119 SwiftStableVersionMask
= 0xffffUL
<< SwiftStableVersionMaskShift
123 // Values for SwiftUnstableVersion
124 // All stable ABIs store SwiftVersion5 here.
131 SwiftVersion4_2
= 6, // [sic]
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
; }
141 bool optimizedByDyldClosure() const { return flags
& OptimizedByDyldClosure
; }
142 bool containsSwift() const { return (flags
& SwiftUnstableVersionMask
) != 0; }
143 uint32_t swiftUnstableVersion() const { return (flags
& SwiftUnstableVersionMask
) >> SwiftUnstableVersionMaskShift
; }
149 Once used for Fix&Continue in old OS X object files (not final linked images)
153 App: GC is required. Framework: GC is supported but not required.
156 Framework: GC is required.
159 Assorted metadata precooked in the dyld shared cache.
160 Never set for images outside the shared cache file itself.
163 Once used on old iOS to mark images that did not have a particular
164 miscompile. Not used by the runtime.
167 Image was compiled for a simulator platform. Not used by the runtime.
170 New ABI: category_t.classProperties fields are present.
171 Old ABI: Set by some compilers. Not used by the runtime.
177 // Read or write an object property. Not all object properties use these.
178 OBJC_EXPORT id _Nullable
179 objc_getProperty(id _Nullable self
, SEL _Nonnull _cmd
,
180 ptrdiff_t offset
, BOOL atomic
)
181 OBJC_AVAILABLE(10.5, 2.0, 9.0, 1.0, 2.0);
184 objc_setProperty(id _Nullable self
, SEL _Nonnull _cmd
, ptrdiff_t offset
,
185 id _Nullable newValue
, BOOL atomic
, signed char shouldCopy
)
186 OBJC_AVAILABLE(10.5, 2.0, 9.0, 1.0, 2.0);
189 objc_setProperty_atomic(id _Nullable self
, SEL _Nonnull _cmd
,
190 id _Nullable newValue
, ptrdiff_t offset
)
191 OBJC_AVAILABLE(10.8, 6.0, 9.0, 1.0, 2.0);
194 objc_setProperty_nonatomic(id _Nullable self
, SEL _Nonnull _cmd
,
195 id _Nullable newValue
, ptrdiff_t offset
)
196 OBJC_AVAILABLE(10.8, 6.0, 9.0, 1.0, 2.0);
199 objc_setProperty_atomic_copy(id _Nullable self
, SEL _Nonnull _cmd
,
200 id _Nullable newValue
, ptrdiff_t offset
)
201 OBJC_AVAILABLE(10.8, 6.0, 9.0, 1.0, 2.0);
204 objc_setProperty_nonatomic_copy(id _Nullable self
, SEL _Nonnull _cmd
,
205 id _Nullable newValue
, ptrdiff_t offset
)
206 OBJC_AVAILABLE(10.8, 6.0, 9.0, 1.0, 2.0);
209 // Read or write a non-object property. Not all uses are C structs,
210 // and not all C struct properties use this.
212 objc_copyStruct(void * _Nonnull dest
, const void * _Nonnull src
,
213 ptrdiff_t size
, BOOL atomic
, BOOL hasStrong
)
214 OBJC_AVAILABLE(10.5, 2.0, 9.0, 1.0, 2.0);
216 // Perform a copy of a C++ object using striped locks. Used by non-POD C++ typed atomic properties.
218 objc_copyCppObjectAtomic(void * _Nonnull dest
, const void * _Nonnull src
,
219 void (* _Nonnull copyHelper
)
220 (void * _Nonnull dest
, const void * _Nonnull source
))
221 OBJC_AVAILABLE(10.8, 6.0, 9.0, 1.0, 2.0);
225 OBJC_EXPORT IMP _Nonnull _objc_empty_vtable
226 OBJC_AVAILABLE(10.5, 2.0, 9.0, 1.0, 2.0);
228 OBJC_EXPORT
struct objc_cache _objc_empty_cache
229 OBJC_AVAILABLE(10.0, 2.0, 9.0, 1.0, 2.0);
235 // objc_msgSendSuper2() takes the current search class, not its superclass.
236 OBJC_EXPORT id _Nullable
237 objc_msgSendSuper2(struct objc_super
* _Nonnull super
, SEL _Nonnull op
, ...)
238 OBJC_AVAILABLE(10.6, 2.0, 9.0, 1.0, 2.0);
241 objc_msgSendSuper2_stret(struct objc_super
* _Nonnull super
,
243 OBJC_AVAILABLE(10.6, 2.0, 9.0, 1.0, 2.0)
244 OBJC_ARM64_UNAVAILABLE
;
246 // objc_msgSend_noarg() may be faster for methods with no additional arguments.
247 OBJC_EXPORT id _Nullable
248 objc_msgSend_noarg(id _Nullable self
, SEL _Nonnull _cmd
)
249 OBJC_AVAILABLE(10.7, 5.0, 9.0, 1.0, 2.0);
253 // Debug messengers. Messengers used by the compiler have a debug flavor that
254 // may perform extra sanity checking.
255 // Old objc_msgSendSuper() does not have a debug version; this is OBJC2 only.
256 // *_fixup() do not have debug versions; use non-fixup only for debug mode.
257 OBJC_EXPORT id _Nullable
258 objc_msgSend_debug(id _Nullable self
, SEL _Nonnull op
, ...)
259 OBJC_AVAILABLE(10.7, 5.0, 9.0, 1.0, 2.0);
261 OBJC_EXPORT id _Nullable
262 objc_msgSendSuper2_debug(struct objc_super
* _Nonnull super
,
263 SEL _Nonnull op
, ...)
264 OBJC_AVAILABLE(10.7, 5.0, 9.0, 1.0, 2.0);
267 objc_msgSend_stret_debug(id _Nullable self
, SEL _Nonnull op
, ...)
268 OBJC_AVAILABLE(10.7, 5.0, 9.0, 1.0, 2.0)
269 OBJC_ARM64_UNAVAILABLE
;
272 objc_msgSendSuper2_stret_debug(struct objc_super
* _Nonnull super
,
274 OBJC_AVAILABLE(10.7, 5.0, 9.0, 1.0, 2.0)
275 OBJC_ARM64_UNAVAILABLE
;
277 # if defined(__i386__)
279 objc_msgSend_fpret_debug(id _Nullable self
, SEL _Nonnull op
, ...)
280 OBJC_AVAILABLE(10.7, 5.0, 9.0, 1.0, 2.0);
281 # elif defined(__x86_64__)
282 OBJC_EXPORT
long double
283 objc_msgSend_fpret_debug(id _Nullable self
, SEL _Nonnull op
, ...)
284 OBJC_AVAILABLE(10.7, 5.0, 9.0, 1.0, 2.0);
285 # if __STDC_VERSION__ >= 199901L
286 OBJC_EXPORT _Complex
long double
287 objc_msgSend_fp2ret_debug(id _Nullable self
, SEL _Nonnull op
, ...)
288 OBJC_AVAILABLE(10.7, 5.0, 9.0, 1.0, 2.0);
291 objc_msgSend_fp2ret_debug(id _Nullable self
, SEL _Nonnull op
, ...)
292 OBJC_AVAILABLE(10.7, 5.0, 9.0, 1.0, 2.0);
299 // Lookup messengers.
300 // These are not callable C functions. Do not call them directly.
301 // The caller should set the method parameters, call objc_msgLookup(),
302 // then immediately call the returned IMP.
305 // - Callee-saved registers are preserved.
306 // - Receiver and selector registers may be modified. These values must
307 // be passed to the called IMP. Other parameter registers are preserved.
308 // - Caller-saved non-parameter registers are not preserved. Some of
309 // these registers are used to pass data from objc_msgLookup() to
310 // the called IMP and must not be disturbed by the caller.
311 // - Red zone is not preserved.
312 // See each architecture's implementation for details.
316 OBJC_AVAILABLE(10.12, 10.0, 10.0, 3.0, 2.0);
319 objc_msgLookupSuper2(void)
320 OBJC_AVAILABLE(10.12, 10.0, 10.0, 3.0, 2.0);
323 objc_msgLookup_stret(void)
324 OBJC_AVAILABLE(10.12, 10.0, 10.0, 3.0, 2.0)
325 OBJC_ARM64_UNAVAILABLE
;
328 objc_msgLookupSuper2_stret(void)
329 OBJC_AVAILABLE(10.12, 10.0, 10.0, 3.0, 2.0)
330 OBJC_ARM64_UNAVAILABLE
;
332 # if defined(__i386__)
334 objc_msgLookup_fpret(void)
335 OBJC_AVAILABLE(10.12, 10.0, 10.0, 3.0, 2.0);
337 # elif defined(__x86_64__)
339 objc_msgLookup_fpret(void)
340 OBJC_AVAILABLE(10.12, 10.0, 10.0, 3.0, 2.0);
343 objc_msgLookup_fp2ret(void)
344 OBJC_AVAILABLE(10.12, 10.0, 10.0, 3.0, 2.0);
349 #if (TARGET_OS_OSX || TARGET_OS_SIMULATOR) && defined(__x86_64__)
350 // objc_msgSend_fixup() was used for vtable-dispatchable call sites.
351 // The symbols remain exported on macOS for binary compatibility.
352 // The symbols can probably be removed from iOS simulator but we haven't tried.
354 objc_msgSend_fixup(void)
355 __OSX_DEPRECATED(10.5, 10.8, "fixup dispatch is no longer optimized");
358 objc_msgSend_stret_fixup(void)
359 __OSX_DEPRECATED(10.5, 10.8, "fixup dispatch is no longer optimized");
362 objc_msgSendSuper2_fixup(void)
363 __OSX_DEPRECATED(10.5, 10.8, "fixup dispatch is no longer optimized");
366 objc_msgSendSuper2_stret_fixup(void)
367 __OSX_DEPRECATED(10.5, 10.8, "fixup dispatch is no longer optimized");
370 objc_msgSend_fpret_fixup(void)
371 __OSX_DEPRECATED(10.5, 10.8, "fixup dispatch is no longer optimized");
374 objc_msgSend_fp2ret_fixup(void)
375 __OSX_DEPRECATED(10.5, 10.8, "fixup dispatch is no longer optimized");
378 /* C++-compatible exception handling. */
381 // Vtable for C++ exception typeinfo for Objective-C types.
382 OBJC_EXPORT
const void * _Nullable objc_ehtype_vtable
[]
383 OBJC_AVAILABLE(10.5, 2.0, 9.0, 1.0, 2.0);
385 // C++ exception typeinfo for type `id`.
386 OBJC_EXPORT
struct objc_typeinfo OBJC_EHTYPE_id
387 OBJC_AVAILABLE(10.5, 2.0, 9.0, 1.0, 2.0);
389 // Exception personality function for Objective-C and Objective-C++ code.
390 struct _Unwind_Exception
;
391 struct _Unwind_Context
;
393 __objc_personality_v0(int version
,
395 uint64_t exceptionClass
,
396 struct _Unwind_Exception
* _Nonnull exceptionObject
,
397 struct _Unwind_Context
* _Nonnull context
)
398 OBJC_AVAILABLE(10.5, 2.0, 9.0, 1.0, 2.0);
404 OBJC_EXPORT id _Nullable
405 objc_retainBlock(id _Nullable
)
406 OBJC_AVAILABLE(10.7, 5.0, 9.0, 1.0, 2.0);
409 /* Non-pointer isa */
413 // Extract class pointer from an isa field.
415 #if TARGET_OS_SIMULATOR && !TARGET_OS_IOSMAC
416 // No simulators use nonpointer isa yet.
419 # define OBJC_HAVE_NONPOINTER_ISA 1
420 # define OBJC_HAVE_PACKED_NONPOINTER_ISA 1
422 // Packed-isa version. This one is used directly by Swift code.
423 // (Class)(isa & (uintptr_t)&objc_absolute_packed_isa_class_mask) == class ptr
424 OBJC_EXPORT
const struct { char c
; } objc_absolute_packed_isa_class_mask
425 OBJC_AVAILABLE(10.12, 10.0, 10.0, 3.0, 2.0);
427 #elif (__ARM_ARCH_7K__ >= 2 || (__arm64__ && !__LP64__))
428 # define OBJC_HAVE_NONPOINTER_ISA 1
429 # define OBJC_HAVE_INDEXED_NONPOINTER_ISA 1
431 // Indexed-isa version.
432 // if (isa & (uintptr_t)&objc_absolute_indexed_isa_magic_mask == (uintptr_t)&objc_absolute_indexed_isa_magic_value) {
433 // uintptr_t index = (isa & (uintptr_t)&objc_absolute_indexed_isa_index_mask) >> (uintptr_t)&objc_absolute_indexed_isa_index_shift;
434 // cls = objc_indexed_classes[index];
438 OBJC_EXPORT
const struct { char c
; } objc_absolute_indexed_isa_magic_mask
439 OBJC_AVAILABLE(10.12, 10.0, 10.0, 3.0, 2.0);
440 OBJC_EXPORT
const struct { char c
; } objc_absolute_indexed_isa_magic_value
441 OBJC_AVAILABLE(10.12, 10.0, 10.0, 3.0, 2.0);
442 OBJC_EXPORT
const struct { char c
; } objc_absolute_indexed_isa_index_mask
443 OBJC_AVAILABLE(10.12, 10.0, 10.0, 3.0, 2.0);
444 OBJC_EXPORT
const struct { char c
; } objc_absolute_indexed_isa_index_shift
445 OBJC_AVAILABLE(10.12, 10.0, 10.0, 3.0, 2.0);
454 // This symbol might be required for binary compatibility, so we
455 // declare it here where TAPI will see it.
456 #if __OBJC__ && __OBJC2__
457 #pragma clang diagnostic push
458 #pragma clang diagnostic ignored "-Wobjc-interface-ivars"
459 #if !defined(OBJC_DECLARE_SYMBOLS)
460 __OSX_AVAILABLE(10.0)
461 __IOS_UNAVAILABLE __TVOS_UNAVAILABLE
462 __WATCHOS_UNAVAILABLE
463 # ifndef __APPLE_BLEACH_SDK__
464 __BRIDGEOS_UNAVAILABLE
472 #pragma clang diagnostic pop