Text file src/runtime/cgo/asm_windows_amd64.s

     1  // Copyright 2026 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 goexperiment.runtimecgopurego && !msan && !tsan && windows && amd64
     6  
     7  #include "go_asm.h"
     8  #include "textflag.h"
     9  #include "abi_amd64.h"
    10  
    11  // cgoCallTrampoline is called by runtime.asmcgocall_landingpad or
    12  // runtime.asmcgocall_no_g using the Win64 C ABI with CX pointing to a
    13  // cgoCallFrame. Reserves 32 bytes of Win64 shadow space on a 16-byte aligned
    14  // stack.
    15  TEXT ·cgoCallTrampoline(SB),NOSPLIT|NOFRAME,$0-0
    16  	PUSHQ	BP
    17  	MOVQ	SP, BP
    18  	PUSHQ	BX
    19  	ADJSP	$40		// record shadow space and alignment for unwinding
    20  	MOVQ	CX, BX
    21  	MOVQ	cgoCallFrame_fn(CX), AX
    22  	MOVQ	cgoCallFrame_a3(CX), R9
    23  	MOVQ	cgoCallFrame_a2(CX), R8
    24  	MOVQ	cgoCallFrame_a1(CX), DX
    25  	MOVQ	cgoCallFrame_a0(CX), CX
    26  	CALL	AX
    27  	MOVQ	AX, cgoCallFrame_r1(BX)
    28  	// Capture TEB.LastErrorValue before returning to runtime.cgocall,
    29  	// so runtime.exitsyscall cannot clobber GetLastError.
    30  	MOVQ	0x30(GS), AX
    31  	MOVL	0x68(AX), AX
    32  	ADJSP	$-40
    33  	POPQ	BX
    34  	POPQ	BP
    35  	RET
    36  
    37  // On Windows we call the ABIInternal targets directly rather than going
    38  // through an ABI0 wrapper: the compiler-generated ABI0 wrapper loads g from
    39  // static TLS, which may be null on C threads created before a c-shared Go DLL
    40  // is loaded via LoadLibrary.
    41  
    42  TEXT _cgo_wait_runtime_init_done(SB),NOSPLIT,$0-0
    43  	LEAQ	·runtime_init_done(SB), AX
    44  	MOVL	(AX), AX
    45  	CMPL	AX, $2
    46  	JNE	slow
    47  	LEAQ	·cgo_context_function(SB), AX
    48  	MOVQ	(AX), AX
    49  	TESTQ	AX, AX
    50  	JNE	slow
    51  	XORL	AX, AX
    52  	RET
    53  slow:
    54  	PUSH_REGS_HOST_TO_ABI0()
    55  	XORPS	X15, X15
    56  #ifndef GOAMD64_v3
    57  #ifndef GOAMD64_v4
    58  	CMPB	internal∕cpu·X86+const_offsetX86HasAVX(SB), $1
    59  	JNE	2(PC)
    60  #endif
    61  #endif
    62  	VXORPS	X15, X15, X15
    63  	XORQ	R14, R14
    64  	CALL	·cgoWaitRuntimeInitDone<ABIInternal>(SB)
    65  	POP_REGS_HOST_TO_ABI0()
    66  	RET
    67  
    68  TEXT _cgo_release_context(SB),NOSPLIT,$0-0
    69  	TESTQ	CX, CX
    70  	JEQ	done
    71  	PUSH_REGS_HOST_TO_ABI0()
    72  	ADJSP	$8		// spill slot for ctxt argument
    73  	MOVQ	CX, AX
    74  	XORPS	X15, X15
    75  #ifndef GOAMD64_v3
    76  #ifndef GOAMD64_v4
    77  	CMPB	internal∕cpu·X86+const_offsetX86HasAVX(SB), $1
    78  	JNE	2(PC)
    79  #endif
    80  #endif
    81  	VXORPS	X15, X15, X15
    82  	XORQ	R14, R14
    83  	CALL	·cgoReleaseContext<ABIInternal>(SB)
    84  	ADJSP	$-8
    85  	POP_REGS_HOST_TO_ABI0()
    86  done:
    87  	RET
    88  

View as plain text