-
Notifications
You must be signed in to change notification settings - Fork 17.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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 <[email protected]> Reviewed-by: Keith Randall <[email protected]> Run-TryBot: Keith Randall <[email protected]>
- Loading branch information
Showing
5 changed files
with
135 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters