github.com/moontrade/unsafe@v0.9.1/cgo/call_amd64.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 "go_tls.h" 7 #include "textflag.h" 8 9 // Based on race_amd64.s; see commentary there. 10 11 #ifdef GOOS_windows 12 #define RARG0 CX 13 #define RARG1 DX 14 #else 15 #define RARG0 DI 16 #define RARG1 SI 17 #endif 18 19 // WARNING!!! 20 // Go doesn't allow packages outside of runtime to include "go_asm.h" so the below 21 // defines required were pulled from generated "go_asm.h" by running make in the 22 // cmd sub-directory of this package. Navigate into the build (WORK) directory and 23 // look for a go_asm.h file that's big (>10kb). The below defines will be in there. 24 // The below defines have been observed to be the same across both linux and darwin 25 // given it appears to be CPU arch based (amd64) only. The below defines are also 26 // the same for arm64. 27 // 28 // Safer to add build tag "libfuzzer" to hook into the auto-generated "go_asm.h". 29 // However, it's about ~1ns slower per call because of linking overhead somehow. 30 31 #define g_m 48 32 #define g_sched 56 33 #define gobuf_sp 0 34 #define m_g0 0 35 36 // void runtime·libfuzzerCall(fn, arg0, arg1 uintptr) 37 // Calls C function fn from libFuzzer and passes 2 arguments to it. 38 TEXT ·NonBlocking(SB), NOSPLIT, $0-24 39 MOVQ fn+0(FP), AX 40 MOVQ arg0+8(FP), RARG0 41 MOVQ arg1+16(FP), RARG1 42 43 get_tls(R12) 44 MOVQ g(R12), R14 45 MOVQ g_m(R14), R13 46 47 // Switch to g0 stack. 48 MOVQ SP, R12 // callee-saved, preserved across the CALL 49 MOVQ m_g0(R13), R10 50 CMPQ R10, R14 51 JE call // already on g0 52 MOVQ (g_sched+gobuf_sp)(R10), SP 53 call: 54 ANDQ $~15, SP // alignment for gcc ABI 55 CALL AX 56 MOVQ R12, SP 57 // Back to Go world, set special registers. 58 // The g register (R14) is preserved in C. 59 //XORPS X15, X15 60 RET