Struct rustc_const_eval::interpret::memory::Memory[][src]

pub struct Memory<'mir, 'tcx, M: Machine<'mir, 'tcx>> {
    pub(super) alloc_map: M::MemoryMap,
    extra_fn_ptr_map: FxHashMap<AllocId, M::ExtraFnVal>,
    pub(super) 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

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.

Internal helper function to determine the allocation and offset of a pointer (if any).

Check if the given pointer points to live memory of given size and align (ignoring M::enforce_alignment). The caller can control the error message for the out-of-bounds case.

Low-level helper function to check if a ptr is in-bounds and potentially return a reference to the allocation it points to. Supports both shared and mutable references, as the actual checking is offloaded to a helper closure. align defines whether and which alignment check is done. Returns None for size 0, and otherwise Some of what alloc_size returned.

Test if the pointer might be null.

Allocation accessors

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.

Gives raw access to the Allocation, without bounds or alignment checks. The caller is responsible for calling the access hooks!

“Safe” (bounds and align-checked) allocation access.

Return the extra field of the given allocation.

Gives raw mutable access to the Allocation, without bounds or alignment checks. The caller is responsible for calling the access hooks!

Also returns a ptr to self.extra so that the caller can use it in parallel with the allocation.

“Safe” (bounds and align-checked) allocation access.

Return the extra field of the given allocation.

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.

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

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

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.

This is used by priroda

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

Performs appropriate bounds checks.

Writes the given stream of bytes into memory.

Performs appropriate bounds checks.

Machine pointer introspection.

Turning a “maybe pointer” into a proper pointer (and some information about where it points), or an absolute address.

Turning a “maybe pointer” into a proper pointer (and some information about where it points).

Trait Implementations

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

Helper function: truncate given value-“overflowed flag” pair to pointer size and update “overflowed flag” if there was an overflow. This should be called by all the other methods before returning! Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

Layout

Note: Unable to compute type layout, possibly due to this type having generic parameters. Layout can only be computed for concrete, fully-instantiated types.