Black Lives Matter. Support the Equal Justice Initiative.

Text file src/runtime/libfuzzer_amd64.s

Documentation: runtime

     1  // Copyright 2019 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 libfuzzer
     6  // +build libfuzzer
     7  
     8  #include "go_asm.h"
     9  #include "go_tls.h"
    10  #include "textflag.h"
    11  
    12  // Based on race_amd64.s; see commentary there.
    13  
    14  #ifdef GOOS_windows
    15  #define RARG0 CX
    16  #define RARG1 DX
    17  #else
    18  #define RARG0 DI
    19  #define RARG1 SI
    20  #endif
    21  
    22  // void runtime¬∑libfuzzerCall(fn, arg0, arg1 uintptr)
    23  // Calls C function fn from libFuzzer and passes 2 arguments to it.
    24  TEXT	runtime¬∑libfuzzerCall(SB), NOSPLIT, $0-24
    25  	MOVQ	fn+0(FP), AX
    26  	MOVQ	arg0+8(FP), RARG0
    27  	MOVQ	arg1+16(FP), RARG1
    28  
    29  	get_tls(R12)
    30  	MOVQ	g(R12), R14
    31  	MOVQ	g_m(R14), R13
    32  
    33  	// Switch to g0 stack.
    34  	MOVQ	SP, R12		// callee-saved, preserved across the CALL
    35  	MOVQ	m_g0(R13), R10
    36  	CMPQ	R10, R14
    37  	JE	call	// already on g0
    38  	MOVQ	(g_sched+gobuf_sp)(R10), SP
    39  call:
    40  	ANDQ	$~15, SP	// alignment for gcc ABI
    41  	CALL	AX
    42  	MOVQ	R12, SP
    43  	RET
    44  

View as plain text