-
Notifications
You must be signed in to change notification settings - Fork 112
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce and plumb ProvenanceCaptureRange
This backs out the sleight of hand from the SmallBuddyRange Co-authored-by: Matthew Parkinson <[email protected]>
- Loading branch information
Showing
5 changed files
with
95 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
#pragma once | ||
|
||
#include "empty_range.h" | ||
|
||
namespace snmalloc | ||
{ | ||
/** | ||
* This Range converts between Arena-bounded chunks parent-wards and | ||
* Chunk-bounded chunks child-wards. In the alloc path, it stores the | ||
* high-authority pointer in the Pagemap, whence it retrieves it on the | ||
* dealloc path. | ||
*/ | ||
template< | ||
SNMALLOC_CONCEPT(IsWritablePagemap) Pagemap, | ||
bool strict_provenance = false, | ||
typename ParentRange = EmptyRange<>> | ||
class ProvenanceCaptureRange : public ContainsParent<ParentRange> | ||
{ | ||
using ContainsParent<ParentRange>::parent; | ||
|
||
public: | ||
/** | ||
* We use a nested Apply type to enable a Pipe operation. | ||
*/ | ||
template<typename ParentRange2> | ||
using Apply = | ||
ProvenanceCaptureRange<Pagemap, strict_provenance, ParentRange2>; | ||
|
||
constexpr ProvenanceCaptureRange() = default; | ||
|
||
static constexpr bool Aligned = ParentRange::Aligned; | ||
|
||
static constexpr bool ConcurrencySafe = ParentRange::ConcurrencySafe; | ||
|
||
using ChunkBounds = capptr::bounds::Chunk; | ||
static_assert( | ||
std::is_same_v<typename ParentRange::ChunkBounds, capptr::bounds::Arena>); | ||
|
||
capptr::Chunk<void> alloc_range(size_t size) | ||
{ | ||
SNMALLOC_ASSERT((size & (MIN_CHUNK_SIZE - 1)) == 0); | ||
|
||
auto arena = parent.alloc_range(size); | ||
|
||
if (arena == nullptr) | ||
return nullptr; | ||
|
||
if constexpr (strict_provenance) | ||
{ | ||
Pagemap::template get_metaentry_mut<false>(address_cast(arena)) | ||
.get_backend_word(Pagemap::Entry::Word::One) = arena.unsafe_uintptr(); | ||
} | ||
|
||
return Aal::capptr_bound<void, capptr::bounds::Chunk>(arena, size); | ||
} | ||
|
||
void dealloc_range(capptr::Chunk<void> chunk, size_t size) | ||
{ | ||
capptr::Arena<void> arena; | ||
if constexpr (strict_provenance) | ||
{ | ||
arena = capptr::Arena<void>(reinterpret_cast<void*>( | ||
Pagemap::template get_metaentry_mut<false>(address_cast(chunk)) | ||
.get_backend_word(Pagemap::Entry::Word::One) | ||
.get())); | ||
SNMALLOC_ASSERT(address_cast(arena) == address_cast(chunk)); | ||
} | ||
else | ||
{ | ||
arena = capptr::Arena<void>(chunk.unsafe_ptr()); | ||
} | ||
|
||
parent.dealloc_range(arena, size); | ||
} | ||
}; | ||
} // namespace snmalloc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters