github.com/AESNooper/go/src@v0.0.0-20220218095104-b56a4ab1bbbb/runtime/asan_amd64.s (about)

     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  #else
    19  #define RARG0 DI
    20  #define RARG1 SI
    21  #endif
    22  
    23  // Called from intrumented code.
    24  // func runtime·asanread(addr unsafe.Pointer, sz uintptr)
    25  TEXT	runtime·asanread(SB), NOSPLIT, $0-16
    26  	MOVQ	addr+0(FP), RARG0
    27  	MOVQ	size+8(FP), RARG1
    28  	// void __asan_read_go(void *addr, uintptr_t sz);
    29  	MOVQ	$__asan_read_go(SB), AX
    30  	JMP	asancall<>(SB)
    31  
    32  // func runtime·asanwrite(addr unsafe.Pointer, sz uintptr)
    33  TEXT	runtime·asanwrite(SB), NOSPLIT, $0-16
    34  	MOVQ	addr+0(FP), RARG0
    35  	MOVQ	size+8(FP), RARG1
    36  	// void __asan_write_go(void *addr, uintptr_t sz);
    37  	MOVQ	$__asan_write_go(SB), AX
    38  	JMP	asancall<>(SB)
    39  
    40  // func runtime·asanunpoison(addr unsafe.Pointer, sz uintptr)
    41  TEXT	runtime·asanunpoison(SB), NOSPLIT, $0-16
    42  	MOVQ	addr+0(FP), RARG0
    43  	MOVQ	size+8(FP), RARG1
    44  	// void __asan_unpoison_go(void *addr, uintptr_t sz);
    45  	MOVQ	$__asan_unpoison_go(SB), AX
    46  	JMP	asancall<>(SB)
    47  
    48  // func runtime·asanpoison(addr unsafe.Pointer, sz uintptr)
    49  TEXT	runtime·asanpoison(SB), NOSPLIT, $0-16
    50  	MOVQ	addr+0(FP), RARG0
    51  	MOVQ	size+8(FP), RARG1
    52  	// void __asan_poison_go(void *addr, uintptr_t sz);
    53  	MOVQ	$__asan_poison_go(SB), AX
    54  	JMP	asancall<>(SB)
    55  
    56  // Switches SP to g0 stack and calls (AX). Arguments already set.
    57  TEXT	asancall<>(SB), NOSPLIT, $0-0
    58  	get_tls(R12)
    59  	MOVQ	g(R12), R14
    60  	MOVQ	SP, R12		// callee-saved, preserved across the CALL
    61  	CMPQ	R14, $0
    62  	JE	call	// no g; still on a system stack
    63  
    64  	MOVQ	g_m(R14), R13
    65  	// Switch to g0 stack.
    66  	MOVQ	m_g0(R13), R10
    67  	CMPQ	R10, R14
    68  	JE	call	// already on g0
    69  
    70  	MOVQ	(g_sched+gobuf_sp)(R10), SP
    71  call:
    72  	ANDQ	$~15, SP	// alignment for gcc ABI
    73  	CALL	AX
    74  	MOVQ	R12, SP
    75  	RET