ia64/xen-unstable

changeset 4229:c8f647bf77b3

bitkeeper revision 1.1236.1.96 (423d91c3JzdYyXv2iF0lgox0Q4n2tA)

fix mapping bugs in map_domain_va in xc_ptrace.c
map pages RO
Signed-off-by: Kip Macy <kmacy@fsmware.com>
Signed-off-by: ian@xensource.com
author iap10@firebug.cl.cam.ac.uk
date Sun Mar 20 15:07:47 2005 +0000 (2005-03-20)
parents e65dba35e87c
children 197ac8c7df4b
files tools/libxc/xc_ptrace.c
line diff
     1.1 --- a/tools/libxc/xc_ptrace.c	Sun Mar 20 15:03:35 2005 +0000
     1.2 +++ b/tools/libxc/xc_ptrace.c	Sun Mar 20 15:07:47 2005 +0000
     1.3 @@ -123,7 +123,7 @@ static full_execution_context_t ctxt;
     1.4  /* --------------------- */
     1.5  
     1.6  static void *
     1.7 -map_domain_va(unsigned long domid, void * guest_va)
     1.8 +map_domain_va(unsigned long domid, void * guest_va, int perm)
     1.9  {
    1.10      unsigned long pde, page;
    1.11      unsigned long va = (unsigned long)guest_va;
    1.12 @@ -134,6 +134,8 @@ 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 +    static int prev_perm;
    1.18      if (!regs_valid) 
    1.19      {
    1.20  	int retval = xc_domain_getfullinfo(xc_handle, domid, 0, NULL, &ctxt);
    1.21 @@ -166,17 +168,19 @@ map_domain_va(unsigned long domid, void 
    1.22      }
    1.23      if ((page = pde_virt[vtopti(va)]) == 0)
    1.24  	goto error_out;
    1.25 -    if (page != page_phys) 
    1.26 +    if (page != page_phys || perm != prev_perm) 
    1.27      {
    1.28  	page_phys = page;
    1.29  	if (page_virt)
    1.30  	    munmap(page_virt, PAGE_SIZE);
    1.31  	if ((page_virt = xc_map_foreign_range(xc_handle, domid, PAGE_SIZE,
    1.32 -					     PROT_READ|PROT_WRITE,
    1.33 +					     perm,
    1.34  					      page_phys >> PAGE_SHIFT)) == NULL) {
    1.35  	    printf("cr3 %lx pde %lx page %lx pti %lx\n", cr3, pde, page, vtopti(va));
    1.36 +	    page_phys = 0;
    1.37  	    goto error_out;
    1.38  	}
    1.39 +	prev_perm = perm;
    1.40      }	
    1.41      return (void *)(((unsigned long)page_virt) | (va & BSD_PAGE_MASK));
    1.42  
    1.43 @@ -247,17 +251,21 @@ xc_ptrace(enum __ptrace_request request,
    1.44      switch (request) {	
    1.45      case PTRACE_PEEKTEXT:
    1.46      case PTRACE_PEEKDATA:
    1.47 -    case PTRACE_POKETEXT:
    1.48 -    case PTRACE_POKEDATA:
    1.49 -	if ((guest_va = (unsigned long *)map_domain_va(pid, addr)) == NULL) {
    1.50 +	if ((guest_va = (unsigned long *)map_domain_va(pid, addr, PROT_READ)) == NULL) {
    1.51  	    status = EFAULT;
    1.52  	    goto done;
    1.53  	}
    1.54  
    1.55 -	if (request == PTRACE_PEEKTEXT || request == PTRACE_PEEKDATA)
    1.56 -	    retval = *guest_va;
    1.57 -	else
    1.58 -	    *guest_va = (unsigned long)data;
    1.59 +	retval = *guest_va;
    1.60 +	break;
    1.61 +    case PTRACE_POKETEXT:
    1.62 +    case PTRACE_POKEDATA:
    1.63 +	if ((guest_va = (unsigned long *)map_domain_va(pid, addr, PROT_READ|PROT_WRITE)) == NULL) {
    1.64 +	    status = EFAULT;
    1.65 +	    goto done;
    1.66 +	}
    1.67 +
    1.68 +	*guest_va = (unsigned long)data;
    1.69  	break;
    1.70      case PTRACE_GETREGS:
    1.71      case PTRACE_GETFPREGS: