aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorNIIBE Yutaka <[email protected]>2025-09-23 04:08:09 +0200
committerNIIBE Yutaka <[email protected]>2025-09-23 04:08:09 +0200
commit00a40c0c599fb439facf1af55495d7ca1e496683 (patch)
treee2213a6cb54e01869d3e6aca134d02d7d138a9af /src
parentestream: Support the %b conversion specifier from C23 (diff)
downloadlibgpg-error-00a40c0c599fb439facf1af55495d7ca1e496683.tar.gz
libgpg-error-00a40c0c599fb439facf1af55495d7ca1e496683.zip
w32:spawn: Fix thread-unfriendly internal check.
* src/gpgrt-int.h (_gpgrt_windows_feature): New. * src/init.c (windows_specific_init): New. (real_init) [HAVE_W32_SYSTEM]: Call windows_specific_init. (_gpgrt_windows_feature): New. * src/spawn-w32.c (check_windows_version): Remove. (_gpgrt_process_spawn): Use _gpgrt_windows_feature. -- Signed-off-by: NIIBE Yutaka <[email protected]>
Diffstat (limited to 'src')
-rw-r--r--src/gpgrt-int.h6
-rw-r--r--src/init.c49
-rw-r--r--src/spawn-w32.c25
3 files changed, 56 insertions, 24 deletions
diff --git a/src/gpgrt-int.h b/src/gpgrt-int.h
index 4de81c4..8d2a936 100644
--- a/src/gpgrt-int.h
+++ b/src/gpgrt-int.h
@@ -863,6 +863,12 @@ char *_gpgrt_w32_reg_get_string (const char *key);
wchar_t *_gpgrt_fname_to_wchar (const char *fname);
+enum gpgrt_windows_feature
+ {
+ GPGRT_WINDOWS_PROC_ATTRIBUTE,
+ GPGRT_WINDOWS_UNDER_WINE
+ };
+int _gpgrt_windows_feature (int);
#endif /*HAVE_W32_SYSTEM*/
diff --git a/src/init.c b/src/init.c
index 8a5e651..7f970d9 100644
--- a/src/init.c
+++ b/src/init.c
@@ -37,6 +37,12 @@
#include <windows.h>
+static struct windows_features
+{
+ unsigned int is_vista_or_later :1; /* If it's Vista or later. */
+ unsigned int semihosted_by_wine :1; /* If it's under Wine or not. */
+} windows_features;
+
static int tls_index = TLS_OUT_OF_INDEXES; /* Index for the TLS functions. */
static volatile int utf8_for_new_threads;
@@ -71,6 +77,26 @@ static void *(*custom_realloc)(void *a, size_t n);
+#ifdef HAVE_W32_SYSTEM
+static void
+windows_specific_init (void)
+{
+ OSVERSIONINFO osvi;
+ HMODULE hntdll = GetModuleHandle ("ntdll.dll");
+
+ memset (&osvi,0,sizeof(osvi));
+ osvi.dwOSVersionInfoSize = sizeof(osvi);
+ GetVersionEx (&osvi);
+
+ /* The feature of process/thread attribute is available on Vista or
+ later. */
+ windows_features.is_vista_or_later = (osvi.dwMajorVersion >= 6);
+
+ if (hntdll && GetProcAddress (hntdll, "wine_get_version"))
+ windows_features.semihosted_by_wine = 1;
+}
+#endif
+
static void
real_init (void)
{
@@ -85,6 +111,9 @@ real_init (void)
drop_locale_dir (locale_dir);
}
#endif
+#ifdef HAVE_W32_SYSTEM
+ windows_specific_init ();
+#endif
_gpgrt_estream_init ();
}
@@ -551,6 +580,26 @@ _gpgrt_internal_trace_end (void)
******** Below is only Windows code. ****
*****************************************/
+/*
+ * Check the feature if it is supported or not
+ */
+int
+_gpgrt_windows_feature (int k)
+{
+ switch (k)
+ {
+ case GPGRT_WINDOWS_PROC_ATTRIBUTE:
+ return windows_features.is_vista_or_later;
+
+ case GPGRT_WINDOWS_UNDER_WINE:
+ return windows_features.semihosted_by_wine;
+
+ default:
+ return 0;
+ }
+}
+
+
/* This function can be called to force utf8 for new threads. */
void
_gpgrt_w32_utf8_for_new_threads (void)
diff --git a/src/spawn-w32.c b/src/spawn-w32.c
index 80cd6c6..ecc9437 100644
--- a/src/spawn-w32.c
+++ b/src/spawn-w32.c
@@ -322,29 +322,6 @@ _gpgrt_make_pipe (int filedes[2], estream_t *r_fp, int direction, int nonblock)
}
-/*
- * Check if STARTUPINFOEXW supports PROC_THREAD_ATTRIBUTE_HANDLE_LIST.
- */
-static int
-check_windows_version (void)
-{
- static int is_vista_or_later = -1;
-
- OSVERSIONINFO osvi;
-
- if (is_vista_or_later == -1)
- {
- memset (&osvi,0,sizeof(osvi));
- osvi.dwOSVersionInfoSize = sizeof(osvi);
- GetVersionEx (&osvi);
-
- /* The feature is available on Vista or later. */
- is_vista_or_later = (osvi.dwMajorVersion >= 6);
- }
-
- return is_vista_or_later;
-}
-
static gpg_err_code_t
prepare_env_block (char **r_env, const char *const *envchange)
{
@@ -753,7 +730,7 @@ _gpgrt_process_spawn (const char *pgmname, const char *argv[],
if (j)
{
- if (check_windows_version ())
+ if (_gpgrt_windows_feature (GPGRT_WINDOWS_PROC_ATTRIBUTE))
{
SIZE_T attr_list_size = 0;