totally-sound-ptr-int-cast

Crates.iototally-sound-ptr-int-cast
lib.rstotally-sound-ptr-int-cast
version0.1.1
sourcesrc
created_at2022-03-31 06:48:27.031985
updated_at2022-03-31 06:53:01.858966
descriptiondo i _look_ like a memory model?
homepage
repositoryhttps://github.com/ben0x539/totally-sound-ptr-int-cast
max_upload_size
id559503
size6,359
Benjamin Herr (ben0x539)

documentation

README

totally sound ptr<-> int casts

doom is upon us

Okay, so, it looks like as-casts between usize and raw pointer types are on the way out. People are talking about how those make provenance really annoying which is bad for formalizing a memory model. In this hypothetical future, it would be highly illegal to cast a pointer to an integer, maybe roundtrip it through some OS or FFI API, cast it back to an integer, and then dereference it.

It may be too late to avert that terrible fate. In this doomed timeline, it may become necessary to use this crate to perform totally sound ptr<->int casts.

let n = totally_sound_ptr_int_cast::ptr2int(
    Bxo::into_raw(your_boxed_stuff.into_raw()));

and, at any later point within the same program execution,

let p = totally_sound_ptr_int_cast::int2ptr_mut(n);
unsafe { println!("{:?}", &*p); } // or whatever

you get your stuff back.

Commit count: 4

cargo fmt