Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,14 @@ option(SNMALLOC_ENABLE_WAIT_ON_ADDRESS "Use wait on address backoff strategy if
option(SNMALLOC_PTHREAD_FORK_PROTECTION "Guard against forking while allocator locks are held using pthread_atfork hooks" OFF)
option(SNMALLOC_ENABLE_FUZZING "Enable fuzzing instrumentation tests" OFF)
option(SNMALLOC_USE_SELF_VENDORED_STL "Avoid using system STL" OFF)
set(
SNMALLOC_DEFAULT_RBTREE_POLICY
"WeakAVLPolicy"
CACHE STRING
"Default RBTree policy class in snmalloc::rankbalancetree (WeakAVLPolicy or RedBlackPolicy)")
set_property(
CACHE SNMALLOC_DEFAULT_RBTREE_POLICY
PROPERTY STRINGS WeakAVLPolicy RedBlackPolicy)
# Options that apply only if we're not building the header-only library
cmake_dependent_option(SNMALLOC_RUST_SUPPORT "Build static library for rust" OFF "NOT SNMALLOC_HEADER_ONLY_LIBRARY" OFF)
cmake_dependent_option(SNMALLOC_RUST_LIBC_API "Include libc API in the rust library" OFF "SNMALLOC_RUST_SUPPORT" OFF)
Expand Down Expand Up @@ -352,6 +360,7 @@ add_as_define_value(SNMALLOC_MIN_ALLOC_SIZE)
add_as_define_value(SNMALLOC_MIN_ALLOC_STEP_SIZE)
add_as_define_value(SNMALLOC_DEALLOC_BATCH_RING_ASSOC)
add_as_define_value(SNMALLOC_DEALLOC_BATCH_RING_SET_BITS)
add_as_define_value(SNMALLOC_DEFAULT_RBTREE_POLICY)

add_as_define_value(SNMALLOC_PAGESIZE)

Expand Down
2 changes: 1 addition & 1 deletion docs/AddressSpace.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ Its contents can be decoded as follows:
This trick of pointing at the child's chunk rather than at the child `MetaEntry` is particularly useful on CHERI:
it allows us to capture the authority to the chunk without needing another pointer and costs just a shift and add.)

3. The `meta` field's `LargeBuddyRep::RED_BIT` is used to carry the red/black color of this node.
3. The `meta` field's `LargeBuddyRep::TREE_TAG_BIT` is used to carry the red/black color of this node.

See `src/backend/largebuddyrange.h`.

Expand Down
26 changes: 13 additions & 13 deletions src/snmalloc/backend_helpers/largebuddyrange.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ namespace snmalloc
/*
* The values we store in our rbtree are the addresses of (combined spans
* of) chunks of the address space; as such, bits in (MIN_CHUNK_SIZE - 1)
* are unused and so the RED_BIT is packed therein. However, in practice,
* are unused and so the TREE_TAG_BIT is packed therein. However, in practice,
* these are not "just any" uintptr_t-s, but specifically the uintptr_t-s
* inside the Pagemap's BackendAllocator::Entry structures.
*
Expand All @@ -37,13 +37,13 @@ namespace snmalloc
* a bit that is a valid part of the address of a chunk.
* @{
*/
static constexpr address_t RED_BIT = 1 << 8;
static constexpr address_t TREE_TAG_BIT = 1 << 8;

static_assert(RED_BIT < MIN_CHUNK_SIZE);
static_assert(TREE_TAG_BIT < MIN_CHUNK_SIZE);
static_assert(MetaEntryBase::is_backend_allowed_value(
MetaEntryBase::Word::One, RED_BIT));
MetaEntryBase::Word::One, TREE_TAG_BIT));
static_assert(MetaEntryBase::is_backend_allowed_value(
MetaEntryBase::Word::Two, RED_BIT));
MetaEntryBase::Word::Two, TREE_TAG_BIT));
///@}

/// The value of a null node, as returned by `get`
Expand All @@ -56,15 +56,15 @@ namespace snmalloc
*/
static void set(Handle ptr, Contents r)
{
ptr = r | (static_cast<address_t>(ptr.get()) & RED_BIT);
ptr = r | (static_cast<address_t>(ptr.get()) & TREE_TAG_BIT);
}

/**
* Returns the value, stripping out the red/black colour.
*/
static Contents get(const Handle ptr)
{
return ptr.get() & ~RED_BIT;
return ptr.get() & ~TREE_TAG_BIT;
}

/**
Expand All @@ -87,19 +87,19 @@ namespace snmalloc
return entry.get_backend_word(Pagemap::Entry::Word::Two);
}

static bool is_red(Contents k)
static bool tree_tag(Contents k)
{
return (ref(true, k).get() & RED_BIT) == RED_BIT;
return (ref(true, k).get() & TREE_TAG_BIT) == TREE_TAG_BIT;
}

static void set_red(Contents k, bool new_is_red)
static void set_tree_tag(Contents k, bool new_tree_tag)
{
if (new_is_red != is_red(k))
if (new_tree_tag != tree_tag(k))
{
auto v = ref(true, k);
v = v.get() ^ RED_BIT;
v = v.get() ^ TREE_TAG_BIT;
}
SNMALLOC_ASSERT(is_red(k) == new_is_red);
SNMALLOC_ASSERT(tree_tag(k) == new_tree_tag);
}

static Contents offset(Contents k, size_t size)
Expand Down
10 changes: 5 additions & 5 deletions src/snmalloc/backend_helpers/smallbuddyrange.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,21 +57,21 @@ namespace snmalloc
return &r->right;
}

static bool is_red(Contents k)
static bool tree_tag(Contents k)
{
if (k == nullptr)
return false;
return (address_cast(*ref(false, k)) & MASK) == MASK;
}

static void set_red(Contents k, bool new_is_red)
static void set_tree_tag(Contents k, bool new_tree_tag)
{
if (new_is_red != is_red(k))
if (new_tree_tag != tree_tag(k))
{
auto r = ref(false, k);
auto old_addr = pointer_align_down<2, FreeChunk<bounds>>(r->as_void());

if (new_is_red)
if (new_tree_tag)
{
if (old_addr == nullptr)
*r = CapPtr<FreeChunk<bounds>, bounds>::unsafe_from(
Expand All @@ -84,7 +84,7 @@ namespace snmalloc
{
*r = old_addr;
}
SNMALLOC_ASSERT(is_red(k) == new_is_red);
SNMALLOC_ASSERT(tree_tag(k) == new_tree_tag);
}
}

Expand Down
1 change: 1 addition & 0 deletions src/snmalloc/ds_core/concept.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once

#include "snmalloc/stl/type_traits.h"
#include <stddef.h>

/**
* C++20 concepts are referenced as if they were types in declarations within
Expand Down
2 changes: 1 addition & 1 deletion src/snmalloc/ds_core/ds_core.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@
#include "helpers.h"
#include "mitigations.h"
#include "ptrwrap.h"
#include "redblacktree.h"
#include "rankbalancetree.h"
#include "tid.h"
Loading
Loading