[PATCH] w32: Use __declspec(thread) for FIPS thread context TLS

Werner Koch wk at gnupg.org
Tue Dec 9 15:08:05 CET 2025


On Tue,  9 Dec 2025 05:59, Knugi said:

> the thread-local variables defined using __thread. More specifically, with
> __thread, libaacs could not be properly initialized.

How did you noticed that libgpg-error TLS was also not properly
intialized?

Did you noticed this comment in gpg_err_init:

# ifdef DLL_EXPORT
  /* We always have a constructor and thus this function is called
     automatically.  Due to the way the C init code of mingw works,
     the constructors are called before our DllMain function is
     called.  The problem with that is that the TLS has not been setup
     and w32-gettext.c requires TLS.  To solve this we do nothing here
     but call the actual init code from our DllMain.  */

and later in DLLMain:

    case DLL_PROCESS_ATTACH:
      tls_index = TlsAlloc ();
      if (tls_index == TLS_OUT_OF_INDEXES)
        return FALSE;
#ifndef _GPG_ERR_HAVE_CONSTRUCTOR
      /* If we have no constructors (e.g. MSC) we call it here.  */
      _gpg_w32__init_gettext_module ();
      _gpgrt_w32__init_utils ();
#endif
      /* fallthru.  */

?


Shalom-Salam,

   Werner

-- 
The pioneers of a warless world are the youth that
refuse military service.             - A. Einstein
-------------- next part --------------
A non-text attachment was scrubbed...
Name: openpgp-digital-signature.asc
Type: application/pgp-signature
Size: 284 bytes
Desc: not available
URL: <https://lists.gnupg.org/pipermail/gcrypt-devel/attachments/20251209/6addcfad/attachment.sig>


More information about the Gcrypt-devel mailing list