Skip to content

Commit

Permalink
Add utils (#62)
Browse files Browse the repository at this point in the history
* add utils file
* user only guard.
  • Loading branch information
rmalmain authored Apr 17, 2024
1 parent c9519ee commit 2edf778
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 1 deletion.
7 changes: 7 additions & 0 deletions include/libafl/utils.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#pragma once

#include "qemu/osdep.h"

#ifndef CONFIG_USER_ONLY
uint8_t* libafl_paddr2host(CPUState* cpu, hwaddr addr, bool is_write);
#endif
3 changes: 2 additions & 1 deletion libafl/meson.build
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
specific_ss.add(files(
'exit.c',
'hook.c',
'jit.c'
'jit.c',
'utils.c',
))

specific_ss.add(when: 'CONFIG_SOFTMMU', if_true: [files(
Expand Down
24 changes: 24 additions & 0 deletions libafl/utils.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#include "qemu/osdep.h"

#ifndef CONFIG_USER_ONLY
#include "exec/memory.h"
#include "qemu/rcu.h"
#include "cpu.h"

#include "libafl/utils.h"

uint8_t* libafl_paddr2host(CPUState* cpu, hwaddr addr, bool is_write)
{
if (addr == -1) {
return NULL;
}

hwaddr xlat;
MemoryRegion* mr;
WITH_RCU_READ_LOCK_GUARD() {
mr = address_space_translate(cpu->as, addr, &xlat, NULL, is_write, MEMTXATTRS_UNSPECIFIED);
}

return qemu_map_ram_ptr(mr->ram_block, xlat);
}
#endif

0 comments on commit 2edf778

Please sign in to comment.