use usize instead of u64 for memory limits
This commit is contained in:
parent
a7d3a85d9e
commit
8d3817cfc6
3 changed files with 16 additions and 17 deletions
|
|
@ -30,9 +30,9 @@ pub enum EvalError<'tcx> {
|
|||
Math(Span, ConstMathErr),
|
||||
InvalidChar(u32),
|
||||
OutOfMemory {
|
||||
allocation_size: u64,
|
||||
memory_size: u64,
|
||||
memory_usage: u64,
|
||||
allocation_size: usize,
|
||||
memory_size: usize,
|
||||
memory_usage: usize,
|
||||
},
|
||||
ExecutionTimeLimitReached,
|
||||
StackFrameLimitReached,
|
||||
|
|
|
|||
|
|
@ -136,8 +136,7 @@ enum ConstantKind {
|
|||
}
|
||||
|
||||
impl<'a, 'tcx> EvalContext<'a, 'tcx> {
|
||||
pub fn new(tcx: TyCtxt<'a, 'tcx, 'tcx>, mir_map: &'a MirMap<'tcx>, memory_size: u64, stack_limit: u64) -> Self {
|
||||
assert_eq!(stack_limit as usize as u64, stack_limit);
|
||||
pub fn new(tcx: TyCtxt<'a, 'tcx, 'tcx>, mir_map: &'a MirMap<'tcx>, memory_size: usize, stack_limit: usize) -> Self {
|
||||
EvalContext {
|
||||
tcx: tcx,
|
||||
mir_map: mir_map,
|
||||
|
|
@ -145,7 +144,7 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
|
|||
memory: Memory::new(&tcx.data_layout, memory_size),
|
||||
statics: HashMap::new(),
|
||||
stack: Vec::new(),
|
||||
stack_limit: stack_limit as usize,
|
||||
stack_limit: stack_limit,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -937,9 +936,9 @@ pub fn eval_main<'a, 'tcx: 'a>(
|
|||
tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
||||
mir_map: &'a MirMap<'tcx>,
|
||||
node_id: ast::NodeId,
|
||||
memory_size: u64,
|
||||
memory_size: usize,
|
||||
step_limit: u64,
|
||||
stack_limit: u64,
|
||||
stack_limit: usize,
|
||||
) {
|
||||
let mir = mir_map.map.get(&node_id).expect("no mir for main function");
|
||||
let def_id = tcx.map.local_def_id(node_id);
|
||||
|
|
|
|||
|
|
@ -67,9 +67,9 @@ pub struct Memory<'a, 'tcx> {
|
|||
/// Actual memory allocations (arbitrary bytes, may contain pointers into other allocations)
|
||||
alloc_map: HashMap<AllocId, Allocation>,
|
||||
/// Number of virtual bytes allocated
|
||||
memory_usage: u64,
|
||||
memory_usage: usize,
|
||||
/// Maximum number of virtual bytes that may be allocated
|
||||
memory_size: u64,
|
||||
memory_size: usize,
|
||||
/// Function "allocations". They exist solely so pointers have something to point to, and
|
||||
/// we can figure out what they point to.
|
||||
functions: HashMap<AllocId, FunctionDefinition<'tcx>>,
|
||||
|
|
@ -82,7 +82,7 @@ pub struct Memory<'a, 'tcx> {
|
|||
const ZST_ALLOC_ID: AllocId = AllocId(0);
|
||||
|
||||
impl<'a, 'tcx> Memory<'a, 'tcx> {
|
||||
pub fn new(layout: &'a TargetDataLayout, max_memory: u64) -> Self {
|
||||
pub fn new(layout: &'a TargetDataLayout, max_memory: usize) -> Self {
|
||||
let mut mem = Memory {
|
||||
alloc_map: HashMap::new(),
|
||||
functions: HashMap::new(),
|
||||
|
|
@ -137,14 +137,14 @@ impl<'a, 'tcx> Memory<'a, 'tcx> {
|
|||
if size == 0 {
|
||||
return Ok(Pointer::zst_ptr());
|
||||
}
|
||||
if self.memory_size - self.memory_usage < size as u64 {
|
||||
if self.memory_size - self.memory_usage < size {
|
||||
return Err(EvalError::OutOfMemory {
|
||||
allocation_size: size as u64,
|
||||
allocation_size: size,
|
||||
memory_size: self.memory_size,
|
||||
memory_usage: self.memory_usage,
|
||||
});
|
||||
}
|
||||
self.memory_usage += size as u64;
|
||||
self.memory_usage += size;
|
||||
let alloc = Allocation {
|
||||
bytes: vec![0; size],
|
||||
relocations: BTreeMap::new(),
|
||||
|
|
@ -174,14 +174,14 @@ impl<'a, 'tcx> Memory<'a, 'tcx> {
|
|||
|
||||
if new_size > size {
|
||||
let amount = new_size - size;
|
||||
self.memory_usage += amount as u64;
|
||||
self.memory_usage += amount;
|
||||
let alloc = self.get_mut(ptr.alloc_id)?;
|
||||
alloc.bytes.extend(iter::repeat(0).take(amount));
|
||||
alloc.undef_mask.grow(amount, false);
|
||||
} else if size > new_size {
|
||||
// it's possible to cause miri to use arbitrary amounts of memory that aren't detectable
|
||||
// through the memory_usage value, by allocating a lot and reallocating to zero
|
||||
self.memory_usage -= (size - new_size) as u64;
|
||||
self.memory_usage -= size - new_size;
|
||||
self.clear_relocations(ptr.offset(new_size as isize), size - new_size)?;
|
||||
let alloc = self.get_mut(ptr.alloc_id)?;
|
||||
alloc.bytes.truncate(new_size);
|
||||
|
|
@ -202,7 +202,7 @@ impl<'a, 'tcx> Memory<'a, 'tcx> {
|
|||
}
|
||||
|
||||
if let Some(alloc) = self.alloc_map.remove(&ptr.alloc_id) {
|
||||
self.memory_usage -= alloc.bytes.len() as u64;
|
||||
self.memory_usage -= alloc.bytes.len();
|
||||
} else {
|
||||
debug!("deallocated a pointer twice: {}", ptr.alloc_id);
|
||||
// TODO(solson): Report error about erroneous free. This is blocked on properly tracking
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue