]> git.saurik.com Git - apple/objc4.git/blob - runtime/objc-abi.h
objc4-723.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
50 _objcInit(void)
51 OBJC_AVAILABLE(10.0, 2.0, 9.0, 1.0, 2.0);
52
53 /* Images */
54
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
59 uint32_t flags;
60
61 #if __cplusplus >= 201103L
62 private:
63 enum : uint32_t {
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
71
72 SwiftVersionMaskShift = 8,
73 SwiftVersionMask = 0xff << SwiftVersionMaskShift // Swift ABI version
74
75 };
76 public:
77 enum : uint32_t {
78 SwiftVersion1 = 1,
79 SwiftVersion1_2 = 2,
80 SwiftVersion2 = 3,
81 SwiftVersion3 = 4
82 };
83
84 public:
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; }
92 #endif
93 } objc_image_info;
94
95 /*
96 IsReplacement:
97 Once used for Fix&Continue in old OS X object files (not final linked images)
98 Not currently used.
99
100 SupportsGC:
101 App: GC is required. Framework: GC is supported but not required.
102
103 RequiresGC:
104 Framework: GC is required.
105
106 OptimizedByDyld:
107 Assorted metadata precooked in the dyld shared cache.
108 Never set for images outside the shared cache file itself.
109
110 CorrectedSynthesize:
111 Once used on old iOS to mark images that did not have a particular
112 miscompile. Not used by the runtime.
113
114 IsSimulated:
115 Image was compiled for a simulator platform. Not used by the runtime.
116
117 HasClassProperties:
118 New ABI: category_t.classProperties fields are present.
119 Old ABI: Set by some compilers. Not used by the runtime.
120 */
121
122
123 /* Properties */
124
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);
130
131 OBJC_EXPORT void
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);
135
136 OBJC_EXPORT void
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);
140
141 OBJC_EXPORT void
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);
145
146 OBJC_EXPORT void
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);
150
151 OBJC_EXPORT void
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);
155
156
157 // Read or write a non-object property. Not all uses are C structs,
158 // and not all C struct properties use this.
159 OBJC_EXPORT void
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);
163
164 // Perform a copy of a C++ object using striped locks. Used by non-POD C++ typed atomic properties.
165 OBJC_EXPORT void
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);
170
171 /* Classes. */
172 #if __OBJC2__
173 OBJC_EXPORT IMP _Nonnull _objc_empty_vtable
174 OBJC_AVAILABLE(10.5, 2.0, 9.0, 1.0, 2.0);
175 #endif
176 OBJC_EXPORT struct objc_cache _objc_empty_cache
177 OBJC_AVAILABLE(10.0, 2.0, 9.0, 1.0, 2.0);
178
179
180 /* Messages */
181
182 #if __OBJC2__
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);
187
188 OBJC_EXPORT void
189 objc_msgSendSuper2_stret(struct objc_super * _Nonnull super,
190 SEL _Nonnull op,...)
191 OBJC_AVAILABLE(10.6, 2.0, 9.0, 1.0, 2.0)
192 OBJC_ARM64_UNAVAILABLE;
193
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);
198 #endif
199
200 #if __OBJC2__
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);
208
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);
213
214 OBJC_EXPORT void
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;
218
219 OBJC_EXPORT void
220 objc_msgSendSuper2_stret_debug(struct objc_super * _Nonnull super,
221 SEL _Nonnull op,...)
222 OBJC_AVAILABLE(10.7, 5.0, 9.0, 1.0, 2.0)
223 OBJC_ARM64_UNAVAILABLE;
224
225 # if defined(__i386__)
226 OBJC_EXPORT double
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);
237 # else
238 OBJC_EXPORT void
239 objc_msgSend_fp2ret_debug(id _Nullable self, SEL _Nonnull op, ...)
240 OBJC_AVAILABLE(10.7, 5.0, 9.0, 1.0, 2.0);
241 # endif
242 # endif
243
244 #endif
245
246 #if __OBJC2__
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.
251 //
252 // Generic ABI:
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.
261
262 OBJC_EXPORT void
263 objc_msgLookup(void)
264 OBJC_AVAILABLE(10.12, 10.0, 10.0, 3.0, 2.0);
265
266 OBJC_EXPORT void
267 objc_msgLookupSuper2(void)
268 OBJC_AVAILABLE(10.12, 10.0, 10.0, 3.0, 2.0);
269
270 OBJC_EXPORT void
271 objc_msgLookup_stret(void)
272 OBJC_AVAILABLE(10.12, 10.0, 10.0, 3.0, 2.0)
273 OBJC_ARM64_UNAVAILABLE;
274
275 OBJC_EXPORT void
276 objc_msgLookupSuper2_stret(void)
277 OBJC_AVAILABLE(10.12, 10.0, 10.0, 3.0, 2.0)
278 OBJC_ARM64_UNAVAILABLE;
279
280 # if defined(__i386__)
281 OBJC_EXPORT void
282 objc_msgLookup_fpret(void)
283 OBJC_AVAILABLE(10.12, 10.0, 10.0, 3.0, 2.0);
284
285 # elif defined(__x86_64__)
286 OBJC_EXPORT void
287 objc_msgLookup_fpret(void)
288 OBJC_AVAILABLE(10.12, 10.0, 10.0, 3.0, 2.0);
289
290 OBJC_EXPORT void
291 objc_msgLookup_fp2ret(void)
292 OBJC_AVAILABLE(10.12, 10.0, 10.0, 3.0, 2.0);
293 # endif
294
295 #endif
296
297 #if TARGET_OS_OSX && defined(__x86_64__)
298 // objc_msgSend_fixup() is used for vtable-dispatchable call sites.
299 OBJC_EXPORT void
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;
304
305 OBJC_EXPORT void
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;
310
311 OBJC_EXPORT void
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;
316
317 OBJC_EXPORT void
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;
322
323 OBJC_EXPORT void
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;
328
329 OBJC_EXPORT void
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;
334 #endif
335
336 /* C++-compatible exception handling. */
337 #if __OBJC2__
338
339 // fixme these conflict with C++ compiler's internal definitions
340 #if !defined(__cplusplus)
341
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);
345
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);
349
350 #endif
351
352 // Exception personality function for Objective-C and Objective-C++ code.
353 struct _Unwind_Exception;
354 struct _Unwind_Context;
355 OBJC_EXPORT int
356 __objc_personality_v0(int version,
357 int actions,
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);
362
363 #endif
364
365 /* ARC */
366
367 OBJC_EXPORT id _Nullable
368 objc_retainBlock(id _Nullable)
369 OBJC_AVAILABLE(10.7, 5.0, 9.0, 1.0, 2.0);
370
371
372 /* Non-pointer isa */
373
374 #if __OBJC2__
375
376 // Extract class pointer from an isa field.
377
378 #if TARGET_OS_SIMULATOR
379 // No simulators use nonpointer isa yet.
380
381 #elif __LP64__
382 # define OBJC_HAVE_NONPOINTER_ISA 1
383 # define OBJC_HAVE_PACKED_NONPOINTER_ISA 1
384
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);
389
390 #elif __ARM_ARCH_7K__ >= 2
391 # define OBJC_HAVE_NONPOINTER_ISA 1
392 # define OBJC_HAVE_INDEXED_NONPOINTER_ISA 1
393
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];
398 // } else
399 // cls = (Class)isa;
400 // }
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);
409
410 #endif
411
412 // OBJC2
413 #endif
414
415 // _OBJC_ABI_H
416 #endif