From d54c5731320dd7705e7636c50712643983ef2eaf Mon Sep 17 00:00:00 2001 From: cadmic Date: Tue, 3 Sep 2024 18:18:53 -0700 Subject: [PATCH] Match stackcheck.c (#2107) --- include/functions.h | 2 -- src/boot/stackcheck.c | 67 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 67 insertions(+), 2 deletions(-) diff --git a/include/functions.h b/include/functions.h index adadeef622..7ca8a2ae27 100644 --- a/include/functions.h +++ b/include/functions.h @@ -28,8 +28,6 @@ void Mio0_Decompress(u8* src, u8* dst); void StackCheck_Init(StackEntry* entry, void* stackBottom, void* stackTop, u32 initValue, s32 minSpace, const char* name); void StackCheck_Cleanup(StackEntry* entry); -u32 StackCheck_GetState(StackEntry* entry); -u32 StackCheck_CheckAll(void); u32 StackCheck_Check(StackEntry* entry); #if OOT_DEBUG void LogUtils_LogHexDump(void* ptr, s32 size0); diff --git a/src/boot/stackcheck.c b/src/boot/stackcheck.c index e33ec5b197..a1cff55e62 100644 --- a/src/boot/stackcheck.c +++ b/src/boot/stackcheck.c @@ -17,6 +17,8 @@ void StackCheck_Init(StackEntry* entry, void* stackBottom, void* stackTop, u32 i entry->initValue = initValue; entry->minSpace = minSpace; entry->name = name; + +#if PLATFORM_GC iter = sStackInfoListStart; while (iter) { if (iter == entry) { @@ -27,6 +29,7 @@ void StackCheck_Init(StackEntry* entry, void* stackBottom, void* stackTop, u32 i } iter = iter->next; } +#endif entry->prev = sStackInfoListEnd; entry->next = NULL; @@ -50,6 +53,17 @@ void StackCheck_Init(StackEntry* entry, void* stackBottom, void* stackTop, u32 i } void StackCheck_Cleanup(StackEntry* entry) { +#if PLATFORM_N64 + if (!entry->prev) { + sStackInfoListStart = entry->next; + } else { + entry->prev->next = entry->next; + } + + if (!entry->next) { + sStackInfoListEnd = entry->prev; + } +#else u32 inconsistency = false; if (!entry->prev) { @@ -69,13 +83,64 @@ void StackCheck_Cleanup(StackEntry* entry) { inconsistency = true; } } + if (inconsistency) { PRINTF(VT_COL(RED, WHITE) T("stackcheck_cleanup: %08x リスト不整合です\n", "stackcheck_cleanup: %08x list inconsistent\n") VT_RST, entry); } +#endif } +#if PLATFORM_N64 + +u32 StackCheck_Check(StackEntry* entry) { + if (entry == NULL) { + u32 ret = 0; + StackEntry* iter = sStackInfoListStart; + + while (iter) { + u32 state = StackCheck_Check(iter); + + if (state != STACK_STATUS_OK) { + ret = 1; + } + iter = iter->next; + } + + return ret; + } else { + u32* last; + u32 used; + u32 free; + u32 ret; + + for (last = entry->head; last < entry->tail; last++) { + if (entry->initValue != *last) { + break; + } + } + + used = (uintptr_t)entry->tail - (uintptr_t)last; + free = (uintptr_t)last - (uintptr_t)entry->head; + + if (free == 0) { + ret = STACK_STATUS_OVERFLOW; + } else if (free < (u32)entry->minSpace && entry->minSpace != -1) { + ret = STACK_STATUS_WARNING; + } else { + ret = STACK_STATUS_OK; + } + + osSyncPrintf("head=%08x tail=%08x last=%08x used=%08x free=%08x [%s]\n", entry->head, entry->tail, last, used, + free, entry->name != NULL ? entry->name : "(null)"); + + return ret; + } +} + +#else + u32 StackCheck_GetState(StackEntry* entry) { u32* last; u32 used; @@ -143,3 +208,5 @@ u32 StackCheck_Check(StackEntry* entry) { return StackCheck_GetState(entry); } } + +#endif