build(deps): bump github.com/testcontainers/testcontainers-go

Bumps [github.com/testcontainers/testcontainers-go](https://github.com/testcontainers/testcontainers-go) from 0.40.0 to 0.41.0.
- [Release notes](https://github.com/testcontainers/testcontainers-go/releases)
- [Commits](https://github.com/testcontainers/testcontainers-go/compare/v0.40.0...v0.41.0)

---
updated-dependencies:
- dependency-name: github.com/testcontainers/testcontainers-go
  dependency-version: 0.41.0
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
This commit is contained in:
dependabot[bot]
2026-03-11 11:55:40 +01:00
committed by Ralf Haferkamp
parent fef601f104
commit de59bb63ad
195 changed files with 30918 additions and 2151 deletions
+2 -2
View File
@@ -1,12 +1,12 @@
// SPDX-License-Identifier: Apache-2.0
// SPDX-FileCopyrightText: 2024 The Ebitengine Authors
//go:build freebsd || linux
//go:build freebsd || linux || netbsd
package cgo
/*
#cgo LDFLAGS: -ldl
#cgo !netbsd LDFLAGS: -ldl
#include <dlfcn.h>
#include <stdlib.h>
+2 -2
View File
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: Apache-2.0
// SPDX-FileCopyrightText: 2022 The Ebitengine Authors
//go:build freebsd || (linux && !(arm64 || amd64))
//go:build freebsd || (linux && !(386 || amd64 || arm || arm64 || loong64 || ppc64le || riscv64)) || netbsd
package cgo
@@ -9,7 +9,7 @@ package cgo
// because Cgo and assembly files can't be in the same package.
/*
#cgo LDFLAGS: -ldl
#cgo !netbsd LDFLAGS: -ldl
#include <stdint.h>
#include <dlfcn.h>
+60
View File
@@ -0,0 +1,60 @@
// Copyright 2022 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// Macros for transitioning from the host ABI to Go ABI0.
//
// These macros save and restore the callee-saved registers
// from the stack, but they don't adjust stack pointer, so
// the user should prepare stack space in advance.
// SAVE_R22_TO_R31(offset) saves R22 ~ R31 to the stack space
// of ((offset)+0*8)(R3) ~ ((offset)+9*8)(R3).
//
// SAVE_F24_TO_F31(offset) saves F24 ~ F31 to the stack space
// of ((offset)+0*8)(R3) ~ ((offset)+7*8)(R3).
//
// Note: g is R22
#define SAVE_R22_TO_R31(offset) \
MOVV g, ((offset)+(0*8))(R3) \
MOVV R23, ((offset)+(1*8))(R3) \
MOVV R24, ((offset)+(2*8))(R3) \
MOVV R25, ((offset)+(3*8))(R3) \
MOVV R26, ((offset)+(4*8))(R3) \
MOVV R27, ((offset)+(5*8))(R3) \
MOVV R28, ((offset)+(6*8))(R3) \
MOVV R29, ((offset)+(7*8))(R3) \
MOVV R30, ((offset)+(8*8))(R3) \
MOVV R31, ((offset)+(9*8))(R3)
#define SAVE_F24_TO_F31(offset) \
MOVD F24, ((offset)+(0*8))(R3) \
MOVD F25, ((offset)+(1*8))(R3) \
MOVD F26, ((offset)+(2*8))(R3) \
MOVD F27, ((offset)+(3*8))(R3) \
MOVD F28, ((offset)+(4*8))(R3) \
MOVD F29, ((offset)+(5*8))(R3) \
MOVD F30, ((offset)+(6*8))(R3) \
MOVD F31, ((offset)+(7*8))(R3)
#define RESTORE_R22_TO_R31(offset) \
MOVV ((offset)+(0*8))(R3), g \
MOVV ((offset)+(1*8))(R3), R23 \
MOVV ((offset)+(2*8))(R3), R24 \
MOVV ((offset)+(3*8))(R3), R25 \
MOVV ((offset)+(4*8))(R3), R26 \
MOVV ((offset)+(5*8))(R3), R27 \
MOVV ((offset)+(6*8))(R3), R28 \
MOVV ((offset)+(7*8))(R3), R29 \
MOVV ((offset)+(8*8))(R3), R30 \
MOVV ((offset)+(9*8))(R3), R31
#define RESTORE_F24_TO_F31(offset) \
MOVD ((offset)+(0*8))(R3), F24 \
MOVD ((offset)+(1*8))(R3), F25 \
MOVD ((offset)+(2*8))(R3), F26 \
MOVD ((offset)+(3*8))(R3), F27 \
MOVD ((offset)+(4*8))(R3), F28 \
MOVD ((offset)+(5*8))(R3), F29 \
MOVD ((offset)+(6*8))(R3), F30 \
MOVD ((offset)+(7*8))(R3), F31
+195
View File
@@ -0,0 +1,195 @@
// Copyright 2023 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// Macros for transitioning from the host ABI to Go ABI
//
// On PPC64/ELFv2 targets, the following registers are callee
// saved when called from C. They must be preserved before
// calling into Go which does not preserve any of them.
//
// R14-R31
// CR2-4
// VR20-31
// F14-F31
//
// xcoff(aix) and ELFv1 are similar, but may only require a
// subset of these.
//
// These macros assume a 16 byte aligned stack pointer. This
// is required by ELFv1, ELFv2, and AIX PPC64.
#define SAVE_GPR_SIZE (18*8)
#define SAVE_GPR(offset) \
MOVD R14, (offset+8*0)(R1) \
MOVD R15, (offset+8*1)(R1) \
MOVD R16, (offset+8*2)(R1) \
MOVD R17, (offset+8*3)(R1) \
MOVD R18, (offset+8*4)(R1) \
MOVD R19, (offset+8*5)(R1) \
MOVD R20, (offset+8*6)(R1) \
MOVD R21, (offset+8*7)(R1) \
MOVD R22, (offset+8*8)(R1) \
MOVD R23, (offset+8*9)(R1) \
MOVD R24, (offset+8*10)(R1) \
MOVD R25, (offset+8*11)(R1) \
MOVD R26, (offset+8*12)(R1) \
MOVD R27, (offset+8*13)(R1) \
MOVD R28, (offset+8*14)(R1) \
MOVD R29, (offset+8*15)(R1) \
MOVD g, (offset+8*16)(R1) \
MOVD R31, (offset+8*17)(R1)
#define RESTORE_GPR(offset) \
MOVD (offset+8*0)(R1), R14 \
MOVD (offset+8*1)(R1), R15 \
MOVD (offset+8*2)(R1), R16 \
MOVD (offset+8*3)(R1), R17 \
MOVD (offset+8*4)(R1), R18 \
MOVD (offset+8*5)(R1), R19 \
MOVD (offset+8*6)(R1), R20 \
MOVD (offset+8*7)(R1), R21 \
MOVD (offset+8*8)(R1), R22 \
MOVD (offset+8*9)(R1), R23 \
MOVD (offset+8*10)(R1), R24 \
MOVD (offset+8*11)(R1), R25 \
MOVD (offset+8*12)(R1), R26 \
MOVD (offset+8*13)(R1), R27 \
MOVD (offset+8*14)(R1), R28 \
MOVD (offset+8*15)(R1), R29 \
MOVD (offset+8*16)(R1), g \
MOVD (offset+8*17)(R1), R31
#define SAVE_FPR_SIZE (18*8)
#define SAVE_FPR(offset) \
FMOVD F14, (offset+8*0)(R1) \
FMOVD F15, (offset+8*1)(R1) \
FMOVD F16, (offset+8*2)(R1) \
FMOVD F17, (offset+8*3)(R1) \
FMOVD F18, (offset+8*4)(R1) \
FMOVD F19, (offset+8*5)(R1) \
FMOVD F20, (offset+8*6)(R1) \
FMOVD F21, (offset+8*7)(R1) \
FMOVD F22, (offset+8*8)(R1) \
FMOVD F23, (offset+8*9)(R1) \
FMOVD F24, (offset+8*10)(R1) \
FMOVD F25, (offset+8*11)(R1) \
FMOVD F26, (offset+8*12)(R1) \
FMOVD F27, (offset+8*13)(R1) \
FMOVD F28, (offset+8*14)(R1) \
FMOVD F29, (offset+8*15)(R1) \
FMOVD F30, (offset+8*16)(R1) \
FMOVD F31, (offset+8*17)(R1)
#define RESTORE_FPR(offset) \
FMOVD (offset+8*0)(R1), F14 \
FMOVD (offset+8*1)(R1), F15 \
FMOVD (offset+8*2)(R1), F16 \
FMOVD (offset+8*3)(R1), F17 \
FMOVD (offset+8*4)(R1), F18 \
FMOVD (offset+8*5)(R1), F19 \
FMOVD (offset+8*6)(R1), F20 \
FMOVD (offset+8*7)(R1), F21 \
FMOVD (offset+8*8)(R1), F22 \
FMOVD (offset+8*9)(R1), F23 \
FMOVD (offset+8*10)(R1), F24 \
FMOVD (offset+8*11)(R1), F25 \
FMOVD (offset+8*12)(R1), F26 \
FMOVD (offset+8*13)(R1), F27 \
FMOVD (offset+8*14)(R1), F28 \
FMOVD (offset+8*15)(R1), F29 \
FMOVD (offset+8*16)(R1), F30 \
FMOVD (offset+8*17)(R1), F31
// Save and restore VR20-31 (aka VSR56-63). These
// macros must point to a 16B aligned offset.
#define SAVE_VR_SIZE (12*16)
#define SAVE_VR(offset, rtmp) \
MOVD $(offset+16*0), rtmp \
STVX V20, (rtmp)(R1) \
MOVD $(offset+16*1), rtmp \
STVX V21, (rtmp)(R1) \
MOVD $(offset+16*2), rtmp \
STVX V22, (rtmp)(R1) \
MOVD $(offset+16*3), rtmp \
STVX V23, (rtmp)(R1) \
MOVD $(offset+16*4), rtmp \
STVX V24, (rtmp)(R1) \
MOVD $(offset+16*5), rtmp \
STVX V25, (rtmp)(R1) \
MOVD $(offset+16*6), rtmp \
STVX V26, (rtmp)(R1) \
MOVD $(offset+16*7), rtmp \
STVX V27, (rtmp)(R1) \
MOVD $(offset+16*8), rtmp \
STVX V28, (rtmp)(R1) \
MOVD $(offset+16*9), rtmp \
STVX V29, (rtmp)(R1) \
MOVD $(offset+16*10), rtmp \
STVX V30, (rtmp)(R1) \
MOVD $(offset+16*11), rtmp \
STVX V31, (rtmp)(R1)
#define RESTORE_VR(offset, rtmp) \
MOVD $(offset+16*0), rtmp \
LVX (rtmp)(R1), V20 \
MOVD $(offset+16*1), rtmp \
LVX (rtmp)(R1), V21 \
MOVD $(offset+16*2), rtmp \
LVX (rtmp)(R1), V22 \
MOVD $(offset+16*3), rtmp \
LVX (rtmp)(R1), V23 \
MOVD $(offset+16*4), rtmp \
LVX (rtmp)(R1), V24 \
MOVD $(offset+16*5), rtmp \
LVX (rtmp)(R1), V25 \
MOVD $(offset+16*6), rtmp \
LVX (rtmp)(R1), V26 \
MOVD $(offset+16*7), rtmp \
LVX (rtmp)(R1), V27 \
MOVD $(offset+16*8), rtmp \
LVX (rtmp)(R1), V28 \
MOVD $(offset+16*9), rtmp \
LVX (rtmp)(R1), V29 \
MOVD $(offset+16*10), rtmp \
LVX (rtmp)(R1), V30 \
MOVD $(offset+16*11), rtmp \
LVX (rtmp)(R1), V31
// LR and CR are saved in the caller's frame. The callee must
// make space for all other callee-save registers.
#define SAVE_ALL_REG_SIZE (SAVE_GPR_SIZE+SAVE_FPR_SIZE+SAVE_VR_SIZE)
// Stack a frame and save all callee-save registers following the
// host OS's ABI. Fortunately, this is identical for AIX, ELFv1, and
// ELFv2. All host ABIs require the stack pointer to maintain 16 byte
// alignment, and save the callee-save registers in the same places.
//
// To restate, R1 is assumed to be aligned when this macro is used.
// This assumes the caller's frame is compliant with the host ABI.
// CR and LR are saved into the caller's frame per the host ABI.
// R0 is initialized to $0 as expected by Go.
#define STACK_AND_SAVE_HOST_TO_GO_ABI(extra) \
MOVD LR, R0 \
MOVD R0, 16(R1) \
MOVW CR, R0 \
MOVD R0, 8(R1) \
MOVDU R1, -(extra)-FIXED_FRAME-SAVE_ALL_REG_SIZE(R1) \
SAVE_GPR(extra+FIXED_FRAME) \
SAVE_FPR(extra+FIXED_FRAME+SAVE_GPR_SIZE) \
SAVE_VR(extra+FIXED_FRAME+SAVE_GPR_SIZE+SAVE_FPR_SIZE, R0) \
MOVD $0, R0
// This unstacks the frame, restoring all callee-save registers
// as saved by STACK_AND_SAVE_HOST_TO_GO_ABI.
//
// R0 is not guaranteed to contain $0 after this macro.
#define UNSTACK_AND_RESTORE_GO_TO_HOST_ABI(extra) \
RESTORE_GPR(extra+FIXED_FRAME) \
RESTORE_FPR(extra+FIXED_FRAME+SAVE_GPR_SIZE) \
RESTORE_VR(extra+FIXED_FRAME+SAVE_GPR_SIZE+SAVE_FPR_SIZE, R0) \
ADD $(extra+FIXED_FRAME+SAVE_ALL_REG_SIZE), R1 \
MOVD 16(R1), R0 \
MOVD R0, LR \
MOVD 8(R1), R0 \
MOVW R0, CR
+29
View File
@@ -0,0 +1,29 @@
// Copyright 2009 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
#include "textflag.h"
// Called by C code generated by cmd/cgo.
// func crosscall2(fn, a unsafe.Pointer, n int32, ctxt uintptr)
// Saves C callee-saved registers and calls cgocallback with three arguments.
// fn is the PC of a func(a unsafe.Pointer) function.
TEXT crosscall2(SB), NOSPLIT, $28-16
MOVL BP, 24(SP)
MOVL BX, 20(SP)
MOVL SI, 16(SP)
MOVL DI, 12(SP)
MOVL ctxt+12(FP), AX
MOVL AX, 8(SP)
MOVL a+4(FP), AX
MOVL AX, 4(SP)
MOVL fn+0(FP), AX
MOVL AX, 0(SP)
CALL runtime·cgocallback(SB)
MOVL 12(SP), DI
MOVL 16(SP), SI
MOVL 20(SP), BX
MOVL 24(SP), BP
RET
+52
View File
@@ -0,0 +1,52 @@
// Copyright 2012 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
#include "textflag.h"
// Called by C code generated by cmd/cgo.
// func crosscall2(fn, a unsafe.Pointer, n int32, ctxt uintptr)
// Saves C callee-saved registers and calls cgocallback with three arguments.
// fn is the PC of a func(a unsafe.Pointer) function.
TEXT crosscall2(SB), NOSPLIT|NOFRAME, $0
SUB $(8*9), R13 // Reserve space for the floating point registers.
// The C arguments arrive in R0, R1, R2, and R3. We want to
// pass R0, R1, and R3 to Go, so we push those on the stack.
// Also, save C callee-save registers R4-R12.
MOVM.WP [R0, R1, R3, R4, R5, R6, R7, R8, R9, g, R11, R12], (R13)
// Finally, save the link register R14. This also puts the
// arguments we pushed for cgocallback where they need to be,
// starting at 4(R13).
MOVW.W R14, -4(R13)
// Save VFP callee-saved registers D8-D15 (same as S16-S31).
// Note: We always save these since we target hard-float ABI.
MOVD F8, (13*4+8*1)(R13)
MOVD F9, (13*4+8*2)(R13)
MOVD F10, (13*4+8*3)(R13)
MOVD F11, (13*4+8*4)(R13)
MOVD F12, (13*4+8*5)(R13)
MOVD F13, (13*4+8*6)(R13)
MOVD F14, (13*4+8*7)(R13)
MOVD F15, (13*4+8*8)(R13)
BL runtime·load_g(SB)
// We set up the arguments to cgocallback when saving registers above.
BL runtime·cgocallback(SB)
MOVD (13*4+8*1)(R13), F8
MOVD (13*4+8*2)(R13), F9
MOVD (13*4+8*3)(R13), F10
MOVD (13*4+8*4)(R13), F11
MOVD (13*4+8*5)(R13), F12
MOVD (13*4+8*6)(R13), F13
MOVD (13*4+8*7)(R13), F14
MOVD (13*4+8*8)(R13), F15
MOVW.P 4(R13), R14
MOVM.IAW (R13), [R0, R1, R3, R4, R5, R6, R7, R8, R9, g, R11, R12]
ADD $(8*9), R13
MOVW R14, R15
+40
View File
@@ -0,0 +1,40 @@
// Copyright 2022 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
#include "textflag.h"
#include "abi_loong64.h"
// Called by C code generated by cmd/cgo.
// func crosscall2(fn, a unsafe.Pointer, n int32, ctxt uintptr)
// Saves C callee-saved registers and calls cgocallback with three arguments.
// fn is the PC of a func(a unsafe.Pointer) function.
TEXT crosscall2(SB), NOSPLIT|NOFRAME, $0
/*
* We still need to save all callee save register as before, and then
* push 3 args for fn (R4, R5, R7), skipping R6.
* Also note that at procedure entry in gc world, 8(R29) will be the
* first arg.
*/
ADDV $(-23*8), R3
MOVV R4, (1*8)(R3) // fn unsafe.Pointer
MOVV R5, (2*8)(R3) // a unsafe.Pointer
MOVV R7, (3*8)(R3) // ctxt uintptr
SAVE_R22_TO_R31((4*8))
SAVE_F24_TO_F31((14*8))
MOVV R1, (22*8)(R3)
// Initialize Go ABI environment
JAL runtime·load_g(SB)
JAL runtime·cgocallback(SB)
RESTORE_R22_TO_R31((4*8))
RESTORE_F24_TO_F31((14*8))
MOVV (22*8)(R3), R1
ADDV $(23*8), R3
RET
+82
View File
@@ -0,0 +1,82 @@
// Copyright 2014 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
#include "textflag.h"
#include "abi_ppc64x.h"
// Called by C code generated by cmd/cgo.
// func crosscall2(fn, a unsafe.Pointer, n int32, ctxt uintptr)
// Saves C callee-saved registers and calls cgocallback with three arguments.
// fn is the PC of a func(a unsafe.Pointer) function.
//
// This is a simplified version that only saves GPR and FPR registers,
// not vector registers. This keeps the stack frame smaller to avoid
// exceeding the nosplit stack limit.
//
// On PPC64LE ELFv2, callee-save registers are:
// R14-R31 (18 GPRs = 144 bytes)
// F14-F31 (18 FPRs = 144 bytes)
// CR2-CR4 (saved in CR field)
//
// Stack layout (must be 16-byte aligned):
// 32 (FIXED_FRAME) + 24 (args) + 144 (GPR) + 144 (FPR) = 344
// Rounded to 352 for 16-byte alignment.
#define FIXED_FRAME 32
#define SAVE_SIZE 352
#define GPR_OFFSET (FIXED_FRAME+24)
#define FPR_OFFSET (GPR_OFFSET+SAVE_GPR_SIZE)
TEXT crosscall2(SB), NOSPLIT|NOFRAME, $0
// Save LR and CR in caller's frame per ELFv2 ABI
MOVD LR, R0
MOVD R0, 16(R1)
MOVW CR, R0
MOVD R0, 8(R1)
// Allocate our stack frame
MOVDU R1, -SAVE_SIZE(R1)
// Save TOC (R2) in case needed
MOVD R2, 24(R1)
// Save callee-save GPRs
SAVE_GPR(GPR_OFFSET)
// Save callee-save FPRs
SAVE_FPR(FPR_OFFSET)
// Initialize R0 to 0 as expected by Go
MOVD $0, R0
// Load the current g.
BL runtime·load_g(SB)
// Set up arguments for cgocallback
MOVD R3, FIXED_FRAME+0(R1) // fn unsafe.Pointer
MOVD R4, FIXED_FRAME+8(R1) // a unsafe.Pointer
// Skip R5 = n uint32
MOVD R6, FIXED_FRAME+16(R1) // ctxt uintptr
BL runtime·cgocallback(SB)
// Restore callee-save FPRs
RESTORE_FPR(FPR_OFFSET)
// Restore callee-save GPRs
RESTORE_GPR(GPR_OFFSET)
// Restore TOC
MOVD 24(R1), R2
// Deallocate stack frame
ADD $SAVE_SIZE, R1
// Restore LR and CR from caller's frame
MOVD 16(R1), R0
MOVD R0, LR
MOVD 8(R1), R0
MOVW R0, CR
RET
+78
View File
@@ -0,0 +1,78 @@
// Copyright 2020 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
#include "textflag.h"
// Called by C code generated by cmd/cgo.
// func crosscall2(fn, a unsafe.Pointer, n int32, ctxt uintptr)
// Saves C callee-saved registers and calls cgocallback with three arguments.
// fn is the PC of a func(a unsafe.Pointer) function.
TEXT crosscall2(SB), NOSPLIT|NOFRAME, $0
/*
* Push arguments for fn (X10, X11, X13), along with all callee-save
* registers. Note that at procedure entry the first argument is at
* 8(X2).
*/
ADD $(-8*29), X2
MOV X10, (8*1)(X2) // fn unsafe.Pointer
MOV X11, (8*2)(X2) // a unsafe.Pointer
MOV X13, (8*3)(X2) // ctxt uintptr
MOV X8, (8*4)(X2)
MOV X9, (8*5)(X2)
MOV X18, (8*6)(X2)
MOV X19, (8*7)(X2)
MOV X20, (8*8)(X2)
MOV X21, (8*9)(X2)
MOV X22, (8*10)(X2)
MOV X23, (8*11)(X2)
MOV X24, (8*12)(X2)
MOV X25, (8*13)(X2)
MOV X26, (8*14)(X2)
MOV g, (8*15)(X2)
MOV X1, (8*16)(X2)
MOVD F8, (8*17)(X2)
MOVD F9, (8*18)(X2)
MOVD F18, (8*19)(X2)
MOVD F19, (8*20)(X2)
MOVD F20, (8*21)(X2)
MOVD F21, (8*22)(X2)
MOVD F22, (8*23)(X2)
MOVD F23, (8*24)(X2)
MOVD F24, (8*25)(X2)
MOVD F25, (8*26)(X2)
MOVD F26, (8*27)(X2)
MOVD F27, (8*28)(X2)
// Initialize Go ABI environment
CALL runtime·load_g(SB)
CALL runtime·cgocallback(SB)
MOV (8*4)(X2), X8
MOV (8*5)(X2), X9
MOV (8*6)(X2), X18
MOV (8*7)(X2), X19
MOV (8*8)(X2), X20
MOV (8*9)(X2), X21
MOV (8*10)(X2), X22
MOV (8*11)(X2), X23
MOV (8*12)(X2), X24
MOV (8*13)(X2), X25
MOV (8*14)(X2), X26
MOV (8*15)(X2), g
MOV (8*16)(X2), X1
MOVD (8*17)(X2), F8
MOVD (8*18)(X2), F9
MOVD (8*19)(X2), F18
MOVD (8*20)(X2), F19
MOVD (8*21)(X2), F20
MOVD (8*22)(X2), F21
MOVD (8*23)(X2), F22
MOVD (8*24)(X2), F23
MOVD (8*25)(X2), F24
MOVD (8*26)(X2), F25
MOVD (8*27)(X2), F26
MOVD (8*28)(X2), F27
ADD $(8*29), X2
RET
+55
View File
@@ -0,0 +1,55 @@
// Copyright 2016 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
#include "textflag.h"
// Called by C code generated by cmd/cgo.
// func crosscall2(fn, a unsafe.Pointer, n int32, ctxt uintptr)
// Saves C callee-saved registers and calls cgocallback with three arguments.
// fn is the PC of a func(a unsafe.Pointer) function.
TEXT crosscall2(SB), NOSPLIT|NOFRAME, $0
// Start with standard C stack frame layout and linkage.
// Save R6-R15 in the register save area of the calling function.
STMG R6, R15, 48(R15)
// Allocate 96 bytes on the stack.
MOVD $-96(R15), R15
// Save F8-F15 in our stack frame.
FMOVD F8, 32(R15)
FMOVD F9, 40(R15)
FMOVD F10, 48(R15)
FMOVD F11, 56(R15)
FMOVD F12, 64(R15)
FMOVD F13, 72(R15)
FMOVD F14, 80(R15)
FMOVD F15, 88(R15)
// Initialize Go ABI environment.
BL runtime·load_g(SB)
MOVD R2, 8(R15) // fn unsafe.Pointer
MOVD R3, 16(R15) // a unsafe.Pointer
// Skip R4 = n uint32
MOVD R5, 24(R15) // ctxt uintptr
BL runtime·cgocallback(SB)
FMOVD 32(R15), F8
FMOVD 40(R15), F9
FMOVD 48(R15), F10
FMOVD 56(R15), F11
FMOVD 64(R15), F12
FMOVD 72(R15), F13
FMOVD 80(R15), F14
FMOVD 88(R15), F15
// De-allocate stack frame.
MOVD $96(R15), R15
// Restore R6-R15.
LMG 48(R15), R6, R15
RET
+1 -1
View File
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//go:build !cgo && (darwin || freebsd || linux)
//go:build !cgo && (darwin || freebsd || linux || netbsd)
package fakecgo
+1 -1
View File
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: Apache-2.0
// SPDX-FileCopyrightText: 2022 The Ebitengine Authors
//go:build !cgo && (darwin || freebsd || linux)
//go:build !cgo && (darwin || freebsd || linux || netbsd)
// Package fakecgo implements the Cgo runtime (runtime/cgo) entirely in Go.
// This allows code that calls into C to function properly when CGO_ENABLED=0.
+14
View File
@@ -0,0 +1,14 @@
// SPDX-License-Identifier: Apache-2.0
// SPDX-FileCopyrightText: 2025 The Ebitengine Authors
//go:build !cgo && (darwin || freebsd || linux || netbsd)
package fakecgo
import _ "unsafe"
// setg_trampoline calls setg with the G provided
func setg_trampoline(setg uintptr, G uintptr)
// call5 takes fn the C function and 5 arguments and calls the function with those arguments
func call5(fn, a1, a2, a3, a4, a5 uintptr) uintptr
@@ -1,73 +0,0 @@
// Copyright 2011 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//go:build !cgo
package fakecgo
import "unsafe"
//go:nosplit
//go:norace
func _cgo_sys_thread_start(ts *ThreadStart) {
var attr pthread_attr_t
var ign, oset sigset_t
var p pthread_t
var size size_t
var err int
sigfillset(&ign)
pthread_sigmask(SIG_SETMASK, &ign, &oset)
size = pthread_get_stacksize_np(pthread_self())
pthread_attr_init(&attr)
pthread_attr_setstacksize(&attr, size)
// Leave stacklo=0 and set stackhi=size; mstart will do the rest.
ts.g.stackhi = uintptr(size)
err = _cgo_try_pthread_create(&p, &attr, unsafe.Pointer(threadentry_trampolineABI0), ts)
pthread_sigmask(SIG_SETMASK, &oset, nil)
if err != 0 {
print("fakecgo: pthread_create failed: ")
println(err)
abort()
}
}
// threadentry_trampolineABI0 maps the C ABI to Go ABI then calls the Go function
//
//go:linkname x_threadentry_trampoline threadentry_trampoline
var x_threadentry_trampoline byte
var threadentry_trampolineABI0 = &x_threadentry_trampoline
//go:nosplit
//go:norace
func threadentry(v unsafe.Pointer) unsafe.Pointer {
ts := *(*ThreadStart)(v)
free(v)
setg_trampoline(setg_func, uintptr(unsafe.Pointer(ts.g)))
// faking funcs in go is a bit a... involved - but the following works :)
fn := uintptr(unsafe.Pointer(&ts.fn))
(*(*func())(unsafe.Pointer(&fn)))()
return nil
}
// here we will store a pointer to the provided setg func
var setg_func uintptr
//go:nosplit
//go:norace
func x_cgo_init(g *G, setg uintptr) {
var size size_t
setg_func = setg
size = pthread_get_stacksize_np(pthread_self())
g.stacklo = uintptr(unsafe.Add(unsafe.Pointer(&size), -size+4096))
}
@@ -92,6 +92,8 @@ func x_cgo_init(g *G, setg uintptr) {
}
pthread_attr_init(attr)
pthread_attr_getstacksize(attr, &size)
// runtime/cgo uses __builtin_frame_address(0) instead of `uintptr(unsafe.Pointer(&size))`
// but this should be OK since we are taking the address of the first variable in this function.
g.stacklo = uintptr(unsafe.Pointer(&size)) - uintptr(size) + 4096
pthread_attr_destroy(attr)
free(unsafe.Pointer(attr))
+1 -1
View File
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: Apache-2.0
// SPDX-FileCopyrightText: 2022 The Ebitengine Authors
//go:build !cgo && (darwin || freebsd || linux)
//go:build !cgo && (darwin || freebsd || linux || netbsd)
package fakecgo
@@ -92,6 +92,8 @@ func x_cgo_init(g *G, setg uintptr) {
}
pthread_attr_init(attr)
pthread_attr_getstacksize(attr, &size)
// runtime/cgo uses __builtin_frame_address(0) instead of `uintptr(unsafe.Pointer(&size))`
// but this should be OK since we are taking the address of the first variable in this function.
g.stacklo = uintptr(unsafe.Pointer(&size)) - uintptr(size) + 4096
pthread_attr_destroy(attr)
free(unsafe.Pointer(attr))
-95
View File
@@ -1,95 +0,0 @@
// Copyright 2011 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//go:build !cgo
package fakecgo
import "unsafe"
//go:nosplit
func _cgo_sys_thread_start(ts *ThreadStart) {
var attr pthread_attr_t
var ign, oset sigset_t
var p pthread_t
var size size_t
var err int
//fprintf(stderr, "runtime/cgo: _cgo_sys_thread_start: fn=%p, g=%p\n", ts->fn, ts->g); // debug
sigfillset(&ign)
pthread_sigmask(SIG_SETMASK, &ign, &oset)
pthread_attr_init(&attr)
pthread_attr_getstacksize(&attr, &size)
// Leave stacklo=0 and set stackhi=size; mstart will do the rest.
ts.g.stackhi = uintptr(size)
err = _cgo_try_pthread_create(&p, &attr, unsafe.Pointer(threadentry_trampolineABI0), ts)
pthread_sigmask(SIG_SETMASK, &oset, nil)
if err != 0 {
print("fakecgo: pthread_create failed: ")
println(err)
abort()
}
}
// threadentry_trampolineABI0 maps the C ABI to Go ABI then calls the Go function
//
//go:linkname x_threadentry_trampoline threadentry_trampoline
var x_threadentry_trampoline byte
var threadentry_trampolineABI0 = &x_threadentry_trampoline
//go:nosplit
func threadentry(v unsafe.Pointer) unsafe.Pointer {
ts := *(*ThreadStart)(v)
free(v)
setg_trampoline(setg_func, uintptr(unsafe.Pointer(ts.g)))
// faking funcs in go is a bit a... involved - but the following works :)
fn := uintptr(unsafe.Pointer(&ts.fn))
(*(*func())(unsafe.Pointer(&fn)))()
return nil
}
// here we will store a pointer to the provided setg func
var setg_func uintptr
//go:nosplit
func x_cgo_init(g *G, setg uintptr) {
var size size_t
var attr *pthread_attr_t
/* The memory sanitizer distributed with versions of clang
before 3.8 has a bug: if you call mmap before malloc, mmap
may return an address that is later overwritten by the msan
library. Avoid this problem by forcing a call to malloc
here, before we ever call malloc.
This is only required for the memory sanitizer, so it's
unfortunate that we always run it. It should be possible
to remove this when we no longer care about versions of
clang before 3.8. The test for this is
misc/cgo/testsanitizers.
GCC works hard to eliminate a seemingly unnecessary call to
malloc, so we actually use the memory we allocate. */
setg_func = setg
attr = (*pthread_attr_t)(malloc(unsafe.Sizeof(*attr)))
if attr == nil {
println("fakecgo: malloc failed")
abort()
}
pthread_attr_init(attr)
pthread_attr_getstacksize(attr, &size)
// runtime/cgo uses __builtin_frame_address(0) instead of `uintptr(unsafe.Pointer(&size))`
// but this should be OK since we are taking the address of the first variable in this function.
g.stacklo = uintptr(unsafe.Pointer(&size)) - uintptr(size) + 4096
pthread_attr_destroy(attr)
free(unsafe.Pointer(attr))
}
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//go:build !cgo
//go:build !cgo && (amd64 || arm64)
package fakecgo
@@ -16,7 +16,7 @@ func _cgo_sys_thread_start(ts *ThreadStart) {
var size size_t
var err int
//fprintf(stderr, "runtime/cgo: _cgo_sys_thread_start: fn=%p, g=%p\n", ts->fn, ts->g); // debug
// fprintf(stderr, "runtime/cgo: _cgo_sys_thread_start: fn=%p, g=%p\n", ts->fn, ts->g); // debug
sigfillset(&ign)
pthread_sigmask(SIG_SETMASK, &ign, &oset)
@@ -44,9 +44,20 @@ var threadentry_trampolineABI0 = &x_threadentry_trampoline
//go:nosplit
func threadentry(v unsafe.Pointer) unsafe.Pointer {
var ss stack_t
ts := *(*ThreadStart)(v)
free(v)
// On NetBSD, a new thread inherits the signal stack of the
// creating thread. That confuses minit, so we remove that
// signal stack here before calling the regular mstart. It's
// a bit baroque to remove a signal stack here only to add one
// in minit, but it's a simple change that keeps NetBSD
// working like other OS's. At this point all signals are
// blocked, so there is no race.
ss.ss_flags = SS_DISABLE
sigaltstack(&ss, nil)
setg_trampoline(setg_func, uintptr(unsafe.Pointer(ts.g)))
// faking funcs in go is a bit a... involved - but the following works :)
+1 -1
View File
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: Apache-2.0
// SPDX-FileCopyrightText: 2022 The Ebitengine Authors
//go:build !cgo && (darwin || freebsd || linux)
//go:build !cgo && (darwin || freebsd || linux || netbsd)
package fakecgo
+4 -3
View File
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: Apache-2.0
// SPDX-FileCopyrightText: 2022 The Ebitengine Authors
//go:build !cgo && (darwin || freebsd || linux)
//go:build !cgo && (darwin || freebsd || linux || netbsd)
package fakecgo
@@ -28,8 +28,9 @@ func x_cgo_thread_start(arg *ThreadStart) {
abort()
}
// *ts = *arg would cause a writebarrier so copy using slices
s1 := unsafe.Slice((*uintptr)(unsafe.Pointer(ts)), unsafe.Sizeof(*ts)/8)
s2 := unsafe.Slice((*uintptr)(unsafe.Pointer(arg)), unsafe.Sizeof(*arg)/8)
const ptrSize = unsafe.Sizeof(uintptr(0))
s1 := unsafe.Slice((*uintptr)(unsafe.Pointer(ts)), unsafe.Sizeof(*ts)/ptrSize)
s2 := unsafe.Slice((*uintptr)(unsafe.Pointer(arg)), unsafe.Sizeof(*arg)/ptrSize)
for i := range s2 {
s1[i] = s2[i]
}
+1 -1
View File
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//go:build !cgo && (darwin || freebsd || linux)
//go:build !cgo && (darwin || freebsd || linux || netbsd)
// The runtime package contains an uninitialized definition
// for runtime·iscgo. Override it to tell the runtime we're here.
+1 -1
View File
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: Apache-2.0
// SPDX-FileCopyrightText: 2022 The Ebitengine Authors
//go:build !cgo && (darwin || freebsd || linux)
//go:build !cgo && (darwin || freebsd || linux || netbsd)
package fakecgo
@@ -20,3 +20,7 @@ var (
PTHREAD_COND_INITIALIZER = pthread_cond_t{sig: 0x3CB0B1BB}
PTHREAD_MUTEX_INITIALIZER = pthread_mutex_t{sig: 0x32AAABA7}
)
type stack_t struct {
/* not implemented */
}
@@ -14,3 +14,7 @@ var (
PTHREAD_COND_INITIALIZER = pthread_cond_t(0)
PTHREAD_MUTEX_INITIALIZER = pthread_mutex_t(0)
)
type stack_t struct {
/* not implemented */
}
+4
View File
@@ -14,3 +14,7 @@ var (
PTHREAD_COND_INITIALIZER = pthread_cond_t{}
PTHREAD_MUTEX_INITIALIZER = pthread_mutex_t{}
)
type stack_t struct {
/* not implemented */
}
+26
View File
@@ -0,0 +1,26 @@
// SPDX-License-Identifier: Apache-2.0
// SPDX-FileCopyrightText: 2025 The Ebitengine Authors
//go:build !cgo
package fakecgo
type (
pthread_cond_t uintptr
pthread_mutex_t uintptr
)
var (
PTHREAD_COND_INITIALIZER = pthread_cond_t(0)
PTHREAD_MUTEX_INITIALIZER = pthread_mutex_t(0)
)
// Source: https://github.com/NetBSD/src/blob/613e27c65223fd2283b6ed679da1197e12f50e27/sys/compat/linux/arch/m68k/linux_signal.h#L133
type stack_t struct {
ss_sp uintptr
ss_flags int32
ss_size uintptr
}
// Source: https://github.com/NetBSD/src/blob/613e27c65223fd2283b6ed679da1197e12f50e27/sys/sys/signal.h#L261
const SS_DISABLE = 0x004
+23
View File
@@ -0,0 +1,23 @@
// Copyright 2010 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//go:build netbsd
package fakecgo
import _ "unsafe" // for go:linkname
// Supply environ and __progname, because we don't
// link against the standard NetBSD crt0.o and the
// libc dynamic library needs them.
//go:linkname _environ environ
//go:linkname _progname __progname
//go:linkname ___ps_strings __ps_strings
var (
_environ uintptr
_progname uintptr
___ps_strings uintptr
)
+1 -1
View File
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//go:build !cgo && (darwin || freebsd || linux)
//go:build !cgo && (darwin || freebsd || linux || netbsd)
package fakecgo
+107
View File
@@ -0,0 +1,107 @@
// SPDX-License-Identifier: Apache-2.0
// SPDX-FileCopyrightText: 2026 The Ebitengine Authors
//go:build !cgo && (freebsd || linux)
#include "textflag.h"
#include "go_asm.h"
// These trampolines map the gcc ABI to Go ABI0 and then call into the Go equivalent functions.
// On i386, both GCC and Go use stack-based calling conventions.
//
// When C calls a function, the stack looks like:
// 0(SP) = return address
// 4(SP) = arg1
// 8(SP) = arg2
// ...
//
// When we declare a Go function with frame size $N-0, Go's prologue
// effectively does SUB $N, SP, so the C arguments shift up by N bytes:
// N+0(SP) = return address
// N+4(SP) = arg1
// N+8(SP) = arg2
//
// Go ABI0 on 386 expects arguments starting at 0(FP) which equals N+4(SP)
// after the prologue (where N is the local frame size).
TEXT x_cgo_init_trampoline(SB), NOSPLIT, $8-0
// C args at 12(SP) and 16(SP) after frame setup (8 bytes local + 4 bytes ret addr)
// Go function expects args at 0(SP) and 4(SP) in local frame
MOVL 12(SP), AX // first C arg
MOVL 16(SP), BX // second C arg
MOVL AX, 0(SP) // Go arg 1
MOVL BX, 4(SP) // Go arg 2
MOVL ·x_cgo_init_call(SB), CX
MOVL (CX), CX
CALL CX
RET
TEXT x_cgo_thread_start_trampoline(SB), NOSPLIT, $4-0
// C args at 8(SP) after frame setup (4 bytes local + 4 bytes ret addr)
MOVL 8(SP), AX // first C arg
MOVL AX, 0(SP) // Go arg 1
MOVL ·x_cgo_thread_start_call(SB), CX
MOVL (CX), CX
CALL CX
RET
TEXT x_cgo_setenv_trampoline(SB), NOSPLIT, $4-0
MOVL 8(SP), AX // first C arg
MOVL AX, 0(SP) // Go arg 1
MOVL ·x_cgo_setenv_call(SB), CX
MOVL (CX), CX
CALL CX
RET
TEXT x_cgo_unsetenv_trampoline(SB), NOSPLIT, $4-0
MOVL 8(SP), AX // first C arg
MOVL AX, 0(SP) // Go arg 1
MOVL ·x_cgo_unsetenv_call(SB), CX
MOVL (CX), CX
CALL CX
RET
TEXT x_cgo_notify_runtime_init_done_trampoline(SB), NOSPLIT, $0-0
CALL ·x_cgo_notify_runtime_init_done(SB)
RET
TEXT x_cgo_bindm_trampoline(SB), NOSPLIT, $0
CALL ·x_cgo_bindm(SB)
RET
// func setg_trampoline(setg uintptr, g uintptr)
// This is called from Go, so args are at normal FP positions
TEXT ·setg_trampoline(SB), NOSPLIT, $4-8
MOVL g+4(FP), AX
MOVL setg+0(FP), BX
// setg expects g in 0(SP)
MOVL AX, 0(SP)
CALL BX
RET
TEXT threadentry_trampoline(SB), NOSPLIT, $4-0
MOVL 8(SP), AX // first C arg
MOVL AX, 0(SP) // Go arg 1
MOVL ·threadentry_call(SB), CX
MOVL (CX), CX
CALL CX
RET
TEXT ·call5(SB), NOSPLIT, $20-28
MOVL fn+0(FP), AX
MOVL a1+4(FP), BX
MOVL a2+8(FP), CX
MOVL a3+12(FP), DX
MOVL a4+16(FP), SI
MOVL a5+20(FP), DI
// Place arguments on local stack frame for C calling convention
MOVL BX, 0(SP) // a1
MOVL CX, 4(SP) // a2
MOVL DX, 8(SP) // a3
MOVL SI, 12(SP) // a4
MOVL DI, 16(SP) // a5
CALL AX
MOVL AX, r1+24(FP)
RET
+33 -30
View File
@@ -7,12 +7,6 @@
trampoline for emulating required C functions for cgo in go (see cgo.go)
(we convert cdecl calling convention to go and vice-versa)
Since we're called from go and call into C we can cheat a bit with the calling conventions:
- in go all the registers are caller saved
- in C we have a couple of callee saved registers
=> we can use BX, R12, R13, R14, R15 instead of the stack
C Calling convention cdecl used here (we only need integer args):
1. arg: DI
2. arg: SI
@@ -22,66 +16,75 @@ C Calling convention cdecl used here (we only need integer args):
6. arg: R9
We don't need floats with these functions -> AX=0
return value will be in AX
temporary register is R11
*/
#include "textflag.h"
#include "go_asm.h"
#include "abi_amd64.h"
// these trampolines map the gcc ABI to Go ABI and then calls into the Go equivalent functions.
TEXT x_cgo_init_trampoline(SB), NOSPLIT, $16
MOVQ DI, AX
MOVQ SI, BX
MOVQ ·x_cgo_init_call(SB), DX
MOVQ (DX), CX
CALL CX
MOVQ ·x_cgo_init_call(SB), R11
MOVQ (R11), R11
CALL R11
RET
TEXT x_cgo_thread_start_trampoline(SB), NOSPLIT, $8
MOVQ DI, AX
MOVQ ·x_cgo_thread_start_call(SB), DX
MOVQ (DX), CX
CALL CX
MOVQ ·x_cgo_thread_start_call(SB), R11
MOVQ (R11), R11
CALL R11
RET
TEXT x_cgo_setenv_trampoline(SB), NOSPLIT, $8
MOVQ DI, AX
MOVQ ·x_cgo_setenv_call(SB), DX
MOVQ (DX), CX
CALL CX
MOVQ ·x_cgo_setenv_call(SB), R11
MOVQ (R11), R11
CALL R11
RET
TEXT x_cgo_unsetenv_trampoline(SB), NOSPLIT, $8
MOVQ DI, AX
MOVQ ·x_cgo_unsetenv_call(SB), DX
MOVQ (DX), CX
CALL CX
MOVQ ·x_cgo_unsetenv_call(SB), R11
MOVQ (R11), R11
CALL R11
RET
TEXT x_cgo_notify_runtime_init_done_trampoline(SB), NOSPLIT, $0
CALL ·x_cgo_notify_runtime_init_done(SB)
RET
JMP ·x_cgo_notify_runtime_init_done(SB)
TEXT x_cgo_bindm_trampoline(SB), NOSPLIT, $0
CALL ·x_cgo_bindm(SB)
RET
JMP ·x_cgo_bindm(SB)
// func setg_trampoline(setg uintptr, g uintptr)
TEXT ·setg_trampoline(SB), NOSPLIT, $0-16
MOVQ G+8(FP), DI
MOVQ setg+0(FP), BX
MOVQ setg+0(FP), R11
XORL AX, AX
CALL BX
CALL R11
RET
TEXT threadentry_trampoline(SB), NOSPLIT, $16
TEXT threadentry_trampoline(SB), NOSPLIT, $0
// See crosscall2.
PUSH_REGS_HOST_TO_ABI0()
// X15 is designated by Go as a fixed zero register.
// Calling directly into ABIInternal, ensure it is zero.
PXOR X15, X15
MOVQ DI, AX
MOVQ ·threadentry_call(SB), DX
MOVQ (DX), CX
CALL CX
MOVQ ·threadentry_call(SB), R11
MOVQ (R11), R11
CALL R11
POP_REGS_HOST_TO_ABI0()
RET
TEXT ·call5(SB), NOSPLIT, $0-56
MOVQ fn+0(FP), BX
MOVQ fn+0(FP), R11
MOVQ a1+8(FP), DI
MOVQ a2+16(FP), SI
MOVQ a3+24(FP), DX
@@ -95,7 +98,7 @@ TEXT ·call5(SB), NOSPLIT, $0-56
SUBQ $16, SP // allocate space for alignment
ANDQ $-16, SP // align on 16 bytes for SSE
CALL BX
CALL R11
MOVQ BP, SP // get SP back
POPQ BP // restore BP
+81
View File
@@ -0,0 +1,81 @@
// SPDX-License-Identifier: Apache-2.0
// SPDX-FileCopyrightText: 2026 The Ebitengine Authors
//go:build !cgo && (freebsd || linux)
#include "textflag.h"
#include "go_asm.h"
// These trampolines map the gcc ABI to Go ABI0 and then call into the Go equivalent functions.
// On ARM32, Go ABI0 uses stack-based calling convention.
// Arguments are placed on the stack starting at 4(SP) after the prologue.
TEXT x_cgo_init_trampoline(SB), NOSPLIT, $8-0
MOVW R0, 4(R13)
MOVW R1, 8(R13)
MOVW ·x_cgo_init_call(SB), R12
MOVW (R12), R12
CALL (R12)
RET
TEXT x_cgo_thread_start_trampoline(SB), NOSPLIT, $8-0
MOVW R0, 4(R13)
MOVW ·x_cgo_thread_start_call(SB), R12
MOVW (R12), R12
CALL (R12)
RET
TEXT x_cgo_setenv_trampoline(SB), NOSPLIT, $8-0
MOVW R0, 4(R13)
MOVW ·x_cgo_setenv_call(SB), R12
MOVW (R12), R12
CALL (R12)
RET
TEXT x_cgo_unsetenv_trampoline(SB), NOSPLIT, $8-0
MOVW R0, 4(R13)
MOVW ·x_cgo_unsetenv_call(SB), R12
MOVW (R12), R12
CALL (R12)
RET
TEXT x_cgo_notify_runtime_init_done_trampoline(SB), NOSPLIT, $0-0
CALL ·x_cgo_notify_runtime_init_done(SB)
RET
TEXT x_cgo_bindm_trampoline(SB), NOSPLIT, $0
CALL ·x_cgo_bindm(SB)
RET
// func setg_trampoline(setg uintptr, g uintptr)
TEXT ·setg_trampoline(SB), NOSPLIT, $0-8
MOVW G+4(FP), R0
MOVW setg+0(FP), R12
BL (R12)
RET
TEXT threadentry_trampoline(SB), NOSPLIT, $8-0
// See crosscall2.
MOVW R0, 4(R13)
MOVW ·threadentry_call(SB), R12
MOVW (R12), R12
CALL (R12)
RET
TEXT ·call5(SB), NOSPLIT, $8-28
MOVW fn+0(FP), R12
MOVW a1+4(FP), R0
MOVW a2+8(FP), R1
MOVW a3+12(FP), R2
MOVW a4+16(FP), R3
MOVW a5+20(FP), R4
// Store 5th arg below SP (in local frame area)
MOVW R4, arg5-8(SP)
// Align SP to 8 bytes for call (required by ARM AAPCS)
SUB $8, R13
CALL (R12)
ADD $8, R13
MOVW R0, r1+24(FP)
RET
+39 -27
View File
@@ -5,36 +5,34 @@
#include "textflag.h"
#include "go_asm.h"
#include "abi_arm64.h"
// these trampolines map the gcc ABI to Go ABI and then calls into the Go equivalent functions.
// These trampolines map the gcc ABI to Go ABIInternal and then calls into the Go equivalent functions.
// Note that C arguments are passed in R0-R7, which matches Go ABIInternal for the first eight arguments.
// R9 is used as a temporary register.
TEXT x_cgo_init_trampoline(SB), NOSPLIT, $0-0
MOVD R0, 8(RSP)
MOVD R1, 16(RSP)
MOVD ·x_cgo_init_call(SB), R26
MOVD (R26), R2
CALL (R2)
MOVD ·x_cgo_init_call(SB), R9
MOVD (R9), R9
CALL R9
RET
TEXT x_cgo_thread_start_trampoline(SB), NOSPLIT, $0-0
MOVD R0, 8(RSP)
MOVD ·x_cgo_thread_start_call(SB), R26
MOVD (R26), R2
CALL (R2)
MOVD ·x_cgo_thread_start_call(SB), R9
MOVD (R9), R9
CALL R9
RET
TEXT x_cgo_setenv_trampoline(SB), NOSPLIT, $0-0
MOVD R0, 8(RSP)
MOVD ·x_cgo_setenv_call(SB), R26
MOVD (R26), R2
CALL (R2)
MOVD ·x_cgo_setenv_call(SB), R9
MOVD (R9), R9
CALL R9
RET
TEXT x_cgo_unsetenv_trampoline(SB), NOSPLIT, $0-0
MOVD R0, 8(RSP)
MOVD ·x_cgo_unsetenv_call(SB), R26
MOVD (R26), R2
CALL (R2)
MOVD ·x_cgo_unsetenv_call(SB), R9
MOVD (R9), R9
CALL R9
RET
TEXT x_cgo_notify_runtime_init_done_trampoline(SB), NOSPLIT, $0-0
@@ -48,25 +46,39 @@ TEXT x_cgo_bindm_trampoline(SB), NOSPLIT, $0
// func setg_trampoline(setg uintptr, g uintptr)
TEXT ·setg_trampoline(SB), NOSPLIT, $0-16
MOVD G+8(FP), R0
MOVD setg+0(FP), R1
CALL R1
MOVD setg+0(FP), R9
CALL R9
RET
TEXT threadentry_trampoline(SB), NOSPLIT, $0-0
MOVD R0, 8(RSP)
MOVD ·threadentry_call(SB), R26
MOVD (R26), R2
CALL (R2)
MOVD $0, R0 // TODO: get the return value from threadentry
// See crosscall2.
SUB $(8*24), RSP
STP (R0, R1), (8*1)(RSP)
MOVD R3, (8*3)(RSP)
SAVE_R19_TO_R28(8*4)
SAVE_F8_TO_F15(8*14)
STP (R29, R30), (8*22)(RSP)
MOVD ·threadentry_call(SB), R9
MOVD (R9), R9
CALL R9
MOVD $0, R0 // TODO: get the return value from threadentry
RESTORE_R19_TO_R28(8*4)
RESTORE_F8_TO_F15(8*14)
LDP (8*22)(RSP), (R29, R30)
ADD $(8*24), RSP
RET
TEXT ·call5(SB), NOSPLIT, $0-0
MOVD fn+0(FP), R6
MOVD fn+0(FP), R9
MOVD a1+8(FP), R0
MOVD a2+16(FP), R1
MOVD a3+24(FP), R2
MOVD a4+32(FP), R3
MOVD a5+40(FP), R4
CALL R6
CALL R9
MOVD R0, ret+48(FP)
RET
@@ -0,0 +1,88 @@
// SPDX-License-Identifier: Apache-2.0
// SPDX-FileCopyrightText: 2025 The Ebitengine Authors
//go:build !cgo && linux
#include "textflag.h"
#include "go_asm.h"
#include "abi_loong64.h"
// these trampolines map the gcc ABI to Go ABI and then calls into the Go equivalent functions.
// R23 is used as temporary register.
TEXT x_cgo_init_trampoline(SB), NOSPLIT, $16
MOVV R4, 8(R3)
MOVV R5, 16(R3)
MOVV ·x_cgo_init_call(SB), R23
MOVV (R23), R23
CALL (R23)
RET
TEXT x_cgo_thread_start_trampoline(SB), NOSPLIT, $8
MOVV R4, 8(R3)
MOVV ·x_cgo_thread_start_call(SB), R23
MOVV (R23), R23
CALL (R23)
RET
TEXT x_cgo_setenv_trampoline(SB), NOSPLIT, $8
MOVV R4, 8(R3)
MOVV ·x_cgo_setenv_call(SB), R23
MOVV (R23), R23
CALL (R23)
RET
TEXT x_cgo_unsetenv_trampoline(SB), NOSPLIT, $8
MOVV R4, 8(R3)
MOVV ·x_cgo_unsetenv_call(SB), R23
MOVV (R23), R23
CALL (R23)
RET
TEXT x_cgo_notify_runtime_init_done_trampoline(SB), NOSPLIT, $0
CALL ·x_cgo_notify_runtime_init_done(SB)
RET
TEXT x_cgo_bindm_trampoline(SB), NOSPLIT, $0
CALL ·x_cgo_bindm(SB)
RET
// func setg_trampoline(setg uintptr, g uintptr)
TEXT ·setg_trampoline(SB), NOSPLIT, $0
MOVV G+8(FP), R4
MOVV setg+0(FP), R23
CALL (R23)
RET
TEXT threadentry_trampoline(SB), NOSPLIT, $0
// See crosscall2.
ADDV $(-23*8), R3
MOVV R4, (1*8)(R3) // fn unsafe.Pointer
MOVV R5, (2*8)(R3) // a unsafe.Pointer
MOVV R7, (3*8)(R3) // ctxt uintptr
SAVE_R22_TO_R31((4*8))
SAVE_F24_TO_F31((14*8))
MOVV R1, (22*8)(R3)
MOVV ·threadentry_call(SB), R23
MOVV (R23), R23
CALL (R23)
RESTORE_R22_TO_R31((4*8))
RESTORE_F24_TO_F31((14*8))
MOVV (22*8)(R3), R1
ADDV $(23*8), R3
RET
TEXT ·call5(SB), NOSPLIT, $0-0
MOVV fn+0(FP), R23
MOVV a1+8(FP), R4
MOVV a2+16(FP), R5
MOVV a3+24(FP), R6
MOVV a4+32(FP), R7
MOVV a5+40(FP), R8
CALL (R23)
MOVV R4, ret+48(FP)
RET
@@ -0,0 +1,227 @@
// SPDX-License-Identifier: Apache-2.0
// SPDX-FileCopyrightText: 2026 The Ebitengine Authors
//go:build !cgo && linux
#include "textflag.h"
#include "go_asm.h"
// These trampolines map the C ABI to Go ABI and call into the Go equivalent functions.
//
// PPC64LE ELFv2 ABI stack frame layout:
// 0(R1) = backchain (pointer to caller's frame)
// 8(R1) = CR save area
// 16(R1) = LR save area
// 24(R1) = reserved
// 32(R1) = parameter save area (minimum 64 bytes for 8 args)
//
// Two patterns are used depending on call direction:
//
// CGo trampolines: The C caller already provides a 32-byte linkage area.
// Save LR/CR into caller's frame at 16(R1)/8(R1) BEFORE allocating,
// then use MOVDU to allocate and set backchain atomically.
//
// GoC trampolines: Go callers don't provide ELFv2 linkage area.
// Allocate frame first with MOVDU, then save LR/CR into OUR frame.
TEXT x_cgo_init_trampoline(SB), NOSPLIT|NOFRAME, $0-0
MOVD LR, 16(R1)
MOVW CR, R0
MOVD R0, 8(R1)
MOVDU R1, -32(R1)
// R3, R4 already have the arguments
MOVD ·x_cgo_init_call(SB), R12
MOVD (R12), R12
MOVD R12, CTR
CALL CTR
ADD $32, R1
MOVD 16(R1), LR
MOVD 8(R1), R0
MOVW R0, CR
RET
TEXT x_cgo_thread_start_trampoline(SB), NOSPLIT|NOFRAME, $0-0
MOVD LR, 16(R1)
MOVW CR, R0
MOVD R0, 8(R1)
MOVDU R1, -32(R1)
MOVD ·x_cgo_thread_start_call(SB), R12
MOVD (R12), R12
MOVD R12, CTR
CALL CTR
ADD $32, R1
MOVD 16(R1), LR
MOVD 8(R1), R0
MOVW R0, CR
RET
// void (*_cgo_setenv)(char**)
// C arg: R3 = pointer to env
// This is CGo: caller is C ABI.
TEXT x_cgo_setenv_trampoline(SB), NOSPLIT|NOFRAME, $0-0
MOVD LR, 16(R1)
MOVW CR, R0
MOVD R0, 8(R1)
MOVDU R1, -32(R1)
MOVD ·x_cgo_setenv_call(SB), R12
MOVD (R12), R12
MOVD R12, CTR
CALL CTR
ADD $32, R1
MOVD 16(R1), LR
MOVD 8(R1), R0
MOVW R0, CR
RET
TEXT x_cgo_unsetenv_trampoline(SB), NOSPLIT|NOFRAME, $0-0
MOVD LR, 16(R1)
MOVW CR, R0
MOVD R0, 8(R1)
MOVDU R1, -32(R1)
MOVD ·x_cgo_unsetenv_call(SB), R12
MOVD (R12), R12
MOVD R12, CTR
CALL CTR
ADD $32, R1
MOVD 16(R1), LR
MOVD 8(R1), R0
MOVW R0, CR
RET
TEXT x_cgo_notify_runtime_init_done_trampoline(SB), NOSPLIT|NOFRAME, $0-0
MOVD LR, 16(R1)
MOVW CR, R0
MOVD R0, 8(R1)
MOVDU R1, -32(R1)
CALL ·x_cgo_notify_runtime_init_done(SB)
ADD $32, R1
MOVD 16(R1), LR
MOVD 8(R1), R0
MOVW R0, CR
RET
TEXT x_cgo_bindm_trampoline(SB), NOSPLIT|NOFRAME, $0-0
MOVD LR, 16(R1)
MOVW CR, R0
MOVD R0, 8(R1)
MOVDU R1, -32(R1)
CALL ·x_cgo_bindm(SB)
ADD $32, R1
MOVD 16(R1), LR
MOVD 8(R1), R0
MOVW R0, CR
RET
TEXT ·setg_trampoline(SB), NOSPLIT|NOFRAME, $0-16
// Save LR, CR, and R31 to non-volatile registers (C ABI preserves R14-R31)
MOVD LR, R20
MOVW CR, R21
MOVD R31, R22 // save R31 because load_g clobbers it
// Load arguments from Go stack
MOVD 32(R1), R12 // setg function pointer
MOVD 40(R1), R3 // g pointer first C arg
// Allocate ELFv2 frame for the C callee (32 bytes minimum)
MOVDU R1, -32(R1)
// Call setg_gcc which stores g to TLS
MOVD R12, CTR
CALL CTR
// setg_gcc stored g to TLS but restored old g in R30.
// Call load_g to reload g from TLS into R30.
// Note: load_g clobbers R31
CALL runtime·load_g(SB)
// Deallocate frame
ADD $32, R1
// Clear R0 before returning to Go code.
// Go uses R0 as a constant 0 for things like "std r0,X(r1)" to zero stack locations.
// C/assembly functions may leave garbage in R0.
XOR R0, R0, R0
// Restore LR, CR, and R31 from non-volatile registers
MOVD R22, R31 // restore R31
MOVD R20, LR
MOVW R21, CR
RET
TEXT threadentry_trampoline(SB), NOSPLIT|NOFRAME, $0-0
MOVD LR, 16(R1)
MOVW CR, R0
MOVD R0, 8(R1)
MOVDU R1, -32(R1)
MOVD ·threadentry_call(SB), R12
MOVD (R12), R12
MOVD R12, CTR
CALL CTR
ADD $32, R1
MOVD 16(R1), LR
MOVD 8(R1), R0
MOVW R0, CR
RET
TEXT ·call5(SB), NOSPLIT|NOFRAME, $0-56
MOVD LR, R20
MOVW CR, R21
// Load arguments from Go stack into C argument registers
// Go placed args at 32(R1), 40(R1), etc.
MOVD 32(R1), R12 // fn
MOVD 40(R1), R3 // a1 first C arg
MOVD 48(R1), R4 // a2 second C arg
MOVD 56(R1), R5 // a3 third C arg
MOVD 64(R1), R6 // a4 fourth C arg
MOVD 72(R1), R7 // a5 fifth C arg
MOVDU R1, -32(R1)
MOVD R12, CTR
CALL CTR
// Store return value
// After MOVDU -32, original 80(R1) is now at 80+32=112(R1)
MOVD R3, (80+32)(R1)
// Deallocate frame
ADD $32, R1
// Clear R0 before returning to Go code.
// Go uses R0 as a constant 0 register for things like "std r0,X(r1)"
// to zero stack locations. C functions may leave garbage in R0.
XOR R0, R0, R0
// Restore LR/CR from non-volatile registers
MOVD R20, LR
MOVW R21, CR
RET
@@ -0,0 +1,72 @@
// SPDX-License-Identifier: Apache-2.0
// SPDX-FileCopyrightText: 2026 The Ebitengine Authors
//go:build !cgo && linux
#include "textflag.h"
#include "go_asm.h"
// these trampolines map the gcc ABI to Go ABI and then calls into the Go equivalent functions.
// X5 is used as temporary register.
TEXT x_cgo_init_trampoline(SB), NOSPLIT, $16
MOV X10, 8(SP)
MOV X11, 16(SP)
MOV ·x_cgo_init_call(SB), X5
MOV (X5), X5
CALL X5
RET
TEXT x_cgo_thread_start_trampoline(SB), NOSPLIT, $8
MOV X10, 8(SP)
MOV ·x_cgo_thread_start_call(SB), X5
MOV (X5), X5
CALL X5
RET
TEXT x_cgo_setenv_trampoline(SB), NOSPLIT, $8
MOV X10, 8(SP)
MOV ·x_cgo_setenv_call(SB), X5
MOV (X5), X5
CALL X5
RET
TEXT x_cgo_unsetenv_trampoline(SB), NOSPLIT, $8
MOV X10, 8(SP)
MOV ·x_cgo_unsetenv_call(SB), X5
MOV (X5), X5
CALL X5
RET
TEXT x_cgo_notify_runtime_init_done_trampoline(SB), NOSPLIT, $0
CALL ·x_cgo_notify_runtime_init_done(SB)
RET
TEXT x_cgo_bindm_trampoline(SB), NOSPLIT, $0
CALL ·x_cgo_bindm(SB)
RET
// func setg_trampoline(setg uintptr, g uintptr)
TEXT ·setg_trampoline(SB), NOSPLIT, $0
MOV gp+8(FP), X10
MOV setg+0(FP), X5
CALL X5
RET
TEXT threadentry_trampoline(SB), NOSPLIT, $16
MOV X10, 8(SP)
MOV ·threadentry_call(SB), X5
MOV (X5), X5
CALL X5
RET
TEXT ·call5(SB), NOSPLIT, $0-48
MOV fn+0(FP), X5
MOV a1+8(FP), X10
MOV a2+16(FP), X11
MOV a3+24(FP), X12
MOV a4+32(FP), X13
MOV a5+40(FP), X14
CALL X5
MOV X10, ret+48(FP)
RET
@@ -3,7 +3,7 @@
// SPDX-License-Identifier: Apache-2.0
// SPDX-FileCopyrightText: 2022 The Ebitengine Authors
//go:build !cgo && (darwin || freebsd || linux)
//go:build !cgo && (darwin || freebsd || linux || netbsd)
package fakecgo
@@ -12,12 +12,6 @@ import (
"unsafe"
)
// setg_trampoline calls setg with the G provided
func setg_trampoline(setg uintptr, G uintptr)
// call5 takes fn the C function and 5 arguments and calls the function with those arguments
func call5(fn, a1, a2, a3, a4, a5 uintptr) uintptr
//go:nosplit
//go:norace
func malloc(size uintptr) unsafe.Pointer {
@@ -86,36 +80,6 @@ func pthread_sigmask(how sighow, ign *sigset_t, oset *sigset_t) int32 {
return int32(call5(pthread_sigmaskABI0, uintptr(how), uintptr(unsafe.Pointer(ign)), uintptr(unsafe.Pointer(oset)), 0, 0))
}
//go:nosplit
//go:norace
func pthread_self() pthread_t {
return pthread_t(call5(pthread_selfABI0, 0, 0, 0, 0, 0))
}
//go:nosplit
//go:norace
func pthread_get_stacksize_np(thread pthread_t) size_t {
return size_t(call5(pthread_get_stacksize_npABI0, uintptr(thread), 0, 0, 0, 0))
}
//go:nosplit
//go:norace
func pthread_attr_getstacksize(attr *pthread_attr_t, stacksize *size_t) int32 {
return int32(call5(pthread_attr_getstacksizeABI0, uintptr(unsafe.Pointer(attr)), uintptr(unsafe.Pointer(stacksize)), 0, 0, 0))
}
//go:nosplit
//go:norace
func pthread_attr_setstacksize(attr *pthread_attr_t, size size_t) int32 {
return int32(call5(pthread_attr_setstacksizeABI0, uintptr(unsafe.Pointer(attr)), uintptr(size), 0, 0, 0))
}
//go:nosplit
//go:norace
func pthread_attr_destroy(attr *pthread_attr_t) int32 {
return int32(call5(pthread_attr_destroyABI0, uintptr(unsafe.Pointer(attr)), 0, 0, 0, 0))
}
//go:nosplit
//go:norace
func pthread_mutex_lock(mutex *pthread_mutex_t) int32 {
@@ -184,26 +148,6 @@ var pthread_detachABI0 = uintptr(unsafe.Pointer(&_pthread_detach))
var _pthread_sigmask uint8
var pthread_sigmaskABI0 = uintptr(unsafe.Pointer(&_pthread_sigmask))
//go:linkname _pthread_self _pthread_self
var _pthread_self uint8
var pthread_selfABI0 = uintptr(unsafe.Pointer(&_pthread_self))
//go:linkname _pthread_get_stacksize_np _pthread_get_stacksize_np
var _pthread_get_stacksize_np uint8
var pthread_get_stacksize_npABI0 = uintptr(unsafe.Pointer(&_pthread_get_stacksize_np))
//go:linkname _pthread_attr_getstacksize _pthread_attr_getstacksize
var _pthread_attr_getstacksize uint8
var pthread_attr_getstacksizeABI0 = uintptr(unsafe.Pointer(&_pthread_attr_getstacksize))
//go:linkname _pthread_attr_setstacksize _pthread_attr_setstacksize
var _pthread_attr_setstacksize uint8
var pthread_attr_setstacksizeABI0 = uintptr(unsafe.Pointer(&_pthread_attr_setstacksize))
//go:linkname _pthread_attr_destroy _pthread_attr_destroy
var _pthread_attr_destroy uint8
var pthread_attr_destroyABI0 = uintptr(unsafe.Pointer(&_pthread_attr_destroy))
//go:linkname _pthread_mutex_lock _pthread_mutex_lock
var _pthread_mutex_lock uint8
var pthread_mutex_lockABI0 = uintptr(unsafe.Pointer(&_pthread_mutex_lock))
@@ -7,6 +7,8 @@
package fakecgo
import "unsafe"
//go:cgo_import_dynamic purego_malloc malloc "/usr/lib/libSystem.B.dylib"
//go:cgo_import_dynamic purego_free free "/usr/lib/libSystem.B.dylib"
//go:cgo_import_dynamic purego_setenv setenv "/usr/lib/libSystem.B.dylib"
@@ -18,12 +20,40 @@ package fakecgo
//go:cgo_import_dynamic purego_pthread_create pthread_create "/usr/lib/libSystem.B.dylib"
//go:cgo_import_dynamic purego_pthread_detach pthread_detach "/usr/lib/libSystem.B.dylib"
//go:cgo_import_dynamic purego_pthread_sigmask pthread_sigmask "/usr/lib/libSystem.B.dylib"
//go:cgo_import_dynamic purego_pthread_self pthread_self "/usr/lib/libSystem.B.dylib"
//go:cgo_import_dynamic purego_pthread_get_stacksize_np pthread_get_stacksize_np "/usr/lib/libSystem.B.dylib"
//go:cgo_import_dynamic purego_pthread_attr_getstacksize pthread_attr_getstacksize "/usr/lib/libSystem.B.dylib"
//go:cgo_import_dynamic purego_pthread_attr_setstacksize pthread_attr_setstacksize "/usr/lib/libSystem.B.dylib"
//go:cgo_import_dynamic purego_pthread_attr_destroy pthread_attr_destroy "/usr/lib/libSystem.B.dylib"
//go:cgo_import_dynamic purego_pthread_mutex_lock pthread_mutex_lock "/usr/lib/libSystem.B.dylib"
//go:cgo_import_dynamic purego_pthread_mutex_unlock pthread_mutex_unlock "/usr/lib/libSystem.B.dylib"
//go:cgo_import_dynamic purego_pthread_cond_broadcast pthread_cond_broadcast "/usr/lib/libSystem.B.dylib"
//go:cgo_import_dynamic purego_pthread_setspecific pthread_setspecific "/usr/lib/libSystem.B.dylib"
//go:cgo_import_dynamic purego_pthread_self pthread_self "/usr/lib/libSystem.B.dylib"
//go:cgo_import_dynamic purego_pthread_get_stacksize_np pthread_get_stacksize_np "/usr/lib/libSystem.B.dylib"
//go:cgo_import_dynamic purego_pthread_attr_setstacksize pthread_attr_setstacksize "/usr/lib/libSystem.B.dylib"
//go:nosplit
//go:norace
func pthread_self() pthread_t {
return pthread_t(call5(pthread_selfABI0, 0, 0, 0, 0, 0))
}
//go:nosplit
//go:norace
func pthread_get_stacksize_np(thread pthread_t) size_t {
return size_t(call5(pthread_get_stacksize_npABI0, uintptr(thread), 0, 0, 0, 0))
}
//go:nosplit
//go:norace
func pthread_attr_setstacksize(attr *pthread_attr_t, size size_t) int32 {
return int32(call5(pthread_attr_setstacksizeABI0, uintptr(unsafe.Pointer(attr)), uintptr(size), 0, 0, 0))
}
//go:linkname _pthread_self _pthread_self
var _pthread_self uint8
var pthread_selfABI0 = uintptr(unsafe.Pointer(&_pthread_self))
//go:linkname _pthread_get_stacksize_np _pthread_get_stacksize_np
var _pthread_get_stacksize_np uint8
var pthread_get_stacksize_npABI0 = uintptr(unsafe.Pointer(&_pthread_get_stacksize_np))
//go:linkname _pthread_attr_setstacksize _pthread_attr_setstacksize
var _pthread_attr_setstacksize uint8
var pthread_attr_setstacksizeABI0 = uintptr(unsafe.Pointer(&_pthread_attr_setstacksize))
@@ -7,6 +7,8 @@
package fakecgo
import "unsafe"
//go:cgo_import_dynamic purego_malloc malloc "libc.so.7"
//go:cgo_import_dynamic purego_free free "libc.so.7"
//go:cgo_import_dynamic purego_setenv setenv "libc.so.7"
@@ -18,12 +20,29 @@ package fakecgo
//go:cgo_import_dynamic purego_pthread_create pthread_create "libpthread.so"
//go:cgo_import_dynamic purego_pthread_detach pthread_detach "libpthread.so"
//go:cgo_import_dynamic purego_pthread_sigmask pthread_sigmask "libpthread.so"
//go:cgo_import_dynamic purego_pthread_self pthread_self "libpthread.so"
//go:cgo_import_dynamic purego_pthread_get_stacksize_np pthread_get_stacksize_np "libpthread.so"
//go:cgo_import_dynamic purego_pthread_attr_getstacksize pthread_attr_getstacksize "libpthread.so"
//go:cgo_import_dynamic purego_pthread_attr_setstacksize pthread_attr_setstacksize "libpthread.so"
//go:cgo_import_dynamic purego_pthread_attr_destroy pthread_attr_destroy "libpthread.so"
//go:cgo_import_dynamic purego_pthread_mutex_lock pthread_mutex_lock "libpthread.so"
//go:cgo_import_dynamic purego_pthread_mutex_unlock pthread_mutex_unlock "libpthread.so"
//go:cgo_import_dynamic purego_pthread_cond_broadcast pthread_cond_broadcast "libpthread.so"
//go:cgo_import_dynamic purego_pthread_setspecific pthread_setspecific "libpthread.so"
//go:cgo_import_dynamic purego_pthread_attr_getstacksize pthread_attr_getstacksize "libpthread.so"
//go:cgo_import_dynamic purego_pthread_attr_destroy pthread_attr_destroy "libpthread.so"
//go:nosplit
//go:norace
func pthread_attr_getstacksize(attr *pthread_attr_t, stacksize *size_t) int32 {
return int32(call5(pthread_attr_getstacksizeABI0, uintptr(unsafe.Pointer(attr)), uintptr(unsafe.Pointer(stacksize)), 0, 0, 0))
}
//go:nosplit
//go:norace
func pthread_attr_destroy(attr *pthread_attr_t) int32 {
return int32(call5(pthread_attr_destroyABI0, uintptr(unsafe.Pointer(attr)), 0, 0, 0, 0))
}
//go:linkname _pthread_attr_getstacksize _pthread_attr_getstacksize
var _pthread_attr_getstacksize uint8
var pthread_attr_getstacksizeABI0 = uintptr(unsafe.Pointer(&_pthread_attr_getstacksize))
//go:linkname _pthread_attr_destroy _pthread_attr_destroy
var _pthread_attr_destroy uint8
var pthread_attr_destroyABI0 = uintptr(unsafe.Pointer(&_pthread_attr_destroy))
@@ -7,6 +7,8 @@
package fakecgo
import "unsafe"
//go:cgo_import_dynamic purego_malloc malloc "libc.so.6"
//go:cgo_import_dynamic purego_free free "libc.so.6"
//go:cgo_import_dynamic purego_setenv setenv "libc.so.6"
@@ -18,12 +20,29 @@ package fakecgo
//go:cgo_import_dynamic purego_pthread_create pthread_create "libpthread.so.0"
//go:cgo_import_dynamic purego_pthread_detach pthread_detach "libpthread.so.0"
//go:cgo_import_dynamic purego_pthread_sigmask pthread_sigmask "libpthread.so.0"
//go:cgo_import_dynamic purego_pthread_self pthread_self "libpthread.so.0"
//go:cgo_import_dynamic purego_pthread_get_stacksize_np pthread_get_stacksize_np "libpthread.so.0"
//go:cgo_import_dynamic purego_pthread_attr_getstacksize pthread_attr_getstacksize "libpthread.so.0"
//go:cgo_import_dynamic purego_pthread_attr_setstacksize pthread_attr_setstacksize "libpthread.so.0"
//go:cgo_import_dynamic purego_pthread_attr_destroy pthread_attr_destroy "libpthread.so.0"
//go:cgo_import_dynamic purego_pthread_mutex_lock pthread_mutex_lock "libpthread.so.0"
//go:cgo_import_dynamic purego_pthread_mutex_unlock pthread_mutex_unlock "libpthread.so.0"
//go:cgo_import_dynamic purego_pthread_cond_broadcast pthread_cond_broadcast "libpthread.so.0"
//go:cgo_import_dynamic purego_pthread_setspecific pthread_setspecific "libpthread.so.0"
//go:cgo_import_dynamic purego_pthread_attr_getstacksize pthread_attr_getstacksize "libpthread.so.0"
//go:cgo_import_dynamic purego_pthread_attr_destroy pthread_attr_destroy "libpthread.so.0"
//go:nosplit
//go:norace
func pthread_attr_getstacksize(attr *pthread_attr_t, stacksize *size_t) int32 {
return int32(call5(pthread_attr_getstacksizeABI0, uintptr(unsafe.Pointer(attr)), uintptr(unsafe.Pointer(stacksize)), 0, 0, 0))
}
//go:nosplit
//go:norace
func pthread_attr_destroy(attr *pthread_attr_t) int32 {
return int32(call5(pthread_attr_destroyABI0, uintptr(unsafe.Pointer(attr)), 0, 0, 0, 0))
}
//go:linkname _pthread_attr_getstacksize _pthread_attr_getstacksize
var _pthread_attr_getstacksize uint8
var pthread_attr_getstacksizeABI0 = uintptr(unsafe.Pointer(&_pthread_attr_getstacksize))
//go:linkname _pthread_attr_destroy _pthread_attr_destroy
var _pthread_attr_destroy uint8
var pthread_attr_destroyABI0 = uintptr(unsafe.Pointer(&_pthread_attr_destroy))
@@ -0,0 +1,59 @@
// Code generated by 'go generate' with gen.go. DO NOT EDIT.
// SPDX-License-Identifier: Apache-2.0
// SPDX-FileCopyrightText: 2022 The Ebitengine Authors
//go:build !cgo
package fakecgo
import "unsafe"
//go:cgo_import_dynamic purego_malloc malloc "libc.so"
//go:cgo_import_dynamic purego_free free "libc.so"
//go:cgo_import_dynamic purego_setenv setenv "libc.so"
//go:cgo_import_dynamic purego_unsetenv unsetenv "libc.so"
//go:cgo_import_dynamic purego_sigfillset sigfillset "libc.so"
//go:cgo_import_dynamic purego_nanosleep nanosleep "libc.so"
//go:cgo_import_dynamic purego_abort abort "libc.so"
//go:cgo_import_dynamic purego_sigaltstack sigaltstack "libc.so"
//go:cgo_import_dynamic purego_pthread_attr_init pthread_attr_init "libpthread.so"
//go:cgo_import_dynamic purego_pthread_create pthread_create "libpthread.so"
//go:cgo_import_dynamic purego_pthread_detach pthread_detach "libpthread.so"
//go:cgo_import_dynamic purego_pthread_sigmask pthread_sigmask "libpthread.so"
//go:cgo_import_dynamic purego_pthread_mutex_lock pthread_mutex_lock "libpthread.so"
//go:cgo_import_dynamic purego_pthread_mutex_unlock pthread_mutex_unlock "libpthread.so"
//go:cgo_import_dynamic purego_pthread_cond_broadcast pthread_cond_broadcast "libpthread.so"
//go:cgo_import_dynamic purego_pthread_setspecific pthread_setspecific "libpthread.so"
//go:cgo_import_dynamic purego_pthread_attr_getstacksize pthread_attr_getstacksize "libpthread.so"
//go:cgo_import_dynamic purego_pthread_attr_destroy pthread_attr_destroy "libpthread.so"
//go:nosplit
//go:norace
func sigaltstack(ss *stack_t, old_ss *stack_t) int32 {
return int32(call5(sigaltstackABI0, uintptr(unsafe.Pointer(ss)), uintptr(unsafe.Pointer(old_ss)), 0, 0, 0))
}
//go:nosplit
//go:norace
func pthread_attr_getstacksize(attr *pthread_attr_t, stacksize *size_t) int32 {
return int32(call5(pthread_attr_getstacksizeABI0, uintptr(unsafe.Pointer(attr)), uintptr(unsafe.Pointer(stacksize)), 0, 0, 0))
}
//go:nosplit
//go:norace
func pthread_attr_destroy(attr *pthread_attr_t) int32 {
return int32(call5(pthread_attr_destroyABI0, uintptr(unsafe.Pointer(attr)), 0, 0, 0, 0))
}
//go:linkname _sigaltstack _sigaltstack
var _sigaltstack uint8
var sigaltstackABI0 = uintptr(unsafe.Pointer(&_sigaltstack))
//go:linkname _pthread_attr_getstacksize _pthread_attr_getstacksize
var _pthread_attr_getstacksize uint8
var pthread_attr_getstacksizeABI0 = uintptr(unsafe.Pointer(&_pthread_attr_getstacksize))
//go:linkname _pthread_attr_destroy _pthread_attr_destroy
var _pthread_attr_destroy uint8
var pthread_attr_destroyABI0 = uintptr(unsafe.Pointer(&_pthread_attr_destroy))
@@ -0,0 +1,19 @@
// Code generated by 'go generate' with gen.go. DO NOT EDIT.
// SPDX-License-Identifier: Apache-2.0
// SPDX-FileCopyrightText: 2022 The Ebitengine Authors
//go:build !cgo
#include "textflag.h"
// these stubs are here because it is not possible to go:linkname directly the C functions
TEXT _pthread_self(SB), NOSPLIT|NOFRAME, $0-0
JMP purego_pthread_self(SB)
TEXT _pthread_get_stacksize_np(SB), NOSPLIT|NOFRAME, $0-0
JMP purego_pthread_get_stacksize_np(SB)
TEXT _pthread_attr_setstacksize(SB), NOSPLIT|NOFRAME, $0-0
JMP purego_pthread_attr_setstacksize(SB)
@@ -0,0 +1,16 @@
// Code generated by 'go generate' with gen.go. DO NOT EDIT.
// SPDX-License-Identifier: Apache-2.0
// SPDX-FileCopyrightText: 2022 The Ebitengine Authors
//go:build !cgo
#include "textflag.h"
// these stubs are here because it is not possible to go:linkname directly the C functions
TEXT _pthread_attr_getstacksize(SB), NOSPLIT|NOFRAME, $0-0
JMP purego_pthread_attr_getstacksize(SB)
TEXT _pthread_attr_destroy(SB), NOSPLIT|NOFRAME, $0-0
JMP purego_pthread_attr_destroy(SB)
@@ -0,0 +1,16 @@
// Code generated by 'go generate' with gen.go. DO NOT EDIT.
// SPDX-License-Identifier: Apache-2.0
// SPDX-FileCopyrightText: 2022 The Ebitengine Authors
//go:build !cgo
#include "textflag.h"
// these stubs are here because it is not possible to go:linkname directly the C functions
TEXT _pthread_attr_getstacksize(SB), NOSPLIT|NOFRAME, $0-0
JMP purego_pthread_attr_getstacksize(SB)
TEXT _pthread_attr_destroy(SB), NOSPLIT|NOFRAME, $0-0
JMP purego_pthread_attr_destroy(SB)
@@ -0,0 +1,19 @@
// Code generated by 'go generate' with gen.go. DO NOT EDIT.
// SPDX-License-Identifier: Apache-2.0
// SPDX-FileCopyrightText: 2022 The Ebitengine Authors
//go:build !cgo
#include "textflag.h"
// these stubs are here because it is not possible to go:linkname directly the C functions
TEXT _sigaltstack(SB), NOSPLIT|NOFRAME, $0-0
JMP purego_sigaltstack(SB)
TEXT _pthread_attr_getstacksize(SB), NOSPLIT|NOFRAME, $0-0
JMP purego_pthread_attr_getstacksize(SB)
TEXT _pthread_attr_destroy(SB), NOSPLIT|NOFRAME, $0-0
JMP purego_pthread_attr_destroy(SB)
@@ -3,88 +3,53 @@
// SPDX-License-Identifier: Apache-2.0
// SPDX-FileCopyrightText: 2022 The Ebitengine Authors
//go:build !cgo && (darwin || freebsd || linux)
//go:build !cgo && (darwin || freebsd || linux || netbsd)
#include "textflag.h"
// these stubs are here because it is not possible to go:linkname directly the C functions on darwin arm64
// these stubs are here because it is not possible to go:linkname directly the C functions
TEXT _malloc(SB), NOSPLIT|NOFRAME, $0-0
JMP purego_malloc(SB)
RET
TEXT _free(SB), NOSPLIT|NOFRAME, $0-0
JMP purego_free(SB)
RET
TEXT _setenv(SB), NOSPLIT|NOFRAME, $0-0
JMP purego_setenv(SB)
RET
TEXT _unsetenv(SB), NOSPLIT|NOFRAME, $0-0
JMP purego_unsetenv(SB)
RET
TEXT _sigfillset(SB), NOSPLIT|NOFRAME, $0-0
JMP purego_sigfillset(SB)
RET
TEXT _nanosleep(SB), NOSPLIT|NOFRAME, $0-0
JMP purego_nanosleep(SB)
RET
TEXT _abort(SB), NOSPLIT|NOFRAME, $0-0
JMP purego_abort(SB)
RET
TEXT _pthread_attr_init(SB), NOSPLIT|NOFRAME, $0-0
JMP purego_pthread_attr_init(SB)
RET
TEXT _pthread_create(SB), NOSPLIT|NOFRAME, $0-0
JMP purego_pthread_create(SB)
RET
TEXT _pthread_detach(SB), NOSPLIT|NOFRAME, $0-0
JMP purego_pthread_detach(SB)
RET
TEXT _pthread_sigmask(SB), NOSPLIT|NOFRAME, $0-0
JMP purego_pthread_sigmask(SB)
RET
TEXT _pthread_self(SB), NOSPLIT|NOFRAME, $0-0
JMP purego_pthread_self(SB)
RET
TEXT _pthread_get_stacksize_np(SB), NOSPLIT|NOFRAME, $0-0
JMP purego_pthread_get_stacksize_np(SB)
RET
TEXT _pthread_attr_getstacksize(SB), NOSPLIT|NOFRAME, $0-0
JMP purego_pthread_attr_getstacksize(SB)
RET
TEXT _pthread_attr_setstacksize(SB), NOSPLIT|NOFRAME, $0-0
JMP purego_pthread_attr_setstacksize(SB)
RET
TEXT _pthread_attr_destroy(SB), NOSPLIT|NOFRAME, $0-0
JMP purego_pthread_attr_destroy(SB)
RET
TEXT _pthread_mutex_lock(SB), NOSPLIT|NOFRAME, $0-0
JMP purego_pthread_mutex_lock(SB)
RET
TEXT _pthread_mutex_unlock(SB), NOSPLIT|NOFRAME, $0-0
JMP purego_pthread_mutex_unlock(SB)
RET
TEXT _pthread_cond_broadcast(SB), NOSPLIT|NOFRAME, $0-0
JMP purego_pthread_cond_broadcast(SB)
RET
TEXT _pthread_setspecific(SB), NOSPLIT|NOFRAME, $0-0
JMP purego_pthread_setspecific(SB)
RET
+15
View File
@@ -0,0 +1,15 @@
// SPDX-License-Identifier: Apache-2.0
// SPDX-FileCopyrightText: 2025 The Ebitengine Authors
//go:build !go1.25
package xreflect
import "reflect"
// TODO: remove this and use Go 1.25's reflect.TypeAssert when minimum go.mod version is 1.25
func TypeAssert[T any](v reflect.Value) (T, bool) {
v2, ok := v.Interface().(T)
return v2, ok
}
+12
View File
@@ -0,0 +1,12 @@
// SPDX-License-Identifier: Apache-2.0
// SPDX-FileCopyrightText: 2025 The Ebitengine Authors
//go:build go1.25
package xreflect
import "reflect"
func TypeAssert[T any](v reflect.Value) (T, bool) {
return reflect.TypeAssert[T](v)
}