ia64/xen-unstable
changeset 1077:2c88db033b06
bitkeeper revision 1.713 (40279235AxaLHUV_M0BdLtyB_QaInw)
xc_vbd.c, xc_netbsd_build.c, xc_linux_build.c:
Fix netbsd builder for xen 1.3.
xc_vbd.c, xc_netbsd_build.c, xc_linux_build.c:
Fix netbsd builder for xen 1.3.
author | kaf24@scramble.cl.cam.ac.uk |
---|---|
date | Mon Feb 09 13:59:17 2004 +0000 (2004-02-09) |
parents | 7fee64560644 |
children | 9538ca5cdb40 61fc940adace |
files | tools/xc/lib/xc_linux_build.c tools/xc/lib/xc_netbsd_build.c tools/xc/lib/xc_vbd.c |
line diff
1.1 --- a/tools/xc/lib/xc_linux_build.c Mon Feb 09 13:39:44 2004 +0000 1.2 +++ b/tools/xc/lib/xc_linux_build.c Mon Feb 09 13:59:17 2004 +0000 1.3 @@ -166,26 +166,27 @@ static int setup_guestos(int xc_handle, 1.4 /* Load the initial ramdisk image. */ 1.5 if ( initrd_gfd ) 1.6 { 1.7 - int size; 1.8 + int size; 1.9 1.10 - for ( j=0, i=ksize; i < ((tot_pages/2) * PAGE_SIZE); i += PAGE_SIZE ) 1.11 - { 1.12 - char page[PAGE_SIZE]; 1.13 + for ( j=0, i=ksize; i < ((tot_pages/2) * PAGE_SIZE); i += PAGE_SIZE ) 1.14 + { 1.15 + char page[PAGE_SIZE]; 1.16 if ( (size = gzread(initrd_gfd, page, PAGE_SIZE)) == -1 ) 1.17 { 1.18 - PERROR("Error reading initrd image, could not"); 1.19 - goto error_out; 1.20 - } 1.21 - j += size; 1.22 - if ( size > 0 ) 1.23 - copy_to_domain_page(pm_handle, page_array[i>>PAGE_SHIFT], page); 1.24 - if ( size < PAGE_SIZE ) 1.25 - goto initrd_copied; 1.26 - } 1.27 - ERROR("Kernel/initrd too big to safely fit in domain memory"); 1.28 - goto error_out; 1.29 + PERROR("Error reading initrd image, could not"); 1.30 + goto error_out; 1.31 + } 1.32 + j += size; 1.33 + if ( size > 0 ) 1.34 + copy_to_domain_page(pm_handle, 1.35 + page_array[i>>PAGE_SHIFT], page); 1.36 + if ( size < PAGE_SIZE ) 1.37 + goto initrd_copied; 1.38 + } 1.39 + ERROR("Kernel/initrd too big to safely fit in domain memory"); 1.40 + goto error_out; 1.41 1.42 - initrd_copied: 1.43 + initrd_copied: 1.44 initrd_addr = virt_load_addr + ksize; 1.45 initrd_len = j; 1.46 } 1.47 @@ -234,11 +235,11 @@ static int setup_guestos(int xc_handle, 1.48 memset(vl1tab, 0, PAGE_SIZE); 1.49 unmap_pfn(pm_handle, vl1tab); 1.50 alloc_index--; 1.51 - 1.52 + 1.53 l1e = l1tab + (l1_table_offset(virt_load_addr+(count<<PAGE_SHIFT))* 1.54 sizeof(l1_pgentry_t)); 1.55 1.56 - /* make apropriate entry in the page directory */ 1.57 + /* Make appropriate entry in the page directory. */ 1.58 pgt_updates->ptr = l2e; 1.59 pgt_updates->val = l1tab | L2_PROT; 1.60 pgt_updates++; 1.61 @@ -373,11 +374,11 @@ int xc_linux_build(int xc_handle, 1.62 goto error_out; 1.63 } 1.64 1.65 - if ( (initrd_gfd = gzdopen(initrd_fd, "rb")) == NULL ) 1.66 - { 1.67 - PERROR("Could not allocate decompression state for initrd"); 1.68 - goto error_out; 1.69 - } 1.70 + if ( (initrd_gfd = gzdopen(initrd_fd, "rb")) == NULL ) 1.71 + { 1.72 + PERROR("Could not allocate decompression state for initrd"); 1.73 + goto error_out; 1.74 + } 1.75 1.76 } 1.77 1.78 @@ -408,11 +409,11 @@ int xc_linux_build(int xc_handle, 1.79 if ( kernel_fd >= 0 ) 1.80 close(kernel_fd); 1.81 if( kernel_gfd ) 1.82 - gzclose(kernel_gfd); 1.83 + gzclose(kernel_gfd); 1.84 if ( initrd_fd >= 0 ) 1.85 close(initrd_fd); 1.86 if( initrd_gfd ) 1.87 - gzclose(initrd_gfd); 1.88 + gzclose(initrd_gfd); 1.89 1.90 ctxt = &launch_op.u.builddomain.ctxt; 1.91 1.92 @@ -480,11 +481,11 @@ int xc_linux_build(int xc_handle, 1.93 if ( kernel_fd >= 0 ) 1.94 close(kernel_fd); 1.95 if( kernel_gfd ) 1.96 - gzclose(kernel_gfd); 1.97 + gzclose(kernel_gfd); 1.98 if ( initrd_fd >= 0 ) 1.99 close(initrd_fd); 1.100 if( initrd_gfd ) 1.101 - gzclose(initrd_gfd); 1.102 + gzclose(initrd_gfd); 1.103 1.104 return -1; 1.105 }
2.1 --- a/tools/xc/lib/xc_netbsd_build.c Mon Feb 09 13:39:44 2004 +0000 2.2 +++ b/tools/xc/lib/xc_netbsd_build.c Mon Feb 09 13:59:17 2004 +0000 2.3 @@ -3,12 +3,10 @@ 2.4 */ 2.5 2.6 #include "xc_private.h" 2.7 -#define ELFSIZE 32 /* XXX */ 2.8 +#define ELFSIZE 32 /* XXX */ 2.9 #include "xc_elf.h" 2.10 #include <zlib.h> 2.11 2.12 -/* #define DEBUG 1 */ 2.13 - 2.14 #ifdef DEBUG 2.15 #define DPRINTF(x) printf x 2.16 #else 2.17 @@ -16,8 +14,8 @@ 2.18 #endif 2.19 2.20 static int loadelfimage(gzFile, int, unsigned long *, unsigned long, 2.21 - unsigned long *, unsigned long *, 2.22 - unsigned long *, unsigned long *); 2.23 + unsigned long *, unsigned long *, 2.24 + unsigned long *, unsigned long *); 2.25 2.26 #define ELFROUND (ELFSIZE / 8) 2.27 2.28 @@ -86,12 +84,12 @@ static int setup_guestos(int xc_handle, 2.29 const char *cmdline, 2.30 unsigned long shared_info_frame) 2.31 { 2.32 - l1_pgentry_t *vl1tab = NULL, *vl1e = NULL; 2.33 - l2_pgentry_t *vl2tab = NULL, *vl2e = NULL; 2.34 + l1_pgentry_t *vl1tab; 2.35 + l2_pgentry_t *vl2tab; 2.36 unsigned long *page_array = NULL; 2.37 mmu_update_t *pgt_update_arr = NULL, *pgt_updates = NULL; 2.38 int alloc_index, num_pt_pages; 2.39 - unsigned long l2tab; 2.40 + unsigned long l2tab, l2e, l1e=0; 2.41 unsigned long l1tab = 0; 2.42 unsigned long num_pgt_updates = 0; 2.43 unsigned long count, pt_start; 2.44 @@ -122,15 +120,16 @@ static int setup_guestos(int xc_handle, 2.45 } 2.46 2.47 if (loadelfimage(kernel_gfd, pm_handle, page_array, tot_pages, 2.48 - virt_load_addr, &ksize, &symtab_addr, &symtab_len)) 2.49 - goto error_out; 2.50 + virt_load_addr, &ksize, &symtab_addr, &symtab_len)) 2.51 + goto error_out; 2.52 2.53 /* ksize is kernel-image size rounded up to a page boundary. */ 2.54 2.55 alloc_index = tot_pages - 1; 2.56 2.57 /* Count bottom-level PTs, rounding up. */ 2.58 - num_pt_pages = (l1_table_offset(*virt_load_addr) + tot_pages + 1023) / 1024; 2.59 + num_pt_pages = (l1_table_offset(*virt_load_addr) + tot_pages + 1023) 2.60 + / 1024; 2.61 2.62 /* We must also count the page directory. */ 2.63 num_pt_pages++; 2.64 @@ -159,44 +158,47 @@ static int setup_guestos(int xc_handle, 2.65 if ( (vl2tab = map_pfn(pm_handle, l2tab >> PAGE_SHIFT)) == NULL ) 2.66 goto error_out; 2.67 memset(vl2tab, 0, PAGE_SIZE); 2.68 - vl2e = vl2tab + l2_table_offset(*virt_load_addr); 2.69 + unmap_pfn(pm_handle, vl2tab); 2.70 + l2e = l2tab + (l2_table_offset(*virt_load_addr)*sizeof(l2_pgentry_t)); 2.71 for ( count = 0; count < tot_pages; count++ ) 2.72 - { 2.73 - if ( ((unsigned long)vl1e & (PAGE_SIZE-1)) == 0 ) 2.74 + { 2.75 + if ( (l1e & (PAGE_SIZE-1)) == 0 ) 2.76 { 2.77 l1tab = page_array[alloc_index] << PAGE_SHIFT; 2.78 if ( (vl1tab = map_pfn(pm_handle, l1tab >> PAGE_SHIFT)) == NULL ) 2.79 goto error_out; 2.80 memset(vl1tab, 0, PAGE_SIZE); 2.81 + unmap_pfn(pm_handle, vl1tab); 2.82 alloc_index--; 2.83 - 2.84 - vl1e = vl1tab + l1_table_offset(*virt_load_addr + 2.85 - (count << PAGE_SHIFT)); 2.86 + 2.87 + l1e = l1tab + (l1_table_offset(*virt_load_addr + 2.88 + (count<<PAGE_SHIFT)) * 2.89 + sizeof(l1_pgentry_t)); 2.90 2.91 - /* make apropriate entry in the page directory */ 2.92 - pgt_updates->ptr = (unsigned long)vl2e; 2.93 + /* Make appropriate entry in the page directory. */ 2.94 + pgt_updates->ptr = l2e; 2.95 pgt_updates->val = l1tab | L2_PROT; 2.96 pgt_updates++; 2.97 num_pgt_updates++; 2.98 - vl2e++; 2.99 + l2e += sizeof(l2_pgentry_t); 2.100 } 2.101 2.102 if ( count < pt_start ) 2.103 { 2.104 - pgt_updates->ptr = (unsigned long)vl1e; 2.105 + pgt_updates->ptr = l1e; 2.106 pgt_updates->val = (page_array[count] << PAGE_SHIFT) | L1_PROT; 2.107 pgt_updates++; 2.108 num_pgt_updates++; 2.109 - vl1e++; 2.110 + l1e += sizeof(l1_pgentry_t); 2.111 } 2.112 else 2.113 { 2.114 - pgt_updates->ptr = (unsigned long)vl1e; 2.115 + pgt_updates->ptr = l1e; 2.116 pgt_updates->val = 2.117 ((page_array[count] << PAGE_SHIFT) | L1_PROT) & ~_PAGE_RW; 2.118 pgt_updates++; 2.119 num_pgt_updates++; 2.120 - vl1e++; 2.121 + l1e += sizeof(l1_pgentry_t); 2.122 } 2.123 2.124 pgt_updates->ptr = 2.125 @@ -247,9 +249,9 @@ static int setup_guestos(int xc_handle, 2.126 } 2.127 2.128 int xc_netbsd_build(int xc_handle, 2.129 - unsigned int domid, 2.130 - const char *image_name, 2.131 - const char *cmdline) 2.132 + unsigned int domid, 2.133 + const char *image_name, 2.134 + const char *cmdline) 2.135 { 2.136 dom0_op_t launch_op, op; 2.137 unsigned long load_addr; 2.138 @@ -307,7 +309,7 @@ int xc_netbsd_build(int xc_handle, 2.139 if ( kernel_fd >= 0 ) 2.140 close(kernel_fd); 2.141 if( kernel_gfd ) 2.142 - gzclose(kernel_gfd); 2.143 + gzclose(kernel_gfd); 2.144 2.145 ctxt = &launch_op.u.builddomain.ctxt; 2.146 2.147 @@ -375,7 +377,7 @@ int xc_netbsd_build(int xc_handle, 2.148 if ( kernel_fd >= 0 ) 2.149 close(kernel_fd); 2.150 if( kernel_gfd ) 2.151 - gzclose(kernel_gfd); 2.152 + gzclose(kernel_gfd); 2.153 2.154 return -1; 2.155 } 2.156 @@ -388,22 +390,22 @@ myseek(gzFile gfd, off_t offset, int whe 2.157 int c; 2.158 2.159 if (offset < 0) { 2.160 - ERROR("seek back not supported"); 2.161 - return -1; 2.162 + ERROR("seek back not supported"); 2.163 + return -1; 2.164 } 2.165 2.166 while (offset) { 2.167 - c = offset; 2.168 - if (c > MYSEEK_BUFSIZE) 2.169 - c = MYSEEK_BUFSIZE; 2.170 - if (gzread(gfd, tmp, c) != c) { 2.171 - PERROR("Error seeking in image."); 2.172 - return -1; 2.173 - } 2.174 - offset -= c; 2.175 + c = offset; 2.176 + if (c > MYSEEK_BUFSIZE) 2.177 + c = MYSEEK_BUFSIZE; 2.178 + if (gzread(gfd, tmp, c) != c) { 2.179 + PERROR("Error seeking in image."); 2.180 + return -1; 2.181 + } 2.182 + offset -= c; 2.183 } 2.184 2.185 - return 0; /* XXX */ 2.186 + return 0; /* XXX */ 2.187 } 2.188 2.189 /* 2.190 @@ -434,15 +436,15 @@ myseek(gzFile gfd, off_t offset, int whe 2.191 * ---------------- ehdr.e_entry + *ksize << PAGE_SHIFT 2.192 */ 2.193 2.194 -#define IS_TEXT(p) (p.p_flags & PF_X) 2.195 -#define IS_DATA(p) (p.p_flags & PF_W) 2.196 -#define IS_BSS(p) (p.p_filesz < p.p_memsz) 2.197 +#define IS_TEXT(p) (p.p_flags & PF_X) 2.198 +#define IS_DATA(p) (p.p_flags & PF_W) 2.199 +#define IS_BSS(p) (p.p_filesz < p.p_memsz) 2.200 2.201 static int 2.202 loadelfimage(gzFile kernel_gfd, int pm_handle, unsigned long *page_array, 2.203 - unsigned long tot_pages, unsigned long *virt_load_addr, 2.204 - unsigned long *ksize, unsigned long *symtab_addr, 2.205 - unsigned long *symtab_len) 2.206 + unsigned long tot_pages, unsigned long *virt_load_addr, 2.207 + unsigned long *ksize, unsigned long *symtab_addr, 2.208 + unsigned long *symtab_len) 2.209 { 2.210 Elf_Ehdr ehdr; 2.211 Elf_Phdr *phdr; 2.212 @@ -458,14 +460,14 @@ loadelfimage(gzFile kernel_gfd, int pm_h 2.213 maxva = 0; 2.214 2.215 if (gzread(kernel_gfd, &ehdr, sizeof(Elf_Ehdr)) != sizeof(Elf_Ehdr)) { 2.216 - PERROR("Error reading kernel image ELF header."); 2.217 - goto out; 2.218 + PERROR("Error reading kernel image ELF header."); 2.219 + goto out; 2.220 } 2.221 curpos = sizeof(Elf_Ehdr); 2.222 2.223 if (!IS_ELF(ehdr)) { 2.224 - PERROR("Image does not have an ELF header."); 2.225 - goto out; 2.226 + PERROR("Image does not have an ELF header."); 2.227 + goto out; 2.228 } 2.229 2.230 *virt_load_addr = ehdr.e_entry; 2.231 @@ -476,7 +478,7 @@ loadelfimage(gzFile kernel_gfd, int pm_h 2.232 } 2.233 2.234 if ((*virt_load_addr + (tot_pages << PAGE_SHIFT)) > 2.235 - HYPERVISOR_VIRT_START) { 2.236 + HYPERVISOR_VIRT_START) { 2.237 ERROR("Cannot map all domain memory without hitting Xen space"); 2.238 goto out; 2.239 } 2.240 @@ -484,94 +486,94 @@ loadelfimage(gzFile kernel_gfd, int pm_h 2.241 2.242 phdr = malloc(ehdr.e_phnum * sizeof(Elf_Phdr)); 2.243 if (phdr == NULL) { 2.244 - ERROR("Cannot allocate memory for Elf_Phdrs"); 2.245 - goto out; 2.246 + ERROR("Cannot allocate memory for Elf_Phdrs"); 2.247 + goto out; 2.248 } 2.249 2.250 if (myseek(kernel_gfd, ehdr.e_phoff - curpos, SEEK_SET) == -1) { 2.251 - ERROR("Seek to program header failed"); 2.252 - goto out; 2.253 + ERROR("Seek to program header failed"); 2.254 + goto out; 2.255 } 2.256 curpos = ehdr.e_phoff; 2.257 2.258 if (gzread(kernel_gfd, phdr, ehdr.e_phnum * sizeof(Elf_Phdr)) != 2.259 - ehdr.e_phnum * sizeof(Elf_Phdr)) { 2.260 - PERROR("Error reading kernel image ELF program header."); 2.261 - goto out; 2.262 + ehdr.e_phnum * sizeof(Elf_Phdr)) { 2.263 + PERROR("Error reading kernel image ELF program header."); 2.264 + goto out; 2.265 } 2.266 curpos += ehdr.e_phnum * sizeof(Elf_Phdr); 2.267 2.268 2.269 for (h = 0; h < ehdr.e_phnum; h++) { 2.270 - if (phdr[h].p_type != PT_LOAD || 2.271 - (phdr[h].p_flags & (PF_W|PF_X)) == 0) 2.272 - continue; 2.273 + if (phdr[h].p_type != PT_LOAD || 2.274 + (phdr[h].p_flags & (PF_W|PF_X)) == 0) 2.275 + continue; 2.276 2.277 - if (IS_TEXT(phdr[h]) || IS_DATA(phdr[h])) { 2.278 - if (myseek(kernel_gfd, phdr[h].p_offset - curpos, SEEK_SET) == 2.279 - -1) { 2.280 - ERROR("Seek to section failed"); 2.281 - goto out; 2.282 - } 2.283 - curpos = phdr[h].p_offset; 2.284 + if (IS_TEXT(phdr[h]) || IS_DATA(phdr[h])) { 2.285 + if (myseek(kernel_gfd, phdr[h].p_offset - curpos, SEEK_SET) == 2.286 + -1) { 2.287 + ERROR("Seek to section failed"); 2.288 + goto out; 2.289 + } 2.290 + curpos = phdr[h].p_offset; 2.291 2.292 - for (iva = phdr[h].p_vaddr; 2.293 - iva < phdr[h].p_vaddr + phdr[h].p_filesz; iva += c) { 2.294 - c = PAGE_SIZE - (iva & (PAGE_SIZE - 1)); 2.295 - if (iva + c > phdr[h].p_vaddr + phdr[h].p_filesz) 2.296 - c = phdr[h].p_vaddr + phdr[h].p_filesz - iva; 2.297 - if (gzread(kernel_gfd, page, c) != c) { 2.298 - PERROR("Error reading kernel image page."); 2.299 - goto out; 2.300 - } 2.301 - curpos += c; 2.302 - vaddr = map_pfn(pm_handle, page_array[(iva - *virt_load_addr) 2.303 - >> PAGE_SHIFT]); 2.304 - if (vaddr == NULL) { 2.305 - ERROR("Couldn't map guest memory"); 2.306 - goto out; 2.307 - } 2.308 - DPRINTF(("copy page %p to %p, count 0x%x\n", (void *)iva, 2.309 - vaddr + (iva & (PAGE_SIZE - 1)), c)); 2.310 - memcpy(vaddr + (iva & (PAGE_SIZE - 1)), page, c); 2.311 - unmap_pfn(pm_handle, vaddr); 2.312 - } 2.313 + for (iva = phdr[h].p_vaddr; 2.314 + iva < phdr[h].p_vaddr + phdr[h].p_filesz; iva += c) { 2.315 + c = PAGE_SIZE - (iva & (PAGE_SIZE - 1)); 2.316 + if (iva + c > phdr[h].p_vaddr + phdr[h].p_filesz) 2.317 + c = phdr[h].p_vaddr + phdr[h].p_filesz - iva; 2.318 + if (gzread(kernel_gfd, page, c) != c) { 2.319 + PERROR("Error reading kernel image page."); 2.320 + goto out; 2.321 + } 2.322 + curpos += c; 2.323 + vaddr = map_pfn(pm_handle, page_array[(iva - *virt_load_addr) 2.324 + >> PAGE_SHIFT]); 2.325 + if (vaddr == NULL) { 2.326 + ERROR("Couldn't map guest memory"); 2.327 + goto out; 2.328 + } 2.329 + DPRINTF(("copy page %p to %p, count 0x%x\n", (void *)iva, 2.330 + vaddr + (iva & (PAGE_SIZE - 1)), c)); 2.331 + memcpy(vaddr + (iva & (PAGE_SIZE - 1)), page, c); 2.332 + unmap_pfn(pm_handle, vaddr); 2.333 + } 2.334 2.335 - if (phdr[h].p_vaddr + phdr[h].p_filesz > maxva) 2.336 - maxva = phdr[h].p_vaddr + phdr[h].p_filesz; 2.337 - } 2.338 + if (phdr[h].p_vaddr + phdr[h].p_filesz > maxva) 2.339 + maxva = phdr[h].p_vaddr + phdr[h].p_filesz; 2.340 + } 2.341 2.342 - if (IS_BSS(phdr[h])) { 2.343 - /* XXX maybe clear phdr[h].p_memsz bytes from 2.344 - phdr[h].p_vaddr + phdr[h].p_filesz ??? */ 2.345 - if (phdr[h].p_vaddr + phdr[h].p_memsz > maxva) 2.346 - maxva = phdr[h].p_vaddr + phdr[h].p_memsz; 2.347 - DPRINTF(("bss from %p to %p, maxva %p\n", 2.348 - (void *)(phdr[h].p_vaddr + phdr[h].p_filesz), 2.349 - (void *)(phdr[h].p_vaddr + phdr[h].p_memsz), 2.350 - (void *)maxva)); 2.351 - } 2.352 + if (IS_BSS(phdr[h])) { 2.353 + /* XXX maybe clear phdr[h].p_memsz bytes from 2.354 + phdr[h].p_vaddr + phdr[h].p_filesz ??? */ 2.355 + if (phdr[h].p_vaddr + phdr[h].p_memsz > maxva) 2.356 + maxva = phdr[h].p_vaddr + phdr[h].p_memsz; 2.357 + DPRINTF(("bss from %p to %p, maxva %p\n", 2.358 + (void *)(phdr[h].p_vaddr + phdr[h].p_filesz), 2.359 + (void *)(phdr[h].p_vaddr + phdr[h].p_memsz), 2.360 + (void *)maxva)); 2.361 + } 2.362 } 2.363 2.364 p = malloc(sizeof(int) + sizeof(Elf_Ehdr) + 2.365 - ehdr.e_shnum * sizeof(Elf_Shdr)); 2.366 + ehdr.e_shnum * sizeof(Elf_Shdr)); 2.367 if (p == NULL) { 2.368 - ERROR("Cannot allocate memory for Elf_Shdrs"); 2.369 - goto out; 2.370 + ERROR("Cannot allocate memory for Elf_Shdrs"); 2.371 + goto out; 2.372 } 2.373 2.374 shdr = (Elf_Shdr *)(p + sizeof(int) + sizeof(Elf_Ehdr)); 2.375 2.376 if (myseek(kernel_gfd, ehdr.e_shoff - curpos, SEEK_SET) == -1) { 2.377 - ERROR("Seek to symbol header failed"); 2.378 - goto out; 2.379 + ERROR("Seek to symbol header failed"); 2.380 + goto out; 2.381 } 2.382 curpos = ehdr.e_shoff; 2.383 2.384 if (gzread(kernel_gfd, shdr, ehdr.e_shnum * sizeof(Elf_Shdr)) != 2.385 - ehdr.e_shnum * sizeof(Elf_Shdr)) { 2.386 - PERROR("Error reading kernel image ELF symbol header."); 2.387 - goto out; 2.388 + ehdr.e_shnum * sizeof(Elf_Shdr)) { 2.389 + PERROR("Error reading kernel image ELF symbol header."); 2.390 + goto out; 2.391 } 2.392 curpos += ehdr.e_shnum * sizeof(Elf_Shdr); 2.393 2.394 @@ -584,68 +586,68 @@ loadelfimage(gzFile kernel_gfd, int pm_h 2.395 maxva = (maxva + ELFROUND - 1) & ~(ELFROUND - 1); 2.396 2.397 for (h = 0; h < ehdr.e_shnum; h++) { 2.398 - if (shdr[h].sh_type == SHT_STRTAB) { 2.399 - for (i = 0; i < ehdr.e_shnum; i++) 2.400 - if (shdr[i].sh_type == SHT_SYMTAB && 2.401 - shdr[i].sh_link == h) 2.402 - break; 2.403 - if (i == ehdr.e_shnum) { 2.404 - shdr[h].sh_offset = 0; 2.405 - continue; 2.406 - } 2.407 - } 2.408 + if (shdr[h].sh_type == SHT_STRTAB) { 2.409 + for (i = 0; i < ehdr.e_shnum; i++) 2.410 + if (shdr[i].sh_type == SHT_SYMTAB && 2.411 + shdr[i].sh_link == h) 2.412 + break; 2.413 + if (i == ehdr.e_shnum) { 2.414 + shdr[h].sh_offset = 0; 2.415 + continue; 2.416 + } 2.417 + } 2.418 2.419 - if (shdr[h].sh_type == SHT_STRTAB || 2.420 - shdr[h].sh_type == SHT_SYMTAB) { 2.421 - if (myseek(kernel_gfd, shdr[h].sh_offset - curpos, SEEK_SET) == 2.422 - -1) { 2.423 - ERROR("Seek to symbol section failed"); 2.424 - goto out; 2.425 - } 2.426 - curpos = shdr[h].sh_offset; 2.427 + if (shdr[h].sh_type == SHT_STRTAB || 2.428 + shdr[h].sh_type == SHT_SYMTAB) { 2.429 + if (myseek(kernel_gfd, shdr[h].sh_offset - curpos, SEEK_SET) == 2.430 + -1) { 2.431 + ERROR("Seek to symbol section failed"); 2.432 + goto out; 2.433 + } 2.434 + curpos = shdr[h].sh_offset; 2.435 2.436 - shdr[h].sh_offset = maxva - *symtab_addr; 2.437 + shdr[h].sh_offset = maxva - *symtab_addr; 2.438 2.439 - DPRINTF(("copy section %d, size 0x%x\n", h, shdr[h].sh_size)); 2.440 - for (i = 0; i < shdr[h].sh_size; i += c, maxva += c) { 2.441 - c = PAGE_SIZE - (maxva & (PAGE_SIZE - 1)); 2.442 - if (c > (shdr[h].sh_size - i)) 2.443 - c = shdr[h].sh_size - i; 2.444 - if (gzread(kernel_gfd, page, c) != c) { 2.445 - PERROR("Error reading kernel image page."); 2.446 - goto out; 2.447 - } 2.448 - curpos += c; 2.449 + DPRINTF(("copy section %d, size 0x%x\n", h, shdr[h].sh_size)); 2.450 + for (i = 0; i < shdr[h].sh_size; i += c, maxva += c) { 2.451 + c = PAGE_SIZE - (maxva & (PAGE_SIZE - 1)); 2.452 + if (c > (shdr[h].sh_size - i)) 2.453 + c = shdr[h].sh_size - i; 2.454 + if (gzread(kernel_gfd, page, c) != c) { 2.455 + PERROR("Error reading kernel image page."); 2.456 + goto out; 2.457 + } 2.458 + curpos += c; 2.459 2.460 - vaddr = map_pfn(pm_handle, page_array[(maxva - *virt_load_addr) 2.461 - >> PAGE_SHIFT]); 2.462 - if (vaddr == NULL) { 2.463 - ERROR("Couldn't map guest memory"); 2.464 - goto out; 2.465 - } 2.466 - DPRINTF(("copy page %p to %p, count 0x%x\n", (void *)maxva, 2.467 - vaddr + (maxva & (PAGE_SIZE - 1)), c)); 2.468 - memcpy(vaddr + (maxva & (PAGE_SIZE - 1)), page, c); 2.469 - unmap_pfn(pm_handle, vaddr); 2.470 - } 2.471 + vaddr = map_pfn(pm_handle, page_array[(maxva - *virt_load_addr) 2.472 + >> PAGE_SHIFT]); 2.473 + if (vaddr == NULL) { 2.474 + ERROR("Couldn't map guest memory"); 2.475 + goto out; 2.476 + } 2.477 + DPRINTF(("copy page %p to %p, count 0x%x\n", (void *)maxva, 2.478 + vaddr + (maxva & (PAGE_SIZE - 1)), c)); 2.479 + memcpy(vaddr + (maxva & (PAGE_SIZE - 1)), page, c); 2.480 + unmap_pfn(pm_handle, vaddr); 2.481 + } 2.482 2.483 - *symtab_len += shdr[h].sh_size; 2.484 - maxva = (maxva + ELFROUND - 1) & ~(ELFROUND - 1); 2.485 + *symtab_len += shdr[h].sh_size; 2.486 + maxva = (maxva + ELFROUND - 1) & ~(ELFROUND - 1); 2.487 2.488 - } 2.489 - shdr[h].sh_name = 0; 2.490 + } 2.491 + shdr[h].sh_name = 0; 2.492 } 2.493 2.494 if (*symtab_len == 0) { 2.495 - DPRINTF(("no symbol table\n")); 2.496 - *symtab_addr = 0; 2.497 - ret = 0; 2.498 - goto out; 2.499 + DPRINTF(("no symbol table\n")); 2.500 + *symtab_addr = 0; 2.501 + ret = 0; 2.502 + goto out; 2.503 } 2.504 2.505 DPRINTF(("sym header va %p from %p/%p size %x/%x\n", (void *)symva, 2.506 - shdr, p, ehdr.e_shnum * sizeof(Elf_Shdr), 2.507 - ehdr.e_shnum * sizeof(Elf_Shdr) + sizeof(Elf_Ehdr))); 2.508 + shdr, p, ehdr.e_shnum * sizeof(Elf_Shdr), 2.509 + ehdr.e_shnum * sizeof(Elf_Shdr) + sizeof(Elf_Ehdr))); 2.510 ehdr.e_phoff = 0; 2.511 ehdr.e_shoff = sizeof(Elf_Ehdr); 2.512 ehdr.e_phentsize = 0; 2.513 @@ -656,39 +658,39 @@ loadelfimage(gzFile kernel_gfd, int pm_h 2.514 2.515 s = sizeof(int) + sizeof(Elf_Ehdr) + ehdr.e_shnum * sizeof(Elf_Shdr); 2.516 for (i = 0; i < s; i += c, symva += c) { 2.517 - c = PAGE_SIZE - (symva & (PAGE_SIZE - 1)); 2.518 - if (c > s - i) 2.519 - c = s - i; 2.520 - vaddr = map_pfn(pm_handle, page_array[(symva - *virt_load_addr) 2.521 - >> PAGE_SHIFT]); 2.522 - if (vaddr == NULL) { 2.523 - ERROR("Couldn't map guest memory"); 2.524 - goto out; 2.525 - } 2.526 - DPRINTF(("copy page %p to %p, count 0x%x\n", (void *)symva, 2.527 - vaddr + (symva & (PAGE_SIZE - 1)), c)); 2.528 - memcpy(vaddr + (symva & (PAGE_SIZE - 1)), p + i, 2.529 - c); 2.530 - unmap_pfn(pm_handle, vaddr); 2.531 + c = PAGE_SIZE - (symva & (PAGE_SIZE - 1)); 2.532 + if (c > s - i) 2.533 + c = s - i; 2.534 + vaddr = map_pfn(pm_handle, page_array[(symva - *virt_load_addr) 2.535 + >> PAGE_SHIFT]); 2.536 + if (vaddr == NULL) { 2.537 + ERROR("Couldn't map guest memory"); 2.538 + goto out; 2.539 + } 2.540 + DPRINTF(("copy page %p to %p, count 0x%x\n", (void *)symva, 2.541 + vaddr + (symva & (PAGE_SIZE - 1)), c)); 2.542 + memcpy(vaddr + (symva & (PAGE_SIZE - 1)), p + i, 2.543 + c); 2.544 + unmap_pfn(pm_handle, vaddr); 2.545 } 2.546 2.547 *symtab_len = maxva - *symtab_addr; 2.548 2.549 ret = 0; 2.550 2.551 - out: 2.552 + out: 2.553 if (ret == 0) { 2.554 - maxva = (maxva + PAGE_SIZE - 1) & ~(PAGE_SIZE - 1); 2.555 - *ksize = (maxva - *virt_load_addr) >> PAGE_SHIFT; 2.556 + maxva = (maxva + PAGE_SIZE - 1) & ~(PAGE_SIZE - 1); 2.557 + *ksize = (maxva - *virt_load_addr) >> PAGE_SHIFT; 2.558 2.559 - DPRINTF(("virt_addr %p, kpages 0x%lx, symtab_addr %p, symtab_len %p\n", 2.560 - (void *)*virt_load_addr, *ksize, (void *)*symtab_addr, 2.561 - (void *)*symtab_len)); 2.562 + DPRINTF(("virt_addr %p, kpages 0x%lx, symtab_addr %p, symtab_len %p\n", 2.563 + (void *)*virt_load_addr, *ksize, (void *)*symtab_addr, 2.564 + (void *)*symtab_len)); 2.565 } 2.566 2.567 if (phdr) 2.568 - free(phdr); 2.569 + free(phdr); 2.570 if (p) 2.571 - free(p); 2.572 + free(p); 2.573 return ret; 2.574 }
3.1 --- a/tools/xc/lib/xc_vbd.c Mon Feb 09 13:39:44 2004 +0000 3.2 +++ b/tools/xc/lib/xc_vbd.c Mon Feb 09 13:59:17 2004 +0000 3.3 @@ -187,7 +187,7 @@ int xc_vbd_probe(int xc_handle, 3.4 3.5 if ( ret >= 0 ) 3.6 { 3.7 - for ( i = 0, j = 0; i < xdi->count; i++ ) 3.8 + for ( i = 0, j = 0; i < xdi->count; i++ ) 3.9 { 3.10 if ( !(xdi->disks[i].info & XD_FLAG_VIRT) ) 3.11 continue;