ia64/xen-unstable

changeset 14287:e68ee3665cba

dump-core: always use elfclass64 format to support x86_32pae.
Without this patch xen dump-core format can't handle over 4GB case.

Signed-off-by: Isaku Yamahata <yamahata@valinux.co.jp>
author kfraser@localhost.localdomain
date Wed Mar 07 10:53:34 2007 +0000 (2007-03-07)
parents 9be942ec0247
children dad3d143c3b0
files docs/misc/dump-core-format.txt tools/libxc/xc_core.c tools/libxc/xc_core.h tools/libxc/xc_core_ia64.c tools/libxc/xc_core_ia64.h tools/libxc/xc_core_x86.h tools/libxc/xc_ptrace_core.c
line diff
     1.1 --- a/docs/misc/dump-core-format.txt	Wed Mar 07 10:49:20 2007 +0000
     1.2 +++ b/docs/misc/dump-core-format.txt	Wed Mar 07 10:53:34 2007 +0000
     1.3 @@ -26,11 +26,12 @@ For xen related structure, please see th
     1.4  Elf header
     1.5  ----------
     1.6  The elf header members are set as follows
     1.7 +        e_ident[EI_CLASS] = ELFCLASS64 = 2
     1.8          e_ident[EI_OSABI] = ELFOSABI_SYSV = 0
     1.9          e_type = ET_CORE = 4
    1.10 -e_ident[EI_CLASS], e_ident[EI_DATA] and e_flags are set according
    1.11 -to an architecture which a file is created. Other members are set as usual.
    1.12 -
    1.13 +ELFCLASS64 is always used independent of architecture.
    1.14 +e_ident[EI_DATA] and e_flags are set according to the dumping system's
    1.15 +architecture. Other members are set as usual.
    1.16  
    1.17  Sections
    1.18  --------
    1.19 @@ -221,5 +222,10 @@ format_version descriptor
    1.20  
    1.21  Format version history
    1.22  ----------------------
    1.23 -The currently only (major, minor) = (0, 1) is used.
    1.24 +Currently only (major, minor) = (0, 1) is used.
    1.25  [When the format is changed, it would be described here.]
    1.26 +
    1.27 +(0, 1) update
    1.28 +- EI_CLASS member of elf header was changed to ELFCLASS64 independent of
    1.29 +  architecture. This is mainly for x86_32pae.
    1.30 +  The format version isn't bumped because analysis tools can distinguish it.
     2.1 --- a/tools/libxc/xc_core.c	Wed Mar 07 10:49:20 2007 +0000
     2.2 +++ b/tools/libxc/xc_core.c	Wed Mar 07 10:53:34 2007 +0000
     2.3 @@ -153,7 +153,7 @@ struct xc_core_section_headers {
     2.4      uint16_t    num;
     2.5      uint16_t    num_max;
     2.6  
     2.7 -    Elf_Shdr   *shdrs;
     2.8 +    Elf64_Shdr  *shdrs;
     2.9  };
    2.10  #define SHDR_INIT       16
    2.11  #define SHDR_INC        4
    2.12 @@ -184,14 +184,14 @@ xc_core_shdr_free(struct xc_core_section
    2.13      free(sheaders);
    2.14  }
    2.15  
    2.16 -Elf_Shdr*
    2.17 +Elf64_Shdr*
    2.18  xc_core_shdr_get(struct xc_core_section_headers *sheaders)
    2.19  {
    2.20 -    Elf_Shdr *shdr;
    2.21 +    Elf64_Shdr *shdr;
    2.22  
    2.23      if ( sheaders->num == sheaders->num_max )
    2.24      {
    2.25 -        Elf_Shdr *shdrs;
    2.26 +        Elf64_Shdr *shdrs;
    2.27          if ( sheaders->num_max + SHDR_INC < sheaders->num_max )
    2.28          {
    2.29              errno = E2BIG;
    2.30 @@ -212,7 +212,7 @@ xc_core_shdr_get(struct xc_core_section_
    2.31  }
    2.32  
    2.33  int
    2.34 -xc_core_shdr_set(Elf_Shdr *shdr,
    2.35 +xc_core_shdr_set(Elf64_Shdr *shdr,
    2.36                   struct xc_core_strtab *strtab,
    2.37                   const char *name, uint32_t type,
    2.38                   uint64_t offset, uint64_t size,
    2.39 @@ -317,15 +317,15 @@ xc_domain_dumpcore_via_callback(int xc_h
    2.40  
    2.41      uint64_t *pfn_array = NULL;
    2.42  
    2.43 -    Elf_Ehdr ehdr;
    2.44 -    unsigned long filesz;
    2.45 -    unsigned long offset;
    2.46 -    unsigned long fixup;
    2.47 +    Elf64_Ehdr ehdr;
    2.48 +    uint64_t filesz;
    2.49 +    uint64_t offset;
    2.50 +    uint64_t fixup;
    2.51  
    2.52      struct xc_core_strtab *strtab = NULL;
    2.53      uint16_t strtab_idx;
    2.54      struct xc_core_section_headers *sheaders = NULL;
    2.55 -    Elf_Shdr *shdr;
    2.56 +    Elf64_Shdr *shdr;
    2.57  
    2.58      /* elf notes */
    2.59      struct elfnote elfnote;
    2.60 @@ -460,7 +460,7 @@ xc_domain_dumpcore_via_callback(int xc_h
    2.61      ehdr.e_ident[EI_MAG1] = ELFMAG1;
    2.62      ehdr.e_ident[EI_MAG2] = ELFMAG2;
    2.63      ehdr.e_ident[EI_MAG3] = ELFMAG3;
    2.64 -    ehdr.e_ident[EI_CLASS] = ELFCLASS;
    2.65 +    ehdr.e_ident[EI_CLASS] = ELFCLASS64;
    2.66      ehdr.e_ident[EI_DATA] = ELF_ARCH_DATA;
    2.67      ehdr.e_ident[EI_VERSION] = EV_CURRENT;
    2.68      ehdr.e_ident[EI_OSABI] = ELFOSABI_SYSV;
    2.69 @@ -474,9 +474,9 @@ xc_domain_dumpcore_via_callback(int xc_h
    2.70      ehdr.e_shoff = sizeof(ehdr);
    2.71      ehdr.e_flags = ELF_CORE_EFLAGS;
    2.72      ehdr.e_ehsize = sizeof(ehdr);
    2.73 -    ehdr.e_phentsize = sizeof(Elf_Phdr);
    2.74 +    ehdr.e_phentsize = sizeof(Elf64_Phdr);
    2.75      ehdr.e_phnum = 0;
    2.76 -    ehdr.e_shentsize = sizeof(Elf_Shdr);
    2.77 +    ehdr.e_shentsize = sizeof(Elf64_Shdr);
    2.78      /* ehdr.e_shnum and ehdr.e_shstrndx aren't known here yet. fill it later*/
    2.79  
    2.80      /* create section header */
     3.1 --- a/tools/libxc/xc_core.h	Wed Mar 07 10:49:20 2007 +0000
     3.2 +++ b/tools/libxc/xc_core.h	Wed Mar 07 10:53:34 2007 +0000
     3.3 @@ -116,10 +116,10 @@ struct xen_dumpcore_p2m {
     3.4  struct xc_core_strtab;
     3.5  struct xc_core_section_headers;
     3.6  
     3.7 -Elf_Shdr*
     3.8 +Elf64_Shdr*
     3.9  xc_core_shdr_get(struct xc_core_section_headers *sheaders);
    3.10  int
    3.11 -xc_core_shdr_set(Elf_Shdr *shdr,
    3.12 +xc_core_shdr_set(Elf64_Shdr *shdr,
    3.13                   struct xc_core_strtab *strtab,
    3.14                   const char *name, uint32_t type,
    3.15                   uint64_t offset, uint64_t size,
     4.1 --- a/tools/libxc/xc_core_ia64.c	Wed Mar 07 10:49:20 2007 +0000
     4.2 +++ b/tools/libxc/xc_core_ia64.c	Wed Mar 07 10:53:34 2007 +0000
     4.3 @@ -266,10 +266,10 @@ int
     4.4  xc_core_arch_context_get_shdr(struct xc_core_arch_context *arch_ctxt, 
     4.5                                struct xc_core_section_headers *sheaders,
     4.6                                struct xc_core_strtab *strtab,
     4.7 -                              unsigned long *filesz, unsigned long offset)
     4.8 +                              uint64_t *filesz, uint64_t offset)
     4.9  {
    4.10      int sts = -1;
    4.11 -    Elf_Shdr *shdr;
    4.12 +    Elf64_Shdr *shdr;
    4.13  
    4.14      /* mmapped priv regs */
    4.15      shdr = xc_core_shdr_get(sheaders);
     5.1 --- a/tools/libxc/xc_core_ia64.h	Wed Mar 07 10:49:20 2007 +0000
     5.2 +++ b/tools/libxc/xc_core_ia64.h	Wed Mar 07 10:53:34 2007 +0000
     5.3 @@ -42,7 +42,7 @@ int
     5.4  xc_core_arch_context_get_shdr(struct xc_core_arch_context* arch_ctxt, 
     5.5                                struct xc_core_section_headers *sheaders,
     5.6                                struct xc_core_strtab *strtab,
     5.7 -                              unsigned long *filesz, unsigned long offset);
     5.8 +                              uint64_t *filesz, uint64_t offset);
     5.9  int
    5.10  xc_core_arch_context_dump(struct xc_core_arch_context* arch_ctxt,
    5.11                            void* args, dumpcore_rtn_t dump_rtn);
     6.1 --- a/tools/libxc/xc_core_x86.h	Wed Mar 07 10:49:20 2007 +0000
     6.2 +++ b/tools/libxc/xc_core_x86.h	Wed Mar 07 10:53:34 2007 +0000
     6.3 @@ -45,7 +45,7 @@ static inline int
     6.4  xc_core_arch_context_get_shdr(struct xc_core_arch_context *arch_ctxt, 
     6.5                                struct xc_core_section_headers *sheaders,
     6.6                                struct xc_core_strtab *strtab,
     6.7 -                              unsigned long *filesz, unsigned long offset)
     6.8 +                              uint64_t *filesz, uint64_t offset)
     6.9  {
    6.10      *filesz = 0;
    6.11      return 0;
     7.1 --- a/tools/libxc/xc_ptrace_core.c	Wed Mar 07 10:49:20 2007 +0000
     7.2 +++ b/tools/libxc/xc_ptrace_core.c	Wed Mar 07 10:53:34 2007 +0000
     7.3 @@ -192,7 +192,7 @@ pread_exact(int fd, void* buffer, size_t
     7.4  struct elf_core
     7.5  {
     7.6      int         domfd;
     7.7 -    Elf_Ehdr    ehdr;
     7.8 +    Elf64_Ehdr  ehdr;
     7.9  
    7.10      char*       shdr;
    7.11      
    7.12 @@ -242,6 +242,8 @@ elf_core_init(struct elf_core* ecore, in
    7.13      /* check elf header */
    7.14      if (!IS_ELF(ecore->ehdr) || ecore->ehdr.e_type != ET_CORE)
    7.15          goto out;
    7.16 +    if (ecore->ehdr.e_ident[EI_CLASS] != ELFCLASS64)
    7.17 +        goto out;
    7.18      /* check elf header more: EI_DATA, EI_VERSION, e_machine... */
    7.19  
    7.20      /* read section headers */
    7.21 @@ -294,7 +296,7 @@ elf_core_search_note(struct elf_core* ec
    7.22  }
    7.23  
    7.24  static int
    7.25 -elf_core_alloc_read_sec(struct elf_core* ecore, const Elf_Shdr* shdr,
    7.26 +elf_core_alloc_read_sec(struct elf_core* ecore, const Elf64_Shdr* shdr,
    7.27                          char** buf)
    7.28  {
    7.29      int ret;
    7.30 @@ -309,19 +311,19 @@ elf_core_alloc_read_sec(struct elf_core*
    7.31      return ret;
    7.32  }
    7.33  
    7.34 -static Elf_Shdr*
    7.35 +static Elf64_Shdr*
    7.36  elf_core_shdr_by_index(struct elf_core* ecore, uint16_t index)
    7.37  {
    7.38      if (index >= ecore->ehdr.e_shnum)
    7.39          return NULL;
    7.40 -    return (Elf_Shdr*)(ecore->shdr + ecore->ehdr.e_shentsize * index);
    7.41 +    return (Elf64_Shdr*)(ecore->shdr + ecore->ehdr.e_shentsize * index);
    7.42  }
    7.43  
    7.44  static int
    7.45  elf_core_alloc_read_sec_by_index(struct elf_core* ecore, uint16_t index,
    7.46                                   char** buf, uint64_t* size)
    7.47  {
    7.48 -    Elf_Shdr* shdr = elf_core_shdr_by_index(ecore, index);
    7.49 +    Elf64_Shdr* shdr = elf_core_shdr_by_index(ecore, index);
    7.50      if (shdr == NULL)
    7.51          return -1;
    7.52      if (size != NULL)
    7.53 @@ -329,14 +331,14 @@ elf_core_alloc_read_sec_by_index(struct 
    7.54      return elf_core_alloc_read_sec(ecore, shdr, buf);
    7.55  }
    7.56  
    7.57 -static Elf_Shdr*
    7.58 +static Elf64_Shdr*
    7.59  elf_core_shdr_by_name(struct elf_core* ecore, const char* name)
    7.60  {
    7.61      const char* s;
    7.62      for (s = ecore->shdr;
    7.63           s < ecore->shdr + ecore->ehdr.e_shentsize * ecore->ehdr.e_shnum;
    7.64           s += ecore->ehdr.e_shentsize) {
    7.65 -        Elf_Shdr* shdr = (Elf_Shdr*)s;
    7.66 +        Elf64_Shdr* shdr = (Elf64_Shdr*)s;
    7.67  
    7.68          if (strncmp(ecore->shstrtab + shdr->sh_name, name, strlen(name)) == 0)
    7.69              return shdr;
    7.70 @@ -348,7 +350,7 @@ elf_core_shdr_by_name(struct elf_core* e
    7.71  static int
    7.72  elf_core_read_sec_by_name(struct elf_core* ecore, const char* name, char* buf)
    7.73  {
    7.74 -    Elf_Shdr* shdr = elf_core_shdr_by_name(ecore, name);
    7.75 +    Elf64_Shdr* shdr = elf_core_shdr_by_name(ecore, name);
    7.76      return pread_exact(ecore->domfd, buf, shdr->sh_size, shdr->sh_offset);
    7.77      
    7.78  }
    7.79 @@ -357,7 +359,7 @@ static int
    7.80  elf_core_alloc_read_sec_by_name(struct elf_core* ecore, const char* name,
    7.81                                  char** buf, uint64_t* size)
    7.82  {
    7.83 -    Elf_Shdr* shdr = elf_core_shdr_by_name(ecore, name);
    7.84 +    Elf64_Shdr* shdr = elf_core_shdr_by_name(ecore, name);
    7.85      if (shdr == NULL)
    7.86          return -1;
    7.87      if (size != NULL)
    7.88 @@ -508,8 +510,8 @@ xc_waitdomain_core_elf(
    7.89      struct xen_dumpcore_elfnote_xen_version *xen_version;
    7.90      struct xen_dumpcore_elfnote_format_version *format_version;
    7.91  
    7.92 -    Elf_Shdr* table_shdr;
    7.93 -    Elf_Shdr* pages_shdr;
    7.94 +    Elf64_Shdr* table_shdr;
    7.95 +    Elf64_Shdr* pages_shdr;
    7.96  
    7.97      if (elf_core_init(&ecore, domfd) < 0)
    7.98          goto out;