summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSeungha Yang <seungha@centricular.com>2021-04-12 21:30:37 +0900
committerGStreamer Marge Bot <gitlab-merge-bot@gstreamer-foundation.org>2021-04-12 15:23:03 +0000
commitb8f7c8da7cc1ff1e9b8037856cc4e2d527aff15a (patch)
tree84a1aa7fa2b77802ae726e88d551b0ed93dda883
parente752c6df1c6b648e3a0c61af160b2da516b29836 (diff)
orc: Fix ORC_ERROR messages when generating code with orcc.exe on windows
Apply the fix https://gitlab.freedesktop.org/gstreamer/orc/-/merge_requests/44 Part-of: <https://gitlab.freedesktop.org/gstreamer/cerbero/-/merge_requests/694>
-rw-r--r--recipes/orc.recipe4
-rw-r--r--recipes/orc/0001-orc-Fix-indentation.patch57
-rw-r--r--recipes/orc/0002-orc-Print-hex-value-directly-instead-of-a-constant.patch54
-rw-r--r--recipes/orc/0003-orc-Don-t-set-memory-protection-if-there-s-no-code.patch31
4 files changed, 146 insertions, 0 deletions
diff --git a/recipes/orc.recipe b/recipes/orc.recipe
index 3ef31f3c..b93a1b49 100644
--- a/recipes/orc.recipe
+++ b/recipes/orc.recipe
@@ -29,6 +29,10 @@ class Recipe(recipe.Recipe):
'orc/0003-orc-Fix-some-warnings-on-MSVC-and-enable-werror.patch',
# https://gitlab.freedesktop.org/gstreamer/orc/-/merge_requests/48
'orc/0001-orc-Use-page-size-aligned-memory-block-for-Windows.patch',
+ # https://gitlab.freedesktop.org/gstreamer/orc/-/merge_requests/44
+ 'orc/0001-orc-Fix-indentation.patch',
+ 'orc/0002-orc-Print-hex-value-directly-instead-of-a-constant.patch',
+ 'orc/0003-orc-Don-t-set-memory-protection-if-there-s-no-code.patch',
]
def prepare(self):
diff --git a/recipes/orc/0001-orc-Fix-indentation.patch b/recipes/orc/0001-orc-Fix-indentation.patch
new file mode 100644
index 00000000..48078a68
--- /dev/null
+++ b/recipes/orc/0001-orc-Fix-indentation.patch
@@ -0,0 +1,57 @@
+From 9e221d8bec087aceebbd81cca286dde6f74d31aa Mon Sep 17 00:00:00 2001
+From: Nirbheek Chauhan <nirbheek@centricular.com>
+Date: Thu, 2 Jul 2020 15:01:40 +0530
+Subject: [PATCH 1/3] orc: Fix indentation
+
+Only whitespace changes.
+
+Part-of: <https://gitlab.freedesktop.org/gstreamer/orc/-/merge_requests/44>
+---
+ orc/orccompiler.c | 27 ++++++++++++++-------------
+ 1 file changed, 14 insertions(+), 13 deletions(-)
+
+diff --git a/orc/orccompiler.c b/orc/orccompiler.c
+index 600e66b..e6bd43c 100644
+--- a/orc/orccompiler.c
++++ b/orc/orccompiler.c
+@@ -234,23 +234,24 @@ _get_protect_name (int protect)
+ static orc_bool
+ _set_virtual_protect (void * mem, size_t size, int code_protect)
+ {
+- char *msg;
+- DWORD old_protect;
++ char *msg;
++ DWORD old_protect;
+
+- if (!mem)
+- return FALSE;
+
+- if (_virtualprotect (mem, size, code_protect, &old_protect) > 0)
+- return TRUE;
++ if (!mem)
++ return FALSE;
+
+- FormatMessageA (FORMAT_MESSAGE_ALLOCATE_BUFFER
+- | FORMAT_MESSAGE_IGNORE_INSERTS | FORMAT_MESSAGE_FROM_SYSTEM, NULL,
+- GetLastError (), 0, (LPTSTR) &msg, 0, NULL);
+- ORC_ERROR ("Couldn't set memory protect on %p from %s to %s: %s", mem,
+- _get_protect_name (old_protect), _get_protect_name (code_protect), msg);
+- LocalFree (msg);
++ if (_virtualprotect (mem, size, code_protect, &old_protect) > 0)
++ return TRUE;
+
+- return FALSE;
++ FormatMessageA (FORMAT_MESSAGE_ALLOCATE_BUFFER
++ | FORMAT_MESSAGE_IGNORE_INSERTS | FORMAT_MESSAGE_FROM_SYSTEM, NULL,
++ GetLastError (), 0, (LPTSTR) &msg, 0, NULL);
++ ORC_ERROR ("Couldn't set memory protect on %p from %s to %s: %s", mem,
++ _get_protect_name (old_protect), _get_protect_name (code_protect), msg);
++ LocalFree (msg);
++
++ return FALSE;
+ }
+ #endif
+
+--
+2.25.1
+
diff --git a/recipes/orc/0002-orc-Print-hex-value-directly-instead-of-a-constant.patch b/recipes/orc/0002-orc-Print-hex-value-directly-instead-of-a-constant.patch
new file mode 100644
index 00000000..9f721097
--- /dev/null
+++ b/recipes/orc/0002-orc-Print-hex-value-directly-instead-of-a-constant.patch
@@ -0,0 +1,54 @@
+From e6ff84bdf56eb8213f240b2e74ec441d8ec80814 Mon Sep 17 00:00:00 2001
+From: Nirbheek Chauhan <nirbheek@centricular.com>
+Date: Thu, 2 Jul 2020 15:02:12 +0530
+Subject: [PATCH 2/3] orc: Print hex value directly instead of a constant
+
+This is actually more useful because the constants are all bitfields
+and it's fairly straightforward to look it up:
+
+https://docs.microsoft.com/en-us/windows/win32/memory/memory-protection-constants
+
+Part-of: <https://gitlab.freedesktop.org/gstreamer/orc/-/merge_requests/44>
+---
+ orc/orccompiler.c | 18 ++----------------
+ 1 file changed, 2 insertions(+), 16 deletions(-)
+
+diff --git a/orc/orccompiler.c b/orc/orccompiler.c
+index e6bd43c..23a1a84 100644
+--- a/orc/orccompiler.c
++++ b/orc/orccompiler.c
+@@ -217,20 +217,6 @@ orc_program_compile_for_target (OrcProgram *program, OrcTarget *target)
+ }
+
+ #if defined(HAVE_CODEMEM_VIRTUALALLOC)
+-static const char*
+-_get_protect_name (int protect)
+-{
+- switch (protect) {
+- /* These are the only two memory protection constants we use */
+- case PAGE_EXECUTE:
+- return "execute";
+- case PAGE_READWRITE:
+- return "readwrite";
+- default:
+- return "unknown";
+- }
+-}
+-
+ static orc_bool
+ _set_virtual_protect (void * mem, size_t size, int code_protect)
+ {
+@@ -247,8 +233,8 @@ _set_virtual_protect (void * mem, size_t size, int code_protect)
+ FormatMessageA (FORMAT_MESSAGE_ALLOCATE_BUFFER
+ | FORMAT_MESSAGE_IGNORE_INSERTS | FORMAT_MESSAGE_FROM_SYSTEM, NULL,
+ GetLastError (), 0, (LPTSTR) &msg, 0, NULL);
+- ORC_ERROR ("Couldn't set memory protect on %p from %s to %s: %s", mem,
+- _get_protect_name (old_protect), _get_protect_name (code_protect), msg);
++ ORC_ERROR ("Couldn't set memory protect on %p from %x to %x: %s", mem,
++ old_protect, code_protect, msg);
+ LocalFree (msg);
+
+ return FALSE;
+--
+2.25.1
+
diff --git a/recipes/orc/0003-orc-Don-t-set-memory-protection-if-there-s-no-code.patch b/recipes/orc/0003-orc-Don-t-set-memory-protection-if-there-s-no-code.patch
new file mode 100644
index 00000000..08cfa638
--- /dev/null
+++ b/recipes/orc/0003-orc-Don-t-set-memory-protection-if-there-s-no-code.patch
@@ -0,0 +1,31 @@
+From 1ec0f3f9238d44eb9c60d72c3572c42c98cf2ad4 Mon Sep 17 00:00:00 2001
+From: Nirbheek Chauhan <nirbheek@centricular.com>
+Date: Thu, 2 Jul 2020 15:02:57 +0530
+Subject: [PATCH 3/3] orc: Don't set memory protection if there's no code
+
+If the size of the JIT code is 0, there's no code and the *mem is
+uninitialized. This can happen when orcc.exe is used to generate
+backup C code.
+
+Part-of: <https://gitlab.freedesktop.org/gstreamer/orc/-/merge_requests/44>
+---
+ orc/orccompiler.c | 3 +++
+ 1 file changed, 3 insertions(+)
+
+diff --git a/orc/orccompiler.c b/orc/orccompiler.c
+index 23a1a84..63eee29 100644
+--- a/orc/orccompiler.c
++++ b/orc/orccompiler.c
+@@ -223,6 +223,9 @@ _set_virtual_protect (void * mem, size_t size, int code_protect)
+ char *msg;
+ DWORD old_protect;
+
++ /* No code, so we 'succeed' */
++ if (size == 0)
++ return TRUE;
+
+ if (!mem)
+ return FALSE;
+--
+2.25.1
+