From 8f2841ecdb4db099d5670fa396012810179d7a06 Mon Sep 17 00:00:00 2001 From: Choongwoo Han Date: Mon, 20 Mar 2023 17:07:15 -0700 Subject: [PATCH 1/2] Cache index for find_memory_region --- uc.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/uc.c b/uc.c index 76c4eb28..ed9663ef 100644 --- a/uc.c +++ b/uc.c @@ -1532,8 +1532,10 @@ MemoryRegion *find_memory_region(struct uc_struct *uc, uint64_t address) if (i < uc->mapped_block_count && address >= uc->mapped_blocks[i]->addr && - address <= uc->mapped_blocks[i]->end - 1) + address < uc->mapped_blocks[i]->end) { + uc->mapped_block_cache_index = i; return uc->mapped_blocks[i]; + } // not found return NULL; From 0a38a0bf1728bfcf6e358e3574211dac4b62446b Mon Sep 17 00:00:00 2001 From: Choongwoo Han Date: Mon, 20 Mar 2023 18:41:59 -0700 Subject: [PATCH 2/2] Fix test failure --- uc.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/uc.c b/uc.c index ed9663ef..a1a71366 100644 --- a/uc.c +++ b/uc.c @@ -1524,7 +1524,7 @@ MemoryRegion *find_memory_region(struct uc_struct *uc, uint64_t address) if (i < uc->mapped_block_count && address >= uc->mapped_blocks[i]->addr && - address < uc->mapped_blocks[i]->end) { + address <= uc->mapped_blocks[i]->end - 1) { return uc->mapped_blocks[i]; } @@ -1532,7 +1532,7 @@ MemoryRegion *find_memory_region(struct uc_struct *uc, uint64_t address) if (i < uc->mapped_block_count && address >= uc->mapped_blocks[i]->addr && - address < uc->mapped_blocks[i]->end) { + address <= uc->mapped_blocks[i]->end - 1) { uc->mapped_block_cache_index = i; return uc->mapped_blocks[i]; }