-
Notifications
You must be signed in to change notification settings - Fork 112
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
Use pointers, not addresses, in more places #188
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.
Otherwise, LGTM.
src/mem/alloc.h
Outdated
|
||
while (size > 64) | ||
{ | ||
// This is a large alloc redirect. | ||
ss = ss - (1ULL << (size - 64)); | ||
ss = pointer_offset_signed(ss, -(1 << (size - 64))); |
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.
I'm always worried about lines like this, and that the shift will occur not at 64bits, because it decides 1 is 32bit, and then this doesn't behave as expected.
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.
Annoyingly, when I use 1LL
, my host compiler barfs:
/cheri/source/mainline/snmalloc/src/mem/alloc.h:431:40: error: implicit conversion changes signedness: 'long long' to 'ptrdiff_t' (aka 'long') [-Werror,-Wsign-conversion]
which just seems wrong to me? Anyway, I've worked around it by doing static_cast<ptrdiff_t>(1)
which should make everyone happy on all platforms, yes?
Just always work with pointers using the functions defined in ds/address.h. This more obviously preserves provenance through the chain of reasoning. Note that there is still risk of malloc() being used as an amplification oracle on CHERI, but there's no additional risk from this change. Rename the external_address into external_pointer.
Since we anticipate address_t not carrying provenance on CHERI, but rather being vaddr_t there, it doesn't make sense to offer conversion back to a provenance-carrying pointer. Thankfully, there is not much to be done here: the uses were few and could be replaced with the vocabulary of other pointer operations in ds/address.h
This should produce equivalent code everywhere and more obviously preserves provenance where desired. Ultimately, eliminate
pointer_cast
entirely since it won't make sense to cast an address back to a pointer on CHERI platforms.