[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH v6 47/50] osdep: introduce qemu_mprotect_rwx/none
From: |
Richard Henderson |
Subject: |
[Qemu-devel] [PATCH v6 47/50] osdep: introduce qemu_mprotect_rwx/none |
Date: |
Mon, 16 Oct 2017 10:26:06 -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..1231f9f876 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 %ld",
+ __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] [PATCH v6 37/50] tcg: Remove CF_IGNORE_ICOUNT, (continued)
- [Qemu-devel] [PATCH v6 37/50] tcg: Remove CF_IGNORE_ICOUNT, Richard Henderson, 2017/10/16
- [Qemu-devel] [PATCH v6 34/50] tcg: check CF_PARALLEL instead of parallel_cpus, Richard Henderson, 2017/10/16
- [Qemu-devel] [PATCH v6 38/50] translate-all: use a binary search tree to track TBs in TBContext, Richard Henderson, 2017/10/16
- [Qemu-devel] [PATCH v6 40/50] translate-all: report correct avg host TB size, Richard Henderson, 2017/10/16
- [Qemu-devel] [PATCH v6 39/50] exec-all: rename tb_free to tb_remove, Richard Henderson, 2017/10/16
- [Qemu-devel] [PATCH v6 41/50] tcg: take tb_ctx out of TCGContext, Richard Henderson, 2017/10/16
- [Qemu-devel] [PATCH v6 43/50] gen-icount: fold exitreq_label into TCGContext, Richard Henderson, 2017/10/16
- [Qemu-devel] [PATCH v6 44/50] tcg: introduce **tcg_ctxs to keep track of all TCGContext's, Richard Henderson, 2017/10/16
- [Qemu-devel] [PATCH v6 47/50] osdep: introduce qemu_mprotect_rwx/none,
Richard Henderson <=
- [Qemu-devel] [PATCH v6 45/50] tcg: distribute profiling counters across TCGContext's, Richard Henderson, 2017/10/16
- [Qemu-devel] [PATCH v6 48/50] translate-all: use qemu_protect_rwx/none helpers, Richard Henderson, 2017/10/16
- [Qemu-devel] [PATCH v6 46/50] tcg: allocate optimizer temps with tcg_malloc, Richard Henderson, 2017/10/16
- [Qemu-devel] [PATCH v6 42/50] tcg: define tcg_init_ctx and make tcg_ctx a pointer, Richard Henderson, 2017/10/16
- [Qemu-devel] [PATCH v6 49/50] tcg: introduce regions to split code_gen_buffer, Richard Henderson, 2017/10/16
- [Qemu-devel] [PATCH v6 50/50] tcg: enable multiple TCG contexts in softmmu, Richard Henderson, 2017/10/16
- Re: [Qemu-devel] [PATCH v6 00/50] tcg tb_lock removal, no-reply, 2017/10/16
- Re: [Qemu-devel] [PATCH v6 00/50] tcg tb_lock removal, Emilio G. Cota, 2017/10/18