Skip to content

Fix Miri Stacked Borrows violation in ffi wrapper macros#131

Merged
kinetiknz merged 1 commit into
masterfrom
miri_stacked
Feb 9, 2026
Merged

Fix Miri Stacked Borrows violation in ffi wrapper macros#131
kinetiknz merged 1 commit into
masterfrom
miri_stacked

Conversation

@kinetiknz

Copy link
Copy Markdown
Contributor

The Opaque ZST wrapper (UnsafeCell<()>) used for borrowed FFI reference types caused zero-byte borrow tags under Miri's Stacked Borrows model. Any pointer derived from &StreamParamsRef (or other *Ref types) inherited this zero-byte tag, making all reads through it undefined behavior.

Replace Opaque with MaybeUninit<$ctype> so each borrowed type has the same size and alignment as its underlying C type, ensuring borrow tags cover the actual data bytes. Apply the same fix to DeviceCollectionRef which used Opaque directly.

Updated tests that used sentinel pointers to use valid allocations.

The Opaque ZST wrapper (UnsafeCell<()>) used for borrowed FFI reference
types caused zero-byte borrow tags under Miri's Stacked Borrows model.
Any pointer derived from &StreamParamsRef (or other *Ref types)
inherited this zero-byte tag, making all reads through it undefined
behavior.

Replace Opaque with MaybeUninit<$ctype> so each borrowed type has the
same size and alignment as its underlying C type, ensuring borrow tags
cover the actual data bytes. Apply the same fix to DeviceCollectionRef
which used Opaque directly.

Updated tests that used sentinel pointers to use valid allocations.
@kinetiknz kinetiknz requested review from Pehrsons and padenot February 9, 2026 01:58
@kinetiknz kinetiknz self-assigned this Feb 9, 2026
@kinetiknz kinetiknz merged commit 32671bf into master Feb 9, 2026
8 of 14 checks passed
@kinetiknz kinetiknz deleted the miri_stacked branch February 9, 2026 21:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants