Format
This commit is contained in:
@@ -293,15 +293,14 @@ static void test_arm64_hook_mrs(void)
|
|||||||
uc_close(uc);
|
uc_close(uc);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define CHECK(x) \
|
||||||
#define CHECK(x) do { \
|
do { \
|
||||||
if ((x) != UC_ERR_OK) { \
|
if ((x) != UC_ERR_OK) { \
|
||||||
fprintf(stderr, "FAIL at %s:%d: %s\n", __FILE__, __LINE__, #x); \
|
fprintf(stderr, "FAIL at %s:%d: %s\n", __FILE__, __LINE__, #x); \
|
||||||
exit(1); \
|
exit(1); \
|
||||||
} \
|
} \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
|
|
||||||
/* Test PAC support in the emulator. Code adapted from
|
/* Test PAC support in the emulator. Code adapted from
|
||||||
https://github.com/unicorn-engine/unicorn/issues/1789#issuecomment-1536320351 */
|
https://github.com/unicorn-engine/unicorn/issues/1789#issuecomment-1536320351 */
|
||||||
static void test_arm64_pac(void)
|
static void test_arm64_pac(void)
|
||||||
@@ -318,7 +317,8 @@ static void test_arm64_pac(void)
|
|||||||
CHECK(uc_open(UC_ARCH_ARM64, UC_MODE_ARM, &uc));
|
CHECK(uc_open(UC_ARCH_ARM64, UC_MODE_ARM, &uc));
|
||||||
CHECK(uc_ctl_set_cpu_model(uc, UC_CPU_ARM64_MAX));
|
CHECK(uc_ctl_set_cpu_model(uc, UC_CPU_ARM64_MAX));
|
||||||
CHECK(uc_mem_map(uc, ADDRESS, 2 * 1024 * 1024, UC_PROT_ALL));
|
CHECK(uc_mem_map(uc, ADDRESS, 2 * 1024 * 1024, UC_PROT_ALL));
|
||||||
CHECK(uc_mem_write(uc, ADDRESS, ARM64_PAC_CODE, sizeof(ARM64_PAC_CODE) - 1));
|
CHECK(
|
||||||
|
uc_mem_write(uc, ADDRESS, ARM64_PAC_CODE, sizeof(ARM64_PAC_CODE) - 1));
|
||||||
CHECK(uc_reg_write(uc, UC_ARM64_REG_X1, &x1));
|
CHECK(uc_reg_write(uc, UC_ARM64_REG_X1, &x1));
|
||||||
|
|
||||||
/** Initialize PAC support **/
|
/** Initialize PAC support **/
|
||||||
@@ -365,7 +365,8 @@ static void test_arm64_pac(void)
|
|||||||
CHECK(uc_reg_write(uc, UC_ARM64_REG_CP_REG, ®));
|
CHECK(uc_reg_write(uc, UC_ARM64_REG_CP_REG, ®));
|
||||||
|
|
||||||
/** Check that PAC worked **/
|
/** Check that PAC worked **/
|
||||||
CHECK(uc_emu_start(uc, ADDRESS, ADDRESS + sizeof(ARM64_PAC_CODE) - 1, 0, 0));
|
CHECK(
|
||||||
|
uc_emu_start(uc, ADDRESS, ADDRESS + sizeof(ARM64_PAC_CODE) - 1, 0, 0));
|
||||||
CHECK(uc_reg_read(uc, UC_ARM64_REG_X1, &x1));
|
CHECK(uc_reg_read(uc, UC_ARM64_REG_X1, &x1));
|
||||||
|
|
||||||
printf("X1 = 0x%" PRIx64 "\n", x1);
|
printf("X1 = 0x%" PRIx64 "\n", x1);
|
||||||
|
|||||||
@@ -333,7 +333,8 @@ static void test_snapshot_with_vtlb(void)
|
|||||||
uc_hook hook;
|
uc_hook hook;
|
||||||
|
|
||||||
// mov eax, [0x2020]; inc eax; mov [0x2020], eax
|
// mov eax, [0x2020]; inc eax; mov [0x2020], eax
|
||||||
char code[] = "\xA1\x20\x20\x00\x00\x04\x00\x00\x00\xFF\xC0\xA3\x20\x20\x00\x00\x04\x00\x00\x00";
|
char code[] = "\xA1\x20\x20\x00\x00\x04\x00\x00\x00\xFF\xC0\xA3\x20\x20\x00"
|
||||||
|
"\x00\x04\x00\x00\x00";
|
||||||
|
|
||||||
OK(uc_open(UC_ARCH_X86, UC_MODE_64, &uc));
|
OK(uc_open(UC_ARCH_X86, UC_MODE_64, &uc));
|
||||||
|
|
||||||
@@ -342,9 +343,9 @@ static void test_snapshot_with_vtlb(void)
|
|||||||
OK(uc_context_alloc(uc, &c1));
|
OK(uc_context_alloc(uc, &c1));
|
||||||
OK(uc_ctl_context_mode(uc, UC_CTL_CONTEXT_MEMORY));
|
OK(uc_ctl_context_mode(uc, UC_CTL_CONTEXT_MEMORY));
|
||||||
|
|
||||||
|
|
||||||
OK(uc_ctl_tlb_mode(uc, UC_TLB_VIRTUAL));
|
OK(uc_ctl_tlb_mode(uc, UC_TLB_VIRTUAL));
|
||||||
OK(uc_hook_add(uc, &hook, UC_HOOK_TLB_FILL, test_snapshot_with_vtlb_callback, NULL, 1, 0));
|
OK(uc_hook_add(uc, &hook, UC_HOOK_TLB_FILL,
|
||||||
|
test_snapshot_with_vtlb_callback, NULL, 1, 0));
|
||||||
|
|
||||||
// Map physical memory
|
// Map physical memory
|
||||||
OK(uc_mem_map(uc, 0x1000, 0x1000, UC_PROT_EXEC | UC_PROT_READ));
|
OK(uc_mem_map(uc, 0x1000, 0x1000, UC_PROT_EXEC | UC_PROT_READ));
|
||||||
@@ -354,11 +355,13 @@ static void test_snapshot_with_vtlb(void)
|
|||||||
// Initial context save
|
// Initial context save
|
||||||
OK(uc_context_save(uc, c0));
|
OK(uc_context_save(uc, c0));
|
||||||
|
|
||||||
OK(uc_emu_start(uc, 0x400000000 + 0x1000, 0x400000000 + 0x1000 + sizeof(code) - 1, 0, 0));
|
OK(uc_emu_start(uc, 0x400000000 + 0x1000,
|
||||||
|
0x400000000 + 0x1000 + sizeof(code) - 1, 0, 0));
|
||||||
OK(uc_mem_read(uc, 0x2020, &mem, sizeof(mem)));
|
OK(uc_mem_read(uc, 0x2020, &mem, sizeof(mem)));
|
||||||
TEST_CHECK(mem == 1);
|
TEST_CHECK(mem == 1);
|
||||||
OK(uc_context_save(uc, c1));
|
OK(uc_context_save(uc, c1));
|
||||||
OK(uc_emu_start(uc, 0x400000000 + 0x1000, 0x400000000 + 0x1000 + sizeof(code) - 1, 0, 0));
|
OK(uc_emu_start(uc, 0x400000000 + 0x1000,
|
||||||
|
0x400000000 + 0x1000 + sizeof(code) - 1, 0, 0));
|
||||||
OK(uc_mem_read(uc, 0x2020, &mem, sizeof(mem)));
|
OK(uc_mem_read(uc, 0x2020, &mem, sizeof(mem)));
|
||||||
TEST_CHECK(mem == 2);
|
TEST_CHECK(mem == 2);
|
||||||
OK(uc_context_restore(uc, c1));
|
OK(uc_context_restore(uc, c1));
|
||||||
|
|||||||
@@ -1518,7 +1518,8 @@ static void test_x86_64_not_overwriting_tmp0_for_pc_update()
|
|||||||
#define MEM_STACK MEM_BASE + (MEM_SIZE / 2)
|
#define MEM_STACK MEM_BASE + (MEM_SIZE / 2)
|
||||||
#define MEM_TEXT MEM_STACK + 4096
|
#define MEM_TEXT MEM_STACK + 4096
|
||||||
|
|
||||||
static void test_fxsave_fpip_x86(void) {
|
static void test_fxsave_fpip_x86(void)
|
||||||
|
{
|
||||||
// note: fxsave was introduced in Pentium II
|
// note: fxsave was introduced in Pentium II
|
||||||
uint8_t code_x86[] = {
|
uint8_t code_x86[] = {
|
||||||
// help testing through NOP offset [disassembly in at&t syntax]
|
// help testing through NOP offset [disassembly in at&t syntax]
|
||||||
@@ -1554,7 +1555,8 @@ static void test_fxsave_fpip_x86(void) {
|
|||||||
OK(uc_close(uc));
|
OK(uc_close(uc));
|
||||||
}
|
}
|
||||||
|
|
||||||
static void test_fxsave_fpip_x64(void) {
|
static void test_fxsave_fpip_x64(void)
|
||||||
|
{
|
||||||
uint8_t code_x64[] = {
|
uint8_t code_x64[] = {
|
||||||
// help testing through NOP offset [disassembly in at&t]
|
// help testing through NOP offset [disassembly in at&t]
|
||||||
0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, // nops
|
0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, // nops
|
||||||
|
|||||||
Reference in New Issue
Block a user