diff --git a/src/snmalloc/aal/aal.h b/src/snmalloc/aal/aal.h index 7648444..626cbf6 100644 --- a/src/snmalloc/aal/aal.h +++ b/src/snmalloc/aal/aal.h @@ -16,7 +16,7 @@ # define SNMALLOC_TICK_USE_CLOCK_GETTIME # endif #endif -#include +#include #include #ifndef SNMALLOC_TICK_USE_CLOCK_GETTIME diff --git a/src/snmalloc/aal/aal_arm.h b/src/snmalloc/aal/aal_arm.h index 11013c4..c076ce7 100644 --- a/src/snmalloc/aal/aal_arm.h +++ b/src/snmalloc/aal/aal_arm.h @@ -12,7 +12,7 @@ # endif #endif -#include +#include namespace snmalloc { diff --git a/src/snmalloc/aal/aal_consts.h b/src/snmalloc/aal/aal_consts.h index 8990a41..7b3d22a 100644 --- a/src/snmalloc/aal/aal_consts.h +++ b/src/snmalloc/aal/aal_consts.h @@ -1,5 +1,5 @@ #pragma once -#include +#include namespace snmalloc { diff --git a/src/snmalloc/aal/address.h b/src/snmalloc/aal/address.h index 6c1a760..91cce94 100644 --- a/src/snmalloc/aal/address.h +++ b/src/snmalloc/aal/address.h @@ -1,7 +1,7 @@ #pragma once #include "../ds_core/ds_core.h" -#include +#include namespace snmalloc { diff --git a/src/snmalloc/ds/aba.h b/src/snmalloc/ds/aba.h index be4ef53..b0f67ec 100644 --- a/src/snmalloc/ds/aba.h +++ b/src/snmalloc/ds/aba.h @@ -27,7 +27,7 @@ namespace snmalloc class ABA { public: - struct alignas(2 * sizeof(std::size_t)) Linked + struct alignas(2 * sizeof(size_t)) Linked { T* ptr{nullptr}; uintptr_t aba{0}; @@ -43,13 +43,13 @@ namespace snmalloc sizeof(Linked) == sizeof(Independent), "Expecting identical struct sizes in union"); static_assert( - sizeof(Linked) == (2 * sizeof(std::size_t)), + sizeof(Linked) == (2 * sizeof(size_t)), "Expecting ABA to be the size of two pointers"); private: union { - alignas(2 * sizeof(std::size_t)) stl::Atomic linked; + alignas(2 * sizeof(size_t)) stl::Atomic linked; Independent independent; }; diff --git a/src/snmalloc/ds_core/bits.h b/src/snmalloc/ds_core/bits.h index ff481f9..3391e70 100644 --- a/src/snmalloc/ds_core/bits.h +++ b/src/snmalloc/ds_core/bits.h @@ -1,7 +1,6 @@ #pragma once -#include -#include +#include // #define USE_LZCNT @@ -9,9 +8,10 @@ #include "snmalloc/stl/atomic.h" #include "snmalloc/stl/type_traits.h" -#include -#include +#include +#include #if defined(_MSC_VER) +# include # include #endif @@ -95,15 +95,15 @@ namespace snmalloc return BITS - index - 1; # endif #else - if constexpr (stl::is_same_v) + if constexpr (stl::is_same_v) { return static_cast(__builtin_clzl(x)); } - else if constexpr (stl::is_same_v) + else if constexpr (stl::is_same_v) { return static_cast(__builtin_clzll(x)); } - else if constexpr (stl::is_same_v) + else if constexpr (stl::is_same_v) { return static_cast(__builtin_clz(x)); } @@ -182,15 +182,15 @@ namespace snmalloc return _tzcnt_u32(static_cast(x)); # endif #else - if constexpr (stl::is_same_v) + if constexpr (stl::is_same_v) { return static_cast(__builtin_ctzl(x)); } - else if constexpr (stl::is_same_v) + else if constexpr (stl::is_same_v) { return static_cast(__builtin_ctzll(x)); } - else if constexpr (stl::is_same_v) + else if constexpr (stl::is_same_v) { return static_cast(__builtin_ctz(x)); } diff --git a/src/snmalloc/ds_core/defines.h b/src/snmalloc/ds_core/defines.h index 8c076b9..fa85b68 100644 --- a/src/snmalloc/ds_core/defines.h +++ b/src/snmalloc/ds_core/defines.h @@ -1,5 +1,5 @@ #pragma once -#include +#include #if defined(_MSC_VER) && !defined(__clang__) // 28 is FAST_FAIL_INVALID_BUFFER_ACCESS. Not using the symbolic constant to diff --git a/src/snmalloc/ds_core/helpers.h b/src/snmalloc/ds_core/helpers.h index 0041857..753b8ed 100644 --- a/src/snmalloc/ds_core/helpers.h +++ b/src/snmalloc/ds_core/helpers.h @@ -5,7 +5,7 @@ #include "snmalloc/stl/type_traits.h" #include -#include +#include namespace snmalloc { diff --git a/src/snmalloc/ds_core/mitigations.h b/src/snmalloc/ds_core/mitigations.h index 6e60c9d..4f52008 100644 --- a/src/snmalloc/ds_core/mitigations.h +++ b/src/snmalloc/ds_core/mitigations.h @@ -1,7 +1,7 @@ #pragma once #include "defines.h" -#include +#include namespace snmalloc { diff --git a/src/snmalloc/ds_core/redblacktree.h b/src/snmalloc/ds_core/redblacktree.h index 724e7e1..585c173 100644 --- a/src/snmalloc/ds_core/redblacktree.h +++ b/src/snmalloc/ds_core/redblacktree.h @@ -1,8 +1,8 @@ #pragma once #include -#include -#include +#include +#include namespace snmalloc { diff --git a/src/snmalloc/ds_core/seqset.h b/src/snmalloc/ds_core/seqset.h index 2816825..65b188c 100644 --- a/src/snmalloc/ds_core/seqset.h +++ b/src/snmalloc/ds_core/seqset.h @@ -4,7 +4,7 @@ #include "../ds_core/ds_core.h" #include "snmalloc/stl/type_traits.h" -#include +#include namespace snmalloc { diff --git a/src/snmalloc/mem/entropy.h b/src/snmalloc/mem/entropy.h index 3692907..d05fb36 100644 --- a/src/snmalloc/mem/entropy.h +++ b/src/snmalloc/mem/entropy.h @@ -4,7 +4,7 @@ #include "../pal/pal.h" #include "snmalloc/stl/type_traits.h" -#include +#include namespace snmalloc { diff --git a/src/snmalloc/mem/freelist.h b/src/snmalloc/mem/freelist.h index 07b47e6..75c96f2 100644 --- a/src/snmalloc/mem/freelist.h +++ b/src/snmalloc/mem/freelist.h @@ -37,7 +37,7 @@ #include "entropy.h" #include "snmalloc/stl/new.h" -#include +#include namespace snmalloc { diff --git a/src/snmalloc/mem/localalloc.h b/src/snmalloc/mem/localalloc.h index 946d853..2cdefc8 100644 --- a/src/snmalloc/mem/localalloc.h +++ b/src/snmalloc/mem/localalloc.h @@ -1,5 +1,6 @@ #pragma once +#include "snmalloc/aal/address.h" #if defined(_MSC_VER) # define ALLOCATOR __declspec(allocator) __declspec(restrict) #elif __has_attribute(malloc) @@ -888,8 +889,18 @@ namespace snmalloc auto sizeclass = entry.get_sizeclass(); return snmalloc::remaining_bytes(sizeclass, p); #else - return reinterpret_cast( - std::numeric_limits::max() - p); + constexpr address_t mask = static_cast(-1); + constexpr bool is_signed = mask < 0; + constexpr address_t sign_bit = + bits::one_at_bit(CHAR_BIT * sizeof(address_t) - 1); + if constexpr (is_signed) + { + return (mask ^ sign_bit) - p; + } + else + { + return mask - p; + } #endif } diff --git a/src/snmalloc/mem/ticker.h b/src/snmalloc/mem/ticker.h index 2bce041..c48ff19 100644 --- a/src/snmalloc/mem/ticker.h +++ b/src/snmalloc/mem/ticker.h @@ -2,7 +2,7 @@ #include "../ds_core/ds_core.h" -#include +#include namespace snmalloc { diff --git a/src/snmalloc/override/jemalloc_compat.cc b/src/snmalloc/override/jemalloc_compat.cc index 79206fe..0f47845 100644 --- a/src/snmalloc/override/jemalloc_compat.cc +++ b/src/snmalloc/override/jemalloc_compat.cc @@ -1,6 +1,7 @@ #include "override.h" #include +#include #include using namespace snmalloc; @@ -182,7 +183,7 @@ extern "C" return allocm_err_not_moved; } - if (std::numeric_limits::max() - size > extra) + if (SIZE_MAX - size > extra) { alloc_size = f.aligned_size(size + extra); } diff --git a/src/snmalloc/override/rust.cc b/src/snmalloc/override/rust.cc index 4a5dcda..980ba8d 100644 --- a/src/snmalloc/override/rust.cc +++ b/src/snmalloc/override/rust.cc @@ -1,7 +1,7 @@ #define SNMALLOC_NAME_MANGLE(a) sn_##a #include "snmalloc/snmalloc.h" -#include +#include #ifndef SNMALLOC_EXPORT # define SNMALLOC_EXPORT @@ -39,7 +39,7 @@ extern "C" SNMALLOC_EXPORT void* SNMALLOC_NAME_MANGLE(rust_realloc)( void* p = ThreadAlloc::get().alloc(aligned_new_size); if (p) { - std::memcpy(p, ptr, old_size < new_size ? old_size : new_size); + memcpy(p, ptr, old_size < new_size ? old_size : new_size); ThreadAlloc::get().dealloc(ptr, aligned_old_size); } return p; diff --git a/src/snmalloc/pal/pal_concept.h b/src/snmalloc/pal/pal_concept.h index 469c8f3..b4b7d87 100644 --- a/src/snmalloc/pal/pal_concept.h +++ b/src/snmalloc/pal/pal_concept.h @@ -30,8 +30,8 @@ namespace snmalloc template concept IsPAL_static_sizes = requires() { - typename stl::integral_constant; - typename stl::integral_constant; + typename stl::integral_constant; + typename stl::integral_constant; }; /** @@ -48,7 +48,7 @@ namespace snmalloc * PALs expose a basic library of memory operations. */ template - concept IsPAL_memops = requires(void* vp, std::size_t sz) { + concept IsPAL_memops = requires(void* vp, size_t sz) { { PAL::notify_not_using(vp, sz) } noexcept -> ConceptSame; @@ -72,7 +72,7 @@ namespace snmalloc * Absent any feature flags, the PAL must support a crude primitive allocator */ template - concept IsPAL_reserve = requires(PAL p, std::size_t sz) { + concept IsPAL_reserve = requires(PAL p, size_t sz) { { PAL::reserve(sz) } noexcept -> ConceptSame; @@ -82,7 +82,7 @@ namespace snmalloc * Some PALs expose a richer allocator which understands aligned allocations */ template - concept IsPAL_reserve_aligned = requires(std::size_t sz) { + concept IsPAL_reserve_aligned = requires(size_t sz) { { PAL::template reserve_aligned(sz) } noexcept -> ConceptSame; diff --git a/src/snmalloc/pal/pal_noalloc.h b/src/snmalloc/pal/pal_noalloc.h index 49b0d4b..590aefe 100644 --- a/src/snmalloc/pal/pal_noalloc.h +++ b/src/snmalloc/pal/pal_noalloc.h @@ -8,7 +8,7 @@ #include "pal_consts.h" #include "pal_timer_default.h" -#include +#include namespace snmalloc { diff --git a/src/snmalloc/pal/pal_posix.h b/src/snmalloc/pal/pal_posix.h index bbbc658..0d50f36 100644 --- a/src/snmalloc/pal/pal_posix.h +++ b/src/snmalloc/pal/pal_posix.h @@ -5,17 +5,18 @@ #if defined(SNMALLOC_BACKTRACE_HEADER) # include SNMALLOC_BACKTRACE_HEADER #endif -#include #include #include #include #include +#include #include #include #include #include #include #include + #if __has_include() # include #endif diff --git a/src/test/func/jemalloc/jemalloc.cc b/src/test/func/jemalloc/jemalloc.cc index 5baddd7..0e34e1f 100644 --- a/src/test/func/jemalloc/jemalloc.cc +++ b/src/test/func/jemalloc/jemalloc.cc @@ -1,4 +1,5 @@ #include +#include #include #include #include @@ -288,7 +289,7 @@ namespace { START_TEST("allocm out-of-memory behaviour"); void* ptr = nullptr; - int ret = Allocm(&ptr, nullptr, std::numeric_limits::max() / 2, 0); + int ret = Allocm(&ptr, nullptr, SIZE_MAX / 2, 0); EXPECT( (ptr == nullptr) && (ret == OUR_ALLOCM_ERR_OOM), "Expected massive allocation to fail with out of memory ({}), received "