• 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 "partition_alloc/partition_root.h"
6 
7 #include <cstring>
8 
9 #include "partition_alloc/partition_alloc_base/component_export.h"
10 #include "partition_alloc/partition_alloc_base/no_destructor.h"
11 
12 namespace partition_alloc::internal {
13 
14 namespace {
15 constexpr PartitionOptions kConfig{};
16 }  // namespace
17 
PA_COMPONENT_EXPORT(PARTITION_ALLOC)18 PA_COMPONENT_EXPORT(PARTITION_ALLOC)
19 PartitionRoot& PCScanMetadataAllocator() {
20   static internal::base::NoDestructor<PartitionRoot> allocator(kConfig);
21   return *allocator;
22 }
23 
24 // TODO(tasak): investigate whether PartitionAlloc tests really need this
25 // function or not. If we found no tests need, remove it.
ReinitPCScanMetadataAllocatorForTesting()26 void ReinitPCScanMetadataAllocatorForTesting() {
27   // First, purge memory owned by PCScanMetadataAllocator.
28   PCScanMetadataAllocator().PurgeMemory(PurgeFlags::kDecommitEmptySlotSpans |
29                                         PurgeFlags::kDiscardUnusedSystemPages);
30   // Then, reinit the allocator.
31   PCScanMetadataAllocator().ResetForTesting(true);  // IN-TEST
32   PCScanMetadataAllocator().Init(kConfig);
33 }
34 
35 }  // namespace partition_alloc::internal
36