Skip to content

Commit

Permalink
fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
rmalmain committed Aug 13, 2024
1 parent 511fecd commit 63f75da
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 46 deletions.
2 changes: 1 addition & 1 deletion include/libafl/cpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 2 additions & 1 deletion include/libafl/gdb.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
1 change: 0 additions & 1 deletion include/libafl/user.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

45 changes: 21 additions & 24 deletions libafl/cpu.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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;
}
Expand All @@ -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;
}

Expand All @@ -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;
}

Expand Down Expand Up @@ -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)
Expand All @@ -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; }
12 changes: 8 additions & 4 deletions libafl/gdb.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
4 changes: 1 addition & 3 deletions libafl/syx-snapshot/device-save.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
20 changes: 8 additions & 12 deletions libafl/user.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand All @@ -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;
Expand Down

0 comments on commit 63f75da

Please sign in to comment.