From a0c44a30cf6731df08fcede2f54f069397ee36e9 Mon Sep 17 00:00:00 2001 From: Matthew Parkinson Date: Sun, 18 Dec 2022 22:47:41 +0000 Subject: [PATCH] Make reinterpret_cast more descriptive. Add an operation to get a tag free pointer from an address_t, and use it --- src/snmalloc/aal/address.h | 9 +++++++++ src/snmalloc/mem/freelist.h | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/snmalloc/aal/address.h b/src/snmalloc/aal/address.h index 2a9d614ae..26824a4ee 100644 --- a/src/snmalloc/aal/address.h +++ b/src/snmalloc/aal/address.h @@ -290,4 +290,13 @@ namespace snmalloc return static_cast(a - pointer_align_down(a)); } + /** + * Convert an address_t to a pointer. The returned pointer should never be followed. + * On CHERI following this pointer will result in a capability violation. + */ + template + SNMALLOC_FAST_PATH_INLINE T* useless_ptr_from_addr(address_t p) + { + return reinterpret_cast(p); + } } // namespace snmalloc diff --git a/src/snmalloc/mem/freelist.h b/src/snmalloc/mem/freelist.h index ba7346f63..a4ad423a1 100644 --- a/src/snmalloc/mem/freelist.h +++ b/src/snmalloc/mem/freelist.h @@ -695,7 +695,7 @@ namespace snmalloc // the Freelist builder always knows which block it is referring too. head[i] = Object::code_next( address_cast(&head[i]), - reinterpret_cast*>(slab), + useless_ptr_from_addr>(address_cast(slab)), key); } }