ia64/xen-unstable

changeset 4867:a9b0f5ea7651

bitkeeper revision 1.1389.19.6 (4283326fLInxsBy4d19FLaiMPEMO4w)

Some more mmap() error-return fixes.
Signed-off-by: Keir Fraser <keir@xensource.com>
author kaf24@firebug.cl.cam.ac.uk
date Thu May 12 10:39:43 2005 +0000 (2005-05-12)
parents f80fbc4d6526
children 3291b52e8ca6
files tools/libxc/xc_ptrace_core.c
line diff
     1.1 --- a/tools/libxc/xc_ptrace_core.c	Thu May 12 10:33:58 2005 +0000
     1.2 +++ b/tools/libxc/xc_ptrace_core.c	Thu May 12 10:39:43 2005 +0000
     1.3 @@ -107,6 +107,7 @@ map_domain_va(unsigned long domfd, int c
     1.4  {
     1.5      unsigned long pde, page;
     1.6      unsigned long va = (unsigned long)guest_va;
     1.7 +    void *v;
     1.8  
     1.9      static unsigned long  cr3_phys[MAX_VIRT_CPUS];
    1.10      static unsigned long *cr3_virt[MAX_VIRT_CPUS];
    1.11 @@ -120,13 +121,15 @@ map_domain_va(unsigned long domfd, int c
    1.12  	cr3_phys[cpu] = cr3[cpu];
    1.13  	if (cr3_virt[cpu])
    1.14  	    munmap(cr3_virt[cpu], PAGE_SIZE);
    1.15 -	if ((cr3_virt[cpu] = mmap(NULL, PAGE_SIZE, PROT_READ, 
    1.16 -				  MAP_PRIVATE, domfd, map_mtop_offset(cr3_phys[cpu]))) == 
    1.17 -	    (unsigned long*)0xffffffff)
    1.18 +	v = mmap(
    1.19 +            NULL, PAGE_SIZE, PROT_READ, MAP_PRIVATE, domfd,
    1.20 +            map_mtop_offset(cr3_phys[cpu]));
    1.21 +        if (v == MAP_FAILED)
    1.22  	{
    1.23  	    perror("mmap failed");
    1.24  	    goto error_out;
    1.25  	}
    1.26 +        cr3_virt[cpu] = v;
    1.27      } 
    1.28      if ((pde = cr3_virt[cpu][vtopdi(va)]) == 0) /* logical address */
    1.29  	goto error_out;
    1.30 @@ -137,9 +140,12 @@ map_domain_va(unsigned long domfd, int c
    1.31  	pde_phys[cpu] = pde;
    1.32  	if (pde_virt[cpu])
    1.33  	    munmap(pde_virt[cpu], PAGE_SIZE);
    1.34 -	if ((pde_virt[cpu] =  mmap(NULL, PAGE_SIZE, PROT_READ, 
    1.35 -				  MAP_PRIVATE, domfd, map_mtop_offset(pde_phys[cpu]))) == NULL)
    1.36 +	v = mmap(
    1.37 +            NULL, PAGE_SIZE, PROT_READ, MAP_PRIVATE, domfd,
    1.38 +            map_mtop_offset(pde_phys[cpu]));
    1.39 +        if (v == MAP_FAILED)
    1.40  	    goto error_out;
    1.41 +        pde_virt[cpu] = v;
    1.42      }
    1.43      if ((page = pde_virt[cpu][vtopti(va)]) == 0) /* logical address */
    1.44  	goto error_out;
    1.45 @@ -150,12 +156,15 @@ map_domain_va(unsigned long domfd, int c
    1.46  	page_phys[cpu] = page;
    1.47  	if (page_virt[cpu])
    1.48  	    munmap(page_virt[cpu], PAGE_SIZE);
    1.49 -	if ((page_virt[cpu] = mmap(NULL, PAGE_SIZE, PROT_READ, 
    1.50 -				  MAP_PRIVATE, domfd, map_mtop_offset(page_phys[cpu]))) == NULL) {
    1.51 +	v = mmap(
    1.52 +            NULL, PAGE_SIZE, PROT_READ, MAP_PRIVATE, domfd,
    1.53 +            map_mtop_offset(page_phys[cpu]));
    1.54 +        if (v == MAP_FAILED) {
    1.55  	    printf("cr3 %lx pde %lx page %lx pti %lx\n", cr3[cpu], pde, page, vtopti(va));
    1.56  	    page_phys[cpu] = 0;
    1.57  	    goto error_out;
    1.58  	}
    1.59 +        page_virt[cpu] = v;
    1.60      }	
    1.61      return (void *)(((unsigned long)page_virt[cpu]) | (va & BSD_PAGE_MASK));
    1.62