-
Notifications
You must be signed in to change notification settings - Fork 18k
syscall: can't call Windows function that returns float #37273
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
It would help if somebody suggested specific new API that would work for all known cases. It seems to me that just adding |
Good point. I had not yet encountered a case where I needed this in my own projects, but that should be considered as well. I’ll try to come up with a list and post it here. |
Are the APIs you reference unimplemented in x/sys/windows? See also discussion in #6510. |
Looking through both package syscall and golang.org/x/sys/windows, it appears these are the APIs that need a "Float" variant for the return:
Regarding @networkimprov 's question: golang.org/x/sys/windows doesn't implement the syscall code itself -- it just calls through to the implementation in syscall. |
Another possibility, which would require only a single code change in function |
Do Windows function that accept floating point arguments work correctly? Is there a need to fix this in the syscall package, which is more or less frozen, or can we just fix it in golang.org/x/sys/windows? |
In my usage of them, yes, floating point args do work since the fix to fill the first four registers was put in. I found I do have to pass them by calling the conversion function in the math package, but that’s workable. As stated earlier, the fix has to be in the runtime package, as that’s where the info is and the plumbing is private to that package so can’t be fixed externally. |
Which API are you talking about?
That sounds reasonable. Is X0 register documented by Microsoft to receive returned value on amd64?
Fair enough. Alex |
As stated above, both the Direct2D and DirectWrite APIs are the ones I'm currently using. Did you want a specific function call? If so, here's one off the top of my head: https://docs.microsoft.com/en-us/windows/win32/api/d2d1/nf-d2d1-id2d1brush-getopacity
Yes. From here: https://docs.microsoft.com/en-us/cpp/build/x64-calling-convention?view=vs-2019: |
Change https://golang.org/cl/220578 mentions this issue: |
I did. I was not aware of its existence.
Sounds good. Thank you.
No argument.
Looks good. Thank you. Alex |
RELNOTE=yes Fixes golang#37273
Change https://golang.org/cl/236562 mentions this issue: |
Updates #6510. Updates #37273. Change-Id: Id2732fcff0a0c5e4a324cd33ef995c7e528f5e1a Reviewed-on: https://go-review.googlesource.com/c/go/+/236562 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
This is essentially a request for #3588 to be solved rather than just closed out and ignored.
Currently, it is not possible to retrieve a floating point value returned by a syscall. As noted in the original report, that's not very common in the old Windows APIs, but it does occur in many of the newer APIs, especially around graphics. My particular case is the Direct2D and DirectWrite APIs, although I've seen the need elsewhere as well.
I've looked, and it seems to be fairly straight-forward to add this support via a new set of functions (SyscallFloat, perhaps) -- however, it currently seems impossible to do so without doing it inside the
runtime
andsyscall
packages, which would require a fork, since there is various internal state that an outside package cannot access.If we can't have the additional call(s) created for some reason, can we instead at least expose enough of the internals that an external module could provide the functionality?
I'd be happy to create the necessary PR to make either scenario work.
One thing to note: I realize I could get around this by using cgo. However, as most would likely agree, using cgo on the Windows platform is a nightmare. It's generally quite tolerable on platforms like macOS and linux, where the compiler toolchain is easily installed, but Windows makes that difficult and I've found getting downstream developers to be able to get their Windows machine setup properly for cgo to require a lot of hand-holding, unlike with other platforms, essentially making it a non-starter.
The text was updated successfully, but these errors were encountered: