detached c0e6605

fix: align 32-bit raw syscall limits

commit
c0e6605bb442fed24f44b479974513aa30d36199
author
brice · · 2026-04-13 09:54 UTC
parent
90cebfb
signature
GPG VerifiedCD88F9E564E0102646FB6077A1A07C7C7C3E349D · arch-gpg Verified for the committer email
2 files · +42 -4
M syscall_32bit.go +6 -4
@@ -13,7 +13,7 @@ package purego
1313 type CDecl struct{}
1414
1515 const (
16- maxArgs = 32
16+ maxArgs = 15
1717 )
1818
1919 type syscall15Args struct {
@@ -78,8 +78,8 @@ func (s *syscall15Args) Set(fn uintptr, ints []uintptr, floats []uintptr, r8 uin
7878 }
7979
8080 // SyscallN takes fn, a C function pointer and a list of arguments as uintptr.
81-// There is an internal maximum number of arguments that SyscallN can take. It panics
82-// when the maximum is exceeded. It returns the result and the libc error code if there is one.
81+// On 386 and arm, SyscallN supports at most 15 uintptr arguments. It panics when
82+// the maximum is exceeded. It returns the result and the libc error code if there is one.
8383 //
8484 // In order to call this function properly make sure to follow all the rules specified in [unsafe.Pointer]
8585 // especially point 4.
@@ -111,7 +111,9 @@ func SyscallN(fn uintptr, args ...uintptr) (r1, r2, err uintptr) {
111111
112112 // SyscallSelf is like SyscallN but efficiently prepends self to args without allocation.
113113 // It is designed for method-like calls where the first argument is always a receiver pointer.
114-// This avoids the heap allocation that would occur with SyscallN(fn, append([]uintptr{self}, args...)...).
114+// It shares SyscallN's argument-placement limits, and the total count including self is
115+// limited to 15 on 386 and arm. This avoids the heap allocation that would occur with
116+// SyscallN(fn, append([]uintptr{self}, args...)...).
115117 //
116118 //go:uintptrescapes
117119 func SyscallSelf(fn, self uintptr, args ...uintptr) (r1, r2, err uintptr) {
@@ -13,7 +13,7 @@ package purego
13 type CDecl struct{}13 type CDecl struct{}
14 14
15 const (15 const (
16- maxArgs = 3216+ maxArgs = 15
17 )17 )
18 18
19 type syscall15Args struct {19 type syscall15Args struct {
@@ -78,8 +78,8 @@ func (s *syscall15Args) Set(fn uintptr, ints []uintptr, floats []uintptr, r8 uin
78 }78 }
79 79
80 // SyscallN takes fn, a C function pointer and a list of arguments as uintptr.80 // SyscallN takes fn, a C function pointer and a list of arguments as uintptr.
81-// There is an internal maximum number of arguments that SyscallN can take. It panics81+// On 386 and arm, SyscallN supports at most 15 uintptr arguments. It panics when
82-// when the maximum is exceeded. It returns the result and the libc error code if there is one.82+// the maximum is exceeded. It returns the result and the libc error code if there is one.
83 //83 //
84 // In order to call this function properly make sure to follow all the rules specified in [unsafe.Pointer]84 // In order to call this function properly make sure to follow all the rules specified in [unsafe.Pointer]
85 // especially point 4.85 // especially point 4.
@@ -111,7 +111,9 @@ func SyscallN(fn uintptr, args ...uintptr) (r1, r2, err uintptr) {
111 111
112 // SyscallSelf is like SyscallN but efficiently prepends self to args without allocation.112 // SyscallSelf is like SyscallN but efficiently prepends self to args without allocation.
113 // It is designed for method-like calls where the first argument is always a receiver pointer.113 // It is designed for method-like calls where the first argument is always a receiver pointer.
114-// This avoids the heap allocation that would occur with SyscallN(fn, append([]uintptr{self}, args...)...).114+// It shares SyscallN's argument-placement limits, and the total count including self is
115+// limited to 15 on 386 and arm. This avoids the heap allocation that would occur with
116+// SyscallN(fn, append([]uintptr{self}, args...)...).
115 //117 //
116 //go:uintptrescapes118 //go:uintptrescapes
117 func SyscallSelf(fn, self uintptr, args ...uintptr) (r1, r2, err uintptr) {119 func SyscallSelf(fn, self uintptr, args ...uintptr) (r1, r2, err uintptr) {
A syscall_32bit_test.go +36 -0
@@ -0,0 +1,36 @@
1+//go:build (386 || arm) && (freebsd || linux || netbsd || windows)
2+
3+package purego_test
4+
5+import (
6+ "fmt"
7+ "testing"
8+
9+ "github.com/ebitengine/purego"
10+)
11+
12+func TestSyscallN32BitPanicsAt16Args(t *testing.T) {
13+ defer func() {
14+ r := recover()
15+ if r == nil {
16+ t.Fatal("expected panic")
17+ }
18+ if got := fmt.Sprint(r); got != "purego: too many arguments to SyscallN" {
19+ t.Fatalf("panic = %q, want %q", got, "purego: too many arguments to SyscallN")
20+ }
21+ }()
22+ purego.SyscallN(uintptr(1), make([]uintptr, 16)...)
23+}
24+
25+func TestSyscallSelf32BitPanicsAt16Args(t *testing.T) {
26+ defer func() {
27+ r := recover()
28+ if r == nil {
29+ t.Fatal("expected panic")
30+ }
31+ if got := fmt.Sprint(r); got != "purego: too many arguments to SyscallSelf" {
32+ t.Fatalf("panic = %q, want %q", got, "purego: too many arguments to SyscallSelf")
33+ }
34+ }()
35+ purego.SyscallSelf(uintptr(1), 1, make([]uintptr, 15)...)
36+}
@@ -0,0 +1,36 @@
1+//go:build (386 || arm) && (freebsd || linux || netbsd || windows)
2+
3+package purego_test
4+
5+import (
6+ "fmt"
7+ "testing"
8+
9+ "github.com/ebitengine/purego"
10+)
11+
12+func TestSyscallN32BitPanicsAt16Args(t *testing.T) {
13+ defer func() {
14+ r := recover()
15+ if r == nil {
16+ t.Fatal("expected panic")
17+ }
18+ if got := fmt.Sprint(r); got != "purego: too many arguments to SyscallN" {
19+ t.Fatalf("panic = %q, want %q", got, "purego: too many arguments to SyscallN")
20+ }
21+ }()
22+ purego.SyscallN(uintptr(1), make([]uintptr, 16)...)
23+}
24+
25+func TestSyscallSelf32BitPanicsAt16Args(t *testing.T) {
26+ defer func() {
27+ r := recover()
28+ if r == nil {
29+ t.Fatal("expected panic")
30+ }
31+ if got := fmt.Sprint(r); got != "purego: too many arguments to SyscallSelf" {
32+ t.Fatalf("panic = %q, want %q", got, "purego: too many arguments to SyscallSelf")
33+ }
34+ }()
35+ purego.SyscallSelf(uintptr(1), 1, make([]uintptr, 15)...)
36+}

Keyboard shortcuts

Single-key shortcuts are on. ctrl k and esc work whatever this says.

ctrl k :
go to a section, branch, tag, file or repository
?
this list
j k
move the row cursor down / up
enter
open the row under the cursor; on Files, a directory opens or closes in place
↑ ↓ ← → home end
in the file tree (focus on a row): previous / next row, close / open a directory or go to its parent / first entry, first / last row. They never open a file
l h
on Files: open a directory or a file / close a directory or go up to its parent, then to the parent page. Elsewhere: into the side panel (on a merge request, its files) / back to the content; there j k move between its controls
g g G
first / last row
/
filter the list; on Files, find a file anywhere in the repository (esc clears, enter opens the best match)
b
switch branch or tag
g s g f g c g b g m g i g r g a
tabs: summary, files, commits, branches & tags, merge requests, issues, releases, actions (when available)
g h
home
w
wide mode: use the whole width of the screen, or not (remembered)
y
copy a permalink pinned to the commit
d u x
diff: split / unified / collapse or expand all
e E
diff: the whole file in view / every file, with the lines the hunks hide
n
merge request: next note in the diff
esc
close a dialog, leave a field

Branches 1

Tags 102

↑↓ moveenter openesc close