Add utils (#62)

* add utils file
* user only guard.
This commit is contained in:
Romain Malmain 2024-04-17 18:08:38 +02:00 committed by GitHub
parent c9519ee8b6
commit 2edf778b1c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 33 additions and 1 deletions

7
include/libafl/utils.h Normal file
View File

@ -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

View File

@ -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(

24
libafl/utils.c Normal file
View File

@ -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