X-Git-Url: http://v3vee.org/palacios/gitweb/gitweb.cgi?a=blobdiff_plain;f=palacios%2Fsrc%2Fdevices%2Framdisk.c;h=a17d9aec7906fead668378b9761ca6650b8c4d4f;hb=e5025259695bdad570649b0f39329d135428f388;hp=5695bc48f03e58bf5d22d7663f8d49a004b8ef70;hpb=72420d58d18ec71d4777d029daaf0c6a1c820b32;p=palacios.git diff --git a/palacios/src/devices/ramdisk.c b/palacios/src/devices/ramdisk.c index 5695bc4..a17d9ae 100644 --- a/palacios/src/devices/ramdisk.c +++ b/palacios/src/devices/ramdisk.c @@ -21,7 +21,7 @@ #include -#ifndef CONFIG_DEBUG_RAMDISK +#ifndef V3_CONFIG_DEBUG_RAMDISK #undef PrintDebug #define PrintDebug(fmt, args...) #endif @@ -37,6 +37,12 @@ static int read(uint8_t * buf, uint64_t lba, uint64_t num_bytes, void * private_ PrintDebug("Reading %d bytes from %p to %p\n", (uint32_t)num_bytes, (uint8_t *)(disk->disk_image + lba), buf); + if (lba + num_bytes > disk->capacity) { + PrintError("read out of bounds: lba=%llu (%p), num_bytes=%llu, capacity=%d (%p)\n", + lba, (void *)(addr_t)lba, num_bytes, disk->capacity, (void *)(addr_t)disk->capacity); + return -1; + } + memcpy(buf, (uint8_t *)(disk->disk_image + lba), num_bytes); return 0; @@ -48,6 +54,13 @@ static int write(uint8_t * buf, uint64_t lba, uint64_t num_bytes, void * private PrintDebug("Writing %d bytes from %p to %p\n", (uint32_t)num_bytes, buf, (uint8_t *)(disk->disk_image + lba)); + if (lba + num_bytes > disk->capacity) { + PrintError("write out of bounds: lba=%llu (%p), num_bytes=%llu, capacity=%d (%p)\n", + lba, (void *)(addr_t)lba, num_bytes, disk->capacity, (void *)(addr_t)disk->capacity); + return -1; + } + + memcpy((uint8_t *)(disk->disk_image + lba), buf, num_bytes); return 0; @@ -72,12 +85,14 @@ static struct v3_dev_blk_ops blk_ops = { -static int disk_free(struct vm_device * dev) { +static int disk_free(struct disk_state * state) { + + V3_Free(state); return 0; } static struct v3_device_ops dev_ops = { - .free = disk_free, + .free = (int (*)(void *))disk_free, };