10b57cec5SDimitry Andric// The content of this file is x86_64-only: 20b57cec5SDimitry Andric#if defined(__x86_64__) 30b57cec5SDimitry Andric 40b57cec5SDimitry Andric#include "sanitizer_common/sanitizer_asm.h" 50b57cec5SDimitry Andric 60b57cec5SDimitry Andric#if !defined(__APPLE__) 70b57cec5SDimitry Andric.section .text 80b57cec5SDimitry Andric#else 90b57cec5SDimitry Andric.section __TEXT,__text 100b57cec5SDimitry Andric#endif 110b57cec5SDimitry Andric 120b57cec5SDimitry AndricASM_HIDDEN(__tsan_setjmp) 130b57cec5SDimitry Andric#if defined(__NetBSD__) 140b57cec5SDimitry Andric.comm _ZN14__interception15real___setjmp14E,8,8 150b57cec5SDimitry Andric#elif !defined(__APPLE__) 160b57cec5SDimitry Andric.comm _ZN14__interception11real_setjmpE,8,8 170b57cec5SDimitry Andric#endif 180b57cec5SDimitry Andric#if defined(__NetBSD__) 190b57cec5SDimitry Andric.globl ASM_SYMBOL_INTERCEPTOR(__setjmp14) 200b57cec5SDimitry AndricASM_TYPE_FUNCTION(ASM_SYMBOL_INTERCEPTOR(__setjmp14)) 210b57cec5SDimitry AndricASM_SYMBOL_INTERCEPTOR(__setjmp14): 220b57cec5SDimitry Andric#else 230b57cec5SDimitry Andric.globl ASM_SYMBOL_INTERCEPTOR(setjmp) 240b57cec5SDimitry AndricASM_TYPE_FUNCTION(ASM_SYMBOL_INTERCEPTOR(setjmp)) 250b57cec5SDimitry AndricASM_SYMBOL_INTERCEPTOR(setjmp): 260b57cec5SDimitry Andric#endif 270b57cec5SDimitry Andric CFI_STARTPROC 28*349cc55cSDimitry Andric _CET_ENDBR 290b57cec5SDimitry Andric // save env parameter 300b57cec5SDimitry Andric push %rdi 310b57cec5SDimitry Andric CFI_ADJUST_CFA_OFFSET(8) 320b57cec5SDimitry Andric CFI_REL_OFFSET(%rdi, 0) 330b57cec5SDimitry Andric // obtain SP, store in %rdi, first argument to `void __tsan_setjmp(uptr sp)` 340b57cec5SDimitry Andric#if defined(__FreeBSD__) || defined(__NetBSD__) 350b57cec5SDimitry Andric lea 8(%rsp), %rdi 360b57cec5SDimitry Andric#elif defined(__linux__) || defined(__APPLE__) 370b57cec5SDimitry Andric lea 16(%rsp), %rdi 380b57cec5SDimitry Andric#else 390b57cec5SDimitry Andric# error "Unknown platform" 400b57cec5SDimitry Andric#endif 410b57cec5SDimitry Andric // call tsan interceptor 420b57cec5SDimitry Andric call ASM_SYMBOL(__tsan_setjmp) 430b57cec5SDimitry Andric // restore env parameter 440b57cec5SDimitry Andric pop %rdi 450b57cec5SDimitry Andric CFI_ADJUST_CFA_OFFSET(-8) 460b57cec5SDimitry Andric CFI_RESTORE(%rdi) 470b57cec5SDimitry Andric // tail jump to libc setjmp 480b57cec5SDimitry Andric movl $0, %eax 490b57cec5SDimitry Andric#if defined(__NetBSD__) 500b57cec5SDimitry Andric movq _ZN14__interception15real___setjmp14E@GOTPCREL(%rip), %rdx 510b57cec5SDimitry Andric jmp *(%rdx) 520b57cec5SDimitry Andric#elif !defined(__APPLE__) 530b57cec5SDimitry Andric movq _ZN14__interception11real_setjmpE@GOTPCREL(%rip), %rdx 540b57cec5SDimitry Andric jmp *(%rdx) 550b57cec5SDimitry Andric#else 560b57cec5SDimitry Andric jmp ASM_SYMBOL(setjmp) 570b57cec5SDimitry Andric#endif 580b57cec5SDimitry Andric CFI_ENDPROC 590b57cec5SDimitry Andric#if defined(__NetBSD__) 600b57cec5SDimitry AndricASM_SIZE(ASM_SYMBOL_INTERCEPTOR(__setjmp14)) 610b57cec5SDimitry Andric#else 620b57cec5SDimitry AndricASM_SIZE(ASM_SYMBOL_INTERCEPTOR(setjmp)) 630b57cec5SDimitry Andric#endif 640b57cec5SDimitry Andric 650b57cec5SDimitry Andric.comm _ZN14__interception12real__setjmpE,8,8 660b57cec5SDimitry Andric.globl ASM_SYMBOL_INTERCEPTOR(_setjmp) 670b57cec5SDimitry AndricASM_TYPE_FUNCTION(ASM_SYMBOL_INTERCEPTOR(_setjmp)) 680b57cec5SDimitry AndricASM_SYMBOL_INTERCEPTOR(_setjmp): 690b57cec5SDimitry Andric CFI_STARTPROC 70*349cc55cSDimitry Andric _CET_ENDBR 710b57cec5SDimitry Andric // save env parameter 720b57cec5SDimitry Andric push %rdi 730b57cec5SDimitry Andric CFI_ADJUST_CFA_OFFSET(8) 740b57cec5SDimitry Andric CFI_REL_OFFSET(%rdi, 0) 750b57cec5SDimitry Andric // obtain SP, store in %rdi, first argument to `void __tsan_setjmp(uptr sp)` 760b57cec5SDimitry Andric#if defined(__FreeBSD__) || defined(__NetBSD__) 770b57cec5SDimitry Andric lea 8(%rsp), %rdi 780b57cec5SDimitry Andric#elif defined(__linux__) || defined(__APPLE__) 790b57cec5SDimitry Andric lea 16(%rsp), %rdi 800b57cec5SDimitry Andric#else 810b57cec5SDimitry Andric# error "Unknown platform" 820b57cec5SDimitry Andric#endif 830b57cec5SDimitry Andric // call tsan interceptor 840b57cec5SDimitry Andric call ASM_SYMBOL(__tsan_setjmp) 850b57cec5SDimitry Andric // restore env parameter 860b57cec5SDimitry Andric pop %rdi 870b57cec5SDimitry Andric CFI_ADJUST_CFA_OFFSET(-8) 880b57cec5SDimitry Andric CFI_RESTORE(%rdi) 890b57cec5SDimitry Andric // tail jump to libc setjmp 900b57cec5SDimitry Andric movl $0, %eax 910b57cec5SDimitry Andric#if !defined(__APPLE__) 920b57cec5SDimitry Andric movq _ZN14__interception12real__setjmpE@GOTPCREL(%rip), %rdx 930b57cec5SDimitry Andric jmp *(%rdx) 940b57cec5SDimitry Andric#else 950b57cec5SDimitry Andric jmp ASM_SYMBOL(_setjmp) 960b57cec5SDimitry Andric#endif 970b57cec5SDimitry Andric CFI_ENDPROC 980b57cec5SDimitry AndricASM_SIZE(ASM_SYMBOL_INTERCEPTOR(_setjmp)) 990b57cec5SDimitry Andric 1000b57cec5SDimitry Andric#if defined(__NetBSD__) 1010b57cec5SDimitry Andric.comm _ZN14__interception18real___sigsetjmp14E,8,8 1020b57cec5SDimitry Andric.globl ASM_SYMBOL_INTERCEPTOR(__sigsetjmp14) 1030b57cec5SDimitry AndricASM_TYPE_FUNCTION(ASM_SYMBOL_INTERCEPTOR(__sigsetjmp14)) 1040b57cec5SDimitry AndricASM_SYMBOL_INTERCEPTOR(__sigsetjmp14): 1050b57cec5SDimitry Andric#else 1060b57cec5SDimitry Andric.comm _ZN14__interception14real_sigsetjmpE,8,8 1070b57cec5SDimitry Andric.globl ASM_SYMBOL_INTERCEPTOR(sigsetjmp) 1080b57cec5SDimitry AndricASM_TYPE_FUNCTION(ASM_SYMBOL_INTERCEPTOR(sigsetjmp)) 1090b57cec5SDimitry AndricASM_SYMBOL_INTERCEPTOR(sigsetjmp): 1100b57cec5SDimitry Andric#endif 1110b57cec5SDimitry Andric CFI_STARTPROC 112*349cc55cSDimitry Andric _CET_ENDBR 1130b57cec5SDimitry Andric // save env parameter 1140b57cec5SDimitry Andric push %rdi 1150b57cec5SDimitry Andric CFI_ADJUST_CFA_OFFSET(8) 1160b57cec5SDimitry Andric CFI_REL_OFFSET(%rdi, 0) 1170b57cec5SDimitry Andric // save savesigs parameter 1180b57cec5SDimitry Andric push %rsi 1190b57cec5SDimitry Andric CFI_ADJUST_CFA_OFFSET(8) 1200b57cec5SDimitry Andric CFI_REL_OFFSET(%rsi, 0) 1210b57cec5SDimitry Andric // align stack frame 1220b57cec5SDimitry Andric sub $8, %rsp 1230b57cec5SDimitry Andric CFI_ADJUST_CFA_OFFSET(8) 1240b57cec5SDimitry Andric // obtain SP, store in %rdi, first argument to `void __tsan_setjmp(uptr sp)` 1250b57cec5SDimitry Andric#if defined(__FreeBSD__) || defined(__NetBSD__) 1260b57cec5SDimitry Andric lea 24(%rsp), %rdi 1270b57cec5SDimitry Andric#elif defined(__linux__) || defined(__APPLE__) 1280b57cec5SDimitry Andric lea 32(%rsp), %rdi 1290b57cec5SDimitry Andric#else 1300b57cec5SDimitry Andric# error "Unknown platform" 1310b57cec5SDimitry Andric#endif 1320b57cec5SDimitry Andric // call tsan interceptor 1330b57cec5SDimitry Andric call ASM_SYMBOL(__tsan_setjmp) 1340b57cec5SDimitry Andric // unalign stack frame 1350b57cec5SDimitry Andric add $8, %rsp 1360b57cec5SDimitry Andric CFI_ADJUST_CFA_OFFSET(-8) 1370b57cec5SDimitry Andric // restore savesigs parameter 1380b57cec5SDimitry Andric pop %rsi 1390b57cec5SDimitry Andric CFI_ADJUST_CFA_OFFSET(-8) 1400b57cec5SDimitry Andric CFI_RESTORE(%rsi) 1410b57cec5SDimitry Andric // restore env parameter 1420b57cec5SDimitry Andric pop %rdi 1430b57cec5SDimitry Andric CFI_ADJUST_CFA_OFFSET(-8) 1440b57cec5SDimitry Andric CFI_RESTORE(%rdi) 1450b57cec5SDimitry Andric // tail jump to libc sigsetjmp 1460b57cec5SDimitry Andric movl $0, %eax 1470b57cec5SDimitry Andric#if defined(__NetBSD__) 1480b57cec5SDimitry Andric movq _ZN14__interception18real___sigsetjmp14E@GOTPCREL(%rip), %rdx 1490b57cec5SDimitry Andric jmp *(%rdx) 1500b57cec5SDimitry Andric#elif !defined(__APPLE__) 1510b57cec5SDimitry Andric movq _ZN14__interception14real_sigsetjmpE@GOTPCREL(%rip), %rdx 1520b57cec5SDimitry Andric jmp *(%rdx) 1530b57cec5SDimitry Andric#else 1540b57cec5SDimitry Andric jmp ASM_SYMBOL(sigsetjmp) 1550b57cec5SDimitry Andric#endif 1560b57cec5SDimitry Andric CFI_ENDPROC 1570b57cec5SDimitry Andric#if defined(__NetBSD__) 1580b57cec5SDimitry AndricASM_SIZE(ASM_SYMBOL_INTERCEPTOR(__sigsetjmp14)) 1590b57cec5SDimitry Andric#else 1600b57cec5SDimitry AndricASM_SIZE(ASM_SYMBOL_INTERCEPTOR(sigsetjmp)) 1610b57cec5SDimitry Andric#endif 1620b57cec5SDimitry Andric 1630b57cec5SDimitry Andric#if !defined(__APPLE__) && !defined(__NetBSD__) 1640b57cec5SDimitry Andric.comm _ZN14__interception16real___sigsetjmpE,8,8 1650b57cec5SDimitry Andric.globl ASM_SYMBOL_INTERCEPTOR(__sigsetjmp) 1660b57cec5SDimitry AndricASM_TYPE_FUNCTION(ASM_SYMBOL_INTERCEPTOR(__sigsetjmp)) 1670b57cec5SDimitry AndricASM_SYMBOL_INTERCEPTOR(__sigsetjmp): 1680b57cec5SDimitry Andric CFI_STARTPROC 169*349cc55cSDimitry Andric _CET_ENDBR 1700b57cec5SDimitry Andric // save env parameter 1710b57cec5SDimitry Andric push %rdi 1720b57cec5SDimitry Andric CFI_ADJUST_CFA_OFFSET(8) 1730b57cec5SDimitry Andric CFI_REL_OFFSET(%rdi, 0) 1740b57cec5SDimitry Andric // save savesigs parameter 1750b57cec5SDimitry Andric push %rsi 1760b57cec5SDimitry Andric CFI_ADJUST_CFA_OFFSET(8) 1770b57cec5SDimitry Andric CFI_REL_OFFSET(%rsi, 0) 1780b57cec5SDimitry Andric // align stack frame 1790b57cec5SDimitry Andric sub $8, %rsp 1800b57cec5SDimitry Andric CFI_ADJUST_CFA_OFFSET(8) 1810b57cec5SDimitry Andric // obtain SP, store in %rdi, first argument to `void __tsan_setjmp(uptr sp)` 1820b57cec5SDimitry Andric#if defined(__FreeBSD__) 1830b57cec5SDimitry Andric lea 24(%rsp), %rdi 1840b57cec5SDimitry Andric#else 1850b57cec5SDimitry Andric lea 32(%rsp), %rdi 1860b57cec5SDimitry Andric#endif 1870b57cec5SDimitry Andric // call tsan interceptor 1880b57cec5SDimitry Andric call ASM_SYMBOL(__tsan_setjmp) 1890b57cec5SDimitry Andric // unalign stack frame 1900b57cec5SDimitry Andric add $8, %rsp 1910b57cec5SDimitry Andric CFI_ADJUST_CFA_OFFSET(-8) 1920b57cec5SDimitry Andric // restore savesigs parameter 1930b57cec5SDimitry Andric pop %rsi 1940b57cec5SDimitry Andric CFI_ADJUST_CFA_OFFSET(-8) 1950b57cec5SDimitry Andric CFI_RESTORE(%rsi) 1960b57cec5SDimitry Andric // restore env parameter 1970b57cec5SDimitry Andric pop %rdi 1980b57cec5SDimitry Andric CFI_ADJUST_CFA_OFFSET(-8) 1990b57cec5SDimitry Andric CFI_RESTORE(%rdi) 2000b57cec5SDimitry Andric // tail jump to libc sigsetjmp 2010b57cec5SDimitry Andric movl $0, %eax 2020b57cec5SDimitry Andric movq _ZN14__interception16real___sigsetjmpE@GOTPCREL(%rip), %rdx 2030b57cec5SDimitry Andric jmp *(%rdx) 2040b57cec5SDimitry Andric CFI_ENDPROC 2050b57cec5SDimitry AndricASM_SIZE(ASM_SYMBOL_INTERCEPTOR(__sigsetjmp)) 2060b57cec5SDimitry Andric#endif // !defined(__APPLE__) && !defined(__NetBSD__) 2070b57cec5SDimitry Andric 2080b57cec5SDimitry AndricNO_EXEC_STACK_DIRECTIVE 2090b57cec5SDimitry Andric 2100b57cec5SDimitry Andric#endif 211