CTFE Machine: do not expose Allocation
This commit is contained in:
parent
3e827cc21e
commit
50a9f008f2
@ -313,7 +313,7 @@ fn init_allocation_extra<'b>(
|
|||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
fn memory_read(
|
fn memory_read(
|
||||||
_memory_extra: &Self::MemoryExtra,
|
_memory_extra: &Self::MemoryExtra,
|
||||||
_alloc: &Allocation<Self::PointerTag, Self::AllocExtra>,
|
_alloc_extra: &Self::AllocExtra,
|
||||||
_ptr: Pointer<Self::PointerTag>,
|
_ptr: Pointer<Self::PointerTag>,
|
||||||
_size: Size,
|
_size: Size,
|
||||||
) -> InterpResult<'tcx> {
|
) -> InterpResult<'tcx> {
|
||||||
@ -324,7 +324,7 @@ fn memory_read(
|
|||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
fn memory_written(
|
fn memory_written(
|
||||||
_memory_extra: &mut Self::MemoryExtra,
|
_memory_extra: &mut Self::MemoryExtra,
|
||||||
_alloc: &mut Allocation<Self::PointerTag, Self::AllocExtra>,
|
_alloc_extra: &mut Self::AllocExtra,
|
||||||
_ptr: Pointer<Self::PointerTag>,
|
_ptr: Pointer<Self::PointerTag>,
|
||||||
_size: Size,
|
_size: Size,
|
||||||
) -> InterpResult<'tcx> {
|
) -> InterpResult<'tcx> {
|
||||||
@ -335,8 +335,9 @@ fn memory_written(
|
|||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
fn memory_deallocated(
|
fn memory_deallocated(
|
||||||
_memory_extra: &mut Self::MemoryExtra,
|
_memory_extra: &mut Self::MemoryExtra,
|
||||||
_alloc: &mut Allocation<Self::PointerTag, Self::AllocExtra>,
|
_alloc_extra: &mut Self::AllocExtra,
|
||||||
_ptr: Pointer<Self::PointerTag>,
|
_ptr: Pointer<Self::PointerTag>,
|
||||||
|
_size: Size,
|
||||||
) -> InterpResult<'tcx> {
|
) -> InterpResult<'tcx> {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
@ -343,10 +343,11 @@ pub fn deallocate(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Let the machine take some extra action
|
// Let the machine take some extra action
|
||||||
M::memory_deallocated(&mut self.extra, &mut alloc, ptr)?;
|
let size = alloc.size();
|
||||||
|
M::memory_deallocated(&mut self.extra, &mut alloc.extra, ptr, size)?;
|
||||||
|
|
||||||
// Don't forget to remember size and align of this now-dead allocation
|
// Don't forget to remember size and align of this now-dead allocation
|
||||||
let old = self.dead_alloc_map.insert(ptr.alloc_id, (alloc.size(), alloc.align));
|
let old = self.dead_alloc_map.insert(ptr.alloc_id, (size, alloc.align));
|
||||||
if old.is_some() {
|
if old.is_some() {
|
||||||
bug!("Nothing can be deallocated twice");
|
bug!("Nothing can be deallocated twice");
|
||||||
}
|
}
|
||||||
@ -591,7 +592,7 @@ pub fn get<'a>(
|
|||||||
},
|
},
|
||||||
)?;
|
)?;
|
||||||
if let Some((ptr, alloc)) = ptr_and_alloc {
|
if let Some((ptr, alloc)) = ptr_and_alloc {
|
||||||
M::memory_read(&self.extra, alloc, ptr, size)?;
|
M::memory_read(&self.extra, &alloc.extra, ptr, size)?;
|
||||||
let range = alloc_range(ptr.offset, size);
|
let range = alloc_range(ptr.offset, size);
|
||||||
Ok(Some(AllocRef { alloc, range, tcx: self.tcx, alloc_id: ptr.alloc_id }))
|
Ok(Some(AllocRef { alloc, range, tcx: self.tcx, alloc_id: ptr.alloc_id }))
|
||||||
} else {
|
} else {
|
||||||
@ -660,7 +661,7 @@ pub fn get_mut<'a>(
|
|||||||
// FIXME: can we somehow avoid looking up the allocation twice here?
|
// FIXME: can we somehow avoid looking up the allocation twice here?
|
||||||
// We cannot call `get_raw_mut` inside `check_and_deref_ptr` as that would duplicate `&mut self`.
|
// We cannot call `get_raw_mut` inside `check_and_deref_ptr` as that would duplicate `&mut self`.
|
||||||
let (alloc, extra) = self.get_raw_mut(ptr.alloc_id)?;
|
let (alloc, extra) = self.get_raw_mut(ptr.alloc_id)?;
|
||||||
M::memory_written(extra, alloc, ptr, size)?;
|
M::memory_written(extra, &mut alloc.extra, ptr, size)?;
|
||||||
let range = alloc_range(ptr.offset, size);
|
let range = alloc_range(ptr.offset, size);
|
||||||
Ok(Some(AllocRefMut { alloc, range, tcx, alloc_id: ptr.alloc_id }))
|
Ok(Some(AllocRefMut { alloc, range, tcx, alloc_id: ptr.alloc_id }))
|
||||||
} else {
|
} else {
|
||||||
@ -1029,7 +1030,7 @@ pub fn copy_repeatedly(
|
|||||||
Some(src_ptr) => src_ptr,
|
Some(src_ptr) => src_ptr,
|
||||||
};
|
};
|
||||||
let src_alloc = self.get_raw(src.alloc_id)?;
|
let src_alloc = self.get_raw(src.alloc_id)?;
|
||||||
M::memory_read(&self.extra, src_alloc, src, size)?;
|
M::memory_read(&self.extra, &src_alloc.extra, src, size)?;
|
||||||
// We need the `dest` ptr for the next operation, so we get it now.
|
// We need the `dest` ptr for the next operation, so we get it now.
|
||||||
// We already did the source checks and called the hooks so we are good to return early.
|
// We already did the source checks and called the hooks so we are good to return early.
|
||||||
let dest = match dest {
|
let dest = match dest {
|
||||||
@ -1058,7 +1059,7 @@ pub fn copy_repeatedly(
|
|||||||
|
|
||||||
// Destination alloc preparations and access hooks.
|
// Destination alloc preparations and access hooks.
|
||||||
let (dest_alloc, extra) = self.get_raw_mut(dest.alloc_id)?;
|
let (dest_alloc, extra) = self.get_raw_mut(dest.alloc_id)?;
|
||||||
M::memory_written(extra, dest_alloc, dest, size * num_copies)?;
|
M::memory_written(extra, &mut dest_alloc.extra, dest, size * num_copies)?;
|
||||||
let dest_bytes = dest_alloc
|
let dest_bytes = dest_alloc
|
||||||
.get_bytes_mut_ptr(&tcx, alloc_range(dest.offset, size * num_copies))
|
.get_bytes_mut_ptr(&tcx, alloc_range(dest.offset, size * num_copies))
|
||||||
.as_mut_ptr();
|
.as_mut_ptr();
|
||||||
|
Loading…
Reference in New Issue
Block a user