1
Fork 0

Add post-initialization hook for static memory initialized using the interpereter.

This commit is contained in:
JCTyblaidd 2020-12-11 18:42:36 +00:00
parent a9f7d19a91
commit 56d89364a5
2 changed files with 14 additions and 1 deletions

View file

@ -9,6 +9,7 @@ use std::hash::Hash;
use rustc_middle::mir; use rustc_middle::mir;
use rustc_middle::ty::{self, Ty}; use rustc_middle::ty::{self, Ty};
use rustc_span::def_id::DefId; use rustc_span::def_id::DefId;
use rustc_target::abi::Size;
use super::{ use super::{
AllocId, Allocation, AllocationExtra, CheckInAllocMsg, Frame, ImmTy, InterpCx, InterpResult, AllocId, Allocation, AllocationExtra, CheckInAllocMsg, Frame, ImmTy, InterpCx, InterpResult,
@ -299,6 +300,15 @@ pub trait Machine<'mir, 'tcx>: Sized {
Ok(()) Ok(())
} }
/// Called after initializing static memory using the interpreter.
fn after_static_mem_initialized(
_ecx: &mut InterpCx<'mir, 'tcx, Self>,
_ptr: Pointer<Self::PointerTag>,
_size: Size
) -> InterpResult<'tcx> {
Ok(())
}
/// Executes a retagging operation /// Executes a retagging operation
#[inline] #[inline]
fn retag( fn retag(

View file

@ -56,8 +56,9 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
// If you touch this code, be sure to also make the corresponding changes to // If you touch this code, be sure to also make the corresponding changes to
// `get_vtable` in `rust_codegen_llvm/meth.rs`. // `get_vtable` in `rust_codegen_llvm/meth.rs`.
// ///////////////////////////////////////////////////////////////////////////////////////// // /////////////////////////////////////////////////////////////////////////////////////////
let vtable_size = ptr_size * u64::try_from(methods.len()).unwrap().checked_add(3).unwrap();
let vtable = self.memory.allocate( let vtable = self.memory.allocate(
ptr_size * u64::try_from(methods.len()).unwrap().checked_add(3).unwrap(), vtable_size,
ptr_align, ptr_align,
MemoryKind::Vtable, MemoryKind::Vtable,
); );
@ -93,6 +94,8 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
} }
} }
M::after_static_mem_initialized(self, vtable, vtable_size)?;
self.memory.mark_immutable(vtable.alloc_id)?; self.memory.mark_immutable(vtable.alloc_id)?;
assert!(self.vtables.insert((ty, poly_trait_ref), vtable).is_none()); assert!(self.vtables.insert((ty, poly_trait_ref), vtable).is_none());