github.com/moontrade/nogc@v0.1.7/unsafecgo/call_arm64.s (about)

     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  #include "go_asm.h"
     6  #include "textflag.h"
     7  
     8  // Based on race_arm64.s; see commentary there.
     9  
    10  // WARNING!!!
    11  // Go doesn't allow packages outside of runtime to include "go_asm.h" so the below
    12  // defines required were pulled from generated "go_asm.h" by running make in the
    13  // cmd sub-directory of this package. Navigate into the build (WORK) directory and
    14  // look for a go_asm.h file that's big (>10kb). The below defines will be in there.
    15  // The below defines have been observed to be the same across both linux and darwin
    16  // given it appears to be CPU arch based (amd64) only. The below defines are also
    17  // the same for arm64.
    18  //
    19  // Safer to add build tag "libfuzzer" to hook into the auto-generated "go_asm.h".
    20  // However, it's about ~1ns slower per call because of linking overhead somehow.
    21  
    22  #define g_m 48
    23  #define g_sched 56
    24  #define gobuf_sp 0
    25  #define m_g0 0
    26  
    27  // func runtime·libfuzzerCall(fn, arg0, arg1 uintptr)
    28  // Calls C function fn from libFuzzer and passes 2 arguments to it.
    29  TEXT ·NonBlocking(SB), NOSPLIT, $0-24
    30  	MOVD	fn+0(FP), R9
    31  	MOVD	arg0+8(FP), R0
    32  	MOVD	arg1+16(FP), R1
    33  
    34  	MOVD	g_m(g), R10
    35  
    36  	// Switch to g0 stack.
    37  	MOVD	RSP, R19	// callee-saved, preserved across the CALL
    38  	MOVD	m_g0(R10), R11
    39  	CMP	R11, g
    40  	BEQ	call	// already on g0
    41  	MOVD	(g_sched+gobuf_sp)(R11), R12
    42  	MOVD	R12, RSP
    43  call:
    44  	BL	R9
    45  	MOVD	R19, RSP
    46  	RET