Minimal changes to make miri work

This commit is contained in:
Rune Tynan 2023-02-14 15:26:47 -05:00
parent 871c1dee33
commit 936b567d2e
No known key found for this signature in database
GPG Key ID: 7ECC932F8B2C731E
6 changed files with 23 additions and 23 deletions

View File

@ -16,8 +16,8 @@
use crate::const_eval::CheckAlignment; use crate::const_eval::CheckAlignment;
use super::{ use super::{
AllocId, AllocRange, Allocation, AllocBytes, ConstAllocation, Frame, ImmTy, InterpCx, InterpResult, AllocBytes, AllocId, AllocRange, Allocation, ConstAllocation, Frame, ImmTy, InterpCx,
MemoryKind, OpTy, Operand, PlaceTy, Pointer, Provenance, Scalar, StackPopUnwind, InterpResult, MemoryKind, OpTy, Operand, PlaceTy, Pointer, Provenance, Scalar, StackPopUnwind,
}; };
/// Data returned by Machine::stack_pop, /// Data returned by Machine::stack_pop,
@ -111,7 +111,10 @@ pub trait Machine<'mir, 'tcx>: Sized {
/// Memory's allocation map /// Memory's allocation map
type MemoryMap: AllocMap< type MemoryMap: AllocMap<
AllocId, AllocId,
(MemoryKind<Self::MemoryKind>, Allocation<Self::Provenance, Self::AllocExtra, Self::Bytes>), (
MemoryKind<Self::MemoryKind>,
Allocation<Self::Provenance, Self::AllocExtra, Self::Bytes>,
),
> + Default > + Default
+ Clone; + Clone;

View File

@ -581,7 +581,8 @@ pub fn get_ptr_alloc<'a>(
ptr: Pointer<Option<M::Provenance>>, ptr: Pointer<Option<M::Provenance>>,
size: Size, size: Size,
align: Align, align: Align,
) -> InterpResult<'tcx, Option<AllocRef<'a, 'tcx, M::Provenance, M::AllocExtra, M::Bytes>>> { ) -> InterpResult<'tcx, Option<AllocRef<'a, 'tcx, M::Provenance, M::AllocExtra, M::Bytes>>>
{
let ptr_and_alloc = self.check_and_deref_ptr( let ptr_and_alloc = self.check_and_deref_ptr(
ptr, ptr,
size, size,
@ -653,7 +654,8 @@ pub fn get_ptr_alloc_mut<'a>(
ptr: Pointer<Option<M::Provenance>>, ptr: Pointer<Option<M::Provenance>>,
size: Size, size: Size,
align: Align, align: Align,
) -> InterpResult<'tcx, Option<AllocRefMut<'a, 'tcx, M::Provenance, M::AllocExtra, M::Bytes>>> { ) -> InterpResult<'tcx, Option<AllocRefMut<'a, 'tcx, M::Provenance, M::AllocExtra, M::Bytes>>>
{
let parts = self.get_ptr_access(ptr, size, align)?; let parts = self.get_ptr_access(ptr, size, align)?;
if let Some((alloc_id, offset, prov)) = parts { if let Some((alloc_id, offset, prov)) = parts {
let tcx = *self.tcx; let tcx = *self.tcx;
@ -924,7 +926,9 @@ fn write_allocation_track_relocs<'tcx, Prov: Provenance, Extra, Bytes: AllocByte
} }
/// Reading and writing. /// Reading and writing.
impl<'tcx, 'a, Prov: Provenance, Extra, Bytes: AllocBytes> AllocRefMut<'a, 'tcx, Prov, Extra, Bytes> { impl<'tcx, 'a, Prov: Provenance, Extra, Bytes: AllocBytes>
AllocRefMut<'a, 'tcx, Prov, Extra, Bytes>
{
/// `range` is relative to this allocation reference, not the base of the allocation. /// `range` is relative to this allocation reference, not the base of the allocation.
pub fn write_scalar(&mut self, range: AllocRange, val: Scalar<Prov>) -> InterpResult<'tcx> { pub fn write_scalar(&mut self, range: AllocRange, val: Scalar<Prov>) -> InterpResult<'tcx> {
let range = self.range.subrange(range); let range = self.range.subrange(range);

View File

@ -340,7 +340,8 @@ pub fn deref_operand(
pub(super) fn get_place_alloc( pub(super) fn get_place_alloc(
&self, &self,
place: &MPlaceTy<'tcx, M::Provenance>, place: &MPlaceTy<'tcx, M::Provenance>,
) -> InterpResult<'tcx, Option<AllocRef<'_, 'tcx, M::Provenance, M::AllocExtra, M::Bytes>>> { ) -> InterpResult<'tcx, Option<AllocRef<'_, 'tcx, M::Provenance, M::AllocExtra, M::Bytes>>>
{
assert!(place.layout.is_sized()); assert!(place.layout.is_sized());
assert!(!place.meta.has_meta()); assert!(!place.meta.has_meta());
let size = place.layout.size; let size = place.layout.size;
@ -351,7 +352,8 @@ pub(super) fn get_place_alloc(
pub(super) fn get_place_alloc_mut( pub(super) fn get_place_alloc_mut(
&mut self, &mut self,
place: &MPlaceTy<'tcx, M::Provenance>, place: &MPlaceTy<'tcx, M::Provenance>,
) -> InterpResult<'tcx, Option<AllocRefMut<'_, 'tcx, M::Provenance, M::AllocExtra, M::Bytes>>> { ) -> InterpResult<'tcx, Option<AllocRefMut<'_, 'tcx, M::Provenance, M::AllocExtra, M::Bytes>>>
{
assert!(place.layout.is_sized()); assert!(place.layout.is_sized());
assert!(!place.meta.has_meta()); assert!(!place.meta.has_meta());
let size = place.layout.size; let size = place.layout.size;

View File

@ -32,13 +32,7 @@
/// Functionality required for the bytes of an `Allocation`. /// Functionality required for the bytes of an `Allocation`.
pub trait AllocBytes: pub trait AllocBytes:
Clone Clone + fmt::Debug + Eq + PartialEq + Hash + Deref<Target = [u8]> + DerefMut<Target = [u8]>
+ fmt::Debug
+ Eq
+ PartialEq
+ Hash
+ Deref<Target = [u8]>
+ DerefMut<Target = [u8]>
{ {
/// Adjust the bytes to the specified alignment -- by default, this is a no-op. /// Adjust the bytes to the specified alignment -- by default, this is a no-op.
fn adjust_to_align(self, _align: Align) -> Self; fn adjust_to_align(self, _align: Align) -> Self;
@ -271,11 +265,7 @@ pub fn subrange(self, subrange: AllocRange) -> AllocRange {
// The constructors are all without extra; the extra gets added by a machine hook later. // The constructors are all without extra; the extra gets added by a machine hook later.
impl<Prov: Provenance, Bytes: AllocBytes> Allocation<Prov, (), Bytes> { impl<Prov: Provenance, Bytes: AllocBytes> Allocation<Prov, (), Bytes> {
/// Creates an allocation from an existing `Bytes` value - this is needed for miri FFI support /// Creates an allocation from an existing `Bytes` value - this is needed for miri FFI support
pub fn from_raw_bytes( pub fn from_raw_bytes(bytes: Bytes, align: Align, mutability: Mutability) -> Self {
bytes: Bytes,
align: Align,
mutability: Mutability,
) -> Self {
let size = Size::from_bytes(bytes.len()); let size = Size::from_bytes(bytes.len());
Self { Self {
bytes, bytes,

View File

@ -127,8 +127,8 @@ macro_rules! throw_machine_stop {
pub use self::value::{get_slice_bytes, ConstAlloc, ConstValue, Scalar}; pub use self::value::{get_slice_bytes, ConstAlloc, ConstValue, Scalar};
pub use self::allocation::{ pub use self::allocation::{
alloc_range, AllocBytes, AllocError, AllocRange, AllocResult, Allocation, ConstAllocation, InitChunk, alloc_range, AllocBytes, AllocError, AllocRange, AllocResult, Allocation, ConstAllocation,
InitChunkIter, InitChunk, InitChunkIter,
}; };
pub use self::pointer::{Pointer, PointerArithmetic, Provenance}; pub use self::pointer::{Pointer, PointerArithmetic, Provenance};

View File

@ -771,10 +771,11 @@ impl<'mir, 'tcx> Machine<'mir, 'tcx> for MiriMachine<'mir, 'tcx> {
type Provenance = Provenance; type Provenance = Provenance;
type ProvenanceExtra = ProvenanceExtra; type ProvenanceExtra = ProvenanceExtra;
type Bytes = Box<[u8]>;
type MemoryMap = MonoHashMap< type MemoryMap = MonoHashMap<
AllocId, AllocId,
(MemoryKind<MiriMemoryKind>, Allocation<Provenance, Self::AllocExtra>), (MemoryKind<MiriMemoryKind>, Allocation<Provenance, Self::AllocExtra, Self::Bytes>),
>; >;
const GLOBAL_KIND: Option<MiriMemoryKind> = Some(MiriMemoryKind::Global); const GLOBAL_KIND: Option<MiriMemoryKind> = Some(MiriMemoryKind::Global);