mirror of
https://github.com/zeldaret/oot.git
synced 2024-11-14 21:40:03 +00:00
Match stackcheck.c (#2107)
This commit is contained in:
parent
45158f57d6
commit
d54c573132
2 changed files with 67 additions and 2 deletions
|
@ -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);
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue