ia64/xen-unstable

changeset 6928:619e3d6f01b3

Re-indent libxc to avoid hard tabs. Also, fix the PAE
domain builder to correctly write PTEs that map pages
above 4GB.

Signed-off-by: Keir Fraser <keir@xensource.com>
author kaf24@firebug.cl.cam.ac.uk
date Mon Sep 19 11:06:05 2005 +0000 (2005-09-19)
parents cedb89d6b707
children 3133e64d0462
files 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
line diff
     1.1 --- a/tools/libxc/xc_core.c	Mon Sep 19 09:14:41 2005 +0000
     1.2 +++ b/tools/libxc/xc_core.c	Mon Sep 19 11:06:05 2005 +0000
     1.3 @@ -11,10 +11,10 @@
     1.4  
     1.5  static int
     1.6  copy_from_domain_page(int xc_handle,
     1.7 -		      u32 domid,
     1.8 -		      unsigned long *page_array,
     1.9 -		      unsigned long src_pfn,
    1.10 -		      void *dst_page)
    1.11 +                      u32 domid,
    1.12 +                      unsigned long *page_array,
    1.13 +                      unsigned long src_pfn,
    1.14 +                      void *dst_page)
    1.15  {
    1.16      void *vaddr = xc_map_foreign_range(
    1.17          xc_handle, domid, PAGE_SIZE, PROT_READ, page_array[src_pfn]);
    1.18 @@ -27,90 +27,100 @@ copy_from_domain_page(int xc_handle,
    1.19  
    1.20  int 
    1.21  xc_domain_dumpcore(int xc_handle,
    1.22 -		   u32 domid,
    1.23 -		   const char *corename)
    1.24 +                   u32 domid,
    1.25 +                   const char *corename)
    1.26  {
    1.27 -	unsigned long nr_pages;
    1.28 -	unsigned long *page_array;
    1.29 -	xc_dominfo_t info;
    1.30 -	int i, j, vcpu_map_size, dump_fd;
    1.31 -	char *dump_mem, *dump_mem_start = NULL;
    1.32 -	struct xc_core_header header;
    1.33 -	vcpu_guest_context_t     ctxt[MAX_VIRT_CPUS];
    1.34 +    unsigned long nr_pages;
    1.35 +    unsigned long *page_array;
    1.36 +    xc_dominfo_t info;
    1.37 +    int i, j, vcpu_map_size, dump_fd;
    1.38 +    char *dump_mem, *dump_mem_start = NULL;
    1.39 +    struct xc_core_header header;
    1.40 +    vcpu_guest_context_t     ctxt[MAX_VIRT_CPUS];
    1.41  
    1.42 -	
    1.43 -	if ((dump_fd = open(corename, O_CREAT|O_RDWR, S_IWUSR|S_IRUSR)) < 0) {
    1.44 -		PERROR("Could not open corefile %s: %s", corename, strerror(errno));
    1.45 -		goto error_out;
    1.46 -	}
    1.47 -	
    1.48 -	if ((dump_mem_start = malloc(DUMP_INCREMENT*PAGE_SIZE)) == NULL) {
    1.49 -		PERROR("Could not allocate dump_mem");
    1.50 -		goto error_out;
    1.51 -	}
    1.52 -	
    1.53 -	if (xc_domain_getinfo(xc_handle, domid, 1, &info) != 1) {
    1.54 -		PERROR("Could not get info for domain");
    1.55 -		goto error_out;
    1.56 -	}
    1.57 -	
    1.58 -	vcpu_map_size =  sizeof(info.vcpu_to_cpu) / sizeof(info.vcpu_to_cpu[0]);
    1.59 + 
    1.60 +    if ((dump_fd = open(corename, O_CREAT|O_RDWR, S_IWUSR|S_IRUSR)) < 0) {
    1.61 +        PERROR("Could not open corefile %s: %s", corename, strerror(errno));
    1.62 +        goto error_out;
    1.63 +    }
    1.64 + 
    1.65 +    if ((dump_mem_start = malloc(DUMP_INCREMENT*PAGE_SIZE)) == NULL) {
    1.66 +        PERROR("Could not allocate dump_mem");
    1.67 +        goto error_out;
    1.68 +    }
    1.69 + 
    1.70 +    if (xc_domain_getinfo(xc_handle, domid, 1, &info) != 1) {
    1.71 +        PERROR("Could not get info for domain");
    1.72 +        goto error_out;
    1.73 +    }
    1.74 + 
    1.75 +    vcpu_map_size =  sizeof(info.vcpu_to_cpu) / sizeof(info.vcpu_to_cpu[0]);
    1.76  
    1.77 -	for (i = 0, j = 0; i < vcpu_map_size; i++) {
    1.78 -		if (info.vcpu_to_cpu[i] == -1) {
    1.79 -			continue;
    1.80 -		}
    1.81 -		if (xc_domain_get_vcpu_context(xc_handle, domid, i, &ctxt[j])) {
    1.82 -			PERROR("Could not get all vcpu contexts for domain");
    1.83 -			goto error_out;
    1.84 -		}
    1.85 -		j++;
    1.86 -	}
    1.87 -	
    1.88 -	nr_pages = info.nr_pages;
    1.89 +    for (i = 0, j = 0; i < vcpu_map_size; i++) {
    1.90 +        if (info.vcpu_to_cpu[i] == -1) {
    1.91 +            continue;
    1.92 +        }
    1.93 +        if (xc_domain_get_vcpu_context(xc_handle, domid, i, &ctxt[j])) {
    1.94 +            PERROR("Could not get all vcpu contexts for domain");
    1.95 +            goto error_out;
    1.96 +        }
    1.97 +        j++;
    1.98 +    }
    1.99 + 
   1.100 +    nr_pages = info.nr_pages;
   1.101  
   1.102 -	header.xch_magic = 0xF00FEBED; 
   1.103 -	header.xch_nr_vcpus = info.vcpus;
   1.104 -	header.xch_nr_pages = nr_pages;
   1.105 -	header.xch_ctxt_offset = sizeof(struct xc_core_header);
   1.106 -	header.xch_index_offset = sizeof(struct xc_core_header) +
   1.107 -	    sizeof(vcpu_guest_context_t)*info.vcpus;
   1.108 -	header.xch_pages_offset = round_pgup(sizeof(struct xc_core_header) +
   1.109 -	    (sizeof(vcpu_guest_context_t) * info.vcpus) + 
   1.110 -	    (nr_pages * sizeof(unsigned long)));
   1.111 +    header.xch_magic = 0xF00FEBED; 
   1.112 +    header.xch_nr_vcpus = info.vcpus;
   1.113 +    header.xch_nr_pages = nr_pages;
   1.114 +    header.xch_ctxt_offset = sizeof(struct xc_core_header);
   1.115 +    header.xch_index_offset = sizeof(struct xc_core_header) +
   1.116 +        sizeof(vcpu_guest_context_t)*info.vcpus;
   1.117 +    header.xch_pages_offset = round_pgup(sizeof(struct xc_core_header) +
   1.118 +                                         (sizeof(vcpu_guest_context_t) * info.vcpus) + 
   1.119 +                                         (nr_pages * sizeof(unsigned long)));
   1.120  
   1.121 -	write(dump_fd, &header, sizeof(struct xc_core_header));
   1.122 -	write(dump_fd, &ctxt, sizeof(ctxt[0]) * info.vcpus);
   1.123 +    write(dump_fd, &header, sizeof(struct xc_core_header));
   1.124 +    write(dump_fd, &ctxt, sizeof(ctxt[0]) * info.vcpus);
   1.125  
   1.126 -	if ((page_array = malloc(nr_pages * sizeof(unsigned long))) == NULL) {
   1.127 -	    printf("Could not allocate memory\n");
   1.128 -	    goto error_out;
   1.129 -	}
   1.130 -	if (xc_get_pfn_list(xc_handle, domid, page_array, nr_pages) != nr_pages) {
   1.131 -	    printf("Could not get the page frame list\n");
   1.132 -	    goto error_out;
   1.133 -	}
   1.134 -	write(dump_fd, page_array, nr_pages * sizeof(unsigned long));
   1.135 -	lseek(dump_fd, header.xch_pages_offset, SEEK_SET);
   1.136 -	for (dump_mem = dump_mem_start, i = 0; i < nr_pages; i++) {
   1.137 -		copy_from_domain_page(xc_handle, domid, page_array, i, dump_mem);
   1.138 -		dump_mem += PAGE_SIZE;
   1.139 -		if (((i + 1) % DUMP_INCREMENT == 0) || (i + 1) == nr_pages) {
   1.140 -			if (write(dump_fd, dump_mem_start, dump_mem - dump_mem_start) < 
   1.141 -			    dump_mem - dump_mem_start) {
   1.142 -				PERROR("Partial write, file system full?");
   1.143 -				goto error_out;
   1.144 -			}
   1.145 -			dump_mem = dump_mem_start;
   1.146 -		}
   1.147 -	}
   1.148 +    if ((page_array = malloc(nr_pages * sizeof(unsigned long))) == NULL) {
   1.149 +        printf("Could not allocate memory\n");
   1.150 +        goto error_out;
   1.151 +    }
   1.152 +    if (xc_get_pfn_list(xc_handle, domid, page_array, nr_pages) != nr_pages) {
   1.153 +        printf("Could not get the page frame list\n");
   1.154 +        goto error_out;
   1.155 +    }
   1.156 +    write(dump_fd, page_array, nr_pages * sizeof(unsigned long));
   1.157 +    lseek(dump_fd, header.xch_pages_offset, SEEK_SET);
   1.158 +    for (dump_mem = dump_mem_start, i = 0; i < nr_pages; i++) {
   1.159 +        copy_from_domain_page(xc_handle, domid, page_array, i, dump_mem);
   1.160 +        dump_mem += PAGE_SIZE;
   1.161 +        if (((i + 1) % DUMP_INCREMENT == 0) || (i + 1) == nr_pages) {
   1.162 +            if (write(dump_fd, dump_mem_start, dump_mem - dump_mem_start) < 
   1.163 +                dump_mem - dump_mem_start) {
   1.164 +                PERROR("Partial write, file system full?");
   1.165 +                goto error_out;
   1.166 +            }
   1.167 +            dump_mem = dump_mem_start;
   1.168 +        }
   1.169 +    }
   1.170  
   1.171 -	close(dump_fd);
   1.172 -	free(dump_mem_start);
   1.173 -	return 0;
   1.174 +    close(dump_fd);
   1.175 +    free(dump_mem_start);
   1.176 +    return 0;
   1.177   error_out:
   1.178 -	if (dump_fd != -1)
   1.179 -		close(dump_fd);
   1.180 -	free(dump_mem_start);
   1.181 -	return -1;
   1.182 +    if (dump_fd != -1)
   1.183 +        close(dump_fd);
   1.184 +    free(dump_mem_start);
   1.185 +    return -1;
   1.186  }
   1.187 +
   1.188 +/*
   1.189 + * Local variables:
   1.190 + * mode: C
   1.191 + * c-set-style: "BSD"
   1.192 + * c-basic-offset: 4
   1.193 + * tab-width: 4
   1.194 + * indent-tabs-mode: nil
   1.195 + * End:
   1.196 + */
     2.1 --- a/tools/libxc/xc_domain.c	Mon Sep 19 09:14:41 2005 +0000
     2.2 +++ b/tools/libxc/xc_domain.c	Mon Sep 19 11:06:05 2005 +0000
     2.3 @@ -265,7 +265,7 @@ int xc_domain_memory_increase_reservatio
     2.4                                            unsigned long nr_extents,
     2.5                                            unsigned int extent_order,
     2.6                                            unsigned int address_bits,
     2.7 -					  unsigned long *extent_start)
     2.8 +                                          unsigned long *extent_start)
     2.9  {
    2.10      int err;
    2.11      struct xen_memory_reservation reservation = {
    2.12 @@ -296,7 +296,7 @@ int xc_domain_memory_decrease_reservatio
    2.13                                            u32 domid, 
    2.14                                            unsigned long nr_extents,
    2.15                                            unsigned int extent_order,
    2.16 -					  unsigned long *extent_start)
    2.17 +                                          unsigned long *extent_start)
    2.18  {
    2.19      int err;
    2.20      struct xen_memory_reservation reservation = {
    2.21 @@ -328,3 +328,13 @@ int xc_domain_memory_decrease_reservatio
    2.22  
    2.23      return err;
    2.24  }
    2.25 +
    2.26 +/*
    2.27 + * Local variables:
    2.28 + * mode: C
    2.29 + * c-set-style: "BSD"
    2.30 + * c-basic-offset: 4
    2.31 + * tab-width: 4
    2.32 + * indent-tabs-mode: nil
    2.33 + * End:
    2.34 + */
     3.1 --- a/tools/libxc/xc_ia64_stubs.c	Mon Sep 19 09:14:41 2005 +0000
     3.2 +++ b/tools/libxc/xc_ia64_stubs.c	Mon Sep 19 11:06:05 2005 +0000
     3.3 @@ -9,8 +9,8 @@ int xc_linux_save(int xc_handle, int io_
     3.4  }
     3.5  
     3.6  int xc_linux_restore(int xc_handle, int io_fd, u32 dom, unsigned long nr_pfns,
     3.7 -		     unsigned int store_evtchn, unsigned long *store_mfn,
     3.8 -		     unsigned int console_evtchn, unsigned long *console_mfn)
     3.9 +                     unsigned int store_evtchn, unsigned long *store_mfn,
    3.10 +                     unsigned int console_evtchn, unsigned long *console_mfn)
    3.11  {
    3.12      PERROR("xc_linux_restore not implemented\n");
    3.13      return -1;
    3.14 @@ -44,3 +44,12 @@ xc_plan9_build(int xc_handle,
    3.15      return -1;
    3.16  }
    3.17  
    3.18 +/*
    3.19 + * Local variables:
    3.20 + * mode: C
    3.21 + * c-set-style: "BSD"
    3.22 + * c-basic-offset: 4
    3.23 + * tab-width: 4
    3.24 + * indent-tabs-mode: nil
    3.25 + * End:
    3.26 + */
     4.1 --- a/tools/libxc/xc_linux_build.c	Mon Sep 19 09:14:41 2005 +0000
     4.2 +++ b/tools/libxc/xc_linux_build.c	Mon Sep 19 11:06:05 2005 +0000
     4.3 @@ -13,7 +13,6 @@
     4.4  #define ELFSIZE 64
     4.5  #endif
     4.6  
     4.7 -
     4.8  #include "xc_elf.h"
     4.9  #include "xc_aout9.h"
    4.10  #include <stdlib.h>
    4.11 @@ -33,6 +32,13 @@
    4.12  #define L4_PROT (_PAGE_PRESENT|_PAGE_RW|_PAGE_ACCESSED|_PAGE_DIRTY|_PAGE_USER)
    4.13  #endif
    4.14  
    4.15 +#ifdef __ia64__
    4.16 +#define already_built(ctxt) (0)
    4.17 +#define get_tot_pages xc_get_max_pages
    4.18 +#else
    4.19 +#define already_built(ctxt) ((ctxt)->ctrlreg[3] != 0)
    4.20 +#define get_tot_pages xc_get_tot_pages
    4.21 +#endif
    4.22  
    4.23  #define round_pgup(_p)    (((_p)+(PAGE_SIZE-1))&PAGE_MASK)
    4.24  #define round_pgdown(_p)  ((_p)&PAGE_MASK)
    4.25 @@ -47,7 +53,7 @@ static int probeimageformat(char *image,
    4.26  {
    4.27      if ( probe_elf(image, image_size, load_funcs) &&
    4.28           probe_bin(image, image_size, load_funcs) &&
    4.29 -	 probe_aout9(image, image_size, load_funcs) )
    4.30 +         probe_aout9(image, image_size, load_funcs) )
    4.31      {
    4.32          ERROR( "Unrecognized image format" );
    4.33          return -EINVAL;
    4.34 @@ -56,27 +62,27 @@ static int probeimageformat(char *image,
    4.35      return 0;
    4.36  }
    4.37  
    4.38 -#define alloc_pt(ltab, vltab) \
    4.39 -        ltab = (unsigned long long)(page_array[ppt_alloc++]) << PAGE_SHIFT; \
    4.40 -        if (vltab != NULL) { \
    4.41 -            munmap(vltab, PAGE_SIZE); \
    4.42 -        } \
    4.43 -        if ((vltab = xc_map_foreign_range(xc_handle, dom, PAGE_SIZE, \
    4.44 -                          PROT_READ|PROT_WRITE, \
    4.45 -                          ltab >> PAGE_SHIFT)) == NULL) { \
    4.46 -            goto error_out; \
    4.47 -        } \
    4.48 -        memset(vltab, 0, PAGE_SIZE);
    4.49 +#define alloc_pt(ltab, vltab)                                           \
    4.50 +do {                                                                    \
    4.51 +    ltab = (u64)page_array[ppt_alloc++] << PAGE_SHIFT;                  \
    4.52 +    if ( vltab != NULL )                                                \
    4.53 +        munmap(vltab, PAGE_SIZE);                                       \
    4.54 +    if ( (vltab = xc_map_foreign_range(xc_handle, dom, PAGE_SIZE,       \
    4.55 +                                       PROT_READ|PROT_WRITE,            \
    4.56 +                                       ltab >> PAGE_SHIFT)) == NULL )   \
    4.57 +        goto error_out;                                                 \
    4.58 +    memset(vltab, 0, PAGE_SIZE);                                        \
    4.59 +} while ( 0 )
    4.60  
    4.61  #if defined(__i386__)
    4.62  
    4.63  static int setup_pg_tables(int xc_handle, u32 dom,
    4.64 -			   vcpu_guest_context_t *ctxt,
    4.65 -			   unsigned long dsi_v_start,
    4.66 -			   unsigned long v_end,
    4.67 -			   unsigned long *page_array,
    4.68 -			   unsigned long vpt_start,
    4.69 -			   unsigned long vpt_end)
    4.70 +                           vcpu_guest_context_t *ctxt,
    4.71 +                           unsigned long dsi_v_start,
    4.72 +                           unsigned long v_end,
    4.73 +                           unsigned long *page_array,
    4.74 +                           unsigned long vpt_start,
    4.75 +                           unsigned long vpt_end)
    4.76  {
    4.77      l1_pgentry_t *vl1tab=NULL, *vl1e=NULL;
    4.78      l2_pgentry_t *vl2tab=NULL, *vl2e=NULL;
    4.79 @@ -90,11 +96,11 @@ static int setup_pg_tables(int xc_handle
    4.80      vl2e = &vl2tab[l2_table_offset(dsi_v_start)];
    4.81      ctxt->ctrlreg[3] = l2tab;
    4.82  
    4.83 -    for ( count = 0; count < ((v_end-dsi_v_start)>>PAGE_SHIFT); count++ )
    4.84 +    for ( count = 0; count < ((v_end - dsi_v_start) >> PAGE_SHIFT); count++ )
    4.85      {    
    4.86          if ( ((unsigned long)vl1e & (PAGE_SIZE-1)) == 0 )
    4.87          {
    4.88 -	    alloc_pt(l1tab, vl1tab);
    4.89 +            alloc_pt(l1tab, vl1tab);
    4.90              vl1e = &vl1tab[l1_table_offset(dsi_v_start + (count<<PAGE_SHIFT))];
    4.91              *vl2e++ = l1tab | L2_PROT;
    4.92          }
    4.93 @@ -111,79 +117,67 @@ static int setup_pg_tables(int xc_handle
    4.94  
    4.95   error_out:
    4.96      if (vl1tab)
    4.97 -	munmap(vl1tab, PAGE_SIZE);
    4.98 +        munmap(vl1tab, PAGE_SIZE);
    4.99      if (vl2tab)
   4.100 -	munmap(vl2tab, PAGE_SIZE);
   4.101 +        munmap(vl2tab, PAGE_SIZE);
   4.102      return -1;
   4.103  }
   4.104  
   4.105  static int setup_pg_tables_pae(int xc_handle, u32 dom,
   4.106 -			       vcpu_guest_context_t *ctxt,
   4.107 -			       unsigned long dsi_v_start,
   4.108 -			       unsigned long v_end,
   4.109 -			       unsigned long *page_array,
   4.110 -			       unsigned long vpt_start,
   4.111 -			       unsigned long vpt_end)
   4.112 +                               vcpu_guest_context_t *ctxt,
   4.113 +                               unsigned long dsi_v_start,
   4.114 +                               unsigned long v_end,
   4.115 +                               unsigned long *page_array,
   4.116 +                               unsigned long vpt_start,
   4.117 +                               unsigned long vpt_end)
   4.118  {
   4.119 -    l1_pgentry_64_t *vl1tab=NULL, *vl1e=NULL;
   4.120 -    l2_pgentry_64_t *vl2tab=NULL, *vl2e=NULL;
   4.121 -    l3_pgentry_64_t *vl3tab=NULL, *vl3e=NULL;
   4.122 -    unsigned long long l1tab = 0;
   4.123 -    unsigned long long l2tab = 0;
   4.124 -    unsigned long long l3tab = 0;
   4.125 -    unsigned long ppt_alloc;
   4.126 -    unsigned long count;
   4.127 +    l1_pgentry_64_t *vl1tab = NULL, *vl1e = NULL;
   4.128 +    l2_pgentry_64_t *vl2tab = NULL, *vl2e = NULL;
   4.129 +    l3_pgentry_64_t *vl3tab = NULL, *vl3e = NULL;
   4.130 +    u64 l1tab, l2tab, l3tab;
   4.131 +    unsigned long ppt_alloc, count, nmfn;
   4.132  
   4.133      /* First allocate page for page dir. */
   4.134      ppt_alloc = (vpt_start - dsi_v_start) >> PAGE_SHIFT;
   4.135  
   4.136      if ( page_array[ppt_alloc] > 0xfffff )
   4.137      {
   4.138 -	unsigned long nmfn;
   4.139 -	nmfn = xc_make_page_below_4G( xc_handle, dom, page_array[ppt_alloc] );
   4.140 -	if ( nmfn == 0 )
   4.141 -	{
   4.142 -	    fprintf(stderr, "Couldn't get a page below 4GB :-(\n");
   4.143 -	    goto error_out;
   4.144 -	}
   4.145 -	page_array[ppt_alloc] = nmfn;
   4.146 +        nmfn = xc_make_page_below_4G(xc_handle, dom, page_array[ppt_alloc]);
   4.147 +        if ( nmfn == 0 )
   4.148 +        {
   4.149 +            fprintf(stderr, "Couldn't get a page below 4GB :-(\n");
   4.150 +            goto error_out;
   4.151 +        }
   4.152 +        page_array[ppt_alloc] = nmfn;
   4.153      }
   4.154  
   4.155      alloc_pt(l3tab, vl3tab);
   4.156      vl3e = &vl3tab[l3_table_offset_pae(dsi_v_start)];
   4.157      ctxt->ctrlreg[3] = l3tab;
   4.158  
   4.159 -    if(l3tab>0xfffff000ULL)
   4.160 -    {
   4.161 -        fprintf(stderr,"L3TAB = %llx above 4GB!\n",l3tab);
   4.162 -        goto error_out;
   4.163 -    }
   4.164 - 
   4.165 -    for ( count = 0; count < ((v_end-dsi_v_start)>>PAGE_SHIFT); count++)
   4.166 +    for ( count = 0; count < ((v_end - dsi_v_start) >> PAGE_SHIFT); count++)
   4.167      {
   4.168          if ( !((unsigned long)vl1e & (PAGE_SIZE-1)) )
   4.169          {
   4.170 +            if ( !((unsigned long)vl2e & (PAGE_SIZE-1)) )
   4.171 +            {
   4.172 +                alloc_pt(l2tab, vl2tab);
   4.173 +                vl2e = &vl2tab[l2_table_offset_pae(
   4.174 +                    dsi_v_start + (count << PAGE_SHIFT))];
   4.175 +                *vl3e++ = l2tab | L3_PROT;
   4.176 +            }
   4.177 +
   4.178              alloc_pt(l1tab, vl1tab);
   4.179 -            
   4.180 -                if ( !((unsigned long)vl2e & (PAGE_SIZE-1)) )
   4.181 -                {
   4.182 -                    alloc_pt(l2tab, vl2tab);
   4.183 -                    vl2e = &vl2tab[l2_table_offset_pae(dsi_v_start + (count<<PAGE_SHIFT))];
   4.184 -                    *vl3e = l2tab | L3_PROT;
   4.185 -                    vl3e++;
   4.186 -                }
   4.187 -            vl1e = &vl1tab[l1_table_offset_pae(dsi_v_start + (count<<PAGE_SHIFT))];
   4.188 -            *vl2e = l1tab | L2_PROT;
   4.189 -            vl2e++;
   4.190 +            vl1e = &vl1tab[l1_table_offset_pae(
   4.191 +                dsi_v_start + (count << PAGE_SHIFT))];
   4.192 +            *vl2e++ = l1tab | L2_PROT;
   4.193          }
   4.194          
   4.195 -        *vl1e = (page_array[count] << PAGE_SHIFT) | L1_PROT;
   4.196 +        *vl1e = ((u64)page_array[count] << PAGE_SHIFT) | L1_PROT;
   4.197          if ( (count >= ((vpt_start-dsi_v_start)>>PAGE_SHIFT)) &&
   4.198 -	     (count <  ((vpt_end  -dsi_v_start)>>PAGE_SHIFT)) ) 
   4.199 -        {
   4.200 -	    *vl1e &= ~_PAGE_RW;
   4.201 -        }
   4.202 -	vl1e++;
   4.203 +             (count <  ((vpt_end  -dsi_v_start)>>PAGE_SHIFT)) ) 
   4.204 +            *vl1e &= ~_PAGE_RW;
   4.205 +        vl1e++;
   4.206      }
   4.207       
   4.208      munmap(vl1tab, PAGE_SIZE);
   4.209 @@ -193,11 +187,11 @@ static int setup_pg_tables_pae(int xc_ha
   4.210  
   4.211   error_out:
   4.212      if (vl1tab)
   4.213 -	munmap(vl1tab, PAGE_SIZE);
   4.214 +        munmap(vl1tab, PAGE_SIZE);
   4.215      if (vl2tab)
   4.216 -	munmap(vl2tab, PAGE_SIZE);
   4.217 +        munmap(vl2tab, PAGE_SIZE);
   4.218      if (vl3tab)
   4.219 -	munmap(vl3tab, PAGE_SIZE);
   4.220 +        munmap(vl3tab, PAGE_SIZE);
   4.221      return -1;
   4.222  }
   4.223  
   4.224 @@ -206,12 +200,12 @@ static int setup_pg_tables_pae(int xc_ha
   4.225  #if defined(__x86_64__)
   4.226  
   4.227  static int setup_pg_tables_64(int xc_handle, u32 dom,
   4.228 -			      vcpu_guest_context_t *ctxt,
   4.229 -			      unsigned long dsi_v_start,
   4.230 -			      unsigned long v_end,
   4.231 -			      unsigned long *page_array,
   4.232 -			      unsigned long vpt_start,
   4.233 -			      unsigned long vpt_end)
   4.234 +                              vcpu_guest_context_t *ctxt,
   4.235 +                              unsigned long dsi_v_start,
   4.236 +                              unsigned long v_end,
   4.237 +                              unsigned long *page_array,
   4.238 +                              unsigned long vpt_start,
   4.239 +                              unsigned long vpt_end)
   4.240  {
   4.241      l1_pgentry_t *vl1tab=NULL, *vl1e=NULL;
   4.242      l2_pgentry_t *vl2tab=NULL, *vl2e=NULL;
   4.243 @@ -236,20 +230,20 @@ static int setup_pg_tables_64(int xc_han
   4.244          {
   4.245              alloc_pt(l1tab, vl1tab);
   4.246              
   4.247 -                if ( !((unsigned long)vl2e & (PAGE_SIZE-1)) )
   4.248 +            if ( !((unsigned long)vl2e & (PAGE_SIZE-1)) )
   4.249 +            {
   4.250 +                alloc_pt(l2tab, vl2tab);
   4.251 +                if ( !((unsigned long)vl3e & (PAGE_SIZE-1)) )
   4.252                  {
   4.253 -                    alloc_pt(l2tab, vl2tab);
   4.254 -                    if ( !((unsigned long)vl3e & (PAGE_SIZE-1)) )
   4.255 -                    {
   4.256 -                        alloc_pt(l3tab, vl3tab);
   4.257 -                        vl3e = &vl3tab[l3_table_offset(dsi_v_start + (count<<PAGE_SHIFT))];
   4.258 -                        *vl4e = l3tab | L4_PROT;
   4.259 -                        vl4e++;
   4.260 -                    }
   4.261 -                    vl2e = &vl2tab[l2_table_offset(dsi_v_start + (count<<PAGE_SHIFT))];
   4.262 -                    *vl3e = l2tab | L3_PROT;
   4.263 -                    vl3e++;
   4.264 +                    alloc_pt(l3tab, vl3tab);
   4.265 +                    vl3e = &vl3tab[l3_table_offset(dsi_v_start + (count<<PAGE_SHIFT))];
   4.266 +                    *vl4e = l3tab | L4_PROT;
   4.267 +                    vl4e++;
   4.268                  }
   4.269 +                vl2e = &vl2tab[l2_table_offset(dsi_v_start + (count<<PAGE_SHIFT))];
   4.270 +                *vl3e = l2tab | L3_PROT;
   4.271 +                vl3e++;
   4.272 +            }
   4.273              vl1e = &vl1tab[l1_table_offset(dsi_v_start + (count<<PAGE_SHIFT))];
   4.274              *vl2e = l1tab | L2_PROT;
   4.275              vl2e++;
   4.276 @@ -257,11 +251,11 @@ static int setup_pg_tables_64(int xc_han
   4.277          
   4.278          *vl1e = (page_array[count] << PAGE_SHIFT) | L1_PROT;
   4.279          if ( (count >= ((vpt_start-dsi_v_start)>>PAGE_SHIFT)) &&
   4.280 -            (count <  ((vpt_end  -dsi_v_start)>>PAGE_SHIFT)) ) 
   4.281 +             (count <  ((vpt_end  -dsi_v_start)>>PAGE_SHIFT)) ) 
   4.282          {
   4.283 -                *vl1e &= ~_PAGE_RW;
   4.284 +            *vl1e &= ~_PAGE_RW;
   4.285          }
   4.286 -            vl1e++;
   4.287 +        vl1e++;
   4.288      }
   4.289       
   4.290      munmap(vl1tab, PAGE_SIZE);
   4.291 @@ -272,13 +266,13 @@ static int setup_pg_tables_64(int xc_han
   4.292  
   4.293   error_out:
   4.294      if (vl1tab)
   4.295 -	munmap(vl1tab, PAGE_SIZE);
   4.296 +        munmap(vl1tab, PAGE_SIZE);
   4.297      if (vl2tab)
   4.298 -	munmap(vl2tab, PAGE_SIZE);
   4.299 +        munmap(vl2tab, PAGE_SIZE);
   4.300      if (vl3tab)
   4.301 -	munmap(vl3tab, PAGE_SIZE);
   4.302 +        munmap(vl3tab, PAGE_SIZE);
   4.303      if (vl4tab)
   4.304 -	munmap(vl4tab, PAGE_SIZE);
   4.305 +        munmap(vl4tab, PAGE_SIZE);
   4.306      return -1;
   4.307  }
   4.308  #endif
   4.309 @@ -286,18 +280,18 @@ static int setup_pg_tables_64(int xc_han
   4.310  #ifdef __ia64__
   4.311  #include <asm/fpu.h> /* for FPSR_DEFAULT */
   4.312  static int setup_guest(int xc_handle,
   4.313 -                         u32 dom,
   4.314 -                         char *image, unsigned long image_size,
   4.315 -                         gzFile initrd_gfd, unsigned long initrd_len,
   4.316 -                         unsigned long nr_pages,
   4.317 -                         unsigned long *pvsi, unsigned long *pvke,
   4.318 -                         unsigned long *pvss, vcpu_guest_context_t *ctxt,
   4.319 -                         const char *cmdline,
   4.320 -                         unsigned long shared_info_frame,
   4.321 -                         unsigned long flags,
   4.322 -                         unsigned int vcpus,
   4.323 -                         unsigned int store_evtchn, unsigned long *store_mfn,
   4.324 -		         unsigned int console_evtchn, unsigned long *console_mfn)
   4.325 +                       u32 dom,
   4.326 +                       char *image, unsigned long image_size,
   4.327 +                       gzFile initrd_gfd, unsigned long initrd_len,
   4.328 +                       unsigned long nr_pages,
   4.329 +                       unsigned long *pvsi, unsigned long *pvke,
   4.330 +                       unsigned long *pvss, vcpu_guest_context_t *ctxt,
   4.331 +                       const char *cmdline,
   4.332 +                       unsigned long shared_info_frame,
   4.333 +                       unsigned long flags,
   4.334 +                       unsigned int vcpus,
   4.335 +                       unsigned int store_evtchn, unsigned long *store_mfn,
   4.336 +                       unsigned int console_evtchn, unsigned long *console_mfn)
   4.337  {
   4.338      unsigned long *page_array = NULL;
   4.339      struct load_funcs load_funcs;
   4.340 @@ -339,19 +333,20 @@ static int setup_guest(int xc_handle,
   4.341      *pvke = dsi.v_kernentry;
   4.342  
   4.343      /* Now need to retrieve machine pfn for system pages:
   4.344 -     * 	start_info/store/console
   4.345 +     *  start_info/store/console
   4.346       */
   4.347      pgnr = 3;
   4.348 -    if ( xc_ia64_get_pfn_list(xc_handle, dom, page_array, nr_pages - 3, pgnr) != pgnr)
   4.349 +    if ( xc_ia64_get_pfn_list(xc_handle, dom, page_array,
   4.350 +                              nr_pages - 3, pgnr) != pgnr )
   4.351      {
   4.352 -	PERROR("Could not get page frame for xenstore");
   4.353 -	goto error_out;
   4.354 +        PERROR("Could not get page frame for xenstore");
   4.355 +        goto error_out;
   4.356      }
   4.357  
   4.358      *store_mfn = page_array[1];
   4.359      *console_mfn = page_array[2];
   4.360      printf("store_mfn: 0x%lx, console_mfn: 0x%lx\n",
   4.361 -	(u64)store_mfn, (u64)console_mfn);
   4.362 +           (u64)store_mfn, (u64)console_mfn);
   4.363  
   4.364      start_info = xc_map_foreign_range(
   4.365          xc_handle, dom, PAGE_SIZE, PROT_READ|PROT_WRITE, page_array[0]);
   4.366 @@ -382,8 +377,8 @@ static int setup_guest(int xc_handle,
   4.367                         unsigned long shared_info_frame,
   4.368                         unsigned long flags,
   4.369                         unsigned int vcpus,
   4.370 -		       unsigned int store_evtchn, unsigned long *store_mfn,
   4.371 -		       unsigned int console_evtchn, unsigned long *console_mfn)
   4.372 +                       unsigned int store_evtchn, unsigned long *store_mfn,
   4.373 +                       unsigned int console_evtchn, unsigned long *console_mfn)
   4.374  {
   4.375      unsigned long *page_array = NULL;
   4.376      unsigned long count, i;
   4.377 @@ -458,26 +453,26 @@ static int setup_guest(int xc_handle,
   4.378          if ( (v_end - vstack_end) < (512UL << 10) )
   4.379              v_end += 1UL << 22; /* Add extra 4MB to get >= 512kB padding. */
   4.380  #if defined(__i386__)
   4.381 -	if (dsi.pae_kernel) {
   4.382 -	    /* FIXME: assumes one L2 pgtable @ 0xc0000000 */
   4.383 -	    if ( (((v_end - dsi.v_start + ((1<<L2_PAGETABLE_SHIFT_PAE)-1)) >> 
   4.384 -		   L2_PAGETABLE_SHIFT_PAE) + 2) <= nr_pt_pages )
   4.385 -		break;
   4.386 -	} else {
   4.387 -	    if ( (((v_end - dsi.v_start + ((1<<L2_PAGETABLE_SHIFT)-1)) >> 
   4.388 -		   L2_PAGETABLE_SHIFT) + 1) <= nr_pt_pages )
   4.389 -		break;
   4.390 -	}
   4.391 +        if (dsi.pae_kernel) {
   4.392 +            /* FIXME: assumes one L2 pgtable @ 0xc0000000 */
   4.393 +            if ( (((v_end - dsi.v_start + ((1<<L2_PAGETABLE_SHIFT_PAE)-1)) >> 
   4.394 +                   L2_PAGETABLE_SHIFT_PAE) + 2) <= nr_pt_pages )
   4.395 +                break;
   4.396 +        } else {
   4.397 +            if ( (((v_end - dsi.v_start + ((1<<L2_PAGETABLE_SHIFT)-1)) >> 
   4.398 +                   L2_PAGETABLE_SHIFT) + 1) <= nr_pt_pages )
   4.399 +                break;
   4.400 +        }
   4.401  #endif
   4.402  #if defined(__x86_64__)
   4.403  #define NR(_l,_h,_s) \
   4.404      (((((_h) + ((1UL<<(_s))-1)) & ~((1UL<<(_s))-1)) - \
   4.405      ((_l) & ~((1UL<<(_s))-1))) >> (_s))
   4.406 -    if ( (1 + /* # L4 */
   4.407 -        NR(dsi.v_start, v_end, L4_PAGETABLE_SHIFT) + /* # L3 */
   4.408 -        NR(dsi.v_start, v_end, L3_PAGETABLE_SHIFT) + /* # L2 */
   4.409 -        NR(dsi.v_start, v_end, L2_PAGETABLE_SHIFT))  /* # L1 */
   4.410 -        <= nr_pt_pages )
   4.411 +        if ( (1 + /* # L4 */
   4.412 +              NR(dsi.v_start, v_end, L4_PAGETABLE_SHIFT) + /* # L3 */
   4.413 +              NR(dsi.v_start, v_end, L3_PAGETABLE_SHIFT) + /* # L2 */
   4.414 +              NR(dsi.v_start, v_end, L2_PAGETABLE_SHIFT))  /* # L1 */
   4.415 +             <= nr_pt_pages )
   4.416              break;
   4.417  #endif
   4.418      }
   4.419 @@ -541,7 +536,7 @@ static int setup_guest(int xc_handle,
   4.420                  goto error_out;
   4.421              }
   4.422              xc_copy_to_domain_page(xc_handle, dom,
   4.423 -                                page_array[i>>PAGE_SHIFT], page);
   4.424 +                                   page_array[i>>PAGE_SHIFT], page);
   4.425          }
   4.426      }
   4.427  
   4.428 @@ -551,22 +546,22 @@ static int setup_guest(int xc_handle,
   4.429      /* setup page tables */
   4.430  #if defined(__i386__)
   4.431      if (dsi.pae_kernel)
   4.432 -	rc = setup_pg_tables_pae(xc_handle, dom, ctxt,
   4.433 -				 dsi.v_start, v_end,
   4.434 -				 page_array, vpt_start, vpt_end);
   4.435 +        rc = setup_pg_tables_pae(xc_handle, dom, ctxt,
   4.436 +                                 dsi.v_start, v_end,
   4.437 +                                 page_array, vpt_start, vpt_end);
   4.438      else {
   4.439 -	rc = setup_pg_tables(xc_handle, dom, ctxt,
   4.440 -			     dsi.v_start, v_end,
   4.441 -			     page_array, vpt_start, vpt_end);
   4.442 +        rc = setup_pg_tables(xc_handle, dom, ctxt,
   4.443 +                             dsi.v_start, v_end,
   4.444 +                             page_array, vpt_start, vpt_end);
   4.445      }
   4.446  #endif
   4.447  #if defined(__x86_64__)
   4.448      rc = setup_pg_tables_64(xc_handle, dom, ctxt,
   4.449 -			    dsi.v_start, v_end,
   4.450 -			    page_array, vpt_start, vpt_end);
   4.451 +                            dsi.v_start, v_end,
   4.452 +                            page_array, vpt_start, vpt_end);
   4.453  #endif
   4.454      if (0 != rc)
   4.455 -	goto error_out;
   4.456 +        goto error_out;
   4.457  
   4.458      /* Write the phys->machine and machine->phys table entries. */
   4.459      physmap_pfn = (vphysmap_start - dsi.v_start) >> PAGE_SHIFT;
   4.460 @@ -576,11 +571,13 @@ static int setup_guest(int xc_handle,
   4.461  
   4.462      for ( count = 0; count < nr_pages; count++ )
   4.463      {
   4.464 -        if ( xc_add_mmu_update(xc_handle, mmu,
   4.465 -			       ((unsigned long long)page_array[count] << PAGE_SHIFT) | 
   4.466 -			       MMU_MACHPHYS_UPDATE, count) )
   4.467 +        if ( xc_add_mmu_update(
   4.468 +            xc_handle, mmu,
   4.469 +            ((u64)page_array[count] << PAGE_SHIFT) | MMU_MACHPHYS_UPDATE,
   4.470 +            count) )
   4.471          {
   4.472 -            fprintf(stderr,"m2p update failure p=%lx m=%lx\n",count,page_array[count] ); 
   4.473 +            fprintf(stderr,"m2p update failure p=%lx m=%lx\n",
   4.474 +                    count, page_array[count]); 
   4.475              munmap(physmap, PAGE_SIZE);
   4.476              goto error_out;
   4.477          }
   4.478 @@ -601,13 +598,13 @@ static int setup_guest(int xc_handle,
   4.479       * correct protection for the page
   4.480       */
   4.481      if (dsi.pae_kernel) {
   4.482 -	if ( pin_table(xc_handle, MMUEXT_PIN_L3_TABLE,
   4.483 -		       ctxt->ctrlreg[3] >> PAGE_SHIFT, dom) )
   4.484 -	    goto error_out;
   4.485 +        if ( pin_table(xc_handle, MMUEXT_PIN_L3_TABLE,
   4.486 +                       ctxt->ctrlreg[3] >> PAGE_SHIFT, dom) )
   4.487 +            goto error_out;
   4.488      } else {
   4.489 -	if ( pin_table(xc_handle, MMUEXT_PIN_L2_TABLE,
   4.490 -		       ctxt->ctrlreg[3] >> PAGE_SHIFT, dom) )
   4.491 -	    goto error_out;
   4.492 +        if ( pin_table(xc_handle, MMUEXT_PIN_L2_TABLE,
   4.493 +                       ctxt->ctrlreg[3] >> PAGE_SHIFT, dom) )
   4.494 +            goto error_out;
   4.495      }
   4.496  #endif
   4.497  
   4.498 @@ -616,8 +613,8 @@ static int setup_guest(int xc_handle,
   4.499       * Pin down l4tab addr as page dir page - causes hypervisor to  provide
   4.500       * correct protection for the page
   4.501       */
   4.502 -     if ( pin_table(xc_handle, MMUEXT_PIN_L4_TABLE,
   4.503 -		    ctxt->ctrlreg[3] >> PAGE_SHIFT, dom) )
   4.504 +    if ( pin_table(xc_handle, MMUEXT_PIN_L4_TABLE,
   4.505 +                   ctxt->ctrlreg[3] >> PAGE_SHIFT, dom) )
   4.506          goto error_out;
   4.507  #endif
   4.508  
   4.509 @@ -703,12 +700,7 @@ int xc_linux_build(int xc_handle,
   4.510      unsigned long image_size, initrd_size=0;
   4.511      unsigned long vstartinfo_start, vkern_entry, vstack_start;
   4.512  
   4.513 -#ifdef __ia64__
   4.514 -    /* Current xen/ia64 allocates domU pages on demand */
   4.515 -    if ( (nr_pages = xc_get_max_pages(xc_handle, domid)) < 0 )
   4.516 -#else
   4.517 -    if ( (nr_pages = xc_get_tot_pages(xc_handle, domid)) < 0 )
   4.518 -#endif
   4.519 +    if ( (nr_pages = get_tot_pages(xc_handle, domid)) < 0 )
   4.520      {
   4.521          PERROR("Could not find total pages for domain");
   4.522          goto error_out;
   4.523 @@ -755,12 +747,7 @@ int xc_linux_build(int xc_handle,
   4.524          goto error_out;
   4.525      }
   4.526  
   4.527 -    if ( !(op.u.getdomaininfo.flags & DOMFLAGS_PAUSED) ||
   4.528 -#ifdef __ia64__
   4.529 -	0 )
   4.530 -#else
   4.531 -         (ctxt->ctrlreg[3] != 0) )
   4.532 -#endif
   4.533 +    if ( !(op.u.getdomaininfo.flags & DOMFLAGS_PAUSED) || already_built(ctxt) )
   4.534      {
   4.535          ERROR("Domain is already constructed");
   4.536          goto error_out;
   4.537 @@ -773,7 +760,7 @@ int xc_linux_build(int xc_handle,
   4.538                       op.u.getdomaininfo.shared_info_frame,
   4.539                       flags, vcpus,
   4.540                       store_evtchn, store_mfn,
   4.541 -		     console_evtchn, console_mfn) < 0 )
   4.542 +                     console_evtchn, console_mfn) < 0 )
   4.543      {
   4.544          ERROR("Error constructing guest OS");
   4.545          goto error_out;
   4.546 @@ -789,12 +776,13 @@ int xc_linux_build(int xc_handle,
   4.547      /* based on new_thread in xen/arch/ia64/domain.c */
   4.548      ctxt->flags = 0;
   4.549      ctxt->shared.flags = flags;
   4.550 -    ctxt->shared.start_info_pfn = nr_pages - 3; // metaphysical
   4.551 +    ctxt->shared.start_info_pfn = nr_pages - 3; /* metaphysical */
   4.552      ctxt->regs.cr_ipsr = 0; /* all necessary bits filled by hypervisor */
   4.553      ctxt->regs.cr_iip = vkern_entry;
   4.554      ctxt->regs.cr_ifs = 1UL << 63;
   4.555      ctxt->regs.ar_fpsr = FPSR_DEFAULT;
   4.556 -    /* ctxt->regs.r28 = dom_fw_setup(); currently done by hypervisor, should move here */
   4.557 +    /* currently done by hypervisor, should move here */
   4.558 +    /* ctxt->regs.r28 = dom_fw_setup(); */
   4.559      ctxt->vcpu.privregs = 0;
   4.560      ctxt->sys_pgnr = nr_pages - 3;
   4.561      i = 0; /* silence unused variable warning */
   4.562 @@ -875,3 +863,13 @@ int xc_linux_build(int xc_handle,
   4.563  
   4.564      return -1;
   4.565  }
   4.566 +
   4.567 +/*
   4.568 + * Local variables:
   4.569 + * mode: C
   4.570 + * c-set-style: "BSD"
   4.571 + * c-basic-offset: 4
   4.572 + * tab-width: 4
   4.573 + * indent-tabs-mode: nil
   4.574 + * End:
   4.575 + */
     5.1 --- a/tools/libxc/xc_linux_save.c	Mon Sep 19 09:14:41 2005 +0000
     5.2 +++ b/tools/libxc/xc_linux_save.c	Mon Sep 19 11:06:05 2005 +0000
     5.3 @@ -18,7 +18,6 @@
     5.4  
     5.5  #define MAX_MBIT_RATE 500
     5.6  
     5.7 -
     5.8  /*
     5.9  ** Default values for important tuning parameters. Can override by passing
    5.10  ** non-zero replacement values to xc_linux_save().  
    5.11 @@ -29,13 +28,10 @@
    5.12  #define DEF_MAX_ITERS   29   /* limit us to 30 times round loop */ 
    5.13  #define DEF_MAX_FACTOR   3   /* never send more than 3x nr_pfns */
    5.14  
    5.15 -
    5.16 -
    5.17  /* Flags to control behaviour of xc_linux_save */
    5.18  #define XCFLAGS_LIVE      1
    5.19  #define XCFLAGS_DEBUG     2
    5.20  
    5.21 -
    5.22  #define DEBUG 0
    5.23  
    5.24  #if 1
    5.25 @@ -115,8 +111,8 @@ static inline int count_bits ( int nr, v
    5.26      int i, count = 0;
    5.27      unsigned long *p = (unsigned long *)addr;
    5.28      /* We know that the array is padded to unsigned long. */
    5.29 -    for(i=0;i<nr/(sizeof(unsigned long)*8);i++,p++)
    5.30 -        count += hweight32( *p );
    5.31 +    for( i = 0; i < (nr / (sizeof(unsigned long)*8)); i++, p++ )
    5.32 +        count += hweight32(*p);
    5.33      return count;
    5.34  }
    5.35  
    5.36 @@ -201,42 +197,50 @@ ratewrite(int io_fd, void *buf, int n)
    5.37      struct timespec delay;
    5.38      long long delta;
    5.39  
    5.40 -    if (START_MBIT_RATE == 0)
    5.41 -	return write(io_fd, buf, n);
    5.42 +    if ( START_MBIT_RATE == 0 )
    5.43 +        return write(io_fd, buf, n);
    5.44      
    5.45      budget -= n;
    5.46 -    if (budget < 0) {
    5.47 -	if (MBIT_RATE != ombit_rate) {
    5.48 -	    BURST_TIME_US = RATE_TO_BTU / MBIT_RATE;
    5.49 -	    ombit_rate = MBIT_RATE;
    5.50 -	    DPRINTF("rate limit: %d mbit/s burst budget %d slot time %d\n",
    5.51 -		    MBIT_RATE, BURST_BUDGET, BURST_TIME_US);
    5.52 -	}
    5.53 -	if (last_put.tv_sec == 0) {
    5.54 -	    budget += BURST_BUDGET;
    5.55 -	    gettimeofday(&last_put, NULL);
    5.56 -	} else {
    5.57 -	    while (budget < 0) {
    5.58 -		gettimeofday(&now, NULL);
    5.59 -		delta = tv_delta(&now, &last_put);
    5.60 -		while (delta > BURST_TIME_US) {
    5.61 -		    budget += BURST_BUDGET;
    5.62 -		    last_put.tv_usec += BURST_TIME_US;
    5.63 -		    if (last_put.tv_usec > 1000000) {
    5.64 -			last_put.tv_usec -= 1000000;
    5.65 -			last_put.tv_sec++;
    5.66 -		    }
    5.67 -		    delta -= BURST_TIME_US;
    5.68 -		}
    5.69 -		if (budget > 0)
    5.70 -		    break;
    5.71 -		delay.tv_sec = 0;
    5.72 -		delay.tv_nsec = 1000 * (BURST_TIME_US - delta);
    5.73 -		while (delay.tv_nsec > 0)
    5.74 -		    if (nanosleep(&delay, &delay) == 0)
    5.75 -			break;
    5.76 -	    }
    5.77 -	}
    5.78 +    if ( budget < 0 )
    5.79 +    {
    5.80 +        if ( MBIT_RATE != ombit_rate )
    5.81 +        {
    5.82 +            BURST_TIME_US = RATE_TO_BTU / MBIT_RATE;
    5.83 +            ombit_rate = MBIT_RATE;
    5.84 +            DPRINTF("rate limit: %d mbit/s burst budget %d slot time %d\n",
    5.85 +                    MBIT_RATE, BURST_BUDGET, BURST_TIME_US);
    5.86 +        }
    5.87 +        if ( last_put.tv_sec == 0 )
    5.88 +        {
    5.89 +            budget += BURST_BUDGET;
    5.90 +            gettimeofday(&last_put, NULL);
    5.91 +        }
    5.92 +        else
    5.93 +        {
    5.94 +            while ( budget < 0 )
    5.95 +            {
    5.96 +                gettimeofday(&now, NULL);
    5.97 +                delta = tv_delta(&now, &last_put);
    5.98 +                while ( delta > BURST_TIME_US )
    5.99 +                {
   5.100 +                    budget += BURST_BUDGET;
   5.101 +                    last_put.tv_usec += BURST_TIME_US;
   5.102 +                    if ( last_put.tv_usec > 1000000 )
   5.103 +                    {
   5.104 +                        last_put.tv_usec -= 1000000;
   5.105 +                        last_put.tv_sec++;
   5.106 +                    }
   5.107 +                    delta -= BURST_TIME_US;
   5.108 +                }
   5.109 +                if ( budget > 0 )
   5.110 +                    break;
   5.111 +                delay.tv_sec = 0;
   5.112 +                delay.tv_nsec = 1000 * (BURST_TIME_US - delta);
   5.113 +                while ( delay.tv_nsec > 0 )
   5.114 +                    if ( nanosleep(&delay, &delay) == 0 )
   5.115 +                        break;
   5.116 +            }
   5.117 +        }
   5.118      }
   5.119      return write(io_fd, buf, n);
   5.120  }
   5.121 @@ -271,20 +275,21 @@ static int print_stats( int xc_handle, u
   5.122  
   5.123      if ( print )
   5.124          fprintf(stderr,
   5.125 -		"delta %lldms, dom0 %d%%, target %d%%, sent %dMb/s, "
   5.126 -		"dirtied %dMb/s %" PRId32 " pages\n",
   5.127 -		wall_delta, 
   5.128 -		(int)((d0_cpu_delta*100)/wall_delta),
   5.129 -		(int)((d1_cpu_delta*100)/wall_delta),
   5.130 -		(int)((pages_sent*PAGE_SIZE)/(wall_delta*(1000/8))),
   5.131 -		(int)((stats->dirty_count*PAGE_SIZE)/(wall_delta*(1000/8))),
   5.132 -		stats->dirty_count);
   5.133 +                "delta %lldms, dom0 %d%%, target %d%%, sent %dMb/s, "
   5.134 +                "dirtied %dMb/s %" PRId32 " pages\n",
   5.135 +                wall_delta, 
   5.136 +                (int)((d0_cpu_delta*100)/wall_delta),
   5.137 +                (int)((d1_cpu_delta*100)/wall_delta),
   5.138 +                (int)((pages_sent*PAGE_SIZE)/(wall_delta*(1000/8))),
   5.139 +                (int)((stats->dirty_count*PAGE_SIZE)/(wall_delta*(1000/8))),
   5.140 +                stats->dirty_count);
   5.141  
   5.142 -    if (((stats->dirty_count*PAGE_SIZE)/(wall_delta*(1000/8))) > mbit_rate) {
   5.143 -	mbit_rate = (int)((stats->dirty_count*PAGE_SIZE)/(wall_delta*(1000/8)))
   5.144 -	    + 50;
   5.145 -	if (mbit_rate > MAX_MBIT_RATE)
   5.146 -	    mbit_rate = MAX_MBIT_RATE;
   5.147 +    if ( ((stats->dirty_count*PAGE_SIZE)/(wall_delta*(1000/8))) > mbit_rate )
   5.148 +    {
   5.149 +        mbit_rate = (int)((stats->dirty_count*PAGE_SIZE)/(wall_delta*(1000/8)))
   5.150 +            + 50;
   5.151 +        if (mbit_rate > MAX_MBIT_RATE)
   5.152 +            mbit_rate = MAX_MBIT_RATE;
   5.153      }
   5.154  
   5.155      d0_cpu_last  = d0_cpu_now;
   5.156 @@ -303,7 +308,7 @@ static int analysis_phase( int xc_handle
   5.157  
   5.158      start = llgettimeofday();
   5.159  
   5.160 -    for (j = 0; j < runs; j++)
   5.161 +    for ( j = 0; j < runs; j++ )
   5.162      {
   5.163          int i;
   5.164  
   5.165 @@ -320,10 +325,10 @@ static int analysis_phase( int xc_handle
   5.166                                 NULL, 0, &stats);
   5.167  
   5.168              fprintf(stderr, "now= %lld faults= %" PRId32 " dirty= %" PRId32
   5.169 -		    " dirty_net= %" PRId32 " dirty_block= %" PRId32"\n", 
   5.170 -		    ((now-start)+500)/1000, 
   5.171 -		    stats.fault_count, stats.dirty_count,
   5.172 -		    stats.dirty_net_count, stats.dirty_block_count);
   5.173 +                    " dirty_net= %" PRId32 " dirty_block= %" PRId32"\n", 
   5.174 +                    ((now-start)+500)/1000, 
   5.175 +                    stats.fault_count, stats.dirty_count,
   5.176 +                    stats.dirty_net_count, stats.dirty_block_count);
   5.177          }
   5.178      }
   5.179  
   5.180 @@ -331,7 +336,7 @@ static int analysis_phase( int xc_handle
   5.181  }
   5.182  
   5.183  
   5.184 -static int suspend_and_state(int xc_handle, int io_fd,	int dom,	      
   5.185 +static int suspend_and_state(int xc_handle, int io_fd, int dom,       
   5.186                               xc_dominfo_t *info,
   5.187                               vcpu_guest_context_t *ctxt)
   5.188  {
   5.189 @@ -340,51 +345,53 @@ static int suspend_and_state(int xc_hand
   5.190  
   5.191      printf("suspend\n");
   5.192      fflush(stdout);
   5.193 -    if (fgets(ans, sizeof(ans), stdin) == NULL) {
   5.194 +    if ( fgets(ans, sizeof(ans), stdin) == NULL )
   5.195 +    {
   5.196          ERR("failed reading suspend reply");
   5.197          return -1;
   5.198      }
   5.199 -    if (strncmp(ans, "done\n", 5)) {
   5.200 +    if ( strncmp(ans, "done\n", 5) )
   5.201 +    {
   5.202          ERR("suspend reply incorrect: %s", ans);
   5.203          return -1;
   5.204      }
   5.205  
   5.206 -retry:
   5.207 + retry:
   5.208  
   5.209      if ( xc_domain_getinfo(xc_handle, dom, 1, info) != 1)
   5.210      {
   5.211 -	ERR("Could not get domain info");
   5.212 -	return -1;
   5.213 +        ERR("Could not get domain info");
   5.214 +        return -1;
   5.215      }
   5.216  
   5.217      if ( xc_domain_get_vcpu_context(xc_handle, dom, 0 /* XXX */, 
   5.218 -				    ctxt) )
   5.219 +                                    ctxt) )
   5.220      {
   5.221          ERR("Could not get vcpu context");
   5.222      }
   5.223  
   5.224      if ( info->shutdown && info->shutdown_reason == SHUTDOWN_suspend )
   5.225      {
   5.226 -	return 0; // success
   5.227 +        return 0; // success
   5.228      }
   5.229  
   5.230      if ( info->paused )
   5.231      {
   5.232 -	// try unpausing domain, wait, and retest	
   5.233 -	xc_domain_unpause( xc_handle, dom );
   5.234 +        // try unpausing domain, wait, and retest 
   5.235 +        xc_domain_unpause( xc_handle, dom );
   5.236  
   5.237 -	ERR("Domain was paused. Wait and re-test.");
   5.238 -	usleep(10000);  // 10ms
   5.239 +        ERR("Domain was paused. Wait and re-test.");
   5.240 +        usleep(10000);  // 10ms
   5.241  
   5.242 -	goto retry;
   5.243 +        goto retry;
   5.244      }
   5.245  
   5.246  
   5.247      if( ++i < 100 )
   5.248      {
   5.249 -	ERR("Retry suspend domain.");
   5.250 -	usleep(10000);  // 10ms	
   5.251 -	goto retry;
   5.252 +        ERR("Retry suspend domain.");
   5.253 +        usleep(10000);  // 10ms 
   5.254 +        goto retry;
   5.255      }
   5.256  
   5.257      ERR("Unable to suspend domain.");
   5.258 @@ -454,26 +461,26 @@ int xc_linux_save(int xc_handle, int io_
   5.259  
   5.260  
   5.261      /* If no explicit control parameters given, use defaults */
   5.262 -    if(!max_iters) 
   5.263 +    if( !max_iters ) 
   5.264          max_iters = DEF_MAX_ITERS; 
   5.265 -    if(!max_factor) 
   5.266 +    if( !max_factor ) 
   5.267          max_factor = DEF_MAX_FACTOR; 
   5.268  
   5.269  
   5.270      DPRINTF("xc_linux_save start DOM%u live=%s\n", dom, live?"true":"false"); 
   5.271  
   5.272 -    if (mlock(&ctxt, sizeof(ctxt))) {
   5.273 +    if ( mlock(&ctxt, sizeof(ctxt)) ) 
   5.274 +    {
   5.275          ERR("Unable to mlock ctxt");
   5.276          return 1;
   5.277      }
   5.278      
   5.279 -    if ( xc_domain_getinfo(xc_handle, dom, 1, &info) != 1)
   5.280 +    if ( xc_domain_getinfo(xc_handle, dom, 1, &info) != 1 )
   5.281      {
   5.282          ERR("Could not get domain info");
   5.283          goto out;
   5.284      }
   5.285 -    if ( xc_domain_get_vcpu_context( xc_handle, dom, /* FIXME */ 0, 
   5.286 -                                &ctxt) )
   5.287 +    if ( xc_domain_get_vcpu_context(xc_handle, dom, /* FIXME */ 0, &ctxt) )
   5.288      {
   5.289          ERR("Could not get vcpu context");
   5.290          goto out;
   5.291 @@ -481,7 +488,8 @@ int xc_linux_save(int xc_handle, int io_
   5.292      shared_info_frame = info.shared_info_frame;
   5.293  
   5.294      /* A cheesy test to see whether the domain contains valid state. */
   5.295 -    if ( ctxt.ctrlreg[3] == 0 ){
   5.296 +    if ( ctxt.ctrlreg[3] == 0 )
   5.297 +    {
   5.298          ERR("Domain is not in a valid Linux guest OS state");
   5.299          goto out;
   5.300      }
   5.301 @@ -496,18 +504,17 @@ int xc_linux_save(int xc_handle, int io_
   5.302      }
   5.303  
   5.304      /* Map the shared info frame */
   5.305 -    live_shinfo = xc_map_foreign_range(xc_handle, dom,
   5.306 -                                        PAGE_SIZE, PROT_READ,
   5.307 -                                        shared_info_frame);
   5.308 -
   5.309 -    if (!live_shinfo){
   5.310 +    live_shinfo = xc_map_foreign_range(
   5.311 +        xc_handle, dom, PAGE_SIZE, PROT_READ, shared_info_frame);
   5.312 +    if ( !live_shinfo )
   5.313 +    {
   5.314          ERR("Couldn't map live_shinfo");
   5.315          goto out;
   5.316      }
   5.317  
   5.318 -    live_pfn_to_mfn_frame_list_list = xc_map_foreign_range(xc_handle, dom,
   5.319 -                                        PAGE_SIZE, PROT_READ,
   5.320 -                                        live_shinfo->arch.pfn_to_mfn_frame_list_list);
   5.321 +    live_pfn_to_mfn_frame_list_list = xc_map_foreign_range(
   5.322 +        xc_handle, dom,
   5.323 +        PAGE_SIZE, PROT_READ, live_shinfo->arch.pfn_to_mfn_frame_list_list);
   5.324  
   5.325      if (!live_pfn_to_mfn_frame_list_list){
   5.326          ERR("Couldn't map pfn_to_mfn_frame_list_list");
   5.327 @@ -515,12 +522,13 @@ int xc_linux_save(int xc_handle, int io_
   5.328      }
   5.329  
   5.330      live_pfn_to_mfn_frame_list = 
   5.331 -	xc_map_foreign_batch(xc_handle, dom, 
   5.332 -			     PROT_READ,
   5.333 -			     live_pfn_to_mfn_frame_list_list,
   5.334 -			     (nr_pfns+(1024*1024)-1)/(1024*1024) );
   5.335 +        xc_map_foreign_batch(xc_handle, dom, 
   5.336 +                             PROT_READ,
   5.337 +                             live_pfn_to_mfn_frame_list_list,
   5.338 +                             (nr_pfns+(1024*1024)-1)/(1024*1024) );
   5.339  
   5.340 -    if (!live_pfn_to_mfn_frame_list){
   5.341 +    if ( !live_pfn_to_mfn_frame_list)
   5.342 +    {
   5.343          ERR("Couldn't map pfn_to_mfn_frame_list");
   5.344          goto out;
   5.345      }
   5.346 @@ -535,7 +543,8 @@ int xc_linux_save(int xc_handle, int io_
   5.347                                                   PROT_READ,
   5.348                                                   live_pfn_to_mfn_frame_list,
   5.349                                                   (nr_pfns+1023)/1024 );  
   5.350 -    if( !live_pfn_to_mfn_table ){
   5.351 +    if ( !live_pfn_to_mfn_table )
   5.352 +    {
   5.353          ERR("Couldn't map pfn_to_mfn table");
   5.354          goto out;
   5.355      }
   5.356 @@ -544,15 +553,17 @@ int xc_linux_save(int xc_handle, int io_
   5.357      mfn_to_pfn_table_start_mfn = xc_get_m2p_start_mfn( xc_handle );
   5.358  
   5.359      live_mfn_to_pfn_table = 
   5.360 -	xc_map_foreign_range(xc_handle, DOMID_XEN, 
   5.361 -			      PAGE_SIZE*1024, PROT_READ, 
   5.362 -			      mfn_to_pfn_table_start_mfn );
   5.363 +        xc_map_foreign_range(xc_handle, DOMID_XEN, 
   5.364 +                             PAGE_SIZE*1024, PROT_READ, 
   5.365 +                             mfn_to_pfn_table_start_mfn );
   5.366  
   5.367      /* Canonicalise the pfn-to-mfn table frame-number list. */
   5.368      memcpy( pfn_to_mfn_frame_list, live_pfn_to_mfn_frame_list, PAGE_SIZE );
   5.369  
   5.370 -    for ( i = 0; i < nr_pfns; i += 1024 ){
   5.371 -        if ( !translate_mfn_to_pfn(&pfn_to_mfn_frame_list[i/1024]) ){
   5.372 +    for ( i = 0; i < nr_pfns; i += 1024 )
   5.373 +    {
   5.374 +        if ( !translate_mfn_to_pfn(&pfn_to_mfn_frame_list[i/1024]) )
   5.375 +        {
   5.376              ERR("Frame# in pfn-to-mfn frame list is not in pseudophys");
   5.377              goto out;
   5.378          }
   5.379 @@ -561,40 +572,44 @@ int xc_linux_save(int xc_handle, int io_
   5.380  
   5.381      /* Domain is still running at this point */
   5.382  
   5.383 -    if( live )
   5.384 +    if ( live )
   5.385      {
   5.386          if ( xc_shadow_control( xc_handle, dom, 
   5.387                                  DOM0_SHADOW_CONTROL_OP_ENABLE_LOGDIRTY,
   5.388 -                                NULL, 0, NULL ) < 0 ) {
   5.389 +                                NULL, 0, NULL ) < 0 )
   5.390 +        {
   5.391              ERR("Couldn't enable shadow mode");
   5.392              goto out;
   5.393          }
   5.394  
   5.395          last_iter = 0;
   5.396 -    } else{
   5.397 -	/* This is a non-live suspend. Issue the call back to get the
   5.398 -	 domain suspended */
   5.399 +    } 
   5.400 +    else
   5.401 +    {
   5.402 +        /* This is a non-live suspend. Issue the call back to get the
   5.403 +           domain suspended */
   5.404  
   5.405          last_iter = 1;
   5.406  
   5.407 -	if ( suspend_and_state( xc_handle, io_fd, dom, &info, &ctxt) )
   5.408 -	{
   5.409 -	    ERR("Domain appears not to have suspended");
   5.410 -	    goto out;
   5.411 -	}
   5.412 +        if ( suspend_and_state( xc_handle, io_fd, dom, &info, &ctxt) )
   5.413 +        {
   5.414 +            ERR("Domain appears not to have suspended");
   5.415 +            goto out;
   5.416 +        }
   5.417  
   5.418      }
   5.419      sent_last_iter = 1<<20; /* 4GB of pages */
   5.420  
   5.421      /* calculate the power of 2 order of nr_pfns, e.g.
   5.422         15->4 16->4 17->5 */
   5.423 -    for( i=nr_pfns-1, order_nr=0; i ; i>>=1, order_nr++ );
   5.424 +    for ( i = nr_pfns-1, order_nr = 0; i ; i >>= 1, order_nr++ )
   5.425 +        continue;
   5.426  
   5.427      /* Setup to_send bitmap */
   5.428      {
   5.429 -	/* size these for a maximal 4GB domain, to make interaction
   5.430 -	   with balloon driver easier. It's only user space memory,
   5.431 -	   ater all... (3x 128KB) */
   5.432 +        /* size these for a maximal 4GB domain, to make interaction
   5.433 +           with balloon driver easier. It's only user space memory,
   5.434 +           ater all... (3x 128KB) */
   5.435  
   5.436          int sz = ( 1<<20 ) / 8;
   5.437   
   5.438 @@ -602,21 +617,24 @@ int xc_linux_save(int xc_handle, int io_
   5.439          to_fix  = calloc( 1, sz );
   5.440          to_skip = malloc( sz );
   5.441  
   5.442 -        if (!to_send || !to_fix || !to_skip){
   5.443 +        if ( !to_send || !to_fix || !to_skip )
   5.444 +        {
   5.445              ERR("Couldn't allocate to_send array");
   5.446              goto out;
   5.447          }
   5.448  
   5.449 -        memset( to_send, 0xff, sz );
   5.450 +        memset(to_send, 0xff, sz);
   5.451  
   5.452 -        if ( mlock( to_send, sz ) ){
   5.453 +        if ( mlock(to_send, sz) )
   5.454 +        {
   5.455              ERR("Unable to mlock to_send");
   5.456              return 1;
   5.457          }
   5.458  
   5.459          /* (to fix is local only) */
   5.460  
   5.461 -        if ( mlock( to_skip, sz ) ){
   5.462 +        if ( mlock(to_skip, sz) )
   5.463 +        {
   5.464              ERR("Unable to mlock to_skip");
   5.465              return 1;
   5.466          }
   5.467 @@ -629,12 +647,14 @@ int xc_linux_save(int xc_handle, int io_
   5.468      pfn_type = calloc(BATCH_SIZE, sizeof(unsigned long));
   5.469      pfn_batch = calloc(BATCH_SIZE, sizeof(unsigned long));
   5.470  
   5.471 -    if ( (pfn_type == NULL) || (pfn_batch == NULL) ){
   5.472 +    if ( (pfn_type == NULL) || (pfn_batch == NULL) )
   5.473 +    {
   5.474          errno = ENOMEM;
   5.475          goto out;
   5.476      }
   5.477  
   5.478 -    if ( mlock( pfn_type, BATCH_SIZE * sizeof(unsigned long) ) ){
   5.479 +    if ( mlock(pfn_type, BATCH_SIZE * sizeof(unsigned long)) )
   5.480 +    {
   5.481          ERR("Unable to mlock");
   5.482          goto out;
   5.483      }
   5.484 @@ -645,31 +665,34 @@ int xc_linux_save(int xc_handle, int io_
   5.485       */
   5.486  #if DEBUG
   5.487      {
   5.488 -	int err=0;
   5.489 -	for ( i = 0; i < nr_pfns; i++ )
   5.490 -	{
   5.491 -	    mfn = live_pfn_to_mfn_table[i];
   5.492 -	    
   5.493 -	    if( (live_mfn_to_pfn_table[mfn] != i) && (mfn != 0xffffffffUL) )
   5.494 -	    {
   5.495 -		fprintf(stderr, "i=0x%x mfn=%lx live_mfn_to_pfn_table=%lx\n",
   5.496 -			i,mfn,live_mfn_to_pfn_table[mfn]);
   5.497 -		err++;
   5.498 -	    }
   5.499 -	}
   5.500 -	fprintf(stderr, "Had %d unexplained entries in p2m table\n",err);
   5.501 +        int err=0;
   5.502 +        for ( i = 0; i < nr_pfns; i++ )
   5.503 +        {
   5.504 +            mfn = live_pfn_to_mfn_table[i];
   5.505 +     
   5.506 +            if( (live_mfn_to_pfn_table[mfn] != i) && (mfn != 0xffffffffUL) )
   5.507 +            {
   5.508 +                fprintf(stderr, "i=0x%x mfn=%lx live_mfn_to_pfn_table=%lx\n",
   5.509 +                        i,mfn,live_mfn_to_pfn_table[mfn]);
   5.510 +                err++;
   5.511 +            }
   5.512 +        }
   5.513 +        fprintf(stderr, "Had %d unexplained entries in p2m table\n",err);
   5.514      }
   5.515  #endif
   5.516  
   5.517  
   5.518      /* Start writing out the saved-domain record. */
   5.519  
   5.520 -    if (write(io_fd, &nr_pfns, sizeof(unsigned long)) !=
   5.521 -	sizeof(unsigned long)) {
   5.522 -	ERR("write: nr_pfns");
   5.523 -	goto out;
   5.524 +    if ( write(io_fd, &nr_pfns, sizeof(unsigned long)) !=
   5.525 +         sizeof(unsigned long) )
   5.526 +    {
   5.527 +        ERR("write: nr_pfns");
   5.528 +        goto out;
   5.529      }
   5.530 -    if (write(io_fd, pfn_to_mfn_frame_list, PAGE_SIZE) != PAGE_SIZE) {
   5.531 +
   5.532 +    if ( write(io_fd, pfn_to_mfn_frame_list, PAGE_SIZE) != PAGE_SIZE )
   5.533 +    {
   5.534          ERR("write: pfn_to_mfn_frame_list");
   5.535          goto out;
   5.536      }
   5.537 @@ -678,7 +701,8 @@ int xc_linux_save(int xc_handle, int io_
   5.538  
   5.539      /* Now write out each data page, canonicalising page tables as we go... */
   5.540      
   5.541 -    while(1){
   5.542 +    for ( ; ; )
   5.543 +    {
   5.544          unsigned int prev_pc, sent_this_iter, N, batch;
   5.545  
   5.546          iter++;
   5.547 @@ -689,10 +713,12 @@ int xc_linux_save(int xc_handle, int io_
   5.548  
   5.549          DPRINTF("Saving memory pages: iter %d   0%%", iter);
   5.550  
   5.551 -        while( N < nr_pfns ){
   5.552 +        while ( N < nr_pfns )
   5.553 +        {
   5.554              unsigned int this_pc = (N * 100) / nr_pfns;
   5.555  
   5.556 -            if ( (this_pc - prev_pc) >= 5 ){
   5.557 +            if ( (this_pc - prev_pc) >= 5 )
   5.558 +            {
   5.559                  DPRINTF("\b\b\b\b%3d%%", this_pc);
   5.560                  prev_pc = this_pc;
   5.561              }
   5.562 @@ -701,10 +727,10 @@ int xc_linux_save(int xc_handle, int io_
   5.563                 but this is fast enough for the moment. */
   5.564  
   5.565              if ( !last_iter && 
   5.566 -		 xc_shadow_control(xc_handle, dom, 
   5.567 +                 xc_shadow_control(xc_handle, dom, 
   5.568                                     DOM0_SHADOW_CONTROL_OP_PEEK,
   5.569                                     to_skip, nr_pfns, NULL) != nr_pfns )
   5.570 -	    {
   5.571 +            {
   5.572                  ERR("Error peeking shadow bitmap");
   5.573                  goto out;
   5.574              }
   5.575 @@ -748,7 +774,7 @@ int xc_linux_save(int xc_handle, int io_
   5.576                  pfn_type[batch] = live_pfn_to_mfn_table[n];
   5.577  
   5.578                  if( ! is_mapped(pfn_type[batch]) )
   5.579 -		{
   5.580 +                {
   5.581                      /* not currently in pusedo-physical map -- set bit
   5.582                         in to_fix that we must send this page in last_iter
   5.583                         unless its sent sooner anyhow */
   5.584 @@ -756,7 +782,7 @@ int xc_linux_save(int xc_handle, int io_
   5.585                      set_bit( n, to_fix );
   5.586                      if( iter>1 )
   5.587                          DPRINTF("netbuf race: iter %d, pfn %x. mfn %lx\n",
   5.588 -				iter,n,pfn_type[batch]);
   5.589 +                                iter,n,pfn_type[batch]);
   5.590                      continue;
   5.591                  }
   5.592  
   5.593 @@ -790,8 +816,10 @@ int xc_linux_save(int xc_handle, int io_
   5.594                  goto out;
   5.595              }
   5.596       
   5.597 -            for ( j = 0; j < batch; j++ ){
   5.598 -                if ( (pfn_type[j] & LTAB_MASK) == XTAB ){
   5.599 +            for ( j = 0; j < batch; j++ )
   5.600 +            {
   5.601 +                if ( (pfn_type[j] & LTAB_MASK) == XTAB )
   5.602 +                {
   5.603                      DPRINTF("type fail: page %i mfn %08lx\n",j,pfn_type[j]);
   5.604                      continue;
   5.605                  }
   5.606 @@ -809,21 +837,25 @@ int xc_linux_save(int xc_handle, int io_
   5.607                  pfn_type[j] = (pfn_type[j] & LTAB_MASK) | pfn_batch[j];
   5.608              }
   5.609  
   5.610 -            if (write(io_fd, &batch, sizeof(int)) != sizeof(int)) {
   5.611 +            if ( write(io_fd, &batch, sizeof(int)) != sizeof(int) )
   5.612 +            {
   5.613                  ERR("Error when writing to state file (2)");
   5.614                  goto out;
   5.615              }
   5.616  
   5.617 -            if (write(io_fd, pfn_type, sizeof(unsigned long)*j) !=
   5.618 -		sizeof(unsigned long)*j) {
   5.619 +            if ( write(io_fd, pfn_type, sizeof(unsigned long)*j) !=
   5.620 +                 (sizeof(unsigned long) * j) )
   5.621 +            {
   5.622                  ERR("Error when writing to state file (3)");
   5.623                  goto out;
   5.624              }
   5.625       
   5.626              /* entering this loop, pfn_type is now in pfns (Not mfns) */
   5.627 -            for( j = 0; j < batch; j++ ){
   5.628 +            for ( j = 0; j < batch; j++ )
   5.629 +            {
   5.630                  /* write out pages in batch */
   5.631 -                if( (pfn_type[j] & LTAB_MASK) == XTAB){
   5.632 +                if ( (pfn_type[j] & LTAB_MASK) == XTAB )
   5.633 +                {
   5.634                      DPRINTF("SKIP BOGUS page %i mfn %08lx\n",j,pfn_type[j]);
   5.635                      continue;
   5.636                  }
   5.637 @@ -836,7 +868,8 @@ int xc_linux_save(int xc_handle, int io_
   5.638                            k < (((pfn_type[j] & LTABTYPE_MASK) == L2TAB) ? 
   5.639                                 (HYPERVISOR_VIRT_START >> L2_PAGETABLE_SHIFT) :
   5.640                                 1024); 
   5.641 -                          k++ ){
   5.642 +                          k++ )
   5.643 +                    {
   5.644                          unsigned long pfn;
   5.645  
   5.646                          if ( !(page[k] & _PAGE_PRESENT) )
   5.647 @@ -849,13 +882,13 @@ int xc_linux_save(int xc_handle, int io_
   5.648                          {
   5.649                              /* I don't think this should ever happen */
   5.650                              fprintf(stderr, "FNI %d : [%08lx,%d] pte=%08lx, "
   5.651 -				    "mfn=%08lx, pfn=%08lx [mfn]=%08lx\n",
   5.652 -				    j, pfn_type[j], k,
   5.653 -				    page[k], mfn, live_mfn_to_pfn_table[mfn],
   5.654 -				    (live_mfn_to_pfn_table[mfn]<nr_pfns)? 
   5.655 -				    live_pfn_to_mfn_table[
   5.656 -					live_mfn_to_pfn_table[mfn]] : 
   5.657 -				    0xdeadbeef);
   5.658 +                                    "mfn=%08lx, pfn=%08lx [mfn]=%08lx\n",
   5.659 +                                    j, pfn_type[j], k,
   5.660 +                                    page[k], mfn, live_mfn_to_pfn_table[mfn],
   5.661 +                                    (live_mfn_to_pfn_table[mfn]<nr_pfns)? 
   5.662 +                                    live_pfn_to_mfn_table[
   5.663 +                                        live_mfn_to_pfn_table[mfn]] : 
   5.664 +                                    0xdeadbeef);
   5.665  
   5.666                              pfn = 0; /* be suspicious */
   5.667                          }
   5.668 @@ -865,12 +898,12 @@ int xc_linux_save(int xc_handle, int io_
   5.669     
   5.670  #if 0
   5.671                          fprintf(stderr,
   5.672 -				"L%d i=%d pfn=%d mfn=%d k=%d pte=%08lx "
   5.673 -				"xpfn=%d\n",
   5.674 -				pfn_type[j]>>28,
   5.675 -				j,i,mfn,k,page[k],page[k]>>PAGE_SHIFT);
   5.676 +                                "L%d i=%d pfn=%d mfn=%d k=%d pte=%08lx "
   5.677 +                                "xpfn=%d\n",
   5.678 +                                pfn_type[j]>>28,
   5.679 +                                j,i,mfn,k,page[k],page[k]>>PAGE_SHIFT);
   5.680  #endif     
   5.681 -			
   5.682 +   
   5.683                      } /* end of page table rewrite for loop */
   5.684        
   5.685                      if (ratewrite(io_fd, page, PAGE_SIZE) != PAGE_SIZE) {
   5.686 @@ -880,8 +913,9 @@ int xc_linux_save(int xc_handle, int io_
   5.687        
   5.688                  }  /* end of it's a PT page */ else {  /* normal page */
   5.689  
   5.690 -                    if (ratewrite(io_fd, region_base + (PAGE_SIZE*j), 
   5.691 -				  PAGE_SIZE) != PAGE_SIZE) {
   5.692 +                    if ( ratewrite(io_fd, region_base + (PAGE_SIZE*j), 
   5.693 +                                   PAGE_SIZE) != PAGE_SIZE )
   5.694 +                    {
   5.695                          ERR("Error when writing to state file (5)");
   5.696                          goto out;
   5.697                      }
   5.698 @@ -899,13 +933,13 @@ int xc_linux_save(int xc_handle, int io_
   5.699          total_sent += sent_this_iter;
   5.700  
   5.701          DPRINTF("\r %d: sent %d, skipped %d, ", 
   5.702 -                       iter, sent_this_iter, skip_this_iter );
   5.703 +                iter, sent_this_iter, skip_this_iter );
   5.704  
   5.705          if ( last_iter ) {
   5.706              print_stats( xc_handle, dom, sent_this_iter, &stats, 1);
   5.707  
   5.708              DPRINTF("Total pages sent= %d (%.2fx)\n", 
   5.709 -                           total_sent, ((float)total_sent)/nr_pfns );
   5.710 +                    total_sent, ((float)total_sent)/nr_pfns );
   5.711              DPRINTF("(of which %d were fixups)\n", needed_to_fix  );
   5.712          }       
   5.713  
   5.714 @@ -930,7 +964,7 @@ int xc_linux_save(int xc_handle, int io_
   5.715          {
   5.716              if ( 
   5.717                  ( ( sent_this_iter > sent_last_iter ) &&
   5.718 -		  (mbit_rate == MAX_MBIT_RATE ) ) ||
   5.719 +                  (mbit_rate == MAX_MBIT_RATE ) ) ||
   5.720                  (iter >= max_iters) || 
   5.721                  (sent_this_iter+skip_this_iter < 50) || 
   5.722                  (total_sent > nr_pfns*max_factor) )
   5.723 @@ -938,15 +972,15 @@ int xc_linux_save(int xc_handle, int io_
   5.724                  DPRINTF("Start last iteration\n");
   5.725                  last_iter = 1;
   5.726  
   5.727 -		if ( suspend_and_state( xc_handle, io_fd, dom, &info, &ctxt) )
   5.728 -		{
   5.729 -		    ERR("Domain appears not to have suspended");
   5.730 -		    goto out;
   5.731 -		}
   5.732 +                if ( suspend_and_state( xc_handle, io_fd, dom, &info, &ctxt) )
   5.733 +                {
   5.734 +                    ERR("Domain appears not to have suspended");
   5.735 +                    goto out;
   5.736 +                }
   5.737  
   5.738 -		DPRINTF("SUSPEND shinfo %08lx eip %08u esi %08u\n",
   5.739 -			info.shared_info_frame,
   5.740 -			ctxt.user_regs.eip, ctxt.user_regs.esi);
   5.741 +                DPRINTF("SUSPEND shinfo %08lx eip %08u esi %08u\n",
   5.742 +                        info.shared_info_frame,
   5.743 +                        ctxt.user_regs.eip, ctxt.user_regs.esi);
   5.744              } 
   5.745  
   5.746              if ( xc_shadow_control( xc_handle, dom, 
   5.747 @@ -972,86 +1006,92 @@ int xc_linux_save(int xc_handle, int io_
   5.748      rc = 0;
   5.749      
   5.750      /* Zero terminate */
   5.751 -    if (write(io_fd, &rc, sizeof(int)) != sizeof(int)) {
   5.752 +    if ( write(io_fd, &rc, sizeof(int)) != sizeof(int) )
   5.753 +    {
   5.754          ERR("Error when writing to state file (6)");
   5.755          goto out;
   5.756      }
   5.757  
   5.758      /* Send through a list of all the PFNs that were not in map at the close */
   5.759      {
   5.760 -	unsigned int i,j;
   5.761 -	unsigned int pfntab[1024];
   5.762 +        unsigned int i,j;
   5.763 +        unsigned int pfntab[1024];
   5.764  
   5.765 -	for ( i = 0, j = 0; i < nr_pfns; i++ )
   5.766 -	{
   5.767 -	    if ( ! is_mapped(live_pfn_to_mfn_table[i]) )
   5.768 -		j++;
   5.769 -	}
   5.770 +        for ( i = 0, j = 0; i < nr_pfns; i++ )
   5.771 +            if ( !is_mapped(live_pfn_to_mfn_table[i]) )
   5.772 +                j++;
   5.773  
   5.774 -	if (write(io_fd, &j, sizeof(unsigned int)) != sizeof(unsigned int)) {
   5.775 -	    ERR("Error when writing to state file (6a)");
   5.776 -	    goto out;
   5.777 -	}	
   5.778 +        if ( write(io_fd, &j, sizeof(unsigned int)) != sizeof(unsigned int) )
   5.779 +        {
   5.780 +            ERR("Error when writing to state file (6a)");
   5.781 +            goto out;
   5.782 +        } 
   5.783  
   5.784 -	for ( i = 0, j = 0; i < nr_pfns; )
   5.785 -	{
   5.786 -	    if ( ! is_mapped(live_pfn_to_mfn_table[i]) )
   5.787 -	    {
   5.788 -		pfntab[j++] = i;
   5.789 -	    }
   5.790 -	    i++;
   5.791 -	    if ( j == 1024 || i == nr_pfns )
   5.792 -	    {
   5.793 -		if (write(io_fd, &pfntab, sizeof(unsigned long)*j) !=
   5.794 -		    sizeof(unsigned long)*j) {
   5.795 -		    ERR("Error when writing to state file (6b)");
   5.796 -		    goto out;
   5.797 -		}	
   5.798 -		j = 0;
   5.799 -	    }
   5.800 -	}
   5.801 +        for ( i = 0, j = 0; i < nr_pfns; )
   5.802 +        {
   5.803 +            if ( !is_mapped(live_pfn_to_mfn_table[i]) )
   5.804 +            {
   5.805 +                pfntab[j++] = i;
   5.806 +            }
   5.807 +            i++;
   5.808 +            if ( j == 1024 || i == nr_pfns )
   5.809 +            {
   5.810 +                if ( write(io_fd, &pfntab, sizeof(unsigned long)*j) !=
   5.811 +                     (sizeof(unsigned long) * j) )
   5.812 +                {
   5.813 +                    ERR("Error when writing to state file (6b)");
   5.814 +                    goto out;
   5.815 +                } 
   5.816 +                j = 0;
   5.817 +            }
   5.818 +        }
   5.819      }
   5.820  
   5.821      /* Canonicalise the suspend-record frame number. */
   5.822 -    if ( !translate_mfn_to_pfn(&ctxt.user_regs.esi) ){
   5.823 +    if ( !translate_mfn_to_pfn(&ctxt.user_regs.esi) )
   5.824 +    {
   5.825          ERR("Suspend record is not in range of pseudophys map");
   5.826          goto out;
   5.827      }
   5.828  
   5.829      /* Canonicalise each GDT frame number. */
   5.830 -    for ( i = 0; i < ctxt.gdt_ents; i += 512 ) {
   5.831 -        if ( !translate_mfn_to_pfn(&ctxt.gdt_frames[i]) ) {
   5.832 +    for ( i = 0; i < ctxt.gdt_ents; i += 512 )
   5.833 +    {
   5.834 +        if ( !translate_mfn_to_pfn(&ctxt.gdt_frames[i]) ) 
   5.835 +        {
   5.836              ERR("GDT frame is not in range of pseudophys map");
   5.837              goto out;
   5.838          }
   5.839      }
   5.840  
   5.841      /* Canonicalise the page table base pointer. */
   5.842 -    if ( !MFN_IS_IN_PSEUDOPHYS_MAP(ctxt.ctrlreg[3] >> PAGE_SHIFT) ) {
   5.843 +    if ( !MFN_IS_IN_PSEUDOPHYS_MAP(ctxt.ctrlreg[3] >> PAGE_SHIFT) )
   5.844 +    {
   5.845          ERR("PT base is not in range of pseudophys map");
   5.846          goto out;
   5.847      }
   5.848      ctxt.ctrlreg[3] = live_mfn_to_pfn_table[ctxt.ctrlreg[3] >> PAGE_SHIFT] <<
   5.849          PAGE_SHIFT;
   5.850  
   5.851 -    if (write(io_fd, &ctxt, sizeof(ctxt)) != sizeof(ctxt) ||
   5.852 -	write(io_fd, live_shinfo, PAGE_SIZE) != PAGE_SIZE) {
   5.853 +    if ( write(io_fd, &ctxt, sizeof(ctxt)) != sizeof(ctxt) ||
   5.854 +         write(io_fd, live_shinfo, PAGE_SIZE) != PAGE_SIZE)
   5.855 +    {
   5.856          ERR("Error when writing to state file (1)");
   5.857          goto out;
   5.858      }
   5.859  
   5.860   out:
   5.861  
   5.862 -    if(live_shinfo)
   5.863 +    if ( live_shinfo )
   5.864          munmap(live_shinfo, PAGE_SIZE);
   5.865  
   5.866 -    if(live_pfn_to_mfn_frame_list) 
   5.867 +    if ( live_pfn_to_mfn_frame_list ) 
   5.868          munmap(live_pfn_to_mfn_frame_list, PAGE_SIZE);
   5.869  
   5.870 -    if(live_pfn_to_mfn_table) 
   5.871 +    if ( live_pfn_to_mfn_table ) 
   5.872          munmap(live_pfn_to_mfn_table, nr_pfns*4);
   5.873  
   5.874 -    if(live_mfn_to_pfn_table) 
   5.875 +    if ( live_mfn_to_pfn_table ) 
   5.876          munmap(live_mfn_to_pfn_table, PAGE_SIZE*1024);
   5.877  
   5.878      free(pfn_type);
   5.879 @@ -1063,3 +1103,13 @@ int xc_linux_save(int xc_handle, int io_
   5.880      DPRINTF("Save exit rc=%d\n",rc);
   5.881      return !!rc;
   5.882  }
   5.883 +
   5.884 +/*
   5.885 + * Local variables:
   5.886 + * mode: C
   5.887 + * c-set-style: "BSD"
   5.888 + * c-basic-offset: 4
   5.889 + * tab-width: 4
   5.890 + * indent-tabs-mode: nil
   5.891 + * End:
   5.892 + */
     6.1 --- a/tools/libxc/xc_load_aout9.c	Mon Sep 19 09:14:41 2005 +0000
     6.2 +++ b/tools/libxc/xc_load_aout9.c	Mon Sep 19 11:06:05 2005 +0000
     6.3 @@ -64,11 +64,11 @@ parseaout9image(
     6.4      dstart = round_pgup(start + ehdr.text);
     6.5      end = dstart + ehdr.data + ehdr.bss;
     6.6  
     6.7 -    dsi->v_start	= KZERO;
     6.8 -    dsi->v_kernstart	= start;
     6.9 -    dsi->v_kernend	= end;
    6.10 -    dsi->v_kernentry	= ehdr.entry;
    6.11 -    dsi->v_end		= end;
    6.12 +    dsi->v_start     = KZERO;
    6.13 +    dsi->v_kernstart = start;
    6.14 +    dsi->v_kernend   = end;
    6.15 +    dsi->v_kernentry = ehdr.entry;
    6.16 +    dsi->v_end       = end;
    6.17  
    6.18      /* XXX load symbols */
    6.19  
    6.20 @@ -168,3 +168,12 @@ get_header(
    6.21      return ehdr;
    6.22  }
    6.23  
    6.24 +/*
    6.25 + * Local variables:
    6.26 + * mode: C
    6.27 + * c-set-style: "BSD"
    6.28 + * c-basic-offset: 4
    6.29 + * tab-width: 4
    6.30 + * indent-tabs-mode: nil
    6.31 + * End:
    6.32 + */
     7.1 --- a/tools/libxc/xc_load_bin.c	Mon Sep 19 09:14:41 2005 +0000
     7.2 +++ b/tools/libxc/xc_load_bin.c	Mon Sep 19 11:06:05 2005 +0000
     7.3 @@ -109,8 +109,8 @@ loadbinimage(
     7.4      unsigned long *parray, struct domain_setup_info *dsi);
     7.5  
     7.6  int probe_bin(char *image,
     7.7 -	      unsigned long image_size,
     7.8 -	      struct load_funcs *load_funcs)
     7.9 +              unsigned long image_size,
    7.10 +              struct load_funcs *load_funcs)
    7.11  {
    7.12      if ( NULL == findtable(image, image_size) )
    7.13      {
    7.14 @@ -297,3 +297,13 @@ loadbinimage(
    7.15  
    7.16      return 0;
    7.17  }
    7.18 +
    7.19 +/*
    7.20 + * Local variables:
    7.21 + * mode: C
    7.22 + * c-set-style: "BSD"
    7.23 + * c-basic-offset: 4
    7.24 + * tab-width: 4
    7.25 + * indent-tabs-mode: nil
    7.26 + * End:
    7.27 + */
     8.1 --- a/tools/libxc/xc_load_elf.c	Mon Sep 19 09:14:41 2005 +0000
     8.2 +++ b/tools/libxc/xc_load_elf.c	Mon Sep 19 11:06:05 2005 +0000
     8.3 @@ -30,8 +30,8 @@ loadelfsymtab(
     8.4      struct domain_setup_info *dsi);
     8.5  
     8.6  int probe_elf(char *image,
     8.7 -	      unsigned long image_size,
     8.8 -	      struct load_funcs *load_funcs)
     8.9 +              unsigned long image_size,
    8.10 +              struct load_funcs *load_funcs)
    8.11  {
    8.12      Elf_Ehdr *ehdr = (Elf_Ehdr *)image;
    8.13  
    8.14 @@ -116,7 +116,7 @@ static int parseelfimage(char *image,
    8.15              return -EINVAL;
    8.16          }
    8.17          if ( (strstr(guestinfo, "PAE=yes") != NULL) )
    8.18 -	    dsi->pae_kernel = 1;
    8.19 +            dsi->pae_kernel = 1;
    8.20  
    8.21          break;
    8.22      }
    8.23 @@ -313,3 +313,13 @@ loadelfsymtab(
    8.24  
    8.25      return 0;
    8.26  }
    8.27 +
    8.28 +/*
    8.29 + * Local variables:
    8.30 + * mode: C
    8.31 + * c-set-style: "BSD"
    8.32 + * c-basic-offset: 4
    8.33 + * tab-width: 4
    8.34 + * indent-tabs-mode: nil
    8.35 + * End:
    8.36 + */
     9.1 --- a/tools/libxc/xc_misc.c	Mon Sep 19 09:14:41 2005 +0000
     9.2 +++ b/tools/libxc/xc_misc.c	Mon Sep 19 11:06:05 2005 +0000
     9.3 @@ -133,5 +133,15 @@ int xc_msr_write(int xc_handle, int cpu_
     9.4  
     9.5  long xc_init_store(int xc_handle, int remote_port)
     9.6  {
     9.7 -	return ioctl(xc_handle, IOCTL_PRIVCMD_INITDOMAIN_STORE, remote_port);
     9.8 +    return ioctl(xc_handle, IOCTL_PRIVCMD_INITDOMAIN_STORE, remote_port);
     9.9  }
    9.10 +
    9.11 +/*
    9.12 + * Local variables:
    9.13 + * mode: C
    9.14 + * c-set-style: "BSD"
    9.15 + * c-basic-offset: 4
    9.16 + * tab-width: 4
    9.17 + * indent-tabs-mode: nil
    9.18 + * End:
    9.19 + */
    10.1 --- a/tools/libxc/xc_private.c	Mon Sep 19 09:14:41 2005 +0000
    10.2 +++ b/tools/libxc/xc_private.c	Mon Sep 19 11:06:05 2005 +0000
    10.3 @@ -15,7 +15,7 @@ void *xc_map_foreign_batch(int xc_handle
    10.4      void *addr;
    10.5      addr = mmap(NULL, num*PAGE_SIZE, prot, MAP_SHARED, xc_handle, 0);
    10.6      if ( addr == MAP_FAILED )
    10.7 -	return NULL;
    10.8 +        return NULL;
    10.9  
   10.10      ioctlx.num=num;
   10.11      ioctlx.dom=dom;
   10.12 @@ -24,10 +24,10 @@ void *xc_map_foreign_batch(int xc_handle
   10.13      if ( ioctl( xc_handle, IOCTL_PRIVCMD_MMAPBATCH, &ioctlx ) < 0 )
   10.14      {
   10.15          int saved_errno = errno;
   10.16 -	perror("XXXXXXXX");
   10.17 -	(void)munmap(addr, num*PAGE_SIZE);
   10.18 +        perror("XXXXXXXX");
   10.19 +        (void)munmap(addr, num*PAGE_SIZE);
   10.20          errno = saved_errno;
   10.21 -	return NULL;
   10.22 +        return NULL;
   10.23      }
   10.24      return addr;
   10.25  
   10.26 @@ -36,15 +36,15 @@ void *xc_map_foreign_batch(int xc_handle
   10.27  /*******************/
   10.28  
   10.29  void *xc_map_foreign_range(int xc_handle, u32 dom,
   10.30 -                            int size, int prot,
   10.31 -                            unsigned long mfn )
   10.32 +                           int size, int prot,
   10.33 +                           unsigned long mfn )
   10.34  {
   10.35      privcmd_mmap_t ioctlx; 
   10.36      privcmd_mmap_entry_t entry; 
   10.37      void *addr;
   10.38      addr = mmap(NULL, size, prot, MAP_SHARED, xc_handle, 0);
   10.39      if ( addr == MAP_FAILED )
   10.40 -	return NULL;
   10.41 +        return NULL;
   10.42  
   10.43      ioctlx.num=1;
   10.44      ioctlx.dom=dom;
   10.45 @@ -55,9 +55,9 @@ void *xc_map_foreign_range(int xc_handle
   10.46      if ( ioctl( xc_handle, IOCTL_PRIVCMD_MMAP, &ioctlx ) < 0 )
   10.47      {
   10.48          int saved_errno = errno;
   10.49 -	(void)munmap(addr, size);
   10.50 +        (void)munmap(addr, size);
   10.51          errno = saved_errno;
   10.52 -	return NULL;
   10.53 +        return NULL;
   10.54      }
   10.55      return addr;
   10.56  }
   10.57 @@ -66,7 +66,7 @@ void *xc_map_foreign_range(int xc_handle
   10.58  
   10.59  /* NB: arr must be mlock'ed */
   10.60  int xc_get_pfn_type_batch(int xc_handle, 
   10.61 -			  u32 dom, int num, unsigned long *arr)
   10.62 +                          u32 dom, int num, unsigned long *arr)
   10.63  {
   10.64      dom0_op_t op;
   10.65      op.cmd = DOM0_GETPAGEFRAMEINFO2;
   10.66 @@ -116,8 +116,8 @@ int xc_mmuext_op(
   10.67  
   10.68      if ( (ret = do_xen_hypercall(xc_handle, &hypercall)) < 0 )
   10.69      {
   10.70 -	fprintf(stderr, "Dom_mmuext operation failed (rc=%ld errno=%d)-- need to"
   10.71 -                    " rebuild the user-space tool set?\n",ret,errno);
   10.72 +        fprintf(stderr, "Dom_mmuext operation failed (rc=%ld errno=%d)-- need to"
   10.73 +                " rebuild the user-space tool set?\n",ret,errno);
   10.74      }
   10.75  
   10.76      safe_munlock(op, nr_ops*sizeof(*op));
   10.77 @@ -172,7 +172,7 @@ xc_mmu_t *xc_init_mmu_updates(int xc_han
   10.78  }
   10.79  
   10.80  int xc_add_mmu_update(int xc_handle, xc_mmu_t *mmu, 
   10.81 -		      unsigned long long ptr, unsigned long long val)
   10.82 +                      unsigned long long ptr, unsigned long long val)
   10.83  {
   10.84      mmu->updates[mmu->idx].ptr = ptr;
   10.85      mmu->updates[mmu->idx].val = val;
   10.86 @@ -229,7 +229,7 @@ int xc_memory_op(int xc_handle,
   10.87  
   10.88      if ( (ret = do_xen_hypercall(xc_handle, &hypercall)) < 0 )
   10.89      {
   10.90 -	fprintf(stderr, "hypercall failed (rc=%ld errno=%d)-- need to"
   10.91 +        fprintf(stderr, "hypercall failed (rc=%ld errno=%d)-- need to"
   10.92                  " rebuild the user-space tool set?\n",ret,errno);
   10.93      }
   10.94  
   10.95 @@ -275,16 +275,16 @@ unsigned long xc_get_m2p_start_mfn ( int
   10.96  
   10.97      if ( ioctl( xc_handle, IOCTL_PRIVCMD_GET_MACH2PHYS_START_MFN, &mfn ) < 0 )
   10.98      {
   10.99 -	perror("xc_get_m2p_start_mfn:");
  10.100 -	return 0;
  10.101 +        perror("xc_get_m2p_start_mfn:");
  10.102 +        return 0;
  10.103      }
  10.104      return mfn;
  10.105  }
  10.106  
  10.107  int xc_get_pfn_list(int xc_handle,
  10.108 -		 u32 domid, 
  10.109 -		 unsigned long *pfn_buf, 
  10.110 -		 unsigned long max_pfns)
  10.111 +                    u32 domid, 
  10.112 +                    unsigned long *pfn_buf, 
  10.113 +                    unsigned long max_pfns)
  10.114  {
  10.115      dom0_op_t op;
  10.116      int ret;
  10.117 @@ -306,16 +306,16 @@ int xc_get_pfn_list(int xc_handle,
  10.118  
  10.119  #if 0
  10.120  #ifdef DEBUG
  10.121 -	DPRINTF(("Ret for xc_get_pfn_list is %d\n", ret));
  10.122 -	if (ret >= 0) {
  10.123 -		int i, j;
  10.124 -		for (i = 0; i < op.u.getmemlist.num_pfns; i += 16) {
  10.125 -			fprintf(stderr, "0x%x: ", i);
  10.126 -			for (j = 0; j < 16; j++)
  10.127 -				fprintf(stderr, "0x%lx ", pfn_buf[i + j]);
  10.128 -			fprintf(stderr, "\n");
  10.129 -		}
  10.130 -	}
  10.131 +    DPRINTF(("Ret for xc_get_pfn_list is %d\n", ret));
  10.132 +    if (ret >= 0) {
  10.133 +        int i, j;
  10.134 +        for (i = 0; i < op.u.getmemlist.num_pfns; i += 16) {
  10.135 +            fprintf(stderr, "0x%x: ", i);
  10.136 +            for (j = 0; j < 16; j++)
  10.137 +                fprintf(stderr, "0x%lx ", pfn_buf[i + j]);
  10.138 +            fprintf(stderr, "\n");
  10.139 +        }
  10.140 +    }
  10.141  #endif
  10.142  #endif
  10.143  
  10.144 @@ -324,10 +324,10 @@ int xc_get_pfn_list(int xc_handle,
  10.145  
  10.146  #ifdef __ia64__
  10.147  int xc_ia64_get_pfn_list(int xc_handle,
  10.148 -		 u32 domid, 
  10.149 -		 unsigned long *pfn_buf, 
  10.150 -		 unsigned int start_page,
  10.151 -		 unsigned int nr_pages)
  10.152 +                         u32 domid, 
  10.153 +                         unsigned long *pfn_buf, 
  10.154 +                         unsigned int start_page,
  10.155 +                         unsigned int nr_pages)
  10.156  {
  10.157      dom0_op_t op;
  10.158      int ret;
  10.159 @@ -372,9 +372,9 @@ long xc_get_tot_pages(int xc_handle, u32
  10.160  }
  10.161  
  10.162  int xc_copy_to_domain_page(int xc_handle,
  10.163 -                                   u32 domid,
  10.164 -                                   unsigned long dst_pfn, 
  10.165 -                                   void *src_page)
  10.166 +                           u32 domid,
  10.167 +                           unsigned long dst_pfn, 
  10.168 +                           void *src_page)
  10.169  {
  10.170      void *vaddr = xc_map_foreign_range(
  10.171          xc_handle, domid, PAGE_SIZE, PROT_WRITE, dst_pfn);
  10.172 @@ -465,18 +465,28 @@ unsigned long xc_make_page_below_4G(
  10.173      unsigned long new_mfn;
  10.174  
  10.175      if ( xc_domain_memory_decrease_reservation( 
  10.176 -	xc_handle, domid, 1, 0, &mfn) != 0 )
  10.177 +        xc_handle, domid, 1, 0, &mfn) != 0 )
  10.178      {
  10.179 -	fprintf(stderr,"xc_make_page_below_4G decrease failed. mfn=%lx\n",mfn);
  10.180 -	return 0;
  10.181 +        fprintf(stderr,"xc_make_page_below_4G decrease failed. mfn=%lx\n",mfn);
  10.182 +        return 0;
  10.183      }
  10.184  
  10.185      if ( xc_domain_memory_increase_reservation(
  10.186          xc_handle, domid, 1, 0, 32, &new_mfn) != 0 )
  10.187      {
  10.188 -	fprintf(stderr,"xc_make_page_below_4G increase failed. mfn=%lx\n",mfn);
  10.189 -	return 0;
  10.190 +        fprintf(stderr,"xc_make_page_below_4G increase failed. mfn=%lx\n",mfn);
  10.191 +        return 0;
  10.192      }
  10.193  
  10.194      return new_mfn;
  10.195  }
  10.196 +
  10.197 +/*
  10.198 + * Local variables:
  10.199 + * mode: C
  10.200 + * c-set-style: "BSD"
  10.201 + * c-basic-offset: 4
  10.202 + * tab-width: 4
  10.203 + * indent-tabs-mode: nil
  10.204 + * End:
  10.205 + */
    11.1 --- a/tools/libxc/xc_ptrace.c	Mon Sep 19 09:14:41 2005 +0000
    11.2 +++ b/tools/libxc/xc_ptrace.c	Mon Sep 19 11:06:05 2005 +0000
    11.3 @@ -5,12 +5,9 @@
    11.4  
    11.5  #define X86_CR0_PE              0x00000001 /* Enable Protected Mode    (RW) */
    11.6  #define X86_CR0_PG              0x80000000 /* Paging                   (RW) */
    11.7 -
    11.8 -#define BSD_PAGE_MASK	(PAGE_SIZE-1)
    11.9 -#define	PG_FRAME	(~((unsigned long)BSD_PAGE_MASK)
   11.10 +#define BSD_PAGE_MASK (PAGE_SIZE-1)
   11.11  #define PDRSHIFT        22
   11.12 -#define	PSL_T		0x00000100	/* trace enable bit */
   11.13 -
   11.14 +#define PSL_T  0x00000100 /* trace enable bit */
   11.15  #define VCPU            0               /* XXX */
   11.16  
   11.17  /*
   11.18 @@ -69,67 +66,66 @@ struct gdb_regs {
   11.19      int  xss;    /* 64 */
   11.20  };
   11.21  
   11.22 -#define FETCH_REGS(cpu) \
   11.23 -    if (!regs_valid[cpu]) \
   11.24 -    {                \
   11.25 -	int retval = xc_domain_get_vcpu_context(xc_handle, domid, cpu, &ctxt[cpu]); \
   11.26 -	if (retval) \
   11.27 -	    goto error_out; \
   11.28 -	cr3[cpu] = ctxt[cpu].ctrlreg[3]; /* physical address */ \
   11.29 -	regs_valid[cpu] = 1; \
   11.30 -    } \
   11.31 +#define FETCH_REGS(cpu)                                         \
   11.32 +    if (!regs_valid[cpu])                                       \
   11.33 +    {                                                           \
   11.34 +        int retval = xc_domain_get_vcpu_context(                \
   11.35 +            xc_handle, domid, cpu, &ctxt[cpu]);                 \
   11.36 +        if (retval)                                             \
   11.37 +            goto error_out;                                     \
   11.38 +        cr3[cpu] = ctxt[cpu].ctrlreg[3]; /* physical address */ \
   11.39 +        regs_valid[cpu] = 1;                                    \
   11.40 +    }
   11.41  
   11.42  #define printval(x) printf("%s = %lx\n", #x, (long)x);
   11.43 -#define SET_PT_REGS(pt, xc) \
   11.44 -{ \
   11.45 -    pt.ebx = xc.ebx; \
   11.46 -    pt.ecx = xc.ecx; \
   11.47 -    pt.edx = xc.edx; \
   11.48 -    pt.esi = xc.esi; \
   11.49 -    pt.edi = xc.edi; \
   11.50 -    pt.ebp = xc.ebp; \
   11.51 -    pt.eax = xc.eax; \
   11.52 -    pt.eip = xc.eip; \
   11.53 -    pt.xcs = xc.cs; \
   11.54 -    pt.eflags = xc.eflags; \
   11.55 -    pt.esp = xc.esp; \
   11.56 -    pt.xss = xc.ss; \
   11.57 -    pt.xes = xc.es; \
   11.58 -    pt.xds = xc.ds; \
   11.59 -    pt.xfs = xc.fs; \
   11.60 -    pt.xgs = xc.gs; \
   11.61 +#define SET_PT_REGS(pt, xc)                     \
   11.62 +{                                               \
   11.63 +    pt.ebx = xc.ebx;                            \
   11.64 +    pt.ecx = xc.ecx;                            \
   11.65 +    pt.edx = xc.edx;                            \
   11.66 +    pt.esi = xc.esi;                            \
   11.67 +    pt.edi = xc.edi;                            \
   11.68 +    pt.ebp = xc.ebp;                            \
   11.69 +    pt.eax = xc.eax;                            \
   11.70 +    pt.eip = xc.eip;                            \
   11.71 +    pt.xcs = xc.cs;                             \
   11.72 +    pt.eflags = xc.eflags;                      \
   11.73 +    pt.esp = xc.esp;                            \
   11.74 +    pt.xss = xc.ss;                             \
   11.75 +    pt.xes = xc.es;                             \
   11.76 +    pt.xds = xc.ds;                             \
   11.77 +    pt.xfs = xc.fs;                             \
   11.78 +    pt.xgs = xc.gs;                             \
   11.79  }
   11.80  
   11.81 -#define SET_XC_REGS(pt, xc) \
   11.82 -{ \
   11.83 -    xc.ebx = pt->ebx; \
   11.84 -    xc.ecx = pt->ecx; \
   11.85 -    xc.edx = pt->edx; \
   11.86 -    xc.esi = pt->esi; \
   11.87 -    xc.edi = pt->edi; \
   11.88 -    xc.ebp = pt->ebp; \
   11.89 -    xc.eax = pt->eax; \
   11.90 -    xc.eip = pt->eip; \
   11.91 -    xc.cs = pt->xcs; \
   11.92 -    xc.eflags = pt->eflags; \
   11.93 -    xc.esp = pt->esp; \
   11.94 -    xc.ss = pt->xss; \
   11.95 -    xc.es = pt->xes; \
   11.96 -    xc.ds = pt->xds; \
   11.97 -    xc.fs = pt->xfs; \
   11.98 -    xc.gs = pt->xgs; \
   11.99 +#define SET_XC_REGS(pt, xc)                     \
  11.100 +{                                               \
  11.101 +    xc.ebx = pt->ebx;                           \
  11.102 +    xc.ecx = pt->ecx;                           \
  11.103 +    xc.edx = pt->edx;                           \
  11.104 +    xc.esi = pt->esi;                           \
  11.105 +    xc.edi = pt->edi;                           \
  11.106 +    xc.ebp = pt->ebp;                           \
  11.107 +    xc.eax = pt->eax;                           \
  11.108 +    xc.eip = pt->eip;                           \
  11.109 +    xc.cs = pt->xcs;                            \
  11.110 +    xc.eflags = pt->eflags;                     \
  11.111 +    xc.esp = pt->esp;                           \
  11.112 +    xc.ss = pt->xss;                            \
  11.113 +    xc.es = pt->xes;                            \
  11.114 +    xc.ds = pt->xds;                            \
  11.115 +    xc.fs = pt->xfs;                            \
  11.116 +    xc.gs = pt->xgs;                            \
  11.117  }
  11.118  
  11.119 -
  11.120  #define vtopdi(va) ((va) >> PDRSHIFT)
  11.121  #define vtopti(va) (((va) >> PAGE_SHIFT) & 0x3ff)
  11.122  
  11.123  /* XXX application state */
  11.124  
  11.125 -
  11.126  static int                      xc_handle;
  11.127 -static long			nr_pages = 0;
  11.128 -unsigned long			*page_array = NULL;
  11.129 +static long   nr_pages = 0;
  11.130 +unsigned long   *page_array = NULL;
  11.131  static int                      regs_valid[MAX_VIRT_CPUS];
  11.132  static unsigned long            cr3[MAX_VIRT_CPUS];
  11.133  static vcpu_guest_context_t ctxt[MAX_VIRT_CPUS];
  11.134 @@ -160,64 +156,64 @@ map_domain_va(unsigned long domid, int c
  11.135      static int            prev_perm[MAX_VIRT_CPUS];
  11.136  
  11.137      if (nr_pages != npgs) {
  11.138 -	if (nr_pages > 0)
  11.139 -	    free(page_array);
  11.140 -	nr_pages = npgs;
  11.141 -	if ((page_array = malloc(nr_pages * sizeof(unsigned long))) == NULL) {
  11.142 -	    printf("Could not allocate memory\n");
  11.143 -	    goto error_out;
  11.144 -	}
  11.145 +        if (nr_pages > 0)
  11.146 +            free(page_array);
  11.147 +        nr_pages = npgs;
  11.148 +        if ((page_array = malloc(nr_pages * sizeof(unsigned long))) == NULL) {
  11.149 +            printf("Could not allocate memory\n");
  11.150 +            goto error_out;
  11.151 +        }
  11.152  
  11.153 -	if (xc_get_pfn_list(xc_handle, domid, page_array, nr_pages) != nr_pages) {
  11.154 -		printf("Could not get the page frame list\n");
  11.155 -		goto error_out;
  11.156 -	}
  11.157 +        if (xc_get_pfn_list(xc_handle, domid, page_array, nr_pages) != nr_pages) {
  11.158 +            printf("Could not get the page frame list\n");
  11.159 +            goto error_out;
  11.160 +        }
  11.161      }
  11.162  
  11.163      FETCH_REGS(cpu);
  11.164  
  11.165      if (cr3[cpu] != cr3_phys[cpu]) 
  11.166      {
  11.167 -	cr3_phys[cpu] = cr3[cpu];
  11.168 -	if (cr3_virt[cpu])
  11.169 -	    munmap(cr3_virt[cpu], PAGE_SIZE);
  11.170 -	if ((cr3_virt[cpu] = xc_map_foreign_range(xc_handle, domid, PAGE_SIZE,
  11.171 -					     PROT_READ,
  11.172 -					     cr3_phys[cpu] >> PAGE_SHIFT)) == NULL)
  11.173 -	    goto error_out;
  11.174 +        cr3_phys[cpu] = cr3[cpu];
  11.175 +        if (cr3_virt[cpu])
  11.176 +            munmap(cr3_virt[cpu], PAGE_SIZE);
  11.177 +        if ((cr3_virt[cpu] = xc_map_foreign_range(xc_handle, domid, PAGE_SIZE,
  11.178 +                                                  PROT_READ,
  11.179 +                                                  cr3_phys[cpu] >> PAGE_SHIFT)) == NULL)
  11.180 +            goto error_out;
  11.181      } 
  11.182      if ((pde = cr3_virt[cpu][vtopdi(va)]) == 0) /* logical address */
  11.183 -	goto error_out;
  11.184 +        goto error_out;
  11.185      if ((ctxt[cpu].flags & VGCF_VMX_GUEST) && paging_enabled(&ctxt[cpu]))
  11.186          pde = page_array[pde >> PAGE_SHIFT] << PAGE_SHIFT;
  11.187      if (pde != pde_phys[cpu]) 
  11.188      {
  11.189 -	pde_phys[cpu] = pde;
  11.190 -	if (pde_virt[cpu])
  11.191 -	    munmap(pde_virt[cpu], PAGE_SIZE);
  11.192 -	if ((pde_virt[cpu] = xc_map_foreign_range(xc_handle, domid, PAGE_SIZE,
  11.193 -					     PROT_READ,
  11.194 -					     pde_phys[cpu] >> PAGE_SHIFT)) == NULL)
  11.195 -	    goto error_out;
  11.196 +        pde_phys[cpu] = pde;
  11.197 +        if (pde_virt[cpu])
  11.198 +            munmap(pde_virt[cpu], PAGE_SIZE);
  11.199 +        if ((pde_virt[cpu] = xc_map_foreign_range(xc_handle, domid, PAGE_SIZE,
  11.200 +                                                  PROT_READ,
  11.201 +                                                  pde_phys[cpu] >> PAGE_SHIFT)) == NULL)
  11.202 +            goto error_out;
  11.203      }
  11.204      if ((page = pde_virt[cpu][vtopti(va)]) == 0) /* logical address */
  11.205 -	goto error_out;
  11.206 +        goto error_out;
  11.207      if (ctxt[cpu].flags & VGCF_VMX_GUEST && paging_enabled(&ctxt[cpu]))
  11.208          page = page_array[page >> PAGE_SHIFT] << PAGE_SHIFT;
  11.209      if (page != page_phys[cpu] || perm != prev_perm[cpu]) 
  11.210      {
  11.211 -	page_phys[cpu] = page;
  11.212 -	if (page_virt[cpu])
  11.213 -	    munmap(page_virt[cpu], PAGE_SIZE);
  11.214 -	if ((page_virt[cpu] = xc_map_foreign_range(xc_handle, domid, PAGE_SIZE,
  11.215 -					      perm,
  11.216 -					      page_phys[cpu] >> PAGE_SHIFT)) == NULL) {
  11.217 -	    printf("cr3 %lx pde %lx page %lx pti %lx\n", cr3[cpu], pde, page, vtopti(va));
  11.218 -	    page_phys[cpu] = 0;
  11.219 -	    goto error_out;
  11.220 -	}
  11.221 -	prev_perm[cpu] = perm;
  11.222 -    }	
  11.223 +        page_phys[cpu] = page;
  11.224 +        if (page_virt[cpu])
  11.225 +            munmap(page_virt[cpu], PAGE_SIZE);
  11.226 +        if ((page_virt[cpu] = xc_map_foreign_range(xc_handle, domid, PAGE_SIZE,
  11.227 +                                                   perm,
  11.228 +                                                   page_phys[cpu] >> PAGE_SHIFT)) == NULL) {
  11.229 +            printf("cr3 %lx pde %lx page %lx pti %lx\n", cr3[cpu], pde, page, vtopti(va));
  11.230 +            page_phys[cpu] = 0;
  11.231 +            goto error_out;
  11.232 +        }
  11.233 +        prev_perm[cpu] = perm;
  11.234 +    } 
  11.235      return (void *)(((unsigned long)page_virt[cpu]) | (va & BSD_PAGE_MASK));
  11.236  
  11.237   error_out:
  11.238 @@ -234,29 +230,29 @@ xc_waitdomain(int domain, int *status, i
  11.239      ts.tv_nsec = 10*1000*1000;
  11.240  
  11.241      if (!xc_handle)
  11.242 -	if ((xc_handle = xc_interface_open()) < 0) 
  11.243 -	{
  11.244 -	    printf("xc_interface_open failed\n");
  11.245 -	    return -1;
  11.246 -	}
  11.247 +        if ((xc_handle = xc_interface_open()) < 0) 
  11.248 +        {
  11.249 +            printf("xc_interface_open failed\n");
  11.250 +            return -1;
  11.251 +        }
  11.252      op.cmd = DOM0_GETDOMAININFO;
  11.253      op.u.getdomaininfo.domain = domain;
  11.254   retry:
  11.255  
  11.256      retval = do_dom0_op(xc_handle, &op);
  11.257      if (retval || op.u.getdomaininfo.domain != domain) {
  11.258 -	printf("getdomaininfo failed\n");
  11.259 -	goto done;
  11.260 +        printf("getdomaininfo failed\n");
  11.261 +        goto done;
  11.262      }
  11.263      *status = op.u.getdomaininfo.flags;
  11.264      
  11.265      if (options & WNOHANG)
  11.266 -	goto done;
  11.267 -	
  11.268 +        goto done;
  11.269 + 
  11.270  
  11.271 -    if (!(op.u.getdomaininfo.flags & DOMFLAGS_PAUSED)) {	
  11.272 -	nanosleep(&ts,NULL);
  11.273 -	goto retry;
  11.274 +    if (!(op.u.getdomaininfo.flags & DOMFLAGS_PAUSED)) { 
  11.275 +        nanosleep(&ts,NULL);
  11.276 +        goto retry;
  11.277      }
  11.278   done:
  11.279      return retval;
  11.280 @@ -278,107 +274,107 @@ xc_ptrace(enum __ptrace_request request,
  11.281      op.interface_version = DOM0_INTERFACE_VERSION;
  11.282      
  11.283      if (!xc_handle)
  11.284 -	if ((xc_handle = xc_interface_open()) < 0)
  11.285 -	    return -1;
  11.286 +        if ((xc_handle = xc_interface_open()) < 0)
  11.287 +            return -1;
  11.288  #if 0
  11.289      printf("%20s %d, %p, %p \n", ptrace_names[request], domid, addr, data);
  11.290  #endif
  11.291 -    switch (request) {	
  11.292 +    switch (request) { 
  11.293      case PTRACE_PEEKTEXT:
  11.294      case PTRACE_PEEKDATA:
  11.295 -	if ((guest_va = (unsigned long *)map_domain_va(domid, cpu, addr, PROT_READ)) == NULL) {
  11.296 -	    status = EFAULT;
  11.297 -	    goto error_out;
  11.298 -	}
  11.299 +        if ((guest_va = (unsigned long *)map_domain_va(domid, cpu, addr, PROT_READ)) == NULL) {
  11.300 +            status = EFAULT;
  11.301 +            goto error_out;
  11.302 +        }
  11.303  
  11.304 -	retval = *guest_va;
  11.305 -	break;
  11.306 +        retval = *guest_va;
  11.307 +        break;
  11.308      case PTRACE_POKETEXT:
  11.309      case PTRACE_POKEDATA:
  11.310 -	if ((guest_va = (unsigned long *)map_domain_va(domid, cpu, addr, PROT_READ|PROT_WRITE)) == NULL) {
  11.311 -	    status = EFAULT;
  11.312 -	    goto error_out;
  11.313 -	}
  11.314 +        if ((guest_va = (unsigned long *)map_domain_va(domid, cpu, addr, PROT_READ|PROT_WRITE)) == NULL) {
  11.315 +            status = EFAULT;
  11.316 +            goto error_out;
  11.317 +        }
  11.318  
  11.319 -	*guest_va = (unsigned long)data;
  11.320 -	break;
  11.321 +        *guest_va = (unsigned long)data;
  11.322 +        break;
  11.323      case PTRACE_GETREGS:
  11.324      case PTRACE_GETFPREGS:
  11.325      case PTRACE_GETFPXREGS:
  11.326 -	FETCH_REGS(cpu);
  11.327 +        FETCH_REGS(cpu);
  11.328  
  11.329 -	if (request == PTRACE_GETREGS) {
  11.330 -		SET_PT_REGS(pt, ctxt[cpu].user_regs); 
  11.331 -		memcpy(data, &pt, sizeof(struct gdb_regs));
  11.332 -	} else if (request == PTRACE_GETFPREGS)
  11.333 -	    memcpy(data, &ctxt[cpu].fpu_ctxt, sizeof(ctxt[cpu].fpu_ctxt));
  11.334 -	else /*if (request == PTRACE_GETFPXREGS)*/
  11.335 -	    memcpy(data, &ctxt[cpu].fpu_ctxt, sizeof(ctxt[cpu].fpu_ctxt));
  11.336 -	break;
  11.337 +        if (request == PTRACE_GETREGS) {
  11.338 +            SET_PT_REGS(pt, ctxt[cpu].user_regs); 
  11.339 +            memcpy(data, &pt, sizeof(struct gdb_regs));
  11.340 +        } else if (request == PTRACE_GETFPREGS)
  11.341 +            memcpy(data, &ctxt[cpu].fpu_ctxt, sizeof(ctxt[cpu].fpu_ctxt));
  11.342 +        else /*if (request == PTRACE_GETFPXREGS)*/
  11.343 +            memcpy(data, &ctxt[cpu].fpu_ctxt, sizeof(ctxt[cpu].fpu_ctxt));
  11.344 +        break;
  11.345      case PTRACE_SETREGS:
  11.346 -	op.cmd = DOM0_SETDOMAININFO;
  11.347 -	SET_XC_REGS(((struct gdb_regs *)data), ctxt[VCPU].user_regs);
  11.348 -	op.u.setdomaininfo.domain = domid;
  11.349 -	/* XXX need to understand multiple vcpus */
  11.350 -	op.u.setdomaininfo.vcpu = cpu;
  11.351 -	op.u.setdomaininfo.ctxt = &ctxt[cpu];
  11.352 -	retval = do_dom0_op(xc_handle, &op);
  11.353 -	if (retval)
  11.354 -	    goto error_out;
  11.355 +        op.cmd = DOM0_SETDOMAININFO;
  11.356 +        SET_XC_REGS(((struct gdb_regs *)data), ctxt[VCPU].user_regs);
  11.357 +        op.u.setdomaininfo.domain = domid;
  11.358 +        /* XXX need to understand multiple vcpus */
  11.359 +        op.u.setdomaininfo.vcpu = cpu;
  11.360 +        op.u.setdomaininfo.ctxt = &ctxt[cpu];
  11.361 +        retval = do_dom0_op(xc_handle, &op);
  11.362 +        if (retval)
  11.363 +            goto error_out;
  11.364  
  11.365 -	break;
  11.366 +        break;
  11.367      case PTRACE_ATTACH:
  11.368 -	op.cmd = DOM0_GETDOMAININFO;
  11.369 -	op.u.getdomaininfo.domain = domid;
  11.370 -	retval = do_dom0_op(xc_handle, &op);
  11.371 -	if (retval || op.u.getdomaininfo.domain != domid) {
  11.372 -	    perror("dom0 op failed");
  11.373 -	    goto error_out;
  11.374 -	}
  11.375 -	if (op.u.getdomaininfo.flags & DOMFLAGS_PAUSED) {
  11.376 -	    printf("domain currently paused\n");
  11.377 -	    goto error_out;
  11.378 -	}
  11.379 -	printf("domain not currently paused\n");
  11.380 -	op.cmd = DOM0_PAUSEDOMAIN;
  11.381 -	op.u.pausedomain.domain = domid;
  11.382 -	retval = do_dom0_op(xc_handle, &op);
  11.383 -	break;
  11.384 +        op.cmd = DOM0_GETDOMAININFO;
  11.385 +        op.u.getdomaininfo.domain = domid;
  11.386 +        retval = do_dom0_op(xc_handle, &op);
  11.387 +        if (retval || op.u.getdomaininfo.domain != domid) {
  11.388 +            perror("dom0 op failed");
  11.389 +            goto error_out;
  11.390 +        }
  11.391 +        if (op.u.getdomaininfo.flags & DOMFLAGS_PAUSED) {
  11.392 +            printf("domain currently paused\n");
  11.393 +            goto error_out;
  11.394 +        }
  11.395 +        printf("domain not currently paused\n");
  11.396 +        op.cmd = DOM0_PAUSEDOMAIN;
  11.397 +        op.u.pausedomain.domain = domid;
  11.398 +        retval = do_dom0_op(xc_handle, &op);
  11.399 +        break;
  11.400      case PTRACE_SINGLESTEP:
  11.401 -	ctxt[VCPU].user_regs.eflags |= PSL_T;
  11.402 -	op.cmd = DOM0_SETDOMAININFO;
  11.403 -	op.u.setdomaininfo.domain = domid;
  11.404 -	op.u.setdomaininfo.vcpu = 0;
  11.405 -	op.u.setdomaininfo.ctxt = &ctxt[cpu];
  11.406 -	retval = do_dom0_op(xc_handle, &op);	
  11.407 -	if (retval) {
  11.408 -	    perror("dom0 op failed");
  11.409 -	    goto error_out;
  11.410 -	}
  11.411 -    	/* FALLTHROUGH */
  11.412 +        ctxt[VCPU].user_regs.eflags |= PSL_T;
  11.413 +        op.cmd = DOM0_SETDOMAININFO;
  11.414 +        op.u.setdomaininfo.domain = domid;
  11.415 +        op.u.setdomaininfo.vcpu = 0;
  11.416 +        op.u.setdomaininfo.ctxt = &ctxt[cpu];
  11.417 +        retval = do_dom0_op(xc_handle, &op); 
  11.418 +        if (retval) {
  11.419 +            perror("dom0 op failed");
  11.420 +            goto error_out;
  11.421 +        }
  11.422 +        /* FALLTHROUGH */
  11.423      case PTRACE_CONT:
  11.424      case PTRACE_DETACH:
  11.425 -	if (request != PTRACE_SINGLESTEP) {
  11.426 -	    FETCH_REGS(cpu);
  11.427 -	    /* Clear trace flag */
  11.428 -	    if (ctxt[cpu].user_regs.eflags & PSL_T) {
  11.429 -		ctxt[cpu].user_regs.eflags &= ~PSL_T;
  11.430 -		op.cmd = DOM0_SETDOMAININFO;
  11.431 -		op.u.setdomaininfo.domain = domid;
  11.432 -		op.u.setdomaininfo.vcpu = cpu;
  11.433 -		op.u.setdomaininfo.ctxt = &ctxt[cpu];
  11.434 -		retval = do_dom0_op(xc_handle, &op);	
  11.435 -		if (retval) {
  11.436 -		    perror("dom0 op failed");
  11.437 -		    goto error_out;
  11.438 -		}
  11.439 -	    }
  11.440 -	}
  11.441 -	regs_valid[cpu] = 0;
  11.442 -	op.cmd = DOM0_UNPAUSEDOMAIN;
  11.443 -	op.u.unpausedomain.domain = domid > 0 ? domid : -domid;
  11.444 -	retval = do_dom0_op(xc_handle, &op);
  11.445 -	break;
  11.446 +        if (request != PTRACE_SINGLESTEP) {
  11.447 +            FETCH_REGS(cpu);
  11.448 +            /* Clear trace flag */
  11.449 +            if (ctxt[cpu].user_regs.eflags & PSL_T) {
  11.450 +                ctxt[cpu].user_regs.eflags &= ~PSL_T;
  11.451 +                op.cmd = DOM0_SETDOMAININFO;
  11.452 +                op.u.setdomaininfo.domain = domid;
  11.453 +                op.u.setdomaininfo.vcpu = cpu;
  11.454 +                op.u.setdomaininfo.ctxt = &ctxt[cpu];
  11.455 +                retval = do_dom0_op(xc_handle, &op); 
  11.456 +                if (retval) {
  11.457 +                    perror("dom0 op failed");
  11.458 +                    goto error_out;
  11.459 +                }
  11.460 +            }
  11.461 +        }
  11.462 +        regs_valid[cpu] = 0;
  11.463 +        op.cmd = DOM0_UNPAUSEDOMAIN;
  11.464 +        op.u.unpausedomain.domain = domid > 0 ? domid : -domid;
  11.465 +        retval = do_dom0_op(xc_handle, &op);
  11.466 +        break;
  11.467      case PTRACE_SETFPREGS:
  11.468      case PTRACE_SETFPXREGS:
  11.469      case PTRACE_PEEKUSER:
  11.470 @@ -386,20 +382,30 @@ xc_ptrace(enum __ptrace_request request,
  11.471      case PTRACE_SYSCALL:
  11.472      case PTRACE_KILL:
  11.473  #ifdef DEBUG
  11.474 -	printf("unsupported xc_ptrace request %s\n", ptrace_names[request]);
  11.475 +        printf("unsupported xc_ptrace request %s\n", ptrace_names[request]);
  11.476  #endif
  11.477 -	/* XXX not yet supported */
  11.478 -	status = ENOSYS;
  11.479 -	break;
  11.480 +        /* XXX not yet supported */
  11.481 +        status = ENOSYS;
  11.482 +        break;
  11.483      case PTRACE_TRACEME:
  11.484 -	printf("PTRACE_TRACEME is an invalid request under Xen\n");
  11.485 -	status = EINVAL;
  11.486 +        printf("PTRACE_TRACEME is an invalid request under Xen\n");
  11.487 +        status = EINVAL;
  11.488      }
  11.489      
  11.490      if (status) {
  11.491 -	errno = status;
  11.492 -	retval = -1;
  11.493 +        errno = status;
  11.494 +        retval = -1;
  11.495      }
  11.496   error_out:
  11.497      return retval;
  11.498  }
  11.499 +
  11.500 +/*
  11.501 + * Local variables:
  11.502 + * mode: C
  11.503 + * c-set-style: "BSD"
  11.504 + * c-basic-offset: 4
  11.505 + * tab-width: 4
  11.506 + * indent-tabs-mode: nil
  11.507 + * End:
  11.508 + */
    12.1 --- a/tools/libxc/xc_ptrace_core.c	Mon Sep 19 09:14:41 2005 +0000
    12.2 +++ b/tools/libxc/xc_ptrace_core.c	Mon Sep 19 11:06:05 2005 +0000
    12.3 @@ -3,12 +3,8 @@
    12.4  #include "xc_private.h"
    12.5  #include <time.h>
    12.6  
    12.7 -
    12.8 -#define BSD_PAGE_MASK	(PAGE_SIZE-1)
    12.9 -#define	PG_FRAME	(~((unsigned long)BSD_PAGE_MASK)
   12.10 +#define BSD_PAGE_MASK (PAGE_SIZE-1)
   12.11  #define PDRSHIFT        22
   12.12 -#define	PSL_T		0x00000100	/* trace enable bit */
   12.13 -
   12.14  #define VCPU            0               /* XXX */
   12.15  
   12.16  /*
   12.17 @@ -16,7 +12,6 @@
   12.18   * ptrace(enum __ptrace_request request, pid_t pid, void *addr, void *data);
   12.19   */
   12.20  
   12.21 -
   12.22  struct gdb_regs {
   12.23      long ebx; /* 0 */
   12.24      long ecx; /* 4 */
   12.25 @@ -38,44 +33,44 @@ struct gdb_regs {
   12.26  };
   12.27  
   12.28  #define printval(x) printf("%s = %lx\n", #x, (long)x);
   12.29 -#define SET_PT_REGS(pt, xc) \
   12.30 -{ \
   12.31 -    pt.ebx = xc.ebx; \
   12.32 -    pt.ecx = xc.ecx; \
   12.33 -    pt.edx = xc.edx; \
   12.34 -    pt.esi = xc.esi; \
   12.35 -    pt.edi = xc.edi; \
   12.36 -    pt.ebp = xc.ebp; \
   12.37 -    pt.eax = xc.eax; \
   12.38 -    pt.eip = xc.eip; \
   12.39 -    pt.xcs = xc.cs; \
   12.40 -    pt.eflags = xc.eflags; \
   12.41 -    pt.esp = xc.esp; \
   12.42 -    pt.xss = xc.ss; \
   12.43 -    pt.xes = xc.es; \
   12.44 -    pt.xds = xc.ds; \
   12.45 -    pt.xfs = xc.fs; \
   12.46 -    pt.xgs = xc.gs; \
   12.47 +#define SET_PT_REGS(pt, xc)                     \
   12.48 +{                                               \
   12.49 +    pt.ebx = xc.ebx;                            \
   12.50 +    pt.ecx = xc.ecx;                            \
   12.51 +    pt.edx = xc.edx;                            \
   12.52 +    pt.esi = xc.esi;                            \
   12.53 +    pt.edi = xc.edi;                            \
   12.54 +    pt.ebp = xc.ebp;                            \
   12.55 +    pt.eax = xc.eax;                            \
   12.56 +    pt.eip = xc.eip;                            \
   12.57 +    pt.xcs = xc.cs;                             \
   12.58 +    pt.eflags = xc.eflags;                      \
   12.59 +    pt.esp = xc.esp;                            \
   12.60 +    pt.xss = xc.ss;                             \
   12.61 +    pt.xes = xc.es;                             \
   12.62 +    pt.xds = xc.ds;                             \
   12.63 +    pt.xfs = xc.fs;                             \
   12.64 +    pt.xgs = xc.gs;                             \
   12.65  }
   12.66  
   12.67 -#define SET_XC_REGS(pt, xc) \
   12.68 -{ \
   12.69 -    xc.ebx = pt->ebx; \
   12.70 -    xc.ecx = pt->ecx; \
   12.71 -    xc.edx = pt->edx; \
   12.72 -    xc.esi = pt->esi; \
   12.73 -    xc.edi = pt->edi; \
   12.74 -    xc.ebp = pt->ebp; \
   12.75 -    xc.eax = pt->eax; \
   12.76 -    xc.eip = pt->eip; \
   12.77 -    xc.cs = pt->xcs; \
   12.78 -    xc.eflags = pt->eflags; \
   12.79 -    xc.esp = pt->esp; \
   12.80 -    xc.ss = pt->xss; \
   12.81 -    xc.es = pt->xes; \
   12.82 -    xc.ds = pt->xds; \
   12.83 -    xc.fs = pt->xfs; \
   12.84 -    xc.gs = pt->xgs; \
   12.85 +#define SET_XC_REGS(pt, xc)                     \
   12.86 +{                                               \
   12.87 +    xc.ebx = pt->ebx;                           \
   12.88 +    xc.ecx = pt->ecx;                           \
   12.89 +    xc.edx = pt->edx;                           \
   12.90 +    xc.esi = pt->esi;                           \
   12.91 +    xc.edi = pt->edi;                           \
   12.92 +    xc.ebp = pt->ebp;                           \
   12.93 +    xc.eax = pt->eax;                           \
   12.94 +    xc.eip = pt->eip;                           \
   12.95 +    xc.cs = pt->xcs;                            \
   12.96 +    xc.eflags = pt->eflags;                     \
   12.97 +    xc.esp = pt->esp;                           \
   12.98 +    xc.ss = pt->xss;                            \
   12.99 +    xc.es = pt->xes;                            \
  12.100 +    xc.ds = pt->xds;                            \
  12.101 +    xc.fs = pt->xfs;                            \
  12.102 +    xc.gs = pt->xgs;                            \
  12.103  }
  12.104  
  12.105  
  12.106 @@ -84,10 +79,9 @@ struct gdb_regs {
  12.107  
  12.108  /* XXX application state */
  12.109  
  12.110 -
  12.111 -static long			nr_pages = 0;
  12.112 -static unsigned long		*p2m_array = NULL;
  12.113 -static unsigned long		*m2p_array = NULL;
  12.114 +static long   nr_pages = 0;
  12.115 +static unsigned long  *p2m_array = NULL;
  12.116 +static unsigned long  *m2p_array = NULL;
  12.117  static unsigned long            pages_offset;
  12.118  static unsigned long            cr3[MAX_VIRT_CPUS];
  12.119  static vcpu_guest_context_t     ctxt[MAX_VIRT_CPUS];
  12.120 @@ -117,54 +111,54 @@ map_domain_va(unsigned long domfd, int c
  12.121  
  12.122      if (cr3[cpu] != cr3_phys[cpu]) 
  12.123      {
  12.124 -	cr3_phys[cpu] = cr3[cpu];
  12.125 -	if (cr3_virt[cpu])
  12.126 -	    munmap(cr3_virt[cpu], PAGE_SIZE);
  12.127 -	v = mmap(
  12.128 +        cr3_phys[cpu] = cr3[cpu];
  12.129 +        if (cr3_virt[cpu])
  12.130 +            munmap(cr3_virt[cpu], PAGE_SIZE);
  12.131 +        v = mmap(
  12.132              NULL, PAGE_SIZE, PROT_READ, MAP_PRIVATE, domfd,
  12.133              map_mtop_offset(cr3_phys[cpu]));
  12.134          if (v == MAP_FAILED)
  12.135 -	{
  12.136 -	    perror("mmap failed");
  12.137 -	    goto error_out;
  12.138 -	}
  12.139 +        {
  12.140 +            perror("mmap failed");
  12.141 +            goto error_out;
  12.142 +        }
  12.143          cr3_virt[cpu] = v;
  12.144      } 
  12.145      if ((pde = cr3_virt[cpu][vtopdi(va)]) == 0) /* logical address */
  12.146 -	goto error_out;
  12.147 +        goto error_out;
  12.148      if (ctxt[cpu].flags & VGCF_VMX_GUEST)
  12.149 -	pde = p2m_array[pde >> PAGE_SHIFT] << PAGE_SHIFT;
  12.150 +        pde = p2m_array[pde >> PAGE_SHIFT] << PAGE_SHIFT;
  12.151      if (pde != pde_phys[cpu]) 
  12.152      {
  12.153 -	pde_phys[cpu] = pde;
  12.154 -	if (pde_virt[cpu])
  12.155 -	    munmap(pde_virt[cpu], PAGE_SIZE);
  12.156 -	v = mmap(
  12.157 +        pde_phys[cpu] = pde;
  12.158 +        if (pde_virt[cpu])
  12.159 +            munmap(pde_virt[cpu], PAGE_SIZE);
  12.160 +        v = mmap(
  12.161              NULL, PAGE_SIZE, PROT_READ, MAP_PRIVATE, domfd,
  12.162              map_mtop_offset(pde_phys[cpu]));
  12.163          if (v == MAP_FAILED)
  12.164 -	    goto error_out;
  12.165 +            goto error_out;
  12.166          pde_virt[cpu] = v;
  12.167      }
  12.168      if ((page = pde_virt[cpu][vtopti(va)]) == 0) /* logical address */
  12.169 -	goto error_out;
  12.170 +        goto error_out;
  12.171      if (ctxt[cpu].flags & VGCF_VMX_GUEST)
  12.172 -	page = p2m_array[page >> PAGE_SHIFT] << PAGE_SHIFT;
  12.173 +        page = p2m_array[page >> PAGE_SHIFT] << PAGE_SHIFT;
  12.174      if (page != page_phys[cpu]) 
  12.175      {
  12.176 -	page_phys[cpu] = page;
  12.177 -	if (page_virt[cpu])
  12.178 -	    munmap(page_virt[cpu], PAGE_SIZE);
  12.179 -	v = mmap(
  12.180 +        page_phys[cpu] = page;
  12.181 +        if (page_virt[cpu])
  12.182 +            munmap(page_virt[cpu], PAGE_SIZE);
  12.183 +        v = mmap(
  12.184              NULL, PAGE_SIZE, PROT_READ, MAP_PRIVATE, domfd,
  12.185              map_mtop_offset(page_phys[cpu]));
  12.186          if (v == MAP_FAILED) {
  12.187 -	    printf("cr3 %lx pde %lx page %lx pti %lx\n", cr3[cpu], pde, page, vtopti(va));
  12.188 -	    page_phys[cpu] = 0;
  12.189 -	    goto error_out;
  12.190 -	}
  12.191 +            printf("cr3 %lx pde %lx page %lx pti %lx\n", cr3[cpu], pde, page, vtopti(va));
  12.192 +            page_phys[cpu] = 0;
  12.193 +            goto error_out;
  12.194 +        }
  12.195          page_virt[cpu] = v;
  12.196 -    }	
  12.197 +    } 
  12.198      return (void *)(((unsigned long)page_virt[cpu]) | (va & BSD_PAGE_MASK));
  12.199  
  12.200   error_out:
  12.201 @@ -181,37 +175,37 @@ xc_waitdomain_core(int domfd, int *statu
  12.202  
  12.203      if (nr_pages == 0) {
  12.204  
  12.205 -	if (read(domfd, &header, sizeof(header)) != sizeof(header))
  12.206 -	    return -1;
  12.207 +        if (read(domfd, &header, sizeof(header)) != sizeof(header))
  12.208 +            return -1;
  12.209  
  12.210 -	nr_pages = header.xch_nr_pages;
  12.211 -	nr_vcpus = header.xch_nr_vcpus;
  12.212 -	pages_offset = header.xch_pages_offset;
  12.213 +        nr_pages = header.xch_nr_pages;
  12.214 +        nr_vcpus = header.xch_nr_vcpus;
  12.215 +        pages_offset = header.xch_pages_offset;
  12.216  
  12.217 -	if (read(domfd, ctxt, sizeof(vcpu_guest_context_t)*nr_vcpus) != 
  12.218 -	    sizeof(vcpu_guest_context_t)*nr_vcpus)
  12.219 -	    return -1;
  12.220 +        if (read(domfd, ctxt, sizeof(vcpu_guest_context_t)*nr_vcpus) != 
  12.221 +            sizeof(vcpu_guest_context_t)*nr_vcpus)
  12.222 +            return -1;
  12.223  
  12.224 -	for (i = 0; i < nr_vcpus; i++) {
  12.225 -	    cr3[i] = ctxt[i].ctrlreg[3];
  12.226 -	}
  12.227 -	if ((p2m_array = malloc(nr_pages * sizeof(unsigned long))) == NULL) {
  12.228 -	    printf("Could not allocate p2m_array\n");
  12.229 -	    goto error_out;
  12.230 -	}
  12.231 -	if (read(domfd, p2m_array, sizeof(unsigned long)*nr_pages) != 
  12.232 -	    sizeof(unsigned long)*nr_pages)
  12.233 -	    return -1;
  12.234 +        for (i = 0; i < nr_vcpus; i++) {
  12.235 +            cr3[i] = ctxt[i].ctrlreg[3];
  12.236 +        }
  12.237 +        if ((p2m_array = malloc(nr_pages * sizeof(unsigned long))) == NULL) {
  12.238 +            printf("Could not allocate p2m_array\n");
  12.239 +            goto error_out;
  12.240 +        }
  12.241 +        if (read(domfd, p2m_array, sizeof(unsigned long)*nr_pages) != 
  12.242 +            sizeof(unsigned long)*nr_pages)
  12.243 +            return -1;
  12.244  
  12.245 -	if ((m2p_array = malloc((1<<20) * sizeof(unsigned long))) == NULL) {
  12.246 -	    printf("Could not allocate m2p array\n");
  12.247 -	    goto error_out;
  12.248 -	}
  12.249 -	bzero(m2p_array, sizeof(unsigned long)* 1 << 20);
  12.250 +        if ((m2p_array = malloc((1<<20) * sizeof(unsigned long))) == NULL) {
  12.251 +            printf("Could not allocate m2p array\n");
  12.252 +            goto error_out;
  12.253 +        }
  12.254 +        bzero(m2p_array, sizeof(unsigned long)* 1 << 20);
  12.255  
  12.256 -	for (i = 0; i < nr_pages; i++) {
  12.257 -	    m2p_array[p2m_array[i]] = i;
  12.258 -	}
  12.259 +        for (i = 0; i < nr_pages; i++) {
  12.260 +            m2p_array[p2m_array[i]] = i;
  12.261 +        }
  12.262  
  12.263      }
  12.264      retval = 0;
  12.265 @@ -234,38 +228,38 @@ xc_ptrace_core(enum __ptrace_request req
  12.266  #if 0
  12.267      printf("%20s %d, %p, %p \n", ptrace_names[request], domid, addr, data);
  12.268  #endif
  12.269 -    switch (request) {	
  12.270 +    switch (request) { 
  12.271      case PTRACE_PEEKTEXT:
  12.272      case PTRACE_PEEKDATA:
  12.273 -	if ((guest_va = (unsigned long *)map_domain_va(domfd, cpu, addr)) == NULL) {
  12.274 -	    status = EFAULT;
  12.275 -	    goto error_out;
  12.276 -	}
  12.277 +        if ((guest_va = (unsigned long *)map_domain_va(domfd, cpu, addr)) == NULL) {
  12.278 +            status = EFAULT;
  12.279 +            goto error_out;
  12.280 +        }
  12.281  
  12.282 -	retval = *guest_va;
  12.283 -	break;
  12.284 +        retval = *guest_va;
  12.285 +        break;
  12.286      case PTRACE_POKETEXT:
  12.287      case PTRACE_POKEDATA:
  12.288 -	if ((guest_va = (unsigned long *)map_domain_va(domfd, cpu, addr)) == NULL) {
  12.289 -	    status = EFAULT;
  12.290 -	    goto error_out;
  12.291 -	}
  12.292 -	*guest_va = (unsigned long)data;
  12.293 -	break;
  12.294 +        if ((guest_va = (unsigned long *)map_domain_va(domfd, cpu, addr)) == NULL) {
  12.295 +            status = EFAULT;
  12.296 +            goto error_out;
  12.297 +        }
  12.298 +        *guest_va = (unsigned long)data;
  12.299 +        break;
  12.300      case PTRACE_GETREGS:
  12.301      case PTRACE_GETFPREGS:
  12.302      case PTRACE_GETFPXREGS:
  12.303 -	if (request == PTRACE_GETREGS) {
  12.304 -		SET_PT_REGS(pt, ctxt[cpu].user_regs); 
  12.305 -		memcpy(data, &pt, sizeof(struct gdb_regs));
  12.306 -	} else if (request == PTRACE_GETFPREGS)
  12.307 -	    memcpy(data, &ctxt[cpu].fpu_ctxt, sizeof(ctxt[cpu].fpu_ctxt));
  12.308 -	else /*if (request == PTRACE_GETFPXREGS)*/
  12.309 -	    memcpy(data, &ctxt[cpu].fpu_ctxt, sizeof(ctxt[cpu].fpu_ctxt));
  12.310 -	break;
  12.311 +        if (request == PTRACE_GETREGS) {
  12.312 +            SET_PT_REGS(pt, ctxt[cpu].user_regs); 
  12.313 +            memcpy(data, &pt, sizeof(struct gdb_regs));
  12.314 +        } else if (request == PTRACE_GETFPREGS)
  12.315 +            memcpy(data, &ctxt[cpu].fpu_ctxt, sizeof(ctxt[cpu].fpu_ctxt));
  12.316 +        else /*if (request == PTRACE_GETFPXREGS)*/
  12.317 +            memcpy(data, &ctxt[cpu].fpu_ctxt, sizeof(ctxt[cpu].fpu_ctxt));
  12.318 +        break;
  12.319      case PTRACE_ATTACH:
  12.320 -	retval = 0;
  12.321 -	break;
  12.322 +        retval = 0;
  12.323 +        break;
  12.324      case PTRACE_SETREGS:
  12.325      case PTRACE_SINGLESTEP:
  12.326      case PTRACE_CONT:
  12.327 @@ -277,19 +271,29 @@ xc_ptrace_core(enum __ptrace_request req
  12.328      case PTRACE_SYSCALL:
  12.329      case PTRACE_KILL:
  12.330  #ifdef DEBUG
  12.331 -	printf("unsupported xc_ptrace request %s\n", ptrace_names[request]);
  12.332 +        printf("unsupported xc_ptrace request %s\n", ptrace_names[request]);
  12.333  #endif
  12.334 -	status = ENOSYS;
  12.335 -	break;
  12.336 +        status = ENOSYS;
  12.337 +        break;
  12.338      case PTRACE_TRACEME:
  12.339 -	printf("PTRACE_TRACEME is an invalid request under Xen\n");
  12.340 -	status = EINVAL;
  12.341 +        printf("PTRACE_TRACEME is an invalid request under Xen\n");
  12.342 +        status = EINVAL;
  12.343      }
  12.344      
  12.345      if (status) {
  12.346 -	errno = status;
  12.347 -	retval = -1;
  12.348 +        errno = status;
  12.349 +        retval = -1;
  12.350      }
  12.351   error_out:
  12.352      return retval;
  12.353  }
  12.354 +
  12.355 +/*
  12.356 + * Local variables:
  12.357 + * mode: C
  12.358 + * c-set-style: "BSD"
  12.359 + * c-basic-offset: 4
  12.360 + * tab-width: 4
  12.361 + * indent-tabs-mode: nil
  12.362 + * End:
  12.363 + */
    13.1 --- a/tools/libxc/xc_vmx_build.c	Mon Sep 19 09:14:41 2005 +0000
    13.2 +++ b/tools/libxc/xc_vmx_build.c	Mon Sep 19 11:06:05 2005 +0000
    13.3 @@ -109,9 +109,9 @@ static void build_e820map(struct mem_map
    13.4  
    13.5  #ifdef __i386__
    13.6  static int zap_mmio_range(int xc_handle, u32 dom,
    13.7 -                            l2_pgentry_32_t *vl2tab,
    13.8 -                            unsigned long mmio_range_start,
    13.9 -                            unsigned long mmio_range_size)
   13.10 +                          l2_pgentry_32_t *vl2tab,
   13.11 +                          unsigned long mmio_range_start,
   13.12 +                          unsigned long mmio_range_size)
   13.13  {
   13.14      unsigned long mmio_addr;
   13.15      unsigned long mmio_range_end = mmio_range_start + mmio_range_size;
   13.16 @@ -123,12 +123,14 @@ static int zap_mmio_range(int xc_handle,
   13.17          vl2e = vl2tab[l2_table_offset(mmio_addr)];
   13.18          if (vl2e == 0)
   13.19              continue;
   13.20 -        vl1tab = xc_map_foreign_range(xc_handle, dom, PAGE_SIZE,
   13.21 -                                PROT_READ|PROT_WRITE, vl2e >> PAGE_SHIFT);
   13.22 -	if (vl1tab == 0) {
   13.23 -	    PERROR("Failed zap MMIO range");
   13.24 -	    return -1;
   13.25 -	}
   13.26 +        vl1tab = xc_map_foreign_range(
   13.27 +            xc_handle, dom, PAGE_SIZE,
   13.28 +            PROT_READ|PROT_WRITE, vl2e >> PAGE_SHIFT);
   13.29 +        if ( vl1tab == 0 )
   13.30 +        {
   13.31 +            PERROR("Failed zap MMIO range");
   13.32 +            return -1;
   13.33 +        }
   13.34          vl1tab[l1_table_offset(mmio_addr)] = 0;
   13.35          munmap(vl1tab, PAGE_SIZE);
   13.36      }
   13.37 @@ -136,114 +138,118 @@ static int zap_mmio_range(int xc_handle,
   13.38  }
   13.39  
   13.40  static int zap_mmio_ranges(int xc_handle, u32 dom,
   13.41 -                            unsigned long l2tab,
   13.42 -                            struct mem_map *mem_mapp)
   13.43 +                           unsigned long l2tab,
   13.44 +                           struct mem_map *mem_mapp)
   13.45  {
   13.46      int i;
   13.47      l2_pgentry_32_t *vl2tab = xc_map_foreign_range(xc_handle, dom, PAGE_SIZE,
   13.48 -                                                PROT_READ|PROT_WRITE,
   13.49 -                                                l2tab >> PAGE_SHIFT);
   13.50 -    if (vl2tab == 0)
   13.51 -    	return -1;
   13.52 -    for (i = 0; i < mem_mapp->nr_map; i++) {
   13.53 -        if ((mem_mapp->map[i].type == E820_IO)
   13.54 -          && (mem_mapp->map[i].caching_attr == MEMMAP_UC))
   13.55 -            if (zap_mmio_range(xc_handle, dom, vl2tab,
   13.56 -	    		mem_mapp->map[i].addr, mem_mapp->map[i].size) == -1)
   13.57 -		return -1;
   13.58 +                                                   PROT_READ|PROT_WRITE,
   13.59 +                                                   l2tab >> PAGE_SHIFT);
   13.60 +    if ( vl2tab == 0 )
   13.61 +        return -1;
   13.62 +
   13.63 +    for ( i = 0; i < mem_mapp->nr_map; i++ )
   13.64 +    {
   13.65 +        if ( (mem_mapp->map[i].type == E820_IO) &&
   13.66 +             (mem_mapp->map[i].caching_attr == MEMMAP_UC) &&
   13.67 +             (zap_mmio_range(xc_handle, dom, vl2tab,
   13.68 +                             mem_mapp->map[i].addr,
   13.69 +                             mem_mapp->map[i].size) == -1) )
   13.70 +            return -1;
   13.71      }
   13.72 +
   13.73      munmap(vl2tab, PAGE_SIZE);
   13.74      return 0;
   13.75  }
   13.76  #else
   13.77  static int zap_mmio_range(int xc_handle, u32 dom,
   13.78 -                           l3_pgentry_t *vl3tab,
   13.79 -                           unsigned long mmio_range_start,
   13.80 -                           unsigned long mmio_range_size)
   13.81 +                          l3_pgentry_t *vl3tab,
   13.82 +                          unsigned long mmio_range_start,
   13.83 +                          unsigned long mmio_range_size)
   13.84  {
   13.85 -   unsigned long mmio_addr;
   13.86 -   unsigned long mmio_range_end = mmio_range_start + mmio_range_size;
   13.87 -   unsigned long vl2e = 0;
   13.88 -   unsigned long vl3e;
   13.89 -   l1_pgentry_t *vl1tab;
   13.90 -   l2_pgentry_t *vl2tab;
   13.91 +    unsigned long mmio_addr;
   13.92 +    unsigned long mmio_range_end = mmio_range_start + mmio_range_size;
   13.93 +    unsigned long vl2e = 0;
   13.94 +    unsigned long vl3e;
   13.95 +    l1_pgentry_t *vl1tab;
   13.96 +    l2_pgentry_t *vl2tab;
   13.97   
   13.98 -   mmio_addr = mmio_range_start & PAGE_MASK;
   13.99 -   for ( ; mmio_addr < mmio_range_end; mmio_addr += PAGE_SIZE )
  13.100 -   {
  13.101 -       vl3e = vl3tab[l3_table_offset(mmio_addr)];
  13.102 -       if ( vl3e == 0 )
  13.103 -           continue;
  13.104 +    mmio_addr = mmio_range_start & PAGE_MASK;
  13.105 +    for ( ; mmio_addr < mmio_range_end; mmio_addr += PAGE_SIZE )
  13.106 +    {
  13.107 +        vl3e = vl3tab[l3_table_offset(mmio_addr)];
  13.108 +        if ( vl3e == 0 )
  13.109 +            continue;
  13.110  
  13.111 -       vl2tab = xc_map_foreign_range(
  13.112 -           xc_handle, dom, PAGE_SIZE, PROT_READ|PROT_WRITE, vl3e>>PAGE_SHIFT);
  13.113 -       if ( vl2tab == NULL )
  13.114 -       {
  13.115 -           PERROR("Failed zap MMIO range");
  13.116 -           return -1;
  13.117 -       }
  13.118 +        vl2tab = xc_map_foreign_range(
  13.119 +            xc_handle, dom, PAGE_SIZE, PROT_READ|PROT_WRITE, vl3e>>PAGE_SHIFT);
  13.120 +        if ( vl2tab == NULL )
  13.121 +        {
  13.122 +            PERROR("Failed zap MMIO range");
  13.123 +            return -1;
  13.124 +        }
  13.125  
  13.126 -       vl2e = vl2tab[l2_table_offset(mmio_addr)];
  13.127 -       if ( vl2e == 0 )
  13.128 -       {
  13.129 -           munmap(vl2tab, PAGE_SIZE);
  13.130 -           continue;
  13.131 -       }
  13.132 +        vl2e = vl2tab[l2_table_offset(mmio_addr)];
  13.133 +        if ( vl2e == 0 )
  13.134 +        {
  13.135 +            munmap(vl2tab, PAGE_SIZE);
  13.136 +            continue;
  13.137 +        }
  13.138  
  13.139 -       vl1tab = xc_map_foreign_range(
  13.140 -           xc_handle, dom, PAGE_SIZE, PROT_READ|PROT_WRITE, vl2e>>PAGE_SHIFT);
  13.141 -       if ( vl1tab == NULL )
  13.142 -       {
  13.143 -           PERROR("Failed zap MMIO range");
  13.144 -           munmap(vl2tab, PAGE_SIZE);
  13.145 -           return -1;
  13.146 -       }
  13.147 +        vl1tab = xc_map_foreign_range(
  13.148 +            xc_handle, dom, PAGE_SIZE, PROT_READ|PROT_WRITE, vl2e>>PAGE_SHIFT);
  13.149 +        if ( vl1tab == NULL )
  13.150 +        {
  13.151 +            PERROR("Failed zap MMIO range");
  13.152 +            munmap(vl2tab, PAGE_SIZE);
  13.153 +            return -1;
  13.154 +        }
  13.155  
  13.156 -       vl1tab[l1_table_offset(mmio_addr)] = 0;
  13.157 -       munmap(vl2tab, PAGE_SIZE);
  13.158 -       munmap(vl1tab, PAGE_SIZE);
  13.159 -   }
  13.160 -   return 0;
  13.161 +        vl1tab[l1_table_offset(mmio_addr)] = 0;
  13.162 +        munmap(vl2tab, PAGE_SIZE);
  13.163 +        munmap(vl1tab, PAGE_SIZE);
  13.164 +    }
  13.165 +    return 0;
  13.166  }
  13.167  
  13.168  static int zap_mmio_ranges(int xc_handle, u32 dom,
  13.169                             unsigned long l3tab,
  13.170                             struct mem_map *mem_mapp)
  13.171  {
  13.172 -   int i;
  13.173 -   l3_pgentry_t *vl3tab = xc_map_foreign_range(xc_handle, dom, PAGE_SIZE,
  13.174 -                                               PROT_READ|PROT_WRITE,
  13.175 -                                               l3tab >> PAGE_SHIFT);
  13.176 -   if (vl3tab == 0)
  13.177 -   	return -1;
  13.178 -   for (i = 0; i < mem_mapp->nr_map; i++) {
  13.179 -       if ((mem_mapp->map[i].type == E820_IO)
  13.180 -         && (mem_mapp->map[i].caching_attr == MEMMAP_UC))
  13.181 -           if (zap_mmio_range(xc_handle, dom, vl3tab,
  13.182 -	    		mem_mapp->map[i].addr, mem_mapp->map[i].size) == -1)
  13.183 -		return -1;
  13.184 -   }
  13.185 -   munmap(vl3tab, PAGE_SIZE);
  13.186 -   return 0;
  13.187 +    int i;
  13.188 +    l3_pgentry_t *vl3tab = xc_map_foreign_range(xc_handle, dom, PAGE_SIZE,
  13.189 +                                                PROT_READ|PROT_WRITE,
  13.190 +                                                l3tab >> PAGE_SHIFT);
  13.191 +    if (vl3tab == 0)
  13.192 +        return -1;
  13.193 +    for (i = 0; i < mem_mapp->nr_map; i++) {
  13.194 +        if ((mem_mapp->map[i].type == E820_IO)
  13.195 +            && (mem_mapp->map[i].caching_attr == MEMMAP_UC))
  13.196 +            if (zap_mmio_range(xc_handle, dom, vl3tab,
  13.197 +                               mem_mapp->map[i].addr, mem_mapp->map[i].size) == -1)
  13.198 +                return -1;
  13.199 +    }
  13.200 +    munmap(vl3tab, PAGE_SIZE);
  13.201 +    return 0;
  13.202  }
  13.203  
  13.204  #endif
  13.205  
  13.206  static int setup_guest(int xc_handle,
  13.207 -                         u32 dom, int memsize,
  13.208 -                         char *image, unsigned long image_size,
  13.209 -                         gzFile initrd_gfd, unsigned long initrd_len,
  13.210 -                         unsigned long nr_pages,
  13.211 -                         vcpu_guest_context_t *ctxt,
  13.212 -                         const char *cmdline,
  13.213 -                         unsigned long shared_info_frame,
  13.214 -                         unsigned int control_evtchn,
  13.215 -                         unsigned long flags,
  13.216 -                         unsigned int vcpus,
  13.217 -                         unsigned int store_evtchn,
  13.218 -                         unsigned long *store_mfn,
  13.219 -                         struct mem_map *mem_mapp
  13.220 -                         )
  13.221 +                       u32 dom, int memsize,
  13.222 +                       char *image, unsigned long image_size,
  13.223 +                       gzFile initrd_gfd, unsigned long initrd_len,
  13.224 +                       unsigned long nr_pages,
  13.225 +                       vcpu_guest_context_t *ctxt,
  13.226 +                       const char *cmdline,
  13.227 +                       unsigned long shared_info_frame,
  13.228 +                       unsigned int control_evtchn,
  13.229 +                       unsigned long flags,
  13.230 +                       unsigned int vcpus,
  13.231 +                       unsigned int store_evtchn,
  13.232 +                       unsigned long *store_mfn,
  13.233 +                       struct mem_map *mem_mapp
  13.234 +    )
  13.235  {
  13.236      l1_pgentry_t *vl1tab=NULL, *vl1e=NULL;
  13.237      l2_pgentry_t *vl2tab=NULL, *vl2e=NULL;
  13.238 @@ -303,7 +309,8 @@ static int setup_guest(int xc_handle,
  13.239  
  13.240      /* memsize is in megabytes */
  13.241      v_end              = memsize << 20;
  13.242 -    vinitrd_end        = v_end - PAGE_SIZE; /* leaving the top 4k untouched for IO requests page use */
  13.243 +    /* leaving the top 4k untouched for IO requests page use */
  13.244 +    vinitrd_end        = v_end - PAGE_SIZE;
  13.245      vinitrd_start      = vinitrd_end - initrd_len;
  13.246      vinitrd_start      = vinitrd_start & (~(PAGE_SIZE - 1));
  13.247  
  13.248 @@ -369,7 +376,7 @@ static int setup_guest(int xc_handle,
  13.249                  goto error_out;
  13.250              }
  13.251              xc_copy_to_domain_page(xc_handle, dom,
  13.252 -                                page_array[i>>PAGE_SHIFT], page);
  13.253 +                                   page_array[i>>PAGE_SHIFT], page);
  13.254          }
  13.255      }
  13.256  
  13.257 @@ -380,14 +387,14 @@ static int setup_guest(int xc_handle,
  13.258      ppt_alloc = (vpt_start - dsi.v_start) >> PAGE_SHIFT;
  13.259      if ( page_array[ppt_alloc] > 0xfffff )
  13.260      {
  13.261 -	unsigned long nmfn;
  13.262 -	nmfn = xc_make_page_below_4G( xc_handle, dom, page_array[ppt_alloc] );
  13.263 -	if ( nmfn == 0 )
  13.264 -	{
  13.265 -	    fprintf(stderr, "Couldn't get a page below 4GB :-(\n");
  13.266 -	    goto error_out;
  13.267 -	}
  13.268 -	page_array[ppt_alloc] = nmfn;
  13.269 +        unsigned long nmfn;
  13.270 +        nmfn = xc_make_page_below_4G( xc_handle, dom, page_array[ppt_alloc] );
  13.271 +        if ( nmfn == 0 )
  13.272 +        {
  13.273 +            fprintf(stderr, "Couldn't get a page below 4GB :-(\n");
  13.274 +            goto error_out;
  13.275 +        }
  13.276 +        page_array[ppt_alloc] = nmfn;
  13.277      }
  13.278  
  13.279  #ifdef __i386__
  13.280 @@ -448,8 +455,8 @@ static int setup_guest(int xc_handle,
  13.281                  munmap(vl2tab, PAGE_SIZE);
  13.282  
  13.283              if ( (vl2tab = xc_map_foreign_range(xc_handle, dom, PAGE_SIZE,
  13.284 -                      PROT_READ|PROT_WRITE,
  13.285 -                      l2tab >> PAGE_SHIFT)) == NULL )
  13.286 +                                                PROT_READ|PROT_WRITE,
  13.287 +                                                l2tab >> PAGE_SHIFT)) == NULL )
  13.288                  goto error_out;
  13.289  
  13.290              memset(vl2tab, 0, PAGE_SIZE);
  13.291 @@ -462,8 +469,8 @@ static int setup_guest(int xc_handle,
  13.292              if ( vl1tab != NULL )
  13.293                  munmap(vl1tab, PAGE_SIZE);
  13.294              if ( (vl1tab = xc_map_foreign_range(xc_handle, dom, PAGE_SIZE,
  13.295 -                      PROT_READ|PROT_WRITE,
  13.296 -                      l1tab >> PAGE_SHIFT)) == NULL )
  13.297 +                                                PROT_READ|PROT_WRITE,
  13.298 +                                                l1tab >> PAGE_SHIFT)) == NULL )
  13.299              {
  13.300                  munmap(vl2tab, PAGE_SIZE);
  13.301                  goto error_out;
  13.302 @@ -485,15 +492,15 @@ static int setup_guest(int xc_handle,
  13.303      for ( count = 0; count < nr_pages; count++ )
  13.304      {
  13.305          if ( xc_add_mmu_update(xc_handle, mmu,
  13.306 -			       (page_array[count] << PAGE_SHIFT) | 
  13.307 -			       MMU_MACHPHYS_UPDATE, count) )
  13.308 -	    goto error_out;
  13.309 +                               (page_array[count] << PAGE_SHIFT) | 
  13.310 +                               MMU_MACHPHYS_UPDATE, count) )
  13.311 +            goto error_out;
  13.312      }
  13.313      
  13.314  
  13.315      if ((boot_paramsp = xc_map_foreign_range(
  13.316 -		xc_handle, dom, PAGE_SIZE, PROT_READ|PROT_WRITE,
  13.317 -		page_array[(vboot_params_start-dsi.v_start)>>PAGE_SHIFT])) == 0)
  13.318 +        xc_handle, dom, PAGE_SIZE, PROT_READ|PROT_WRITE,
  13.319 +        page_array[(vboot_params_start-dsi.v_start)>>PAGE_SHIFT])) == 0)
  13.320          goto error_out;
  13.321  
  13.322      memset(boot_paramsp, 0, sizeof(*boot_paramsp));
  13.323 @@ -558,9 +565,9 @@ static int setup_guest(int xc_handle,
  13.324  #if defined (__i386__)
  13.325      if (zap_mmio_ranges(xc_handle, dom, l2tab, mem_mapp) == -1)
  13.326  #else
  13.327 -    if (zap_mmio_ranges(xc_handle, dom, l3tab, mem_mapp) == -1)
  13.328 +        if (zap_mmio_ranges(xc_handle, dom, l3tab, mem_mapp) == -1)
  13.329  #endif
  13.330 -    	goto error_out;
  13.331 +            goto error_out;
  13.332      boot_paramsp->e820_map_nr = mem_mapp->nr_map;
  13.333      for (i=0; i<mem_mapp->nr_map; i++) {
  13.334          boot_paramsp->e820_map[i].addr = mem_mapp->map[i].addr; 
  13.335 @@ -572,9 +579,9 @@ static int setup_guest(int xc_handle,
  13.336      munmap(boot_paramsp, PAGE_SIZE); 
  13.337  
  13.338      if ((boot_gdtp = xc_map_foreign_range(
  13.339 -		xc_handle, dom, PAGE_SIZE, PROT_READ|PROT_WRITE,
  13.340 -		page_array[(vboot_gdt_start-dsi.v_start)>>PAGE_SHIFT])) == 0)
  13.341 -	goto error_out;
  13.342 +        xc_handle, dom, PAGE_SIZE, PROT_READ|PROT_WRITE,
  13.343 +        page_array[(vboot_gdt_start-dsi.v_start)>>PAGE_SHIFT])) == 0)
  13.344 +        goto error_out;
  13.345      memset(boot_gdtp, 0, PAGE_SIZE);
  13.346      boot_gdtp[12*4 + 0] = boot_gdtp[13*4 + 0] = 0xffff; /* limit */
  13.347      boot_gdtp[12*4 + 1] = boot_gdtp[13*4 + 1] = 0x0000; /* base */
  13.348 @@ -584,9 +591,9 @@ static int setup_guest(int xc_handle,
  13.349  
  13.350      /* shared_info page starts its life empty. */
  13.351      if ((shared_info = xc_map_foreign_range(
  13.352 -		xc_handle, dom, PAGE_SIZE, PROT_READ|PROT_WRITE,
  13.353 -		shared_info_frame)) == 0)
  13.354 -	goto error_out;
  13.355 +        xc_handle, dom, PAGE_SIZE, PROT_READ|PROT_WRITE,
  13.356 +        shared_info_frame)) == 0)
  13.357 +        goto error_out;
  13.358      memset(shared_info, 0, sizeof(shared_info_t));
  13.359      /* Mask all upcalls... */
  13.360      for ( i = 0; i < MAX_VIRT_CPUS; i++ )
  13.361 @@ -595,9 +602,9 @@ static int setup_guest(int xc_handle,
  13.362  
  13.363      /* Populate the event channel port in the shared page */
  13.364      if ((sp = (shared_iopage_t *) xc_map_foreign_range(
  13.365 -		xc_handle, dom, PAGE_SIZE, PROT_READ|PROT_WRITE,
  13.366 -		page_array[shared_page_frame])) == 0)
  13.367 -	goto error_out;
  13.368 +        xc_handle, dom, PAGE_SIZE, PROT_READ|PROT_WRITE,
  13.369 +        page_array[shared_page_frame])) == 0)
  13.370 +        goto error_out;
  13.371      memset(sp, 0, PAGE_SIZE);
  13.372      sp->sp_global.eport = control_evtchn;
  13.373      munmap(sp, PAGE_SIZE);
  13.374 @@ -622,7 +629,7 @@ static int setup_guest(int xc_handle,
  13.375      ctxt->user_regs.edx = vboot_gdt_start;
  13.376      ctxt->user_regs.eax = 0x800;
  13.377      ctxt->user_regs.esp = vboot_gdt_end;
  13.378 -    ctxt->user_regs.ebx = 0;	/* startup_32 expects this to be 0 to signal boot cpu */
  13.379 +    ctxt->user_regs.ebx = 0; /* startup_32 expects this to be 0 to signal boot cpu */
  13.380      ctxt->user_regs.ecx = mem_mapp->nr_map;
  13.381      ctxt->user_regs.esi = vboot_params_start;
  13.382      ctxt->user_regs.edi = vboot_params_start + 0x2d0;
  13.383 @@ -646,9 +653,9 @@ static int vmx_identify(void)
  13.384  
  13.385  #ifdef __i386__
  13.386      __asm__ __volatile__ ("pushl %%ebx; cpuid; popl %%ebx" 
  13.387 -			  : "=a" (eax), "=c" (ecx) 
  13.388 -			  : "0" (1) 
  13.389 -			  : "dx");
  13.390 +                          : "=a" (eax), "=c" (ecx) 
  13.391 +                          : "0" (1) 
  13.392 +                          : "dx");
  13.393  #elif defined __x86_64__
  13.394      __asm__ __volatile__ ("pushq %%rbx; cpuid; popq %%rbx"
  13.395                            : "=a" (eax), "=c" (ecx)
  13.396 @@ -663,17 +670,17 @@ static int vmx_identify(void)
  13.397  }
  13.398  
  13.399  int xc_vmx_build(int xc_handle,
  13.400 -                   u32 domid,
  13.401 -                   int memsize,
  13.402 -                   const char *image_name,
  13.403 -                   struct mem_map *mem_mapp,
  13.404 -                   const char *ramdisk_name,
  13.405 -                   const char *cmdline,
  13.406 -                   unsigned int control_evtchn,
  13.407 -                   unsigned long flags,
  13.408 -                   unsigned int vcpus,
  13.409 -                   unsigned int store_evtchn,
  13.410 -                   unsigned long *store_mfn)
  13.411 +                 u32 domid,
  13.412 +                 int memsize,
  13.413 +                 const char *image_name,
  13.414 +                 struct mem_map *mem_mapp,
  13.415 +                 const char *ramdisk_name,
  13.416 +                 const char *cmdline,
  13.417 +                 unsigned int control_evtchn,
  13.418 +                 unsigned long flags,
  13.419 +                 unsigned int vcpus,
  13.420 +                 unsigned int store_evtchn,
  13.421 +                 unsigned long *store_mfn)
  13.422  {
  13.423      dom0_op_t launch_op, op;
  13.424      int initrd_fd = -1;
  13.425 @@ -745,11 +752,11 @@ int xc_vmx_build(int xc_handle,
  13.426      }
  13.427  
  13.428      if ( setup_guest(xc_handle, domid, memsize, image, image_size, 
  13.429 -                       initrd_gfd, initrd_size, nr_pages, 
  13.430 -                       ctxt, cmdline,
  13.431 -                       op.u.getdomaininfo.shared_info_frame,
  13.432 -                       control_evtchn, flags, vcpus, store_evtchn, store_mfn,
  13.433 -                       mem_mapp) < 0 )
  13.434 +                     initrd_gfd, initrd_size, nr_pages, 
  13.435 +                     ctxt, cmdline,
  13.436 +                     op.u.getdomaininfo.shared_info_frame,
  13.437 +                     control_evtchn, flags, vcpus, store_evtchn, store_mfn,
  13.438 +                     mem_mapp) < 0 )
  13.439      {
  13.440          ERROR("Error constructing guest OS");
  13.441          goto error_out;
  13.442 @@ -780,8 +787,8 @@ int xc_vmx_build(int xc_handle,
  13.443  
  13.444      /* Ring 1 stack is the initial stack. */
  13.445  /*
  13.446 -    ctxt->kernel_ss = FLAT_KERNEL_DS;
  13.447 -    ctxt->kernel_sp = vstartinfo_start;
  13.448 +  ctxt->kernel_ss = FLAT_KERNEL_DS;
  13.449 +  ctxt->kernel_sp = vstartinfo_start;
  13.450  */
  13.451      /* No debugging. */
  13.452      memset(ctxt->debugreg, 0, sizeof(ctxt->debugreg));
  13.453 @@ -861,7 +868,7 @@ static int parseelfimage(char *elfbase,
  13.454          return -EINVAL;
  13.455      }
  13.456      shdr = (Elf32_Shdr *)(elfbase + ehdr->e_shoff + 
  13.457 -                        (ehdr->e_shstrndx*ehdr->e_shentsize));
  13.458 +                          (ehdr->e_shstrndx*ehdr->e_shentsize));
  13.459      shstrtab = elfbase + shdr->sh_offset;
  13.460      
  13.461      for ( h = 0; h < ehdr->e_phnum; h++ ) 
  13.462 @@ -916,9 +923,9 @@ loadelfimage(
  13.463          {
  13.464              pa = (phdr->p_paddr + done) - dsi->v_start - LINUX_PAGE_OFFSET;
  13.465              if ((va = xc_map_foreign_range(
  13.466 -			xch, dom, PAGE_SIZE, PROT_WRITE,
  13.467 -			parray[pa>>PAGE_SHIFT])) == 0)
  13.468 -		return -1;
  13.469 +                xch, dom, PAGE_SIZE, PROT_WRITE,
  13.470 +                parray[pa>>PAGE_SHIFT])) == 0)
  13.471 +                return -1;
  13.472              chunksz = phdr->p_filesz - done;
  13.473              if ( chunksz > (PAGE_SIZE - (pa & (PAGE_SIZE-1))) )
  13.474                  chunksz = PAGE_SIZE - (pa & (PAGE_SIZE-1));
  13.475 @@ -931,9 +938,9 @@ loadelfimage(
  13.476          {
  13.477              pa = (phdr->p_paddr + done) - dsi->v_start - LINUX_PAGE_OFFSET;
  13.478              if ((va = xc_map_foreign_range(
  13.479 -			xch, dom, PAGE_SIZE, PROT_WRITE,
  13.480 -			parray[pa>>PAGE_SHIFT])) == 0)
  13.481 -		return -1;
  13.482 +                xch, dom, PAGE_SIZE, PROT_WRITE,
  13.483 +                parray[pa>>PAGE_SHIFT])) == 0)
  13.484 +                return -1;
  13.485              chunksz = phdr->p_memsz - done;
  13.486              if ( chunksz > (PAGE_SIZE - (pa & (PAGE_SIZE-1))) )
  13.487                  chunksz = PAGE_SIZE - (pa & (PAGE_SIZE-1));
  13.488 @@ -944,3 +951,13 @@ loadelfimage(
  13.489  
  13.490      return 0;
  13.491  }
  13.492 +
  13.493 +/*
  13.494 + * Local variables:
  13.495 + * mode: C
  13.496 + * c-set-style: "BSD"
  13.497 + * c-basic-offset: 4
  13.498 + * tab-width: 4
  13.499 + * indent-tabs-mode: nil
  13.500 + * End:
  13.501 + */