x/sys/windows: correct FormatMessage parameter
Second FormatMessage parameter lpSource is uintptr not uint32.
Update golang/go#11147.
Change-Id: Icaa67abaed93efdad41564b21f8e511e8f9694b1
Reviewed-on: https://go-review.googlesource.com/11165
Reviewed-by: Yasuhiro MATSUMOTO <mattn.jp@gmail.com>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
diff --git a/windows/syscall_windows.go b/windows/syscall_windows.go
index c798402..441c193 100644
--- a/windows/syscall_windows.go
+++ b/windows/syscall_windows.go
@@ -87,7 +87,7 @@
//sys FreeLibrary(handle Handle) (err error)
//sys GetProcAddress(module Handle, procname string) (proc uintptr, err error)
//sys GetVersion() (ver uint32, err error)
-//sys FormatMessage(flags uint32, msgsrc uint32, msgid uint32, langid uint32, buf []uint16, args *byte) (n uint32, err error) = FormatMessageW
+//sys FormatMessage(flags uint32, msgsrc uintptr, msgid uint32, langid uint32, buf []uint16, args *byte) (n uint32, err error) = FormatMessageW
//sys ExitProcess(exitcode uint32)
//sys CreateFile(name *uint16, access uint32, mode uint32, sa *SecurityAttributes, createmode uint32, attrs uint32, templatefile int32) (handle Handle, err error) [failretval==InvalidHandle] = CreateFileW
//sys ReadFile(handle Handle, buf []byte, done *uint32, overlapped *Overlapped) (err error)
diff --git a/windows/syscall_windows_test.go b/windows/syscall_windows_test.go
index 0462bcf..0f73c11 100644
--- a/windows/syscall_windows_test.go
+++ b/windows/syscall_windows_test.go
@@ -10,6 +10,7 @@
"path/filepath"
"syscall"
"testing"
+ "unsafe"
"golang.org/x/sys/windows"
)
@@ -52,6 +53,38 @@
}
}
+func TestFormatMessage(t *testing.T) {
+ dll := windows.MustLoadDLL("pdh.dll")
+
+ pdhOpenQuery := func(datasrc *uint16, userdata uint32, query *windows.Handle) (errno uintptr) {
+ r0, _, _ := syscall.Syscall(dll.MustFindProc("PdhOpenQueryW").Addr(), 3, uintptr(unsafe.Pointer(datasrc)), uintptr(userdata), uintptr(unsafe.Pointer(query)))
+ return r0
+ }
+
+ pdhCloseQuery := func(query windows.Handle) (errno uintptr) {
+ r0, _, _ := syscall.Syscall(dll.MustFindProc("PdhCloseQuery").Addr(), 1, uintptr(query), 0, 0)
+ return r0
+ }
+
+ var q windows.Handle
+ name, err := windows.UTF16PtrFromString("no_such_source")
+ if err != nil {
+ t.Fatal(err)
+ }
+ errno := pdhOpenQuery(name, 0, &q)
+ if errno == 0 {
+ pdhCloseQuery(q)
+ t.Fatal("PdhOpenQuery succeeded, but expected to fail.")
+ }
+
+ const flags uint32 = syscall.FORMAT_MESSAGE_FROM_HMODULE | syscall.FORMAT_MESSAGE_ARGUMENT_ARRAY | syscall.FORMAT_MESSAGE_IGNORE_INSERTS
+ buf := make([]uint16, 300)
+ _, err = windows.FormatMessage(flags, uintptr(dll.Handle), uint32(errno), 0, buf, nil)
+ if err != nil {
+ t.Fatal("FormatMessage for handle=%x and errno=%x failed: %v", dll.Handle, errno, err)
+ }
+}
+
func abort(funcname string, err error) {
panic(funcname + " failed: " + err.Error())
}
diff --git a/windows/zsyscall_windows.go b/windows/zsyscall_windows.go
index cec5d5a..e130ddd 100644
--- a/windows/zsyscall_windows.go
+++ b/windows/zsyscall_windows.go
@@ -473,7 +473,7 @@
return
}
-func FormatMessage(flags uint32, msgsrc uint32, msgid uint32, langid uint32, buf []uint16, args *byte) (n uint32, err error) {
+func FormatMessage(flags uint32, msgsrc uintptr, msgid uint32, langid uint32, buf []uint16, args *byte) (n uint32, err error) {
var _p0 *uint16
if len(buf) > 0 {
_p0 = &buf[0]