diff options
author | Wen Congyang <wency@cn.fujitsu.com> | 2012-05-07 12:09:36 +0800 |
---|---|---|
committer | Luiz Capitulino <lcapitulino@redhat.com> | 2012-06-04 13:49:34 -0300 |
commit | 0038ffb09692955b8f8f363958cbf58c205ae772 (patch) | |
tree | 785b00b3acc3a7c566994a151ab5f6545a00f259 | |
parent | 25ae9c1d8bbfeb6c00eccb4297a5937d8375a44a (diff) | |
download | qemu-0038ffb09692955b8f8f363958cbf58c205ae772.tar.gz qemu-0038ffb09692955b8f8f363958cbf58c205ae772.tar.bz2 qemu-0038ffb09692955b8f8f363958cbf58c205ae772.zip |
target-i386: Add API to get note's size
We should know where the note and memory is stored before writing
them to vmcore. If we know this, we can avoid using lseek() when
creating vmcore.
Signed-off-by: Wen Congyang <wency@cn.fujitsu.com>
Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
-rw-r--r-- | cpu-all.h | 6 | ||||
-rw-r--r-- | target-i386/arch_dump.c | 33 |
2 files changed, 39 insertions, 0 deletions
@@ -553,6 +553,7 @@ int cpu_write_elf64_qemunote(write_core_dump_function f, CPUArchState *env, int cpu_write_elf32_qemunote(write_core_dump_function f, CPUArchState *env, void *opaque); int cpu_get_dump_info(ArchDumpInfo *info); +size_t cpu_get_note_size(int class, int machine, int nr_cpus); #else static inline int cpu_write_elf64_note(write_core_dump_function f, CPUArchState *env, int cpuid, @@ -586,6 +587,11 @@ static inline int cpu_get_dump_info(ArchDumpInfo *info) { return -1; } + +static inline int cpu_get_note_size(int class, int machine, int nr_cpus) +{ + return -1; +} #endif #endif /* CPU_ALL_H */ diff --git a/target-i386/arch_dump.c b/target-i386/arch_dump.c index e37857968d..135d855c4a 100644 --- a/target-i386/arch_dump.c +++ b/target-i386/arch_dump.c @@ -414,3 +414,36 @@ int cpu_get_dump_info(ArchDumpInfo *info) return 0; } + +size_t cpu_get_note_size(int class, int machine, int nr_cpus) +{ + int name_size = 5; /* "CORE" or "QEMU" */ + size_t elf_note_size = 0; + size_t qemu_note_size = 0; + int elf_desc_size = 0; + int qemu_desc_size = 0; + int note_head_size; + + if (class == ELFCLASS32) { + note_head_size = sizeof(Elf32_Nhdr); + } else { + note_head_size = sizeof(Elf64_Nhdr); + } + + if (machine == EM_386) { + elf_desc_size = sizeof(x86_elf_prstatus); + } +#ifdef TARGET_X86_64 + else { + elf_desc_size = sizeof(x86_64_elf_prstatus); + } +#endif + qemu_desc_size = sizeof(QEMUCPUState); + + elf_note_size = ((note_head_size + 3) / 4 + (name_size + 3) / 4 + + (elf_desc_size + 3) / 4) * 4; + qemu_note_size = ((note_head_size + 3) / 4 + (name_size + 3) / 4 + + (qemu_desc_size + 3) / 4) * 4; + + return (elf_note_size + qemu_note_size) * nr_cpus; +} |