Avoid lossy ptr-int transmutes by using AtomicPtr#66
Avoid lossy ptr-int transmutes by using AtomicPtr#66yoshuawuyts merged 1 commit intoasync-rs:masterfrom
Conversation
|
@yoshuawuyts any chance on getting this merged soon? Would be pretty useful since this crate is causing Miri checking to fail for many crates. |
|
Meanwhile, RFC 3559 has been accepted, which states that
@yoshuawuyts would be good to see this fix land so this widely-used crate can be brought into the realm of unambiguously sound code. :) |
yoshuawuyts
left a comment
There was a problem hiding this comment.
I'm trusting @Nilstrieb and @RalfJung that you've looked at this code and determined it correctly upholds the rules. That's good enough for me; thank you! - merging!
|
Published as |
This project looks pretty inactive, but it is still used very widely by the ecosystem and Miri detects UB in it that looks unambiguously bad to me, so that's why I'm submitting a patch for it.
Rust doesn't have a formal memory model yet, but as far as we can tell it isn't sound to round-trip a pointer through an integer via transmutes in a compiler which does provenance-based optimizations (which LLVM and basically all modern compilers currently do). The fix here is pretty easy: we store an
AtomicPtrinstead of anAtomicUsizeand we create our sentinel values using thewrapping_pointer methods.This PR is very similar to rust-lang/rust#95621.