ntdll: Catch the exceptions in the TLS callback like Windows does

Dmitry Timoshkov dmitry at codeweavers.com
Tue Mar 13 05:21:37 CDT 2007


Hello,

while investigating a crash in the TLS callback reported in the bug 7649
I've written a test (attached to that bug) which generates an exception in
the TLS callback. The test survives and continues execution under Windows,
but crashes under Wine. This patch helps to eliminate the crash, and my test
app produces identical output under XP and Wine. The app in the bug 7649
continues loading, it still crashes, but much later.

Changelog:
    ntdll: Catch the exceptions in the TLS callback like Windows does.

---
 dlls/ntdll/loader.c |   21 ++++++++++++++++++++-
 1 files changed, 20 insertions(+), 1 deletions(-)

diff --git a/dlls/ntdll/loader.c b/dlls/ntdll/loader.c
index 7ff3ca1..a81a118 100644
--- a/dlls/ntdll/loader.c
+++ b/dlls/ntdll/loader.c
@@ -782,6 +782,14 @@ static NTSTATUS alloc_thread_tls(void)
 
 
 /*************************************************************************
+ * A catch-all exception filter
+ */
+static WINE_EXCEPTION_FILTER(tls_exception_filter)
+{
+    return EXCEPTION_EXECUTE_HANDLER;
+}
+
+/*************************************************************************
  *              call_tls_callbacks
  */
 static void call_tls_callbacks( HMODULE module, UINT reason )
@@ -798,7 +806,18 @@ static void call_tls_callbacks( HMODULE module, UINT reason )
         if (TRACE_ON(relay))
             DPRINTF("%04x:Call TLS callback (proc=%p,module=%p,reason=%s,reserved=0)\n",
                     GetCurrentThreadId(), *callback, module, reason_names[reason] );
-        (*callback)( module, reason, NULL );
+        __TRY
+        {
+            (*callback)( module, reason, NULL );
+        }
+        __EXCEPT(tls_exception_filter)
+        {
+            if (TRACE_ON(relay))
+                DPRINTF("%04x:exception in TLS callback (proc=%p,module=%p,reason=%s,reserved=0)\n",
+                        GetCurrentThreadId(), callback, module, reason_names[reason] );
+            return;
+        }
+        __ENDTRY
         if (TRACE_ON(relay))
             DPRINTF("%04x:Ret  TLS callback (proc=%p,module=%p,reason=%s,reserved=0)\n",
                     GetCurrentThreadId(), *callback, module, reason_names[reason] );
-- 
1.5.0.2






More information about the wine-patches mailing list