-
Notifications
You must be signed in to change notification settings - Fork 124
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
Bug: Possible misalignment of struct windows_sys::Win32::System::Diagnostics::Debug::CONTEXT #1412
Comments
Small update
Of course this leads to GetThreadContext no longer accepting my context variable, since the type does not match.
I no longer get the 998 error, but it doesn't work out in the end anyway,... my best guess is, that internally the struct is still being populated the wrong way, since the function internals work with the wrong type. Edit: seems I just had a bug in my own code. |
Sorry you hit this issue. It's known and being worked on #1044. |
@kennykerr Shall we transfer this to metadata and close it as a duplicate? |
Yes, the alignment is wrong. It should be 16 on 64-bit and 4 on 32-bit. |
Closing as dupe of #1044, thanks @BlackMagicCoding for the ping / should get resolved soon as this is a hot issue. |
Which crate is this about?
windows-sys
Crate version
0.42.0
Summary
Hello,
I am currently trying to use the windows_sys crate to get the thread context of a suspended thread, but everytime I do it, I get an unexpected error when calling "GetThreadContext" - 998
According to documentation this means:
ERROR_NOACCESS
Yes, this is a 64 bit process which has been tried to be accessed with the 64 bit version of GetThreadContext (you might correct me if I am wrong).
After some research I found this interesting StackOverflow article (even though it is about C++):
GetThreadContext fails after a successful SuspendThread in Windows 7
Before I used the windows_sys crate, I tried unsuccessfuly with winapi crate version 0.3.9.
At their definition of CONTEXT I can see something, which would also hint to the alignment problem:
Now I looked at the definition of CONTEXT in windows_sys:
As you can see the struct has C representation, but is missing the 16 Byte alignment as well.
From what I gathered, the necessary alignment depends on the OS version - I am running 64 bit Windows 10 (Build 19044.2364) right now.
Can someone of the developers confirm if this is reproducible for them as well?
Could you at least try if doing the alignment would solve it?
Yes, I assume that you most likely won't simply replace 1 line and be done with it, but rather make both versions available somehow.
The representation might look something like that:
#[repr(C, align(16))]
Is there any workaround/hack I can perform to use a correctly aligned CONTEXT struct with the windows_sys crate's call for GetThreadContext?
Toolchain version/configuration
Default host: x86_64-pc-windows-msvc
rustup home: C:\Users\thatsme.rustup
stable-x86_64-pc-windows-msvc (default)
rustc 1.65.0 (897e37553 2022-11-02)
Reproducible example
Crate manifest
Expected behavior
successfully got thread context... yay!
Actual behavior
could not get thread context: 998
Additional comments
This is my first time using unsafe Rust as well as doing Windows programming, so take everything I say with a giant pile of salt.
The text was updated successfully, but these errors were encountered: