Struct windows_permissions::localheap::LocalBox[][src]

pub struct LocalBox<T> { /* fields omitted */ }
Expand description

A smart pointer to an object on the local heap.

Windows has several different options for allocation, and the local heap is no longer recommended. However, several of the WinAPI calls in this crate use the local heap, allocating with LocalAlloc and freeing with LocalFree. This type encapsulates that behavior, representing objects that reside on the local heap.

It is primarily created using unsafe code in the wrappers crate when the WinAPI allocates a data structure for the program (using from_raw).

However, allocations can be manually made with allocate or try_allocate. For example:

use std::mem::size_of;
use windows_permissions::LocalBox;

let mut local_ptr1: LocalBox<u32> = unsafe { LocalBox::allocate() };

let mut local_ptr2: LocalBox<u32> = unsafe {
    LocalBox::try_allocate(true, size_of::<u32>()).unwrap()
};

*local_ptr1 = 5u32;
*local_ptr2 = 5u32;
assert_eq!(local_ptr1, local_ptr2);

For details, see MSDN.

Exotically-sized types

This struct has not been tested with exotically-sized types. Use with extreme caution.

Implementations

impl<T> LocalBox<T>[src]

pub unsafe fn from_raw(ptr: NonNull<T>) -> Self[src]

Get a LocalBox from a NonNull

Requirements

  • The NonNull pointer must have been allocated with a Windows API call. When the resulting NonNull<T> is dropped, it will be dropped with LocalFree
  • The buffer pointed to by the pointer must be a valid T

pub unsafe fn allocate() -> Self[src]

Allocate enough zeroed memory to hold a T with LocalAlloc

The memory will always come back zeroed, which has a modest performance penalty but can reduce the impact of buffer overruns.

Panics

Panics if the underlying LocalAlloc call fails.

Safety

The allocated memory is zeroed, which may not be a valid representation of a T.

pub unsafe fn try_allocate(zeroed: bool, size: usize) -> Result<Self>[src]

Allocate memory with LocalAlloc

If the allocation fails, returns the error code.

Safety

The contents of the memory are not guaranteed to be a valid T. The contents will either be zeroed or uninitialized depending on the zeroed parameter.

Additionally, size should be large enough to contain a T.

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

Get a pointer to the underlying data structure

Use this when interacting with FFI libraries that want pointers.

Trait Implementations

impl<T> AsRef<T> for LocalBox<T>[src]

fn as_ref(&self) -> &T[src]

Performs the conversion.

impl<T> Borrow<T> for LocalBox<T>[src]

fn borrow(&self) -> &T[src]

Immutably borrows from an owned value. Read more

impl<T> BorrowMut<T> for LocalBox<T>[src]

fn borrow_mut(&mut self) -> &mut T[src]

Mutably borrows from an owned value. Read more

impl<T: Debug> Debug for LocalBox<T>[src]

fn fmt(&self, fmt: &mut Formatter<'_>) -> Result[src]

Formats the value using the given formatter. Read more

impl<T> Deref for LocalBox<T>[src]

type Target = T

The resulting type after dereferencing.

fn deref(&self) -> &Self::Target[src]

Dereferences the value.

impl<T> DerefMut for LocalBox<T>[src]

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

Mutably dereferences the value.

impl<T: Display> Display for LocalBox<T>[src]

fn fmt(&self, fmt: &mut Formatter<'_>) -> Result[src]

Formats the value using the given formatter. Read more

impl<T> Drop for LocalBox<T>[src]

fn drop(&mut self)[src]

Executes the destructor for this type. Read more

impl FromStr for LocalBox<SecurityDescriptor>[src]

type Err = Error

The associated error which can be returned from parsing.

fn from_str(s: &str) -> Result<Self, Self::Err>[src]

Parses a string s to return a value of this type. Read more

impl FromStr for LocalBox<Sid>[src]

type Err = Error

The associated error which can be returned from parsing.

fn from_str(s: &str) -> Result<Self, Self::Err>[src]

Parses a string s to return a value of this type. Read more

impl<T> Hash for LocalBox<T> where
    T: Hash
[src]

fn hash<H: Hasher>(&self, state: &mut H)[src]

Feeds this value into the given Hasher. Read more

fn hash_slice<H>(data: &[Self], state: &mut H) where
    H: Hasher
1.3.0[src]

Feeds a slice of this type into the given Hasher. Read more

impl<T, U> PartialEq<LocalBox<U>> for LocalBox<T> where
    T: PartialEq<U>, 
[src]

fn eq(&self, other: &LocalBox<U>) -> bool[src]

This method tests for self and other values to be equal, and is used by ==. Read more

#[must_use]
fn ne(&self, other: &Rhs) -> bool
1.0.0[src]

This method tests for !=.

impl<T> Eq for LocalBox<T> where
    T: Eq
[src]

impl<U: Send> Send for LocalBox<U>[src]

impl<U: Sync> Sync for LocalBox<U>[src]

Auto Trait Implementations

impl<T> RefUnwindSafe for LocalBox<T> where
    T: RefUnwindSafe

impl<T> Unpin for LocalBox<T>

impl<T> UnwindSafe for LocalBox<T> where
    T: RefUnwindSafe

Blanket Implementations

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

pub fn type_id(&self) -> TypeId[src]

Gets the TypeId of self. Read more

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

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

Immutably borrows from an owned value. Read more

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

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

Mutably borrows from an owned value. Read more

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

pub fn from(t: T) -> T[src]

Performs the conversion.

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

pub fn into(self) -> U[src]

Performs the conversion.

impl<T> ToString for T where
    T: Display + ?Sized
[src]

pub default fn to_string(&self) -> String[src]

Converts the given value to a String. Read more

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.

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

Performs the conversion.

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.

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

Performs the conversion.