#ifdef __V3VEE__
#include <palacios/vmm_types.h>
+#include <palacios/vmm_lock.h>
struct v3_bitmap {
+ v3_lock_t lock;
int num_bits; // number of valid bit positions in the bitmap
uint8_t * bits; // actual bitmap. Dynamically allocated... ugly
};
int v3_bitmap_init(struct v3_bitmap * bitmap, int num_bits) {
int num_bytes = (num_bits / 8) + ((num_bits % 8) > 0);
+ v3_lock_init(&(bitmap->lock));
bitmap->num_bits = num_bits;
bitmap->bits = V3_Malloc(num_bytes);
+
if (bitmap->bits == NULL) {
PrintError("Could not allocate bitmap of %d bits\n", num_bits);
return -1;
int major = index / 8;
int minor = index % 8;
int old_val = 0;
+ uint32_t flags = 0;
if (index > (bitmap->num_bits - 1)) {
PrintError("Index out of bitmap range: (pos = %d) (num_bits = %d)\n",
return -1;
}
+
+ flags = v3_lock_irqsave(bitmap->lock);
+
old_val = (bitmap->bits[major] & (0x1 << minor));
bitmap->bits[major] |= (0x1 << minor);
+ v3_unlock_irqrestore(bitmap->lock, flags);
+
return old_val;
}
int major = index / 8;
int minor = index % 8;
int old_val = 0;
+ uint32_t flags = 0;
if (index > (bitmap->num_bits - 1)) {
PrintError("Index out of bitmap range: (pos = %d) (num_bits = %d)\n",
return -1;
}
+ flags = v3_lock_irqsave(bitmap->lock);
+
old_val = (bitmap->bits[major] & (0x1 << minor));
bitmap->bits[major] &= ~(0x1 << minor);
+ v3_unlock_irqrestore(bitmap->lock, flags);
+
return old_val;
}