diff --git a/qemu/memory.c b/qemu/memory.c index be7933d5..8d5604b9 100644 --- a/qemu/memory.c +++ b/qemu/memory.c @@ -49,9 +49,12 @@ void memory_unmap(struct uc_struct *uc, MemoryRegion *mr) { int i; target_ulong addr; - //make sure all pages associated with the MemoryRegion are flushed - for (addr = mr->addr; addr < mr->end; addr += uc->target_page_size) { - tlb_flush_page(uc->current_cpu, addr); + // Make sure all pages associated with the MemoryRegion are flushed + // Only need to do this if we are in a running state + if (uc->current_cpu) { + for (addr = mr->addr; addr < mr->end; addr += uc->target_page_size) { + tlb_flush_page(uc->current_cpu, addr); + } } mr->enabled = false; memory_region_del_subregion(get_system_memory(uc), mr); diff --git a/regress/Makefile b/regress/Makefile index 806db172..14d5c383 100644 --- a/regress/Makefile +++ b/regress/Makefile @@ -7,6 +7,9 @@ TESTS += block_test TESTS += ro_mem_test nr_mem_test TESTS += timeout_segfault TESTS += rep_movsb +TESTS += mem_unmap +TESTS += mem_protect +TESTS += mem_exec all: $(TESTS) diff --git a/samples/mem_exec.c b/regress/mem_exec.c similarity index 100% rename from samples/mem_exec.c rename to regress/mem_exec.c diff --git a/samples/mem_protect.c b/regress/mem_protect.c similarity index 100% rename from samples/mem_protect.c rename to regress/mem_protect.c diff --git a/samples/mem_unmap.c b/regress/mem_unmap.c similarity index 100% rename from samples/mem_unmap.c rename to regress/mem_unmap.c diff --git a/samples/Makefile b/samples/Makefile index f6345ae8..1ebb891f 100644 --- a/samples/Makefile +++ b/samples/Makefile @@ -97,9 +97,6 @@ endif ifneq (,$(findstring x86,$(UNICORN_ARCHS))) SOURCES += sample_x86.c SOURCES += shellcode.c -SOURCES += mem_unmap.c -SOURCES += mem_protect.c -SOURCES += mem_exec.c endif ifneq (,$(findstring m68k,$(UNICORN_ARCHS))) SOURCES += sample_m68k.c @@ -114,8 +111,7 @@ all: $(BINARY) clean: rm -rf *.o $(OBJS_ELF) $(BINARY) $(SAMPLEDIR)/*.exe $(SAMPLEDIR)/*.static $(OBJDIR)/lib$(LIBNAME)* $(OBJDIR)/$(LIBNAME)* rm -rf libunicorn*.so libunicorn*.lib libunicorn*.dylib unicorn*.dll unicorn*.lib - rm -rf sample_x86 sample_arm sample_arm64 sample_mips sample_sparc sample_ppc sample_m68k \ - shellcode mem_unmap mem_protect mem_exec + rm -rf sample_x86 sample_arm sample_arm64 sample_mips sample_sparc sample_ppc sample_m68k shellcode $(BINARY): $(OBJS)