From 7758dfc7191c62c8ab0ffb524f7c8b70ce9938f3 Mon Sep 17 00:00:00 2001 From: "kfraser@dhcp93.uk.xensource.com" Date: Tue, 13 Jun 2006 14:36:04 +0100 Subject: [PATCH] [TOOLS][BUILDER] Extend Elf header checks for multiple architectures. Based on a patch from Hollis Blanchard. Signed-off-by: Keir Fraser --- tools/libxc/xc_elf.h | 3 ++- tools/libxc/xc_load_elf.c | 32 ++++++++++++++++++++++---------- xen/include/xen/elf.h | 2 +- 3 files changed, 25 insertions(+), 12 deletions(-) diff --git a/tools/libxc/xc_elf.h b/tools/libxc/xc_elf.h index 42da8762c4..6507667abd 100644 --- a/tools/libxc/xc_elf.h +++ b/tools/libxc/xc_elf.h @@ -170,13 +170,14 @@ typedef struct { #define EM_PARISC 15 /* HPPA */ #define EM_SPARC32PLUS 18 /* Enhanced instruction set SPARC */ #define EM_PPC 20 /* PowerPC */ +#define EM_PPC64 21 /* PowerPC 64-bit */ #define EM_ARM 40 /* Advanced RISC Machines ARM */ #define EM_ALPHA 41 /* DEC ALPHA */ #define EM_SPARCV9 43 /* SPARC version 9 */ #define EM_ALPHA_EXP 0x9026 /* DEC ALPHA */ +#define EM_IA_64 50 /* Intel Merced */ #define EM_X86_64 62 /* AMD x86-64 architecture */ #define EM_VAX 75 /* DEC VAX */ -#define EM_NUM 15 /* number of machine types */ /* Version */ #define EV_NONE 0 /* Invalid */ diff --git a/tools/libxc/xc_load_elf.c b/tools/libxc/xc_load_elf.c index 3cbb2499d9..54fc9e5fc4 100644 --- a/tools/libxc/xc_load_elf.c +++ b/tools/libxc/xc_load_elf.c @@ -22,6 +22,24 @@ loadelfsymtab( const char *image, int xch, uint32_t dom, xen_pfn_t *parray, struct domain_setup_info *dsi); +/* + * Elf header attributes we require for each supported host platform. + * These are checked in parseelfimage(). + */ +#if defined(__ia64__) +#define ELFCLASS ELFCLASS64 +#define ELFDATA ELFDATA2LSB +#define ELFMACHINE EM_IA_64 +#elif defined(__i386__) +#define ELFCLASS ELFCLASS32 +#define ELFDATA ELFDATA2LSB +#define ELFMACHINE EM_386 +#elif defined(__x86_64__) +#define ELFCLASS ELFCLASS64 +#define ELFDATA ELFDATA2LSB +#define ELFMACHINE EM_X86_64 +#endif + int probe_elf(const char *image, unsigned long image_size, struct load_funcs *load_funcs) @@ -61,16 +79,10 @@ static int parseelfimage(const char *image, return -EINVAL; } - if ( -#if defined(__i386__) - (ehdr->e_ident[EI_CLASS] != ELFCLASS32) || - (ehdr->e_machine != EM_386) || -#elif defined(__x86_64__) - (ehdr->e_ident[EI_CLASS] != ELFCLASS64) || - (ehdr->e_machine != EM_X86_64) || -#endif - (ehdr->e_ident[EI_DATA] != ELFDATA2LSB) || - (ehdr->e_type != ET_EXEC) ) + if ( (ehdr->e_ident[EI_CLASS] != ELFCLASS) || + (ehdr->e_machine != ELFMACHINE) || + (ehdr->e_ident[EI_DATA] != ELFDATA) || + (ehdr->e_type != ET_EXEC) ) { ERROR("Kernel not a Xen-compatible Elf image."); return -EINVAL; diff --git a/xen/include/xen/elf.h b/xen/include/xen/elf.h index 1d2ac6919a..dcf36fb856 100644 --- a/xen/include/xen/elf.h +++ b/xen/include/xen/elf.h @@ -178,9 +178,9 @@ typedef struct { #define EM_ALPHA 41 /* DEC ALPHA */ #define EM_SPARCV9 43 /* SPARC version 9 */ #define EM_ALPHA_EXP 0x9026 /* DEC ALPHA */ +#define EM_IA_64 50 /* Intel Merced */ #define EM_X86_64 62 /* AMD x86-64 architecture */ #define EM_VAX 75 /* DEC VAX */ -#define EM_NUM 15 /* number of machine types */ /* Version */ #define EV_NONE 0 /* Invalid */ -- 2.30.2