Struct UserMut

Source
pub struct UserMut<'a, T: Sized, R: Copy + ReprMut<T> = *mut T> { /* private fields */ }
Expand description

A pointer to mutable userspace memory with a defined in-memory representation.

This exists primarily for use in defining safe ioctl/etc request types, to ensure that only valid addresses can be assigned to a field from safe Rust. Using this is important for any pointer that the kernel might write through, to ensure that safe Rust cannot assign an address that might cause the kernel to corrupt memory.

If a struct type used with an ioctl request has a field containing an address that the kernel might write to then defining that field as a UserPtr ensures that it can only have a valid address assigned to it unless the caller uses the unsafe Self::from_ptr.

The in-memory representation of this type is guaranteed to match that of type parameter R, which defaults to being a pointer to T.

Implementations§

Source§

impl<'a, T: Sized, R: Copy + ReprMut<T>> UserMut<'a, T, R>

Source

pub unsafe fn from_ptr(ptr: *mut T) -> Self

Create a representation of the given pointer.

§Safety

The pointer must remain valid for the lifetime of the result.

Source

pub fn from_ref(r: &'a mut T) -> Self

Create a representation of a pointer referring to the same object as the given reference.

Source

pub fn repr(&self) -> R

Get the in-memory representation of the pointer.

Auto Trait Implementations§

§

impl<'a, T, R> Freeze for UserMut<'a, T, R>
where R: Freeze,

§

impl<'a, T, R> RefUnwindSafe for UserMut<'a, T, R>

§

impl<'a, T, R> Send for UserMut<'a, T, R>
where R: Send, T: Send,

§

impl<'a, T, R> Sync for UserMut<'a, T, R>
where R: Sync, T: Sync,

§

impl<'a, T, R> Unpin for UserMut<'a, T, R>
where R: Unpin,

§

impl<'a, T, R = *mut T> !UnwindSafe for UserMut<'a, T, R>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.