regress: add mem_64_c.c from issue #523 by Chris Eagle

This commit is contained in:
Nguyen Anh Quynh 2016-04-24 22:53:30 +08:00
parent 53466d84b6
commit 4084a385c2
3 changed files with 41 additions and 0 deletions

1
.gitignore vendored
View file

@ -76,6 +76,7 @@ sample_batch_reg.static
sample_x86_32_gdt_and_seg_regs sample_x86_32_gdt_and_seg_regs
sample_x86_32_gdt_and_seg_regs.exe sample_x86_32_gdt_and_seg_regs.exe
sample_x86_32_gdt_and_seg_regs.static sample_x86_32_gdt_and_seg_regs.static
mem_64_c
libunicorn*.dll libunicorn*.dll
libunicorn*.so libunicorn*.so

View file

@ -44,6 +44,7 @@ TESTS += 003-qemu__fatal__wdebug_not_implemented
TESTS += 004-segmentation_fault_1 TESTS += 004-segmentation_fault_1
TESTS += 005-qemu__fatal__illegal_instruction__0000___00000404 TESTS += 005-qemu__fatal__illegal_instruction__0000___00000404
TESTS += 006-qemu__fatal__illegal_instruction__0421___00040026 TESTS += 006-qemu__fatal__illegal_instruction__0421___00040026
TESTS += mem_64_c
TESTS += memleak_x86 TESTS += memleak_x86
TESTS += memleak_arm TESTS += memleak_arm

39
tests/regress/mem_64_c.c Normal file
View file

@ -0,0 +1,39 @@
#include <stdio.h>
#include <unicorn/unicorn.h>
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, &regions, &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;
}