#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;
}
+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;
}
/**
)
{
frees++;
- kfree(addr);
+ kfree(addr-ALLOC_PAD);
return;
}
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);