Text file
src/runtime/asan_amd64.s
1 // Copyright 2021 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
4
5 //go:build asan
6
7 #include "go_asm.h"
8 #include "go_tls.h"
9 #include "funcdata.h"
10 #include "textflag.h"
11
12 // This is like race_amd64.s, but for the asan calls.
13 // See race_amd64.s for detailed comments.
14
15 #ifdef GOOS_windows
16 #define RARG0 CX
17 #define RARG1 DX
18 #define RARG2 R8
19 #define RARG3 R9
20 #else
21 #define RARG0 DI
22 #define RARG1 SI
23 #define RARG2 DX
24 #define RARG3 CX
25 #endif
26
27 // Called from intrumented code.
28 // func runtime·doasanread(addr unsafe.Pointer, sz, sp, pc uintptr)
29 TEXT runtime·doasanread(SB), NOSPLIT, $0-32
30 MOVQ addr+0(FP), RARG0
31 MOVQ size+8(FP), RARG1
32 MOVQ sp+16(FP), RARG2
33 MOVQ pc+24(FP), RARG3
34 // void __asan_read_go(void *addr, uintptr_t sz, void *sp, void *pc);
35 MOVQ $__asan_read_go(SB), AX
36 JMP asancall<>(SB)
37
38 // func runtime·doasanwrite(addr unsafe.Pointer, sz, sp, pc uintptr)
39 TEXT runtime·doasanwrite(SB), NOSPLIT, $0-32
40 MOVQ addr+0(FP), RARG0
41 MOVQ size+8(FP), RARG1
42 MOVQ sp+16(FP), RARG2
43 MOVQ pc+24(FP), RARG3
44 // void __asan_write_go(void *addr, uintptr_t sz, void *sp, void *pc);
45 MOVQ $__asan_write_go(SB), AX
46 JMP asancall<>(SB)
47
48 // func runtime·asanunpoison(addr unsafe.Pointer, sz uintptr)
49 TEXT runtime·asanunpoison(SB), NOSPLIT, $0-16
50 MOVQ addr+0(FP), RARG0
51 MOVQ size+8(FP), RARG1
52 // void __asan_unpoison_go(void *addr, uintptr_t sz);
53 MOVQ $__asan_unpoison_go(SB), AX
54 JMP asancall<>(SB)
55
56 // func runtime·asanpoison(addr unsafe.Pointer, sz uintptr)
57 TEXT runtime·asanpoison(SB), NOSPLIT, $0-16
58 MOVQ addr+0(FP), RARG0
59 MOVQ size+8(FP), RARG1
60 // void __asan_poison_go(void *addr, uintptr_t sz);
61 MOVQ $__asan_poison_go(SB), AX
62 JMP asancall<>(SB)
63
64 // Switches SP to g0 stack and calls (AX). Arguments already set.
65 TEXT asancall<>(SB), NOSPLIT, $0-0
66 get_tls(R12)
67 MOVQ g(R12), R14
68 MOVQ SP, R12 // callee-saved, preserved across the CALL
69 CMPQ R14, $0
70 JE call // no g; still on a system stack
71
72 MOVQ g_m(R14), R13
73 // Switch to g0 stack.
74 MOVQ m_g0(R13), R10
75 CMPQ R10, R14
76 JE call // already on g0
77
78 MOVQ (g_sched+gobuf_sp)(R10), SP
79 call:
80 ANDQ $~15, SP // alignment for gcc ABI
81 CALL AX
82 MOVQ R12, SP
83 RET
84
View as plain text