Backed out changeset bd51857879db (bug 1862957) for causing WakeLock related failures...
[gecko.git] / xpcom / base / MemoryInfo.h
blobd122f6d3775faff046e33a7906c098eadf467daf
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef mozilla_MemoryInfo_h
8 #define mozilla_MemoryInfo_h
10 #include <cstddef>
11 #include <cstdint>
12 #include "mozilla/Attributes.h"
13 #include "mozilla/EnumSet.h"
14 /**
15 * MemoryInfo is a helper class which describes the attributes and sizes of a
16 * particular region of VM memory on Windows. It roughtly corresponds to the
17 * values in a MEMORY_BASIC_INFORMATION struct, summed over an entire region or
18 * memory.
21 namespace mozilla {
23 class MemoryInfo final {
24 public:
25 enum class Perm : uint8_t {
26 Read,
27 Write,
28 Execute,
29 CopyOnWrite,
30 Guard,
31 NoCache,
32 WriteCombine,
34 enum class PageType : uint8_t {
35 Image,
36 Mapped,
37 Private,
40 using PermSet = EnumSet<Perm>;
41 using PageTypeSet = EnumSet<PageType>;
43 MemoryInfo() = default;
44 MOZ_IMPLICIT MemoryInfo(const MemoryInfo&) = default;
46 uintptr_t Start() const { return mStart; }
47 uintptr_t End() const { return mEnd; }
49 PageTypeSet Type() const { return mType; }
50 PermSet Perms() const { return mPerms; }
52 size_t Reserved() const { return mReserved; }
53 size_t Committed() const { return mCommitted; }
54 size_t Free() const { return mFree; }
55 size_t Size() const { return mSize; }
57 // Returns a MemoryInfo object containing the sums of all region sizes,
58 // divided into Reserved, Committed, and Free, depending on their State
59 // properties.
61 // The entire range of aSize bytes starting at aPtr must correspond to a
62 // single allocation. This restriction is enforced in debug builds.
63 static MemoryInfo Get(const void* aPtr, size_t aSize);
65 private:
66 uintptr_t mStart = 0;
67 uintptr_t mEnd = 0;
69 size_t mReserved = 0;
70 size_t mCommitted = 0;
71 size_t mFree = 0;
72 size_t mSize = 0;
74 PageTypeSet mType{};
76 PermSet mPerms{};
79 } // namespace mozilla
81 #endif // mozilla_MemoryInfo_h