• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
5 #ifndef THIRD_PARTY_BASE_ALLOCATOR_PARTITION_ALLOCATOR_PAGE_ALLOCATOR_CONSTANTS_H_
6 #define THIRD_PARTY_BASE_ALLOCATOR_PARTITION_ALLOCATOR_PAGE_ALLOCATOR_CONSTANTS_H_
7 
8 #include <stddef.h>
9 
10 #include "build/build_config.h"
11 
12 namespace pdfium {
13 namespace base {
14 #if defined(OS_WIN) || defined(ARCH_CPU_PPC64)
15 static constexpr size_t kPageAllocationGranularityShift = 16;  // 64KB
16 #elif defined(_MIPS_ARCH_LOONGSON)
17 static constexpr size_t kPageAllocationGranularityShift = 14;  // 16KB
18 #else
19 static constexpr size_t kPageAllocationGranularityShift = 12;  // 4KB
20 #endif
21 static constexpr size_t kPageAllocationGranularity =
22     1 << kPageAllocationGranularityShift;
23 static constexpr size_t kPageAllocationGranularityOffsetMask =
24     kPageAllocationGranularity - 1;
25 static constexpr size_t kPageAllocationGranularityBaseMask =
26     ~kPageAllocationGranularityOffsetMask;
27 
28 #if defined(_MIPS_ARCH_LOONGSON)
29 static constexpr size_t kSystemPageSize = 16384;
30 #elif defined(ARCH_CPU_PPC64)
31 // Modern ppc64 systems support 4KB and 64KB page sizes.
32 // Since 64KB is the de-facto standard on the platform
33 // and binaries compiled for 64KB are likely to work on 4KB systems,
34 // 64KB is a good choice here.
35 static constexpr size_t kSystemPageSize = 65536;
36 #else
37 static constexpr size_t kSystemPageSize = 4096;
38 #endif
39 static constexpr size_t kSystemPageOffsetMask = kSystemPageSize - 1;
40 static_assert((kSystemPageSize & (kSystemPageSize - 1)) == 0,
41               "kSystemPageSize must be power of 2");
42 static constexpr size_t kSystemPageBaseMask = ~kSystemPageOffsetMask;
43 
44 static constexpr size_t kPageMetadataShift = 5;  // 32 bytes per partition page.
45 static constexpr size_t kPageMetadataSize = 1 << kPageMetadataShift;
46 
47 }  // namespace base
48 }  // namespace pdfium
49 
50 #endif  // THIRD_PARTY_BASE_ALLOCATOR_PARTITION_ALLOCATOR_PAGE_ALLOCATOR_CONSTANTS_H_
51