-
Notifications
You must be signed in to change notification settings - Fork 139
fix(guest-bin): align user memory allocations #753
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
base: main
Are you sure you want to change the base?
Conversation
7aee0e0
to
b81669d
Compare
b81669d
to
f3efbb5
Compare
The guest allocation wrapper aligned only the total memory block but did not guarantee that the pointer returned to the user was itself properly aligned. This patch attempts to fix that. It also adds alloc_aligned function which would be tricky to implement outside the guest but will make implementing other posix like allocation API much easier. Signed-off-by: Tomasz Andrzejak <[email protected]>
f3efbb5
to
cc20014
Compare
Signed-off-by: Tomasz Andrzejak <[email protected]>
0e3f72e
to
c623979
Compare
/// # Safety | ||
/// The returned pointer must be freed with `memory::free` when it is no longer needed, otherwise memory will leak. | ||
unsafe fn alloc_helper(size: usize, zero: bool) -> *mut c_void { | ||
unsafe fn alloc_helper(size: usize, alignment: usize, zero: bool) -> *mut c_void { |
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.
Are there any tests we should be adding to verify this new behavior?
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.
Yeah, this is tricky. This crate default target is baremetal and cargo doesn't allow different default targets for build and test: rust-lang/cargo#6784 so cargo test
won't work.
It really only make sense to write the tests within this module so we have an access to internal memory layout with header and whatnot. So we should probably either use custom test harness or unstable test_runner
features?
https://doc.rust-lang.org/beta/unstable-book/language-features/custom-test-frameworks.html
cc: @jprendes
The guest allocation wrapper aligned only the total memory block but did not guarantee that the pointer returned to the user was itself properly aligned. This patch attempts to fix that.
It also adds alloc_aligned function which would be tricky to implement outside the guest but will make implementing other posix like allocation API much easier.