arm64-asm.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. /*
  2. * @APPLE_LICENSE_HEADER_START@
  3. *
  4. * Copyright (c) 2018 Apple Inc. All Rights Reserved.
  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. * arm64-asm.h - asm tools for arm64/arm64_32 and ROP/JOP
  26. *
  27. ********************************************************************/
  28. #if __arm64__
  29. #if __LP64__
  30. // true arm64
  31. #define SUPPORT_TAGGED_POINTERS 1
  32. #define PTR .quad
  33. #define PTRSIZE 8
  34. #define PTRSHIFT 3 // 1<<PTRSHIFT == PTRSIZE
  35. // "p" registers are pointer-sized
  36. #define UXTP UXTX
  37. #define p0 x0
  38. #define p1 x1
  39. #define p2 x2
  40. #define p3 x3
  41. #define p4 x4
  42. #define p5 x5
  43. #define p6 x6
  44. #define p7 x7
  45. #define p8 x8
  46. #define p9 x9
  47. #define p10 x10
  48. #define p11 x11
  49. #define p12 x12
  50. #define p13 x13
  51. #define p14 x14
  52. #define p15 x15
  53. #define p16 x16
  54. #define p17 x17
  55. // true arm64
  56. #else
  57. // arm64_32
  58. #define SUPPORT_TAGGED_POINTERS 0
  59. #define PTR .long
  60. #define PTRSIZE 4
  61. #define PTRSHIFT 2 // 1<<PTRSHIFT == PTRSIZE
  62. // "p" registers are pointer-sized
  63. #define UXTP UXTW
  64. #define p0 w0
  65. #define p1 w1
  66. #define p2 w2
  67. #define p3 w3
  68. #define p4 w4
  69. #define p5 w5
  70. #define p6 w6
  71. #define p7 w7
  72. #define p8 w8
  73. #define p9 w9
  74. #define p10 w10
  75. #define p11 w11
  76. #define p12 w12
  77. #define p13 w13
  78. #define p14 w14
  79. #define p15 w15
  80. #define p16 w16
  81. #define p17 w17
  82. // arm64_32
  83. #endif
  84. #if __has_feature(ptrauth_returns)
  85. // ROP
  86. # define SignLR pacibsp
  87. # define AuthenticateLR autibsp
  88. #else
  89. // not ROP
  90. # define SignLR
  91. # define AuthenticateLR
  92. #endif
  93. #if __has_feature(ptrauth_calls)
  94. // JOP
  95. .macro TailCallFunctionPointer
  96. // $0 = function pointer value
  97. braaz $0
  98. .endmacro
  99. .macro TailCallCachedImp
  100. // $0 = cached imp, $1 = address of cached imp
  101. brab $0, $1
  102. .endmacro
  103. .macro TailCallMethodListImp
  104. // $0 = method list imp, $1 = address of method list imp
  105. braa $0, $1
  106. .endmacro
  107. .macro TailCallBlockInvoke
  108. // $0 = invoke function, $1 = address of invoke function
  109. braa $0, $1
  110. .endmacro
  111. .macro AuthAndResignAsIMP
  112. // $0 = cached imp, $1 = address of cached imp
  113. autib $0, $1 // authenticate cached imp
  114. paciza $0 // resign cached imp as IMP
  115. .endmacro
  116. // JOP
  117. #else
  118. // not JOP
  119. .macro TailCallFunctionPointer
  120. // $0 = function pointer value
  121. br $0
  122. .endmacro
  123. .macro TailCallCachedImp
  124. // $0 = cached imp, $1 = address of cached imp
  125. br $0
  126. .endmacro
  127. .macro TailCallMethodListImp
  128. // $0 = method list imp, $1 = address of method list imp
  129. br $0
  130. .endmacro
  131. .macro TailCallBlockInvoke
  132. // $0 = invoke function, $1 = address of invoke function
  133. br $0
  134. .endmacro
  135. .macro AuthAndResignAsIMP
  136. // empty
  137. .endmacro
  138. // not JOP
  139. #endif
  140. #define TailCallBlockInvoke TailCallMethodListImp
  141. // __arm64__
  142. #endif