use address_space_translate to find memory mapping
first version has bugs
This commit is contained in:
parent
cd85f589a2
commit
065af19dc5
@ -100,6 +100,8 @@ typedef MemoryRegion *(*uc_args_uc_ram_size_ptr_t)(struct uc_struct *,
|
||||
|
||||
typedef void (*uc_mem_unmap_t)(struct uc_struct *, MemoryRegion *mr);
|
||||
|
||||
typedef MemoryRegion *(*uc_memory_mapping_t)(struct uc_struct *, hwaddr addr);
|
||||
|
||||
typedef void (*uc_readonly_mem_t)(MemoryRegion *mr, bool readonly);
|
||||
|
||||
typedef int (*uc_cpus_init)(struct uc_struct *, const char *);
|
||||
@ -277,6 +279,7 @@ struct uc_struct {
|
||||
uc_args_uc_long_t tcg_exec_init;
|
||||
uc_args_uc_ram_size_t memory_map;
|
||||
uc_args_uc_ram_size_ptr_t memory_map_ptr;
|
||||
uc_memory_mapping_t memory_mapping;
|
||||
uc_mem_unmap_t memory_unmap;
|
||||
uc_readonly_mem_t readonly_mem;
|
||||
uc_cpus_init cpus_init;
|
||||
@ -410,9 +413,6 @@ struct uc_context {
|
||||
char data[0]; // context
|
||||
};
|
||||
|
||||
// check if this address is mapped in (via uc_mem_map())
|
||||
MemoryRegion *find_memory_region(struct uc_struct *uc, uint64_t address);
|
||||
|
||||
// We have to support 32bit system so we can't hold uint64_t on void*
|
||||
static inline void uc_add_exit(uc_engine *uc, uint64_t addr)
|
||||
{
|
||||
|
@ -151,6 +151,7 @@
|
||||
#define address_space_destroy address_space_destroy_aarch64
|
||||
#define memory_region_init_ram memory_region_init_ram_aarch64
|
||||
#define memory_mapping_list_add_merge_sorted memory_mapping_list_add_merge_sorted_aarch64
|
||||
#define find_memory_mapping find_memory_mapping_aarch64
|
||||
#define exec_inline_op exec_inline_op_aarch64
|
||||
#define floatx80_default_nan floatx80_default_nan_aarch64
|
||||
#define float_raise float_raise_aarch64
|
||||
|
@ -1460,7 +1460,7 @@ load_helper(CPUArchState *env, target_ulong addr, TCGMemOpIdx oi,
|
||||
}
|
||||
|
||||
paddr = entry->paddr | (addr & ~TARGET_PAGE_MASK);
|
||||
mr = find_memory_region(uc, paddr);
|
||||
mr = uc->memory_mapping(uc, paddr);
|
||||
|
||||
// memory might be still unmapped while reading or fetching
|
||||
if (mr == NULL) {
|
||||
@ -1517,7 +1517,7 @@ load_helper(CPUArchState *env, target_ulong addr, TCGMemOpIdx oi,
|
||||
tlb_addr &= ~TLB_INVALID_MASK;
|
||||
}
|
||||
paddr = entry->paddr | (addr & ~TARGET_PAGE_MASK);
|
||||
mr = find_memory_region(uc, paddr);
|
||||
mr = uc->memory_mapping(uc, paddr);
|
||||
if (mr == NULL) {
|
||||
uc->invalid_error = UC_ERR_MAP;
|
||||
if (uc->nested_level > 0 && !uc->cpu->stopped) {
|
||||
@ -2053,7 +2053,7 @@ store_helper(CPUArchState *env, target_ulong addr, uint64_t val,
|
||||
|
||||
// Load the latest memory mapping.
|
||||
paddr = entry->paddr | (addr & ~TARGET_PAGE_MASK);
|
||||
mr = find_memory_region(uc, paddr);
|
||||
mr = uc->memory_mapping(uc, paddr);
|
||||
|
||||
if (!uc->size_recur_mem) { // disabling write callback if in recursive call
|
||||
// Unicorn: callback on memory write
|
||||
@ -2107,7 +2107,7 @@ store_helper(CPUArchState *env, target_ulong addr, uint64_t val,
|
||||
tlb_addr = tlb_addr_write(entry) & ~TLB_INVALID_MASK;
|
||||
}
|
||||
paddr = entry->paddr | (addr & ~TARGET_PAGE_MASK);
|
||||
mr = find_memory_region(uc, paddr);
|
||||
mr = uc->memory_mapping(uc, paddr);
|
||||
if (mr == NULL) {
|
||||
uc->invalid_error = UC_ERR_MAP;
|
||||
cpu_exit(uc->cpu);
|
||||
|
@ -151,6 +151,7 @@
|
||||
#define address_space_destroy address_space_destroy_arm
|
||||
#define memory_region_init_ram memory_region_init_ram_arm
|
||||
#define memory_mapping_list_add_merge_sorted memory_mapping_list_add_merge_sorted_arm
|
||||
#define find_memory_mapping find_memory_mapping_arm
|
||||
#define exec_inline_op exec_inline_op_arm
|
||||
#define floatx80_default_nan floatx80_default_nan_arm
|
||||
#define float_raise float_raise_arm
|
||||
|
@ -151,6 +151,7 @@
|
||||
#define address_space_destroy address_space_destroy_m68k
|
||||
#define memory_region_init_ram memory_region_init_ram_m68k
|
||||
#define memory_mapping_list_add_merge_sorted memory_mapping_list_add_merge_sorted_m68k
|
||||
#define find_memory_mapping find_memory_mapping_m68k
|
||||
#define exec_inline_op exec_inline_op_m68k
|
||||
#define floatx80_default_nan floatx80_default_nan_m68k
|
||||
#define float_raise float_raise_m68k
|
||||
|
@ -151,6 +151,7 @@
|
||||
#define address_space_destroy address_space_destroy_mips
|
||||
#define memory_region_init_ram memory_region_init_ram_mips
|
||||
#define memory_mapping_list_add_merge_sorted memory_mapping_list_add_merge_sorted_mips
|
||||
#define find_memory_mapping find_memory_mapping_mips
|
||||
#define exec_inline_op exec_inline_op_mips
|
||||
#define floatx80_default_nan floatx80_default_nan_mips
|
||||
#define float_raise float_raise_mips
|
||||
|
@ -151,6 +151,7 @@
|
||||
#define address_space_destroy address_space_destroy_mips64
|
||||
#define memory_region_init_ram memory_region_init_ram_mips64
|
||||
#define memory_mapping_list_add_merge_sorted memory_mapping_list_add_merge_sorted_mips64
|
||||
#define find_memory_mapping find_memory_mapping_mips64
|
||||
#define exec_inline_op exec_inline_op_mips64
|
||||
#define floatx80_default_nan floatx80_default_nan_mips64
|
||||
#define float_raise float_raise_mips64
|
||||
|
@ -151,6 +151,7 @@
|
||||
#define address_space_destroy address_space_destroy_mips64el
|
||||
#define memory_region_init_ram memory_region_init_ram_mips64el
|
||||
#define memory_mapping_list_add_merge_sorted memory_mapping_list_add_merge_sorted_mips64el
|
||||
#define find_memory_mapping find_memory_mapping_mips64el
|
||||
#define exec_inline_op exec_inline_op_mips64el
|
||||
#define floatx80_default_nan floatx80_default_nan_mips64el
|
||||
#define float_raise float_raise_mips64el
|
||||
|
@ -151,6 +151,7 @@
|
||||
#define address_space_destroy address_space_destroy_mipsel
|
||||
#define memory_region_init_ram memory_region_init_ram_mipsel
|
||||
#define memory_mapping_list_add_merge_sorted memory_mapping_list_add_merge_sorted_mipsel
|
||||
#define find_memory_mapping find_memory_mapping_mipsel
|
||||
#define exec_inline_op exec_inline_op_mipsel
|
||||
#define floatx80_default_nan floatx80_default_nan_mipsel
|
||||
#define float_raise float_raise_mipsel
|
||||
|
@ -151,6 +151,7 @@
|
||||
#define address_space_destroy address_space_destroy_ppc
|
||||
#define memory_region_init_ram memory_region_init_ram_ppc
|
||||
#define memory_mapping_list_add_merge_sorted memory_mapping_list_add_merge_sorted_ppc
|
||||
#define find_memory_mapping find_memory_mapping_ppc
|
||||
#define exec_inline_op exec_inline_op_ppc
|
||||
#define floatx80_default_nan floatx80_default_nan_ppc
|
||||
#define float_raise float_raise_ppc
|
||||
|
@ -151,6 +151,7 @@
|
||||
#define address_space_destroy address_space_destroy_ppc64
|
||||
#define memory_region_init_ram memory_region_init_ram_ppc64
|
||||
#define memory_mapping_list_add_merge_sorted memory_mapping_list_add_merge_sorted_ppc64
|
||||
#define find_memory_mapping find_memory_mapping_ppc64
|
||||
#define exec_inline_op exec_inline_op_ppc64
|
||||
#define floatx80_default_nan floatx80_default_nan_ppc64
|
||||
#define float_raise float_raise_ppc64
|
||||
|
@ -151,6 +151,7 @@
|
||||
#define address_space_destroy address_space_destroy_riscv32
|
||||
#define memory_region_init_ram memory_region_init_ram_riscv32
|
||||
#define memory_mapping_list_add_merge_sorted memory_mapping_list_add_merge_sorted_riscv32
|
||||
#define find_memory_mapping find_memory_mapping_riscv32
|
||||
#define exec_inline_op exec_inline_op_riscv32
|
||||
#define floatx80_default_nan floatx80_default_nan_riscv32
|
||||
#define float_raise float_raise_riscv32
|
||||
|
@ -151,6 +151,7 @@
|
||||
#define address_space_destroy address_space_destroy_riscv64
|
||||
#define memory_region_init_ram memory_region_init_ram_riscv64
|
||||
#define memory_mapping_list_add_merge_sorted memory_mapping_list_add_merge_sorted_riscv64
|
||||
#define find_memory_mapping find_memory_mapping_riscv64
|
||||
#define exec_inline_op exec_inline_op_riscv64
|
||||
#define floatx80_default_nan floatx80_default_nan_riscv64
|
||||
#define float_raise float_raise_riscv64
|
||||
|
@ -151,6 +151,7 @@
|
||||
#define address_space_destroy address_space_destroy_s390x
|
||||
#define memory_region_init_ram memory_region_init_ram_s390x
|
||||
#define memory_mapping_list_add_merge_sorted memory_mapping_list_add_merge_sorted_s390x
|
||||
#define find_memory_mapping find_memory_mapping_s390x
|
||||
#define exec_inline_op exec_inline_op_s390x
|
||||
#define floatx80_default_nan floatx80_default_nan_s390x
|
||||
#define float_raise float_raise_s390x
|
||||
|
@ -179,8 +179,8 @@ void memory_unmap(struct uc_struct *uc, MemoryRegion *mr)
|
||||
|
||||
int memory_free(struct uc_struct *uc)
|
||||
{
|
||||
MemoryRegion *mr;
|
||||
int i;
|
||||
MemoryRegion *mr;
|
||||
|
||||
for (i = 0; i < uc->mapped_block_count; i++) {
|
||||
mr = uc->mapped_blocks[i];
|
||||
|
@ -151,6 +151,7 @@
|
||||
#define address_space_destroy address_space_destroy_sparc
|
||||
#define memory_region_init_ram memory_region_init_ram_sparc
|
||||
#define memory_mapping_list_add_merge_sorted memory_mapping_list_add_merge_sorted_sparc
|
||||
#define find_memory_mapping find_memory_mapping_sparc
|
||||
#define exec_inline_op exec_inline_op_sparc
|
||||
#define floatx80_default_nan floatx80_default_nan_sparc
|
||||
#define float_raise float_raise_sparc
|
||||
|
@ -151,6 +151,7 @@
|
||||
#define address_space_destroy address_space_destroy_sparc64
|
||||
#define memory_region_init_ram memory_region_init_ram_sparc64
|
||||
#define memory_mapping_list_add_merge_sorted memory_mapping_list_add_merge_sorted_sparc64
|
||||
#define find_memory_mapping find_memory_mapping_sparc64
|
||||
#define exec_inline_op exec_inline_op_sparc64
|
||||
#define floatx80_default_nan floatx80_default_nan_sparc64
|
||||
#define float_raise float_raise_sparc64
|
||||
|
@ -151,6 +151,7 @@
|
||||
#define address_space_destroy address_space_destroy_tricore
|
||||
#define memory_region_init_ram memory_region_init_ram_tricore
|
||||
#define memory_mapping_list_add_merge_sorted memory_mapping_list_add_merge_sorted_tricore
|
||||
#define find_memory_mapping find_memory_mapping_tricore
|
||||
#define exec_inline_op exec_inline_op_tricore
|
||||
#define floatx80_default_nan floatx80_default_nan_tricore
|
||||
#define float_raise float_raise_tricore
|
||||
|
@ -107,6 +107,18 @@ static uc_err uc_set_tlb(struct uc_struct *uc, int mode) {
|
||||
}
|
||||
}
|
||||
|
||||
MemoryRegion *find_memory_mapping(struct uc_struct *uc, hwaddr address)
|
||||
{
|
||||
hwaddr xlat = 0;
|
||||
hwaddr len = 1;
|
||||
MemoryRegion *mr = address_space_translate(&uc->address_space_memory, address, &xlat, &len, false, MEMTXATTRS_UNSPECIFIED);
|
||||
|
||||
if (mr == &uc->io_mem_unassigned) {
|
||||
return NULL;
|
||||
}
|
||||
return mr;
|
||||
}
|
||||
|
||||
void softfloat_init(void);
|
||||
static inline void uc_common_init(struct uc_struct* uc)
|
||||
{
|
||||
@ -124,6 +136,7 @@ static inline void uc_common_init(struct uc_struct* uc)
|
||||
uc->tcg_flush_tlb = tcg_flush_softmmu_tlb;
|
||||
uc->memory_map_io = memory_map_io;
|
||||
uc->set_tlb = uc_set_tlb;
|
||||
uc->memory_mapping = find_memory_mapping;
|
||||
|
||||
if (!uc->release)
|
||||
uc->release = release_common;
|
||||
|
@ -151,6 +151,7 @@
|
||||
#define address_space_destroy address_space_destroy_x86_64
|
||||
#define memory_region_init_ram memory_region_init_ram_x86_64
|
||||
#define memory_mapping_list_add_merge_sorted memory_mapping_list_add_merge_sorted_x86_64
|
||||
#define find_memory_mapping find_memory_mapping_x86_64
|
||||
#define exec_inline_op exec_inline_op_x86_64
|
||||
#define floatx80_default_nan floatx80_default_nan_x86_64
|
||||
#define float_raise float_raise_x86_64
|
||||
|
@ -151,6 +151,7 @@ address_space_init \
|
||||
address_space_destroy \
|
||||
memory_region_init_ram \
|
||||
memory_mapping_list_add_merge_sorted \
|
||||
find_memory_mapping \
|
||||
exec_inline_op \
|
||||
floatx80_default_nan \
|
||||
float_raise \
|
||||
|
5
uc.c
5
uc.c
@ -31,6 +31,7 @@
|
||||
#include "qemu-common.h"
|
||||
|
||||
static void clear_deleted_hooks(uc_engine *uc);
|
||||
static MemoryRegion *find_memory_region(struct uc_struct *uc, uint64_t address);
|
||||
|
||||
static void *hook_insert(struct list *l, struct hook *h)
|
||||
{
|
||||
@ -1083,12 +1084,14 @@ static bool memory_overlap(struct uc_struct *uc, uint64_t begin, size_t size)
|
||||
return true;
|
||||
|
||||
// not found
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// common setup/error checking shared between uc_mem_map and uc_mem_map_ptr
|
||||
static uc_err mem_map(uc_engine *uc, MemoryRegion *block)
|
||||
{
|
||||
|
||||
MemoryRegion **regions;
|
||||
int pos;
|
||||
|
||||
@ -1609,7 +1612,7 @@ uc_err uc_mem_unmap(struct uc_struct *uc, uint64_t address, size_t size)
|
||||
}
|
||||
|
||||
// find the memory region of this address
|
||||
MemoryRegion *find_memory_region(struct uc_struct *uc, uint64_t address)
|
||||
static MemoryRegion *find_memory_region(struct uc_struct *uc, uint64_t address)
|
||||
{
|
||||
unsigned int i;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user