# HG changeset patch # User yamahata@xxxxxxxxxxxxx # Date 1173235747 -32400 # Node ID 07c57aa351fa3415c1a086c978e61ed04635b1c3 # Parent 3ac19fda0bc256bac20a4decf7e13bb086162220 dump-core: always use elfclass64 format to support x86_32pae. Without this patch xen dump-core format can't handle over 4GB case. PATCHNAME: dump_core_elfclass64 Signed-off-by: Isaku Yamahata diff -r 3ac19fda0bc2 -r 07c57aa351fa docs/misc/dump-core-format.txt --- a/docs/misc/dump-core-format.txt Fri Mar 02 12:11:52 2007 +0000 +++ b/docs/misc/dump-core-format.txt Wed Mar 07 11:49:07 2007 +0900 @@ -26,11 +26,12 @@ Elf header Elf header ---------- The elf header members are set as follows + e_ident[EI_CLASS] = ELFCLASS64 = 2 e_ident[EI_OSABI] = ELFOSABI_SYSV = 0 e_type = ET_CORE = 4 -e_ident[EI_CLASS], e_ident[EI_DATA] and e_flags are set according -to an architecture which a file is created. Other members are set as usual. - +ELFCLASS64 is always used independent of architecture. +e_ident[EI_DATA] and e_flags are set according to an architecture which +a file is created. Other members are set as usual. Sections -------- @@ -223,3 +224,8 @@ Format version history ---------------------- The currently only (major, minor) = (0, 1) is used. [When the format is changed, it would be described here.] + +(0, 1) update +- EI_CLASS member of elf header was changed to ELFCLASS64 independent of + architecture. This is mainly for x86_32pae. + The format version isn't bumped because analysis tools can ditinguish it. diff -r 3ac19fda0bc2 -r 07c57aa351fa tools/libxc/xc_core.c --- a/tools/libxc/xc_core.c Fri Mar 02 12:11:52 2007 +0000 +++ b/tools/libxc/xc_core.c Wed Mar 07 11:49:07 2007 +0900 @@ -153,7 +153,7 @@ struct xc_core_section_headers { uint16_t num; uint16_t num_max; - Elf_Shdr *shdrs; + Elf64_Shdr *shdrs; }; #define SHDR_INIT 16 #define SHDR_INC 4 @@ -184,14 +184,14 @@ xc_core_shdr_free(struct xc_core_section free(sheaders); } -Elf_Shdr* +Elf64_Shdr* xc_core_shdr_get(struct xc_core_section_headers *sheaders) { - Elf_Shdr *shdr; + Elf64_Shdr *shdr; if ( sheaders->num == sheaders->num_max ) { - Elf_Shdr *shdrs; + Elf64_Shdr *shdrs; if ( sheaders->num_max + SHDR_INC < sheaders->num_max ) { errno = E2BIG; @@ -212,7 +212,7 @@ xc_core_shdr_get(struct xc_core_section_ } int -xc_core_shdr_set(Elf_Shdr *shdr, +xc_core_shdr_set(Elf64_Shdr *shdr, struct xc_core_strtab *strtab, const char *name, uint32_t type, uint64_t offset, uint64_t size, @@ -317,15 +317,15 @@ xc_domain_dumpcore_via_callback(int xc_h uint64_t *pfn_array = NULL; - Elf_Ehdr ehdr; - unsigned long filesz; - unsigned long offset; - unsigned long fixup; + Elf64_Ehdr ehdr; + uint64_t filesz; + uint64_t offset; + uint64_t fixup; struct xc_core_strtab *strtab = NULL; uint16_t strtab_idx; struct xc_core_section_headers *sheaders = NULL; - Elf_Shdr *shdr; + Elf64_Shdr *shdr; /* elf notes */ struct elfnote elfnote; @@ -460,7 +460,7 @@ xc_domain_dumpcore_via_callback(int xc_h ehdr.e_ident[EI_MAG1] = ELFMAG1; ehdr.e_ident[EI_MAG2] = ELFMAG2; ehdr.e_ident[EI_MAG3] = ELFMAG3; - ehdr.e_ident[EI_CLASS] = ELFCLASS; + ehdr.e_ident[EI_CLASS] = ELFCLASS64; ehdr.e_ident[EI_DATA] = ELF_ARCH_DATA; ehdr.e_ident[EI_VERSION] = EV_CURRENT; ehdr.e_ident[EI_OSABI] = ELFOSABI_SYSV; @@ -474,9 +474,9 @@ xc_domain_dumpcore_via_callback(int xc_h ehdr.e_shoff = sizeof(ehdr); ehdr.e_flags = ELF_CORE_EFLAGS; ehdr.e_ehsize = sizeof(ehdr); - ehdr.e_phentsize = sizeof(Elf_Phdr); + ehdr.e_phentsize = sizeof(Elf64_Phdr); ehdr.e_phnum = 0; - ehdr.e_shentsize = sizeof(Elf_Shdr); + ehdr.e_shentsize = sizeof(Elf64_Shdr); /* ehdr.e_shnum and ehdr.e_shstrndx aren't known here yet. fill it later*/ /* create section header */ diff -r 3ac19fda0bc2 -r 07c57aa351fa tools/libxc/xc_core.h --- a/tools/libxc/xc_core.h Fri Mar 02 12:11:52 2007 +0000 +++ b/tools/libxc/xc_core.h Wed Mar 07 11:49:07 2007 +0900 @@ -116,10 +116,10 @@ struct xc_core_strtab; struct xc_core_strtab; struct xc_core_section_headers; -Elf_Shdr* +Elf64_Shdr* xc_core_shdr_get(struct xc_core_section_headers *sheaders); int -xc_core_shdr_set(Elf_Shdr *shdr, +xc_core_shdr_set(Elf64_Shdr *shdr, struct xc_core_strtab *strtab, const char *name, uint32_t type, uint64_t offset, uint64_t size, diff -r 3ac19fda0bc2 -r 07c57aa351fa tools/libxc/xc_core_ia64.c --- a/tools/libxc/xc_core_ia64.c Fri Mar 02 12:11:52 2007 +0000 +++ b/tools/libxc/xc_core_ia64.c Wed Mar 07 11:49:07 2007 +0900 @@ -266,10 +266,10 @@ xc_core_arch_context_get_shdr(struct xc_ xc_core_arch_context_get_shdr(struct xc_core_arch_context *arch_ctxt, struct xc_core_section_headers *sheaders, struct xc_core_strtab *strtab, - unsigned long *filesz, unsigned long offset) + uint64_t *filesz, uint64_t offset) { int sts = -1; - Elf_Shdr *shdr; + Elf64_Shdr *shdr; /* mmapped priv regs */ shdr = xc_core_shdr_get(sheaders); diff -r 3ac19fda0bc2 -r 07c57aa351fa tools/libxc/xc_core_ia64.h --- a/tools/libxc/xc_core_ia64.h Fri Mar 02 12:11:52 2007 +0000 +++ b/tools/libxc/xc_core_ia64.h Wed Mar 07 11:49:07 2007 +0900 @@ -42,7 +42,7 @@ xc_core_arch_context_get_shdr(struct xc_ xc_core_arch_context_get_shdr(struct xc_core_arch_context* arch_ctxt, struct xc_core_section_headers *sheaders, struct xc_core_strtab *strtab, - unsigned long *filesz, unsigned long offset); + uint64_t *filesz, uint64_t offset); int xc_core_arch_context_dump(struct xc_core_arch_context* arch_ctxt, void* args, dumpcore_rtn_t dump_rtn); diff -r 3ac19fda0bc2 -r 07c57aa351fa tools/libxc/xc_core_x86.h --- a/tools/libxc/xc_core_x86.h Fri Mar 02 12:11:52 2007 +0000 +++ b/tools/libxc/xc_core_x86.h Wed Mar 07 11:49:07 2007 +0900 @@ -45,7 +45,7 @@ xc_core_arch_context_get_shdr(struct xc_ xc_core_arch_context_get_shdr(struct xc_core_arch_context *arch_ctxt, struct xc_core_section_headers *sheaders, struct xc_core_strtab *strtab, - unsigned long *filesz, unsigned long offset) + uint64_t *filesz, uint64_t offset) { *filesz = 0; return 0; diff -r 3ac19fda0bc2 -r 07c57aa351fa tools/libxc/xc_ptrace_core.c --- a/tools/libxc/xc_ptrace_core.c Fri Mar 02 12:11:52 2007 +0000 +++ b/tools/libxc/xc_ptrace_core.c Wed Mar 07 11:49:07 2007 +0900 @@ -192,7 +192,7 @@ struct elf_core struct elf_core { int domfd; - Elf_Ehdr ehdr; + Elf64_Ehdr ehdr; char* shdr; @@ -241,6 +241,8 @@ elf_core_init(struct elf_core* ecore, in /* check elf header */ if (!IS_ELF(ecore->ehdr) || ecore->ehdr.e_type != ET_CORE) + goto out; + if (ecore->ehdr.e_ident[EI_CLASS] != ELFCLASS64) goto out; /* check elf header more: EI_DATA, EI_VERSION, e_machine... */ @@ -294,7 +296,7 @@ elf_core_search_note(struct elf_core* ec } static int -elf_core_alloc_read_sec(struct elf_core* ecore, const Elf_Shdr* shdr, +elf_core_alloc_read_sec(struct elf_core* ecore, const Elf64_Shdr* shdr, char** buf) { int ret; @@ -309,19 +311,19 @@ elf_core_alloc_read_sec(struct elf_core* return ret; } -static Elf_Shdr* +static Elf64_Shdr* elf_core_shdr_by_index(struct elf_core* ecore, uint16_t index) { if (index >= ecore->ehdr.e_shnum) return NULL; - return (Elf_Shdr*)(ecore->shdr + ecore->ehdr.e_shentsize * index); + return (Elf64_Shdr*)(ecore->shdr + ecore->ehdr.e_shentsize * index); } static int elf_core_alloc_read_sec_by_index(struct elf_core* ecore, uint16_t index, char** buf, uint64_t* size) { - Elf_Shdr* shdr = elf_core_shdr_by_index(ecore, index); + Elf64_Shdr* shdr = elf_core_shdr_by_index(ecore, index); if (shdr == NULL) return -1; if (size != NULL) @@ -329,14 +331,14 @@ elf_core_alloc_read_sec_by_index(struct return elf_core_alloc_read_sec(ecore, shdr, buf); } -static Elf_Shdr* +static Elf64_Shdr* elf_core_shdr_by_name(struct elf_core* ecore, const char* name) { const char* s; for (s = ecore->shdr; s < ecore->shdr + ecore->ehdr.e_shentsize * ecore->ehdr.e_shnum; s += ecore->ehdr.e_shentsize) { - Elf_Shdr* shdr = (Elf_Shdr*)s; + Elf64_Shdr* shdr = (Elf64_Shdr*)s; if (strncmp(ecore->shstrtab + shdr->sh_name, name, strlen(name)) == 0) return shdr; @@ -348,7 +350,7 @@ static int static int elf_core_read_sec_by_name(struct elf_core* ecore, const char* name, char* buf) { - Elf_Shdr* shdr = elf_core_shdr_by_name(ecore, name); + Elf64_Shdr* shdr = elf_core_shdr_by_name(ecore, name); return pread_exact(ecore->domfd, buf, shdr->sh_size, shdr->sh_offset); } @@ -357,7 +359,7 @@ elf_core_alloc_read_sec_by_name(struct e elf_core_alloc_read_sec_by_name(struct elf_core* ecore, const char* name, char** buf, uint64_t* size) { - Elf_Shdr* shdr = elf_core_shdr_by_name(ecore, name); + Elf64_Shdr* shdr = elf_core_shdr_by_name(ecore, name); if (shdr == NULL) return -1; if (size != NULL) @@ -508,8 +510,8 @@ xc_waitdomain_core_elf( struct xen_dumpcore_elfnote_xen_version *xen_version; struct xen_dumpcore_elfnote_format_version *format_version; - Elf_Shdr* table_shdr; - Elf_Shdr* pages_shdr; + Elf64_Shdr* table_shdr; + Elf64_Shdr* pages_shdr; if (elf_core_init(&ecore, domfd) < 0) goto out;