[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 13/77] elf-ops.h: Add get_elf_note_type()
From: |
Paolo Bonzini |
Subject: |
[Qemu-devel] [PULL 13/77] elf-ops.h: Add get_elf_note_type() |
Date: |
Mon, 4 Feb 2019 19:35:15 +0100 |
From: Liam Merwick <address@hidden>
Introduce a routine which, given a pointer to a range of ELF Notes,
searches through them looking for a note matching the type specified
and returns a pointer to the matching ELF note.
get_elf_note_type() is used by elf_load[32|64]() to find the
specified note type required by the 'elf_note_fn' parameter
added in the previous commit.
Signed-off-by: Liam Merwick <address@hidden>
Signed-off-by: Paolo Bonzini <address@hidden>
Signed-off-by: Liam Merwick <address@hidden>
---
include/hw/elf_ops.h | 75 ++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 75 insertions(+)
diff --git a/include/hw/elf_ops.h b/include/hw/elf_ops.h
index 3438d6f..690f923 100644
--- a/include/hw/elf_ops.h
+++ b/include/hw/elf_ops.h
@@ -265,6 +265,51 @@ fail:
return ret;
}
+/*
+ * Given 'nhdr', a pointer to a range of ELF Notes, search through them
+ * for a note matching type 'elf_note_type' and return a pointer to
+ * the matching ELF note.
+ */
+static struct elf_note *glue(get_elf_note_type, SZ)(struct elf_note *nhdr,
+ elf_word note_size,
+ elf_word phdr_align,
+ elf_word elf_note_type)
+{
+ elf_word nhdr_size = sizeof(struct elf_note);
+ elf_word elf_note_entry_offset = 0;
+ elf_word note_type;
+ elf_word nhdr_namesz;
+ elf_word nhdr_descsz;
+
+ if (nhdr == NULL) {
+ return NULL;
+ }
+
+ note_type = nhdr->n_type;
+ while (note_type != elf_note_type) {
+ nhdr_namesz = nhdr->n_namesz;
+ nhdr_descsz = nhdr->n_descsz;
+
+ elf_note_entry_offset = nhdr_size +
+ QEMU_ALIGN_UP(nhdr_namesz, phdr_align) +
+ QEMU_ALIGN_UP(nhdr_descsz, phdr_align);
+
+ /*
+ * If the offset calculated in this iteration exceeds the
+ * supplied size, we are done and no matching note was found.
+ */
+ if (elf_note_entry_offset > note_size) {
+ return NULL;
+ }
+
+ /* skip to the next ELF Note entry */
+ nhdr = (void *)nhdr + elf_note_entry_offset;
+ note_type = nhdr->n_type;
+ }
+
+ return nhdr;
+}
+
static int glue(load_elf, SZ)(const char *name, int fd,
uint64_t (*elf_note_fn)(void *, void *, bool),
uint64_t (*translate_fn)(void *, uint64_t),
@@ -497,6 +542,36 @@ static int glue(load_elf, SZ)(const char *name, int fd,
high = addr + mem_size;
data = NULL;
+
+ } else if (ph->p_type == PT_NOTE && elf_note_fn) {
+ struct elf_note *nhdr = NULL;
+
+ file_size = ph->p_filesz; /* Size of the range of ELF notes */
+ data = g_malloc0(file_size);
+ if (ph->p_filesz > 0) {
+ if (lseek(fd, ph->p_offset, SEEK_SET) < 0) {
+ goto fail;
+ }
+ if (read(fd, data, file_size) != file_size) {
+ goto fail;
+ }
+ }
+
+ /*
+ * Search the ELF notes to find one with a type matching the
+ * value passed in via 'translate_opaque'
+ */
+ nhdr = (struct elf_note *)data;
+ assert(translate_opaque != NULL);
+ nhdr = glue(get_elf_note_type, SZ)(nhdr, file_size, ph->p_align,
+ *(uint64_t *)translate_opaque);
+ if (nhdr != NULL) {
+ bool is64 =
+ sizeof(struct elf_note) == sizeof(struct elf64_note);
+ elf_note_fn((void *)nhdr, (void *)&ph->p_align, is64);
+ }
+ g_free(data);
+ data = NULL;
}
}
--
1.8.3.1
- [Qemu-devel] [PULL 06/77] vhost-user-test: reduce usage of global_qtest, (continued)
- [Qemu-devel] [PULL 06/77] vhost-user-test: reduce usage of global_qtest, Paolo Bonzini, 2019/02/04
- [Qemu-devel] [PULL 07/77] tap: flush STDOUT on newline, Paolo Bonzini, 2019/02/04
- [Qemu-devel] [PULL 11/77] cpus: ignore ESRCH in qemu_cpu_kick_thread(), Paolo Bonzini, 2019/02/04
- [Qemu-devel] [PULL 03/77] vhost-user: support cross-endian vnet headers, Paolo Bonzini, 2019/02/04
- [Qemu-devel] [PULL 05/77] vhost-user-test: skip if there is no memory at address 0, Paolo Bonzini, 2019/02/04
- [Qemu-devel] [PULL 14/77] pvh: Add x86/HVM direct boot ABI header file, Paolo Bonzini, 2019/02/04
- [Qemu-devel] [PULL 09/77] cpu-exec: reset BQL after longjmp in cpu_exec_step_atomic, Paolo Bonzini, 2019/02/04
- [Qemu-devel] [PULL 02/77] vhost-user-test: signal data_cond when s->rings changes, Paolo Bonzini, 2019/02/04
- [Qemu-devel] [PULL 17/77] linuxboot_dma: remove duplicate definitions of FW_CFG, Paolo Bonzini, 2019/02/04
- [Qemu-devel] [PULL 13/77] elf-ops.h: Add get_elf_note_type(),
Paolo Bonzini <=
- [Qemu-devel] [PULL 20/77] hw/i386/pc: use PVH option rom, Paolo Bonzini, 2019/02/04
- [Qemu-devel] [PULL 01/77] vhost-user-test: use g_cond_broadcast, Paolo Bonzini, 2019/02/04
- [Qemu-devel] [PULL 29/77] contrib/elf2dmp: use GLib in PDB processing, Paolo Bonzini, 2019/02/04
- [Qemu-devel] [PULL 16/77] pvh: load initrd and expose it through fw_cfg, Paolo Bonzini, 2019/02/04
- [Qemu-devel] [PULL 18/77] linuxboot_dma: move common functions in a new header, Paolo Bonzini, 2019/02/04
- [Qemu-devel] [PULL 23/77] i386: remove the new CPUID 'PCONFIG' from Icelake-Server CPU model, Paolo Bonzini, 2019/02/04
- [Qemu-devel] [PULL 30/77] contrib/elf2dmp: fix structures definitions, Paolo Bonzini, 2019/02/04
- [Qemu-devel] [PULL 32/77] configure: enable elf2dmp build for Windows hosts, Paolo Bonzini, 2019/02/04
- [Qemu-devel] [PULL 12/77] elf: Add optional function ptr to load_elf() to parse ELF notes, Paolo Bonzini, 2019/02/04
- [Qemu-devel] [PULL 24/77] i386: remove the 'INTEL_PT' CPUID bit from named CPU models, Paolo Bonzini, 2019/02/04