diff options
author | Akira Akashi <rubenru09@aol.com> | 2021-08-30 23:08:09 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-08-30 23:08:09 +0100 |
commit | 30d5f531aff3e3e25f807b7711f9d80f03951610 (patch) | |
tree | d198edad36c4ec8674003187c69b941cdc4aa4ef /arm9/lib/libnns/src/NNS_FND_heapcommon.c | |
parent | 118a959ee77459bb3a663b182183b66499acb95e (diff) | |
parent | 6afd7bd12a7a7c5b9d3616dd843b7a8ef2df8f27 (diff) |
Merge branch 'master' into msgenc_refactor
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);
+}
|