aboutsummaryrefslogtreecommitdiff
path: root/src/runtime/testdata/testsyscall/testsyscall.go
diff options
context:
space:
mode:
authorqmuntal <quimmuntal@gmail.com>2025-09-10 16:34:22 +0200
committerQuim Muntal <quimmuntal@gmail.com>2025-09-12 08:39:47 -0700
commit7acb0d044695ca0fbedf94dca7abfdfd991bc69a (patch)
treed1b9769bdb0c9eec3b9c028f79bf2dbdc17ca99a /src/runtime/testdata/testsyscall/testsyscall.go
parent60c1ee91834d6c9701c5058830645da6eaa0cee9 (diff)
downloadgo-7acb0d044695ca0fbedf94dca7abfdfd991bc69a.tar.xz
runtime: fix syscall9 on darwin/arm64
The aarch64 ABI says that only the first 8 arguments should be passed as registers, subsequent arguments should be put on the stack. Syscall9 is not putting the 9th argument on the stack, and it should. The standard library hasn't hit this issue because it uses Syscall9 for functions that only require 7 or 8 parameters. Change-Id: I1fafca5b16f977ea856e3f08b4ff3d0a2a7a4dfe Reviewed-on: https://go-review.googlesource.com/c/go/+/702297 Reviewed-by: Michael Pratt <mpratt@google.com> Reviewed-by: Cherry Mui <cherryyz@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Diffstat (limited to 'src/runtime/testdata/testsyscall/testsyscall.go')
-rw-r--r--src/runtime/testdata/testsyscall/testsyscall.go65
1 files changed, 65 insertions, 0 deletions
diff --git a/src/runtime/testdata/testsyscall/testsyscall.go b/src/runtime/testdata/testsyscall/testsyscall.go
new file mode 100644
index 0000000000..23cca16494
--- /dev/null
+++ b/src/runtime/testdata/testsyscall/testsyscall.go
@@ -0,0 +1,65 @@
+// Copyright 2025 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package main
+
+import (
+ _ "runtime/testdata/testsyscall/testsyscallc" // unfortunately, we can't put C and assembly in the package
+ _ "unsafe" // for go:linkname
+)
+
+//go:linkname syscall_syscall syscall.syscall
+func syscall_syscall(fn, a1, a2, a3 uintptr) (r1, r2, err uintptr)
+
+//go:linkname syscall_syscall6 syscall.syscall6
+func syscall_syscall6(fn, a1, a2, a3, a4, a5, a6 uintptr) (r1, r2, err uintptr)
+
+//go:linkname syscall_syscall9 syscall.syscall9
+func syscall_syscall9(fn, a1, a2, a3, a4, a5, a6, a7, a8, a9 uintptr) (r1, r2, err uintptr)
+
+var (
+ syscall_check0_trampoline_addr uintptr
+ syscall_check1_trampoline_addr uintptr
+ syscall_check2_trampoline_addr uintptr
+ syscall_check3_trampoline_addr uintptr
+ syscall_check4_trampoline_addr uintptr
+ syscall_check5_trampoline_addr uintptr
+ syscall_check6_trampoline_addr uintptr
+ syscall_check7_trampoline_addr uintptr
+ syscall_check8_trampoline_addr uintptr
+ syscall_check9_trampoline_addr uintptr
+)
+
+func main() {
+ if ret, _, _ := syscall_syscall(syscall_check0_trampoline_addr, 0, 0, 0); ret != 1 {
+ panic("hello0")
+ }
+ if ret, _, _ := syscall_syscall(syscall_check1_trampoline_addr, 1, 0, 0); ret != 1 {
+ panic("hello1")
+ }
+ if ret, _, _ := syscall_syscall(syscall_check2_trampoline_addr, 1, 2, 0); ret != 1 {
+ panic("hello2")
+ }
+ if ret, _, _ := syscall_syscall(syscall_check3_trampoline_addr, 1, 2, 3); ret != 1 {
+ panic("hello3")
+ }
+ if ret, _, _ := syscall_syscall6(syscall_check4_trampoline_addr, 1, 2, 3, 4, 0, 0); ret != 1 {
+ panic("hello4")
+ }
+ if ret, _, _ := syscall_syscall6(syscall_check5_trampoline_addr, 1, 2, 3, 4, 5, 0); ret != 1 {
+ panic("hello5")
+ }
+ if ret, _, _ := syscall_syscall6(syscall_check6_trampoline_addr, 1, 2, 3, 4, 5, 6); ret != 1 {
+ panic("hello6")
+ }
+ if ret, _, _ := syscall_syscall9(syscall_check7_trampoline_addr, 1, 2, 3, 4, 5, 6, 7, 0, 0); ret != 1 {
+ panic("hello7")
+ }
+ if ret, _, _ := syscall_syscall9(syscall_check8_trampoline_addr, 1, 2, 3, 4, 5, 6, 7, 8, 0); ret != 1 {
+ panic("hello8")
+ }
+ if ret, _, _ := syscall_syscall9(syscall_check9_trampoline_addr, 1, 2, 3, 4, 5, 6, 7, 8, 9); ret != 1 {
+ panic("hello9")
+ }
+}