• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2021 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 "base/allocator/partition_allocator/partition_root.h"
6 
7 #include <cstring>
8 
9 #include "base/allocator/partition_allocator/partition_alloc_base/component_export.h"
10 #include "base/allocator/partition_allocator/partition_alloc_base/no_destructor.h"
11 
12 namespace partition_alloc::internal {
13 
14 namespace {
15 constexpr PartitionOptions kConfig{
16     PartitionOptions::AlignedAlloc::kDisallowed,
17     PartitionOptions::ThreadCache::kDisabled,
18     PartitionOptions::Quarantine::kDisallowed,
19     PartitionOptions::Cookie::kAllowed,
20     PartitionOptions::BackupRefPtr::kDisabled,
21     PartitionOptions::BackupRefPtrZapping::kDisabled,
22     PartitionOptions::UseConfigurablePool::kNo,
23 };
24 }  // namespace
25 
PA_COMPONENT_EXPORT(PARTITION_ALLOC)26 PA_COMPONENT_EXPORT(PARTITION_ALLOC)
27 ThreadSafePartitionRoot& PCScanMetadataAllocator() {
28   static internal::base::NoDestructor<ThreadSafePartitionRoot> allocator(
29       kConfig);
30   return *allocator;
31 }
32 
33 // TODO(tasak): investigate whether PartitionAlloc tests really need this
34 // function or not. If we found no tests need, remove it.
ReinitPCScanMetadataAllocatorForTesting()35 void ReinitPCScanMetadataAllocatorForTesting() {
36   // First, purge memory owned by PCScanMetadataAllocator.
37   PCScanMetadataAllocator().PurgeMemory(PurgeFlags::kDecommitEmptySlotSpans |
38                                         PurgeFlags::kDiscardUnusedSystemPages);
39   // Then, reinit the allocator.
40   PCScanMetadataAllocator().ResetForTesting(true);  // IN-TEST
41   PCScanMetadataAllocator().Init(kConfig);
42 }
43 
44 }  // namespace partition_alloc::internal
45