[−][src]Struct rustc_mir::interpret::memory::Memory

pub struct Memory<'mir, 'tcx, M: Machine<'mir, 'tcx>> {
    pub(in interpret) alloc_map: M::MemoryMap,
    extra_fn_ptr_map: FxHashMap<AllocId, M::ExtraFnVal>,
    pub(in interpret) dead_alloc_map: FxHashMap<AllocId, (Size, Align)>,
    pub extra: M::MemoryExtra,
    pub tcx: TyCtxt<'tcx>,
}

Fields

alloc_map: M::MemoryMap

Allocations local to this instance of the miri engine. The kind helps ensure that the same mechanism is used for allocation and deallocation. When an allocation is not found here, it is a global and looked up in the tcx for read access. Some machines may have to mutate this map even on a read-only access to a global (because they do pointer provenance tracking and the allocations in tcx have the wrong type), so we let the machine override this type. Either way, if the machine allows writing to a global, doing so will create a copy of the global allocation here.

extra_fn_ptr_map: FxHashMap<AllocId, M::ExtraFnVal>

Map for "extra" function pointers.

dead_alloc_map: FxHashMap<AllocId, (Size, Align)>

To be able to compare pointers with NULL, and to check alignment for accesses to ZSTs (where pointers may dangle), we keep track of the size even for allocations that do not exist any more.

extra: M::MemoryExtra

Extra data added by the machine.

tcx: TyCtxt<'tcx>

Lets us implement HasDataLayout, which is awfully convenient.

Implementations

impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M>[src]

pub fn new(tcx: TyCtxt<'tcx>, extra: M::MemoryExtra) -> Self[src]

pub fn global_base_pointer(
    &self,
    ptr: Pointer
) -> InterpResult<'tcx, Pointer<M::PointerTag>>
[src]

Call this to turn untagged "global" pointers (obtained via tcx) into the machine pointer to the allocation. Must never be used for any other pointers, nor for TLS statics.

Using the resulting pointer represents a direct access to that memory (e.g. by directly using a static), as opposed to access through a pointer that was created by the program.

This function can fail only if ptr points to an extern static.

pub fn create_fn_alloc(
    &mut self,
    fn_val: FnVal<'tcx, M::ExtraFnVal>
) -> Pointer<M::PointerTag>
[src]

pub fn allocate(
    &mut self,
    size: Size,
    align: Align,
    kind: MemoryKind<M::MemoryKind>
) -> Pointer<M::PointerTag>
[src]

pub fn allocate_bytes(
    &mut self,
    bytes: &[u8],
    kind: MemoryKind<M::MemoryKind>
) -> Pointer<M::PointerTag>
[src]

pub fn allocate_with(
    &mut self,
    alloc: Allocation,
    kind: MemoryKind<M::MemoryKind>
) -> Pointer<M::PointerTag>
[src]

pub fn reallocate(
    &mut self,
    ptr: Pointer<M::PointerTag>,
    old_size_and_align: Option<(Size, Align)>,
    new_size: Size,
    new_align: Align,
    kind: MemoryKind<M::MemoryKind>
) -> InterpResult<'tcx, Pointer<M::PointerTag>>
[src]

pub fn deallocate_local(
    &mut self,
    ptr: Pointer<M::PointerTag>
) -> InterpResult<'tcx>
[src]

Deallocate a local, or do nothing if that local has been made into a global.

pub fn deallocate(
    &mut self,
    ptr: Pointer<M::PointerTag>,
    old_size_and_align: Option<(Size, Align)>,
    kind: MemoryKind<M::MemoryKind>
) -> InterpResult<'tcx>
[src]

pub fn check_ptr_access(
    &self,
    sptr: Scalar<M::PointerTag>,
    size: Size,
    align: Align
) -> InterpResult<'tcx, Option<Pointer<M::PointerTag>>>
[src]

Check if the given scalar is allowed to do a memory access of given size and align. On success, returns None for zero-sized accesses (where nothing else is left to do) and a Pointer to use for the actual access otherwise. Crucially, if the input is a Pointer, we will test it for liveness even if the size is 0.

Everyone accessing memory based on a Scalar should use this method to get the Pointer they need. And even if you already have a Pointer, call this method to make sure it is sufficiently aligned and not dangling. Not doing that may cause ICEs.

Most of the time you should use check_mplace_access, but when you just have a pointer, this method is still appropriate.

pub fn check_ptr_access_align(
    &self,
    sptr: Scalar<M::PointerTag>,
    size: Size,
    align: Option<Align>,
    msg: CheckInAllocMsg
) -> InterpResult<'tcx, Option<Pointer<M::PointerTag>>>
[src]

Like check_ptr_access, but definitely checks alignment when align is Some (overriding M::enforce_alignment). Also lets the caller control the error message for the out-of-bounds case.

pub fn ptr_may_be_null(&self, ptr: Pointer<M::PointerTag>) -> bool[src]

Test if the pointer might be NULL.

impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M>[src]

Allocation accessors

pub(in interpret::memory) fn get_global_alloc(
    memory_extra: &M::MemoryExtra,
    tcx: TyCtxt<'tcx>,
    id: AllocId,
    is_write: bool
) -> InterpResult<'tcx, Cow<'tcx, Allocation<M::PointerTag, M::AllocExtra>>>
[src]

Helper function to obtain a global (tcx) allocation. This attempts to return a reference to an existing allocation if one can be found in tcx. That, however, is only possible if tcx and this machine use the same pointer tag, so it is indirected through M::tag_allocation.

pub fn get_raw(
    &self,
    id: AllocId
) -> InterpResult<'tcx, &Allocation<M::PointerTag, M::AllocExtra>>
[src]

Gives raw access to the Allocation, without bounds or alignment checks. Use the higher-level, PlaceTy- and OpTy-based APIs in InterpCx instead!

pub fn get_raw_mut(
    &mut self,
    id: AllocId
) -> InterpResult<'tcx, &mut Allocation<M::PointerTag, M::AllocExtra>>
[src]

Gives raw mutable access to the Allocation, without bounds or alignment checks. Use the higher-level, PlaceTy- and OpTy-based APIs in InterpCx instead!

pub fn get_size_and_align(
    &self,
    id: AllocId,
    liveness: AllocCheck
) -> InterpResult<'static, (Size, Align)>
[src]

Obtain the size and alignment of an allocation, even if that allocation has been deallocated.

If liveness is AllocCheck::MaybeDead, this function always returns Ok.

pub(in interpret::memory) fn get_fn_alloc(
    &self,
    id: AllocId
) -> Option<FnVal<'tcx, M::ExtraFnVal>>
[src]

pub fn get_fn(
    &self,
    ptr: Scalar<M::PointerTag>
) -> InterpResult<'tcx, FnVal<'tcx, M::ExtraFnVal>>
[src]

pub fn mark_immutable(&mut self, id: AllocId) -> InterpResult<'tcx>[src]

#[must_use]pub fn dump_alloc<'a>(&'a self, id: AllocId) -> DumpAllocs<'a, 'mir, 'tcx, M>[src]

Create a lazy debug printer that prints the given allocation and all allocations it points to, recursively.

#[must_use]pub fn dump_allocs<'a>(
    &'a self,
    allocs: Vec<AllocId>
) -> DumpAllocs<'a, 'mir, 'tcx, M>
[src]

Create a lazy debug printer for a list of allocations and all allocations they point to, recursively.

pub fn leak_report(&self, static_roots: &[AllocId]) -> usize[src]

Print leaked memory. Allocations reachable from static_roots or a Global allocation are not considered leaked. Leaks whose kind may_leak() returns true are not reported.

pub fn alloc_map(&self) -> &M::MemoryMap[src]

This is used by priroda

impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M>[src]

Reading and writing.

pub fn read_bytes(
    &self,
    ptr: Scalar<M::PointerTag>,
    size: Size
) -> InterpResult<'tcx, &[u8]>
[src]

Reads the given number of bytes from memory. Returns them as a slice.

Performs appropriate bounds checks.

pub fn read_c_str(
    &self,
    ptr: Scalar<M::PointerTag>
) -> InterpResult<'tcx, &[u8]>
[src]

Reads a 0-terminated sequence of bytes from memory. Returns them as a slice.

Performs appropriate bounds checks.

pub fn read_wide_str(
    &self,
    ptr: Scalar<M::PointerTag>
) -> InterpResult<'tcx, Vec<u16>>
[src]

Reads a 0x0000-terminated u16-sequence from memory. Returns them as a Vec. Terminator 0x0000 is not included in the returned Vec.

Performs appropriate bounds checks.

pub fn write_bytes(
    &mut self,
    ptr: Scalar<M::PointerTag>,
    src: impl IntoIterator<Item = u8>
) -> InterpResult<'tcx>
[src]

Writes the given stream of bytes into memory.

Performs appropriate bounds checks.

pub fn write_u16s(
    &mut self,
    ptr: Scalar<M::PointerTag>,
    src: impl IntoIterator<Item = u16>
) -> InterpResult<'tcx>
[src]

Writes the given stream of u16s into memory.

Performs appropriate bounds checks.

pub fn copy(
    &mut self,
    src: Pointer<M::PointerTag>,
    dest: Pointer<M::PointerTag>,
    size: Size,
    nonoverlapping: bool
) -> InterpResult<'tcx>
[src]

Expects the caller to have checked bounds and alignment.

pub fn copy_repeatedly(
    &mut self,
    src: Pointer<M::PointerTag>,
    dest: Pointer<M::PointerTag>,
    size: Size,
    length: u64,
    nonoverlapping: bool
) -> InterpResult<'tcx>
[src]

Expects the caller to have checked bounds and alignment.

impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M>[src]

Machine pointer introspection.

pub fn force_ptr(
    &self,
    scalar: Scalar<M::PointerTag>
) -> InterpResult<'tcx, Pointer<M::PointerTag>>
[src]

pub fn force_bits(
    &self,
    scalar: Scalar<M::PointerTag>,
    size: Size
) -> InterpResult<'tcx, u128>
[src]

Trait Implementations

impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> HasDataLayout for Memory<'mir, 'tcx, M>[src]

Auto Trait Implementations

impl<'mir, 'tcx, M> !RefUnwindSafe for Memory<'mir, 'tcx, M>

impl<'mir, 'tcx, M> !Send for Memory<'mir, 'tcx, M>

impl<'mir, 'tcx, M> !Sync for Memory<'mir, 'tcx, M>

impl<'mir, 'tcx, M> Unpin for Memory<'mir, 'tcx, M> where
    <M as Machine<'mir, 'tcx>>::ExtraFnVal: Unpin,
    <M as Machine<'mir, 'tcx>>::MemoryExtra: Unpin,
    <M as Machine<'mir, 'tcx>>::MemoryMap: Unpin, 

impl<'mir, 'tcx, M> !UnwindSafe for Memory<'mir, 'tcx, M>

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> PointerArithmetic for T where
    T: HasDataLayout, 
[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.

impl<T> WithConstness for T[src]