Home | History | Annotate | Download | only in rtl
      1 #include "sanitizer_common/sanitizer_asm.h"
      2 .section .text
      3 
      4 .hidden __tsan_trace_switch
      5 .globl __tsan_trace_switch_thunk
      6 __tsan_trace_switch_thunk:
      7   CFI_STARTPROC
      8   # Save scratch registers.
      9   push %rax
     10   CFI_ADJUST_CFA_OFFSET(8)
     11   CFI_REL_OFFSET(%rax, 0)
     12   push %rcx
     13   CFI_ADJUST_CFA_OFFSET(8)
     14   CFI_REL_OFFSET(%rcx, 0)
     15   push %rdx
     16   CFI_ADJUST_CFA_OFFSET(8)
     17   CFI_REL_OFFSET(%rdx, 0)
     18   push %rsi
     19   CFI_ADJUST_CFA_OFFSET(8)
     20   CFI_REL_OFFSET(%rsi, 0)
     21   push %rdi
     22   CFI_ADJUST_CFA_OFFSET(8)
     23   CFI_REL_OFFSET(%rdi, 0)
     24   push %r8
     25   CFI_ADJUST_CFA_OFFSET(8)
     26   CFI_REL_OFFSET(%r8, 0)
     27   push %r9
     28   CFI_ADJUST_CFA_OFFSET(8)
     29   CFI_REL_OFFSET(%r9, 0)
     30   push %r10
     31   CFI_ADJUST_CFA_OFFSET(8)
     32   CFI_REL_OFFSET(%r10, 0)
     33   push %r11
     34   CFI_ADJUST_CFA_OFFSET(8)
     35   CFI_REL_OFFSET(%r11, 0)
     36   # Align stack frame.
     37   push %rbx  # non-scratch
     38   CFI_ADJUST_CFA_OFFSET(8)
     39   CFI_REL_OFFSET(%rbx, 0)
     40   mov %rsp, %rbx  # save current rsp
     41   CFI_DEF_CFA_REGISTER(%rbx)
     42   shr $4, %rsp  # clear 4 lsb, align to 16
     43   shl $4, %rsp
     44 
     45   call __tsan_trace_switch
     46 
     47   # Unalign stack frame back.
     48   mov %rbx, %rsp  # restore the original rsp
     49   CFI_DEF_CFA_REGISTER(%rsp)
     50   pop %rbx
     51   CFI_ADJUST_CFA_OFFSET(-8)
     52   # Restore scratch registers.
     53   pop %r11
     54   CFI_ADJUST_CFA_OFFSET(-8)
     55   pop %r10
     56   CFI_ADJUST_CFA_OFFSET(-8)
     57   pop %r9
     58   CFI_ADJUST_CFA_OFFSET(-8)
     59   pop %r8
     60   CFI_ADJUST_CFA_OFFSET(-8)
     61   pop %rdi
     62   CFI_ADJUST_CFA_OFFSET(-8)
     63   pop %rsi
     64   CFI_ADJUST_CFA_OFFSET(-8)
     65   pop %rdx
     66   CFI_ADJUST_CFA_OFFSET(-8)
     67   pop %rcx
     68   CFI_ADJUST_CFA_OFFSET(-8)
     69   pop %rax
     70   CFI_ADJUST_CFA_OFFSET(-8)
     71   CFI_RESTORE(%rax)
     72   CFI_RESTORE(%rbx)
     73   CFI_RESTORE(%rcx)
     74   CFI_RESTORE(%rdx)
     75   CFI_RESTORE(%rsi)
     76   CFI_RESTORE(%rdi)
     77   CFI_RESTORE(%r8)
     78   CFI_RESTORE(%r9)
     79   CFI_RESTORE(%r10)
     80   CFI_RESTORE(%r11)
     81   ret
     82   CFI_ENDPROC
     83 
     84 .hidden __tsan_report_race
     85 .globl __tsan_report_race_thunk
     86 __tsan_report_race_thunk:
     87   CFI_STARTPROC
     88   # Save scratch registers.
     89   push %rax
     90   CFI_ADJUST_CFA_OFFSET(8)
     91   CFI_REL_OFFSET(%rax, 0)
     92   push %rcx
     93   CFI_ADJUST_CFA_OFFSET(8)
     94   CFI_REL_OFFSET(%rcx, 0)
     95   push %rdx
     96   CFI_ADJUST_CFA_OFFSET(8)
     97   CFI_REL_OFFSET(%rdx, 0)
     98   push %rsi
     99   CFI_ADJUST_CFA_OFFSET(8)
    100   CFI_REL_OFFSET(%rsi, 0)
    101   push %rdi
    102   CFI_ADJUST_CFA_OFFSET(8)
    103   CFI_REL_OFFSET(%rdi, 0)
    104   push %r8
    105   CFI_ADJUST_CFA_OFFSET(8)
    106   CFI_REL_OFFSET(%r8, 0)
    107   push %r9
    108   CFI_ADJUST_CFA_OFFSET(8)
    109   CFI_REL_OFFSET(%r9, 0)
    110   push %r10
    111   CFI_ADJUST_CFA_OFFSET(8)
    112   CFI_REL_OFFSET(%r10, 0)
    113   push %r11
    114   CFI_ADJUST_CFA_OFFSET(8)
    115   CFI_REL_OFFSET(%r11, 0)
    116   # Align stack frame.
    117   push %rbx  # non-scratch
    118   CFI_ADJUST_CFA_OFFSET(8)
    119   CFI_REL_OFFSET(%rbx, 0)
    120   mov %rsp, %rbx  # save current rsp
    121   CFI_DEF_CFA_REGISTER(%rbx)
    122   shr $4, %rsp  # clear 4 lsb, align to 16
    123   shl $4, %rsp
    124 
    125   call __tsan_report_race
    126 
    127   # Unalign stack frame back.
    128   mov %rbx, %rsp  # restore the original rsp
    129   CFI_DEF_CFA_REGISTER(%rsp)
    130   pop %rbx
    131   CFI_ADJUST_CFA_OFFSET(-8)
    132   # Restore scratch registers.
    133   pop %r11
    134   CFI_ADJUST_CFA_OFFSET(-8)
    135   pop %r10
    136   CFI_ADJUST_CFA_OFFSET(-8)
    137   pop %r9
    138   CFI_ADJUST_CFA_OFFSET(-8)
    139   pop %r8
    140   CFI_ADJUST_CFA_OFFSET(-8)
    141   pop %rdi
    142   CFI_ADJUST_CFA_OFFSET(-8)
    143   pop %rsi
    144   CFI_ADJUST_CFA_OFFSET(-8)
    145   pop %rdx
    146   CFI_ADJUST_CFA_OFFSET(-8)
    147   pop %rcx
    148   CFI_ADJUST_CFA_OFFSET(-8)
    149   pop %rax
    150   CFI_ADJUST_CFA_OFFSET(-8)
    151   CFI_RESTORE(%rax)
    152   CFI_RESTORE(%rbx)
    153   CFI_RESTORE(%rcx)
    154   CFI_RESTORE(%rdx)
    155   CFI_RESTORE(%rsi)
    156   CFI_RESTORE(%rdi)
    157   CFI_RESTORE(%r8)
    158   CFI_RESTORE(%r9)
    159   CFI_RESTORE(%r10)
    160   CFI_RESTORE(%r11)
    161   ret
    162   CFI_ENDPROC
    163 
    164 .hidden __tsan_setjmp
    165 .comm _ZN14__interception11real_setjmpE,8,8
    166 .globl setjmp
    167 .type setjmp, @function
    168 setjmp:
    169   CFI_STARTPROC
    170   // save env parameter
    171   push %rdi
    172   CFI_ADJUST_CFA_OFFSET(8)
    173   CFI_REL_OFFSET(%rdi, 0)
    174   // obtain %rsp
    175 #if defined(__FreeBSD__)
    176   lea 8(%rsp), %rdi
    177   mov %rdi, %rsi
    178 #else
    179   lea 16(%rsp), %rdi
    180   mov %rdi, %rsi
    181   xor %fs:0x30, %rsi  // magic mangling of rsp (see libc setjmp)
    182   rol $0x11, %rsi
    183 #endif
    184   // call tsan interceptor
    185   call __tsan_setjmp
    186   // restore env parameter
    187   pop %rdi
    188   CFI_ADJUST_CFA_OFFSET(-8)
    189   CFI_RESTORE(%rdi)
    190   // tail jump to libc setjmp
    191   movl $0, %eax
    192   movq _ZN14__interception11real_setjmpE@GOTPCREL(%rip), %rdx
    193   jmp *(%rdx)
    194   CFI_ENDPROC
    195 .size setjmp, .-setjmp
    196 
    197 .comm _ZN14__interception12real__setjmpE,8,8
    198 .globl _setjmp
    199 .type _setjmp, @function
    200 _setjmp:
    201   CFI_STARTPROC
    202   // save env parameter
    203   push %rdi
    204   CFI_ADJUST_CFA_OFFSET(8)
    205   CFI_REL_OFFSET(%rdi, 0)
    206   // obtain %rsp
    207 #if defined(__FreeBSD__)
    208   lea 8(%rsp), %rdi
    209   mov %rdi, %rsi
    210 #else
    211   lea 16(%rsp), %rdi
    212   mov %rdi, %rsi
    213   xor %fs:0x30, %rsi  // magic mangling of rsp (see libc setjmp)
    214   rol $0x11, %rsi
    215 #endif
    216   // call tsan interceptor
    217   call __tsan_setjmp
    218   // restore env parameter
    219   pop %rdi
    220   CFI_ADJUST_CFA_OFFSET(-8)
    221   CFI_RESTORE(%rdi)
    222   // tail jump to libc setjmp
    223   movl $0, %eax
    224   movq _ZN14__interception12real__setjmpE@GOTPCREL(%rip), %rdx
    225   jmp *(%rdx)
    226   CFI_ENDPROC
    227 .size _setjmp, .-_setjmp
    228 
    229 .comm _ZN14__interception14real_sigsetjmpE,8,8
    230 .globl sigsetjmp
    231 .type sigsetjmp, @function
    232 sigsetjmp:
    233   CFI_STARTPROC
    234   // save env parameter
    235   push %rdi
    236   CFI_ADJUST_CFA_OFFSET(8)
    237   CFI_REL_OFFSET(%rdi, 0)
    238   // save savesigs parameter
    239   push %rsi
    240   CFI_ADJUST_CFA_OFFSET(8)
    241   CFI_REL_OFFSET(%rsi, 0)
    242   // align stack frame
    243   sub $8, %rsp
    244   CFI_ADJUST_CFA_OFFSET(8)
    245   // obtain %rsp
    246 #if defined(__FreeBSD__)
    247   lea 24(%rsp), %rdi
    248   mov %rdi, %rsi
    249 #else
    250   lea 32(%rsp), %rdi
    251   mov %rdi, %rsi
    252   xor %fs:0x30, %rsi  // magic mangling of rsp (see libc setjmp)
    253   rol $0x11, %rsi
    254 #endif
    255   // call tsan interceptor
    256   call __tsan_setjmp
    257   // unalign stack frame
    258   add $8, %rsp
    259   CFI_ADJUST_CFA_OFFSET(-8)
    260   // restore savesigs parameter
    261   pop %rsi
    262   CFI_ADJUST_CFA_OFFSET(-8)
    263   CFI_RESTORE(%rsi)
    264   // restore env parameter
    265   pop %rdi
    266   CFI_ADJUST_CFA_OFFSET(-8)
    267   CFI_RESTORE(%rdi)
    268   // tail jump to libc sigsetjmp
    269   movl $0, %eax
    270   movq _ZN14__interception14real_sigsetjmpE@GOTPCREL(%rip), %rdx
    271   jmp *(%rdx)
    272   CFI_ENDPROC
    273 .size sigsetjmp, .-sigsetjmp
    274 
    275 .comm _ZN14__interception16real___sigsetjmpE,8,8
    276 .globl __sigsetjmp
    277 .type __sigsetjmp, @function
    278 __sigsetjmp:
    279   CFI_STARTPROC
    280   // save env parameter
    281   push %rdi
    282   CFI_ADJUST_CFA_OFFSET(8)
    283   CFI_REL_OFFSET(%rdi, 0)
    284   // save savesigs parameter
    285   push %rsi
    286   CFI_ADJUST_CFA_OFFSET(8)
    287   CFI_REL_OFFSET(%rsi, 0)
    288   // align stack frame
    289   sub $8, %rsp
    290   CFI_ADJUST_CFA_OFFSET(8)
    291   // obtain %rsp
    292 #if defined(__FreeBSD__)
    293   lea 24(%rsp), %rdi
    294   mov %rdi, %rsi
    295 #else
    296   lea 32(%rsp), %rdi
    297   mov %rdi, %rsi
    298   xor %fs:0x30, %rsi  // magic mangling of rsp (see libc setjmp)
    299   rol $0x11, %rsi
    300 #endif
    301   // call tsan interceptor
    302   call __tsan_setjmp
    303   // unalign stack frame
    304   add $8, %rsp
    305   CFI_ADJUST_CFA_OFFSET(-8)
    306   // restore savesigs parameter
    307   pop %rsi
    308   CFI_ADJUST_CFA_OFFSET(-8)
    309   CFI_RESTORE(%rsi)
    310   // restore env parameter
    311   pop %rdi
    312   CFI_ADJUST_CFA_OFFSET(-8)
    313   CFI_RESTORE(%rdi)
    314   // tail jump to libc sigsetjmp
    315   movl $0, %eax
    316   movq _ZN14__interception16real___sigsetjmpE@GOTPCREL(%rip), %rdx
    317   jmp *(%rdx)
    318   CFI_ENDPROC
    319 .size __sigsetjmp, .-__sigsetjmp
    320 
    321 #if defined(__FreeBSD__) || defined(__linux__)
    322 /* We do not need executable stack.  */
    323 .section        .note.GNU-stack,"",@progbits
    324 #endif
    325