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 /* Runtime startup. */
48 // Old static initializer. Used by old crt1.o and old bug workarounds.
51 OBJC_AVAILABLE(10.0, 2.0, 9.0, 1.0, 2.0);
55 // Description of an Objective-C image.
56 // __DATA,__objc_imageinfo stores one of these.
57 typedef struct objc_image_info
{
58 uint32_t version
; // currently 0
61 #if __cplusplus >= 201103L
64 IsReplacement
= 1<<0, // used for Fix&Continue, now ignored
65 SupportsGC
= 1<<1, // image supports GC
66 RequiresGC
= 1<<2, // image requires GC
67 OptimizedByDyld
= 1<<3, // image is from an optimized shared cache
68 CorrectedSynthesize
= 1<<4, // used for an old workaround, now ignored
69 IsSimulated
= 1<<5, // image compiled for a simulator platform
70 HasCategoryClassProperties
= 1<<6, // class properties in category_t
72 SwiftVersionMaskShift
= 8,
73 SwiftVersionMask
= 0xff << SwiftVersionMaskShift
// Swift ABI version
85 bool isReplacement() const { return flags
& IsReplacement
; }
86 bool supportsGC() const { return flags
& SupportsGC
; }
87 bool requiresGC() const { return flags
& RequiresGC
; }
88 bool optimizedByDyld() const { return flags
& OptimizedByDyld
; }
89 bool hasCategoryClassProperties() const { return flags
& HasCategoryClassProperties
; }
90 bool containsSwift() const { return (flags
& SwiftVersionMask
) != 0; }
91 uint32_t swiftVersion() const { return (flags
& SwiftVersionMask
) >> SwiftVersionMaskShift
; }
97 Once used for Fix&Continue in old OS X object files (not final linked images)
101 App: GC is required. Framework: GC is supported but not required.
104 Framework: GC is required.
107 Assorted metadata precooked in the dyld shared cache.
108 Never set for images outside the shared cache file itself.
111 Once used on old iOS to mark images that did not have a particular
112 miscompile. Not used by the runtime.
115 Image was compiled for a simulator platform. Not used by the runtime.
118 New ABI: category_t.classProperties fields are present.
119 Old ABI: Set by some compilers. Not used by the runtime.
125 // Read or write an object property. Not all object properties use these.
126 OBJC_EXPORT id _Nullable
127 objc_getProperty(id _Nullable self
, SEL _Nonnull _cmd
,
128 ptrdiff_t offset
, BOOL atomic
)
129 OBJC_AVAILABLE(10.5, 2.0, 9.0, 1.0, 2.0);
132 objc_setProperty(id _Nullable self
, SEL _Nonnull _cmd
, ptrdiff_t offset
,
133 id _Nullable newValue
, BOOL atomic
, signed char shouldCopy
)
134 OBJC_AVAILABLE(10.5, 2.0, 9.0, 1.0, 2.0);
137 objc_setProperty_atomic(id _Nullable self
, SEL _Nonnull _cmd
,
138 id _Nullable newValue
, ptrdiff_t offset
)
139 OBJC_AVAILABLE(10.8, 6.0, 9.0, 1.0, 2.0);
142 objc_setProperty_nonatomic(id _Nullable self
, SEL _Nonnull _cmd
,
143 id _Nullable newValue
, ptrdiff_t offset
)
144 OBJC_AVAILABLE(10.8, 6.0, 9.0, 1.0, 2.0);
147 objc_setProperty_atomic_copy(id _Nullable self
, SEL _Nonnull _cmd
,
148 id _Nullable newValue
, ptrdiff_t offset
)
149 OBJC_AVAILABLE(10.8, 6.0, 9.0, 1.0, 2.0);
152 objc_setProperty_nonatomic_copy(id _Nullable self
, SEL _Nonnull _cmd
,
153 id _Nullable newValue
, ptrdiff_t offset
)
154 OBJC_AVAILABLE(10.8, 6.0, 9.0, 1.0, 2.0);
157 // Read or write a non-object property. Not all uses are C structs,
158 // and not all C struct properties use this.
160 objc_copyStruct(void * _Nonnull dest
, const void * _Nonnull src
,
161 ptrdiff_t size
, BOOL atomic
, BOOL hasStrong
)
162 OBJC_AVAILABLE(10.5, 2.0, 9.0, 1.0, 2.0);
164 // Perform a copy of a C++ object using striped locks. Used by non-POD C++ typed atomic properties.
166 objc_copyCppObjectAtomic(void * _Nonnull dest
, const void * _Nonnull src
,
167 void (* _Nonnull copyHelper
)
168 (void * _Nonnull dest
, const void * _Nonnull source
))
169 OBJC_AVAILABLE(10.8, 6.0, 9.0, 1.0, 2.0);
173 OBJC_EXPORT IMP _Nonnull _objc_empty_vtable
174 OBJC_AVAILABLE(10.5, 2.0, 9.0, 1.0, 2.0);
176 OBJC_EXPORT
struct objc_cache _objc_empty_cache
177 OBJC_AVAILABLE(10.0, 2.0, 9.0, 1.0, 2.0);
183 // objc_msgSendSuper2() takes the current search class, not its superclass.
184 OBJC_EXPORT id _Nullable
185 objc_msgSendSuper2(struct objc_super
* _Nonnull super
, SEL _Nonnull op
, ...)
186 OBJC_AVAILABLE(10.6, 2.0, 9.0, 1.0, 2.0);
189 objc_msgSendSuper2_stret(struct objc_super
* _Nonnull super
,
191 OBJC_AVAILABLE(10.6, 2.0, 9.0, 1.0, 2.0)
192 OBJC_ARM64_UNAVAILABLE
;
194 // objc_msgSend_noarg() may be faster for methods with no additional arguments.
195 OBJC_EXPORT id _Nullable
196 objc_msgSend_noarg(id _Nullable self
, SEL _Nonnull _cmd
)
197 OBJC_AVAILABLE(10.7, 5.0, 9.0, 1.0, 2.0);
201 // Debug messengers. Messengers used by the compiler have a debug flavor that
202 // may perform extra sanity checking.
203 // Old objc_msgSendSuper() does not have a debug version; this is OBJC2 only.
204 // *_fixup() do not have debug versions; use non-fixup only for debug mode.
205 OBJC_EXPORT id _Nullable
206 objc_msgSend_debug(id _Nullable self
, SEL _Nonnull op
, ...)
207 OBJC_AVAILABLE(10.7, 5.0, 9.0, 1.0, 2.0);
209 OBJC_EXPORT id _Nullable
210 objc_msgSendSuper2_debug(struct objc_super
* _Nonnull super
,
211 SEL _Nonnull op
, ...)
212 OBJC_AVAILABLE(10.7, 5.0, 9.0, 1.0, 2.0);
215 objc_msgSend_stret_debug(id _Nullable self
, SEL _Nonnull op
, ...)
216 OBJC_AVAILABLE(10.7, 5.0, 9.0, 1.0, 2.0)
217 OBJC_ARM64_UNAVAILABLE
;
220 objc_msgSendSuper2_stret_debug(struct objc_super
* _Nonnull super
,
222 OBJC_AVAILABLE(10.7, 5.0, 9.0, 1.0, 2.0)
223 OBJC_ARM64_UNAVAILABLE
;
225 # if defined(__i386__)
227 objc_msgSend_fpret_debug(id _Nullable self
, SEL _Nonnull op
, ...)
228 OBJC_AVAILABLE(10.7, 5.0, 9.0, 1.0, 2.0);
229 # elif defined(__x86_64__)
230 OBJC_EXPORT
long double
231 objc_msgSend_fpret_debug(id _Nullable self
, SEL _Nonnull op
, ...)
232 OBJC_AVAILABLE(10.7, 5.0, 9.0, 1.0, 2.0);
233 # if __STDC_VERSION__ >= 199901L
234 OBJC_EXPORT _Complex
long double
235 objc_msgSend_fp2ret_debug(id _Nullable self
, SEL _Nonnull op
, ...)
236 OBJC_AVAILABLE(10.7, 5.0, 9.0, 1.0, 2.0);
239 objc_msgSend_fp2ret_debug(id _Nullable self
, SEL _Nonnull op
, ...)
240 OBJC_AVAILABLE(10.7, 5.0, 9.0, 1.0, 2.0);
247 // Lookup messengers.
248 // These are not callable C functions. Do not call them directly.
249 // The caller should set the method parameters, call objc_msgLookup(),
250 // then immediately call the returned IMP.
253 // - Callee-saved registers are preserved.
254 // - Receiver and selector registers may be modified. These values must
255 // be passed to the called IMP. Other parameter registers are preserved.
256 // - Caller-saved non-parameter registers are not preserved. Some of
257 // these registers are used to pass data from objc_msgLookup() to
258 // the called IMP and must not be disturbed by the caller.
259 // - Red zone is not preserved.
260 // See each architecture's implementation for details.
264 OBJC_AVAILABLE(10.12, 10.0, 10.0, 3.0, 2.0);
267 objc_msgLookupSuper2(void)
268 OBJC_AVAILABLE(10.12, 10.0, 10.0, 3.0, 2.0);
271 objc_msgLookup_stret(void)
272 OBJC_AVAILABLE(10.12, 10.0, 10.0, 3.0, 2.0)
273 OBJC_ARM64_UNAVAILABLE
;
276 objc_msgLookupSuper2_stret(void)
277 OBJC_AVAILABLE(10.12, 10.0, 10.0, 3.0, 2.0)
278 OBJC_ARM64_UNAVAILABLE
;
280 # if defined(__i386__)
282 objc_msgLookup_fpret(void)
283 OBJC_AVAILABLE(10.12, 10.0, 10.0, 3.0, 2.0);
285 # elif defined(__x86_64__)
287 objc_msgLookup_fpret(void)
288 OBJC_AVAILABLE(10.12, 10.0, 10.0, 3.0, 2.0);
291 objc_msgLookup_fp2ret(void)
292 OBJC_AVAILABLE(10.12, 10.0, 10.0, 3.0, 2.0);
297 #if TARGET_OS_OSX && defined(__x86_64__)
298 // objc_msgSend_fixup() is used for vtable-dispatchable call sites.
300 objc_msgSend_fixup(void)
301 __OSX_DEPRECATED(10.5, 10.8, "fixup dispatch is no longer optimized")
302 __IOS_UNAVAILABLE __TVOS_UNAVAILABLE
303 __WATCHOS_UNAVAILABLE __BRIDGEOS_UNAVAILABLE
;
306 objc_msgSend_stret_fixup(void)
307 __OSX_DEPRECATED(10.5, 10.8, "fixup dispatch is no longer optimized")
308 __IOS_UNAVAILABLE __TVOS_UNAVAILABLE
309 __WATCHOS_UNAVAILABLE __BRIDGEOS_UNAVAILABLE
;
312 objc_msgSendSuper2_fixup(void)
313 __OSX_DEPRECATED(10.5, 10.8, "fixup dispatch is no longer optimized")
314 __IOS_UNAVAILABLE __TVOS_UNAVAILABLE
315 __WATCHOS_UNAVAILABLE __BRIDGEOS_UNAVAILABLE
;
318 objc_msgSendSuper2_stret_fixup(void)
319 __OSX_DEPRECATED(10.5, 10.8, "fixup dispatch is no longer optimized")
320 __IOS_UNAVAILABLE __TVOS_UNAVAILABLE
321 __WATCHOS_UNAVAILABLE __BRIDGEOS_UNAVAILABLE
;
324 objc_msgSend_fpret_fixup(void)
325 __OSX_DEPRECATED(10.5, 10.8, "fixup dispatch is no longer optimized")
326 __IOS_UNAVAILABLE __TVOS_UNAVAILABLE
327 __WATCHOS_UNAVAILABLE __BRIDGEOS_UNAVAILABLE
;
330 objc_msgSend_fp2ret_fixup(void)
331 __OSX_DEPRECATED(10.5, 10.8, "fixup dispatch is no longer optimized")
332 __IOS_UNAVAILABLE __TVOS_UNAVAILABLE
333 __WATCHOS_UNAVAILABLE __BRIDGEOS_UNAVAILABLE
;
336 /* C++-compatible exception handling. */
339 // fixme these conflict with C++ compiler's internal definitions
340 #if !defined(__cplusplus)
342 // Vtable for C++ exception typeinfo for Objective-C types.
343 OBJC_EXPORT
const void * _Nullableobjc_ehtype_vtable
[]
344 OBJC_AVAILABLE(10.5, 2.0, 9.0, 1.0, 2.0);
346 // C++ exception typeinfo for type `id`.
347 OBJC_EXPORT
struct objc_typeinfo OBJC_EHTYPE_id
348 OBJC_AVAILABLE(10.5, 2.0, 9.0, 1.0, 2.0);
352 // Exception personality function for Objective-C and Objective-C++ code.
353 struct _Unwind_Exception
;
354 struct _Unwind_Context
;
356 __objc_personality_v0(int version
,
358 uint64_t exceptionClass
,
359 struct _Unwind_Exception
* _Nonnull exceptionObject
,
360 struct _Unwind_Context
* _Nonnull context
)
361 OBJC_AVAILABLE(10.5, 2.0, 9.0, 1.0, 2.0);
367 OBJC_EXPORT id _Nullable
368 objc_retainBlock(id _Nullable
)
369 OBJC_AVAILABLE(10.7, 5.0, 9.0, 1.0, 2.0);
372 /* Non-pointer isa */
376 // Extract class pointer from an isa field.
378 #if TARGET_OS_SIMULATOR
379 // No simulators use nonpointer isa yet.
382 # define OBJC_HAVE_NONPOINTER_ISA 1
383 # define OBJC_HAVE_PACKED_NONPOINTER_ISA 1
385 // Packed-isa version. This one is used directly by Swift code.
386 // (Class)(isa & (uintptr_t)&objc_absolute_packed_isa_class_mask) == class ptr
387 OBJC_EXPORT
const struct { char c
; } objc_absolute_packed_isa_class_mask
388 OBJC_AVAILABLE(10.12, 10.0, 10.0, 3.0, 2.0);
390 #elif __ARM_ARCH_7K__ >= 2
391 # define OBJC_HAVE_NONPOINTER_ISA 1
392 # define OBJC_HAVE_INDEXED_NONPOINTER_ISA 1
394 // Indexed-isa version.
395 // if (isa & (uintptr_t)&objc_absolute_indexed_isa_magic_mask == (uintptr_t)&objc_absolute_indexed_isa_magic_value) {
396 // uintptr_t index = (isa & (uintptr_t)&objc_absolute_indexed_isa_index_mask) >> (uintptr_t)&objc_absolute_indexed_isa_index_shift;
397 // cls = objc_indexed_classes[index];
401 OBJC_EXPORT
const struct { char c
; } objc_absolute_indexed_isa_magic_mask
402 OBJC_AVAILABLE(10.12, 10.0, 10.0, 3.0, 2.0);
403 OBJC_EXPORT
const struct { char c
; } objc_absolute_indexed_isa_magic_value
404 OBJC_AVAILABLE(10.12, 10.0, 10.0, 3.0, 2.0);
405 OBJC_EXPORT
const struct { char c
; } objc_absolute_indexed_isa_index_mask
406 OBJC_AVAILABLE(10.12, 10.0, 10.0, 3.0, 2.0);
407 OBJC_EXPORT
const struct { char c
; } objc_absolute_indexed_isa_index_shift
408 OBJC_AVAILABLE(10.12, 10.0, 10.0, 3.0, 2.0);