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
Adjust Allocation Bytes used by Miri to custom MiriAllocBytes #3526
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, this is a good start!
} else { | ||
alloc_fn(layout) | ||
}; | ||
if ptr.is_null() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're now checking this even in the size == 0
case, which is unnecessary. You can move this if
inside the else { ... }
above.
} | ||
|
||
impl Clone for MiriAllocBytes { | ||
fn clone(&self) -> Self { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you implement this using MiriAllocBytes:: from_bytes(Cow::Borrowed(&*self), ...)
? Then you don't need unsafe here. :)
let alloc_bytes = MiriAllocBytes::alloc_with(size, align, alloc_fn) | ||
.unwrap_or_else(|layout| alloc::handle_alloc_error(layout)); | ||
// SAFETY: `alloc_bytes.ptr` and `slice.as_ptr()` are non-null, properly aligned | ||
// and valid for the `slice.len()`-many bytes to be copied. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// and valid for the `slice.len()`-many bytes to be copied. | |
// and valid for the `size`-many bytes to be copied. |
fn as_mut_ptr(&mut self) -> *mut u8 { | ||
self.ptr | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add a newline at the end. (./miri fmt
should do that automatically, and also otherwise will make sure you use standard Rust formatting.)
@@ -122,7 +122,7 @@ impl VisitProvenance for OpTy<'_, Provenance> { | |||
} | |||
} | |||
|
|||
impl VisitProvenance for Allocation<Provenance, AllocExtra<'_>> { | |||
impl<Bytes: AllocBytes> VisitProvenance for Allocation<Provenance, AllocExtra<'_>, Bytes> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
impl<Bytes: AllocBytes> VisitProvenance for Allocation<Provenance, AllocExtra<'_>, Bytes> { | |
impl VisitProvenance for Allocation<Provenance, AllocExtra<'_>, MiriAllocBytes> { |
fn from_bytes<'a>(slice: impl Into<Cow<'a, [u8]>>, align: Align) -> Self { | ||
let slice = slice.into(); | ||
let size = slice.len(); | ||
let align = align.bytes().try_into().unwrap(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After rebasing over the latest Miri master, you should be able to use align.bytes_usize()
here.
This comment was marked as outdated.
This comment was marked as outdated.
Co-authored-by: Ralf Jung <post@ralfj.de>
Co-authored-by: Ralf Jung <post@ralfj.de>
Co-authored-by: Ralf Jung <post@ralfj.de>
Preparing for merge from rustc Unblocks #3526.
If you rebase over the latest Miri master, you should get the updated rustc that includes your PR, so that this one can finally build. :) |
Preparing for merge from rustc Unblocks rust-lang/miri#3526.
Preparing for merge from rustc Unblocks rust-lang/miri#3526.
Previously, the
MiriMachine
usedtype Bytes = Box<[u8]>
for its allocations.This PR swaps this out for a custom
MiriAllocBytes
type implemented inalloc_bytes.rs
.This is in anticipation of an extension to Miri's FFI, which will require its allocations to take care of alignment (the methods in
impl AllocBytes for Box<[u8]>
ignore this_align: Align
argument).Needs rust-lang/rust#124492