aboutsummaryrefslogtreecommitdiff
path: root/misc
diff options
context:
space:
mode:
authorElias Naur <mail@eliasnaur.com>2021-09-15 14:36:54 +0100
committerElias Naur <mail@eliasnaur.com>2021-09-22 18:10:24 +0000
commit635e49388bf746a2b8c7ab1e9026aede0eb88b31 (patch)
tree9b1b562c485b828a8317418355fe2ff4f003a1d2 /misc
parente128749be88278768c50907ca87270b9d5e96eb5 (diff)
downloadgo-635e49388bf746a2b8c7ab1e9026aede0eb88b31.tar.gz
go-635e49388bf746a2b8c7ab1e9026aede0eb88b31.zip
cmd/cgo: add go:notinheap annotation to Windows handle types
Fixes #42018 Change-Id: I6a40f3effe860e67a45fca2e8ab86f3e9887ffee Reviewed-on: https://go-review.googlesource.com/c/go/+/350070 Trust: Elias Naur <mail@eliasnaur.com> Reviewed-by: Keith Randall <khr@golang.org> Run-TryBot: Keith Randall <khr@golang.org>
Diffstat (limited to 'misc')
-rw-r--r--misc/cgo/test/cgo_test.go1
-rw-r--r--misc/cgo/test/issue42018.go14
-rw-r--r--misc/cgo/test/issue42018_windows.go46
3 files changed, 61 insertions, 0 deletions
diff --git a/misc/cgo/test/cgo_test.go b/misc/cgo/test/cgo_test.go
index 143f23f0e0..fe99e251e9 100644
--- a/misc/cgo/test/cgo_test.go
+++ b/misc/cgo/test/cgo_test.go
@@ -59,6 +59,7 @@ func Test28896(t *testing.T) { test28896(t) }
func Test30065(t *testing.T) { test30065(t) }
func Test32579(t *testing.T) { test32579(t) }
func Test31891(t *testing.T) { test31891(t) }
+func Test42018(t *testing.T) { test42018(t) }
func Test45451(t *testing.T) { test45451(t) }
func TestAlign(t *testing.T) { testAlign(t) }
func TestAtol(t *testing.T) { testAtol(t) }
diff --git a/misc/cgo/test/issue42018.go b/misc/cgo/test/issue42018.go
new file mode 100644
index 0000000000..fab686a678
--- /dev/null
+++ b/misc/cgo/test/issue42018.go
@@ -0,0 +1,14 @@
+// Copyright 2021 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.
+
+//go:build !windows
+// +build !windows
+
+package cgotest
+
+import "testing"
+
+func test42018(t *testing.T) {
+ t.Skip("skipping Windows-only test")
+}
diff --git a/misc/cgo/test/issue42018_windows.go b/misc/cgo/test/issue42018_windows.go
new file mode 100644
index 0000000000..8f4570ab2a
--- /dev/null
+++ b/misc/cgo/test/issue42018_windows.go
@@ -0,0 +1,46 @@
+// Copyright 2021 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 cgotest
+
+/*
+typedef void *HANDLE;
+
+struct HWND__{int unused;}; typedef struct HWND__ *HWND;
+*/
+import "C"
+
+import (
+ "testing"
+ "unsafe"
+)
+
+func test42018(t *testing.T) {
+ // Test that Windows handles are marked go:notinheap, by growing the
+ // stack and checking for pointer adjustments. Trick from
+ // test/fixedbugs/issue40954.go.
+ var i int
+ handle := C.HANDLE(unsafe.Pointer(uintptr(unsafe.Pointer(&i))))
+ recurseHANDLE(100, handle, uintptr(unsafe.Pointer(&i)))
+ hwnd := C.HWND(unsafe.Pointer(uintptr(unsafe.Pointer(&i))))
+ recurseHWND(400, hwnd, uintptr(unsafe.Pointer(&i)))
+}
+
+func recurseHANDLE(n int, p C.HANDLE, v uintptr) {
+ if n > 0 {
+ recurseHANDLE(n-1, p, v)
+ }
+ if uintptr(unsafe.Pointer(p)) != v {
+ panic("adjusted notinheap pointer")
+ }
+}
+
+func recurseHWND(n int, p C.HWND, v uintptr) {
+ if n > 0 {
+ recurseHWND(n-1, p, v)
+ }
+ if uintptr(unsafe.Pointer(p)) != v {
+ panic("adjusted notinheap pointer")
+ }
+}