summaryrefslogtreecommitdiffstats
path: root/xpcom/base/MemoryInfo.h
blob: d122f6d3775faff046e33a7906c098eadf467daf (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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef mozilla_MemoryInfo_h
#define mozilla_MemoryInfo_h

#include <cstddef>
#include <cstdint>
#include "mozilla/Attributes.h"
#include "mozilla/EnumSet.h"
/**
 * MemoryInfo is a helper class which describes the attributes and sizes of a
 * particular region of VM memory on Windows. It roughtly corresponds to the
 * values in a MEMORY_BASIC_INFORMATION struct, summed over an entire region or
 * memory.
 */

namespace mozilla {

class MemoryInfo final {
 public:
  enum class Perm : uint8_t {
    Read,
    Write,
    Execute,
    CopyOnWrite,
    Guard,
    NoCache,
    WriteCombine,
  };
  enum class PageType : uint8_t {
    Image,
    Mapped,
    Private,
  };

  using PermSet = EnumSet<Perm>;
  using PageTypeSet = EnumSet<PageType>;

  MemoryInfo() = default;
  MOZ_IMPLICIT MemoryInfo(const MemoryInfo&) = default;

  uintptr_t Start() const { return mStart; }
  uintptr_t End() const { return mEnd; }

  PageTypeSet Type() const { return mType; }
  PermSet Perms() const { return mPerms; }

  size_t Reserved() const { return mReserved; }
  size_t Committed() const { return mCommitted; }
  size_t Free() const { return mFree; }
  size_t Size() const { return mSize; }

  // Returns a MemoryInfo object containing the sums of all region sizes,
  // divided into Reserved, Committed, and Free, depending on their State
  // properties.
  //
  // The entire range of aSize bytes starting at aPtr must correspond to a
  // single allocation. This restriction is enforced in debug builds.
  static MemoryInfo Get(const void* aPtr, size_t aSize);

 private:
  uintptr_t mStart = 0;
  uintptr_t mEnd = 0;

  size_t mReserved = 0;
  size_t mCommitted = 0;
  size_t mFree = 0;
  size_t mSize = 0;

  PageTypeSet mType{};

  PermSet mPerms{};
};

}  // namespace mozilla

#endif  // mozilla_MemoryInfo_h