NFC: move some capptr utility functions to that namespace

We'll want user_address_control_type in some particular PALs, so it can't live
in pal.h.

While here, make the spelling be capptr::is_spatial_refinement.
This commit is contained in:
Nathaniel Wesley Filardo
2021-10-17 18:37:38 +01:00
committed by Nathaniel Wesley Filardo
parent 1de28eead7
commit dba795ac6f
3 changed files with 45 additions and 45 deletions

View File

@@ -197,7 +197,7 @@ namespace snmalloc
{
// Impose constraints on bounds annotations.
static_assert(BIn::spatial >= capptr::dimension::Spatial::Chunk);
static_assert(capptr_is_spatial_refinement<BIn, BOut>());
static_assert(capptr::is_spatial_refinement<BIn, BOut>());
UNUSED(size);
return CapPtr<T, BOut>(a.template as_static<T>().unsafe_capptr);

View File

@@ -48,7 +48,7 @@ namespace snmalloc
/**
* On some platforms (e.g., CHERI), pointers can be checked to see whether
* they authorize control of the address space. See the PAL's
* capptr_export().
* capptr_to_user_address_control().
*/
enum class AddressSpaceControl
{
@@ -188,38 +188,48 @@ namespace snmalloc
*/
using AllocWild = Alloc::with_wildness<dimension::Wildness::Wild>;
} // namespace bounds
/**
* Compute the AddressSpaceControl::User variant of a capptr::bound
* annotation. This is used by the PAL's capptr_to_user_address_control
* function to compute its return value's annotation.
*/
template<SNMALLOC_CONCEPT(capptr::ConceptBound) B>
using user_address_control_type =
typename B::template with_address_space_control<
dimension::AddressSpaceControl::User>;
/**
* Determine whether BI is a spatial refinement of BO.
* Chunk and ChunkD are considered eqivalent here.
*/
template<
SNMALLOC_CONCEPT(capptr::ConceptBound) BI,
SNMALLOC_CONCEPT(capptr::ConceptBound) BO>
SNMALLOC_CONSTEVAL bool is_spatial_refinement()
{
if (BI::address_space_control != BO::address_space_control)
{
return false;
}
if (BI::wildness != BO::wildness)
{
return false;
}
switch (BI::spatial)
{
using namespace capptr::dimension;
case Spatial::Chunk:
return true;
case Spatial::Alloc:
return BO::spatial == Spatial::Alloc;
}
}
} // namespace capptr
/**
* Determine whether BI is a spatial refinement of BO.
* Chunk and ChunkD are considered eqivalent here.
*/
template<
SNMALLOC_CONCEPT(capptr::ConceptBound) BI,
SNMALLOC_CONCEPT(capptr::ConceptBound) BO>
SNMALLOC_CONSTEVAL bool capptr_is_spatial_refinement()
{
if (BI::address_space_control != BO::address_space_control)
{
return false;
}
if (BI::wildness != BO::wildness)
{
return false;
}
switch (BI::spatial)
{
using namespace capptr::dimension;
case Spatial::Chunk:
return true;
case Spatial::Alloc:
return BO::spatial == Spatial::Alloc;
}
}
/**
* A pointer annotated with a "phantom type parameter" carrying a static
* summary of its StrictProvenance metadata.

View File

@@ -69,16 +69,6 @@ namespace snmalloc
// Used to keep Superslab metadata committed.
static constexpr size_t OS_PAGE_SIZE = Pal::page_size;
/**
* Compute the AddressSpaceControl::User variant of a capptr::bound
* annotation. This is used by the PAL's capptr_export function to compute
* its return value's annotation.
*/
template<SNMALLOC_CONCEPT(capptr::ConceptBound) B>
using capptr_user_address_control_type =
typename B::template with_address_space_control<
capptr::dimension::AddressSpaceControl::User>;
/**
* Perform platform-specific adjustment of return pointers.
*
@@ -92,10 +82,10 @@ namespace snmalloc
SNMALLOC_CONCEPT(capptr::ConceptBound) B>
static inline typename std::enable_if_t<
!aal_supports<StrictProvenance, AAL>,
CapPtr<T, capptr_user_address_control_type<B>>>
CapPtr<T, capptr::user_address_control_type<B>>>
capptr_to_user_address_control(CapPtr<T, B> p)
{
return CapPtr<T, capptr_user_address_control_type<B>>(p.unsafe_capptr);
return CapPtr<T, capptr::user_address_control_type<B>>(p.unsafe_capptr);
}
template<
@@ -105,7 +95,7 @@ namespace snmalloc
SNMALLOC_CONCEPT(capptr::ConceptBound) B>
static SNMALLOC_FAST_PATH typename std::enable_if_t<
aal_supports<StrictProvenance, AAL>,
CapPtr<T, capptr_user_address_control_type<B>>>
CapPtr<T, capptr::user_address_control_type<B>>>
capptr_to_user_address_control(CapPtr<T, B> p)
{
return PAL::capptr_to_user_address_control(p);