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