You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We can't implement is_bit_valid for UnsafeCell because it requires reading from memory which is behind an UnsafeCell. There's no way to do this without raw pointers, and even with raw pointers, we don't know how other code is accessing the same memory (e.g., it might be using atomics, which would cause UB if we accessed it via non-atomic accesses).
We should modify is_bit_valid to have a where Self: NoCell bound.
We still want to be able to use TryFromBytes for UnsafeCell.
We should add a separate method: TryFromBytes::is_bit_valid_mut. Like is_bit_valid, but its Ptr argument has invariant::Exclusive.
We can call this method from try_read_from
Inside of the is_bit_valid_mut impl for UnsafeCell, we do the following:
Cast to UnsafeCell<Unalign<MaybeValid<T>>> (see below for discussion of MaybeValid)
Use Ptr::as_mut to get a &mut UnsafeCell<Unalign<MaybeValid<T>>>
Use UnsafeCell::get_mut to get a &mut Unalign<MaybeValid<T>>
Delegate to <Unalign<MaybeValid<T>> as TryFromBytes>::is_bit_valid_mut
Add MaybeValid<T>, which is just MaybeUninit<T> but with the "as initialized" invariant.
The text was updated successfully, but these errors were encountered:
TODO: Expand based on the following ideas:
is_bit_valid
forUnsafeCell
because it requires reading from memory which is behind anUnsafeCell
. There's no way to do this without raw pointers, and even with raw pointers, we don't know how other code is accessing the same memory (e.g., it might be using atomics, which would cause UB if we accessed it via non-atomic accesses).is_bit_valid
to have awhere Self: NoCell
bound.TryFromBytes
forUnsafeCell
.TryFromBytes::is_bit_valid_mut
. Likeis_bit_valid
, but itsPtr
argument hasinvariant::Exclusive
.try_read_from
is_bit_valid_mut
impl forUnsafeCell
, we do the following:UnsafeCell<Unalign<MaybeValid<T>>>
(see below for discussion ofMaybeValid
)Ptr::as_mut
to get a&mut UnsafeCell<Unalign<MaybeValid<T>>>
UnsafeCell::get_mut
to get a&mut Unalign<MaybeValid<T>>
<Unalign<MaybeValid<T>> as TryFromBytes>::is_bit_valid_mut
MaybeValid<T>
, which is justMaybeUninit<T>
but with the "as initialized" invariant.The text was updated successfully, but these errors were encountered: