]> git.lizzy.rs Git - rust.git/blob - src/memory.rs
Auto merge of #798 - RalfJung:format-ptr, r=RalfJung
[rust.git] / src / memory.rs
1 use rand::rngs::StdRng;
2
3 use rustc_mir::interpret::{Pointer, Allocation, AllocationExtra, InterpResult};
4 use rustc_target::abi::Size;
5
6 use crate::{stacked_borrows, intptrcast};
7 use crate::stacked_borrows::Tag;
8
9 #[derive(Default, Clone, Debug)]
10 pub struct MemoryExtra {
11     pub stacked_borrows: stacked_borrows::MemoryExtra,
12     pub intptrcast: intptrcast::MemoryExtra,
13     /// The random number generator to use if Miri is running in non-deterministic mode and to
14     /// enable intptrcast
15     pub(crate) rng: Option<StdRng>
16 }
17
18 #[derive(Debug, Clone)]
19 pub struct AllocExtra {
20     pub stacked_borrows: stacked_borrows::AllocExtra,
21     pub intptrcast: intptrcast::AllocExtra,
22 }
23
24 impl AllocationExtra<Tag> for AllocExtra {
25     #[inline(always)]
26     fn memory_read<'tcx>(
27         alloc: &Allocation<Tag, AllocExtra>,
28         ptr: Pointer<Tag>,
29         size: Size,
30     ) -> InterpResult<'tcx> {
31         alloc.extra.stacked_borrows.memory_read(ptr, size)
32     }
33
34     #[inline(always)]
35     fn memory_written<'tcx>(
36         alloc: &mut Allocation<Tag, AllocExtra>,
37         ptr: Pointer<Tag>,
38         size: Size,
39     ) -> InterpResult<'tcx> {
40         alloc.extra.stacked_borrows.memory_written(ptr, size)
41     }
42
43     #[inline(always)]
44     fn memory_deallocated<'tcx>(
45         alloc: &mut Allocation<Tag, AllocExtra>,
46         ptr: Pointer<Tag>,
47         size: Size,
48     ) -> InterpResult<'tcx> {
49         alloc.extra.stacked_borrows.memory_deallocated(ptr, size)
50     }
51 }