-
Notifications
You must be signed in to change notification settings - Fork 391
Retagging: Recurse into compound values #526
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 3 commits
1e51a38
a1f895d
c54dcf5
36b97cd
b7dbb5e
880229d
662821f
56f1ef3
c847071
19f8a9d
aad47db
06d7773
a806805
d619049
b8486ce
6085865
cfa6397
5b095e1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -405,12 +405,12 @@ impl<'tcx> Stacks { | |
|
||
|
||
pub trait EvalContextExt<'tcx> { | ||
fn tag_dereference( | ||
fn ptr_dereference( | ||
&self, | ||
place: MPlaceTy<'tcx, Borrow>, | ||
size: Size, | ||
mutability: Option<Mutability>, | ||
) -> EvalResult<'tcx, Borrow>; | ||
) -> EvalResult<'tcx>; | ||
|
||
fn tag_new_allocation( | ||
&mut self, | ||
|
@@ -480,13 +480,13 @@ impl<'a, 'mir, 'tcx> EvalContextExt<'tcx> for MiriEvalContext<'a, 'mir, 'tcx> { | |
/// | ||
/// Note that this does NOT mean that all this memory will actually get accessed/referenced! | ||
/// We could be in the middle of `&(*var).1`. | ||
fn tag_dereference( | ||
fn ptr_dereference( | ||
&self, | ||
place: MPlaceTy<'tcx, Borrow>, | ||
size: Size, | ||
mutability: Option<Mutability>, | ||
) -> EvalResult<'tcx, Borrow> { | ||
trace!("tag_dereference: Accessing {} reference for {:?} (pointee {})", | ||
) -> EvalResult<'tcx> { | ||
trace!("ptr_dereference: Accessing {} reference for {:?} (pointee {})", | ||
if let Some(mutability) = mutability { format!("{:?}", mutability) } else { format!("raw") }, | ||
place.ptr, place.layout.ty); | ||
let ptr = place.ptr.to_ptr()?; | ||
|
@@ -497,12 +497,8 @@ impl<'a, 'mir, 'tcx> EvalContextExt<'tcx> for MiriEvalContext<'a, 'mir, 'tcx> { | |
// That can transmute a raw ptr to a (shared/mut) ref, and a mut ref to a shared one. | ||
match (mutability, ptr.tag) { | ||
(None, _) => { | ||
// Don't use the tag, this is a raw access! They should happen tagless. | ||
// This is needed for `*mut` to make any sense: Writes *do* enforce the | ||
// `Uniq` tag to be up top, but we must make sure raw writes do not do that. | ||
// This does mean, however, that `&*foo` is *not* a NOP *if* `foo` is a raw ptr. | ||
// Also don't do any further validation, this is raw after all. | ||
return Ok(Borrow::default()); | ||
// No further validation on raw accesses. | ||
return Ok(()); | ||
} | ||
(Some(MutMutable), Borrow::Uniq(_)) | | ||
(Some(MutImmutable), Borrow::Shr(_)) => { | ||
|
@@ -543,8 +539,8 @@ impl<'a, 'mir, 'tcx> EvalContextExt<'tcx> for MiriEvalContext<'a, 'mir, 'tcx> { | |
alloc.extra.deref(ptr, size, kind)?; | ||
} | ||
|
||
// All is good, and do not change the tag | ||
Ok(ptr.tag) | ||
// All is good | ||
Ok(()) | ||
} | ||
|
||
/// The given place may henceforth be accessed through raw pointers. | ||
|
@@ -661,14 +657,14 @@ impl<'a, 'mir, 'tcx> EvalContextExt<'tcx> for MiriEvalContext<'a, 'mir, 'tcx> { | |
// Primitives of reference type, that is the one thing we are interested in. | ||
fn visit_primitive(&mut self, place: MPlaceTy<'tcx, Borrow>) -> EvalResult<'tcx> | ||
{ | ||
match place.layout.ty.sty { | ||
ty::Ref(_, _, mutbl) => { | ||
let val = self.ecx.read_immediate(place.into())?; | ||
let val = self.ecx.retag_reference(val, mutbl)?; | ||
self.ecx.write_immediate(val, place.into())?; | ||
} | ||
_ => {}, // nothing to do | ||
} | ||
let mutbl = match place.layout.ty.sty { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this can be simplified to an if let on There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unfortunately that reports immutable for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I added a comment explaining this. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wat. I need to review all uses of that method now -.- There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please do.^^ And/or fix that method? ;) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess this is related to the fact that
works but
says it needs a |
||
ty::Ref(_, _, mutbl) => mutbl, | ||
ty::Adt(..) if place.layout.ty.is_box() => MutMutable, | ||
_ => return Ok(()), // nothing to do | ||
}; | ||
let val = self.ecx.read_immediate(place.into())?; | ||
let val = self.ecx.retag_reference(val, mutbl)?; | ||
self.ecx.write_immediate(val, place.into())?; | ||
Ok(()) | ||
} | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
fn demo_mut_advanced_unique(mut our: Box<i32>) -> i32 { | ||
unknown_code_1(&*our); | ||
|
||
// This "re-asserts" uniqueness of the reference: After writing, we know | ||
// our tag is at the top of the stack. | ||
*our = 5; | ||
|
||
unknown_code_2(); | ||
|
||
// We know this will return 5 | ||
*our //~ ERROR does not exist on the stack | ||
} | ||
|
||
// Now comes the evil context | ||
use std::ptr; | ||
|
||
static mut LEAK: *mut i32 = ptr::null_mut(); | ||
|
||
fn unknown_code_1(x: &i32) { unsafe { | ||
LEAK = x as *const _ as *mut _; | ||
} } | ||
|
||
fn unknown_code_2() { unsafe { | ||
*LEAK = 7; | ||
} } | ||
|
||
fn main() { | ||
assert_eq!(demo_mut_advanced_unique(Box::new(0)), 5); | ||
} |
Uh oh!
There was an error while loading. Please reload this page.