[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-changelog] xc_private.h, xc_linux_build.c, Makefile:



ChangeSet 1.1665.4.1, 2005/06/06 09:44:32+01:00, cl349@xxxxxxxxxxxxxxxxxxxx

        xc_private.h, xc_linux_build.c, Makefile:
          Add support for loading ``bin'' format images, as used by ReactOS.
          Move image probing/parsing/loading code out of domain builder to allow
          multiple image formats without having to duplicate the domain building
          code.
        xc_load_elf.c, xc_load_bin.c:
          new file
        xc_vmx_build.c:
          Cleanup.
        Signed-Off-By: Ge van Geldorp <gvg@xxxxxxxxxxx>
        Signed-off-by: Christian Limpach <Christian.Limpach@xxxxxxxxxxxx>



 Makefile         |    2 
 xc_linux_build.c |  308 +++---------------------------------------------------
 xc_load_bin.c    |  299 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 xc_load_elf.c    |  310 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 xc_private.h     |   35 +++++-
 xc_vmx_build.c   |   20 +--
 6 files changed, 669 insertions(+), 305 deletions(-)


diff -Nru a/tools/libxc/Makefile b/tools/libxc/Makefile
--- a/tools/libxc/Makefile      2005-06-06 06:01:29 -04:00
+++ b/tools/libxc/Makefile      2005-06-06 06:01:29 -04:00
@@ -19,6 +19,8 @@
 SRCS     += xc_domain.c
 SRCS     += xc_evtchn.c
 SRCS     += xc_gnttab.c
+SRCS     += xc_load_bin.c
+SRCS     += xc_load_elf.c
 SRCS     += xc_linux_build.c
 SRCS     += xc_plan9_build.c
 SRCS     += xc_linux_restore.c
diff -Nru a/tools/libxc/xc_linux_build.c b/tools/libxc/xc_linux_build.c
--- a/tools/libxc/xc_linux_build.c      2005-06-06 06:01:29 -04:00
+++ b/tools/libxc/xc_linux_build.c      2005-06-06 06:01:29 -04:00
@@ -33,30 +33,19 @@
 #define round_pgup(_p)    (((_p)+(PAGE_SIZE-1))&PAGE_MASK)
 #define round_pgdown(_p)  ((_p)&PAGE_MASK)
 
-struct domain_setup_info
+static int probeimageformat(char *image,
+                            unsigned long image_size,
+                            struct load_funcs *load_funcs)
 {
-    unsigned long v_start;
-    unsigned long v_end;
-    unsigned long v_kernstart;
-    unsigned long v_kernend;
-    unsigned long v_kernentry;
-
-    unsigned int  load_symtab;
-    unsigned long symtab_addr;
-    unsigned long symtab_len;
-};
-
-static int
-parseelfimage(
-    char *elfbase, unsigned long elfsize, struct domain_setup_info *dsi);
-static int
-loadelfimage(
-    char *elfbase, int xch, u32 dom, unsigned long *parray,
-    struct domain_setup_info *dsi);
-static int
-loadelfsymtab(
-    char *elfbase, int xch, u32 dom, unsigned long *parray,
-    struct domain_setup_info *dsi);
+    if ( probe_elf(image, image_size, load_funcs) &&
+         probe_bin(image, image_size, load_funcs) )
+    {
+        ERROR( "Unrecognized image format" );
+        return -EINVAL;
+    }
+
+    return 0;
+}
 
 static int setup_guest(int xc_handle,
                          u32 dom,
@@ -94,6 +83,7 @@
     unsigned long ppt_alloc;
     unsigned long *physmap, *physmap_e, physmap_pfn;
 
+    struct load_funcs load_funcs;
     struct domain_setup_info dsi;
     unsigned long vinitrd_start;
     unsigned long vinitrd_end;
@@ -107,9 +97,13 @@
     unsigned long vpt_end;
     unsigned long v_end;
 
+    rc = probeimageformat(image, image_size, &load_funcs);
+    if ( rc != 0 )
+        goto error_out;
+
     memset(&dsi, 0, sizeof(struct domain_setup_info));
 
-    rc = parseelfimage(image, image_size, &dsi);
+    rc = (load_funcs.parseimage)(image, image_size, &dsi);
     if ( rc != 0 )
         goto error_out;
 
@@ -198,7 +192,8 @@
         goto error_out;
     }
 
-    loadelfimage(image, xc_handle, dom, page_array, &dsi);
+    (load_funcs.loadimage)(image, image_size, xc_handle, dom, page_array,
+                          &dsi);
 
     /* Load the initial ramdisk image. */
     if ( initrd_len != 0 )
@@ -592,267 +587,4 @@
         free(image);
 
     return -1;
-}
-
-static inline int is_loadable_phdr(Elf_Phdr *phdr)
-{
-    return ((phdr->p_type == PT_LOAD) &&
-            ((phdr->p_flags & (PF_W|PF_X)) != 0));
-}
-
-static int parseelfimage(char *elfbase, 
-                         unsigned long elfsize,
-                         struct domain_setup_info *dsi)
-{
-    Elf_Ehdr *ehdr = (Elf_Ehdr *)elfbase;
-    Elf_Phdr *phdr;
-    Elf_Shdr *shdr;
-    unsigned long kernstart = ~0UL, kernend=0UL;
-    char *shstrtab, *guestinfo=NULL, *p;
-    int h;
-
-    if ( !IS_ELF(*ehdr) )
-    {
-        ERROR("Kernel image does not have an ELF header.");
-        return -EINVAL;
-    }
-
-    if ( (ehdr->e_phoff + (ehdr->e_phnum * ehdr->e_phentsize)) > elfsize )
-    {
-        ERROR("ELF program headers extend beyond end of image.");
-        return -EINVAL;
-    }
-
-    if ( (ehdr->e_shoff + (ehdr->e_shnum * ehdr->e_shentsize)) > elfsize )
-    {
-        ERROR("ELF section headers extend beyond end of image.");
-        return -EINVAL;
-    }
-
-    /* Find the section-header strings table. */
-    if ( ehdr->e_shstrndx == SHN_UNDEF )
-    {
-        ERROR("ELF image has no section-header strings table (shstrtab).");
-        return -EINVAL;
-    }
-    shdr = (Elf_Shdr *)(elfbase + ehdr->e_shoff + 
-                        (ehdr->e_shstrndx*ehdr->e_shentsize));
-    shstrtab = elfbase + shdr->sh_offset;
-    
-    /* Find the special '__xen_guest' section and check its contents. */
-    for ( h = 0; h < ehdr->e_shnum; h++ )
-    {
-        shdr = (Elf_Shdr *)(elfbase + ehdr->e_shoff + (h*ehdr->e_shentsize));
-        if ( strcmp(&shstrtab[shdr->sh_name], "__xen_guest") != 0 )
-            continue;
-
-        guestinfo = elfbase + shdr->sh_offset;
-
-        if ( (strstr(guestinfo, "LOADER=generic") == NULL) &&
-             (strstr(guestinfo, "GUEST_OS=linux") == NULL) )
-        {
-            ERROR("Will only load images built for the generic loader "
-                  "or Linux images");
-            ERROR("Actually saw: '%s'", guestinfo);
-            return -EINVAL;
-        }
-
-        if ( (strstr(guestinfo, "XEN_VER=3.0") == NULL) )
-        {
-            ERROR("Will only load images built for Xen v3.0");
-            ERROR("Actually saw: '%s'", guestinfo);
-            return -EINVAL;
-        }
-
-        break;
-    }
-    if ( guestinfo == NULL )
-    {
-        ERROR("Not a Xen-ELF image: '__xen_guest' section not found.");
-        return -EINVAL;
-    }
-
-    for ( h = 0; h < ehdr->e_phnum; h++ ) 
-    {
-        phdr = (Elf_Phdr *)(elfbase + ehdr->e_phoff + (h*ehdr->e_phentsize));
-        if ( !is_loadable_phdr(phdr) )
-            continue;
-        if ( phdr->p_paddr < kernstart )
-            kernstart = phdr->p_paddr;
-        if ( (phdr->p_paddr + phdr->p_memsz) > kernend )
-            kernend = phdr->p_paddr + phdr->p_memsz;
-    }
-
-    if ( (kernstart > kernend) || 
-         (ehdr->e_entry < kernstart) || 
-         (ehdr->e_entry > kernend) )
-    {
-        ERROR("Malformed ELF image.");
-        return -EINVAL;
-    }
-
-    dsi->v_start = kernstart;
-    if ( (p = strstr(guestinfo, "VIRT_BASE=")) != NULL )
-        dsi->v_start = strtoul(p+10, &p, 0);
-
-    if ( (p = strstr(guestinfo, "BSD_SYMTAB")) != NULL )
-        dsi->load_symtab = 1;
-
-    dsi->v_kernstart = kernstart;
-    dsi->v_kernend   = kernend;
-    dsi->v_kernentry = ehdr->e_entry;
-    dsi->v_end       = dsi->v_kernend;
-
-    loadelfsymtab(elfbase, 0, 0, NULL, dsi);
-
-    return 0;
-}
-
-static int
-loadelfimage(
-    char *elfbase, int xch, u32 dom, unsigned long *parray,
-    struct domain_setup_info *dsi)
-{
-    Elf_Ehdr *ehdr = (Elf_Ehdr *)elfbase;
-    Elf_Phdr *phdr;
-    int h;
-
-    char         *va;
-    unsigned long pa, done, chunksz;
-
-    for ( h = 0; h < ehdr->e_phnum; h++ ) 
-    {
-        phdr = (Elf_Phdr *)(elfbase + ehdr->e_phoff + (h*ehdr->e_phentsize));
-        if ( !is_loadable_phdr(phdr) )
-            continue;
-        
-        for ( done = 0; done < phdr->p_filesz; done += chunksz )
-        {
-            pa = (phdr->p_paddr + done) - dsi->v_start;
-            va = xc_map_foreign_range(
-                xch, dom, PAGE_SIZE, PROT_WRITE, parray[pa>>PAGE_SHIFT]);
-            chunksz = phdr->p_filesz - done;
-            if ( chunksz > (PAGE_SIZE - (pa & (PAGE_SIZE-1))) )
-                chunksz = PAGE_SIZE - (pa & (PAGE_SIZE-1));
-            memcpy(va + (pa & (PAGE_SIZE-1)),
-                   elfbase + phdr->p_offset + done, chunksz);
-            munmap(va, PAGE_SIZE);
-        }
-
-        for ( ; done < phdr->p_memsz; done += chunksz )
-        {
-            pa = (phdr->p_paddr + done) - dsi->v_start;
-            va = xc_map_foreign_range(
-                xch, dom, PAGE_SIZE, PROT_WRITE, parray[pa>>PAGE_SHIFT]);
-            chunksz = phdr->p_memsz - done;
-            if ( chunksz > (PAGE_SIZE - (pa & (PAGE_SIZE-1))) )
-                chunksz = PAGE_SIZE - (pa & (PAGE_SIZE-1));

_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.