diff --git a/README.md b/README.md index 0a642671..63fd2d20 100644 --- a/README.md +++ b/README.md @@ -38,6 +38,11 @@ Wine. All those differences are also documented on the Included bug fixes and improvements =================================== +**Bugfixes and features included in the next upcoming release [1]:** + +* Fix race-condition when threads are killed during shutdown + + **Bugs fixed in Wine Staging 1.7.37 [182]:** * Add Dynamic DST exceptions for Israel Standard Time ([Wine Bug #36374](https://bugs.winehq.org/show_bug.cgi?id=36374)) diff --git a/debian/changelog b/debian/changelog index 759c1171..606fce54 100644 --- a/debian/changelog +++ b/debian/changelog @@ -5,6 +5,7 @@ wine-staging (1.7.38) UNRELEASED; urgency=low * Added patch to skip Wine specific __wine_check_for_events calls in ReactOS (by Amine Khaldi, wine-patched/pull/4). * Added patch to declare pDirectInputCreateEx in a MSVC compatible way (by Amine Khaldi, wine-patched/pull/5). * Added patch to complete and properly pack DNS_HEADER structure (by Amine Khaldi, wine-patched/pull/6). + * Added patch to fix race-condition when threads are killed during shutdown. * Removed patch to properly call DriverUnload when unloading device drivers (accepted upstream). * Removed patch to allow Accept-Encoding for HTTP/1.0 in wininet (accepted upstream). * Removed patch to declare pDirectInputCreateEx in a MSVC compatible way (accepted upstream). diff --git a/patches/ntdll-Threading/0001-ntdll-Fix-race-condition-when-threads-are-killed-dur.patch b/patches/ntdll-Threading/0001-ntdll-Fix-race-condition-when-threads-are-killed-dur.patch new file mode 100644 index 00000000..3d85c76b --- /dev/null +++ b/patches/ntdll-Threading/0001-ntdll-Fix-race-condition-when-threads-are-killed-dur.patch @@ -0,0 +1,55 @@ +From f7a85ba8219c46b226376aed23f2d81bfff902dc Mon Sep 17 00:00:00 2001 +From: Sebastian Lackner +Date: Wed, 25 Feb 2015 22:45:42 +0100 +Subject: ntdll: Fix race-condition when threads are killed during shutdown. + +When exit_thread is executed, nb_threads is decremented before the thread is +fully shutdown. When another thread runs ExitProcess() this will cause a SIGQUIT +signal to all threads, effectively decrementing nb_threads twice. The process +will terminate with a wrong exitcode then because the refcount reaches zero too +early. + +Currently Wine has no locking protection of LdrShutdownProcess(), so it can +only be executed safely when all other threads have terminated before. Most +likely there are more Wine bugs in this area, but the attached patch should +fix the most critical one (messed up refcounting of threads) for now. +--- + dlls/ntdll/thread.c | 8 +++++++- + 1 file changed, 7 insertions(+), 1 deletion(-) + +diff --git a/dlls/ntdll/thread.c b/dlls/ntdll/thread.c +index 3696c8e..74e64c9 100644 +--- a/dlls/ntdll/thread.c ++++ b/dlls/ntdll/thread.c +@@ -370,6 +370,7 @@ void terminate_thread( int status ) + void exit_thread( int status ) + { + static void *prev_teb; ++ sigset_t sigset; + TEB *teb; + + if (status) /* send the exit code to the server (0 is already the default) */ +@@ -383,7 +384,7 @@ void exit_thread( int status ) + SERVER_END_REQ; + } + +- if (interlocked_xchg_add( &nb_threads, -1 ) <= 1) ++ if (interlocked_xchg_add( &nb_threads, 0 ) <= 1) + { + LdrShutdownProcess(); + exit( status ); +@@ -405,6 +406,11 @@ void exit_thread( int status ) + } + } + ++ sigemptyset( &sigset ); ++ sigaddset( &sigset, SIGQUIT ); ++ pthread_sigmask( SIG_BLOCK, &sigset, NULL ); ++ if (interlocked_xchg_add( &nb_threads, -1 ) <= 1) _exit( status ); ++ + close( ntdll_get_thread_data()->wait_fd[0] ); + close( ntdll_get_thread_data()->wait_fd[1] ); + close( ntdll_get_thread_data()->reply_fd ); +-- +2.3.0 + diff --git a/patches/ntdll-Threading/definition b/patches/ntdll-Threading/definition new file mode 100644 index 00000000..d0e88f9b --- /dev/null +++ b/patches/ntdll-Threading/definition @@ -0,0 +1 @@ +Fixes: Fix race-condition when threads are killed during shutdown diff --git a/patches/patchinstall.sh b/patches/patchinstall.sh index 978d656d..209e2e02 100755 --- a/patches/patchinstall.sh +++ b/patches/patchinstall.sh @@ -133,6 +133,7 @@ patch_enable_all () enable_ntdll_RtlIpv4StringToAddressExA="$1" enable_ntdll_RtlUnwindEx="$1" enable_ntdll_ThreadTime="$1" + enable_ntdll_Threading="$1" enable_ntdll_User_Shared_Data="$1" enable_ntdll_Vista_Threadpool="$1" enable_ntdll_WRITECOPY="$1" @@ -430,6 +431,9 @@ patch_enable () ntdll-ThreadTime) enable_ntdll_ThreadTime="$2" ;; + ntdll-Threading) + enable_ntdll_Threading="$2" + ;; ntdll-User_Shared_Data) enable_ntdll_User_Shared_Data="$2" ;; @@ -2743,6 +2747,18 @@ if test "$enable_ntdll_ThreadTime" -eq 1; then ) >> "$patchlist" fi +# Patchset ntdll-Threading +# | +# | Modified files: +# | * dlls/ntdll/thread.c +# | +if test "$enable_ntdll_Threading" -eq 1; then + patch_apply ntdll-Threading/0001-ntdll-Fix-race-condition-when-threads-are-killed-dur.patch + ( + echo '+ { "Sebastian Lackner", "ntdll: Fix race-condition when threads are killed during shutdown.", 1 },'; + ) >> "$patchlist" +fi + # Patchset ntdll-User_Shared_Data # | # | Modified files: diff --git a/patches/wined3d-CSMT_Main/9999-IfDefined.patch b/patches/wined3d-CSMT_Main/9999-IfDefined.patch index 3741edfc..c20a20e2 100644 --- a/patches/wined3d-CSMT_Main/9999-IfDefined.patch +++ b/patches/wined3d-CSMT_Main/9999-IfDefined.patch @@ -473,7 +473,7 @@ diff --git a/dlls/wined3d/state.c b/dlls/wined3d/state.c diff --git a/dlls/d3d8/tests/visual.c b/dlls/d3d8/tests/visual.c --- a/dlls/d3d8/tests/visual.c +++ b/dlls/d3d8/tests/visual.c -@@ -5034,7 +5034,11 @@ +@@ -5033,7 +5033,11 @@ fill_surface(surface_managed, 0x0000ff00, D3DLOCK_NO_DIRTY_UPDATE); add_dirty_rect_test_draw(device); color = getPixelColor(device, 320, 240);