diff options
| author | Dragorn421 <Dragorn421@users.noreply.github.com> | 2024-11-08 02:27:19 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-11-07 17:27:19 -0800 |
| commit | fcc5cf828ded5d362b2e63a8868374a50df405ed (patch) | |
| tree | 530d7d6d8690599593f6588b04d10441e364b5c7 /src/boot/O2/system_heap.c | |
| parent | 9cd9099a0431b369be39f111bf57051f544bead3 (diff) | |
libu64 (#1705)
* libu64
* libu64 -O2
* Add libu64.md
Diffstat (limited to 'src/boot/O2/system_heap.c')
| -rw-r--r-- | src/boot/O2/system_heap.c | 123 |
1 files changed, 0 insertions, 123 deletions
diff --git a/src/boot/O2/system_heap.c b/src/boot/O2/system_heap.c deleted file mode 100644 index 7ad21b6ae..000000000 --- a/src/boot/O2/system_heap.c +++ /dev/null @@ -1,123 +0,0 @@ -/** - * @file system_heap.c - * - * @note: - * Only SystemHeap_Init() is used, and is essentially just a wrapper for MallocInit(). - * - */ -#include "global.h" -#include "libc64/malloc.h" - -typedef void (*BlockFunc)(uintptr_t); -typedef void (*BlockFunc1)(uintptr_t, u32); -typedef void (*BlockFunc8)(uintptr_t, u32, u32, u32, u32, u32, u32, u32, u32); - -typedef struct InitFunc { - /* 0x0 */ uintptr_t nextOffset; - /* 0x4 */ void (*func)(void); -} InitFunc; // size = 0x8 - -void* sInitFuncs = NULL; - -char sNew[] = ""; - -UNK_TYPE1 D_80097508[] = { - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7F, 0x80, 0x00, 0x00, - 0xFF, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, -}; - -void* SystemHeap_Malloc(size_t size) { - if (size == 0) { - size = 1; - } - - return __osMalloc(&malloc_arena, size); -} - -void SystemHeap_Free(void* ptr) { - if (ptr != NULL) { - __osFree(&malloc_arena, ptr); - } -} - -void SystemHeap_RunBlockFunc(void* blk, size_t nBlk, size_t blkSize, BlockFunc blockFunc) { - uintptr_t pos = (uintptr_t)blk; - - for (; pos < (uintptr_t)blk + (nBlk * blkSize); pos += (blkSize & ~0)) { - blockFunc(pos); - } -} - -void SystemHeap_RunBlockFunc1(void* blk, size_t nBlk, size_t blkSize, BlockFunc1 blockFunc) { - uintptr_t pos = (uintptr_t)blk; - - for (; pos < (uintptr_t)blk + (nBlk * blkSize); pos += (blkSize & ~0)) { - blockFunc(pos, 2); - } -} - -void* SystemHeap_RunBlockFunc8(void* blk, size_t nBlk, size_t blkSize, BlockFunc8 blockFunc) { - if (blk == NULL) { - blk = SystemHeap_Malloc(nBlk * blkSize); - } - - if ((blk != NULL) && (blockFunc != NULL)) { - uintptr_t pos = (uintptr_t)blk; - - for (; pos < (uintptr_t)blk + (nBlk * blkSize); pos += (blkSize & ~0)) { - blockFunc(pos, 0, 0, 0, 0, 0, 0, 0, 0); - } - } - - return blk; -} - -void SystemHeap_RunBlockFunc1Reverse(void* blk, size_t nBlk, size_t blkSize, BlockFunc1 blockFunc, s32 shouldFree) { - uintptr_t pos; - uintptr_t start; - size_t maskedBlkSize; - - if (blk == NULL) { - return; - } - - if (blockFunc != NULL) { - start = (uintptr_t)blk; - maskedBlkSize = (blkSize & ~0); - pos = (uintptr_t)start + (nBlk * blkSize); - - while (pos > start) { - pos -= maskedBlkSize; - blockFunc(pos, 2); - } - } - - if (shouldFree) { - SystemHeap_Free(blk); - } -} - -void SystemHeap_RunInits(void) { - InitFunc* initFunc = (InitFunc*)&sInitFuncs; - u32 nextOffset = initFunc->nextOffset; - InitFunc* prev = NULL; - - while (nextOffset != 0) { - initFunc = (InitFunc*)((uintptr_t)initFunc + nextOffset); - - if (initFunc->func != NULL) { - (*initFunc->func)(); - } - - nextOffset = initFunc->nextOffset; - initFunc->nextOffset = (uintptr_t)prev; - prev = initFunc; - } - - sInitFuncs = prev; -} - -void SystemHeap_Init(void* start, size_t size) { - MallocInit(start, size); - SystemHeap_RunInits(); -} |
