From 63f75dad339a4c36f44c1d35a52c2128b66e03ae Mon Sep 17 00:00:00 2001 From: Romain Malmain Date: Tue, 13 Aug 2024 19:17:46 +0200 Subject: [PATCH] fmt --- include/libafl/cpu.h | 2 +- include/libafl/gdb.h | 3 ++- include/libafl/user.h | 1 - libafl/cpu.c | 45 +++++++++++++++---------------- libafl/gdb.c | 12 ++++++--- libafl/syx-snapshot/device-save.c | 4 +-- libafl/user.c | 20 ++++++-------- 7 files changed, 41 insertions(+), 46 deletions(-) diff --git a/include/libafl/cpu.h b/include/libafl/cpu.h index a786d1f023..5fca7ca0e5 100644 --- a/include/libafl/cpu.h +++ b/include/libafl/cpu.h @@ -22,7 +22,7 @@ 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_num_regs(CPUState* cpu); void libafl_flush_jit(void); -void libafl_breakpoint_invalidate(CPUState *cpu, target_ulong pc); +void libafl_breakpoint_invalidate(CPUState* cpu, target_ulong pc); int libafl_qemu_main(void); int libafl_qemu_run(void); diff --git a/include/libafl/gdb.h b/include/libafl/gdb.h index 65cfd0ac6e..94e7debffb 100644 --- a/include/libafl/gdb.h +++ b/include/libafl/gdb.h @@ -8,6 +8,7 @@ struct libafl_custom_gdb_cmd { struct libafl_custom_gdb_cmd* next; }; -void libafl_qemu_add_gdb_cmd(bool (*callback)(void*, uint8_t*, size_t), void* data); +void libafl_qemu_add_gdb_cmd(bool (*callback)(void*, uint8_t*, size_t), + void* data); void libafl_qemu_gdb_reply(const uint8_t* buf, size_t len); bool libafl_qemu_gdb_exec(void); diff --git a/include/libafl/user.h b/include/libafl/user.h index a008c63dd7..69eba3995f 100644 --- a/include/libafl/user.h +++ b/include/libafl/user.h @@ -30,4 +30,3 @@ struct image_info* libafl_get_image_info(void); uint64_t libafl_get_brk(void); uint64_t libafl_set_brk(uint64_t new_brk); - diff --git a/libafl/cpu.c b/libafl/cpu.c index d5c0851a83..3b75bb56f0 100644 --- a/libafl/cpu.c +++ b/libafl/cpu.c @@ -13,10 +13,10 @@ #include "libafl/exit.h" #include "libafl/hook.h" -int gdb_write_register(CPUState *cpu, uint8_t *mem_buf, int reg); +int gdb_write_register(CPUState* cpu, uint8_t* mem_buf, int reg); -static __thread GByteArray *libafl_qemu_mem_buf = NULL; -static __thread CPUArchState *libafl_qemu_env; +static __thread GByteArray* libafl_qemu_mem_buf = NULL; +static __thread CPUArchState* libafl_qemu_env; #ifndef CONFIG_USER_ONLY uint8_t* libafl_paddr2host(CPUState* cpu, hwaddr addr, bool is_write) @@ -46,28 +46,30 @@ hwaddr libafl_qemu_current_paging_id(CPUState* cpu) } } -void libafl_breakpoint_invalidate(CPUState *cpu, target_ulong pc) +void libafl_breakpoint_invalidate(CPUState* cpu, target_ulong pc) { // TODO invalidate only the virtual pages related to the TB tb_flush(cpu); } #else -void libafl_breakpoint_invalidate(CPUState *cpu, target_ulong pc) +void libafl_breakpoint_invalidate(CPUState* cpu, target_ulong pc) { - mmap_lock(); - tb_invalidate_phys_range(pc, pc + 1); - mmap_unlock(); + mmap_lock(); + tb_invalidate_phys_range(pc, pc + 1); + mmap_unlock(); } #endif -target_ulong libafl_page_from_addr(target_ulong addr) { +target_ulong libafl_page_from_addr(target_ulong addr) +{ return addr & TARGET_PAGE_MASK; } CPUState* libafl_qemu_get_cpu(int cpu_index) { - CPUState *cpu; - CPU_FOREACH(cpu) { + CPUState* cpu; + CPU_FOREACH(cpu) + { if (cpu->cpu_index == cpu_index) return cpu; } @@ -76,11 +78,9 @@ CPUState* libafl_qemu_get_cpu(int cpu_index) int libafl_qemu_num_cpus(void) { - CPUState *cpu; + CPUState* cpu; int num = 0; - CPU_FOREACH(cpu) { - num++; - } + CPU_FOREACH(cpu) { num++; } return num; } @@ -96,7 +96,8 @@ CPUState* libafl_qemu_current_cpu(void) int libafl_qemu_cpu_index(CPUState* cpu) { - if (cpu) return cpu->cpu_index; + if (cpu) + return cpu->cpu_index; return -1; } @@ -126,16 +127,14 @@ 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); + CPUClass* cc = CPU_GET_CLASS(cpu); return cc->gdb_num_core_regs; } void libafl_flush_jit(void) { - CPUState *cpu; - CPU_FOREACH(cpu) { - tb_flush(cpu); - } + CPUState* cpu; + CPU_FOREACH(cpu) { tb_flush(cpu); } } __attribute__((weak)) int libafl_qemu_main(void) @@ -150,6 +149,4 @@ int libafl_qemu_run(void) return 1; } -void libafl_set_qemu_env(CPUArchState* env) { - libafl_qemu_env = env; -} +void libafl_set_qemu_env(CPUArchState* env) { libafl_qemu_env = env; } diff --git a/libafl/gdb.c b/libafl/gdb.c index cc6d2d3075..9745287c46 100644 --- a/libafl/gdb.c +++ b/libafl/gdb.c @@ -4,9 +4,11 @@ static struct libafl_custom_gdb_cmd* libafl_qemu_gdb_cmds; -void libafl_qemu_add_gdb_cmd(bool (*callback)(void*, uint8_t*, size_t), void* data) +void libafl_qemu_add_gdb_cmd(bool (*callback)(void*, uint8_t*, size_t), + void* data) { - struct libafl_custom_gdb_cmd* c = malloc(sizeof(struct libafl_custom_gdb_cmd)); + struct libafl_custom_gdb_cmd* c = + malloc(sizeof(struct libafl_custom_gdb_cmd)); c->callback = callback; c->data = data; c->next = libafl_qemu_gdb_cmds; @@ -20,11 +22,13 @@ void libafl_qemu_gdb_reply(const uint8_t* buf, size_t len) gdb_put_packet(hex_buf->str); } -bool libafl_qemu_gdb_exec(void) { +bool libafl_qemu_gdb_exec(void) +{ struct libafl_custom_gdb_cmd** c = &libafl_qemu_gdb_cmds; bool recognized = false; while (*c) { - recognized |= (*c)->callback((*c)->data, gdbserver_state.mem_buf->data, gdbserver_state.mem_buf->len); + recognized |= (*c)->callback((*c)->data, gdbserver_state.mem_buf->data, + gdbserver_state.mem_buf->len); c = &(*c)->next; } return recognized; diff --git a/libafl/syx-snapshot/device-save.c b/libafl/syx-snapshot/device-save.c index 39b6f6e892..1b12e231c0 100644 --- a/libafl/syx-snapshot/device-save.c +++ b/libafl/syx-snapshot/device-save.c @@ -16,9 +16,7 @@ extern int vmstate_save(QEMUFile* f, SaveStateEntry* se, JSONWriter* vmdesc); static bool libafl_restoring_devices = false; -bool libafl_devices_is_restoring(void) { - return libafl_restoring_devices; -} +bool libafl_devices_is_restoring(void) { return libafl_restoring_devices; } // iothread must be locked DeviceSaveState* device_save_all(void) diff --git a/libafl/user.c b/libafl/user.c index 331c4b1faa..a0335e68a8 100644 --- a/libafl/user.c +++ b/libafl/user.c @@ -9,9 +9,10 @@ static struct image_info libafl_image_info; extern abi_ulong target_brk, initial_target_brk; -void host_signal_handler(int host_sig, siginfo_t *info, void *puc); +void host_signal_handler(int host_sig, siginfo_t* info, void* puc); -void libafl_qemu_handle_crash(int host_sig, siginfo_t *info, void *puc) { +void libafl_qemu_handle_crash(int host_sig, siginfo_t* info, void* puc) +{ host_signal_handler(host_sig, info, puc); } @@ -22,19 +23,14 @@ void libafl_dump_core_exec(int signal) } } -uint64_t libafl_load_addr(void) { - return libafl_image_info.load_addr; -} +uint64_t libafl_load_addr(void) { return libafl_image_info.load_addr; } -struct image_info* libafl_get_image_info(void) { - return &libafl_image_info; -} +struct image_info* libafl_get_image_info(void) { return &libafl_image_info; } -uint64_t libafl_get_brk(void) { - return (uint64_t)target_brk; -} +uint64_t libafl_get_brk(void) { return (uint64_t)target_brk; } -uint64_t libafl_set_brk(uint64_t new_brk) { +uint64_t libafl_set_brk(uint64_t new_brk) +{ uint64_t old_brk = (uint64_t)target_brk; target_brk = (abi_ulong)new_brk; return old_brk;