From 93eceba03e8a29a622a3f145dd5c157062f37293 Mon Sep 17 00:00:00 2001 From: Alexandre Julliard Date: Wed, 29 Nov 2017 10:43:39 +0100 Subject: [PATCH] ntdll: Move freeing the thread stack to a common helper. Signed-off-by: Alexandre Julliard --- dlls/ntdll/signal_arm.c | 8 +------- dlls/ntdll/signal_arm64.c | 8 +------- dlls/ntdll/signal_i386.c | 10 ++-------- dlls/ntdll/signal_powerpc.c | 8 +------- dlls/ntdll/signal_x86_64.c | 8 +------- dlls/ntdll/thread.c | 20 ++++++++++++++++++-- 6 files changed, 24 insertions(+), 38 deletions(-) diff --git a/dlls/ntdll/signal_arm.c b/dlls/ntdll/signal_arm.c index bbd6c59bb8e..2102dd0c604 100644 --- a/dlls/ntdll/signal_arm.c +++ b/dlls/ntdll/signal_arm.c @@ -944,14 +944,8 @@ NTSTATUS signal_alloc_thread( TEB **teb ) */ void signal_free_thread( TEB *teb ) { - SIZE_T size; + SIZE_T size = 0; - if (teb->DeallocationStack) - { - size = 0; - NtFreeVirtualMemory( GetCurrentProcess(), &teb->DeallocationStack, &size, MEM_RELEASE ); - } - size = 0; NtFreeVirtualMemory( NtCurrentProcess(), (void **)&teb, &size, MEM_RELEASE ); } diff --git a/dlls/ntdll/signal_arm64.c b/dlls/ntdll/signal_arm64.c index 5b3e8879b8f..7f2977d9d3f 100644 --- a/dlls/ntdll/signal_arm64.c +++ b/dlls/ntdll/signal_arm64.c @@ -817,14 +817,8 @@ NTSTATUS signal_alloc_thread( TEB **teb ) */ void signal_free_thread( TEB *teb ) { - SIZE_T size; + SIZE_T size = 0; - if (teb->DeallocationStack) - { - size = 0; - NtFreeVirtualMemory( GetCurrentProcess(), &teb->DeallocationStack, &size, MEM_RELEASE ); - } - size = 0; NtFreeVirtualMemory( NtCurrentProcess(), (void **)&teb, &size, MEM_RELEASE ); } diff --git a/dlls/ntdll/signal_i386.c b/dlls/ntdll/signal_i386.c index 4038436a426..671c35f35b5 100644 --- a/dlls/ntdll/signal_i386.c +++ b/dlls/ntdll/signal_i386.c @@ -2504,16 +2504,10 @@ NTSTATUS signal_alloc_thread( TEB **teb ) */ void signal_free_thread( TEB *teb ) { - SIZE_T size; + SIZE_T size = 0; struct x86_thread_data *thread_data = (struct x86_thread_data *)teb->SystemReserved2; - if (thread_data) wine_ldt_free_fs( thread_data->fs ); - if (teb->DeallocationStack) - { - size = 0; - NtFreeVirtualMemory( GetCurrentProcess(), &teb->DeallocationStack, &size, MEM_RELEASE ); - } - size = 0; + wine_ldt_free_fs( thread_data->fs ); NtFreeVirtualMemory( NtCurrentProcess(), (void **)&teb, &size, MEM_RELEASE ); } diff --git a/dlls/ntdll/signal_powerpc.c b/dlls/ntdll/signal_powerpc.c index e5a009c2aa2..2d3bd0a2b6b 100644 --- a/dlls/ntdll/signal_powerpc.c +++ b/dlls/ntdll/signal_powerpc.c @@ -1023,14 +1023,8 @@ NTSTATUS signal_alloc_thread( TEB **teb ) */ void signal_free_thread( TEB *teb ) { - SIZE_T size; + SIZE_T size = 0; - if (teb->DeallocationStack) - { - size = 0; - NtFreeVirtualMemory( GetCurrentProcess(), &teb->DeallocationStack, &size, MEM_RELEASE ); - } - size = 0; NtFreeVirtualMemory( NtCurrentProcess(), (void **)&teb, &size, MEM_RELEASE ); } diff --git a/dlls/ntdll/signal_x86_64.c b/dlls/ntdll/signal_x86_64.c index 691ee1ffdbf..a052a4824e8 100644 --- a/dlls/ntdll/signal_x86_64.c +++ b/dlls/ntdll/signal_x86_64.c @@ -2983,14 +2983,8 @@ NTSTATUS signal_alloc_thread( TEB **teb ) */ void signal_free_thread( TEB *teb ) { - SIZE_T size; + SIZE_T size = 0; - if (teb->DeallocationStack) - { - size = 0; - NtFreeVirtualMemory( GetCurrentProcess(), &teb->DeallocationStack, &size, MEM_RELEASE ); - } - size = 0; NtFreeVirtualMemory( NtCurrentProcess(), (void **)&teb, &size, MEM_RELEASE ); } diff --git a/dlls/ntdll/thread.c b/dlls/ntdll/thread.c index 511fd94c9ba..9c7cd137312 100644 --- a/dlls/ntdll/thread.c +++ b/dlls/ntdll/thread.c @@ -403,6 +403,22 @@ HANDLE thread_init(void) } +/*********************************************************************** + * free_thread_data + */ +static void free_thread_data( TEB *teb ) +{ + SIZE_T size; + + if (teb->DeallocationStack) + { + size = 0; + NtFreeVirtualMemory( GetCurrentProcess(), &teb->DeallocationStack, &size, MEM_RELEASE ); + } + signal_free_thread( teb ); +} + + /*********************************************************************** * terminate_thread */ @@ -456,7 +472,7 @@ void exit_thread( int status ) if (thread_data->pthread_id) { pthread_join( thread_data->pthread_id, NULL ); - signal_free_thread( teb ); + free_thread_data( teb ); } } @@ -634,7 +650,7 @@ NTSTATUS WINAPI RtlCreateUserThread( HANDLE process, const SECURITY_DESCRIPTOR * return STATUS_SUCCESS; error: - if (teb) signal_free_thread( teb ); + if (teb) free_thread_data( teb ); if (handle) NtClose( handle ); pthread_sigmask( SIG_SETMASK, &sigset, NULL ); close( request_pipe[1] );