Skip to content

Commit 033e79a

Browse files
committed
Added cache flush after code patching in unit tests for arm64 and riscv
1 parent 549274f commit 033e79a

File tree

2 files changed

+4
-0
lines changed

2 files changed

+4
-0
lines changed

tests/unit/test_arm64.c

+2
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ static void test_arm64_code_patching() {
7878
OK(uc_close(uc));
7979
}
8080

81+
// Need to flush the cache before running the emulation after patching
8182
static void test_arm64_code_patching_count() {
8283
uc_engine *uc;
8384
char code[] = "\x00\x04\x00\x11"; // add w0, w0, 0x1
@@ -93,6 +94,7 @@ static void test_arm64_code_patching_count() {
9394
// patch instruction
9495
char patch_code[] = "\x00\xfc\x1f\x11"; // add w0, w0, 0x7FF
9596
OK(uc_mem_write(uc, code_start, patch_code, sizeof(patch_code) - 1));
97+
OK(uc_ctl_remove_cache(uc, code_start, code_start + sizeof(patch_code) - 1));
9698
// zero out x0
9799
r_x0 = 0x0;
98100
OK(uc_reg_write(uc, UC_ARM64_REG_X0, &r_x0));

tests/unit/test_riscv.c

+2
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,7 @@ static void test_riscv64_code_patching() {
399399
OK(uc_close(uc));
400400
}
401401

402+
// Need to flush the cache before running the emulation after patching
402403
static void test_riscv64_code_patching_count() {
403404
uc_engine *uc;
404405
char code[] = "\x93\x82\x12\x00"; // addi t0, t0, 0x1
@@ -414,6 +415,7 @@ static void test_riscv64_code_patching_count() {
414415
// patch instruction
415416
char patch_code[] = "\x93\x82\xf2\x7f"; // addi t0, t0, 0x7FF
416417
OK(uc_mem_write(uc, code_start, patch_code, sizeof(patch_code) - 1));
418+
OK(uc_ctl_remove_cache(uc, code_start, code_start + sizeof(patch_code) - 1));
417419
// zero out t0
418420
r_t0 = 0x0;
419421
OK(uc_reg_write(uc, UC_RISCV_REG_T0, &r_t0));

0 commit comments

Comments
 (0)