Skip to content
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

Add TBI helpers for AArch64 #1622

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

dheaton-arm
Copy link
Contributor

Adds a trait to core_arch for AArch64 to set a value in the top byte of a pointer (which should logically become the canonical address of the allocation), and to retrieve the value stored in the top byte of a pointer, if any.

The intent is for a Rust-provided mechanism for such adjustments to pointers, so that any internal pointer tracking could be updated as necessary, such as to enable this pattern within Miri.

@rustbot
Copy link
Collaborator

rustbot commented Aug 2, 2024

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @Amanieu (or someone else) some time within the next two weeks.

@bors
Copy link
Contributor

bors commented Aug 3, 2024

☔ The latest upstream changes (presumably 5097cfb) made this pull request unmergeable. Please resolve the merge conflicts.

Adds a new `TBIBox` type in `core_arch`, which allows for modifying the
top byte of the address that the allocation lives at.

Modifying the top byte reallocates the data, thereby invalidating any
existing pointers and avoiding aliasing.
)
};
// Reconstruct the `Box` using the address with the new top byte and return that, wrapped as a TBIBox
Self(Some(unsafe { Box::from_raw(ptr) }), original_ptr, top_byte)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't hide things sufficiently well from the compiler. The compiler can still see that ptr is just the same as original_ptr with an offset applied -- making this still UB.

You need the computation of ptr itself to occur in a "black box".

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah yes I see, maybe I could move the step that actually sets the top byte i.e. addr | top_byte_shifted into the inline asm block and do it there with an explicit ORR, do you think that would work?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah that would be better.

@mrkajetanp
Copy link
Contributor

Because the TBIBox interacts with Box and does allocations, it does not actually fit into stdarch - this will be moved into alloc, though there'll be an RFC coming first.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants