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 enables use of
miri
to check for correctness of the codebase at MIR level.miri
allows you to be more sure of soundness of your unsafe blocks.The first thing that had to be changed is use of
libc::mmap
forNockStack
. I changed it to the system allocator. Now, I'm aware that there is some special care taken to prevent system allocations, but I don't think I know the full story, so I'm not so sure what the difference is between calling mmap directly or invokingalloc::alloc
, but what I know is thatlibc::mmap
(or any third party lib) is not usable undermiri
, so allocation code needs to be somewhat generic to work (if usinglibc::mmap
is a must, it can be worked around with#[cfg(miri)]
).The second thing is pointer handling. If you were to run
cargo +nightly miri test
on the first two commits, you'd get errors about dangling pointers, which occur because pointers to the stack get built from integers without provenance data. Pointer provenance is a bit of a complicated subject, but it basically boils down to "keeping track of which allocation it came from", which I guess is always going to be theNockStack
it resides in. If you don't track provenance, probably not much is going to happen today, but compilers, especiallyrustc
, are likely to start to rely on pointer provenance to enable some tricky optimizations leading to very subtle miscompilations down the road. There is also an existing rustc experiment, which probably won't get anywhere in the next 5 years, but still worth mentioning: rust-lang/rust#95228.The third commit restores provenance to the pointers. This could potentially work under
-Zmiri-strict-provenance
, but there are issues with noun tags:To fix this we'd want to swap the tagging around to add bits to direct nouns rather than other way around, but that's another problem on its own.
The question is how useful is this? I'd say this will prevent subtle miscompilations many years down the road, plus any potential memory issues stemming from use of unsafe.