diff --git a/bindings/python/unicorn/__init__.py b/bindings/python/unicorn/__init__.py index 066df054..d75278bc 100644 --- a/bindings/python/unicorn/__init__.py +++ b/bindings/python/unicorn/__init__.py @@ -53,6 +53,7 @@ __all__ = [ 'UC_ERR_CODE_INVALID', 'UC_ERR_HOOK', 'UC_ERR_INSN_INVALID', + 'UC_ERR_MAP', 'UC_HOOK_INTR', 'UC_HOOK_INSN', @@ -122,6 +123,7 @@ UC_ERR_MEM_WRITE = 8 # Quit emulation due to invalid memory WRITE: uc_emu_st UC_ERR_CODE_INVALID = 9 # Quit emulation due to invalid code address: uc_emu_start() UC_ERR_HOOK = 10 # Invalid hook type: uc_hook_add() UC_ERR_INSN_INVALID = 11 # Invalid instruction +UC_ERR_MAP = 12 # Invalid memory mapping # All type of hooks for uc_hook_add() API. diff --git a/include/unicorn/unicorn.h b/include/unicorn/unicorn.h index 474c6afe..faea2016 100644 --- a/include/unicorn/unicorn.h +++ b/include/unicorn/unicorn.h @@ -116,6 +116,7 @@ typedef enum uc_err { UC_ERR_CODE_INVALID, // Quit emulation due to invalid code address: uc_emu_start() 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; diff --git a/uc.c b/uc.c index 3c59f0c8..3472c78a 100644 --- a/uc.c +++ b/uc.c @@ -126,6 +126,8 @@ const char *uc_strerror(uc_err code) return "Invalid instruction (UC_ERR_INSN_INVALID)"; case UC_ERR_HOOK: return "Invalid hook type (UC_ERR_HOOK)"; + case UC_ERR_MAP: + return "Invalid memory mapping (UC_ERR_MAP)"; } } @@ -552,6 +554,10 @@ uc_err uc_mem_map(uch handle, uint64_t address, size_t size) // invalid handle return UC_ERR_UCH; + if (size == 0) + // invalid memory mapping + return UC_ERR_MAP; + // align to 8KB boundary map_begin[map_count] = address & (~ (8*1024 - 1)); s = (size + 8*1024 - 1) & (~ (8*1024 - 1));