Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

x/sys/windows: FormatMessage can't accept a DLL handle on 64-bit systems #11147

Closed
actgardner opened this issue Jun 10, 2015 · 8 comments
Closed

Comments

@actgardner
Copy link

  1. What version of Go are you using (go version)?
    go1.3.3 windows/amd64
  2. What operating system and processor architecture are you using?
    Windows x86-64
  3. What did you do?
    Try to call syscall.FormatMessage with a DLL handle.
var flags uint32 = syscall.FORMAT_MESSAGE_ARGUMENT_ARRAY | syscall.FORMAT_MESSAGE_IGNORE_INSERTS | syscall.FORMAT_MESSAGE_FROM_HMODULE
libpdhDll := syscall.MustLoadDLL("pdh.dll")
buffer := make([]uint16, 300)

// Have to cast Handle, which is a uintptr, to a uint32 due to the signature of FormatMessage
syscall.FormatMessage(flags, uint32(libpdhDll.Handle), <some error number>, 0, buffer, nil)
  1. What did you expect to see?
    FormatMessage should accept a syscall.Handle or a uintptr so the cast to uint32 doesn't have to happen.

5.What did you see instead?
FormatMessage returns an error because the truncated pointer doesn't point to a DLL.

@bradfitz
Copy link
Contributor

Go 1.3.3 is old and unsupported. Please try with Go 1.4.2 or ideally Go tip and report back.

@actgardner
Copy link
Author

The same issue clearly exists in master: https://github.com/golang/sys/blob/master/windows/zsyscall_windows.go#L476

func FormatMessage(flags uint32, msgsrc uint32, msgid uint32, langid uint32, buf []uint16, args *byte) (n uint32, err error) {

edit: To be clear, the issue is just that msgsrc does an insane roundtrip from uintptr to uint32 back to uintptr, which doesn't make sense on 64-bit.

@minux minux changed the title syscall/FormatMessage can't accept a DLL handle on 64-bit systems x/sys/windows: FormatMessage can't accept a DLL handle on 64-bit systems Jun 10, 2015
@minux minux added this to the Unreleased milestone Jun 10, 2015
@minux
Copy link
Member

minux commented Jun 10, 2015

The syscall package is frozen, but we can fix the problem in
x/sys/windows sub-repo instead.

@alexbrainman
Copy link
Member

My mistake. I am 386 person.

Any suggestion on what to do about syscall.FormatMessage are welcome. I cannot see what we could do besides documenting the bug.

Alex

@alexbrainman
Copy link
Member

@alanctgardner here https://go-review.googlesource.com/11165 is the change. Will that work for you?

Alex

@actgardner
Copy link
Author

Looks good @alexbrainman, thanks for the fix!

@gopherbot
Copy link

CL https://golang.org/cl/11165 mentions this issue.

@gopherbot
Copy link

CL https://golang.org/cl/12067 mentions this issue.

gopherbot pushed a commit to golang/sys that referenced this issue Jul 21, 2015
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>
@golang golang locked and limited conversation to collaborators Jul 20, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

6 participants