From 6a945643557084578509e149c84cf5dde3c59c3c Mon Sep 17 00:00:00 2001 From: John Hodge Date: Fri, 20 Aug 2010 09:49:49 +0800 Subject: [PATCH] Improving the debug capabilities of the heap code, changed VFS to use const char* instead of char* - Also, misc work on SpiderScript --- Kernel/Makefile | 2 +- Kernel/drv/fifo.c | 18 +- Kernel/drv/pci.c | 50 +++-- Kernel/drv/proc.c | 6 +- Kernel/drv/vterm.c | 6 +- Kernel/heap.c | 184 ++++++++++++++---- Kernel/include/acess.h | 13 +- Kernel/include/heap.h | 30 +-- Kernel/include/vfs.h | 8 +- Kernel/include/vfs_int.h | 4 +- Kernel/vfs/fs/devfs.c | 4 +- Kernel/vfs/fs/root.c | 12 +- Kernel/vfs/memfile.c | 8 +- Kernel/vfs/open.c | 44 +++-- Modules/Filesystems/Ext2/dir.c | 18 +- Modules/Filesystems/Ext2/ext2_common.h | 6 +- Modules/Filesystems/FAT/fat.c | 8 +- Modules/Filesystems/NTFS/dir.c | 4 +- Modules/Filesystems/NTFS/main.c | 2 +- Modules/IPStack/link.c | 8 +- Modules/IPStack/main.c | 8 +- Modules/IPStack/tcp.c | 4 +- Modules/IPStack/udp.c | 4 +- Modules/Makefile.tpl | 4 +- Modules/Network/NE2000/ne2000.c | 6 +- Modules/Storage/ATA/main.c | 6 +- Modules/Storage/FDD/fdd.c | 6 +- Modules/USB/Core/main.c | 6 +- .../Libraries/libspiderscript.so_src/ast.h | 4 +- .../libspiderscript.so_src/exec_ast.c | 62 +++--- .../libspiderscript.so_src/exports.c | 4 +- .../Libraries/libspiderscript.so_src/main.c | 8 +- 32 files changed, 334 insertions(+), 223 deletions(-) diff --git a/Kernel/Makefile b/Kernel/Makefile index 225928c3..efd5e057 100644 --- a/Kernel/Makefile +++ b/Kernel/Makefile @@ -14,7 +14,7 @@ KERNEL_VERSION = 0.5 MAKEDEP = $(CC) -M -CPPFLAGS += -I./include -I./arch/$(ARCHDIR)/include +CPPFLAGS += -I./include -I./arch/$(ARCHDIR)/include -D_MODULE_NAME_=\"Kernel\" CPPFLAGS += -DARCH=$(ARCH) -DARCHDIR=$(ARCHDIR) -DKERNEL_VERSION=$(KERNEL_VERSION) -DBUILD_NUM=$(BUILD_NUM) CFLAGS += -Wall -Werror -O3 -fno-stack-protector -fno-builtin -Wstrict-prototypes ASFLAGS += -D ARCH=\"$(ARCH)\" -D ARCHDIR=\"$(ARCHDIR)\" diff --git a/Kernel/drv/fifo.c b/Kernel/drv/fifo.c index 67b9a6d7..83d11755 100644 --- a/Kernel/drv/fifo.c +++ b/Kernel/drv/fifo.c @@ -25,10 +25,10 @@ typedef struct sPipe { int FIFO_Install(char **Arguments); int FIFO_IOCtl(tVFS_Node *Node, int Id, void *Data); char *FIFO_ReadDir(tVFS_Node *Node, int Id); -tVFS_Node *FIFO_FindDir(tVFS_Node *Node, char *Filename); - int FIFO_MkNod(tVFS_Node *Node, char *Name, Uint Flags); +tVFS_Node *FIFO_FindDir(tVFS_Node *Node, const char *Filename); + int FIFO_MkNod(tVFS_Node *Node, const char *Name, Uint Flags); void FIFO_Close(tVFS_Node *Node); - int FIFO_Relink(tVFS_Node *Node, char *OldName, char *NewName); + int FIFO_Relink(tVFS_Node *Node, const char *OldName, const char *NewName); Uint64 FIFO_Read(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer); Uint64 FIFO_Write(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer); tPipe *FIFO_Int_NewPipe(int Size, char *Name); @@ -92,11 +92,11 @@ char *FIFO_ReadDir(tVFS_Node *Node, int Id) } /** - * \fn tVFS_Node *FIFO_FindDir(tVFS_Node *Node, char *Filename) + * \fn tVFS_Node *FIFO_FindDir(tVFS_Node *Node, const char *Filename) * \brief Find a file in the FIFO root * \note Creates an anon pipe if anon is requested */ -tVFS_Node *FIFO_FindDir(tVFS_Node *Node, char *Filename) +tVFS_Node *FIFO_FindDir(tVFS_Node *Node, const char *Filename) { tPipe *tmp; if(!Filename) return NULL; @@ -124,9 +124,9 @@ tVFS_Node *FIFO_FindDir(tVFS_Node *Node, char *Filename) } /** - * \fn int FIFO_MkNod(tVFS_Node *Node, char *Name, Uint Flags) + * \fn int FIFO_MkNod(tVFS_Node *Node, const char *Name, Uint Flags) */ -int FIFO_MkNod(tVFS_Node *Node, char *Name, Uint Flags) +int FIFO_MkNod(tVFS_Node *Node, const char *Name, Uint Flags) { return 0; } @@ -154,10 +154,10 @@ void FIFO_Close(tVFS_Node *Node) } /** - * \fn int FIFO_Relink(tVFS_Node *Node, char *OldName, char *NewName) + * \fn int FIFO_Relink(tVFS_Node *Node, const char *OldName, const char *NewName) * \brief Relink a file (Deletes named pipes) */ -int FIFO_Relink(tVFS_Node *Node, char *OldName, char *NewName) +int FIFO_Relink(tVFS_Node *Node, const char *OldName, const char *NewName) { tPipe *pipe, *tmp; diff --git a/Kernel/drv/pci.c b/Kernel/drv/pci.c index 92608474..b4881d3b 100644 --- a/Kernel/drv/pci.c +++ b/Kernel/drv/pci.c @@ -34,10 +34,10 @@ typedef struct sPCIDevice // === PROTOTYPES === int PCI_Install(char **Arguments); - int PCI_ScanBus(int ID); + int PCI_ScanBus(int ID, int bFill); char *PCI_ReadDirRoot(tVFS_Node *node, int pos); -tVFS_Node *PCI_FindDirRoot(tVFS_Node *node, char *filename); +tVFS_Node *PCI_FindDirRoot(tVFS_Node *node, const char *filename); Uint64 PCI_ReadDevice(tVFS_Node *node, Uint64 pos, Uint64 length, void *buffer); int PCI_CountDevices(Uint16 vendor, Uint16 device, Uint16 fcn); @@ -99,8 +99,8 @@ int PCI_Install(char **Arguments) for( i = 0; i < MAX_RESERVED_PORT % 32; i ++ ) gaPCI_PortBitmap[MAX_RESERVED_PORT / 32] = 1 << i; - // Scan Bus - i = PCI_ScanBus(0); + // Scan Bus (Bus 0, Don't fill gPCI_Devices) + i = PCI_ScanBus(0, 0); if(i != MODULE_ERR_OK) return i; if(giPCI_DeviceCount == 0) { @@ -108,12 +108,23 @@ int PCI_Install(char **Arguments) return MODULE_ERR_NOTNEEDED; } - // Ensure the buffer is nice and tight - tmpPtr = realloc(gPCI_Devices, giPCI_DeviceCount*sizeof(tPCIDevice)); - if(tmpPtr == NULL) + // Allocate device buffer + tmpPtr = malloc(giPCI_DeviceCount * sizeof(tPCIDevice)); + if(tmpPtr == NULL) { + Log_Warning("PCI", "Malloc ERROR"); return MODULE_ERR_MALLOC; + } gPCI_Devices = tmpPtr; + Log_Log("PCI", "%i devices, filling structure"); + + // Reset counts + giPCI_DeviceCount = 0; + giPCI_BusCount = 0; + memset(gaPCI_BusBitmap, 0, sizeof(gaPCI_BusBitmap)); + // Rescan, filling the PCI device array + PCI_ScanBus(0, 1); + // Complete Driver Structure gPCI_DriverStruct.RootNode.Size = giPCI_DeviceCount; @@ -125,12 +136,13 @@ int PCI_Install(char **Arguments) /** * \brief Scans a specific PCI Bus + * \param BusID PCI Bus ID to scan + * \param bFill Fill the \a gPCI_Devices array? */ -int PCI_ScanBus(int BusID) +int PCI_ScanBus(int BusID, int bFill) { int dev, fcn; tPCIDevice devInfo; - void *tmpPtr = NULL; if( gaPCI_BusBitmap[BusID/32] & (1 << (BusID%32)) ) return MODULE_ERR_OK; @@ -145,12 +157,6 @@ int PCI_ScanBus(int BusID) if(!PCI_EnumDevice(BusID, dev, fcn, &devInfo)) continue; - // Allocate - tmpPtr = realloc(gPCI_Devices, (giPCI_DeviceCount+1)*sizeof(tPCIDevice)); - if(tmpPtr == NULL) - return MODULE_ERR_MALLOC; - gPCI_Devices = tmpPtr; - if(devInfo.oc == PCI_OC_PCIBRIDGE) { #if LIST_DEVICES @@ -158,8 +164,8 @@ int PCI_ScanBus(int BusID) BusID, dev, fcn, devInfo.vendor, devInfo.device); #endif //TODO: Handle PCI-PCI Bridges - //PCI_ScanBus( ); - giPCI_BusCount++; + //PCI_ScanBus(devInfo.???, bFill); + giPCI_BusCount ++; } else { @@ -169,8 +175,10 @@ int PCI_ScanBus(int BusID) #endif } - devInfo.Node.Inode = giPCI_DeviceCount; - memcpy(&gPCI_Devices[giPCI_DeviceCount], &devInfo, sizeof(tPCIDevice)); + if( bFill ) { + devInfo.Node.Inode = giPCI_DeviceCount; + memcpy(&gPCI_Devices[giPCI_DeviceCount], &devInfo, sizeof(tPCIDevice)); + } giPCI_DeviceCount ++; // WTF is this for? @@ -202,9 +210,9 @@ char *PCI_ReadDirRoot(tVFS_Node *Node, int Pos) return strdup( gPCI_Devices[Pos].Name ); } /** - * \fn tVFS_Node *PCI_FindDirRoot(tVFS_Node *node, char *filename) + * \fn tVFS_Node *PCI_FindDirRoot(tVFS_Node *node, const char *filename) */ -tVFS_Node *PCI_FindDirRoot(tVFS_Node *node, char *filename) +tVFS_Node *PCI_FindDirRoot(tVFS_Node *node, const char *filename) { int bus,slot,fcn; int i; diff --git a/Kernel/drv/proc.c b/Kernel/drv/proc.c index 521bb055..cf19a66a 100644 --- a/Kernel/drv/proc.c +++ b/Kernel/drv/proc.c @@ -31,7 +31,7 @@ typedef struct sSysFS_Ent int SysFS_RemoveFile(int ID); char *SysFS_Comm_ReadDir(tVFS_Node *Node, int Id); -tVFS_Node *SysFS_Comm_FindDir(tVFS_Node *Node, char *Filename); +tVFS_Node *SysFS_Comm_FindDir(tVFS_Node *Node, const char *Filename); Uint64 SysFS_Comm_ReadFile(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer); void SysFS_Comm_CloseFile(tVFS_Node *Node); @@ -322,10 +322,10 @@ char *SysFS_Comm_ReadDir(tVFS_Node *Node, int Pos) } /** - * \fn tVFS_Node *SysFS_Comm_FindDir(tVFS_Node *Node, char *Filename) + * \fn tVFS_Node *SysFS_Comm_FindDir(tVFS_Node *Node, const char *Filename) * \brief Find a file in a SysFS directory */ -tVFS_Node *SysFS_Comm_FindDir(tVFS_Node *Node, char *Filename) +tVFS_Node *SysFS_Comm_FindDir(tVFS_Node *Node, const char *Filename) { tSysFS_Ent *child = (tSysFS_Ent*)Node->ImplPtr; diff --git a/Kernel/drv/vterm.c b/Kernel/drv/vterm.c index 094903cd..da82d674 100644 --- a/Kernel/drv/vterm.c +++ b/Kernel/drv/vterm.c @@ -71,7 +71,7 @@ extern void Debug_SetKTerminal(char *File); void VT_InitOutput(void); void VT_InitInput(void); char *VT_ReadDir(tVFS_Node *Node, int Pos); -tVFS_Node *VT_FindDir(tVFS_Node *Node, char *Name); +tVFS_Node *VT_FindDir(tVFS_Node *Node, const char *Name); int VT_Root_IOCtl(tVFS_Node *Node, int Id, void *Data); Uint64 VT_Read(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer); Uint64 VT_Write(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer); @@ -324,12 +324,12 @@ char *VT_ReadDir(tVFS_Node *Node, int Pos) } /** - * \fn tVFS_Node *VT_FindDir(tVFS_Node *Node, char *Name) + * \fn tVFS_Node *VT_FindDir(tVFS_Node *Node, const char *Name) * \brief Find an item in the VTerm directory * \param Node Root node * \param Name Name (number) of the terminal */ -tVFS_Node *VT_FindDir(tVFS_Node *Node, char *Name) +tVFS_Node *VT_FindDir(tVFS_Node *Node, const char *Name) { int num; diff --git a/Kernel/heap.c b/Kernel/heap.c index 5e6ccfe6..97f2d9f1 100644 --- a/Kernel/heap.c +++ b/Kernel/heap.c @@ -4,27 +4,33 @@ */ #include #include -#include +#include #define WARNINGS 1 #define DEBUG_TRACE 0 // === CONSTANTS === #define HEAP_INIT_SIZE 0x8000 // 32 KiB -#define BLOCK_SIZE (sizeof(void*))*8 // 8 Machine Words +#define MIN_SIZE (sizeof(void*))*8 // 8 Machine Words +#define POW2_SIZES 0 #define COMPACT_HEAP 0 // Use 4 byte header? #define FIRST_FIT 0 -#define MAGIC_FOOT 0x2ACE5505 -#define MAGIC_FREE 0xACE55000 -#define MAGIC_USED 0x862B0505 // MAGIC_FOOT ^ MAGIC_FREE +//#define MAGIC_FOOT 0x2ACE5505 +//#define MAGIC_FREE 0xACE55000 +//#define MAGIC_USED 0x862B0505 // MAGIC_FOOT ^ MAGIC_FREE +#define MAGIC_FOOT 0x544F4F46 // 'FOOT' +#define MAGIC_FREE 0x45455246 // 'FREE' +#define MAGIC_USED 0x44455355 // 'USED' // === PROTOTYPES === void Heap_Install(void); void *Heap_Extend(int Bytes); void *Heap_Merge(tHeapHead *Head); -void *malloc(size_t Bytes); -void free(void *Ptr); +void *Heap_Allocate(const char *File, int Line, size_t Bytes); +void *Heap_AllocateZero(const char *File, int Line, size_t Bytes); +void *Heap_Reallocate(const char *File, int Line, void *Ptr, size_t Bytes); +void Heap_Deallocate(void *Ptr); void Heap_Dump(void); void Heap_Stats(void); @@ -124,10 +130,12 @@ void *Heap_Merge(tHeapHead *Head) } /** - * \fn void *malloc(size_t Bytes) * \brief Allocate memory from the heap + * \param File Allocating source file + * \param Line Source line + * \param Bytes Size of region to allocate */ -void *malloc(size_t Bytes) +void *Heap_Allocate(const char *File, int Line, size_t Bytes) { tHeapHead *head, *newhead; tHeapFoot *foot, *newfoot; @@ -135,7 +143,12 @@ void *malloc(size_t Bytes) Uint bestSize = 0; // Speed hack // Get required size - Bytes = (Bytes + sizeof(tHeapHead) + sizeof(tHeapFoot) + BLOCK_SIZE-1) & ~(BLOCK_SIZE-1); + #if POW2_SIZES + Bytes = Bytes + sizeof(tHeapHead) + sizeof(tHeapFoot); + Bytes = 1UUL << LOG2(Bytes); + #else + Bytes = (Bytes + sizeof(tHeapHead) + sizeof(tHeapFoot) + MIN_SIZE-1) & ~(MIN_SIZE-1); + #endif // Lock Heap LOCK(&glHeap); @@ -147,7 +160,11 @@ void *malloc(size_t Bytes) ) { // Alignment Check - if( head->Size & (BLOCK_SIZE-1) ) { + #if POW2_SIZES + if( head->Size != 1UUL << LOG2(head->Size) ) { + #else + if( head->Size & (MIN_SIZE-1) ) { + #endif RELEASE(&glHeap); // Release spinlock #if WARNINGS Log_Warning("Heap", "Size of heap address %p is invalid not aligned (0x%x)", head, head->Size); @@ -174,6 +191,8 @@ void *malloc(size_t Bytes) // Perfect fit if(head->Size == Bytes) { head->Magic = MAGIC_USED; + head->File = File; + head->Line = Line; RELEASE(&glHeap); // Release spinlock #if DEBUG_TRACE Log("[Heap ] Malloc'd %p (%i bytes), returning to %p", head->Data, head->Size, __builtin_return_address(0)); @@ -207,6 +226,8 @@ void *malloc(size_t Bytes) // Check size if(best->Size == Bytes) { best->Magic = MAGIC_USED; // Mark block as used + best->File = File; + best->Line = Line; RELEASE(&glHeap); // Release spinlock #if DEBUG_TRACE Log("[Heap ] Malloc'd %p (%i bytes), returning to %p", best->Data, best->Size, __builtin_return_address(0)); @@ -227,19 +248,23 @@ void *malloc(size_t Bytes) foot->Head = newhead; // Update backlink in old footer best->Size = Bytes; // Update size in old header best->Magic = MAGIC_USED; // Mark block as used + best->File = File; + best->Line = Line; RELEASE(&glHeap); // Release spinlock #if DEBUG_TRACE - Log("[Heap ] Malloc'd %p (%i bytes), returning to %p", best->Data, best->Size, __builtin_return_address(0)); + Log_Debug("Heap", "newhead(%p)->Size = 0x%x", newhead, newhead->Size); + Log_Debug("Heap", "Malloc'd %p (0x%x bytes), returning to %s:%i", + best->Data, best->Size, File, Line); #endif return best->Data; } /** - * \fn void free(void *Ptr) + * \fn void Heap_Deallocate(void *Ptr) * \brief Free an allocated memory block */ -void free(void *Ptr) +void Heap_Deallocate(void *Ptr) { tHeapHead *head; tHeapFoot *foot; @@ -270,18 +295,21 @@ void free(void *Ptr) return; } if(head->Magic != MAGIC_USED) { - Log_Warning("Heap", "free - Magic value is invalid (%p, 0x%x)\n", head, head->Magic); + Log_Warning("Heap", "free - Magic value is invalid (%p, 0x%x)", head, head->Magic); + Log_Notice("Heap", "Allocated %s:%i", head->File, head->Line); return; } // Check memory block - Footer foot = (void*)( (Uint)head + head->Size - sizeof(tHeapFoot) ); if(foot->Head != head) { - Log_Warning("Heap", "free - Footer backlink is incorrect (%p, 0x%x)\n", head, foot->Head); + Log_Warning("Heap", "free - Footer backlink is incorrect (%p, 0x%x)", head, foot->Head); + Log_Notice("Heap", "Allocated %s:%i", head->File, head->Line); return; } if(foot->Magic != MAGIC_FOOT) { - Log_Warning("Heap", "free - Footer magic is invalid (%p, %p = 0x%x)\n", head, &foot->Magic, foot->Magic); + Log_Warning("Heap", "free - Footer magic is invalid (%p, %p = 0x%x)", head, &foot->Magic, foot->Magic); + Log_Notice("Heap", "Allocated %s:%i", head->File, head->Line); return; } @@ -299,15 +327,15 @@ void free(void *Ptr) /** */ -void *realloc(void *__ptr, size_t __size) +void *Heap_Reallocate(const char *File, int Line, void *__ptr, size_t __size) { tHeapHead *head = (void*)( (Uint)__ptr-8 ); tHeapHead *nextHead; tHeapFoot *foot; - Uint newSize = (__size + sizeof(tHeapFoot)+sizeof(tHeapHead)+BLOCK_SIZE-1)&~(BLOCK_SIZE-1); + Uint newSize = (__size + sizeof(tHeapFoot)+sizeof(tHeapHead)+MIN_SIZE-1)&~(MIN_SIZE-1); // Check for reallocating NULL - if(__ptr == NULL) return malloc(__size); + if(__ptr == NULL) return Heap_Allocate(File, Line, __size); // Check if resize is needed if(newSize <= head->Size) return __ptr; @@ -323,6 +351,8 @@ void *realloc(void *__ptr, size_t __size) // Exact Fit if(size == newSize) { head->Size = newSize; + head->File = File; + head->Line = Line; foot->Head = head; nextHead->Magic = 0; nextHead->Size = 0; @@ -334,6 +364,8 @@ void *realloc(void *__ptr, size_t __size) nextHead->Magic = MAGIC_FREE; foot->Head = nextHead; // Edit 2nd footer head->Size = newSize; // Edit first header + head->File = File; + head->Line = Line; // Create new footer foot = (void*)( (Uint)head + newSize - sizeof(tHeapFoot) ); foot->Head = head; @@ -361,6 +393,8 @@ void *realloc(void *__ptr, size_t __size) // Set 1st (new/lower) header nextHead->Magic = MAGIC_USED; nextHead->Size = newSize; + nextHead->File = File; + nextHead->Line = Line; // Get 2nd (old) footer foot = (void*)( (Uint)nextHead + newSize ); foot->Head = nextHead; @@ -378,8 +412,10 @@ void *realloc(void *__ptr, size_t __size) } // Well, darn - nextHead = malloc( __size ); + nextHead = Heap_Allocate( File, Line, __size ); nextHead -= 1; + nextHead->File = File; + nextHead->Line = Line; memcpy( nextHead->Data, @@ -393,26 +429,27 @@ void *realloc(void *__ptr, size_t __size) } /** - * \fn void *calloc(size_t num, size_t size) + * \fn void *Heap_AllocateZero(const char *File, int Line, size_t size) * \brief Allocate and Zero a buffer in memory - * \param num Number of elements - * \param size Size of each element + * \param File Allocating file + * \param Line Line of allocation + * \param size Size of the allocation */ -void *calloc(size_t num, size_t size) +void *Heap_AllocateZero(const char *File, int Line, size_t size) { - void *ret = malloc(num*size); + void *ret = Heap_Allocate(File, Line, size); if(ret == NULL) return NULL; - memset( ret, 0, num*size ); + memset( ret, 0, size ); return ret; } /** - * \fn int IsHeap(void *Ptr) + * \fn int Heap_IsHeapAddr(void *Ptr) * \brief Checks if an address is a heap pointer */ -int IsHeap(void *Ptr) +int Heap_IsHeapAddr(void *Ptr) { tHeapHead *head; if((Uint)Ptr < (Uint)gHeapStart) return 0; @@ -429,16 +466,20 @@ int IsHeap(void *Ptr) #if WARNINGS void Heap_Dump(void) { - tHeapHead *head; + tHeapHead *head, *badHead; tHeapFoot *foot; head = gHeapStart; while( (Uint)head < (Uint)gHeapEnd ) { foot = (void*)( (Uint)head + head->Size - sizeof(tHeapFoot) ); - Log_Log("Heap", "%p (0x%x): 0x%08lx 0x%lx", - head, MM_GetPhysAddr((Uint)head), head->Size, head->Magic); - Log_Log("Heap", "%p 0x%lx", foot->Head, foot->Magic); + Log_Log("Heap", "%p (0x%llx): 0x%08lx %4C", + head, MM_GetPhysAddr((Uint)head), head->Size, &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", ""); // Sanity Check Header @@ -446,7 +487,7 @@ void Heap_Dump(void) Log_Warning("Heap", "HALTED - Size is zero"); break; } - if(head->Size & (BLOCK_SIZE-1)) { + if(head->Size & (MIN_SIZE-1)) { Log_Warning("Heap", "HALTED - Size is malaligned"); break; } @@ -468,6 +509,59 @@ void Heap_Dump(void) // All OK? Go to next head = foot->NextHead; } + + // Check for a bad return + if( (tVAddr)head >= (tVAddr)gHeapEnd ) + return ; + + badHead = head; + + Log_Log("Heap", "==== Going Backwards ==== (from %p)", badHead); + + // Work backwards + foot = (void*)( (tVAddr)gHeapEnd - sizeof(tHeapFoot) ); + head = foot->Head; + while( (tVAddr)head >= (tVAddr)badHead ) + { + Log_Log("Heap", "%p (0x%llx): 0x%08lx %4C", + head, MM_GetPhysAddr((Uint)head), head->Size, &head->Magic); + Log_Log("Heap", "%p %4C", foot->Head, &foot->Magic); + if(head->File) + Log_Log("Heap", "%sowned by %s:%i", + (head->Magic!=MAGIC_USED?"was ":""), + head->File, head->Line); + Log_Log("Heap", ""); + + // Sanity Check Header + if(head->Size == 0) { + Log_Warning("Heap", "HALTED - Size is zero"); + break; + } + if(head->Size & (MIN_SIZE-1)) { + Log_Warning("Heap", " - Size is malaligned (&0x%x)", ~(MIN_SIZE-1)); + break ; + } + if(head->Magic != MAGIC_FREE && head->Magic != MAGIC_USED) { + Log_Warning("Heap", "HALTED - Head Magic is Bad"); + break; + } + + // Check footer + if(foot->Magic != MAGIC_FOOT) { + Log_Warning("Heap", "HALTED - Foot Magic is Bad"); + break; + } + if(head != foot->Head) { + Log_Warning("Heap", "HALTED - Footer backlink is invalid"); + break; + } + + if(head == badHead) break; + + foot = (void*)( (tVAddr)head - sizeof(tHeapFoot) ); + head = foot->Head; + Log_Debug("Heap", "head=%p", head); + } } #endif @@ -486,7 +580,7 @@ void Heap_Stats(void) (Uint)head < (Uint)gHeapEnd; head = (void*)( (Uint)head + head->Size ) ) - { + { nBlocks ++; totalBytes += head->Size; if( head->Magic == MAGIC_FREE ) @@ -494,11 +588,21 @@ void Heap_Stats(void) nFree ++; freeBytes += head->Size; } - else { + else if( head->Magic == MAGIC_USED) { if(maxAlloc < head->Size) maxAlloc = head->Size; if(minAlloc == -1 || minAlloc > head->Size) minAlloc = head->Size; } + else { + Log_Warning("Heap", "Magic on %p invalid, skipping remainder of heap", head); + break; + } + + // Print the block info? + #if 1 + Log_Debug("Heap", "%p - 0x%x Owned by %s:%i", + head, head->Size, head->File, head->Line); + #endif } Log_Log("Heap", "%i blocks (0x%x bytes)", nBlocks, totalBytes); @@ -560,6 +664,8 @@ void Heap_Stats(void) #endif // === EXPORTS === -EXPORT(malloc); -EXPORT(realloc); -EXPORT(free); +EXPORT(Heap_Allocate); +EXPORT(Heap_AllocateZero); +EXPORT(Heap_Reallocate); +EXPORT(Heap_Deallocate); +EXPORT(Heap_IsHeapAddr); diff --git a/Kernel/include/acess.h b/Kernel/include/acess.h index 5708ad2e..f6f87f70 100644 --- a/Kernel/include/acess.h +++ b/Kernel/include/acess.h @@ -339,18 +339,7 @@ extern Uint rand(void); extern int CallWithArgArray(void *Function, int NArgs, Uint *Args); // --- Heap --- -/** - * \name Heap - * \{ - */ -extern void *malloc(size_t size); -extern void *calloc(size_t num, size_t size); -extern void *realloc(void *ptr, size_t size); -extern void free(void *Ptr); -extern int IsHeap(void *Ptr); -/** - * \} - */ +#include // --- Modules --- /** diff --git a/Kernel/include/heap.h b/Kernel/include/heap.h index 1b883eb4..38a3f1d0 100644 --- a/Kernel/include/heap.h +++ b/Kernel/include/heap.h @@ -1,20 +1,22 @@ -/* - * AcessOS Microkernel Version +/** + * Acess2 Kernel * heap.h + * - Dynamic Memory Allocation exports */ -#ifndef _HEAP_H -#define _HEAP_H -typedef struct { - Uint Size; - Uint Magic; - char Data[]; -} tHeapHead; +#ifndef _HEAP_H_ +#define _HEAP_H_ -typedef struct { - Uint Magic; - tHeapHead *Head; - tHeapHead NextHead[]; // Array to make it act like an element, but have no size and refer to the next block -} tHeapFoot; +extern void *Heap_Allocate(const char *File, int Line, size_t Bytes); +extern void *Heap_AllocateZero(const char *File, int Line, size_t Bytes); +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); + +#define malloc(size) Heap_Allocate(_MODULE_NAME_"/"__FILE__, __LINE__, (size)) +#define calloc(num,size) Heap_AllocateZero(_MODULE_NAME_"/"__FILE__, __LINE__, (num)*(size)) +#define realloc(ptr,size) Heap_Reallocate(_MODULE_NAME_"/"__FILE__, __LINE__, (ptr), (size)) +#define free(ptr) Heap_Deallocate((ptr)) +#define IsHeap(ptr) Heap_IsHeapAddr((ptr)) #endif diff --git a/Kernel/include/vfs.h b/Kernel/include/vfs.h index f6659430..4f1fc66e 100644 --- a/Kernel/include/vfs.h +++ b/Kernel/include/vfs.h @@ -206,7 +206,7 @@ typedef struct sVFS_Node * \note The node returned must be accessable until ::tVFS_Node.Close * is called and ReferenceCount reaches zero. */ - struct sVFS_Node *(*FindDir)(struct sVFS_Node *Node, char *Name); + struct sVFS_Node *(*FindDir)(struct sVFS_Node *Node, const char *Name); /** * \brief Read from a directory @@ -227,7 +227,7 @@ typedef struct sVFS_Node * \param Flags Flags to apply to the new child (directory or symlink) * \return Zero on Success, non-zero on error (see errno.h) */ - int (*MkNod)(struct sVFS_Node *Node, char *Name, Uint Flags); + int (*MkNod)(struct sVFS_Node *Node, const char *Name, Uint Flags); /** * \brief Relink (Rename/Remove) a file/directory @@ -236,7 +236,7 @@ typedef struct sVFS_Node * \param NewName New name (or NULL if unlinking is wanted) * \return Zero on Success, non-zero on error (see errno.h) */ - int (*Relink)(struct sVFS_Node *Node, char *OldName, char *NewName); + int (*Relink)(struct sVFS_Node *Node, const char *OldName, const char *NewName); /** * \brief Link a node to a name @@ -245,7 +245,7 @@ typedef struct sVFS_Node * \param NewName Name for the new link * \return Zeron on success, non-zero on error (see errno.h) */ - int (*Link)(struct sVFS_Node *Node, struct sVFS_Node *Child, char *NewName); + int (*Link)(struct sVFS_Node *Node, struct sVFS_Node *Child, const char *NewName); /** * \} diff --git a/Kernel/include/vfs_int.h b/Kernel/include/vfs_int.h index e5480623..d4a533da 100644 --- a/Kernel/include/vfs_int.h +++ b/Kernel/include/vfs_int.h @@ -40,8 +40,8 @@ extern tVFS_Mount *gVFS_Mounts; // === PROTOTYPES === // --- OPEN.C --- -extern char *VFS_GetAbsPath(char *Path); -extern tVFS_Node *VFS_ParsePath(char *Path, char **TruePath); +extern char *VFS_GetAbsPath(const char *Path); +extern tVFS_Node *VFS_ParsePath(const char *Path, char **TruePath); extern tVFS_Handle *VFS_GetHandle(int FD); // --- ACLS.C --- extern int VFS_CheckACL(tVFS_Node *Node, Uint Permissions); diff --git a/Kernel/vfs/fs/devfs.c b/Kernel/vfs/fs/devfs.c index b7379ad5..13fe1099 100644 --- a/Kernel/vfs/fs/devfs.c +++ b/Kernel/vfs/fs/devfs.c @@ -12,7 +12,7 @@ void DevFS_DelDevice(tDevFS_Driver *Device); tVFS_Node *DevFS_InitDevice(char *Device, char **Options); char *DevFS_ReadDir(tVFS_Node *Node, int Pos); -tVFS_Node *DevFS_FindDir(tVFS_Node *Node, char *Name); +tVFS_Node *DevFS_FindDir(tVFS_Node *Node, const char *Name); // === GLOBALS === tVFS_Driver gDevFS_Info = { @@ -131,7 +131,7 @@ char *DevFS_ReadDir(tVFS_Node *Node, int Pos) * \fn tVFS_Node *DevFS_FindDir(tVFS_Node *Node, char *Name) * \brief Get an entry from the devices directory */ -tVFS_Node *DevFS_FindDir(tVFS_Node *Node, char *Name) +tVFS_Node *DevFS_FindDir(tVFS_Node *Node, const char *Name) { tDevFS_Driver *dev; diff --git a/Kernel/vfs/fs/root.c b/Kernel/vfs/fs/root.c index c613cfd5..d9660419 100644 --- a/Kernel/vfs/fs/root.c +++ b/Kernel/vfs/fs/root.c @@ -11,8 +11,8 @@ // === PROTOTYPES === tVFS_Node *Root_InitDevice(char *Device, char **Options); - int Root_MkNod(tVFS_Node *Node, char *Name, Uint Flags); -tVFS_Node *Root_FindDir(tVFS_Node *Node, char *Name); + int Root_MkNod(tVFS_Node *Node, const char *Name, Uint Flags); +tVFS_Node *Root_FindDir(tVFS_Node *Node, const char *Name); char *Root_ReadDir(tVFS_Node *Node, int Pos); Uint64 Root_Read(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer); Uint64 Root_Write(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer); @@ -67,10 +67,10 @@ tVFS_Node *Root_InitDevice(char *Device, char **Options) } /** - * \fn int Root_MkNod(tVFS_Node *Node, char *Name, Uint Flags) + * \fn int Root_MkNod(tVFS_Node *Node, const char *Name, Uint Flags) * \brief Create an entry in the root directory */ -int Root_MkNod(tVFS_Node *Node, char *Name, Uint Flags) +int Root_MkNod(tVFS_Node *Node, const char *Name, Uint Flags) { tRamFS_File *parent = Node->ImplPtr; tRamFS_File *child = parent->Data.FirstChild; @@ -126,10 +126,10 @@ int Root_MkNod(tVFS_Node *Node, char *Name, Uint Flags) } /** - * \fn tVFS_Node *Root_FindDir(tVFS_Node *Node, char *Name) + * \fn tVFS_Node *Root_FindDir(tVFS_Node *Node, const char *Name) * \brief Find an entry in the filesystem */ -tVFS_Node *Root_FindDir(tVFS_Node *Node, char *Name) +tVFS_Node *Root_FindDir(tVFS_Node *Node, const char *Name) { tRamFS_File *parent = Node->ImplPtr; tRamFS_File *child = parent->Data.FirstChild; diff --git a/Kernel/vfs/memfile.c b/Kernel/vfs/memfile.c index 3c756713..941fcfe2 100644 --- a/Kernel/vfs/memfile.c +++ b/Kernel/vfs/memfile.c @@ -7,7 +7,7 @@ #include // === PROTOTYPES === -tVFS_Node *VFS_MemFile_Create(tVFS_Node *Unused, char *Path); +tVFS_Node *VFS_MemFile_Create(tVFS_Node *Unused, const char *Path); void VFS_MemFile_Close(tVFS_Node *Node); Uint64 VFS_MemFile_Read(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer); Uint64 VFS_MemFile_Write(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer); @@ -21,13 +21,13 @@ tVFS_Node gVFS_MemRoot = { // === CODE === /** - * \fn tVFS_Node *VFS_MemFile_Create(tVFS_Node *Unused, char *Path) + * \fn tVFS_Node *VFS_MemFile_Create(tVFS_Node *Unused, const char *Path) * \note Treated as finddir by VFS_ParsePath */ -tVFS_Node *VFS_MemFile_Create(tVFS_Node *Unused, char *Path) +tVFS_Node *VFS_MemFile_Create(tVFS_Node *Unused, const char *Path) { Uint base, size; - char *str = Path; + const char *str = Path; tVFS_Node *ret; str++; // Eat '$' diff --git a/Kernel/vfs/open.c b/Kernel/vfs/open.c index 552276d9..a396465b 100644 --- a/Kernel/vfs/open.c +++ b/Kernel/vfs/open.c @@ -24,10 +24,10 @@ tVFS_Handle *gaKernelHandles = (void*)MM_KERNEL_VFS; // === CODE === /** - * \fn char *VFS_GetAbsPath(char *Path) + * \fn char *VFS_GetAbsPath(const char *Path) * \brief Create an absolute path from a relative one */ -char *VFS_GetAbsPath(char *Path) +char *VFS_GetAbsPath(const char *Path) { char *ret; int pathLen = strlen(Path); @@ -170,7 +170,7 @@ char *VFS_GetAbsPath(char *Path) * \fn char *VFS_ParsePath(char *Path, char **TruePath) * \brief Parses a path, resolving sysmlinks and applying permissions */ -tVFS_Node *VFS_ParsePath(char *Path, char **TruePath) +tVFS_Node *VFS_ParsePath(const char *Path, char **TruePath) { tVFS_Mount *mnt; tVFS_Mount *longestMount = gVFS_RootMount; // Root is first @@ -260,13 +260,15 @@ tVFS_Node *VFS_ParsePath(char *Path, char **TruePath) curNode->ReferenceCount ++; // Parse Path ofs = mnt->MountPointLen+1; - for(; (nextSlash = strpos(&Path[ofs], '/')) != -1; Path[nextSlash]='/',ofs = nextSlash + 1) + for(; (nextSlash = strpos(&Path[ofs], '/')) != -1; ofs = nextSlash + 1) { - nextSlash += ofs; - Path[nextSlash] = '\0'; - - // Check for empty string - if( Path[ofs] == '\0' ) continue; + char pathEle[nextSlash+1]; + + // Empty String + if(nextSlash == 0) continue; + + memcpy(pathEle, &Path[ofs], nextSlash); + pathEle[nextSlash] = 0; // Check permissions on root of filesystem if( !VFS_CheckACL(curNode, VFS_PERM_EXECUTE) ) { @@ -288,27 +290,25 @@ tVFS_Node *VFS_ParsePath(char *Path, char **TruePath) free(*TruePath); *TruePath = NULL; } - Path[nextSlash] = '/'; //Log("FindDir fail on '%s'", Path); LEAVE('n'); return NULL; } - LOG("FindDir(%p, '%s')", curNode, &Path[ofs]); + LOG("FindDir(%p, '%s')", curNode, pathEle); // Get Child Node - tmpNode = curNode->FindDir(curNode, &Path[ofs]); + tmpNode = curNode->FindDir(curNode, pathEle); LOG("tmpNode = %p", tmpNode); if(curNode->Close) curNode->Close(curNode); curNode = tmpNode; // Error Check if(!curNode) { - LOG("Node '%s' not found in dir '%s'", &Path[ofs], Path); + LOG("Node '%s' not found in dir '%s'", pathEle, Path); if(TruePath) { free(*TruePath); *TruePath = NULL; } - //Log("Child fail on '%s' ('%s)", Path, &Path[ofs]); - Path[nextSlash] = '/'; + //Log("Child fail on '%s' ('%s)", Path, pathEle); LEAVE('n'); return NULL; } @@ -332,6 +332,8 @@ tVFS_Node *VFS_ParsePath(char *Path, char **TruePath) // Parse Symlink Path curNode = VFS_ParsePath(tmp, TruePath); + if(TruePath) + Log_Debug("VFS", "*TruePath='%s'", *TruePath); // Error Check if(!curNode) { @@ -341,12 +343,12 @@ tVFS_Node *VFS_ParsePath(char *Path, char **TruePath) return NULL; } + // Free temp link + free(tmp); + // Set Path Variable if(TruePath) { - *TruePath = tmp; - retLength = strlen(tmp); - } else { - free(tmp); // Free temp string + retLength = strlen(*TruePath); } continue; @@ -377,9 +379,9 @@ tVFS_Node *VFS_ParsePath(char *Path, char **TruePath) *TruePath = tmp; // Append to path (*TruePath)[retLength] = '/'; - strcpy(*TruePath+retLength+1, &Path[ofs]); + strcpy(*TruePath+retLength+1, pathEle); // - Extend Path - retLength += strlen(&Path[ofs])+1; + retLength += nextSlash; } // Get last node diff --git a/Modules/Filesystems/Ext2/dir.c b/Modules/Filesystems/Ext2/dir.c index 0cadca2b..99e787e8 100644 --- a/Modules/Filesystems/Ext2/dir.c +++ b/Modules/Filesystems/Ext2/dir.c @@ -16,10 +16,10 @@ // === PROTOTYPES === char *Ext2_ReadDir(tVFS_Node *Node, int Pos); -tVFS_Node *Ext2_FindDir(tVFS_Node *Node, char *FileName); - int Ext2_MkNod(tVFS_Node *Node, char *Name, Uint Flags); - int Ext2_Relink(tVFS_Node *Node, char *OldName, char *NewName); - int Ext2_Link(tVFS_Node *Parent, tVFS_Node *Node, char *Name); +tVFS_Node *Ext2_FindDir(tVFS_Node *Node, const char *FileName); + int Ext2_MkNod(tVFS_Node *Node, const char *Name, Uint Flags); + int Ext2_Relink(tVFS_Node *Node, const char *OldName, const char *NewName); + int Ext2_Link(tVFS_Node *Parent, tVFS_Node *Node, const char *Name); // --- Helpers --- tVFS_Node *Ext2_int_CreateNode(tExt2_Disk *Disk, Uint InodeId); @@ -103,7 +103,7 @@ char *Ext2_ReadDir(tVFS_Node *Node, int Pos) * \param Filename Name of wanted file * \return VFS Node of file */ -tVFS_Node *Ext2_FindDir(tVFS_Node *Node, char *Filename) +tVFS_Node *Ext2_FindDir(tVFS_Node *Node, const char *Filename) { tExt2_Disk *disk = Node->ImplPtr; tExt2_Inode inode; @@ -151,10 +151,10 @@ tVFS_Node *Ext2_FindDir(tVFS_Node *Node, char *Filename) } /** - * \fn int Ext2_MkNod(tVFS_Node *Parent, char *Name, Uint Flags) + * \fn int Ext2_MkNod(tVFS_Node *Parent, const char *Name, Uint Flags) * \brief Create a new node */ -int Ext2_MkNod(tVFS_Node *Parent, char *Name, Uint Flags) +int Ext2_MkNod(tVFS_Node *Parent, const char *Name, Uint Flags) { #if 0 tVFS_Node *child; @@ -193,7 +193,7 @@ int Ext2_MkNod(tVFS_Node *Parent, char *Name, Uint Flags) * \param NewName New name for file * \return Boolean Failure - See ::tVFS_Node.Relink for info */ -int Ext2_Relink(tVFS_Node *Node, char *OldName, char *NewName) +int Ext2_Relink(tVFS_Node *Node, const char *OldName, const char *NewName) { return 1; } @@ -205,7 +205,7 @@ int Ext2_Relink(tVFS_Node *Node, char *OldName, char *NewName) * \param Name New name for the node * \return Boolean Failure - See ::tVFS_Node.Link for info */ -int Ext2_Link(tVFS_Node *Node, tVFS_Node *Child, char *Name) +int Ext2_Link(tVFS_Node *Node, tVFS_Node *Child, const char *Name) { #if 0 tExt2_Disk *disk = Node->ImplPtr; diff --git a/Modules/Filesystems/Ext2/ext2_common.h b/Modules/Filesystems/Ext2/ext2_common.h index 25d296c8..be4ae392 100644 --- a/Modules/Filesystems/Ext2/ext2_common.h +++ b/Modules/Filesystems/Ext2/ext2_common.h @@ -36,9 +36,9 @@ extern int Ext2_int_ReadInode(tExt2_Disk *Disk, Uint32 InodeId, tExt2_Inode *Ino extern int Ext2_int_WriteInode(tExt2_Disk *Disk, Uint32 InodeId, tExt2_Inode *Inode); // --- Dir --- extern char *Ext2_ReadDir(tVFS_Node *Node, int Pos); -extern tVFS_Node *Ext2_FindDir(tVFS_Node *Node, char *FileName); -extern int Ext2_MkNod(tVFS_Node *Node, char *Name, Uint Flags); -extern int Ext2_Link(tVFS_Node *Parent, tVFS_Node *Node, char *Name); +extern tVFS_Node *Ext2_FindDir(tVFS_Node *Node, const char *FileName); +extern int Ext2_MkNod(tVFS_Node *Node, const char *Name, Uint Flags); +extern int Ext2_Link(tVFS_Node *Parent, tVFS_Node *Node, const char *Name); // --- Read --- extern Uint64 Ext2_Read(tVFS_Node *node, Uint64 offset, Uint64 length, void *buffer); // --- Write --- diff --git a/Modules/Filesystems/FAT/fat.c b/Modules/Filesystems/FAT/fat.c index e3a681af..fbf4f71b 100644 --- a/Modules/Filesystems/FAT/fat.c +++ b/Modules/Filesystems/FAT/fat.c @@ -73,10 +73,10 @@ Uint64 FAT_Write(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer); #endif // --- Directory IO char *FAT_ReadDir(tVFS_Node *Node, int ID); -tVFS_Node *FAT_FindDir(tVFS_Node *Node, char *Name); +tVFS_Node *FAT_FindDir(tVFS_Node *Node, const char *Name); #if SUPPORT_WRITE - int FAT_Mknod(tVFS_Node *Node, char *Name, Uint Flags); - int FAT_Relink(tVFS_Node *node, char *OldName, char *NewName); + int FAT_Mknod(tVFS_Node *Node, const char *Name, Uint Flags); + int FAT_Relink(tVFS_Node *node, const char *OldName, const char *NewName); #endif void FAT_CloseFile(tVFS_Node *node); @@ -1303,7 +1303,7 @@ char *FAT_ReadDir(tVFS_Node *Node, int ID) * \fn tVFS_Node *FAT_FindDir(tVFS_Node *node, char *name) * \brief Finds an entry in the current directory */ -tVFS_Node *FAT_FindDir(tVFS_Node *Node, char *Name) +tVFS_Node *FAT_FindDir(tVFS_Node *Node, const char *Name) { fat_filetable fileinfo[16]; char tmpName[13]; diff --git a/Modules/Filesystems/NTFS/dir.c b/Modules/Filesystems/NTFS/dir.c index f0331415..c3a90682 100644 --- a/Modules/Filesystems/NTFS/dir.c +++ b/Modules/Filesystems/NTFS/dir.c @@ -10,7 +10,7 @@ // === PROTOTYPES === char *NTFS_ReadDir(tVFS_Node *Node, int Pos); -tVFS_Node *NTFS_FindDir(tVFS_Node *Node, char *Name); +tVFS_Node *NTFS_FindDir(tVFS_Node *Node, const char *Name); Uint64 NTFS_int_IndexLookup(Uint64 Inode, const char *IndexName, const char *Str); // === CODE === @@ -25,7 +25,7 @@ char *NTFS_ReadDir(tVFS_Node *Node, int Pos) /** * \brief Get an entry from a directory by name */ -tVFS_Node *NTFS_FindDir(tVFS_Node *Node, char *Name) +tVFS_Node *NTFS_FindDir(tVFS_Node *Node, const char *Name) { tNTFS_Disk *disk = Node->ImplPtr; Uint64 inode = NTFS_int_IndexLookup(Node->Inode, "$I30", Name); diff --git a/Modules/Filesystems/NTFS/main.c b/Modules/Filesystems/NTFS/main.c index 5cdcc667..ae70558c 100644 --- a/Modules/Filesystems/NTFS/main.c +++ b/Modules/Filesystems/NTFS/main.c @@ -13,7 +13,7 @@ // === IMPORTS === extern char *NTFS_ReadDir(tVFS_Node *Node, int Pos); -extern tVFS_Node *NTFS_FindDir(tVFS_Node *Node, char *Name); +extern tVFS_Node *NTFS_FindDir(tVFS_Node *Node, const char *Name); // === PROTOTYPES === int NTFS_Install(char **Arguments); diff --git a/Modules/IPStack/link.c b/Modules/IPStack/link.c index 8316b638..afd54eb1 100644 --- a/Modules/IPStack/link.c +++ b/Modules/IPStack/link.c @@ -17,6 +17,7 @@ void Link_WatchDevice(tAdapter *Adapter); // === GLOBALS === int giRegisteredTypes = 0; + int giRegisteredTypeSpace = 0; struct { Uint16 Type; tPacketCallback Callback; @@ -50,17 +51,18 @@ void Link_RegisterType(Uint16 Type, tPacketCallback Callback) if(i == -1) { - tmp = realloc(gaRegisteredTypes, (giRegisteredTypes+1)*sizeof(*gaRegisteredTypes)); + giRegisteredTypeSpace += 5; + tmp = realloc(gaRegisteredTypes, giRegisteredTypeSpace*sizeof(*gaRegisteredTypes)); if(!tmp) { Log_Warning("NET", "Out of heap space! (Attempted to allocate %i)", - (giRegisteredTypes+1)*sizeof(*gaRegisteredTypes) + giRegisteredTypeSpace*sizeof(*gaRegisteredTypes) ); return ; } + gaRegisteredTypes = tmp; i = giRegisteredTypes; giRegisteredTypes ++; - gaRegisteredTypes = tmp; } gaRegisteredTypes[i].Callback = Callback; diff --git a/Modules/IPStack/main.c b/Modules/IPStack/main.c index 13bc5615..d087a9bf 100644 --- a/Modules/IPStack/main.c +++ b/Modules/IPStack/main.c @@ -28,12 +28,12 @@ extern int IPv6_Initialise(); int IPStack_Install(char **Arguments); int IPStack_IOCtlRoot(tVFS_Node *Node, int ID, void *Data); char *IPStack_Root_ReadDir(tVFS_Node *Node, int Pos); -tVFS_Node *IPStack_Root_FindDir(tVFS_Node *Node, char *Name); +tVFS_Node *IPStack_Root_FindDir(tVFS_Node *Node, const char *Name); int IPStack_Root_IOCtl(tVFS_Node *Node, int ID, void *Data); int IPStack_AddInterface(char *Device); tAdapter *IPStack_GetAdapter(char *Path); char *IPStack_Iface_ReadDir(tVFS_Node *Node, int Pos); -tVFS_Node *IPStack_Iface_FindDir(tVFS_Node *Node, char *Name); +tVFS_Node *IPStack_Iface_FindDir(tVFS_Node *Node, const char *Name); int IPStack_Iface_IOCtl(tVFS_Node *Node, int ID, void *Data); // === GLOBALS === @@ -154,7 +154,7 @@ char *IPStack_Root_ReadDir(tVFS_Node *Node, int Pos) /** * \brief Get the node of an interface */ -tVFS_Node *IPStack_Root_FindDir(tVFS_Node *Node, char *Name) +tVFS_Node *IPStack_Root_FindDir(tVFS_Node *Node, const char *Name) { int i, num; tInterface *iface; @@ -247,7 +247,7 @@ char *IPStack_Iface_ReadDir(tVFS_Node *Node, int Pos) /** * \brief Gets a named node from an interface directory */ -tVFS_Node *IPStack_Iface_FindDir(tVFS_Node *Node, char *Name) +tVFS_Node *IPStack_Iface_FindDir(tVFS_Node *Node, const char *Name) { tSocketFile *file = gIP_FileTemplates; diff --git a/Modules/IPStack/tcp.c b/Modules/IPStack/tcp.c index bf88dd5a..616e5d53 100644 --- a/Modules/IPStack/tcp.c +++ b/Modules/IPStack/tcp.c @@ -28,7 +28,7 @@ Uint16 TCP_GetUnusedPort(); // --- Server tVFS_Node *TCP_Server_Init(tInterface *Interface); char *TCP_Server_ReadDir(tVFS_Node *Node, int Pos); -tVFS_Node *TCP_Server_FindDir(tVFS_Node *Node, char *Name); +tVFS_Node *TCP_Server_FindDir(tVFS_Node *Node, const char *Name); int TCP_Server_IOCtl(tVFS_Node *Node, int ID, void *Data); void TCP_Server_Close(tVFS_Node *Node); // --- Client @@ -605,7 +605,7 @@ char *TCP_Server_ReadDir(tVFS_Node *Node, int Pos) * \param Node Server node * \param Name Hexadecimal ID of the node */ -tVFS_Node *TCP_Server_FindDir(tVFS_Node *Node, char *Name) +tVFS_Node *TCP_Server_FindDir(tVFS_Node *Node, const char *Name) { tTCPConnection *conn; tTCPListener *srv = Node->ImplPtr; diff --git a/Modules/IPStack/udp.c b/Modules/IPStack/udp.c index 4ce447d8..43dd023e 100644 --- a/Modules/IPStack/udp.c +++ b/Modules/IPStack/udp.c @@ -16,7 +16,7 @@ void UDP_SendPacket(tUDPChannel *Channel, void *Data, size_t Length); // --- Listening Server tVFS_Node *UDP_Server_Init(tInterface *Interface); char *UDP_Server_ReadDir(tVFS_Node *Node, int ID); -tVFS_Node *UDP_Server_FindDir(tVFS_Node *Node, char *Name); +tVFS_Node *UDP_Server_FindDir(tVFS_Node *Node, const char *Name); int UDP_Server_IOCtl(tVFS_Node *Node, int ID, void *Data); void UDP_Server_Close(tVFS_Node *Node); // --- Client Channels @@ -239,7 +239,7 @@ char *UDP_Server_ReadDir(tVFS_Node *Node, int ID) /** * \brief Take a string and find the channel */ -tVFS_Node *UDP_Server_FindDir(tVFS_Node *Node, char *Name) +tVFS_Node *UDP_Server_FindDir(tVFS_Node *Node, const char *Name) { tUDPServer *srv = Node->ImplPtr; tUDPChannel *chan; diff --git a/Modules/Makefile.tpl b/Modules/Makefile.tpl index 6fce4152..2fabb12f 100644 --- a/Modules/Makefile.tpl +++ b/Modules/Makefile.tpl @@ -12,7 +12,7 @@ CFGFILES += $(shell test -f Makefile.cfg && echo Makefile.cfg) -include $(CFGFILES) CPPFLAGS := -I$(ACESSDIR)/Kernel/include -I$(ACESSDIR)/Kernel/arch/$(ARCHDIR)/include -DARCH=$(ARCH) $(_CPPFLAGS) -CFLAGS := -Wall -Werror -fno-stack-protector $(CPPFLAGS) -O3 -fno-builtin +CFLAGS = -Wall -Werror -fno-stack-protector $(CPPFLAGS) -O3 -fno-builtin ifneq ($(CATEGORY),) FULLNAME := $(CATEGORY)_$(NAME) @@ -20,6 +20,8 @@ else FULLNAME := $(NAME) endif +CPPFLAGS += -D_MODULE_NAME_=\"$(FULLNAME)\" + ifneq ($(BUILDTYPE),static) _SUFFIX := dyn_$(ARCH) BIN := ../$(FULLNAME).kmd.$(ARCH) diff --git a/Modules/Network/NE2000/ne2000.c b/Modules/Network/NE2000/ne2000.c index 1ebe778f..5cd23d25 100644 --- a/Modules/Network/NE2000/ne2000.c +++ b/Modules/Network/NE2000/ne2000.c @@ -85,7 +85,7 @@ typedef struct sNe2k_Card { // === PROTOTYPES === int Ne2k_Install(char **Arguments); char *Ne2k_ReadDir(tVFS_Node *Node, int Pos); -tVFS_Node *Ne2k_FindDir(tVFS_Node *Node, char *Name); +tVFS_Node *Ne2k_FindDir(tVFS_Node *Node, const char *Name); int Ne2k_IOCtl(tVFS_Node *Node, int ID, void *Data); Uint64 Ne2k_Write(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer); Uint64 Ne2k_Read(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer); @@ -236,9 +236,9 @@ char *Ne2k_ReadDir(tVFS_Node *Node, int Pos) } /** - * \fn tVFS_Node *Ne2k_FindDir(tVFS_Node *Node, char *Name) + * \fn tVFS_Node *Ne2k_FindDir(tVFS_Node *Node, const char *Name) */ -tVFS_Node *Ne2k_FindDir(tVFS_Node *Node, char *Name) +tVFS_Node *Ne2k_FindDir(tVFS_Node *Node, const char *Name) { if(Name[0] == '\0' || Name[1] != '\0') return NULL; diff --git a/Modules/Storage/ATA/main.c b/Modules/Storage/ATA/main.c index 9c71a901..7f8964d2 100644 --- a/Modules/Storage/ATA/main.c +++ b/Modules/Storage/ATA/main.c @@ -25,7 +25,7 @@ void ATA_int_MakePartition(tATA_Partition *Part, int Disk, int Num, Uint64 Start Uint16 ATA_GetBasePort(int Disk); // Filesystem Interface char *ATA_ReadDir(tVFS_Node *Node, int Pos); -tVFS_Node *ATA_FindDir(tVFS_Node *Node, char *Name); +tVFS_Node *ATA_FindDir(tVFS_Node *Node, const char *Name); Uint64 ATA_ReadFS(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer); Uint64 ATA_WriteFS(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer); int ATA_IOCtl(tVFS_Node *Node, int Id, void *Data); @@ -250,9 +250,9 @@ char *ATA_ReadDir(tVFS_Node *UNUSED(Node), int Pos) } /** - * \fn tVFS_Node *ATA_FindDir(tVFS_Node *Node, char *Name) + * \fn tVFS_Node *ATA_FindDir(tVFS_Node *Node, const char *Name) */ -tVFS_Node *ATA_FindDir(tVFS_Node *UNUSED(Node), char *Name) +tVFS_Node *ATA_FindDir(tVFS_Node *UNUSED(Node), const char *Name) { int part; tATA_Disk *disk; diff --git a/Modules/Storage/FDD/fdd.c b/Modules/Storage/FDD/fdd.c index b0bbf784..149465e3 100644 --- a/Modules/Storage/FDD/fdd.c +++ b/Modules/Storage/FDD/fdd.c @@ -88,7 +88,7 @@ enum FloppyCommands { void FDD_UnloadModule(); // --- VFS Methods char *FDD_ReadDir(tVFS_Node *Node, int pos); -tVFS_Node *FDD_FindDir(tVFS_Node *dirNode, char *Name); +tVFS_Node *FDD_FindDir(tVFS_Node *dirNode, const char *Name); int FDD_IOCtl(tVFS_Node *Node, int ID, void *Data); Uint64 FDD_ReadFS(tVFS_Node *node, Uint64 off, Uint64 len, void *buffer); // --- Functions for IOCache/DrvUtil @@ -241,10 +241,10 @@ char *FDD_ReadDir(tVFS_Node *UNUSED(Node), int Pos) } /** - * \fn tVFS_Node *FDD_FindDir(tVFS_Node *Node, char *filename); + * \fn tVFS_Node *FDD_FindDir(tVFS_Node *Node, const char *filename); * \brief Find File Routine (for vfs_node) */ -tVFS_Node *FDD_FindDir(tVFS_Node *UNUSED(Node), char *Filename) +tVFS_Node *FDD_FindDir(tVFS_Node *UNUSED(Node), const char *Filename) { int i; diff --git a/Modules/USB/Core/main.c b/Modules/USB/Core/main.c index 36e898cc..712f6028 100644 --- a/Modules/USB/Core/main.c +++ b/Modules/USB/Core/main.c @@ -17,7 +17,7 @@ extern int UHCI_Initialise(void); int USB_Install(char **Arguments); void USB_Cleanup(void); char *USB_ReadDir(tVFS_Node *Node, int Pos); -tVFS_Node *USB_FindDir(tVFS_Node *Node, char *Name); +tVFS_Node *USB_FindDir(tVFS_Node *Node, const char *Name); int USB_IOCtl(tVFS_Node *Node, int Id, void *Data); // === GLOBALS === @@ -65,10 +65,10 @@ char *USB_ReadDir(tVFS_Node *Node, int Pos) } /** - * \fn tVFS_Node *USB_FindDir(tVFS_Node *Node, char *Name) + * \fn tVFS_Node *USB_FindDir(tVFS_Node *Node, const char *Name) * \brief Locate an entry in the USB root */ -tVFS_Node *USB_FindDir(tVFS_Node *Node, char *Name) +tVFS_Node *USB_FindDir(tVFS_Node *Node, const char *Name) { return NULL; } diff --git a/Usermode/Libraries/libspiderscript.so_src/ast.h b/Usermode/Libraries/libspiderscript.so_src/ast.h index 91795636..4fa98ca0 100644 --- a/Usermode/Libraries/libspiderscript.so_src/ast.h +++ b/Usermode/Libraries/libspiderscript.so_src/ast.h @@ -159,7 +159,7 @@ struct sAST_Variable { tAST_Variable *Next; int Type; // Only used for static typing - tSpiderObject *Object; + tSpiderValue *Object; char Name[]; }; @@ -187,6 +187,6 @@ extern tAST_Node *AST_NewUniOp(int Operation, tAST_Node *Value); extern void AST_FreeNode(tAST_Node *Node); // exec_ast.h -extern tSpiderObject *AST_ExecuteNode(tAST_BlockState *Block, tAST_Node *Node); +extern tSpiderValue *AST_ExecuteNode(tAST_BlockState *Block, tAST_Node *Node); #endif diff --git a/Usermode/Libraries/libspiderscript.so_src/exec_ast.c b/Usermode/Libraries/libspiderscript.so_src/exec_ast.c index cf7416a4..2bbfd1ca 100644 --- a/Usermode/Libraries/libspiderscript.so_src/exec_ast.c +++ b/Usermode/Libraries/libspiderscript.so_src/exec_ast.c @@ -6,33 +6,33 @@ #include "ast.h" // === PROTOTYPES === -void Object_Dereference(tSpiderObject *Object); -void Object_Reference(tSpiderObject *Object); -tSpiderObject *Object_CreateInteger(uint64_t Value); -tSpiderObject *Object_CreateReal(double Value); -tSpiderObject *Object_CreateString(int Length, const char *Data); -tSpiderObject *Object_CastTo(int Type, tSpiderObject *Source); - int Object_IsTrue(tSpiderObject *Value); +void Object_Dereference(tSpiderValue *Object); +void Object_Reference(tSpiderValue *Object); +tSpiderValue *Object_CreateInteger(uint64_t Value); +tSpiderValue *Object_CreateReal(double Value); +tSpiderValue *Object_CreateString(int Length, const char *Data); +tSpiderValue *Object_CastTo(int Type, tSpiderValue *Source); + int Object_IsTrue(tSpiderValue *Value); -tSpiderObject *AST_ExecuteNode(tAST_BlockState *Block, tAST_Node *Node); +tSpiderValue *AST_ExecuteNode(tAST_BlockState *Block, tAST_Node *Node); tAST_Variable *Variable_Define(tAST_BlockState *Block, int Type, const char *Name); -void Variable_SetValue(tAST_BlockState *Block, const char *Name, tSpiderObject *Value); -tSpiderObject *Variable_GetValue(tAST_BlockState *Block, const char *Name); +void Variable_SetValue(tAST_BlockState *Block, const char *Name, tSpiderValue *Value); +tSpiderValue *Variable_GetValue(tAST_BlockState *Block, const char *Name); void Variable_Destroy(tAST_Variable *Variable); // === CODE === /** * \brief Dereference a created object */ -void Object_Dereference(tSpiderObject *Object) +void Object_Dereference(tSpiderValue *Object) { if(!Object) return ; Object->ReferenceCount --; if( Object->ReferenceCount == 0 ) free(Object); } -void Object_Reference(tSpiderObject *Object) +void Object_Reference(tSpiderValue *Object) { if(!Object) return ; Object->ReferenceCount ++; @@ -41,9 +41,9 @@ void Object_Reference(tSpiderObject *Object) /** * \brief Create an integer object */ -tSpiderObject *Object_CreateInteger(uint64_t Value) +tSpiderValue *Object_CreateInteger(uint64_t Value) { - tSpiderObject *ret = malloc( sizeof(tSpiderObject) ); + tSpiderValue *ret = malloc( sizeof(tSpiderValue) ); ret->Type = SS_DATATYPE_INTEGER; ret->ReferenceCount = 1; ret->Integer = Value; @@ -53,9 +53,9 @@ tSpiderObject *Object_CreateInteger(uint64_t Value) /** * \brief Create an real number object */ -tSpiderObject *Object_CreateReal(double Value) +tSpiderValue *Object_CreateReal(double Value) { - tSpiderObject *ret = malloc( sizeof(tSpiderObject) ); + tSpiderValue *ret = malloc( sizeof(tSpiderValue) ); ret->Type = SS_DATATYPE_REAL; ret->ReferenceCount = 1; ret->Real = Value; @@ -65,9 +65,9 @@ tSpiderObject *Object_CreateReal(double Value) /** * \brief Create an string object */ -tSpiderObject *Object_CreateString(int Length, const char *Data) +tSpiderValue *Object_CreateString(int Length, const char *Data) { - tSpiderObject *ret = malloc( sizeof(tSpiderObject) + Length + 1 ); + tSpiderValue *ret = malloc( sizeof(tSpiderValue) + Length + 1 ); ret->Type = SS_DATATYPE_STRING; ret->ReferenceCount = 1; ret->String.Length = Length; @@ -79,13 +79,13 @@ tSpiderObject *Object_CreateString(int Length, const char *Data) /** * \brief Concatenate two strings */ -tSpiderObject *Object_StringConcat(tSpiderObject *Str1, tSpiderObject *Str2) +tSpiderValue *Object_StringConcat(tSpiderValue *Str1, tSpiderValue *Str2) { int newLen = 0; - tSpiderObject *ret; + tSpiderValue *ret; if(Str1) newLen += Str1->String.Length; if(Str2) newLen += Str2->String.Length; - ret = malloc( sizeof(tSpiderObject) + newLen + 1 ); + ret = malloc( sizeof(tSpiderValue) + newLen + 1 ); ret->Type = SS_DATATYPE_STRING; ret->ReferenceCount = 1; ret->String.Length = newLen; @@ -104,9 +104,9 @@ tSpiderObject *Object_StringConcat(tSpiderObject *Str1, tSpiderObject *Str2) /** * \brief Cast one object to another */ -tSpiderObject *Object_CastTo(int Type, tSpiderObject *Source) +tSpiderValue *Object_CastTo(int Type, tSpiderValue *Source) { - tSpiderObject *ret = ERRPTR; + tSpiderValue *ret = ERRPTR; // Check if anything needs to be done if( Source->Type == Type ) { Object_Reference(Source); @@ -122,7 +122,7 @@ tSpiderObject *Object_CastTo(int Type, tSpiderObject *Source) return ERRPTR; case SS_DATATYPE_INTEGER: - ret = malloc(sizeof(tSpiderObject)); + ret = malloc(sizeof(tSpiderValue)); ret->Type = SS_DATATYPE_INTEGER; ret->ReferenceCount = 1; switch(Source->Type) @@ -148,7 +148,7 @@ tSpiderObject *Object_CastTo(int Type, tSpiderObject *Source) /** * \brief Condenses a value down to a boolean */ -int Object_IsTrue(tSpiderObject *Value) +int Object_IsTrue(tSpiderValue *Value) { switch(Value->Type) { @@ -177,11 +177,11 @@ int Object_IsTrue(tSpiderObject *Value) /** * \brief Execute an AST node and return its value */ -tSpiderObject *AST_ExecuteNode(tAST_BlockState *Block, tAST_Node *Node) +tSpiderValue *AST_ExecuteNode(tAST_BlockState *Block, tAST_Node *Node) { tAST_Node *node; - tSpiderObject *ret, *tmpobj; - tSpiderObject *op1, *op2; // Binary operations + tSpiderValue *ret, *tmpobj; + tSpiderValue *op1, *op2; // Binary operations int cmp; // Used in comparisons switch(Node->Type) @@ -243,7 +243,7 @@ tSpiderObject *AST_ExecuteNode(tAST_BlockState *Block, tAST_Node *Node) } // Logical block (used to allocate `params`) { - tSpiderObject *params[nParams]; + tSpiderValue *params[nParams]; int i=0; for(node = Node->FunctionCall.FirstArg; node; node = node->NextSibling) { params[i] = AST_ExecuteNode(Block, node); @@ -555,7 +555,7 @@ tAST_Variable *Variable_Define(tAST_BlockState *Block, int Type, const char *Nam /** * \brief Set the value of a variable */ -void Variable_SetValue(tAST_BlockState *Block, const char *Name, tSpiderObject *Value) +void Variable_SetValue(tAST_BlockState *Block, const char *Name, tSpiderValue *Value) { tAST_Variable *var; tAST_BlockState *bs; @@ -594,7 +594,7 @@ void Variable_SetValue(tAST_BlockState *Block, const char *Name, tSpiderObject * /** * \brief Get the value of a variable */ -tSpiderObject *Variable_GetValue(tAST_BlockState *Block, const char *Name) +tSpiderValue *Variable_GetValue(tAST_BlockState *Block, const char *Name) { tAST_Variable *var; tAST_BlockState *bs; diff --git a/Usermode/Libraries/libspiderscript.so_src/exports.c b/Usermode/Libraries/libspiderscript.so_src/exports.c index bce3e79f..a8b05852 100644 --- a/Usermode/Libraries/libspiderscript.so_src/exports.c +++ b/Usermode/Libraries/libspiderscript.so_src/exports.c @@ -8,7 +8,7 @@ #include // === PROTOTYPES === -tSpiderObject *Exports_Lang_Struct(tSpiderScript *Script, int NArgs, tSpiderObject **Args); +tSpiderValue *Exports_Lang_Struct(tSpiderScript *Script, int NArgs, tSpiderValue **Args); // === GLOBALS === int gaExports_Lang_Struct_Args[] = {SS_DATATYPE_STRING,-1}; @@ -19,7 +19,7 @@ tSpiderFunction gaSpiderScript_Exports[] = { const int giSpiderScript_NumExports = sizeof(gaSpiderScript_Exports)/sizeof(tSpiderFunction); // === CODE === -tSpiderObject *Exports_Lang_Struct(tSpiderScript *Script, int NArgs, tSpiderObject **Args) +tSpiderValue *Exports_Lang_Struct(tSpiderScript *Script, int NArgs, tSpiderValue **Args) { int i; printf("Exports_Lang_Struct: (Script=%p, NArgs=%i, Args=%p)\n", Script, NArgs, Args); diff --git a/Usermode/Libraries/libspiderscript.so_src/main.c b/Usermode/Libraries/libspiderscript.so_src/main.c index e5c225ce..a6b1bde5 100644 --- a/Usermode/Libraries/libspiderscript.so_src/main.c +++ b/Usermode/Libraries/libspiderscript.so_src/main.c @@ -13,7 +13,7 @@ extern tAST_Script *Parse_Buffer(tSpiderVariant *Variant, char *Buffer); extern const int giSpiderScript_NumExports; extern tSpiderFunction gaSpiderScript_Exports[]; extern tAST_Variable *Variable_Define(tAST_BlockState *Block, int Type, const char *Name); -extern void Variable_SetValue(tAST_BlockState *Block, const char *Name, tSpiderObject *Value); +extern void Variable_SetValue(tAST_BlockState *Block, const char *Name, tSpiderValue *Value); // === CODE === /** @@ -74,13 +74,13 @@ tSpiderScript *SpiderScript_ParseFile(tSpiderVariant *Variant, const char *Filen * \param NArguments Number of arguments to pass * \param Arguments Arguments passed */ -tSpiderObject *SpiderScript_ExecuteMethod(tSpiderScript *Script, - const char *Function, int NArguments, tSpiderObject **Arguments) +tSpiderValue *SpiderScript_ExecuteMethod(tSpiderScript *Script, + const char *Function, int NArguments, tSpiderValue **Arguments) { char *trueName = NULL; int i; int bFound = 0; // Used to keep nesting levels down - tSpiderObject *ret = ERRPTR; + tSpiderValue *ret = ERRPTR; // Handle namespaces if( Function[0] == '.' ) { -- 2.20.1