-/* \r
- * Ringbuffer Routines for VM\r
- * (c) Lei Xia, 2010\r
+/*\r
+ * Ringbuffer implementation\r
+ * (c) Lei Xia 2010\r
*/\r
+ \r
+\r
#include <linux/errno.h>\r
#include <linux/percpu.h>\r
#include <linux/sched.h>\r
#include "util-ringbuffer.h"\r
\r
void init_ringbuf(struct ringbuf * ring, unsigned int size) {\r
- ring->buf = kmalloc(size, GFP_KERNEL);\r
+ ring->buf = palacios_alloc(size);\r
+\r
+ if (!(ring->buf)) { \r
+ ERROR("Cannot allocate ring buffer data\n");\r
+ size=0;\r
+ }\r
+\r
ring->size = size;\r
\r
ring->start = 0;\r
}\r
\r
struct ringbuf * create_ringbuf(unsigned int size) {\r
- struct ringbuf * ring = (struct ringbuf *)kmalloc(sizeof(struct ringbuf), GFP_KERNEL);\r
+ struct ringbuf * ring = (struct ringbuf *)palacios_alloc(sizeof(struct ringbuf));\r
+\r
+ if (!ring) { \r
+ ERROR("Cannot allocate ring buffer\n");\r
+ return NULL;\r
+ }\r
+\r
init_ringbuf(ring, size);\r
\r
return ring;\r
}\r
\r
void free_ringbuf(struct ringbuf * ring) {\r
- kfree(ring->buf);\r
- kfree(ring);\r
+ palacios_free(ring->buf);\r
+ palacios_free(ring);\r
}\r
\r
static inline unsigned char * get_read_ptr(struct ringbuf * ring) {\r