mirror of
https://github.com/yuzu-emu/unicorn.git
synced 2024-12-23 06:35:27 +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
|
@ -16,8 +16,8 @@
|
||||||
QTAILQ_HEAD(CPUTailQ, CPUState);
|
QTAILQ_HEAD(CPUTailQ, CPUState);
|
||||||
|
|
||||||
typedef struct MemoryBlock {
|
typedef struct MemoryBlock {
|
||||||
uint64_t begin;
|
uint64_t begin; //inclusive
|
||||||
size_t size;
|
uint64_t end; //exclusive
|
||||||
uint32_t perms;
|
uint32_t perms;
|
||||||
} MemoryBlock;
|
} MemoryBlock;
|
||||||
|
|
||||||
|
@ -67,6 +67,9 @@ struct hook_struct {
|
||||||
// extend memory to keep 32 more hooks each time
|
// extend memory to keep 32 more hooks each time
|
||||||
#define HOOK_SIZE 32
|
#define HOOK_SIZE 32
|
||||||
|
|
||||||
|
//relloc increment, KEEP THIS A POWER OF 2!
|
||||||
|
#define MEM_BLOCK_INCR 32
|
||||||
|
|
||||||
struct uc_struct {
|
struct uc_struct {
|
||||||
uc_arch arch;
|
uc_arch arch;
|
||||||
uc_mode mode;
|
uc_mode mode;
|
||||||
|
|
8
uc.c
8
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)
|
if ((size & (4*1024 - 1)) != 0)
|
||||||
return UC_ERR_MAP;
|
return UC_ERR_MAP;
|
||||||
|
|
||||||
blocks = realloc(uc->mapped_blocks, sizeof(MemoryBlock) * (uc->mapped_block_count + 1));
|
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) {
|
if (blocks == NULL) {
|
||||||
return UC_ERR_OOM;
|
return UC_ERR_OOM;
|
||||||
}
|
}
|
||||||
uc->mapped_blocks = blocks;
|
uc->mapped_blocks = blocks;
|
||||||
|
}
|
||||||
blocks[uc->mapped_block_count].begin = address;
|
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
|
//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;
|
blocks[uc->mapped_block_count].perms = UC_PROT_READ | UC_PROT_WRITE | UC_PROT_EXEC;
|
||||||
uc->memory_map(uc, address, size);
|
uc->memory_map(uc, address, size);
|
||||||
|
@ -568,7 +570,7 @@ bool memory_mapping(struct uc_struct* uc, uint64_t address)
|
||||||
unsigned int i;
|
unsigned int i;
|
||||||
|
|
||||||
for(i = 0; i < uc->mapped_block_count; 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;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue