#include <heap_int.h>
#define WARNINGS 1
-#define DEBUG_TRACE 1
+#define DEBUG_TRACE 0
#define VERBOSE_DUMP 0
// === CONSTANTS ===
*/
void *Heap_Reallocate(const char *File, int Line, void *__ptr, size_t __size)
{
- tHeapHead *head = (void*)( (Uint)__ptr-8 );
+ tHeapHead *head = (void*)( (Uint)__ptr-sizeof(tHeapHead) );
tHeapHead *nextHead;
tHeapFoot *foot;
Uint newSize = (__size + sizeof(tHeapFoot)+sizeof(tHeapHead)+MIN_SIZE-1)&~(MIN_SIZE-1);
return 1;
}
+/**
+ */
+void Heap_Validate(void)
+{
+ Heap_Dump();
+}
+
#if WARNINGS
void Heap_Dump(void)
{
tHeapHead *head, *badHead;
- tHeapFoot *foot;
+ tHeapFoot *foot = NULL;
head = gHeapStart;
while( (Uint)head < (Uint)gHeapEnd )
head = foot->NextHead;
}
+ // If the heap is valid, ok!
+ if( (tVAddr)head == (tVAddr)gHeapEnd )
+ return ;
+
// Check for a bad return
if( (tVAddr)head >= (tVAddr)gHeapEnd )
return ;
head = foot->Head;
Log_Debug("Heap", "head=%p", head);
}
+
+ Panic("Heap_Dump - Heap is corrupted, kernel panic!");
}
#endif
extern void *Heap_Reallocate(const char *File, int Line, void *Ptr, size_t Bytes);
extern void Heap_Deallocate(void *Ptr);
extern int Heap_IsHeapAddr(void *Ptr);
+extern void Heap_Validate(void);
#define malloc(size) Heap_Allocate(_MODULE_NAME_"/"__FILE__, __LINE__, (size))
#define calloc(num,size) Heap_AllocateZero(_MODULE_NAME_"/"__FILE__, __LINE__, (num)*(size))
tFAT_LFNCache *cache;\r
int i, firstFree;\r
\r
+ Mutex_Acquire( &Node->Lock );\r
+ \r
// TODO: Thread Safety (Lock things)\r
cache = Node->Data;\r
\r
cache->NumEntries = 1;\r
cache->Entries[0].ID = ID;\r
cache->Entries[0].Data[0] = '\0';\r
+ Mutex_Release( &Node->Lock );\r
+ //Log_Debug("FAT", "Return = %p (new)", cache->Entries[0].Data);\r
return cache->Entries[0].Data;\r
}\r
\r
- // Scan for a current entry\r
+ // Scan for this entry\r
firstFree = -1;\r
for( i = 0; i < cache->NumEntries; i++ )\r
{\r
- if( cache->Entries[i].ID == ID )\r
+ if( cache->Entries[i].ID == ID ) {\r
+ Mutex_Release( &Node->Lock );\r
+ //Log_Debug("FAT", "Return = %p (match)", cache->Entries[i].Data);\r
return cache->Entries[i].Data;\r
+ }\r
if( cache->Entries[i].ID == -1 && firstFree == -1 )\r
firstFree = i;\r
}\r
i = sizeof(tFAT_LFNCache) + (cache->NumEntries+1)*sizeof(tFAT_LFNCacheEnt);\r
Node->Data = realloc( Node->Data, i );\r
if( !Node->Data ) {\r
- Log_Error("FAT", "malloc() fail, unable to allocate %i for LFN cache", i);\r
+ Log_Error("FAT", "realloc() fail, unable to allocate %i for LFN cache", i);\r
+ Mutex_Release( &Node->Lock );\r
return NULL;\r
}\r
+ //Log_Debug("FAT", "Realloc (%i)\n", i);\r
cache = Node->Data;\r
i = cache->NumEntries;\r
cache->NumEntries ++;\r
cache->Entries[ i ].ID = ID;\r
cache->Entries[ i ].Data[0] = '\0';\r
\r
- //TODO: Unlock\r
+ Mutex_Release( &Node->Lock );\r
+ //Log_Debug("FAT", "Return = %p (firstFree, i = %i)", cache->Entries[i].Data, i);\r
return cache->Entries[ i ].Data;\r
}\r
\r
lfn = FAT_int_GetLFN( Node, ID + (lfnInfo->id & 0x3F) );\r
\r
// Bit 6 indicates the start of an entry\r
- if(lfnInfo->id & 0x40) memset(lfn, 0, 256);\r
+ if(lfnInfo->id & 0x40) {\r
+ //Log_Debug("FAT", "lfn = %p", lfn);\r
+ //Heap_Validate();\r
+ //Log_Debug("FAT", "Clearing LFN");\r
+ memset(lfn, 0, 256);\r
+ //Heap_Validate();\r
+ //Log_Debug("FAT", "Check Passed");\r
+ }\r
\r
a = (lfnInfo->id & 0x3F) * 13;\r
\r