Skip to content
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: CONTEXT structure should be aligned to 16 bytes #1477

Closed
TimMisiak opened this issue Feb 23, 2023 · 3 comments
Closed

Bug: CONTEXT structure should be aligned to 16 bytes #1477

TimMisiak opened this issue Feb 23, 2023 · 3 comments
Labels
bug Something isn't working

Comments

@TimMisiak
Copy link

Which crate is this about?

windows-sys

Crate version

0.45.0

Summary

The following code will fail randomly on x86/x64 because CONTEXT is defined as DECLSPEC_ALIGN(16) in winnt.h, but does not have any alignment annotation in windows-rs.

        let hthread = unsafe { OpenThread(THREAD_ALL_ACCESS, FALSE, debug_event.dwThreadId) };

        let mut ctx: CONTEXT = unsafe { std::mem::zeroed() };
        ctx.ContextFlags = CONTEXT_ALL;
        let ret = unsafe { GetThreadContext(hthread, &mut ctx) };

Winnt.h:

typedef struct DECLSPEC_ALIGN(16) DECLSPEC_NOINITALL _CONTEXT {

Toolchain version/configuration

Default host: x86_64-pc-windows-msvc
rustup home: C:\Users\timmi.rustup

stable-x86_64-pc-windows-msvc (default)
rustc 1.67.0 (fc594f156 2023-01-24)

Reproducible example

No response

Crate manifest

[dependencies.windows-sys]
version = "0.45.0"
features = [
    "Win32_Foundation",
    "Win32_Security",
    "Win32_System_Kernel",
    "Win32_System_Threading",
    "Win32_UI_WindowsAndMessaging",
    "Win32_System_Diagnostics_Debug",
    "Win32_System_Environment",
    "Win32_System_WindowsProgramming",
]

Expected behavior

Alignment should be 16 bytes

Actual behavior

Structure has no explicit alignment, causing random failures when using it with APIs that expect alignment.

Additional comments

No response

@TimMisiak TimMisiak added the bug Something isn't working label Feb 23, 2023
@kennykerr
Copy link
Contributor

Hi Tim, this is a known issue: #1044

I hope to bribe someone to fix this very soon. @riverar donuts are on the way.

@kennykerr
Copy link
Contributor

I tried working around the issues in microsoft/windows-rs#2352 but that didn't work out. Transferring to the Win32 metadata repo, as I don't think there's anything I can do until the metadata has been fixed.

@kennykerr kennykerr transferred this issue from microsoft/windows-rs Mar 6, 2023
@mikebattista
Copy link
Contributor

Duplicate of #1044

@mikebattista mikebattista marked this as a duplicate of #1044 Mar 6, 2023
@mikebattista mikebattista closed this as not planned Won't fix, can't repro, duplicate, stale Mar 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants