Skip to content

Commit

Permalink
Make reinterpret_cast more descriptive.
Browse files Browse the repository at this point in the history
Add an operation to get a tag free pointer from an address_t, and use it
  • Loading branch information
mjp41 committed Dec 18, 2022
1 parent 9b77a3f commit a0c44a3
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
9 changes: 9 additions & 0 deletions src/snmalloc/aal/address.h
Original file line number Diff line number Diff line change
Expand Up @@ -290,4 +290,13 @@ namespace snmalloc
return static_cast<size_t>(a - pointer_align_down<alignment>(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<typename T>
SNMALLOC_FAST_PATH_INLINE T* useless_ptr_from_addr(address_t p)
{
return reinterpret_cast<T*>(p);
}
} // namespace snmalloc
2 changes: 1 addition & 1 deletion src/snmalloc/mem/freelist.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<Object::T<BQueue>*>(slab),
useless_ptr_from_addr<Object::T<BQueue>>(address_cast(slab)),
key);
}
}
Expand Down

0 comments on commit a0c44a3

Please sign in to comment.