ia64/linux-2.6.18-xen.hg

annotate include/xen/interface/libelf.h @ 540:db71fb3204b5

Sync public Xen hedaers with xen-unstable.hg
Signed-off-by: Keir Fraser <keir.fraser@citrix.com>
author Keir Fraser <keir.fraser@citrix.com>
date Mon May 12 10:03:08 2008 +0100 (2008-05-12)
parents be78655b9e87
children
rev   line source
keir@439 1 /******************************************************************************
keir@439 2 * libelf.h
keir@439 3 *
keir@439 4 * Permission is hereby granted, free of charge, to any person obtaining a copy
keir@439 5 * of this software and associated documentation files (the "Software"), to
keir@439 6 * deal in the Software without restriction, including without limitation the
keir@439 7 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
keir@439 8 * sell copies of the Software, and to permit persons to whom the Software is
keir@439 9 * furnished to do so, subject to the following conditions:
keir@439 10 *
keir@439 11 * The above copyright notice and this permission notice shall be included in
keir@439 12 * all copies or substantial portions of the Software.
keir@439 13 *
keir@439 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
keir@439 15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
keir@439 16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
keir@439 17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
keir@439 18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
keir@439 19 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
keir@439 20 * DEALINGS IN THE SOFTWARE.
keir@439 21 */
keir@439 22
ian@26 23 #ifndef __XC_LIBELF__
ian@26 24 #define __XC_LIBELF__ 1
ian@26 25
keir@540 26 #if defined(__i386__) || defined(__x86_64__) || defined(__ia64__)
ian@26 27 #define XEN_ELF_LITTLE_ENDIAN
ian@26 28 #else
ian@26 29 #error define architectural endianness
ian@26 30 #endif
ian@26 31
ian@26 32 #undef ELFSIZE
ian@26 33 #include "elfnote.h"
ian@26 34 #include "elfstructs.h"
ian@26 35 #include "features.h"
ian@26 36
ian@26 37 /* ------------------------------------------------------------------------ */
ian@26 38
ian@26 39 typedef union {
ian@26 40 Elf32_Ehdr e32;
ian@26 41 Elf64_Ehdr e64;
ian@26 42 } elf_ehdr;
ian@26 43
ian@26 44 typedef union {
ian@26 45 Elf32_Phdr e32;
ian@26 46 Elf64_Phdr e64;
ian@26 47 } elf_phdr;
ian@26 48
ian@26 49 typedef union {
ian@26 50 Elf32_Shdr e32;
ian@26 51 Elf64_Shdr e64;
ian@26 52 } elf_shdr;
ian@26 53
ian@26 54 typedef union {
ian@26 55 Elf32_Sym e32;
ian@26 56 Elf64_Sym e64;
ian@26 57 } elf_sym;
ian@26 58
ian@26 59 typedef union {
ian@26 60 Elf32_Rel e32;
ian@26 61 Elf64_Rel e64;
ian@26 62 } elf_rel;
ian@26 63
ian@26 64 typedef union {
ian@26 65 Elf32_Rela e32;
ian@26 66 Elf64_Rela e64;
ian@26 67 } elf_rela;
ian@26 68
ian@26 69 typedef union {
ian@26 70 Elf32_Note e32;
ian@26 71 Elf64_Note e64;
ian@26 72 } elf_note;
ian@26 73
ian@26 74 struct elf_binary {
ian@26 75 /* elf binary */
ian@26 76 const char *image;
ian@26 77 size_t size;
ian@26 78 char class;
ian@26 79 char data;
ian@26 80
ian@26 81 const elf_ehdr *ehdr;
ian@26 82 const char *sec_strtab;
ian@26 83 const elf_shdr *sym_tab;
ian@26 84 const char *sym_strtab;
ian@26 85
ian@26 86 /* loaded to */
ian@26 87 char *dest;
ian@26 88 uint64_t pstart;
ian@26 89 uint64_t pend;
ian@26 90 uint64_t reloc_offset;
ian@26 91
keir@258 92 uint64_t bsd_symtab_pstart;
keir@258 93 uint64_t bsd_symtab_pend;
keir@258 94
ian@26 95 #ifndef __XEN__
ian@26 96 /* misc */
ian@26 97 FILE *log;
ian@26 98 #endif
ian@26 99 int verbose;
ian@26 100 };
ian@26 101
ian@26 102 /* ------------------------------------------------------------------------ */
ian@26 103 /* accessing elf header fields */
ian@26 104
ian@26 105 #ifdef XEN_ELF_BIG_ENDIAN
ian@26 106 # define NATIVE_ELFDATA ELFDATA2MSB
ian@26 107 #else
ian@26 108 # define NATIVE_ELFDATA ELFDATA2LSB
ian@26 109 #endif
ian@26 110
ian@26 111 #define elf_32bit(elf) (ELFCLASS32 == (elf)->class)
ian@26 112 #define elf_64bit(elf) (ELFCLASS64 == (elf)->class)
ian@26 113 #define elf_msb(elf) (ELFDATA2MSB == (elf)->data)
ian@26 114 #define elf_lsb(elf) (ELFDATA2LSB == (elf)->data)
ian@26 115 #define elf_swap(elf) (NATIVE_ELFDATA != (elf)->data)
ian@26 116
keir@258 117 #define elf_uval(elf, str, elem) \
keir@258 118 ((ELFCLASS64 == (elf)->class) \
keir@258 119 ? elf_access_unsigned((elf), (str), \
keir@258 120 offsetof(typeof(*(str)),e64.elem), \
keir@258 121 sizeof((str)->e64.elem)) \
keir@258 122 : elf_access_unsigned((elf), (str), \
keir@258 123 offsetof(typeof(*(str)),e32.elem), \
keir@258 124 sizeof((str)->e32.elem)))
ian@26 125
keir@258 126 #define elf_sval(elf, str, elem) \
keir@258 127 ((ELFCLASS64 == (elf)->class) \
keir@258 128 ? elf_access_signed((elf), (str), \
keir@258 129 offsetof(typeof(*(str)),e64.elem), \
keir@258 130 sizeof((str)->e64.elem)) \
keir@258 131 : elf_access_signed((elf), (str), \
keir@258 132 offsetof(typeof(*(str)),e32.elem), \
keir@258 133 sizeof((str)->e32.elem)))
ian@26 134
keir@258 135 #define elf_size(elf, str) \
keir@258 136 ((ELFCLASS64 == (elf)->class) \
keir@258 137 ? sizeof((str)->e64) : sizeof((str)->e32))
ian@26 138
ian@26 139 uint64_t elf_access_unsigned(struct elf_binary *elf, const void *ptr,
keir@258 140 uint64_t offset, size_t size);
ian@26 141 int64_t elf_access_signed(struct elf_binary *elf, const void *ptr,
keir@258 142 uint64_t offset, size_t size);
ian@26 143
ian@26 144 uint64_t elf_round_up(struct elf_binary *elf, uint64_t addr);
ian@26 145
ian@26 146 /* ------------------------------------------------------------------------ */
ian@26 147 /* xc_libelf_tools.c */
ian@26 148
ian@26 149 int elf_shdr_count(struct elf_binary *elf);
ian@26 150 int elf_phdr_count(struct elf_binary *elf);
ian@26 151
ian@26 152 const elf_shdr *elf_shdr_by_name(struct elf_binary *elf, const char *name);
ian@26 153 const elf_shdr *elf_shdr_by_index(struct elf_binary *elf, int index);
ian@26 154 const elf_phdr *elf_phdr_by_index(struct elf_binary *elf, int index);
ian@26 155
ian@26 156 const char *elf_section_name(struct elf_binary *elf, const elf_shdr * shdr);
ian@26 157 const void *elf_section_start(struct elf_binary *elf, const elf_shdr * shdr);
ian@26 158 const void *elf_section_end(struct elf_binary *elf, const elf_shdr * shdr);
ian@26 159
ian@26 160 const void *elf_segment_start(struct elf_binary *elf, const elf_phdr * phdr);
ian@26 161 const void *elf_segment_end(struct elf_binary *elf, const elf_phdr * phdr);
ian@26 162
ian@26 163 const elf_sym *elf_sym_by_name(struct elf_binary *elf, const char *symbol);
ian@26 164 const elf_sym *elf_sym_by_index(struct elf_binary *elf, int index);
ian@26 165
ian@26 166 const char *elf_note_name(struct elf_binary *elf, const elf_note * note);
ian@26 167 const void *elf_note_desc(struct elf_binary *elf, const elf_note * note);
ian@26 168 uint64_t elf_note_numeric(struct elf_binary *elf, const elf_note * note);
ian@26 169 const elf_note *elf_note_next(struct elf_binary *elf, const elf_note * note);
ian@26 170
ian@26 171 int elf_is_elfbinary(const void *image);
ian@26 172 int elf_phdr_is_loadable(struct elf_binary *elf, const elf_phdr * phdr);
ian@26 173
ian@26 174 /* ------------------------------------------------------------------------ */
ian@26 175 /* xc_libelf_loader.c */
ian@26 176
ian@26 177 int elf_init(struct elf_binary *elf, const char *image, size_t size);
ian@26 178 #ifdef __XEN__
ian@26 179 void elf_set_verbose(struct elf_binary *elf);
ian@26 180 #else
ian@26 181 void elf_set_logfile(struct elf_binary *elf, FILE * log, int verbose);
ian@26 182 #endif
ian@26 183
ian@26 184 void elf_parse_binary(struct elf_binary *elf);
ian@26 185 void elf_load_binary(struct elf_binary *elf);
ian@26 186
ian@26 187 void *elf_get_ptr(struct elf_binary *elf, unsigned long addr);
ian@26 188 uint64_t elf_lookup_addr(struct elf_binary *elf, const char *symbol);
ian@26 189
keir@258 190 void elf_parse_bsdsyms(struct elf_binary *elf, uint64_t pstart); /* private */
keir@258 191
ian@26 192 /* ------------------------------------------------------------------------ */
ian@26 193 /* xc_libelf_relocate.c */
ian@26 194
ian@26 195 int elf_reloc(struct elf_binary *elf);
ian@26 196
ian@26 197 /* ------------------------------------------------------------------------ */
ian@26 198 /* xc_libelf_dominfo.c */
ian@26 199
ian@26 200 #define UNSET_ADDR ((uint64_t)-1)
ian@26 201
ian@26 202 enum xen_elfnote_type {
ian@26 203 XEN_ENT_NONE = 0,
ian@26 204 XEN_ENT_LONG = 1,
ian@26 205 XEN_ENT_STR = 2
ian@26 206 };
ian@26 207
ian@26 208 struct xen_elfnote {
ian@26 209 enum xen_elfnote_type type;
ian@26 210 const char *name;
ian@26 211 union {
keir@258 212 const char *str;
keir@258 213 uint64_t num;
ian@26 214 } data;
ian@26 215 };
ian@26 216
ian@26 217 struct elf_dom_parms {
ian@26 218 /* raw */
ian@26 219 const char *guest_info;
ian@26 220 const void *elf_note_start;
ian@26 221 const void *elf_note_end;
ian@26 222 struct xen_elfnote elf_notes[XEN_ELFNOTE_MAX + 1];
ian@26 223
ian@26 224 /* parsed */
ian@26 225 char guest_os[16];
ian@26 226 char guest_ver[16];
ian@26 227 char xen_ver[16];
ian@26 228 char loader[16];
ian@26 229 int pae;
ian@26 230 int bsd_symtab;
ian@26 231 uint64_t virt_base;
ian@26 232 uint64_t virt_entry;
ian@26 233 uint64_t virt_hypercall;
ian@26 234 uint64_t virt_hv_start_low;
ian@26 235 uint64_t elf_paddr_offset;
ian@26 236 uint32_t f_supported[XENFEAT_NR_SUBMAPS];
ian@26 237 uint32_t f_required[XENFEAT_NR_SUBMAPS];
ian@26 238
ian@26 239 /* calculated */
ian@26 240 uint64_t virt_offset;
ian@26 241 uint64_t virt_kstart;
ian@26 242 uint64_t virt_kend;
ian@26 243 };
ian@26 244
ian@26 245 static inline void elf_xen_feature_set(int nr, uint32_t * addr)
ian@26 246 {
ian@26 247 addr[nr >> 5] |= 1 << (nr & 31);
ian@26 248 }
ian@26 249 static inline int elf_xen_feature_get(int nr, uint32_t * addr)
ian@26 250 {
ian@26 251 return !!(addr[nr >> 5] & (1 << (nr & 31)));
ian@26 252 }
ian@26 253
ian@26 254 int elf_xen_parse_features(const char *features,
keir@258 255 uint32_t *supported,
keir@258 256 uint32_t *required);
ian@26 257 int elf_xen_parse_note(struct elf_binary *elf,
keir@258 258 struct elf_dom_parms *parms,
keir@258 259 const elf_note *note);
ian@26 260 int elf_xen_parse_guest_info(struct elf_binary *elf,
keir@258 261 struct elf_dom_parms *parms);
ian@26 262 int elf_xen_parse(struct elf_binary *elf,
keir@258 263 struct elf_dom_parms *parms);
ian@26 264
ian@26 265 #endif /* __XC_LIBELF__ */