Skip to content

Commit

Permalink
Fix strict provenance polyfills (#34)
Browse files Browse the repository at this point in the history
* Fix strict provenance polyfills

* Make sure we pass Miri without the nightly feature too
  • Loading branch information
saethlin authored Oct 4, 2024
1 parent d93c886 commit f312112
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,6 @@ jobs:
rustup override set nightly
cargo miri setup
- name: Test with Miri
run: cargo miri test --features nightly
run: |
cargo miri test
cargo miri test --features nightly
6 changes: 3 additions & 3 deletions src/sptr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,16 @@ mod implementation {
}

pub fn without_provenance_mut<T>(addr: usize) -> *mut T {
addr as _
unsafe { core::mem::transmute(addr) }
}

pub fn with_metadata_of<T: ?Sized, U: ?Sized>(ptr: *const T, meta: *const U) -> *const U {
with_metadata_of_mut(cast_to_mut(ptr), meta)
}

pub fn with_metadata_of_mut<T: ?Sized, U: ?Sized>(ptr: *mut T, mut meta: *const U) -> *mut U {
let meta_ptr = addr_of_mut!(meta).cast::<usize>();
unsafe { meta_ptr.write(ptr.cast::<u8>() as usize) }
let meta_ptr = addr_of_mut!(meta).cast::<*mut u8>();
unsafe { meta_ptr.write(ptr.cast::<u8>()) }
cast_to_mut(meta)
}
}
Expand Down

0 comments on commit f312112

Please # to comment.