Skip to main content

User

Struct User 

Source
pub struct User<T: UserSafe + ?Sized>(/* private fields */);
🔬This is a nightly-only experimental API. (sgx_platform #56975)
Available on Fortanix and SGX only.
Expand description

An owned type in userspace memory. User<T> is equivalent to Box<T> in enclave memory. Access to the memory is only allowed by copying to avoid TOCTTOU issues. The user memory will be freed when the value is dropped. After copying, code should make sure to completely check the value before use.

Implementations§

Source§

impl<T> User<T>
where T: UserSafe + ?Sized,

Source

pub fn new_from_enclave(val: &T) -> Self

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

Copies val into freshly allocated space in user memory.

Source

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

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

Creates an owned User<T> from a raw pointer.

§Safety

The caller must ensure ptr points to T, is freeable with the free usercall and the alignment of T, and is uniquely owned.

§Panics

This function panics if:

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

pub fn into_raw(self) -> *mut T

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

Converts this value into a raw pointer. The value will no longer be automatically freed.

Source§

impl<T> User<T>
where T: UserSafe,

Source

pub fn uninitialized() -> Self

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

Allocates space for T in user memory.

Source§

impl<T> User<[T]>
where [T]: UserSafe,

Source

pub fn uninitialized(n: usize) -> Self

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

Allocates space for a [T] of n elements in user memory.

Source

pub unsafe fn from_raw_parts(ptr: *mut T, len: usize) -> Self

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

Creates an owned User<[T]> from a raw thin pointer and a slice length.

§Safety

The caller must ensure ptr points to len elements of T, is freeable with the free usercall and the alignment of T, and is uniquely owned.

§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

Methods from Deref<Target = UserRef<T>>§

Source

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

🔬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.

Source

pub fn copy_to_enclave<U: ?Sized + UserSafeCopyDestination<T>>( &self, dest: &mut U, )

🔬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.

Source

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

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

Obtain a raw pointer from this reference.

Source

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

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

Obtain a raw pointer from this reference.

Source

pub fn to_enclave(&self) -> T

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

Copies the value from user memory into enclave memory.

Trait Implementations§

Source§

impl<T> Deref for User<T>
where T: UserSafe + ?Sized,

Source§

type Target = UserRef<T>

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.
Source§

impl<T> DerefMut for User<T>
where T: UserSafe + ?Sized,

Source§

fn deref_mut(&mut self) -> &mut Self::Target

Mutably dereferences the value.
Source§

impl<T> Drop for User<T>
where T: UserSafe + ?Sized,

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics #130494)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more
Source§

impl<T: UserSafeSized> Send for User<T>

Source§

impl<T: UserSafeSized> Send for User<[T]>

Auto Trait Implementations§

§

impl<T> !RefUnwindSafe for User<T>

§

impl<T> !Sync for User<T>

§

impl<T> !UnwindSafe for User<T>

§

impl<T> Freeze for User<T>
where NonNull<UserRef<T>>: Freeze, T: ?Sized,

§

impl<T> Unpin for User<T>
where NonNull<UserRef<T>>: Unpin, T: ?Sized,

§

impl<T> UnsafeUnpin for User<T>
where NonNull<UserRef<T>>: UnsafeUnpin, T: ?Sized,

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<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types #44874)
The target type on which the method may be called.
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.
Source§

impl<T> UserSafeCopyDestination<T> for T

Source§

fn as_mut_ptr(&mut self) -> *mut T

🔬This is a nightly-only experimental API. (sgx_platform #56975)
Available on Fortanix and SGX only.
Returns a pointer for writing to the value.