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//go:noescape
14//go:linkname noescapeFixed runtime.noescape
15func noescapeFixed(p unsafe.Pointer) unsafe.Pointer
16
17// Syscall15 calls fn with up to 15 integer-class arguments without
18// allocating. Unused arguments must be 0. Unlike SyscallN it does not use a
19// variadic argument slice. Like SyscallN, a uintptr converted from an
20// unsafe.Pointer in the call expression keeps its object alive and un-moved
21// for the duration of the call (go:uintptrescapes); the object escapes to
22// the heap. The C function must not retain the pointer after returning.
23// Mixed integer/float arguments are not supported, as for SyscallN.
24//
25//go:uintptrescapes
26func Syscall15(fn, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15 uintptr) (r1, r2, err uintptr) {
27 if fn == 0 {
28 panic("purego: fn is nil")
29 }
30 if runtime.GOOS == "windows" {
31 return syscall_syscallN(fn, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15)
32 }
33 s := syscallArgs{
34 fn: fn, a1: a1, a2: a2, a3: a3, a4: a4, a5: a5,
35 a6: a6, a7: a7, a8: a8, a9: a9, a10: a10,
36 a11: a11, a12: a12, a13: a13, a14: a14, a15: a15,
37 }
38 // cgocall is synchronous: s remains on this goroutine's stack until it returns.
39 runtime_cgocall(syscallXABI0, noescapeFixed(unsafe.Pointer(&s)))
40 return s.a1, s.a2, s.a3
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}