| 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) |
| 29 |
TEXT 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) |
| 39 |
TEXT 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) |
| 49 |
TEXT 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) |
| 57 |
TEXT 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) |
| 65 |
TEXT 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 |
// func runtime·lsanregisterrootregion(addr unsafe.Pointer, n uintptr) |
| 73 |
TEXT runtime·lsanregisterrootregion(SB), NOSPLIT, $0-16 |
| 74 |
MOVQ addr+0(FP), RARG0 |
| 75 |
MOVQ n+8(FP), RARG1 |
| 76 |
// void __lsan_register_root_region_go(void *addr, uintptr_t sz) |
| 77 |
MOVQ $__lsan_register_root_region_go(SB), AX |
| 78 |
JMP asancall<>(SB) |
| 79 |
|
| 80 |
// func runtime·lsanunregisterrootregion(addr unsafe.Pointer, n uintptr) |
| 81 |
TEXT runtime·lsanunregisterrootregion(SB), NOSPLIT, $0-16 |
| 82 |
MOVQ addr+0(FP), RARG0 |
| 83 |
MOVQ n+8(FP), RARG1 |
| 84 |
// void __lsan_unregister_root_region_go(void *addr, uintptr_t sz) |
| 85 |
MOVQ $__lsan_unregister_root_region_go(SB), AX |
| 86 |
JMP asancall<>(SB) |
| 87 |
|
| 88 |
// func runtime·lsandoleakcheck() |
| 89 |
TEXT runtime·lsandoleakcheck(SB), NOSPLIT, $0-0 |
| 90 |
// void __lsan_do_leak_check_go(void); |
| 91 |
MOVQ $__lsan_do_leak_check_go(SB), AX |
| 92 |
JMP asancall<>(SB) |
| 93 |
|
| 94 |
// Switches SP to g0 stack and calls (AX). Arguments already set. |
| 95 |
TEXT asancall<>(SB), NOSPLIT, $0-0 |
| 96 |
get_tls(R12) |
| 97 |
MOVQ g(R12), R14 |
| 98 |
MOVQ SP, R12 // callee-saved, preserved across the CALL |
| 99 |
CMPQ R14, $0 |
| 100 |
JE call // no g; still on a system stack |
| 101 |
|
| 102 |
MOVQ g_m(R14), R13 |
| 103 |
|
| 104 |
// Switch to g0 stack if we aren't already on g0 or gsignal. |
| 105 |
MOVQ m_gsignal(R13), R10 |
| 106 |
CMPQ R10, R14 |
| 107 |
JE call // already on gsignal |
| 108 |
|
| 109 |
MOVQ m_g0(R13), R10 |
| 110 |
CMPQ R10, R14 |
| 111 |
JE call // already on g0 |
| 112 |
|
| 113 |
MOVQ (g_sched+gobuf_sp)(R10), SP |
| 114 |
call: |
| 115 |
ANDQ $~15, SP // alignment for gcc ABI |
| 116 |
CALL AX |
| 117 |
MOVQ R12, SP |
| 118 |
RET |