From: Rabin Vincent <rabin@rab.in>
To: qemu-devel@nongnu.org
Cc: Rabin Vincent <rabin@rab.in>
Subject: [Qemu-devel] [PATCH 3/4] dump: extract out get note size function
Date: Wed, 20 Jun 2012 22:58:22 +0530 [thread overview]
Message-ID: <1340213303-596-3-git-send-email-rabin@rab.in> (raw)
In-Reply-To: <1340213303-596-1-git-send-email-rabin@rab.in>
Extract out the ELF note size function from i386 so we can use it from
other targets.
Signed-off-by: Rabin Vincent <rabin@rab.in>
---
dump.c | 15 +++++++++++++++
dump.h | 2 ++
target-i386/arch_dump.c | 14 ++------------
3 files changed, 19 insertions(+), 12 deletions(-)
diff --git a/dump.c b/dump.c
index be96c6c..d3ca953 100644
--- a/dump.c
+++ b/dump.c
@@ -468,6 +468,21 @@ static target_phys_addr_t get_offset(target_phys_addr_t phys_addr,
return -1;
}
+size_t dump_get_note_size(int class, const char *name, size_t descsz)
+{
+ int name_size = strlen(name) + 1;
+ int note_head_size;
+
+ if (class == ELFCLASS32) {
+ note_head_size = sizeof(Elf32_Nhdr);
+ } else {
+ note_head_size = sizeof(Elf64_Nhdr);
+ }
+
+ return ((note_head_size + 3) / 4 + (name_size + 3) / 4
+ + (descsz + 3) / 4) * 4;
+}
+
int dump_write_elf_note(int class, const char *name, uint32_t type,
void *desc, size_t descsz,
write_core_dump_function f, void *opaque)
diff --git a/dump.h b/dump.h
index b07816a..a06b149 100644
--- a/dump.h
+++ b/dump.h
@@ -36,4 +36,6 @@ int dump_write_elf_note(int class, const char *name, uint32_t type, void *desc,
size_t descsz, write_core_dump_function f,
void *opaque);
+size_t dump_get_note_size(int class, const char *name, size_t descsz);
+
#endif
diff --git a/target-i386/arch_dump.c b/target-i386/arch_dump.c
index dbc94bc..e2d18a0 100644
--- a/target-i386/arch_dump.c
+++ b/target-i386/arch_dump.c
@@ -305,18 +305,10 @@ int cpu_get_dump_info(ArchDumpInfo *info)
ssize_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);
@@ -328,10 +320,8 @@ ssize_t cpu_get_note_size(int class, int machine, int nr_cpus)
#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;
+ elf_note_size = dump_get_note_size(class, "CORE", elf_desc_size);
+ qemu_note_size = dump_get_note_size(class, "QEMU", qemu_desc_size);
return (elf_note_size + qemu_note_size) * nr_cpus;
}
--
1.7.9.5
next prev parent reply other threads:[~2012-06-20 17:28 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-06-20 17:28 [Qemu-devel] [PATCH 1/4] dump: create writable files Rabin Vincent
2012-06-20 17:28 ` [Qemu-devel] [PATCH 2/4] dump: extract out note helper Rabin Vincent
2012-07-04 2:21 ` Wen Congyang
2012-07-04 2:31 ` Wen Congyang
2012-06-20 17:28 ` Rabin Vincent [this message]
2012-07-04 2:25 ` [Qemu-devel] [PATCH 3/4] dump: extract out get note size function Wen Congyang
2012-06-20 17:28 ` [Qemu-devel] [PATCH 4/4] target-arm: add minimal dump-guest-memory support Rabin Vincent
[not found] ` <CAFEAcA_x1HKmzgdjbi1Xv90Kwn3fwL3U3+_hiaO0wkTiNFR4pA@mail.gmail.com>
2012-07-01 6:22 ` Rabin Vincent
2012-07-04 2:48 ` Wen Congyang
[not found] ` <4FEDA2C0.7040405@suse.de>
2012-07-04 2:57 ` Wen Congyang
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=1340213303-596-3-git-send-email-rabin@rab.in \
--to=rabin@rab.in \
--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).