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.


Lock bugfixes - missing lock deinits This also adds deinit calls in the linux_module...
[palacios.git] / linux_module / palacios-stubs.c
index 7f02fe7..4bceb8c 100644 (file)
@@ -22,6 +22,7 @@
 
 #include "mm.h"
 
+#include "memcheck.h"
 #include "lockcheck.h"
 
 // The following can be used to track heap bugs
@@ -167,6 +168,11 @@ void palacios_print_scoped(void * vm, int vcore, const char *fmt, ...) {
 void *palacios_allocate_pages(int num_pages, unsigned int alignment) {
     void * pg_addr = NULL;
 
+    if (num_pages<=0) { 
+      ERROR("ALERT ALERT Attempt to allocate zero or fewer pages\n");
+      return NULL;
+    }
+
     pg_addr = (void *)alloc_palacios_pgs(num_pages, alignment);
 
     if (!pg_addr) { 
@@ -176,6 +182,8 @@ void *palacios_allocate_pages(int num_pages, unsigned int alignment) {
 
     pg_allocs += num_pages;
 
+    MEMCHECK_ALLOC_PAGES(pg_addr,num_pages*4096);
+
     return pg_addr;
 }
 
@@ -189,6 +197,8 @@ void *palacios_allocate_pages(int num_pages, unsigned int alignment) {
 void palacios_free_pages(void * page_paddr, int num_pages) {
     pg_frees += num_pages;
     free_palacios_pgs((uintptr_t)page_paddr, num_pages);
+    MEMCHECK_FREE_PAGES(page_paddr,num_pages*4096);
+
 }
 
 
@@ -196,6 +206,14 @@ void *
 palacios_alloc_extended(unsigned int size, unsigned int flags) {
     void * addr = NULL;
 
+    if (size==0) { 
+      // note that modern kernels will respond to a zero byte
+      // kmalloc and return the address 0x10...  In Palacios, 
+      // we will simply not allow 0 byte allocs at all, of any kind
+      ERROR("ALERT ALERT attempt to kmalloc zero bytes rejected\n");
+      return NULL;
+    }
+
     addr = kmalloc(size+2*ALLOC_PAD, flags);
 
     if (!addr) { 
@@ -209,6 +227,8 @@ palacios_alloc_extended(unsigned int size, unsigned int flags) {
     memset(addr,0,size+2*ALLOC_PAD);
 #endif
 
+    MEMCHECK_KMALLOC(addr,size+2*ALLOC_PAD);
+
     return addr+ALLOC_PAD;
 }
 
@@ -217,6 +237,11 @@ palacios_valloc(unsigned int size)
 {
     void * addr = NULL;
 
+    if (size==0) { 
+      ERROR("ALERT ALERT attempt to vmalloc zero bytes rejected\n");
+      return NULL;
+    }
+
     addr = vmalloc(size);
 
     if (!addr) { 
@@ -226,6 +251,8 @@ palacios_valloc(unsigned int size)
 
     vmallocs++;
 
+    MEMCHECK_VMALLOC(addr,size);
+
     return addr;
 }
 
@@ -233,6 +260,7 @@ void palacios_vfree(void *p)
 {
   vfree(p);
   vfrees++;
+  MEMCHECK_VFREE(p);
 }
 
 /**
@@ -264,7 +292,7 @@ palacios_free(
 {
     frees++;
     kfree(addr-ALLOC_PAD);
-    return;
+    MEMCHECK_KFREE(addr-ALLOC_PAD);
 }
 
 /**
@@ -657,6 +685,17 @@ void palacios_mutex_init(void *mutex)
   }
 }
 
+void palacios_mutex_deinit(void *mutex)
+{
+  spinlock_t *lock = (spinlock_t*)mutex;
+  
+  if (lock) {
+    // no actual spin_lock_deinit on linux
+    // our purpose here is to drive the lock checker
+    LOCKCHECK_FREE(lock);
+  }
+}
+
 
 /**
  * Frees a mutex.