evil-class-def.m 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321
  1. #include <sys/cdefs.h>
  2. #if __LP64__
  3. # define PTR " .quad "
  4. # define PTRSIZE "8"
  5. # define LOGPTRSIZE "3"
  6. #else
  7. # define PTR " .long "
  8. # define PTRSIZE "4"
  9. # define LOGPTRSIZE "2"
  10. #endif
  11. #if __has_feature(ptrauth_calls)
  12. # define SIGNED_METHOD_LIST_IMP "@AUTH(ia,0,addr) "
  13. #else
  14. # define SIGNED_METHOD_LIST_IMP
  15. #endif
  16. #define str(x) #x
  17. #define str2(x) str(x)
  18. __BEGIN_DECLS
  19. // not id to avoid ARC operations because the class doesn't implement RR methods
  20. void* nop(void* self) { return self; }
  21. __END_DECLS
  22. asm(
  23. ".globl _OBJC_CLASS_$_Super \n"
  24. ".section __DATA,__objc_data \n"
  25. ".align 3 \n"
  26. "_OBJC_CLASS_$_Super: \n"
  27. PTR "_OBJC_METACLASS_$_Super \n"
  28. PTR "0 \n"
  29. PTR "__objc_empty_cache \n"
  30. PTR "0 \n"
  31. PTR "L_ro \n"
  32. // pad to OBJC_MAX_CLASS_SIZE
  33. PTR "0 \n"
  34. PTR "0 \n"
  35. PTR "0 \n"
  36. PTR "0 \n"
  37. PTR "0 \n"
  38. PTR "0 \n"
  39. PTR "0 \n"
  40. PTR "0 \n"
  41. PTR "0 \n"
  42. PTR "0 \n"
  43. PTR "0 \n"
  44. PTR "0 \n"
  45. PTR "0 \n"
  46. PTR "0 \n"
  47. PTR "0 \n"
  48. PTR "0 \n"
  49. PTR "0 \n"
  50. PTR "0 \n"
  51. PTR "0 \n"
  52. PTR "0 \n"
  53. PTR "0 \n"
  54. PTR "0 \n"
  55. PTR "0 \n"
  56. PTR "0 \n"
  57. PTR "0 \n"
  58. PTR "0 \n"
  59. PTR "0 \n"
  60. ""
  61. "_OBJC_METACLASS_$_Super: \n"
  62. PTR "_OBJC_METACLASS_$_Super \n"
  63. PTR "_OBJC_CLASS_$_Super \n"
  64. PTR "__objc_empty_cache \n"
  65. PTR "0 \n"
  66. PTR "L_meta_ro \n"
  67. // pad to OBJC_MAX_CLASS_SIZE
  68. PTR "0 \n"
  69. PTR "0 \n"
  70. PTR "0 \n"
  71. PTR "0 \n"
  72. PTR "0 \n"
  73. PTR "0 \n"
  74. PTR "0 \n"
  75. PTR "0 \n"
  76. PTR "0 \n"
  77. PTR "0 \n"
  78. PTR "0 \n"
  79. PTR "0 \n"
  80. PTR "0 \n"
  81. PTR "0 \n"
  82. PTR "0 \n"
  83. PTR "0 \n"
  84. PTR "0 \n"
  85. PTR "0 \n"
  86. PTR "0 \n"
  87. PTR "0 \n"
  88. PTR "0 \n"
  89. PTR "0 \n"
  90. PTR "0 \n"
  91. PTR "0 \n"
  92. PTR "0 \n"
  93. PTR "0 \n"
  94. PTR "0 \n"
  95. ""
  96. "L_ro: \n"
  97. ".long 2 \n"
  98. ".long 0 \n"
  99. ".long " PTRSIZE " \n"
  100. #if __LP64__
  101. ".long 0 \n"
  102. #endif
  103. PTR "0 \n"
  104. PTR "L_super_name \n"
  105. #if EVIL_SUPER
  106. PTR "L_evil_methods \n"
  107. #else
  108. PTR "L_good_methods \n"
  109. #endif
  110. PTR "0 \n"
  111. PTR "L_super_ivars \n"
  112. PTR "0 \n"
  113. PTR "0 \n"
  114. ""
  115. "L_meta_ro: \n"
  116. ".long 3 \n"
  117. ".long 40 \n"
  118. ".long 40 \n"
  119. #if __LP64__
  120. ".long 0 \n"
  121. #endif
  122. PTR "0 \n"
  123. PTR "L_super_name \n"
  124. #if EVIL_SUPER_META
  125. PTR "L_evil_methods \n"
  126. #else
  127. PTR "L_good_methods \n"
  128. #endif
  129. PTR "0 \n"
  130. PTR "0 \n"
  131. PTR "0 \n"
  132. PTR "0 \n"
  133. ".globl _OBJC_CLASS_$_Sub \n"
  134. ".section __DATA,__objc_data \n"
  135. ".align 3 \n"
  136. "_OBJC_CLASS_$_Sub: \n"
  137. PTR "_OBJC_METACLASS_$_Sub \n"
  138. PTR "_OBJC_CLASS_$_Super \n"
  139. PTR "__objc_empty_cache \n"
  140. PTR "0 \n"
  141. PTR "L_sub_ro \n"
  142. // pad to OBJC_MAX_CLASS_SIZE
  143. PTR "0 \n"
  144. PTR "0 \n"
  145. PTR "0 \n"
  146. PTR "0 \n"
  147. PTR "0 \n"
  148. PTR "0 \n"
  149. PTR "0 \n"
  150. PTR "0 \n"
  151. PTR "0 \n"
  152. PTR "0 \n"
  153. PTR "0 \n"
  154. PTR "0 \n"
  155. PTR "0 \n"
  156. PTR "0 \n"
  157. PTR "0 \n"
  158. PTR "0 \n"
  159. PTR "0 \n"
  160. PTR "0 \n"
  161. PTR "0 \n"
  162. PTR "0 \n"
  163. PTR "0 \n"
  164. PTR "0 \n"
  165. PTR "0 \n"
  166. PTR "0 \n"
  167. PTR "0 \n"
  168. PTR "0 \n"
  169. PTR "0 \n"
  170. ""
  171. "_OBJC_METACLASS_$_Sub: \n"
  172. PTR "_OBJC_METACLASS_$_Super \n"
  173. PTR "_OBJC_METACLASS_$_Super \n"
  174. PTR "__objc_empty_cache \n"
  175. PTR "0 \n"
  176. PTR "L_sub_meta_ro \n"
  177. // pad to OBJC_MAX_CLASS_SIZE
  178. PTR "0 \n"
  179. PTR "0 \n"
  180. PTR "0 \n"
  181. PTR "0 \n"
  182. PTR "0 \n"
  183. PTR "0 \n"
  184. PTR "0 \n"
  185. PTR "0 \n"
  186. PTR "0 \n"
  187. PTR "0 \n"
  188. PTR "0 \n"
  189. PTR "0 \n"
  190. PTR "0 \n"
  191. PTR "0 \n"
  192. PTR "0 \n"
  193. PTR "0 \n"
  194. PTR "0 \n"
  195. PTR "0 \n"
  196. PTR "0 \n"
  197. PTR "0 \n"
  198. PTR "0 \n"
  199. PTR "0 \n"
  200. PTR "0 \n"
  201. PTR "0 \n"
  202. PTR "0 \n"
  203. PTR "0 \n"
  204. PTR "0 \n"
  205. ""
  206. "L_sub_ro: \n"
  207. ".long 2 \n"
  208. ".long 0 \n"
  209. ".long " PTRSIZE " \n"
  210. #if __LP64__
  211. ".long 0 \n"
  212. #endif
  213. PTR "0 \n"
  214. PTR "L_sub_name \n"
  215. #if EVIL_SUB
  216. PTR "L_evil_methods \n"
  217. #else
  218. PTR "L_good_methods \n"
  219. #endif
  220. PTR "0 \n"
  221. PTR "L_sub_ivars \n"
  222. PTR "0 \n"
  223. PTR "0 \n"
  224. ""
  225. "L_sub_meta_ro: \n"
  226. ".long 3 \n"
  227. ".long 40 \n"
  228. ".long 40 \n"
  229. #if __LP64__
  230. ".long 0 \n"
  231. #endif
  232. PTR "0 \n"
  233. PTR "L_sub_name \n"
  234. #if EVIL_SUB_META
  235. PTR "L_evil_methods \n"
  236. #else
  237. PTR "L_good_methods \n"
  238. #endif
  239. PTR "0 \n"
  240. PTR "0 \n"
  241. PTR "0 \n"
  242. PTR "0 \n"
  243. "L_evil_methods: \n"
  244. ".long 3*" PTRSIZE " \n"
  245. ".long 1 \n"
  246. PTR "L_load \n"
  247. PTR "L_load \n"
  248. PTR "_abort" SIGNED_METHOD_LIST_IMP "\n"
  249. // assumes that abort is inside the dyld shared cache
  250. "L_good_methods: \n"
  251. ".long 3*" PTRSIZE " \n"
  252. ".long 2 \n"
  253. PTR "L_load \n"
  254. PTR "L_load \n"
  255. PTR "_nop" SIGNED_METHOD_LIST_IMP "\n"
  256. PTR "L_self \n"
  257. PTR "L_self \n"
  258. PTR "_nop" SIGNED_METHOD_LIST_IMP "\n"
  259. "L_super_ivars: \n"
  260. ".long 4*" PTRSIZE " \n"
  261. ".long 1 \n"
  262. PTR "L_super_ivar_offset \n"
  263. PTR "L_super_ivar_name \n"
  264. PTR "L_super_ivar_type \n"
  265. ".long " LOGPTRSIZE " \n"
  266. ".long " PTRSIZE " \n"
  267. "L_sub_ivars: \n"
  268. ".long 4*" PTRSIZE " \n"
  269. ".long 1 \n"
  270. PTR "L_sub_ivar_offset \n"
  271. PTR "L_sub_ivar_name \n"
  272. PTR "L_sub_ivar_type \n"
  273. ".long " LOGPTRSIZE " \n"
  274. ".long " PTRSIZE " \n"
  275. "L_super_ivar_offset: \n"
  276. ".long 0 \n"
  277. "L_sub_ivar_offset: \n"
  278. ".long " PTRSIZE " \n"
  279. ".cstring \n"
  280. "L_super_name: .ascii \"Super\\0\" \n"
  281. "L_sub_name: .ascii \"Sub\\0\" \n"
  282. "L_load: .ascii \"load\\0\" \n"
  283. "L_self: .ascii \"self\\0\" \n"
  284. "L_super_ivar_name: .ascii \"super_ivar\\0\" \n"
  285. "L_super_ivar_type: .ascii \"c\\0\" \n"
  286. "L_sub_ivar_name: .ascii \"sub_ivar\\0\" \n"
  287. "L_sub_ivar_type: .ascii \"@\\0\" \n"
  288. ".section __DATA,__objc_classlist \n"
  289. #if !OMIT_SUPER
  290. PTR "_OBJC_CLASS_$_Super \n"
  291. #endif
  292. #if !OMIT_SUB
  293. PTR "_OBJC_CLASS_$_Sub \n"
  294. #endif
  295. ".section __DATA,__objc_nlclslist \n"
  296. #if !OMIT_NL_SUPER
  297. PTR "_OBJC_CLASS_$_Super \n"
  298. #endif
  299. #if !OMIT_NL_SUB
  300. PTR "_OBJC_CLASS_$_Sub \n"
  301. #endif
  302. ".text \n"
  303. );
  304. void fn(void) { }