microsoft / microsoft/windows-rs
`windows-clang` drops per-member `POINTER_ALIGNMENT`: `IO_STACK_LOCATION_0_16` layout in master
- Dominant language
- Rust
- Stars
- 12.8k
- Forks
- 665
- Avg merge
- 7h 9m
- Merged PRs (30d)
- 70
Description
### Summary
#4404 described the `IO_STACK_LOCATION::Parameters::DeviceIoControl` layout for 0.61. The code regenerated by `windows-clang` in master (4479a78, 2026-09-17) has the same layout, so the per-member case looks like it was not covered by #4649/#4680, which handle record-level `DECLSPEC_ALIGN` (the `CONTEXT` case in #3761).
The WDK spells per-member alignment `POINTER_ALIGNMENT` (`DECLSPEC_ALIGN(8)` on 64-bit). WDK 10.0.26100.0 `km/wdm.h` line 33160:
```c
struct {
ULONG OutputBufferLength;
ULONG POINTER_ALIGNMENT InputBufferLength;
ULONG POINTER_ALIGNMENT IoControlCode;
PVOID Type3InputBuffer;
} DeviceIoControl;
```
MSVC x64 offsets 0x00 / 0x08 / 0x10 / 0x18, size 0x20.
Master `crates/libs/windows/src/Windows/Win32/wdm/mod.rs` lines 8574-8583:
```rust
#[repr(C)]
#[cfg(any(target_arch = "aarch64", target_arch = "arm64ec", target_arch = "x86_64"))]
pub struct IO_STACK_LOCATION_0_16 {
pub OutputBufferLength: u32,
pub InputBufferLength: u32,
pub IoControlCode: u32,
pub Type3InputBuffer: *mut core::ffi::c_void,
}
```
Rust offsets 0 / 4 / 8 / 16, size 24. `InputBufferLength` and `IoControlCode` read 4 bytes early and `Type3InputBuffer` 8 bytes early.
Where the information is lost: `crates/libs/clang/src/extract.rs:3174` records the true offset per field (`clang_Cursor_getOffsetOfField`), but the `.rdl` output only carries record-level `#[align(N)]` / `#[packed]`. `metadata/wdk/wdm.rdl` line 3717 has no alignment on this arm at all:
```
DeviceIoControl: struct {
OutputBufferLength: u32,
InputBufferLength: u32,
IoControlCode: u32,
Type3InputBuffer: *mut void,
},
```
Record-level `#[align(8)]` does not repair the arms where it was emitted either. `wdm.h` line 33169:
```c
struct {
SECURITY_INFORMATION SecurityInformation;
ULONG POINTER_ALIGNMENT Length;
} QuerySecurity;
```
MSVC x64: `Length` at 0x08, size 0x10. Master emits `#[repr(C, align(8))] struct IO_STACK_LOCATION_0_17 { SecurityInformation, Length: u32 }` (lines 8584-8591): `Length` at 4, size 8. The struct alignment is right; the member offset is not.
Every `POINTER_ALIGNMENT` member in `IO_STACK_LOCATION.Parameters` (Read, Write, QueryFile, SetFile, QueryVolume, SetVolume, FileSystemControl, DeviceIoControl, QuerySecurity, ...) is affected the same way. I first hit it in the 0.62.2 `FLT_PARAMETERS_3/4/5/6/13` bindings from `fltKernel.h`, which follow the same header pattern.
Possible fix: since `field.offset` is already recorded, emit explicit padding fields wherever a field's recorded offset exceeds what natural `repr(C)` layout gives. That is exact by construction for the scraped target and needs no `.rdl` grammar change. The alternative is a per-field `#[align(N)]` in `.rdl` with `windows-bindgen` wrapping such fields in an aligned newtype.
Verification (any 64-bit target):
```rust
use std::mem::{offset_of, size_of};
#[repr(C)] struct DevIoCtl { a: u32, b: u32, c: u32, d: *mut u8 }
#[repr(C, align(8))] struct QuerySec { a: u32, b: u32 }
fn main() {
println!("{} {} {} {} size {}", offset_of!(DevIoCtl, a), offset_of!(DevIoCtl, b), offset_of!(DevIoCtl, c), offset_of!(DevIoCtl, d), size_of::());
println!("{} {} size {}", offset_of!(QuerySec, a), offset_of!(QuerySec, b), size_of::());
}
// 0 4 8 16 size 24 (WDK: 0 8 16 24 size 32)
// 0 4 size 8 (WDK: 0 8 size 16)
```
### Crate manifest
```toml
[dependencies]
windows = { version = "0.62.2", features = ["Wdk_Foundation", "Wdk_System_SystemServices"] }
```
Same layout observed in master 4479a78 with features `wdm`, `ntifs`.
### Crate code
```rust
use windows::Wdk::Foundation::IO_STACK_LOCATION_0_16;
fn main() {
// WDK x64: 0x10. Generated: 8.
assert_eq!(core::mem::offset_of!(IO_STACK_LOCATION_0_16, IoControlCode), 0x10);
}
```
Contributor guide
Research direction
Start in crates/libs/clang/src/extract.rs at the field-offset recording, then compare metadata/wdk/wdm.rdl with the generated IO_STACK_LOCATION_* definitions in crates/libs/windows/src/Windows/Win32/wdm/mod.rs. Run the supplied offset_of and size_of checks for the affected structs. Done means generated layouts match the WDK offsets and sizes for per-member-aligned fields.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Active
- Clarity
- Clearly specified
- Newbie friendliness
- 68/100