diff options
author | Akira Akashi <rubenru09@aol.com> | 2021-08-30 23:07:56 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-08-30 23:07:56 +0100 |
commit | 6afd7bd12a7a7c5b9d3616dd843b7a8ef2df8f27 (patch) | |
tree | eee378a2b4e09ff5e46faae7f4880f76ab075a26 /arm9/lib/libnns/src/NNS_FND_heapcommon.c | |
parent | 7994935696dcf9d81888e2d9d991f4b6a3e00738 (diff) | |
parent | c17dcd24d24b9309ce2c1da1c709816afbea975b (diff) |
Merge pull request #452 from PikalaxALT/pikalax_work
NNS fnd
Diffstat (limited to 'arm9/lib/libnns/src/NNS_FND_heapcommon.c')
-rw-r--r-- | arm9/lib/libnns/src/NNS_FND_heapcommon.c | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/arm9/lib/libnns/src/NNS_FND_heapcommon.c b/arm9/lib/libnns/src/NNS_FND_heapcommon.c new file mode 100644 index 00000000..73646030 --- /dev/null +++ b/arm9/lib/libnns/src/NNS_FND_heapcommon.c @@ -0,0 +1,55 @@ +#include "nitro.h"
+#include "NNS_FND_heapcommon.h"
+#include "NNS_FND_list.h"
+
+BOOL sRootListInitialized;
+NNSFndList sRootList;
+
+ARM_FUNC void *NNS_FndGetNextListObject(NNSFndList *, void *);
+
+ARM_FUNC static NNSiFndHeapHead* FindContainHeap(NNSFndList * pList, const void * memBlock)
+{
+ NNSiFndHeapHead * pHead = NULL;
+
+ while ((pHead = NNS_FndGetNextListObject(pList, pHead)) != NULL)
+ {
+ if (pHead->heapStart <= memBlock && memBlock < pHead->heapEnd)
+ {
+ NNSiFndHeapHead * ret = FindContainHeap(&pHead->childList, memBlock);
+ if (ret == NULL)
+ ret = pHead;
+ return ret;
+ }
+ }
+ return NULL;
+}
+
+ARM_FUNC static NNSFndList* FindListContainHeap(const void * memBlock)
+{
+ NNSFndList* ret = &sRootList;
+ NNSiFndHeapHead* pHead = FindContainHeap(&sRootList, memBlock);
+ if (pHead != NULL)
+ ret = &pHead->childList;
+ return ret;
+}
+
+ARM_FUNC void NNSi_FndInitHeapHead(NNSiFndHeapHead *pHead, u32 signature, void* heapStart, void* heapEnd, u16 optionFlag)
+{
+ pHead->signature = signature;
+ pHead->heapStart = heapStart;
+ pHead->heapEnd = heapEnd;
+ pHead->attribute = 0;
+ SetOptForHeap(pHead, optionFlag);
+ NNS_FndInitList(&pHead->childList, 4);
+ if (!sRootListInitialized)
+ {
+ NNS_FndInitList(&sRootList, 4);
+ sRootListInitialized = TRUE;
+ }
+ NNS_FndAppendListObject(FindListContainHeap(pHead), pHead);
+}
+
+ARM_FUNC void NNSi_FndFinalizeHeap(NNSiFndHeapHead *pHead)
+{
+ NNS_FndRemoveListObject(FindListContainHeap(pHead), pHead);
+}
|