1// SPDX-License-Identifier: Apache-2.0
2// SPDX-FileCopyrightText: 2026 The Ebitengine Authors
3
4//go:build darwin || freebsd || linux || netbsd || windows
5
6package purego
7
8import (
9 "runtime"
10 "unsafe"
11)
12
13// Syscall15 calls fn with up to 15 integer-class arguments. It does not
14// allocate per call once its argument pool is warm. Unused arguments must be 0. Unlike SyscallN it does not use a
15// variadic argument slice. Like SyscallN, a uintptr converted from an
16// unsafe.Pointer in the call expression keeps its object alive and un-moved
17// for the duration of the call (go:uintptrescapes); the object escapes to
18// the heap. The C function must not retain the pointer after returning.
19// Mixed integer/float arguments are not supported, as for SyscallN.
20//
21//go:uintptrescapes
22func Syscall15(fn, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15 uintptr) (r1, r2, err uintptr) {
23 if fn == 0 {
24 panic("purego: fn is nil")
25 }
26 if runtime.GOOS == "windows" {
27 return syscall_syscallN(fn, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15)
28 }
29 // Must not live on the goroutine stack: a Go callback made by fn can move
30 // that stack, and syscallX would store results through the stale address.
31 s := thePool.Get().(*syscallArgs)
32 *s = syscallArgs{
33 fn: fn, a1: a1, a2: a2, a3: a3, a4: a4, a5: a5,
34 a6: a6, a7: a7, a8: a8, a9: a9, a10: a10,
35 a11: a11, a12: a12, a13: a13, a14: a14, a15: a15,
36 }
37 runtime_cgocall(syscallXABI0, unsafe.Pointer(s))
38 r1, r2, err = s.a1, s.a2, s.a3
39 thePool.Put(s)
40 return r1, r2, err
41}
42
43// Syscall6 is Syscall15 with six arguments. Like Syscall15, pointer-derived
44// uintptr arguments keep their objects alive and cause them to escape.
45//
46//go:uintptrescapes
47func Syscall6(fn, a1, a2, a3, a4, a5, a6 uintptr) (r1, r2, err uintptr) {
48 return Syscall15(fn, a1, a2, a3, a4, a5, a6, 0, 0, 0, 0, 0, 0, 0, 0, 0)
49}