mirror of
https://github.com/yuzu-emu/unicorn
synced 2024-11-24 12:48:16 +00:00
disallow mapping memory range that is already mapped. this fixes issue #350
This commit is contained in:
parent
6e534417f1
commit
7e16f7a50d
1 changed files with 29 additions and 0 deletions
29
uc.c
29
uc.c
|
@ -577,6 +577,30 @@ static uc_err _hook_mem_access(uc_engine *uc, uc_hook_type type,
|
|||
return UC_ERR_OK;
|
||||
}
|
||||
|
||||
// find if a memory range overlaps with existing mapped regions
|
||||
static bool memory_overlap(struct uc_struct *uc, uint64_t begin, size_t size)
|
||||
{
|
||||
unsigned int i;
|
||||
uint64_t end = begin + size - 1;
|
||||
|
||||
for(i = 0; i < uc->mapped_block_count; i++) {
|
||||
// begin address falls inside this region?
|
||||
if (begin >= uc->mapped_blocks[i]->addr && begin <= uc->mapped_blocks[i]->end - 1)
|
||||
return true;
|
||||
|
||||
// end address falls inside this region?
|
||||
if (end >= uc->mapped_blocks[i]->addr && end <= uc->mapped_blocks[i]->end - 1)
|
||||
return true;
|
||||
|
||||
// this region falls totally inside this range?
|
||||
if (begin < uc->mapped_blocks[i]->addr && end > uc->mapped_blocks[i]->end - 1)
|
||||
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, uint64_t address, size_t size, uint32_t perms, MemoryRegion *block)
|
||||
{
|
||||
|
@ -602,6 +626,10 @@ static uc_err mem_map(uc_engine *uc, uint64_t address, size_t size, uint32_t per
|
|||
if ((perms & ~UC_PROT_ALL) != 0)
|
||||
return UC_ERR_ARG;
|
||||
|
||||
// this area overlaps existing mapped regions?
|
||||
if (memory_overlap(uc, address, size))
|
||||
return UC_ERR_MAP;
|
||||
|
||||
if (block == NULL)
|
||||
return UC_ERR_NOMEM;
|
||||
|
||||
|
@ -860,6 +888,7 @@ uc_err uc_mem_unmap(struct uc_struct *uc, uint64_t address, size_t size)
|
|||
return UC_ERR_OK;
|
||||
}
|
||||
|
||||
// find the memory region of this address
|
||||
MemoryRegion *memory_mapping(struct uc_struct* uc, uint64_t address)
|
||||
{
|
||||
unsigned int i;
|
||||
|
|
Loading…
Reference in a new issue