Commit b8f7c8da authored by Seungha Yang's avatar Seungha Yang 🐑 Committed by GStreamer Marge Bot
Browse files

orc: Fix ORC_ERROR messages when generating code with orcc.exe on windows

Apply the fix orc!44

Part-of: <!694>
parent e752c6df
Pipeline #299738 canceled with stages
in 64 minutes and 57 seconds
......@@ -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):
......
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
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
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
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment