-
Notifications
You must be signed in to change notification settings - Fork 142
Closed
Description
TODO: Expand based on the following ideas:
- We can't implement
is_bit_validforUnsafeCellbecause 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).- We should modify
is_bit_validto have awhere Self: NoCellbound.
- We should modify
- We still want to be able to use
TryFromBytesforUnsafeCell. - We should add a separate method:
TryFromBytes::is_bit_valid_mut. Likeis_bit_valid, but itsPtrargument hasinvariant::Exclusive.- We can call this method from
try_read_from
- We can call this method from
- Inside of the
is_bit_valid_mutimpl forUnsafeCell, we do the following:- Cast to
UnsafeCell<Unalign<MaybeValid<T>>>(see below for discussion ofMaybeValid) - Use
Ptr::as_mutto get a&mut UnsafeCell<Unalign<MaybeValid<T>>> - Use
UnsafeCell::get_mutto get a&mut Unalign<MaybeValid<T>> - Delegate to
<Unalign<MaybeValid<T>> as TryFromBytes>::is_bit_valid_mut
- Cast to
- Add
MaybeValid<T>, which is justMaybeUninit<T>but with the "as initialized" invariant.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels