Jimi Xenidis
2006-Jun-22 18:50 UTC
[Xen-devel] [patch] [do-over] load 64-bit files with 32-bit tools
This patch allows 32bit libxc to grok 64bit files by: - using 64bit integral types for addresses in struct domain_start_info - uses stroull() so it can parse 64bit values - removes redundant _p(a) definition and comments it - smarter print formatting as per discussion with <Keir.Fraser@cl.cam.ac.uk> and <aliguori@us.ibm.com> Signed-off-by: Jimi Xenidis <jimix@watson.ibm.com> --- diff -r 05ab081f3c67 tools/libxc/xc_hvm_build.c --- a/tools/libxc/xc_hvm_build.c Fri Jun 16 18:08:27 2006 +0100 +++ b/tools/libxc/xc_hvm_build.c Thu Jun 22 14:46:01 2006 -0400 @@ -208,11 +208,11 @@ static int setup_guest(int xc_handle, v_end = (unsigned long long)memsize << 20; IPRINTF("VIRTUAL MEMORY ARRANGEMENT:\n" - " Loaded HVM loader: %08lx->%08lx\n" - " TOTAL: %08lx->%016llx\n", + " Loaded HVM loader: %016llx->%016llx\n" + " TOTAL: %016llx->%016llx\n", dsi.v_kernstart, dsi.v_kernend, dsi.v_start, v_end); - IPRINTF(" ENTRY ADDRESS: %08lx\n", dsi.v_kernentry); + IPRINTF(" ENTRY ADDRESS: %016llx\n", dsi.v_kernentry); if ( (v_end - dsi.v_start) > ((unsigned long long)nr_pages << PAGE_SHIFT) ) { diff -r 05ab081f3c67 tools/libxc/xc_linux_build.c --- a/tools/libxc/xc_linux_build.c Fri Jun 16 18:08:27 2006 +0100 +++ b/tools/libxc/xc_linux_build.c Thu Jun 22 14:46:01 2006 -0400 @@ -12,6 +12,9 @@ #include <unistd.h> #include <inttypes.h> #include <zlib.h> + +/* Handy for printing out ''0'' prepended values at native pointer size */ +#define _p(a) ((void *) ((ulong)a)) #if defined(__i386__) #define L1_PROT (_PAGE_PRESENT|_PAGE_RW|_PAGE_ACCESSED) @@ -508,8 +511,6 @@ static int setup_guest(int xc_handle, goto error_out; } -#define _p(a) ((void *) (a)) - IPRINTF("VIRTUAL MEMORY ARRANGEMENT:\n" " Loaded kernel: %p->%p\n" " Init. ramdisk: %p->%p\n" @@ -803,8 +804,6 @@ static int setup_guest(int xc_handle, #endif } -#define _p(a) ((void *) (a)) - IPRINTF("VIRTUAL MEMORY ARRANGEMENT:\n"); IPRINTF(" Loaded kernel: %p->%p\n", _p(dsi.v_kernstart), _p(dsi.v_kernend)); @@ -825,8 +824,8 @@ static int setup_guest(int xc_handle, if ( ((v_end - dsi.v_start)>>PAGE_SHIFT) > nr_pages ) { PERROR("Initial guest OS requires too much space\n" - "(%luMB is greater than %luMB limit)\n", - (v_end-dsi.v_start)>>20, nr_pages>>(20-PAGE_SHIFT)); + "(%pMB is greater than %luMB limit)\n", + _p((v_end-dsi.v_start)>>20), nr_pages>>(20-PAGE_SHIFT)); goto error_out; } diff -r 05ab081f3c67 tools/libxc/xc_load_elf.c --- a/tools/libxc/xc_load_elf.c Fri Jun 16 18:08:27 2006 +0100 +++ b/tools/libxc/xc_load_elf.c Thu Jun 22 14:46:01 2006 -0400 @@ -68,7 +68,7 @@ static int parseelfimage(const char *ima Elf_Ehdr *ehdr = (Elf_Ehdr *)image; Elf_Phdr *phdr; Elf_Shdr *shdr; - unsigned long kernstart = ~0UL, kernend=0UL, vaddr, virt_base, elf_pa_off; + Elf_Addr kernstart = -1, kernend = 0, vaddr, virt_base, elf_pa_off; const char *shstrtab; char *guestinfo=NULL, *p; int h, virt_base_defined, elf_pa_off_defined; @@ -162,12 +162,12 @@ static int parseelfimage(const char *ima /* Initial guess for virt_base is 0 if it is not explicitly defined. */ p = strstr(guestinfo, "VIRT_BASE="); virt_base_defined = (p != NULL); - virt_base = virt_base_defined ? strtoul(p+10, &p, 0) : 0; + virt_base = virt_base_defined ? strtoull(p+10, &p, 0) : 0; /* Initial guess for elf_pa_off is virt_base if not explicitly defined. */ p = strstr(guestinfo, "ELF_PADDR_OFFSET="); elf_pa_off_defined = (p != NULL); - elf_pa_off = elf_pa_off_defined ? strtoul(p+17, &p, 0) : virt_base; + elf_pa_off = elf_pa_off_defined ? strtoull(p+17, &p, 0) : virt_base; if ( elf_pa_off_defined && !virt_base_defined ) goto bad_image; @@ -196,7 +196,7 @@ static int parseelfimage(const char *ima dsi->v_kernentry = ehdr->e_entry; if ( (p = strstr(guestinfo, "VIRT_ENTRY=")) != NULL ) - dsi->v_kernentry = strtoul(p+11, &p, 0); + dsi->v_kernentry = strtoull(p+11, &p, 0); if ( (kernstart > kernend) || (dsi->v_kernentry < kernstart) || diff -r 05ab081f3c67 tools/libxc/xg_private.h --- a/tools/libxc/xg_private.h Fri Jun 16 18:08:27 2006 +0100 +++ b/tools/libxc/xg_private.h Thu Jun 22 14:46:01 2006 -0400 @@ -132,13 +132,13 @@ typedef unsigned long l4_pgentry_t; struct domain_setup_info { - unsigned long v_start; - unsigned long v_end; - unsigned long v_kernstart; - unsigned long v_kernend; - unsigned long v_kernentry; - - unsigned long elf_paddr_offset; + unsigned long long v_start; + unsigned long long v_end; + unsigned long long v_kernstart; + unsigned long long v_kernend; + unsigned long long v_kernentry; + + unsigned long long elf_paddr_offset; #define PAEKERN_no 0 #define PAEKERN_yes 1 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
Keir Fraser
2006-Jun-22 20:13 UTC
Re: [Xen-devel] [patch] [do-over] load 64-bit files with 32-bit tools
On 22 Jun 2006, at 19:50, Jimi Xenidis wrote:> + unsigned long long v_start; > + unsigned long long v_end; > + unsigned long long v_kernstart; > + unsigned long long v_kernend; > + unsigned long long v_kernentry; > + > + unsigned long long elf_paddr_offset;I liked these as uint64_t. Why the change? -- Keir _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
Jimi Xenidis
2006-Jun-22 21:46 UTC
Re: [Xen-devel] [patch] [do-over] load 64-bit files with 32-bit tools
On Jun 22, 2006, at 4:13 PM, Keir Fraser wrote:> > On 22 Jun 2006, at 19:50, Jimi Xenidis wrote:[...]>> + unsigned long long elf_paddr_offset; > > I liked these as uint64_t. Why the change?I noticed the rest of the struct did not use derived types and thought that was intentional, it also addressed the issue anthony brought up where uint64_t was unsigned long on some machines for formatting might still be a problem. I actually prefer the derived types as well. shall I resubmit? -JX _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
Hollis Blanchard
2006-Jun-30 20:16 UTC
Re: [Xen-devel] [patch] [do-over] load 64-bit files with 32-bit tools
On Thu, 2006-06-22 at 21:13 +0100, Keir Fraser wrote:> On 22 Jun 2006, at 19:50, Jimi Xenidis wrote: > > > + unsigned long long v_start; > > + unsigned long long v_end; > > + unsigned long long v_kernstart; > > + unsigned long long v_kernend; > > + unsigned long long v_kernentry; > > + > > + unsigned long long elf_paddr_offset; > > I liked these as uint64_t. Why the change?Allow 32-bit libxc to load 64-bit ELF files. - use 64-bit integral types for addresses in struct domain_start_info - use stroull() to parse 64-bit values - remove redundant _p(a) definition and add a comment - printf format changes for the new types Signed-off-by: Jimi Xenidis <jimix@watson.ibm.com> Signed-off-by: Hollis Blanchard <hollisb@us.ibm.com> diff -r 17e9daeb2c50 tools/libxc/xc_hvm_build.c --- a/tools/libxc/xc_hvm_build.c Fri Jun 30 14:41:13 2006 +0100 +++ b/tools/libxc/xc_hvm_build.c Fri Jun 30 15:02:28 2006 -0500 @@ -208,11 +208,11 @@ static int setup_guest(int xc_handle, v_end = (unsigned long long)memsize << 20; IPRINTF("VIRTUAL MEMORY ARRANGEMENT:\n" - " Loaded HVM loader: %08lx->%08lx\n" - " TOTAL: %08lx->%016llx\n", + " Loaded HVM loader: %016llx->%016llx\n" + " TOTAL: %016llx->%016llx\n", dsi.v_kernstart, dsi.v_kernend, dsi.v_start, v_end); - IPRINTF(" ENTRY ADDRESS: %08lx\n", dsi.v_kernentry); + IPRINTF(" ENTRY ADDRESS: %016llx\n", dsi.v_kernentry); if ( (v_end - dsi.v_start) > ((unsigned long long)nr_pages << PAGE_SHIFT) ) { diff -r 17e9daeb2c50 tools/libxc/xc_linux_build.c --- a/tools/libxc/xc_linux_build.c Fri Jun 30 14:41:13 2006 +0100 +++ b/tools/libxc/xc_linux_build.c Fri Jun 30 15:02:28 2006 -0500 @@ -11,6 +11,9 @@ #include <unistd.h> #include <inttypes.h> #include <zlib.h> + +/* Handy for printing out ''0'' prepended values at native pointer size */ +#define _p(a) ((void *) ((ulong)a)) #if defined(__i386__) #define L1_PROT (_PAGE_PRESENT|_PAGE_RW|_PAGE_ACCESSED) @@ -502,8 +505,6 @@ static int setup_guest(int xc_handle, goto error_out; } -#define _p(a) ((void *) (a)) - IPRINTF("VIRTUAL MEMORY ARRANGEMENT:\n" " Loaded kernel: %p->%p\n" " Init. ramdisk: %p->%p\n" @@ -797,8 +798,6 @@ static int setup_guest(int xc_handle, #endif } -#define _p(a) ((void *) (a)) - IPRINTF("VIRTUAL MEMORY ARRANGEMENT:\n"); IPRINTF(" Loaded kernel: %p->%p\n", _p(dsi.v_kernstart), _p(dsi.v_kernend)); @@ -819,8 +818,8 @@ static int setup_guest(int xc_handle, if ( ((v_end - dsi.v_start)>>PAGE_SHIFT) > nr_pages ) { PERROR("Initial guest OS requires too much space\n" - "(%luMB is greater than %luMB limit)\n", - (v_end-dsi.v_start)>>20, nr_pages>>(20-PAGE_SHIFT)); + "(%pMB is greater than %luMB limit)\n", + _p((v_end-dsi.v_start)>>20), nr_pages>>(20-PAGE_SHIFT)); goto error_out; } diff -r 17e9daeb2c50 tools/libxc/xc_load_elf.c --- a/tools/libxc/xc_load_elf.c Fri Jun 30 14:41:13 2006 +0100 +++ b/tools/libxc/xc_load_elf.c Fri Jun 30 15:02:28 2006 -0500 @@ -162,12 +162,12 @@ static int parseelfimage(const char *ima /* Initial guess for virt_base is 0 if it is not explicitly defined. */ p = strstr(guestinfo, "VIRT_BASE="); virt_base_defined = (p != NULL); - virt_base = virt_base_defined ? strtoul(p+10, &p, 0) : 0; + virt_base = virt_base_defined ? strtoull(p+10, &p, 0) : 0; /* Initial guess for elf_pa_off is virt_base if not explicitly defined. */ p = strstr(guestinfo, "ELF_PADDR_OFFSET="); elf_pa_off_defined = (p != NULL); - elf_pa_off = elf_pa_off_defined ? strtoul(p+17, &p, 0) : virt_base; + elf_pa_off = elf_pa_off_defined ? strtoull(p+17, &p, 0) : virt_base; if ( elf_pa_off_defined && !virt_base_defined ) goto bad_image; @@ -196,7 +196,7 @@ static int parseelfimage(const char *ima dsi->v_kernentry = ehdr->e_entry; if ( (p = strstr(guestinfo, "VIRT_ENTRY=")) != NULL ) - dsi->v_kernentry = strtoul(p+11, &p, 0); + dsi->v_kernentry = strtoull(p+11, &p, 0); if ( (kernstart > kernend) || (dsi->v_kernentry < kernstart) || diff -r 17e9daeb2c50 tools/libxc/xg_private.h --- a/tools/libxc/xg_private.h Fri Jun 30 14:41:13 2006 +0100 +++ b/tools/libxc/xg_private.h Fri Jun 30 15:02:28 2006 -0500 @@ -132,13 +132,13 @@ typedef unsigned long l4_pgentry_t; struct domain_setup_info { - unsigned long v_start; - unsigned long v_end; - unsigned long v_kernstart; - unsigned long v_kernend; - unsigned long v_kernentry; - - unsigned long elf_paddr_offset; + uint64_t v_start; + uint64_t v_end; + uint64_t v_kernstart; + uint64_t v_kernend; + uint64_t v_kernentry; + + uint64_t elf_paddr_offset; #define PAEKERN_no 0 #define PAEKERN_yes 1 -- Hollis Blanchard IBM Linux Technology Center _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel