[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH qom-cpu v4 16/18] dump: Abstract write_elf{64, 32}_n
From: |
Andreas Färber |
Subject: |
[Qemu-devel] [PATCH qom-cpu v4 16/18] dump: Abstract write_elf{64, 32}_notes() with qemu_for_each_cpu() |
Date: |
Sun, 9 Jun 2013 18:10:45 +0200 |
Removes the last use of CPUArchState.
Signed-off-by: Andreas Färber <address@hidden>
---
dump.c | 133 +++++++++++++++++++++++++++++++++++++++++++++++------------------
1 file changed, 97 insertions(+), 36 deletions(-)
diff --git a/dump.c b/dump.c
index 4e6b855..d3cb8e2 100644
--- a/dump.c
+++ b/dump.c
@@ -273,29 +273,62 @@ static inline int cpu_index(CPUState *cpu)
return cpu->cpu_index + 1;
}
-static int write_elf64_notes(DumpState *s)
-{
- CPUArchState *env;
- CPUState *cpu;
+typedef struct WriteELFNoteData {
+ DumpState *state;
int ret;
+} WriteELFNoteData;
+
+static void write_one_elf64_note(CPUState *cpu, void *data)
+{
+ WriteELFNoteData *d = data;
int id;
+ int ret;
- for (env = first_cpu; env != NULL; env = env->next_cpu) {
- cpu = ENV_GET_CPU(env);
- id = cpu_index(cpu);
- ret = cpu_write_elf64_note(fd_write_vmcore, cpu, id, s);
- if (ret < 0) {
- dump_error(s, "dump: failed to write elf notes.\n");
- return -1;
- }
+ if (d->ret != 0) {
+ return;
}
- for (env = first_cpu; env != NULL; env = env->next_cpu) {
- ret = cpu_write_elf64_qemunote(fd_write_vmcore, cpu, s);
- if (ret < 0) {
- dump_error(s, "dump: failed to write CPU status.\n");
- return -1;
- }
+ id = cpu_index(cpu);
+ ret = cpu_write_elf64_note(fd_write_vmcore, cpu, id, d->state);
+ if (ret < 0) {
+ dump_error(d->state, "dump: failed to write elf notes.\n");
+ d->ret = -1;
+ return;
+ }
+}
+
+static void write_one_elf64_qemunote(CPUState *cpu, void *data)
+{
+ WriteELFNoteData *d = data;
+ int ret;
+
+ if (d->ret != 0) {
+ return;
+ }
+
+ ret = cpu_write_elf64_qemunote(fd_write_vmcore, cpu, d->state);
+ if (ret < 0) {
+ dump_error(d->state, "dump: failed to write CPU status.\n");
+ d->ret = -1;
+ return;
+ }
+}
+
+static int write_elf64_notes(DumpState *s)
+{
+ WriteELFNoteData data = {
+ .state = s,
+ .ret = 0,
+ };
+
+ qemu_for_each_cpu(write_one_elf64_note, &data);
+ if (data.ret != 0) {
+ return data.ret;
+ }
+
+ qemu_for_each_cpu(write_one_elf64_qemunote, &data);
+ if (data.ret != 0) {
+ return data.ret;
}
return 0;
@@ -325,29 +358,57 @@ static int write_elf32_note(DumpState *s)
return 0;
}
-static int write_elf32_notes(DumpState *s)
+static void write_one_elf32_note(CPUState *cpu, void *data)
{
- CPUArchState *env;
- CPUState *cpu;
- int ret;
+ WriteELFNoteData *d = data;
int id;
+ int ret;
- for (env = first_cpu; env != NULL; env = env->next_cpu) {
- cpu = ENV_GET_CPU(env);
- id = cpu_index(cpu);
- ret = cpu_write_elf32_note(fd_write_vmcore, cpu, id, s);
- if (ret < 0) {
- dump_error(s, "dump: failed to write elf notes.\n");
- return -1;
- }
+ if (d->ret != 0) {
+ return;
}
- for (env = first_cpu; env != NULL; env = env->next_cpu) {
- ret = cpu_write_elf32_qemunote(fd_write_vmcore, cpu, s);
- if (ret < 0) {
- dump_error(s, "dump: failed to write CPU status.\n");
- return -1;
- }
+ id = cpu_index(cpu);
+ ret = cpu_write_elf32_note(fd_write_vmcore, cpu, id, d->state);
+ if (ret < 0) {
+ dump_error(d->state, "dump: failed to write elf notes.\n");
+ d->ret = -1;
+ return;
+ }
+}
+
+static void write_one_elf32_qemunote(CPUState *cpu, void *data)
+{
+ WriteELFNoteData *d = data;
+ int ret;
+
+ if (d->ret != 0) {
+ return;
+ }
+
+ ret = cpu_write_elf32_qemunote(fd_write_vmcore, cpu, d->state);
+ if (ret < 0) {
+ dump_error(d->state, "dump: failed to write CPU status.\n");
+ d->ret = -1;
+ return;
+ }
+}
+
+static int write_elf32_notes(DumpState *s)
+{
+ WriteELFNoteData data = {
+ .state = s,
+ .ret = 0,
+ };
+
+ qemu_for_each_cpu(write_one_elf32_note, &data);
+ if (data.ret != 0) {
+ return data.ret;
+ }
+
+ qemu_for_each_cpu(write_one_elf32_qemunote, &data);
+ if (data.ret != 0) {
+ return data.ret;
}
return 0;
--
1.8.1.4
- Re: [Qemu-devel] [PATCH qom-cpu v4 14/18] dump: Abstract dump_init() with cpu_synchronize_all_states(), (continued)
- [Qemu-devel] [PATCH qom-cpu v4 12/18] cpu: Change default for CPUClass::get_paging_enabled(), Andreas Färber, 2013/06/09
- [Qemu-devel] [PATCH qom-cpu v4 13/18] memory_mapping: Cleanup qemu_get_guest_memory_mapping(), Andreas Färber, 2013/06/09
- [Qemu-devel] [PATCH qom-cpu v4 15/18] dump: Abstract dump_init() further with qemu_for_each_cpu(), Andreas Färber, 2013/06/09
- [Qemu-devel] [PATCH qom-cpu v4 16/18] dump: Abstract write_elf{64, 32}_notes() with qemu_for_each_cpu(),
Andreas Färber <=
- [Qemu-devel] [PATCH qom-cpu v4 17/18] memory_mapping: Use hwaddr type for MemoryMapping virt_addr field, Andreas Färber, 2013/06/09
- [Qemu-devel] [PATCH qom-cpu v4 18/18] memory_mapping: Build only once, Andreas Färber, 2013/06/09
- Re: [Qemu-devel] [PATCH qom-cpu v4 00/18] dump: Build cleanups, redone, Andreas Färber, 2013/06/09
- Re: [Qemu-devel] [PATCH qom-cpu v4 00/18] dump: Build cleanups, redone, Andreas Färber, 2013/06/11