From: Alexander Graf <agraf@suse.de>
To: qemu-devel Developers <qemu-devel@nongnu.org>
Cc: Gerd Hoffmann <kraxel@redhat.com>
Subject: [Qemu-devel] [PATCH 04/40] elf: add section analyzer
Date: Mon, 1 Nov 2010 16:01:17 +0100 [thread overview]
Message-ID: <1288623713-28062-5-git-send-email-agraf@suse.de> (raw)
In-Reply-To: <1288623713-28062-1-git-send-email-agraf@suse.de>
---
hw/elf_ops.h | 32 ++++++++++++++++++++++++++++++--
hw/loader.c | 7 +++++++
hw/loader.h | 3 +++
3 files changed, 40 insertions(+), 2 deletions(-)
diff --git a/hw/elf_ops.h b/hw/elf_ops.h
index 5bcba7e..6a042c5 100644
--- a/hw/elf_ops.h
+++ b/hw/elf_ops.h
@@ -100,13 +100,14 @@ static int glue(symcmp, SZ)(const void *s0, const void *s1)
}
static int glue(load_symbols, SZ)(struct elfhdr *ehdr, int fd, int must_swab,
- int clear_lsb)
+ int clear_lsb, ElfHandlers *handlers)
{
struct elf_shdr *symtab, *strtab, *shdr_table = NULL;
struct elf_sym *syms = NULL;
struct syminfo *s;
int nsyms, i;
char *str = NULL;
+ char *secstr = NULL;
shdr_table = load_at(fd, ehdr->e_shoff,
sizeof(struct elf_shdr) * ehdr->e_shnum);
@@ -172,6 +173,32 @@ static int glue(load_symbols, SZ)(struct elfhdr *ehdr, int fd, int must_swab,
if (!str)
goto fail;
+ /* Section string table */
+ if (ehdr->e_shstrndx >= ehdr->e_shnum)
+ goto fail;
+ strtab = &shdr_table[ehdr->e_shstrndx];
+
+ secstr = load_at(fd, strtab->sh_offset, strtab->sh_size);
+ if (!secstr)
+ goto fail;
+
+ /* External section analyzer */
+ for (i = 0; i < ehdr->e_shnum; i++) {
+ struct elf_shdr *cursec = &shdr_table[i];
+ uint8_t *section, *name;
+
+ if (!cursec->sh_size) {
+ continue;
+ }
+
+ name = (uint8_t*)&secstr[cursec->sh_name];
+ section = load_at(fd, cursec->sh_offset, cursec->sh_size);
+ handlers->section_fn(handlers->section_opaque, name, cursec->sh_size,
+ section);
+ qemu_free(section);
+ }
+
+
/* Commit */
s = qemu_mallocz(sizeof(*s));
s->lookup_symbol = glue(lookup_symbol, SZ);
@@ -185,6 +212,7 @@ static int glue(load_symbols, SZ)(struct elfhdr *ehdr, int fd, int must_swab,
fail:
qemu_free(syms);
qemu_free(str);
+ qemu_free(secstr);
qemu_free(shdr_table);
return -1;
}
@@ -273,7 +301,7 @@ static int glue(load_elf, SZ)(const char *name, int fd,
if (pentry)
*pentry = (uint64_t)(elf_sword)ehdr.e_entry;
- glue(load_symbols, SZ)(&ehdr, fd, must_swab, clear_lsb);
+ glue(load_symbols, SZ)(&ehdr, fd, must_swab, clear_lsb, handlers);
size = ehdr.e_phnum * sizeof(phdr[0]);
lseek(fd, ehdr.e_phoff, SEEK_SET);
diff --git a/hw/loader.c b/hw/loader.c
index 6a43fda..cf3c1ad 100644
--- a/hw/loader.c
+++ b/hw/loader.c
@@ -234,6 +234,11 @@ static void elf_default_note(void *opaque, uint8_t *name, uint32_t name_len,
{
}
+static void elf_default_section(void *opaque, uint8_t *name, uint32_t len,
+ uint8_t *data)
+{
+}
+
static uint64_t elf_default_translate(void *opaque, uint64_t addr)
{
return addr;
@@ -251,6 +256,8 @@ ElfHandlers elf_default_handlers = {
.note_opaque = NULL,
.header_notify_fn = elf_default_header_notify,
.header_notify_opaque = NULL,
+ .section_fn = elf_default_section,
+ .section_opaque = NULL,
};
diff --git a/hw/loader.h b/hw/loader.h
index 090b815..6351644 100644
--- a/hw/loader.h
+++ b/hw/loader.h
@@ -14,6 +14,9 @@ typedef struct ElfHandlers {
void *note_opaque;
void (*header_notify_fn)(void *opaque, void *ehdr, int bits);
void *header_notify_opaque;
+ void (*section_fn)(void *opaque, uint8_t *name, uint32_t len,
+ uint8_t *data);
+ void *section_opaque;
} ElfHandlers;
extern ElfHandlers elf_default_handlers;
--
1.6.0.2
next prev parent reply other threads:[~2010-11-01 15:02 UTC|newest]
Thread overview: 96+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-11-01 15:01 [Qemu-devel] [PATCH 00/40] RFC: Xenner Alexander Graf
2010-11-01 15:01 ` [Qemu-devel] [PATCH 01/40] elf: Move translate_fn to helper struct Alexander Graf
2010-11-01 15:01 ` [Qemu-devel] [PATCH 02/40] elf: Add notes implementation Alexander Graf
2010-11-01 18:29 ` Blue Swirl
2010-11-01 18:42 ` Stefan Weil
2010-11-01 19:51 ` Alexander Graf
2010-11-01 20:19 ` Stefan Weil
2010-11-01 21:17 ` Alexander Graf
2010-11-01 21:28 ` [Qemu-devel] " Paolo Bonzini
2010-11-01 21:31 ` [Qemu-devel] " Stefan Weil
2010-11-02 10:17 ` Michael Matz
2010-11-01 18:41 ` [Qemu-devel] " Paolo Bonzini
2010-11-01 18:52 ` Alexander Graf
2010-11-01 19:43 ` Paolo Bonzini
2010-11-01 19:48 ` Alexander Graf
2010-11-01 21:23 ` Paolo Bonzini
2010-11-01 15:01 ` [Qemu-devel] [PATCH 03/40] elf: add header notification Alexander Graf
2010-11-01 15:01 ` Alexander Graf [this message]
2010-11-01 15:01 ` [Qemu-devel] [PATCH 05/40] xen-disk: disable aio Alexander Graf
2010-11-01 15:01 ` [Qemu-devel] [PATCH 06/40] qdev-ify: xen backends Alexander Graf
2010-11-02 10:08 ` Markus Armbruster
2010-11-02 10:43 ` Gerd Hoffmann
2010-11-02 13:26 ` Markus Armbruster
2010-11-01 15:01 ` [Qemu-devel] [PATCH 07/40] xenner: kernel: 32 bit files Alexander Graf
2010-11-01 15:01 ` [Qemu-devel] [PATCH 08/40] xenner: kernel: 64-bit files Alexander Graf
2010-11-01 15:44 ` Anthony Liguori
2010-11-01 15:47 ` Alexander Graf
2010-11-01 15:59 ` Anthony Liguori
2010-11-01 19:00 ` Blue Swirl
2010-11-01 19:02 ` Anthony Liguori
2010-11-01 19:05 ` Alexander Graf
2010-11-01 19:23 ` Blue Swirl
2010-11-01 19:37 ` Anthony Liguori
2010-11-01 15:01 ` [Qemu-devel] [PATCH 09/40] xenner: kernel: Global data Alexander Graf
2010-11-01 15:01 ` [Qemu-devel] [PATCH 10/40] xenner: kernel: Hypercall handler (i386) Alexander Graf
2010-11-01 15:01 ` [Qemu-devel] [PATCH 11/40] xenner: kernel: Hypercall handler (x86_64) Alexander Graf
2010-11-01 15:01 ` [Qemu-devel] [PATCH 12/40] xenner: kernel: Hypercall handler (generic) Alexander Graf
2010-11-01 15:01 ` [Qemu-devel] [PATCH 13/40] xenner: kernel: Headers Alexander Graf
2010-11-01 15:01 ` [Qemu-devel] [PATCH 14/40] xenner: kernel: Instruction emulator Alexander Graf
2010-11-01 15:41 ` malc
2010-11-01 18:46 ` [Qemu-devel] " Paolo Bonzini
2010-11-01 15:01 ` [Qemu-devel] [PATCH 15/40] xenner: kernel: lapic code Alexander Graf
2010-11-01 15:01 ` [Qemu-devel] [PATCH 16/40] xenner: kernel: Main (i386) Alexander Graf
2010-11-01 15:01 ` [Qemu-devel] [PATCH 17/40] xenner: kernel: Main (x86_64) Alexander Graf
2010-11-01 15:01 ` [Qemu-devel] [PATCH 18/40] xenner: kernel: Main Alexander Graf
2010-11-01 15:01 ` [Qemu-devel] [PATCH 19/40] xenner: kernel: Makefile Alexander Graf
2010-11-01 15:01 ` [Qemu-devel] [PATCH 20/40] xenner: kernel: mmu support for 32-bit PAE Alexander Graf
2010-11-01 15:01 ` [Qemu-devel] [PATCH 21/40] xenner: kernel: mmu support for 32-bit normal Alexander Graf
2010-11-01 15:01 ` [Qemu-devel] [PATCH 22/40] xenner: kernel: mmu support for 64-bit Alexander Graf
2010-11-01 15:01 ` [Qemu-devel] [PATCH 23/40] xenner: kernel: generic MM functionality Alexander Graf
2010-11-01 15:01 ` [Qemu-devel] [PATCH 24/40] xenner: kernel: printk Alexander Graf
2010-11-01 15:01 ` [Qemu-devel] [PATCH 25/40] xenner: kernel: KVM PV code Alexander Graf
2010-11-01 15:01 ` [Qemu-devel] [PATCH 26/40] xenner: kernel: xen-names Alexander Graf
2010-11-01 15:01 ` [Qemu-devel] [PATCH 27/40] xenner: add xc_dom.h Alexander Graf
2010-11-01 15:01 ` [Qemu-devel] [PATCH 28/40] xenner: libxc emu: evtchn Alexander Graf
2010-11-01 15:45 ` Anthony Liguori
2010-11-01 15:49 ` Alexander Graf
2010-11-01 16:01 ` Anthony Liguori
2010-11-01 16:07 ` Alexander Graf
2010-11-01 16:14 ` Anthony Liguori
2010-11-01 16:15 ` Alexander Graf
2010-11-01 19:39 ` [Qemu-devel] " Paolo Bonzini
2010-11-01 19:41 ` Anthony Liguori
2010-11-01 19:47 ` Alexander Graf
2010-11-01 20:32 ` Anthony Liguori
2010-11-01 21:47 ` Paolo Bonzini
2010-11-01 22:00 ` Anthony Liguori
2010-11-01 22:08 ` Paolo Bonzini
2010-11-01 22:29 ` Anthony Liguori
2010-11-02 4:33 ` Stefano Stabellini
2010-11-02 10:06 ` Paolo Bonzini
2010-11-02 10:31 ` Gerd Hoffmann
2010-11-02 10:38 ` Paolo Bonzini
2010-11-02 13:55 ` Stefano Stabellini
2010-11-02 15:48 ` Alexander Graf
2010-11-02 19:20 ` Stefano Stabellini
2010-11-01 15:01 ` [Qemu-devel] [PATCH 29/40] xenner: libxc emu: grant tables Alexander Graf
2010-11-01 15:01 ` [Qemu-devel] [PATCH 30/40] xenner: libxc emu: memory mapping Alexander Graf
2010-11-01 15:12 ` malc
2010-11-01 15:15 ` Alexander Graf
2010-11-01 15:01 ` [Qemu-devel] [PATCH 31/40] xenner: libxc emu: xenstore Alexander Graf
2010-11-01 18:36 ` Blue Swirl
2010-11-01 15:01 ` [Qemu-devel] [PATCH 32/40] xenner: emudev Alexander Graf
2010-11-01 15:01 ` [Qemu-devel] [PATCH 33/40] xenner: core Alexander Graf
2010-11-01 15:13 ` malc
2010-11-01 15:01 ` [Qemu-devel] [PATCH 34/40] xenner: PV machine Alexander Graf
2010-11-01 15:01 ` [Qemu-devel] [PATCH 35/40] xenner: Domain Builder Alexander Graf
2010-11-02 10:09 ` [Qemu-devel] " Paolo Bonzini
2010-11-02 15:36 ` Alexander Graf
2010-11-02 15:51 ` Paolo Bonzini
2010-11-02 16:28 ` Alexander Graf
2010-11-01 15:21 ` [Qemu-devel] [PATCH 00/40] RFC: Xenner Alexander Graf
2010-11-02 16:26 ` [Qemu-devel] [PATCH 36/40] xen: only create dummy env when necessary Alexander Graf
2010-11-02 16:26 ` [Qemu-devel] [PATCH 38/40] xenner: integrate into build system Alexander Graf
2010-11-02 16:26 ` [Qemu-devel] [PATCH 39/40] xenner: integrate into xen pv machine Alexander Graf
2010-11-02 16:26 ` [Qemu-devel] [PATCH 40/40] xen: add sysrq support Alexander Graf
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1288623713-28062-5-git-send-email-agraf@suse.de \
--to=agraf@suse.de \
--cc=kraxel@redhat.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).