2 * This file is part of the Palacios Virtual Machine Monitor developed
3 * by the V3VEE Project with funding from the United States National
4 * Science Foundation and the Department of Energy.
6 * The V3VEE Project is a joint project between Northwestern University
7 * and the University of New Mexico. You can find out more at
10 * Copyright (c) 2008, Jack Lange <jarusl@cs.northwestern.edu>
11 * Copyright (c) 2008, The V3VEE Project <http://www.v3vee.org>
12 * All rights reserved.
14 * Author: Jack Lange <jarusl@cs.northwestern.edu>
16 * This is free software. You are permitted to use,
17 * redistribute, and modify it as specified in the file "V3VEE_LICENSE".
21 static inline int activate_shadow_pt_64(struct guest_info * info) {
22 struct cr3_64 * shadow_cr3 = (struct cr3_64 *)&(info->ctrl_regs.cr3);
23 struct cr3_64 * guest_cr3 = (struct cr3_64 *)&(info->shdw_pg_state.guest_cr3);
24 struct shadow_page_data * shadow_pt = create_new_shadow_pt(info);
25 addr_t shadow_pt_addr = shadow_pt->page_pa;
27 // Because this is a new CR3 load the allocated page is the new CR3 value
28 shadow_pt->cr3 = shadow_pt->page_pa;
30 PrintDebug("Top level Shadow page pa=%p\n", (void *)shadow_pt_addr);
32 shadow_cr3->pml4t_base_addr = PAGE_BASE_ADDR_4KB(shadow_pt_addr);
33 PrintDebug("Creating new 64 bit shadow page table %p\n", (void *)BASE_TO_PAGE_ADDR(shadow_cr3->pml4t_base_addr));
36 shadow_cr3->pwt = guest_cr3->pwt;
37 shadow_cr3->pcd = guest_cr3->pcd;
50 * * 64 bit Page table fault handlers
55 static int handle_2MB_shadow_pagefault_64(struct guest_info * info, addr_t fault_addr, pf_error_t error_code,
56 pte64_t * shadow_pt, pde64_2MB_t * large_guest_pde);
58 static int handle_pte_shadow_pagefault_64(struct guest_info * info, addr_t fault_addr, pf_error_t error_code,
59 pte64_t * shadow_pt, pte64_t * guest_pt);
61 static int handle_pde_shadow_pagefault_64(struct guest_info * info, addr_t fault_addr, pf_error_t error_code,
62 pde64_t * shadow_pd, pde64_t * guest_pd);
64 static int handle_pdpe_shadow_pagefault_64(struct guest_info * info, addr_t fault_addr, pf_error_t error_code,
65 pdpe64_t * shadow_pdp, pdpe64_t * guest_pdp);
68 static inline int handle_shadow_pagefault_64(struct guest_info * info, addr_t fault_addr, pf_error_t error_code) {
69 pml4e64_t * guest_pml = NULL;
70 pml4e64_t * shadow_pml = CR3_TO_PML4E64_VA(info->ctrl_regs.cr3);
71 addr_t guest_cr3 = CR3_TO_PML4E64_PA(info->shdw_pg_state.guest_cr3);
72 pt_access_status_t guest_pml4e_access;
73 pt_access_status_t shadow_pml4e_access;
74 pml4e64_t * guest_pml4e = NULL;
75 pml4e64_t * shadow_pml4e = (pml4e64_t *)&(shadow_pml[PML4E64_INDEX(fault_addr)]);
77 PrintDebug("64 bit Shadow page fault handler: %p\n", (void *)fault_addr);
78 PrintDebug("Handling PML fault\n");
80 if (guest_pa_to_host_va(info, guest_cr3, (addr_t*)&guest_pml) == -1) {
81 PrintError("Invalid Guest PML4E Address: 0x%p\n", (void *)guest_cr3);
85 guest_pml4e = (pml4e64_t *)&(guest_pml[PML4E64_INDEX(fault_addr)]);
87 PrintDebug("Checking Guest %p\n", (void *)guest_pml);
88 // Check the guest page permissions
89 guest_pml4e_access = v3_can_access_pml4e64(guest_pml, fault_addr, error_code);
91 PrintDebug("Checking shadow %p\n", (void *)shadow_pml);
92 // Check the shadow page permissions
93 shadow_pml4e_access = v3_can_access_pml4e64(shadow_pml, fault_addr, error_code);
95 /* Was the page fault caused by the Guest's page tables? */
96 if (is_guest_pf(guest_pml4e_access, shadow_pml4e_access) == 1) {
97 PrintDebug("Injecting PML4E pf to guest: (guest access error=%d) (pf error code=%d)\n",
98 *(uint_t *)&guest_pml4e_access, *(uint_t *)&error_code);
99 inject_guest_pf(info, fault_addr, error_code);
103 if (shadow_pml4e_access == PT_ACCESS_USER_ERROR) {
105 // PML4 Entry marked non-user
107 PrintDebug("Shadow Paging User access error (shadow_pml4e_access=0x%x, guest_pml4e_access=0x%x)\n",
108 shadow_pml4e_access, guest_pml4e_access);
109 inject_guest_pf(info, fault_addr, error_code);
111 } else if ((shadow_pml4e_access != PT_ACCESS_NOT_PRESENT) &&
112 (shadow_pml4e_access != PT_ACCESS_OK)) {
113 // inject page fault in guest
114 inject_guest_pf(info, fault_addr, error_code);
115 PrintDebug("Unknown Error occurred (shadow_pde_access=%d)\n", shadow_pml4e_access);
116 PrintDebug("Manual Says to inject page fault into guest\n");
121 pdpe64_t * shadow_pdp = NULL;
122 pdpe64_t * guest_pdp = NULL;
124 // Get the next shadow page level, allocate if not present
126 if (shadow_pml4e_access == PT_ACCESS_NOT_PRESENT) {
127 struct shadow_page_data * shdw_page = create_new_shadow_pt(info);
128 shadow_pdp = (pdpe64_t *)V3_VAddr((void *)shdw_page->page_pa);
131 shadow_pml4e->present = 1;
132 shadow_pml4e->user_page = guest_pml4e->user_page;
133 shadow_pml4e->writable = guest_pml4e->writable;
135 // VMM Specific options
136 shadow_pml4e->write_through = 0;
137 shadow_pml4e->cache_disable = 0;
140 guest_pml4e->accessed = 1;
142 shadow_pml4e->pdp_base_addr = PAGE_BASE_ADDR(shdw_page->page_pa);
144 shadow_pdp = (pdpe64_t *)V3_VAddr((void *)(addr_t)BASE_TO_PAGE_ADDR(shadow_pml4e->pdp_base_addr));
147 // Continue processing at the next level
149 if (guest_pa_to_host_va(info, BASE_TO_PAGE_ADDR(guest_pml4e->pdp_base_addr), (addr_t *)&guest_pdp) == -1) {
150 // Machine check the guest
151 PrintDebug("Invalid Guest PDP Address: 0x%p\n", (void *)BASE_TO_PAGE_ADDR(guest_pml4e->pdp_base_addr));
152 v3_raise_exception(info, MC_EXCEPTION);
156 if (handle_pdpe_shadow_pagefault_64(info, fault_addr, error_code, shadow_pdp, guest_pdp) == -1) {
157 PrintError("Error handling Page fault caused by PDPE\n");
166 // For now we are not going to handle 1 Gigabyte pages
167 static int handle_pdpe_shadow_pagefault_64(struct guest_info * info, addr_t fault_addr, pf_error_t error_code,
168 pdpe64_t * shadow_pdp, pdpe64_t * guest_pdp) {
169 pt_access_status_t guest_pdpe_access;
170 pt_access_status_t shadow_pdpe_access;
171 pdpe64_t * guest_pdpe = (pdpe64_t *)&(guest_pdp[PDPE64_INDEX(fault_addr)]);
172 pdpe64_t * shadow_pdpe = (pdpe64_t *)&(shadow_pdp[PDPE64_INDEX(fault_addr)]);
174 PrintDebug("Handling PDP fault\n");
177 PrintDebug("Guest Page Tree for guest virtual address zero fault\n");
178 PrintGuestPageTree(info,fault_addr,(addr_t)(info->shdw_pg_state.guest_cr3));
179 PrintDebug("Host Page Tree for guest virtual address zero fault\n");
180 PrintHostPageTree(info,fault_addr,(addr_t)(info->ctrl_regs.cr3));
183 // Check the guest page permissions
184 guest_pdpe_access = v3_can_access_pdpe64(guest_pdp, fault_addr, error_code);
186 // Check the shadow page permissions
187 shadow_pdpe_access = v3_can_access_pdpe64(shadow_pdp, fault_addr, error_code);
189 /* Was the page fault caused by the Guest's page tables? */
190 if (is_guest_pf(guest_pdpe_access, shadow_pdpe_access) == 1) {
191 PrintDebug("Injecting PDPE pf to guest: (guest access error=%d) (pf error code=%d)\n",
192 *(uint_t *)&guest_pdpe_access, *(uint_t *)&error_code);
193 inject_guest_pf(info, fault_addr, error_code);
197 if (shadow_pdpe_access == PT_ACCESS_USER_ERROR) {
199 // PML4 Entry marked non-user
201 PrintDebug("Shadow Paging User access error (shadow_pdpe_access=0x%x, guest_pdpe_access=0x%x)\n",
202 shadow_pdpe_access, guest_pdpe_access);
203 inject_guest_pf(info, fault_addr, error_code);
205 } else if ((shadow_pdpe_access != PT_ACCESS_NOT_PRESENT) &&
206 (shadow_pdpe_access != PT_ACCESS_OK)) {
207 // inject page fault in guest
208 inject_guest_pf(info, fault_addr, error_code);
209 PrintDebug("Unknown Error occurred (shadow_pde_access=%d)\n", shadow_pdpe_access);
210 PrintDebug("Manual Says to inject page fault into guest\n");
215 pde64_t * shadow_pd = NULL;
216 pde64_t * guest_pd = NULL;
218 // Get the next shadow page level, allocate if not present
220 if (shadow_pdpe_access == PT_ACCESS_NOT_PRESENT) {
221 struct shadow_page_data * shdw_page = create_new_shadow_pt(info);
222 shadow_pd = (pde64_t *)V3_VAddr((void *)shdw_page->page_pa);
225 shadow_pdpe->present = 1;
226 shadow_pdpe->user_page = guest_pdpe->user_page;
227 shadow_pdpe->writable = guest_pdpe->writable;
229 // VMM Specific options
230 shadow_pdpe->write_through = 0;
231 shadow_pdpe->cache_disable = 0;
234 guest_pdpe->accessed = 1;
236 shadow_pdpe->pd_base_addr = PAGE_BASE_ADDR(shdw_page->page_pa);
238 shadow_pd = (pde64_t *)V3_VAddr((void *)(addr_t)BASE_TO_PAGE_ADDR(shadow_pdpe->pd_base_addr));
241 // Continue processing at the next level
243 if (guest_pa_to_host_va(info, BASE_TO_PAGE_ADDR(guest_pdpe->pd_base_addr), (addr_t *)&guest_pd) == -1) {
244 // Machine check the guest
245 PrintDebug("Invalid Guest PTE Address: 0x%p\n", (void *)BASE_TO_PAGE_ADDR(guest_pdpe->pd_base_addr));
246 v3_raise_exception(info, MC_EXCEPTION);
250 if (handle_pde_shadow_pagefault_64(info, fault_addr, error_code, shadow_pd, guest_pd) == -1) {
251 PrintError("Error handling Page fault caused by PDE\n");
259 static int handle_pde_shadow_pagefault_64(struct guest_info * info, addr_t fault_addr, pf_error_t error_code,
260 pde64_t * shadow_pd, pde64_t * guest_pd) {
261 pt_access_status_t guest_pde_access;
262 pt_access_status_t shadow_pde_access;
263 pde64_t * guest_pde = (pde64_t *)&(guest_pd[PDE64_INDEX(fault_addr)]);
264 pde64_t * shadow_pde = (pde64_t *)&(shadow_pd[PDE64_INDEX(fault_addr)]);
266 PrintDebug("Handling PDE fault\n");
268 // Check the guest page permissions
269 guest_pde_access = v3_can_access_pde64(guest_pd, fault_addr, error_code);
271 // Check the shadow page permissions
272 shadow_pde_access = v3_can_access_pde64(shadow_pd, fault_addr, error_code);
274 /* Was the page fault caused by the Guest's page tables? */
275 if (is_guest_pf(guest_pde_access, shadow_pde_access) == 1) {
276 PrintDebug("Injecting PDE pf to guest: (guest access error=%d) (pf error code=%d)\n",
277 *(uint_t *)&guest_pde_access, *(uint_t *)&error_code);
278 inject_guest_pf(info, fault_addr, error_code);
282 if (shadow_pde_access == PT_ACCESS_USER_ERROR) {
284 // PDE Entry marked non-user
286 PrintDebug("Shadow Paging User access error (shadow_pdpe_access=0x%x, guest_pdpe_access=0x%x)\n",
287 shadow_pde_access, guest_pde_access);
288 inject_guest_pf(info, fault_addr, error_code);
291 } else if ((shadow_pde_access == PT_ACCESS_WRITE_ERROR) &&
292 (guest_pde->large_page == 1)) {
294 ((pde64_2MB_t *)guest_pde)->dirty = 1;
295 shadow_pde->writable = guest_pde->writable;
297 //PrintDebug("Returning due to large page Write Error\n");
298 //PrintHostPageTree(info, fault_addr, info->ctrl_regs.cr3);
301 } else if ((shadow_pde_access != PT_ACCESS_NOT_PRESENT) &&
302 (shadow_pde_access != PT_ACCESS_OK)) {
303 // inject page fault in guest
304 inject_guest_pf(info, fault_addr, error_code);
305 PrintDebug("Unknown Error occurred (shadow_pde_access=%d)\n", shadow_pde_access);
306 PrintDebug("Manual Says to inject page fault into guest\n");
311 pte64_t * shadow_pt = NULL;
312 pte64_t * guest_pt = NULL;
314 // Get the next shadow page level, allocate if not present
316 if (shadow_pde_access == PT_ACCESS_NOT_PRESENT) {
317 struct shadow_page_data * shdw_page = create_new_shadow_pt(info);
318 shadow_pt = (pte64_t *)V3_VAddr((void *)shdw_page->page_pa);
320 PrintDebug("Creating new shadow PT: %p\n", shadow_pt);
322 shadow_pde->present = 1;
323 shadow_pde->user_page = guest_pde->user_page;
326 if (guest_pde->large_page == 0) {
327 shadow_pde->writable = guest_pde->writable;
329 // This large page flag is temporary until we can get a working cache....
330 ((pde64_2MB_t *)guest_pde)->vmm_info = V3_LARGE_PG;
332 if (error_code.write) {
333 shadow_pde->writable = guest_pde->writable;
334 ((pde64_2MB_t *)guest_pde)->dirty = 1;
336 shadow_pde->writable = 0;
337 ((pde64_2MB_t *)guest_pde)->dirty = 0;
341 // VMM Specific options
342 shadow_pde->write_through = 0;
343 shadow_pde->cache_disable = 0;
344 shadow_pde->global_page = 0;
347 guest_pde->accessed = 1;
349 shadow_pde->pt_base_addr = PAGE_BASE_ADDR(shdw_page->page_pa);
351 shadow_pt = (pte64_t *)V3_VAddr((void *)BASE_TO_PAGE_ADDR(shadow_pde->pt_base_addr));
354 // Continue processing at the next level
355 if (guest_pde->large_page == 0) {
356 if (guest_pa_to_host_va(info, BASE_TO_PAGE_ADDR(guest_pde->pt_base_addr), (addr_t *)&guest_pt) == -1) {
357 // Machine check the guest
358 PrintDebug("Invalid Guest PTE Address: 0x%p\n", (void *)BASE_TO_PAGE_ADDR(guest_pde->pt_base_addr));
359 v3_raise_exception(info, MC_EXCEPTION);
363 if (handle_pte_shadow_pagefault_64(info, fault_addr, error_code, shadow_pt, guest_pt) == -1) {
364 PrintError("Error handling Page fault caused by PDE\n");
368 if (handle_2MB_shadow_pagefault_64(info, fault_addr, error_code, shadow_pt, (pde64_2MB_t *)guest_pde) == -1) {
369 PrintError("Error handling large pagefault\n");
378 static int handle_pte_shadow_pagefault_64(struct guest_info * info, addr_t fault_addr, pf_error_t error_code,
379 pte64_t * shadow_pt, pte64_t * guest_pt) {
380 pt_access_status_t guest_pte_access;
381 pt_access_status_t shadow_pte_access;
382 pte64_t * guest_pte = (pte64_t *)&(guest_pt[PTE64_INDEX(fault_addr)]);;
383 pte64_t * shadow_pte = (pte64_t *)&(shadow_pt[PTE64_INDEX(fault_addr)]);
384 addr_t guest_pa = BASE_TO_PAGE_ADDR((addr_t)(guest_pte->page_base_addr)) + PAGE_OFFSET(fault_addr);
385 // struct shadow_page_state * state = &(info->shdw_pg_state);
387 PrintDebug("Handling PTE fault\n");
389 struct v3_shadow_region * shdw_reg = v3_get_shadow_region(info, guest_pa);
393 if ((shdw_reg == NULL) ||
394 (shdw_reg->host_type == SHDW_REGION_INVALID)) {
395 // Inject a machine check in the guest
396 PrintDebug("Invalid Guest Address in page table (0x%p)\n", (void *)guest_pa);
397 v3_raise_exception(info, MC_EXCEPTION);
401 // Check the guest page permissions
402 guest_pte_access = v3_can_access_pte64(guest_pt, fault_addr, error_code);
404 // Check the shadow page permissions
405 shadow_pte_access = v3_can_access_pte64(shadow_pt, fault_addr, error_code);
407 /* Was the page fault caused by the Guest's page tables? */
408 if (is_guest_pf(guest_pte_access, shadow_pte_access) == 1) {
409 PrintDebug("Access error injecting pf to guest (guest access error=%d) (pf error code=%d)\n",
410 guest_pte_access, *(uint_t*)&error_code);
411 inject_guest_pf(info, fault_addr, error_code);
416 if (shadow_pte_access == PT_ACCESS_OK) {
417 // Inconsistent state...
418 // Guest Re-Entry will flush page tables and everything should now work
419 PrintDebug("Inconsistent state... Guest re-entry should flush tlb\n");
424 if (shadow_pte_access == PT_ACCESS_NOT_PRESENT) {
425 // Page Table Entry Not Present
426 PrintDebug("guest_pa =%p\n", (void *)guest_pa);
428 if ((shdw_reg->host_type == SHDW_REGION_ALLOCATED) ||
429 (shdw_reg->host_type == SHDW_REGION_WRITE_HOOK)) {
430 addr_t shadow_pa = v3_get_shadow_addr(shdw_reg, guest_pa);
432 shadow_pte->page_base_addr = PAGE_BASE_ADDR(shadow_pa);
434 shadow_pte->present = guest_pte->present;
435 shadow_pte->user_page = guest_pte->user_page;
437 //set according to VMM policy
438 shadow_pte->write_through = 0;
439 shadow_pte->cache_disable = 0;
440 shadow_pte->global_page = 0;
443 guest_pte->accessed = 1;
445 if (guest_pte->dirty == 1) {
446 shadow_pte->writable = guest_pte->writable;
447 } else if ((guest_pte->dirty == 0) && (error_code.write == 1)) {
448 shadow_pte->writable = guest_pte->writable;
449 guest_pte->dirty = 1;
450 } else if ((guest_pte->dirty == 0) && (error_code.write == 0)) {
451 shadow_pte->writable = 0;
454 // dirty flag has been set, check if its in the cache
455 /* if (find_pte_map(state->cached_ptes, PAGE_ADDR(guest_pa)) != NULL) { */
456 /* if (error_code.write == 1) { */
457 /* state->cached_cr3 = 0; */
458 /* shadow_pte->writable = guest_pte->writable; */
460 /* shadow_pte->writable = 0; */
464 // Write hooks trump all, and are set Read Only
465 if (shdw_reg->host_type == SHDW_REGION_WRITE_HOOK) {
466 shadow_pte->writable = 0;
470 // Page fault handled by hook functions
472 if (v3_handle_mem_full_hook(info, fault_addr, guest_pa, shdw_reg, error_code) == -1) {
473 PrintError("Special Page fault handler returned error for address: %p\n", (void *)fault_addr);
477 } else if (shadow_pte_access == PT_ACCESS_WRITE_ERROR) {
478 guest_pte->dirty = 1;
480 if (shdw_reg->host_type == SHDW_REGION_WRITE_HOOK) {
481 if (v3_handle_mem_wr_hook(info, fault_addr, guest_pa, shdw_reg, error_code) == -1) {
482 PrintError("Special Page fault handler returned error for address: %p\n", (void *)fault_addr);
486 PrintDebug("Shadow PTE Write Error\n");
487 shadow_pte->writable = guest_pte->writable;
490 /* if (find_pte_map(state->cached_ptes, PAGE_ADDR(guest_pa)) != NULL) { */
491 /* struct shadow_page_state * state = &(info->shdw_pg_state); */
492 /* PrintDebug("Write operation on Guest PAge Table Page\n"); */
493 /* state->cached_cr3 = 0; */
499 // Inject page fault into the guest
500 inject_guest_pf(info, fault_addr, error_code);
501 PrintError("PTE Page fault fell through... Not sure if this should ever happen\n");
502 PrintError("Manual Says to inject page fault into guest\n");
511 static int handle_2MB_shadow_pagefault_64(struct guest_info * info,
512 addr_t fault_addr, pf_error_t error_code,
513 pte64_t * shadow_pt, pde64_2MB_t * large_guest_pde)
515 pt_access_status_t shadow_pte_access = v3_can_access_pte64(shadow_pt, fault_addr, error_code);
516 pte64_t * shadow_pte = (pte64_t *)&(shadow_pt[PTE64_INDEX(fault_addr)]);
517 addr_t guest_fault_pa = BASE_TO_PAGE_ADDR_2MB(large_guest_pde->page_base_addr) + PAGE_OFFSET_2MB(fault_addr);
518 // struct shadow_page_state * state = &(info->shdw_pg_state);
520 PrintDebug("Handling 2MB fault (guest_fault_pa=%p) (error_code=%x)\n", (void *)guest_fault_pa, *(uint_t*)&error_code);
521 PrintDebug("ShadowPT=%p, LargeGuestPDE=%p\n", shadow_pt, large_guest_pde);
523 struct v3_shadow_region * shdw_reg = v3_get_shadow_region(info, guest_fault_pa);
526 if ((shdw_reg == NULL) ||
527 (shdw_reg->host_type == SHDW_REGION_INVALID)) {
528 // Inject a machine check in the guest
529 PrintDebug("Invalid Guest Address in page table (0x%p)\n", (void *)guest_fault_pa);
530 v3_raise_exception(info, MC_EXCEPTION);
534 if (shadow_pte_access == PT_ACCESS_OK) {
535 // Inconsistent state...
536 // Guest Re-Entry will flush tables and everything should now workd
537 PrintDebug("Inconsistent state... Guest re-entry should flush tlb\n");
538 //PrintHostPageTree(info, fault_addr, info->ctrl_regs.cr3);
543 if (shadow_pte_access == PT_ACCESS_NOT_PRESENT) {
544 // Get the guest physical address of the fault
546 if ((shdw_reg->host_type == SHDW_REGION_ALLOCATED) ||
547 (shdw_reg->host_type == SHDW_REGION_WRITE_HOOK)) {
548 addr_t shadow_pa = v3_get_shadow_addr(shdw_reg, guest_fault_pa);
550 PrintDebug("Shadow PA=%p, ShadowPTE=%p\n", (void *)shadow_pa, (void *)shadow_pte);
552 shadow_pte->page_base_addr = PAGE_BASE_ADDR(shadow_pa);
553 PrintDebug("Test1\n");
555 shadow_pte->present = 1;
557 /* We are assuming that the PDE entry has precedence
558 * so the Shadow PDE will mirror the guest PDE settings,
559 * and we don't have to worry about them here
562 shadow_pte->user_page = 1;
566 /* if (find_pte_map(state->cached_ptes, PAGE_ADDR(guest_fault_pa)) != NULL) { */
567 /* // Check if the entry is a page table... */
568 /* PrintDebug("Marking page as Guest Page Table (large page)\n"); */
569 /* shadow_pte->writable = 0; */
570 /* } else */ if (shdw_reg->host_type == SHDW_REGION_WRITE_HOOK) {
571 shadow_pte->writable = 0;
573 shadow_pte->writable = 1;
576 //set according to VMM policy
577 shadow_pte->write_through = 0;
578 shadow_pte->cache_disable = 0;
579 shadow_pte->global_page = 0;
583 // Handle hooked pages as well as other special pages
584 // if (handle_special_page_fault(info, fault_addr, guest_fault_pa, error_code) == -1) {
586 if (v3_handle_mem_full_hook(info, fault_addr, guest_fault_pa, shdw_reg, error_code) == -1) {
587 PrintError("Special Page Fault handler returned error for address: %p\n", (void *)fault_addr);
591 } else if (shadow_pte_access == PT_ACCESS_WRITE_ERROR) {
593 if (shdw_reg->host_type == SHDW_REGION_WRITE_HOOK) {
595 if (v3_handle_mem_wr_hook(info, fault_addr, guest_fault_pa, shdw_reg, error_code) == -1) {
596 PrintError("Special Page Fault handler returned error for address: %p\n", (void *)fault_addr);
602 /* if (find_pte_map(state->cached_ptes, PAGE_ADDR(guest_fault_pa)) != NULL) { */
603 /* struct shadow_page_state * state = &(info->shdw_pg_state); */
604 /* PrintDebug("Write operation on Guest PAge Table Page (large page)\n"); */
605 /* state->cached_cr3 = 0; */
606 /* shadow_pte->writable = 1; */
610 PrintError("Error in large page fault handler...\n");
611 PrintError("This case should have been handled at the top level handler\n");
615 // PrintHostPageTree(info, fault_addr, info->ctrl_regs.cr3);
616 PrintDebug("Returning from large page fault handler\n");
623 static int invalidation_cb_64(struct guest_info * info, page_type_t type,
624 addr_t vaddr, addr_t page_ptr, addr_t page_pa,
625 void * private_data) {
630 pml4e64_t * pml = (pml4e64_t *)page_ptr;
632 if (pml[PML4E64_INDEX(vaddr)].present == 0) {
639 pdpe64_t * pdp = (pdpe64_t *)page_ptr;
640 pdpe64_t * pdpe = &(pdp[PDPE64_INDEX(vaddr)]);
642 if (pdpe->present == 0) {
646 if (pdpe->vmm_info == V3_LARGE_PG) {
647 PrintError("1 Gigabyte pages not supported\n");
658 pde64_t * pd = (pde64_t *)page_ptr;
659 pde64_t * pde = &(pd[PDE64_INDEX(vaddr)]);
661 if (pde->present == 0) {
665 if (pde->vmm_info == V3_LARGE_PG) {
674 pte64_t * pt = (pte64_t *)page_ptr;
676 pt[PTE64_INDEX(vaddr)].present = 0;
681 PrintError("Invalid Page Type\n");
686 // should not get here
687 PrintError("Should not get here....\n");
692 static inline int handle_shadow_invlpg_64(struct guest_info * info, addr_t vaddr) {
693 PrintDebug("INVLPG64 - %p\n",(void*)vaddr);
695 int ret = v3_drill_host_pt_64(info, info->ctrl_regs.cr3, vaddr, invalidation_cb_64, NULL);
697 PrintError("Page table drill returned error.... \n");
698 PrintHostPageTree(info, vaddr, info->ctrl_regs.cr3);
701 return (ret == -1) ? -1 : 0;