Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid lossy ptr-int transmutes by using AtomicPtr #19

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

saethlin
Copy link

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#66


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 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.

@saethlin saethlin changed the title Avoid probably-UB ptr-int transmutes by using AtomicPtr Avoid lossy ptr-int transmutes by using AtomicPtr Sep 17, 2022
whizsid added a commit to whizsid/wasmtimer-rs that referenced this pull request Jan 10, 2023
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.

1 participant