]> git.saurik.com Git - apple/objc4.git/blob - runtime/objc-abi.h
objc4-706.tar.gz
[apple/objc4.git] / runtime / objc-abi.h
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>
41 #include <TargetConditionals.h>
42 #include <objc/objc.h>
43 #include <objc/runtime.h>
44 #include <objc/message.h>
45
46 /* Runtime startup. */
47
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);
51
52 /* Images */
53
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
58 uint32_t flags;
59
60 #if __cplusplus >= 201103L
61 private:
62 enum : uint32_t {
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
70
71 SwiftVersionMaskShift = 8,
72 SwiftVersionMask = 0xff << SwiftVersionMaskShift // Swift ABI version
73
74 };
75 public:
76 enum : uint32_t {
77 SwiftVersion1 = 1,
78 SwiftVersion1_2 = 2,
79 SwiftVersion2 = 3,
80 SwiftVersion3 = 4
81 };
82
83 public:
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; }
91 #endif
92 } objc_image_info;
93
94 /*
95 IsReplacement:
96 Once used for Fix&Continue in old OS X object files (not final linked images)
97 Not currently used.
98
99 SupportsGC:
100 App: GC is required. Framework: GC is supported but not required.
101
102 RequiresGC:
103 Framework: GC is required.
104
105 OptimizedByDyld:
106 Assorted metadata precooked in the dyld shared cache.
107 Never set for images outside the shared cache file itself.
108
109 CorrectedSynthesize:
110 Once used on old iOS to mark images that did not have a particular
111 miscompile. Not used by the runtime.
112
113 IsSimulated:
114 Image was compiled for a simulator platform. Not used by the runtime.
115
116 HasClassProperties:
117 New ABI: category_t.classProperties fields are present.
118 Old ABI: Set by some compilers. Not used by the runtime.
119 */
120
121
122 /* Properties */
123
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);
129
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);
138
139
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);
144
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);
148
149 /* Classes. */
150 #if __OBJC2__
151 OBJC_EXPORT IMP _objc_empty_vtable
152 OBJC_AVAILABLE(10.5, 2.0, 9.0, 1.0);
153 #endif
154 OBJC_EXPORT struct objc_cache _objc_empty_cache
155 OBJC_AVAILABLE(10.0, 2.0, 9.0, 1.0);
156
157
158 /* Messages */
159
160 #if __OBJC2__
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;
167
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);
171 #endif
172
173 #if __OBJC2__
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;
188
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);
198 # else
199 OBJC_EXPORT void objc_msgSend_fp2ret_debug(id self, SEL op, ...)
200 OBJC_AVAILABLE(10.7, 5.0, 9.0, 1.0);
201 # endif
202 # endif
203
204 #endif
205
206 #if __OBJC2__
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.
211 //
212 // Generic ABI:
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.
221
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;
232
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);
241 # endif
242
243 #endif
244
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;
265 #endif
266
267 /* C++-compatible exception handling. */
268 #if __OBJC2__
269
270 // fixme these conflict with C++ compiler's internal definitions
271 #if !defined(__cplusplus)
272
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);
276
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);
280
281 #endif
282
283 // Exception personality function for Objective-C and Objective-C++ code.
284 struct _Unwind_Exception;
285 struct _Unwind_Context;
286 OBJC_EXPORT int
287 __objc_personality_v0(int version,
288 int actions,
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);
293
294 #endif
295
296 /* ARC */
297
298 OBJC_EXPORT id objc_retainBlock(id)
299 OBJC_AVAILABLE(10.7, 5.0, 9.0, 1.0);
300
301
302 /* Non-pointer isa */
303
304 #if __OBJC2__
305
306 // Extract class pointer from an isa field.
307
308 #if TARGET_OS_SIMULATOR
309 // No simulators use nonpointer isa yet.
310
311 #elif __LP64__
312 # define OBJC_HAVE_NONPOINTER_ISA 1
313 # define OBJC_HAVE_PACKED_NONPOINTER_ISA 1
314
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);
319
320 #elif __ARM_ARCH_7K__ >= 2
321 # define OBJC_HAVE_NONPOINTER_ISA 1
322 # define OBJC_HAVE_INDEXED_NONPOINTER_ISA 1
323
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];
328 // } else
329 // cls = (Class)isa;
330 // }
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);
339
340 #endif
341
342 // OBJC2
343 #endif
344
345 // _OBJC_ABI_H
346 #endif