pub unsafe trait WriteableProcessBuffer: ReadableProcessBuffer {
// Required method
fn mut_enter<F, R>(&self, fun: F) -> Result<R, Error>
where F: FnOnce(&WriteableProcessSlice) -> R;
// Provided method
fn mut_ptr(&self) -> *mut u8 { ... }
}Expand description
A readable and writeable region of userspace process memory.
This trait can be used to gain read-write access to memory regions
wrapped in a ReadWriteProcessBuffer.
This is a supertrait of ReadableProcessBuffer, which features
methods allowing mutable access.
§Safety
This is an unsafe trait as users of this trait need to trust that the
implementation of WriteableProcessBuffer::mut_ptr is
correct.
Implementors of this trait must ensure that the
WriteableProcessBuffer::mut_ptr method follows the semantics and
invariants described in its documentation, and that the length of the
WriteableProcessBuffer is identical to the value returned by the
ReadableProcessBuffer::len supertrait method.
Additionally, when using the default implementation of mut_ptr provided by
this trait, implementors guarantee that the readable pointer returned by
ReadableProcessBuffer::ptr points to the same read-write allowed shared
memory region as described by the WriteableProcessBuffer, and that
writes through the pointer returned by ReadableProcessBuffer::ptr are
sound for ReadableProcessBuffer::len bytes, notwithstanding any aliasing
requirements.
Required Methods§
Sourcefn mut_enter<F, R>(&self, fun: F) -> Result<R, Error>where
F: FnOnce(&WriteableProcessSlice) -> R,
fn mut_enter<F, R>(&self, fun: F) -> Result<R, Error>where
F: FnOnce(&WriteableProcessSlice) -> R,
Applies a function to the mutable process slice reference
pointed to by the ReadWriteProcessBuffer.
If the process is no longer alive and the memory has been
reclaimed, this method must return
Err(process::Error::NoSuchApp).
§Default Process Buffer
A default instance of a process buffer must return
Err(process::Error::NoSuchApp) without executing the passed
closure.
Provided Methods§
Sourcefn mut_ptr(&self) -> *mut u8
fn mut_ptr(&self) -> *mut u8
Pointer to the first byte of the userspace-allowed memory region.
If ReadableProcessBuffer::len returns a non-zero value,
then this method is guaranteed to return a pointer to the
start address of a memory region (of length returned by
len), allowable by a userspace process, and allowed to the
kernel for read or write operations.
If the length of the initially shared memory region
(irrespective of the return value of
len) is 0, this function
returns a pointer to address 0x0. This is because processes
may allow zero-length buffer to share no memory with the
kernel. Because these buffers have zero length, they may have
any arbitrary pointer value. However, these “dummy addresses”
should not be leaked, so this method returns 0 for zero-length
slices. Care must be taken to not create a Rust (slice)
reference over a null-pointer, as that is undefined behavior.
Users of this pointer must not produce any mutable aliasing, such as by
creating a reference from this pointer concurrently with calling
WriteableProcessBuffer::mut_enter.
§Default Process Buffer
A default instance of a process buffer must return a pointer
to address 0x0.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.