Struct UserPtr

Source
pub struct UserPtr<'a, T: Sized, R: Copy + Repr<T> = *const T> { /* private fields */ }
Expand description

A pointer to readable 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.

If a struct type used with an ioctl request has a field containing an address that the kernel only reads from 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 + Repr<T>> UserPtr<'a, T, R>

Source

pub unsafe fn from_ptr(ptr: *const 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 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 UserPtr<'a, T, R>
where R: Freeze,

§

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

§

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

§

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

§

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

§

impl<'a, T, R> UnwindSafe for UserPtr<'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.