Skip to content

Commit 2edf778

Browse files
authored
Add utils (#62)
* add utils file * user only guard.
1 parent c9519ee commit 2edf778

File tree

3 files changed

+33
-1
lines changed

3 files changed

+33
-1
lines changed

include/libafl/utils.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#pragma once
2+
3+
#include "qemu/osdep.h"
4+
5+
#ifndef CONFIG_USER_ONLY
6+
uint8_t* libafl_paddr2host(CPUState* cpu, hwaddr addr, bool is_write);
7+
#endif

libafl/meson.build

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
specific_ss.add(files(
22
'exit.c',
33
'hook.c',
4-
'jit.c'
4+
'jit.c',
5+
'utils.c',
56
))
67

78
specific_ss.add(when: 'CONFIG_SOFTMMU', if_true: [files(

libafl/utils.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#include "qemu/osdep.h"
2+
3+
#ifndef CONFIG_USER_ONLY
4+
#include "exec/memory.h"
5+
#include "qemu/rcu.h"
6+
#include "cpu.h"
7+
8+
#include "libafl/utils.h"
9+
10+
uint8_t* libafl_paddr2host(CPUState* cpu, hwaddr addr, bool is_write)
11+
{
12+
if (addr == -1) {
13+
return NULL;
14+
}
15+
16+
hwaddr xlat;
17+
MemoryRegion* mr;
18+
WITH_RCU_READ_LOCK_GUARD() {
19+
mr = address_space_translate(cpu->as, addr, &xlat, NULL, is_write, MEMTXATTRS_UNSPECIFIED);
20+
}
21+
22+
return qemu_map_ram_ptr(mr->ram_block, xlat);
23+
}
24+
#endif

0 commit comments

Comments
 (0)