tsan_rtl_amd64.S 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. // The content of this file is x86_64-only:
  2. #if defined(__x86_64__)
  3. #include "sanitizer_common/sanitizer_asm.h"
  4. #if !defined(__APPLE__)
  5. .section .text
  6. #else
  7. .section __TEXT,__text
  8. #endif
  9. ASM_HIDDEN(__tsan_setjmp)
  10. #if defined(__NetBSD__)
  11. .comm _ZN14__interception15real___setjmp14E,8,8
  12. #elif !defined(__APPLE__)
  13. .comm _ZN14__interception11real_setjmpE,8,8
  14. #endif
  15. #if defined(__NetBSD__)
  16. .globl ASM_SYMBOL_INTERCEPTOR(__setjmp14)
  17. ASM_TYPE_FUNCTION(ASM_SYMBOL_INTERCEPTOR(__setjmp14))
  18. ASM_SYMBOL_INTERCEPTOR(__setjmp14):
  19. #else
  20. .globl ASM_SYMBOL_INTERCEPTOR(setjmp)
  21. ASM_TYPE_FUNCTION(ASM_SYMBOL_INTERCEPTOR(setjmp))
  22. ASM_SYMBOL_INTERCEPTOR(setjmp):
  23. #endif
  24. CFI_STARTPROC
  25. _CET_ENDBR
  26. // save env parameter
  27. push %rdi
  28. CFI_ADJUST_CFA_OFFSET(8)
  29. CFI_REL_OFFSET(%rdi, 0)
  30. // obtain SP, store in %rdi, first argument to `void __tsan_setjmp(uptr sp)`
  31. #if defined(__FreeBSD__) || defined(__NetBSD__)
  32. lea 8(%rsp), %rdi
  33. #elif defined(__linux__) || defined(__APPLE__)
  34. lea 16(%rsp), %rdi
  35. #else
  36. # error "Unknown platform"
  37. #endif
  38. // call tsan interceptor
  39. call ASM_SYMBOL(__tsan_setjmp)
  40. // restore env parameter
  41. pop %rdi
  42. CFI_ADJUST_CFA_OFFSET(-8)
  43. CFI_RESTORE(%rdi)
  44. // tail jump to libc setjmp
  45. movl $0, %eax
  46. #if defined(__NetBSD__)
  47. movq _ZN14__interception15real___setjmp14E@GOTPCREL(%rip), %rdx
  48. jmp *(%rdx)
  49. #elif !defined(__APPLE__)
  50. movq _ZN14__interception11real_setjmpE@GOTPCREL(%rip), %rdx
  51. jmp *(%rdx)
  52. #else
  53. jmp ASM_SYMBOL(setjmp)
  54. #endif
  55. CFI_ENDPROC
  56. #if defined(__NetBSD__)
  57. ASM_SIZE(ASM_SYMBOL_INTERCEPTOR(__setjmp14))
  58. #else
  59. ASM_SIZE(ASM_SYMBOL_INTERCEPTOR(setjmp))
  60. #endif
  61. .comm _ZN14__interception12real__setjmpE,8,8
  62. .globl ASM_SYMBOL_INTERCEPTOR(_setjmp)
  63. ASM_TYPE_FUNCTION(ASM_SYMBOL_INTERCEPTOR(_setjmp))
  64. ASM_SYMBOL_INTERCEPTOR(_setjmp):
  65. CFI_STARTPROC
  66. _CET_ENDBR
  67. // save env parameter
  68. push %rdi
  69. CFI_ADJUST_CFA_OFFSET(8)
  70. CFI_REL_OFFSET(%rdi, 0)
  71. // obtain SP, store in %rdi, first argument to `void __tsan_setjmp(uptr sp)`
  72. #if defined(__FreeBSD__) || defined(__NetBSD__)
  73. lea 8(%rsp), %rdi
  74. #elif defined(__linux__) || defined(__APPLE__)
  75. lea 16(%rsp), %rdi
  76. #else
  77. # error "Unknown platform"
  78. #endif
  79. // call tsan interceptor
  80. call ASM_SYMBOL(__tsan_setjmp)
  81. // restore env parameter
  82. pop %rdi
  83. CFI_ADJUST_CFA_OFFSET(-8)
  84. CFI_RESTORE(%rdi)
  85. // tail jump to libc setjmp
  86. movl $0, %eax
  87. #if !defined(__APPLE__)
  88. movq _ZN14__interception12real__setjmpE@GOTPCREL(%rip), %rdx
  89. jmp *(%rdx)
  90. #else
  91. jmp ASM_SYMBOL(_setjmp)
  92. #endif
  93. CFI_ENDPROC
  94. ASM_SIZE(ASM_SYMBOL_INTERCEPTOR(_setjmp))
  95. #if defined(__NetBSD__)
  96. .comm _ZN14__interception18real___sigsetjmp14E,8,8
  97. .globl ASM_SYMBOL_INTERCEPTOR(__sigsetjmp14)
  98. ASM_TYPE_FUNCTION(ASM_SYMBOL_INTERCEPTOR(__sigsetjmp14))
  99. ASM_SYMBOL_INTERCEPTOR(__sigsetjmp14):
  100. #else
  101. .comm _ZN14__interception14real_sigsetjmpE,8,8
  102. .globl ASM_SYMBOL_INTERCEPTOR(sigsetjmp)
  103. ASM_TYPE_FUNCTION(ASM_SYMBOL_INTERCEPTOR(sigsetjmp))
  104. ASM_SYMBOL_INTERCEPTOR(sigsetjmp):
  105. #endif
  106. CFI_STARTPROC
  107. _CET_ENDBR
  108. // save env parameter
  109. push %rdi
  110. CFI_ADJUST_CFA_OFFSET(8)
  111. CFI_REL_OFFSET(%rdi, 0)
  112. // save savesigs parameter
  113. push %rsi
  114. CFI_ADJUST_CFA_OFFSET(8)
  115. CFI_REL_OFFSET(%rsi, 0)
  116. // align stack frame
  117. sub $8, %rsp
  118. CFI_ADJUST_CFA_OFFSET(8)
  119. // obtain SP, store in %rdi, first argument to `void __tsan_setjmp(uptr sp)`
  120. #if defined(__FreeBSD__) || defined(__NetBSD__)
  121. lea 24(%rsp), %rdi
  122. #elif defined(__linux__) || defined(__APPLE__)
  123. lea 32(%rsp), %rdi
  124. #else
  125. # error "Unknown platform"
  126. #endif
  127. // call tsan interceptor
  128. call ASM_SYMBOL(__tsan_setjmp)
  129. // unalign stack frame
  130. add $8, %rsp
  131. CFI_ADJUST_CFA_OFFSET(-8)
  132. // restore savesigs parameter
  133. pop %rsi
  134. CFI_ADJUST_CFA_OFFSET(-8)
  135. CFI_RESTORE(%rsi)
  136. // restore env parameter
  137. pop %rdi
  138. CFI_ADJUST_CFA_OFFSET(-8)
  139. CFI_RESTORE(%rdi)
  140. // tail jump to libc sigsetjmp
  141. movl $0, %eax
  142. #if defined(__NetBSD__)
  143. movq _ZN14__interception18real___sigsetjmp14E@GOTPCREL(%rip), %rdx
  144. jmp *(%rdx)
  145. #elif !defined(__APPLE__)
  146. movq _ZN14__interception14real_sigsetjmpE@GOTPCREL(%rip), %rdx
  147. jmp *(%rdx)
  148. #else
  149. jmp ASM_SYMBOL(sigsetjmp)
  150. #endif
  151. CFI_ENDPROC
  152. #if defined(__NetBSD__)
  153. ASM_SIZE(ASM_SYMBOL_INTERCEPTOR(__sigsetjmp14))
  154. #else
  155. ASM_SIZE(ASM_SYMBOL_INTERCEPTOR(sigsetjmp))
  156. #endif
  157. #if !defined(__APPLE__) && !defined(__NetBSD__)
  158. .comm _ZN14__interception16real___sigsetjmpE,8,8
  159. .globl ASM_SYMBOL_INTERCEPTOR(__sigsetjmp)
  160. ASM_TYPE_FUNCTION(ASM_SYMBOL_INTERCEPTOR(__sigsetjmp))
  161. ASM_SYMBOL_INTERCEPTOR(__sigsetjmp):
  162. CFI_STARTPROC
  163. _CET_ENDBR
  164. // save env parameter
  165. push %rdi
  166. CFI_ADJUST_CFA_OFFSET(8)
  167. CFI_REL_OFFSET(%rdi, 0)
  168. // save savesigs parameter
  169. push %rsi
  170. CFI_ADJUST_CFA_OFFSET(8)
  171. CFI_REL_OFFSET(%rsi, 0)
  172. // align stack frame
  173. sub $8, %rsp
  174. CFI_ADJUST_CFA_OFFSET(8)
  175. // obtain SP, store in %rdi, first argument to `void __tsan_setjmp(uptr sp)`
  176. #if defined(__FreeBSD__)
  177. lea 24(%rsp), %rdi
  178. #else
  179. lea 32(%rsp), %rdi
  180. #endif
  181. // call tsan interceptor
  182. call ASM_SYMBOL(__tsan_setjmp)
  183. // unalign stack frame
  184. add $8, %rsp
  185. CFI_ADJUST_CFA_OFFSET(-8)
  186. // restore savesigs parameter
  187. pop %rsi
  188. CFI_ADJUST_CFA_OFFSET(-8)
  189. CFI_RESTORE(%rsi)
  190. // restore env parameter
  191. pop %rdi
  192. CFI_ADJUST_CFA_OFFSET(-8)
  193. CFI_RESTORE(%rdi)
  194. // tail jump to libc sigsetjmp
  195. movl $0, %eax
  196. movq _ZN14__interception16real___sigsetjmpE@GOTPCREL(%rip), %rdx
  197. jmp *(%rdx)
  198. CFI_ENDPROC
  199. ASM_SIZE(ASM_SYMBOL_INTERCEPTOR(__sigsetjmp))
  200. #endif // !defined(__APPLE__) && !defined(__NetBSD__)
  201. NO_EXEC_STACK_DIRECTIVE
  202. #endif