-
Notifications
You must be signed in to change notification settings - Fork 18k
syscall: panic calling Windows system call in 1.7, worked in 1.6 #17908
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
Comments
Yes. The problem here is confusion between garbage collector and your Windows. In your example resume_handle is stored on stack (resume_handle is not listed as escaped in the following output):
I suspect NetLocalGroupGetMembers is slow to return (it, probably, searches network), and garbage collector moves goroutine stack before NetLocalGroupGetMembers returns. When NetLocalGroupGetMembers returns, Windows writes at resume_handle old address, and god only knows what is there at that time. Therefore the crash. If I change your program just a little, it starts working again:
See I do not know why your program worked in the past. Perhaps garbage collector behaved differently. Maybe compiler generates more efficient code now (by using stack instead of heap). I will let others tell you what to do to prevent this from happening. From what I know about current Go runtime, you need to keep long living variables (that are also accessible by Windows) on the heap. Alex |
This is what https://golang.org/pkg/runtime/#KeepAlive is for. But syscall.Syscall calls should be treated as if KeepAlive were used immediately after. Maybe they're not on Windows? |
We had this conversation before: https://groups.google.com/d/topic/golang-dev/AlMCfgQLkdo/discussion Alex |
Based on @alexbrainman 's comment, this is not a But I don't agree with the full analysis. The garbage collector should not move the stack of a goroutine that is waiting for a system call to complete. The And I don't see a way that the stack could grow in the If I am reading the exception information correctly, the error is an attempt to read from the address A few things to try to get more information. Set Set |
Output from
|
Thanks. Unfortunately I don't see anything useful there. I don't know what the problem is. Does it make any difference if you move the call to |
If it is not garbage collector, perhaps @pquerna you made mistake in your program. The NetLocalGroupGetMembers resumehandle type is PDWORD_PTR, which is pointer to pointer. But you pass pointer to uint32 there. But pointers are 64 bits long on windows/amd64. Perhaps Windows writes uint64 where you only provided uint32. Try this:
It works for me. Alex |
@pquerna, can you confirm? We're trying to close Go 1.8 bugs. |
@bradfitz Confirmed. Thanks, this resolves the issue for us. |
Calling syscalls on Windows can cause a panic. This does not occur in Go 1.6 with the same code.
I believe this code follows the rules listed at: https://golang.org/pkg/unsafe/#Pointer, most specifically:
It appears to me that this code is triggering a garbage collector or compiler bug by defining
resume_handle
in the scope of the functionresumeHandlePtrCrashes
and passing it to the syscall called incallingNetLocalGroupGetMembers
.What version of Go are you using (
go version
)?go version go1.7.3 windows/amd64
What operating system and processor architecture are you using (
go env
)?What did you do?
A small test program:
go run test.go
What did you expect to see?
Running under Go 1.6, this code would produce:
NetLocalGroupGetMembers = 0
What did you see instead?
An error like this:
Background
The above code is generated by $GOROOT/src/syscall/mksyscall_windows.go, from this:
The text was updated successfully, but these errors were encountered: