Skip to content

Commit b57cee7

Browse files
committed
small perf improvement
1 parent 5348a03 commit b57cee7

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

libafl/cpu.c

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
int gdb_write_register(CPUState* cpu, uint8_t* mem_buf, int reg);
2020

2121
static __thread GByteArray* libafl_qemu_mem_buf = NULL;
22+
static __thread int num_regs = 0;
2223

2324
#ifdef CONFIG_USER_ONLY
2425
static __thread CPUArchState* libafl_qemu_env;
@@ -133,16 +134,22 @@ int libafl_qemu_read_reg(CPUState* cpu, int reg, uint8_t* val)
133134

134135
int libafl_qemu_num_regs(CPUState* cpu)
135136
{
136-
CPUClass* cc = CPU_GET_CLASS(cpu);
137+
if (!num_regs) {
138+
CPUClass* cc = CPU_GET_CLASS(cpu);
137139

138-
if (cc->gdb_num_core_regs) {
139-
return cc->gdb_num_core_regs;
140-
} else {
141-
const GDBFeature *feature = gdb_find_static_feature(cc->gdb_core_xml_file);
142-
g_assert(feature);
140+
if (cc->gdb_num_core_regs) {
141+
num_regs = cc->gdb_num_core_regs;
142+
} else {
143+
const GDBFeature *feature = gdb_find_static_feature(cc->gdb_core_xml_file);
143144

144-
return feature->num_regs;
145+
g_assert(feature);
146+
g_assert(feature->num_regs > 0);
147+
148+
num_regs = feature->num_regs;
149+
}
145150
}
151+
152+
return num_regs;
146153
}
147154

148155
void libafl_flush_jit(void)

0 commit comments

Comments
 (0)