DLL entry point can propagate failure via FALSE return value.
Use this approach instead of calling the fatal _amsg_exit() function.
---
 mingw-w64-crt/crt/crtdll.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/mingw-w64-crt/crt/crtdll.c b/mingw-w64-crt/crt/crtdll.c
index c2982b39e274..31a137f34012 100644
--- a/mingw-w64-crt/crt/crtdll.c
+++ b/mingw-w64-crt/crt/crtdll.c
@@ -69,7 +69,8 @@ WINBOOL WINAPI _CRT_INIT (HANDLE hDllHandle, DWORD dwReason, 
LPVOID lpreserved)
        }
       if (__native_startup_state != __uninitialized)
        {
-         _amsg_exit (31);
+         ret = 1;
+         goto i__leave;
        }
       else
        {
@@ -122,6 +123,7 @@ i__leave:
       void *lock_free = NULL;
       void *fiberid = ((PNT_TIB)NtCurrentTeb ())->StackBase;
       BOOL nested = FALSE;
+      BOOL failed = FALSE;
 
       while ((lock_free = InterlockedCompareExchangePointer 
(&__native_startup_lock, fiberid, NULL)) != 0)
        {
@@ -134,7 +136,7 @@ i__leave:
        }
       if (__native_startup_state != __initialized)
        {
-         _amsg_exit (31);
+         failed = TRUE;
        }
       else
        {
@@ -152,6 +154,10 @@ i__leave:
        {
          (void) InterlockedExchangePointer (&__native_startup_lock, NULL);
        }
+      if (failed)
+       {
+         return FALSE;
+       }
     }
   else if (dwReason == DLL_THREAD_DETACH)
     {
-- 
2.20.1



_______________________________________________
Mingw-w64-public mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public

Reply via email to