ia64/xen-unstable

changeset 9637:86db4688d514

Additional sanity / compatability checks during guest build.

Signed-off-by: Steven Hand <steven@xensource.com>
author smh22@firebug.cl.cam.ac.uk
date Fri Apr 07 15:58:00 2006 +0100 (2006-04-07)
parents 3b0d07af46cb
children 05db1d61e031
files tools/libxc/xc_linux_build.c tools/libxc/xc_load_elf.c
line diff
     1.1 --- a/tools/libxc/xc_linux_build.c	Fri Apr 07 14:27:46 2006 +0100
     1.2 +++ b/tools/libxc/xc_linux_build.c	Fri Apr 07 15:58:00 2006 +0100
     1.3 @@ -110,10 +110,10 @@ static int parse_features(
     1.4  
     1.5          if ( i == XENFEAT_NR_SUBMAPS*32 )
     1.6          {
     1.7 -            ERROR("Unknown feature \"%.*s\".\n", (int)(p-feats), feats);
     1.8 +            ERROR("Unknown feature \"%.*s\".", (int)(p-feats), feats);
     1.9              if ( req )
    1.10              {
    1.11 -                ERROR("Kernel requires an unknown hypervisor feature.\n");
    1.12 +                ERROR("Kernel requires an unknown hypervisor feature.");
    1.13                  return -EINVAL;
    1.14              }
    1.15          }
    1.16 @@ -579,6 +579,31 @@ static int setup_guest(int xc_handle,
    1.17      return -1;
    1.18  }
    1.19  #else /* x86 */
    1.20 +
    1.21 +/* Check if the platform supports the guest kernel format */
    1.22 +static int compat_check(int xc_handle, struct domain_setup_info *dsi)
    1.23 +{
    1.24 +    xen_capabilities_info_t xen_caps = "";
    1.25 +
    1.26 +    if (xc_version(xc_handle, XENVER_capabilities, &xen_caps) != 0) {
    1.27 +        ERROR("Cannot determine host capabilities.");
    1.28 +        return 0;
    1.29 +    }
    1.30 +
    1.31 +    if (strstr(xen_caps, "xen-3.0-x86_32p")) {
    1.32 +        if (!dsi->pae_kernel) {
    1.33 +            ERROR("Non PAE-kernel on PAE host.");
    1.34 +            return 0;
    1.35 +        }
    1.36 +    } else if (dsi->pae_kernel) {
    1.37 +        ERROR("PAE-kernel on non-PAE host.");
    1.38 +        return 0;
    1.39 +    }
    1.40 +
    1.41 +    return 1;
    1.42 +}
    1.43 +
    1.44 +
    1.45  static int setup_guest(int xc_handle,
    1.46                         uint32_t dom,
    1.47                         const char *image, unsigned long image_size,
    1.48 @@ -635,10 +660,13 @@ static int setup_guest(int xc_handle,
    1.49  
    1.50      if ( (dsi.v_start & (PAGE_SIZE-1)) != 0 )
    1.51      {
    1.52 -        PERROR("Guest OS must load to a page boundary.\n");
    1.53 +        PERROR("Guest OS must load to a page boundary.");
    1.54          goto error_out;
    1.55      }
    1.56  
    1.57 +    if (!compat_check(xc_handle, &dsi))
    1.58 +        goto error_out;
    1.59 +
    1.60      /* Parse and validate kernel features. */
    1.61      p = strstr(dsi.xen_guest_string, "FEATURES=");
    1.62      if ( p != NULL )
    1.63 @@ -647,7 +675,7 @@ static int setup_guest(int xc_handle,
    1.64                               supported_features,
    1.65                               required_features) )
    1.66          {
    1.67 -            ERROR("Failed to parse guest kernel features.\n");
    1.68 +            ERROR("Failed to parse guest kernel features.");
    1.69              goto error_out;
    1.70          }
    1.71  
    1.72 @@ -659,7 +687,7 @@ static int setup_guest(int xc_handle,
    1.73      {
    1.74          if ( (supported_features[i]&required_features[i]) != required_features[i] )
    1.75          {
    1.76 -            ERROR("Guest kernel does not support a required feature.\n");
    1.77 +            ERROR("Guest kernel does not support a required feature.");
    1.78              goto error_out;
    1.79          }
    1.80      }
     2.1 --- a/tools/libxc/xc_load_elf.c	Fri Apr 07 14:27:46 2006 +0100
     2.2 +++ b/tools/libxc/xc_load_elf.c	Fri Apr 07 15:58:00 2006 +0100
     2.3 @@ -69,6 +69,21 @@ static int parseelfimage(const char *ima
     2.4          return -EINVAL;
     2.5      }
     2.6  
     2.7 +    if (
     2.8 +#if defined(__i386__)
     2.9 +        (ehdr->e_ident[EI_CLASS] != ELFCLASS32) ||
    2.10 +        (ehdr->e_machine != EM_386) ||
    2.11 +#elif defined(__x86_64__)
    2.12 +        (ehdr->e_ident[EI_CLASS] != ELFCLASS64) ||
    2.13 +        (ehdr->e_machine != EM_X86_64) ||
    2.14 +#endif
    2.15 +        (ehdr->e_ident[EI_DATA] != ELFDATA2LSB) ||
    2.16 +        (ehdr->e_type != ET_EXEC) )
    2.17 +    {
    2.18 +        ERROR("Kernel not a Xen-compatible Elf image.");
    2.19 +        return -EINVAL;
    2.20 +    }
    2.21 +
    2.22      if ( (ehdr->e_phoff + (ehdr->e_phnum * ehdr->e_phentsize)) > elfsize )
    2.23      {
    2.24          ERROR("ELF program headers extend beyond end of image.");