1 #include "asan_mapping.h"
2 #include "sanitizer_common/sanitizer_asm.h"
4 #if defined(__x86_64__)
5 #include "sanitizer_common/sanitizer_platform.h"
7 .file "asan_rtl_x86_64.S"
9 #define NAME(n, reg, op, s, i) n##_##op##_##i##_##s##_##reg
11 #define FNAME(reg, op, s, i) NAME(__asan_check, reg, op, s, i)
12 #define RLABEL(reg, op, s, i) NAME(.return, reg, op, s, i)
13 #define CLABEL(reg, op, s, i) NAME(.check, reg, op, s, i)
14 #define FLABEL(reg, op, s, i) NAME(.fail, reg, op, s, i)
16 #define BEGINF(reg, op, s, i) \
17 .section .text.FNAME(reg, op, s, i),"ax",@progbits ;\
18 .globl FNAME(reg, op, s, i) ;\
19 .hidden FNAME(reg, op, s, i) ;\
20 ASM_TYPE_FUNCTION(FNAME(reg, op, s, i)) ;\
22 FNAME(reg, op, s, i): ;\
24 #define ENDF .cfi_endproc ;\
26 // Access check functions for 1,2 and 4 byte types, which require extra checks.
27 #define ASAN_MEMORY_ACCESS_INITIAL_CHECK_ADD(reg, op, s) \
30 movsbl ASAN_SHADOW_OFFSET_CONST(%r10),%r10d ;\
32 jne CLABEL(reg, op, s, add) ;\
33 RLABEL(reg, op, s, add): ;\
36 #define ASAN_MEMORY_ACCESS_EXTRA_CHECK_1(reg, op, i) \
37 CLABEL(reg, op, 1, i): ;\
41 jl RLABEL(reg, op, 1, i);\
43 jmp __asan_report_##op##1_asm ;\
45 #define ASAN_MEMORY_ACCESS_EXTRA_CHECK_2(reg, op, i) \
46 CLABEL(reg, op, 2, i): ;\
51 jl RLABEL(reg, op, 2, i);\
53 jmp __asan_report_##op##2_asm ;\
55 #define ASAN_MEMORY_ACCESS_EXTRA_CHECK_4(reg, op, i) \
56 CLABEL(reg, op, 4, i): ;\
61 jl RLABEL(reg, op, 4, i);\
63 jmp __asan_report_##op##4_asm ;\
65 #define ASAN_MEMORY_ACCESS_CALLBACK_ADD_1(reg, op) \
66 BEGINF(reg, op, 1, add) ;\
67 ASAN_MEMORY_ACCESS_INITIAL_CHECK_ADD(reg, op, 1) ;\
68 ASAN_MEMORY_ACCESS_EXTRA_CHECK_1(reg, op, add) ;\
71 #define ASAN_MEMORY_ACCESS_CALLBACK_ADD_2(reg, op) \
72 BEGINF(reg, op, 2, add) ;\
73 ASAN_MEMORY_ACCESS_INITIAL_CHECK_ADD(reg, op, 2) ;\
74 ASAN_MEMORY_ACCESS_EXTRA_CHECK_2(reg, op, add) ;\
77 #define ASAN_MEMORY_ACCESS_CALLBACK_ADD_4(reg, op) \
78 BEGINF(reg, op, 4, add) ;\
79 ASAN_MEMORY_ACCESS_INITIAL_CHECK_ADD(reg, op, 4) ;\
80 ASAN_MEMORY_ACCESS_EXTRA_CHECK_4(reg, op, add) ;\
83 // Access check functions for 8 and 16 byte types: no extra checks required.
84 #define ASAN_MEMORY_ACCESS_CHECK_ADD(reg, op, s, c) \
87 ##c $0x0,ASAN_SHADOW_OFFSET_CONST(%r10) ;\
88 jne FLABEL(reg, op, s, add) ;\
91 #define ASAN_MEMORY_ACCESS_FAIL(reg, op, s, i) \
92 FLABEL(reg, op, s, i): ;\
94 jmp __asan_report_##op##s##_asm;\
96 #define ASAN_MEMORY_ACCESS_CALLBACK_ADD_8(reg, op) \
97 BEGINF(reg, op, 8, add) ;\
98 ASAN_MEMORY_ACCESS_CHECK_ADD(reg, op, 8, cmpb) ;\
99 ASAN_MEMORY_ACCESS_FAIL(reg, op, 8, add) ;\
102 #define ASAN_MEMORY_ACCESS_CALLBACK_ADD_16(reg, op) \
103 BEGINF(reg, op, 16, add) ;\
104 ASAN_MEMORY_ACCESS_CHECK_ADD(reg, op, 16, cmpw) ;\
105 ASAN_MEMORY_ACCESS_FAIL(reg, op, 16, add) ;\
108 #define ASAN_MEMORY_ACCESS_CALLBACKS_ADD(reg) \
109 ASAN_MEMORY_ACCESS_CALLBACK_ADD_1(reg, load) \
110 ASAN_MEMORY_ACCESS_CALLBACK_ADD_1(reg, store) \
111 ASAN_MEMORY_ACCESS_CALLBACK_ADD_2(reg, load) \
112 ASAN_MEMORY_ACCESS_CALLBACK_ADD_2(reg, store) \
113 ASAN_MEMORY_ACCESS_CALLBACK_ADD_4(reg, load) \
114 ASAN_MEMORY_ACCESS_CALLBACK_ADD_4(reg, store) \
115 ASAN_MEMORY_ACCESS_CALLBACK_ADD_8(reg, load) \
116 ASAN_MEMORY_ACCESS_CALLBACK_ADD_8(reg, store) \
117 ASAN_MEMORY_ACCESS_CALLBACK_ADD_16(reg, load) \
118 ASAN_MEMORY_ACCESS_CALLBACK_ADD_16(reg, store) \
121 // Instantiate all but R10 and R11 callbacks. We are using PLTSafe class with
122 // the intrinsic, which guarantees that the code generation will never emit
123 // R10 or R11 callback.
124 ASAN_MEMORY_ACCESS_CALLBACKS_ADD(RAX)
125 ASAN_MEMORY_ACCESS_CALLBACKS_ADD(RBX)
126 ASAN_MEMORY_ACCESS_CALLBACKS_ADD(RCX)
127 ASAN_MEMORY_ACCESS_CALLBACKS_ADD(RDX)
128 ASAN_MEMORY_ACCESS_CALLBACKS_ADD(RSI)
129 ASAN_MEMORY_ACCESS_CALLBACKS_ADD(RDI)
130 ASAN_MEMORY_ACCESS_CALLBACKS_ADD(RBP)
131 ASAN_MEMORY_ACCESS_CALLBACKS_ADD(R8)
132 ASAN_MEMORY_ACCESS_CALLBACKS_ADD(R9)
133 ASAN_MEMORY_ACCESS_CALLBACKS_ADD(R12)
134 ASAN_MEMORY_ACCESS_CALLBACKS_ADD(R13)
135 ASAN_MEMORY_ACCESS_CALLBACKS_ADD(R14)
136 ASAN_MEMORY_ACCESS_CALLBACKS_ADD(R15)
140 NO_EXEC_STACK_DIRECTIVE