1
0
Fork 0
mirror of https://github.com/zeldaret/oot.git synced 2024-12-02 15:55:59 +00:00
oot/src/code/debug_malloc.c

112 lines
3.2 KiB
C
Raw Normal View History

#include "global.h"
2020-03-17 04:31:30 +00:00
2020-03-22 21:19:43 +00:00
#define LOG_SEVERITY_NOLOG 0
#define LOG_SEVERITY_ERROR 2
#define LOG_SEVERITY_VERBOSE 3
2020-03-17 04:31:30 +00:00
s32 gDebugArenaLogSeverity = LOG_SEVERITY_ERROR;
Arena sDebugArena;
2020-03-22 21:19:43 +00:00
void DebugArena_CheckPointer(void* ptr, u32 size, const char* name, const char* action) {
if (ptr == NULL) {
2020-03-22 21:19:43 +00:00
if (gDebugArenaLogSeverity >= LOG_SEVERITY_ERROR) {
// "%s: %u bytes %s failed\n"
2020-03-17 04:31:30 +00:00
osSyncPrintf("%s: %u バイトの%sに失敗しました\n", name, size, action);
2020-03-22 21:19:43 +00:00
__osDisplayArena(&sDebugArena);
2020-03-17 04:31:30 +00:00
return;
}
2020-03-22 21:19:43 +00:00
} else if (gDebugArenaLogSeverity >= LOG_SEVERITY_VERBOSE) {
// "%s: %u bytes %s succeeded\n"
2020-03-17 04:31:30 +00:00
osSyncPrintf("%s: %u バイトの%sに成功しました\n", name, size, action);
}
}
2020-03-22 21:19:43 +00:00
void* DebugArena_Malloc(u32 size) {
void* ptr = __osMalloc(&sDebugArena, size);
DebugArena_CheckPointer(ptr, size, "debug_malloc", "確保"); // "Secure"
2020-03-17 04:31:30 +00:00
return ptr;
}
2020-03-22 21:19:43 +00:00
void* DebugArena_MallocDebug(u32 size, const char* file, s32 line) {
void* ptr = __osMallocDebug(&sDebugArena, size, file, line);
DebugArena_CheckPointer(ptr, size, "debug_malloc_DEBUG", "確保"); // "Secure"
2020-03-17 04:31:30 +00:00
return ptr;
}
2020-03-22 21:19:43 +00:00
void* DebugArena_MallocR(u32 size) {
void* ptr = __osMallocR(&sDebugArena, size);
DebugArena_CheckPointer(ptr, size, "debug_malloc_r", "確保"); // "Secure"
2020-03-17 04:31:30 +00:00
return ptr;
}
2020-03-22 21:19:43 +00:00
void* DebugArena_MallocRDebug(u32 size, const char* file, s32 line) {
void* ptr = __osMallocRDebug(&sDebugArena, size, file, line);
DebugArena_CheckPointer(ptr, size, "debug_malloc_r_DEBUG", "確保"); // "Secure"
2020-03-17 04:31:30 +00:00
return ptr;
}
2020-03-22 21:19:43 +00:00
void* DebugArena_Realloc(void* ptr, u32 newSize) {
2020-03-17 04:31:30 +00:00
ptr = __osRealloc(&sDebugArena, ptr, newSize);
DebugArena_CheckPointer(ptr, newSize, "debug_realloc", "再確保"); // "Re-securing"
2020-03-17 04:31:30 +00:00
return ptr;
}
2020-03-22 21:19:43 +00:00
void* DebugArena_ReallocDebug(void* ptr, u32 newSize, const char* file, s32 line) {
2020-03-17 04:31:30 +00:00
ptr = __osReallocDebug(&sDebugArena, ptr, newSize, file, line);
DebugArena_CheckPointer(ptr, newSize, "debug_realloc_DEBUG", "再確保"); // "Re-securing"
2020-03-17 04:31:30 +00:00
return ptr;
}
2020-03-22 21:19:43 +00:00
void DebugArena_Free(void* ptr) {
2020-03-17 04:31:30 +00:00
__osFree(&sDebugArena, ptr);
}
2020-03-22 21:19:43 +00:00
void DebugArena_FreeDebug(void* ptr, const char* file, s32 line) {
2020-03-17 04:31:30 +00:00
__osFreeDebug(&sDebugArena, ptr, file, line);
}
2020-03-22 21:19:43 +00:00
void* DebugArena_Calloc(u32 num, u32 size) {
2020-03-17 04:31:30 +00:00
void* ret;
u32 n = num * size;
2020-03-22 21:19:43 +00:00
2020-03-17 04:31:30 +00:00
ret = __osMalloc(&sDebugArena, n);
if (ret != NULL) {
2020-03-17 04:31:30 +00:00
bzero(ret, n);
2020-03-22 21:19:43 +00:00
}
2020-03-17 04:31:30 +00:00
DebugArena_CheckPointer(ret, n, "debug_calloc", "確保");
return ret;
}
void DebugArena_Display(void) {
Fix/cleanup/rephrase miscellaneous stuff (#983) * Add parens around params usage in VEC_SET macro * Remove unnecessary space character in a xml * Use defines instead of magic values in head/tail magic comments * Use `OS_USEC_TO_CYCLES` to make a time look better in `Graph_TaskSet00` * `0x25800` -> `sizeof(u16[SCREEN_HEIGHT][SCREEN_WIDTH])` * `0x803DA800` -> `0x80400000 - frame buffer size` * Use `OS_VI_` defines instead of hex * Add empty line after some variable declarations * Remove unused `extern CutsceneData` in `z_bg_dy_yoseizo.c` * `Matrix_MtxFToYXZRotS` does not use `MTXMODE_` * Use `MTXMODE_` more * Remove `ASCII_TO_U32`, use `'IS64'` * Add explicit `!= NULL` in some ternaries * Use `INV_CONTENT`, `AMMO` macros more * Use `PLAYER_AP_` enum more to compare to `Player#heldItemActionParam` * Get rid of lowercase hex (outside libultra) * `gWindMill*` -> `gWindmill*` * Format and small fix enums in `z_boss_mo.h` * Use `CHECK_BTN_ANY` more * Fix xz/xy mistake in comment in tektite * Rephrase comments mentioning "the devs" in a more neutral way * Clean-up some objectively useless parens * Fix some negative values written as u16 instead of s16 in ichains * `SKJ_ACTON_` -> `SKJ_ACTION_` * Run formatter * Fix unk_ offset of `TransformUpdateIndex#unk_10` -> `unk_0E` * Remove comments using in-game text * Remove `U` suffix from integer literals * Revert "Remove `ASCII_TO_U32`, use `'IS64'`" This reverts commit c801337dde9fe5e8b7a7ecf85ad3629bf5b87aaf. * Use `PLAYER_STR_*` to compare to `CUR_UPG_VALUE(UPG_STRENGTH)` * Add empty line after decl x2 * Revert "Use `PLAYER_STR_*` to compare to `CUR_UPG_VALUE(UPG_STRENGTH)`" This reverts commit d80bdb32da449edc74e02b8ab3f5a2c532e74bdb. * Make `CUR_UPG_VALUE(UPG_STRENGTH)` compare to integers (eventually needs its own enum) * Only use `PLAYER_SHIELD_` enum with `Player#currentShield` * Only use `PLAYER_TUNIC_` enum with `Player#currentTunic`
2021-10-03 03:17:09 +00:00
// "Zelda heap display" ("Zelda" should probably have been changed to "Debug")
2020-03-17 04:31:30 +00:00
osSyncPrintf("ゼルダヒープ表示\n");
__osDisplayArena(&sDebugArena);
}
2020-03-22 21:19:43 +00:00
void DebugArena_GetSizes(u32* outMaxFree, u32* outFree, u32* outAlloc) {
2020-03-17 04:31:30 +00:00
ArenaImpl_GetSizes(&sDebugArena, outMaxFree, outFree, outAlloc);
}
void DebugArena_Check(void) {
2020-03-17 04:31:30 +00:00
__osCheckArena(&sDebugArena);
}
2020-03-22 21:19:43 +00:00
void DebugArena_Init(void* start, u32 size) {
2020-03-17 04:31:30 +00:00
gDebugArenaLogSeverity = LOG_SEVERITY_NOLOG;
__osMallocInit(&sDebugArena, start, size);
}
void DebugArena_Cleanup(void) {
2020-03-17 04:31:30 +00:00
gDebugArenaLogSeverity = LOG_SEVERITY_NOLOG;
__osMallocCleanup(&sDebugArena);
}
u8 DebugArena_IsInitialized(void) {
return __osMallocIsInitialized(&sDebugArena);
2020-03-17 04:31:30 +00:00
}