go issue42018_windows 源码

2022-07-15 浏览 (1443)

golang issue42018_windows 代码

文件路径:/misc/cgo/test/issue42018_windows.go

/ 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")
	}
}

相关信息

go 源码目录

相关文章

go backdoor 源码

go buildid_linux 源码

go callback 源码

go cgo_linux_test 源码

go cgo_stubs_android_test 源码

go cgo_test 源码

go cgo_thread_lock 源码

go cgo_unix_test 源码

go issue1435 源码

go issue18146 源码

  • 所属分类: 后端技术
  • 本文标签: golang
  • 版权声明: 本文链接 https://seaxiang.com/blog/277cca5bfd354f94bae7da5c08b05468