* All rights reserved.
*
* Author: Jack Lange <jarusl@cs.northwestern.edu>
+ * Author: Chunxiao Diao <chunxiaodiao2012@u.northwestern.edu>
+ *
*
* This is free software. You are permitted to use,
* redistribute, and modify it as specified in the file "V3VEE_LICENSE".
#include "vmm_shdw_pg_tlb_32pae.h"
#include "vmm_shdw_pg_tlb_64.h"
+static inline int get_constraints(struct guest_info *core)
+{
+ // the current version of VTLB does not require any constraints
+ // on where page tables are allocated since it will use
+ // 32PAE page tables on a 64 bit machine even in 32 bit mode and below
+ return 0;
+}
+
static struct shadow_page_data * create_new_shadow_pt(struct guest_info * core) {
struct v3_shdw_pg_state * state = &(core->shdw_pg_state);
if (page_tail->cr3 != cur_cr3) {
- PrintDebug("Reusing old shadow Page: %p (cur_CR3=%p)(page_cr3=%p) \n",
+ PrintDebug(core->vm_info, core, "Reusing old shadow Page: %p (cur_CR3=%p)(page_cr3=%p) \n",
(void *)(addr_t)page_tail->page_pa,
(void *)(addr_t)cur_cr3,
(void *)(addr_t)(page_tail->cr3));
// else
page_tail = (struct shadow_page_data *)V3_Malloc(sizeof(struct shadow_page_data));
- page_tail->page_pa = (addr_t)V3_AllocPages(1);
- PrintDebug("Allocating new shadow Page: %p (cur_cr3=%p)\n",
+ if (!page_tail) {
+ PrintError(core->vm_info, core, "Cannot allocate\n");
+ return NULL;
+ }
+
+ page_tail->page_pa = (addr_t)V3_AllocPagesExtended(1,PAGE_SIZE_4KB,-1,get_constraints(core));
+
+ if (!page_tail->page_pa) {
+ PrintError(core->vm_info, core, "Cannot allocate page\n");
+ return NULL;
+ }
+
+ PrintDebug(core->vm_info, core, "Allocating new shadow Page: %p (cur_cr3=%p)\n",
(void *)(addr_t)page_tail->page_pa,
(void *)(addr_t)cur_cr3);
static int vtlb_init(struct v3_vm_info * vm, v3_cfg_tree_t * cfg) {
- V3_Print("VTLB initialization\n");
+ V3_Print(vm, VCORE_NONE, "VTLB initialization\n");
return 0;
}
struct v3_shdw_pg_state * state = &(core->shdw_pg_state);
struct vtlb_local_state * vtlb_state = NULL;
- V3_Print("VTLB local initialization\n");
+ V3_Print(core->vm_info, core, "VTLB local initialization\n");
vtlb_state = (struct vtlb_local_state *)V3_Malloc(sizeof(struct vtlb_local_state));
+ if (!vtlb_state) {
+ PrintError(core->vm_info, core, "Cannot allocate\n");
+ return -1;
+ }
+
INIT_LIST_HEAD(&(vtlb_state->page_list));
state->local_impl_data = vtlb_state;
case PROTECTED:
return activate_shadow_pt_32(core);
+ break;
case PROTECTED_PAE:
return activate_shadow_pt_32pae(core);
+ break;
case LONG:
case LONG_32_COMPAT:
case LONG_16_COMPAT:
return activate_shadow_pt_64(core);
+ break;
default:
- PrintError("Invalid CPU mode: %s\n", v3_cpu_mode_to_str(v3_get_vm_cpu_mode(core)));
+ PrintError(core->vm_info, core, "Invalid CPU mode: %s\n", v3_cpu_mode_to_str(v3_get_vm_cpu_mode(core)));
return -1;
+ break;
}
return 0;
static int vtlb_handle_pf(struct guest_info * core, addr_t fault_addr, pf_error_t error_code) {
-
+
switch (v3_get_vm_cpu_mode(core)) {
case PROTECTED:
return handle_shadow_pagefault_32(core, fault_addr, error_code);
return handle_shadow_pagefault_64(core, fault_addr, error_code);
break;
default:
- PrintError("Unhandled CPU Mode: %s\n", v3_cpu_mode_to_str(v3_get_vm_cpu_mode(core)));
+ PrintError(core->vm_info, core, "Unhandled CPU Mode: %s\n", v3_cpu_mode_to_str(v3_get_vm_cpu_mode(core)));
return -1;
}
}
switch (v3_get_vm_cpu_mode(core)) {
case PROTECTED:
return handle_shadow_invlpg_32(core, vaddr);
+ break;
case PROTECTED_PAE:
return handle_shadow_invlpg_32pae(core, vaddr);
+ break;
case LONG:
case LONG_32_COMPAT:
case LONG_16_COMPAT:
return handle_shadow_invlpg_64(core, vaddr);
+ break;
default:
- PrintError("Invalid CPU mode: %s\n", v3_cpu_mode_to_str(v3_get_vm_cpu_mode(core)));
+ PrintError(core->vm_info, core, "Invalid CPU mode: %s\n", v3_cpu_mode_to_str(v3_get_vm_cpu_mode(core)));
return -1;
+ break;
}
}