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)\"
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);
}
/**
- * \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;
}
/**
- * \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;
}
}
/**
- * \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;
\r
// === PROTOTYPES ===\r
int PCI_Install(char **Arguments);\r
- int PCI_ScanBus(int ID);\r
+ int PCI_ScanBus(int ID, int bFill);\r
\r
char *PCI_ReadDirRoot(tVFS_Node *node, int pos);\r
-tVFS_Node *PCI_FindDirRoot(tVFS_Node *node, char *filename);\r
+tVFS_Node *PCI_FindDirRoot(tVFS_Node *node, const char *filename);\r
Uint64 PCI_ReadDevice(tVFS_Node *node, Uint64 pos, Uint64 length, void *buffer);\r
\r
int PCI_CountDevices(Uint16 vendor, Uint16 device, Uint16 fcn);\r
for( i = 0; i < MAX_RESERVED_PORT % 32; i ++ )\r
gaPCI_PortBitmap[MAX_RESERVED_PORT / 32] = 1 << i;\r
\r
- // Scan Bus\r
- i = PCI_ScanBus(0);\r
+ // Scan Bus (Bus 0, Don't fill gPCI_Devices)\r
+ i = PCI_ScanBus(0, 0);\r
if(i != MODULE_ERR_OK) return i;\r
\r
if(giPCI_DeviceCount == 0) {\r
return MODULE_ERR_NOTNEEDED;\r
}\r
\r
- // Ensure the buffer is nice and tight\r
- tmpPtr = realloc(gPCI_Devices, giPCI_DeviceCount*sizeof(tPCIDevice));\r
- if(tmpPtr == NULL)\r
+ // Allocate device buffer\r
+ tmpPtr = malloc(giPCI_DeviceCount * sizeof(tPCIDevice));\r
+ if(tmpPtr == NULL) {\r
+ Log_Warning("PCI", "Malloc ERROR");\r
return MODULE_ERR_MALLOC;\r
+ }\r
gPCI_Devices = tmpPtr;\r
\r
+ Log_Log("PCI", "%i devices, filling structure");\r
+ \r
+ // Reset counts\r
+ giPCI_DeviceCount = 0;\r
+ giPCI_BusCount = 0;\r
+ memset(gaPCI_BusBitmap, 0, sizeof(gaPCI_BusBitmap));\r
+ // Rescan, filling the PCI device array\r
+ PCI_ScanBus(0, 1);\r
+ \r
// Complete Driver Structure\r
gPCI_DriverStruct.RootNode.Size = giPCI_DeviceCount;\r
\r
\r
/**\r
* \brief Scans a specific PCI Bus\r
+ * \param BusID PCI Bus ID to scan\r
+ * \param bFill Fill the \a gPCI_Devices array?\r
*/\r
-int PCI_ScanBus(int BusID)\r
+int PCI_ScanBus(int BusID, int bFill)\r
{\r
int dev, fcn;\r
tPCIDevice devInfo;\r
- void *tmpPtr = NULL;\r
\r
if( gaPCI_BusBitmap[BusID/32] & (1 << (BusID%32)) )\r
return MODULE_ERR_OK;\r
if(!PCI_EnumDevice(BusID, dev, fcn, &devInfo))\r
continue;\r
\r
- // Allocate\r
- tmpPtr = realloc(gPCI_Devices, (giPCI_DeviceCount+1)*sizeof(tPCIDevice));\r
- if(tmpPtr == NULL)\r
- return MODULE_ERR_MALLOC;\r
- gPCI_Devices = tmpPtr;\r
- \r
if(devInfo.oc == PCI_OC_PCIBRIDGE)\r
{\r
#if LIST_DEVICES\r
BusID, dev, fcn, devInfo.vendor, devInfo.device);\r
#endif\r
//TODO: Handle PCI-PCI Bridges\r
- //PCI_ScanBus( );\r
- giPCI_BusCount++;\r
+ //PCI_ScanBus(devInfo.???, bFill);\r
+ giPCI_BusCount ++;\r
}\r
else\r
{\r
#endif\r
}\r
\r
- devInfo.Node.Inode = giPCI_DeviceCount;\r
- memcpy(&gPCI_Devices[giPCI_DeviceCount], &devInfo, sizeof(tPCIDevice));\r
+ if( bFill ) {\r
+ devInfo.Node.Inode = giPCI_DeviceCount;\r
+ memcpy(&gPCI_Devices[giPCI_DeviceCount], &devInfo, sizeof(tPCIDevice));\r
+ }\r
giPCI_DeviceCount ++;\r
\r
// WTF is this for?\r
return strdup( gPCI_Devices[Pos].Name );\r
}\r
/**\r
- * \fn tVFS_Node *PCI_FindDirRoot(tVFS_Node *node, char *filename)\r
+ * \fn tVFS_Node *PCI_FindDirRoot(tVFS_Node *node, const char *filename)\r
*/\r
-tVFS_Node *PCI_FindDirRoot(tVFS_Node *node, char *filename)\r
+tVFS_Node *PCI_FindDirRoot(tVFS_Node *node, const char *filename)\r
{\r
int bus,slot,fcn;\r
int i;\r
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);
}
/**
- * \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;
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);
}
/**
- * \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;
*/
#include <acess.h>
#include <mm_virt.h>
-#include <heap.h>
+#include <heap_int.h>
#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);
}
/**
- * \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;
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);
)
{
// 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);
// 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));
// 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));
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;
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;
}
/**
*/
-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;
// Exact Fit
if(size == newSize) {
head->Size = newSize;
+ head->File = File;
+ head->Line = Line;
foot->Head = head;
nextHead->Magic = 0;
nextHead->Size = 0;
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;
// 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;
}
// Well, darn
- nextHead = malloc( __size );
+ nextHead = Heap_Allocate( File, Line, __size );
nextHead -= 1;
+ nextHead->File = File;
+ nextHead->Line = Line;
memcpy(
nextHead->Data,
}
/**
- * \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;
#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
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;
}
// 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
(Uint)head < (Uint)gHeapEnd;
head = (void*)( (Uint)head + head->Size )
)
- {
+ {
nBlocks ++;
totalBytes += head->Size;
if( head->Magic == MAGIC_FREE )
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);
#endif
// === EXPORTS ===
-EXPORT(malloc);
-EXPORT(realloc);
-EXPORT(free);
+EXPORT(Heap_Allocate);
+EXPORT(Heap_AllocateZero);
+EXPORT(Heap_Reallocate);
+EXPORT(Heap_Deallocate);
+EXPORT(Heap_IsHeapAddr);
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 <heap.h>
// --- Modules ---
/**
-/*
- * 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
* \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
* \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
* \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
* \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);
/**
* \}
// === 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);
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 = {
* \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;
// === 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);
}
/**
- * \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;
}
/**
- * \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;
#include <vfs.h>
// === 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);
// === 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 '$'
// === 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);
* \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
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) ) {
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;
}
// Parse Symlink Path
curNode = VFS_ParsePath(tmp, TruePath);
+ if(TruePath)
+ Log_Debug("VFS", "*TruePath='%s'", *TruePath);
// Error Check
if(!curNode) {
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;
*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
// === 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);
* \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;
}
/**
- * \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;
* \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;
}
* \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;
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 ---
#endif\r
// --- Directory IO\r
char *FAT_ReadDir(tVFS_Node *Node, int ID);\r
-tVFS_Node *FAT_FindDir(tVFS_Node *Node, char *Name);\r
+tVFS_Node *FAT_FindDir(tVFS_Node *Node, const char *Name);\r
#if SUPPORT_WRITE\r
- int FAT_Mknod(tVFS_Node *Node, char *Name, Uint Flags);\r
- int FAT_Relink(tVFS_Node *node, char *OldName, char *NewName);\r
+ int FAT_Mknod(tVFS_Node *Node, const char *Name, Uint Flags);\r
+ int FAT_Relink(tVFS_Node *node, const char *OldName, const char *NewName);\r
#endif\r
void FAT_CloseFile(tVFS_Node *node);\r
\r
* \fn tVFS_Node *FAT_FindDir(tVFS_Node *node, char *name)\r
* \brief Finds an entry in the current directory\r
*/\r
-tVFS_Node *FAT_FindDir(tVFS_Node *Node, char *Name)\r
+tVFS_Node *FAT_FindDir(tVFS_Node *Node, const char *Name)\r
{\r
fat_filetable fileinfo[16];\r
char tmpName[13];\r
// === 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 ===
/**
* \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);
// === 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);
// === GLOBALS ===
int giRegisteredTypes = 0;
+ int giRegisteredTypeSpace = 0;
struct {
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;
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 ===
/**
* \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;
/**
* \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;
// --- 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
* \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;
// --- 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
/**
* \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;
-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)
FULLNAME := $(NAME)
endif
+CPPFLAGS += -D_MODULE_NAME_=\"$(FULLNAME)\"
+
ifneq ($(BUILDTYPE),static)
_SUFFIX := dyn_$(ARCH)
BIN := ../$(FULLNAME).kmd.$(ARCH)
// === 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);
}
/**
- * \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;
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);
}
/**
- * \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;
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
}
/**
- * \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;
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 ===
}
/**
- * \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;
}
{
tAST_Variable *Next;
int Type; // Only used for static typing
- tSpiderObject *Object;
+ tSpiderValue *Object;
char Name[];
};
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
#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 ++;
/**
* \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;
/**
* \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;
/**
* \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;
/**
* \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;
/**
* \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);
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)
/**
* \brief Condenses a value down to a boolean
*/
-int Object_IsTrue(tSpiderObject *Value)
+int Object_IsTrue(tSpiderValue *Value)
{
switch(Value->Type)
{
/**
* \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)
}
// 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);
/**
* \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;
/**
* \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;
#include <spiderscript.h>
// === 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};
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);
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 ===
/**
* \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] == '.' ) {