Text file src/runtime/valgrind_amd64.s

     1  // Copyright 2025 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 valgrind && linux
     6  
     7  #include "textflag.h"
     8  
     9  // Instead of using cgo and using the Valgrind macros, we just emit the special client request
    10  // assembly ourselves. The client request mechanism is basically the same across all architectures,
    11  // with the notable difference being the special preamble that lets Valgrind know we want to do
    12  // a client request.
    13  //
    14  // The form of the VALGRIND_DO_CLIENT_REQUEST macro assembly can be found in the valgrind/valgrind.h
    15  // header file [0].
    16  //
    17  // [0] https://sourceware.org/git/?p=valgrind.git;a=blob;f=include/valgrind.h.in;h=f1710924aa7372e7b7e2abfbf7366a2286e33d2d;hb=HEAD
    18  
    19  // func valgrindClientRequest(uintptr, uintptr, uintptr, uintptr, uintptr, uintptr) (ret uintptr)
    20  TEXT runtime·valgrindClientRequest(SB), NOSPLIT, $0-56
    21  	// Load the address of the first of the (contiguous) arguments into AX.
    22  	LEAQ args+0(FP), AX
    23  
    24  	// Zero DX, since some requests may not populate it.
    25  	XORL DX, DX
    26  
    27  	// Emit the special preabmle.
    28  	ROLQ $3, DI; ROLQ $13, DI
    29  	ROLQ $61, DI; ROLQ $51, DI
    30  
    31  	// "Execute" the client request.
    32  	XCHGQ BX, BX
    33  
    34  	// Copy the result out of DX.
    35  	MOVQ DX, ret+48(FP)
    36  
    37  	RET
    38  

View as plain text