summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorL. E. Segovia <amy@centricular.com>2024-04-09 14:02:11 -0300
committerGStreamer Marge Bot <gitlab-merge-bot@gstreamer-foundation.org>2024-04-15 18:38:56 +0000
commitbc7669480c0407f14d307efd014f3f58404b979c (patch)
treec5f892f514d529c0189ae845dde90fd801d71558
parent95d7f4f9a3b06156e0d0f712e3f1aae938d96525 (diff)
orccompiler: Implement checking for JIT support under Linux
This enables falling back to emulation when mmap(2) is not available for executable pages. This seems to be the case under a combination of SELinux sandboxing and noexec mounting. Part-of: <https://gitlab.freedesktop.org/gstreamer/orc/-/merge_requests/176>
-rw-r--r--orc/orccodemem.c2
-rw-r--r--orc/orccompiler.c32
-rw-r--r--orc/orcinternal.h5
3 files changed, 29 insertions, 10 deletions
diff --git a/orc/orccodemem.c b/orc/orccodemem.c
index e128d0d..c59c77e 100644
--- a/orc/orccodemem.c
+++ b/orc/orccodemem.c
@@ -37,8 +37,6 @@
/* See _orc_compiler_init() */
extern int _orc_codemem_alignment;
-typedef struct _OrcCodeRegion OrcCodeRegion;
-
struct _OrcCodeRegion {
orc_uint8 *write_ptr;
orc_uint8 *exec_ptr;
diff --git a/orc/orccompiler.c b/orc/orccompiler.c
index 7591858..b3e29e0 100644
--- a/orc/orccompiler.c
+++ b/orc/orccompiler.c
@@ -112,16 +112,18 @@ _orc_compiler_init (void)
_orc_codemem_alignment = 15;
#endif
-#ifdef ORC_WINAPI_ONLY_APP
- if (!_orc_compiler_flag_backup && !_orc_compiler_flag_emulate) {
- int can_jit = FALSE;
+ int can_jit = TRUE;
+ if (!_orc_compiler_flag_backup && !_orc_compiler_flag_emulate) {
/* If backup code is not enabled and emulation is not enabled, that means
* we will do JIT compilation and call orc_code_region_allocate_codemem().
- * When targeting Windows Store apps, the codeGeneration capability must
+ */
+#if defined(HAVE_CODEMEM_VIRTUALALLOC) && defined(ORC_WINAPI_ONLY_APP)
+ /* When targeting Windows Store apps, the codeGeneration capability must
* be enabled in the app manifest, or passing PAGE_EXECUTE to
* VirtualProtectFromApp will return NULL. In this case, we must force
* backup C code, and if that's not available, we must emulate. */
+ can_jit = FALSE;
void *mem = VirtualAllocFromApp (NULL, page_size, MEM_COMMIT,
PAGE_READWRITE);
if (mem) {
@@ -129,16 +131,32 @@ _orc_compiler_init (void)
if (VirtualProtectFromApp (mem, page_size, PAGE_EXECUTE, &old_protect) > 0)
can_jit = TRUE;
VirtualFree (mem, 0, MEM_RELEASE);
+ } else {
+ ORC_WARNING ("Unable to allocate executable pages: using backup code or "
+ "emulation: codeGeneration capability isn't set in the app manifest?");
}
+#elif defined(HAVE_CODEMEM_MMAP)
+ /* In this case, we need to check that we can mmap pages as executable.
+ * This is not the case under the combination of SELinux and sandboxing
+ * profiles.
+ */
+ can_jit = FALSE;
+ OrcCodeRegion *region = orc_code_region_alloc();
+ if (region) {
+ can_jit = TRUE;
+ // FIXME: the file descriptor should be kept somewhere
+ // Currently the underlying mmap'd pages are leaked
+ free(region);
+ } else {
+ ORC_WARNING ("Unable to allocate executable pages: using backup code or emulation");
+ }
+#endif
if (!can_jit) {
- ORC_WARNING ("Unable to allocate executable pages: using backup code or "
- "emulation: codeGeneration capability isn't set in the app manifest?");
_orc_compiler_flag_backup = TRUE;
_orc_compiler_flag_emulate = TRUE;
}
}
-#endif
}
int
diff --git a/orc/orcinternal.h b/orc/orcinternal.h
index d1355a0..f7374a4 100644
--- a/orc/orcinternal.h
+++ b/orc/orcinternal.h
@@ -21,9 +21,12 @@ void orc_c64x_init (void);
void orc_c64x_c_init (void);
void orc_mips_init (void);
+typedef struct _OrcCodeRegion OrcCodeRegion;
typedef struct _OrcCodeChunk OrcCodeChunk;
-/* This is internal API, nothing in the public headers returns an OrcCodeChunk */
+/* This is internal API, nothing in the public headers returns an OrcCodeChunk
+ */
+OrcCodeRegion * orc_code_region_alloc (void);
void orc_code_chunk_free (OrcCodeChunk *chunk);
extern int _orc_data_cache_size_level1;