Palacios Public Git Repository

To checkout Palacios execute

  git clone http://v3vee.org/palacios/palacios.web/palacios.git
This will give you the master branch. You probably want the devel branch or one of the release branches. To switch to the devel branch, simply execute
  cd palacios
  git checkout --track -b devel origin/devel
The other branches are similar.


Expose kmalloc flags within linux_module + add further debugging features for heap...
Peter Dinda [Sat, 7 Jul 2012 23:33:46 +0000 (18:33 -0500)]
linux_module/palacios-stubs.c
linux_module/palacios.h

index 60b481f..5ced6d2 100644 (file)
 
 #include "mm.h"
 
+// The following can be used to track heap bugs
+// zero memory after allocation
+#define ALLOC_ZERO_MEM 0
+// pad allocations by this many bytes on both ends of block
+#define ALLOC_PAD      0
+
 
 u32 pg_allocs = 0;
 u32 pg_frees = 0;
@@ -168,32 +174,44 @@ void palacios_free_pages(void * page_paddr, int num_pages) {
 }
 
 
+void *
+palacios_alloc_extended(unsigned int size, unsigned int flags) {
+    void * addr = NULL;
+
+    addr = kmalloc(size+2*ALLOC_PAD, flags);
+
+    if (!addr) { 
+       ERROR("ALERT ALERT  kmalloc has FAILED FAILED FAILED\n");
+       return NULL;
+    }  
+
+    mallocs++;
+
+#if ALLOC_ZERO_MEM
+    memset(addr,0,size+2*ALLOC_PAD);
+#endif
+
+    return addr+ALLOC_PAD;
+}
+
+
 /**
  * Allocates 'size' bytes of kernel memory.
  * Returns the kernel virtual address of the memory allocated.
  */
 void *
 palacios_alloc(unsigned int size) {
-    void * addr = NULL;
 
     // It is very important that this test remains since 
     // this function is used extensively throughout palacios and the linux
     // module, both in places where interrupts are off and where they are on
     // a GFP_KERNEL call, when done with interrupts off can lead to DEADLOCK
     if (irqs_disabled()) {
-       addr = kmalloc(size, GFP_ATOMIC);
+       return palacios_alloc_extended(size,GFP_ATOMIC);
     } else {
-       addr = kmalloc(size, GFP_KERNEL);
+       return palacios_alloc_extended(size,GFP_KERNEL);
     }
 
-    if (!addr) { 
-       ERROR("ALERT ALERT  kmalloc has FAILED FAILED FAILED\n");
-       return NULL;
-    }  
-
-    mallocs++;
-
-    return addr;
 }
 
 /**
@@ -205,7 +223,7 @@ palacios_free(
 )
 {
     frees++;
-    kfree(addr);
+    kfree(addr-ALLOC_PAD);
     return;
 }
 
index 9bee6c9..43ffa57 100644 (file)
@@ -107,6 +107,7 @@ void  palacios_print(const char *fmt, ...);
 void *palacios_allocate_pages(int num_pages, unsigned int alignment);
 void  palacios_free_pages(void *page_addr, int num_pages);
 void *palacios_alloc(unsigned int size);
+void *palacios_alloc_extended(unsigned int size, unsigned int flags);
 void  palacios_free(void *);
 void *palacios_vaddr_to_paddr(void *vaddr);
 void *palacios_paddr_to_vaddr(void *paddr);