ia64/xen-unstable

changeset 4121:c04324140af0

bitkeeper revision 1.1236.25.15 (423392ebXXffMtGJq4KKBtLnkTDFIg)

Add further error checking to map_domain_va
Fix page table index calculation
Signed-off-by: Kip Macy
author cl349@firebug.cl.cam.ac.uk[cl349]
date Sun Mar 13 01:10:03 2005 +0000 (2005-03-13)
parents 3236c27b9832
children ee903ed94912
files tools/libxc/xc_ptrace.c
line diff
     1.1 --- a/tools/libxc/xc_ptrace.c	Sun Mar 13 00:35:14 2005 +0000
     1.2 +++ b/tools/libxc/xc_ptrace.c	Sun Mar 13 01:10:03 2005 +0000
     1.3 @@ -110,7 +110,7 @@ struct gdb_regs {
     1.4  
     1.5  
     1.6  #define vtopdi(va) ((va) >> PDRSHIFT)
     1.7 -#define vtopti(va) (((va) >> PAGE_SHIFT) & BSD_PAGE_MASK)
     1.8 +#define vtopti(va) (((va) >> PAGE_SHIFT) & 0x3ff)
     1.9  
    1.10  /* XXX application state */
    1.11  
    1.12 @@ -134,7 +134,14 @@ map_domain_va(unsigned long domid, void 
    1.13      static unsigned long *pde_virt;
    1.14      static unsigned long page_phys;
    1.15      static unsigned long *page_virt;
    1.16 -
    1.17 +    if (!regs_valid) 
    1.18 +    {
    1.19 +	int retval = xc_domain_getfullinfo(xc_handle, domid, 0, NULL, &ctxt);
    1.20 +	if (retval)
    1.21 +	    goto error_out;
    1.22 +	cr3 = ctxt.pt_base;
    1.23 +	regs_valid = 1;
    1.24 +    }
    1.25      if (cr3 != cr3_phys) 
    1.26      {
    1.27  	cr3_phys = cr3;
    1.28 @@ -145,7 +152,8 @@ map_domain_va(unsigned long domid, void 
    1.29  					     cr3_phys >> PAGE_SHIFT)) == NULL)
    1.30  	    goto error_out;
    1.31      } 
    1.32 -    pde = cr3_virt[vtopdi(va)];
    1.33 +    if ((pde = cr3_virt[vtopdi(va)]) == 0)
    1.34 +	goto error_out;
    1.35      if (pde != pde_phys) 
    1.36      {
    1.37  	pde_phys = pde;
    1.38 @@ -156,7 +164,8 @@ map_domain_va(unsigned long domid, void 
    1.39  					     pde_phys >> PAGE_SHIFT)) == NULL)
    1.40  	    goto error_out;
    1.41      }
    1.42 -    page = pde_virt[vtopti(va)];
    1.43 +    if ((page = pde_virt[vtopti(va)]) == 0)
    1.44 +	goto error_out;
    1.45      if (page != page_phys) 
    1.46      {
    1.47  	page_phys = page;
    1.48 @@ -164,8 +173,10 @@ map_domain_va(unsigned long domid, void 
    1.49  	    munmap(page_virt, PAGE_SIZE);
    1.50  	if ((page_virt = xc_map_foreign_range(xc_handle, domid, PAGE_SIZE,
    1.51  					     PROT_READ|PROT_WRITE,
    1.52 -					     page_phys >> PAGE_SHIFT)) == NULL)
    1.53 +					      page_phys >> PAGE_SHIFT)) == NULL) {
    1.54 +	    printf("cr3 %lx pde %lx page %lx pti %lx\n", cr3, pde, page, vtopti(va));
    1.55  	    goto error_out;
    1.56 +	}
    1.57      }	
    1.58      return (void *)(((unsigned long)page_virt) | (va & BSD_PAGE_MASK));
    1.59  
    1.60 @@ -238,8 +249,10 @@ xc_ptrace(enum __ptrace_request request,
    1.61      case PTRACE_PEEKDATA:
    1.62      case PTRACE_POKETEXT:
    1.63      case PTRACE_POKEDATA:
    1.64 -	if ((guest_va = (unsigned long *)map_domain_va(pid, addr)) == NULL)
    1.65 +	if ((guest_va = (unsigned long *)map_domain_va(pid, addr)) == NULL) {
    1.66 +	    status = EFAULT;
    1.67  	    goto done;
    1.68 +	}
    1.69  
    1.70  	if (request == PTRACE_PEEKTEXT || request == PTRACE_PEEKDATA)
    1.71  	    retval = *guest_va;