summaryrefslogtreecommitdiff
path: root/third_party/base/allocator/partition_allocator/page_allocator_constants.h
blob: 945273b1f25aee4f6c22a2b1c2ca289d69daa3b7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
// Copyright (c) 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef THIRD_PARTY_BASE_ALLOCATOR_PARTITION_ALLOCATOR_PAGE_ALLOCATOR_CONSTANTS_H_
#define THIRD_PARTY_BASE_ALLOCATOR_PARTITION_ALLOCATOR_PAGE_ALLOCATOR_CONSTANTS_H_

#include <stddef.h>

#include "build/build_config.h"

namespace pdfium {
namespace base {
#if defined(OS_WIN)
static constexpr size_t kPageAllocationGranularityShift = 16;  // 64KB
#elif defined(_MIPS_ARCH_LOONGSON)
static constexpr size_t kPageAllocationGranularityShift = 14;  // 16KB
#else
static constexpr size_t kPageAllocationGranularityShift = 12;  // 4KB
#endif
static constexpr size_t kPageAllocationGranularity =
    1 << kPageAllocationGranularityShift;
static constexpr size_t kPageAllocationGranularityOffsetMask =
    kPageAllocationGranularity - 1;
static constexpr size_t kPageAllocationGranularityBaseMask =
    ~kPageAllocationGranularityOffsetMask;

#if defined(_MIPS_ARCH_LOONGSON)
static constexpr size_t kSystemPageSize = 16384;
#else
static constexpr size_t kSystemPageSize = 4096;
#endif
static constexpr size_t kSystemPageOffsetMask = kSystemPageSize - 1;
static_assert((kSystemPageSize & (kSystemPageSize - 1)) == 0,
              "kSystemPageSize must be power of 2");
static constexpr size_t kSystemPageBaseMask = ~kSystemPageOffsetMask;

static constexpr size_t kPageMetadataShift = 5;  // 32 bytes per partition page.
static constexpr size_t kPageMetadataSize = 1 << kPageMetadataShift;

}  // namespace base
}  // namespace pdfium

#endif  // THIRD_PARTY_BASE_ALLOCATOR_PARTITION_ALLOCATOR_PAGE_ALLOCATOR_CONSTANTS_H_