-
Notifications
You must be signed in to change notification settings - Fork 525
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: struct layout problems: Some C short
s are u32
structs, and structs are not packed correctly
#2257
Comments
Related
Just leaving this note here, haven't looked at this yet. |
The field size issues should have been fixed - you can confirm by targeting the repo rather than the crate. The alignment issues seem to be related to microsoft/win32metadata#1044 where the packing metadata is missing, but in this case alignment seems to match MSVC so perhaps what you're seeing is just a side effect of the incorrect struct field sizes in the version you're testing. |
Thanks! I can confirm that by referencing the repo itself (with
|
Sweet - thanks for checking! |
Which crate is this about?
windows
Crate version
0.43.0
Summary
While attempting to use the
EnumDisplaySettingsExW()
function to find info about my displays, I discovered that the RustDEVMODEW.dmPelsHeight
field is 8 bytes away from where it should be. It looks like there are two causes for this:short
in C++, are implemented asu32
structs in Rust ("newtype" idiom). They should bei16
's.u32
fields in the Rust struct are 4-byte aligned. They should not be 4-byte aligned if they are not 4-byte aligned in C++, and should be packed instead.Below is the
DEVMODEW
Rust struct with comments indicating the lines where I've traced down problems.This is likely caused by two separate bugs, but I'm going to log them both into one issue for now, since I found them both in the same struct.
Toolchain version/configuration
rustup show
Default host: x86_64-pc-windows-msvc
rustup home: C:\Users\me.rustup
stable-x86_64-pc-windows-msvc (default)
rustc 1.66.0 (69f9c33d7 2022-12-12)
Reproducible example
Crate manifest
Expected behavior
In my original program, I expected to be able to read
DEVMODEW.dmPelsWidth
and get the width of my monitor. (I instead get refresh rate.)In the program I pasted above, I expect the offsets in Rust to be the same as the offsets seen in C++, and expect see this output:
Actual behavior
The field offsets beyond
dmColor
are incorrect:Additional comments
No response
The text was updated successfully, but these errors were encountered: