interpret: support for per-byte provenance
This commit is contained in:
parent
452cf4f710
commit
2cef9e3d19
18 changed files with 506 additions and 291 deletions
|
@ -103,8 +103,7 @@ impl<T: HasDataLayout> PointerArithmetic for T {}
|
|||
/// This trait abstracts over the kind of provenance that is associated with a `Pointer`. It is
|
||||
/// mostly opaque; the `Machine` trait extends it with some more operations that also have access to
|
||||
/// some global state.
|
||||
/// We don't actually care about this `Debug` bound (we use `Provenance::fmt` to format the entire
|
||||
/// pointer), but `derive` adds some unnecessary bounds.
|
||||
/// The `Debug` rendering is used to distplay bare provenance, and for the default impl of `fmt`.
|
||||
pub trait Provenance: Copy + fmt::Debug {
|
||||
/// Says whether the `offset` field of `Pointer`s with this provenance is the actual physical address.
|
||||
/// - If `false`, the offset *must* be relative. This means the bytes representing a pointer are
|
||||
|
@ -115,14 +114,23 @@ pub trait Provenance: Copy + fmt::Debug {
|
|||
/// pointer, and implement ptr-to-int transmutation by stripping provenance.
|
||||
const OFFSET_IS_ADDR: bool;
|
||||
|
||||
/// We also use this trait to control whether to abort execution when a pointer is being partially overwritten
|
||||
/// (this avoids a separate trait in `allocation.rs` just for this purpose).
|
||||
const ERR_ON_PARTIAL_PTR_OVERWRITE: bool;
|
||||
|
||||
/// Determines how a pointer should be printed.
|
||||
///
|
||||
/// Default impl is only good for when `OFFSET_IS_ADDR == true`.
|
||||
fn fmt(ptr: &Pointer<Self>, f: &mut fmt::Formatter<'_>) -> fmt::Result
|
||||
where
|
||||
Self: Sized;
|
||||
Self: Sized,
|
||||
{
|
||||
assert!(Self::OFFSET_IS_ADDR);
|
||||
let (prov, addr) = ptr.into_parts(); // address is absolute
|
||||
write!(f, "{:#x}", addr.bytes())?;
|
||||
if f.alternate() {
|
||||
write!(f, "{prov:#?}")?;
|
||||
} else {
|
||||
write!(f, "{prov:?}")?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// If `OFFSET_IS_ADDR == false`, provenance must always be able to
|
||||
/// identify the allocation this ptr points to (i.e., this must return `Some`).
|
||||
|
@ -139,9 +147,6 @@ impl Provenance for AllocId {
|
|||
// so ptr-to-int casts are not possible (since we do not know the global physical offset).
|
||||
const OFFSET_IS_ADDR: bool = false;
|
||||
|
||||
// For now, do not allow this, so that we keep our options open.
|
||||
const ERR_ON_PARTIAL_PTR_OVERWRITE: bool = true;
|
||||
|
||||
fn fmt(ptr: &Pointer<Self>, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
// Forward `alternate` flag to `alloc_id` printing.
|
||||
if f.alternate() {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue