//#include <palacios/svm.h>
+#define V3_MAX_TAG_LEN 256
+
struct v3_vm_info;
struct v3_vm_info * v3_config_guest( void * cfg_blob, void * priv_data);
void * data;
uint64_t size;
- char tag[256];
+ char tag[V3_MAX_TAG_LEN];
struct list_head file_node;
};
#include <palacios/vmm_rbtree.h>
+#define V3_MTREE_NAME_LEN 50
struct v3_mtree {
- char name[50];
+ char name[V3_MTREE_NAME_LEN];
union {
uint8_t flags;
struct dma_state * dma = NULL;
dma = (struct dma_state *)V3_Malloc(sizeof(struct dma_state));
- V3_ASSERT(dma != NULL);
+
+ if (!dma) {
+ PrintError("Cannot allocate\n");
+ return NULL;
+ }
struct vm_device * dev = v3_create_device("DMA", &dev_ops, dma);
pit_state = (struct pit *)V3_Malloc(sizeof(struct pit));
- V3_ASSERT(pit_state != NULL);
+ if (!pit_state) {
+ PrintError("Cannot allocate in init\n");
+ return -1;
+ }
+
pit_state->speaker = 0;
pit_state->vm = vm;
state = (struct pic_internal *)V3_Malloc(sizeof(struct pic_internal));
- V3_ASSERT(state != NULL);
+ if (!state) {
+ PrintError("Cannot allocate in init\n");
+ return -1;
+ }
struct vm_device * dev = v3_add_device(vm, dev_id, &dev_ops, state);
apic_dev = (struct apic_dev_state *)V3_Malloc(sizeof(struct apic_dev_state) +
sizeof(struct apic_state) * vm->num_cores);
+
+ if (!apic_dev) {
+ PrintError("Failed to allocate space for APIC\n");
+ return -1;
+ }
+
apic_dev->num_apics = vm->num_cores;
v3_lock_init(&(apic_dev->state_lock));
PrintDebug("video: init_device\n");
video_state = (struct video_internal *)V3_Malloc(sizeof(struct video_internal));
+
+ if (!video_state) {
+ PrintError("Cannot allocate space for CGA state\n");
+ return -1;
+ }
+
memset(video_state, 0, sizeof(struct video_internal));
struct vm_device * dev = v3_add_device(vm, dev_id, &dev_ops, video_state);
video_state->dev = dev;
video_state->framebuf_pa = (addr_t)V3_AllocPages(FRAMEBUF_SIZE / 4096);
+
+ if (!video_state->framebuf_pa) {
+ PrintError("Cannot allocate frame buffer\n");
+ V3_Free(video_state);
+ return -1;
+ }
+
video_state->framebuf = V3_VAddr((void *)(video_state->framebuf_pa));
+
memset(video_state->framebuf, 0, FRAMEBUF_SIZE);
PrintDebug("PA of array: %p\n", (void *)(video_state->framebuf_pa));
struct vm_device * pci_bus = v3_find_dev(vm, v3_cfg_val(cfg, "bus"));
char * dev_id = v3_cfg_val(cfg, "ID");
+
+ if (!video_state) {
+ PrintError("Cannot allocate state in cirrus gfx\n");
+ return -1;
+ }
+
struct vm_device * dev = v3_add_device(vm, dev_id, &dev_ops, video_state);
if (dev == NULL) {
PrintError("Could not attach device %s\n", dev_id);
+ V3_Free(video_state)
return -1;
}
PrintDebug("Num Pages=%d\n", SIZE_OF_REGION / 4096);
video_state->video_memory_pa = (addr_t)V3_AllocPages(SIZE_OF_REGION / 4096);
+ if (!video_state->video_memory_pa) {
+ PrintError("Cannot allocate video memory\n");
+ V3_Free(video_state);
+ return -1;
+ }
+
video_state->video_memory = V3_VAddr((void *)video_state->video_memory_pa);
memset(video_state->video_memory, 0, SIZE_OF_REGION);
/* allocate state */
state = (struct cons_state *)V3_Malloc(sizeof(struct cons_state));
- V3_ASSERT(state);
+
+ if (!state) {
+ PrintError("Cannot allocate curses state\n");
+ V3_Free(state);
+ return -1;
+ }
state->frontend_dev = frontend;
state->cols = 80;
state->rows = 25;
state->framebuf = V3_Malloc(state->cols * state->rows * BYTES_PER_COL);
+ if (!state->framebuf) {
+ PrintError("Cannot allocate frame buffer\n");
+ V3_Free(state);
+ return -1;
+ }
/* open tty for screen display */
state->cons = v3_console_open(vm, state->cols, state->rows);
if (!state->cons) {
PrintError("Could not open console\n");
+ V3_Free(state->framebuf);
V3_Free(state);
return -1;
}
if (dev == NULL) {
PrintError("Could not attach device %s\n", dev_id);
+ V3_Free(state->framebuf);
V3_Free(state);
return -1;
}
uint32_t seek_time = atoi(v3_cfg_val(cfg, "seek_us"));
struct disk_state * model = (struct disk_state *)V3_Malloc(sizeof(struct disk_state));
+ if (!model) {
+ PrintError("Cannot allocate\n");
+ return -1;
+ }
model->ops = ops;
model->seek_usecs = seek_time;
state = (struct i440_state *)V3_Malloc(sizeof(struct i440_state));
+ if (!state) {
+ PrintError("Cannot allocate state\n");
+ return -1;
+ }
+
state->pci = pci;
struct vm_device * dev = v3_add_device(vm, dev_id, &dev_ops, state);
struct io_apic_state * ioapic = (struct io_apic_state *)V3_Malloc(sizeof(struct io_apic_state));
+ if (!ioapic) {
+ PrintError("Cannot allocate in init\n");
+ return -1;
+ }
+
ioapic->apic_dev_data = apic_dev;
struct vm_device * dev = v3_add_device(vm, dev_id, &dev_ops, ioapic);
kbd = (struct keyboard_internal *)V3_Malloc(sizeof(struct keyboard_internal));
+ if (!kbd) {
+ PrintError("Cannot allocate in init\n");
+ return -1;
+ }
+
memset(kbd, 0, sizeof(struct keyboard_internal));
kbd->vm = vm;
virtio_state = (struct virtio_balloon_state *)V3_Malloc(sizeof(struct virtio_balloon_state));
+
+ if (!virtio_state) {
+ PrintError("Cannot allocate in init\n");
+ return -1;
+ }
+
memset(virtio_state, 0, sizeof(struct virtio_balloon_state));
struct virtio_dev_state * virtio = (struct virtio_dev_state *)frontend_data;
struct virtio_blk_state * blk_state = (struct virtio_blk_state *)V3_Malloc(sizeof(struct virtio_blk_state));
+
+ if (!blk_state) {
+ PrintError("Cannot allocate in connect\n");
+ return -1;
+ }
+
+
memset(blk_state, 0, sizeof(struct virtio_blk_state));
register_dev(virtio, blk_state);
virtio_state = (struct virtio_dev_state *)V3_Malloc(sizeof(struct virtio_dev_state));
+
+ if (!virtio_state) {
+ PrintError("Cannot allocate in init\n");
+ return -1;
+ }
+
memset(virtio_state, 0, sizeof(struct virtio_dev_state));
INIT_LIST_HEAD(&(virtio_state->dev_list));
virtio_state = (struct virtio_console_state *)V3_Malloc(sizeof(struct virtio_console_state));
+
+ if (!virtio_state) {
+ PrintError("Cannot allocate in init\n");
+ return -1;
+ }
+
memset(virtio_state, 0, sizeof(struct virtio_console_state));
struct virtio_dev_state * virtio = (struct virtio_dev_state *)frontend_data;
struct virtio_net_state * net_state = (struct virtio_net_state *)V3_Malloc(sizeof(struct virtio_net_state));
+ if (!net_state) {
+ PrintError("Cannot allocate in connect\n");
+ return -1;
+ }
+
memset(net_state, 0, sizeof(struct virtio_net_state));
register_dev(virtio, net_state);
}
virtio_state = (struct virtio_dev_state *)V3_Malloc(sizeof(struct virtio_dev_state));
+
+ if (!virtio_state) {
+ PrintError("Cannot allocate in init\n");
+ return -1;
+ }
+
memset(virtio_state, 0, sizeof(struct virtio_dev_state));
INIT_LIST_HEAD(&(virtio_state->dev_list));
virtio_state = (struct virtio_sym_state *)V3_Malloc(sizeof(struct virtio_sym_state));
+
+ if (!virtio_state) {
+ PrintError("Cannot allocate in init\n");
+ return -1;
+ }
+
memset(virtio_state, 0, sizeof(struct virtio_sym_state));
}
virtio_state = (struct virtio_sym_state *)V3_Malloc(sizeof(struct virtio_sym_state));
+
+ if (!virtio_state) {
+ PrintError("Cannot allocate in init\n");
+ return -1;
+ }
+
memset(virtio_state, 0, sizeof(struct virtio_sym_state));
virtio_state->vm = vm;
}
vnet_state = (struct virtio_vnet_state *)V3_Malloc(sizeof(struct virtio_vnet_state));
+
+ if (!vnet_state) {
+ PrintError("Cannot allocate in init\n");
+ return -1;
+ }
+
memset(vnet_state, 0, sizeof(struct virtio_vnet_state));
vnet_state->vm = vm;
char * macstr = v3_cfg_val(cfg, "mac");
nic_state = (struct ne2k_state *)V3_Malloc(sizeof(struct ne2k_state));
+
+ if (!nic_state) {
+ PrintError("Cannot allocate in init\n");
+ return -1;
+ }
+
memset(nic_state, 0, sizeof(struct ne2k_state));
nic_state->pci_bus = pci_bus;
static int disk_init(struct v3_vm_info * vm, v3_cfg_tree_t * cfg) {
struct disk_state * disk = (struct disk_state *)V3_Malloc(sizeof(struct disk_state));
+ if (!disk) {
+ PrintError("Cannot allocate in init\n");
+ return -1;
+ }
+
char * ip_str = v3_cfg_val(cfg, "IP");
char * port_str = v3_cfg_val(cfg, "port");
char * disk_tag = v3_cfg_val(cfg, "tag");
}
bridge = (struct nic_bridge_state *)V3_Malloc(sizeof(struct nic_bridge_state));
+
+ if (!bridge) {
+ PrintError("Cannot allocate in init\n");
+ return -1;
+ }
+
memset(bridge, 0, sizeof(struct nic_bridge_state));
struct vm_device * dev = v3_add_device(vm, dev_id, &dev_ops, bridge);
PrintDebug("nvram: init_device\n");
nvram_state = (struct nvram_internal *)V3_Malloc(sizeof(struct nvram_internal) + 1000);
+ if (!nvram_state) {
+ PrintError("Cannot allocate in init\n");
+ return -1;
+ }
+
PrintDebug("nvram: internal at %p\n", (void *)nvram_state);
nvram_state->ide = ide;
state = (struct debug_state *)V3_Malloc(sizeof(struct debug_state));
+ if (!state) {
+ PrintError("Cannot allocate in init\n");
+ return -1;
+ }
+
PrintDebug("Creating OS Debug Device\n");
struct vm_device * dev = v3_add_device(vm, dev_id, &dev_ops, state);
addr_t pkt_gpa = info->vm_regs.rbx;
int pkt_len = info->vm_regs.rcx;
uchar_t * pkt = V3_Malloc(pkt_len);
+
+ if (!pkt) {
+ PrintError("Cannot allocate in transmit!\n");
+ return -1;
+ }
PrintDebug("Transmitting Packet\n");
state = (struct nic_state *)V3_Malloc(sizeof(struct nic_state));
+ if (!state) {
+ PrintError("Cannot allocate in init\n");
+ return -1;
+ }
+
PrintDebug("Creating VMNet Device\n");
struct vm_device * dev = v3_allocate_device(dev_id, &dev_ops, state);
static int pci_init(struct v3_vm_info * vm, v3_cfg_tree_t * cfg) {
struct pci_internal * pci_state = V3_Malloc(sizeof(struct pci_internal));
+
+ if (!pci_state) {
+ PrintError("Cannot allocate in init\n");
+ return -1;
+ }
+
int i = 0;
char * dev_id = v3_cfg_val(cfg, "ID");
int ret = 0;
struct vm_device * pci = v3_find_dev(vm, v3_cfg_val(cfg, "bus"));
char * dev_id = v3_cfg_val(cfg, "ID");
+ if (!state) {
+ PrintError("Cannot allocate in init\n");
+ return -1;
+ }
memset(state, 0, sizeof(struct pt_dev_state));
struct vm_device * pci = v3_find_dev(vm, v3_cfg_val(cfg, "bus"));
char * dev_id = v3_cfg_val(cfg, "ID");
+ if (!piix3) {
+ PrintError("Cannot allocate in init\n");
+ return -1;
+ }
+
if (!pci) {
PrintError("Could not find PCI device\n");
return -1;
disk = (struct disk_state *)V3_Malloc(sizeof(struct disk_state));
+
+ if (!disk) {
+ PrintError("Cannot allocate in init\n");
+ return -1;
+ }
+
memset(disk, 0, sizeof(struct disk_state));
disk->disk_image = file->data;
char * macstr = v3_cfg_val(cfg, "mac");
nic_state = (struct rtl8139_state *)V3_Malloc(sizeof(struct rtl8139_state));
+
+ if (!nic_state) {
+ PrintError("Cannot allocate in init\n");
+ return -1;
+ }
+
memset(nic_state, 0, sizeof(struct rtl8139_state));
nic_state->pci_bus = pci_bus;
static int pic_init(struct guest_info * vm, void * cfg_data) {
struct pic_internal * state = NULL;
state = (struct pic_internal *)V3_Malloc(sizeof(struct pic_internal));
- V3_ASSERT(state != NULL);
+
+ if (!state) {
+ PrintError("Cannot allocate in init\n");
+ return -1;
+ }
struct vm_device * dev = v3_allocate_device("SIMPLE_PIC", &dev_ops, state);
if (v3_attach_device(vm, dev) == -1) {
PrintError("Could not attach device %s\n", "SIMPLE_PIC");
+ V3_Free(state);
return -1;
}
swap = (struct swap_state *)V3_Malloc(sizeof(struct swap_state) + ((capacity / 4096) / 8));
+ if (!swap) {
+ PrintError("Cannot allocate in init\n");
+ return -1;
+ }
+
swap->vm = vm;
swap->capacity = capacity;
swap->hdr = (union swap_header *)swap;
swap->swap_base_addr = (addr_t)V3_AllocPages(swap->capacity / 4096);
+
+ if (!swap->swap_base_addr) {
+ PrintError("Cannot allocate swap space\n");
+ V3_Free(swap);
+ return -1;
+ }
+
swap->swap_space = (uint8_t *)V3_VAddr((void *)(swap->swap_base_addr));
memset(swap->swap_space, 0, swap->capacity);
swap = (struct swap_state *)V3_Malloc(sizeof(struct swap_state));
+ if (!swap) {
+ PrintError("Cannot allocate in connect\n");
+ return -1;
+ }
+
swap->vm = vm;
swap->cache_size = cache_size;
swap->io_flag = 0;
INIT_LIST_HEAD(&(swap->entry_list));
INIT_LIST_HEAD(&(swap->free_list));
swap->entry_map = (struct cache_entry *)V3_Malloc(sizeof(struct cache_entry) * (cache_size / 4096));
+
+ if (!swap->entry_map) {
+ PrintError("Cannot allocate in connect\n");
+ return -1;
+ }
+
for (i = 0; i < (cache_size / 4096); i++) {
list_add(&(swap->entry_map[i].cache_node), &(swap->free_list));
swap->active = 0;
swap->cache_base_addr = (addr_t)V3_AllocPages(swap->cache_size / 4096);
+
+ if (!swap->cache_base_addr) {
+ PrintError("Cannot allocate cache space\n");
+ V3_Free(swap);
+ return -1;
+ }
+
+
swap->cache = (uint8_t *)V3_VAddr((void *)(addr_t)(swap->cache_base_addr));
memset(swap->cache, 0, swap->cache_size);
}
struct vm_device * frontend = v3_find_dev(vm, v3_cfg_val(frontend_cfg, "tag"));
char * dev_id = v3_cfg_val(cfg, "ID");
+ if (!state) {
+ PrintError("Cannot allocate in init\n");
+ return -1;
+ }
+
+
state->vm = vm;
state->server_fd = 0;
state->client_fd = 0;
static int timer_init(struct guest_info * vm, void * cfg_data) {
struct timer_state * timer = NULL;
timer = (struct timer_state *)V3_Malloc( sizeof(struct timer_state));
- V3_ASSERT(timer != NULL);
+
+ if (!timer) {
+ PrintError("Cannot allocate in init\n");
+ return -1;
+ }
struct vm_device * dev = v3_allocate_device("TIMER", &dev_ops, timer);
blk = (struct blk_state *)V3_Malloc(sizeof(struct blk_state));
+ if (!blk) {
+ PrintError("Cannot allocate in init\n");
+ return -1;
+ }
+
blk->capacity = capacity;
blk->blk_base_addr = (addr_t)V3_AllocPages(blk->capacity / 4096);
+
+ if (!blk->blk_base_addr) {
+ PrintError("Cannot allocate block space\n");
+ V3_Free(blk);
+ return -1;
+ }
+
blk->blk_space = (uint8_t *)V3_VAddr((void *)(blk->blk_base_addr));
memset(blk->blk_space, 0, capacity);
// Now allocate the maps
for (i=0;i<MAP_NUM;i++) {
- vga->map[i] = (vga_map) V3_VAddr((void*)V3_AllocPages(MAP_SIZE/4096));
- if (!(vga->map[i])) {
+ void *temp;
+
+ temp = (void*)V3_AllocPages(MAP_SIZE/4096);
+ if (!temp) {
PrintError("vga: cannot allocate maps\n");
free_vga(vga);
return -1;
}
+
+ vga->map[i] = (vga_map) V3_VAddr(temp);
+
memset(vga->map[i],0,MAP_SIZE);
}
v3_cfg_tree_t * frontend_cfg = v3_cfg_subtree(cfg, "frontend");
vnetnic = (struct vnet_nic_state *)V3_Malloc(sizeof(struct vnet_nic_state));
+
+ if (!vnetnic) {
+ PrintError("Cannot allocate in init\n");
+ return -1;
+ }
+
memset(vnetnic, 0, sizeof(struct vnet_nic_state));
struct vm_device * dev = v3_add_device(vm, dev_id, &dev_ops, vnetnic);
static int init_inspector(struct v3_vm_info * vm, v3_cfg_tree_t * cfg, void ** priv_data) {
struct v3_inspector_state * state = V3_Malloc(sizeof(struct v3_inspector_state));
+
+ if (!state) {
+ PrintError("Cannot allocate state in inspector\n");
+ return -1;
+ }
+
memset(state, 0, sizeof(struct v3_inspector_state));
strncpy(state->state_tree.name, "vm->name", 50);
state = (struct mcheck_state *)V3_Malloc(sizeof(struct mcheck_state));
if (state == NULL) {
- PrintError(MSG_PRE "Failed to allocate machine-check architecture state.\n");
- return -1;
+ PrintError(MSG_PRE "Failed to allocate machine-check architecture state.\n");
+ return -1;
}
int ret = 0;
state = V3_Malloc(sizeof(struct mtrr_state));
+
+ if (!state) {
+ PrintError("Cannot allocate in initializing MTRRs\n");
+ return -1;
+ }
+
+
memset(state, 0, sizeof(struct mtrr_state));
*priv_data = state;
// first back up old code
inject->old_code = (char*)V3_Malloc(size);
+
+ if (!inject->old_code) {
+ PrintError("Cannot allocate in planting code\n");
+ return -1;
+ }
+
for (i = 0; i < size; i++)
inject->old_code[i] = *(hva + i);
}
inject->old_code = V3_Malloc(MUNMAP_SIZE);
+
if (!inject->old_code) {
PrintError("Problem mallocing old code segment\n");
return -1;
PrintDebug("Found a page we need to fault in\n");
inject->cont = (struct v3_cont *)V3_Malloc(sizeof(struct v3_cont));
+
+ if (!inject->cont) {
+ PrintError("Cannot allocate in doing inject\n");
+ return -1;
+ }
+
ret = v3_gva_to_gpa(core, elf_gva, &elf_hva);
if (ret == -1) {
struct v3_env_injects * injects = &env_injects;
struct v3_env_inject_info * inject = V3_Malloc(sizeof(struct v3_env_inject_info));
+ if (!inject) {
+ PrintError("Cannot allocate in inserting environment inject\n");
+ return -1;
+ }
+
+
memset(inject, 0, sizeof(struct v3_env_inject_info));
inject->env_vars = strings;
struct exec_hook * hook = V3_Malloc(sizeof(struct exec_hook));
struct v3_exec_hooks * hooks = &exec_hooks;
addr_t key;
+
+ if (!hook) {
+ PrintError("Cannot allocate in hooking exec\n");
+ return -1;
+ }
memset(hook, 0, sizeof(struct exec_hook));
/* account for new args */
argc += argcnt;
var_dump.argv = (char**)V3_Malloc(sizeof(char*)*argc);
+
+ if (!var_dump.argv) {
+ PrintError("Cannot allocate in copying\n");
+ return -1;
+ }
+
var_dump.argc = argc;
bytes += sizeof(uint32_t)*argc;
/* malloc room for the string */
char * tmpstr = (char*)V3_Malloc(strlen((char*)argvn) + 1);
+ if (!tmpstr) {
+ PrintError("Cannot allocate temporary\n");
+ return -1;
+ }
+
/* copy the pointer */
var_dump.argv[i] = tmpstr;
int j = 0;
while (j < argcnt) {
char * tmpstr = (char*)V3_Malloc(strlen(argstrs[j]) + 1);
+
+ if (!tmpstr) {
+ PrintError("Cannot allocate temp string\n");
+ return -1;
+ }
+
strncpy(tmpstr, argstrs[i], strlen(argstrs[j]) + 1);
var_dump.argv[i] = tmpstr;
bytes += strlen(argstrs[j]) + 1;
envc += envcnt;
var_dump.envp = (char**)V3_Malloc(sizeof(char*)*envc);
+
+ if (!var_dump.envp) {
+ PrintError("Cannot allocate var dump\n");
+ return -1;
+ }
+
var_dump.envc = envc;
bytes += sizeof(uint32_t)*envc;
/* malloc room for the string */
char * tmpstr = (char*)V3_Malloc(strlen((char*)envpn) + 1);
+
+ if (!tmpstr) {
+ PrintError("Cannot allocate temp string\n");
+ return -1;
+ }
/* copy the pointer */
var_dump.envp[i] = tmpstr;
j = 0;
while (j < envcnt) {
char * tmpstr = (char*)V3_Malloc(strlen(envstrs[j]) + 1);
+
+ if (!tmpstr) {
+ PrintError("Cannot allocate temp string\n");
+ return -1;
+ }
+
strncpy(tmpstr, envstrs[j], strlen(envstrs[j]) + 1);
var_dump.envp[i] = tmpstr;
bytes += strlen(envstrs[j]) + 1;
/* account for new strings */
argc += argcnt;
var_dump.argv = (char**)V3_Malloc(sizeof(char*)*argc);
+
+ if (!var_dump.argv) {
+ PrintError("Cannot allocate var dump\n");
+ return -1;
+ }
+
var_dump.argc = argc;
bytes += sizeof(char*)*argc;
/* malloc room for the string */
char * tmpstr = (char*)V3_Malloc(strlen((char*)argvn) + 1);
+ if (!tmpstr) {
+ PrintError("Cannot allocate temp string\n");
+ return -1;
+ }
+
/* copy the pointer */
var_dump.argv[i] = tmpstr;
int j = 0;
while (j < argcnt) {
char * tmpstr = (char*)V3_Malloc(strlen(argstrs[j]) + 1);
+
+ if (!tmpstr) {
+ PrintError("Cannot allocate temp string\n");
+ return -1;
+ }
+
strncpy(tmpstr, argstrs[j], strlen(argstrs[j]) + 1);
var_dump.argv[i] = tmpstr;
bytes += strlen(argstrs[j]) + 1;
envc += envcnt;
var_dump.envp = (char**)V3_Malloc(sizeof(char*)*envc);
+
+ if (!var_dump.envp) {
+ PrintError("Cannot allocate var dump\n");
+ return -1;
+ }
+
var_dump.envc = envc;
bytes += sizeof(uint64_t)*(envc);
/* malloc room for the string */
char * tmpstr = (char*)V3_Malloc(strlen((char*)envpn) + 1);
+
+ if (!tmpstr) {
+ PrintError("Cannot allocate temp string\n");
+ return -1;
+ }
/* copy the pointer */
var_dump.envp[i] = tmpstr;
j = 0;
while (j < envcnt) {
char * tmpstr = (char*)V3_Malloc(strlen(envstrs[j]) + 1);
+
+ if (!tmpstr) {
+ PrintError("Cannot allocate temp string\n");
+ return -1;
+ }
+
strncpy(tmpstr, envstrs[i], strlen(envstrs[j]) + 1);
var_dump.envp[i] = tmpstr;
bytes += strlen(envstrs[j]) + 1;
struct v3_swintr_hook * hook = (struct v3_swintr_hook*)V3_Malloc(sizeof(struct v3_swintr_hook));
if (hook == NULL) {
+ PrintError("Cannot allocate for swintr hook\n");
return -1;
}
if (hook == NULL) {
+ PrintError("Cannot allocate for syscall hook\n");
return -1;
}
struct bounce_data *b = V3_Malloc(sizeof(struct bounce_data));
if (!b) {
- return -1;
+ PrintError("Unable to allocate in registering host hypercall\n");
+ return -1;
}
b->hypercall=hypercall;
hypercall_id,
bounce,
b) < 0) {
- return -1;
+ PrintError("Cannot register host hypercall\n");
+ V3_Free(b);
+ return -1;
}
return 0;
packet = V3_Malloc(sizeof(struct v3_packet));
+ if (!packet) {
+ PrintError("Cannot allocate in connecting packet\n");
+ return NULL;
+ }
+
memcpy(packet->dev_mac, vm_mac, ETH_ALEN);
packet->input = input;
packet->guest_packet_data = guest_packet_data;
stream = V3_Malloc(sizeof(struct v3_stream));
+ if (!stream) {
+ PrintError("Cannot allocate in opening a stream\n");
+ return NULL;
+ }
+
stream->input = input;
stream->guest_stream_data = guest_stream_data;
stream->host_stream_data = stream_hooks->open(stream, name, vm->host_priv_data);
if (rmap_list == NULL) {
rmap_list = V3_Malloc(sizeof(struct list_head));
+
+ if (!rmap_list) {
+ PrintError("Cannot allocate\n");
+ return -1;
+ }
+
INIT_LIST_HEAD(rmap_list);
v3_htable_insert(cache_state->reverse_map, gpa, (addr_t)rmap_list);
entry = V3_Malloc(sizeof(struct rmap_entry));
+ if (!entry) {
+ PrintError("Cannot allocate\n");
+ return -1;
+ }
+
entry->gva = gva;
entry->gpa = pg_data->tuple.gpa;
entry->pt_type = pg_data->tuple.pt_type;
static int link_shdw_pg(struct shdw_pg_data * child_pg, struct shdw_pg_data * parent_pg, addr_t gva) {
struct shdw_back_ptr * back_ptr = V3_Malloc(sizeof(struct shdw_back_ptr));
+
+ if (!back_ptr) {
+ PrintError("Cannot allocate\n");
+ return -1;
+ }
+
memset(back_ptr, 0, sizeof(struct shdw_back_ptr));
back_ptr->pg_data = parent_pg;
if (cache_state->pgs_in_cache < cache_state->max_cache_pgs) {
pg_data = V3_Malloc(sizeof(struct shdw_pg_data));
+ if (!pg_data) {
+ PrintError("Cannot allocate\n");
+ return NULL;
+ }
+
pg_data->hpa = (addr_t)V3_AllocPages(1);
+
+ if (!pg_data->hpa) {
+ PrintError("Cannot allocate page for shadow page table\n");
+ return NULL;
+ }
+
pg_data->hva = (void *)V3_VAddr((void *)pg_data->hpa);
} else if (cache_state->pgs_in_free_list) {
V3_Print("Shadow Page Cache initialization\n");
cache_state = V3_Malloc(sizeof(struct cache_vm_state));
+
+ if (!cache_state) {
+ PrintError("Cannot allocate\n");
+ return -1;
+ }
+
memset(cache_state, 0, sizeof(struct cache_vm_state));
cache_state->page_htable = v3_create_htable(0, cache_hash_fn, cache_eq_fn);
V3_FreePages((void *)page->page_pa, 1);
page->page_pa=(addr_t)V3_AllocPages(1);
+
+ if (!page->page_pa) {
+ PrintError("Freeing shadow page failed on allocation\n");
+ return;
+ }
list_add(&page->link,&core->free_pages);
++core->n_free_shadow_pages;
INIT_LIST_HEAD(&page_header->link);
if (!(page_header->page_pa = (addr_t)V3_AllocPages(1))) {
+ PrintError("Allocation failed in allocating shadow page\n");
goto error_1;
}
addr_t shdw_page = (addr_t)V3_VAddr((void *)(page_header->page_pa));
}
shadow_page_put_page(core, page, shadow_pde);
PrintDebug("zap_parent: pde: shadow %p\n",(void *)*((addr_t *)shadow_pde));
- memset((void *)shadow_pde, 0, sizeof(struct pde32));
+ memset((void *)shadow_pde, 0, sizeof(uint32_t));
}
shadow_page_unlink_children(core, page);
guest_pde = (pde32_t*)&(guest_pd[i]);
present = shadow_pde->present;
if (shadow_pde->present) PrintDebug("ulink_child: pde shadow %x\n", *((uint32_t*)shadow_pde));
- memset((void*)shadow_pde, 0, sizeof(struct pde32));
+ memset((void*)shadow_pde, 0, sizeof(uint32_t));
if (present != 1) continue;
struct shadow_page_cache_data *shdw_page;
}
if (guest_pte->present == 0) {
- memset((void *)shadow_pte, 0, sizeof(struct pte32));
+ memset((void *)shadow_pte, 0, sizeof(uint32_t));
PrintDebug("\twrpf: guest non present\n");
return 0;
}
}
if (guest_pte->present == 0) {
- memset((void*)shadow_pte, 0, sizeof(struct pte64));
+ memset((void*)shadow_pte, 0, sizeof(uint64_t));
PrintDebug("\tWritePf: Guest Not Present\n");
return 0;
}
if (shdw_ptr_list == NULL) {
shdw_ptr_list = (struct list_head *)V3_Malloc(sizeof(struct list_head));
+
+ if (!shdw_ptr_list) {
+ PrintError("Cannot allocate\n");
+ return 0;
+ }
+
#ifdef V3_CONFIG_SWAPBYPASS_TELEMETRY
swap_state->list_size++;
#endif
// else
page_tail = (struct shadow_page_data *)V3_Malloc(sizeof(struct shadow_page_data));
+
+ if (!page_tail) {
+ PrintError("Cannot allocate\n");
+ return -1;
+ }
+
page_tail->page_pa = (addr_t)V3_AllocPages(1);
+ if (!page_tail->page_pa) {
+ PrintError("Cannot allocate page\n");
+ return NULL;
+ }
+
PrintDebug("Allocating new shadow Page: %p (cur_cr3=%p)\n",
(void *)(addr_t)page_tail->page_pa,
(void *)(addr_t)cur_cr3);
swapbypass_state = (struct swapbypass_local_state *)V3_Malloc(sizeof(struct swapbypass_local_state));
+ if (!swapbypass_state) {
+ PrintError("Cannot allocate\n");
+ return -1;
+ }
+
+
INIT_LIST_HEAD(&(swapbypass_state->page_list));
state->local_impl_data = swapbypass_state;
// else
page_tail = (struct shadow_page_data *)V3_Malloc(sizeof(struct shadow_page_data));
+
+ if (!page_tail) {
+ PrintError("Cannot allocate\n");
+ return NULL;
+ }
+
page_tail->page_pa = (addr_t)V3_AllocPages(1);
+ if (!page_tail->page_pa) {
+ PrintError("Cannot allocate page\n");
+ return NULL;
+ }
+
PrintDebug("Allocating new shadow Page: %p (cur_cr3=%p)\n",
(void *)(addr_t)page_tail->page_pa,
(void *)(addr_t)cur_cr3);
vtlb_state = (struct vtlb_local_state *)V3_Malloc(sizeof(struct vtlb_local_state));
+ if (!vtlb_state) {
+ PrintError("Cannot allocate\n");
+ return -1;
+ }
+
INIT_LIST_HEAD(&(vtlb_state->page_list));
state->local_impl_data = vtlb_state;
// Setup the host state save area
host_vmcbs[cpu_id] = (addr_t)V3_AllocPages(4);
+ if (!host_vmcbs[cpu_id]) {
+ PrintError("Failed to allocate VMCB\n");
+ return;
+ }
+
/* 64-BIT-ISSUE */
// msr.e_reg.high = 0;
//msr.e_reg.low = (uint_t)host_vmcb;
ctrl_area->instrs.IOIO_PROT = 1;
ctrl_area->IOPM_BASE_PA = (uint_t)V3_AllocPages(3);
+
+ if (!ctrl_area->IOPM_BASE_PA) {
+ PrintError("Cannot allocate IO bitmap\n");
+ return;
+ }
{
reg_ex_t tmp_reg;
int v3_init_svm_io_map(struct v3_vm_info * vm) {
+ void *temp;
+
vm->io_map.update_map = update_map;
- vm->io_map.arch_data = V3_VAddr(V3_AllocPages(3));
+ temp = V3_AllocPages(3);
+
+ if (!temp) {
+ PrintError("Cannot allocate io bitmap\n");
+ return -1;
+ }
+
+ vm->io_map.arch_data = V3_VAddr(temp);
+
memset(vm->io_map.arch_data, 0xff, PAGE_SIZE_4KB * 3);
int v3_init_svm_msr_map(struct v3_vm_info * vm) {
+ void *temp;
struct v3_msr_map * msr_map = &(vm->msr_map);
msr_map->update_map = update_map;
- msr_map->arch_data = V3_VAddr(V3_AllocPages(2));
+ temp = V3_AllocPages(2);
+
+ if (!temp) {
+ PrintError("Cannot allocate msr bitmap\n");
+ return -1;
+ }
+
+ msr_map->arch_data = V3_VAddr(temp);
+
memset(msr_map->arch_data, 0xff, PAGE_SIZE_4KB * 2);
v3_refresh_msr_map(vm);
ctx = V3_Malloc(sizeof(struct file_ctx));
+
+ if (!ctx) {
+ PrintError("Cannot allocate\n");
+ return NULL;
+ }
+
memset(ctx, 0, sizeof(struct file_ctx));
ctx->filename = V3_Malloc(strlen(url) + strlen(name) + 5);
+
+ if (!ctx->filename) {
+ PrintError("Cannot allocate\n");
+ V3_Free(ctx);
+ return -1;
+ }
+
+
memset(ctx->filename, 0, strlen(url) + strlen(name) + 5);
snprintf(ctx->filename, strlen(url) + strlen(name) + 5, "%s/%s", url, name);
offset += 8;
cfg = (struct v3_config *)V3_Malloc(sizeof(struct v3_config));
+
+ if (!cfg) {
+ PrintError("Unable to allocate while parsing\n");
+ return NULL;
+ }
+
memset(cfg, 0, sizeof(struct v3_config));
cfg->blob = cfg_blob;
INIT_LIST_HEAD(&(cfg->file_list));
cfg->file_table = v3_create_htable(0, file_hash_fn, file_eq_fn);
+
+ if (!(cfg->file_table)) {
+ PrintError("Unable to allocate hash table while parsing\n");
+ V3_Free(cfg);
+ return NULL;
+ }
xml_len = *(uint32_t *)(cfg_blob + offset);
offset += 4;
if (!file) {
PrintError("Could not allocate file structure\n");
+ v3_free_htable(cfg->file_table,0,0);
+ V3_Free(cfg);
return NULL;
}
V3_Print("File index=%d id=%s\n", idx, id);
- strncpy(file->tag, id, 256);
+ strncpy(file->tag, id, V3_MAX_TAG_LEN);
file->size = hdr->size;
file->data = cfg_blob + hdr->offset;
static struct v3_vm_info * allocate_guest(int num_cores) {
int guest_state_size = sizeof(struct v3_vm_info) + (sizeof(struct guest_info) * num_cores);
struct v3_vm_info * vm = V3_Malloc(guest_state_size);
+
+ if (!vm) {
+ PrintError("Unable to allocate space for guest data structures\n");
+ return NULL;
+ }
+
int i = 0;
memset(vm, 0, guest_state_size);
if (hook == NULL) {
struct masked_cpuid * mask = V3_Malloc(sizeof(struct masked_cpuid));
+
+ if (!mask) {
+ PrintError("Unable to alocate space for cpu id mask\n");
+ return -1;
+ }
+
memset(mask, 0, sizeof(struct masked_cpuid));
mask->rax_mask = rax_mask;
if (v3_hook_cpuid(vm, cpuid, mask_hook, mask) == -1) {
PrintError("Error hooking cpuid %d\n", cpuid);
+ V3_Free(mask);
return -1;
}
} else {
}
hook = (struct v3_cpuid_hook *)V3_Malloc(sizeof(struct v3_cpuid_hook));
+
+ if (!hook) {
+ PrintError("Cannot allocate memory to hook cpu id\n");
+ return -1;
+ }
+
hook->cpuid = cpuid;
hook->private_data = private_data;
hook->hook_fn = hook_fn;
#ifdef V3_CONFIG_CHECKPOINT
#include <palacios/vmm_checkpoint.h>
+
+#define V3_MAX_DEVICE_NAME 32
+
#endif
struct v3_chkpt_ctx * dev_mgr_ctx = NULL;
uint32_t num_saved_devs = 0;
- uint32_t table_len = mgr->num_devs * 32;
+ uint32_t table_len = mgr->num_devs * V3_MAX_DEVICE_NAME;
char * name_table = NULL;
uint32_t tbl_offset = 0;
list_for_each_entry(dev, &(mgr->dev_list), dev_link) {
if (dev->ops->save) {
- strncpy(name_table + tbl_offset, dev->name, 32);
- tbl_offset += 32;
+ strncpy(name_table + tbl_offset, dev->name, V3_MAX_DEVICE_NAME);
+ tbl_offset += V3_MAX_DEVICE_NAME;
num_saved_devs++;
} else {
PrintDebug("Skipping device %s\n");
return -1;
}
- if (v3_chkpt_save(dev_mgr_ctx, "names", num_saved_devs*32, name_table) == -1) {
+ if (v3_chkpt_save(dev_mgr_ctx, "names", num_saved_devs*V3_MAX_DEVICE_NAME, name_table) == -1) {
PrintError("Unable to store names of devices\n");
v3_chkpt_close_ctx(dev_mgr_ctx);
V3_Free(name_table);
V3_Print("Loading State for %d devices\n", num_devs);
- name_table = V3_Malloc(32 * num_devs);
+ name_table = V3_Malloc(V3_MAX_DEVICE_NAME * num_devs);
if (!name_table) {
PrintError("Unable to allocate space for device table\n");
return -1;
}
- if (v3_chkpt_load(dev_mgr_ctx, "names", 32 * num_devs, name_table) == -1) {
+ if (v3_chkpt_load(dev_mgr_ctx, "names", V3_MAX_DEVICE_NAME * num_devs, name_table) == -1) {
PrintError("Unable to load device name table\n");
v3_chkpt_close_ctx(dev_mgr_ctx);
V3_Free(name_table);
v3_chkpt_close_ctx(dev_mgr_ctx);
for (i = 0; i < num_devs; i++) {
- char * name = &(name_table[i * 32]);
+ char * name = &(name_table[i * V3_MAX_DEVICE_NAME]);
struct v3_chkpt_ctx * dev_ctx = NULL;
dev = v3_find_dev(vm, name);
dev = (struct vm_device *)V3_Malloc(sizeof(struct vm_device));
if (dev == NULL) {
+ PrintError("Cannot allocate in adding a device\n");
return NULL;
}
struct blk_frontend * frontend = NULL;
frontend = (struct blk_frontend *)V3_Malloc(sizeof(struct blk_frontend));
+
+ if (!frontend) {
+ PrintError("Cannot allocate in adding a block front end\n");
+ return -1;
+ }
+
memset(frontend, 0, sizeof(struct blk_frontend));
frontend->connect = connect;
struct net_frontend * frontend = NULL;
frontend = (struct net_frontend *)V3_Malloc(sizeof(struct net_frontend));
+
+ if (!frontend) {
+ PrintError("Cannot allocate in adding a net front end\n");
+ return -1;
+ }
+
memset(frontend, 0, sizeof(struct net_frontend));
frontend->connect = connect;
struct cons_frontend * frontend = NULL;
frontend = (struct cons_frontend *)V3_Malloc(sizeof(struct cons_frontend));
+
+ if (!frontend) {
+ PrintError("Cannot allocate in adding a console front end\n");
+ return -1;
+ }
+
memset(frontend, 0, sizeof(struct cons_frontend));
frontend->connect = connect;
struct char_frontend * frontend = NULL;
frontend = (struct char_frontend *)V3_Malloc(sizeof(struct char_frontend));
+
+ if (!frontend) {
+ PrintError("Cannot allocate in adding a char front end\n");
+ return -1;
+ }
+
memset(frontend, 0, sizeof(struct char_frontend));
frontend->connect = connect;
static addr_t create_generic_pt_page() {
void * page = 0;
- page = V3_VAddr(V3_AllocPages(1));
+ void *temp;
+
+ temp = V3_AllocPages(1);
+ if (!temp) {
+ PrintError("Cannot allocate page\n");
+ return 0;
+ }
+
+ page = V3_VAddr(temp);
memset(page, 0, PAGE_SIZE);
return (addr_t)page;
struct hypercall * hcall = (struct hypercall *)V3_Malloc(sizeof(struct hypercall));
+ if (!hcall) {
+ PrintError("Cannot allocate in registering hypercall\n");
+ return -1;
+ }
+
hcall->id = hypercall_id;
hcall->priv_data = priv_data;
hcall->hcall_fn = hypercall;
void * v3_register_intr_controller(struct guest_info * info, struct intr_ctrl_ops * ops, void * priv_data) {
struct intr_controller * ctrlr = (struct intr_controller *)V3_Malloc(sizeof(struct intr_controller));
+ if (!ctrlr) {
+ PrintError("Cannot allocate in registering an interrupt controller\n");
+ return NULL;
+ }
+
ctrlr->priv_data = priv_data;
ctrlr->ctrl_ops = ops;
void * v3_register_intr_router(struct v3_vm_info * vm, struct intr_router_ops * ops, void * priv_data) {
struct intr_router * router = (struct intr_router *)V3_Malloc(sizeof(struct intr_router));
+ if (!router) {
+ PrintError("Cannot allocate in registering an interrupt router\n");
+ return NULL;
+ }
+
router->priv_data = priv_data;
router->router_ops = ops;
{
struct v3_irq_hook * hook = (struct v3_irq_hook *)V3_Malloc(sizeof(struct v3_irq_hook));
+
if (hook == NULL) {
+ PrintError("Cannot allocate when hooking an irq\n");
return -1;
}
if (get_irq_hook(vm, irq) != NULL) {
PrintError("IRQ %d already hooked\n", irq);
+ V3_Free(hook);
return -1;
}
if (V3_Hook_Interrupt(vm, irq)) {
PrintError("hook_irq: failed to hook irq %d\n", irq);
+ vm->intr_routers.hooks[irq] = NULL;
+ V3_Free(hook);
return -1;
} else {
PrintDebug("hook_irq: hooked irq %d\n", irq);
void * priv_data) {
struct v3_io_hook * io_hook = (struct v3_io_hook *)V3_Malloc(sizeof(struct v3_io_hook));
+ if (!io_hook) {
+ PrintError("Cannot allocate in hooking an I/O port\n");
+ return -1;
+ }
+
+
io_hook->port = port;
if (!read) {
}
entry = (struct v3_mem_region *)V3_Malloc(sizeof(struct v3_mem_region));
+
+ if (!entry) {
+ PrintError("Cannot allocate in creating a memory region\n");
+ return NULL;
+ }
+
memset(entry, 0, sizeof(struct v3_mem_region));
entry->guest_start = guest_addr_start;
}
int v3_init_mem_hooks(struct v3_vm_info * vm) {
+ void *temp;
+
struct v3_mem_hooks * hooks = &(vm->mem_hooks);
- hooks->hook_hvas_1 = V3_VAddr(V3_AllocPages(vm->num_cores));
- hooks->hook_hvas_2 = V3_VAddr(V3_AllocPages(vm->num_cores));
+ temp = V3_AllocPages(vm->num_cores);
+
+ if (!temp) {
+ PrintError("Cannot allocate space for mem hooks\n");
+ return -1;
+ }
+
+ hooks->hook_hvas_1 = V3_VAddr(temp);
+
+ temp = V3_AllocPages(vm->num_cores);
+
+ if (!temp) {
+ PrintError("Cannot allocate space for mem hooks\n");
+ V3_FreePages(hooks->hook_hvas_1,vm->num_cores);
+ return -1;
+ }
+
+ hooks->hook_hvas_2 = V3_VAddr(temp);
INIT_LIST_HEAD(&(hooks->hook_list));
struct mem_hook * hook = V3_Malloc(sizeof(struct mem_hook));
struct v3_mem_hooks * hooks = &(vm->mem_hooks);
+ if (!hook) {
+ PrintError("Cannot allocate in hooking memory for full access\n");
+ return -1;
+ }
+
memset(hook, 0, sizeof(struct mem_hook));
hook->write = write;
struct mem_hook * hook = V3_Malloc(sizeof(struct mem_hook));
struct v3_mem_hooks * hooks = &(vm->mem_hooks);
+ if (!hook) {
+ PrintError("Cannot allocate in hooking memory for writing\n");
+ return -1;
+ }
+
memset(hook, 0, sizeof(struct mem_hook));
hook->write = write;
hook->priv_data = priv_data;
entry = v3_create_mem_region(vm, core_id, guest_addr_start, guest_addr_end);
+
+ if (!entry) {
+ PrintError("Cannot create memory region\n");
+ V3_Free(hook);
+ return -1;
+ }
+
hook->region = entry;
entry->unhandled = handle_mem_hook;
entry->priv_data = hook;
if (v3_insert_mem_region(vm, entry)) {
+ PrintError("Cannot insert memory region\n");
V3_Free(entry);
V3_Free(hook);
return -1;
PrintDebug("Creating Node %s\n", name);
+
+ if (!node) {
+ PrintError("Cannot allocate multitree node\n");
+ return NULL;
+ }
+
memset(node, 0, sizeof(struct v3_mtree));
- strncpy(node->name, name, 50);
+ strncpy(node->name, name, V3_MTREE_NAME_LEN);
if ((ret = __insert_mtree_node(root, node))) {
PrintError("Insertion failure\n");
struct v3_queue * v3_create_queue() {
struct v3_queue * tmp_queue = V3_Malloc(sizeof(struct v3_queue));
+
+ if (!tmp_queue) {
+ PrintError("Cannot allocate a queue\n");
+ return NULL;
+ }
+
v3_init_queue(tmp_queue);
return tmp_queue;
}
struct v3_queue_entry * q_entry = V3_Malloc(sizeof(struct v3_queue_entry));
unsigned int flags = 0;
+ if (!q_entry) {
+ PrintError("Cannot allocate a queue entry for enqueue\n");
+ return ;
+ }
+
flags = v3_lock_irqsave(queue->lock);
q_entry->entry = entry;
list_add_tail(&(q_entry->entry_list), &(queue->entries));
void NO_INST v3_init_ringbuf(struct v3_ringbuf * ring, uint_t size) {
ring->buf = V3_Malloc(size);
+
+ if (!(ring->buf)) {
+ PrintError("Cannot init a ring buffer\n");
+ return;
+ }
+
ring->size = size;
ring->start = 0;
struct v3_ringbuf * v3_create_ringbuf(uint_t size) {
struct v3_ringbuf * ring = (struct v3_ringbuf *)V3_Malloc(sizeof(struct v3_ringbuf));
+ if (!ring) {
+ PrintError("Cannot allocate a ring buffer\n");
+ return NULL;
+ }
+
v3_init_ringbuf(ring, size);
return ring;
#ifdef V3_CONFIG_BUILT_IN_MEMMOVE
void * memmove(void * dst, const void * src, size_t n) {
uint8_t * tmp = (uint8_t *)V3_Malloc(n);
+
+ if (!tmp) {
+ PrintError("Cannot allocate in built-in memmove\n");
+ return NULL;
+ }
memcpy(tmp, src, n);
memcpy(dst, tmp, n);
char *ret;
ret = V3_Malloc(strlen(s1) + 1);
+
+ if (!ret) {
+ PrintError("Cannot allocate in built-in strdup\n");
+ return NULL;
+ }
+
strcpy(ret, s1);
return ret;
capsule = V3_Malloc(sizeof(struct v3_sym_capsule));
+
+ if (!capsule) {
+ PrintError("Cannot allocate in initializing symmod\n");
+ return -1;
+ }
+
+
memset(capsule, 0, sizeof(struct v3_sym_capsule));
capsule->name = tmp_def->name;
capsule->guest_size = capsule->size;
capsule->capsule_data = NULL;
} else {
+ V3_Free(capsule)
return -1;
}
(addr_t)(tmp_def->name),
(addr_t)(capsule)) == 0) {
PrintError("Could not insert module %s to master list\n", tmp_def->name);
+ V3_Free(capsule);
return -1;
}
new_symbol = (struct v3_symbol *)V3_Malloc(sizeof(struct v3_symbol));
+ if (!new_symbol) {
+ PrintError("Cannot allocate in symbiotic hcall handler\n");
+ return -1;
+ }
+
strncpy(new_symbol->name, sym_name, 256);
new_symbol->linkage = tmp_symbol->value;
int v3_init_symspy_vm(struct v3_vm_info * vm, struct v3_symspy_global_state * state) {
state->global_page_pa = (addr_t)V3_AllocPages(1);
+ if (!state->global_page_pa) {
+ PrintError("Cannot allocate page\n");
+ return -1;
+ }
+
state->sym_page = (struct v3_symspy_global_page *)V3_VAddr((void *)state->global_page_pa);
memset(state->sym_page, 0, PAGE_SIZE_4KB);
int v3_init_symspy_core(struct guest_info * core, struct v3_symspy_local_state * state) {
state->local_page_pa = (addr_t)V3_AllocPages(1);
+
+ if (!state->local_page_pa) {
+ PrintError("Cannot allocate page\n");
+ return -1;
+ }
state->local_page = (struct v3_symspy_local_page *)V3_VAddr((void *)state->local_page_pa);
memset(state->local_page, 0, PAGE_SIZE_4KB);
static inline struct exit_event * create_exit(uint_t exit_code) {
struct exit_event * evt = V3_Malloc(sizeof(struct exit_event));
+ if (!evt) {
+ PrintError("Cannot allocate in createing exit in telemetry\n");
+ return NULL;
+ }
+
evt->exit_code = exit_code;
evt->cnt = 0;
evt->handler_time = 0;
struct v3_telemetry_state * telemetry = &(vm->telemetry);
struct telemetry_cb * cb = (struct telemetry_cb *)V3_Malloc(sizeof(struct telemetry_cb));
+ if (!cb) {
+ PrintError("Cannot allocate in adding a telemtry callback\n");
+ return ;
+ }
+
cb->private_data = private_data;
cb->telemetry_fn = telemetry_fn;
void * private_data) {
struct v3_timer * timer = NULL;
timer = (struct v3_timer *)V3_Malloc(sizeof(struct v3_timer));
+
+ if (!timer) {
+ PrintError("Cannot allocate in adding a timer\n");
+ return NULL;
+ }
+
V3_ASSERT(timer != NULL);
timer->ops = ops;
}
xed_state_t * decoder_state = (xed_state_t *)V3_Malloc(sizeof(xed_state_t));
+
+ if (!decoder_state) {
+ PrintError("Cannot allocate in initializing decoder\n");
+ return -1;
+ }
+
xed_state_zero(decoder_state);
xed_state_init(decoder_state,
XED_MACHINE_MODE_LEGACY_32,
new_buf = V3_Malloc(new_size);
if (new_buf == NULL) {
+ PrintError("Cannot allocate in tmp_realloc in xml\n");
return NULL;
}
char * tmp = NULL;
tmp = V3_Malloc((l = strlen(xml->txt)) + len);
+
+ if (!tmp) {
+ PrintError("Cannot allocate in xml char content\n");
+ return ;
+ }
+
strcpy(tmp, xml->txt);
xml->txt = tmp;
}
static struct v3_xml * v3_xml_new(const char * name) {
struct v3_xml_root * root = (struct v3_xml_root *)V3_Malloc(sizeof(struct v3_xml_root));
+
+ if (!root) {
+ PrintError("Cannot allocate in xml_new\n");
+ return NULL;
+ }
+
memset(root, 0, sizeof(struct v3_xml_root));
root->xml.name = (char *)name;
}
child = (struct v3_xml *)V3_Malloc(sizeof(struct v3_xml));
+
+ if (!child) {
+ PrintError("Cannot allocate in xml_add_child\n");
+ return NULL;
+ }
+
memset(child, 0, sizeof(struct v3_xml));
child->name = (char *)name;
((attr_cnt * (2 * sizeof(char *))) +
(2 * sizeof(char *))));
+ if (!attr) {
+ PrintError("Cannot reallocate in xml parse string\n");
+ return NULL;
+ }
+
attr[last_idx] = tmp_realloc(attr[last_idx - 2],
attr_cnt,
(attr_cnt + 1));
+
+ if (!attr[last_idx]) {
+ PrintError("Cannot reallocate in xml parse string\n");
+ return NULL;
+ }
+
} else {
attr = V3_Malloc(4 * sizeof(char *));
+ if (!attr) {
+ PrintError("Cannot allocate in xml parse string\n");
+ return NULL;
+ }
attr[last_idx] = V3_Malloc(2);
+ if (!attr[last_idx]) {
+ PrintError("Cannot alloocate in xml parse string\n");
+ return NULL;
+ }
}
attr[attr_idx] = buf; // set attribute name
str_len = strlen(buf);
xml_buf = (char *)V3_Malloc(str_len + 1);
+
+ if (!xml_buf) {
+ PrintError("Cannot allocate in xml parse\n");
+ return NULL;
+ }
+
strcpy(xml_buf, buf);
return parse_str(xml_buf, str_len);
// first attribute
xml->attr = V3_Malloc(4 * sizeof(char *));
+ if (!xml->attr) {
+ PrintError("Cannot allocate in xml set attr\n");
+ return NULL;
+ }
+
// empty list of malloced names/vals
xml->attr[1] = strdup("");
+
+ if (!xml->attr[1]) {
+ PrintError("Cannot strdup in xml set attr\n");
+ return NULL;
+ }
+
} else {
xml->attr = tmp_realloc(xml->attr, l * sizeof(char *), (l + 4) * sizeof(char *));
+
+ if (!xml->attr) {
+ PrintError("Cannot reallocate in xml set attr\n");
+ return NULL;
+ }
}
// set attribute name
strlen(xml->attr[l + 1]),
(c = strlen(xml->attr[l + 1])) + 2);
+
+ if (!xml->attr[l + 3]) {
+ PrintError("Cannot reallocate in xml set attr\n");
+ return NULL;
+ }
+
// set name/value as not malloced
strcpy(xml->attr[l + 3] + c, " ");
struct v3_xml * o = (xml) ? xml->ordered : NULL;
struct v3_xml_root * root = (struct v3_xml_root *)xml;
size_t len = 0, max = V3_XML_BUFSIZE;
- char *s = strcpy(V3_Malloc(max), "");
+ char *s = V3_Malloc(max);
+
+ if (!s) {
+ PrintError("Cannot allocate in xml tostrr\n");
+ return NULL;
+ }
+
+ strcpy(s, "");
if (! xml || ! xml->name) return tmp_realloc(s, max, len + 1);
while (root->xml.parent) root = (struct v3_xml_root *)root->xml.parent; // root tag
static addr_t allocate_vmcs() {
+ void *temp;
struct vmcs_data * vmcs_page = NULL;
PrintDebug("Allocating page\n");
- vmcs_page = (struct vmcs_data *)V3_VAddr(V3_AllocPages(1));
+ temp = V3_AllocPages(1);
+ if (!temp) {
+ PrintError("Cannot allocate VMCS\n");
+ return -1;
+ }
+ vmcs_page = (struct vmcs_data *)V3_VAddr(temp);
memset(vmcs_page, 0, 4096);
vmcs_page->revision = hw_info.basic_info.revision;
int vmx_ret = 0;
vmx_state = (struct vmx_data *)V3_Malloc(sizeof(struct vmx_data));
+
+ if (!vmx_state) {
+ PrintError("Unable to allocate in initializing vmx vmcs\n");
+ return;
+ }
+
memset(vmx_state, 0, sizeof(struct vmx_data));
PrintDebug("vmx_data pointer: %p\n", (void *)vmx_state);
static addr_t create_ept_page() {
+ void * temp;
void * page = 0;
- page = V3_VAddr(V3_AllocPages(1));
+
+ temp = V3_AllocPages(1);
+ if (!temp) {
+ PrintError("Cannot allocate EPT page\n");
+ return 0;
+ }
+ page = V3_VAddr(temp);
memset(page, 0, PAGE_SIZE);
return (addr_t)page;
}
int v3_init_vmx_io_map(struct v3_vm_info * vm) {
+ void *temp;
+
vm->io_map.update_map = update_map;
-
- vm->io_map.arch_data = V3_VAddr(V3_AllocPages(2));
+
+ temp = V3_AllocPages(2);
+ if (!temp) {
+ PrintError("Cannot allocate io bitmap\n");
+ return -1;
+ }
+
+ vm->io_map.arch_data = V3_VAddr(temp);
memset(vm->io_map.arch_data, 0xff, PAGE_SIZE_4KB * 2);
v3_refresh_io_map(vm);
}
int v3_init_vmx_msr_map(struct v3_vm_info * vm) {
+ void *temp;
+
struct v3_msr_map * msr_map = &(vm->msr_map);
msr_map->update_map = update_map;
- msr_map->arch_data = V3_VAddr(V3_AllocPages(1));
+ temp = V3_AllocPages(1);
+ if (!temp) {
+ PrintError("Cannot allocat MSR bitmap\n");
+ return -1;
+ }
+ msr_map->arch_data = V3_VAddr(temp);
memset(msr_map->arch_data, 0xff, PAGE_SIZE_4KB);
v3_refresh_msr_map(vm);
unsigned long flags;
new_route = (struct vnet_route_info *)Vnet_Malloc(sizeof(struct vnet_route_info));
+
+ if (!new_route) {
+ PrintError("Cannot allocate new route\n");
+ return -1;
+ }
+
memset(new_route, 0, sizeof(struct vnet_route_info));
#ifdef V3_CONFIG_DEBUG_VNET
PrintDebug("VNET/P Core: match_route: Matches=%d\n", num_matches);
- if (num_matches == 0) {
+ if (num_matches <= 0) {
return NULL;
}
matches = (struct route_list *)Vnet_Malloc(sizeof(struct route_list) +
(sizeof(struct vnet_route_info *) * num_matches));
+
+ if (!matches) {
+ PrintError("VNET/P Core: Unable to allocate matches\n");
+ return NULL;
+ }
+
matches->num_routes = num_matches;
{
int i;
int cpu = V3_Get_CPU();
+
Vnet_Print(2, "VNET/P Core: cpu %d: pkt (size %d, src_id:%d, src_type: %d, dst_id: %d, dst_type: %d)\n",
cpu, pkt->size, pkt->src_id,
pkt->src_type, pkt->dst_id, pkt->dst_type);
+
if(net_debug >= 4){
v3_hexdump(pkt->data, pkt->size, NULL, 0);
}
vnet_state.stats.rx_pkts++;
look_into_cache(pkt, &matched_routes);
+
if (matched_routes == NULL) {
- PrintDebug("VNET/P Core: send pkt Looking into routing table\n");
+ PrintDebug("VNET/P Core: sending pkt - matching route\n");
matched_routes = match_route(pkt);
if (matched_routes) {
add_route_to_cache(pkt, matched_routes);
} else {
- PrintDebug("VNET/P Core: Could not find route for packet... discards packet\n");
+ PrintDebug("VNET/P Core: Could not find route for packet... discarding packet\n");
vnet_unlock_irqrestore(vnet_state.lock, flags);
return 0; /* do we return -1 here?*/
}
new_dev = (struct vnet_dev *)Vnet_Malloc(sizeof(struct vnet_dev));
if (new_dev == NULL) {
- Vnet_Print(0, "Malloc fails\n");
+ Vnet_Print(0, "VNET/P Core: Unable to allocate a new device\n");
return -1;
}
new_dev->private_data = priv_data;
new_dev->vm = vm;
new_dev->dev_id = 0;
- new_dev->quote = quote<VNET_MAX_QUOTE?quote:VNET_MAX_QUOTE;
+ new_dev->quote = quote<VNET_MAX_QUOTE ? quote : VNET_MAX_QUOTE;
new_dev->poll = poll_state;
flags = vnet_lock_irqsave(vnet_state.lock);
v3_enqueue(vnet_state.poll_devs, (addr_t)new_dev);
}
} else {
- PrintError("VNET/P: Device with the same MAC is already there\n");
+ PrintError("VNET/P: Device with the same MAC has already been added\n");
}
vnet_unlock_irqrestore(vnet_state.lock, flags);
Vnet_Free(dev);
- PrintDebug("VNET/P Core: Remove Device: dev_id %d\n", dev_id);
+ PrintDebug("VNET/P Core: Removed Device: dev_id %d\n", dev_id);
return 0;
}
tmp_bridge = (struct vnet_brg_dev *)Vnet_Malloc(sizeof(struct vnet_brg_dev));
if (tmp_bridge == NULL) {
- PrintError("Malloc Fails\n");
+ PrintError("VNET/P Core: Unable to allocate new bridge\n");
vnet_state.bridge = NULL;
return -1;
}
if (vnet_state.bridge != NULL && vnet_state.bridge->type == type) {
tmp_bridge = vnet_state.bridge;
- vnet_state.bridge = NULL;
+ vnet_state.bridge = NULL;
}
vnet_unlock_irqrestore(vnet_state.lock, flags);
}
}
+
+ Vnet_Free(tq);
Vnet_Print(0, "VNET/P Polling Thread Done.\n");
vnet_thread_stop(vnet_state.pkt_flush_thread);
// At this point there should be no lock-holder
+ Vnet_Free(vnet_state.poll_devs);
+
+
PrintDebug("Deiniting Device List\n");
// close any devices we have open
deinit_devices_list();
struct vnet_thread * vnet_start_thread(int (*func)(void *), void *arg, char * name){
if((host_hooks) && host_hooks->thread_start){
+
struct vnet_thread * thread = Vnet_Malloc(sizeof(struct vnet_thread));
+
+ if (!thread) {
+ PrintError("Cannot allocate space to create a vnet thread\n");
+ return NULL;
+ }
+
thread->host_thread = host_hooks->thread_start(func, arg, name);
if(thread->host_thread){
void * priv_data){
if((host_hooks) && host_hooks->timer_create){
struct vnet_timer * timer = Vnet_Malloc(sizeof(struct vnet_timer));
+
+ if (!timer) {
+ PrintError("Cannot allocate space to create a vnet timer\n");
+ return NULL;
+ }
+
timer->host_timer = host_hooks->timer_create(interval, timer_fun, priv_data);
+
return timer;
}