diff --git a/patches/ntdll-RtlCreateUserThread/0001-ntdll-Refactor-RtlCreateUserThread-into-NtCreateThre.patch b/patches/ntdll-RtlCreateUserThread/0001-ntdll-Refactor-RtlCreateUserThread-into-NtCreateThre.patch index bab1591c..1dee3e61 100644 --- a/patches/ntdll-RtlCreateUserThread/0001-ntdll-Refactor-RtlCreateUserThread-into-NtCreateThre.patch +++ b/patches/ntdll-RtlCreateUserThread/0001-ntdll-Refactor-RtlCreateUserThread-into-NtCreateThre.patch @@ -1,4 +1,4 @@ -From 9b9a9666a78c0cf0a8dda6f01103849a9e7422c3 Mon Sep 17 00:00:00 2001 +From 1a7a4c790294dc0eddd3202853c17967d6bb8e1a Mon Sep 17 00:00:00 2001 From: Andrew Wesie Date: Fri, 27 Jul 2018 01:22:59 -0500 Subject: [PATCH] ntdll: Refactor RtlCreateUserThread into NtCreateThreadEx. @@ -12,7 +12,7 @@ reported version), and expects it to be called whenever a thread is created. 3 files changed, 187 insertions(+), 36 deletions(-) diff --git a/dlls/ntdll/ntdll.spec b/dlls/ntdll/ntdll.spec -index 82b1d58aff71..af8a14b50a67 100644 +index cb6a8ec8c4..16ec96bc56 100644 --- a/dlls/ntdll/ntdll.spec +++ b/dlls/ntdll/ntdll.spec @@ -182,7 +182,7 @@ @@ -25,10 +25,10 @@ index 82b1d58aff71..af8a14b50a67 100644 @ stdcall NtCreateTimer(ptr long ptr long) @ stub NtCreateToken diff --git a/dlls/ntdll/thread.c b/dlls/ntdll/thread.c -index 484e60fc21e9..605221ee144b 100644 +index ceadcff1b2..2c4a9c4949 100644 --- a/dlls/ntdll/thread.c +++ b/dlls/ntdll/thread.c -@@ -409,34 +409,18 @@ static void start_thread( struct startup_info *info ) +@@ -413,34 +413,18 @@ static void start_thread( struct startup_info *info ) /*********************************************************************** * NtCreateThreadEx (NTDLL.@) */ @@ -68,7 +68,7 @@ index 484e60fc21e9..605221ee144b 100644 HANDLE handle = 0, actctx = 0; TEB *teb = NULL; DWORD tid = 0; -@@ -447,6 +431,33 @@ NTSTATUS WINAPI RtlCreateUserThread( HANDLE process, SECURITY_DESCRIPTOR *descr, +@@ -451,6 +435,33 @@ NTSTATUS WINAPI RtlCreateUserThread( HANDLE process, SECURITY_DESCRIPTOR *descr, struct object_attributes *objattr = NULL; INITIAL_TEB stack; @@ -102,7 +102,7 @@ index 484e60fc21e9..605221ee144b 100644 if (process != NtCurrentProcess()) { apc_call_t call; -@@ -472,12 +483,7 @@ NTSTATUS WINAPI RtlCreateUserThread( HANDLE process, SECURITY_DESCRIPTOR *descr, +@@ -476,12 +487,7 @@ NTSTATUS WINAPI RtlCreateUserThread( HANDLE process, SECURITY_DESCRIPTOR *descr, return result.create_thread.status; } @@ -116,7 +116,7 @@ index 484e60fc21e9..605221ee144b 100644 if (server_pipe( request_pipe ) == -1) { -@@ -489,7 +495,7 @@ NTSTATUS WINAPI RtlCreateUserThread( HANDLE process, SECURITY_DESCRIPTOR *descr, +@@ -493,7 +499,7 @@ NTSTATUS WINAPI RtlCreateUserThread( HANDLE process, SECURITY_DESCRIPTOR *descr, SERVER_START_REQ( new_thread ) { req->process = wine_server_obj_handle( process ); @@ -125,7 +125,7 @@ index 484e60fc21e9..605221ee144b 100644 req->suspend = suspended; req->request_fd = request_pipe[0]; wine_server_add_data( req, objattr, len ); -@@ -548,20 +554,20 @@ NTSTATUS WINAPI RtlCreateUserThread( HANDLE process, SECURITY_DESCRIPTOR *descr, +@@ -552,20 +558,20 @@ NTSTATUS WINAPI RtlCreateUserThread( HANDLE process, SECURITY_DESCRIPTOR *descr, thread_data->wait_fd[1] = -1; thread_data->start_stack = (char *)teb->Tib.StackBase; @@ -149,11 +149,11 @@ index 484e60fc21e9..605221ee144b 100644 goto error; } - pthread_attr_destroy( &attr ); -+ pthread_attr_destroy( &nb_threads ); ++ pthread_attr_destroy( &pthread_attr ); pthread_sigmask( SIG_SETMASK, &sigset, NULL ); if (id) id->UniqueThread = ULongToHandle(tid); -@@ -578,6 +584,124 @@ error: +@@ -582,6 +588,124 @@ error: return status; } @@ -279,10 +279,10 @@ index 484e60fc21e9..605221ee144b 100644 /****************************************************************************** * RtlGetNtGlobalFlags (NTDLL.@) diff --git a/include/winternl.h b/include/winternl.h -index 865e39d16e06..1d2d49414448 100644 +index 733c8a33f6..5c3f7a05ff 100644 --- a/include/winternl.h +++ b/include/winternl.h -@@ -2251,6 +2251,33 @@ typedef struct _NLSTABLEINFO +@@ -2250,6 +2250,33 @@ typedef struct _NLSTABLEINFO USHORT *LowerCaseTable; } NLSTABLEINFO, *PNLSTABLEINFO; 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 index 447033e1..e463ba9e 100644 --- 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 @@ -1,4 +1,4 @@ -From 91a597b6a9299483c29c2d79b7471735b3839009 Mon Sep 17 00:00:00 2001 +From f8e12f51bebca8cda3be339bcc216ca8cc60a718 Mon Sep 17 00:00:00 2001 From: Sebastian Lackner Date: Wed, 25 Feb 2015 22:45:42 +0100 Subject: [PATCH] ntdll: Fix race-condition when threads are killed during @@ -15,14 +15,14 @@ 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 | 6 ++++++ - 1 file changed, 6 insertions(+) + 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 eda5d1cea12b..8a0b612b39a4 100644 +index b25f87e437..5fbd9e06c3 100644 --- a/dlls/ntdll/thread.c +++ b/dlls/ntdll/thread.c -@@ -429,6 +429,7 @@ void exit_thread( int status ) +@@ -336,6 +336,7 @@ void exit_thread( int status ) void WINAPI RtlExitUserThread( ULONG status ) { static void *prev_teb; @@ -30,14 +30,23 @@ index eda5d1cea12b..8a0b612b39a4 100644 TEB *teb; if (status) /* send the exit code to the server (0 is already the default) */ -@@ -465,6 +466,11 @@ void WINAPI RtlExitUserThread( ULONG status ) +@@ -349,7 +350,7 @@ void WINAPI RtlExitUserThread( ULONG status ) + SERVER_END_REQ; + } + +- if (InterlockedDecrement( &nb_threads ) <= 0) ++ if (InterlockedCompareExchange( &nb_threads, 0, 0 ) <= 0) + { + LdrShutdownProcess(); + pthread_sigmask( SIG_BLOCK, &server_block_set, NULL ); +@@ -372,6 +373,11 @@ void WINAPI RtlExitUserThread( ULONG status ) } } + sigemptyset( &sigset ); + sigaddset( &sigset, SIGQUIT ); + pthread_sigmask( SIG_BLOCK, &sigset, NULL ); -+ if (InterlockedDecrement( &nb_threads ) <= 1) _exit( status ); ++ if (!InterlockedDecrement( &nb_threads )) _exit( status ); + signal_exit_thread( status ); }