summaryrefslogtreecommitdiffstats
path: root/include/qemu
diff options
context:
space:
mode:
authorRoman Bolshakov2021-01-13 04:28:07 +0100
committerRichard Henderson2021-01-23 23:13:00 +0100
commit653b87eb36045b506b79f0bb433016ef1c54bc9a (patch)
tree9072762b0292a3b668f5e55f94da53e1edb9c5a2 /include/qemu
parentaccel/tcg: Restrict cpu_io_recompile() from other accelerators (diff)
downloadqemu-653b87eb36045b506b79f0bb433016ef1c54bc9a.tar.gz
qemu-653b87eb36045b506b79f0bb433016ef1c54bc9a.tar.xz
qemu-653b87eb36045b506b79f0bb433016ef1c54bc9a.zip
tcg: Toggle page execution for Apple Silicon
Pages can't be both write and executable at the same time on Apple Silicon. macOS provides public API to switch write protection [1] for JIT applications, like TCG. 1. https://developer.apple.com/documentation/apple_silicon/porting_just-in-time_compilers_to_apple_silicon Tested-by: Alexander Graf <agraf@csgraf.de> Signed-off-by: Roman Bolshakov <r.bolshakov@yadro.com> Message-Id: <20210113032806.18220-1-r.bolshakov@yadro.com> [rth: Inline the qemu_thread_jit_* functions; drop the MAP_JIT change for a follow-on patch.] Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
Diffstat (limited to 'include/qemu')
-rw-r--r--include/qemu/osdep.h28
1 files changed, 28 insertions, 0 deletions
diff --git a/include/qemu/osdep.h b/include/qemu/osdep.h
index a434382c58..b6ffdc15bf 100644
--- a/include/qemu/osdep.h
+++ b/include/qemu/osdep.h
@@ -119,6 +119,10 @@ extern int daemon(int, int);
#include "sysemu/os-posix.h"
#endif
+#ifdef __APPLE__
+#include <AvailabilityMacros.h>
+#endif
+
#include "glib-compat.h"
#include "qemu/typedefs.h"
@@ -682,4 +686,28 @@ char *qemu_get_host_name(Error **errp);
*/
size_t qemu_get_host_physmem(void);
+/*
+ * Toggle write/execute on the pages marked MAP_JIT
+ * for the current thread.
+ */
+#if defined(MAC_OS_VERSION_11_0) && \
+ MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_VERSION_11_0
+static inline void qemu_thread_jit_execute(void)
+{
+ if (__builtin_available(macOS 11.0, *)) {
+ pthread_jit_write_protect_np(true);
+ }
+}
+
+static inline void qemu_thread_jit_write(void)
+{
+ if (__builtin_available(macOS 11.0, *)) {
+ pthread_jit_write_protect_np(false);
+ }
+}
+#else
+static inline void qemu_thread_jit_write(void) {}
+static inline void qemu_thread_jit_execute(void) {}
+#endif
+
#endif