Skip to content

Commit 1018b62

Browse files
author
Ellen Arteca
committed
store the pointer in the allocextra -- now just need to make it the allocid
1 parent 450ef91 commit 1018b62

File tree

3 files changed

+10
-37
lines changed

3 files changed

+10
-37
lines changed

src/machine.rs

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ pub struct AllocExtra {
224224
/// Weak memory emulation via the use of store buffers,
225225
/// this is only added if it is enabled.
226226
pub weak_memory: Option<weak_memory::AllocExtra>,
227-
// pub real_pointer: u64,
227+
pub real_pointer: *const u8,
228228
}
229229

230230
/// Precomputed layouts of primitive types
@@ -698,16 +698,10 @@ impl<'mir, 'tcx> Machine<'mir, 'tcx> for Evaluator<'mir, 'tcx> {
698698
alloc: Cow<'b, Allocation>,
699699
kind: Option<MemoryKind<Self::MemoryKind>>,
700700
) -> InterpResult<'tcx, Cow<'b, Allocation<Self::Provenance, Self::AllocExtra>>> {
701-
let (size, _, _) = ecx.get_alloc_info(id);
702-
let fake_range = AllocRange{ start: rustc_target::abi::Size::ZERO, size: size};
703-
let ree = ecx.memory.alloc_map().get(id).unwrap().1.get_bytes_with_uninit_and_ptr(ecx, fake_range).unwrap();
704-
705-
// let bytes_ptr = alloc.get_bytes( ecx, fake_range);
706-
// unsafe {
707-
// if bytes_ptr.is_ok() {//&& id.0 > std::num::NonZeroU64::new(1600).unwrap(){
708-
// // println!("{:?}, {:?}", id, *(bytes_ptr.unwrap().as_ptr()));
709-
// }
710-
// }
701+
let size = alloc.size();
702+
let alloc_range = AllocRange{ start: rustc_target::abi::Size::ZERO, size: size};
703+
let alloc_bytes_ptr = alloc.get_bytes_with_uninit_and_ptr(ecx, alloc_range).unwrap().as_ptr();
704+
711705
let kind = kind.expect("we set our STATIC_KIND so this cannot be None");
712706
if ecx.machine.tracked_alloc_ids.contains(&id) {
713707
register_diagnostic(NonHaltingDiagnostic::CreatedAlloc(
@@ -745,14 +739,13 @@ impl<'mir, 'tcx> Machine<'mir, 'tcx> for Evaluator<'mir, 'tcx> {
745739
} else {
746740
None
747741
};
748-
// println!("{:?}", ree.as_ptr() as u64);
749742
let alloc: Allocation<Provenance, Self::AllocExtra> = alloc.adjust_from_tcx(
750743
&ecx.tcx,
751744
AllocExtra {
752745
stacked_borrows: stacks.map(RefCell::new),
753746
data_race: race_alloc,
754747
weak_memory: buffer_alloc,
755-
// real_pointer: 0,
748+
real_pointer: alloc_bytes_ptr,
756749
},
757750
|ptr| ecx.global_base_pointer(ptr),
758751
)?;

src/mono_hash_map.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ impl<K: Hash + Eq, V> Default for MonoHashMap<K, V> {
3737
}
3838
}
3939

40-
impl<K: Hash + Eq, V: std::fmt::Debug> AllocMap<K, V> for MonoHashMap<K, V> {
40+
impl<K: Hash + Eq, V> AllocMap<K, V> for MonoHashMap<K, V> {
4141
#[inline(always)]
4242
fn contains_key<Q: ?Sized + Hash + Eq>(&mut self, k: &Q) -> bool
4343
where
@@ -48,7 +48,6 @@ impl<K: Hash + Eq, V: std::fmt::Debug> AllocMap<K, V> for MonoHashMap<K, V> {
4848

4949
#[inline(always)]
5050
fn insert(&mut self, k: K, v: V) -> Option<V> {
51-
println!("WHY: {:?}", v);
5251
self.0.get_mut().insert(k, Box::new(v)).map(|x| *x)
5352
}
5453

src/shims/ffi_support.rs

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -81,28 +81,9 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
8181
match k {
8282
ScalarMaybeUninit::Scalar(Scalar::Ptr(ptr, sz)) => {
8383
let (alloc_id, _, _) = cx.ptr_get_alloc_id(ptr.into())?;
84-
let (size, align, _) = cx.get_alloc_info(alloc_id);
85-
let fake_range = AllocRange{ start: rustc_target::abi::Size::ZERO, size: size};
86-
println!("{:?}, {:?}", size, align);
87-
let alloc = cx.get_ptr_alloc(ptr.into(), size, align)?.unwrap();
88-
let wtf = alloc.read_integer(alloc_range(rustc_target::abi::Size::ZERO, size));
89-
println!("UMM {:?}", wtf);
90-
let ree = cx.memory.alloc_map().get(alloc_id).unwrap().1.get_bytes_with_uninit_and_ptr(cx, fake_range).unwrap();
91-
println!("{:?}", ree.as_ptr());
92-
let bytes = cx.read_bytes_ptr(ptr.into(), size);
93-
println!("WHAT {:?}", bytes);
94-
// println!("{:?}", ptr.into_parts().0);
95-
// let ree = &ptr.into_parts().1.bytes();
96-
// println!("{:?}", self.memory);
97-
// println!("{:?}", ptr.get_alloc_id());
98-
// unsafe {
99-
// println!("{:?}", *(ree as *const u64));
100-
// println!("{:?}", *(ptr.into_parts().1.bytes() as *mut u64));
101-
// }
102-
// println!("REE {:?}", intptrcast::GlobalStateInner::rel_ptr_to_addr(cx, ptr));
103-
// let the_int = s.assert_int();
104-
// println!("{:?}", the_int.try_to_u64().unwrap());
105-
let inner_carg = CArg::ConstPtrUInt8(unsafe{ree.as_ptr()});
84+
let ree = cx.memory.alloc_map().get(alloc_id).unwrap().1.extra.real_pointer;//get_bytes_with_uninit_and_ptr(cx, fake_range).unwrap();
85+
println!("{:?}", ree);
86+
let inner_carg = CArg::ConstPtrUInt8(ree);
10687
return Ok(CArg::RecMutPtrCarg(Box::new(inner_carg)));
10788
// return Ok(CArg::USize(the_int.try_to_u64().unwrap().try_into().unwrap()));
10889
// println!("{:?}", s.assert_int())

0 commit comments

Comments
 (0)