Auto merge of #116724 - RalfJung:alloc-bytes, r=oli-obk
interpret: clean up AllocBytes Fixes https://github.com/rust-lang/miri/issues/2836 Nothing has moved here in half a year, so let's just remove these unused stubs -- they need a proper re-design anyway. r? `@oli-obk`
This commit is contained in:
commit
a00c09e9d8
2 changed files with 5 additions and 24 deletions
|
@ -538,17 +538,6 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get the base address for the bytes in an `Allocation` specified by the
|
|
||||||
/// `AllocID` passed in; error if no such allocation exists.
|
|
||||||
///
|
|
||||||
/// It is up to the caller to take sufficient care when using this address:
|
|
||||||
/// there could be provenance or uninit memory in there, and other memory
|
|
||||||
/// accesses could invalidate the exposed pointer.
|
|
||||||
pub fn alloc_base_addr(&self, id: AllocId) -> InterpResult<'tcx, *const u8> {
|
|
||||||
let alloc = self.get_alloc_raw(id)?;
|
|
||||||
Ok(alloc.base_addr())
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Gives raw access to the `Allocation`, without bounds or alignment checks.
|
/// Gives raw access to the `Allocation`, without bounds or alignment checks.
|
||||||
/// The caller is responsible for calling the access hooks!
|
/// The caller is responsible for calling the access hooks!
|
||||||
///
|
///
|
||||||
|
|
|
@ -32,23 +32,16 @@ pub use init_mask::{InitChunk, InitChunkIter};
|
||||||
pub trait AllocBytes:
|
pub trait AllocBytes:
|
||||||
Clone + fmt::Debug + Eq + PartialEq + Hash + Deref<Target = [u8]> + DerefMut<Target = [u8]>
|
Clone + 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.
|
|
||||||
fn adjust_to_align(self, _align: Align) -> Self;
|
|
||||||
|
|
||||||
/// Create an `AllocBytes` from a slice of `u8`.
|
/// Create an `AllocBytes` from a slice of `u8`.
|
||||||
fn from_bytes<'a>(slice: impl Into<Cow<'a, [u8]>>, _align: Align) -> Self;
|
fn from_bytes<'a>(slice: impl Into<Cow<'a, [u8]>>, _align: Align) -> Self;
|
||||||
|
|
||||||
/// Create a zeroed `AllocBytes` of the specified size and alignment;
|
/// Create a zeroed `AllocBytes` of the specified size and alignment.
|
||||||
/// call the callback error handler if there is an error in allocating the memory.
|
/// Returns `None` if we ran out of memory on the host.
|
||||||
fn zeroed(size: Size, _align: Align) -> Option<Self>;
|
fn zeroed(size: Size, _align: Align) -> Option<Self>;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Default `bytes` for `Allocation` is a `Box<[u8]>`.
|
// Default `bytes` for `Allocation` is a `Box<[u8]>`.
|
||||||
impl AllocBytes for Box<[u8]> {
|
impl AllocBytes for Box<[u8]> {
|
||||||
fn adjust_to_align(self, _align: Align) -> Self {
|
|
||||||
self
|
|
||||||
}
|
|
||||||
|
|
||||||
fn from_bytes<'a>(slice: impl Into<Cow<'a, [u8]>>, _align: Align) -> Self {
|
fn from_bytes<'a>(slice: impl Into<Cow<'a, [u8]>>, _align: Align) -> Self {
|
||||||
Box::<[u8]>::from(slice.into())
|
Box::<[u8]>::from(slice.into())
|
||||||
}
|
}
|
||||||
|
@ -299,6 +292,7 @@ impl<Prov: Provenance, Bytes: AllocBytes> Allocation<Prov, (), Bytes> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn uninit_inner<R>(size: Size, align: Align, fail: impl FnOnce() -> R) -> Result<Self, R> {
|
fn uninit_inner<R>(size: Size, align: Align, fail: impl FnOnce() -> R) -> Result<Self, R> {
|
||||||
|
// We raise an error if we cannot create the allocation on the host.
|
||||||
// This results in an error that can happen non-deterministically, since the memory
|
// This results in an error that can happen non-deterministically, since the memory
|
||||||
// available to the compiler can change between runs. Normally queries are always
|
// available to the compiler can change between runs. Normally queries are always
|
||||||
// deterministic. However, we can be non-deterministic here because all uses of const
|
// deterministic. However, we can be non-deterministic here because all uses of const
|
||||||
|
@ -351,10 +345,8 @@ impl<Bytes: AllocBytes> Allocation<AllocId, (), Bytes> {
|
||||||
extra: Extra,
|
extra: Extra,
|
||||||
mut adjust_ptr: impl FnMut(Pointer<AllocId>) -> Result<Pointer<Prov>, Err>,
|
mut adjust_ptr: impl FnMut(Pointer<AllocId>) -> Result<Pointer<Prov>, Err>,
|
||||||
) -> Result<Allocation<Prov, Extra, Bytes>, Err> {
|
) -> Result<Allocation<Prov, Extra, Bytes>, Err> {
|
||||||
// Compute new pointer provenance, which also adjusts the bytes, and realign the pointer if
|
let mut bytes = self.bytes;
|
||||||
// necessary.
|
// Adjust provenance of pointers stored in this allocation.
|
||||||
let mut bytes = self.bytes.adjust_to_align(self.align);
|
|
||||||
|
|
||||||
let mut new_provenance = Vec::with_capacity(self.provenance.ptrs().len());
|
let mut new_provenance = Vec::with_capacity(self.provenance.ptrs().len());
|
||||||
let ptr_size = cx.data_layout().pointer_size.bytes_usize();
|
let ptr_size = cx.data_layout().pointer_size.bytes_usize();
|
||||||
let endian = cx.data_layout().endian;
|
let endian = cx.data_layout().endian;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue