From 658e399776954f046689c5409486437af5e9bc3d Mon Sep 17 00:00:00 2001 From: Chris Eagle Date: Mon, 31 Aug 2015 19:08:48 -0700 Subject: [PATCH] clean up mem_protect related constants --- include/unicorn/unicorn.h | 5 +++-- qemu/softmmu_template.h | 16 ++++++++-------- uc.c | 10 ++++++---- 3 files changed, 17 insertions(+), 14 deletions(-) diff --git a/include/unicorn/unicorn.h b/include/unicorn/unicorn.h index e4b5e359..962598a8 100644 --- a/include/unicorn/unicorn.h +++ b/include/unicorn/unicorn.h @@ -116,8 +116,9 @@ typedef enum uc_err { UC_ERR_HOOK, // Invalid hook type: uc_hook_add() UC_ERR_INSN_INVALID, // Quit emulation due to invalid instruction: uc_emu_start() UC_ERR_MAP, // Invalid memory mapping: uc_mem_map() - UC_ERR_MEM_WRITE_NW, // Quit emulation due to write to non-writable: uc_emu_start() - UC_ERR_MEM_READ_NR, // Quit emulation due to read from non-readable: uc_emu_start() + UC_ERR_PROT_WRITE, // Quit emulation due to UC_PROT_WRITE violation: uc_emu_start() + UC_ERR_PROT_READ, // Quit emulation due to UC_PROT_READ violation: uc_emu_start() + UC_ERR_PROT_EXEC, // Quit emulation due to UC_PROT_EXEC violation: uc_emu_start() } uc_err; diff --git a/qemu/softmmu_template.h b/qemu/softmmu_template.h index 8c181824..a448a787 100644 --- a/qemu/softmmu_template.h +++ b/qemu/softmmu_template.h @@ -191,8 +191,8 @@ WORD_TYPE helper_le_ld_name(CPUArchState *env, target_ulong addr, int mmu_idx, } else { env->invalid_addr = addr; - env->invalid_error = UC_ERR_MEM_READ; - // printf("***** Invalid memory read (non-readable) at " TARGET_FMT_lx "\n", addr); + env->invalid_error = UC_ERR_PROT_EXEC; + // printf("***** Invalid fetch (non-executable) at " TARGET_FMT_lx "\n", addr); cpu_exit(uc->current_cpu); return 0; } @@ -233,7 +233,7 @@ WORD_TYPE helper_le_ld_name(CPUArchState *env, target_ulong addr, int mmu_idx, } else { env->invalid_addr = addr; - env->invalid_error = UC_ERR_MEM_READ_NR; + env->invalid_error = UC_ERR_PROT_READ; // printf("***** Invalid memory read (non-readable) at " TARGET_FMT_lx "\n", addr); cpu_exit(uc->current_cpu); return 0; @@ -350,8 +350,8 @@ WORD_TYPE helper_be_ld_name(CPUArchState *env, target_ulong addr, int mmu_idx, } else { env->invalid_addr = addr; - env->invalid_error = UC_ERR_MEM_READ; - // printf("***** Invalid memory read (non-readable) at " TARGET_FMT_lx "\n", addr); + env->invalid_error = UC_ERR_PROT_EXEC; + // printf("***** Invalid fetch (non-executable) at " TARGET_FMT_lx "\n", addr); cpu_exit(uc->current_cpu); return 0; } @@ -392,7 +392,7 @@ WORD_TYPE helper_be_ld_name(CPUArchState *env, target_ulong addr, int mmu_idx, } else { env->invalid_addr = addr; - env->invalid_error = UC_ERR_MEM_READ_NR; + env->invalid_error = UC_ERR_PROT_READ; // printf("***** Invalid memory read (non-readable) at " TARGET_FMT_lx "\n", addr); cpu_exit(uc->current_cpu); return 0; @@ -571,7 +571,7 @@ void helper_le_st_name(CPUArchState *env, target_ulong addr, DATA_TYPE val, } else { env->invalid_addr = addr; - env->invalid_error = UC_ERR_MEM_WRITE_NW; + env->invalid_error = UC_ERR_PROT_WRITE; // printf("***** Invalid memory write (ro) at " TARGET_FMT_lx "\n", addr); cpu_exit(uc->current_cpu); return; @@ -705,7 +705,7 @@ void helper_be_st_name(CPUArchState *env, target_ulong addr, DATA_TYPE val, } else { env->invalid_addr = addr; - env->invalid_error = UC_ERR_MEM_WRITE_NW; + env->invalid_error = UC_ERR_PROT_WRITE; // printf("***** Invalid memory write (ro) at " TARGET_FMT_lx "\n", addr); cpu_exit(uc->current_cpu); return; diff --git a/uc.c b/uc.c index 2dddb39c..85624a36 100644 --- a/uc.c +++ b/uc.c @@ -92,10 +92,12 @@ const char *uc_strerror(uc_err code) return "Invalid hook type (UC_ERR_HOOK)"; case UC_ERR_MAP: return "Invalid memory mapping (UC_ERR_MAP)"; - case UC_ERR_MEM_WRITE_NW: - return "Write to non-writable (UC_ERR_MEM_WRITE_NW)"; - case UC_ERR_MEM_READ_NR: - return "Read from non-readable (UC_ERR_MEM_READ_NR)"; + case UC_ERR_PROT_WRITE: + return "Write to non-writable memory (UC_ERR_PROT_WRITE)"; + case UC_ERR_PROT_READ: + return "Read from non-readable memory (UC_ERR_PROT_READ)"; + case UC_ERR_PROT_EXEC: + return "Fetch from non-executable memory (UC_ERR_PROT_EXEC)"; } }