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
runtime: native callback on Windows only returns 32 bit result on 64 bit platform #29331
Comments
Thank you for reporting this issue. I am pretty sure, it is a bug to use MOVL instead of MOVQ in that code. windows/386 was first version of Go, and then windows/amd64 was created later. I suspect 386 code was copied onto amd64, and we did not adjusted that line. We also obviously do not have the test for that code. I will try and write new test, and change this code, and see if anything gets affected in a bad way. We won't be able to make this change until after go1.12 is released. It has been broken forever, so it cannot be urgent. If you want to try and implement the change yourself, let me know. This https://golang.org/doc/contribute.html is how to contribute. Alex |
o no,I met the like problem when go64exe load 64dll which call a callback function imp in go under windows10 x64.after c function call the callback ,the go program stop at asm_amd64.s cgocallback_gofunc.i hope these bugs are fiexed as soon as possible.thanks. (by the workround mentioned here ,i modified file and rebuilt a go.exe,but it dont work for me) |
Change https://golang.org/cl/159579 mentions this issue: |
@rixtox and @OliverZou please try https://golang.org/cl/159579 see if it fixes your problem. https://golang.org/cl/159579 fixes syscall package, not golang.org/x/sys/windows. So just replace golang.org/x/sys/windows with syscall in your test program. If syscall fix works, I will copy that code into golang.org/x/sys/windows. Thank you. Alex |
@alexbrainman The fix works for me. |
Thanks for confirming. Now we need for someone to review my change (I made a note there to wait until go1.12 is released). Alex |
Cool, thanks for the CL @alexbrainman! @randall77 and I reviewed and approved your CL, and there is a small pending update to the test. |
I tried copying CL 159579 into golang.org/x/sys/windows, but there is nothing to do. CL 159579 inly changed src/runtime/sys_windows_amd64.s file, that lives in runtime (not syscall) package. Let me know, if I am mistaken. Alex |
@alexbrainman You are right. https://github.com/golang/sys/blob/master/windows/syscall_windows.go#L116 |
What version of Go are you using?
Problem
I'm calling a DLL function, that takes a callback function, where the callback function returns a pointer to some data structure, and the DLL will perform some action on the data structure.
I'm running Go on Windows 64-bit machine, the DLL is also 64-bit. The above code will print the address of the pointer, which is
0xC000080018
, but the call to the DLL will fail silently.Cause
I don't have the source code to the DLL so I can't make it print the value it gets. So I used IDA pro to dynamically debug the program, and I found that the Go callback function is actually returning 32-bit value instead of 64-bit value. This is the final code of the Go callback routine before it returns back to the DLL:
As you can see Go is writing the return value in
eax
instead ofrax
, which will discard the higher address, therefore the DLL will only get0x80018
and caused errors.Possible fix?
I've done some digging into Go's implementation of the callback, and found the assembly code at
src/runtime/sys_windows_amd64.s
. I noticed that inruntime·callbackasm1
, the return value is set usingMOVL
instead ofMOVQ
. So I changed it toMOVQ
and everything worked.I'm not sure if it's a bug or actually intended, so I'm opening an issue first.
The text was updated successfully, but these errors were encountered: