summaryrefslogtreecommitdiff
path: root/orc/orccodemem.c
diff options
context:
space:
mode:
authorNirbheek Chauhan <nirbheek@centricular.com>2020-06-30 16:16:39 +0530
committerNirbheek Chauhan <nirbheek@centricular.com>2020-07-01 07:26:16 +0530
commitcd8eabf041a14b5cdcc13c5436dbccdd66d558bb (patch)
treef8a0ada6c886a48707d6ac6898d988939cd0c9e3 /orc/orccodemem.c
parente990f2e17a1eb6c195583db15b25dd1bba88dfa9 (diff)
downloadorc-cd8eabf041a14b5cdcc13c5436dbccdd66d558bb.tar.gz
orccodemem: Add support for Universal Windows Platform apps
VirtualAlloc is VirtualAllocFromApp when targeting UWP, and you can only allocate executable pages if you have the codeGeneration capability set in the app manifest. Check for that capability in _orc_compiler_init() and switch to backup code or emulation if it isn't available instead of crashing when VirtualAllocFromApp returns NULL. Also you cannot allocate pages that are both READWRITE and EXECUTE, so we allocate as read-write first, then set the memory as execute-only after the code has been compiled and copied over. Part-of: <https://gitlab.freedesktop.org/gstreamer/orc/-/merge_requests/42>
Diffstat (limited to 'orc/orccodemem.c')
-rw-r--r--orc/orccodemem.c12
1 files changed, 11 insertions, 1 deletions
diff --git a/orc/orccodemem.c b/orc/orccodemem.c
index 14aadbd..0081835 100644
--- a/orc/orccodemem.c
+++ b/orc/orccodemem.c
@@ -11,11 +11,18 @@
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
+
#ifdef HAVE_CODEMEM_MMAP
#include <sys/mman.h>
#endif
+
#ifdef HAVE_CODEMEM_VIRTUALALLOC
#include <windows.h>
+ #ifdef ORC_WINAPI_ONLY_APP
+ #define _virtualalloc VirtualAllocFromApp
+ #else
+ #define _virtualalloc VirtualAlloc
+ #endif
#endif
#include <orc/orcinternal.h>
@@ -299,7 +306,10 @@ orc_code_region_allocate_codemem (OrcCodeRegion *region)
void
orc_code_region_allocate_codemem (OrcCodeRegion *region)
{
- region->write_ptr = VirtualAlloc(NULL, SIZE, MEM_COMMIT, PAGE_EXECUTE_READWRITE);
+ /* On UWP, we can't allocate memory as executable from the start. We can only
+ * set that later after compiling and copying the code over. This is a good
+ * idea in general to avoid security issues, so we do it on win32 too. */
+ region->write_ptr = _virtualalloc (NULL, SIZE, MEM_COMMIT, PAGE_READWRITE);
region->exec_ptr = region->write_ptr;
region->size = SIZE;
}