use tls::MemoryExt;
-use super::memory::Kind;
+use super::memory::MemoryKind;
pub trait EvalContextExt<'tcx> {
fn call_c_abi(
self.write_null(dest, dest_ty)?;
} else {
let align = self.memory.pointer_size();
- let ptr = self.memory.allocate(size, align, Kind::C.into())?;
+ let ptr = self.memory.allocate(size, align, MemoryKind::C.into())?;
self.write_primval(dest, PrimVal::Ptr(ptr), dest_ty)?;
}
}
"free" => {
let ptr = args[0].into_ptr(&mut self.memory)?;
if !ptr.is_null()? {
- self.memory.deallocate(ptr.to_ptr()?, None, Kind::C.into())?;
+ self.memory.deallocate(ptr.to_ptr()?, None, MemoryKind::C.into())?;
}
}
}
if let Some(old) = success {
if let Some(var) = old {
- self.memory.deallocate(var, None, Kind::Env.into())?;
+ self.memory.deallocate(var, None, MemoryKind::Env.into())?;
}
self.write_null(dest, dest_ty)?;
} else {
}
if let Some((name, value)) = new {
// +1 for the null terminator
- let value_copy = self.memory.allocate((value.len() + 1) as u64, 1, Kind::Env.into())?;
+ let value_copy = self.memory.allocate((value.len() + 1) as u64, 1, MemoryKind::Env.into())?;
self.memory.write_bytes(value_copy.into(), &value)?;
let trailing_zero_ptr = value_copy.offset(value.len() as u64, &self)?.into();
self.memory.write_bytes(trailing_zero_ptr, &[0])?;
if let Some(var) = self.machine_data.env_vars.insert(name.to_owned(), value_copy) {
- self.memory.deallocate(var, None, Kind::Env.into())?;
+ self.memory.deallocate(var, None, MemoryKind::Env.into())?;
}
self.write_null(dest, dest_ty)?;
} else {
if !align.is_power_of_two() {
return err!(HeapAllocNonPowerOfTwoAlignment(align));
}
- let ptr = self.memory.allocate(size, align, Kind::Rust.into())?;
+ let ptr = self.memory.allocate(size, align, MemoryKind::Rust.into())?;
self.write_primval(dest, PrimVal::Ptr(ptr), dest_ty)?;
}
"alloc::heap::::__rust_alloc_zeroed" => {
if !align.is_power_of_two() {
return err!(HeapAllocNonPowerOfTwoAlignment(align));
}
- let ptr = self.memory.allocate(size, align, Kind::Rust.into())?;
+ let ptr = self.memory.allocate(size, align, MemoryKind::Rust.into())?;
self.memory.write_repeat(ptr.into(), 0, size)?;
self.write_primval(dest, PrimVal::Ptr(ptr), dest_ty)?;
}
if !align.is_power_of_two() {
return err!(HeapAllocNonPowerOfTwoAlignment(align));
}
- self.memory.deallocate(ptr, Some((old_size, align)), Kind::Rust.into())?;
+ self.memory.deallocate(ptr, Some((old_size, align)), MemoryKind::Rust.into())?;
}
"alloc::heap::::__rust_realloc" => {
let ptr = args[0].into_ptr(&mut self.memory)?.to_ptr()?;
if !new_align.is_power_of_two() {
return err!(HeapAllocNonPowerOfTwoAlignment(new_align));
}
- let new_ptr = self.memory.reallocate(ptr, old_size, old_align, new_size, new_align, Kind::Rust.into())?;
+ let new_ptr = self.memory.reallocate(ptr, old_size, old_align, new_size, new_align, MemoryKind::Rust.into())?;
self.write_primval(dest, PrimVal::Ptr(new_ptr), dest_ty)?;
}
// Return value
let size = ecx.tcx.data_layout.pointer_size.bytes();
let align = ecx.tcx.data_layout.pointer_align.abi();
- let ret_ptr = ecx.memory_mut().allocate(size, align, Kind::Stack)?;
+ let ret_ptr = ecx.memory_mut().allocate(size, align, MemoryKind::Stack)?;
cleanup_ptr = Some(ret_ptr);
// Push our stack frame
while ecx.step()? {}
ecx.run_tls_dtors()?;
if let Some(cleanup_ptr) = cleanup_ptr {
- ecx.memory_mut().deallocate(cleanup_ptr, None, Kind::Stack)?;
+ ecx.memory_mut().deallocate(cleanup_ptr, None, MemoryKind::Stack)?;
}
Ok(())
}
impl<'tcx> Machine<'tcx> for Evaluator {
type Data = EvaluatorData;
type MemoryData = MemoryData<'tcx>;
- type MemoryKinds = memory::Kind;
+ type MemoryKinds = memory::MemoryKind;
/// Returns Ok() when the function was handled, fail otherwise
fn eval_fn_call<'a>(
ecx.ptr_op(bin_op, left, left_ty, right, right_ty)
}
- fn mark_static_initialized(m: memory::Kind) -> EvalResult<'tcx> {
- use memory::Kind::*;
+ fn mark_static_initialized(m: memory::MemoryKind) -> EvalResult<'tcx> {
+ use memory::MemoryKind::*;
match m {
// FIXME: This could be allowed, but not for env vars set during miri execution
Env => err!(Unimplemented("statics can't refer to env vars".to_owned())),
Ok(PrimVal::Bytes(align.into()))
} else {
ecx.memory
- .allocate(size, align, Kind::Machine(memory::Kind::Rust))
+ .allocate(size, align, MemoryKind::Machine(memory::MemoryKind::Rust))
.map(PrimVal::Ptr)
}
}
#[derive(Debug, PartialEq, Copy, Clone)]
-pub enum Kind {
+pub enum MemoryKind {
/// Error if deallocated any other way than `rust_deallocate`
Rust,
/// Error if deallocated any other way than `free`
Env,
}
-impl Into<::rustc_miri::interpret::Kind<Kind>> for Kind {
- fn into(self) -> ::rustc_miri::interpret::Kind<Kind> {
- ::rustc_miri::interpret::Kind::Machine(self)
+impl Into<::rustc_miri::interpret::MemoryKind<MemoryKind>> for MemoryKind {
+ fn into(self) -> ::rustc_miri::interpret::MemoryKind<MemoryKind> {
+ ::rustc_miri::interpret::MemoryKind::Machine(self)
}
}
GlobalId, Lvalue, Value,
PrimVal,
EvalContext, StackPopCleanup, PtrAndAlign,
- Kind,
+ MemoryKind,
};
use rustc_const_math::ConstInt;
if !ecx.globals.contains_key(&cid) {
let size = ecx.type_size_with_substs(mir.return_ty, instance.substs)?.expect("unsized global");
let align = ecx.type_align_with_substs(mir.return_ty, instance.substs)?;
- let ptr = ecx.memory.allocate(size, align, Kind::UninitializedStatic)?;
+ let ptr = ecx.memory.allocate(size, align, MemoryKind::UninitializedStatic)?;
let aligned = !ecx.is_packed(mir.return_ty)?;
ecx.globals.insert(cid, PtrAndAlign { ptr: ptr.into(), aligned });
let mutable = !mir.return_ty.is_freeze(
EvalError, EvalResult, EvalErrorKind,
GlobalId, Lvalue, LvalueExtra,
Memory, MemoryPointer, HasMemory,
- Kind as MemoryKind,
+ MemoryKind,
operator,
PrimVal, PrimValKind, Value, Pointer,
ValidationQuery,
/// Use the `mark_static_initalized` method of `Memory` to ensure that an error occurs, if the memory of this
/// allocation is modified or deallocated in the future.
/// Helps guarantee that stack allocations aren't deallocated via `rust_deallocate`
- pub kind: Kind<M>,
+ pub kind: MemoryKind<M>,
/// Memory regions that are locked by some function
locks: RangeMap<LockInfo>,
}
}
#[derive(Debug, PartialEq, Copy, Clone)]
-pub enum Kind<T> {
+pub enum MemoryKind<T> {
/// Error if deallocated except during a stack pop
Stack,
/// Static in the process of being initialized.
return Ok(MemoryPointer::new(alloc_id, 0));
}
- let ptr = self.allocate(bytes.len() as u64, 1, Kind::UninitializedStatic)?;
+ let ptr = self.allocate(bytes.len() as u64, 1, MemoryKind::UninitializedStatic)?;
self.write_bytes(ptr.into(), bytes)?;
self.mark_static_initalized(ptr.alloc_id, Mutability::Immutable)?;
self.literal_alloc_cache.insert(bytes.to_vec(), ptr.alloc_id);
&mut self,
size: u64,
align: u64,
- kind: Kind<M::MemoryKinds>,
+ kind: MemoryKind<M::MemoryKinds>,
) -> EvalResult<'tcx, MemoryPointer> {
assert_ne!(align, 0);
assert!(align.is_power_of_two());
old_align: u64,
new_size: u64,
new_align: u64,
- kind: Kind<M::MemoryKinds>,
+ kind: MemoryKind<M::MemoryKinds>,
) -> EvalResult<'tcx, MemoryPointer> {
use std::cmp::min;
&mut self,
ptr: MemoryPointer,
size_and_align: Option<(u64, u64)>,
- kind: Kind<M::MemoryKinds>,
+ kind: MemoryKind<M::MemoryKinds>,
) -> EvalResult<'tcx> {
if ptr.offset != 0 {
return err!(DeallocateNonBasePtr);
}
let immutable = match (alloc.kind, alloc.mutable) {
- (Kind::UninitializedStatic, _) => " (static in the process of initialization)".to_owned(),
- (Kind::Static, Mutability::Mutable) => " (static mut)".to_owned(),
- (Kind::Static, Mutability::Immutable) => " (immutable)".to_owned(),
- (Kind::Machine(m), _) => format!(" ({:?})", m),
- (Kind::Stack, _) => " (stack)".to_owned(),
+ (MemoryKind::UninitializedStatic, _) => " (static in the process of initialization)".to_owned(),
+ (MemoryKind::Static, Mutability::Mutable) => " (static mut)".to_owned(),
+ (MemoryKind::Static, Mutability::Immutable) => " (immutable)".to_owned(),
+ (MemoryKind::Machine(m), _) => format!(" ({:?})", m),
+ (MemoryKind::Stack, _) => " (stack)".to_owned(),
};
trace!("{}({} bytes, alignment {}){}", msg, alloc.bytes.len(), alloc.align, immutable);
let leaks: Vec<_> = self.alloc_map
.iter()
.filter_map(|(&key, val)| {
- if val.kind != Kind::Static {
+ if val.kind != MemoryKind::Static {
Some(AllocIdKind::Runtime(key).into_alloc_id())
} else {
None
/// mark an allocation pointed to by a static as static and initialized
pub fn mark_inner_allocation(&mut self, alloc: AllocId, mutability: Mutability) -> EvalResult<'tcx> {
// relocations into other statics are not "inner allocations"
- if self.get(alloc).ok().map_or(false, |alloc| alloc.kind != Kind::UninitializedStatic) {
+ if self.get(alloc).ok().map_or(false, |alloc| alloc.kind != MemoryKind::UninitializedStatic) {
self.mark_static_initalized(alloc, mutability)?;
}
Ok(())
match *kind {
// const eval results can refer to "locals".
// E.g. `const Foo: &u32 = &1;` refers to the temp local that stores the `1`
- Kind::Stack |
+ MemoryKind::Stack |
// The entire point of this function
- Kind::UninitializedStatic => {},
- Kind::Machine(m) => M::mark_static_initialized(m)?,
- Kind::Static => {
+ MemoryKind::UninitializedStatic => {},
+ MemoryKind::Machine(m) => M::mark_static_initialized(m)?,
+ MemoryKind::Static => {
trace!("mark_static_initalized: skipping already initialized static referred to by static currently being initialized");
return Ok(());
},
}
- *kind = Kind::Static;
+ *kind = MemoryKind::Static;
*mutable = mutability;
// take out the relocations vector to free the borrow on self, so we can call
// mark recursively
AllocId,
Memory,
MemoryPointer,
- Kind,
+ MemoryKind,
HasMemory,
};
EvalResult,
EvalContext, StackPopCleanup, TyAndPacked, PtrAndAlign,
GlobalId, Lvalue,
- HasMemory, Kind,
+ HasMemory, MemoryKind,
Machine,
};
// FIXME: check that it's `#[linkage = "extern_weak"]`
trace!("Initializing an extern global with NULL");
let ptr_size = self.memory.pointer_size();
- let ptr = self.memory.allocate(ptr_size, ptr_size, Kind::UninitializedStatic)?;
+ let ptr = self.memory.allocate(ptr_size, ptr_size, MemoryKind::UninitializedStatic)?;
self.memory.write_usize(ptr, 0)?;
self.memory.mark_static_initalized(ptr.alloc_id, mutability)?;
self.globals.insert(cid, PtrAndAlign { ptr: ptr.into(), aligned: true });
let mir = self.load_mir(instance.def)?;
let size = self.type_size_with_substs(mir.return_ty, substs)?.expect("unsized global");
let align = self.type_align_with_substs(mir.return_ty, substs)?;
- let ptr = self.memory.allocate(size, align, Kind::UninitializedStatic)?;
+ let ptr = self.memory.allocate(size, align, MemoryKind::UninitializedStatic)?;
let aligned = !self.is_packed(mir.return_ty)?;
self.globals.insert(cid, PtrAndAlign { ptr: ptr.into(), aligned });
let internally_mutable = !mir.return_ty.is_freeze(
self.try(|this| {
let size = this.ecx.type_size_with_substs(mir.return_ty, this.instance.substs)?.expect("unsized global");
let align = this.ecx.type_align_with_substs(mir.return_ty, this.instance.substs)?;
- let ptr = this.ecx.memory.allocate(size, align, Kind::UninitializedStatic)?;
+ let ptr = this.ecx.memory.allocate(size, align, MemoryKind::UninitializedStatic)?;
let aligned = !this.ecx.is_packed(mir.return_ty)?;
this.ecx.globals.insert(cid, PtrAndAlign { ptr: ptr.into(), aligned });
trace!("pushing stack frame for {:?}", index);
use super::{
EvalResult,
EvalContext, eval_context,
- MemoryPointer, Kind,
+ MemoryPointer, MemoryKind,
Value, PrimVal,
Machine,
};
let ptr_size = self.memory.pointer_size();
let methods = ::rustc::traits::get_vtable_methods(self.tcx, trait_ref);
- let vtable = self.memory.allocate(ptr_size * (3 + methods.count() as u64), ptr_size, Kind::UninitializedStatic)?;
+ let vtable = self.memory.allocate(ptr_size * (3 + methods.count() as u64), ptr_size, MemoryKind::UninitializedStatic)?;
let drop = eval_context::resolve_drop_in_place(self.tcx, ty);
let drop = self.memory.create_fn_alloc(drop);