Repository navigation
feat(secondary): add SecondaryAllocatorChain, lookup, and ownership checks - #911
Draft
Jaya Kasa (jayakasadev) wants to merge 2 commits into
Draft
Jaya Kasa (jayakasadev) wants to merge 2 commits into
Jaya Kasa (jayakasadev) wants to merge 2 commits into
Conversation
…hecks Allow two secondary allocators (such as GWP-ASan and a future profiling store) to compose cleanly, and keep main-heap pointers off secondary ownership checks: - Add SecondaryAllocatorChain (mem/secondary/chain.h) and optional-member helpers (mem/secondary/optional.h) for has_pending, cancel_pending, lookup, and debug_is_empty - Add owns() to DefaultSecondaryAllocator and GwpAsanSecondaryAllocator - Add secondary_owns() and secondary_object() in globalalloc.h, gated by a pagemap ownership check so main-heap pointers never query the secondary - Check sizeclass before secondary_owns() in libc::realloc and rust_realloc, and include secondary emptiness in debug_check_empty() - Make Pool::iterate() lock the head read (ds/pool.h) and const-qualify GNU Atomic::load() (stl/gnu/atomic.h) - Add unit tests: secondary_chain and secondary_owns
MetaEntryBase::is_owned() calls get_remote(), which asserts !is_backend_owned() in Debug builds. Check is_backend_owned() first in detail::secondary_object() and secondary_owns() so external_pointer(), remaining_bytes(), and secondary_owns() handle freed main-heap chunks without aborting under non-passthrough secondary allocators (e.g. GWP-ASan). Extend func-secondary_owns to assert that backend-owned chunks neither abort nor reach SecondaryAllocator::owns().
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Lets two secondary allocators compose via
SecondaryAllocatorChain(e.g. GWP-ASan + a future profiling store), adds a fastsecondary_owns()check inglobalalloc.h, and ensuresreallocanddebug_check_empty()handle secondary-owned pointers safely. Also makesPool::iterate()lock its head read and const-qualifies GNUAtomic::load().Why
Heap profiling (#853) stores sampled objects in a secondary allocator so ordinary frees stay fast. Users need that to work alongside GWP-ASan without slowing down normal main-heap
reallocorfree.Cost
Zero when no secondary allocator is enabled (
pass_throughbranches compile away). When a secondary allocator is active,secondary_owns()andsecondary_object()check the pagemap first, so main-heap pointers never query or lock the secondary allocator.Test plan
Run on macOS arm64 (
524cafb):DebugCMake (-fast+-check):ctest -j892/92 passed (including newsecondary_chainandsecondary_ownstests)ReleaseCMake (-fast+-check):ctest -j892/92 passedclang-format 15.0.7 --dry-run -Werrorclean