-
Notifications
You must be signed in to change notification settings - Fork 3
Add methods for MMIO reads and writes #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
volatile_read and volatile_write doesn't work properly in a protected VM.
Any fields not marked with such a wrapper can only be read or written via unsafe methods.
These may be useful for testing, as someone may want to derive these traits for a struct containing a mixture of read-only and write-only fields.
This may be needed both for tests to construct fakes, and for unsafely reading or writing fields directly.
This has methods which don't require uniqueness, and so may be cloned. UniqueMmioPointer derefs to SharedMmioPointer.
These may safely be read from a SharedMmioPointer rather than a UniqueMmioPointer.
This removes the bound on T implementing the corresponding trait.
This pull request sets up GitHub code scanning for this repository. Once the scans have completed and the checks have passed, the analysis results for this pull request branch will appear on this overview. Once you merge this pull request, the 'Security' tab will show more code scanning analysis results (for example, for the default branch). Depending on your configuration and choice of analysis tool, future pull requests will be annotated with code scanning analysis results. For more information about GitHub code scanning, check out the documentation. |
This adds a bunch of different methods and macros to allow safe MMIO reads and writes of individual fields. In particular:
get
andsplit
methods onUniqueMmioPointer<[T]>
andUniqueMmioPointer<[T; _]>
respectively, to go from a pointer to a slice or field to pointers to the individual elements.field!
macro to go from a pointer to a struct to a pointer to an individual field. (Andfield_shared!
to do the same forSharedMmioPointer
.) If [RFC] field projections v2 rust-lang/rfcs#3735 gets stabilised then we could implement that instead of needing a macro.OwnedMmioPointer
is renamed toUniqueMmioPointer
, and a new typeSharedMmioPointer
is added.SharedMmioPointer
is toUniqueMmioPointer
as&T
is to&mut T
. ASharedMmioPointer
can be created from aUniqueMmioPointer
and can be freely cloned, but fewer operations are possible on it.UniqueMmioPointer
also derefs toSharedMmioPointer
.&mut
) whereas a read without side-effects can safely be done via a shared pointer (passed via '&'), e.g. simultaneously from multiple threads.read
andwrite
methods to perform MMIO reads and writes. On most platforms this is implemented viaread_volatile
andwrite_volatile
on the underlying pointer, but on aarch64 inline assembly is used instead to work around Volatile reads and writes on aarch64 sometimes generate instructions not suitable for MMIO in protected VMs rust-lang/rust#131894. To do this safely we require that the underlying type implement the relevant traits from zerocopy.