-
Notifications
You must be signed in to change notification settings - Fork 18k
x/sys/windows: "Invalid access to memory location" when calling CreateAcceleratorTableW API #64729
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
@golang/runtime @alexbrainman per owners |
The error message you get is I don't see a problem with your program. My guess you data is not aligned properly. Sometimes it works and sometimes it does not. My guess it probably wrong. Alex |
Thank you very much @alexbrainman Kevin |
Given that it doesn't seem like there's a bug in Go or x/sys/windows here (especially since this is accessing a Windows API that doesn't have a wrapper in x/sys/windows) I don't think the issue tracker is the right place for this anymore. In triage we think we should close this issue, but please feel free to follow up on https://groups.google.com/g/golang-nuts/ which is a good place for these kinds of questions. Thanks! |
I just tried to build and run both versions of your program with go1.21.5 windows/amd64. And both of them output valid handle and no error. Something like this:
Alex |
I totally understand. Kevin |
Thank you for all your time. After some investigation, I found that the problem is related to the build flags. If I build the code with Any suggestions? |
Yes. It could be related to Delve.
How can I reproduce the problem here? What are the steps? Alex |
Here are the steps:
I'm running Kevin |
windows11 can also reproduce. |
Thanks for the steps. I did not try them, because I am pretty sure, your problem is because your CreateAcceleratorTableW parameter is not aligned properly and Windows is complaining about this. See #65069 for more details. The details should give you enough pointers to solve your problem. Alex |
Thanks for your help. In my example the But I found it's very difficult to align the memory address when go slice is involved. For example
It runs OK. But if I change
The problem goes back. Further more, as mentioned, Kevin |
How do you know that Windows expects CreateAcceleratorTableW parameter to use alignment of 2 bytes? I believe it expects 8. Alex |
I tested in C code and found that CreateAcceleratorTableW needs a 4-byte aligned argument on x64 machine. I don't know why it isn't 8-byte. Anyway, 8-byte alignment is always 4-byte alignment. I tried to write an aux function that aligns go slice data to 8-byte(size of
and the API call:
It passed all my test now, but I am not 100% sure it is correct especially when stack copying is involved. Any advice? |
Go version
go version go1.21.5 windows/amd64
What operating system and processor architecture are you using (
go env
)?What did you do?
What did you expect to see?
What did you see instead?
But the weird thing is if I change the main function to the following, everything will be OK:
The text was updated successfully, but these errors were encountered: