A reimplementation of Mario Kart Wii's physics engine in C++
Loading...
Searching...
No Matches
HeapCommon.hh
1#pragma once
2
3#include "abstract/memory/List.hh"
4
5#include <egg/core/BitFlag.hh>
6
7#include <array>
8
9namespace Kinoko {
10
11namespace Host {
12
13class Context;
14
15} // namespace Host
16
17namespace Abstract::Memory {
18
22 friend class Host::Context;
23
24public:
25 enum class FillType {
26 NoUse = 0,
27 Alloc = 1,
28 Free = 2,
29 };
30
31 enum class eOptFlag {
32 ZeroFillAlloc = 0,
33 DebugFillAlloc = 1,
34 };
36
37 [[nodiscard]] MEMList &getChildList();
38 [[nodiscard]] void *getHeapStart();
39 [[nodiscard]] void *getHeapEnd();
40
41 [[nodiscard]] static MEMList &getRootList();
42 [[nodiscard]] static u32 getFillVal(FillType type);
43 [[nodiscard]] static MEMiHeapHead *findContainHeap(const void *block);
44
45 [[nodiscard]] static constexpr u16 getLinkOffset() {
46 return offsetof(MEMiHeapHead, m_link);
47 }
48
49protected:
50 MEMiHeapHead(u32 signature, void *heapStart, void *heapEnd, const OptFlag &opt);
52
53 void fillNoUseMemory(void *address, u32 size);
54 void fillAllocMemory(void *address, u32 size);
55 void fillFreeMemory(void *address, u32 size);
56
57private:
58 [[nodiscard]] static MEMiHeapHead *findContainHeap(MEMList *list, const void *block);
59 [[nodiscard]] MEMList &findListContainHeap() const;
60
61 u32 m_signature;
62 OptFlag m_optFlag;
63 MEMLink m_link;
64 MEMList m_childList;
65 void *m_heapStart;
66 void *m_heapEnd;
67
68 static MEMList s_rootList;
69 static constexpr std::array<u32, 3> s_fillVals = {{
70 0xC3C3C3C3,
71 0xF3F3F3F3,
72 0xD3D3D3D3,
73 }};
74};
75
76} // namespace Abstract::Memory
77
78} // namespace Kinoko
A low-level representation of a memory heap for managing dynamic memory allocation....
Definition HeapCommon.hh:21
Contexts can be used to restore a previous memory state for the current session.
Definition Context.hh:71
Intrusive doubly-linked list. Links are placed within the corresponding object.
Definition List.hh:14
Wrapper around an integral type with an enum corresponding to its bits.
Definition BitFlag.hh:23