ia64/xen-unstable

changeset 15800:104aba61893e

Some minor cleanup of xc_core.c.
Signed-off-by: Isaku Yamahata <yamahata@valinux.co.jp>
author kfraser@localhost.localdomain
date Thu Aug 30 14:57:24 2007 +0100 (2007-08-30)
parents 1c19a3430ab1
children df860912f348
files tools/libxc/xc_core.c
line diff
     1.1 --- a/tools/libxc/xc_core.c	Thu Aug 30 11:01:39 2007 +0100
     1.2 +++ b/tools/libxc/xc_core.c	Thu Aug 30 14:57:24 2007 +0100
     1.3 @@ -231,6 +231,35 @@ xc_core_shdr_set(Elf64_Shdr *shdr,
     1.4      return 0;
     1.5  }
     1.6  
     1.7 +static void
     1.8 +xc_core_ehdr_init(Elf64_Ehdr *ehdr)
     1.9 +{
    1.10 +    memset(ehdr, 0, sizeof(*ehdr));
    1.11 +    ehdr->e_ident[EI_MAG0] = ELFMAG0;
    1.12 +    ehdr->e_ident[EI_MAG1] = ELFMAG1;
    1.13 +    ehdr->e_ident[EI_MAG2] = ELFMAG2;
    1.14 +    ehdr->e_ident[EI_MAG3] = ELFMAG3;
    1.15 +    ehdr->e_ident[EI_CLASS] = ELFCLASS64;
    1.16 +    ehdr->e_ident[EI_DATA] = ELF_ARCH_DATA;
    1.17 +    ehdr->e_ident[EI_VERSION] = EV_CURRENT;
    1.18 +    ehdr->e_ident[EI_OSABI] = ELFOSABI_SYSV;
    1.19 +    ehdr->e_ident[EI_ABIVERSION] = EV_CURRENT;
    1.20 +
    1.21 +    ehdr->e_type = ET_CORE;
    1.22 +    ehdr->e_machine = ELF_ARCH_MACHINE;
    1.23 +    ehdr->e_version = EV_CURRENT;
    1.24 +    ehdr->e_entry = 0;
    1.25 +    ehdr->e_phoff = 0;
    1.26 +    ehdr->e_shoff = sizeof(*ehdr);
    1.27 +    ehdr->e_flags = ELF_CORE_EFLAGS;
    1.28 +    ehdr->e_ehsize = sizeof(*ehdr);
    1.29 +    ehdr->e_phentsize = sizeof(Elf64_Phdr);
    1.30 +    ehdr->e_phnum = 0;
    1.31 +    ehdr->e_shentsize = sizeof(Elf64_Shdr);
    1.32 +    /* ehdr->e_shnum and ehdr->e_shstrndx aren't known here yet.
    1.33 +     * fill it later */
    1.34 +}
    1.35 +
    1.36  static int
    1.37  elfnote_fill_xen_version(int xc_handle,
    1.38                           struct xen_dumpcore_elfnote_xen_version_desc
    1.39 @@ -277,12 +306,100 @@ elfnote_fill_xen_version(int xc_handle,
    1.40      return 0;
    1.41  }
    1.42  
    1.43 -static int
    1.44 +static void
    1.45  elfnote_fill_format_version(struct xen_dumpcore_elfnote_format_version_desc
    1.46                              *format_version)
    1.47  {
    1.48      format_version->version = XEN_DUMPCORE_FORMAT_VERSION_CURRENT;
    1.49 -    return 0;
    1.50 +}
    1.51 +
    1.52 +static void
    1.53 +elfnote_init(struct elfnote *elfnote)
    1.54 +{
    1.55 +    /* elf note section */
    1.56 +    memset(elfnote, 0, sizeof(*elfnote));
    1.57 +    elfnote->namesz = strlen(XEN_DUMPCORE_ELFNOTE_NAME) + 1;
    1.58 +    strncpy(elfnote->name, XEN_DUMPCORE_ELFNOTE_NAME, sizeof(elfnote->name));
    1.59 +}
    1.60 +
    1.61 +static int
    1.62 +elfnote_dump_none(void *args, dumpcore_rtn_t dump_rtn)
    1.63 +{
    1.64 +    int sts;
    1.65 +    struct elfnote elfnote;
    1.66 +    struct xen_dumpcore_elfnote_none_desc none;
    1.67 +
    1.68 +    elfnote_init(&elfnote);
    1.69 +    memset(&none, 0, sizeof(none));
    1.70 +
    1.71 +    elfnote.descsz = sizeof(none);
    1.72 +    elfnote.type = XEN_ELFNOTE_DUMPCORE_NONE;
    1.73 +    sts = dump_rtn(args, (char*)&elfnote, sizeof(elfnote));
    1.74 +    if ( sts != 0 )
    1.75 +        return sts;
    1.76 +    return dump_rtn(args, (char*)&none, sizeof(none));
    1.77 +}
    1.78 +
    1.79 +static int
    1.80 +elfnote_dump_core_header(
    1.81 +    void *args, dumpcore_rtn_t dump_rtn, const xc_dominfo_t *info,
    1.82 +    int nr_vcpus, unsigned long nr_pages)
    1.83 +{
    1.84 +    int sts;
    1.85 +    struct elfnote elfnote;
    1.86 +    struct xen_dumpcore_elfnote_header_desc header;
    1.87 +    
    1.88 +    elfnote_init(&elfnote);
    1.89 +    memset(&header, 0, sizeof(header));
    1.90 +    
    1.91 +    elfnote.descsz = sizeof(header);
    1.92 +    elfnote.type = XEN_ELFNOTE_DUMPCORE_HEADER;
    1.93 +    header.xch_magic = info->hvm ? XC_CORE_MAGIC_HVM : XC_CORE_MAGIC;
    1.94 +    header.xch_nr_vcpus = nr_vcpus;
    1.95 +    header.xch_nr_pages = nr_pages;
    1.96 +    header.xch_page_size = PAGE_SIZE;
    1.97 +    sts = dump_rtn(args, (char*)&elfnote, sizeof(elfnote));
    1.98 +    if ( sts != 0 )
    1.99 +        return sts;
   1.100 +    return dump_rtn(args, (char*)&header, sizeof(header));
   1.101 +}
   1.102 +
   1.103 +static int
   1.104 +elfnote_dump_xen_version(void *args, dumpcore_rtn_t dump_rtn, int xc_handle)
   1.105 +{
   1.106 +    int sts;
   1.107 +    struct elfnote elfnote;
   1.108 +    struct xen_dumpcore_elfnote_xen_version_desc xen_version;
   1.109 +
   1.110 +    elfnote_init(&elfnote);
   1.111 +    memset(&xen_version, 0, sizeof(xen_version));
   1.112 +
   1.113 +    elfnote.descsz = sizeof(xen_version);
   1.114 +    elfnote.type = XEN_ELFNOTE_DUMPCORE_XEN_VERSION;
   1.115 +    elfnote_fill_xen_version(xc_handle, &xen_version);
   1.116 +    sts = dump_rtn(args, (char*)&elfnote, sizeof(elfnote));
   1.117 +    if ( sts != 0 )
   1.118 +        return sts;
   1.119 +    return dump_rtn(args, (char*)&xen_version, sizeof(xen_version));
   1.120 +}
   1.121 +
   1.122 +static int
   1.123 +elfnote_dump_format_version(void *args, dumpcore_rtn_t dump_rtn)
   1.124 +{
   1.125 +    int sts;
   1.126 +    struct elfnote elfnote;
   1.127 +    struct xen_dumpcore_elfnote_format_version_desc format_version;
   1.128 +
   1.129 +    elfnote_init(&elfnote);
   1.130 +    memset(&format_version, 0, sizeof(format_version));
   1.131 +    
   1.132 +    elfnote.descsz = sizeof(format_version);
   1.133 +    elfnote.type = XEN_ELFNOTE_DUMPCORE_FORMAT_VERSION;
   1.134 +    elfnote_fill_format_version(&format_version);
   1.135 +    sts = dump_rtn(args, (char*)&elfnote, sizeof(elfnote));
   1.136 +    if ( sts != 0 )
   1.137 +        return sts;
   1.138 +    return dump_rtn(args, (char*)&format_version, sizeof(format_version));
   1.139  }
   1.140  
   1.141  int
   1.142 @@ -327,13 +444,6 @@ xc_domain_dumpcore_via_callback(int xc_h
   1.143      struct xc_core_section_headers *sheaders = NULL;
   1.144      Elf64_Shdr *shdr;
   1.145  
   1.146 -    /* elf notes */
   1.147 -    struct elfnote elfnote;
   1.148 -    struct xen_dumpcore_elfnote_none_desc none;
   1.149 -    struct xen_dumpcore_elfnote_header_desc header;
   1.150 -    struct xen_dumpcore_elfnote_xen_version_desc xen_version;
   1.151 -    struct xen_dumpcore_elfnote_format_version_desc format_version;
   1.152 -
   1.153      xc_core_arch_context_init(&arch_ctxt);
   1.154      if ( (dump_mem_start = malloc(DUMP_INCREMENT*PAGE_SIZE)) == NULL )
   1.155      {
   1.156 @@ -451,29 +561,8 @@ xc_domain_dumpcore_via_callback(int xc_h
   1.157          nr_pages = j;
   1.158      }
   1.159  
   1.160 -    memset(&ehdr, 0, sizeof(ehdr));
   1.161 -    ehdr.e_ident[EI_MAG0] = ELFMAG0;
   1.162 -    ehdr.e_ident[EI_MAG1] = ELFMAG1;
   1.163 -    ehdr.e_ident[EI_MAG2] = ELFMAG2;
   1.164 -    ehdr.e_ident[EI_MAG3] = ELFMAG3;
   1.165 -    ehdr.e_ident[EI_CLASS] = ELFCLASS64;
   1.166 -    ehdr.e_ident[EI_DATA] = ELF_ARCH_DATA;
   1.167 -    ehdr.e_ident[EI_VERSION] = EV_CURRENT;
   1.168 -    ehdr.e_ident[EI_OSABI] = ELFOSABI_SYSV;
   1.169 -    ehdr.e_ident[EI_ABIVERSION] = EV_CURRENT;
   1.170 -
   1.171 -    ehdr.e_type = ET_CORE;
   1.172 -    ehdr.e_machine = ELF_ARCH_MACHINE;
   1.173 -    ehdr.e_version = EV_CURRENT;
   1.174 -    ehdr.e_entry = 0;
   1.175 -    ehdr.e_phoff = 0;
   1.176 -    ehdr.e_shoff = sizeof(ehdr);
   1.177 -    ehdr.e_flags = ELF_CORE_EFLAGS;
   1.178 -    ehdr.e_ehsize = sizeof(ehdr);
   1.179 -    ehdr.e_phentsize = sizeof(Elf64_Phdr);
   1.180 -    ehdr.e_phnum = 0;
   1.181 -    ehdr.e_shentsize = sizeof(Elf64_Shdr);
   1.182      /* ehdr.e_shnum and ehdr.e_shstrndx aren't known here yet. fill it later*/
   1.183 +    xc_core_ehdr_init(&ehdr);
   1.184  
   1.185      /* create section header */
   1.186      strtab = xc_core_strtab_init();
   1.187 @@ -549,7 +638,7 @@ xc_domain_dumpcore_via_callback(int xc_h
   1.188      /* arch context */
   1.189      sts = xc_core_arch_context_get_shdr(&arch_ctxt, sheaders, strtab,
   1.190                                          &filesz, offset);
   1.191 -    if ( sts != 0)
   1.192 +    if ( sts != 0 )
   1.193          goto out;
   1.194      offset += filesz;
   1.195  
   1.196 @@ -645,54 +734,23 @@ xc_domain_dumpcore_via_callback(int xc_h
   1.197      if ( sts != 0 )
   1.198          goto out;
   1.199  
   1.200 -    /* elf note section */
   1.201 -    memset(&elfnote, 0, sizeof(elfnote));
   1.202 -    elfnote.namesz = strlen(XEN_DUMPCORE_ELFNOTE_NAME) + 1;
   1.203 -    strncpy(elfnote.name, XEN_DUMPCORE_ELFNOTE_NAME, sizeof(elfnote.name));
   1.204 -
   1.205 -    /* elf note section:xen core header */
   1.206 -    elfnote.descsz = sizeof(none);
   1.207 -    elfnote.type = XEN_ELFNOTE_DUMPCORE_NONE;
   1.208 -    sts = dump_rtn(args, (char*)&elfnote, sizeof(elfnote));
   1.209 -    if ( sts != 0 )
   1.210 -        goto out;
   1.211 -    sts = dump_rtn(args, (char*)&none, sizeof(none));
   1.212 -    if ( sts != 0 )
   1.213 +    /* elf note section: xen core header */
   1.214 +    sts = elfnote_dump_none(args, dump_rtn);
   1.215 +    if ( sts != 0)
   1.216          goto out;
   1.217  
   1.218 -    /* elf note section:xen core header */
   1.219 -    elfnote.descsz = sizeof(header);
   1.220 -    elfnote.type = XEN_ELFNOTE_DUMPCORE_HEADER;
   1.221 -    header.xch_magic = info.hvm ? XC_CORE_MAGIC_HVM : XC_CORE_MAGIC;
   1.222 -    header.xch_nr_vcpus = nr_vcpus;
   1.223 -    header.xch_nr_pages = nr_pages;
   1.224 -    header.xch_page_size = PAGE_SIZE;
   1.225 -    sts = dump_rtn(args, (char*)&elfnote, sizeof(elfnote));
   1.226 -    if ( sts != 0 )
   1.227 -        goto out;
   1.228 -    sts = dump_rtn(args, (char*)&header, sizeof(header));
   1.229 +    /* elf note section: xen core header */
   1.230 +    sts = elfnote_dump_core_header(args, dump_rtn, &info, nr_vcpus, nr_pages);
   1.231      if ( sts != 0 )
   1.232          goto out;
   1.233  
   1.234      /* elf note section: xen version */
   1.235 -    elfnote.descsz = sizeof(xen_version);
   1.236 -    elfnote.type = XEN_ELFNOTE_DUMPCORE_XEN_VERSION;
   1.237 -    elfnote_fill_xen_version(xc_handle, &xen_version);
   1.238 -    sts = dump_rtn(args, (char*)&elfnote, sizeof(elfnote));
   1.239 -    if ( sts != 0 )
   1.240 -        goto out;
   1.241 -    sts = dump_rtn(args, (char*)&xen_version, sizeof(xen_version));
   1.242 +    sts = elfnote_dump_xen_version(args, dump_rtn, xc_handle);
   1.243      if ( sts != 0 )
   1.244          goto out;
   1.245  
   1.246      /* elf note section: format version */
   1.247 -    elfnote.descsz = sizeof(format_version);
   1.248 -    elfnote.type = XEN_ELFNOTE_DUMPCORE_FORMAT_VERSION;
   1.249 -    elfnote_fill_format_version(&format_version);
   1.250 -    sts = dump_rtn(args, (char*)&elfnote, sizeof(elfnote));
   1.251 -    if ( sts != 0 )
   1.252 -        goto out;
   1.253 -    sts = dump_rtn(args, (char*)&format_version, sizeof(format_version));
   1.254 +    sts = elfnote_dump_format_version(args, dump_rtn);
   1.255      if ( sts != 0 )
   1.256          goto out;
   1.257