Alignment of the bytes of Allocation to match align parameter#100467
Closed
emarteca wants to merge 25 commits intorust-lang:masterfrom
Closed
Alignment of the bytes of Allocation to match align parameter#100467emarteca wants to merge 25 commits intorust-lang:masterfrom
bytes of Allocation to match align parameter#100467emarteca wants to merge 25 commits intorust-lang:masterfrom
Conversation
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Aligning the
bytesfield ofAllocationso that it is aligned matching thealignparameter.Main changes are to:
Allocationconstructorsfrom_bytesanduninitadjust_from_tcxmethod inAllocationInstead of just converting the relevant
[u8]to aBox<[u8]>directly we now:std::alloc::Layoutof the alignment theAllocationis specified to have[u8]for this bufferThen we write the relevant bytes to it, check for uninit, etc -- same process as previously.
NOTE
With this current code, when the
bytesfield is deallocated, even though the size is right, in the layout the alignment might be under-required: for example we might have allocated it with alignment 4 and deallocate it with alignment 2. We know this is undefined behaviour violating the memory fitting requirements ofdealloc-- we're going to work around this by adding a wrapper struct for theBox<[u8]>that stores the alignment it was allocated with, and manually implements deallocation with the right alignment.Why are we doing this?
We want the address of the
bytesfield of anAllocationto be accessible, and represent the actual address of the[u8]. This is part of an effort to pass pointers in Miri to the C FFI.