diff options
| author | cadmic <cadmic24@gmail.com> | 2024-02-02 12:01:49 -0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-02-02 15:01:49 -0500 |
| commit | 8db76a27dab8b1b6423776b6d91d78269b03f6d5 (patch) | |
| tree | 01402d187979c2a4227df774bfbda1e653ce9549 /src/code/system_malloc.c | |
| parent | 0444a6f0949f8ddb3426e55d3b83b7a5302a15d0 (diff) | |
Match retail system_malloc.c and z_malloc.c (#1683)
* Match system_malloc.c and z_malloc.c
* Rename CHECK_POINTER
Diffstat (limited to 'src/code/system_malloc.c')
| -rw-r--r-- | src/code/system_malloc.c | 37 |
1 files changed, 29 insertions, 8 deletions
diff --git a/src/code/system_malloc.c b/src/code/system_malloc.c index af1815eaf..74e69ed46 100644 --- a/src/code/system_malloc.c +++ b/src/code/system_malloc.c @@ -4,9 +4,11 @@ #define LOG_SEVERITY_ERROR 2 #define LOG_SEVERITY_VERBOSE 3 -s32 gSystemArenaLogSeverity = LOG_SEVERITY_NOLOG; Arena gSystemArena; +#if OOT_DEBUG +s32 gSystemArenaLogSeverity = LOG_SEVERITY_NOLOG; + void SystemArena_CheckPointer(void* ptr, u32 size, const char* name, const char* action) { if (ptr == NULL) { if (gSystemArenaLogSeverity >= LOG_SEVERITY_ERROR) { @@ -21,53 +23,66 @@ void SystemArena_CheckPointer(void* ptr, u32 size, const char* name, const char* } } +#define SYSTEM_ARENA_CHECK_POINTER(ptr, size, name, action) SystemArena_CheckPointer(ptr, size, name, action) +#else +#define SYSTEM_ARENA_CHECK_POINTER(ptr, size, name, action) (void)0 +#endif + void* SystemArena_Malloc(u32 size) { void* ptr = __osMalloc(&gSystemArena, size); - SystemArena_CheckPointer(ptr, size, "malloc", "確保"); // "Secure" + SYSTEM_ARENA_CHECK_POINTER(ptr, size, "malloc", "確保"); // "Secure" return ptr; } +#if OOT_DEBUG void* SystemArena_MallocDebug(u32 size, const char* file, s32 line) { void* ptr = __osMallocDebug(&gSystemArena, size, file, line); - SystemArena_CheckPointer(ptr, size, "malloc_DEBUG", "確保"); // "Secure" + SYSTEM_ARENA_CHECK_POINTER(ptr, size, "malloc_DEBUG", "確保"); // "Secure" return ptr; } +#endif void* SystemArena_MallocR(u32 size) { void* ptr = __osMallocR(&gSystemArena, size); - SystemArena_CheckPointer(ptr, size, "malloc_r", "確保"); // "Secure" + SYSTEM_ARENA_CHECK_POINTER(ptr, size, "malloc_r", "確保"); // "Secure" return ptr; } +#if OOT_DEBUG void* SystemArena_MallocRDebug(u32 size, const char* file, s32 line) { void* ptr = __osMallocRDebug(&gSystemArena, size, file, line); - SystemArena_CheckPointer(ptr, size, "malloc_r_DEBUG", "確保"); // "Secure" + SYSTEM_ARENA_CHECK_POINTER(ptr, size, "malloc_r_DEBUG", "確保"); // "Secure" return ptr; } +#endif void* SystemArena_Realloc(void* ptr, u32 newSize) { ptr = __osRealloc(&gSystemArena, ptr, newSize); - SystemArena_CheckPointer(ptr, newSize, "realloc", "再確保"); // "Re-securing" + SYSTEM_ARENA_CHECK_POINTER(ptr, newSize, "realloc", "再確保"); // "Re-securing" return ptr; } +#if OOT_DEBUG void* SystemArena_ReallocDebug(void* ptr, u32 newSize, const char* file, s32 line) { ptr = __osReallocDebug(&gSystemArena, ptr, newSize, file, line); - SystemArena_CheckPointer(ptr, newSize, "realloc_DEBUG", "再確保"); // "Re-securing" + SYSTEM_ARENA_CHECK_POINTER(ptr, newSize, "realloc_DEBUG", "再確保"); // "Re-securing" return ptr; } +#endif void SystemArena_Free(void* ptr) { __osFree(&gSystemArena, ptr); } +#if OOT_DEBUG void SystemArena_FreeDebug(void* ptr, const char* file, s32 line) { __osFreeDebug(&gSystemArena, ptr, file, line); } +#endif void* SystemArena_Calloc(u32 num, u32 size) { void* ret; @@ -78,14 +93,16 @@ void* SystemArena_Calloc(u32 num, u32 size) { bzero(ret, n); } - SystemArena_CheckPointer(ret, n, "calloc", "確保"); + SYSTEM_ARENA_CHECK_POINTER(ret, n, "calloc", "確保"); return ret; } +#if OOT_DEBUG void SystemArena_Display(void) { PRINTF("システムヒープ表示\n"); // "System heap display" __osDisplayArena(&gSystemArena); } +#endif void SystemArena_GetSizes(u32* outMaxFree, u32* outFree, u32* outAlloc) { ArenaImpl_GetSizes(&gSystemArena, outMaxFree, outFree, outAlloc); @@ -96,12 +113,16 @@ void SystemArena_Check(void) { } void SystemArena_Init(void* start, u32 size) { +#if OOT_DEBUG gSystemArenaLogSeverity = LOG_SEVERITY_NOLOG; +#endif __osMallocInit(&gSystemArena, start, size); } void SystemArena_Cleanup(void) { +#if OOT_DEBUG gSystemArenaLogSeverity = LOG_SEVERITY_NOLOG; +#endif __osMallocCleanup(&gSystemArena); } |
