/// Used by `check_in_alloc` to indicate context of check
#[derive(Debug, Copy, Clone, RustcEncodable, RustcDecodable, HashStable)]
pub enum CheckInAllocMsg {
- ReadCStr,
- CheckBytes,
- WriteBytes,
- WriteRepeat,
- ReadScalar,
- WriteScalar,
- SlicePatCoveredByConst,
- ReadDiscriminant,
- CheckAlign,
- ReadBytes,
- CopyRepeatedly,
- CheckBounds,
+ MemoryAccess,
+ NullPointer,
+ PointerArithmetic,
+ OutOfBounds,
}
impl Display for CheckInAllocMsg {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}", match *self {
- CheckInAllocMsg::ReadCStr => "read C str",
- CheckInAllocMsg::CheckBytes => "check bytes",
- CheckInAllocMsg::WriteBytes => "write bytes",
- CheckInAllocMsg::WriteRepeat => "write repeat",
- CheckInAllocMsg::ReadScalar => "read scalar",
- CheckInAllocMsg::WriteScalar => "write scalar",
- CheckInAllocMsg::SlicePatCoveredByConst => "slice pat covered by const",
- CheckInAllocMsg::ReadDiscriminant => "read discriminant",
- CheckInAllocMsg::CheckAlign => "check align",
- CheckInAllocMsg::ReadBytes => "read bytes",
- CheckInAllocMsg::CopyRepeatedly => "copy repeatedly",
- CheckInAllocMsg::CheckBounds => "check bounds",
+ CheckInAllocMsg::MemoryAccess => "memory access",
+ CheckInAllocMsg::NullPointer => "null pointer",
+ CheckInAllocMsg::PointerArithmetic => "pointer arithmetic",
+ CheckInAllocMsg::OutOfBounds => "out of bounds",
})
}
}
// Go through `get_bytes` for checks and AllocationExtra hooks.
// We read the null, so we include it in the request, but we want it removed
// from the result!
- Ok(&self.get_bytes(cx, ptr, size_with_null, CheckInAllocMsg::ReadCStr)?[..size])
+ Ok(&self.get_bytes(cx, ptr, size_with_null, CheckInAllocMsg::NullPointer)?[..size])
}
None => err!(UnterminatedCString(ptr.erase_tag())),
}
where Extra: AllocationExtra<Tag, MemoryExtra>
{
// Check bounds and relocations on the edges
- self.get_bytes_with_undef_and_ptr(cx, ptr, size, CheckInAllocMsg::CheckBytes)?;
+ self.get_bytes_with_undef_and_ptr(cx, ptr, size, CheckInAllocMsg::OutOfBounds)?;
// Check undef and ptr
if !allow_ptr_and_undef {
self.check_defined(ptr, size)?;
where Extra: AllocationExtra<Tag, MemoryExtra>
{
let bytes = self.get_bytes_mut(cx, ptr, Size::from_bytes(src.len() as u64),
- CheckInAllocMsg::WriteBytes)?;
+ CheckInAllocMsg::MemoryAccess)?;
bytes.clone_from_slice(src);
Ok(())
}
// FIXME: Working around https://github.com/rust-lang/rust/issues/56209
where Extra: AllocationExtra<Tag, MemoryExtra>
{
- let bytes = self.get_bytes_mut(cx, ptr, count, CheckInAllocMsg::WriteRepeat)?;
+ let bytes = self.get_bytes_mut(cx, ptr, count, CheckInAllocMsg::MemoryAccess)?;
for b in bytes {
*b = val;
}
where Extra: AllocationExtra<Tag, MemoryExtra>
{
// get_bytes_unchecked tests relocation edges
- let bytes = self.get_bytes_with_undef_and_ptr(cx, ptr, size, CheckInAllocMsg::ReadScalar)?;
+ let bytes = self.get_bytes_with_undef_and_ptr(cx, ptr, size, CheckInAllocMsg::PointerArithmetic)?;
// Undef check happens *after* we established that the alignment is correct.
// We must not return Ok() for unaligned pointers!
if self.check_defined(ptr, size).is_err() {
};
let endian = cx.data_layout().endian;
- let dst = self.get_bytes_mut(cx, ptr, type_size, CheckInAllocMsg::WriteScalar)?;
+ let dst = self.get_bytes_mut(cx, ptr, type_size, CheckInAllocMsg::PointerArithmetic)?;
write_target_uint(endian, dst, bytes).unwrap();
// See if we have to also write a relocation
Scalar::Ptr(ptr) => {
// check this is not NULL -- which we can ensure only if this is in-bounds
// of some (potentially dead) allocation.
- let align = self.check_bounds_ptr(ptr, CheckInAllocMsg::CheckAlign)?;
+ let align = self.check_bounds_ptr(ptr, CheckInAllocMsg::NullPointer)?;
(ptr.offset.bytes(), align)
}
Scalar::Bits { bits, size } => {
Ok((layout.size, layout.align.abi))
}
_ => match msg {
- CheckInAllocMsg::CheckAlign | CheckInAllocMsg::ReadDiscriminant => {
+ CheckInAllocMsg::NullPointer | CheckInAllocMsg::OutOfBounds => {
// Must be a deallocated pointer
Ok(*self.dead_alloc_map.get(&id).expect(
"allocation missing in dead_alloc_map"
Ok(&[])
} else {
let ptr = ptr.to_ptr()?;
- self.get(ptr.alloc_id)?.get_bytes(self, ptr, size, CheckInAllocMsg::ReadBytes)
+ self.get(ptr.alloc_id)?.get_bytes(self, ptr, size, CheckInAllocMsg::MemoryAccess)
}
}
}
// This checks relocation edges on the src.
let src_bytes = self.get(src.alloc_id)?
- .get_bytes_with_undef_and_ptr(&tcx, src, size, CheckInAllocMsg::CopyRepeatedly)?
+ .get_bytes_with_undef_and_ptr(&tcx, src, size, CheckInAllocMsg::MemoryAccess)?
.as_ptr();
let dest_bytes = self.get_mut(dest.alloc_id)?
- .get_bytes_mut(&tcx, dest, size * length, CheckInAllocMsg::CopyRepeatedly)?
+ .get_bytes_mut(&tcx, dest, size * length, CheckInAllocMsg::MemoryAccess)?
.as_mut_ptr();
// SAFE: The above indexing would have panicked if there weren't at least `size` bytes