#include <heap_int.h>
#define WARNINGS 1
-#define DEBUG_TRACE 0
+#define DEBUG_TRACE 1
+#define VERBOSE_DUMP 0
// === CONSTANTS ===
#define HEAP_INIT_SIZE 0x8000 // 32 KiB
* \param Line Source line
* \param Bytes Size of region to allocate
*/
-void *Heap_Allocate(const char *File, int Line, size_t Bytes)
+void *Heap_Allocate(const char *File, int Line, size_t __Bytes)
{
tHeapHead *head, *newhead;
tHeapFoot *foot, *newfoot;
tHeapHead *best = NULL;
Uint bestSize = 0; // Speed hack
+ size_t Bytes;
// Get required size
#if POW2_SIZES
- Bytes = Bytes + sizeof(tHeapHead) + sizeof(tHeapFoot);
- Bytes = 1UUL << LOG2(Bytes);
+ Bytes = __Bytes + sizeof(tHeapHead) + sizeof(tHeapFoot);
+ Bytes = 1UUL << LOG2(__Bytes);
#else
- Bytes = (Bytes + sizeof(tHeapHead) + sizeof(tHeapFoot) + MIN_SIZE-1) & ~(MIN_SIZE-1);
+ Bytes = (__Bytes + sizeof(tHeapHead) + sizeof(tHeapFoot) + MIN_SIZE-1) & ~(MIN_SIZE-1);
#endif
// Lock Heap
newhead->Magic = MAGIC_FREE;
foot->Head = newhead; // Update backlink in old footer
best->Size = Bytes; // Update size in old header
+ best->ValidSize = __Bytes;
best->Magic = MAGIC_USED; // Mark block as used
best->File = File;
best->Line = Line;
// Mark as free
head->Magic = MAGIC_FREE;
- head->File = NULL;
- head->Line = 0;
+ //head->File = NULL;
+ //head->Line = 0;
head->ValidSize = 0;
// Merge blocks
Heap_Merge( head );
while( (Uint)head < (Uint)gHeapEnd )
{
foot = (void*)( (Uint)head + head->Size - sizeof(tHeapFoot) );
+ #if VERBOSE_DUMP
Log_Log("Heap", "%p (0x%llx): 0x%08lx (%i) %4C",
head, MM_GetPhysAddr((Uint)head), head->Size, head->ValidSize, &head->Magic);
Log_Log("Heap", "%p %4C", foot->Head, &foot->Magic);
Log_Log("Heap", "%sowned by %s:%i",
(head->Magic==MAGIC_FREE?"was ":""), head->File, head->Line);
}
- Log_Log("Heap", "");
+ #endif
// Sanity Check Header
if(head->Size == 0) {
break;
}
+ #if VERBOSE_DUMP
+ Log_Log("Heap", "");
+ #endif
+
// All OK? Go to next
head = foot->NextHead;
}
// Check for a bad return
if( (tVAddr)head >= (tVAddr)gHeapEnd )
return ;
+
+ #if !VERBOSE_DUMP
+ Log_Log("Heap", "%p (0x%llx): 0x%08lx (%i) %4C",
+ head, MM_GetPhysAddr((Uint)head), head->Size, head->ValidSize, &head->Magic);
+ Log_Log("Heap", "%p %4C", foot->Head, &foot->Magic);
+ if(head->File) {
+ Log_Log("Heap", "%sowned by %s:%i",
+ (head->Magic==MAGIC_FREE?"was ":""), head->File, head->Line);
+ }
+ Log_Log("Heap", "");
+ #endif
- badHead = head;
- Log_Log("Heap", "==== Going Backwards ==== (from %p)", badHead);
+ badHead = head;
// Work backwards
foot = (void*)( (tVAddr)gHeapEnd - sizeof(tHeapFoot) );
+ Log_Log("Heap", "==== Going Backwards ==== (from %p)", foot);
head = foot->Head;
while( (tVAddr)head >= (tVAddr)badHead )
{
extern int strcmp(const char *__str1, const char *__str2);
extern int strncmp(const char *Str1, const char *Str2, size_t num);
extern int strucmp(const char *Str1, const char *Str2);
-extern char *strdup(const char *Str);
+//extern char *strdup(const char *Str);
+#define strdup(Str) _strdup(_MODULE_NAME_"/"__FILE__, __LINE__, (Str))
+extern char *_strdup(const char *File, int Line, const char *Str);
extern char **str_split(const char *__str, char __ch);
extern int strpos(const char *Str, char Ch);
extern int strpos8(const char *str, Uint32 search);
* this if needed
*/
void *Data;
+
+ /**
+ * \brief Node mutex
+ * \note Provided for the Filesystem driver's use
+ */
+ tMutex Lock;
+
/**
* \}
*/
char *strncpy(char *__str1, const char *__str2, size_t max);
int strcmp(const char *str1, const char *str2);
int strncmp(const char *str1, const char *str2, size_t num);
-char *strdup(const char *Str);
+char *_strdup(const char *File, int Line, const char *Str);
char **str_split(const char *__str, char __ch);
int strpos8(const char *str, Uint32 Search);
int ReadUTF8(Uint8 *str, Uint32 *Val);
EXPORT(strncpy);
EXPORT(strcmp);
EXPORT(strncmp);
-EXPORT(strdup);
+//EXPORT(strdup);
+EXPORT(_strdup); // Takes File/Line too
EXPORT(str_split);
EXPORT(strpos8);
EXPORT(DivUp);
return *Str1-*Str2;
}
+#if 0
/**
* \fn char *strdup(const char *Str)
* \brief Duplicates a string
strcpy(ret, Str);
return ret;
}
+#endif
+
+/**
+ * \fn char *_strdup(const char *File, int Line, const char *Str)
+ * \brief Duplicates a string
+ */
+char *_strdup(const char *File, int Line, const char *Str)
+{
+ char *ret;
+ ret = Heap_Allocate(File, Line, strlen(Str)+1);
+ if( !ret ) return NULL;
+ strcpy(ret, Str);
+ return ret;
+}
/**
* \brief Split a string using the passed character
typedef struct sFAT_LFNCacheEnt\r
{\r
int ID;\r
+ // TODO: Handle UTF16 names correctly\r
char Data[256];\r
} tFAT_LFNCacheEnt;\r
/**\r
{\r
#endif\r
ret = (char*) malloc(13);\r
+ if( !ret ) {\r
+ Log_Warning("FAT", "FAT_int_CreateName: malloc(13) failed");\r
+ return NULL;\r
+ }\r
FAT_int_ProperFilename(ret, ft->name);\r
#if USE_LFN\r
}\r
}\r
#endif\r
\r
-#if USE_LFN\r
-// I should probably more tightly associate the LFN cache with the node\r
-// somehow, maybe by adding a field to tVFS_Node before locking it\r
-// Maybe .Cache or something like that (something that is free'd by the\r
-// Inode_UncacheNode function)\r
- \r
+#if USE_LFN \r
/**\r
* \fn char *FAT_int_GetLFN(tVFS_Node *node)\r
* \brief Return pointer to LFN cache entry\r
if(fileinfo[a].attrib == ATTR_LFN)\r
{\r
fat_longfilename *lfnInfo;\r
- int len;\r
\r
lfnInfo = (fat_longfilename *) &fileinfo[a];\r
\r
// Get cache for corresponding file\r
+ // > ID + Index gets the corresponding short node\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
\r
- // Get the current length\r
- len = strlen(lfn);\r
+ a = (lfnInfo->id & 0x3F) * 13;\r
\r
// Sanity Check (FAT implementations should not allow >255 character names)\r
- if(len + 13 > 255) return VFS_SKIP;\r
- // Rebase all bytes\r
- for(a=len+1;a--;) lfn[a+13] = lfn[a];\r
+ if(a > 255) return VFS_SKIP;\r
\r
// Append new bytes\r
- lfn[ 0] = lfnInfo->name1[0]; lfn[ 1] = lfnInfo->name1[1];\r
- lfn[ 2] = lfnInfo->name1[2]; lfn[ 3] = lfnInfo->name1[3];\r
- lfn[ 4] = lfnInfo->name1[4]; \r
- lfn[ 5] = lfnInfo->name2[0]; lfn[ 6] = lfnInfo->name2[1];\r
- lfn[ 7] = lfnInfo->name2[2]; lfn[ 8] = lfnInfo->name2[3];\r
- lfn[ 9] = lfnInfo->name2[4]; lfn[10] = lfnInfo->name2[5];\r
- lfn[11] = lfnInfo->name3[0]; lfn[12] = lfnInfo->name3[1];\r
+ lfn[a+ 0] = lfnInfo->name1[0]; lfn[a+ 1] = lfnInfo->name1[1];\r
+ lfn[a+ 2] = lfnInfo->name1[2]; lfn[a+ 3] = lfnInfo->name1[3];\r
+ lfn[a+ 4] = lfnInfo->name1[4]; \r
+ lfn[a+ 5] = lfnInfo->name2[0]; lfn[a+ 6] = lfnInfo->name2[1];\r
+ lfn[a+ 7] = lfnInfo->name2[2]; lfn[a+ 8] = lfnInfo->name2[3];\r
+ lfn[a+ 9] = lfnInfo->name2[4]; lfn[a+10] = lfnInfo->name2[5];\r
+ lfn[a+11] = lfnInfo->name3[0]; lfn[a+12] = lfnInfo->name3[1];\r
LOG("lfn = '%s'", lfn);\r
LEAVE('p', VFS_SKIP);\r
return VFS_SKIP;\r
-include $(CFGFILES)
CPPFLAGS := -I$(ACESSDIR)/Kernel/include -I$(ACESSDIR)/Kernel/arch/$(ARCHDIR)/include -DARCH=$(ARCH) $(_CPPFLAGS)
-CFLAGS = -Wall -Werror -fno-stack-protector $(CPPFLAGS) -g -O3 -fno-builtin
+CFLAGS := -Wall -Werror -fno-stack-protector -g -O3 -fno-builtin
ifneq ($(CATEGORY),)
FULLNAME := $(CATEGORY)_$(NAME)
%.o.$(_SUFFIX): %.c Makefile ../Makefile.tpl $(CFGFILES)
@echo --- $(CC) -o $@
- @$(CC) $(CFLAGS) -o $@ -c $<
+ @$(CC) $(CFLAGS) $(CPPFLAGS) -o $@ -c $<
@$(CC) -M $(CPPFLAGS) -MT $@ -o $*.d.$(ARCH) $<
-include $(DEPFILES)