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.
49 OBJC_EXPORT
void _objcInit(void)
50 OBJC_AVAILABLE(10.0, 2.0, 9.0, 1.0);
54 // Description of an Objective-C image.
55 // __DATA,__objc_imageinfo stores one of these.
56 typedef struct objc_image_info
{
57 uint32_t version
; // currently 0
60 #if __cplusplus >= 201103L
63 IsReplacement
= 1<<0, // used for Fix&Continue, now ignored
64 SupportsGC
= 1<<1, // image supports GC
65 RequiresGC
= 1<<2, // image requires GC
66 OptimizedByDyld
= 1<<3, // image is from an optimized shared cache
67 CorrectedSynthesize
= 1<<4, // used for an old workaround, now ignored
68 IsSimulated
= 1<<5, // image compiled for a simulator platform
69 HasCategoryClassProperties
= 1<<6, // class properties in category_t
71 SwiftVersionMaskShift
= 8,
72 SwiftVersionMask
= 0xff << SwiftVersionMaskShift
// Swift ABI version
84 bool isReplacement() const { return flags
& IsReplacement
; }
85 bool supportsGC() const { return flags
& SupportsGC
; }
86 bool requiresGC() const { return flags
& RequiresGC
; }
87 bool optimizedByDyld() const { return flags
& OptimizedByDyld
; }
88 bool hasCategoryClassProperties() const { return flags
& HasCategoryClassProperties
; }
89 bool containsSwift() const { return (flags
& SwiftVersionMask
) != 0; }
90 uint32_t swiftVersion() const { return (flags
& SwiftVersionMask
) >> SwiftVersionMaskShift
; }
96 Once used for Fix&Continue in old OS X object files (not final linked images)
100 App: GC is required. Framework: GC is supported but not required.
103 Framework: GC is required.
106 Assorted metadata precooked in the dyld shared cache.
107 Never set for images outside the shared cache file itself.
110 Once used on old iOS to mark images that did not have a particular
111 miscompile. Not used by the runtime.
114 Image was compiled for a simulator platform. Not used by the runtime.
117 New ABI: category_t.classProperties fields are present.
118 Old ABI: Set by some compilers. Not used by the runtime.
124 // Read or write an object property. Not all object properties use these.
125 OBJC_EXPORT id
objc_getProperty(id self
, SEL _cmd
, ptrdiff_t offset
, BOOL atomic
)
126 OBJC_AVAILABLE(10.5, 2.0, 9.0, 1.0);
127 OBJC_EXPORT
void objc_setProperty(id self
, SEL _cmd
, ptrdiff_t offset
, id newValue
, BOOL atomic
, signed char shouldCopy
)
128 OBJC_AVAILABLE(10.5, 2.0, 9.0, 1.0);
130 OBJC_EXPORT
void objc_setProperty_atomic(id self
, SEL _cmd
, id newValue
, ptrdiff_t offset
)
131 OBJC_AVAILABLE(10.8, 6.0, 9.0, 1.0);
132 OBJC_EXPORT
void objc_setProperty_nonatomic(id self
, SEL _cmd
, id newValue
, ptrdiff_t offset
)
133 OBJC_AVAILABLE(10.8, 6.0, 9.0, 1.0);
134 OBJC_EXPORT
void objc_setProperty_atomic_copy(id self
, SEL _cmd
, id newValue
, ptrdiff_t offset
)
135 OBJC_AVAILABLE(10.8, 6.0, 9.0, 1.0);
136 OBJC_EXPORT
void objc_setProperty_nonatomic_copy(id self
, SEL _cmd
, id newValue
, ptrdiff_t offset
)
137 OBJC_AVAILABLE(10.8, 6.0, 9.0, 1.0);
140 // Read or write a non-object property. Not all uses are C structs,
141 // and not all C struct properties use this.
142 OBJC_EXPORT
void objc_copyStruct(void *dest
, const void *src
, ptrdiff_t size
, BOOL atomic
, BOOL hasStrong
)
143 OBJC_AVAILABLE(10.5, 2.0, 9.0, 1.0);
145 // Perform a copy of a C++ object using striped locks. Used by non-POD C++ typed atomic properties.
146 OBJC_EXPORT
void objc_copyCppObjectAtomic(void *dest
, const void *src
, void (*copyHelper
) (void *dest
, const void *source
))
147 OBJC_AVAILABLE(10.8, 6.0, 9.0, 1.0);
151 OBJC_EXPORT IMP _objc_empty_vtable
152 OBJC_AVAILABLE(10.5, 2.0, 9.0, 1.0);
154 OBJC_EXPORT
struct objc_cache _objc_empty_cache
155 OBJC_AVAILABLE(10.0, 2.0, 9.0, 1.0);
161 // objc_msgSendSuper2() takes the current search class, not its superclass.
162 OBJC_EXPORT id
objc_msgSendSuper2(struct objc_super
*super
, SEL op
, ...)
163 OBJC_AVAILABLE(10.6, 2.0, 9.0, 1.0);
164 OBJC_EXPORT
void objc_msgSendSuper2_stret(struct objc_super
*super
, SEL op
,...)
165 OBJC_AVAILABLE(10.6, 2.0, 9.0, 1.0)
166 OBJC_ARM64_UNAVAILABLE
;
168 // objc_msgSend_noarg() may be faster for methods with no additional arguments.
169 OBJC_EXPORT id
objc_msgSend_noarg(id self
, SEL _cmd
)
170 OBJC_AVAILABLE(10.7, 5.0, 9.0, 1.0);
174 // Debug messengers. Messengers used by the compiler have a debug flavor that
175 // may perform extra sanity checking.
176 // Old objc_msgSendSuper() does not have a debug version; this is OBJC2 only.
177 // *_fixup() do not have debug versions; use non-fixup only for debug mode.
178 OBJC_EXPORT id
objc_msgSend_debug(id self
, SEL op
, ...)
179 OBJC_AVAILABLE(10.7, 5.0, 9.0, 1.0);
180 OBJC_EXPORT id
objc_msgSendSuper2_debug(struct objc_super
*super
, SEL op
, ...)
181 OBJC_AVAILABLE(10.7, 5.0, 9.0, 1.0);
182 OBJC_EXPORT
void objc_msgSend_stret_debug(id self
, SEL op
, ...)
183 OBJC_AVAILABLE(10.7, 5.0, 9.0, 1.0)
184 OBJC_ARM64_UNAVAILABLE
;
185 OBJC_EXPORT
void objc_msgSendSuper2_stret_debug(struct objc_super
*super
, SEL op
,...)
186 OBJC_AVAILABLE(10.7, 5.0, 9.0, 1.0)
187 OBJC_ARM64_UNAVAILABLE
;
189 # if defined(__i386__)
190 OBJC_EXPORT
double objc_msgSend_fpret_debug(id self
, SEL op
, ...)
191 OBJC_AVAILABLE(10.7, 5.0, 9.0, 1.0);
192 # elif defined(__x86_64__)
193 OBJC_EXPORT
long double objc_msgSend_fpret_debug(id self
, SEL op
, ...)
194 OBJC_AVAILABLE(10.7, 5.0, 9.0, 1.0);
195 # if __STDC_VERSION__ >= 199901L
196 OBJC_EXPORT _Complex
long double objc_msgSend_fp2ret_debug(id self
, SEL op
, ...)
197 OBJC_AVAILABLE(10.7, 5.0, 9.0, 1.0);
199 OBJC_EXPORT
void objc_msgSend_fp2ret_debug(id self
, SEL op
, ...)
200 OBJC_AVAILABLE(10.7, 5.0, 9.0, 1.0);
207 // Lookup messengers.
208 // These are not callable C functions. Do not call them directly.
209 // The caller should set the method parameters, call objc_msgLookup(),
210 // then immediately call the returned IMP.
213 // - Callee-saved registers are preserved.
214 // - Receiver and selector registers may be modified. These values must
215 // be passed to the called IMP. Other parameter registers are preserved.
216 // - Caller-saved non-parameter registers are not preserved. Some of
217 // these registers are used to pass data from objc_msgLookup() to
218 // the called IMP and must not be disturbed by the caller.
219 // - Red zone is not preserved.
220 // See each architecture's implementation for details.
222 OBJC_EXPORT
void objc_msgLookup(void)
223 OBJC_AVAILABLE(10.12, 10.0, 10.0, 3.0);
224 OBJC_EXPORT
void objc_msgLookupSuper2(void)
225 OBJC_AVAILABLE(10.12, 10.0, 10.0, 3.0);
226 OBJC_EXPORT
void objc_msgLookup_stret(void)
227 OBJC_AVAILABLE(10.12, 10.0, 10.0, 3.0)
228 OBJC_ARM64_UNAVAILABLE
;
229 OBJC_EXPORT
void objc_msgLookupSuper2_stret(void)
230 OBJC_AVAILABLE(10.12, 10.0, 10.0, 3.0)
231 OBJC_ARM64_UNAVAILABLE
;
233 # if defined(__i386__)
234 OBJC_EXPORT
void objc_msgLookup_fpret(void)
235 OBJC_AVAILABLE(10.12, 10.0, 10.0, 3.0);
236 # elif defined(__x86_64__)
237 OBJC_EXPORT
void objc_msgLookup_fpret(void)
238 OBJC_AVAILABLE(10.12, 10.0, 10.0, 3.0);
239 OBJC_EXPORT
void objc_msgLookup_fp2ret(void)
240 OBJC_AVAILABLE(10.12, 10.0, 10.0, 3.0);
245 #if TARGET_OS_OSX && defined(__x86_64__)
246 // objc_msgSend_fixup() is used for vtable-dispatchable call sites.
247 OBJC_EXPORT
void objc_msgSend_fixup(void)
248 __OSX_DEPRECATED(10.5, 10.8, "fixup dispatch is no longer optimized")
249 __IOS_UNAVAILABLE __TVOS_UNAVAILABLE __WATCHOS_UNAVAILABLE
;
250 OBJC_EXPORT
void objc_msgSend_stret_fixup(void)
251 __OSX_DEPRECATED(10.5, 10.8, "fixup dispatch is no longer optimized")
252 __IOS_UNAVAILABLE __TVOS_UNAVAILABLE __WATCHOS_UNAVAILABLE
;
253 OBJC_EXPORT
void objc_msgSendSuper2_fixup(void)
254 __OSX_DEPRECATED(10.5, 10.8, "fixup dispatch is no longer optimized")
255 __IOS_UNAVAILABLE __TVOS_UNAVAILABLE __WATCHOS_UNAVAILABLE
;
256 OBJC_EXPORT
void objc_msgSendSuper2_stret_fixup(void)
257 __OSX_DEPRECATED(10.5, 10.8, "fixup dispatch is no longer optimized")
258 __IOS_UNAVAILABLE __TVOS_UNAVAILABLE __WATCHOS_UNAVAILABLE
;
259 OBJC_EXPORT
void objc_msgSend_fpret_fixup(void)
260 __OSX_DEPRECATED(10.5, 10.8, "fixup dispatch is no longer optimized")
261 __IOS_UNAVAILABLE __TVOS_UNAVAILABLE __WATCHOS_UNAVAILABLE
;
262 OBJC_EXPORT
void objc_msgSend_fp2ret_fixup(void)
263 __OSX_DEPRECATED(10.5, 10.8, "fixup dispatch is no longer optimized")
264 __IOS_UNAVAILABLE __TVOS_UNAVAILABLE __WATCHOS_UNAVAILABLE
;
267 /* C++-compatible exception handling. */
270 // fixme these conflict with C++ compiler's internal definitions
271 #if !defined(__cplusplus)
273 // Vtable for C++ exception typeinfo for Objective-C types.
274 OBJC_EXPORT
const void *objc_ehtype_vtable
[]
275 OBJC_AVAILABLE(10.5, 2.0, 9.0, 1.0);
277 // C++ exception typeinfo for type `id`.
278 OBJC_EXPORT
struct objc_typeinfo OBJC_EHTYPE_id
279 OBJC_AVAILABLE(10.5, 2.0, 9.0, 1.0);
283 // Exception personality function for Objective-C and Objective-C++ code.
284 struct _Unwind_Exception
;
285 struct _Unwind_Context
;
287 __objc_personality_v0(int version
,
289 uint64_t exceptionClass
,
290 struct _Unwind_Exception
*exceptionObject
,
291 struct _Unwind_Context
*context
)
292 OBJC_AVAILABLE(10.5, 2.0, 9.0, 1.0);
298 OBJC_EXPORT id
objc_retainBlock(id
)
299 OBJC_AVAILABLE(10.7, 5.0, 9.0, 1.0);
302 /* Non-pointer isa */
306 // Extract class pointer from an isa field.
308 #if TARGET_OS_SIMULATOR
309 // No simulators use nonpointer isa yet.
312 # define OBJC_HAVE_NONPOINTER_ISA 1
313 # define OBJC_HAVE_PACKED_NONPOINTER_ISA 1
315 // Packed-isa version. This one is used directly by Swift code.
316 // (Class)(isa & (uintptr_t)&objc_absolute_packed_isa_class_mask) == class ptr
317 OBJC_EXPORT
const struct { char c
; } objc_absolute_packed_isa_class_mask
318 OBJC_AVAILABLE(10.12, 10.0, 10.0, 3.0);
320 #elif __ARM_ARCH_7K__ >= 2
321 # define OBJC_HAVE_NONPOINTER_ISA 1
322 # define OBJC_HAVE_INDEXED_NONPOINTER_ISA 1
324 // Indexed-isa version.
325 // if (isa & (uintptr_t)&objc_absolute_indexed_isa_magic_mask == (uintptr_t)&objc_absolute_indexed_isa_magic_value) {
326 // uintptr_t index = (isa & (uintptr_t)&objc_absolute_indexed_isa_index_mask) >> (uintptr_t)&objc_absolute_indexed_isa_index_shift;
327 // cls = objc_indexed_classes[index];
331 OBJC_EXPORT
const struct { char c
; } objc_absolute_indexed_isa_magic_mask
332 OBJC_AVAILABLE(10.12, 10.0, 10.0, 3.0);
333 OBJC_EXPORT
const struct { char c
; } objc_absolute_indexed_isa_magic_value
334 OBJC_AVAILABLE(10.12, 10.0, 10.0, 3.0);
335 OBJC_EXPORT
const struct { char c
; } objc_absolute_indexed_isa_index_mask
336 OBJC_AVAILABLE(10.12, 10.0, 10.0, 3.0);
337 OBJC_EXPORT
const struct { char c
; } objc_absolute_indexed_isa_index_shift
338 OBJC_AVAILABLE(10.12, 10.0, 10.0, 3.0);