[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v3 17/19] contrib/elf2dmp: Use GPtrArray
From: |
Akihiko Odaki |
Subject: |
[PATCH v3 17/19] contrib/elf2dmp: Use GPtrArray |
Date: |
Wed, 06 Mar 2024 15:12:23 +0900 |
This removes the need to enumarate QEMUCPUState twice and saves code.
Signed-off-by: Akihiko Odaki <akihiko.odaki@daynix.com>
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
---
contrib/elf2dmp/qemu_elf.c | 25 ++++++++-----------------
1 file changed, 8 insertions(+), 17 deletions(-)
diff --git a/contrib/elf2dmp/qemu_elf.c b/contrib/elf2dmp/qemu_elf.c
index a22c057d3ec3..7d896cac5b15 100644
--- a/contrib/elf2dmp/qemu_elf.c
+++ b/contrib/elf2dmp/qemu_elf.c
@@ -66,7 +66,7 @@ static bool init_states(QEMU_Elf *qe)
Elf64_Nhdr *start = (void *)((uint8_t *)qe->map + phdr[0].p_offset);
Elf64_Nhdr *end = (void *)((uint8_t *)start + phdr[0].p_memsz);
Elf64_Nhdr *nhdr;
- size_t cpu_nr = 0;
+ GPtrArray *states;
if (phdr[0].p_type != PT_NOTE) {
eprintf("Failed to find PT_NOTE\n");
@@ -74,38 +74,29 @@ static bool init_states(QEMU_Elf *qe)
}
qe->has_kernel_gs_base = 1;
+ states = g_ptr_array_new();
for (nhdr = start; nhdr < end; nhdr = nhdr_get_next(nhdr)) {
if (!strcmp(nhdr_get_name(nhdr), QEMU_NOTE_NAME)) {
QEMUCPUState *state = nhdr_get_desc(nhdr);
if (state->size < sizeof(*state)) {
- eprintf("CPU #%zu: QEMU CPU state size %u doesn't match\n",
- cpu_nr, state->size);
+ eprintf("CPU #%u: QEMU CPU state size %u doesn't match\n",
+ states->len, state->size);
/*
* We assume either every QEMU CPU state has KERNEL_GS_BASE or
* no one has.
*/
qe->has_kernel_gs_base = 0;
}
- cpu_nr++;
+ g_ptr_array_add(states, state);
}
}
- printf("%zu CPU states has been found\n", cpu_nr);
+ printf("%u CPU states has been found\n", states->len);
- qe->state = g_new(QEMUCPUState*, cpu_nr);
-
- cpu_nr = 0;
-
- for (nhdr = start; nhdr < end; nhdr = nhdr_get_next(nhdr)) {
- if (!strcmp(nhdr_get_name(nhdr), QEMU_NOTE_NAME)) {
- qe->state[cpu_nr] = nhdr_get_desc(nhdr);
- cpu_nr++;
- }
- }
-
- qe->state_nr = cpu_nr;
+ qe->state_nr = states->len;
+ qe->state = (void *)g_ptr_array_free(states, FALSE);
return true;
}
--
2.44.0
- [PATCH v3 10/19] contrib/elf2dmp: Always check for PA resolution failure, (continued)
- [PATCH v3 10/19] contrib/elf2dmp: Always check for PA resolution failure, Akihiko Odaki, 2024/03/06
- [PATCH v3 02/19] contrib/elf2dmp: Assume error by default, Akihiko Odaki, 2024/03/06
- [PATCH v3 09/19] contrib/elf2dmp: Fix error reporting style in main.c, Akihiko Odaki, 2024/03/06
- [PATCH v3 12/19] contrib/elf2dmp: Ensure segment fits in file, Akihiko Odaki, 2024/03/06
- [PATCH v3 14/19] contrib/elf2dmp: Use rol64() to decode, Akihiko Odaki, 2024/03/06
- [PATCH v3 11/19] contrib/elf2dmp: Always destroy PA space, Akihiko Odaki, 2024/03/06
- [PATCH v3 13/19] contrib/elf2dmp: Use lduw_le_p() to read PDB, Akihiko Odaki, 2024/03/06
- [PATCH v3 15/19] MAINTAINERS: Add Akihiko Odaki as a elf2dmp reviewer, Akihiko Odaki, 2024/03/06
- [PATCH v3 16/19] contrib/elf2dmp: Build only for little endian host, Akihiko Odaki, 2024/03/06
- [PATCH v3 19/19] contrib/elf2dmp: Ensure phdrs fit in file, Akihiko Odaki, 2024/03/06
- [PATCH v3 17/19] contrib/elf2dmp: Use GPtrArray,
Akihiko Odaki <=
- [PATCH v3 18/19] contrib/elf2dmp: Clamp QEMU note to file size, Akihiko Odaki, 2024/03/06