Rollup merge of #126787 - Strophox:get-bytes, r=RalfJung
Add direct accessors for memory addresses in `Machine` (for Miri) The purpose of this PR is to enable direct (immutable) access to memory addresses in `Machine`, which will be needed for further extension of Miri. This is done by adding (/completing missings pairs of) accessor functions, with the relevant signatures as follows: ```rust /* rust/compiler/rustc_middle/src/mir/interpret/allocation.rs */ pub trait AllocBytes { // .. fn as_ptr(&self) -> *const u8; /*fn as_mut_ptr(&mut self) -> *mut u8; -- Already in the compiler*/ } impl<Prov: Provenance, Extra, Bytes: AllocBytes> Allocation<Prov, Extra, Bytes> { // .. pub fn get_bytes_unchecked_raw(&self) -> *const u8; /*pub fn get_bytes_unchecked_raw_mut(&mut self) -> *mut u8; -- Already in the compiler*/ } ``` ```rust /* rust/compiler/rustc_const_eval/src/interpret/memory.rs */ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> { // .. pub fn get_alloc_bytes_unchecked_raw(&self, id: AllocId) -> InterpResult<'tcx, *const u8>; pub fn get_alloc_bytes_unchecked_raw_mut(&mut self, id: AllocId) -> InterpResult<'tcx, *mut u8>; } ``` r? ``@RalfJung``
This commit is contained in:
commit
9498d5cf2f
3 changed files with 44 additions and 3 deletions
|
@ -630,6 +630,13 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
|
|||
}
|
||||
}
|
||||
|
||||
/// Gives raw, immutable access to the `Allocation` address, without bounds or alignment checks.
|
||||
/// The caller is responsible for calling the access hooks!
|
||||
pub fn get_alloc_bytes_unchecked_raw(&self, id: AllocId) -> InterpResult<'tcx, *const u8> {
|
||||
let alloc = self.get_alloc_raw(id)?;
|
||||
Ok(alloc.get_bytes_unchecked_raw())
|
||||
}
|
||||
|
||||
/// Bounds-checked *but not align-checked* allocation access.
|
||||
pub fn get_ptr_alloc<'a>(
|
||||
&'a self,
|
||||
|
@ -713,6 +720,16 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
|
|||
Ok((alloc, &mut self.machine))
|
||||
}
|
||||
|
||||
/// Gives raw, mutable access to the `Allocation` address, without bounds or alignment checks.
|
||||
/// The caller is responsible for calling the access hooks!
|
||||
pub fn get_alloc_bytes_unchecked_raw_mut(
|
||||
&mut self,
|
||||
id: AllocId,
|
||||
) -> InterpResult<'tcx, *mut u8> {
|
||||
let alloc = self.get_alloc_raw_mut(id)?.0;
|
||||
Ok(alloc.get_bytes_unchecked_raw_mut())
|
||||
}
|
||||
|
||||
/// Bounds-checked *but not align-checked* allocation access.
|
||||
pub fn get_ptr_alloc_mut<'a>(
|
||||
&'a mut self,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue