diff --git a/include/unicorn/unicorn.h b/include/unicorn/unicorn.h index 6980748a..fd341055 100644 --- a/include/unicorn/unicorn.h +++ b/include/unicorn/unicorn.h @@ -522,7 +522,7 @@ typedef enum uc_control_type { // Read: @args = (uint64_t, uc_tb*) UC_CTL_TB_REQUEST_CACHE, // Invalidate a tb cache at a specific address - // Write: @args = (uint64_t) + // Write: @args = (uint64_t, uint64_t) UC_CTL_TB_REMOVE_CACHE } uc_control_type; @@ -594,8 +594,8 @@ See sample_ctl.c for a detailed example. uc_ctl(uc, UC_CTL_READ(UC_CTL_CPU_MODEL, 1), (model)) #define uc_ctl_set_cpu_model(uc, model) \ uc_ctl(uc, UC_CTL_WRITE(UC_CTL_CPU_MODEL, 1), (model)) -#define uc_ctl_remove_cache(uc, address) \ - uc_ctl(uc, UC_CTL_WRITE(UC_CTL_TB_REMOVE_CACHE, 1), (address)) +#define uc_ctl_remove_cache(uc, address, end) \ + uc_ctl(uc, UC_CTL_WRITE(UC_CTL_TB_REMOVE_CACHE, 2), (address), (end)) #define uc_ctl_request_cache(uc, address, tb) \ uc_ctl(uc, UC_CTL_READ_WRITE(UC_CTL_TB_REQUEST_CACHE, 2), (address), (tb)) diff --git a/samples/sample_ctl.c b/samples/sample_ctl.c index 119d1f02..bf55c02a 100644 --- a/samples/sample_ctl.c +++ b/samples/sample_ctl.c @@ -258,7 +258,8 @@ static void test_uc_ctl_tb_cache() // Now we clear cache for all TBs. for (int i = 0; i < TB_COUNT; i++) { - err = uc_ctl_remove_cache(uc, ADDRESS + i * TCG_MAX_INSNS); + err = uc_ctl_remove_cache(uc, ADDRESS + i * TCG_MAX_INSNS, + ADDRESS + i * TCG_MAX_INSNS + 1); if (err) { printf("Failed on uc_ctl() with error returned: %u\n", err); return; diff --git a/tests/unit/test_ctl.c b/tests/unit/test_ctl.c index b4fa563f..2e0a668d 100644 --- a/tests/unit/test_ctl.c +++ b/tests/unit/test_ctl.c @@ -144,7 +144,8 @@ static void test_uc_ctl_tb_cache() cached = time_emulation(uc, code_start, code_start + sizeof(code) - 1); for (int i = 0; i < TB_COUNT; i++) { - OK(uc_ctl_remove_cache(uc, code_start + i * TCG_MAX_INSNS)); + OK(uc_ctl_remove_cache(uc, code_start + i * TCG_MAX_INSNS, + code_start + i * TCG_MAX_INSNS + 1)); } evicted = time_emulation(uc, code_start, code_start + sizeof(code) - 1); diff --git a/uc.c b/uc.c index ecb954cc..1fc34fa6 100644 --- a/uc.c +++ b/uc.c @@ -2105,7 +2105,12 @@ uc_err uc_ctl(uc_engine *uc, uc_control_type control, ...) if (rw == UC_CTL_IO_WRITE) { uint64_t addr = va_arg(args, uint64_t); - uc->uc_invalidate_tb(uc, addr, 1); + uint64_t end = va_arg(args, uint64_t); + if (end <= addr) { + err = UC_ERR_ARG; + } else { + uc->uc_invalidate_tb(uc, addr, end - addr); + } } else { err = UC_ERR_ARG; }