[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 09/46] memory: follow Error API guidelines
From: |
Philippe Mathieu-Daudé |
Subject: |
[PULL 09/46] memory: follow Error API guidelines |
Date: |
Thu, 19 Oct 2023 23:17:34 +0200 |
From: Marc-André Lureau <marcandre.lureau@redhat.com>
Return true/false on success/failure.
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Reviewed-by: David Hildenbrand <david@redhat.com>
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Message-ID: <20231009075310.153617-1-marcandre.lureau@redhat.com>
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
include/hw/core/cpu.h | 4 +++-
include/hw/core/sysemu-cpu-ops.h | 2 +-
include/sysemu/memory_mapping.h | 2 +-
target/i386/cpu.h | 2 +-
hw/core/cpu-sysemu.c | 6 +++---
system/memory_mapping.c | 13 ++++++-------
target/i386/arch_memory_mapping.c | 6 ++++--
7 files changed, 19 insertions(+), 16 deletions(-)
diff --git a/include/hw/core/cpu.h b/include/hw/core/cpu.h
index 3968369554..18593db5b2 100644
--- a/include/hw/core/cpu.h
+++ b/include/hw/core/cpu.h
@@ -618,8 +618,10 @@ bool cpu_paging_enabled(const CPUState *cpu);
* @cpu: The CPU whose memory mappings are to be obtained.
* @list: Where to write the memory mappings to.
* @errp: Pointer for reporting an #Error.
+ *
+ * Returns: %true on success, %false otherwise.
*/
-void cpu_get_memory_mapping(CPUState *cpu, MemoryMappingList *list,
+bool cpu_get_memory_mapping(CPUState *cpu, MemoryMappingList *list,
Error **errp);
#if !defined(CONFIG_USER_ONLY)
diff --git a/include/hw/core/sysemu-cpu-ops.h b/include/hw/core/sysemu-cpu-ops.h
index ee169b872c..24d003fe04 100644
--- a/include/hw/core/sysemu-cpu-ops.h
+++ b/include/hw/core/sysemu-cpu-ops.h
@@ -19,7 +19,7 @@ typedef struct SysemuCPUOps {
/**
* @get_memory_mapping: Callback for obtaining the memory mappings.
*/
- void (*get_memory_mapping)(CPUState *cpu, MemoryMappingList *list,
+ bool (*get_memory_mapping)(CPUState *cpu, MemoryMappingList *list,
Error **errp);
/**
* @get_paging_enabled: Callback for inquiring whether paging is enabled.
diff --git a/include/sysemu/memory_mapping.h b/include/sysemu/memory_mapping.h
index 3bbeb1bcb4..021e0a6230 100644
--- a/include/sysemu/memory_mapping.h
+++ b/include/sysemu/memory_mapping.h
@@ -71,7 +71,7 @@ void guest_phys_blocks_free(GuestPhysBlockList *list);
void guest_phys_blocks_init(GuestPhysBlockList *list);
void guest_phys_blocks_append(GuestPhysBlockList *list);
-void qemu_get_guest_memory_mapping(MemoryMappingList *list,
+bool qemu_get_guest_memory_mapping(MemoryMappingList *list,
const GuestPhysBlockList *guest_phys_blocks,
Error **errp);
diff --git a/target/i386/cpu.h b/target/i386/cpu.h
index e1875466b9..471e71dbc5 100644
--- a/target/i386/cpu.h
+++ b/target/i386/cpu.h
@@ -2055,7 +2055,7 @@ int x86_cpu_write_elf64_qemunote(WriteCoreDumpFunction f,
CPUState *cpu,
int x86_cpu_write_elf32_qemunote(WriteCoreDumpFunction f, CPUState *cpu,
DumpState *s);
-void x86_cpu_get_memory_mapping(CPUState *cpu, MemoryMappingList *list,
+bool x86_cpu_get_memory_mapping(CPUState *cpu, MemoryMappingList *list,
Error **errp);
void x86_cpu_dump_state(CPUState *cs, FILE *f, int flags);
diff --git a/hw/core/cpu-sysemu.c b/hw/core/cpu-sysemu.c
index 5eaf2e79e6..d0d6a910f9 100644
--- a/hw/core/cpu-sysemu.c
+++ b/hw/core/cpu-sysemu.c
@@ -34,17 +34,17 @@ bool cpu_paging_enabled(const CPUState *cpu)
return false;
}
-void cpu_get_memory_mapping(CPUState *cpu, MemoryMappingList *list,
+bool cpu_get_memory_mapping(CPUState *cpu, MemoryMappingList *list,
Error **errp)
{
CPUClass *cc = CPU_GET_CLASS(cpu);
if (cc->sysemu_ops->get_memory_mapping) {
- cc->sysemu_ops->get_memory_mapping(cpu, list, errp);
- return;
+ return cc->sysemu_ops->get_memory_mapping(cpu, list, errp);
}
error_setg(errp, "Obtaining memory mappings is unsupported on this CPU.");
+ return false;
}
hwaddr cpu_get_phys_page_attrs_debug(CPUState *cpu, vaddr addr,
diff --git a/system/memory_mapping.c b/system/memory_mapping.c
index 8ba9968f8c..6f884c5b90 100644
--- a/system/memory_mapping.c
+++ b/system/memory_mapping.c
@@ -304,10 +304,11 @@ static CPUState *find_paging_enabled_cpu(void)
return NULL;
}
-void qemu_get_guest_memory_mapping(MemoryMappingList *list,
+bool qemu_get_guest_memory_mapping(MemoryMappingList *list,
const GuestPhysBlockList *guest_phys_blocks,
Error **errp)
{
+ ERRP_GUARD();
CPUState *cpu, *first_paging_enabled_cpu;
GuestPhysBlock *block;
ram_addr_t offset, length;
@@ -316,14 +317,11 @@ void qemu_get_guest_memory_mapping(MemoryMappingList
*list,
if (first_paging_enabled_cpu) {
for (cpu = first_paging_enabled_cpu; cpu != NULL;
cpu = CPU_NEXT(cpu)) {
- Error *err = NULL;
- cpu_get_memory_mapping(cpu, list, &err);
- if (err) {
- error_propagate(errp, err);
- return;
+ if (!cpu_get_memory_mapping(cpu, list, errp)) {
+ return false;
}
}
- return;
+ return true;
}
/*
@@ -335,6 +333,7 @@ void qemu_get_guest_memory_mapping(MemoryMappingList *list,
length = block->target_end - block->target_start;
create_new_memory_mapping(list, offset, offset, length);
}
+ return true;
}
void qemu_get_guest_simple_memory_mapping(MemoryMappingList *list,
diff --git a/target/i386/arch_memory_mapping.c
b/target/i386/arch_memory_mapping.c
index 271cb5e41b..d1ff659128 100644
--- a/target/i386/arch_memory_mapping.c
+++ b/target/i386/arch_memory_mapping.c
@@ -266,7 +266,7 @@ static void walk_pml5e(MemoryMappingList *list,
AddressSpace *as,
}
#endif
-void x86_cpu_get_memory_mapping(CPUState *cs, MemoryMappingList *list,
+bool x86_cpu_get_memory_mapping(CPUState *cs, MemoryMappingList *list,
Error **errp)
{
X86CPU *cpu = X86_CPU(cs);
@@ -275,7 +275,7 @@ void x86_cpu_get_memory_mapping(CPUState *cs,
MemoryMappingList *list,
if (!cpu_paging_enabled(cs)) {
/* paging is disabled */
- return;
+ return true;
}
a20_mask = x86_get_a20_mask(env);
@@ -310,5 +310,7 @@ void x86_cpu_get_memory_mapping(CPUState *cs,
MemoryMappingList *list,
pse = !!(env->cr[4] & CR4_PSE_MASK);
walk_pde2(list, cs->as, pde_addr, a20_mask, pse);
}
+
+ return true;
}
--
2.41.0
- [PULL 00/46] Misc HW/UI patches for 2023-10-19, Philippe Mathieu-Daudé, 2023/10/19
- [PULL 02/46] MAINTAINERS: Split vt82c686 out of fuloong2e, Philippe Mathieu-Daudé, 2023/10/19
- [PULL 01/46] mailmap: update email addresses for Luc Michel, Philippe Mathieu-Daudé, 2023/10/19
- [PULL 03/46] MAINTAINERS: Add hw/input/lasips2.c to the HPPA machine section, Philippe Mathieu-Daudé, 2023/10/19
- [PULL 04/46] MAINTAINERS: Add include/hw/intc/loongson_liointc.h to the Loongson-3 virt section, Philippe Mathieu-Daudé, 2023/10/19
- [PULL 05/46] MAINTAINERS: Add include/hw/openrisc/ to the OpenRISC section, Philippe Mathieu-Daudé, 2023/10/19
- [PULL 06/46] cutils: Fix get_relocated_path on Windows, Philippe Mathieu-Daudé, 2023/10/19
- [PULL 07/46] buildsys: Only display Objective-C information when Objective-C is used, Philippe Mathieu-Daudé, 2023/10/19
- [PULL 08/46] memory: drop needless argument, Philippe Mathieu-Daudé, 2023/10/19
- [PULL 09/46] memory: follow Error API guidelines,
Philippe Mathieu-Daudé <=
- [PULL 10/46] hw/sd/sdhci: Block Size Register bits [14:12] is lost, Philippe Mathieu-Daudé, 2023/10/19
- [PULL 11/46] hw/mips/malta: Use sdram_type enum from 'hw/i2c/smbus_eeprom.h', Philippe Mathieu-Daudé, 2023/10/19
- [PULL 12/46] hw/mips: Merge 'hw/mips/cpudevs.h' with 'target/mips/cpu.h', Philippe Mathieu-Daudé, 2023/10/19
- [PULL 13/46] hw/misc/mips_itu: Declare itc_reconfigure() in 'hw/misc/mips_itu.h', Philippe Mathieu-Daudé, 2023/10/19
- [PULL 14/46] hw/misc/mips_itu: Make MIPSITUState target agnostic, Philippe Mathieu-Daudé, 2023/10/19
- [PULL 15/46] hw/pci-host/sh_pcic: Declare CPU QOM types using DEFINE_TYPES() macro, Philippe Mathieu-Daudé, 2023/10/19
- [PULL 16/46] hw/pci-host/sh_pcic: Correct PCI host / devfn#0 function names, Philippe Mathieu-Daudé, 2023/10/19
- [PULL 17/46] hw/pci-host/sh_pcic: Replace magic value by proper definition, Philippe Mathieu-Daudé, 2023/10/19
- [PULL 18/46] hw/sparc64/ebus: Access memory regions via pci_address_space_io(), Philippe Mathieu-Daudé, 2023/10/19
- [PULL 19/46] hw/acpi/pcihp: Clean up global variable shadowing in acpi_pcihp_init(), Philippe Mathieu-Daudé, 2023/10/19