Add and plumb unsafe_{to,from}_uintptr<T> casts

These encapsulate the wildly powerful reinterpret_cast<> operator where one side
is a uintptr_t and the other is a native pointer.  In both cases we require the
pointer type to be explicitly given.
This commit is contained in:
Nathaniel Wesley Filardo
2022-03-17 17:34:26 +00:00
committed by Nathaniel Wesley Filardo
parent 4ad99d7392
commit 26324e8bfc
6 changed files with 45 additions and 21 deletions

View File

@@ -20,7 +20,7 @@ int main()
auto& global = GlobalChunkmap::pagemap();
SNMALLOC_CHECK(&p == &global);
// Get a valid heap address
uintptr_t addr = reinterpret_cast<uintptr_t>(malloc(42));
uintptr_t addr = unsafe_to_uintptr<void>(malloc(42));
// Make this very strongly aligned
addr &= ~0xfffffULL;
void* page = p.page_for_address(addr);