#include <palacios/vm_guest_mem.h>
-#ifndef CONFIG_DEBUG_SHDW_PG_VTLB
+#ifndef V3_CONFIG_DEBUG_SHDW_PG_VTLB
#undef PrintDebug
#define PrintDebug(fmt, ...)
#endif
// 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);
}
static int vtlb_deinit(struct v3_vm_info * vm) {
- return -1;
+ return 0;
}
static int vtlb_local_init(struct guest_info * core) {
V3_Print("VTLB local initialization\n");
-
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;
}
+static int vtlb_local_deinit(struct guest_info * core) {
+ struct v3_shdw_pg_state * state = &(core->shdw_pg_state);
+ struct vtlb_local_state * vtlb_state = state->local_impl_data;
+
+ struct shadow_page_data * shdw_pg = NULL;
+ struct shadow_page_data * tmp = NULL;
+
+ // free page list...
+ list_for_each_entry_safe(shdw_pg, tmp, &(vtlb_state->page_list), page_list_node) {
+ list_del(&(shdw_pg->page_list_node));
+ V3_FreePages((void *)shdw_pg->page_pa, 1);
+ V3_Free(shdw_pg);
+ }
+
+
+ V3_Free(vtlb_state);
+
+ return 0;
+}
+
+
static int vtlb_activate_shdw_pt(struct guest_info * core) {
switch (v3_get_vm_cpu_mode(core)) {
.init = vtlb_init,
.deinit = vtlb_deinit,
.local_init = vtlb_local_init,
+ .local_deinit = vtlb_local_deinit,
.handle_pagefault = vtlb_handle_pf,
.handle_invlpg = vtlb_handle_invlpg,
.activate_shdw_pt = vtlb_activate_shdw_pt,