mirror of
https://github.com/zeldaret/mm.git
synced 2026-05-23 23:05:08 -04:00
Docs Cleanup (#1153)
* sysheap * Gorons * Update goron comment * functions.h * Update src/boot_O2/system_heap.c Co-authored-by: engineer124 <47598039+engineer124@users.noreply.github.com> * add header * Fix header guards * Update data * Add malloc and free to header --------- Co-authored-by: engineer124 <47598039+engineer124@users.noreply.github.com>
This commit is contained in:
@@ -1,3 +1,10 @@
|
||||
/**
|
||||
* @file system_heap.c
|
||||
*
|
||||
* @note:
|
||||
* Only SystemHeap_Init() is used, and is essentially just a wrapper for SystemArena_Init().
|
||||
*
|
||||
*/
|
||||
#include "global.h"
|
||||
#include "system_malloc.h"
|
||||
|
||||
@@ -6,20 +13,20 @@ typedef void (*BlockFunc1)(void*, u32);
|
||||
typedef void (*BlockFunc8)(void*, u32, u32, u32, u32, u32, u32, u32, u32);
|
||||
|
||||
typedef struct InitFunc {
|
||||
uintptr_t nextOffset;
|
||||
void (*func)(void);
|
||||
} InitFunc;
|
||||
/* 0x0 */ uintptr_t nextOffset;
|
||||
/* 0x4 */ void (*func)(void);
|
||||
} InitFunc; // size = 0x8
|
||||
|
||||
void* sInitFuncs = NULL;
|
||||
|
||||
char sNew[] = { 0x00, 0x00, 0x00, 0x00 };
|
||||
char sNew[] = "";
|
||||
|
||||
char D_80097508[] = {
|
||||
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* SystemArena_MallocMin1(size_t size) {
|
||||
void* SystemHeap_Malloc(size_t size) {
|
||||
if (size == 0) {
|
||||
size = 1;
|
||||
}
|
||||
@@ -27,13 +34,13 @@ void* SystemArena_MallocMin1(size_t size) {
|
||||
return __osMalloc(&gSystemArena, size);
|
||||
}
|
||||
|
||||
void SystemArena_FreeNullCheck(void* ptr) {
|
||||
void SystemHeap_Free(void* ptr) {
|
||||
if (ptr != NULL) {
|
||||
__osFree(&gSystemArena, ptr);
|
||||
}
|
||||
}
|
||||
|
||||
void SystemArena_RunBlockFunc(void* blk, size_t nBlk, size_t blkSize, BlockFunc blockFunc) {
|
||||
void SystemHeap_RunBlockFunc(void* blk, size_t nBlk, size_t blkSize, BlockFunc blockFunc) {
|
||||
uintptr_t pos = blk;
|
||||
|
||||
for (; pos < (uintptr_t)blk + (nBlk * blkSize); pos += (blkSize & ~0)) {
|
||||
@@ -41,7 +48,7 @@ void SystemArena_RunBlockFunc(void* blk, size_t nBlk, size_t blkSize, BlockFunc
|
||||
}
|
||||
}
|
||||
|
||||
void SystemArena_RunBlockFunc1(void* blk, size_t nBlk, size_t blkSize, BlockFunc1 blockFunc) {
|
||||
void SystemHeap_RunBlockFunc1(void* blk, size_t nBlk, size_t blkSize, BlockFunc1 blockFunc) {
|
||||
uintptr_t pos = blk;
|
||||
|
||||
for (; pos < (uintptr_t)blk + (nBlk * blkSize); pos += (blkSize & ~0)) {
|
||||
@@ -49,9 +56,9 @@ void SystemArena_RunBlockFunc1(void* blk, size_t nBlk, size_t blkSize, BlockFunc
|
||||
}
|
||||
}
|
||||
|
||||
void* SystemArena_RunBlockFunc8(void* blk, size_t nBlk, size_t blkSize, BlockFunc8 blockFunc) {
|
||||
void* SystemHeap_RunBlockFunc8(void* blk, size_t nBlk, size_t blkSize, BlockFunc8 blockFunc) {
|
||||
if (blk == NULL) {
|
||||
blk = SystemArena_MallocMin1(nBlk * blkSize);
|
||||
blk = SystemHeap_Malloc(nBlk * blkSize);
|
||||
}
|
||||
|
||||
if (blk != NULL && blockFunc != NULL) {
|
||||
@@ -65,7 +72,7 @@ void* SystemArena_RunBlockFunc8(void* blk, size_t nBlk, size_t blkSize, BlockFun
|
||||
return blk;
|
||||
}
|
||||
|
||||
void SystemArena_RunBlockFunc1Reverse(void* blk, size_t nBlk, size_t blkSize, BlockFunc1 blockFunc, s32 shouldFree) {
|
||||
void SystemHeap_RunBlockFunc1Reverse(void* blk, size_t nBlk, size_t blkSize, BlockFunc1 blockFunc, s32 shouldFree) {
|
||||
uintptr_t pos;
|
||||
uintptr_t start;
|
||||
size_t maskedBlkSize;
|
||||
@@ -86,11 +93,11 @@ void SystemArena_RunBlockFunc1Reverse(void* blk, size_t nBlk, size_t blkSize, Bl
|
||||
}
|
||||
|
||||
if (shouldFree) {
|
||||
SystemArena_FreeNullCheck(blk);
|
||||
SystemHeap_Free(blk);
|
||||
}
|
||||
}
|
||||
|
||||
void SystemArena_RunInits(void) {
|
||||
void SystemHeap_RunInits(void) {
|
||||
InitFunc* initFunc = (InitFunc*)&sInitFuncs;
|
||||
u32 nextOffset = initFunc->nextOffset;
|
||||
InitFunc* prev = NULL;
|
||||
@@ -110,7 +117,7 @@ void SystemArena_RunInits(void) {
|
||||
sInitFuncs = prev;
|
||||
}
|
||||
|
||||
void SystemArena_Init(void* start, size_t size) {
|
||||
SystemArena_InitArena(start, size);
|
||||
SystemArena_RunInits();
|
||||
void SystemHeap_Init(void* start, size_t size) {
|
||||
SystemArena_Init(start, size);
|
||||
SystemHeap_RunInits();
|
||||
}
|
||||
@@ -38,7 +38,7 @@ u32 SystemArena_CheckArena(void) {
|
||||
return __osCheckArena(&gSystemArena);
|
||||
}
|
||||
|
||||
void SystemArena_InitArena(void* start, size_t size) {
|
||||
void SystemArena_Init(void* start, size_t size) {
|
||||
__osMallocInit(&gSystemArena, start, size);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user