]> git.lizzy.rs Git - rust.git/commitdiff
Add post-initialization hook for static memory initialized using the interpereter.
authorJCTyblaidd <JCTyblaidd@users.noreply.github.com>
Fri, 11 Dec 2020 18:42:36 +0000 (18:42 +0000)
committerJCTyblaidd <JCTyblaidd@users.noreply.github.com>
Fri, 11 Dec 2020 18:42:36 +0000 (18:42 +0000)
compiler/rustc_mir/src/interpret/machine.rs
compiler/rustc_mir/src/interpret/traits.rs

index 74625569432c3b59a64f5a16fb98d5d81a2ea35b..67166062d40dabbdf3580bad9aef1f45dfd6c1e2 100644 (file)
@@ -9,6 +9,7 @@
 use rustc_middle::mir;
 use rustc_middle::ty::{self, Ty};
 use rustc_span::def_id::DefId;
+use rustc_target::abi::Size;
 
 use super::{
     AllocId, Allocation, AllocationExtra, CheckInAllocMsg, Frame, ImmTy, InterpCx, InterpResult,
@@ -299,6 +300,15 @@ fn before_deallocation(
         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
     #[inline]
     fn retag(
index fa7036f4e5b02df327b547acb8d563ed6c2521ab..18dba4775980b513760f9d372b77daf51872a454 100644 (file)
@@ -56,8 +56,9 @@ pub fn get_vtable(
         // If you touch this code, be sure to also make the corresponding changes to
         // `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(
-            ptr_size * u64::try_from(methods.len()).unwrap().checked_add(3).unwrap(),
+            vtable_size,
             ptr_align,
             MemoryKind::Vtable,
         );
@@ -93,6 +94,8 @@ pub fn get_vtable(
             }
         }
 
+        M::after_static_mem_initialized(self, vtable, vtable_size)?;
+
         self.memory.mark_immutable(vtable.alloc_id)?;
         assert!(self.vtables.insert((ty, poly_trait_ref), vtable).is_none());