objc-abi.h 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477
  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. #ifndef _OBJC_ABI_H
  24. #define _OBJC_ABI_H
  25. /*
  26. * WARNING DANGER HAZARD BEWARE EEK
  27. *
  28. * Everything in this file is for Apple Internal use only.
  29. * These will change in arbitrary OS updates and in unpredictable ways.
  30. * When your program breaks, you get to keep both pieces.
  31. */
  32. /*
  33. * objc-abi.h: Declarations for functions used by compiler codegen.
  34. */
  35. #include <malloc/malloc.h>
  36. #include <TargetConditionals.h>
  37. #include <objc/objc.h>
  38. #include <objc/runtime.h>
  39. #include <objc/message.h>
  40. /* Linker metadata symbols */
  41. // NSObject was in Foundation/CF on macOS < 10.8.
  42. #if TARGET_OS_OSX
  43. #if __OBJC2__
  44. OBJC_EXPORT const char __objc_nsobject_class_10_5
  45. __asm__("$ld$hide$os10.5$_OBJC_CLASS_$_NSObject");
  46. OBJC_EXPORT const char __objc_nsobject_class_10_6
  47. __asm__("$ld$hide$os10.6$_OBJC_CLASS_$_NSObject");
  48. OBJC_EXPORT const char __objc_nsobject_class_10_7
  49. __asm__("$ld$hide$os10.7$_OBJC_CLASS_$_NSObject");
  50. OBJC_EXPORT const char __objc_nsobject_metaclass_10_5
  51. __asm__("$ld$hide$os10.5$_OBJC_METACLASS_$_NSObject");
  52. OBJC_EXPORT const char __objc_nsobject_metaclass_10_6
  53. __asm__("$ld$hide$os10.6$_OBJC_METACLASS_$_NSObject");
  54. OBJC_EXPORT const char __objc_nsobject_metaclass_10_7
  55. __asm__("$ld$hide$os10.7$_OBJC_METACLASS_$_NSObject");
  56. OBJC_EXPORT const char __objc_nsobject_isa_10_5
  57. __asm__("$ld$hide$os10.5$_OBJC_IVAR_$_NSObject.isa");
  58. OBJC_EXPORT const char __objc_nsobject_isa_10_6
  59. __asm__("$ld$hide$os10.6$_OBJC_IVAR_$_NSObject.isa");
  60. OBJC_EXPORT const char __objc_nsobject_isa_10_7
  61. __asm__("$ld$hide$os10.7$_OBJC_IVAR_$_NSObject.isa");
  62. #else
  63. OBJC_EXPORT const char __objc_nsobject_class_10_5
  64. __asm__("$ld$hide$os10.5$.objc_class_name_NSObject");
  65. OBJC_EXPORT const char __objc_nsobject_class_10_6
  66. __asm__("$ld$hide$os10.6$.objc_class_name_NSObject");
  67. OBJC_EXPORT const char __objc_nsobject_class_10_7
  68. __asm__("$ld$hide$os10.7$.objc_class_name_NSObject");
  69. #endif
  70. #endif
  71. /* Runtime startup. */
  72. // Old static initializer. Used by old crt1.o and old bug workarounds.
  73. OBJC_EXPORT void
  74. _objcInit(void)
  75. OBJC_AVAILABLE(10.0, 2.0, 9.0, 1.0, 2.0);
  76. /* Images */
  77. // Description of an Objective-C image.
  78. // __DATA,__objc_imageinfo stores one of these.
  79. typedef struct objc_image_info {
  80. uint32_t version; // currently 0
  81. uint32_t flags;
  82. #if __cplusplus >= 201103L
  83. private:
  84. enum : uint32_t {
  85. // 1 byte assorted flags
  86. IsReplacement = 1<<0, // used for Fix&Continue, now ignored
  87. SupportsGC = 1<<1, // image supports GC
  88. RequiresGC = 1<<2, // image requires GC
  89. OptimizedByDyld = 1<<3, // image is from an optimized shared cache
  90. CorrectedSynthesize = 1<<4, // used for an old workaround, now ignored
  91. IsSimulated = 1<<5, // image compiled for a simulator platform
  92. HasCategoryClassProperties = 1<<6, // class properties in category_t
  93. OptimizedByDyldClosure = 1 << 7, // dyld (not the shared cache) optimized this.
  94. // 1 byte Swift unstable ABI version number
  95. SwiftUnstableVersionMaskShift = 8,
  96. SwiftUnstableVersionMask = 0xff << SwiftUnstableVersionMaskShift,
  97. // 2 byte Swift stable ABI version number
  98. SwiftStableVersionMaskShift = 16,
  99. SwiftStableVersionMask = 0xffffUL << SwiftStableVersionMaskShift
  100. };
  101. public:
  102. enum : uint32_t {
  103. // Values for SwiftUnstableVersion
  104. // All stable ABIs store SwiftVersion5 here.
  105. SwiftVersion1 = 1,
  106. SwiftVersion1_2 = 2,
  107. SwiftVersion2 = 3,
  108. SwiftVersion3 = 4,
  109. SwiftVersion4 = 5,
  110. SwiftVersion4_1 = 6,
  111. SwiftVersion4_2 = 6, // [sic]
  112. SwiftVersion5 = 7
  113. };
  114. public:
  115. bool isReplacement() const { return flags & IsReplacement; }
  116. bool supportsGC() const { return flags & SupportsGC; }
  117. bool requiresGC() const { return flags & RequiresGC; }
  118. bool optimizedByDyld() const { return flags & OptimizedByDyld; }
  119. bool hasCategoryClassProperties() const { return flags & HasCategoryClassProperties; }
  120. bool optimizedByDyldClosure() const { return flags & OptimizedByDyldClosure; }
  121. bool containsSwift() const { return (flags & SwiftUnstableVersionMask) != 0; }
  122. uint32_t swiftUnstableVersion() const { return (flags & SwiftUnstableVersionMask) >> SwiftUnstableVersionMaskShift; }
  123. #endif
  124. } objc_image_info;
  125. /*
  126. IsReplacement:
  127. Once used for Fix&Continue in old OS X object files (not final linked images)
  128. Not currently used.
  129. SupportsGC:
  130. App: GC is required. Framework: GC is supported but not required.
  131. RequiresGC:
  132. Framework: GC is required.
  133. OptimizedByDyld:
  134. Assorted metadata precooked in the dyld shared cache.
  135. Never set for images outside the shared cache file itself.
  136. CorrectedSynthesize:
  137. Once used on old iOS to mark images that did not have a particular
  138. miscompile. Not used by the runtime.
  139. IsSimulated:
  140. Image was compiled for a simulator platform. Not used by the runtime.
  141. HasClassProperties:
  142. New ABI: category_t.classProperties fields are present.
  143. Old ABI: Set by some compilers. Not used by the runtime.
  144. */
  145. /* Properties */
  146. // Read or write an object property. Not all object properties use these.
  147. OBJC_EXPORT id _Nullable
  148. objc_getProperty(id _Nullable self, SEL _Nonnull _cmd,
  149. ptrdiff_t offset, BOOL atomic)
  150. OBJC_AVAILABLE(10.5, 2.0, 9.0, 1.0, 2.0);
  151. OBJC_EXPORT void
  152. objc_setProperty(id _Nullable self, SEL _Nonnull _cmd, ptrdiff_t offset,
  153. id _Nullable newValue, BOOL atomic, signed char shouldCopy)
  154. OBJC_AVAILABLE(10.5, 2.0, 9.0, 1.0, 2.0);
  155. OBJC_EXPORT void
  156. objc_setProperty_atomic(id _Nullable self, SEL _Nonnull _cmd,
  157. id _Nullable newValue, ptrdiff_t offset)
  158. OBJC_AVAILABLE(10.8, 6.0, 9.0, 1.0, 2.0);
  159. OBJC_EXPORT void
  160. objc_setProperty_nonatomic(id _Nullable self, SEL _Nonnull _cmd,
  161. id _Nullable newValue, ptrdiff_t offset)
  162. OBJC_AVAILABLE(10.8, 6.0, 9.0, 1.0, 2.0);
  163. OBJC_EXPORT void
  164. objc_setProperty_atomic_copy(id _Nullable self, SEL _Nonnull _cmd,
  165. id _Nullable newValue, ptrdiff_t offset)
  166. OBJC_AVAILABLE(10.8, 6.0, 9.0, 1.0, 2.0);
  167. OBJC_EXPORT void
  168. objc_setProperty_nonatomic_copy(id _Nullable self, SEL _Nonnull _cmd,
  169. id _Nullable newValue, ptrdiff_t offset)
  170. OBJC_AVAILABLE(10.8, 6.0, 9.0, 1.0, 2.0);
  171. // Read or write a non-object property. Not all uses are C structs,
  172. // and not all C struct properties use this.
  173. OBJC_EXPORT void
  174. objc_copyStruct(void * _Nonnull dest, const void * _Nonnull src,
  175. ptrdiff_t size, BOOL atomic, BOOL hasStrong)
  176. OBJC_AVAILABLE(10.5, 2.0, 9.0, 1.0, 2.0);
  177. // Perform a copy of a C++ object using striped locks. Used by non-POD C++ typed atomic properties.
  178. OBJC_EXPORT void
  179. objc_copyCppObjectAtomic(void * _Nonnull dest, const void * _Nonnull src,
  180. void (* _Nonnull copyHelper)
  181. (void * _Nonnull dest, const void * _Nonnull source))
  182. OBJC_AVAILABLE(10.8, 6.0, 9.0, 1.0, 2.0);
  183. /* Classes. */
  184. #if __OBJC2__
  185. OBJC_EXPORT IMP _Nonnull _objc_empty_vtable
  186. OBJC_AVAILABLE(10.5, 2.0, 9.0, 1.0, 2.0);
  187. #endif
  188. OBJC_EXPORT struct objc_cache _objc_empty_cache
  189. OBJC_AVAILABLE(10.0, 2.0, 9.0, 1.0, 2.0);
  190. /* Messages */
  191. #if __OBJC2__
  192. // objc_msgSendSuper2() takes the current search class, not its superclass.
  193. OBJC_EXPORT id _Nullable
  194. objc_msgSendSuper2(struct objc_super * _Nonnull super, SEL _Nonnull op, ...)
  195. OBJC_AVAILABLE(10.6, 2.0, 9.0, 1.0, 2.0);
  196. OBJC_EXPORT void
  197. objc_msgSendSuper2_stret(struct objc_super * _Nonnull super,
  198. SEL _Nonnull op,...)
  199. OBJC_AVAILABLE(10.6, 2.0, 9.0, 1.0, 2.0)
  200. OBJC_ARM64_UNAVAILABLE;
  201. // objc_msgSend_noarg() may be faster for methods with no additional arguments.
  202. OBJC_EXPORT id _Nullable
  203. objc_msgSend_noarg(id _Nullable self, SEL _Nonnull _cmd)
  204. OBJC_AVAILABLE(10.7, 5.0, 9.0, 1.0, 2.0);
  205. #endif
  206. #if __OBJC2__
  207. // Debug messengers. Messengers used by the compiler have a debug flavor that
  208. // may perform extra sanity checking.
  209. // Old objc_msgSendSuper() does not have a debug version; this is OBJC2 only.
  210. // *_fixup() do not have debug versions; use non-fixup only for debug mode.
  211. OBJC_EXPORT id _Nullable
  212. objc_msgSend_debug(id _Nullable self, SEL _Nonnull op, ...)
  213. OBJC_AVAILABLE(10.7, 5.0, 9.0, 1.0, 2.0);
  214. OBJC_EXPORT id _Nullable
  215. objc_msgSendSuper2_debug(struct objc_super * _Nonnull super,
  216. SEL _Nonnull op, ...)
  217. OBJC_AVAILABLE(10.7, 5.0, 9.0, 1.0, 2.0);
  218. OBJC_EXPORT void
  219. objc_msgSend_stret_debug(id _Nullable self, SEL _Nonnull op, ...)
  220. OBJC_AVAILABLE(10.7, 5.0, 9.0, 1.0, 2.0)
  221. OBJC_ARM64_UNAVAILABLE;
  222. OBJC_EXPORT void
  223. objc_msgSendSuper2_stret_debug(struct objc_super * _Nonnull super,
  224. SEL _Nonnull op,...)
  225. OBJC_AVAILABLE(10.7, 5.0, 9.0, 1.0, 2.0)
  226. OBJC_ARM64_UNAVAILABLE;
  227. # if defined(__i386__)
  228. OBJC_EXPORT double
  229. objc_msgSend_fpret_debug(id _Nullable self, SEL _Nonnull op, ...)
  230. OBJC_AVAILABLE(10.7, 5.0, 9.0, 1.0, 2.0);
  231. # elif defined(__x86_64__)
  232. OBJC_EXPORT long double
  233. objc_msgSend_fpret_debug(id _Nullable self, SEL _Nonnull op, ...)
  234. OBJC_AVAILABLE(10.7, 5.0, 9.0, 1.0, 2.0);
  235. # if __STDC_VERSION__ >= 199901L
  236. OBJC_EXPORT _Complex long double
  237. objc_msgSend_fp2ret_debug(id _Nullable self, SEL _Nonnull op, ...)
  238. OBJC_AVAILABLE(10.7, 5.0, 9.0, 1.0, 2.0);
  239. # else
  240. OBJC_EXPORT void
  241. objc_msgSend_fp2ret_debug(id _Nullable self, SEL _Nonnull op, ...)
  242. OBJC_AVAILABLE(10.7, 5.0, 9.0, 1.0, 2.0);
  243. # endif
  244. # endif
  245. #endif
  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. OBJC_EXPORT void
  262. objc_msgLookup(void)
  263. OBJC_AVAILABLE(10.12, 10.0, 10.0, 3.0, 2.0);
  264. OBJC_EXPORT void
  265. objc_msgLookupSuper2(void)
  266. OBJC_AVAILABLE(10.12, 10.0, 10.0, 3.0, 2.0);
  267. OBJC_EXPORT void
  268. objc_msgLookup_stret(void)
  269. OBJC_AVAILABLE(10.12, 10.0, 10.0, 3.0, 2.0)
  270. OBJC_ARM64_UNAVAILABLE;
  271. OBJC_EXPORT void
  272. objc_msgLookupSuper2_stret(void)
  273. OBJC_AVAILABLE(10.12, 10.0, 10.0, 3.0, 2.0)
  274. OBJC_ARM64_UNAVAILABLE;
  275. # if defined(__i386__)
  276. OBJC_EXPORT void
  277. objc_msgLookup_fpret(void)
  278. OBJC_AVAILABLE(10.12, 10.0, 10.0, 3.0, 2.0);
  279. # elif defined(__x86_64__)
  280. OBJC_EXPORT void
  281. objc_msgLookup_fpret(void)
  282. OBJC_AVAILABLE(10.12, 10.0, 10.0, 3.0, 2.0);
  283. OBJC_EXPORT void
  284. objc_msgLookup_fp2ret(void)
  285. OBJC_AVAILABLE(10.12, 10.0, 10.0, 3.0, 2.0);
  286. # endif
  287. #endif
  288. #if (TARGET_OS_OSX || TARGET_OS_SIMULATOR) && defined(__x86_64__)
  289. // objc_msgSend_fixup() was used for vtable-dispatchable call sites.
  290. // The symbols remain exported on macOS for binary compatibility.
  291. // The symbols can probably be removed from iOS simulator but we haven't tried.
  292. OBJC_EXPORT void
  293. objc_msgSend_fixup(void)
  294. __OSX_DEPRECATED(10.5, 10.8, "fixup dispatch is no longer optimized");
  295. OBJC_EXPORT void
  296. objc_msgSend_stret_fixup(void)
  297. __OSX_DEPRECATED(10.5, 10.8, "fixup dispatch is no longer optimized");
  298. OBJC_EXPORT void
  299. objc_msgSendSuper2_fixup(void)
  300. __OSX_DEPRECATED(10.5, 10.8, "fixup dispatch is no longer optimized");
  301. OBJC_EXPORT void
  302. objc_msgSendSuper2_stret_fixup(void)
  303. __OSX_DEPRECATED(10.5, 10.8, "fixup dispatch is no longer optimized");
  304. OBJC_EXPORT void
  305. objc_msgSend_fpret_fixup(void)
  306. __OSX_DEPRECATED(10.5, 10.8, "fixup dispatch is no longer optimized");
  307. OBJC_EXPORT void
  308. objc_msgSend_fp2ret_fixup(void)
  309. __OSX_DEPRECATED(10.5, 10.8, "fixup dispatch is no longer optimized");
  310. #endif
  311. /* C++-compatible exception handling. */
  312. #if __OBJC2__
  313. // Vtable for C++ exception typeinfo for Objective-C types.
  314. OBJC_EXPORT const void * _Nullable objc_ehtype_vtable[]
  315. OBJC_AVAILABLE(10.5, 2.0, 9.0, 1.0, 2.0);
  316. // C++ exception typeinfo for type `id`.
  317. OBJC_EXPORT struct objc_typeinfo OBJC_EHTYPE_id
  318. OBJC_AVAILABLE(10.5, 2.0, 9.0, 1.0, 2.0);
  319. // Exception personality function for Objective-C and Objective-C++ code.
  320. struct _Unwind_Exception;
  321. struct _Unwind_Context;
  322. OBJC_EXPORT int
  323. __objc_personality_v0(int version,
  324. int actions,
  325. uint64_t exceptionClass,
  326. struct _Unwind_Exception * _Nonnull exceptionObject,
  327. struct _Unwind_Context * _Nonnull context)
  328. OBJC_AVAILABLE(10.5, 2.0, 9.0, 1.0, 2.0);
  329. #endif
  330. /* ARC */
  331. OBJC_EXPORT id _Nullable
  332. objc_retainBlock(id _Nullable)
  333. OBJC_AVAILABLE(10.7, 5.0, 9.0, 1.0, 2.0);
  334. /* Non-pointer isa */
  335. #if __OBJC2__
  336. // Extract class pointer from an isa field.
  337. #if TARGET_OS_SIMULATOR && !TARGET_OS_IOSMAC
  338. // No simulators use nonpointer isa yet.
  339. #elif __LP64__
  340. # define OBJC_HAVE_NONPOINTER_ISA 1
  341. # define OBJC_HAVE_PACKED_NONPOINTER_ISA 1
  342. // Packed-isa version. This one is used directly by Swift code.
  343. // (Class)(isa & (uintptr_t)&objc_absolute_packed_isa_class_mask) == class ptr
  344. OBJC_EXPORT const struct { char c; } objc_absolute_packed_isa_class_mask
  345. OBJC_AVAILABLE(10.12, 10.0, 10.0, 3.0, 2.0);
  346. #elif (__ARM_ARCH_7K__ >= 2 || (__arm64__ && !__LP64__))
  347. # define OBJC_HAVE_NONPOINTER_ISA 1
  348. # define OBJC_HAVE_INDEXED_NONPOINTER_ISA 1
  349. // Indexed-isa version.
  350. // if (isa & (uintptr_t)&objc_absolute_indexed_isa_magic_mask == (uintptr_t)&objc_absolute_indexed_isa_magic_value) {
  351. // uintptr_t index = (isa & (uintptr_t)&objc_absolute_indexed_isa_index_mask) >> (uintptr_t)&objc_absolute_indexed_isa_index_shift;
  352. // cls = objc_indexed_classes[index];
  353. // } else
  354. // cls = (Class)isa;
  355. // }
  356. OBJC_EXPORT const struct { char c; } objc_absolute_indexed_isa_magic_mask
  357. OBJC_AVAILABLE(10.12, 10.0, 10.0, 3.0, 2.0);
  358. OBJC_EXPORT const struct { char c; } objc_absolute_indexed_isa_magic_value
  359. OBJC_AVAILABLE(10.12, 10.0, 10.0, 3.0, 2.0);
  360. OBJC_EXPORT const struct { char c; } objc_absolute_indexed_isa_index_mask
  361. OBJC_AVAILABLE(10.12, 10.0, 10.0, 3.0, 2.0);
  362. OBJC_EXPORT const struct { char c; } objc_absolute_indexed_isa_index_shift
  363. OBJC_AVAILABLE(10.12, 10.0, 10.0, 3.0, 2.0);
  364. #endif
  365. #endif
  366. /* Object class */
  367. // This symbol might be required for binary compatibility, so we
  368. // declare it here where TAPI will see it.
  369. #if __OBJC__ && __OBJC2__
  370. #pragma clang diagnostic push
  371. #pragma clang diagnostic ignored "-Wobjc-interface-ivars"
  372. #if !defined(OBJC_DECLARE_SYMBOLS)
  373. __OSX_AVAILABLE(10.0)
  374. __IOS_UNAVAILABLE __TVOS_UNAVAILABLE
  375. __WATCHOS_UNAVAILABLE
  376. # ifndef __APPLE_BLEACH_SDK__
  377. __BRIDGEOS_UNAVAILABLE
  378. # endif
  379. #endif
  380. OBJC_ROOT_CLASS
  381. @interface Object {
  382. Class isa;
  383. }
  384. @end
  385. #pragma clang diagnostic pop
  386. #endif
  387. // _OBJC_ABI_H
  388. #endif