mirror of
https://github.com/yuzu-emu/unicorn
synced 2024-11-24 12:48:16 +00:00
Move sanity checks before uc->memory_map is called.
This commit is contained in:
parent
c9f4bd27cc
commit
89eac66bf7
1 changed files with 20 additions and 20 deletions
40
uc.c
40
uc.c
|
@ -606,26 +606,6 @@ static uc_err mem_map(uc_engine *uc, uint64_t address, size_t size, uint32_t per
|
|||
{
|
||||
MemoryRegion **regions;
|
||||
|
||||
if (size == 0)
|
||||
// invalid memory mapping
|
||||
return UC_ERR_ARG;
|
||||
|
||||
// address cannot wrapp around
|
||||
if (address + size - 1 < address)
|
||||
return UC_ERR_ARG;
|
||||
|
||||
// address must be aligned to uc->target_page_size
|
||||
if ((address & uc->target_page_align) != 0)
|
||||
return UC_ERR_ARG;
|
||||
|
||||
// size must be multiple of uc->target_page_size
|
||||
if ((size & uc->target_page_align) != 0)
|
||||
return UC_ERR_ARG;
|
||||
|
||||
// check for only valid permissions
|
||||
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;
|
||||
|
@ -655,6 +635,26 @@ uc_err uc_mem_map(uc_engine *uc, uint64_t address, size_t size, uint32_t perms)
|
|||
address = uc->mem_redirect(address);
|
||||
}
|
||||
|
||||
if (size == 0)
|
||||
// invalid memory mapping
|
||||
return UC_ERR_ARG;
|
||||
|
||||
// address cannot wrapp around
|
||||
if (address + size - 1 < address)
|
||||
return UC_ERR_ARG;
|
||||
|
||||
// address must be aligned to uc->target_page_size
|
||||
if ((address & uc->target_page_align) != 0)
|
||||
return UC_ERR_ARG;
|
||||
|
||||
// size must be multiple of uc->target_page_size
|
||||
if ((size & uc->target_page_align) != 0)
|
||||
return UC_ERR_ARG;
|
||||
|
||||
// check for only valid permissions
|
||||
if ((perms & ~UC_PROT_ALL) != 0)
|
||||
return UC_ERR_ARG;
|
||||
|
||||
return mem_map(uc, address, size, perms, uc->memory_map(uc, address, size, perms));
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue