Conversation
|
cc @RalfJung |
e07803b to
752bdf0
Compare
|
I am not sure what to say about this, assembly code is outside my realm of knowledge.^^ |
|
Also with my Miri maintainer hat on, I have to say that I am a bit worried about fundamental ecosystem crates starting to use |
I'm aware of this issue and tend to avoid inline assembly calls when Miri or Sanitizer is used. (e.g., this code calls unstable core_arch function instead of asm on I plan to do a similar with crossbeam, but, there is currently no Miri-compatible (sound) way to do the equivalent, so we would probably need to keep the current implementation with conditions. (Of cause, the result would be a situation where soundness issues exist only when Miri or Sanitizer is used.) In the future, if |
That is indeed the point: there is no Rust-compatible way of doing that, as in, no way to do this within the confines of the Rust language. (That core::arch intrinsic will not work for Miri, either.) The only way to fix that is go do a proper language extension (this is not just a libs thing, it is a T-lang thing), and add support for this in Rust itself. I am not sure what the best API for this looks like, and this touches on a number of tricky subjects. (For example, Rust by design currently does not have |
This implements atomic CAS operations (
compare_exchange,compare_exchange_weak, andfetch_update) on potentially uninitialized integers.(If this approach is okay) This should be effectively the last requirement to use this crate (as optional deps/experimental features) in crossbeam (and to fix AtomicCell's remaining UBs such as crossbeam-rs/crossbeam#315, crossbeam-rs/crossbeam#748).
Note that this implementation already allows failure ordering stronger than success ordering (rust-lang/rust#98383).
I have not yet documented the pitfall of CAS with values containing uninitialized bytes(EDIT: documented): Comparison of two values containing uninitialized bytes may fail even if they are equivalent as Rust's type, because their contents are not frozen until a pointer to the value containing uninitialized bytes is passed toasm!. (See crossbeam-rs/crossbeam#315 for more)For example, the following example could be an infinite loop:
To work around this problem, you need to use a helper like this function in crossbeam.