/* This will contain function pointers that provide OS services */
struct v3_os_hooks {
- void (*print_info)(const char * format, ...)
- __attribute__ ((format (printf, 1, 2)));
- void (*print_debug)(const char * format, ...)
- __attribute__ ((format (printf, 1, 2)));
- void (*print_trace)(const char * format, ...)
- __attribute__ ((format (printf, 1, 2)));
+ void (*print_info)(const char * format, ...);
+ // __attribute__ ((format (printf, 1, 2)));
+ void (*print_debug)(const char * format, ...);
+ // __attribute__ ((format (printf, 1, 2)));
+ void (*print_trace)(const char * format, ...);
+ // __attribute__ ((format (printf, 1, 2)));
void *(*allocate_pages)(int numPages);
void (*free_page)(void * page);
PrintDebug("Creating initial shadow page table\n");
vm_info->direct_map_pt = (addr_t)V3_PAddr(create_passthrough_pde32_pts(vm_info));
- vm_info->shdw_pg_state.shadow_cr3 |= (vm_info->direct_map_pt & ~0xfff);
+ //vm_info->shdw_pg_state.shadow_cr3 |= (vm_info->direct_map_pt & ~0xfff);
+ vm_info->shdw_pg_state.shadow_cr3 = 0;
vm_info->shdw_pg_state.guest_cr0 = 0x0000000000000010LL;
PrintDebug("Created\n");
- guest_state->cr3 = vm_info->shdw_pg_state.shadow_cr3;
+ //guest_state->cr3 = vm_info->shdw_pg_state.shadow_cr3;
+
+ guest_state->cr3 = vm_info->direct_map_pt;
+
//PrintDebugPageTables((pde32_t*)(vm_info->shdw_pg_state.shadow_cr3.e_reg.low));
addr_t fault_addr = guest_ctrl->exit_info2;
pf_error_t * error_code = (pf_error_t *)&(guest_ctrl->exit_info1);
#ifdef DEBUG_SHADOW_PAGING
- PrintDebug("PageFault at %x (error=%d)\n", fault_addr, *error_code);
+ PrintDebug("PageFault at %p (error=%d)\n",
+ (void *)fault_addr, *(uint_t *)error_code);
#endif
if (info->shdw_pg_mode == SHADOW_PAGING) {
if (v3_handle_shadow_pagefault(info, fault_addr, *error_code) == -1) {
if (info->mem_mode == PHYSICAL_MEM) {
- if (guest_pa_to_host_pa(info, guest_state->rip, &host_addr) == -1) {
+ if (guest_pa_to_host_va(info, guest_state->rip, &host_addr) == -1) {
PrintError("Could not translate guest_state->rip to host address\n");
return -1;
}
} else if (info->mem_mode == VIRTUAL_MEM) {
- if (guest_va_to_host_pa(info, guest_state->rip, &host_addr) == -1) {
+ if (guest_va_to_host_va(info, guest_state->rip, &host_addr) == -1) {
PrintError("Could not translate guest_state->rip to host address\n");
return -1;
}
guest_ctrl->guest_ctrl.V_IGN_TPR = 1;
guest_ctrl->guest_ctrl.V_INTR_PRIO = 0xf;
#ifdef DEBUG_INTERRUPTS
- PrintDebug("Injecting Interrupt %d (EIP=%x)\n", guest_ctrl->guest_ctrl.V_INTR_VECTOR, info->rip);
+ PrintDebug("Injecting Interrupt %d (EIP=%p)\n",
+ guest_ctrl->guest_ctrl.V_INTR_VECTOR,
+ (void *)info->rip);
#endif
v3_injecting_intr(info, irq, EXTERNAL_IRQ);
guest_ctrl->EVENTINJ.valid = 1;
#ifdef DEBUG_INTERRUPTS
- PrintDebug("Injecting Interrupt %d (EIP=%x)\n", guest_ctrl->EVENTINJ.vector, info->rip);
+ PrintDebug("Injecting Interrupt %d (EIP=%p)\n",
+ guest_ctrl->EVENTINJ.vector,
+ (void *)info->rip);
#endif
v3_injecting_intr(info, excp, EXCEPTION);
break;
// This value should be set depending on the host register size...
mask = get_gpr_mask(info);
- PrintDebug("INS io_info invalid address size, mask=0x%x, io_info=0x%x\n",mask,*((uint_t*)(io_info)));
+ PrintDebug("INS io_info invalid address size, mask=0x%p, io_info=0x%p\n",
+ (void *)mask, (void *)(io_info));
// PrintDebug("INS Aborted... Check implementation\n");
//return -1;
}
addr_t host_addr;
dst_addr = get_addr_linear(info, info->vm_regs.rdi & mask, theseg);
- PrintDebug("Writing 0x%x\n", dst_addr);
+ PrintDebug("Writing 0x%p\n", (void *)dst_addr);
if (guest_va_to_host_va(info, dst_addr, &host_addr) == -1) {
// either page fault or gpf...
// This value should be set depending on the host register size...
mask = get_gpr_mask(info);
- PrintDebug("OUTS io_info invalid address size, mask=0x%, io_info=0x%x\n",mask,*((uint_t*)(io_info)));
+ PrintDebug("OUTS io_info invalid address size, mask=0%p, io_info=0x%p\n",
+ (void *)mask, (void *)io_info);
// PrintDebug("INS Aborted... Check implementation\n");
//return -1;
// should never happen
addr_t guest_pde = 0;
if (guest_info->shdw_pg_mode == SHADOW_PAGING) {
- guest_pde = (addr_t)CR3_TO_PDE32((void *)(guest_info->shdw_pg_state.guest_cr3));
+ guest_pde = (addr_t)V3_PAddr((void *)(addr_t)CR3_TO_PDE32((void *)(guest_info->shdw_pg_state.guest_cr3)));
} else if (guest_info->shdw_pg_mode == NESTED_PAGING) {
- guest_pde = (addr_t)CR3_TO_PDE32((void *)(guest_info->ctrl_regs.cr3));
+ guest_pde = (addr_t)V3_PAddr((void *)(addr_t)CR3_TO_PDE32((void *)(guest_info->ctrl_regs.cr3)));
}
if (guest_pa_to_host_va(guest_info, guest_pde, (addr_t *)&pde) == -1) {
if (v3_get_mem_mode(info) == VIRTUAL_MEM) {
struct cr3_32 * shadow_cr3 = (struct cr3_32 *)&(info->shdw_pg_state.shadow_cr3);
-
+ PrintDebug("Setting up Shadow Page Table\n");
info->ctrl_regs.cr3 = *(addr_t*)shadow_cr3;
} else {
info->ctrl_regs.cr3 = *(addr_t*)&(info->direct_map_pt);
*(uint_t*)shadow_cr3, *(uint_t*)guest_cr3);
- cached = v3_cache_page_tables32(info, (addr_t)V3_PAddr((void *)(addr_t)CR3_TO_PDE32((void *)*(addr_t *)new_cr3)));
+ cached = v3_cache_page_tables32(info, (addr_t)V3_PAddr((void *)(addr_t)CR3_TO_PDE32((void *)*(addr_t *)new_cr3)));
+
if (cached == -1) {
PrintError("CR3 Cache failed\n");
return -1;
PrintDebug("Reusing cached shadow Page table\n");
}
+
shadow_cr3->pwt = new_cr3->pwt;
shadow_cr3->pcd = new_cr3->pcd;
static int passthrough_irq_handler(struct guest_info * info, struct v3_interrupt * intr, void * priv_data)
{
- PrintDebug("[passthrough_irq_handler] raise_irq=%d (guest=0x%x)\n", intr->irq, info);
+ PrintDebug("[passthrough_irq_handler] raise_irq=%d (guest=0x%p)\n",
+ intr->irq, (void *)info);
return v3_raise_irq(info, intr->irq);
}
int v3_deliver_irq(struct guest_info * info, struct v3_interrupt * intr) {
- PrintDebug("v3_deliver_irq: irq=%d state=0x%x, \n", intr->irq, intr);
+ PrintDebug("v3_deliver_irq: irq=%d state=0x%p, \n", intr->irq, (void *)intr);
struct v3_irq_hook * hook = get_irq_hook(info, intr->irq);
PrintDebug("VMM IO Map (Entries=%d)\n", io_map->num_ports);
while (iter) {
- PrintDebug("IO Port: %hu (Read=%x) (Write=%x)\n", iter->port, iter->read, iter->write);
+ PrintDebug("IO Port: %hu (Read=%p) (Write=%p)\n",
+ iter->port,
+ (void *)(iter->read), (void *)(iter->write));
}
}
{
struct shadow_region * reg = get_shadow_region_by_addr(&(info->mem_map), fault_gpa);
+ PrintDebug("Handling Special Page Fault\n");
+
switch (reg->host_type) {
case HOST_REGION_HOOK:
return mem_hook_dispatch(info, fault_gva, fault_gpa, access_info, (struct vmm_mem_hook *)(reg->host_addr));
if (host_page_type == HOST_REGION_INVALID) {
// Inject a machine check in the guest
- PrintDebug("Invalid Guest Address in page table (0x%x)\n", guest_fault_pa);
+ PrintDebug("Invalid Guest Address in page table (0x%p)\n", (void *)guest_fault_pa);
v3_raise_exception(info, MC_EXCEPTION);
return 0;
}
/* Was the page fault caused by the Guest's page tables? */
if (is_guest_pf(guest_pde_access, shadow_pde_access) == 1) {
PrintDebug("Injecting PDE pf to guest: (guest access error=%d) (pf error code=%d)\n",
- guest_pde_access, error_code);
+ *(uint_t *)&guest_pde_access, *(uint_t *)&error_code);
inject_guest_pf(info, fault_addr, error_code);
return 0;
}
return 0;
}
- PrintDebug("Returning end of PDE function (rip=%x)\n", info->rip);
+ PrintDebug("Returning end of PDE function (rip=%p)\n", (void *)(info->rip));
return 0;
}
if (host_page_type == HOST_REGION_INVALID) {
// Inject a machine check in the guest
- PrintDebug("Invalid Guest Address in page table (0x%x)\n", guest_pa);
+ PrintDebug("Invalid Guest Address in page table (0x%p)\n", (void *)guest_pa);
v3_raise_exception(info, MC_EXCEPTION);
return 0;
}
if (find_pte_map(state->cached_ptes, PT32_PAGE_ADDR(guest_pa)) != NULL) {
// Check if the entry is a page table...
- PrintDebug("Marking page as Guest Page Table\n", shadow_pte->writable);
+ PrintDebug("Marking page as Guest Page Table %d\n", shadow_pte->writable);
shadow_pte->vmm_info = PT32_GUEST_PT;
}
//PrintDebug("PDE Index=%d\n", PDE32_INDEX(first_operand));
//PrintDebug("FirstOperand = %x\n", first_operand);
- PrintDebug("Invalidating page for %x\n", first_operand);
+ PrintDebug("Invalidating page for %p\n", (void *)first_operand);
guest_pde = (pde32_t *)&(guest_pd[PDE32_INDEX(first_operand)]);