[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 20/23] osdep: introduce qemu_mprotect_rwx/none
From: |
Richard Henderson |
Subject: |
[Qemu-devel] [PULL 20/23] osdep: introduce qemu_mprotect_rwx/none |
Date: |
Mon, 9 Oct 2017 17:55:57 -0700 |
From: "Emilio G. Cota" <address@hidden>
Reviewed-by: Richard Henderson <address@hidden>
Signed-off-by: Emilio G. Cota <address@hidden>
Signed-off-by: Richard Henderson <address@hidden>
---
include/qemu/osdep.h | 2 ++
util/osdep.c | 41 +++++++++++++++++++++++++++++++++++++++++
2 files changed, 43 insertions(+)
diff --git a/include/qemu/osdep.h b/include/qemu/osdep.h
index 826650c58a..281782d526 100644
--- a/include/qemu/osdep.h
+++ b/include/qemu/osdep.h
@@ -371,6 +371,8 @@ void sigaction_invoke(struct sigaction *action,
#endif
int qemu_madvise(void *addr, size_t len, int advice);
+int qemu_mprotect_rwx(void *addr, size_t size);
+int qemu_mprotect_none(void *addr, size_t size);
int qemu_open(const char *name, int flags, ...);
int qemu_close(int fd);
diff --git a/util/osdep.c b/util/osdep.c
index a479fedc4a..0cf6d9944c 100644
--- a/util/osdep.c
+++ b/util/osdep.c
@@ -73,6 +73,47 @@ int qemu_madvise(void *addr, size_t len, int advice)
#endif
}
+static int qemu_mprotect__osdep(void *addr, size_t size, int prot)
+{
+ g_assert(!((uintptr_t)addr & ~qemu_real_host_page_mask));
+ g_assert(!(size & ~qemu_real_host_page_mask));
+
+#ifdef _WIN32
+ DWORD old_protect;
+
+ if (!VirtualProtect(addr, size, prot, &old_protect)) {
+ error_report("%s: VirtualProtect failed with error code %d",
+ __func__, GetLastError());
+ return -1;
+ }
+ return 0;
+#else
+ if (mprotect(addr, size, prot)) {
+ error_report("%s: mprotect failed: %s", __func__, strerror(errno));
+ return -1;
+ }
+ return 0;
+#endif
+}
+
+int qemu_mprotect_rwx(void *addr, size_t size)
+{
+#ifdef _WIN32
+ return qemu_mprotect__osdep(addr, size, PAGE_EXECUTE_READWRITE);
+#else
+ return qemu_mprotect__osdep(addr, size, PROT_READ | PROT_WRITE |
PROT_EXEC);
+#endif
+}
+
+int qemu_mprotect_none(void *addr, size_t size)
+{
+#ifdef _WIN32
+ return qemu_mprotect__osdep(addr, size, PAGE_NOACCESS);
+#else
+ return qemu_mprotect__osdep(addr, size, PROT_NONE);
+#endif
+}
+
#ifndef _WIN32
static int fcntl_op_setlk = -1;
--
2.13.6
- [Qemu-devel] [PULL 09/23] tcg: consolidate TB lookups in tb_lookup__cpu_state, (continued)
- [Qemu-devel] [PULL 09/23] tcg: consolidate TB lookups in tb_lookup__cpu_state, Richard Henderson, 2017/10/09
- [Qemu-devel] [PULL 10/23] exec-all: bring tb->invalid into tb->cflags, Richard Henderson, 2017/10/09
- [Qemu-devel] [PULL 12/23] exec-all: introduce TB_PAGE_ADDR_FMT, Richard Henderson, 2017/10/09
- [Qemu-devel] [PULL 11/23] translate-all: define and use DEBUG_TB_FLUSH_GATE, Richard Henderson, 2017/10/09
- [Qemu-devel] [PULL 13/23] translate-all: define and use DEBUG_TB_INVALIDATE_GATE, Richard Henderson, 2017/10/09
- [Qemu-devel] [PULL 15/23] exec-all: extract tb->tc_* into a separate struct tc_tb, Richard Henderson, 2017/10/09
- [Qemu-devel] [PULL 17/23] tcg: take .helpers out of TCGContext, Richard Henderson, 2017/10/09
- [Qemu-devel] [PULL 14/23] translate-all: define and use DEBUG_TB_CHECK_GATE, Richard Henderson, 2017/10/09
- [Qemu-devel] [PULL 19/23] util: move qemu_real_host_page_size/mask to osdep.h, Richard Henderson, 2017/10/09
- [Qemu-devel] [PULL 16/23] tci: move tci_regs to tcg_qemu_tb_exec's stack, Richard Henderson, 2017/10/09
- [Qemu-devel] [PULL 20/23] osdep: introduce qemu_mprotect_rwx/none,
Richard Henderson <=
- [Qemu-devel] [PULL 21/23] translate-all: use qemu_protect_rwx/none helpers, Richard Henderson, 2017/10/09
- [Qemu-devel] [PULL 18/23] tcg: allocate optimizer temps with tcg_malloc, Richard Henderson, 2017/10/09
- [Qemu-devel] [PULL 22/23] tcg: define TCG_HIGHWATER, Richard Henderson, 2017/10/09
- [Qemu-devel] [PULL 23/23] tcg/mips: delete commented out extern keyword., Richard Henderson, 2017/10/09
- Re: [Qemu-devel] [PULL 00/23] Queued TCG patches, no-reply, 2017/10/09
- Re: [Qemu-devel] [PULL 00/23] Queued TCG patches, no-reply, 2017/10/09
- Re: [Qemu-devel] [PULL 00/23] Queued TCG patches, Peter Maydell, 2017/10/10