ia64/xen-unstable

changeset 6961:3133e64d0462

merge?
author cl349@firebug.cl.cam.ac.uk
date Mon Sep 19 13:24:31 2005 +0000 (2005-09-19)
parents c0c96a494c76 619e3d6f01b3
children fc4375af5854 a5d67e3fbff1
files docs/Makefile tools/debugger/gdb/gdb-6.2.1-xen-sparse/gdb/gdbserver/configure tools/debugger/gdb/gdb-6.2.1-xen-sparse/gdb/gdbserver/configure.in tools/libxc/xc_core.c tools/libxc/xc_domain.c tools/libxc/xc_ia64_stubs.c tools/libxc/xc_linux_build.c tools/libxc/xc_linux_save.c tools/libxc/xc_load_aout9.c tools/libxc/xc_load_bin.c tools/libxc/xc_load_elf.c tools/libxc/xc_misc.c tools/libxc/xc_private.c tools/libxc/xc_ptrace.c tools/libxc/xc_ptrace_core.c tools/libxc/xc_vmx_build.c tools/python/pylintrc tools/python/xen/sv/Main.py tools/python/xen/sv/Wizard.py tools/python/xen/xend/Args.py tools/python/xen/xend/EventServer.py tools/python/xen/xend/Vifctl.py tools/python/xen/xend/XendCheckpoint.py tools/python/xen/xend/XendDomain.py tools/python/xen/xend/XendDomainInfo.py tools/python/xen/xend/image.py tools/python/xen/xend/scheduler.py tools/python/xen/xend/server/SrvDaemon.py tools/python/xen/xend/server/SrvDomainDir.py tools/python/xen/xend/server/SrvNode.py tools/python/xen/xend/server/SrvServer.py tools/python/xen/xend/server/blkif.py tools/python/xen/xend/server/channel.py tools/python/xen/xend/server/event.py tools/python/xen/xend/server/netif.py tools/python/xen/xend/server/pciif.py tools/python/xen/xend/server/tpmif.py tools/python/xen/xend/server/usbif.py tools/python/xen/xend/xenstore/xsobj.py tools/python/xen/xend/xenstore/xstransact.py tools/python/xen/xend/xenstore/xswatch.py tools/python/xen/xm/create.py xen/arch/x86/shadow.c xen/arch/x86/shadow32.c xen/arch/x86/shadow_public.c xen/include/asm-x86/shadow.h
line diff
     4.1 --- a/tools/libxc/xc_core.c	Mon Sep 19 13:24:13 2005 +0000
     4.2 +++ b/tools/libxc/xc_core.c	Mon Sep 19 13:24:31 2005 +0000
     4.3 @@ -11,10 +11,10 @@
     4.4  
     4.5  static int
     4.6  copy_from_domain_page(int xc_handle,
     4.7 -		      u32 domid,
     4.8 -		      unsigned long *page_array,
     4.9 -		      unsigned long src_pfn,
    4.10 -		      void *dst_page)
    4.11 +                      u32 domid,
    4.12 +                      unsigned long *page_array,
    4.13 +                      unsigned long src_pfn,
    4.14 +                      void *dst_page)
    4.15  {
    4.16      void *vaddr = xc_map_foreign_range(
    4.17          xc_handle, domid, PAGE_SIZE, PROT_READ, page_array[src_pfn]);
    4.18 @@ -27,90 +27,100 @@ copy_from_domain_page(int xc_handle,
    4.19  
    4.20  int 
    4.21  xc_domain_dumpcore(int xc_handle,
    4.22 -		   u32 domid,
    4.23 -		   const char *corename)
    4.24 +                   u32 domid,
    4.25 +                   const char *corename)
    4.26  {
    4.27 -	unsigned long nr_pages;
    4.28 -	unsigned long *page_array;
    4.29 -	xc_dominfo_t info;
    4.30 -	int i, j, vcpu_map_size, dump_fd;
    4.31 -	char *dump_mem, *dump_mem_start = NULL;
    4.32 -	struct xc_core_header header;
    4.33 -	vcpu_guest_context_t     ctxt[MAX_VIRT_CPUS];
    4.34 +    unsigned long nr_pages;
    4.35 +    unsigned long *page_array;
    4.36 +    xc_dominfo_t info;
    4.37 +    int i, j, vcpu_map_size, dump_fd;
    4.38 +    char *dump_mem, *dump_mem_start = NULL;
    4.39 +    struct xc_core_header header;
    4.40 +    vcpu_guest_context_t     ctxt[MAX_VIRT_CPUS];
    4.41  
    4.42 -	
    4.43 -	if ((dump_fd = open(corename, O_CREAT|O_RDWR, S_IWUSR|S_IRUSR)) < 0) {
    4.44 -		PERROR("Could not open corefile %s: %s", corename, strerror(errno));
    4.45 -		goto error_out;
    4.46 -	}
    4.47 -	
    4.48 -	if ((dump_mem_start = malloc(DUMP_INCREMENT*PAGE_SIZE)) == NULL) {
    4.49 -		PERROR("Could not allocate dump_mem");
    4.50 -		goto error_out;
    4.51 -	}
    4.52 -	
    4.53 -	if (xc_domain_getinfo(xc_handle, domid, 1, &info) != 1) {
    4.54 -		PERROR("Could not get info for domain");
    4.55 -		goto error_out;
    4.56 -	}
    4.57 -	
    4.58 -	vcpu_map_size =  sizeof(info.vcpu_to_cpu) / sizeof(info.vcpu_to_cpu[0]);
    4.59 + 
    4.60 +    if ((dump_fd = open(corename, O_CREAT|O_RDWR, S_IWUSR|S_IRUSR)) < 0) {
    4.61 +        PERROR("Could not open corefile %s: %s", corename, strerror(errno));
    4.62 +        goto error_out;
    4.63 +    }
    4.64 + 
    4.65 +    if ((dump_mem_start = malloc(DUMP_INCREMENT*PAGE_SIZE)) == NULL) {
    4.66 +        PERROR("Could not allocate dump_mem");
    4.67 +        goto error_out;
    4.68 +    }
    4.69 + 
    4.70 +    if (xc_domain_getinfo(xc_handle, domid, 1, &info) != 1) {
    4.71 +        PERROR("Could not get info for domain");
    4.72 +        goto error_out;
    4.73 +    }
    4.74 + 
    4.75 +    vcpu_map_size =  sizeof(info.vcpu_to_cpu) / sizeof(info.vcpu_to_cpu[0]);
    4.76  
    4.77 -	for (i = 0, j = 0; i < vcpu_map_size; i++) {
    4.78 -		if (info.vcpu_to_cpu[i] == -1) {
    4.79 -			continue;
    4.80 -		}
    4.81 -		if (xc_domain_get_vcpu_context(xc_handle, domid, i, &ctxt[j])) {
    4.82 -			PERROR("Could not get all vcpu contexts for domain");
    4.83 -			goto error_out;
    4.84 -		}
    4.85 -		j++;
    4.86 -	}
    4.87 -	
    4.88 -	nr_pages = info.nr_pages;
    4.89 +    for (i = 0, j = 0; i < vcpu_map_size; i++) {
    4.90 +        if (info.vcpu_to_cpu[i] == -1) {
    4.91 +            continue;
    4.92 +        }
    4.93 +        if (xc_domain_get_vcpu_context(xc_handle, domid, i, &ctxt[j])) {
    4.94 +            PERROR("Could not get all vcpu contexts for domain");
    4.95 +            goto error_out;
    4.96 +        }
    4.97 +        j++;
    4.98 +    }
    4.99 + 
   4.100 +    nr_pages = info.nr_pages;
   4.101  
   4.102 -	header.xch_magic = 0xF00FEBED; 
   4.103 -	header.xch_nr_vcpus = info.vcpus;
   4.104 -	header.xch_nr_pages = nr_pages;
   4.105 -	header.xch_ctxt_offset = sizeof(struct xc_core_header);
   4.106 -	header.xch_index_offset = sizeof(struct xc_core_header) +
   4.107 -	    sizeof(vcpu_guest_context_t)*info.vcpus;
   4.108 -	header.xch_pages_offset = round_pgup(sizeof(struct xc_core_header) +
   4.109 -	    (sizeof(vcpu_guest_context_t) * info.vcpus) + 
   4.110 -	    (nr_pages * sizeof(unsigned long)));
   4.111 +    header.xch_magic = 0xF00FEBED; 
   4.112 +    header.xch_nr_vcpus = info.vcpus;
   4.113 +    header.xch_nr_pages = nr_pages;
   4.114 +    header.xch_ctxt_offset = sizeof(struct xc_core_header);
   4.115 +    header.xch_index_offset = sizeof(struct xc_core_header) +
   4.116 +        sizeof(vcpu_guest_context_t)*info.vcpus;
   4.117 +    header.xch_pages_offset = round_pgup(sizeof(struct xc_core_header) +
   4.118 +                                         (sizeof(vcpu_guest_context_t) * info.vcpus) + 
   4.119 +                                         (nr_pages * sizeof(unsigned long)));
   4.120  
   4.121 -	write(dump_fd, &header, sizeof(struct xc_core_header));
   4.122 -	write(dump_fd, &ctxt, sizeof(ctxt[0]) * info.vcpus);
   4.123 +    write(dump_fd, &header, sizeof(struct xc_core_header));
   4.124 +    write(dump_fd, &ctxt, sizeof(ctxt[0]) * info.vcpus);
   4.125  
   4.126 -	if ((page_array = malloc(nr_pages * sizeof(unsigned long))) == NULL) {
   4.127 -	    printf("Could not allocate memory\n");
   4.128 -	    goto error_out;
   4.129 -	}
   4.130 -	if (xc_get_pfn_list(xc_handle, domid, page_array, nr_pages) != nr_pages) {
   4.131 -	    printf("Could not get the page frame list\n");
   4.132 -	    goto error_out;
   4.133 -	}
   4.134 -	write(dump_fd, page_array, nr_pages * sizeof(unsigned long));
   4.135 -	lseek(dump_fd, header.xch_pages_offset, SEEK_SET);
   4.136 -	for (dump_mem = dump_mem_start, i = 0; i < nr_pages; i++) {
   4.137 -		copy_from_domain_page(xc_handle, domid, page_array, i, dump_mem);
   4.138 -		dump_mem += PAGE_SIZE;
   4.139 -		if (((i + 1) % DUMP_INCREMENT == 0) || (i + 1) == nr_pages) {
   4.140 -			if (write(dump_fd, dump_mem_start, dump_mem - dump_mem_start) < 
   4.141 -			    dump_mem - dump_mem_start) {
   4.142 -				PERROR("Partial write, file system full?");
   4.143 -				goto error_out;
   4.144 -			}
   4.145 -			dump_mem = dump_mem_start;
   4.146 -		}
   4.147 -	}
   4.148 +    if ((page_array = malloc(nr_pages * sizeof(unsigned long))) == NULL) {
   4.149 +        printf("Could not allocate memory\n");
   4.150 +        goto error_out;
   4.151 +    }
   4.152 +    if (xc_get_pfn_list(xc_handle, domid, page_array, nr_pages) != nr_pages) {
   4.153 +        printf("Could not get the page frame list\n");
   4.154 +        goto error_out;
   4.155 +    }
   4.156 +    write(dump_fd, page_array, nr_pages * sizeof(unsigned long));
   4.157 +    lseek(dump_fd, header.xch_pages_offset, SEEK_SET);
   4.158 +    for (dump_mem = dump_mem_start, i = 0; i < nr_pages; i++) {
   4.159 +        copy_from_domain_page(xc_handle, domid, page_array, i, dump_mem);
   4.160 +        dump_mem += PAGE_SIZE;
   4.161 +        if (((i + 1) % DUMP_INCREMENT == 0) || (i + 1) == nr_pages) {
   4.162 +            if (write(dump_fd, dump_mem_start, dump_mem - dump_mem_start) < 
   4.163 +                dump_mem - dump_mem_start) {
   4.164 +                PERROR("Partial write, file system full?");
   4.165 +                goto error_out;
   4.166 +            }
   4.167 +            dump_mem = dump_mem_start;
   4.168 +        }
   4.169 +    }
   4.170  
   4.171 -	close(dump_fd);
   4.172 -	free(dump_mem_start);
   4.173 -	return 0;
   4.174 +    close(dump_fd);
   4.175 +    free(dump_mem_start);
   4.176 +    return 0;
   4.177   error_out:
   4.178 -	if (dump_fd != -1)
   4.179 -		close(dump_fd);
   4.180 -	free(dump_mem_start);
   4.181 -	return -1;
   4.182 +    if (dump_fd != -1)
   4.183 +        close(dump_fd);
   4.184 +    free(dump_mem_start);
   4.185 +    return -1;
   4.186  }
   4.187 +
   4.188 +/*
   4.189 + * Local variables:
   4.190 + * mode: C
   4.191 + * c-set-style: "BSD"
   4.192 + * c-basic-offset: 4
   4.193 + * tab-width: 4
   4.194 + * indent-tabs-mode: nil
   4.195 + * End:
   4.196 + */
     5.1 --- a/tools/libxc/xc_domain.c	Mon Sep 19 13:24:13 2005 +0000
     5.2 +++ b/tools/libxc/xc_domain.c	Mon Sep 19 13:24:31 2005 +0000
     5.3 @@ -265,7 +265,7 @@ int xc_domain_memory_increase_reservatio
     5.4                                            unsigned long nr_extents,
     5.5                                            unsigned int extent_order,
     5.6                                            unsigned int address_bits,
     5.7 -					  unsigned long *extent_start)
     5.8 +                                          unsigned long *extent_start)
     5.9  {
    5.10      int err;
    5.11      struct xen_memory_reservation reservation = {
    5.12 @@ -296,7 +296,7 @@ int xc_domain_memory_decrease_reservatio
    5.13                                            u32 domid, 
    5.14                                            unsigned long nr_extents,
    5.15                                            unsigned int extent_order,
    5.16 -					  unsigned long *extent_start)
    5.17 +                                          unsigned long *extent_start)
    5.18  {
    5.19      int err;
    5.20      struct xen_memory_reservation reservation = {
    5.21 @@ -328,3 +328,13 @@ int xc_domain_memory_decrease_reservatio
    5.22  
    5.23      return err;
    5.24  }
    5.25 +
    5.26 +/*
    5.27 + * Local variables:
    5.28 + * mode: C
    5.29 + * c-set-style: "BSD"
    5.30 + * c-basic-offset: 4
    5.31 + * tab-width: 4
    5.32 + * indent-tabs-mode: nil
    5.33 + * End:
    5.34 + */
     6.1 --- a/tools/libxc/xc_ia64_stubs.c	Mon Sep 19 13:24:13 2005 +0000
     6.2 +++ b/tools/libxc/xc_ia64_stubs.c	Mon Sep 19 13:24:31 2005 +0000
     6.3 @@ -9,8 +9,8 @@ int xc_linux_save(int xc_handle, int io_
     6.4  }
     6.5  
     6.6  int xc_linux_restore(int xc_handle, int io_fd, u32 dom, unsigned long nr_pfns,
     6.7 -		     unsigned int store_evtchn, unsigned long *store_mfn,
     6.8 -		     unsigned int console_evtchn, unsigned long *console_mfn)
     6.9 +                     unsigned int store_evtchn, unsigned long *store_mfn,
    6.10 +                     unsigned int console_evtchn, unsigned long *console_mfn)
    6.11  {
    6.12      PERROR("xc_linux_restore not implemented\n");
    6.13      return -1;
    6.14 @@ -44,3 +44,12 @@ xc_plan9_build(int xc_handle,
    6.15      return -1;
    6.16  }
    6.17  
    6.18 +/*
    6.19 + * Local variables:
    6.20 + * mode: C
    6.21 + * c-set-style: "BSD"
    6.22 + * c-basic-offset: 4
    6.23 + * tab-width: 4
    6.24 + * indent-tabs-mode: nil
    6.25 + * End:
    6.26 + */
     7.1 --- a/tools/libxc/xc_linux_build.c	Mon Sep 19 13:24:13 2005 +0000
     7.2 +++ b/tools/libxc/xc_linux_build.c	Mon Sep 19 13:24:31 2005 +0000
     7.3 @@ -13,7 +13,6 @@
     7.4  #define ELFSIZE 64
     7.5  #endif
     7.6  
     7.7 -
     7.8  #include "xc_elf.h"
     7.9  #include "xc_aout9.h"
    7.10  #include <stdlib.h>
    7.11 @@ -33,6 +32,13 @@
    7.12  #define L4_PROT (_PAGE_PRESENT|_PAGE_RW|_PAGE_ACCESSED|_PAGE_DIRTY|_PAGE_USER)
    7.13  #endif
    7.14  
    7.15 +#ifdef __ia64__
    7.16 +#define already_built(ctxt) (0)
    7.17 +#define get_tot_pages xc_get_max_pages
    7.18 +#else
    7.19 +#define already_built(ctxt) ((ctxt)->ctrlreg[3] != 0)
    7.20 +#define get_tot_pages xc_get_tot_pages
    7.21 +#endif
    7.22  
    7.23  #define round_pgup(_p)    (((_p)+(PAGE_SIZE-1))&PAGE_MASK)
    7.24  #define round_pgdown(_p)  ((_p)&PAGE_MASK)
    7.25 @@ -47,7 +53,7 @@ static int probeimageformat(char *image,
    7.26  {
    7.27      if ( probe_elf(image, image_size, load_funcs) &&
    7.28           probe_bin(image, image_size, load_funcs) &&
    7.29 -	 probe_aout9(image, image_size, load_funcs) )
    7.30 +         probe_aout9(image, image_size, load_funcs) )
    7.31      {
    7.32          ERROR( "Unrecognized image format" );
    7.33          return -EINVAL;
    7.34 @@ -56,27 +62,27 @@ static int probeimageformat(char *image,
    7.35      return 0;
    7.36  }
    7.37  
    7.38 -#define alloc_pt(ltab, vltab) \
    7.39 -        ltab = (unsigned long long)(page_array[ppt_alloc++]) << PAGE_SHIFT; \
    7.40 -        if (vltab != NULL) { \
    7.41 -            munmap(vltab, PAGE_SIZE); \
    7.42 -        } \
    7.43 -        if ((vltab = xc_map_foreign_range(xc_handle, dom, PAGE_SIZE, \
    7.44 -                          PROT_READ|PROT_WRITE, \
    7.45 -                          ltab >> PAGE_SHIFT)) == NULL) { \
    7.46 -            goto error_out; \
    7.47 -        } \
    7.48 -        memset(vltab, 0, PAGE_SIZE);
    7.49 +#define alloc_pt(ltab, vltab)                                           \
    7.50 +do {                                                                    \
    7.51 +    ltab = (u64)page_array[ppt_alloc++] << PAGE_SHIFT;                  \
    7.52 +    if ( vltab != NULL )                                                \
    7.53 +        munmap(vltab, PAGE_SIZE);                                       \
    7.54 +    if ( (vltab = xc_map_foreign_range(xc_handle, dom, PAGE_SIZE,       \
    7.55 +                                       PROT_READ|PROT_WRITE,            \
    7.56 +                                       ltab >> PAGE_SHIFT)) == NULL )   \
    7.57 +        goto error_out;                                                 \
    7.58 +    memset(vltab, 0, PAGE_SIZE);                                        \
    7.59 +} while ( 0 )
    7.60  
    7.61  #if defined(__i386__)
    7.62  
    7.63  static int setup_pg_tables(int xc_handle, u32 dom,
    7.64 -			   vcpu_guest_context_t *ctxt,
    7.65 -			   unsigned long dsi_v_start,
    7.66 -			   unsigned long v_end,
    7.67 -			   unsigned long *page_array,
    7.68 -			   unsigned long vpt_start,
    7.69 -			   unsigned long vpt_end)
    7.70 +                           vcpu_guest_context_t *ctxt,
    7.71 +                           unsigned long dsi_v_start,
    7.72 +                           unsigned long v_end,
    7.73 +                           unsigned long *page_array,
    7.74 +                           unsigned long vpt_start,
    7.75 +                           unsigned long vpt_end)
    7.76  {
    7.77      l1_pgentry_t *vl1tab=NULL, *vl1e=NULL;
    7.78      l2_pgentry_t *vl2tab=NULL, *vl2e=NULL;
    7.79 @@ -90,11 +96,11 @@ static int setup_pg_tables(int xc_handle
    7.80      vl2e = &vl2tab[l2_table_offset(dsi_v_start)];
    7.81      ctxt->ctrlreg[3] = l2tab;
    7.82  
    7.83 -    for ( count = 0; count < ((v_end-dsi_v_start)>>PAGE_SHIFT); count++ )
    7.84 +    for ( count = 0; count < ((v_end - dsi_v_start) >> PAGE_SHIFT); count++ )
    7.85      {    
    7.86          if ( ((unsigned long)vl1e & (PAGE_SIZE-1)) == 0 )
    7.87          {
    7.88 -	    alloc_pt(l1tab, vl1tab);
    7.89 +            alloc_pt(l1tab, vl1tab);
    7.90              vl1e = &vl1tab[l1_table_offset(dsi_v_start + (count<<PAGE_SHIFT))];
    7.91              *vl2e++ = l1tab | L2_PROT;
    7.92          }
    7.93 @@ -111,79 +117,67 @@ static int setup_pg_tables(int xc_handle
    7.94  
    7.95   error_out:
    7.96      if (vl1tab)
    7.97 -	munmap(vl1tab, PAGE_SIZE);
    7.98 +        munmap(vl1tab, PAGE_SIZE);
    7.99      if (vl2tab)
   7.100 -	munmap(vl2tab, PAGE_SIZE);
   7.101 +        munmap(vl2tab, PAGE_SIZE);
   7.102      return -1;
   7.103  }
   7.104  
   7.105  static int setup_pg_tables_pae(int xc_handle, u32 dom,
   7.106 -			       vcpu_guest_context_t *ctxt,
   7.107 -			       unsigned long dsi_v_start,
   7.108 -			       unsigned long v_end,
   7.109 -			       unsigned long *page_array,
   7.110 -			       unsigned long vpt_start,
   7.111 -			       unsigned long vpt_end)
   7.112 +                               vcpu_guest_context_t *ctxt,
   7.113 +                               unsigned long dsi_v_start,
   7.114 +                               unsigned long v_end,
   7.115 +                               unsigned long *page_array,
   7.116 +                               unsigned long vpt_start,
   7.117 +                               unsigned long vpt_end)
   7.118  {
   7.119 -    l1_pgentry_64_t *vl1tab=NULL, *vl1e=NULL;
   7.120 -    l2_pgentry_64_t *vl2tab=NULL, *vl2e=NULL;
   7.121 -    l3_pgentry_64_t *vl3tab=NULL, *vl3e=NULL;
   7.122 -    unsigned long long l1tab = 0;
   7.123 -    unsigned long long l2tab = 0;
   7.124 -    unsigned long long l3tab = 0;
   7.125 -    unsigned long ppt_alloc;
   7.126 -    unsigned long count;
   7.127 +    l1_pgentry_64_t *vl1tab = NULL, *vl1e = NULL;
   7.128 +    l2_pgentry_64_t *vl2tab = NULL, *vl2e = NULL;
   7.129 +    l3_pgentry_64_t *vl3tab = NULL, *vl3e = NULL;
   7.130 +    u64 l1tab, l2tab, l3tab;
   7.131 +    unsigned long ppt_alloc, count, nmfn;
   7.132  
   7.133      /* First allocate page for page dir. */
   7.134      ppt_alloc = (vpt_start - dsi_v_start) >> PAGE_SHIFT;
   7.135  
   7.136      if ( page_array[ppt_alloc] > 0xfffff )
   7.137      {
   7.138 -	unsigned long nmfn;
   7.139 -	nmfn = xc_make_page_below_4G( xc_handle, dom, page_array[ppt_alloc] );
   7.140 -	if ( nmfn == 0 )
   7.141 -	{
   7.142 -	    fprintf(stderr, "Couldn't get a page below 4GB :-(\n");
   7.143 -	    goto error_out;
   7.144 -	}
   7.145 -	page_array[ppt_alloc] = nmfn;
   7.146 +        nmfn = xc_make_page_below_4G(xc_handle, dom, page_array[ppt_alloc]);
   7.147 +        if ( nmfn == 0 )
   7.148 +        {
   7.149 +            fprintf(stderr, "Couldn't get a page below 4GB :-(\n");
   7.150 +            goto error_out;
   7.151 +        }
   7.152 +        page_array[ppt_alloc] = nmfn;
   7.153      }
   7.154  
   7.155      alloc_pt(l3tab, vl3tab);
   7.156      vl3e = &vl3tab[l3_table_offset_pae(dsi_v_start)];
   7.157      ctxt->ctrlreg[3] = l3tab;
   7.158  
   7.159 -    if(l3tab>0xfffff000ULL)
   7.160 -    {
   7.161 -        fprintf(stderr,"L3TAB = %llx above 4GB!\n",l3tab);
   7.162 -        goto error_out;
   7.163 -    }
   7.164 - 
   7.165 -    for ( count = 0; count < ((v_end-dsi_v_start)>>PAGE_SHIFT); count++)
   7.166 +    for ( count = 0; count < ((v_end - dsi_v_start) >> PAGE_SHIFT); count++)
   7.167      {
   7.168          if ( !((unsigned long)vl1e & (PAGE_SIZE-1)) )
   7.169          {
   7.170 +            if ( !((unsigned long)vl2e & (PAGE_SIZE-1)) )
   7.171 +            {
   7.172 +                alloc_pt(l2tab, vl2tab);
   7.173 +                vl2e = &vl2tab[l2_table_offset_pae(
   7.174 +                    dsi_v_start + (count << PAGE_SHIFT))];
   7.175 +                *vl3e++ = l2tab | L3_PROT;
   7.176 +            }
   7.177 +
   7.178              alloc_pt(l1tab, vl1tab);
   7.179 -            
   7.180 -                if ( !((unsigned long)vl2e & (PAGE_SIZE-1)) )
   7.181 -                {
   7.182 -                    alloc_pt(l2tab, vl2tab);
   7.183 -                    vl2e = &vl2tab[l2_table_offset_pae(dsi_v_start + (count<<PAGE_SHIFT))];
   7.184 -                    *vl3e = l2tab | L3_PROT;
   7.185 -                    vl3e++;
   7.186 -                }
   7.187 -            vl1e = &vl1tab[l1_table_offset_pae(dsi_v_start + (count<<PAGE_SHIFT))];
   7.188 -            *vl2e = l1tab | L2_PROT;
   7.189 -            vl2e++;
   7.190 +            vl1e = &vl1tab[l1_table_offset_pae(
   7.191 +                dsi_v_start + (count << PAGE_SHIFT))];
   7.192 +            *vl2e++ = l1tab | L2_PROT;
   7.193          }
   7.194          
   7.195 -        *vl1e = (page_array[count] << PAGE_SHIFT) | L1_PROT;
   7.196 +        *vl1e = ((u64)page_array[count] << PAGE_SHIFT) | L1_PROT;
   7.197          if ( (count >= ((vpt_start-dsi_v_start)>>PAGE_SHIFT)) &&
   7.198 -	     (count <  ((vpt_end  -dsi_v_start)>>PAGE_SHIFT)) ) 
   7.199 -        {
   7.200 -	    *vl1e &= ~_PAGE_RW;
   7.201 -        }
   7.202 -	vl1e++;
   7.203 +             (count <  ((vpt_end  -dsi_v_start)>>PAGE_SHIFT)) ) 
   7.204 +            *vl1e &= ~_PAGE_RW;
   7.205 +        vl1e++;
   7.206      }
   7.207       
   7.208      munmap(vl1tab, PAGE_SIZE);
   7.209 @@ -193,11 +187,11 @@ static int setup_pg_tables_pae(int xc_ha
   7.210  
   7.211   error_out:
   7.212      if (vl1tab)
   7.213 -	munmap(vl1tab, PAGE_SIZE);
   7.214 +        munmap(vl1tab, PAGE_SIZE);
   7.215      if (vl2tab)
   7.216 -	munmap(vl2tab, PAGE_SIZE);
   7.217 +        munmap(vl2tab, PAGE_SIZE);
   7.218      if (vl3tab)
   7.219 -	munmap(vl3tab, PAGE_SIZE);
   7.220 +        munmap(vl3tab, PAGE_SIZE);
   7.221      return -1;
   7.222  }
   7.223  
   7.224 @@ -206,12 +200,12 @@ static int setup_pg_tables_pae(int xc_ha
   7.225  #if defined(__x86_64__)
   7.226  
   7.227  static int setup_pg_tables_64(int xc_handle, u32 dom,
   7.228 -			      vcpu_guest_context_t *ctxt,
   7.229 -			      unsigned long dsi_v_start,
   7.230 -			      unsigned long v_end,
   7.231 -			      unsigned long *page_array,
   7.232 -			      unsigned long vpt_start,
   7.233 -			      unsigned long vpt_end)
   7.234 +                              vcpu_guest_context_t *ctxt,
   7.235 +                              unsigned long dsi_v_start,
   7.236 +                              unsigned long v_end,
   7.237 +                              unsigned long *page_array,
   7.238 +                              unsigned long vpt_start,
   7.239 +                              unsigned long vpt_end)
   7.240  {
   7.241      l1_pgentry_t *vl1tab=NULL, *vl1e=NULL;
   7.242      l2_pgentry_t *vl2tab=NULL, *vl2e=NULL;
   7.243 @@ -236,20 +230,20 @@ static int setup_pg_tables_64(int xc_han
   7.244          {
   7.245              alloc_pt(l1tab, vl1tab);
   7.246              
   7.247 -                if ( !((unsigned long)vl2e & (PAGE_SIZE-1)) )
   7.248 +            if ( !((unsigned long)vl2e & (PAGE_SIZE-1)) )
   7.249 +            {
   7.250 +                alloc_pt(l2tab, vl2tab);
   7.251 +                if ( !((unsigned long)vl3e & (PAGE_SIZE-1)) )
   7.252                  {
   7.253 -                    alloc_pt(l2tab, vl2tab);
   7.254 -                    if ( !((unsigned long)vl3e & (PAGE_SIZE-1)) )
   7.255 -                    {
   7.256 -                        alloc_pt(l3tab, vl3tab);
   7.257 -                        vl3e = &vl3tab[l3_table_offset(dsi_v_start + (count<<PAGE_SHIFT))];
   7.258 -                        *vl4e = l3tab | L4_PROT;
   7.259 -                        vl4e++;
   7.260 -                    }
   7.261 -                    vl2e = &vl2tab[l2_table_offset(dsi_v_start + (count<<PAGE_SHIFT))];
   7.262 -                    *vl3e = l2tab | L3_PROT;
   7.263 -                    vl3e++;
   7.264 +                    alloc_pt(l3tab, vl3tab);
   7.265 +                    vl3e = &vl3tab[l3_table_offset(dsi_v_start + (count<<PAGE_SHIFT))];
   7.266 +                    *vl4e = l3tab | L4_PROT;
   7.267 +                    vl4e++;
   7.268                  }
   7.269 +                vl2e = &vl2tab[l2_table_offset(dsi_v_start + (count<<PAGE_SHIFT))];
   7.270 +                *vl3e = l2tab | L3_PROT;
   7.271 +                vl3e++;
   7.272 +            }
   7.273              vl1e = &vl1tab[l1_table_offset(dsi_v_start + (count<<PAGE_SHIFT))];
   7.274              *vl2e = l1tab | L2_PROT;
   7.275              vl2e++;
   7.276 @@ -257,11 +251,11 @@ static int setup_pg_tables_64(int xc_han
   7.277          
   7.278          *vl1e = (page_array[count] << PAGE_SHIFT) | L1_PROT;
   7.279          if ( (count >= ((vpt_start-dsi_v_start)>>PAGE_SHIFT)) &&
   7.280 -            (count <  ((vpt_end  -dsi_v_start)>>PAGE_SHIFT)) ) 
   7.281 +             (count <  ((vpt_end  -dsi_v_start)>>PAGE_SHIFT)) ) 
   7.282          {
   7.283 -                *vl1e &= ~_PAGE_RW;
   7.284 +            *vl1e &= ~_PAGE_RW;
   7.285          }
   7.286 -            vl1e++;
   7.287 +        vl1e++;
   7.288      }
   7.289       
   7.290      munmap(vl1tab, PAGE_SIZE);
   7.291 @@ -272,13 +266,13 @@ static int setup_pg_tables_64(int xc_han
   7.292  
   7.293   error_out:
   7.294      if (vl1tab)
   7.295 -	munmap(vl1tab, PAGE_SIZE);
   7.296 +        munmap(vl1tab, PAGE_SIZE);
   7.297      if (vl2tab)
   7.298 -	munmap(vl2tab, PAGE_SIZE);
   7.299 +        munmap(vl2tab, PAGE_SIZE);
   7.300      if (vl3tab)
   7.301 -	munmap(vl3tab, PAGE_SIZE);
   7.302 +        munmap(vl3tab, PAGE_SIZE);
   7.303      if (vl4tab)
   7.304 -	munmap(vl4tab, PAGE_SIZE);
   7.305 +        munmap(vl4tab, PAGE_SIZE);
   7.306      return -1;
   7.307  }
   7.308  #endif
   7.309 @@ -286,18 +280,18 @@ static int setup_pg_tables_64(int xc_han
   7.310  #ifdef __ia64__
   7.311  #include <asm/fpu.h> /* for FPSR_DEFAULT */
   7.312  static int setup_guest(int xc_handle,
   7.313 -                         u32 dom,
   7.314 -                         char *image, unsigned long image_size,
   7.315 -                         gzFile initrd_gfd, unsigned long initrd_len,
   7.316 -                         unsigned long nr_pages,
   7.317 -                         unsigned long *pvsi, unsigned long *pvke,
   7.318 -                         unsigned long *pvss, vcpu_guest_context_t *ctxt,
   7.319 -                         const char *cmdline,
   7.320 -                         unsigned long shared_info_frame,
   7.321 -                         unsigned long flags,
   7.322 -                         unsigned int vcpus,
   7.323 -                         unsigned int store_evtchn, unsigned long *store_mfn,
   7.324 -		         unsigned int console_evtchn, unsigned long *console_mfn)
   7.325 +                       u32 dom,
   7.326 +                       char *image, unsigned long image_size,
   7.327 +                       gzFile initrd_gfd, unsigned long initrd_len,
   7.328 +                       unsigned long nr_pages,
   7.329 +                       unsigned long *pvsi, unsigned long *pvke,
   7.330 +                       unsigned long *pvss, vcpu_guest_context_t *ctxt,
   7.331 +                       const char *cmdline,
   7.332 +                       unsigned long shared_info_frame,
   7.333 +                       unsigned long flags,
   7.334 +                       unsigned int vcpus,
   7.335 +                       unsigned int store_evtchn, unsigned long *store_mfn,
   7.336 +                       unsigned int console_evtchn, unsigned long *console_mfn)
   7.337  {
   7.338      unsigned long *page_array = NULL;
   7.339      struct load_funcs load_funcs;
   7.340 @@ -339,19 +333,20 @@ static int setup_guest(int xc_handle,
   7.341      *pvke = dsi.v_kernentry;
   7.342  
   7.343      /* Now need to retrieve machine pfn for system pages:
   7.344 -     * 	start_info/store/console
   7.345 +     *  start_info/store/console
   7.346       */
   7.347      pgnr = 3;
   7.348 -    if ( xc_ia64_get_pfn_list(xc_handle, dom, page_array, nr_pages - 3, pgnr) != pgnr)
   7.349 +    if ( xc_ia64_get_pfn_list(xc_handle, dom, page_array,
   7.350 +                              nr_pages - 3, pgnr) != pgnr )
   7.351      {
   7.352 -	PERROR("Could not get page frame for xenstore");
   7.353 -	goto error_out;
   7.354 +        PERROR("Could not get page frame for xenstore");
   7.355 +        goto error_out;
   7.356      }
   7.357  
   7.358      *store_mfn = page_array[1];
   7.359      *console_mfn = page_array[2];
   7.360      printf("store_mfn: 0x%lx, console_mfn: 0x%lx\n",
   7.361 -	(u64)store_mfn, (u64)console_mfn);
   7.362 +           (u64)store_mfn, (u64)console_mfn);
   7.363  
   7.364      start_info = xc_map_foreign_range(
   7.365          xc_handle, dom, PAGE_SIZE, PROT_READ|PROT_WRITE, page_array[0]);
   7.366 @@ -382,8 +377,8 @@ static int setup_guest(int xc_handle,
   7.367                         unsigned long shared_info_frame,
   7.368                         unsigned long flags,
   7.369                         unsigned int vcpus,
   7.370 -		       unsigned int store_evtchn, unsigned long *store_mfn,
   7.371 -		       unsigned int console_evtchn, unsigned long *console_mfn)
   7.372 +                       unsigned int store_evtchn, unsigned long *store_mfn,
   7.373 +                       unsigned int console_evtchn, unsigned long *console_mfn)
   7.374  {
   7.375      unsigned long *page_array = NULL;
   7.376      unsigned long count, i;
   7.377 @@ -458,26 +453,26 @@ static int setup_guest(int xc_handle,
   7.378          if ( (v_end - vstack_end) < (512UL << 10) )
   7.379              v_end += 1UL << 22; /* Add extra 4MB to get >= 512kB padding. */
   7.380  #if defined(__i386__)
   7.381 -	if (dsi.pae_kernel) {
   7.382 -	    /* FIXME: assumes one L2 pgtable @ 0xc0000000 */
   7.383 -	    if ( (((v_end - dsi.v_start + ((1<<L2_PAGETABLE_SHIFT_PAE)-1)) >> 
   7.384 -		   L2_PAGETABLE_SHIFT_PAE) + 2) <= nr_pt_pages )
   7.385 -		break;
   7.386 -	} else {
   7.387 -	    if ( (((v_end - dsi.v_start + ((1<<L2_PAGETABLE_SHIFT)-1)) >> 
   7.388 -		   L2_PAGETABLE_SHIFT) + 1) <= nr_pt_pages )
   7.389 -		break;
   7.390 -	}
   7.391 +        if (dsi.pae_kernel) {
   7.392 +            /* FIXME: assumes one L2 pgtable @ 0xc0000000 */
   7.393 +            if ( (((v_end - dsi.v_start + ((1<<L2_PAGETABLE_SHIFT_PAE)-1)) >> 
   7.394 +                   L2_PAGETABLE_SHIFT_PAE) + 2) <= nr_pt_pages )
   7.395 +                break;
   7.396 +        } else {
   7.397 +            if ( (((v_end - dsi.v_start + ((1<<L2_PAGETABLE_SHIFT)-1)) >> 
   7.398 +                   L2_PAGETABLE_SHIFT) + 1) <= nr_pt_pages )
   7.399 +                break;
   7.400 +        }
   7.401  #endif
   7.402  #if defined(__x86_64__)
   7.403  #define NR(_l,_h,_s) \
   7.404      (((((_h) + ((1UL<<(_s))-1)) & ~((1UL<<(_s))-1)) - \
   7.405      ((_l) & ~((1UL<<(_s))-1))) >> (_s))
   7.406 -    if ( (1 + /* # L4 */
   7.407 -        NR(dsi.v_start, v_end, L4_PAGETABLE_SHIFT) + /* # L3 */
   7.408 -        NR(dsi.v_start, v_end, L3_PAGETABLE_SHIFT) + /* # L2 */
   7.409 -        NR(dsi.v_start, v_end, L2_PAGETABLE_SHIFT))  /* # L1 */
   7.410 -        <= nr_pt_pages )
   7.411 +        if ( (1 + /* # L4 */
   7.412 +              NR(dsi.v_start, v_end, L4_PAGETABLE_SHIFT) + /* # L3 */
   7.413 +              NR(dsi.v_start, v_end, L3_PAGETABLE_SHIFT) + /* # L2 */
   7.414 +              NR(dsi.v_start, v_end, L2_PAGETABLE_SHIFT))  /* # L1 */
   7.415 +             <= nr_pt_pages )
   7.416              break;
   7.417  #endif
   7.418      }
   7.419 @@ -541,7 +536,7 @@ static int setup_guest(int xc_handle,
   7.420                  goto error_out;
   7.421              }
   7.422              xc_copy_to_domain_page(xc_handle, dom,
   7.423 -                                page_array[i>>PAGE_SHIFT], page);
   7.424 +                                   page_array[i>>PAGE_SHIFT], page);
   7.425          }
   7.426      }
   7.427  
   7.428 @@ -551,22 +546,22 @@ static int setup_guest(int xc_handle,
   7.429      /* setup page tables */
   7.430  #if defined(__i386__)
   7.431      if (dsi.pae_kernel)
   7.432 -	rc = setup_pg_tables_pae(xc_handle, dom, ctxt,
   7.433 -				 dsi.v_start, v_end,
   7.434 -				 page_array, vpt_start, vpt_end);
   7.435 +        rc = setup_pg_tables_pae(xc_handle, dom, ctxt,
   7.436 +                                 dsi.v_start, v_end,
   7.437 +                                 page_array, vpt_start, vpt_end);
   7.438      else {
   7.439 -	rc = setup_pg_tables(xc_handle, dom, ctxt,
   7.440 -			     dsi.v_start, v_end,
   7.441 -			     page_array, vpt_start, vpt_end);
   7.442 +        rc = setup_pg_tables(xc_handle, dom, ctxt,
   7.443 +                             dsi.v_start, v_end,
   7.444 +                             page_array, vpt_start, vpt_end);
   7.445      }
   7.446  #endif
   7.447  #if defined(__x86_64__)
   7.448      rc = setup_pg_tables_64(xc_handle, dom, ctxt,
   7.449 -			    dsi.v_start, v_end,
   7.450 -			    page_array, vpt_start, vpt_end);
   7.451 +                            dsi.v_start, v_end,
   7.452 +                            page_array, vpt_start, vpt_end);
   7.453  #endif
   7.454      if (0 != rc)
   7.455 -	goto error_out;
   7.456 +        goto error_out;
   7.457  
   7.458      /* Write the phys->machine and machine->phys table entries. */
   7.459      physmap_pfn = (vphysmap_start - dsi.v_start) >> PAGE_SHIFT;
   7.460 @@ -576,11 +571,13 @@ static int setup_guest(int xc_handle,
   7.461  
   7.462      for ( count = 0; count < nr_pages; count++ )
   7.463      {
   7.464 -        if ( xc_add_mmu_update(xc_handle, mmu,
   7.465 -			       ((unsigned long long)page_array[count] << PAGE_SHIFT) | 
   7.466 -			       MMU_MACHPHYS_UPDATE, count) )
   7.467 +        if ( xc_add_mmu_update(
   7.468 +            xc_handle, mmu,
   7.469 +            ((u64)page_array[count] << PAGE_SHIFT) | MMU_MACHPHYS_UPDATE,
   7.470 +            count) )
   7.471          {
   7.472 -            fprintf(stderr,"m2p update failure p=%lx m=%lx\n",count,page_array[count] ); 
   7.473 +            fprintf(stderr,"m2p update failure p=%lx m=%lx\n",
   7.474 +                    count, page_array[count]); 
   7.475              munmap(physmap, PAGE_SIZE);
   7.476              goto error_out;
   7.477          }
   7.478 @@ -601,13 +598,13 @@ static int setup_guest(int xc_handle,
   7.479       * correct protection for the page
   7.480       */
   7.481      if (dsi.pae_kernel) {
   7.482 -	if ( pin_table(xc_handle, MMUEXT_PIN_L3_TABLE,
   7.483 -		       ctxt->ctrlreg[3] >> PAGE_SHIFT, dom) )
   7.484 -	    goto error_out;
   7.485 +        if ( pin_table(xc_handle, MMUEXT_PIN_L3_TABLE,
   7.486 +                       ctxt->ctrlreg[3] >> PAGE_SHIFT, dom) )
   7.487 +            goto error_out;
   7.488      } else {
   7.489 -	if ( pin_table(xc_handle, MMUEXT_PIN_L2_TABLE,
   7.490 -		       ctxt->ctrlreg[3] >> PAGE_SHIFT, dom) )
   7.491 -	    goto error_out;
   7.492 +        if ( pin_table(xc_handle, MMUEXT_PIN_L2_TABLE,
   7.493 +                       ctxt->ctrlreg[3] >> PAGE_SHIFT, dom) )
   7.494 +            goto error_out;
   7.495      }
   7.496  #endif
   7.497  
   7.498 @@ -616,8 +613,8 @@ static int setup_guest(int xc_handle,
   7.499       * Pin down l4tab addr as page dir page - causes hypervisor to  provide
   7.500       * correct protection for the page
   7.501       */
   7.502 -     if ( pin_table(xc_handle, MMUEXT_PIN_L4_TABLE,
   7.503 -		    ctxt->ctrlreg[3] >> PAGE_SHIFT, dom) )
   7.504 +    if ( pin_table(xc_handle, MMUEXT_PIN_L4_TABLE,
   7.505 +                   ctxt->ctrlreg[3] >> PAGE_SHIFT, dom) )
   7.506          goto error_out;
   7.507  #endif
   7.508  
   7.509 @@ -703,12 +700,7 @@ int xc_linux_build(int xc_handle,
   7.510      unsigned long image_size, initrd_size=0;
   7.511      unsigned long vstartinfo_start, vkern_entry, vstack_start;
   7.512  
   7.513 -#ifdef __ia64__
   7.514 -    /* Current xen/ia64 allocates domU pages on demand */
   7.515 -    if ( (nr_pages = xc_get_max_pages(xc_handle, domid)) < 0 )
   7.516 -#else
   7.517 -    if ( (nr_pages = xc_get_tot_pages(xc_handle, domid)) < 0 )
   7.518 -#endif
   7.519 +    if ( (nr_pages = get_tot_pages(xc_handle, domid)) < 0 )
   7.520      {
   7.521          PERROR("Could not find total pages for domain");
   7.522          goto error_out;
   7.523 @@ -755,12 +747,7 @@ int xc_linux_build(int xc_handle,
   7.524          goto error_out;
   7.525      }
   7.526  
   7.527 -    if ( !(op.u.getdomaininfo.flags & DOMFLAGS_PAUSED) ||
   7.528 -#ifdef __ia64__
   7.529 -	0 )
   7.530 -#else
   7.531 -         (ctxt->ctrlreg[3] != 0) )
   7.532 -#endif
   7.533 +    if ( !(op.u.getdomaininfo.flags & DOMFLAGS_PAUSED) || already_built(ctxt) )
   7.534      {
   7.535          ERROR("Domain is already constructed");
   7.536          goto error_out;
   7.537 @@ -773,7 +760,7 @@ int xc_linux_build(int xc_handle,
   7.538                       op.u.getdomaininfo.shared_info_frame,
   7.539                       flags, vcpus,
   7.540                       store_evtchn, store_mfn,
   7.541 -		     console_evtchn, console_mfn) < 0 )
   7.542 +                     console_evtchn, console_mfn) < 0 )
   7.543      {
   7.544          ERROR("Error constructing guest OS");
   7.545          goto error_out;
   7.546 @@ -789,12 +776,13 @@ int xc_linux_build(int xc_handle,
   7.547      /* based on new_thread in xen/arch/ia64/domain.c */
   7.548      ctxt->flags = 0;
   7.549      ctxt->shared.flags = flags;
   7.550 -    ctxt->shared.start_info_pfn = nr_pages - 3; // metaphysical
   7.551 +    ctxt->shared.start_info_pfn = nr_pages - 3; /* metaphysical */
   7.552      ctxt->regs.cr_ipsr = 0; /* all necessary bits filled by hypervisor */
   7.553      ctxt->regs.cr_iip = vkern_entry;
   7.554      ctxt->regs.cr_ifs = 1UL << 63;
   7.555      ctxt->regs.ar_fpsr = FPSR_DEFAULT;
   7.556 -    /* ctxt->regs.r28 = dom_fw_setup(); currently done by hypervisor, should move here */
   7.557 +    /* currently done by hypervisor, should move here */
   7.558 +    /* ctxt->regs.r28 = dom_fw_setup(); */
   7.559      ctxt->vcpu.privregs = 0;
   7.560      ctxt->sys_pgnr = nr_pages - 3;
   7.561      i = 0; /* silence unused variable warning */
   7.562 @@ -875,3 +863,13 @@ int xc_linux_build(int xc_handle,
   7.563  
   7.564      return -1;
   7.565  }
   7.566 +
   7.567 +/*
   7.568 + * Local variables:
   7.569 + * mode: C
   7.570 + * c-set-style: "BSD"
   7.571 + * c-basic-offset: 4
   7.572 + * tab-width: 4
   7.573 + * indent-tabs-mode: nil
   7.574 + * End:
   7.575 + */
     8.1 --- a/tools/libxc/xc_linux_save.c	Mon Sep 19 13:24:13 2005 +0000
     8.2 +++ b/tools/libxc/xc_linux_save.c	Mon Sep 19 13:24:31 2005 +0000
     8.3 @@ -18,7 +18,6 @@
     8.4  
     8.5  #define MAX_MBIT_RATE 500
     8.6  
     8.7 -
     8.8  /*
     8.9  ** Default values for important tuning parameters. Can override by passing
    8.10  ** non-zero replacement values to xc_linux_save().  
    8.11 @@ -29,13 +28,10 @@
    8.12  #define DEF_MAX_ITERS   29   /* limit us to 30 times round loop */ 
    8.13  #define DEF_MAX_FACTOR   3   /* never send more than 3x nr_pfns */
    8.14  
    8.15 -
    8.16 -
    8.17  /* Flags to control behaviour of xc_linux_save */
    8.18  #define XCFLAGS_LIVE      1
    8.19  #define XCFLAGS_DEBUG     2
    8.20  
    8.21 -
    8.22  #define DEBUG 0
    8.23  
    8.24  #if 1
    8.25 @@ -115,8 +111,8 @@ static inline int count_bits ( int nr, v
    8.26      int i, count = 0;
    8.27      unsigned long *p = (unsigned long *)addr;
    8.28      /* We know that the array is padded to unsigned long. */
    8.29 -    for(i=0;i<nr/(sizeof(unsigned long)*8);i++,p++)
    8.30 -        count += hweight32( *p );
    8.31 +    for( i = 0; i < (nr / (sizeof(unsigned long)*8)); i++, p++ )
    8.32 +        count += hweight32(*p);
    8.33      return count;
    8.34  }
    8.35  
    8.36 @@ -201,42 +197,50 @@ ratewrite(int io_fd, void *buf, int n)
    8.37      struct timespec delay;
    8.38      long long delta;
    8.39  
    8.40 -    if (START_MBIT_RATE == 0)
    8.41 -	return write(io_fd, buf, n);
    8.42 +    if ( START_MBIT_RATE == 0 )
    8.43 +        return write(io_fd, buf, n);
    8.44      
    8.45      budget -= n;
    8.46 -    if (budget < 0) {
    8.47 -	if (MBIT_RATE != ombit_rate) {
    8.48 -	    BURST_TIME_US = RATE_TO_BTU / MBIT_RATE;
    8.49 -	    ombit_rate = MBIT_RATE;
    8.50 -	    DPRINTF("rate limit: %d mbit/s burst budget %d slot time %d\n",
    8.51 -		    MBIT_RATE, BURST_BUDGET, BURST_TIME_US);
    8.52 -	}
    8.53 -	if (last_put.tv_sec == 0) {
    8.54 -	    budget += BURST_BUDGET;
    8.55 -	    gettimeofday(&last_put, NULL);
    8.56 -	} else {
    8.57 -	    while (budget < 0) {
    8.58 -		gettimeofday(&now, NULL);
    8.59 -		delta = tv_delta(&now, &last_put);
    8.60 -		while (delta > BURST_TIME_US) {
    8.61 -		    budget += BURST_BUDGET;
    8.62 -		    last_put.tv_usec += BURST_TIME_US;
    8.63 -		    if (last_put.tv_usec > 1000000) {
    8.64 -			last_put.tv_usec -= 1000000;
    8.65 -			last_put.tv_sec++;
    8.66 -		    }
    8.67 -		    delta -= BURST_TIME_US;
    8.68 -		}
    8.69 -		if (budget > 0)
    8.70 -		    break;
    8.71 -		delay.tv_sec = 0;
    8.72 -		delay.tv_nsec = 1000 * (BURST_TIME_US - delta);
    8.73 -		while (delay.tv_nsec > 0)
    8.74 -		    if (nanosleep(&delay, &delay) == 0)
    8.75 -			break;
    8.76 -	    }
    8.77 -	}
    8.78 +    if ( budget < 0 )
    8.79 +    {
    8.80 +        if ( MBIT_RATE != ombit_rate )
    8.81 +        {
    8.82 +            BURST_TIME_US = RATE_TO_BTU / MBIT_RATE;
    8.83 +            ombit_rate = MBIT_RATE;
    8.84 +            DPRINTF("rate limit: %d mbit/s burst budget %d slot time %d\n",
    8.85 +                    MBIT_RATE, BURST_BUDGET, BURST_TIME_US);
    8.86 +        }
    8.87 +        if ( last_put.tv_sec == 0 )
    8.88 +        {
    8.89 +            budget += BURST_BUDGET;
    8.90 +            gettimeofday(&last_put, NULL);
    8.91 +        }
    8.92 +        else
    8.93 +        {
    8.94 +            while ( budget < 0 )
    8.95 +            {
    8.96 +                gettimeofday(&now, NULL);
    8.97 +                delta = tv_delta(&now, &last_put);
    8.98 +                while ( delta > BURST_TIME_US )
    8.99 +                {
   8.100 +                    budget += BURST_BUDGET;
   8.101 +                    last_put.tv_usec += BURST_TIME_US;
   8.102 +                    if ( last_put.tv_usec > 1000000 )
   8.103 +                    {
   8.104 +                        last_put.tv_usec -= 1000000;
   8.105 +                        last_put.tv_sec++;
   8.106 +                    }
   8.107 +                    delta -= BURST_TIME_US;
   8.108 +                }
   8.109 +                if ( budget > 0 )
   8.110 +                    break;
   8.111 +                delay.tv_sec = 0;
   8.112 +                delay.tv_nsec = 1000 * (BURST_TIME_US - delta);
   8.113 +                while ( delay.tv_nsec > 0 )
   8.114 +                    if ( nanosleep(&delay, &delay) == 0 )
   8.115 +                        break;
   8.116 +            }
   8.117 +        }
   8.118      }
   8.119      return write(io_fd, buf, n);
   8.120  }
   8.121 @@ -271,20 +275,21 @@ static int print_stats( int xc_handle, u
   8.122  
   8.123      if ( print )
   8.124          fprintf(stderr,
   8.125 -		"delta %lldms, dom0 %d%%, target %d%%, sent %dMb/s, "
   8.126 -		"dirtied %dMb/s %" PRId32 " pages\n",
   8.127 -		wall_delta, 
   8.128 -		(int)((d0_cpu_delta*100)/wall_delta),
   8.129 -		(int)((d1_cpu_delta*100)/wall_delta),
   8.130 -		(int)((pages_sent*PAGE_SIZE)/(wall_delta*(1000/8))),
   8.131 -		(int)((stats->dirty_count*PAGE_SIZE)/(wall_delta*(1000/8))),
   8.132 -		stats->dirty_count);
   8.133 +                "delta %lldms, dom0 %d%%, target %d%%, sent %dMb/s, "
   8.134 +                "dirtied %dMb/s %" PRId32 " pages\n",
   8.135 +                wall_delta, 
   8.136 +                (int)((d0_cpu_delta*100)/wall_delta),
   8.137 +                (int)((d1_cpu_delta*100)/wall_delta),
   8.138 +                (int)((pages_sent*PAGE_SIZE)/(wall_delta*(1000/8))),
   8.139 +                (int)((stats->dirty_count*PAGE_SIZE)/(wall_delta*(1000/8))),
   8.140 +                stats->dirty_count);
   8.141  
   8.142 -    if (((stats->dirty_count*PAGE_SIZE)/(wall_delta*(1000/8))) > mbit_rate) {
   8.143 -	mbit_rate = (int)((stats->dirty_count*PAGE_SIZE)/(wall_delta*(1000/8)))
   8.144 -	    + 50;
   8.145 -	if (mbit_rate > MAX_MBIT_RATE)
   8.146 -	    mbit_rate = MAX_MBIT_RATE;
   8.147 +    if ( ((stats->dirty_count*PAGE_SIZE)/(wall_delta*(1000/8))) > mbit_rate )
   8.148 +    {
   8.149 +        mbit_rate = (int)((stats->dirty_count*PAGE_SIZE)/(wall_delta*(1000/8)))
   8.150 +            + 50;
   8.151 +        if (mbit_rate > MAX_MBIT_RATE)
   8.152 +            mbit_rate = MAX_MBIT_RATE;
   8.153      }
   8.154  
   8.155      d0_cpu_last  = d0_cpu_now;
   8.156 @@ -303,7 +308,7 @@ static int analysis_phase( int xc_handle
   8.157  
   8.158      start = llgettimeofday();
   8.159  
   8.160 -    for (j = 0; j < runs; j++)
   8.161 +    for ( j = 0; j < runs; j++ )
   8.162      {
   8.163          int i;
   8.164  
   8.165 @@ -320,10 +325,10 @@ static int analysis_phase( int xc_handle
   8.166                                 NULL, 0, &stats);
   8.167  
   8.168              fprintf(stderr, "now= %lld faults= %" PRId32 " dirty= %" PRId32
   8.169 -		    " dirty_net= %" PRId32 " dirty_block= %" PRId32"\n", 
   8.170 -		    ((now-start)+500)/1000, 
   8.171 -		    stats.fault_count, stats.dirty_count,
   8.172 -		    stats.dirty_net_count, stats.dirty_block_count);
   8.173 +                    " dirty_net= %" PRId32 " dirty_block= %" PRId32"\n", 
   8.174 +                    ((now-start)+500)/1000, 
   8.175 +                    stats.fault_count, stats.dirty_count,
   8.176 +                    stats.dirty_net_count, stats.dirty_block_count);
   8.177          }
   8.178      }
   8.179  
   8.180 @@ -331,7 +336,7 @@ static int analysis_phase( int xc_handle
   8.181  }
   8.182  
   8.183  
   8.184 -static int suspend_and_state(int xc_handle, int io_fd,	int dom,	      
   8.185 +static int suspend_and_state(int xc_handle, int io_fd, int dom,       
   8.186                               xc_dominfo_t *info,
   8.187                               vcpu_guest_context_t *ctxt)
   8.188  {
   8.189 @@ -340,51 +345,53 @@ static int suspend_and_state(int xc_hand
   8.190  
   8.191      printf("suspend\n");
   8.192      fflush(stdout);
   8.193 -    if (fgets(ans, sizeof(ans), stdin) == NULL) {
   8.194 +    if ( fgets(ans, sizeof(ans), stdin) == NULL )
   8.195 +    {
   8.196          ERR("failed reading suspend reply");
   8.197          return -1;
   8.198      }
   8.199 -    if (strncmp(ans, "done\n", 5)) {
   8.200 +    if ( strncmp(ans, "done\n", 5) )
   8.201 +    {
   8.202          ERR("suspend reply incorrect: %s", ans);
   8.203          return -1;
   8.204      }
   8.205  
   8.206 -retry:
   8.207 + retry:
   8.208  
   8.209      if ( xc_domain_getinfo(xc_handle, dom, 1, info) != 1)
   8.210      {
   8.211 -	ERR("Could not get domain info");
   8.212 -	return -1;
   8.213 +        ERR("Could not get domain info");
   8.214 +        return -1;
   8.215      }
   8.216  
   8.217      if ( xc_domain_get_vcpu_context(xc_handle, dom, 0 /* XXX */, 
   8.218 -				    ctxt) )
   8.219 +                                    ctxt) )
   8.220      {
   8.221          ERR("Could not get vcpu context");
   8.222      }
   8.223  
   8.224      if ( info->shutdown && info->shutdown_reason == SHUTDOWN_suspend )
   8.225      {
   8.226 -	return 0; // success
   8.227 +        return 0; // success
   8.228      }
   8.229  
   8.230      if ( info->paused )
   8.231      {
   8.232 -	// try unpausing domain, wait, and retest	
   8.233 -	xc_domain_unpause( xc_handle, dom );
   8.234 +        // try unpausing domain, wait, and retest 
   8.235 +        xc_domain_unpause( xc_handle, dom );
   8.236  
   8.237 -	ERR("Domain was paused. Wait and re-test.");
   8.238 -	usleep(10000);  // 10ms
   8.239 +        ERR("Domain was paused. Wait and re-test.");
   8.240 +        usleep(10000);  // 10ms
   8.241  
   8.242 -	goto retry;
   8.243 +        goto retry;
   8.244      }
   8.245  
   8.246  
   8.247      if( ++i < 100 )
   8.248      {
   8.249 -	ERR("Retry suspend domain.");
   8.250 -	usleep(10000);  // 10ms	
   8.251 -	goto retry;
   8.252 +        ERR("Retry suspend domain.");
   8.253 +        usleep(10000);  // 10ms 
   8.254 +        goto retry;
   8.255      }
   8.256  
   8.257      ERR("Unable to suspend domain.");
   8.258 @@ -454,26 +461,26 @@ int xc_linux_save(int xc_handle, int io_
   8.259  
   8.260  
   8.261      /* If no explicit control parameters given, use defaults */
   8.262 -    if(!max_iters) 
   8.263 +    if( !max_iters ) 
   8.264          max_iters = DEF_MAX_ITERS; 
   8.265 -    if(!max_factor) 
   8.266 +    if( !max_factor ) 
   8.267          max_factor = DEF_MAX_FACTOR; 
   8.268  
   8.269  
   8.270      DPRINTF("xc_linux_save start DOM%u live=%s\n", dom, live?"true":"false"); 
   8.271  
   8.272 -    if (mlock(&ctxt, sizeof(ctxt))) {
   8.273 +    if ( mlock(&ctxt, sizeof(ctxt)) ) 
   8.274 +    {
   8.275          ERR("Unable to mlock ctxt");
   8.276          return 1;
   8.277      }
   8.278      
   8.279 -    if ( xc_domain_getinfo(xc_handle, dom, 1, &info) != 1)
   8.280 +    if ( xc_domain_getinfo(xc_handle, dom, 1, &info) != 1 )
   8.281      {
   8.282          ERR("Could not get domain info");
   8.283          goto out;
   8.284      }
   8.285 -    if ( xc_domain_get_vcpu_context( xc_handle, dom, /* FIXME */ 0, 
   8.286 -                                &ctxt) )
   8.287 +    if ( xc_domain_get_vcpu_context(xc_handle, dom, /* FIXME */ 0, &ctxt) )
   8.288      {
   8.289          ERR("Could not get vcpu context");
   8.290          goto out;
   8.291 @@ -481,7 +488,8 @@ int xc_linux_save(int xc_handle, int io_
   8.292      shared_info_frame = info.shared_info_frame;
   8.293  
   8.294      /* A cheesy test to see whether the domain contains valid state. */
   8.295 -    if ( ctxt.ctrlreg[3] == 0 ){
   8.296 +    if ( ctxt.ctrlreg[3] == 0 )
   8.297 +    {
   8.298          ERR("Domain is not in a valid Linux guest OS state");
   8.299          goto out;
   8.300      }
   8.301 @@ -496,18 +504,17 @@ int xc_linux_save(int xc_handle, int io_
   8.302      }
   8.303  
   8.304      /* Map the shared info frame */
   8.305 -    live_shinfo = xc_map_foreign_range(xc_handle, dom,
   8.306 -                                        PAGE_SIZE, PROT_READ,
   8.307 -                                        shared_info_frame);
   8.308 -
   8.309 -    if (!live_shinfo){
   8.310 +    live_shinfo = xc_map_foreign_range(
   8.311 +        xc_handle, dom, PAGE_SIZE, PROT_READ, shared_info_frame);
   8.312 +    if ( !live_shinfo )
   8.313 +    {
   8.314          ERR("Couldn't map live_shinfo");
   8.315          goto out;
   8.316      }
   8.317  
   8.318 -    live_pfn_to_mfn_frame_list_list = xc_map_foreign_range(xc_handle, dom,
   8.319 -                                        PAGE_SIZE, PROT_READ,
   8.320 -                                        live_shinfo->arch.pfn_to_mfn_frame_list_list);
   8.321 +    live_pfn_to_mfn_frame_list_list = xc_map_foreign_range(
   8.322 +        xc_handle, dom,
   8.323 +        PAGE_SIZE, PROT_READ, live_shinfo->arch.pfn_to_mfn_frame_list_list);
   8.324  
   8.325      if (!live_pfn_to_mfn_frame_list_list){
   8.326          ERR("Couldn't map pfn_to_mfn_frame_list_list");
   8.327 @@ -515,12 +522,13 @@ int xc_linux_save(int xc_handle, int io_
   8.328      }
   8.329  
   8.330      live_pfn_to_mfn_frame_list = 
   8.331 -	xc_map_foreign_batch(xc_handle, dom, 
   8.332 -			     PROT_READ,
   8.333 -			     live_pfn_to_mfn_frame_list_list,
   8.334 -			     (nr_pfns+(1024*1024)-1)/(1024*1024) );
   8.335 +        xc_map_foreign_batch(xc_handle, dom, 
   8.336 +                             PROT_READ,
   8.337 +                             live_pfn_to_mfn_frame_list_list,
   8.338 +                             (nr_pfns+(1024*1024)-1)/(1024*1024) );
   8.339  
   8.340 -    if (!live_pfn_to_mfn_frame_list){
   8.341 +    if ( !live_pfn_to_mfn_frame_list)
   8.342 +    {
   8.343          ERR("Couldn't map pfn_to_mfn_frame_list");
   8.344          goto out;
   8.345      }
   8.346 @@ -535,7 +543,8 @@ int xc_linux_save(int xc_handle, int io_
   8.347                                                   PROT_READ,
   8.348                                                   live_pfn_to_mfn_frame_list,
   8.349                                                   (nr_pfns+1023)/1024 );  
   8.350 -    if( !live_pfn_to_mfn_table ){
   8.351 +    if ( !live_pfn_to_mfn_table )
   8.352 +    {
   8.353          ERR("Couldn't map pfn_to_mfn table");
   8.354          goto out;
   8.355      }
   8.356 @@ -544,15 +553,17 @@ int xc_linux_save(int xc_handle, int io_
   8.357      mfn_to_pfn_table_start_mfn = xc_get_m2p_start_mfn( xc_handle );
   8.358  
   8.359      live_mfn_to_pfn_table = 
   8.360 -	xc_map_foreign_range(xc_handle, DOMID_XEN, 
   8.361 -			      PAGE_SIZE*1024, PROT_READ, 
   8.362 -			      mfn_to_pfn_table_start_mfn );
   8.363 +        xc_map_foreign_range(xc_handle, DOMID_XEN, 
   8.364 +                             PAGE_SIZE*1024, PROT_READ, 
   8.365 +                             mfn_to_pfn_table_start_mfn );
   8.366  
   8.367      /* Canonicalise the pfn-to-mfn table frame-number list. */
   8.368      memcpy( pfn_to_mfn_frame_list, live_pfn_to_mfn_frame_list, PAGE_SIZE );
   8.369  
   8.370 -    for ( i = 0; i < nr_pfns; i += 1024 ){
   8.371 -        if ( !translate_mfn_to_pfn(&pfn_to_mfn_frame_list[i/1024]) ){
   8.372 +    for ( i = 0; i < nr_pfns; i += 1024 )
   8.373 +    {
   8.374 +        if ( !translate_mfn_to_pfn(&pfn_to_mfn_frame_list[i/1024]) )
   8.375 +        {
   8.376              ERR("Frame# in pfn-to-mfn frame list is not in pseudophys");
   8.377              goto out;
   8.378          }
   8.379 @@ -561,40 +572,44 @@ int xc_linux_save(int xc_handle, int io_
   8.380  
   8.381      /* Domain is still running at this point */
   8.382  
   8.383 -    if( live )
   8.384 +    if ( live )
   8.385      {
   8.386          if ( xc_shadow_control( xc_handle, dom, 
   8.387                                  DOM0_SHADOW_CONTROL_OP_ENABLE_LOGDIRTY,
   8.388 -                                NULL, 0, NULL ) < 0 ) {
   8.389 +                                NULL, 0, NULL ) < 0 )
   8.390 +        {
   8.391              ERR("Couldn't enable shadow mode");
   8.392              goto out;
   8.393          }
   8.394  
   8.395          last_iter = 0;
   8.396 -    } else{
   8.397 -	/* This is a non-live suspend. Issue the call back to get the
   8.398 -	 domain suspended */
   8.399 +    } 
   8.400 +    else
   8.401 +    {
   8.402 +        /* This is a non-live suspend. Issue the call back to get the
   8.403 +           domain suspended */
   8.404  
   8.405          last_iter = 1;
   8.406  
   8.407 -	if ( suspend_and_state( xc_handle, io_fd, dom, &info, &ctxt) )
   8.408 -	{
   8.409 -	    ERR("Domain appears not to have suspended");
   8.410 -	    goto out;
   8.411 -	}
   8.412 +        if ( suspend_and_state( xc_handle, io_fd, dom, &info, &ctxt) )
   8.413 +        {
   8.414 +            ERR("Domain appears not to have suspended");
   8.415 +            goto out;
   8.416 +        }
   8.417  
   8.418      }
   8.419      sent_last_iter = 1<<20; /* 4GB of pages */
   8.420  
   8.421      /* calculate the power of 2 order of nr_pfns, e.g.
   8.422         15->4 16->4 17->5 */
   8.423 -    for( i=nr_pfns-1, order_nr=0; i ; i>>=1, order_nr++ );
   8.424 +    for ( i = nr_pfns-1, order_nr = 0; i ; i >>= 1, order_nr++ )
   8.425 +        continue;
   8.426  
   8.427      /* Setup to_send bitmap */
   8.428      {
   8.429 -	/* size these for a maximal 4GB domain, to make interaction
   8.430 -	   with balloon driver easier. It's only user space memory,
   8.431 -	   ater all... (3x 128KB) */
   8.432 +        /* size these for a maximal 4GB domain, to make interaction
   8.433 +           with balloon driver easier. It's only user space memory,
   8.434 +           ater all... (3x 128KB) */
   8.435  
   8.436          int sz = ( 1<<20 ) / 8;
   8.437   
   8.438 @@ -602,21 +617,24 @@ int xc_linux_save(int xc_handle, int io_
   8.439          to_fix  = calloc( 1, sz );
   8.440          to_skip = malloc( sz );
   8.441  
   8.442 -        if (!to_send || !to_fix || !to_skip){
   8.443 +        if ( !to_send || !to_fix || !to_skip )
   8.444 +        {
   8.445              ERR("Couldn't allocate to_send array");
   8.446              goto out;
   8.447          }
   8.448  
   8.449 -        memset( to_send, 0xff, sz );
   8.450 +        memset(to_send, 0xff, sz);
   8.451  
   8.452 -        if ( mlock( to_send, sz ) ){
   8.453 +        if ( mlock(to_send, sz) )
   8.454 +        {
   8.455              ERR("Unable to mlock to_send");
   8.456              return 1;
   8.457          }
   8.458  
   8.459          /* (to fix is local only) */
   8.460  
   8.461 -        if ( mlock( to_skip, sz ) ){
   8.462 +        if ( mlock(to_skip, sz) )
   8.463 +        {
   8.464              ERR("Unable to mlock to_skip");
   8.465              return 1;
   8.466          }
   8.467 @@ -629,12 +647,14 @@ int xc_linux_save(int xc_handle, int io_
   8.468      pfn_type = calloc(BATCH_SIZE, sizeof(unsigned long));
   8.469      pfn_batch = calloc(BATCH_SIZE, sizeof(unsigned long));
   8.470  
   8.471 -    if ( (pfn_type == NULL) || (pfn_batch == NULL) ){
   8.472 +    if ( (pfn_type == NULL) || (pfn_batch == NULL) )
   8.473 +    {
   8.474          errno = ENOMEM;
   8.475          goto out;
   8.476      }
   8.477  
   8.478 -    if ( mlock( pfn_type, BATCH_SIZE * sizeof(unsigned long) ) ){
   8.479 +    if ( mlock(pfn_type, BATCH_SIZE * sizeof(unsigned long)) )
   8.480 +    {
   8.481          ERR("Unable to mlock");
   8.482          goto out;
   8.483      }
   8.484 @@ -645,31 +665,34 @@ int xc_linux_save(int xc_handle, int io_
   8.485       */
   8.486  #if DEBUG
   8.487      {
   8.488 -	int err=0;
   8.489 -	for ( i = 0; i < nr_pfns; i++ )
   8.490 -	{
   8.491 -	    mfn = live_pfn_to_mfn_table[i];
   8.492 -	    
   8.493 -	    if( (live_mfn_to_pfn_table[mfn] != i) && (mfn != 0xffffffffUL) )
   8.494 -	    {
   8.495 -		fprintf(stderr, "i=0x%x mfn=%lx live_mfn_to_pfn_table=%lx\n",
   8.496 -			i,mfn,live_mfn_to_pfn_table[mfn]);
   8.497 -		err++;
   8.498 -	    }
   8.499 -	}
   8.500 -	fprintf(stderr, "Had %d unexplained entries in p2m table\n",err);
   8.501 +        int err=0;
   8.502 +        for ( i = 0; i < nr_pfns; i++ )
   8.503 +        {
   8.504 +            mfn = live_pfn_to_mfn_table[i];
   8.505 +     
   8.506 +            if( (live_mfn_to_pfn_table[mfn] != i) && (mfn != 0xffffffffUL) )
   8.507 +            {
   8.508 +                fprintf(stderr, "i=0x%x mfn=%lx live_mfn_to_pfn_table=%lx\n",
   8.509 +                        i,mfn,live_mfn_to_pfn_table[mfn]);
   8.510 +                err++;
   8.511 +            }
   8.512 +        }
   8.513 +        fprintf(stderr, "Had %d unexplained entries in p2m table\n",err);
   8.514      }
   8.515  #endif
   8.516  
   8.517  
   8.518      /* Start writing out the saved-domain record. */
   8.519  
   8.520 -    if (write(io_fd, &nr_pfns, sizeof(unsigned long)) !=
   8.521 -	sizeof(unsigned long)) {
   8.522 -	ERR("write: nr_pfns");
   8.523 -	goto out;
   8.524 +    if ( write(io_fd, &nr_pfns, sizeof(unsigned long)) !=
   8.525 +         sizeof(unsigned long) )
   8.526 +    {
   8.527 +        ERR("write: nr_pfns");
   8.528 +        goto out;
   8.529      }
   8.530 -    if (write(io_fd, pfn_to_mfn_frame_list, PAGE_SIZE) != PAGE_SIZE) {
   8.531 +
   8.532 +    if ( write(io_fd, pfn_to_mfn_frame_list, PAGE_SIZE) != PAGE_SIZE )
   8.533 +    {
   8.534          ERR("write: pfn_to_mfn_frame_list");
   8.535          goto out;
   8.536      }
   8.537 @@ -678,7 +701,8 @@ int xc_linux_save(int xc_handle, int io_
   8.538  
   8.539      /* Now write out each data page, canonicalising page tables as we go... */
   8.540      
   8.541 -    while(1){
   8.542 +    for ( ; ; )
   8.543 +    {
   8.544          unsigned int prev_pc, sent_this_iter, N, batch;
   8.545  
   8.546          iter++;
   8.547 @@ -689,10 +713,12 @@ int xc_linux_save(int xc_handle, int io_
   8.548  
   8.549          DPRINTF("Saving memory pages: iter %d   0%%", iter);
   8.550  
   8.551 -        while( N < nr_pfns ){
   8.552 +        while ( N < nr_pfns )
   8.553 +        {
   8.554              unsigned int this_pc = (N * 100) / nr_pfns;
   8.555  
   8.556 -            if ( (this_pc - prev_pc) >= 5 ){
   8.557 +            if ( (this_pc - prev_pc) >= 5 )
   8.558 +            {
   8.559                  DPRINTF("\b\b\b\b%3d%%", this_pc);
   8.560                  prev_pc = this_pc;
   8.561              }
   8.562 @@ -701,10 +727,10 @@ int xc_linux_save(int xc_handle, int io_
   8.563                 but this is fast enough for the moment. */
   8.564  
   8.565              if ( !last_iter && 
   8.566 -		 xc_shadow_control(xc_handle, dom, 
   8.567 +                 xc_shadow_control(xc_handle, dom, 
   8.568                                     DOM0_SHADOW_CONTROL_OP_PEEK,
   8.569                                     to_skip, nr_pfns, NULL) != nr_pfns )
   8.570 -	    {
   8.571 +            {
   8.572                  ERR("Error peeking shadow bitmap");
   8.573                  goto out;
   8.574              }
   8.575 @@ -748,7 +774,7 @@ int xc_linux_save(int xc_handle, int io_
   8.576                  pfn_type[batch] = live_pfn_to_mfn_table[n];
   8.577  
   8.578                  if( ! is_mapped(pfn_type[batch]) )
   8.579 -		{
   8.580 +                {
   8.581                      /* not currently in pusedo-physical map -- set bit
   8.582                         in to_fix that we must send this page in last_iter
   8.583                         unless its sent sooner anyhow */
   8.584 @@ -756,7 +782,7 @@ int xc_linux_save(int xc_handle, int io_
   8.585                      set_bit( n, to_fix );
   8.586                      if( iter>1 )
   8.587                          DPRINTF("netbuf race: iter %d, pfn %x. mfn %lx\n",
   8.588 -				iter,n,pfn_type[batch]);
   8.589 +                                iter,n,pfn_type[batch]);
   8.590                      continue;
   8.591                  }
   8.592  
   8.593 @@ -790,8 +816,10 @@ int xc_linux_save(int xc_handle, int io_
   8.594                  goto out;
   8.595              }
   8.596       
   8.597 -            for ( j = 0; j < batch; j++ ){
   8.598 -                if ( (pfn_type[j] & LTAB_MASK) == XTAB ){
   8.599 +            for ( j = 0; j < batch; j++ )
   8.600 +            {
   8.601 +                if ( (pfn_type[j] & LTAB_MASK) == XTAB )
   8.602 +                {
   8.603                      DPRINTF("type fail: page %i mfn %08lx\n",j,pfn_type[j]);
   8.604                      continue;
   8.605                  }
   8.606 @@ -809,21 +837,25 @@ int xc_linux_save(int xc_handle, int io_
   8.607                  pfn_type[j] = (pfn_type[j] & LTAB_MASK) | pfn_batch[j];
   8.608              }
   8.609  
   8.610 -            if (write(io_fd, &batch, sizeof(int)) != sizeof(int)) {
   8.611 +            if ( write(io_fd, &batch, sizeof(int)) != sizeof(int) )
   8.612 +            {
   8.613                  ERR("Error when writing to state file (2)");
   8.614                  goto out;
   8.615              }
   8.616  
   8.617 -            if (write(io_fd, pfn_type, sizeof(unsigned long)*j) !=
   8.618 -		sizeof(unsigned long)*j) {
   8.619 +            if ( write(io_fd, pfn_type, sizeof(unsigned long)*j) !=
   8.620 +                 (sizeof(unsigned long) * j) )
   8.621 +            {
   8.622                  ERR("Error when writing to state file (3)");
   8.623                  goto out;
   8.624              }
   8.625       
   8.626              /* entering this loop, pfn_type is now in pfns (Not mfns) */
   8.627 -            for( j = 0; j < batch; j++ ){
   8.628 +            for ( j = 0; j < batch; j++ )
   8.629 +            {
   8.630                  /* write out pages in batch */
   8.631 -                if( (pfn_type[j] & LTAB_MASK) == XTAB){
   8.632 +                if ( (pfn_type[j] & LTAB_MASK) == XTAB )
   8.633 +                {
   8.634                      DPRINTF("SKIP BOGUS page %i mfn %08lx\n",j,pfn_type[j]);
   8.635                      continue;
   8.636                  }
   8.637 @@ -836,7 +868,8 @@ int xc_linux_save(int xc_handle, int io_
   8.638                            k < (((pfn_type[j] & LTABTYPE_MASK) == L2TAB) ? 
   8.639                                 (HYPERVISOR_VIRT_START >> L2_PAGETABLE_SHIFT) :
   8.640                                 1024); 
   8.641 -                          k++ ){
   8.642 +                          k++ )
   8.643 +                    {
   8.644                          unsigned long pfn;
   8.645  
   8.646                          if ( !(page[k] & _PAGE_PRESENT) )
   8.647 @@ -849,13 +882,13 @@ int xc_linux_save(int xc_handle, int io_
   8.648                          {
   8.649                              /* I don't think this should ever happen */
   8.650                              fprintf(stderr, "FNI %d : [%08lx,%d] pte=%08lx, "
   8.651 -				    "mfn=%08lx, pfn=%08lx [mfn]=%08lx\n",
   8.652 -				    j, pfn_type[j], k,
   8.653 -				    page[k], mfn, live_mfn_to_pfn_table[mfn],
   8.654 -				    (live_mfn_to_pfn_table[mfn]<nr_pfns)? 
   8.655 -				    live_pfn_to_mfn_table[
   8.656 -					live_mfn_to_pfn_table[mfn]] : 
   8.657 -				    0xdeadbeef);
   8.658 +                                    "mfn=%08lx, pfn=%08lx [mfn]=%08lx\n",
   8.659 +                                    j, pfn_type[j], k,
   8.660 +                                    page[k], mfn, live_mfn_to_pfn_table[mfn],
   8.661 +                                    (live_mfn_to_pfn_table[mfn]<nr_pfns)? 
   8.662 +                                    live_pfn_to_mfn_table[
   8.663 +                                        live_mfn_to_pfn_table[mfn]] : 
   8.664 +                                    0xdeadbeef);
   8.665  
   8.666                              pfn = 0; /* be suspicious */
   8.667                          }
   8.668 @@ -865,12 +898,12 @@ int xc_linux_save(int xc_handle, int io_
   8.669     
   8.670  #if 0
   8.671                          fprintf(stderr,
   8.672 -				"L%d i=%d pfn=%d mfn=%d k=%d pte=%08lx "
   8.673 -				"xpfn=%d\n",
   8.674 -				pfn_type[j]>>28,
   8.675 -				j,i,mfn,k,page[k],page[k]>>PAGE_SHIFT);
   8.676 +                                "L%d i=%d pfn=%d mfn=%d k=%d pte=%08lx "
   8.677 +                                "xpfn=%d\n",
   8.678 +                                pfn_type[j]>>28,
   8.679 +                                j,i,mfn,k,page[k],page[k]>>PAGE_SHIFT);
   8.680  #endif     
   8.681 -			
   8.682 +   
   8.683                      } /* end of page table rewrite for loop */
   8.684        
   8.685                      if (ratewrite(io_fd, page, PAGE_SIZE) != PAGE_SIZE) {
   8.686 @@ -880,8 +913,9 @@ int xc_linux_save(int xc_handle, int io_
   8.687        
   8.688                  }  /* end of it's a PT page */ else {  /* normal page */
   8.689  
   8.690 -                    if (ratewrite(io_fd, region_base + (PAGE_SIZE*j), 
   8.691 -				  PAGE_SIZE) != PAGE_SIZE) {
   8.692 +                    if ( ratewrite(io_fd, region_base + (PAGE_SIZE*j), 
   8.693 +                                   PAGE_SIZE) != PAGE_SIZE )
   8.694 +                    {
   8.695                          ERR("Error when writing to state file (5)");
   8.696                          goto out;
   8.697                      }
   8.698 @@ -899,13 +933,13 @@ int xc_linux_save(int xc_handle, int io_
   8.699          total_sent += sent_this_iter;
   8.700  
   8.701          DPRINTF("\r %d: sent %d, skipped %d, ", 
   8.702 -                       iter, sent_this_iter, skip_this_iter );
   8.703 +                iter, sent_this_iter, skip_this_iter );
   8.704  
   8.705          if ( last_iter ) {
   8.706              print_stats( xc_handle, dom, sent_this_iter, &stats, 1);
   8.707  
   8.708              DPRINTF("Total pages sent= %d (%.2fx)\n", 
   8.709 -                           total_sent, ((float)total_sent)/nr_pfns );
   8.710 +                    total_sent, ((float)total_sent)/nr_pfns );
   8.711              DPRINTF("(of which %d were fixups)\n", needed_to_fix  );
   8.712          }       
   8.713  
   8.714 @@ -930,7 +964,7 @@ int xc_linux_save(int xc_handle, int io_
   8.715          {
   8.716              if ( 
   8.717                  ( ( sent_this_iter > sent_last_iter ) &&
   8.718 -		  (mbit_rate == MAX_MBIT_RATE ) ) ||
   8.719 +                  (mbit_rate == MAX_MBIT_RATE ) ) ||
   8.720                  (iter >= max_iters) || 
   8.721                  (sent_this_iter+skip_this_iter < 50) || 
   8.722                  (total_sent > nr_pfns*max_factor) )
   8.723 @@ -938,15 +972,15 @@ int xc_linux_save(int xc_handle, int io_
   8.724                  DPRINTF("Start last iteration\n");
   8.725                  last_iter = 1;
   8.726  
   8.727 -		if ( suspend_and_state( xc_handle, io_fd, dom, &info, &ctxt) )
   8.728 -		{
   8.729 -		    ERR("Domain appears not to have suspended");
   8.730 -		    goto out;
   8.731 -		}
   8.732 +                if ( suspend_and_state( xc_handle, io_fd, dom, &info, &ctxt) )
   8.733 +                {
   8.734 +                    ERR("Domain appears not to have suspended");
   8.735 +                    goto out;
   8.736 +                }
   8.737  
   8.738 -		DPRINTF("SUSPEND shinfo %08lx eip %08u esi %08u\n",
   8.739 -			info.shared_info_frame,
   8.740 -			ctxt.user_regs.eip, ctxt.user_regs.esi);
   8.741 +                DPRINTF("SUSPEND shinfo %08lx eip %08u esi %08u\n",
   8.742 +                        info.shared_info_frame,
   8.743 +                        ctxt.user_regs.eip, ctxt.user_regs.esi);
   8.744              } 
   8.745  
   8.746              if ( xc_shadow_control( xc_handle, dom, 
   8.747 @@ -972,86 +1006,92 @@ int xc_linux_save(int xc_handle, int io_
   8.748      rc = 0;
   8.749      
   8.750      /* Zero terminate */
   8.751 -    if (write(io_fd, &rc, sizeof(int)) != sizeof(int)) {
   8.752 +    if ( write(io_fd, &rc, sizeof(int)) != sizeof(int) )
   8.753 +    {
   8.754          ERR("Error when writing to state file (6)");
   8.755          goto out;
   8.756      }
   8.757  
   8.758      /* Send through a list of all the PFNs that were not in map at the close */
   8.759      {
   8.760 -	unsigned int i,j;
   8.761 -	unsigned int pfntab[1024];
   8.762 +        unsigned int i,j;
   8.763 +        unsigned int pfntab[1024];
   8.764  
   8.765 -	for ( i = 0, j = 0; i < nr_pfns; i++ )
   8.766 -	{
   8.767 -	    if ( ! is_mapped(live_pfn_to_mfn_table[i]) )
   8.768 -		j++;
   8.769 -	}
   8.770 +        for ( i = 0, j = 0; i < nr_pfns; i++ )
   8.771 +            if ( !is_mapped(live_pfn_to_mfn_table[i]) )
   8.772 +                j++;
   8.773  
   8.774 -	if (write(io_fd, &j, sizeof(unsigned int)) != sizeof(unsigned int)) {
   8.775 -	    ERR("Error when writing to state file (6a)");
   8.776 -	    goto out;
   8.777 -	}	
   8.778 +        if ( write(io_fd, &j, sizeof(unsigned int)) != sizeof(unsigned int) )
   8.779 +        {
   8.780 +            ERR("Error when writing to state file (6a)");
   8.781 +            goto out;
   8.782 +        } 
   8.783  
   8.784 -	for ( i = 0, j = 0; i < nr_pfns; )
   8.785 -	{
   8.786 -	    if ( ! is_mapped(live_pfn_to_mfn_table[i]) )
   8.787 -	    {
   8.788 -		pfntab[j++] = i;
   8.789 -	    }
   8.790 -	    i++;
   8.791 -	    if ( j == 1024 || i == nr_pfns )
   8.792 -	    {
   8.793 -		if (write(io_fd, &pfntab, sizeof(unsigned long)*j) !=
   8.794 -		    sizeof(unsigned long)*j) {
   8.795 -		    ERR("Error when writing to state file (6b)");
   8.796 -		    goto out;
   8.797 -		}	
   8.798 -		j = 0;
   8.799 -	    }
   8.800 -	}
   8.801 +        for ( i = 0, j = 0; i < nr_pfns; )
   8.802 +        {
   8.803 +            if ( !is_mapped(live_pfn_to_mfn_table[i]) )
   8.804 +            {
   8.805 +                pfntab[j++] = i;
   8.806 +            }
   8.807 +            i++;
   8.808 +            if ( j == 1024 || i == nr_pfns )
   8.809 +            {
   8.810 +                if ( write(io_fd, &pfntab, sizeof(unsigned long)*j) !=
   8.811 +                     (sizeof(unsigned long) * j) )
   8.812 +                {
   8.813 +                    ERR("Error when writing to state file (6b)");
   8.814 +                    goto out;
   8.815 +                } 
   8.816 +                j = 0;
   8.817 +            }
   8.818 +        }
   8.819      }
   8.820  
   8.821      /* Canonicalise the suspend-record frame number. */
   8.822 -    if ( !translate_mfn_to_pfn(&ctxt.user_regs.esi) ){
   8.823 +    if ( !translate_mfn_to_pfn(&ctxt.user_regs.esi) )
   8.824 +    {
   8.825          ERR("Suspend record is not in range of pseudophys map");
   8.826          goto out;
   8.827      }
   8.828  
   8.829      /* Canonicalise each GDT frame number. */
   8.830 -    for ( i = 0; i < ctxt.gdt_ents; i += 512 ) {
   8.831 -        if ( !translate_mfn_to_pfn(&ctxt.gdt_frames[i]) ) {
   8.832 +    for ( i = 0; i < ctxt.gdt_ents; i += 512 )
   8.833 +    {
   8.834 +        if ( !translate_mfn_to_pfn(&ctxt.gdt_frames[i]) ) 
   8.835 +        {
   8.836              ERR("GDT frame is not in range of pseudophys map");
   8.837              goto out;
   8.838          }
   8.839      }
   8.840  
   8.841      /* Canonicalise the page table base pointer. */
   8.842 -    if ( !MFN_IS_IN_PSEUDOPHYS_MAP(ctxt.ctrlreg[3] >> PAGE_SHIFT) ) {
   8.843 +    if ( !MFN_IS_IN_PSEUDOPHYS_MAP(ctxt.ctrlreg[3] >> PAGE_SHIFT) )
   8.844 +    {
   8.845          ERR("PT base is not in range of pseudophys map");
   8.846          goto out;
   8.847      }
   8.848      ctxt.ctrlreg[3] = live_mfn_to_pfn_table[ctxt.ctrlreg[3] >> PAGE_SHIFT] <<
   8.849          PAGE_SHIFT;
   8.850  
   8.851 -    if (write(io_fd, &ctxt, sizeof(ctxt)) != sizeof(ctxt) ||
   8.852 -	write(io_fd, live_shinfo, PAGE_SIZE) != PAGE_SIZE) {
   8.853 +    if ( write(io_fd, &ctxt, sizeof(ctxt)) != sizeof(ctxt) ||
   8.854 +         write(io_fd, live_shinfo, PAGE_SIZE) != PAGE_SIZE)
   8.855 +    {
   8.856          ERR("Error when writing to state file (1)");
   8.857          goto out;
   8.858      }
   8.859  
   8.860   out:
   8.861  
   8.862 -    if(live_shinfo)
   8.863 +    if ( live_shinfo )
   8.864          munmap(live_shinfo, PAGE_SIZE);
   8.865  
   8.866 -    if(live_pfn_to_mfn_frame_list) 
   8.867 +    if ( live_pfn_to_mfn_frame_list ) 
   8.868          munmap(live_pfn_to_mfn_frame_list, PAGE_SIZE);
   8.869  
   8.870 -    if(live_pfn_to_mfn_table) 
   8.871 +    if ( live_pfn_to_mfn_table ) 
   8.872          munmap(live_pfn_to_mfn_table, nr_pfns*4);
   8.873  
   8.874 -    if(live_mfn_to_pfn_table) 
   8.875 +    if ( live_mfn_to_pfn_table ) 
   8.876          munmap(live_mfn_to_pfn_table, PAGE_SIZE*1024);
   8.877  
   8.878      free(pfn_type);
   8.879 @@ -1063,3 +1103,13 @@ int xc_linux_save(int xc_handle, int io_
   8.880      DPRINTF("Save exit rc=%d\n",rc);
   8.881      return !!rc;
   8.882  }
   8.883 +
   8.884 +/*
   8.885 + * Local variables:
   8.886 + * mode: C
   8.887 + * c-set-style: "BSD"
   8.888 + * c-basic-offset: 4
   8.889 + * tab-width: 4
   8.890 + * indent-tabs-mode: nil
   8.891 + * End:
   8.892 + */
     9.1 --- a/tools/libxc/xc_load_aout9.c	Mon Sep 19 13:24:13 2005 +0000
     9.2 +++ b/tools/libxc/xc_load_aout9.c	Mon Sep 19 13:24:31 2005 +0000
     9.3 @@ -64,11 +64,11 @@ parseaout9image(
     9.4      dstart = round_pgup(start + ehdr.text);
     9.5      end = dstart + ehdr.data + ehdr.bss;
     9.6  
     9.7 -    dsi->v_start	= KZERO;
     9.8 -    dsi->v_kernstart	= start;
     9.9 -    dsi->v_kernend	= end;
    9.10 -    dsi->v_kernentry	= ehdr.entry;
    9.11 -    dsi->v_end		= end;
    9.12 +    dsi->v_start     = KZERO;
    9.13 +    dsi->v_kernstart = start;
    9.14 +    dsi->v_kernend   = end;
    9.15 +    dsi->v_kernentry = ehdr.entry;
    9.16 +    dsi->v_end       = end;
    9.17  
    9.18      /* XXX load symbols */
    9.19  
    9.20 @@ -168,3 +168,12 @@ get_header(
    9.21      return ehdr;
    9.22  }
    9.23  
    9.24 +/*
    9.25 + * Local variables:
    9.26 + * mode: C
    9.27 + * c-set-style: "BSD"
    9.28 + * c-basic-offset: 4
    9.29 + * tab-width: 4
    9.30 + * indent-tabs-mode: nil
    9.31 + * End:
    9.32 + */
    10.1 --- a/tools/libxc/xc_load_bin.c	Mon Sep 19 13:24:13 2005 +0000
    10.2 +++ b/tools/libxc/xc_load_bin.c	Mon Sep 19 13:24:31 2005 +0000
    10.3 @@ -109,8 +109,8 @@ loadbinimage(
    10.4      unsigned long *parray, struct domain_setup_info *dsi);
    10.5  
    10.6  int probe_bin(char *image,
    10.7 -	      unsigned long image_size,
    10.8 -	      struct load_funcs *load_funcs)
    10.9 +              unsigned long image_size,
   10.10 +              struct load_funcs *load_funcs)
   10.11  {
   10.12      if ( NULL == findtable(image, image_size) )
   10.13      {
   10.14 @@ -297,3 +297,13 @@ loadbinimage(
   10.15  
   10.16      return 0;
   10.17  }
   10.18 +
   10.19 +/*
   10.20 + * Local variables:
   10.21 + * mode: C
   10.22 + * c-set-style: "BSD"
   10.23 + * c-basic-offset: 4
   10.24 + * tab-width: 4
   10.25 + * indent-tabs-mode: nil
   10.26 + * End:
   10.27 + */
    11.1 --- a/tools/libxc/xc_load_elf.c	Mon Sep 19 13:24:13 2005 +0000
    11.2 +++ b/tools/libxc/xc_load_elf.c	Mon Sep 19 13:24:31 2005 +0000
    11.3 @@ -30,8 +30,8 @@ loadelfsymtab(
    11.4      struct domain_setup_info *dsi);
    11.5  
    11.6  int probe_elf(char *image,
    11.7 -	      unsigned long image_size,
    11.8 -	      struct load_funcs *load_funcs)
    11.9 +              unsigned long image_size,
   11.10 +              struct load_funcs *load_funcs)
   11.11  {
   11.12      Elf_Ehdr *ehdr = (Elf_Ehdr *)image;
   11.13  
   11.14 @@ -116,7 +116,7 @@ static int parseelfimage(char *image,
   11.15              return -EINVAL;
   11.16          }
   11.17          if ( (strstr(guestinfo, "PAE=yes") != NULL) )
   11.18 -	    dsi->pae_kernel = 1;
   11.19 +            dsi->pae_kernel = 1;
   11.20  
   11.21          break;
   11.22      }
   11.23 @@ -313,3 +313,13 @@ loadelfsymtab(
   11.24  
   11.25      return 0;
   11.26  }
   11.27 +
   11.28 +/*
   11.29 + * Local variables:
   11.30 + * mode: C
   11.31 + * c-set-style: "BSD"
   11.32 + * c-basic-offset: 4
   11.33 + * tab-width: 4
   11.34 + * indent-tabs-mode: nil
   11.35 + * End:
   11.36 + */
    12.1 --- a/tools/libxc/xc_misc.c	Mon Sep 19 13:24:13 2005 +0000
    12.2 +++ b/tools/libxc/xc_misc.c	Mon Sep 19 13:24:31 2005 +0000
    12.3 @@ -133,5 +133,15 @@ int xc_msr_write(int xc_handle, int cpu_
    12.4  
    12.5  long xc_init_store(int xc_handle, int remote_port)
    12.6  {
    12.7 -	return ioctl(xc_handle, IOCTL_PRIVCMD_INITDOMAIN_STORE, remote_port);
    12.8 +    return ioctl(xc_handle, IOCTL_PRIVCMD_INITDOMAIN_STORE, remote_port);
    12.9  }
   12.10 +
   12.11 +/*
   12.12 + * Local variables:
   12.13 + * mode: C
   12.14 + * c-set-style: "BSD"
   12.15 + * c-basic-offset: 4
   12.16 + * tab-width: 4
   12.17 + * indent-tabs-mode: nil
   12.18 + * End:
   12.19 + */
    13.1 --- a/tools/libxc/xc_private.c	Mon Sep 19 13:24:13 2005 +0000
    13.2 +++ b/tools/libxc/xc_private.c	Mon Sep 19 13:24:31 2005 +0000
    13.3 @@ -15,7 +15,7 @@ void *xc_map_foreign_batch(int xc_handle
    13.4      void *addr;
    13.5      addr = mmap(NULL, num*PAGE_SIZE, prot, MAP_SHARED, xc_handle, 0);
    13.6      if ( addr == MAP_FAILED )
    13.7 -	return NULL;
    13.8 +        return NULL;
    13.9  
   13.10      ioctlx.num=num;
   13.11      ioctlx.dom=dom;
   13.12 @@ -24,10 +24,10 @@ void *xc_map_foreign_batch(int xc_handle
   13.13      if ( ioctl( xc_handle, IOCTL_PRIVCMD_MMAPBATCH, &ioctlx ) < 0 )
   13.14      {
   13.15          int saved_errno = errno;
   13.16 -	perror("XXXXXXXX");
   13.17 -	(void)munmap(addr, num*PAGE_SIZE);
   13.18 +        perror("XXXXXXXX");
   13.19 +        (void)munmap(addr, num*PAGE_SIZE);
   13.20          errno = saved_errno;
   13.21 -	return NULL;
   13.22 +        return NULL;
   13.23      }
   13.24      return addr;
   13.25  
   13.26 @@ -36,15 +36,15 @@ void *xc_map_foreign_batch(int xc_handle
   13.27  /*******************/
   13.28  
   13.29  void *xc_map_foreign_range(int xc_handle, u32 dom,
   13.30 -                            int size, int prot,
   13.31 -                            unsigned long mfn )
   13.32 +                           int size, int prot,
   13.33 +                           unsigned long mfn )
   13.34  {
   13.35      privcmd_mmap_t ioctlx; 
   13.36      privcmd_mmap_entry_t entry; 
   13.37      void *addr;
   13.38      addr = mmap(NULL, size, prot, MAP_SHARED, xc_handle, 0);
   13.39      if ( addr == MAP_FAILED )
   13.40 -	return NULL;
   13.41 +        return NULL;
   13.42  
   13.43      ioctlx.num=1;
   13.44      ioctlx.dom=dom;
   13.45 @@ -55,9 +55,9 @@ void *xc_map_foreign_range(int xc_handle
   13.46      if ( ioctl( xc_handle, IOCTL_PRIVCMD_MMAP, &ioctlx ) < 0 )
   13.47      {
   13.48          int saved_errno = errno;
   13.49 -	(void)munmap(addr, size);
   13.50 +        (void)munmap(addr, size);
   13.51          errno = saved_errno;
   13.52 -	return NULL;
   13.53 +        return NULL;
   13.54      }
   13.55      return addr;
   13.56  }
   13.57 @@ -66,7 +66,7 @@ void *xc_map_foreign_range(int xc_handle
   13.58  
   13.59  /* NB: arr must be mlock'ed */
   13.60  int xc_get_pfn_type_batch(int xc_handle, 
   13.61 -			  u32 dom, int num, unsigned long *arr)
   13.62 +                          u32 dom, int num, unsigned long *arr)
   13.63  {
   13.64      dom0_op_t op;
   13.65      op.cmd = DOM0_GETPAGEFRAMEINFO2;
   13.66 @@ -116,8 +116,8 @@ int xc_mmuext_op(
   13.67  
   13.68      if ( (ret = do_xen_hypercall(xc_handle, &hypercall)) < 0 )
   13.69      {
   13.70 -	fprintf(stderr, "Dom_mmuext operation failed (rc=%ld errno=%d)-- need to"
   13.71 -                    " rebuild the user-space tool set?\n",ret,errno);
   13.72 +        fprintf(stderr, "Dom_mmuext operation failed (rc=%ld errno=%d)-- need to"
   13.73 +                " rebuild the user-space tool set?\n",ret,errno);
   13.74      }
   13.75  
   13.76      safe_munlock(op, nr_ops*sizeof(*op));
   13.77 @@ -172,7 +172,7 @@ xc_mmu_t *xc_init_mmu_updates(int xc_han
   13.78  }
   13.79  
   13.80  int xc_add_mmu_update(int xc_handle, xc_mmu_t *mmu, 
   13.81 -		      unsigned long long ptr, unsigned long long val)
   13.82 +                      unsigned long long ptr, unsigned long long val)
   13.83  {
   13.84      mmu->updates[mmu->idx].ptr = ptr;
   13.85      mmu->updates[mmu->idx].val = val;
   13.86 @@ -229,7 +229,7 @@ int xc_memory_op(int xc_handle,
   13.87  
   13.88      if ( (ret = do_xen_hypercall(xc_handle, &hypercall)) < 0 )
   13.89      {
   13.90 -	fprintf(stderr, "hypercall failed (rc=%ld errno=%d)-- need to"
   13.91 +        fprintf(stderr, "hypercall failed (rc=%ld errno=%d)-- need to"
   13.92                  " rebuild the user-space tool set?\n",ret,errno);
   13.93      }
   13.94  
   13.95 @@ -275,16 +275,16 @@ unsigned long xc_get_m2p_start_mfn ( int
   13.96  
   13.97      if ( ioctl( xc_handle, IOCTL_PRIVCMD_GET_MACH2PHYS_START_MFN, &mfn ) < 0 )
   13.98      {
   13.99 -	perror("xc_get_m2p_start_mfn:");
  13.100 -	return 0;
  13.101 +        perror("xc_get_m2p_start_mfn:");
  13.102 +        return 0;
  13.103      }
  13.104      return mfn;
  13.105  }
  13.106  
  13.107  int xc_get_pfn_list(int xc_handle,
  13.108 -		 u32 domid, 
  13.109 -		 unsigned long *pfn_buf, 
  13.110 -		 unsigned long max_pfns)
  13.111 +                    u32 domid, 
  13.112 +                    unsigned long *pfn_buf, 
  13.113 +                    unsigned long max_pfns)
  13.114  {
  13.115      dom0_op_t op;
  13.116      int ret;
  13.117 @@ -306,16 +306,16 @@ int xc_get_pfn_list(int xc_handle,
  13.118  
  13.119  #if 0
  13.120  #ifdef DEBUG
  13.121 -	DPRINTF(("Ret for xc_get_pfn_list is %d\n", ret));
  13.122 -	if (ret >= 0) {
  13.123 -		int i, j;
  13.124 -		for (i = 0; i < op.u.getmemlist.num_pfns; i += 16) {
  13.125 -			fprintf(stderr, "0x%x: ", i);
  13.126 -			for (j = 0; j < 16; j++)
  13.127 -				fprintf(stderr, "0x%lx ", pfn_buf[i + j]);
  13.128 -			fprintf(stderr, "\n");
  13.129 -		}
  13.130 -	}
  13.131 +    DPRINTF(("Ret for xc_get_pfn_list is %d\n", ret));
  13.132 +    if (ret >= 0) {
  13.133 +        int i, j;
  13.134 +        for (i = 0; i < op.u.getmemlist.num_pfns; i += 16) {
  13.135 +            fprintf(stderr, "0x%x: ", i);
  13.136 +            for (j = 0; j < 16; j++)
  13.137 +                fprintf(stderr, "0x%lx ", pfn_buf[i + j]);
  13.138 +            fprintf(stderr, "\n");
  13.139 +        }
  13.140 +    }
  13.141  #endif
  13.142  #endif
  13.143  
  13.144 @@ -324,10 +324,10 @@ int xc_get_pfn_list(int xc_handle,
  13.145  
  13.146  #ifdef __ia64__
  13.147  int xc_ia64_get_pfn_list(int xc_handle,
  13.148 -		 u32 domid, 
  13.149 -		 unsigned long *pfn_buf, 
  13.150 -		 unsigned int start_page,
  13.151 -		 unsigned int nr_pages)
  13.152 +                         u32 domid, 
  13.153 +                         unsigned long *pfn_buf, 
  13.154 +                         unsigned int start_page,
  13.155 +                         unsigned int nr_pages)
  13.156  {
  13.157      dom0_op_t op;
  13.158      int ret;
  13.159 @@ -372,9 +372,9 @@ long xc_get_tot_pages(int xc_handle, u32
  13.160  }
  13.161  
  13.162  int xc_copy_to_domain_page(int xc_handle,
  13.163 -                                   u32 domid,
  13.164 -                                   unsigned long dst_pfn, 
  13.165 -                                   void *src_page)
  13.166 +                           u32 domid,
  13.167 +                           unsigned long dst_pfn, 
  13.168 +                           void *src_page)
  13.169  {
  13.170      void *vaddr = xc_map_foreign_range(
  13.171          xc_handle, domid, PAGE_SIZE, PROT_WRITE, dst_pfn);
  13.172 @@ -465,18 +465,28 @@ unsigned long xc_make_page_below_4G(
  13.173      unsigned long new_mfn;
  13.174  
  13.175      if ( xc_domain_memory_decrease_reservation( 
  13.176 -	xc_handle, domid, 1, 0, &mfn) != 0 )
  13.177 +        xc_handle, domid, 1, 0, &mfn) != 0 )
  13.178      {
  13.179 -	fprintf(stderr,"xc_make_page_below_4G decrease failed. mfn=%lx\n",mfn);
  13.180 -	return 0;
  13.181 +        fprintf(stderr,"xc_make_page_below_4G decrease failed. mfn=%lx\n",mfn);
  13.182 +        return 0;
  13.183      }
  13.184  
  13.185      if ( xc_domain_memory_increase_reservation(
  13.186          xc_handle, domid, 1, 0, 32, &new_mfn) != 0 )
  13.187      {
  13.188 -	fprintf(stderr,"xc_make_page_below_4G increase failed. mfn=%lx\n",mfn);
  13.189 -	return 0;
  13.190 +        fprintf(stderr,"xc_make_page_below_4G increase failed. mfn=%lx\n",mfn);
  13.191 +        return 0;
  13.192      }
  13.193  
  13.194      return new_mfn;
  13.195  }
  13.196 +
  13.197 +/*
  13.198 + * Local variables:
  13.199 + * mode: C
  13.200 + * c-set-style: "BSD"
  13.201 + * c-basic-offset: 4
  13.202 + * tab-width: 4
  13.203 + * indent-tabs-mode: nil
  13.204 + * End:
  13.205 + */
    14.1 --- a/tools/libxc/xc_ptrace.c	Mon Sep 19 13:24:13 2005 +0000
    14.2 +++ b/tools/libxc/xc_ptrace.c	Mon Sep 19 13:24:31 2005 +0000
    14.3 @@ -5,12 +5,9 @@
    14.4  
    14.5  #define X86_CR0_PE              0x00000001 /* Enable Protected Mode    (RW) */
    14.6  #define X86_CR0_PG              0x80000000 /* Paging                   (RW) */
    14.7 -
    14.8 -#define BSD_PAGE_MASK	(PAGE_SIZE-1)
    14.9 -#define	PG_FRAME	(~((unsigned long)BSD_PAGE_MASK)
   14.10 +#define BSD_PAGE_MASK (PAGE_SIZE-1)
   14.11  #define PDRSHIFT        22
   14.12 -#define	PSL_T		0x00000100	/* trace enable bit */
   14.13 -
   14.14 +#define PSL_T  0x00000100 /* trace enable bit */
   14.15  #define VCPU            0               /* XXX */
   14.16  
   14.17  /*
   14.18 @@ -69,67 +66,66 @@ struct gdb_regs {
   14.19      int  xss;    /* 64 */
   14.20  };
   14.21  
   14.22 -#define FETCH_REGS(cpu) \
   14.23 -    if (!regs_valid[cpu]) \
   14.24 -    {                \
   14.25 -	int retval = xc_domain_get_vcpu_context(xc_handle, domid, cpu, &ctxt[cpu]); \
   14.26 -	if (retval) \
   14.27 -	    goto error_out; \
   14.28 -	cr3[cpu] = ctxt[cpu].ctrlreg[3]; /* physical address */ \
   14.29 -	regs_valid[cpu] = 1; \
   14.30 -    } \
   14.31 +#define FETCH_REGS(cpu)                                         \
   14.32 +    if (!regs_valid[cpu])                                       \
   14.33 +    {                                                           \
   14.34 +        int retval = xc_domain_get_vcpu_context(                \
   14.35 +            xc_handle, domid, cpu, &ctxt[cpu]);                 \
   14.36 +        if (retval)                                             \
   14.37 +            goto error_out;                                     \
   14.38 +        cr3[cpu] = ctxt[cpu].ctrlreg[3]; /* physical address */ \
   14.39 +        regs_valid[cpu] = 1;                                    \
   14.40 +    }
   14.41  
   14.42  #define printval(x) printf("%s = %lx\n", #x, (long)x);
   14.43 -#define SET_PT_REGS(pt, xc) \
   14.44 -{ \
   14.45 -    pt.ebx = xc.ebx; \
   14.46 -    pt.ecx = xc.ecx; \
   14.47 -    pt.edx = xc.edx; \
   14.48 -    pt.esi = xc.esi; \
   14.49 -    pt.edi = xc.edi; \
   14.50 -    pt.ebp = xc.ebp; \
   14.51 -    pt.eax = xc.eax; \
   14.52 -    pt.eip = xc.eip; \
   14.53 -    pt.xcs = xc.cs; \
   14.54 -    pt.eflags = xc.eflags; \
   14.55 -    pt.esp = xc.esp; \
   14.56 -    pt.xss = xc.ss; \
   14.57 -    pt.xes = xc.es; \
   14.58 -    pt.xds = xc.ds; \
   14.59 -    pt.xfs = xc.fs; \
   14.60 -    pt.xgs = xc.gs; \
   14.61 +#define SET_PT_REGS(pt, xc)                     \
   14.62 +{                                               \
   14.63 +    pt.ebx = xc.ebx;                            \
   14.64 +    pt.ecx = xc.ecx;                            \
   14.65 +    pt.edx = xc.edx;                            \
   14.66 +    pt.esi = xc.esi;                            \
   14.67 +    pt.edi = xc.edi;                            \
   14.68 +    pt.ebp = xc.ebp;                            \
   14.69 +    pt.eax = xc.eax;                            \
   14.70 +    pt.eip = xc.eip;                            \
   14.71 +    pt.xcs = xc.cs;                             \
   14.72 +    pt.eflags = xc.eflags;                      \
   14.73 +    pt.esp = xc.esp;                            \
   14.74 +    pt.xss = xc.ss;                             \
   14.75 +    pt.xes = xc.es;                             \
   14.76 +    pt.xds = xc.ds;                             \
   14.77 +    pt.xfs = xc.fs;                             \
   14.78 +    pt.xgs = xc.gs;                             \
   14.79  }
   14.80  
   14.81 -#define SET_XC_REGS(pt, xc) \
   14.82 -{ \
   14.83 -    xc.ebx = pt->ebx; \
   14.84 -    xc.ecx = pt->ecx; \
   14.85 -    xc.edx = pt->edx; \
   14.86 -    xc.esi = pt->esi; \
   14.87 -    xc.edi = pt->edi; \
   14.88 -    xc.ebp = pt->ebp; \
   14.89 -    xc.eax = pt->eax; \
   14.90 -    xc.eip = pt->eip; \
   14.91 -    xc.cs = pt->xcs; \
   14.92 -    xc.eflags = pt->eflags; \
   14.93 -    xc.esp = pt->esp; \
   14.94 -    xc.ss = pt->xss; \
   14.95 -    xc.es = pt->xes; \
   14.96 -    xc.ds = pt->xds; \
   14.97 -    xc.fs = pt->xfs; \
   14.98 -    xc.gs = pt->xgs; \
   14.99 +#define SET_XC_REGS(pt, xc)                     \
  14.100 +{                                               \
  14.101 +    xc.ebx = pt->ebx;                           \
  14.102 +    xc.ecx = pt->ecx;                           \
  14.103 +    xc.edx = pt->edx;                           \
  14.104 +    xc.esi = pt->esi;                           \
  14.105 +    xc.edi = pt->edi;                           \
  14.106 +    xc.ebp = pt->ebp;                           \
  14.107 +    xc.eax = pt->eax;                           \
  14.108 +    xc.eip = pt->eip;                           \
  14.109 +    xc.cs = pt->xcs;                            \
  14.110 +    xc.eflags = pt->eflags;                     \
  14.111 +    xc.esp = pt->esp;                           \
  14.112 +    xc.ss = pt->xss;                            \
  14.113 +    xc.es = pt->xes;                            \
  14.114 +    xc.ds = pt->xds;                            \
  14.115 +    xc.fs = pt->xfs;                            \
  14.116 +    xc.gs = pt->xgs;                            \
  14.117  }
  14.118  
  14.119 -
  14.120  #define vtopdi(va) ((va) >> PDRSHIFT)
  14.121  #define vtopti(va) (((va) >> PAGE_SHIFT) & 0x3ff)
  14.122  
  14.123  /* XXX application state */
  14.124  
  14.125 -
  14.126  static int                      xc_handle;
  14.127 -static long			nr_pages = 0;
  14.128 -unsigned long			*page_array = NULL;
  14.129 +static long   nr_pages = 0;
  14.130 +unsigned long   *page_array = NULL;
  14.131  static int                      regs_valid[MAX_VIRT_CPUS];
  14.132  static unsigned long            cr3[MAX_VIRT_CPUS];
  14.133  static vcpu_guest_context_t ctxt[MAX_VIRT_CPUS];
  14.134 @@ -160,64 +156,64 @@ map_domain_va(unsigned long domid, int c
  14.135      static int            prev_perm[MAX_VIRT_CPUS];
  14.136  
  14.137      if (nr_pages != npgs) {
  14.138 -	if (nr_pages > 0)
  14.139 -	    free(page_array);
  14.140 -	nr_pages = npgs;
  14.141 -	if ((page_array = malloc(nr_pages * sizeof(unsigned long))) == NULL) {
  14.142 -	    printf("Could not allocate memory\n");
  14.143 -	    goto error_out;
  14.144 -	}
  14.145 +        if (nr_pages > 0)
  14.146 +            free(page_array);
  14.147 +        nr_pages = npgs;
  14.148 +        if ((page_array = malloc(nr_pages * sizeof(unsigned long))) == NULL) {
  14.149 +            printf("Could not allocate memory\n");
  14.150 +            goto error_out;
  14.151 +        }
  14.152  
  14.153 -	if (xc_get_pfn_list(xc_handle, domid, page_array, nr_pages) != nr_pages) {
  14.154 -		printf("Could not get the page frame list\n");
  14.155 -		goto error_out;
  14.156 -	}
  14.157 +        if (xc_get_pfn_list(xc_handle, domid, page_array, nr_pages) != nr_pages) {
  14.158 +            printf("Could not get the page frame list\n");
  14.159 +            goto error_out;
  14.160 +        }
  14.161      }
  14.162  
  14.163      FETCH_REGS(cpu);
  14.164  
  14.165      if (cr3[cpu] != cr3_phys[cpu]) 
  14.166      {
  14.167 -	cr3_phys[cpu] = cr3[cpu];
  14.168 -	if (cr3_virt[cpu])
  14.169 -	    munmap(cr3_virt[cpu], PAGE_SIZE);
  14.170 -	if ((cr3_virt[cpu] = xc_map_foreign_range(xc_handle, domid, PAGE_SIZE,
  14.171 -					     PROT_READ,
  14.172 -					     cr3_phys[cpu] >> PAGE_SHIFT)) == NULL)
  14.173 -	    goto error_out;
  14.174 +        cr3_phys[cpu] = cr3[cpu];
  14.175 +        if (cr3_virt[cpu])
  14.176 +            munmap(cr3_virt[cpu], PAGE_SIZE);
  14.177 +        if ((cr3_virt[cpu] = xc_map_foreign_range(xc_handle, domid, PAGE_SIZE,
  14.178 +                                                  PROT_READ,
  14.179 +                                                  cr3_phys[cpu] >> PAGE_SHIFT)) == NULL)
  14.180 +            goto error_out;
  14.181      } 
  14.182      if ((pde = cr3_virt[cpu][vtopdi(va)]) == 0) /* logical address */
  14.183 -	goto error_out;
  14.184 +        goto error_out;
  14.185      if ((ctxt[cpu].flags & VGCF_VMX_GUEST) && paging_enabled(&ctxt[cpu]))
  14.186          pde = page_array[pde >> PAGE_SHIFT] << PAGE_SHIFT;
  14.187      if (pde != pde_phys[cpu]) 
  14.188      {
  14.189 -	pde_phys[cpu] = pde;
  14.190 -	if (pde_virt[cpu])
  14.191 -	    munmap(pde_virt[cpu], PAGE_SIZE);
  14.192 -	if ((pde_virt[cpu] = xc_map_foreign_range(xc_handle, domid, PAGE_SIZE,
  14.193 -					     PROT_READ,
  14.194 -					     pde_phys[cpu] >> PAGE_SHIFT)) == NULL)
  14.195 -	    goto error_out;
  14.196 +        pde_phys[cpu] = pde;
  14.197 +        if (pde_virt[cpu])
  14.198 +            munmap(pde_virt[cpu], PAGE_SIZE);
  14.199 +        if ((pde_virt[cpu] = xc_map_foreign_range(xc_handle, domid, PAGE_SIZE,
  14.200 +                                                  PROT_READ,
  14.201 +                                                  pde_phys[cpu] >> PAGE_SHIFT)) == NULL)
  14.202 +            goto error_out;
  14.203      }
  14.204      if ((page = pde_virt[cpu][vtopti(va)]) == 0) /* logical address */
  14.205 -	goto error_out;
  14.206 +        goto error_out;
  14.207      if (ctxt[cpu].flags & VGCF_VMX_GUEST && paging_enabled(&ctxt[cpu]))
  14.208          page = page_array[page >> PAGE_SHIFT] << PAGE_SHIFT;
  14.209      if (page != page_phys[cpu] || perm != prev_perm[cpu]) 
  14.210      {
  14.211 -	page_phys[cpu] = page;
  14.212 -	if (page_virt[cpu])
  14.213 -	    munmap(page_virt[cpu], PAGE_SIZE);
  14.214 -	if ((page_virt[cpu] = xc_map_foreign_range(xc_handle, domid, PAGE_SIZE,
  14.215 -					      perm,
  14.216 -					      page_phys[cpu] >> PAGE_SHIFT)) == NULL) {
  14.217 -	    printf("cr3 %lx pde %lx page %lx pti %lx\n", cr3[cpu], pde, page, vtopti(va));
  14.218 -	    page_phys[cpu] = 0;
  14.219 -	    goto error_out;
  14.220 -	}
  14.221 -	prev_perm[cpu] = perm;
  14.222 -    }	
  14.223 +        page_phys[cpu] = page;
  14.224 +        if (page_virt[cpu])
  14.225 +            munmap(page_virt[cpu], PAGE_SIZE);
  14.226 +        if ((page_virt[cpu] = xc_map_foreign_range(xc_handle, domid, PAGE_SIZE,
  14.227 +                                                   perm,
  14.228 +                                                   page_phys[cpu] >> PAGE_SHIFT)) == NULL) {
  14.229 +            printf("cr3 %lx pde %lx page %lx pti %lx\n", cr3[cpu], pde, page, vtopti(va));
  14.230 +            page_phys[cpu] = 0;
  14.231 +            goto error_out;
  14.232 +        }
  14.233 +        prev_perm[cpu] = perm;
  14.234 +    } 
  14.235      return (void *)(((unsigned long)page_virt[cpu]) | (va & BSD_PAGE_MASK));
  14.236  
  14.237   error_out:
  14.238 @@ -234,29 +230,29 @@ xc_waitdomain(int domain, int *status, i
  14.239      ts.tv_nsec = 10*1000*1000;
  14.240  
  14.241      if (!xc_handle)
  14.242 -	if ((xc_handle = xc_interface_open()) < 0) 
  14.243 -	{
  14.244 -	    printf("xc_interface_open failed\n");
  14.245 -	    return -1;
  14.246 -	}
  14.247 +        if ((xc_handle = xc_interface_open()) < 0) 
  14.248 +        {
  14.249 +            printf("xc_interface_open failed\n");
  14.250 +            return -1;
  14.251 +        }
  14.252      op.cmd = DOM0_GETDOMAININFO;
  14.253      op.u.getdomaininfo.domain = domain;
  14.254   retry:
  14.255  
  14.256      retval = do_dom0_op(xc_handle, &op);
  14.257      if (retval || op.u.getdomaininfo.domain != domain) {
  14.258 -	printf("getdomaininfo failed\n");
  14.259 -	goto done;
  14.260 +        printf("getdomaininfo failed\n");
  14.261 +        goto done;
  14.262      }
  14.263      *status = op.u.getdomaininfo.flags;
  14.264      
  14.265      if (options & WNOHANG)
  14.266 -	goto done;
  14.267 -	
  14.268 +        goto done;
  14.269 + 
  14.270  
  14.271 -    if (!(op.u.getdomaininfo.flags & DOMFLAGS_PAUSED)) {	
  14.272 -	nanosleep(&ts,NULL);
  14.273 -	goto retry;
  14.274 +    if (!(op.u.getdomaininfo.flags & DOMFLAGS_PAUSED)) { 
  14.275 +        nanosleep(&ts,NULL);
  14.276 +        goto retry;
  14.277      }
  14.278   done:
  14.279      return retval;
  14.280 @@ -278,107 +274,107 @@ xc_ptrace(enum __ptrace_request request,
  14.281      op.interface_version = DOM0_INTERFACE_VERSION;
  14.282      
  14.283      if (!xc_handle)
  14.284 -	if ((xc_handle = xc_interface_open()) < 0)
  14.285 -	    return -1;
  14.286 +        if ((xc_handle = xc_interface_open()) < 0)
  14.287 +            return -1;
  14.288  #if 0
  14.289      printf("%20s %d, %p, %p \n", ptrace_names[request], domid, addr, data);
  14.290  #endif
  14.291 -    switch (request) {	
  14.292 +    switch (request) { 
  14.293      case PTRACE_PEEKTEXT:
  14.294      case PTRACE_PEEKDATA:
  14.295 -	if ((guest_va = (unsigned long *)map_domain_va(domid, cpu, addr, PROT_READ)) == NULL) {
  14.296 -	    status = EFAULT;
  14.297 -	    goto error_out;
  14.298 -	}
  14.299 +        if ((guest_va = (unsigned long *)map_domain_va(domid, cpu, addr, PROT_READ)) == NULL) {
  14.300 +            status = EFAULT;
  14.301 +            goto error_out;
  14.302 +        }
  14.303  
  14.304 -	retval = *guest_va;
  14.305 -	break;
  14.306 +        retval = *guest_va;
  14.307 +        break;
  14.308      case PTRACE_POKETEXT:
  14.309      case PTRACE_POKEDATA:
  14.310 -	if ((guest_va = (unsigned long *)map_domain_va(domid, cpu, addr, PROT_READ|PROT_WRITE)) == NULL) {
  14.311 -	    status = EFAULT;
  14.312 -	    goto error_out;
  14.313 -	}
  14.314 +        if ((guest_va = (unsigned long *)map_domain_va(domid, cpu, addr, PROT_READ|PROT_WRITE)) == NULL) {
  14.315 +            status = EFAULT;
  14.316 +            goto error_out;
  14.317 +        }
  14.318  
  14.319 -	*guest_va = (unsigned long)data;
  14.320 -	break;
  14.321 +        *guest_va = (unsigned long)data;
  14.322 +        break;
  14.323      case PTRACE_GETREGS:
  14.324      case PTRACE_GETFPREGS:
  14.325      case PTRACE_GETFPXREGS:
  14.326 -	FETCH_REGS(cpu);
  14.327 +        FETCH_REGS(cpu);
  14.328  
  14.329 -	if (request == PTRACE_GETREGS) {
  14.330 -		SET_PT_REGS(pt, ctxt[cpu].user_regs); 
  14.331 -		memcpy(data, &pt, sizeof(struct gdb_regs));
  14.332 -	} else if (request == PTRACE_GETFPREGS)
  14.333 -	    memcpy(data, &ctxt[cpu].fpu_ctxt, sizeof(ctxt[cpu].fpu_ctxt));
  14.334 -	else /*if (request == PTRACE_GETFPXREGS)*/
  14.335 -	    memcpy(data, &ctxt[cpu].fpu_ctxt, sizeof(ctxt[cpu].fpu_ctxt));
  14.336 -	break;
  14.337 +        if (request == PTRACE_GETREGS) {
  14.338 +            SET_PT_REGS(pt, ctxt[cpu].user_regs); 
  14.339 +            memcpy(data, &pt, sizeof(struct gdb_regs));
  14.340 +        } else if (request == PTRACE_GETFPREGS)
  14.341 +            memcpy(data, &ctxt[cpu].fpu_ctxt, sizeof(ctxt[cpu].fpu_ctxt));
  14.342 +        else /*if (request == PTRACE_GETFPXREGS)*/
  14.343 +            memcpy(data, &ctxt[cpu].fpu_ctxt, sizeof(ctxt[cpu].fpu_ctxt));
  14.344 +        break;
  14.345      case PTRACE_SETREGS:
  14.346 -	op.cmd = DOM0_SETDOMAININFO;
  14.347 -	SET_XC_REGS(((struct gdb_regs *)data), ctxt[VCPU].user_regs);
  14.348 -	op.u.setdomaininfo.domain = domid;
  14.349 -	/* XXX need to understand multiple vcpus */
  14.350 -	op.u.setdomaininfo.vcpu = cpu;
  14.351 -	op.u.setdomaininfo.ctxt = &ctxt[cpu];
  14.352 -	retval = do_dom0_op(xc_handle, &op);
  14.353 -	if (retval)
  14.354 -	    goto error_out;
  14.355 +        op.cmd = DOM0_SETDOMAININFO;
  14.356 +        SET_XC_REGS(((struct gdb_regs *)data), ctxt[VCPU].user_regs);
  14.357 +        op.u.setdomaininfo.domain = domid;
  14.358 +        /* XXX need to understand multiple vcpus */
  14.359 +        op.u.setdomaininfo.vcpu = cpu;
  14.360 +        op.u.setdomaininfo.ctxt = &ctxt[cpu];
  14.361 +        retval = do_dom0_op(xc_handle, &op);
  14.362 +        if (retval)
  14.363 +            goto error_out;
  14.364  
  14.365 -	break;
  14.366 +        break;
  14.367      case PTRACE_ATTACH:
  14.368 -	op.cmd = DOM0_GETDOMAININFO;
  14.369 -	op.u.getdomaininfo.domain = domid;
  14.370 -	retval = do_dom0_op(xc_handle, &op);
  14.371 -	if (retval || op.u.getdomaininfo.domain != domid) {
  14.372 -	    perror("dom0 op failed");
  14.373 -	    goto error_out;
  14.374 -	}
  14.375 -	if (op.u.getdomaininfo.flags & DOMFLAGS_PAUSED) {
  14.376 -	    printf("domain currently paused\n");
  14.377 -	    goto error_out;
  14.378 -	}
  14.379 -	printf("domain not currently paused\n");
  14.380 -	op.cmd = DOM0_PAUSEDOMAIN;
  14.381 -	op.u.pausedomain.domain = domid;
  14.382 -	retval = do_dom0_op(xc_handle, &op);
  14.383 -	break;
  14.384 +        op.cmd = DOM0_GETDOMAININFO;
  14.385 +        op.u.getdomaininfo.domain = domid;
  14.386 +        retval = do_dom0_op(xc_handle, &op);
  14.387 +        if (retval || op.u.getdomaininfo.domain != domid) {
  14.388 +            perror("dom0 op failed");
  14.389 +            goto error_out;
  14.390 +        }
  14.391 +        if (op.u.getdomaininfo.flags & DOMFLAGS_PAUSED) {
  14.392 +            printf("domain currently paused\n");
  14.393 +            goto error_out;
  14.394 +        }
  14.395 +        printf("domain not currently paused\n");
  14.396 +        op.cmd = DOM0_PAUSEDOMAIN;
  14.397 +        op.u.pausedomain.domain = domid;
  14.398 +        retval = do_dom0_op(xc_handle, &op);
  14.399 +        break;
  14.400      case PTRACE_SINGLESTEP:
  14.401 -	ctxt[VCPU].user_regs.eflags |= PSL_T;
  14.402 -	op.cmd = DOM0_SETDOMAININFO;
  14.403 -	op.u.setdomaininfo.domain = domid;
  14.404 -	op.u.setdomaininfo.vcpu = 0;
  14.405 -	op.u.setdomaininfo.ctxt = &ctxt[cpu];
  14.406 -	retval = do_dom0_op(xc_handle, &op);	
  14.407 -	if (retval) {
  14.408 -	    perror("dom0 op failed");
  14.409 -	    goto error_out;
  14.410 -	}
  14.411 -    	/* FALLTHROUGH */
  14.412 +        ctxt[VCPU].user_regs.eflags |= PSL_T;
  14.413 +        op.cmd = DOM0_SETDOMAININFO;
  14.414 +        op.u.setdomaininfo.domain = domid;
  14.415 +        op.u.setdomaininfo.vcpu = 0;
  14.416 +        op.u.setdomaininfo.ctxt = &ctxt[cpu];
  14.417 +        retval = do_dom0_op(xc_handle, &op); 
  14.418 +        if (retval) {
  14.419 +            perror("dom0 op failed");
  14.420 +            goto error_out;
  14.421 +        }
  14.422 +        /* FALLTHROUGH */
  14.423      case PTRACE_CONT:
  14.424      case PTRACE_DETACH:
  14.425 -	if (request != PTRACE_SINGLESTEP) {
  14.426 -	    FETCH_REGS(cpu);
  14.427 -	    /* Clear trace flag */
  14.428 -	    if (ctxt[cpu].user_regs.eflags & PSL_T) {
  14.429 -		ctxt[cpu].user_regs.eflags &= ~PSL_T;
  14.430 -		op.cmd = DOM0_SETDOMAININFO;
  14.431 -		op.u.setdomaininfo.domain = domid;
  14.432 -		op.u.setdomaininfo.vcpu = cpu;
  14.433 -		op.u.setdomaininfo.ctxt = &ctxt[cpu];
  14.434 -		retval = do_dom0_op(xc_handle, &op);	
  14.435 -		if (retval) {
  14.436 -		    perror("dom0 op failed");
  14.437 -		    goto error_out;
  14.438 -		}
  14.439 -	    }
  14.440 -	}
  14.441 -	regs_valid[cpu] = 0;
  14.442 -	op.cmd = DOM0_UNPAUSEDOMAIN;
  14.443 -	op.u.unpausedomain.domain = domid > 0 ? domid : -domid;
  14.444 -	retval = do_dom0_op(xc_handle, &op);
  14.445 -	break;
  14.446 +        if (request != PTRACE_SINGLESTEP) {
  14.447 +            FETCH_REGS(cpu);
  14.448 +            /* Clear trace flag */
  14.449 +            if (ctxt[cpu].user_regs.eflags & PSL_T) {
  14.450 +                ctxt[cpu].user_regs.eflags &= ~PSL_T;
  14.451 +                op.cmd = DOM0_SETDOMAININFO;
  14.452 +                op.u.setdomaininfo.domain = domid;
  14.453 +                op.u.setdomaininfo.vcpu = cpu;
  14.454 +                op.u.setdomaininfo.ctxt = &ctxt[cpu];
  14.455 +                retval = do_dom0_op(xc_handle, &op); 
  14.456 +                if (retval) {
  14.457 +                    perror("dom0 op failed");
  14.458 +                    goto error_out;
  14.459 +                }
  14.460 +            }
  14.461 +        }
  14.462 +        regs_valid[cpu] = 0;
  14.463 +        op.cmd = DOM0_UNPAUSEDOMAIN;
  14.464 +        op.u.unpausedomain.domain = domid > 0 ? domid : -domid;
  14.465 +        retval = do_dom0_op(xc_handle, &op);
  14.466 +        break;
  14.467      case PTRACE_SETFPREGS:
  14.468      case PTRACE_SETFPXREGS:
  14.469      case PTRACE_PEEKUSER:
  14.470 @@ -386,20 +382,30 @@ xc_ptrace(enum __ptrace_request request,
  14.471      case PTRACE_SYSCALL:
  14.472      case PTRACE_KILL:
  14.473  #ifdef DEBUG
  14.474 -	printf("unsupported xc_ptrace request %s\n", ptrace_names[request]);
  14.475 +        printf("unsupported xc_ptrace request %s\n", ptrace_names[request]);
  14.476  #endif
  14.477 -	/* XXX not yet supported */
  14.478 -	status = ENOSYS;
  14.479 -	break;
  14.480 +        /* XXX not yet supported */
  14.481 +        status = ENOSYS;
  14.482 +        break;
  14.483      case PTRACE_TRACEME:
  14.484 -	printf("PTRACE_TRACEME is an invalid request under Xen\n");
  14.485 -	status = EINVAL;
  14.486 +        printf("PTRACE_TRACEME is an invalid request under Xen\n");
  14.487 +        status = EINVAL;
  14.488      }
  14.489      
  14.490      if (status) {
  14.491 -	errno = status;
  14.492 -	retval = -1;
  14.493 +        errno = status;
  14.494 +        retval = -1;
  14.495      }
  14.496   error_out:
  14.497      return retval;
  14.498  }
  14.499 +
  14.500 +/*
  14.501 + * Local variables:
  14.502 + * mode: C
  14.503 + * c-set-style: "BSD"
  14.504 + * c-basic-offset: 4
  14.505 + * tab-width: 4
  14.506 + * indent-tabs-mode: nil
  14.507 + * End:
  14.508 + */
    15.1 --- a/tools/libxc/xc_ptrace_core.c	Mon Sep 19 13:24:13 2005 +0000
    15.2 +++ b/tools/libxc/xc_ptrace_core.c	Mon Sep 19 13:24:31 2005 +0000
    15.3 @@ -3,12 +3,8 @@
    15.4  #include "xc_private.h"
    15.5  #include <time.h>
    15.6  
    15.7 -
    15.8 -#define BSD_PAGE_MASK	(PAGE_SIZE-1)
    15.9 -#define	PG_FRAME	(~((unsigned long)BSD_PAGE_MASK)
   15.10 +#define BSD_PAGE_MASK (PAGE_SIZE-1)
   15.11  #define PDRSHIFT        22
   15.12 -#define	PSL_T		0x00000100	/* trace enable bit */
   15.13 -
   15.14  #define VCPU            0               /* XXX */
   15.15  
   15.16  /*
   15.17 @@ -16,7 +12,6 @@
   15.18   * ptrace(enum __ptrace_request request, pid_t pid, void *addr, void *data);
   15.19   */
   15.20  
   15.21 -
   15.22  struct gdb_regs {
   15.23      long ebx; /* 0 */
   15.24      long ecx; /* 4 */
   15.25 @@ -38,44 +33,44 @@ struct gdb_regs {
   15.26  };
   15.27  
   15.28  #define printval(x) printf("%s = %lx\n", #x, (long)x);
   15.29 -#define SET_PT_REGS(pt, xc) \
   15.30 -{ \
   15.31 -    pt.ebx = xc.ebx; \
   15.32 -    pt.ecx = xc.ecx; \
   15.33 -    pt.edx = xc.edx; \
   15.34 -    pt.esi = xc.esi; \
   15.35 -    pt.edi = xc.edi; \
   15.36 -    pt.ebp = xc.ebp; \
   15.37 -    pt.eax = xc.eax; \
   15.38 -    pt.eip = xc.eip; \
   15.39 -    pt.xcs = xc.cs; \
   15.40 -    pt.eflags = xc.eflags; \
   15.41 -    pt.esp = xc.esp; \
   15.42 -    pt.xss = xc.ss; \
   15.43 -    pt.xes = xc.es; \
   15.44 -    pt.xds = xc.ds; \
   15.45 -    pt.xfs = xc.fs; \
   15.46 -    pt.xgs = xc.gs; \
   15.47 +#define SET_PT_REGS(pt, xc)                     \
   15.48 +{                                               \
   15.49 +    pt.ebx = xc.ebx;                            \
   15.50 +    pt.ecx = xc.ecx;                            \
   15.51 +    pt.edx = xc.edx;                            \
   15.52 +    pt.esi = xc.esi;                            \
   15.53 +    pt.edi = xc.edi;                            \
   15.54 +    pt.ebp = xc.ebp;                            \
   15.55 +    pt.eax = xc.eax;                            \
   15.56 +    pt.eip = xc.eip;                            \
   15.57 +    pt.xcs = xc.cs;                             \
   15.58 +    pt.eflags = xc.eflags;                      \
   15.59 +    pt.esp = xc.esp;                            \
   15.60 +    pt.xss = xc.ss;                             \
   15.61 +    pt.xes = xc.es;                             \
   15.62 +    pt.xds = xc.ds;                             \
   15.63 +    pt.xfs = xc.fs;                             \
   15.64 +    pt.xgs = xc.gs;                             \
   15.65  }
   15.66  
   15.67 -#define SET_XC_REGS(pt, xc) \
   15.68 -{ \
   15.69 -    xc.ebx = pt->ebx; \
   15.70 -    xc.ecx = pt->ecx; \
   15.71 -    xc.edx = pt->edx; \
   15.72 -    xc.esi = pt->esi; \
   15.73 -    xc.edi = pt->edi; \
   15.74 -    xc.ebp = pt->ebp; \
   15.75 -    xc.eax = pt->eax; \
   15.76 -    xc.eip = pt->eip; \
   15.77 -    xc.cs = pt->xcs; \
   15.78 -    xc.eflags = pt->eflags; \
   15.79 -    xc.esp = pt->esp; \
   15.80 -    xc.ss = pt->xss; \
   15.81 -    xc.es = pt->xes; \
   15.82 -    xc.ds = pt->xds; \
   15.83 -    xc.fs = pt->xfs; \
   15.84 -    xc.gs = pt->xgs; \
   15.85 +#define SET_XC_REGS(pt, xc)                     \
   15.86 +{                                               \
   15.87 +    xc.ebx = pt->ebx;                           \
   15.88 +    xc.ecx = pt->ecx;                           \
   15.89 +    xc.edx = pt->edx;                           \
   15.90 +    xc.esi = pt->esi;                           \
   15.91 +    xc.edi = pt->edi;                           \
   15.92 +    xc.ebp = pt->ebp;                           \
   15.93 +    xc.eax = pt->eax;                           \
   15.94 +    xc.eip = pt->eip;                           \
   15.95 +    xc.cs = pt->xcs;                            \
   15.96 +    xc.eflags = pt->eflags;                     \
   15.97 +    xc.esp = pt->esp;                           \
   15.98 +    xc.ss = pt->xss;                            \
   15.99 +    xc.es = pt->xes;                            \
  15.100 +    xc.ds = pt->xds;                            \
  15.101 +    xc.fs = pt->xfs;                            \
  15.102 +    xc.gs = pt->xgs;                            \
  15.103  }
  15.104  
  15.105  
  15.106 @@ -84,10 +79,9 @@ struct gdb_regs {
  15.107  
  15.108  /* XXX application state */
  15.109  
  15.110 -
  15.111 -static long			nr_pages = 0;
  15.112 -static unsigned long		*p2m_array = NULL;
  15.113 -static unsigned long		*m2p_array = NULL;
  15.114 +static long   nr_pages = 0;
  15.115 +static unsigned long  *p2m_array = NULL;
  15.116 +static unsigned long  *m2p_array = NULL;
  15.117  static unsigned long            pages_offset;
  15.118  static unsigned long            cr3[MAX_VIRT_CPUS];
  15.119  static vcpu_guest_context_t     ctxt[MAX_VIRT_CPUS];
  15.120 @@ -117,54 +111,54 @@ map_domain_va(unsigned long domfd, int c
  15.121  
  15.122      if (cr3[cpu] != cr3_phys[cpu]) 
  15.123      {
  15.124 -	cr3_phys[cpu] = cr3[cpu];
  15.125 -	if (cr3_virt[cpu])
  15.126 -	    munmap(cr3_virt[cpu], PAGE_SIZE);
  15.127 -	v = mmap(
  15.128 +        cr3_phys[cpu] = cr3[cpu];
  15.129 +        if (cr3_virt[cpu])
  15.130 +            munmap(cr3_virt[cpu], PAGE_SIZE);
  15.131 +        v = mmap(
  15.132              NULL, PAGE_SIZE, PROT_READ, MAP_PRIVATE, domfd,
  15.133              map_mtop_offset(cr3_phys[cpu]));
  15.134          if (v == MAP_FAILED)
  15.135 -	{
  15.136 -	    perror("mmap failed");
  15.137 -	    goto error_out;
  15.138 -	}
  15.139 +        {
  15.140 +            perror("mmap failed");
  15.141 +            goto error_out;
  15.142 +        }
  15.143          cr3_virt[cpu] = v;
  15.144      } 
  15.145      if ((pde = cr3_virt[cpu][vtopdi(va)]) == 0) /* logical address */
  15.146 -	goto error_out;
  15.147 +        goto error_out;
  15.148      if (ctxt[cpu].flags & VGCF_VMX_GUEST)
  15.149 -	pde = p2m_array[pde >> PAGE_SHIFT] << PAGE_SHIFT;
  15.150 +        pde = p2m_array[pde >> PAGE_SHIFT] << PAGE_SHIFT;
  15.151      if (pde != pde_phys[cpu]) 
  15.152      {
  15.153 -	pde_phys[cpu] = pde;
  15.154 -	if (pde_virt[cpu])
  15.155 -	    munmap(pde_virt[cpu], PAGE_SIZE);
  15.156 -	v = mmap(
  15.157 +        pde_phys[cpu] = pde;
  15.158 +        if (pde_virt[cpu])
  15.159 +            munmap(pde_virt[cpu], PAGE_SIZE);
  15.160 +        v = mmap(
  15.161              NULL, PAGE_SIZE, PROT_READ, MAP_PRIVATE, domfd,
  15.162              map_mtop_offset(pde_phys[cpu]));
  15.163          if (v == MAP_FAILED)
  15.164 -	    goto error_out;
  15.165 +            goto error_out;
  15.166          pde_virt[cpu] = v;
  15.167      }
  15.168      if ((page = pde_virt[cpu][vtopti(va)]) == 0) /* logical address */
  15.169 -	goto error_out;
  15.170 +        goto error_out;
  15.171      if (ctxt[cpu].flags & VGCF_VMX_GUEST)
  15.172 -	page = p2m_array[page >> PAGE_SHIFT] << PAGE_SHIFT;
  15.173 +        page = p2m_array[page >> PAGE_SHIFT] << PAGE_SHIFT;
  15.174      if (page != page_phys[cpu]) 
  15.175      {
  15.176 -	page_phys[cpu] = page;
  15.177 -	if (page_virt[cpu])
  15.178 -	    munmap(page_virt[cpu], PAGE_SIZE);
  15.179 -	v = mmap(
  15.180 +        page_phys[cpu] = page;
  15.181 +        if (page_virt[cpu])
  15.182 +            munmap(page_virt[cpu], PAGE_SIZE);
  15.183 +        v = mmap(
  15.184              NULL, PAGE_SIZE, PROT_READ, MAP_PRIVATE, domfd,
  15.185              map_mtop_offset(page_phys[cpu]));
  15.186          if (v == MAP_FAILED) {
  15.187 -	    printf("cr3 %lx pde %lx page %lx pti %lx\n", cr3[cpu], pde, page, vtopti(va));
  15.188 -	    page_phys[cpu] = 0;
  15.189 -	    goto error_out;
  15.190 -	}
  15.191 +            printf("cr3 %lx pde %lx page %lx pti %lx\n", cr3[cpu], pde, page, vtopti(va));
  15.192 +            page_phys[cpu] = 0;
  15.193 +            goto error_out;
  15.194 +        }
  15.195          page_virt[cpu] = v;
  15.196 -    }	
  15.197 +    } 
  15.198      return (void *)(((unsigned long)page_virt[cpu]) | (va & BSD_PAGE_MASK));
  15.199  
  15.200   error_out:
  15.201 @@ -181,37 +175,37 @@ xc_waitdomain_core(int domfd, int *statu
  15.202  
  15.203      if (nr_pages == 0) {
  15.204  
  15.205 -	if (read(domfd, &header, sizeof(header)) != sizeof(header))
  15.206 -	    return -1;
  15.207 +        if (read(domfd, &header, sizeof(header)) != sizeof(header))
  15.208 +            return -1;
  15.209  
  15.210 -	nr_pages = header.xch_nr_pages;
  15.211 -	nr_vcpus = header.xch_nr_vcpus;
  15.212 -	pages_offset = header.xch_pages_offset;
  15.213 +        nr_pages = header.xch_nr_pages;
  15.214 +        nr_vcpus = header.xch_nr_vcpus;
  15.215 +        pages_offset = header.xch_pages_offset;
  15.216  
  15.217 -	if (read(domfd, ctxt, sizeof(vcpu_guest_context_t)*nr_vcpus) != 
  15.218 -	    sizeof(vcpu_guest_context_t)*nr_vcpus)
  15.219 -	    return -1;
  15.220 +        if (read(domfd, ctxt, sizeof(vcpu_guest_context_t)*nr_vcpus) != 
  15.221 +            sizeof(vcpu_guest_context_t)*nr_vcpus)
  15.222 +            return -1;
  15.223  
  15.224 -	for (i = 0; i < nr_vcpus; i++) {
  15.225 -	    cr3[i] = ctxt[i].ctrlreg[3];
  15.226 -	}
  15.227 -	if ((p2m_array = malloc(nr_pages * sizeof(unsigned long))) == NULL) {
  15.228 -	    printf("Could not allocate p2m_array\n");
  15.229 -	    goto error_out;
  15.230 -	}
  15.231 -	if (read(domfd, p2m_array, sizeof(unsigned long)*nr_pages) != 
  15.232 -	    sizeof(unsigned long)*nr_pages)
  15.233 -	    return -1;
  15.234 +        for (i = 0; i < nr_vcpus; i++) {
  15.235 +            cr3[i] = ctxt[i].ctrlreg[3];
  15.236 +        }
  15.237 +        if ((p2m_array = malloc(nr_pages * sizeof(unsigned long))) == NULL) {
  15.238 +            printf("Could not allocate p2m_array\n");
  15.239 +            goto error_out;
  15.240 +        }
  15.241 +        if (read(domfd, p2m_array, sizeof(unsigned long)*nr_pages) != 
  15.242 +            sizeof(unsigned long)*nr_pages)
  15.243 +            return -1;
  15.244  
  15.245 -	if ((m2p_array = malloc((1<<20) * sizeof(unsigned long))) == NULL) {
  15.246 -	    printf("Could not allocate m2p array\n");
  15.247 -	    goto error_out;
  15.248 -	}
  15.249 -	bzero(m2p_array, sizeof(unsigned long)* 1 << 20);
  15.250 +        if ((m2p_array = malloc((1<<20) * sizeof(unsigned long))) == NULL) {
  15.251 +            printf("Could not allocate m2p array\n");
  15.252 +            goto error_out;
  15.253 +        }
  15.254 +        bzero(m2p_array, sizeof(unsigned long)* 1 << 20);
  15.255  
  15.256 -	for (i = 0; i < nr_pages; i++) {
  15.257 -	    m2p_array[p2m_array[i]] = i;
  15.258 -	}
  15.259 +        for (i = 0; i < nr_pages; i++) {
  15.260 +            m2p_array[p2m_array[i]] = i;
  15.261 +        }
  15.262  
  15.263      }
  15.264      retval = 0;
  15.265 @@ -234,38 +228,38 @@ xc_ptrace_core(enum __ptrace_request req
  15.266  #if 0
  15.267      printf("%20s %d, %p, %p \n", ptrace_names[request], domid, addr, data);
  15.268  #endif
  15.269 -    switch (request) {	
  15.270 +    switch (request) { 
  15.271      case PTRACE_PEEKTEXT:
  15.272      case PTRACE_PEEKDATA:
  15.273 -	if ((guest_va = (unsigned long *)map_domain_va(domfd, cpu, addr)) == NULL) {
  15.274 -	    status = EFAULT;
  15.275 -	    goto error_out;
  15.276 -	}
  15.277 +        if ((guest_va = (unsigned long *)map_domain_va(domfd, cpu, addr)) == NULL) {
  15.278 +            status = EFAULT;
  15.279 +            goto error_out;
  15.280 +        }
  15.281  
  15.282 -	retval = *guest_va;
  15.283 -	break;
  15.284 +        retval = *guest_va;
  15.285 +        break;
  15.286      case PTRACE_POKETEXT:
  15.287      case PTRACE_POKEDATA:
  15.288 -	if ((guest_va = (unsigned long *)map_domain_va(domfd, cpu, addr)) == NULL) {
  15.289 -	    status = EFAULT;
  15.290 -	    goto error_out;
  15.291 -	}
  15.292 -	*guest_va = (unsigned long)data;
  15.293 -	break;
  15.294 +        if ((guest_va = (unsigned long *)map_domain_va(domfd, cpu, addr)) == NULL) {
  15.295 +            status = EFAULT;
  15.296 +            goto error_out;
  15.297 +        }
  15.298 +        *guest_va = (unsigned long)data;
  15.299 +        break;
  15.300      case PTRACE_GETREGS:
  15.301      case PTRACE_GETFPREGS:
  15.302      case PTRACE_GETFPXREGS:
  15.303 -	if (request == PTRACE_GETREGS) {
  15.304 -		SET_PT_REGS(pt, ctxt[cpu].user_regs); 
  15.305 -		memcpy(data, &pt, sizeof(struct gdb_regs));
  15.306 -	} else if (request == PTRACE_GETFPREGS)
  15.307 -	    memcpy(data, &ctxt[cpu].fpu_ctxt, sizeof(ctxt[cpu].fpu_ctxt));
  15.308 -	else /*if (request == PTRACE_GETFPXREGS)*/
  15.309 -	    memcpy(data, &ctxt[cpu].fpu_ctxt, sizeof(ctxt[cpu].fpu_ctxt));
  15.310 -	break;
  15.311 +        if (request == PTRACE_GETREGS) {
  15.312 +            SET_PT_REGS(pt, ctxt[cpu].user_regs); 
  15.313 +            memcpy(data, &pt, sizeof(struct gdb_regs));
  15.314 +        } else if (request == PTRACE_GETFPREGS)
  15.315 +            memcpy(data, &ctxt[cpu].fpu_ctxt, sizeof(ctxt[cpu].fpu_ctxt));
  15.316 +        else /*if (request == PTRACE_GETFPXREGS)*/
  15.317 +            memcpy(data, &ctxt[cpu].fpu_ctxt, sizeof(ctxt[cpu].fpu_ctxt));
  15.318 +        break;
  15.319      case PTRACE_ATTACH:
  15.320 -	retval = 0;
  15.321 -	break;
  15.322 +        retval = 0;
  15.323 +        break;
  15.324      case PTRACE_SETREGS:
  15.325      case PTRACE_SINGLESTEP:
  15.326      case PTRACE_CONT:
  15.327 @@ -277,19 +271,29 @@ xc_ptrace_core(enum __ptrace_request req
  15.328      case PTRACE_SYSCALL:
  15.329      case PTRACE_KILL:
  15.330  #ifdef DEBUG
  15.331 -	printf("unsupported xc_ptrace request %s\n", ptrace_names[request]);
  15.332 +        printf("unsupported xc_ptrace request %s\n", ptrace_names[request]);
  15.333  #endif
  15.334 -	status = ENOSYS;
  15.335 -	break;
  15.336 +        status = ENOSYS;
  15.337 +        break;
  15.338      case PTRACE_TRACEME:
  15.339 -	printf("PTRACE_TRACEME is an invalid request under Xen\n");
  15.340 -	status = EINVAL;
  15.341 +        printf("PTRACE_TRACEME is an invalid request under Xen\n");
  15.342 +        status = EINVAL;
  15.343      }
  15.344      
  15.345      if (status) {
  15.346 -	errno = status;
  15.347 -	retval = -1;
  15.348 +        errno = status;
  15.349 +        retval = -1;
  15.350      }
  15.351   error_out:
  15.352      return retval;
  15.353  }
  15.354 +
  15.355 +/*
  15.356 + * Local variables:
  15.357 + * mode: C
  15.358 + * c-set-style: "BSD"
  15.359 + * c-basic-offset: 4
  15.360 + * tab-width: 4
  15.361 + * indent-tabs-mode: nil
  15.362 + * End:
  15.363 + */
    16.1 --- a/tools/libxc/xc_vmx_build.c	Mon Sep 19 13:24:13 2005 +0000
    16.2 +++ b/tools/libxc/xc_vmx_build.c	Mon Sep 19 13:24:31 2005 +0000
    16.3 @@ -109,9 +109,9 @@ static void build_e820map(struct mem_map
    16.4  
    16.5  #ifdef __i386__
    16.6  static int zap_mmio_range(int xc_handle, u32 dom,
    16.7 -                            l2_pgentry_32_t *vl2tab,
    16.8 -                            unsigned long mmio_range_start,
    16.9 -                            unsigned long mmio_range_size)
   16.10 +                          l2_pgentry_32_t *vl2tab,
   16.11 +                          unsigned long mmio_range_start,
   16.12 +                          unsigned long mmio_range_size)
   16.13  {
   16.14      unsigned long mmio_addr;
   16.15      unsigned long mmio_range_end = mmio_range_start + mmio_range_size;
   16.16 @@ -123,12 +123,14 @@ static int zap_mmio_range(int xc_handle,
   16.17          vl2e = vl2tab[l2_table_offset(mmio_addr)];
   16.18          if (vl2e == 0)
   16.19              continue;
   16.20 -        vl1tab = xc_map_foreign_range(xc_handle, dom, PAGE_SIZE,
   16.21 -                                PROT_READ|PROT_WRITE, vl2e >> PAGE_SHIFT);
   16.22 -	if (vl1tab == 0) {
   16.23 -	    PERROR("Failed zap MMIO range");
   16.24 -	    return -1;
   16.25 -	}
   16.26 +        vl1tab = xc_map_foreign_range(
   16.27 +            xc_handle, dom, PAGE_SIZE,
   16.28 +            PROT_READ|PROT_WRITE, vl2e >> PAGE_SHIFT);
   16.29 +        if ( vl1tab == 0 )
   16.30 +        {
   16.31 +            PERROR("Failed zap MMIO range");
   16.32 +            return -1;
   16.33 +        }
   16.34          vl1tab[l1_table_offset(mmio_addr)] = 0;
   16.35          munmap(vl1tab, PAGE_SIZE);
   16.36      }
   16.37 @@ -136,114 +138,118 @@ static int zap_mmio_range(int xc_handle,
   16.38  }
   16.39  
   16.40  static int zap_mmio_ranges(int xc_handle, u32 dom,
   16.41 -                            unsigned long l2tab,
   16.42 -                            struct mem_map *mem_mapp)
   16.43 +                           unsigned long l2tab,
   16.44 +                           struct mem_map *mem_mapp)
   16.45  {
   16.46      int i;
   16.47      l2_pgentry_32_t *vl2tab = xc_map_foreign_range(xc_handle, dom, PAGE_SIZE,
   16.48 -                                                PROT_READ|PROT_WRITE,
   16.49 -                                                l2tab >> PAGE_SHIFT);
   16.50 -    if (vl2tab == 0)
   16.51 -    	return -1;
   16.52 -    for (i = 0; i < mem_mapp->nr_map; i++) {
   16.53 -        if ((mem_mapp->map[i].type == E820_IO)
   16.54 -          && (mem_mapp->map[i].caching_attr == MEMMAP_UC))
   16.55 -            if (zap_mmio_range(xc_handle, dom, vl2tab,
   16.56 -	    		mem_mapp->map[i].addr, mem_mapp->map[i].size) == -1)
   16.57 -		return -1;
   16.58 +                                                   PROT_READ|PROT_WRITE,
   16.59 +                                                   l2tab >> PAGE_SHIFT);
   16.60 +    if ( vl2tab == 0 )
   16.61 +        return -1;
   16.62 +
   16.63 +    for ( i = 0; i < mem_mapp->nr_map; i++ )
   16.64 +    {
   16.65 +        if ( (mem_mapp->map[i].type == E820_IO) &&
   16.66 +             (mem_mapp->map[i].caching_attr == MEMMAP_UC) &&
   16.67 +             (zap_mmio_range(xc_handle, dom, vl2tab,
   16.68 +                             mem_mapp->map[i].addr,
   16.69 +                             mem_mapp->map[i].size) == -1) )
   16.70 +            return -1;
   16.71      }
   16.72 +
   16.73      munmap(vl2tab, PAGE_SIZE);
   16.74      return 0;
   16.75  }
   16.76  #else
   16.77  static int zap_mmio_range(int xc_handle, u32 dom,
   16.78 -                           l3_pgentry_t *vl3tab,
   16.79 -                           unsigned long mmio_range_start,
   16.80 -                           unsigned long mmio_range_size)
   16.81 +                          l3_pgentry_t *vl3tab,
   16.82 +                          unsigned long mmio_range_start,
   16.83 +                          unsigned long mmio_range_size)
   16.84  {
   16.85 -   unsigned long mmio_addr;
   16.86 -   unsigned long mmio_range_end = mmio_range_start + mmio_range_size;
   16.87 -   unsigned long vl2e = 0;
   16.88 -   unsigned long vl3e;
   16.89 -   l1_pgentry_t *vl1tab;
   16.90 -   l2_pgentry_t *vl2tab;
   16.91 +    unsigned long mmio_addr;
   16.92 +    unsigned long mmio_range_end = mmio_range_start + mmio_range_size;
   16.93 +    unsigned long vl2e = 0;
   16.94 +    unsigned long vl3e;
   16.95 +    l1_pgentry_t *vl1tab;
   16.96 +    l2_pgentry_t *vl2tab;
   16.97   
   16.98 -   mmio_addr = mmio_range_start & PAGE_MASK;
   16.99 -   for ( ; mmio_addr < mmio_range_end; mmio_addr += PAGE_SIZE )
  16.100 -   {
  16.101 -       vl3e = vl3tab[l3_table_offset(mmio_addr)];
  16.102 -       if ( vl3e == 0 )
  16.103 -           continue;
  16.104 +    mmio_addr = mmio_range_start & PAGE_MASK;
  16.105 +    for ( ; mmio_addr < mmio_range_end; mmio_addr += PAGE_SIZE )
  16.106 +    {
  16.107 +        vl3e = vl3tab[l3_table_offset(mmio_addr)];
  16.108 +        if ( vl3e == 0 )
  16.109 +            continue;
  16.110  
  16.111 -       vl2tab = xc_map_foreign_range(
  16.112 -           xc_handle, dom, PAGE_SIZE, PROT_READ|PROT_WRITE, vl3e>>PAGE_SHIFT);
  16.113 -       if ( vl2tab == NULL )
  16.114 -       {
  16.115 -           PERROR("Failed zap MMIO range");
  16.116 -           return -1;
  16.117 -       }
  16.118 +        vl2tab = xc_map_foreign_range(
  16.119 +            xc_handle, dom, PAGE_SIZE, PROT_READ|PROT_WRITE, vl3e>>PAGE_SHIFT);
  16.120 +        if ( vl2tab == NULL )
  16.121 +        {
  16.122 +            PERROR("Failed zap MMIO range");
  16.123 +            return -1;
  16.124 +        }
  16.125  
  16.126 -       vl2e = vl2tab[l2_table_offset(mmio_addr)];
  16.127 -       if ( vl2e == 0 )
  16.128 -       {
  16.129 -           munmap(vl2tab, PAGE_SIZE);
  16.130 -           continue;
  16.131 -       }
  16.132 +        vl2e = vl2tab[l2_table_offset(mmio_addr)];
  16.133 +        if ( vl2e == 0 )
  16.134 +        {
  16.135 +            munmap(vl2tab, PAGE_SIZE);
  16.136 +            continue;
  16.137 +        }
  16.138  
  16.139 -       vl1tab = xc_map_foreign_range(
  16.140 -           xc_handle, dom, PAGE_SIZE, PROT_READ|PROT_WRITE, vl2e>>PAGE_SHIFT);
  16.141 -       if ( vl1tab == NULL )
  16.142 -       {
  16.143 -           PERROR("Failed zap MMIO range");
  16.144 -           munmap(vl2tab, PAGE_SIZE);
  16.145 -           return -1;
  16.146 -       }
  16.147 +        vl1tab = xc_map_foreign_range(
  16.148 +            xc_handle, dom, PAGE_SIZE, PROT_READ|PROT_WRITE, vl2e>>PAGE_SHIFT);
  16.149 +        if ( vl1tab == NULL )
  16.150 +        {
  16.151 +            PERROR("Failed zap MMIO range");
  16.152 +            munmap(vl2tab, PAGE_SIZE);
  16.153 +            return -1;
  16.154 +        }
  16.155  
  16.156 -       vl1tab[l1_table_offset(mmio_addr)] = 0;
  16.157 -       munmap(vl2tab, PAGE_SIZE);
  16.158 -       munmap(vl1tab, PAGE_SIZE);
  16.159 -   }
  16.160 -   return 0;
  16.161 +        vl1tab[l1_table_offset(mmio_addr)] = 0;
  16.162 +        munmap(vl2tab, PAGE_SIZE);
  16.163 +        munmap(vl1tab, PAGE_SIZE);
  16.164 +    }
  16.165 +    return 0;
  16.166  }
  16.167  
  16.168  static int zap_mmio_ranges(int xc_handle, u32 dom,
  16.169                             unsigned long l3tab,
  16.170                             struct mem_map *mem_mapp)
  16.171  {
  16.172 -   int i;
  16.173 -   l3_pgentry_t *vl3tab = xc_map_foreign_range(xc_handle, dom, PAGE_SIZE,
  16.174 -                                               PROT_READ|PROT_WRITE,
  16.175 -                                               l3tab >> PAGE_SHIFT);
  16.176 -   if (vl3tab == 0)
  16.177 -   	return -1;
  16.178 -   for (i = 0; i < mem_mapp->nr_map; i++) {
  16.179 -       if ((mem_mapp->map[i].type == E820_IO)
  16.180 -         && (mem_mapp->map[i].caching_attr == MEMMAP_UC))
  16.181 -           if (zap_mmio_range(xc_handle, dom, vl3tab,
  16.182 -	    		mem_mapp->map[i].addr, mem_mapp->map[i].size) == -1)
  16.183 -		return -1;
  16.184 -   }
  16.185 -   munmap(vl3tab, PAGE_SIZE);
  16.186 -   return 0;
  16.187 +    int i;
  16.188 +    l3_pgentry_t *vl3tab = xc_map_foreign_range(xc_handle, dom, PAGE_SIZE,
  16.189 +                                                PROT_READ|PROT_WRITE,
  16.190 +                                                l3tab >> PAGE_SHIFT);
  16.191 +    if (vl3tab == 0)
  16.192 +        return -1;
  16.193 +    for (i = 0; i < mem_mapp->nr_map; i++) {
  16.194 +        if ((mem_mapp->map[i].type == E820_IO)
  16.195 +            && (mem_mapp->map[i].caching_attr == MEMMAP_UC))
  16.196 +            if (zap_mmio_range(xc_handle, dom, vl3tab,
  16.197 +                               mem_mapp->map[i].addr, mem_mapp->map[i].size) == -1)
  16.198 +                return -1;
  16.199 +    }
  16.200 +    munmap(vl3tab, PAGE_SIZE);
  16.201 +    return 0;
  16.202  }
  16.203  
  16.204  #endif
  16.205  
  16.206  static int setup_guest(int xc_handle,
  16.207 -                         u32 dom, int memsize,
  16.208 -                         char *image, unsigned long image_size,
  16.209 -                         gzFile initrd_gfd, unsigned long initrd_len,
  16.210 -                         unsigned long nr_pages,
  16.211 -                         vcpu_guest_context_t *ctxt,
  16.212 -                         const char *cmdline,
  16.213 -                         unsigned long shared_info_frame,
  16.214 -                         unsigned int control_evtchn,
  16.215 -                         unsigned long flags,
  16.216 -                         unsigned int vcpus,
  16.217 -                         unsigned int store_evtchn,
  16.218 -                         unsigned long *store_mfn,
  16.219 -                         struct mem_map *mem_mapp
  16.220 -                         )
  16.221 +                       u32 dom, int memsize,
  16.222 +                       char *image, unsigned long image_size,
  16.223 +                       gzFile initrd_gfd, unsigned long initrd_len,
  16.224 +                       unsigned long nr_pages,
  16.225 +                       vcpu_guest_context_t *ctxt,
  16.226 +                       const char *cmdline,
  16.227 +                       unsigned long shared_info_frame,
  16.228 +                       unsigned int control_evtchn,
  16.229 +                       unsigned long flags,
  16.230 +                       unsigned int vcpus,
  16.231 +                       unsigned int store_evtchn,
  16.232 +                       unsigned long *store_mfn,
  16.233 +                       struct mem_map *mem_mapp
  16.234 +    )
  16.235  {
  16.236      l1_pgentry_t *vl1tab=NULL, *vl1e=NULL;
  16.237      l2_pgentry_t *vl2tab=NULL, *vl2e=NULL;
  16.238 @@ -303,7 +309,8 @@ static int setup_guest(int xc_handle,
  16.239  
  16.240      /* memsize is in megabytes */
  16.241      v_end              = memsize << 20;
  16.242 -    vinitrd_end        = v_end - PAGE_SIZE; /* leaving the top 4k untouched for IO requests page use */
  16.243 +    /* leaving the top 4k untouched for IO requests page use */
  16.244 +    vinitrd_end        = v_end - PAGE_SIZE;
  16.245      vinitrd_start      = vinitrd_end - initrd_len;
  16.246      vinitrd_start      = vinitrd_start & (~(PAGE_SIZE - 1));
  16.247  
  16.248 @@ -369,7 +376,7 @@ static int setup_guest(int xc_handle,
  16.249                  goto error_out;
  16.250              }
  16.251              xc_copy_to_domain_page(xc_handle, dom,
  16.252 -                                page_array[i>>PAGE_SHIFT], page);
  16.253 +                                   page_array[i>>PAGE_SHIFT], page);
  16.254          }
  16.255      }
  16.256  
  16.257 @@ -380,14 +387,14 @@ static int setup_guest(int xc_handle,
  16.258      ppt_alloc = (vpt_start - dsi.v_start) >> PAGE_SHIFT;
  16.259      if ( page_array[ppt_alloc] > 0xfffff )
  16.260      {
  16.261 -	unsigned long nmfn;
  16.262 -	nmfn = xc_make_page_below_4G( xc_handle, dom, page_array[ppt_alloc] );
  16.263 -	if ( nmfn == 0 )
  16.264 -	{
  16.265 -	    fprintf(stderr, "Couldn't get a page below 4GB :-(\n");
  16.266 -	    goto error_out;
  16.267 -	}
  16.268 -	page_array[ppt_alloc] = nmfn;
  16.269 +        unsigned long nmfn;
  16.270 +        nmfn = xc_make_page_below_4G( xc_handle, dom, page_array[ppt_alloc] );
  16.271 +        if ( nmfn == 0 )
  16.272 +        {
  16.273 +            fprintf(stderr, "Couldn't get a page below 4GB :-(\n");
  16.274 +            goto error_out;
  16.275 +        }
  16.276 +        page_array[ppt_alloc] = nmfn;
  16.277      }
  16.278  
  16.279  #ifdef __i386__
  16.280 @@ -448,8 +455,8 @@ static int setup_guest(int xc_handle,
  16.281                  munmap(vl2tab, PAGE_SIZE);
  16.282  
  16.283              if ( (vl2tab = xc_map_foreign_range(xc_handle, dom, PAGE_SIZE,
  16.284 -                      PROT_READ|PROT_WRITE,
  16.285 -                      l2tab >> PAGE_SHIFT)) == NULL )
  16.286 +                                                PROT_READ|PROT_WRITE,
  16.287 +                                                l2tab >> PAGE_SHIFT)) == NULL )
  16.288                  goto error_out;
  16.289  
  16.290              memset(vl2tab, 0, PAGE_SIZE);
  16.291 @@ -462,8 +469,8 @@ static int setup_guest(int xc_handle,
  16.292              if ( vl1tab != NULL )
  16.293                  munmap(vl1tab, PAGE_SIZE);
  16.294              if ( (vl1tab = xc_map_foreign_range(xc_handle, dom, PAGE_SIZE,
  16.295 -                      PROT_READ|PROT_WRITE,
  16.296 -                      l1tab >> PAGE_SHIFT)) == NULL )
  16.297 +                                                PROT_READ|PROT_WRITE,
  16.298 +                                                l1tab >> PAGE_SHIFT)) == NULL )
  16.299              {
  16.300                  munmap(vl2tab, PAGE_SIZE);
  16.301                  goto error_out;
  16.302 @@ -485,15 +492,15 @@ static int setup_guest(int xc_handle,
  16.303      for ( count = 0; count < nr_pages; count++ )
  16.304      {
  16.305          if ( xc_add_mmu_update(xc_handle, mmu,
  16.306 -			       (page_array[count] << PAGE_SHIFT) | 
  16.307 -			       MMU_MACHPHYS_UPDATE, count) )
  16.308 -	    goto error_out;
  16.309 +                               (page_array[count] << PAGE_SHIFT) | 
  16.310 +                               MMU_MACHPHYS_UPDATE, count) )
  16.311 +            goto error_out;
  16.312      }
  16.313      
  16.314  
  16.315      if ((boot_paramsp = xc_map_foreign_range(
  16.316 -		xc_handle, dom, PAGE_SIZE, PROT_READ|PROT_WRITE,
  16.317 -		page_array[(vboot_params_start-dsi.v_start)>>PAGE_SHIFT])) == 0)
  16.318 +        xc_handle, dom, PAGE_SIZE, PROT_READ|PROT_WRITE,
  16.319 +        page_array[(vboot_params_start-dsi.v_start)>>PAGE_SHIFT])) == 0)
  16.320          goto error_out;
  16.321  
  16.322      memset(boot_paramsp, 0, sizeof(*boot_paramsp));
  16.323 @@ -558,9 +565,9 @@ static int setup_guest(int xc_handle,
  16.324  #if defined (__i386__)
  16.325      if (zap_mmio_ranges(xc_handle, dom, l2tab, mem_mapp) == -1)
  16.326  #else
  16.327 -    if (zap_mmio_ranges(xc_handle, dom, l3tab, mem_mapp) == -1)
  16.328 +        if (zap_mmio_ranges(xc_handle, dom, l3tab, mem_mapp) == -1)
  16.329  #endif
  16.330 -    	goto error_out;
  16.331 +            goto error_out;
  16.332      boot_paramsp->e820_map_nr = mem_mapp->nr_map;
  16.333      for (i=0; i<mem_mapp->nr_map; i++) {
  16.334          boot_paramsp->e820_map[i].addr = mem_mapp->map[i].addr; 
  16.335 @@ -572,9 +579,9 @@ static int setup_guest(int xc_handle,
  16.336      munmap(boot_paramsp, PAGE_SIZE); 
  16.337  
  16.338      if ((boot_gdtp = xc_map_foreign_range(
  16.339 -		xc_handle, dom, PAGE_SIZE, PROT_READ|PROT_WRITE,
  16.340 -		page_array[(vboot_gdt_start-dsi.v_start)>>PAGE_SHIFT])) == 0)
  16.341 -	goto error_out;
  16.342 +        xc_handle, dom, PAGE_SIZE, PROT_READ|PROT_WRITE,
  16.343 +        page_array[(vboot_gdt_start-dsi.v_start)>>PAGE_SHIFT])) == 0)
  16.344 +        goto error_out;
  16.345      memset(boot_gdtp, 0, PAGE_SIZE);
  16.346      boot_gdtp[12*4 + 0] = boot_gdtp[13*4 + 0] = 0xffff; /* limit */
  16.347      boot_gdtp[12*4 + 1] = boot_gdtp[13*4 + 1] = 0x0000; /* base */
  16.348 @@ -584,9 +591,9 @@ static int setup_guest(int xc_handle,
  16.349  
  16.350      /* shared_info page starts its life empty. */
  16.351      if ((shared_info = xc_map_foreign_range(
  16.352 -		xc_handle, dom, PAGE_SIZE, PROT_READ|PROT_WRITE,
  16.353 -		shared_info_frame)) == 0)
  16.354 -	goto error_out;
  16.355 +        xc_handle, dom, PAGE_SIZE, PROT_READ|PROT_WRITE,
  16.356 +        shared_info_frame)) == 0)
  16.357 +        goto error_out;
  16.358      memset(shared_info, 0, sizeof(shared_info_t));
  16.359      /* Mask all upcalls... */
  16.360      for ( i = 0; i < MAX_VIRT_CPUS; i++ )
  16.361 @@ -595,9 +602,9 @@ static int setup_guest(int xc_handle,
  16.362  
  16.363      /* Populate the event channel port in the shared page */
  16.364      if ((sp = (shared_iopage_t *) xc_map_foreign_range(
  16.365 -		xc_handle, dom, PAGE_SIZE, PROT_READ|PROT_WRITE,
  16.366 -		page_array[shared_page_frame])) == 0)
  16.367 -	goto error_out;
  16.368 +        xc_handle, dom, PAGE_SIZE, PROT_READ|PROT_WRITE,
  16.369 +        page_array[shared_page_frame])) == 0)
  16.370 +        goto error_out;
  16.371      memset(sp, 0, PAGE_SIZE);
  16.372      sp->sp_global.eport = control_evtchn;
  16.373      munmap(sp, PAGE_SIZE);
  16.374 @@ -622,7 +629,7 @@ static int setup_guest(int xc_handle,
  16.375      ctxt->user_regs.edx = vboot_gdt_start;
  16.376      ctxt->user_regs.eax = 0x800;
  16.377      ctxt->user_regs.esp = vboot_gdt_end;
  16.378 -    ctxt->user_regs.ebx = 0;	/* startup_32 expects this to be 0 to signal boot cpu */
  16.379 +    ctxt->user_regs.ebx = 0; /* startup_32 expects this to be 0 to signal boot cpu */
  16.380      ctxt->user_regs.ecx = mem_mapp->nr_map;
  16.381      ctxt->user_regs.esi = vboot_params_start;
  16.382      ctxt->user_regs.edi = vboot_params_start + 0x2d0;
  16.383 @@ -646,9 +653,9 @@ static int vmx_identify(void)
  16.384  
  16.385  #ifdef __i386__
  16.386      __asm__ __volatile__ ("pushl %%ebx; cpuid; popl %%ebx" 
  16.387 -			  : "=a" (eax), "=c" (ecx) 
  16.388 -			  : "0" (1) 
  16.389 -			  : "dx");
  16.390 +                          : "=a" (eax), "=c" (ecx) 
  16.391 +                          : "0" (1) 
  16.392 +                          : "dx");
  16.393  #elif defined __x86_64__
  16.394      __asm__ __volatile__ ("pushq %%rbx; cpuid; popq %%rbx"
  16.395                            : "=a" (eax), "=c" (ecx)
  16.396 @@ -663,17 +670,17 @@ static int vmx_identify(void)
  16.397  }
  16.398  
  16.399  int xc_vmx_build(int xc_handle,
  16.400 -                   u32 domid,
  16.401 -                   int memsize,
  16.402 -                   const char *image_name,
  16.403 -                   struct mem_map *mem_mapp,
  16.404 -                   const char *ramdisk_name,
  16.405 -                   const char *cmdline,
  16.406 -                   unsigned int control_evtchn,
  16.407 -                   unsigned long flags,
  16.408 -                   unsigned int vcpus,
  16.409 -                   unsigned int store_evtchn,
  16.410 -                   unsigned long *store_mfn)
  16.411 +                 u32 domid,
  16.412 +                 int memsize,
  16.413 +                 const char *image_name,
  16.414 +                 struct mem_map *mem_mapp,
  16.415 +                 const char *ramdisk_name,
  16.416 +                 const char *cmdline,
  16.417 +                 unsigned int control_evtchn,
  16.418 +                 unsigned long flags,
  16.419 +                 unsigned int vcpus,
  16.420 +                 unsigned int store_evtchn,
  16.421 +                 unsigned long *store_mfn)
  16.422  {
  16.423      dom0_op_t launch_op, op;
  16.424      int initrd_fd = -1;
  16.425 @@ -745,11 +752,11 @@ int xc_vmx_build(int xc_handle,
  16.426      }
  16.427  
  16.428      if ( setup_guest(xc_handle, domid, memsize, image, image_size, 
  16.429 -                       initrd_gfd, initrd_size, nr_pages, 
  16.430 -                       ctxt, cmdline,
  16.431 -                       op.u.getdomaininfo.shared_info_frame,
  16.432 -                       control_evtchn, flags, vcpus, store_evtchn, store_mfn,
  16.433 -                       mem_mapp) < 0 )
  16.434 +                     initrd_gfd, initrd_size, nr_pages, 
  16.435 +                     ctxt, cmdline,
  16.436 +                     op.u.getdomaininfo.shared_info_frame,
  16.437 +                     control_evtchn, flags, vcpus, store_evtchn, store_mfn,
  16.438 +                     mem_mapp) < 0 )
  16.439      {
  16.440          ERROR("Error constructing guest OS");
  16.441          goto error_out;
  16.442 @@ -780,8 +787,8 @@ int xc_vmx_build(int xc_handle,
  16.443  
  16.444      /* Ring 1 stack is the initial stack. */
  16.445  /*
  16.446 -    ctxt->kernel_ss = FLAT_KERNEL_DS;
  16.447 -    ctxt->kernel_sp = vstartinfo_start;
  16.448 +  ctxt->kernel_ss = FLAT_KERNEL_DS;
  16.449 +  ctxt->kernel_sp = vstartinfo_start;
  16.450  */
  16.451      /* No debugging. */
  16.452      memset(ctxt->debugreg, 0, sizeof(ctxt->debugreg));
  16.453 @@ -861,7 +868,7 @@ static int parseelfimage(char *elfbase,
  16.454          return -EINVAL;
  16.455      }
  16.456      shdr = (Elf32_Shdr *)(elfbase + ehdr->e_shoff + 
  16.457 -                        (ehdr->e_shstrndx*ehdr->e_shentsize));
  16.458 +                          (ehdr->e_shstrndx*ehdr->e_shentsize));
  16.459      shstrtab = elfbase + shdr->sh_offset;
  16.460      
  16.461      for ( h = 0; h < ehdr->e_phnum; h++ ) 
  16.462 @@ -916,9 +923,9 @@ loadelfimage(
  16.463          {
  16.464              pa = (phdr->p_paddr + done) - dsi->v_start - LINUX_PAGE_OFFSET;
  16.465              if ((va = xc_map_foreign_range(
  16.466 -			xch, dom, PAGE_SIZE, PROT_WRITE,
  16.467 -			parray[pa>>PAGE_SHIFT])) == 0)
  16.468 -		return -1;
  16.469 +                xch, dom, PAGE_SIZE, PROT_WRITE,
  16.470 +                parray[pa>>PAGE_SHIFT])) == 0)
  16.471 +                return -1;
  16.472              chunksz = phdr->p_filesz - done;
  16.473              if ( chunksz > (PAGE_SIZE - (pa & (PAGE_SIZE-1))) )
  16.474                  chunksz = PAGE_SIZE - (pa & (PAGE_SIZE-1));
  16.475 @@ -931,9 +938,9 @@ loadelfimage(
  16.476          {
  16.477              pa = (phdr->p_paddr + done) - dsi->v_start - LINUX_PAGE_OFFSET;
  16.478              if ((va = xc_map_foreign_range(
  16.479 -			xch, dom, PAGE_SIZE, PROT_WRITE,
  16.480 -			parray[pa>>PAGE_SHIFT])) == 0)
  16.481 -		return -1;
  16.482 +                xch, dom, PAGE_SIZE, PROT_WRITE,
  16.483 +                parray[pa>>PAGE_SHIFT])) == 0)
  16.484 +                return -1;
  16.485              chunksz = phdr->p_memsz - done;
  16.486              if ( chunksz > (PAGE_SIZE - (pa & (PAGE_SIZE-1))) )
  16.487                  chunksz = PAGE_SIZE - (pa & (PAGE_SIZE-1));
  16.488 @@ -944,3 +951,13 @@ loadelfimage(
  16.489  
  16.490      return 0;
  16.491  }
  16.492 +
  16.493 +/*
  16.494 + * Local variables:
  16.495 + * mode: C
  16.496 + * c-set-style: "BSD"
  16.497 + * c-basic-offset: 4
  16.498 + * tab-width: 4
  16.499 + * indent-tabs-mode: nil
  16.500 + * End:
  16.501 + */