permit locking constant memory (60)
This commit is contained in:
parent
66e55b0d6e
commit
5440fe4b52
1 changed files with 14 additions and 9 deletions
|
|
@ -562,7 +562,7 @@ impl<'a, 'tcx> Memory<'a, 'tcx> {
|
|||
self.check_bounds(ptr.offset(len, self.layout)?, true)?; // if ptr.offset is in bounds, then so is ptr (because offset checks for overflow)
|
||||
self.check_locks(ptr, len, kind)?; // make sure we have the access we are acquiring
|
||||
let lifetime = DynamicLifetime { frame: self.cur_frame, region };
|
||||
let alloc = self.get_mut(ptr.alloc_id)?;
|
||||
let alloc = self.get_mut_unchecked(ptr.alloc_id)?;
|
||||
alloc.locks.entry(MemoryRange::new(ptr.offset, len)).or_insert_with(|| Vec::new()).push(LockInfo { lifetime, kind, status: LockStatus::Held });
|
||||
Ok(())
|
||||
}
|
||||
|
|
@ -571,7 +571,7 @@ impl<'a, 'tcx> Memory<'a, 'tcx> {
|
|||
pub(crate) fn release_write_lock_until(&mut self, ptr: MemoryPointer, len: u64, release_until: Option<CodeExtent>) -> EvalResult<'tcx> {
|
||||
assert!(len > 0);
|
||||
let cur_frame = self.cur_frame;
|
||||
let alloc = self.get_mut(ptr.alloc_id)?;
|
||||
let alloc = self.get_mut_unchecked(ptr.alloc_id)?;
|
||||
|
||||
for (range, locks) in alloc.iter_lock_vecs_mut(ptr.offset, len) {
|
||||
if !range.contains(ptr.offset, len) {
|
||||
|
|
@ -648,14 +648,10 @@ impl<'a, 'tcx> Memory<'a, 'tcx> {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_mut(&mut self, id: AllocId) -> EvalResult<'tcx, &mut Allocation> {
|
||||
|
||||
fn get_mut_unchecked(&mut self, id: AllocId) -> EvalResult<'tcx, &mut Allocation> {
|
||||
match self.alloc_map.get_mut(&id) {
|
||||
Some(alloc) => if alloc.mutable == Mutability::Mutable {
|
||||
Ok(alloc)
|
||||
} else {
|
||||
Err(EvalError::ModifiedConstantMemory)
|
||||
},
|
||||
Some(alloc) => Ok(alloc),
|
||||
None => match self.functions.get(&id) {
|
||||
Some(_) => Err(EvalError::DerefFunctionPointer),
|
||||
None => Err(EvalError::DanglingPointerDeref),
|
||||
|
|
@ -663,6 +659,15 @@ impl<'a, 'tcx> Memory<'a, 'tcx> {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn get_mut(&mut self, id: AllocId) -> EvalResult<'tcx, &mut Allocation> {
|
||||
let alloc = self.get_mut_unchecked(id)?;
|
||||
if alloc.mutable == Mutability::Mutable {
|
||||
Ok(alloc)
|
||||
} else {
|
||||
Err(EvalError::ModifiedConstantMemory)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_fn(&self, ptr: MemoryPointer) -> EvalResult<'tcx, ty::Instance<'tcx>> {
|
||||
if ptr.offset != 0 {
|
||||
return Err(EvalError::InvalidFunctionPointer);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue