ia64/xen-unstable

changeset 10123:d9f63f9361c4

[LOADER] Another change to the elf_paddr_offset/virt_base logic.
This avoids using zero to indicate 'undefined'. Instead we use
an explicit boolean to indicate whether suitable defaults should
be used. As well as making the logic clearer (I believe) it also
avoids problems if anyone ever explicitly specifies virt_base
(and also elf_paddr_offset) as zero.

Signed-off-by: Keir Fraser <keir@xensource.com>
author kaf24@firebug.cl.cam.ac.uk
date Sun May 21 18:55:14 2006 +0100 (2006-05-21)
parents 4dcb93547710
children e99987843336
files tools/libxc/xc_load_elf.c xen/common/elf.c
line diff
     1.1 --- a/tools/libxc/xc_load_elf.c	Sun May 21 09:55:15 2006 +0100
     1.2 +++ b/tools/libxc/xc_load_elf.c	Sun May 21 18:55:14 2006 +0100
     1.3 @@ -58,10 +58,10 @@ static int parseelfimage(const char *ima
     1.4      Elf_Ehdr *ehdr = (Elf_Ehdr *)image;
     1.5      Elf_Phdr *phdr;
     1.6      Elf_Shdr *shdr;
     1.7 -    unsigned long kernstart = ~0UL, kernend=0UL, vaddr, virt_base;
     1.8 +    unsigned long kernstart = ~0UL, kernend=0UL, vaddr, virt_base, elf_pa_off;
     1.9      const char *shstrtab;
    1.10      char *guestinfo=NULL, *p;
    1.11 -    int h;
    1.12 +    int h, virt_base_defined, elf_pa_off_defined;
    1.13  
    1.14      if ( !IS_ELF(*ehdr) )
    1.15      {
    1.16 @@ -148,37 +148,35 @@ static int parseelfimage(const char *ima
    1.17  
    1.18      dsi->xen_guest_string = guestinfo;
    1.19  
    1.20 -    virt_base = 0;
    1.21 -    if ( (p = strstr(guestinfo, "VIRT_BASE=")) != NULL )
    1.22 -        virt_base = strtoul(p+10, &p, 0);
    1.23 -    dsi->elf_paddr_offset = virt_base;
    1.24 -    if ( (p = strstr(guestinfo, "ELF_PADDR_OFFSET=")) != NULL )
    1.25 -        dsi->elf_paddr_offset = strtoul(p+17, &p, 0);
    1.26 +    /* Initial guess for virt_base is 0 if it is not explicitly defined. */
    1.27 +    p = strstr(guestinfo, "VIRT_BASE=");
    1.28 +    virt_base_defined = (p != NULL);
    1.29 +    virt_base = virt_base_defined ? strtoul(p+10, &p, 0) : 0;
    1.30 +
    1.31 +    /* Initial guess for elf_pa_off is virt_base if not explicitly defined. */
    1.32 +    p = strstr(guestinfo, "ELF_PADDR_OFFSET=");
    1.33 +    elf_pa_off_defined = (p != NULL);
    1.34 +    elf_pa_off = elf_pa_off_defined ? strtoul(p+17, &p, 0) : virt_base;
    1.35  
    1.36      for ( h = 0; h < ehdr->e_phnum; h++ )
    1.37      {
    1.38          phdr = (Elf_Phdr *)(image + ehdr->e_phoff + (h*ehdr->e_phentsize));
    1.39          if ( !is_loadable_phdr(phdr) )
    1.40              continue;
    1.41 -        vaddr = phdr->p_paddr - dsi->elf_paddr_offset + virt_base;
    1.42 +        vaddr = phdr->p_paddr - elf_pa_off + virt_base;
    1.43          if ( vaddr < kernstart )
    1.44              kernstart = vaddr;
    1.45          if ( (vaddr + phdr->p_memsz) > kernend )
    1.46              kernend = vaddr + phdr->p_memsz;
    1.47      }
    1.48  
    1.49 -    dsi->v_start = virt_base;
    1.50 -    if ( dsi->v_start == 0 )
    1.51 -    {
    1.52 -        /*
    1.53 -         * Legacy compatibility and images with no __xen_guest section:
    1.54 -         * assume header addresses are virtual addresses, and that 
    1.55 -         * guest memory should be mapped starting at kernel load address.
    1.56 -         */
    1.57 -        dsi->v_start = kernstart;
    1.58 -        if ( dsi->elf_paddr_offset == 0 )
    1.59 -            dsi->elf_paddr_offset = dsi->v_start;
    1.60 -    }
    1.61 +    /*
    1.62 +     * Legacy compatibility and images with no __xen_guest section: assume
    1.63 +     * header addresses are virtual addresses, and that guest memory should be
    1.64 +     * mapped starting at kernel load address.
    1.65 +     */
    1.66 +    dsi->v_start          = virt_base_defined  ? virt_base  : kernstart;
    1.67 +    dsi->elf_paddr_offset = elf_pa_off_defined ? elf_pa_off : dsi->v_start;
    1.68  
    1.69      dsi->v_kernentry = ehdr->e_entry;
    1.70      if ( (p = strstr(guestinfo, "VIRT_ENTRY=")) != NULL )
     2.1 --- a/xen/common/elf.c	Sun May 21 09:55:15 2006 +0100
     2.2 +++ b/xen/common/elf.c	Sun May 21 18:55:14 2006 +0100
     2.3 @@ -23,10 +23,10 @@ int parseelfimage(struct domain_setup_in
     2.4      Elf_Ehdr *ehdr = (Elf_Ehdr *)dsi->image_addr;
     2.5      Elf_Phdr *phdr;
     2.6      Elf_Shdr *shdr;
     2.7 -    unsigned long kernstart = ~0UL, kernend=0UL, vaddr, virt_base;
     2.8 +    unsigned long kernstart = ~0UL, kernend=0UL, vaddr, virt_base, elf_pa_off;
     2.9      char *shstrtab, *guestinfo=NULL, *p;
    2.10      char *elfbase = (char *)dsi->image_addr;
    2.11 -    int h;
    2.12 +    int h, virt_base_defined, elf_pa_off_defined;
    2.13  
    2.14      if ( !elf_sanity_check(ehdr) )
    2.15          return -EINVAL;
    2.16 @@ -84,37 +84,35 @@ int parseelfimage(struct domain_setup_in
    2.17      if ( guestinfo == NULL )
    2.18          guestinfo = "";
    2.19  
    2.20 -    virt_base = 0;
    2.21 -    if ( (p = strstr(guestinfo, "VIRT_BASE=")) != NULL )
    2.22 -        virt_base = simple_strtoul(p+10, &p, 0);
    2.23 -    dsi->elf_paddr_offset = virt_base;
    2.24 -    if ( (p = strstr(guestinfo, "ELF_PADDR_OFFSET=")) != NULL )
    2.25 -        dsi->elf_paddr_offset = simple_strtoul(p+17, &p, 0);
    2.26 +    /* Initial guess for virt_base is 0 if it is not explicitly defined. */
    2.27 +    p = strstr(guestinfo, "VIRT_BASE=");
    2.28 +    virt_base_defined = (p != NULL);
    2.29 +    virt_base = virt_base_defined ? simple_strtoul(p+10, &p, 0) : 0;
    2.30 +
    2.31 +    /* Initial guess for elf_pa_off is virt_base if not explicitly defined. */
    2.32 +    p = strstr(guestinfo, "ELF_PADDR_OFFSET=");
    2.33 +    elf_pa_off_defined = (p != NULL);
    2.34 +    elf_pa_off = elf_pa_off_defined ? simple_strtoul(p+17, &p, 0) : virt_base;
    2.35  
    2.36      for ( h = 0; h < ehdr->e_phnum; h++ )
    2.37      {
    2.38          phdr = (Elf_Phdr *)(elfbase + ehdr->e_phoff + (h*ehdr->e_phentsize));
    2.39          if ( !is_loadable_phdr(phdr) )
    2.40              continue;
    2.41 -        vaddr = phdr->p_paddr - dsi->elf_paddr_offset + virt_base;
    2.42 +        vaddr = phdr->p_paddr - elf_pa_off + virt_base;
    2.43          if ( vaddr < kernstart )
    2.44              kernstart = vaddr;
    2.45          if ( (vaddr + phdr->p_memsz) > kernend )
    2.46              kernend = vaddr + phdr->p_memsz;
    2.47      }
    2.48  
    2.49 -    dsi->v_start = virt_base;
    2.50 -    if ( dsi->v_start == 0 )
    2.51 -    {
    2.52 -        /*
    2.53 -         * Legacy compatibility and images with no __xen_guest section:
    2.54 -         * assume header addresses are virtual addresses, and that 
    2.55 -         * guest memory should be mapped starting at kernel load address.
    2.56 -         */
    2.57 -        dsi->v_start = kernstart;
    2.58 -        if ( dsi->elf_paddr_offset == 0 )
    2.59 -            dsi->elf_paddr_offset = dsi->v_start;
    2.60 -    }
    2.61 +    /*
    2.62 +     * Legacy compatibility and images with no __xen_guest section: assume
    2.63 +     * header addresses are virtual addresses, and that guest memory should be
    2.64 +     * mapped starting at kernel load address.
    2.65 +     */
    2.66 +    dsi->v_start          = virt_base_defined  ? virt_base  : kernstart;
    2.67 +    dsi->elf_paddr_offset = elf_pa_off_defined ? elf_pa_off : dsi->v_start;
    2.68  
    2.69      dsi->v_kernentry = ehdr->e_entry;
    2.70      if ( (p = strstr(guestinfo, "VIRT_ENTRY=")) != NULL )