diff options
| author | Ralf Jung <post@ralfj.de> | 2017-07-13 20:33:06 -0700 |
|---|---|---|
| committer | Oliver Schneider <git-spam-no-reply9815368754983@oli-obk.de> | 2017-07-25 10:22:11 +0200 |
| commit | 5440fe4b522d9348ee699f7095bf0342379d201a (patch) | |
| tree | ad63510ad6f8c4784fe9319023b96044ab9befd3 /src | |
| parent | 66e55b0d6e00706fb9bbfd6a062852c9dbd09cec (diff) | |
| download | rust-5440fe4b522d9348ee699f7095bf0342379d201a.tar.gz rust-5440fe4b522d9348ee699f7095bf0342379d201a.zip | |
permit locking constant memory (60)
Diffstat (limited to 'src')
| -rw-r--r-- | src/librustc_mir/interpret/memory.rs | 23 |
1 files changed, 14 insertions, 9 deletions
diff --git a/src/librustc_mir/interpret/memory.rs b/src/librustc_mir/interpret/memory.rs index 70dfc0aef90..33a9aa8e304 100644 --- a/src/librustc_mir/interpret/memory.rs +++ b/src/librustc_mir/interpret/memory.rs @@ -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); |
