Text file
src/runtime/asan_amd64.s
Documentation: runtime
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 instrumented code.
28// func runtime·doasanread(addr unsafe.Pointer, sz, sp, pc uintptr)
29TEXT runtime·doasanread(SB), NOSPLIT, $0-32
30 MOVQ addr+0(FP), RARG0
31 MOVQ sz+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)
39TEXT runtime·doasanwrite(SB), NOSPLIT, $0-32
40 MOVQ addr+0(FP), RARG0
41 MOVQ sz+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)
49TEXT runtime·asanunpoison(SB), NOSPLIT, $0-16
50 MOVQ addr+0(FP), RARG0
51 MOVQ sz+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)
57TEXT runtime·asanpoison(SB), NOSPLIT, $0-16
58 MOVQ addr+0(FP), RARG0
59 MOVQ sz+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// func runtime·asanregisterglobals(addr unsafe.Pointer, n uintptr)
65TEXT runtime·asanregisterglobals(SB), NOSPLIT, $0-16
66 MOVQ addr+0(FP), RARG0
67 MOVQ n+8(FP), RARG1
68 // void __asan_register_globals_go(void *addr, uintptr_t n);
69 MOVQ $__asan_register_globals_go(SB), AX
70 JMP asancall<>(SB)
71
72// Switches SP to g0 stack and calls (AX). Arguments already set.
73TEXT asancall<>(SB), NOSPLIT, $0-0
74 get_tls(R12)
75 MOVQ g(R12), R14
76 MOVQ SP, R12 // callee-saved, preserved across the CALL
77 CMPQ R14, $0
78 JE call // no g; still on a system stack
79
80 MOVQ g_m(R14), R13
81 // Switch to g0 stack.
82 MOVQ m_g0(R13), R10
83 CMPQ R10, R14
84 JE call // already on g0
85
86 MOVQ (g_sched+gobuf_sp)(R10), SP
87call:
88 ANDQ $~15, SP // alignment for gcc ABI
89 CALL AX
90 MOVQ R12, SP
91 RET
View as plain text