pub struct ProcessMemorySlice<'a> { /* private fields */ }
Available on crate feature memory only.
Expand description

A unowned slice of a buffer in the memory space of a process.

Implementations§

source§

impl<'a> ProcessMemorySlice<'a>

source

pub const unsafe fn from_raw_parts( ptr: *mut u8, len: usize, process: BorrowedProcess<'a> ) -> Self

Constructs a new slice from the given raw parts.

Safety

The caller must ensure that the designated region of memory

source

pub fn is_local(&self) -> bool

Returns whether this slice is in the memory space of the current process.

source

pub fn is_remote(&self) -> bool

Returns whether this slice is in the memory space of another process.

source

pub const fn process(&self) -> BorrowedProcess<'a>

Returns the process that owns the memory of this slice.

source

pub const fn len(&self) -> usize

Returns the length of the slice.

source

pub const fn is_empty(&self) -> bool

Returns whether the slice is empty.

source

pub fn read(&self, buf: &mut [u8]) -> Result<(), ProcessError>

Copies the contents of this slice to the given local buffer.

Panics

This function will panic if this slice is smaller than the given buffer.

source

pub unsafe fn read_buf<T: Copy>( &self, buf: &mut [T] ) -> Result<(), ProcessError>

Copies the contents of this slice to the given local buffer.

Safety

The caller must ensure that the designated region of memory contains valid instances of type T.

Panics

This function will panic if this slice is smaller than the given buffer.

source

pub unsafe fn read_vec<T: Copy>( &self, len: usize ) -> Result<Vec<T>, ProcessError>

Copies len instances of type T at the start of this slice into a newly allocated local Vec<T>.

Safety

The caller must ensure that the designated region of memory contains valid instances of type T.

Panics

This function will panic if this slice is smaller than the given buffer.

source

pub unsafe fn read_struct<T: Copy>(&self) -> Result<T, ProcessError>

Reads a value of type T from the start this slice and copies it into local memory space.

Panics

This function will panic if the size of the value exceeds this slice’s length.

Safety

The caller must ensure that the designated region of memory contains a valid instance of type T.

source

pub fn write(&self, buf: &[u8]) -> Result<(), ProcessError>

Copies the contents of the given local buffer to this slice.

Panics

This function will panic if the size of the local buffer exceeds this slice’s length.

source

pub fn write_buf<T: Copy>(&self, buf: &[T]) -> Result<(), ProcessError>

Copies the contents of the given local buffer to the memory region of this slice.

Panics

This function will panic if the size of the local buffer exceeds this slice’s length.

source

pub fn write_struct<T: ?Sized + Copy>(&self, s: &T) -> Result<(), ProcessError>

Writes a value of type T to the start of this slice.

Panics

This function will panic if the value’s size exceeds this buffer’s length.

source

pub const fn as_ptr(&self) -> *mut u8

Returns a pointer to the start of this slice.

Note

The returned pointer is only valid in the target process.

source

pub fn slice(&self, bounds: impl RangeBounds<usize>) -> Self

Returns a new slice spanning a subregion of this slice.

source

pub fn as_local_slice(&self) -> Option<&[u8]>

Constructs a new local slice spanning the memory of this slice. This function will return None for remote memory slices.

source

pub fn as_local_slice_mut(&mut self) -> Option<&mut [u8]>

Constructs a new mutable slice spanning the memory of this slice. This function will return None for remote memory slices.

source

pub fn flush_instruction_cache(&self) -> Result<(), ProcessError>

Flushes the CPU instruction cache for the whole slice. This may be necesary if the memory is used to store dynamically generated code. For details see FlushInstructionCache.

Trait Implementations§

source§

impl<'a> AsMut<ProcessMemorySlice<'a>> for ProcessMemoryBuffer<'a>

source§

fn as_mut(&mut self) -> &mut ProcessMemorySlice<'a>

Converts this type into a mutable reference of the (usually inferred) input type.
source§

impl<'a> AsRef<ProcessMemorySlice<'a>> for ProcessMemoryBuffer<'a>

source§

fn as_ref(&self) -> &ProcessMemorySlice<'a>

Converts this type into a shared reference of the (usually inferred) input type.
source§

impl<'a> Clone for ProcessMemorySlice<'a>

source§

fn clone(&self) -> ProcessMemorySlice<'a>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<'a> Debug for ProcessMemorySlice<'a>

source§

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

Formats the value using the given formatter. Read more
source§

impl<'a> Copy for ProcessMemorySlice<'a>

Auto Trait Implementations§

§

impl<'a> RefUnwindSafe for ProcessMemorySlice<'a>

§

impl<'a> !Send for ProcessMemorySlice<'a>

§

impl<'a> !Sync for ProcessMemorySlice<'a>

§

impl<'a> Unpin for ProcessMemorySlice<'a>

§

impl<'a> UnwindSafe for ProcessMemorySlice<'a>

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

const: unstable · source§

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

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

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

const: unstable · 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> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

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

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

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

Performs the conversion.
source§

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

§

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

The type returned in the event of a conversion error.
const: unstable · source§

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

Performs the conversion.