Skip to content

feat(secondary): add SecondaryAllocatorChain, lookup, and ownership checks - #911

Draft
Jaya Kasa (jayakasadev) wants to merge 2 commits into
microsoft:mainfrom
jayakasadev:pr1-secondary-chain
Draft

Jaya Kasa (jayakasadev) wants to merge 2 commits into
microsoft:mainfrom
jayakasadev:pr1-secondary-chain

Conversation

@jayakasadev

Copy link
Copy Markdown
Contributor

What

Lets two secondary allocators compose via SecondaryAllocatorChain (e.g. GWP-ASan + a future profiling store), adds a fast secondary_owns() check in globalalloc.h, and ensures realloc and debug_check_empty() handle secondary-owned pointers safely. Also makes Pool::iterate() lock its head read and const-qualifies GNU Atomic::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 realloc or free.

Cost

Zero when no secondary allocator is enabled (pass_through branches compile away). When a secondary allocator is active, secondary_owns() and secondary_object() check the pagemap first, so main-heap pointers never query or lock the secondary allocator.

Test plan

Run on macOS arm64 (524cafb):

  • Debug CMake (-fast + -check): ctest -j8 92/92 passed (including new secondary_chain and secondary_owns tests)
  • Release CMake (-fast + -check): ctest -j8 92/92 passed
  • Whole-tree clang-format 15.0.7 --dry-run -Werror clean

…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().
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant