From b2c75dffb79361990e2f09adc29bb7f4aa637176 Mon Sep 17 00:00:00 2001 From: Nathaniel Wesley Filardo Date: Fri, 1 Jul 2022 12:30:31 +0100 Subject: [PATCH] NFC: rename ConceptBound to IsBound --- docs/StrictProvenance.md | 2 +- src/snmalloc/aal/aal.h | 4 +- src/snmalloc/aal/aal_cheri.h | 4 +- src/snmalloc/aal/address.h | 22 +++--- src/snmalloc/backend/fixedglobalconfig.h | 2 +- src/snmalloc/backend_helpers/empty_range.h | 2 +- src/snmalloc/backend_helpers/range_helpers.h | 5 +- .../backend_helpers/smallbuddyrange.h | 4 +- src/snmalloc/ds_core/ptrwrap.h | 14 ++-- src/snmalloc/mem/backend_wrappers.h | 6 +- src/snmalloc/mem/freelist.h | 67 +++++++++---------- src/snmalloc/pal/pal.h | 6 +- src/snmalloc/pal/pal_freebsd.h | 2 +- src/test/func/domestication/domestication.cc | 2 +- 14 files changed, 69 insertions(+), 73 deletions(-) diff --git a/docs/StrictProvenance.md b/docs/StrictProvenance.md index 8f23604..0678700 100644 --- a/docs/StrictProvenance.md +++ b/docs/StrictProvenance.md @@ -175,7 +175,7 @@ We introduce a multi-dimensional space of bounds. The facets are `enum class`-e * `Wildness` captures whether the pointer has been checked to belong to this allocator. These `dimension`s are composited using a `capptr::bound<>` type that we use as `B` in `CapPtr`. -This is enforced (loosely) using the `ConceptBound` C++20 concept. +This is enforced (loosely) using the `IsBound` C++20 concept. The namespace `snmalloc::capptr::bounds` contains particular points in the space of `capptr::bound<>` types: diff --git a/src/snmalloc/aal/aal.h b/src/snmalloc/aal/aal.h index 98606eb..ec0acce 100644 --- a/src/snmalloc/aal/aal.h +++ b/src/snmalloc/aal/aal.h @@ -198,8 +198,8 @@ namespace snmalloc */ template< typename T, - SNMALLOC_CONCEPT(capptr::ConceptBound) BOut, - SNMALLOC_CONCEPT(capptr::ConceptBound) BIn, + SNMALLOC_CONCEPT(capptr::IsBound) BOut, + SNMALLOC_CONCEPT(capptr::IsBound) BIn, typename U = T> static SNMALLOC_FAST_PATH CapPtr capptr_bound(CapPtr a, size_t size) noexcept diff --git a/src/snmalloc/aal/aal_cheri.h b/src/snmalloc/aal/aal_cheri.h index 587fdf1..25f35bb 100644 --- a/src/snmalloc/aal/aal_cheri.h +++ b/src/snmalloc/aal/aal_cheri.h @@ -63,8 +63,8 @@ namespace snmalloc template< typename T, - SNMALLOC_CONCEPT(capptr::ConceptBound) BOut, - SNMALLOC_CONCEPT(capptr::ConceptBound) BIn, + SNMALLOC_CONCEPT(capptr::IsBound) BOut, + SNMALLOC_CONCEPT(capptr::IsBound) BIn, typename U = T> static SNMALLOC_FAST_PATH CapPtr capptr_bound(CapPtr a, size_t size) noexcept diff --git a/src/snmalloc/aal/address.h b/src/snmalloc/aal/address.h index f373918..9be5998 100644 --- a/src/snmalloc/aal/address.h +++ b/src/snmalloc/aal/address.h @@ -30,7 +30,7 @@ namespace snmalloc unsafe_to_uintptr(base) + static_cast(diff)); } - template + template inline CapPtr pointer_offset(CapPtr base, size_t diff) { @@ -48,7 +48,7 @@ namespace snmalloc return reinterpret_cast(reinterpret_cast(base) + diff); } - template + template inline CapPtr pointer_offset_signed(CapPtr base, ptrdiff_t diff) { @@ -72,7 +72,7 @@ namespace snmalloc * as per above, and uses the wrapper types in its own definition, e.g., of * capptr_bound. */ - template + template inline SNMALLOC_FAST_PATH address_t address_cast(CapPtr a) { return address_cast(a.unsafe_ptr()); @@ -136,7 +136,7 @@ namespace snmalloc template< size_t alignment, typename T, - SNMALLOC_CONCEPT(capptr::ConceptBound) bounds> + SNMALLOC_CONCEPT(capptr::IsBound) bounds> inline CapPtr pointer_align_down(CapPtr p) { return CapPtr::unsafe_from( @@ -174,7 +174,7 @@ namespace snmalloc template< size_t alignment, typename T = void, - SNMALLOC_CONCEPT(capptr::ConceptBound) bounds> + SNMALLOC_CONCEPT(capptr::IsBound) bounds> inline CapPtr pointer_align_up(CapPtr p) { return CapPtr::unsafe_from( @@ -204,7 +204,7 @@ namespace snmalloc #endif } - template + template inline CapPtr pointer_align_down(CapPtr p, size_t alignment) { @@ -229,7 +229,7 @@ namespace snmalloc #endif } - template + template inline CapPtr pointer_align_up(CapPtr p, size_t alignment) { @@ -252,8 +252,8 @@ namespace snmalloc template< typename T = void, typename U = void, - SNMALLOC_CONCEPT(capptr::ConceptBound) Tbounds, - SNMALLOC_CONCEPT(capptr::ConceptBound) Ubounds> + SNMALLOC_CONCEPT(capptr::IsBound) Tbounds, + SNMALLOC_CONCEPT(capptr::IsBound) Ubounds> inline size_t pointer_diff(CapPtr base, CapPtr cursor) { return pointer_diff(base.unsafe_ptr(), cursor.unsafe_ptr()); @@ -272,8 +272,8 @@ namespace snmalloc template< typename T = void, typename U = void, - SNMALLOC_CONCEPT(capptr::ConceptBound) Tbounds, - SNMALLOC_CONCEPT(capptr::ConceptBound) Ubounds> + SNMALLOC_CONCEPT(capptr::IsBound) Tbounds, + SNMALLOC_CONCEPT(capptr::IsBound) Ubounds> inline ptrdiff_t pointer_diff_signed(CapPtr base, CapPtr cursor) { diff --git a/src/snmalloc/backend/fixedglobalconfig.h b/src/snmalloc/backend/fixedglobalconfig.h index 1ad1844..2339074 100644 --- a/src/snmalloc/backend/fixedglobalconfig.h +++ b/src/snmalloc/backend/fixedglobalconfig.h @@ -87,7 +87,7 @@ namespace snmalloc } /* Verify that a pointer points into the region managed by this config */ - template + template static SNMALLOC_FAST_PATH CapPtr< T, typename B::template with_wildness> diff --git a/src/snmalloc/backend_helpers/empty_range.h b/src/snmalloc/backend_helpers/empty_range.h index 0407478..db91b9d 100644 --- a/src/snmalloc/backend_helpers/empty_range.h +++ b/src/snmalloc/backend_helpers/empty_range.h @@ -3,7 +3,7 @@ namespace snmalloc { - template + template class EmptyRange { public: diff --git a/src/snmalloc/backend_helpers/range_helpers.h b/src/snmalloc/backend_helpers/range_helpers.h index 454cba0..1534bb8 100644 --- a/src/snmalloc/backend_helpers/range_helpers.h +++ b/src/snmalloc/backend_helpers/range_helpers.h @@ -4,10 +4,7 @@ namespace snmalloc { - template< - size_t MIN_BITS, - SNMALLOC_CONCEPT(capptr::ConceptBound) B, - typename F> + template void range_to_pow_2_blocks(CapPtr base, size_t length, F f) { auto end = pointer_offset(base, length); diff --git a/src/snmalloc/backend_helpers/smallbuddyrange.h b/src/snmalloc/backend_helpers/smallbuddyrange.h index f19163b..ce54055 100644 --- a/src/snmalloc/backend_helpers/smallbuddyrange.h +++ b/src/snmalloc/backend_helpers/smallbuddyrange.h @@ -10,7 +10,7 @@ namespace snmalloc * struct for representing the redblack nodes * directly inside the meta data. */ - template + template struct FreeChunk { CapPtr left; @@ -20,7 +20,7 @@ namespace snmalloc /** * Class for using the allocations own space to store in the RBTree. */ - template + template class BuddyInplaceRep { public: diff --git a/src/snmalloc/ds_core/ptrwrap.h b/src/snmalloc/ds_core/ptrwrap.h index f602800..c1e56f4 100644 --- a/src/snmalloc/ds_core/ptrwrap.h +++ b/src/snmalloc/ds_core/ptrwrap.h @@ -175,7 +175,7 @@ namespace snmalloc * with that spelling. Both seem happy with this formulation. */ template - concept ConceptBound = + concept IsBound = ConceptSame && ConceptSame && @@ -236,7 +236,7 @@ namespace snmalloc * annotation. This is used by the PAL's capptr_to_user_address_control * function to compute its return value's annotation. */ - template + template using user_address_control_type = typename B::template with_address_space_control< dimension::AddressSpaceControl::User>; @@ -246,8 +246,8 @@ namespace snmalloc * Chunk and ChunkD are considered eqivalent here. */ template< - SNMALLOC_CONCEPT(capptr::ConceptBound) BI, - SNMALLOC_CONCEPT(capptr::ConceptBound) BO> + SNMALLOC_CONCEPT(capptr::IsBound) BI, + SNMALLOC_CONCEPT(capptr::IsBound) BO> SNMALLOC_CONSTEVAL bool is_spatial_refinement() { if (BI::address_space_control != BO::address_space_control) @@ -268,7 +268,7 @@ namespace snmalloc * A pointer annotated with a "phantom type parameter" carrying a static * summary of its StrictProvenance metadata. */ - template + template class CapPtr { T* unsafe_capptr; @@ -446,7 +446,7 @@ namespace snmalloc /** * It's safe to mark any CapPtr as Wild. */ - template + template static inline SNMALLOC_FAST_PATH CapPtr< T, typename B::template with_wildness> @@ -467,7 +467,7 @@ namespace snmalloc * annotations around an un-annotated std::atomic, to appease C++, yet * will expose or consume only CapPtr with the same bounds annotation. */ - template + template class AtomicCapPtr { std::atomic unsafe_capptr; diff --git a/src/snmalloc/mem/backend_wrappers.h b/src/snmalloc/mem/backend_wrappers.h index 2d8b7ee..98320b2 100644 --- a/src/snmalloc/mem/backend_wrappers.h +++ b/src/snmalloc/mem/backend_wrappers.h @@ -42,7 +42,7 @@ namespace snmalloc template< SNMALLOC_CONCEPT(IsConfigDomestication) Config, typename T, - SNMALLOC_CONCEPT(capptr::ConceptBound) B> + SNMALLOC_CONCEPT(capptr::IsBound) B> constexpr SNMALLOC_FAST_PATH_INLINE auto has_domesticate(int) -> std::enable_if_t< std::is_same_v< @@ -65,7 +65,7 @@ namespace snmalloc template< SNMALLOC_CONCEPT(IsConfig) Config, typename T, - SNMALLOC_CONCEPT(capptr::ConceptBound) B> + SNMALLOC_CONCEPT(capptr::IsBound) B> constexpr SNMALLOC_FAST_PATH_INLINE bool has_domesticate(long) { return false; @@ -80,7 +80,7 @@ namespace snmalloc template< SNMALLOC_CONCEPT(IsConfig) Config, typename T, - SNMALLOC_CONCEPT(capptr::ConceptBound) B> + SNMALLOC_CONCEPT(capptr::IsBound) B> SNMALLOC_FAST_PATH_INLINE auto capptr_domesticate(typename Config::LocalState* ls, CapPtr p) { diff --git a/src/snmalloc/mem/freelist.h b/src/snmalloc/mem/freelist.h index 7d67750..335f128 100644 --- a/src/snmalloc/mem/freelist.h +++ b/src/snmalloc/mem/freelist.h @@ -57,8 +57,7 @@ namespace snmalloc { public: template< - SNMALLOC_CONCEPT(capptr::ConceptBound) BQueue = - capptr::bounds::AllocWild> + SNMALLOC_CONCEPT(capptr::IsBound) BQueue = capptr::bounds::AllocWild> class T; /** @@ -67,13 +66,13 @@ namespace snmalloc * place. Give it a shorter name (Object::BQueuePtr) for * convenience. */ - template + template using BQueuePtr = CapPtr, BQueue>; /** * As with BQueuePtr, but atomic. */ - template + template using BAtomicQueuePtr = AtomicCapPtr, BQueue>; /** @@ -83,16 +82,16 @@ namespace snmalloc * looks a little nicer than "CapPtr, BView>". */ template< - SNMALLOC_CONCEPT(capptr::ConceptBound) BView, - SNMALLOC_CONCEPT(capptr::ConceptBound) BQueue> + SNMALLOC_CONCEPT(capptr::IsBound) BView, + SNMALLOC_CONCEPT(capptr::IsBound) BQueue> using BHeadPtr = CapPtr, BView>; /** * As with BHeadPtr, but atomic. */ template< - SNMALLOC_CONCEPT(capptr::ConceptBound) BView, - SNMALLOC_CONCEPT(capptr::ConceptBound) BQueue> + SNMALLOC_CONCEPT(capptr::IsBound) BView, + SNMALLOC_CONCEPT(capptr::IsBound) BQueue> using BAtomicHeadPtr = AtomicCapPtr, BView>; /** @@ -112,14 +111,14 @@ namespace snmalloc * require size to be threaded through, but would provide more OOB * detection. */ - template + template class T { template< bool, bool, - SNMALLOC_CONCEPT(capptr::ConceptBound), - SNMALLOC_CONCEPT(capptr::ConceptBound)> + SNMALLOC_CONCEPT(capptr::IsBound), + SNMALLOC_CONCEPT(capptr::IsBound)> friend class Builder; friend class Object; @@ -139,7 +138,7 @@ namespace snmalloc public: template< - SNMALLOC_CONCEPT(capptr::ConceptBound) BView = typename BQueue:: + SNMALLOC_CONCEPT(capptr::IsBound) BView = typename BQueue:: template with_wildness, typename Domesticator> BHeadPtr @@ -164,7 +163,7 @@ namespace snmalloc * Read the next pointer */ template< - SNMALLOC_CONCEPT(capptr::ConceptBound) BView = typename BQueue:: + SNMALLOC_CONCEPT(capptr::IsBound) BView = typename BQueue:: template with_wildness, typename Domesticator> BHeadPtr @@ -203,8 +202,8 @@ namespace snmalloc // Note the inverted template argument order, since BView is inferable. template< - SNMALLOC_CONCEPT(capptr::ConceptBound) BQueue, - SNMALLOC_CONCEPT(capptr::ConceptBound) BView> + SNMALLOC_CONCEPT(capptr::IsBound) BQueue, + SNMALLOC_CONCEPT(capptr::IsBound) BView> static BHeadPtr make(CapPtr p) { return p.template as_static>(); @@ -213,7 +212,7 @@ namespace snmalloc /** * A container-of operation to convert &f->next_object to f */ - template + template static Object::T* from_next_ptr(CapPtr, BQueue>* ptr) { @@ -225,7 +224,7 @@ namespace snmalloc /** * Involutive encryption with raw pointers */ - template + template inline static Object::T* code_next(address_t curr, Object::T* next, const FreeListKey& key) { @@ -265,8 +264,8 @@ namespace snmalloc * is likely (but not necessarily) Wild. */ template< - SNMALLOC_CONCEPT(capptr::ConceptBound) BView, - SNMALLOC_CONCEPT(capptr::ConceptBound) BQueue> + SNMALLOC_CONCEPT(capptr::IsBound) BView, + SNMALLOC_CONCEPT(capptr::IsBound) BQueue> inline static BQueuePtr encode_next( address_t curr, BHeadPtr next, const FreeListKey& key) { @@ -290,8 +289,8 @@ namespace snmalloc * encapsulated within Object and we do not capture any of it statically. */ template< - SNMALLOC_CONCEPT(capptr::ConceptBound) BView, - SNMALLOC_CONCEPT(capptr::ConceptBound) BQueue> + SNMALLOC_CONCEPT(capptr::IsBound) BView, + SNMALLOC_CONCEPT(capptr::IsBound) BQueue> inline static BHeadPtr decode_next( address_t curr, BHeadPtr next, const FreeListKey& key) { @@ -300,8 +299,8 @@ namespace snmalloc } template< - SNMALLOC_CONCEPT(capptr::ConceptBound) BView, - SNMALLOC_CONCEPT(capptr::ConceptBound) BQueue> + SNMALLOC_CONCEPT(capptr::IsBound) BView, + SNMALLOC_CONCEPT(capptr::IsBound) BQueue> static void assert_view_queue_bounds() { static_assert( @@ -326,8 +325,8 @@ namespace snmalloc * next->next_object is nullptr). */ template< - SNMALLOC_CONCEPT(capptr::ConceptBound) BView, - SNMALLOC_CONCEPT(capptr::ConceptBound) BQueue> + SNMALLOC_CONCEPT(capptr::IsBound) BView, + SNMALLOC_CONCEPT(capptr::IsBound) BQueue> static BQueuePtr* store_next( BQueuePtr* curr, BHeadPtr next, @@ -345,7 +344,7 @@ namespace snmalloc return &(next->next_object); } - template + template static void store_null(BQueuePtr* curr, const FreeListKey& key) { *curr = @@ -358,8 +357,8 @@ namespace snmalloc * Uses the atomic view of next, so can be used in the message queues. */ template< - SNMALLOC_CONCEPT(capptr::ConceptBound) BView, - SNMALLOC_CONCEPT(capptr::ConceptBound) BQueue> + SNMALLOC_CONCEPT(capptr::IsBound) BView, + SNMALLOC_CONCEPT(capptr::IsBound) BQueue> static void atomic_store_next( BHeadPtr curr, BHeadPtr next, @@ -381,8 +380,8 @@ namespace snmalloc } template< - SNMALLOC_CONCEPT(capptr::ConceptBound) BView, - SNMALLOC_CONCEPT(capptr::ConceptBound) BQueue> + SNMALLOC_CONCEPT(capptr::IsBound) BView, + SNMALLOC_CONCEPT(capptr::IsBound) BQueue> static void atomic_store_null(BHeadPtr curr, const FreeListKey& key) { @@ -428,8 +427,8 @@ namespace snmalloc * Checks signing of pointers */ template< - SNMALLOC_CONCEPT(capptr::ConceptBound) BView = capptr::bounds::Alloc, - SNMALLOC_CONCEPT(capptr::ConceptBound) BQueue = capptr::bounds::AllocWild> + SNMALLOC_CONCEPT(capptr::IsBound) BView = capptr::bounds::Alloc, + SNMALLOC_CONCEPT(capptr::IsBound) BQueue = capptr::bounds::AllocWild> class Iter { Object::BHeadPtr curr{nullptr}; @@ -508,8 +507,8 @@ namespace snmalloc template< bool RANDOM, bool INIT = true, - SNMALLOC_CONCEPT(capptr::ConceptBound) BView = capptr::bounds::Alloc, - SNMALLOC_CONCEPT(capptr::ConceptBound) BQueue = capptr::bounds::AllocWild> + SNMALLOC_CONCEPT(capptr::IsBound) BView = capptr::bounds::Alloc, + SNMALLOC_CONCEPT(capptr::IsBound) BQueue = capptr::bounds::AllocWild> class Builder { static constexpr size_t LENGTH = RANDOM ? 2 : 1; diff --git a/src/snmalloc/pal/pal.h b/src/snmalloc/pal/pal.h index a425085..47dde5e 100644 --- a/src/snmalloc/pal/pal.h +++ b/src/snmalloc/pal/pal.h @@ -84,7 +84,7 @@ namespace snmalloc typename PAL = DefaultPal, typename AAL = Aal, typename T, - SNMALLOC_CONCEPT(capptr::ConceptBound) B> + SNMALLOC_CONCEPT(capptr::IsBound) B> static inline typename std::enable_if_t< !aal_supports, CapPtr>> @@ -98,7 +98,7 @@ namespace snmalloc typename PAL = DefaultPal, typename AAL = Aal, typename T, - SNMALLOC_CONCEPT(capptr::ConceptBound) B> + SNMALLOC_CONCEPT(capptr::IsBound) B> static SNMALLOC_FAST_PATH typename std::enable_if_t< aal_supports, CapPtr>> @@ -119,7 +119,7 @@ namespace snmalloc typename PAL, bool page_aligned = false, typename T, - SNMALLOC_CONCEPT(capptr::ConceptBound) B> + SNMALLOC_CONCEPT(capptr::IsBound) B> static SNMALLOC_FAST_PATH void pal_zero(CapPtr p, size_t sz) { static_assert( diff --git a/src/snmalloc/pal/pal_freebsd.h b/src/snmalloc/pal/pal_freebsd.h index 4c5c028..5d208c3 100644 --- a/src/snmalloc/pal/pal_freebsd.h +++ b/src/snmalloc/pal/pal_freebsd.h @@ -124,7 +124,7 @@ namespace snmalloc * manage the address space it references by clearing the SW_VMEM * permission bit. */ - template + template static SNMALLOC_FAST_PATH CapPtr> capptr_to_user_address_control(CapPtr p) { diff --git a/src/test/func/domestication/domestication.cc b/src/test/func/domestication/domestication.cc index c0ae603..5fbff09 100644 --- a/src/test/func/domestication/domestication.cc +++ b/src/test/func/domestication/domestication.cc @@ -79,7 +79,7 @@ namespace snmalloc static inline uintptr_t domesticate_patch_value; /* Verify that a pointer points into the region managed by this config */ - template + template static CapPtr< T, typename B::template with_wildness>