Skip to content

Commit

Permalink
Fix wrong number of registers (#98)
Browse files Browse the repository at this point in the history
* fix num regs in case it's stored in xml file
  • Loading branch information
rmalmain authored Jan 13, 2025
1 parent ace3646 commit 2b5e4bf
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions libafl/cpu.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
int gdb_write_register(CPUState* cpu, uint8_t* mem_buf, int reg);

static __thread GByteArray* libafl_qemu_mem_buf = NULL;
static __thread int num_regs = 0;

#ifdef CONFIG_USER_ONLY
static __thread CPUArchState* libafl_qemu_env;
Expand Down Expand Up @@ -133,8 +134,22 @@ int libafl_qemu_read_reg(CPUState* cpu, int reg, uint8_t* val)

int libafl_qemu_num_regs(CPUState* cpu)
{
CPUClass* cc = CPU_GET_CLASS(cpu);
return cc->gdb_num_core_regs;
if (!num_regs) {
CPUClass* cc = CPU_GET_CLASS(cpu);

if (cc->gdb_num_core_regs) {
num_regs = cc->gdb_num_core_regs;
} else {
const GDBFeature *feature = gdb_find_static_feature(cc->gdb_core_xml_file);

g_assert(feature);
g_assert(feature->num_regs > 0);

num_regs = feature->num_regs;
}
}

return num_regs;
}

void libafl_flush_jit(void)
Expand Down

0 comments on commit 2b5e4bf

Please sign in to comment.