Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/raw/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,9 @@ pub enum RawInsertResult<'g, K, V> {
},
}

// An entry in the hash-table.
#[repr(C)]
// An entry in the hash-table. We force a minimum of 8-byte alignment because
// we store entry flags in the low 3 bits of pointers to this type.
#[repr(C, align(8))]
pub struct Entry<K, V> {
/// The key for this entry.
pub key: K,
Expand Down
8 changes: 7 additions & 1 deletion src/raw/utils/tagged.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use std::mem::align_of;
use std::sync::atomic::{AtomicPtr, Ordering};

// Polyfill for the unstable strict-provenance APIs.
Expand All @@ -12,9 +13,13 @@ pub unsafe trait StrictProvenance<T>: Sized {
}

// Unpack a tagged pointer.
pub trait Unpack {
pub trait Unpack: Sized {
// A mask for the pointer tag bits.
const MASK: usize;

// This constant, if used, will fail to compile if T doesn't have an alignment
// that guarantees all valid pointers have zero in the bits excluded by T::MASK.
const ASSERT_ALIGNMENT: () = assert!(align_of::<Self>() > !Self::MASK);
}

unsafe impl<T> StrictProvenance<T> for *mut T {
Expand All @@ -33,6 +38,7 @@ unsafe impl<T> StrictProvenance<T> for *mut T {
where
T: Unpack,
{
let () = T::ASSERT_ALIGNMENT;
Tagged {
raw: self,
ptr: self.map_addr(|addr| addr & T::MASK),
Expand Down