Skip to content

Conversation

nicholasbishop
Copy link
Member

The existing code had some potential UB; it created a mutable pointer from a const reference and passed it across the FFI boundary. (Whether the pointee is actually mutated depends on the firmware implementation.)

An UnsafeCell allows the interior data to be mutated through a const reference. AtaPassThru now contains an UnsafeCell<AtaPassThruProtocol>, which allows a mutable pointer to be created with less risk of UB. (Note that it's still not allowed to create multiple mutable references to the data, but as long as only raw pointers are used, it should be OK.)

The AtaDevice and AtaDeviceIterator types have been adjusted to take a reference to the UnsafeCell.

Note: we'll likely want the same change in the nvme and scsi protocols.

Checklist

  • Sensible git history (for example, squash "typo" or "fix" commits). See the Rewriting History guide for help.
  • Update the changelog (if necessary)

The existing code had some potential UB; it created a mutable pointer from a
const reference and passed it across the FFI boundary. (Whether the pointee is
actually mutated depends on the firmware implementation.)

An `UnsafeCell` allows the interior data to be mutated through a const
reference. `AtaPassThru` now contains an `UnsafeCell<AtaPassThruProtocol>`,
which allows a mutable pointer to be created with less risk of UB. (Note that
it's still not allowed to create multiple mutable _references_ to the data, but
as long as only raw pointers are used, it should be OK.)

The `AtaDevice` and `AtaDeviceIterator` types have been adjusted to take a
reference to the `UnsafeCell`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant