pluginloader-win32: Use UWP compatible Windows API

CreateFile2 API should be used in case of UWP

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/4556>
This commit is contained in:
Seungha Yang 2023-05-05 23:21:22 +09:00 committed by GStreamer Marge Bot
parent 4449881b08
commit c789b66971
2 changed files with 31 additions and 10 deletions

View file

@ -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 (&params, 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, &params);
#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;

View file

@ -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')