mirror of
https://github.com/zeldaret/mm.git
synced 2026-05-28 16:30:54 -04:00
stackcheck.h (#1204)
* stackcheck.h * warning * Update src/boot_O2/stackcheck.c Co-authored-by: engineer124 <47598039+engineer124@users.noreply.github.com> * Update src/boot_O2/stackcheck.c Co-authored-by: engineer124 <47598039+engineer124@users.noreply.github.com> * Update src/boot_O2/stackcheck.c Co-authored-by: engineer124 <47598039+engineer124@users.noreply.github.com> * stack * format * bss * review * review --------- Co-authored-by: engineer124 <47598039+engineer124@users.noreply.github.com>
This commit is contained in:
+30
-27
@@ -1,18 +1,19 @@
|
||||
#include "global.h"
|
||||
#include "stackcheck.h"
|
||||
#include "libc/stdbool.h"
|
||||
#include "libc/stdint.h"
|
||||
|
||||
StackEntry* sStackInfoListStart = NULL;
|
||||
StackEntry* sStackInfoListEnd = NULL;
|
||||
|
||||
void StackCheck_Init(StackEntry* entry, void* stackTop, void* stackBottom, u32 initValue, s32 minSpace,
|
||||
void StackCheck_Init(StackEntry* entry, void* stackBottom, void* stackTop, u32 initValue, s32 minSpace,
|
||||
const char* name) {
|
||||
StackEntry* iter;
|
||||
u32* addr;
|
||||
|
||||
if (!entry) {
|
||||
if (entry == NULL) {
|
||||
sStackInfoListStart = NULL;
|
||||
} else {
|
||||
entry->head = (u32)stackTop;
|
||||
entry->tail = (u32)stackBottom;
|
||||
StackEntry* iter;
|
||||
|
||||
entry->head = stackBottom;
|
||||
entry->tail = stackTop;
|
||||
entry->initValue = initValue;
|
||||
entry->minSpace = minSpace;
|
||||
entry->name = name;
|
||||
@@ -32,13 +33,14 @@ void StackCheck_Init(StackEntry* entry, void* stackTop, void* stackBottom, u32 i
|
||||
}
|
||||
|
||||
sStackInfoListEnd = entry;
|
||||
if (!sStackInfoListStart) {
|
||||
if (sStackInfoListStart == NULL) {
|
||||
sStackInfoListStart = entry;
|
||||
}
|
||||
|
||||
if (entry->minSpace != -1) {
|
||||
addr = (u32*)entry->head;
|
||||
while ((u32)addr < entry->tail) {
|
||||
u32* addr = entry->head;
|
||||
|
||||
while (addr < (u32*)entry->tail) {
|
||||
*addr++ = entry->initValue;
|
||||
}
|
||||
}
|
||||
@@ -46,13 +48,13 @@ void StackCheck_Init(StackEntry* entry, void* stackTop, void* stackBottom, u32 i
|
||||
}
|
||||
|
||||
void StackCheck_Cleanup(StackEntry* entry) {
|
||||
u32 inconsistency = 0; // unused variable needed to match
|
||||
u32 inconsistency = false;
|
||||
|
||||
if (!entry->prev) {
|
||||
if (entry->prev == NULL) {
|
||||
if (entry == sStackInfoListStart) {
|
||||
sStackInfoListStart = entry->next;
|
||||
} else {
|
||||
inconsistency = 1;
|
||||
inconsistency = true;
|
||||
}
|
||||
} else {
|
||||
entry->prev->next = entry->next;
|
||||
@@ -62,7 +64,7 @@ void StackCheck_Cleanup(StackEntry* entry) {
|
||||
if (entry == sStackInfoListEnd) {
|
||||
sStackInfoListEnd = entry->prev;
|
||||
} else {
|
||||
inconsistency = 1;
|
||||
inconsistency = true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -71,22 +73,22 @@ void StackCheck_Cleanup(StackEntry* entry) {
|
||||
|
||||
StackStatus StackCheck_GetState(StackEntry* entry) {
|
||||
u32* last;
|
||||
u32 used;
|
||||
u32 free;
|
||||
s32 status;
|
||||
size_t used;
|
||||
size_t free;
|
||||
StackStatus status;
|
||||
|
||||
for (last = (u32*)entry->head; (u32)last < entry->tail; last++) {
|
||||
for (last = entry->head; last < (u32*)entry->tail; last++) {
|
||||
if (entry->initValue != *last) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
used = entry->tail - (u32)last;
|
||||
free = (u32)last - entry->head;
|
||||
used = (uintptr_t)entry->tail - (uintptr_t)last;
|
||||
free = (uintptr_t)last - (uintptr_t)entry->head;
|
||||
|
||||
if (free == 0) {
|
||||
status = STACK_STATUS_OVERFLOW;
|
||||
} else if (free < (u32)entry->minSpace && entry->minSpace != -1) {
|
||||
} else if ((free < (size_t)entry->minSpace) && (entry->minSpace != -1)) {
|
||||
status = STACK_STATUS_WARNING;
|
||||
} else {
|
||||
status = STACK_STATUS_OK;
|
||||
@@ -95,13 +97,14 @@ StackStatus StackCheck_GetState(StackEntry* entry) {
|
||||
return status;
|
||||
}
|
||||
|
||||
u32 StackCheck_CheckAll() {
|
||||
u32 StackCheck_CheckAll(void) {
|
||||
u32 ret = 0;
|
||||
StackEntry* iter = sStackInfoListStart;
|
||||
|
||||
while (iter) {
|
||||
u32 state = StackCheck_GetState(iter);
|
||||
if (state) {
|
||||
while (iter != NULL) {
|
||||
StackStatus state = StackCheck_GetState(iter);
|
||||
|
||||
if (state != STACK_STATUS_OK) {
|
||||
ret = 1;
|
||||
}
|
||||
iter = iter->next;
|
||||
@@ -111,7 +114,7 @@ u32 StackCheck_CheckAll() {
|
||||
}
|
||||
|
||||
u32 StackCheck_Check(StackEntry* entry) {
|
||||
if (!entry) {
|
||||
if (entry == NULL) {
|
||||
return StackCheck_CheckAll();
|
||||
} else {
|
||||
return StackCheck_GetState(entry);
|
||||
|
||||
Reference in New Issue
Block a user