Added paging id boilerplate code + x86_64 implementation.

This commit is contained in:
Romain Malmain 2023-11-30 17:27:34 +01:00
parent c105904e66
commit 9928452ab6
4 changed files with 45 additions and 0 deletions

View File

@ -61,6 +61,14 @@ int libafl_qemu_write_reg(CPUState* cpu, int reg, uint8_t* val);
int libafl_qemu_read_reg(CPUState* cpu, int reg, uint8_t* val); int libafl_qemu_read_reg(CPUState* cpu, int reg, uint8_t* val);
int libafl_qemu_num_regs(CPUState* cpu); int libafl_qemu_num_regs(CPUState* cpu);
//// --- Begin LibAFL code ---
#ifndef CONFIG_USER_ONLY
hwaddr libafl_qemu_current_paging_id(CPUState* cpu);
#endif
//// --- End LibAFL code ---
void libafl_flush_jit(void); void libafl_flush_jit(void);
extern int libafl_restoring_devices; extern int libafl_restoring_devices;
@ -153,6 +161,18 @@ int libafl_qemu_num_regs(CPUState* cpu)
return cc->gdb_num_core_regs; return cc->gdb_num_core_regs;
} }
//// --- Begin LibAFL code ---
#ifndef CONFIG_USER_ONLY
hwaddr libafl_qemu_current_paging_id(CPUState* cpu)
{
CPUClass* cc = CPU_GET_CLASS(cpu);
return cc->sysemu_ops->get_paging_id(cpu);
}
#endif
//// --- End LibAFL code ---
void libafl_flush_jit(void) void libafl_flush_jit(void)
{ {
CPUState *cpu; CPUState *cpu;

View File

@ -25,6 +25,12 @@ typedef struct SysemuCPUOps {
* @get_paging_enabled: Callback for inquiring whether paging is enabled. * @get_paging_enabled: Callback for inquiring whether paging is enabled.
*/ */
bool (*get_paging_enabled)(const CPUState *cpu); bool (*get_paging_enabled)(const CPUState *cpu);
//// --- Begin LibAFL code ---
/**
* @get_paging_id: Callback for inquiring paging ID (makes sense iif @get_paging_enabled is true).
*/
hwaddr (*get_paging_id)(const CPUState* cpu);
//// --- End LibAFL code ---
/** /**
* @get_phys_page_debug: Callback for obtaining a physical address. * @get_phys_page_debug: Callback for obtaining a physical address.
*/ */

View File

@ -7654,6 +7654,18 @@ static bool x86_cpu_get_paging_enabled(const CPUState *cs)
return cpu->env.cr[0] & CR0_PG_MASK; return cpu->env.cr[0] & CR0_PG_MASK;
} }
//// --- Begin LibAFL code ---
static hwaddr x86_cpu_get_paging_id(const CPUState *cs)
{
X86CPU *cpu = X86_CPU(cs);
return cpu->env.cr[3] & CR3_PD_BASE;
}
//// --- End LibAFL code ---
#endif /* !CONFIG_USER_ONLY */ #endif /* !CONFIG_USER_ONLY */
static void x86_cpu_set_pc(CPUState *cs, vaddr value) static void x86_cpu_set_pc(CPUState *cs, vaddr value)
@ -7922,6 +7934,7 @@ static Property x86_cpu_properties[] = {
static const struct SysemuCPUOps i386_sysemu_ops = { static const struct SysemuCPUOps i386_sysemu_ops = {
.get_memory_mapping = x86_cpu_get_memory_mapping, .get_memory_mapping = x86_cpu_get_memory_mapping,
.get_paging_enabled = x86_cpu_get_paging_enabled, .get_paging_enabled = x86_cpu_get_paging_enabled,
.get_paging_id = x86_cpu_get_paging_id,
.get_phys_page_attrs_debug = x86_cpu_get_phys_page_attrs_debug, .get_phys_page_attrs_debug = x86_cpu_get_phys_page_attrs_debug,
.asidx_from_attrs = x86_asidx_from_attrs, .asidx_from_attrs = x86_asidx_from_attrs,
.get_crash_info = x86_cpu_get_crash_info, .get_crash_info = x86_cpu_get_crash_info,

View File

@ -238,6 +238,12 @@ typedef enum X86Seg {
#define CR0_CD_MASK (1U << 30) #define CR0_CD_MASK (1U << 30)
#define CR0_PG_MASK (1U << 31) #define CR0_PG_MASK (1U << 31)
//// --- Begin LibAFL code ---
#define CR3_PD_BASE (~(((((target_ulong) 1U) << 12) - 1)))
//// --- End LibAFL code ---
#define CR4_VME_MASK (1U << 0) #define CR4_VME_MASK (1U << 0)
#define CR4_PVI_MASK (1U << 1) #define CR4_PVI_MASK (1U << 1)
#define CR4_TSD_MASK (1U << 2) #define CR4_TSD_MASK (1U << 2)