From c789b669718526f44932603c9b77ae3d27abc70f Mon Sep 17 00:00:00 2001 From: Seungha Yang Date: Fri, 5 May 2023 23:21:22 +0900 Subject: [PATCH] pluginloader-win32: Use UWP compatible Windows API CreateFile2 API should be used in case of UWP Part-of: --- .../gstreamer/gst/gstpluginloader-win32.c | 38 +++++++++++++++---- subprojects/gstreamer/gst/meson.build | 3 +- 2 files changed, 31 insertions(+), 10 deletions(-) diff --git a/subprojects/gstreamer/gst/gstpluginloader-win32.c b/subprojects/gstreamer/gst/gstpluginloader-win32.c index 9844379cd2..d7ace0201c 100644 --- a/subprojects/gstreamer/gst/gstpluginloader-win32.c +++ b/subprojects/gstreamer/gst/gstpluginloader-win32.c @@ -1210,6 +1210,25 @@ gst_plugin_loader_free (GstPluginLoader * self) return got_plugin_detail; } +static HANDLE +gst_plugin_loader_client_create_file (LPCWSTR pipe_name) +{ +#if (_WIN32_WINNT >= _WIN32_WINNT_WIN8) + CREATEFILE2_EXTENDED_PARAMETERS params; + memset (¶ms, 0, sizeof (CREATEFILE2_EXTENDED_PARAMETERS)); + params.dwSize = sizeof (CREATEFILE2_EXTENDED_PARAMETERS); + params.dwFileFlags = FILE_FLAG_OVERLAPPED; + params.dwSecurityQosFlags = SECURITY_IMPERSONATION; + + return CreateFile2 (pipe_name, + GENERIC_READ | GENERIC_WRITE, 0, OPEN_EXISTING, ¶ms); +#else + return CreateFileW (pipe_name, + GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, + FILE_FLAG_OVERLAPPED, NULL); +#endif +} + /* child process routine */ gboolean _gst_plugin_loader_client_run (const gchar * pipe_name) @@ -1218,25 +1237,27 @@ _gst_plugin_loader_client_run (const gchar * pipe_name) Win32PluginLoader loader; DWORD pipe_mode = PIPE_READMODE_MESSAGE; gchar *err = NULL; + LPWSTR pipe_name_wide; + + pipe_name_wide = (LPWSTR) g_utf8_to_utf16 (pipe_name, -1, NULL, NULL, NULL); + if (!pipe_name_wide) { + GST_ERROR ("Couldn't convert %s to wide string", pipe_name); + return FALSE; + } win32_plugin_loader_init (&loader, TRUE); GST_DEBUG ("Connecting pipe %s", pipe_name); /* Connect to server's named pipe */ - loader.pipe = CreateFileA (pipe_name, - GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, - FILE_FLAG_OVERLAPPED, NULL); + loader.pipe = gst_plugin_loader_client_create_file (pipe_name_wide); loader.last_err = GetLastError (); if (loader.pipe == INVALID_HANDLE_VALUE) { /* Server should be pending (waiting for connection) state already, * but do retry if it's not the case */ if (loader.last_err == ERROR_PIPE_BUSY) { - if (WaitNamedPipeA (pipe_name, 5000)) { - loader.pipe = CreateFileA (pipe_name, - GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, - FILE_FLAG_OVERLAPPED, NULL); - } + if (WaitNamedPipeW (pipe_name_wide, 5000)) + loader.pipe = gst_plugin_loader_client_create_file (pipe_name_wide); loader.last_err = GetLastError (); } @@ -1271,6 +1292,7 @@ _gst_plugin_loader_client_run (const gchar * pipe_name) out: g_free (err); + g_free (pipe_name_wide); win32_plugin_loader_clear (&loader); return ret; diff --git a/subprojects/gstreamer/gst/meson.build b/subprojects/gstreamer/gst/meson.build index 6af53ffef4..90ef85a867 100644 --- a/subprojects/gstreamer/gst/meson.build +++ b/subprojects/gstreamer/gst/meson.build @@ -154,8 +154,7 @@ endif install_headers(gst_headers, subdir : 'gstreamer-1.0/gst') -# Some Win32 APIs are not allowed for UWP -if host_system == 'windows' and not building_for_uwp +if host_system == 'windows' gst_sources += files('gstpluginloader-win32.c') else gst_sources += files('gstpluginloader.c')