#endif
-int init_shadow_page_state(struct shadow_page_state * state) {
+
+
+
+
+static int handle_shadow_pte32_fault(struct guest_info* info,
+ addr_t fault_addr,
+ pf_error_t error_code,
+ pte32_t * shadow_pte,
+ pte32_t * guest_pte);
+
+static int handle_shadow_pagefault32(struct guest_info * info, addr_t fault_addr, pf_error_t error_code);
+
+int init_shadow_page_state(struct guest_info * info) {
+ struct shadow_page_state * state = &(info->shdw_pg_state);
state->guest_mode = PDE32;
state->shadow_mode = PDE32;
addr_t create_new_shadow_pt32(struct guest_info * info) {
void * host_pde = 0;
- V3_AllocPages(host_pde, 1);
+ host_pde = V3_AllocPages(1);
memset(host_pde, 0, PAGE_SIZE);
return (addr_t)host_pde;
return 0;
}
-int handle_shadow_pagefault32(struct guest_info * info, addr_t fault_addr, pf_error_t error_code) {
+static int handle_shadow_pagefault32(struct guest_info * info, addr_t fault_addr, pf_error_t error_code) {
pde32_t * guest_pd = NULL;
pde32_t * shadow_pd = (pde32_t *)CR3_TO_PDE32(info->shdw_pg_state.shadow_cr3);
addr_t guest_cr3 = CR3_TO_PDE32(info->shdw_pg_state.guest_cr3);
// inject page fault to the guest (Guest PDE fault)
info->ctrl_regs.cr2 = fault_addr;
- raise_exception_with_error(info, PF_EXCEPTION, *(uint_t *)&error_code);
+ v3_raise_exception_with_error(info, PF_EXCEPTION, *(uint_t *)&error_code);
PrintDebug("Injecting PDE pf to guest: (guest access error=%d) (pf error code=%d)\n", guest_pde_access, error_code);
if (guest_pde->large_page == 0) {
pte32_t * shadow_pt = NULL;
- V3_AllocPages(shadow_pt, 1);
+ shadow_pt = V3_AllocPages(1);
memset(shadow_pt, 0, PAGE_SIZE);
shadow_pde->pt_base_addr = PD32_BASE_ADDR(shadow_pt);
if (host_page_type == HOST_REGION_INVALID) {
- raise_exception(info, MC_EXCEPTION);
+ v3_raise_exception(info, MC_EXCEPTION);
PrintError("Invalid guest address in large page (0x%x)\n", guest_start_addr);
return -1;
} else if (host_page_type == HOST_REGION_PHYSICAL_MEMORY) {
shadow_pde->large_page = 0;
- V3_AllocPages(shadow_pt, 1);
+ shadow_pt = V3_AllocPages(1);
memset(shadow_pt, 0, PAGE_SIZE);
if (handle_pd32_nonaligned_4MB_page(info, shadow_pt, guest_start_addr, large_shadow_pde) == -1) {
PrintDebug("Shadow Paging User access error (shadow_pde_access=0x%x, guest_pde_access=0x%x - injecting into guest\n", shadow_pde_access, guest_pde_access);
info->ctrl_regs.cr2 = fault_addr;
- raise_exception_with_error(info, PF_EXCEPTION, *(uint_t *)&error_code);
+ v3_raise_exception_with_error(info, PF_EXCEPTION, *(uint_t *)&error_code);
return 0;
} else if (shadow_pde_access == PT_ACCESS_OK) {
PrintDebug("Invalid Guest PTE Address: 0x%x\n", PDE32_T_ADDR((*guest_pde)));
// Machine check the guest
- raise_exception(info, MC_EXCEPTION);
+ v3_raise_exception(info, MC_EXCEPTION);
return 0;
}
} else {
// Unknown error raise page fault in guest
info->ctrl_regs.cr2 = fault_addr;
- raise_exception_with_error(info, PF_EXCEPTION, *(uint_t *)&error_code);
+ v3_raise_exception_with_error(info, PF_EXCEPTION, *(uint_t *)&error_code);
// For debugging we will return an error here for the time being,
// this probably shouldn't ever happen
/*
* We assume the the guest pte pointer has already been translated to a host virtual address
*/
-int handle_shadow_pte32_fault(struct guest_info * info,
+static int handle_shadow_pte32_fault(struct guest_info * info,
addr_t fault_addr,
pf_error_t error_code,
pte32_t * shadow_pt,
// Inject page fault into the guest
info->ctrl_regs.cr2 = fault_addr;
- raise_exception_with_error(info, PF_EXCEPTION, *(uint_t *)&error_code);
+ v3_raise_exception_with_error(info, PF_EXCEPTION, *(uint_t *)&error_code);
PrintDebug("Access error injecting pf to guest (guest access error=%d) (pf error code=%d)\n", guest_pte_access, *(uint_t*)&error_code);
return 0;
if (host_page_type == HOST_REGION_INVALID) {
// Inject a machine check in the guest
- raise_exception(info, MC_EXCEPTION);
+ v3_raise_exception(info, MC_EXCEPTION);
#ifdef DEBUG_SHADOW_PAGING
PrintDebug("Invalid Guest Address in page table (0x%x)\n", guest_pa);
PrintDebug("fault_addr=0x%x next are guest and shadow ptes \n",fault_addr);
// Inject page fault into the guest
info->ctrl_regs.cr2 = fault_addr;
- raise_exception_with_error(info, PF_EXCEPTION, *(uint_t *)&error_code);
+ v3_raise_exception_with_error(info, PF_EXCEPTION, *(uint_t *)&error_code);
PrintError("PTE Page fault fell through... Not sure if this should ever happen\n");
PrintError("Manual Says to inject page fault into guest\n");
}
-
-/* Deprecated */
-/*
-addr_t setup_shadow_pt32(struct guest_info * info, addr_t virt_cr3) {
- addr_t cr3_guest_addr = CR3_TO_PDE32(virt_cr3);
- pde32_t * guest_pde;
- pde32_t * host_pde = NULL;
- int i;
-
- // Setup up guest_pde to point to the PageDir in host addr
- if (guest_pa_to_host_va(info, cr3_guest_addr, (addr_t*)&guest_pde) == -1) {
- return 0;
- }
-
- V3_AllocPages(host_pde, 1);
- memset(host_pde, 0, PAGE_SIZE);
-
- for (i = 0; i < MAX_PDE32_ENTRIES; i++) {
- if (guest_pde[i].present == 1) {
- addr_t pt_host_addr;
- addr_t host_pte;
-
- if (guest_pa_to_host_va(info, PDE32_T_ADDR(guest_pde[i]), &pt_host_addr) == -1) {
- return 0;
- }
-
- if ((host_pte = setup_shadow_pte32(info, pt_host_addr)) == 0) {
- return 0;
- }
-
- host_pde[i].present = 1;
- host_pde[i].pt_base_addr = PD32_BASE_ADDR(host_pte);
-
- //
- // Set Page DIR flags
- //
- }
- }
-
- PrintDebugPageTables(host_pde);
-
- return (addr_t)host_pde;
-}
-
-
-
-addr_t setup_shadow_pte32(struct guest_info * info, addr_t pt_host_addr) {
- pte32_t * guest_pte = (pte32_t *)pt_host_addr;
- pte32_t * host_pte = NULL;
- int i;
-
- V3_AllocPages(host_pte, 1);
- memset(host_pte, 0, PAGE_SIZE);
-
- for (i = 0; i < MAX_PTE32_ENTRIES; i++) {
- if (guest_pte[i].present == 1) {
- addr_t guest_pa = PTE32_T_ADDR(guest_pte[i]);
- shadow_mem_type_t page_type;
- addr_t host_pa = 0;
-
- page_type = get_shadow_addr_type(info, guest_pa);
-
- if (page_type == HOST_REGION_PHYSICAL_MEMORY) {
- host_pa = get_shadow_addr(info, guest_pa);
- } else {
-
- //
- // Setup various memory types
- //
- }
-
- host_pte[i].page_base_addr = PT32_BASE_ADDR(host_pa);
- host_pte[i].present = 1;
- }
- }
-
- return (addr_t)host_pte;
-}
-
-*/