[][src]Struct std::os::fortanix_sgx::usercalls::alloc::UserRef

pub struct UserRef<T: ?Sized>(_);
🔬 This is a nightly-only experimental API. (sgx_platform #56975)

A reference to some type in userspace memory. &UserRef<T> is equivalent to &T in enclave memory. Access to the memory is only allowed by copying to avoid TOCTTOU issues. After copying, code should make sure to completely check the value before use.

It is also possible to obtain a mutable reference &mut UserRef<T>. Unlike regular mutable references, these are not exclusive. Userspace may always write to the backing memory at any time, so it can't be assumed that there the pointed-to memory is uniquely borrowed. The two different reference types are used solely to indicate intent: a mutable reference is for writing to user memory, an immutable reference for reading from user memory.

Implementations

impl<T: ?Sized> UserRef<T> where
    T: UserSafe
[src]

pub unsafe fn from_ptr<'a>(ptr: *const T) -> &'a Self[src]

🔬 This is a nightly-only experimental API. (sgx_platform #56975)

Creates a &UserRef<[T]> from a raw pointer.

Safety

The caller must ensure ptr points to T.

Panics

This function panics if:

  • The pointer is not aligned
  • The pointer is null
  • The pointed-to range is not in user memory

pub unsafe fn from_mut_ptr<'a>(ptr: *mut T) -> &'a mut Self[src]

🔬 This is a nightly-only experimental API. (sgx_platform #56975)

Creates a &mut UserRef<[T]> from a raw pointer. See the struct documentation for the nuances regarding a &mut UserRef<T>.

Safety

The caller must ensure ptr points to T.

Panics

This function panics if:

  • The pointer is not aligned
  • The pointer is null
  • The pointed-to range is not in user memory

pub fn copy_from_enclave(&mut self, val: &T)[src]

🔬 This is a nightly-only experimental API. (sgx_platform #56975)

Copies val into user memory.

Panics

This function panics if the destination doesn't have the same size as the source. This can happen for dynamically-sized types such as slices.

pub fn copy_to_enclave(&self, dest: &mut T)[src]

🔬 This is a nightly-only experimental API. (sgx_platform #56975)

Copies the value from user memory and place it into dest.

Panics

This function panics if the destination doesn't have the same size as the source. This can happen for dynamically-sized types such as slices.

pub fn as_raw_ptr(&self) -> *const T[src]

🔬 This is a nightly-only experimental API. (sgx_platform #56975)

Obtain a raw pointer from this reference.

pub fn as_raw_mut_ptr(&mut self) -> *mut T[src]

🔬 This is a nightly-only experimental API. (sgx_platform #56975)

Obtain a raw pointer from this reference.

impl<T> UserRef<T> where
    T: UserSafe
[src]

pub fn to_enclave(&self) -> T[src]

🔬 This is a nightly-only experimental API. (sgx_platform #56975)

Copies the value from user memory into enclave memory.

impl<T> UserRef<[T]> where
    [T]: UserSafe
[src]

pub unsafe fn from_raw_parts<'a>(ptr: *const T, len: usize) -> &'a Self[src]

🔬 This is a nightly-only experimental API. (sgx_platform #56975)

Creates a &UserRef<[T]> from a raw thin pointer and a slice length.

Safety

The caller must ensure ptr points to n elements of T.

Panics

This function panics if:

  • The pointer is not aligned
  • The pointer is null
  • The pointed-to range does not fit in the address space
  • The pointed-to range is not in user memory

pub unsafe fn from_raw_parts_mut<'a>(ptr: *mut T, len: usize) -> &'a mut Self[src]

🔬 This is a nightly-only experimental API. (sgx_platform #56975)

Creates a &mut UserRef<[T]> from a raw thin pointer and a slice length. See the struct documentation for the nuances regarding a &mut UserRef<T>.

Safety

The caller must ensure ptr points to n elements of T.

Panics

This function panics if:

  • The pointer is not aligned
  • The pointer is null
  • The pointed-to range does not fit in the address space
  • The pointed-to range is not in user memory

pub fn as_ptr(&self) -> *const T[src]

🔬 This is a nightly-only experimental API. (sgx_platform #56975)

Obtain a raw pointer to the first element of this user slice.

pub fn as_mut_ptr(&mut self) -> *mut T[src]

🔬 This is a nightly-only experimental API. (sgx_platform #56975)

Obtain a raw pointer to the first element of this user slice.

pub fn len(&self) -> usize[src]

🔬 This is a nightly-only experimental API. (sgx_platform #56975)

Obtain the number of elements in this user slice.

pub fn copy_to_enclave_vec(&self, dest: &mut Vec<T>)[src]

🔬 This is a nightly-only experimental API. (sgx_platform #56975)

Copies the value from user memory and place it into dest. Afterwards, dest will contain exactly self.len() elements.

Panics

This function panics if the destination doesn't have the same size as the source. This can happen for dynamically-sized types such as slices.

pub fn to_enclave(&self) -> Vec<T>[src]

🔬 This is a nightly-only experimental API. (sgx_platform #56975)

Copies the value from user memory into a vector in enclave memory.

pub fn iter(&self) -> Iter<T> where
    T: UserSafe
[src]

🔬 This is a nightly-only experimental API. (sgx_platform #56975)

Returns an iterator over the slice.

pub fn iter_mut(&mut self) -> IterMut<T> where
    T: UserSafe
[src]

🔬 This is a nightly-only experimental API. (sgx_platform #56975)

Returns an iterator that allows modifying each value.

impl UserRef<ByteBuffer>[src]

pub fn copy_user_buffer(&self) -> Vec<u8>[src]

🔬 This is a nightly-only experimental API. (sgx_platform #56975)

Copies the user memory range pointed to by the user ByteBuffer to enclave memory.

Panics

This function panics if, in the user ByteBuffer:

  • The pointer is null
  • The pointed-to range does not fit in the address space
  • The pointed-to range is not in user memory

Trait Implementations

impl<T: CoerceUnsized<U>, U> CoerceUnsized<UserRef<U>> for UserRef<T>[src]

impl<T, I> Index<I> for UserRef<[T]> where
    [T]: UserSafe,
    I: SliceIndex<[T], Output: UserSafe>, 
[src]

type Output = UserRef<I::Output>

The returned type after indexing.

impl<T, I> IndexMut<I> for UserRef<[T]> where
    [T]: UserSafe,
    I: SliceIndex<[T], Output: UserSafe>, 
[src]

Auto Trait Implementations

impl<T> !RefUnwindSafe for UserRef<T>

impl<T: ?Sized> Send for UserRef<T> where
    T: Send

impl<T> !Sync for UserRef<T>

impl<T: ?Sized> Unpin for UserRef<T> where
    T: Unpin

impl<T: ?Sized> UnwindSafe for UserRef<T> where
    T: UnwindSafe

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.