Soundly turning &mut [MaybeUninit] into &mut [u8] with garbage

⚓ Rust    📅 2026-06-12    👤 surdeus    👁️ 1      

surdeus

What's the current state of soundly and efficiently turning a &mut [MaybeUninit<u8>] into &mut [u8] filled with garbage? (u8 here stands in for any type for which all bit patterns are valid.)

As I understand it, this should be possible by writing 1 byte to each memory page spanned by the slice so that the pages are actually mapped as a kernel matter (in case safe code chooses to read from the slice before writing to it) and telling LLVM to consider a freeze over the slice memory to have taken place.

For a long time, I was told that the Rust side was waiting for LLVM to get "freeze", but lately I've been told that the LLVM side is already done.

Is there a library function for performing this operation?

1 post - 1 participant

Read full topic

🏷️ Rust_feed