ia64/linux-2.6.18-xen.hg

view include/xen/interface/libelf.h @ 439:be78655b9e87

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