aboutsummaryrefslogtreecommitdiff
path: root/src/syscall/syscall_windows_test.go
diff options
context:
space:
mode:
authorqmuntal <quimmuntal@gmail.com>2024-11-05 16:01:45 +0100
committerQuim Muntal <quimmuntal@gmail.com>2024-11-06 16:35:17 +0000
commit7fff741016c8157e107cce8013ee3ca621725384 (patch)
treec03c698b3afb66fcc02f8050b7db626c92c52633 /src/syscall/syscall_windows_test.go
parent067d58b53433885124a5f46b381a0378d7aec35d (diff)
downloadgo-7fff741016c8157e107cce8013ee3ca621725384.tar.xz
syscall: mark SyscallN as noescape
syscall.SyscallN is implemented by runtime.syscall_syscalln, which makes sure that the variadic argument doesn't escape. There is no need to worry about the lifetime of the elements of the variadic argument, as the compiler will keep them live until the function returns. Fixes #70197. Cq-Include-Trybots: luci.golang.try:gotip-windows-amd64-longtest,gotip-windows-amd64-race Change-Id: I12991f0be12062eea68f2b103fa0a794c1b527eb Reviewed-on: https://go-review.googlesource.com/c/go/+/625297 Reviewed-by: Ian Lance Taylor <iant@google.com> Reviewed-by: Alex Brainman <alex.brainman@gmail.com> Reviewed-by: David Chase <drchase@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Diffstat (limited to 'src/syscall/syscall_windows_test.go')
-rw-r--r--src/syscall/syscall_windows_test.go47
1 files changed, 47 insertions, 0 deletions
diff --git a/src/syscall/syscall_windows_test.go b/src/syscall/syscall_windows_test.go
index 8b5af9c501..63409daf04 100644
--- a/src/syscall/syscall_windows_test.go
+++ b/src/syscall/syscall_windows_test.go
@@ -227,6 +227,53 @@ func TestGetStartupInfo(t *testing.T) {
}
}
+func TestSyscallAllocations(t *testing.T) {
+ testenv.SkipIfOptimizationOff(t)
+
+ t.Parallel()
+
+ // Test that syscall.SyscallN arguments do not escape.
+ // The function used (in this case GetVersion) doesn't matter
+ // as long as it is always available and doesn't panic.
+ h, err := syscall.LoadLibrary("kernel32.dll")
+ if err != nil {
+ t.Fatal(err)
+ }
+ defer syscall.FreeLibrary(h)
+ proc, err := syscall.GetProcAddress(h, "GetVersion")
+ if err != nil {
+ t.Fatal(err)
+ }
+
+ testAllocs := func(t *testing.T, name string, fn func() error) {
+ t.Run(name, func(t *testing.T) {
+ n := int(testing.AllocsPerRun(10, func() {
+ if err := fn(); err != nil {
+ t.Fatalf("%s: %v", name, err)
+ }
+ }))
+ if n > 0 {
+ t.Errorf("allocs = %d, want 0", n)
+ }
+ })
+ }
+
+ testAllocs(t, "SyscallN", func() error {
+ r0, _, e1 := syscall.SyscallN(proc, 0, 0, 0)
+ if r0 == 0 {
+ return syscall.Errno(e1)
+ }
+ return nil
+ })
+ testAllocs(t, "Syscall", func() error {
+ r0, _, e1 := syscall.Syscall(proc, 3, 0, 0, 0)
+ if r0 == 0 {
+ return syscall.Errno(e1)
+ }
+ return nil
+ })
+}
+
func FuzzUTF16FromString(f *testing.F) {
f.Add("hi") // ASCII
f.Add("รข") // latin1