Added VFS_ReadDir and SYS_READDIR, Implemented basic directory listing in CLIShell
[tpg/acess2.git] / Kernel / heap.c
index fce510c..6823918 100644 (file)
@@ -175,6 +175,7 @@ void *malloc(size_t Bytes)
                if(head->Size == Bytes) {
                        head->Magic = MAGIC_USED;
                        RELEASE(&giHeapSpinlock);       // Release spinlock
+                       LOG("RETURN %p", best->Data);
                        return best->Data;
                }
                
@@ -204,6 +205,7 @@ void *malloc(size_t Bytes)
                // Check size
                if(best->Size == Bytes) {
                        RELEASE(&giHeapSpinlock);       // Release spinlock
+                       LOG("RETURN %p", best->Data);
                        return best->Data;
                }
        }
@@ -222,6 +224,7 @@ void *malloc(size_t Bytes)
        best->Magic = MAGIC_USED;       // Mark block as used
        
        RELEASE(&giHeapSpinlock);       // Release spinlock
+       LOG("RETURN %p", best->Data);
        return best->Data;
 }
 
@@ -234,6 +237,9 @@ void free(void *Ptr)
        tHeapHead       *head;
        tHeapFoot       *foot;
        
+       LOG("Ptr = %p", Ptr);
+       LOG("Returns to %p", __builtin_return_address(0));
+       
        // Alignment Check
        if( (Uint)Ptr & (sizeof(Uint)-1) ) {
                Warning("free - Passed a non-aligned address (%p)\n", Ptr);
@@ -353,6 +359,23 @@ void *realloc(void *__ptr, size_t __size)
        return NULL;
 }
 
+/**
+ * \fn int IsHeap(void *Ptr)
+ * \brief Checks if an address is a heap address
+ */
+int IsHeap(void *Ptr)
+{
+       tHeapHead       *head;
+       if((Uint)Ptr < (Uint)gHeapStart)        return 0;
+       if((Uint)Ptr > (Uint)gHeapEnd)  return 0;
+       
+       head = (void*)( (Uint)Ptr - sizeof(tHeapHead) );
+       if(head->Magic != MAGIC_USED && head->Magic != MAGIC_FREE)
+               return 0;
+       
+       return 1;
+}
+
 #if WARNINGS
 void Heap_Dump()
 {

UCC git Repository :: git.ucc.asn.au