Skip to content

Commit

Permalink
memory: follow Error API guidelines
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
elmarco authored and philmd committed Oct 20, 2023
1 parent 85f3d50 commit 1ff5f4d
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 16 deletions.
6 changes: 3 additions & 3 deletions hw/core/cpu-sysemu.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 3 additions & 1 deletion include/hw/core/cpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion include/hw/core/sysemu-cpu-ops.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion include/sysemu/memory_mapping.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
13 changes: 6 additions & 7 deletions system/memory_mapping.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}

/*
Expand All @@ -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,
Expand Down
6 changes: 4 additions & 2 deletions target/i386/arch_memory_mapping.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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 changes: 1 addition & 1 deletion target/i386/cpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 1ff5f4d

Please sign in to comment.