summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLéo Lam <leo@leolam.fr>2020-09-04 22:38:06 +0200
committerLéo Lam <leo@leolam.fr>2020-09-04 22:38:24 +0200
commit977ff07c85a0dd4db08f4e8b60a991b715f5a2af (patch)
tree91ef3bcca927e684f0fbba98c3d1a15aa9192de2 /src
parent3d371999a4a7223637aaf6bd4428a046574609d8 (diff)
ksys: Implement more heap utilities
Diffstat (limited to 'src')
-rw-r--r--src/KingSystem/Utils/HeapUtil.cpp42
-rw-r--r--src/KingSystem/Utils/HeapUtil.h6
2 files changed, 48 insertions, 0 deletions
diff --git a/src/KingSystem/Utils/HeapUtil.cpp b/src/KingSystem/Utils/HeapUtil.cpp
index fb06c48f..30118e44 100644
--- a/src/KingSystem/Utils/HeapUtil.cpp
+++ b/src/KingSystem/Utils/HeapUtil.cpp
@@ -4,6 +4,26 @@
namespace ksys::util {
+// Name, layout and purpose unknown; this is stubbed in release builds
+class DebugHeapHolder {
+ SEAD_SINGLETON_DISPOSER(DebugHeapHolder)
+public:
+ virtual ~DebugHeapHolder() = default;
+ virtual sead::Heap* getHeap() { return nullptr; }
+};
+
+SEAD_SINGLETON_DISPOSER_IMPL(DebugHeapHolder)
+
+// Name, layout and purpose unknown; this is stubbed in release builds
+class DebugHeapHolder2 {
+ SEAD_SINGLETON_DISPOSER(DebugHeapHolder2)
+public:
+ virtual ~DebugHeapHolder2() = default;
+ virtual sead::Heap* getHeap() { return nullptr; }
+};
+
+SEAD_SINGLETON_DISPOSER_IMPL(DebugHeapHolder2)
+
sead::Heap* getHeapOrCurrentHeap(sead::Heap* heap) {
if (heap)
return heap;
@@ -11,7 +31,29 @@ sead::Heap* getHeapOrCurrentHeap(sead::Heap* heap) {
if (!sead::ThreadMgr::instance())
return nullptr;
+ return getCurrentHeap();
+}
+
+void adjustHeapOrCurrentHeap(sead::Heap* heap) {
+ if (!heap)
+ heap = getCurrentHeap();
+ heap->adjust();
+}
+
+sead::Heap* getCurrentHeap() {
return sead::HeapMgr::instance()->getCurrentHeap();
}
+sead::Heap* getDebugHeap() {
+ if (!DebugHeapHolder::instance())
+ return nullptr;
+ return DebugHeapHolder::instance()->getHeap();
+}
+
+sead::Heap* getDebugHeap2() {
+ if (DebugHeapHolder2::instance())
+ return DebugHeapHolder2::instance()->getHeap();
+ return getDebugHeap();
+}
+
} // namespace ksys::util
diff --git a/src/KingSystem/Utils/HeapUtil.h b/src/KingSystem/Utils/HeapUtil.h
index 0e6be692..599791ef 100644
--- a/src/KingSystem/Utils/HeapUtil.h
+++ b/src/KingSystem/Utils/HeapUtil.h
@@ -11,4 +11,10 @@ namespace ksys::util {
/// Returns the specified heap if it is not null. Otherwise, this returns the current heap.
sead::Heap* getHeapOrCurrentHeap(sead::Heap* heap);
+void adjustHeapOrCurrentHeap(sead::Heap* heap);
+
+sead::Heap* getCurrentHeap();
+sead::Heap* getDebugHeap();
+sead::Heap* getDebugHeap2();
+
} // namespace ksys::util