diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 4ca4853..be96704 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -400,12 +400,14 @@ jobs: # Job to run clang-format and report errors format: - runs-on: ubuntu-20.04 + runs-on: ubuntu-22.04 # We don't need to do the build for this job, but we need to configure it to get the clang-format target steps: - uses: actions/checkout@v3 - name: Install clang-tidy and clang-format - run: sudo apt install clang-tidy-9 clang-format-9 + run: | + sudo apt update + sudo apt install clang-tidy-15 clang-format-15 - name: Configure CMake run: cmake -B ${{github.workspace}}/build -DSNMALLOC_USE_CXX17=ON # Run the clang-format check and error if it generates a diff @@ -417,7 +419,7 @@ jobs: git diff --exit-code - name: Run clang-tidy run: | - clang-tidy-9 src/snmalloc/override/malloc.cc -header-filter="`pwd`/*" -warnings-as-errors='*' -export-fixes=tidy.fail -- -std=c++17 -mcx16 -DSNMALLOC_PLATFORM_HAS_GETENTROPY=0 + clang-tidy-15 src/snmalloc/override/malloc.cc -header-filter="`pwd`/*" -warnings-as-errors='*' -export-fixes=tidy.fail -- -std=c++17 -mcx16 -DSNMALLOC_PLATFORM_HAS_GETENTROPY=0 if [ -f tidy.fail ] ; then cat tidy.fail exit 1 diff --git a/CMakeLists.txt b/CMakeLists.txt index 1d9cbb6..365b854 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -150,7 +150,7 @@ function(clangformat_targets) # tool. It does not work with older versions as AfterCaseLabel is not supported # in earlier versions. find_program(CLANG_FORMAT NAMES - clang-format90 clang-format-9) + clang-format150 clang-format-15) # If we've found a clang-format tool, generate a target for it, otherwise emit # a warning. diff --git a/src/snmalloc/aal/aal_concept.h b/src/snmalloc/aal/aal_concept.h index 3ce64a7..eac6ebc 100644 --- a/src/snmalloc/aal/aal_concept.h +++ b/src/snmalloc/aal/aal_concept.h @@ -14,87 +14,79 @@ namespace snmalloc * machine word size, and an upper bound on the address space size */ template - concept IsAAL_static_members = requires() - { - typename std::integral_constant; - typename std::integral_constant; - typename std::integral_constant; - typename std::integral_constant; - }; + concept IsAAL_static_members = + requires() { + typename std::integral_constant; + typename std::integral_constant; + typename std::integral_constant; + typename std::integral_constant; + }; /** * AALs provide a prefetch operation. */ template - concept IsAAL_prefetch = requires(void* ptr) - { - { - AAL::prefetch(ptr) - } - noexcept->ConceptSame; - }; + concept IsAAL_prefetch = requires(void* ptr) { + { + AAL::prefetch(ptr) + } noexcept -> ConceptSame; + }; /** * AALs provide a notion of high-precision timing. */ template - concept IsAAL_tick = requires() - { - { - AAL::tick() - } - noexcept->ConceptSame; - }; + concept IsAAL_tick = requires() { + { + AAL::tick() + } noexcept -> ConceptSame; + }; template concept IsAAL_capptr_methods = - requires(capptr::Chunk auth, capptr::AllocFull ret, size_t sz) - { - /** - * Produce a pointer with reduced authority from a more privilged pointer. - * The resulting pointer will have base at auth's address and length of - * exactly sz. auth+sz must not exceed auth's limit. - */ - { - AAL::template capptr_bound(auth, sz) - } - noexcept->ConceptSame>; + requires(capptr::Chunk auth, capptr::AllocFull ret, size_t sz) { + /** + * Produce a pointer with reduced authority from a more privilged pointer. + * The resulting pointer will have base at auth's address and length of + * exactly sz. auth+sz must not exceed auth's limit. + */ + { + AAL::template capptr_bound(auth, sz) + } noexcept -> ConceptSame>; - /** - * "Amplify" by copying the address of one pointer into one of higher - * privilege. The resulting pointer differs from auth only in address. - */ - { - AAL::capptr_rebound(auth, ret) - } - noexcept->ConceptSame>; + /** + * "Amplify" by copying the address of one pointer into one of higher + * privilege. The resulting pointer differs from auth only in address. + */ + { + AAL::capptr_rebound(auth, ret) + } noexcept -> ConceptSame>; - /** - * Round up an allocation size to a size this architecture can represent. - * While there may also, in general, be alignment requirements for - * representability, in snmalloc so far we have not had reason to consider - * these explicitly: when we use our... - * - * - sizeclass machinery (for user-facing data), we assume that all - * sizeclasses describe architecturally representable aligned-and-sized - * regions - * - * - Range machinery (for internal meta-data), we always choose NAPOT - * regions big enough for the requested size (returning space above the - * allocation within such regions for use as smaller NAPOT regions). - * - * That is, capptr_size_round is not needed on the user-facing fast paths, - * merely internally for bootstrap and metadata management. - */ - { - AAL::capptr_size_round(sz) - } - noexcept->ConceptSame; - }; + /** + * Round up an allocation size to a size this architecture can represent. + * While there may also, in general, be alignment requirements for + * representability, in snmalloc so far we have not had reason to consider + * these explicitly: when we use our... + * + * - sizeclass machinery (for user-facing data), we assume that all + * sizeclasses describe architecturally representable aligned-and-sized + * regions + * + * - Range machinery (for internal meta-data), we always choose NAPOT + * regions big enough for the requested size (returning space above the + * allocation within such regions for use as smaller NAPOT regions). + * + * That is, capptr_size_round is not needed on the user-facing fast paths, + * merely internally for bootstrap and metadata management. + */ + { + AAL::capptr_size_round(sz) + } noexcept -> ConceptSame; + }; template - concept IsAAL = IsAAL_static_members&& IsAAL_prefetch&& - IsAAL_tick&& IsAAL_capptr_methods; + concept IsAAL = IsAAL_static_members && IsAAL_prefetch && + IsAAL_tick && IsAAL_capptr_methods; } // namespace snmalloc #endif diff --git a/src/snmalloc/backend/fixedglobalconfig.h b/src/snmalloc/backend/fixedglobalconfig.h index c6784e7..37a78c2 100644 --- a/src/snmalloc/backend/fixedglobalconfig.h +++ b/src/snmalloc/backend/fixedglobalconfig.h @@ -63,13 +63,11 @@ namespace snmalloc * C++, and not just its initializer fragment, to initialize a non-prefix * subset of the flags (in any order, at that). */ - static constexpr Flags Options = []() constexpr - { + static constexpr Flags Options = []() constexpr { Flags opts = {}; opts.HasDomesticate = true; return opts; - } - (); + }(); // This needs to be a forward reference as the // thread local state will need to know about this. diff --git a/src/snmalloc/ds/aba.h b/src/snmalloc/ds/aba.h index f14cc9e..af75de9 100644 --- a/src/snmalloc/ds/aba.h +++ b/src/snmalloc/ds/aba.h @@ -71,9 +71,10 @@ namespace snmalloc error("Only one inflight ABA operation at a time is allowed."); operation_in_flight = true; # endif - return Cmp{{independent.ptr.load(std::memory_order_relaxed), - independent.aba.load(std::memory_order_relaxed)}, - this}; + return Cmp{ + {independent.ptr.load(std::memory_order_relaxed), + independent.aba.load(std::memory_order_relaxed)}, + this}; } struct Cmp diff --git a/src/snmalloc/ds_core/helpers.h b/src/snmalloc/ds_core/helpers.h index 61fcee9..e79c569 100644 --- a/src/snmalloc/ds_core/helpers.h +++ b/src/snmalloc/ds_core/helpers.h @@ -324,7 +324,7 @@ namespace snmalloc } std::array buf{{0}}; const char digits[] = "0123456789"; - for (long i = long(buf.size() - 1); i >= 0; i--) + for (long i = static_cast(buf.size() - 1); i >= 0; i--) { buf[static_cast(i)] = digits[s % 10]; s /= 10; @@ -356,7 +356,7 @@ namespace snmalloc const char hexdigits[] = "0123456789abcdef"; // Length of string including null terminator static_assert(sizeof(hexdigits) == 0x11); - for (long i = long(buf.size() - 1); i >= 0; i--) + for (long i = static_cast(buf.size() - 1); i >= 0; i--) { buf[static_cast(i)] = hexdigits[s & 0xf]; s >>= 4; diff --git a/src/snmalloc/ds_core/mitigations.h b/src/snmalloc/ds_core/mitigations.h index 88547dc..2370f29 100644 --- a/src/snmalloc/ds_core/mitigations.h +++ b/src/snmalloc/ds_core/mitigations.h @@ -247,10 +247,10 @@ namespace snmalloc */ full_checks + cheri_checks + clear_meta - freelist_forward_edge - pal_enforce_access : - /** - * clear_meta is important on CHERI to avoid leaking capabilities. - */ - sanity_checks + cheri_checks + clear_meta; + /** + * clear_meta is important on CHERI to avoid leaking capabilities. + */ + sanity_checks + cheri_checks + clear_meta; #else CHECK_CLIENT ? full_checks : no_checks; #endif diff --git a/src/snmalloc/ds_core/redblacktree.h b/src/snmalloc/ds_core/redblacktree.h index df1fb94..f69114b 100644 --- a/src/snmalloc/ds_core/redblacktree.h +++ b/src/snmalloc/ds_core/redblacktree.h @@ -17,11 +17,10 @@ namespace snmalloc * ID. */ template - concept RBRepTypes = requires() - { - typename Rep::Handle; - typename Rep::Contents; - }; + concept RBRepTypes = requires() { + typename Rep::Handle; + typename Rep::Contents; + }; /** * The representation must define operations on the holder and contents @@ -41,50 +40,36 @@ namespace snmalloc */ template concept RBRepMethods = - requires(typename Rep::Handle hp, typename Rep::Contents k, bool b) - { - { - Rep::get(hp) - } - ->ConceptSame; - { - Rep::set(hp, k) - } - ->ConceptSame; - { - Rep::is_red(k) - } - ->ConceptSame; - { - Rep::set_red(k, b) - } - ->ConceptSame; - { - Rep::ref(b, k) - } - ->ConceptSame; - { - Rep::null - } - ->ConceptSameModRef; - { - typename Rep::Handle + requires(typename Rep::Handle hp, typename Rep::Contents k, bool b) { { - const_cast< + Rep::get(hp) + } -> ConceptSame; + { + Rep::set(hp, k) + } -> ConceptSame; + { + Rep::is_red(k) + } -> ConceptSame; + { + Rep::set_red(k, b) + } -> ConceptSame; + { + Rep::ref(b, k) + } -> ConceptSame; + { + Rep::null + } -> ConceptSameModRef; + { + typename Rep::Handle{const_cast< std::remove_const_t>*>( - &Rep::root) - } - } - ->ConceptSame; - }; + &Rep::root)} + } -> ConceptSame; + }; template concept RBRep = // - RBRepTypes // - && RBRepMethods // - && ConceptSame< - decltype(Rep::null), - std::add_const_t>; + RBRepTypes && RBRepMethods && + ConceptSame>; #endif /** @@ -275,7 +260,7 @@ namespace snmalloc std::array path; size_t length = 0; - RBPath(typename Rep::Handle root) : path{} + RBPath(typename Rep::Handle root) { path[0].set(root, false); length = 1; @@ -490,8 +475,7 @@ namespace snmalloc */ path.move(true); while (path.move(false)) - { - } + {} K curr = path.curr(); @@ -510,8 +494,8 @@ namespace snmalloc // If we had a left child, replace ourselves with the extracted value // from above Rep::set_red(curr, Rep::is_red(splice)); - get_dir(true, curr) = K(get_dir(true, splice)); - get_dir(false, curr) = K(get_dir(false, splice)); + get_dir(true, curr) = K{get_dir(true, splice)}; + get_dir(false, curr) = K{get_dir(false, splice)}; splice = curr; path.fixup(); } @@ -742,8 +726,7 @@ namespace snmalloc auto path = get_root_path(); while (path.move(true)) - { - } + {} K result = path.curr(); diff --git a/src/snmalloc/global/memcpy.h b/src/snmalloc/global/memcpy.h index f4996f6..565719a 100644 --- a/src/snmalloc/global/memcpy.h +++ b/src/snmalloc/global/memcpy.h @@ -192,7 +192,8 @@ namespace snmalloc * It's not entirely clear what we would do if this were not the case. * Best not think too hard about it now. */ - static_assert(alignof(void*) == sizeof(void*)); + static_assert( + alignof(void*) == sizeof(void*)); // NOLINT(misc-redundant-expression) static constexpr size_t LargestRegisterSize = 16; diff --git a/src/snmalloc/mem/backend_concept.h b/src/snmalloc/mem/backend_concept.h index f0ed396..1680391 100644 --- a/src/snmalloc/mem/backend_concept.h +++ b/src/snmalloc/mem/backend_concept.h @@ -14,18 +14,15 @@ namespace snmalloc */ template concept IsReadablePagemap = - requires(address_t addr, size_t sz, const typename Pagemap::Entry& t) - { - { - Pagemap::template get_metaentry(addr) - } - ->ConceptSame; + requires(address_t addr, size_t sz, const typename Pagemap::Entry& t) { + { + Pagemap::template get_metaentry(addr) + } -> ConceptSame; - { - Pagemap::template get_metaentry(addr) - } - ->ConceptSame; - }; + { + Pagemap::template get_metaentry(addr) + } -> ConceptSame; + }; /** * The core of the static pagemap accessor interface: {get,set}_metadata. @@ -36,24 +33,20 @@ namespace snmalloc * set_metadata updates the entry in the pagemap. */ template - concept IsWritablePagemap = IsReadablePagemap&& requires( - address_t addr, size_t sz, const typename Pagemap::Entry& t) - { - { - Pagemap::template get_metaentry_mut(addr) - } - ->ConceptSame; + concept IsWritablePagemap = IsReadablePagemap && + requires(address_t addr, size_t sz, const typename Pagemap::Entry& t) { + { + Pagemap::template get_metaentry_mut(addr) + } -> ConceptSame; - { - Pagemap::template get_metaentry_mut(addr) - } - ->ConceptSame; + { + Pagemap::template get_metaentry_mut(addr) + } -> ConceptSame; - { - Pagemap::set_metaentry(addr, sz, t) - } - ->ConceptSame; - }; + { + Pagemap::set_metaentry(addr, sz, t) + } -> ConceptSame; + }; /** * The pagemap can also be told to commit backing storage for a range of @@ -63,13 +56,11 @@ namespace snmalloc * which combines this and the core concept, above. */ template - concept IsPagemapWithRegister = requires(capptr::Arena p, size_t sz) - { - { - Pagemap::register_range(p, sz) - } - ->ConceptSame; - }; + concept IsPagemapWithRegister = requires(capptr::Arena p, size_t sz) { + { + Pagemap::register_range(p, sz) + } -> ConceptSame; + }; /** * The full pagemap accessor interface, with all of {get,set}_metadata and @@ -81,7 +72,7 @@ namespace snmalloc */ template concept IsWritablePagemapWithRegister = - IsWritablePagemap&& IsPagemapWithRegister; + IsWritablePagemap && IsPagemapWithRegister; /** * The configuration also defines domestication (that is, the difference @@ -91,62 +82,50 @@ namespace snmalloc */ template concept IsConfigDomestication = - requires(typename Config::LocalState* ls, capptr::AllocWild ptr) - { - { - Config::capptr_domesticate(ls, ptr) - } - ->ConceptSame>; + requires(typename Config::LocalState* ls, capptr::AllocWild ptr) { + { + Config::capptr_domesticate(ls, ptr) + } -> ConceptSame>; - { - Config::capptr_domesticate(ls, ptr.template as_static()) - } - ->ConceptSame>; - }; + { + Config::capptr_domesticate(ls, ptr.template as_static()) + } -> ConceptSame>; + }; class CommonConfig; struct Flags; template concept IsBackend = - requires(LocalState& local_state, size_t size, uintptr_t ras) - { - { - Backend::alloc_chunk(local_state, size, ras) - } - ->ConceptSame< - std::pair, typename Backend::SlabMetadata*>>; - } - &&requires(LocalState* local_state, size_t size) - { - { - Backend::template alloc_meta_data(local_state, size) - } - ->ConceptSame>; - } - &&requires( - LocalState& local_state, - typename Backend::SlabMetadata& slab_metadata, - capptr::Alloc alloc, - size_t size) - { - { - Backend::dealloc_chunk(local_state, slab_metadata, alloc, size) - } - ->ConceptSame; - } - &&requires(address_t p) - { - { - Backend::template get_metaentry(p) - } - ->ConceptSame; + requires(LocalState& local_state, size_t size, uintptr_t ras) { + { + Backend::alloc_chunk(local_state, size, ras) + } -> ConceptSame< + std::pair, typename Backend::SlabMetadata*>>; + } && + requires(LocalState* local_state, size_t size) { + { + Backend::template alloc_meta_data(local_state, size) + } -> ConceptSame>; + } && + requires( + LocalState& local_state, + typename Backend::SlabMetadata& slab_metadata, + capptr::Alloc alloc, + size_t size) { + { + Backend::dealloc_chunk(local_state, slab_metadata, alloc, size) + } -> ConceptSame; + } && + requires(address_t p) { + { + Backend::template get_metaentry(p) + } -> ConceptSame; - { - Backend::template get_metaentry(p) - } - ->ConceptSame; - }; + { + Backend::template get_metaentry(p) + } -> ConceptSame; + }; /** * Config objects of type T must obey a number of constraints. They @@ -161,38 +140,39 @@ namespace snmalloc * */ template - concept IsConfig = std::is_base_of::value&& - IsPAL&& IsBackend< - typename Config::LocalState, - typename Config::PagemapEntry, - typename Config::Backend>&& requires() - { - typename Config::LocalState; - typename Config::Backend; - typename Config::PagemapEntry; - - { - Config::Options - } - ->ConceptSameModRef; - } - &&( + concept IsConfig = std::is_base_of::value && + IsPAL && + IsBackend && requires() { - Config::Options.CoreAllocIsPoolAllocated == true; - typename Config::GlobalPoolState; + typename Config::LocalState; + typename Config::Backend; + typename Config::PagemapEntry; + { - Config::pool() - } - ->ConceptSame; - } || - requires() { Config::Options.CoreAllocIsPoolAllocated == false; }); + Config::Options + } -> ConceptSameModRef; + } && + ( + requires() { + Config::Options.CoreAllocIsPoolAllocated == true; + typename Config::GlobalPoolState; + { + Config::pool() + } -> ConceptSame; + } || + requires() { + Config::Options.CoreAllocIsPoolAllocated == false; + }); /** * The lazy version of the above; please see ds_core/concept.h and use * sparingly. */ template - concept IsConfigLazy = !is_type_complete_v || IsConfig; + concept IsConfigLazy = ! + is_type_complete_v || IsConfig; } // namespace snmalloc diff --git a/src/snmalloc/mem/sizeclasstable.h b/src/snmalloc/mem/sizeclasstable.h index 2037443..dd2be97 100644 --- a/src/snmalloc/mem/sizeclasstable.h +++ b/src/snmalloc/mem/sizeclasstable.h @@ -167,8 +167,8 @@ namespace snmalloc struct SizeClassTable { - ModArray fast_; - ModArray slow_; + ModArray fast_{}; + ModArray slow_{}; size_t DIV_MULT_SHIFT{0}; @@ -203,7 +203,7 @@ namespace snmalloc return slow_[index.raw()]; } - constexpr SizeClassTable() : fast_(), slow_(), DIV_MULT_SHIFT() + constexpr SizeClassTable() { size_t max_capacity = 0; diff --git a/src/snmalloc/override/jemalloc_compat.cc b/src/snmalloc/override/jemalloc_compat.cc index a655546..7fe11da 100644 --- a/src/snmalloc/override/jemalloc_compat.cc +++ b/src/snmalloc/override/jemalloc_compat.cc @@ -116,7 +116,7 @@ extern "C" * now, this is always implemented to return an error. */ SNMALLOC_EXPORT int - SNMALLOC_NAME_MANGLE(mallctl)(const char*, void*, size_t*, void*, size_t) + SNMALLOC_NAME_MANGLE(mallctl)(const char*, void*, size_t*, void*, size_t) { return ENOENT; } @@ -265,7 +265,7 @@ extern "C" * controlling the thread cache and arena are ignored. */ SNMALLOC_EXPORT void* - SNMALLOC_NAME_MANGLE(rallocx)(void* ptr, size_t size, int flags) + SNMALLOC_NAME_MANGLE(rallocx)(void* ptr, size_t size, int flags) { auto f = JEMallocFlags(flags); size = f.aligned_size(size); diff --git a/src/snmalloc/override/malloc.cc b/src/snmalloc/override/malloc.cc index 512ba3d..b975848 100644 --- a/src/snmalloc/override/malloc.cc +++ b/src/snmalloc/override/malloc.cc @@ -113,7 +113,7 @@ extern "C" #if !defined(SNMALLOC_NO_REALLOCARRAY) SNMALLOC_EXPORT void* - SNMALLOC_NAME_MANGLE(reallocarray)(void* ptr, size_t nmemb, size_t size) + SNMALLOC_NAME_MANGLE(reallocarray)(void* ptr, size_t nmemb, size_t size) { bool overflow = false; size_t sz = bits::umul(size, nmemb, overflow); @@ -128,7 +128,7 @@ extern "C" #if !defined(SNMALLOC_NO_REALLOCARR) SNMALLOC_EXPORT int - SNMALLOC_NAME_MANGLE(reallocarr)(void* ptr_, size_t nmemb, size_t size) + SNMALLOC_NAME_MANGLE(reallocarr)(void* ptr_, size_t nmemb, size_t size) { int err = errno; auto& a = ThreadAlloc::get(); @@ -168,7 +168,7 @@ extern "C" #endif SNMALLOC_EXPORT void* - SNMALLOC_NAME_MANGLE(memalign)(size_t alignment, size_t size) + SNMALLOC_NAME_MANGLE(memalign)(size_t alignment, size_t size) { if ((alignment == 0) || (alignment == size_t(-1))) { @@ -186,7 +186,7 @@ extern "C" } SNMALLOC_EXPORT void* - SNMALLOC_NAME_MANGLE(aligned_alloc)(size_t alignment, size_t size) + SNMALLOC_NAME_MANGLE(aligned_alloc)(size_t alignment, size_t size) { SNMALLOC_ASSERT((size % alignment) == 0); return SNMALLOC_NAME_MANGLE(memalign)(alignment, size); diff --git a/src/snmalloc/override/memcpy.cc b/src/snmalloc/override/memcpy.cc index c2283ec..c6053ae 100644 --- a/src/snmalloc/override/memcpy.cc +++ b/src/snmalloc/override/memcpy.cc @@ -6,7 +6,7 @@ extern "C" * Snmalloc checked memcpy. */ SNMALLOC_EXPORT void* - SNMALLOC_NAME_MANGLE(memcpy)(void* dst, const void* src, size_t len) + SNMALLOC_NAME_MANGLE(memcpy)(void* dst, const void* src, size_t len) { return snmalloc::memcpy(dst, src, len); } diff --git a/src/snmalloc/override/new.cc b/src/snmalloc/override/new.cc index 29372a7..d3e084d 100644 --- a/src/snmalloc/override/new.cc +++ b/src/snmalloc/override/new.cc @@ -38,12 +38,12 @@ void* operator new[](size_t size, std::nothrow_t&) return ThreadAlloc::get().alloc(size); } -void operator delete(void* p)EXCEPTSPEC +void operator delete(void* p) EXCEPTSPEC { ThreadAlloc::get().dealloc(p); } -void operator delete(void* p, size_t size)EXCEPTSPEC +void operator delete(void* p, size_t size) EXCEPTSPEC { if (p == nullptr) return; @@ -96,7 +96,7 @@ void* operator new[](size_t size, std::align_val_t val, std::nothrow_t&) return ThreadAlloc::get().alloc(size); } -void operator delete(void* p, std::align_val_t)EXCEPTSPEC +void operator delete(void* p, std::align_val_t) EXCEPTSPEC { ThreadAlloc::get().dealloc(p); } @@ -106,7 +106,7 @@ void operator delete[](void* p, std::align_val_t) EXCEPTSPEC ThreadAlloc::get().dealloc(p); } -void operator delete(void* p, size_t size, std::align_val_t val)EXCEPTSPEC +void operator delete(void* p, size_t size, std::align_val_t val) EXCEPTSPEC { size = aligned_size(size_t(val), size); ThreadAlloc::get().dealloc(p, size); diff --git a/src/snmalloc/override/rust.cc b/src/snmalloc/override/rust.cc index 64da984..f7825cd 100644 --- a/src/snmalloc/override/rust.cc +++ b/src/snmalloc/override/rust.cc @@ -10,19 +10,19 @@ using namespace snmalloc; extern "C" SNMALLOC_EXPORT void* - SNMALLOC_NAME_MANGLE(rust_alloc)(size_t alignment, size_t size) +SNMALLOC_NAME_MANGLE(rust_alloc)(size_t alignment, size_t size) { return ThreadAlloc::get().alloc(aligned_size(alignment, size)); } extern "C" SNMALLOC_EXPORT void* - SNMALLOC_NAME_MANGLE(rust_alloc_zeroed)(size_t alignment, size_t size) +SNMALLOC_NAME_MANGLE(rust_alloc_zeroed)(size_t alignment, size_t size) { return ThreadAlloc::get().alloc(aligned_size(alignment, size)); } extern "C" SNMALLOC_EXPORT void - SNMALLOC_NAME_MANGLE(rust_dealloc)(void* ptr, size_t alignment, size_t size) +SNMALLOC_NAME_MANGLE(rust_dealloc)(void* ptr, size_t alignment, size_t size) { ThreadAlloc::get().dealloc(ptr, aligned_size(alignment, size)); } diff --git a/src/snmalloc/pal/pal_concept.h b/src/snmalloc/pal/pal_concept.h index 44dec41..7efbd08 100644 --- a/src/snmalloc/pal/pal_concept.h +++ b/src/snmalloc/pal/pal_concept.h @@ -19,62 +19,54 @@ namespace snmalloc * PALs must advertize the bit vector of their supported features. */ template - concept IsPAL_static_features = requires() - { - typename std::integral_constant; - }; + concept IsPAL_static_features = + requires() { + typename std::integral_constant; + }; /** * PALs must advertise the size of the address space and their page size */ template - concept IsPAL_static_sizes = requires() - { - typename std::integral_constant; - typename std::integral_constant; - }; + concept IsPAL_static_sizes = + requires() { + typename std::integral_constant; + typename std::integral_constant; + }; /** * PALs expose an error reporting function which takes a const C string. */ template - concept IsPAL_error = requires(const char* const str) - { - { - PAL::error(str) - } - ->ConceptSame; - }; + concept IsPAL_error = requires(const char* const str) { + { + PAL::error(str) + } -> ConceptSame; + }; /** * PALs expose a basic library of memory operations. */ template - concept IsPAL_memops = requires(void* vp, std::size_t sz) - { - { - PAL::notify_not_using(vp, sz) - } - noexcept->ConceptSame; + concept IsPAL_memops = requires(void* vp, std::size_t sz) { + { + PAL::notify_not_using(vp, sz) + } noexcept -> ConceptSame; - { - PAL::template notify_using(vp, sz) - } - noexcept->ConceptSame; - { - PAL::template notify_using(vp, sz) - } - noexcept->ConceptSame; + { + PAL::template notify_using(vp, sz) + } noexcept -> ConceptSame; + { + PAL::template notify_using(vp, sz) + } noexcept -> ConceptSame; - { - PAL::template zero(vp, sz) - } - noexcept->ConceptSame; - { - PAL::template zero(vp, sz) - } - noexcept->ConceptSame; - }; + { + PAL::template zero(vp, sz) + } noexcept -> ConceptSame; + { + PAL::template zero(vp, sz) + } noexcept -> ConceptSame; + }; /** * The Pal must provide a thread id for debugging. It should not return @@ -82,66 +74,55 @@ namespace snmalloc * places. */ template - concept IsPAL_tid = requires() - { - { - PAL::get_tid() - } - noexcept->ConceptSame; - }; + concept IsPAL_tid = + requires() { + { + PAL::get_tid() + } noexcept -> ConceptSame; + }; /** * Absent any feature flags, the PAL must support a crude primitive allocator */ template - concept IsPAL_reserve = requires(PAL p, std::size_t sz) - { - { - PAL::reserve(sz) - } - noexcept->ConceptSame; - }; + concept IsPAL_reserve = requires(PAL p, std::size_t sz) { + { + PAL::reserve(sz) + } noexcept -> ConceptSame; + }; /** * Some PALs expose a richer allocator which understands aligned allocations */ template - concept IsPAL_reserve_aligned = requires(std::size_t sz) - { - { - PAL::template reserve_aligned(sz) - } - noexcept->ConceptSame; - { - PAL::template reserve_aligned(sz) - } - noexcept->ConceptSame; - }; + concept IsPAL_reserve_aligned = requires(std::size_t sz) { + { + PAL::template reserve_aligned(sz) + } noexcept -> ConceptSame; + { + PAL::template reserve_aligned(sz) + } noexcept -> ConceptSame; + }; /** * Some PALs can provide memory pressure callbacks. */ template - concept IsPAL_mem_low_notify = requires(PalNotificationObject* pno) - { - { - PAL::expensive_low_memory_check() - } - ->ConceptSame; - { - PAL::register_for_low_memory_callback(pno) - } - ->ConceptSame; - }; + concept IsPAL_mem_low_notify = requires(PalNotificationObject* pno) { + { + PAL::expensive_low_memory_check() + } -> ConceptSame; + { + PAL::register_for_low_memory_callback(pno) + } -> ConceptSame; + }; template - concept IsPAL_get_entropy64 = requires() - { - { - PAL::get_entropy64() - } - ->ConceptSame; - }; + concept IsPAL_get_entropy64 = requires() { + { + PAL::get_entropy64() + } -> ConceptSame; + }; /** * PALs ascribe to the conjunction of several concepts. These are broken diff --git a/src/snmalloc/pal/pal_noalloc.h b/src/snmalloc/pal/pal_noalloc.h index 94bc61e..49b0d4b 100644 --- a/src/snmalloc/pal/pal_noalloc.h +++ b/src/snmalloc/pal/pal_noalloc.h @@ -17,7 +17,7 @@ namespace snmalloc * The minimal subset of a PAL that we need for delegation */ template - concept PALNoAllocBase = IsPAL_static_sizes&& IsPAL_error; + concept PALNoAllocBase = IsPAL_static_sizes && IsPAL_error; #endif /** diff --git a/src/test/func/domestication/domestication.cc b/src/test/func/domestication/domestication.cc index 03cc9ba..8ff4fa9 100644 --- a/src/test/func/domestication/domestication.cc +++ b/src/test/func/domestication/domestication.cc @@ -62,14 +62,12 @@ namespace snmalloc * C++, and not just its initializer fragment, to initialize a non-prefix * subset of the flags (in any order, at that). */ - static constexpr Flags Options = []() constexpr - { + static constexpr Flags Options = []() constexpr { Flags opts = {}; opts.QueueHeadsAreTame = false; opts.HasDomesticate = true; return opts; - } - (); + }(); static GlobalPoolState& pool() { diff --git a/src/test/func/sandbox/sandbox.cc b/src/test/func/sandbox/sandbox.cc index 5194880..f3327af 100644 --- a/src/test/func/sandbox/sandbox.cc +++ b/src/test/func/sandbox/sandbox.cc @@ -172,7 +172,7 @@ namespace * sandbox but allocates memory inside. */ struct RemoteAllocator queue; - } * shared_state; + }* shared_state; /** * The memory provider for this sandbox. @@ -195,7 +195,7 @@ namespace Sandbox(size_t sb_size) : start(alloc_sandbox_heap(sb_size)), top(pointer_offset(start, sb_size)), - shared_state(new (start) SharedState()), + shared_state(new(start) SharedState()), state( pointer_offset(CapPtr(start), sizeof(SharedState)), sb_size - sizeof(SharedState)),