[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH v7 47/52] osdep: introduce qemu_mprotect_rwx/none
From: |
Richard Henderson |
Subject: |
[Qemu-devel] [PATCH v7 47/52] osdep: introduce qemu_mprotect_rwx/none |
Date: |
Fri, 20 Oct 2017 16:20:18 -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
- Re: [Qemu-devel] [PATCH v7 37/52] tcg: Remove CF_IGNORE_ICOUNT, (continued)
- [Qemu-devel] [PATCH v7 39/52] exec-all: rename tb_free to tb_remove, Richard Henderson, 2017/10/20
- [Qemu-devel] [PATCH v7 38/52] translate-all: use a binary search tree to track TBs in TBContext, Richard Henderson, 2017/10/20
- [Qemu-devel] [PATCH v7 40/52] translate-all: report correct avg host TB size, Richard Henderson, 2017/10/20
- [Qemu-devel] [PATCH v7 41/52] tcg: take tb_ctx out of TCGContext, Richard Henderson, 2017/10/20
- [Qemu-devel] [PATCH v7 44/52] tcg: introduce **tcg_ctxs to keep track of all TCGContext's, Richard Henderson, 2017/10/20
- [Qemu-devel] [PATCH v7 45/52] tcg: distribute profiling counters across TCGContext's, Richard Henderson, 2017/10/20
- [Qemu-devel] [PATCH v7 42/52] tcg: define tcg_init_ctx and make tcg_ctx a pointer, Richard Henderson, 2017/10/20
- [Qemu-devel] [PATCH v7 46/52] tcg: allocate optimizer temps with tcg_malloc, Richard Henderson, 2017/10/20
- [Qemu-devel] [PATCH v7 43/52] gen-icount: fold exitreq_label into TCGContext, Richard Henderson, 2017/10/20
- [Qemu-devel] [PATCH v7 47/52] osdep: introduce qemu_mprotect_rwx/none,
Richard Henderson <=
- [Qemu-devel] [PATCH v7 49/52] tcg: introduce regions to split code_gen_buffer, Richard Henderson, 2017/10/20
- [Qemu-devel] [PATCH v7 50/52] tcg: enable multiple TCG contexts in softmmu, Richard Henderson, 2017/10/20
- [Qemu-devel] [PATCH v7 52/52] translate-all: exit from tb_phys_invalidate if qht_remove fails, Richard Henderson, 2017/10/20
- [Qemu-devel] [PATCH v7 48/52] translate-all: use qemu_protect_rwx/none helpers, Richard Henderson, 2017/10/20
- [Qemu-devel] [PATCH v7 51/52] tcg: Initialize cpu_env generically, Richard Henderson, 2017/10/20
- Re: [Qemu-devel] [PATCH v7 00/52] tcg queued patches, no-reply, 2017/10/20
- Re: [Qemu-devel] [PATCH v7 00/52] tcg queued patches, no-reply, 2017/10/22
- Re: [Qemu-devel] [PATCH v7 00/52] tcg queued patches, Emilio G. Cota, 2017/10/23