partition_direct_map_extent.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. // Copyright (c) 2018 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #ifndef BASE_ALLOCATOR_PARTITION_ALLOCATOR_PARTITION_DIRECT_MAP_EXTENT_H_
  5. #define BASE_ALLOCATOR_PARTITION_ALLOCATOR_PARTITION_DIRECT_MAP_EXTENT_H_
  6. #include "base/allocator/partition_allocator/partition_alloc_base/compiler_specific.h"
  7. #include "base/allocator/partition_allocator/partition_alloc_check.h"
  8. #include "base/allocator/partition_allocator/partition_bucket.h"
  9. #include "base/allocator/partition_allocator/partition_page.h"
  10. namespace partition_alloc::internal {
  11. template <bool thread_safe>
  12. struct PartitionDirectMapExtent {
  13. PartitionDirectMapExtent<thread_safe>* next_extent;
  14. PartitionDirectMapExtent<thread_safe>* prev_extent;
  15. PartitionBucket<thread_safe>* bucket;
  16. // Size of the entire reservation, including guard pages, meta-data,
  17. // padding for alignment before allocation, and padding for granularity at the
  18. // end of the allocation.
  19. size_t reservation_size;
  20. // Padding between the first partition page (guard pages + meta-data) and
  21. // the allocation.
  22. size_t padding_for_alignment;
  23. PA_ALWAYS_INLINE static PartitionDirectMapExtent<thread_safe>* FromSlotSpan(
  24. SlotSpanMetadata<thread_safe>* slot_span);
  25. };
  26. // Metadata page for direct-mapped allocations.
  27. template <bool thread_safe>
  28. struct PartitionDirectMapMetadata {
  29. // |page| and |subsequent_page| are needed to match the layout of normal
  30. // buckets (specifically, of single-slot slot spans), with the caveat that
  31. // only the first subsequent page is needed (for SubsequentPageMetadata) and
  32. // others aren't used for direct map.
  33. PartitionPage<thread_safe> page;
  34. PartitionPage<thread_safe> subsequent_page;
  35. // The following fields are metadata specific to direct map allocations. All
  36. // these fields will easily fit into the precalculated metadata region,
  37. // because a direct map allocation starts no further than half way through the
  38. // super page.
  39. PartitionBucket<thread_safe> bucket;
  40. PartitionDirectMapExtent<thread_safe> direct_map_extent;
  41. PA_ALWAYS_INLINE static PartitionDirectMapMetadata<thread_safe>* FromSlotSpan(
  42. SlotSpanMetadata<thread_safe>* slot_span);
  43. };
  44. template <bool thread_safe>
  45. PA_ALWAYS_INLINE PartitionDirectMapMetadata<thread_safe>*
  46. PartitionDirectMapMetadata<thread_safe>::FromSlotSpan(
  47. SlotSpanMetadata<thread_safe>* slot_span) {
  48. PA_DCHECK(slot_span->bucket->is_direct_mapped());
  49. // |*slot_span| is the first field of |PartitionDirectMapMetadata|, just cast.
  50. auto* metadata =
  51. reinterpret_cast<PartitionDirectMapMetadata<thread_safe>*>(slot_span);
  52. PA_DCHECK(&metadata->page.slot_span_metadata == slot_span);
  53. return metadata;
  54. }
  55. template <bool thread_safe>
  56. PA_ALWAYS_INLINE PartitionDirectMapExtent<thread_safe>*
  57. PartitionDirectMapExtent<thread_safe>::FromSlotSpan(
  58. SlotSpanMetadata<thread_safe>* slot_span) {
  59. PA_DCHECK(slot_span->bucket->is_direct_mapped());
  60. return &PartitionDirectMapMetadata<thread_safe>::FromSlotSpan(slot_span)
  61. ->direct_map_extent;
  62. }
  63. } // namespace partition_alloc::internal
  64. #endif // BASE_ALLOCATOR_PARTITION_ALLOCATOR_PARTITION_DIRECT_MAP_EXTENT_H_