X-Git-Url: http://v3vee.org/palacios/gitweb/gitweb.cgi?a=blobdiff_plain;f=linux_module%2Fpalacios-stubs.c;h=72604d3cb4aa7a9d9a8f911fac6f5a9e10125012;hb=4a63fd4cef38da57f4b44d8ac88737faa0a12846;hp=ec58c04dd07865154c028101a6e7ad618a6740d5;hpb=298a05652b5704f9881af0683e3f16fc4cd03959;p=palacios.releases.git diff --git a/linux_module/palacios-stubs.c b/linux_module/palacios-stubs.c index ec58c04..72604d3 100644 --- a/linux_module/palacios-stubs.c +++ b/linux_module/palacios-stubs.c @@ -14,16 +14,17 @@ #include #include #include +#include #include #include #include "palacios.h" - - - #include "mm.h" +#include "memcheck.h" +#include "lockcheck.h" + // The following can be used to track heap bugs // zero memory after allocation #define ALLOC_ZERO_MEM 0 @@ -35,7 +36,8 @@ u32 pg_allocs = 0; u32 pg_frees = 0; u32 mallocs = 0; u32 frees = 0; - +u32 vmallocs = 0; +u32 vfrees = 0; static struct v3_vm_info * irq_to_guest_map[256]; @@ -175,6 +177,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; } @@ -188,6 +192,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); + } @@ -208,9 +214,36 @@ palacios_alloc_extended(unsigned int size, unsigned int flags) { memset(addr,0,size+2*ALLOC_PAD); #endif + MEMCHECK_KMALLOC(addr+ALLOC_PAD,size+2*ALLOC_PAD); + return addr+ALLOC_PAD; } +void * +palacios_valloc(unsigned int size) +{ + void * addr = NULL; + + addr = vmalloc(size); + + if (!addr) { + ERROR("ALERT ALERT vmalloc has FAILED FAILED FAILED\n"); + return NULL; + } + + vmallocs++; + + MEMCHECK_VMALLOC(addr,size); + + return addr; +} + +void palacios_vfree(void *p) +{ + vfree(p); + vfrees++; + MEMCHECK_VFREE(p); +} /** * Allocates 'size' bytes of kernel memory. @@ -241,7 +274,7 @@ palacios_free( { frees++; kfree(addr-ALLOC_PAD); - return; + MEMCHECK_KFREE(addr-ALLOC_PAD); } /** @@ -615,6 +648,7 @@ palacios_mutex_alloc(void) if (lock) { spin_lock_init(lock); + LOCKCHECK_ALLOC(lock); } else { ERROR("ALERT ALERT Unable to allocate lock\n"); return NULL; @@ -623,12 +657,24 @@ palacios_mutex_alloc(void) return lock; } +void palacios_mutex_init(void *mutex) +{ + spinlock_t *lock = (spinlock_t*)mutex; + + if (lock) { + spin_lock_init(lock); + LOCKCHECK_ALLOC(lock); + } +} + + /** * Frees a mutex. */ void palacios_mutex_free(void * mutex) { palacios_free(mutex); + LOCKCHECK_FREE(mutex); } /** @@ -637,6 +683,7 @@ palacios_mutex_free(void * mutex) { void palacios_mutex_lock(void * mutex, int must_spin) { spin_lock((spinlock_t *)mutex); + LOCKCHECK_LOCK(mutex); } @@ -649,6 +696,7 @@ palacios_mutex_lock_irqsave(void * mutex, int must_spin) { unsigned long flags; spin_lock_irqsave((spinlock_t *)mutex,flags); + LOCKCHECK_LOCK_IRQSAVE(mutex,flags); return (void *)flags; } @@ -663,6 +711,7 @@ palacios_mutex_unlock( ) { spin_unlock((spinlock_t *)mutex); + LOCKCHECK_UNLOCK(mutex); } @@ -674,6 +723,7 @@ palacios_mutex_unlock_irqrestore(void *mutex, void *flags) { // This is correct, flags is opaque spin_unlock_irqrestore((spinlock_t *)mutex,(unsigned long)flags); + LOCKCHECK_UNLOCK_IRQRESTORE(mutex,(unsigned long)flags); } /**