fix: align 32-bit raw syscall limits
- commit
- c0e6605bb442fed24f44b479974513aa30d36199
- author
- brice · · 2026-04-13 09:54 UTC
- parent
- 90cebfb
- signature
- GPG Verified
CD88F9E564E0102646FB6077A1A07C7C7C3E349D· arch-gpg Verified for the committer email
2 files · +42 -4
M syscall_32bit.go +6 -4
| @@ -13,7 +13,7 @@ package purego | |||
| 13 | 13 | type CDecl struct{} | |
| 14 | 14 | ||
| 15 | 15 | const ( | |
| 16 | - | maxArgs = 32 | |
| 16 | + | maxArgs = 15 | |
| 17 | 17 | ) | |
| 18 | 18 | ||
| 19 | 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 | 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 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. | |
| 83 | 83 | // | |
| 84 | 84 | // In order to call this function properly make sure to follow all the rules specified in [unsafe.Pointer] | |
| 85 | 85 | // especially point 4. | |
| @@ -111,7 +111,9 @@ func SyscallN(fn uintptr, args ...uintptr) (r1, r2, err uintptr) { | |||
| 111 | 111 | ||
| 112 | 112 | // SyscallSelf is like SyscallN but efficiently prepends self to args without allocation. | |
| 113 | 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 | 118 | //go:uintptrescapes | |
| 117 | 119 | 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 = 32 | 16 | + | 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 panics | 81 | + | // 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:uintptrescapes | 118 | //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 | + | } | |||