diff mbox series

[v2,1/3] hmp: fix "dump-quest-memory" segfault (ppc)

Message ID 20170911142056.15643-2-lvivier@redhat.com
State New
Headers show
Series hmp: fix "dump-quest-memory" segfault | expand

Commit Message

Laurent Vivier Sept. 11, 2017, 2:20 p.m. UTC
Commit fd5d23babf (hmp: fix "dump-quest-memory" segfault)
fixes the problem for i386, do the same for ppc.

Running QEMU with
    qemu-system-ppc64 -M none -nographic -m 256
and executing
    dump-guest-memory /dev/null 0 8192
results in segfault

Fix by checking if we have CPU.

Signed-off-by: Laurent Vivier <lvivier@redhat.com>
Reviewed-by: Greg Kurz <groug@kaod.org>
---
 target/ppc/arch_dump.c | 17 +++++++++++------
 1 file changed, 11 insertions(+), 6 deletions(-)
diff mbox series

Patch

diff --git a/target/ppc/arch_dump.c b/target/ppc/arch_dump.c
index 8e9397aa58..dcb7b19950 100644
--- a/target/ppc/arch_dump.c
+++ b/target/ppc/arch_dump.c
@@ -224,17 +224,22 @@  typedef struct NoteFuncDescStruct NoteFuncDesc;
 int cpu_get_dump_info(ArchDumpInfo *info,
                       const struct GuestPhysBlockList *guest_phys_blocks)
 {
-    PowerPCCPU *cpu = POWERPC_CPU(first_cpu);
-    PowerPCCPUClass *pcc = POWERPC_CPU_GET_CLASS(cpu);
-
     info->d_machine = PPC_ELF_MACHINE;
     info->d_class = ELFCLASS;
 
-    if ((*pcc->interrupts_big_endian)(cpu)) {
-        info->d_endian = ELFDATA2MSB;
+    if (first_cpu) {
+        PowerPCCPU *cpu = POWERPC_CPU(first_cpu);
+        PowerPCCPUClass *pcc = POWERPC_CPU_GET_CLASS(cpu);
+
+        if ((*pcc->interrupts_big_endian)(cpu)) {
+            info->d_endian = ELFDATA2MSB;
+        } else {
+            info->d_endian = ELFDATA2LSB;
+        }
     } else {
-        info->d_endian = ELFDATA2LSB;
+        info->d_endian = ELFDATA2MSB;
     }
+
     /* 64KB is the max page size for pseries kernel */
     if (strncmp(object_get_typename(qdev_get_machine()),
                 "pseries-", 8) == 0) {