From 4084a385c2853cd1b34ad65c418abcf5e31485a3 Mon Sep 17 00:00:00 2001 From: Nguyen Anh Quynh Date: Sun, 24 Apr 2016 22:53:30 +0800 Subject: [PATCH] regress: add mem_64_c.c from issue #523 by Chris Eagle --- .gitignore | 1 + tests/regress/Makefile | 1 + tests/regress/mem_64_c.c | 39 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 41 insertions(+) create mode 100644 tests/regress/mem_64_c.c diff --git a/.gitignore b/.gitignore index bcce4e55..03e0ab10 100644 --- a/.gitignore +++ b/.gitignore @@ -76,6 +76,7 @@ sample_batch_reg.static sample_x86_32_gdt_and_seg_regs sample_x86_32_gdt_and_seg_regs.exe sample_x86_32_gdt_and_seg_regs.static +mem_64_c libunicorn*.dll libunicorn*.so diff --git a/tests/regress/Makefile b/tests/regress/Makefile index e50a0b06..9fc1f39c 100644 --- a/tests/regress/Makefile +++ b/tests/regress/Makefile @@ -44,6 +44,7 @@ TESTS += 003-qemu__fatal__wdebug_not_implemented TESTS += 004-segmentation_fault_1 TESTS += 005-qemu__fatal__illegal_instruction__0000___00000404 TESTS += 006-qemu__fatal__illegal_instruction__0421___00040026 +TESTS += mem_64_c TESTS += memleak_x86 TESTS += memleak_arm diff --git a/tests/regress/mem_64_c.c b/tests/regress/mem_64_c.c new file mode 100644 index 00000000..e09a90da --- /dev/null +++ b/tests/regress/mem_64_c.c @@ -0,0 +1,39 @@ +#include +#include + +uint64_t starts[] = {0x10000000, 0x110004000ll}; + +int main(int argc, char **argv, char **envp) { + uc_engine *uc; + uc_err err; + int i; + // Initialize emulator in X86-64bit mode + err = uc_open(UC_ARCH_X86, UC_MODE_64, &uc); + if (err) { + printf("Failed on uc_open() with error returned: %u\n", err); + return 1; + } + + for (i = 0; i < (sizeof(starts) / sizeof(uint64_t)); i++) { + uc_mem_map(uc, starts[i], 4096, UC_PROT_ALL); + } + + uint32_t count; + uc_mem_region *regions; + int err_count = 0; + err = uc_mem_regions(uc, ®ions, &count); + if (err == UC_ERR_OK) { + for (i = 0; i < count; i++) { + fprintf(stderr, "region %d: 0x%llx-0x%llx (%d)\n", i, regions[i].begin, regions[i].end - 1, regions[i].perms); + if (regions[i].begin != starts[i]) { + err_count++; + fprintf(stderr, " ERROR: region start does not match requested start address, expected 0x%llx, found 0x%llx\n", + starts[i], regions[i].begin); + } + } + free(regions); + } + + uc_close(uc); + return err_count; +}