Skip to content

Commit b9c5f0a

Browse files
committed
purego: address review feedback
- Rename syscall15Args to syscallArgs, syscall15X to syscallX, syscall15XABI0 to syscallXABI0 throughout Go and assembly files - Remove unused syscall_syscall15X functions from syscall_unix.go, syscall_windows.go, and syscall_cgo_linux.go - Remove unnecessary float fields f9-f13 from 64-bit syscallArgs struct (only f1-f8 are used by 64-bit assembly) - Replace Set method with syscall_SyscallN function that handles pool acquisition, struct population, and cgocall in one step - Simplify func.go call site to use syscall_SyscallN directly
1 parent fa11290 commit b9c5f0a

24 files changed

Lines changed: 482 additions & 598 deletions

‎func.go‎

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ const (
2323
)
2424

2525
var thePool = sync.Pool{New: func() any {
26-
return new(syscall15Args)
26+
return new(syscallArgs)
2727
}}
2828

2929
// RegisterLibFunc is a wrapper around RegisterFunc that uses the C function returned from Dlsym(handle, name).
@@ -320,22 +320,16 @@ func RegisterFunc(fptr any, cfn uintptr) {
320320
keepAlive = addValue(v, keepAlive, addInt, addFloat, addStack, &numInts, &numFloats, &numStack)
321321
}
322322

323-
syscall := thePool.Get().(*syscall15Args)
324-
defer thePool.Put(syscall)
325-
326-
if runtime.GOARCH == "loong64" || runtime.GOARCH == "ppc64le" || runtime.GOARCH == "riscv64" || runtime.GOARCH == "s390x" {
327-
syscall.Set(cfn, sysargs[:], floats[:], 0)
328-
runtime_cgocall(syscall15XABI0, unsafe.Pointer(syscall))
329-
} else if runtime.GOARCH == "arm64" || runtime.GOOS != "windows" {
330-
// Use the normal arm64 calling convention even on Windows
331-
syscall.Set(cfn, sysargs[:], floats[:], arm64_r8)
332-
runtime_cgocall(syscall15XABI0, unsafe.Pointer(syscall))
333-
} else {
334-
*syscall = syscall15Args{}
335-
// This is a fallback for Windows amd64, 386, and arm.
323+
var syscall *syscallArgs
324+
if runtime.GOOS == "windows" && runtime.GOARCH != "arm64" {
325+
// Windows amd64, 386, and arm use syscall.SyscallN.
326+
syscall = thePool.Get().(*syscallArgs)
336327
syscall.a1, syscall.a2, _ = syscall_syscallN(cfn, sysargs[:numStack]...)
337328
syscall.f1 = syscall.a2 // on amd64 a2 stores the float return. On 32bit platforms floats aren't support
329+
} else {
330+
syscall = syscall_SyscallN(cfn, sysargs[:], floats[:], arm64_r8)
338331
}
332+
defer thePool.Put(syscall)
339333
if ty.NumOut() == 0 {
340334
return nil
341335
}

‎internal/cgo/syscall_cgo_unix.go‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@ package cgo
1616
#include <errno.h>
1717
#include <assert.h>
1818
19-
typedef struct syscall15Args {
19+
typedef struct syscallArgs {
2020
uintptr_t fn;
2121
uintptr_t a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15;
2222
uintptr_t f1, f2, f3, f4, f5, f6, f7, f8;
2323
uintptr_t err;
24-
} syscall15Args;
24+
} syscallArgs;
2525
26-
void syscall15(struct syscall15Args *args) {
26+
void syscall15(struct syscallArgs *args) {
2727
assert((args->f1|args->f2|args->f3|args->f4|args->f5|args->f6|args->f7|args->f8) == 0);
2828
uintptr_t (*func_name)(uintptr_t a1, uintptr_t a2, uintptr_t a3, uintptr_t a4, uintptr_t a5, uintptr_t a6,
2929
uintptr_t a7, uintptr_t a8, uintptr_t a9, uintptr_t a10, uintptr_t a11, uintptr_t a12,
@@ -39,12 +39,12 @@ void syscall15(struct syscall15Args *args) {
3939
import "C"
4040
import "unsafe"
4141

42-
// assign purego.syscall15XABI0 to the C version of this function.
43-
var Syscall15XABI0 = unsafe.Pointer(C.syscall15)
42+
// assign purego.syscallXABI0 to the C version of this function.
43+
var SyscallXABI0 = unsafe.Pointer(C.syscall15)
4444

4545
//go:nosplit
46-
func Syscall15X(fn, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15 uintptr) (r1, r2, err uintptr) {
47-
args := C.syscall15Args{
46+
func SyscallX(fn, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15 uintptr) (r1, r2, err uintptr) {
47+
args := C.syscallArgs{
4848
C.uintptr_t(fn), C.uintptr_t(a1), C.uintptr_t(a2), C.uintptr_t(a3),
4949
C.uintptr_t(a4), C.uintptr_t(a5), C.uintptr_t(a6),
5050
C.uintptr_t(a7), C.uintptr_t(a8), C.uintptr_t(a9), C.uintptr_t(a10), C.uintptr_t(a11), C.uintptr_t(a12),

‎struct_386.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ func addStruct(v reflect.Value, numInts, numFloats, numStack *int, addInt, addFl
1212
panic("purego: struct arguments are not supported")
1313
}
1414

15-
func getStruct(outType reflect.Type, syscall syscall15Args) (v reflect.Value) {
15+
func getStruct(outType reflect.Type, syscall syscallArgs) (v reflect.Value) {
1616
panic("purego: struct returns are not supported")
1717
}
1818

‎struct_amd64.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010
"unsafe"
1111
)
1212

13-
func getStruct(outType reflect.Type, syscall syscall15Args) (v reflect.Value) {
13+
func getStruct(outType reflect.Type, syscall syscallArgs) (v reflect.Value) {
1414
outSize := outType.Size()
1515
switch {
1616
case outSize == 0:

‎struct_arm.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ func addStruct(v reflect.Value, numInts, numFloats, numStack *int, addInt, addFl
2828
return keepAlive
2929
}
3030

31-
func getStruct(outType reflect.Type, syscall syscall15Args) (v reflect.Value) {
31+
func getStruct(outType reflect.Type, syscall syscallArgs) (v reflect.Value) {
3232
outSize := outType.Size()
3333
if outSize == 0 {
3434
return reflect.New(outType).Elem()

‎struct_arm64.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import (
1414
"github.com/ebitengine/purego/internal/strings"
1515
)
1616

17-
func getStruct(outType reflect.Type, syscall syscall15Args) (v reflect.Value) {
17+
func getStruct(outType reflect.Type, syscall syscallArgs) (v reflect.Value) {
1818
outSize := outType.Size()
1919
switch {
2020
case outSize == 0:

‎struct_loong64.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
"unsafe"
1010
)
1111

12-
func getStruct(outType reflect.Type, syscall syscall15Args) (v reflect.Value) {
12+
func getStruct(outType reflect.Type, syscall syscallArgs) (v reflect.Value) {
1313
outSize := outType.Size()
1414
switch {
1515
case outSize == 0:

‎struct_ppc64le.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88
"unsafe"
99
)
1010

11-
func getStruct(outType reflect.Type, syscall syscall15Args) reflect.Value {
11+
func getStruct(outType reflect.Type, syscall syscallArgs) reflect.Value {
1212
outSize := outType.Size()
1313

1414
switch {

‎struct_riscv64.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88
"unsafe"
99
)
1010

11-
func getStruct(outType reflect.Type, syscall syscall15Args) reflect.Value {
11+
func getStruct(outType reflect.Type, syscall syscallArgs) reflect.Value {
1212
outSize := outType.Size()
1313

1414
switch {

‎struct_s390x.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88
"unsafe"
99
)
1010

11-
func getStruct(outType reflect.Type, syscall syscall15Args) reflect.Value {
11+
func getStruct(outType reflect.Type, syscall syscallArgs) reflect.Value {
1212
outSize := outType.Size()
1313

1414
switch {

0 commit comments

Comments
 (0)