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): ;\
43 jl RLABEL(reg, op, 1, i);\
45 jmp __asan_report_##op##1_asm ;\
47 #define ASAN_MEMORY_ACCESS_EXTRA_CHECK_2(reg, op, i) \
48 CLABEL(reg, op, 2, i): ;\
55 jl RLABEL(reg, op, 2, i);\
57 jmp __asan_report_##op##2_asm ;\
59 #define ASAN_MEMORY_ACCESS_EXTRA_CHECK_4(reg, op, i) \
60 CLABEL(reg, op, 4, i): ;\
67 jl RLABEL(reg, op, 4, i);\
69 jmp __asan_report_##op##4_asm ;\
71 #define ASAN_MEMORY_ACCESS_CALLBACK_ADD_1(reg, op) \
72 BEGINF(reg, op, 1, add) ;\
73 ASAN_MEMORY_ACCESS_INITIAL_CHECK_ADD(reg, op, 1) ;\
74 ASAN_MEMORY_ACCESS_EXTRA_CHECK_1(reg, op, add) ;\
77 #define ASAN_MEMORY_ACCESS_CALLBACK_ADD_2(reg, op) \
78 BEGINF(reg, op, 2, add) ;\
79 ASAN_MEMORY_ACCESS_INITIAL_CHECK_ADD(reg, op, 2) ;\
80 ASAN_MEMORY_ACCESS_EXTRA_CHECK_2(reg, op, add) ;\
83 #define ASAN_MEMORY_ACCESS_CALLBACK_ADD_4(reg, op) \
84 BEGINF(reg, op, 4, add) ;\
85 ASAN_MEMORY_ACCESS_INITIAL_CHECK_ADD(reg, op, 4) ;\
86 ASAN_MEMORY_ACCESS_EXTRA_CHECK_4(reg, op, add) ;\
89 // Access check functions for 8 and 16 byte types: no extra checks required.
90 #define ASAN_MEMORY_ACCESS_CHECK_ADD(reg, op, s, c) \
93 ##c $0x0,ASAN_SHADOW_OFFSET_CONST(%r10) ;\
94 jne FLABEL(reg, op, s, add) ;\
97 #define ASAN_MEMORY_ACCESS_FAIL(reg, op, s, i) \
98 FLABEL(reg, op, s, i): ;\
100 jmp __asan_report_##op##s##_asm;\
102 #define ASAN_MEMORY_ACCESS_CALLBACK_ADD_8(reg, op) \
103 BEGINF(reg, op, 8, add) ;\
104 ASAN_MEMORY_ACCESS_CHECK_ADD(reg, op, 8, cmpb) ;\
105 ASAN_MEMORY_ACCESS_FAIL(reg, op, 8, add) ;\
108 #define ASAN_MEMORY_ACCESS_CALLBACK_ADD_16(reg, op) \
109 BEGINF(reg, op, 16, add) ;\
110 ASAN_MEMORY_ACCESS_CHECK_ADD(reg, op, 16, cmpw) ;\
111 ASAN_MEMORY_ACCESS_FAIL(reg, op, 16, add) ;\
114 #define ASAN_MEMORY_ACCESS_CALLBACKS_ADD(reg) \
115 ASAN_MEMORY_ACCESS_CALLBACK_ADD_1(reg, load) \
116 ASAN_MEMORY_ACCESS_CALLBACK_ADD_1(reg, store) \
117 ASAN_MEMORY_ACCESS_CALLBACK_ADD_2(reg, load) \
118 ASAN_MEMORY_ACCESS_CALLBACK_ADD_2(reg, store) \
119 ASAN_MEMORY_ACCESS_CALLBACK_ADD_4(reg, load) \
120 ASAN_MEMORY_ACCESS_CALLBACK_ADD_4(reg, store) \
121 ASAN_MEMORY_ACCESS_CALLBACK_ADD_8(reg, load) \
122 ASAN_MEMORY_ACCESS_CALLBACK_ADD_8(reg, store) \
123 ASAN_MEMORY_ACCESS_CALLBACK_ADD_16(reg, load) \
124 ASAN_MEMORY_ACCESS_CALLBACK_ADD_16(reg, store) \
127 // Instantiate all but R10 and R11 callbacks. We are using PLTSafe class with
128 // the intrinsic, which guarantees that the code generation will never emit
129 // R10 or R11 callback.
130 ASAN_MEMORY_ACCESS_CALLBACKS_ADD(RAX)
131 ASAN_MEMORY_ACCESS_CALLBACKS_ADD(RBX)
132 ASAN_MEMORY_ACCESS_CALLBACKS_ADD(RCX)
133 ASAN_MEMORY_ACCESS_CALLBACKS_ADD(RDX)
134 ASAN_MEMORY_ACCESS_CALLBACKS_ADD(RSI)
135 ASAN_MEMORY_ACCESS_CALLBACKS_ADD(RDI)
136 ASAN_MEMORY_ACCESS_CALLBACKS_ADD(RBP)
137 ASAN_MEMORY_ACCESS_CALLBACKS_ADD(R8)
138 ASAN_MEMORY_ACCESS_CALLBACKS_ADD(R9)
139 ASAN_MEMORY_ACCESS_CALLBACKS_ADD(R12)
140 ASAN_MEMORY_ACCESS_CALLBACKS_ADD(R13)
141 ASAN_MEMORY_ACCESS_CALLBACKS_ADD(R14)
142 ASAN_MEMORY_ACCESS_CALLBACKS_ADD(R15)
146 NO_EXEC_STACK_DIRECTIVE