summaryrefslogtreecommitdiff
path: root/CommonCode.c
diff options
context:
space:
mode:
Diffstat (limited to 'CommonCode.c')
-rw-r--r--CommonCode.c44
1 files changed, 42 insertions, 2 deletions
diff --git a/CommonCode.c b/CommonCode.c
index 26dda97..eb6c011 100644
--- a/CommonCode.c
+++ b/CommonCode.c
@@ -395,16 +395,54 @@ BOK1:
return 0;
}
+
+void CheckFreeQueue(char * File, int Line)
+{
+ void ** pointer;
+ int n = 0;
+ void ** debug;
+ PMESSAGE Test;
+
+ pointer = FREE_Q;
+ debug = &FREE_Q;
+
+ while (pointer)
+ {
+ // Validate pointer to make sure it is in pool - it may be a duff address if Q is corrupt
+
+ Test = (PMESSAGE)pointer;
+
+ if (Test->GuardZone || (uintptr_t)pointer < (uintptr_t)BUFFERPOOL || (uintptr_t)pointer > (uintptr_t)ENDBUFFERPOOL)
+ {
+ // Not pointing to a buffer . debug points to the buffer that this is chained from
+
+ Debugprintf("CheckFree Queue Pool Corruption n = %d, ptr %p prev %p from %s Line %d", n, pointer, debug, File, Line);
+ }
+
+ debug = pointer;
+ pointer = pointer[0];
+ n++;
+
+ if (n > 1000)
+ {
+ Debugprintf("CheckFreeQueue Loop searching free chain - pointer = %p %p from %s Line %d", debug, pointer, File, Line);
+ FindLostBuffers();
+ WriteMiniDump();
+ Restart();
+ }
+ }
+}
+
int _C_Q_ADD(VOID *PQ, VOID *PBUFF, char * File, int Line)
{
void ** Q;
void ** BUFF = PBUFF;
void ** next;
PMESSAGE Test;
-
-
int n = 0;
+ CheckFreeQueue(File, Line);
+
// PQ may not be word aligned, so copy as bytes (for ARM5)
Q = PQ;
@@ -532,6 +570,8 @@ VOID * _GetBuff(char * File, int Line)
char * fptr = 0;
unsigned char * byteaddr;
+ CheckFreeQueue(File, Line);
+
Temp = Q_REM(&FREE_Q);
// FindLostBuffers();