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