mirror of
https://github.com/zeldaret/oot.git
synced 2024-12-27 07:07:09 +00:00
Give debug_malloc.c the same treatment as system_malloc.c and z_malloc.c (#1700)
This commit is contained in:
parent
d9a1148d13
commit
178e95ae50
4 changed files with 50 additions and 21 deletions
|
@ -1464,22 +1464,24 @@ u64* SysUcode_GetUCodeData(void);
|
|||
NORETURN void func_800D31A0(void);
|
||||
void func_800D31F0(void);
|
||||
void func_800D3210(void);
|
||||
void DebugArena_CheckPointer(void* ptr, u32 size, const char* name, const char* action);
|
||||
void* DebugArena_Malloc(u32 size);
|
||||
void* DebugArena_MallocDebug(u32 size, const char* file, s32 line);
|
||||
void* DebugArena_MallocR(u32 size);
|
||||
void* DebugArena_MallocRDebug(u32 size, const char* file, s32 line);
|
||||
void* DebugArena_Realloc(void* ptr, u32 newSize);
|
||||
void* DebugArena_ReallocDebug(void* ptr, u32 newSize, const char* file, s32 line);
|
||||
void DebugArena_Free(void* ptr);
|
||||
void DebugArena_FreeDebug(void* ptr, const char* file, s32 line);
|
||||
void* DebugArena_Calloc(u32 num, u32 size);
|
||||
void DebugArena_Display(void);
|
||||
void DebugArena_GetSizes(u32* outMaxFree, u32* outFree, u32* outAlloc);
|
||||
void DebugArena_Check(void);
|
||||
void DebugArena_Init(void* start, u32 size);
|
||||
void DebugArena_Cleanup(void);
|
||||
u8 DebugArena_IsInitialized(void);
|
||||
#if OOT_DEBUG
|
||||
void DebugArena_CheckPointer(void* ptr, u32 size, const char* name, const char* action);
|
||||
void* DebugArena_MallocDebug(u32 size, const char* file, s32 line);
|
||||
void* DebugArena_MallocRDebug(u32 size, const char* file, s32 line);
|
||||
void* DebugArena_ReallocDebug(void* ptr, u32 newSize, const char* file, s32 line);
|
||||
void DebugArena_FreeDebug(void* ptr, const char* file, s32 line);
|
||||
void DebugArena_Display(void);
|
||||
#endif
|
||||
void UCodeDisas_Init(UCodeDisas*);
|
||||
void UCodeDisas_Destroy(UCodeDisas*);
|
||||
void UCodeDisas_Disassemble(UCodeDisas*, Gfx*);
|
||||
|
|
|
@ -194,6 +194,9 @@ extern struct GraphicsContext* __gfxCtx;
|
|||
#define DMA_REQUEST_SYNC(ram, vrom, size, file, line) DmaMgr_RequestSyncDebug(ram, vrom, size, file, line)
|
||||
#define DMA_REQUEST_ASYNC(req, ram, vrom, size, unk5, queue, msg, file, line) DmaMgr_RequestAsyncDebug(req, ram, vrom, size, unk5, queue, msg, file, line)
|
||||
#define GAME_STATE_ALLOC(gameState, size, file, line) GameState_Alloc(gameState, size, file, line)
|
||||
#define DEBUG_ARENA_MALLOC(size, file, line) DebugArena_MallocDebug(size, file, line)
|
||||
#define DEBUG_ARENA_MALLOC_R(size, file, line) DebugArena_MallocRDebug(size, file, line)
|
||||
#define DEBUG_ARENA_FREE(size, file, line) DebugArena_FreeDebug(size, file, line)
|
||||
#define SYSTEM_ARENA_MALLOC(size, file, line) SystemArena_MallocDebug(size, file, line)
|
||||
#define SYSTEM_ARENA_MALLOC_R(size, file, line) SystemArena_MallocRDebug(size, file, line)
|
||||
#define SYSTEM_ARENA_FREE(size, file, line) SystemArena_FreeDebug(size, file, line)
|
||||
|
@ -224,6 +227,9 @@ extern struct GraphicsContext* __gfxCtx;
|
|||
#define DMA_REQUEST_SYNC(ram, vrom, size, file, line) DmaMgr_RequestSync(ram, vrom, size)
|
||||
#define DMA_REQUEST_ASYNC(req, ram, vrom, size, unk5, queue, msg, file, line) DmaMgr_RequestAsync(req, ram, vrom, size, unk5, queue, msg)
|
||||
#define GAME_STATE_ALLOC(gameState, size, file, line) THA_AllocTailAlign16(&(gameState)->tha, size)
|
||||
#define DEBUG_ARENA_MALLOC(size, file, line) DebugArena_Malloc(size)
|
||||
#define DEBUG_ARENA_MALLOC_R(size, file, line) DebugArena_MallocR(size)
|
||||
#define DEBUG_ARENA_FREE(size, file, line) DebugArena_Free(size)
|
||||
#define SYSTEM_ARENA_MALLOC(size, file, line) SystemArena_Malloc(size)
|
||||
#define SYSTEM_ARENA_MALLOC_R(size, file, line) SystemArena_MallocR(size)
|
||||
#define SYSTEM_ARENA_FREE(size, file, line) SystemArena_Free(size)
|
||||
|
|
|
@ -1538,18 +1538,18 @@ char DebugCamera_InitCut(s32 idx, DebugCamSub* sub) {
|
|||
D_80161250[0x3F + sDebugCamCuts[idx].letter] = 'O';
|
||||
|
||||
i = sub->nPoints * sizeof(CutsceneCameraPoint);
|
||||
sDebugCamCuts[idx].lookAt = DebugArena_MallocDebug(i, "../db_camera.c", 2748);
|
||||
sDebugCamCuts[idx].lookAt = DEBUG_ARENA_MALLOC(i, "../db_camera.c", 2748);
|
||||
if (sDebugCamCuts[idx].lookAt == NULL) {
|
||||
// "Debug camera memory allocation failure"
|
||||
PRINTF("%s: %d: デバッグカメラ メモリ確保失敗!!\n", "../db_camera.c", 2751);
|
||||
return '?';
|
||||
}
|
||||
|
||||
sDebugCamCuts[idx].position = DebugArena_MallocDebug(i, "../db_camera.c", 2754);
|
||||
sDebugCamCuts[idx].position = DEBUG_ARENA_MALLOC(i, "../db_camera.c", 2754);
|
||||
if (sDebugCamCuts[idx].position == NULL) {
|
||||
// "Debug camera memory allocation failure"
|
||||
PRINTF("%s: %d: デバッグカメラ メモリ確保失敗!!\n", "../db_camera.c", 2757);
|
||||
DebugArena_FreeDebug(sDebugCamCuts[idx].lookAt, "../db_camera.c", 2758);
|
||||
DEBUG_ARENA_FREE(sDebugCamCuts[idx].lookAt, "../db_camera.c", 2758);
|
||||
sDebugCamCuts[idx].lookAt = NULL;
|
||||
return '?';
|
||||
}
|
||||
|
@ -1572,8 +1572,8 @@ void DebugCamera_ResetCut(s32 idx, s32 shouldFree) {
|
|||
}
|
||||
|
||||
if (shouldFree) {
|
||||
DebugArena_FreeDebug(sDebugCamCuts[idx].lookAt, "../db_camera.c", 2784);
|
||||
DebugArena_FreeDebug(sDebugCamCuts[idx].position, "../db_camera.c", 2785);
|
||||
DEBUG_ARENA_FREE(sDebugCamCuts[idx].lookAt, "../db_camera.c", 2784);
|
||||
DEBUG_ARENA_FREE(sDebugCamCuts[idx].position, "../db_camera.c", 2785);
|
||||
}
|
||||
|
||||
sDebugCamCuts[idx].letter = '?';
|
||||
|
@ -1623,7 +1623,7 @@ s32 DebugCamera_LoadCallback(char* c) {
|
|||
if (sDebugCamCuts[i].letter != '?') {
|
||||
size = sDebugCamCuts[i].nPoints * sizeof(CutsceneCameraPoint);
|
||||
|
||||
sDebugCamCuts[i].lookAt = DebugArena_MallocDebug(ALIGN32(size), "../db_camera.c", 2844);
|
||||
sDebugCamCuts[i].lookAt = DEBUG_ARENA_MALLOC(ALIGN32(size), "../db_camera.c", 2844);
|
||||
if (sDebugCamCuts[i].lookAt == NULL) {
|
||||
// "Debug camera memory allocation failure"
|
||||
PRINTF("%s: %d: デバッグカメラ メモリ確保失敗!!\n", "../db_camera.c", 2847);
|
||||
|
@ -1634,7 +1634,7 @@ s32 DebugCamera_LoadCallback(char* c) {
|
|||
}
|
||||
off += ALIGN32(size);
|
||||
|
||||
sDebugCamCuts[i].position = DebugArena_MallocDebug(ALIGN32(size), "../db_camera.c", 2855);
|
||||
sDebugCamCuts[i].position = DEBUG_ARENA_MALLOC(ALIGN32(size), "../db_camera.c", 2855);
|
||||
if (sDebugCamCuts[i].position == NULL) {
|
||||
// "Debug camera memory allocation failure"
|
||||
PRINTF("%s: %d: デバッグカメラ メモリ確保失敗!!\n", "../db_camera.c", 2858);
|
||||
|
|
|
@ -4,9 +4,11 @@
|
|||
#define LOG_SEVERITY_ERROR 2
|
||||
#define LOG_SEVERITY_VERBOSE 3
|
||||
|
||||
s32 gDebugArenaLogSeverity = LOG_SEVERITY_ERROR;
|
||||
Arena sDebugArena;
|
||||
|
||||
#if OOT_DEBUG
|
||||
s32 gDebugArenaLogSeverity = LOG_SEVERITY_ERROR;
|
||||
|
||||
void DebugArena_CheckPointer(void* ptr, u32 size, const char* name, const char* action) {
|
||||
if (ptr == NULL) {
|
||||
if (gDebugArenaLogSeverity >= LOG_SEVERITY_ERROR) {
|
||||
|
@ -21,53 +23,66 @@ void DebugArena_CheckPointer(void* ptr, u32 size, const char* name, const char*
|
|||
}
|
||||
}
|
||||
|
||||
#define DEBUG_ARENA_CHECK_POINTER(ptr, size, name, action) DebugArena_CheckPointer(ptr, size, name, action)
|
||||
#else
|
||||
#define DEBUG_ARENA_CHECK_POINTER(ptr, size, name, action) (void)0
|
||||
#endif
|
||||
|
||||
void* DebugArena_Malloc(u32 size) {
|
||||
void* ptr = __osMalloc(&sDebugArena, size);
|
||||
|
||||
DebugArena_CheckPointer(ptr, size, "debug_malloc", "確保"); // "Secure"
|
||||
DEBUG_ARENA_CHECK_POINTER(ptr, size, "debug_malloc", "確保"); // "Secure"
|
||||
return ptr;
|
||||
}
|
||||
|
||||
#if OOT_DEBUG
|
||||
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"
|
||||
DEBUG_ARENA_CHECK_POINTER(ptr, size, "debug_malloc_DEBUG", "確保"); // "Secure"
|
||||
return ptr;
|
||||
}
|
||||
#endif
|
||||
|
||||
void* DebugArena_MallocR(u32 size) {
|
||||
void* ptr = __osMallocR(&sDebugArena, size);
|
||||
|
||||
DebugArena_CheckPointer(ptr, size, "debug_malloc_r", "確保"); // "Secure"
|
||||
DEBUG_ARENA_CHECK_POINTER(ptr, size, "debug_malloc_r", "確保"); // "Secure"
|
||||
return ptr;
|
||||
}
|
||||
|
||||
#if OOT_DEBUG
|
||||
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"
|
||||
DEBUG_ARENA_CHECK_POINTER(ptr, size, "debug_malloc_r_DEBUG", "確保"); // "Secure"
|
||||
return ptr;
|
||||
}
|
||||
#endif
|
||||
|
||||
void* DebugArena_Realloc(void* ptr, u32 newSize) {
|
||||
ptr = __osRealloc(&sDebugArena, ptr, newSize);
|
||||
DebugArena_CheckPointer(ptr, newSize, "debug_realloc", "再確保"); // "Re-securing"
|
||||
DEBUG_ARENA_CHECK_POINTER(ptr, newSize, "debug_realloc", "再確保"); // "Re-securing"
|
||||
return ptr;
|
||||
}
|
||||
|
||||
#if OOT_DEBUG
|
||||
void* DebugArena_ReallocDebug(void* ptr, u32 newSize, const char* file, s32 line) {
|
||||
ptr = __osReallocDebug(&sDebugArena, ptr, newSize, file, line);
|
||||
DebugArena_CheckPointer(ptr, newSize, "debug_realloc_DEBUG", "再確保"); // "Re-securing"
|
||||
DEBUG_ARENA_CHECK_POINTER(ptr, newSize, "debug_realloc_DEBUG", "再確保"); // "Re-securing"
|
||||
return ptr;
|
||||
}
|
||||
#endif
|
||||
|
||||
void DebugArena_Free(void* ptr) {
|
||||
__osFree(&sDebugArena, ptr);
|
||||
}
|
||||
|
||||
#if OOT_DEBUG
|
||||
void DebugArena_FreeDebug(void* ptr, const char* file, s32 line) {
|
||||
__osFreeDebug(&sDebugArena, ptr, file, line);
|
||||
}
|
||||
#endif
|
||||
|
||||
void* DebugArena_Calloc(u32 num, u32 size) {
|
||||
void* ret;
|
||||
|
@ -78,15 +93,17 @@ void* DebugArena_Calloc(u32 num, u32 size) {
|
|||
bzero(ret, n);
|
||||
}
|
||||
|
||||
DebugArena_CheckPointer(ret, n, "debug_calloc", "確保");
|
||||
DEBUG_ARENA_CHECK_POINTER(ret, n, "debug_calloc", "確保");
|
||||
return ret;
|
||||
}
|
||||
|
||||
#if OOT_DEBUG
|
||||
void DebugArena_Display(void) {
|
||||
// "Zelda heap display" ("Zelda" should probably have been changed to "Debug")
|
||||
PRINTF("ゼルダヒープ表示\n");
|
||||
__osDisplayArena(&sDebugArena);
|
||||
}
|
||||
#endif
|
||||
|
||||
void DebugArena_GetSizes(u32* outMaxFree, u32* outFree, u32* outAlloc) {
|
||||
ArenaImpl_GetSizes(&sDebugArena, outMaxFree, outFree, outAlloc);
|
||||
|
@ -97,12 +114,16 @@ void DebugArena_Check(void) {
|
|||
}
|
||||
|
||||
void DebugArena_Init(void* start, u32 size) {
|
||||
#if OOT_DEBUG
|
||||
gDebugArenaLogSeverity = LOG_SEVERITY_NOLOG;
|
||||
#endif
|
||||
__osMallocInit(&sDebugArena, start, size);
|
||||
}
|
||||
|
||||
void DebugArena_Cleanup(void) {
|
||||
#if OOT_DEBUG
|
||||
gDebugArenaLogSeverity = LOG_SEVERITY_NOLOG;
|
||||
#endif
|
||||
__osMallocCleanup(&sDebugArena);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue