1 // Copyright 2024 The Chromium Authors 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #include "partition_alloc/internal_allocator.h" 6 7 namespace partition_alloc::internal { PA_COMPONENT_EXPORT(PARTITION_ALLOC)8PA_COMPONENT_EXPORT(PARTITION_ALLOC) 9 PartitionRoot& InternalAllocatorRoot() { 10 static internal::base::NoDestructor<PartitionRoot> allocator([]() { 11 // Disable features using the internal root to avoid reentrancy issue. 12 PartitionOptions opts; 13 opts.thread_cache = PartitionOptions::kDisabled; 14 opts.scheduler_loop_quarantine = PartitionOptions::kDisabled; 15 return opts; 16 }()); 17 18 return *allocator; 19 } 20 21 // static operator new(size_t count)22void* InternalPartitionAllocated::operator new(size_t count) { 23 return InternalAllocatorRoot().Alloc<AllocFlags::kNoHooks>(count); 24 } 25 // static operator new(size_t count,std::align_val_t alignment)26void* InternalPartitionAllocated::operator new(size_t count, 27 std::align_val_t alignment) { 28 return InternalAllocatorRoot().AlignedAlloc<AllocFlags::kNoHooks>( 29 static_cast<size_t>(alignment), count); 30 } 31 // static operator delete(void * ptr)32void InternalPartitionAllocated::operator delete(void* ptr) { 33 InternalAllocatorRoot().Free<FreeFlags::kNoHooks>(ptr); 34 } 35 // static operator delete(void * ptr,std::align_val_t)36void InternalPartitionAllocated::operator delete(void* ptr, std::align_val_t) { 37 InternalAllocatorRoot().Free<FreeFlags::kNoHooks>(ptr); 38 } 39 40 // A deleter for `std::unique_ptr<T>`. operator ()(void * ptr) const41void InternalPartitionDeleter::operator()(void* ptr) const { 42 InternalAllocatorRoot().Free<FreeFlags::kNoHooks>(ptr); 43 } 44 } // namespace partition_alloc::internal 45