1
0
Fork 0
mirror of https://github.com/zeldaret/oot.git synced 2024-11-15 06:06:04 +00:00

Match stackcheck.c (#2107)

This commit is contained in:
cadmic 2024-09-03 18:18:53 -07:00 committed by GitHub
parent 45158f57d6
commit d54c573132
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 67 additions and 2 deletions

View file

@ -28,8 +28,6 @@ void Mio0_Decompress(u8* src, u8* dst);
void StackCheck_Init(StackEntry* entry, void* stackBottom, void* stackTop, u32 initValue, s32 minSpace, void StackCheck_Init(StackEntry* entry, void* stackBottom, void* stackTop, u32 initValue, s32 minSpace,
const char* name); const char* name);
void StackCheck_Cleanup(StackEntry* entry); void StackCheck_Cleanup(StackEntry* entry);
u32 StackCheck_GetState(StackEntry* entry);
u32 StackCheck_CheckAll(void);
u32 StackCheck_Check(StackEntry* entry); u32 StackCheck_Check(StackEntry* entry);
#if OOT_DEBUG #if OOT_DEBUG
void LogUtils_LogHexDump(void* ptr, s32 size0); void LogUtils_LogHexDump(void* ptr, s32 size0);

View file

@ -17,6 +17,8 @@ void StackCheck_Init(StackEntry* entry, void* stackBottom, void* stackTop, u32 i
entry->initValue = initValue; entry->initValue = initValue;
entry->minSpace = minSpace; entry->minSpace = minSpace;
entry->name = name; entry->name = name;
#if PLATFORM_GC
iter = sStackInfoListStart; iter = sStackInfoListStart;
while (iter) { while (iter) {
if (iter == entry) { if (iter == entry) {
@ -27,6 +29,7 @@ void StackCheck_Init(StackEntry* entry, void* stackBottom, void* stackTop, u32 i
} }
iter = iter->next; iter = iter->next;
} }
#endif
entry->prev = sStackInfoListEnd; entry->prev = sStackInfoListEnd;
entry->next = NULL; entry->next = NULL;
@ -50,6 +53,17 @@ void StackCheck_Init(StackEntry* entry, void* stackBottom, void* stackTop, u32 i
} }
void StackCheck_Cleanup(StackEntry* entry) { 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; u32 inconsistency = false;
if (!entry->prev) { if (!entry->prev) {
@ -69,13 +83,64 @@ void StackCheck_Cleanup(StackEntry* entry) {
inconsistency = true; inconsistency = true;
} }
} }
if (inconsistency) { if (inconsistency) {
PRINTF(VT_COL(RED, WHITE) T("stackcheck_cleanup: %08x リスト不整合です\n", PRINTF(VT_COL(RED, WHITE) T("stackcheck_cleanup: %08x リスト不整合です\n",
"stackcheck_cleanup: %08x list inconsistent\n") VT_RST, "stackcheck_cleanup: %08x list inconsistent\n") VT_RST,
entry); 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 StackCheck_GetState(StackEntry* entry) {
u32* last; u32* last;
u32 used; u32 used;
@ -143,3 +208,5 @@ u32 StackCheck_Check(StackEntry* entry) {
return StackCheck_GetState(entry); return StackCheck_GetState(entry);
} }
} }
#endif