mirror of
https://github.com/yuzu-emu/unicorn
synced 2024-11-24 11:38:11 +00:00
Change allocation strategy for memory block tracking and track begin/end rather than begin/size
This commit is contained in:
parent
cb8e05eb16
commit
e11c0629f9
2 changed files with 13 additions and 8 deletions
|
@ -16,8 +16,8 @@
|
|||
QTAILQ_HEAD(CPUTailQ, CPUState);
|
||||
|
||||
typedef struct MemoryBlock {
|
||||
uint64_t begin;
|
||||
size_t size;
|
||||
uint64_t begin; //inclusive
|
||||
uint64_t end; //exclusive
|
||||
uint32_t perms;
|
||||
} MemoryBlock;
|
||||
|
||||
|
@ -67,6 +67,9 @@ struct hook_struct {
|
|||
// extend memory to keep 32 more hooks each time
|
||||
#define HOOK_SIZE 32
|
||||
|
||||
//relloc increment, KEEP THIS A POWER OF 2!
|
||||
#define MEM_BLOCK_INCR 32
|
||||
|
||||
struct uc_struct {
|
||||
uc_arch arch;
|
||||
uc_mode mode;
|
||||
|
|
14
uc.c
14
uc.c
|
@ -548,13 +548,15 @@ uc_err uc_mem_map(uch handle, uint64_t address, size_t size)
|
|||
if ((size & (4*1024 - 1)) != 0)
|
||||
return UC_ERR_MAP;
|
||||
|
||||
blocks = realloc(uc->mapped_blocks, sizeof(MemoryBlock) * (uc->mapped_block_count + 1));
|
||||
if (blocks == NULL) {
|
||||
return UC_ERR_OOM;
|
||||
if ((uc->mapped_block_count & (MEM_BLOCK_INCR - 1)) == 0) { //time to grow
|
||||
blocks = realloc(uc->mapped_blocks, sizeof(MemoryBlock) * (uc->mapped_block_count + MEM_BLOCK_INCR));
|
||||
if (blocks == NULL) {
|
||||
return UC_ERR_OOM;
|
||||
}
|
||||
uc->mapped_blocks = blocks;
|
||||
}
|
||||
uc->mapped_blocks = blocks;
|
||||
blocks[uc->mapped_block_count].begin = address;
|
||||
blocks[uc->mapped_block_count].size = size;
|
||||
blocks[uc->mapped_block_count].end = address + size;
|
||||
//TODO extend uc_mem_map to accept permissions, figure out how to pass this down to qemu
|
||||
blocks[uc->mapped_block_count].perms = UC_PROT_READ | UC_PROT_WRITE | UC_PROT_EXEC;
|
||||
uc->memory_map(uc, address, size);
|
||||
|
@ -568,7 +570,7 @@ bool memory_mapping(struct uc_struct* uc, uint64_t address)
|
|||
unsigned int i;
|
||||
|
||||
for(i = 0; i < uc->mapped_block_count; i++) {
|
||||
if (address >= uc->mapped_blocks[i].begin && address < (uc->mapped_blocks[i].begin + uc->mapped_blocks[i].size))
|
||||
if (address >= uc->mapped_blocks[i].begin && address < uc->mapped_blocks[i].end)
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue