Avoid lossy ptr-int transmutes by using AtomicPtr#19
Open
saethlin wants to merge 1 commit intotomaka:masterfrom
Open
Avoid lossy ptr-int transmutes by using AtomicPtr#19saethlin wants to merge 1 commit intotomaka:masterfrom
saethlin wants to merge 1 commit intotomaka:masterfrom
Conversation
whizsid
added a commit
to whizsid/wasmtimer-rs
that referenced
this pull request
Jan 10, 2023
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This repo contains a lot of copy-paste from
futures-timer, so this PR is almost a copy-paste of a PR to that repo: async-rs/futures-timer#66This 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 AtomicPtr instead of an AtomicUsize and we create our sentinel values using the wrapping_ pointer methods.
This PR is very similar to rust-lang/rust#95621.