ntdll: Move freeing the thread stack to a common helper.

Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Alexandre Julliard 2017-11-29 10:43:39 +01:00
parent 6f790606c0
commit 93eceba03e
6 changed files with 24 additions and 38 deletions

View File

@ -944,14 +944,8 @@ NTSTATUS signal_alloc_thread( TEB **teb )
*/ */
void signal_free_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 ); NtFreeVirtualMemory( NtCurrentProcess(), (void **)&teb, &size, MEM_RELEASE );
} }

View File

@ -817,14 +817,8 @@ NTSTATUS signal_alloc_thread( TEB **teb )
*/ */
void signal_free_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 ); NtFreeVirtualMemory( NtCurrentProcess(), (void **)&teb, &size, MEM_RELEASE );
} }

View File

@ -2504,16 +2504,10 @@ NTSTATUS signal_alloc_thread( TEB **teb )
*/ */
void signal_free_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; struct x86_thread_data *thread_data = (struct x86_thread_data *)teb->SystemReserved2;
if (thread_data) wine_ldt_free_fs( thread_data->fs ); wine_ldt_free_fs( thread_data->fs );
if (teb->DeallocationStack)
{
size = 0;
NtFreeVirtualMemory( GetCurrentProcess(), &teb->DeallocationStack, &size, MEM_RELEASE );
}
size = 0;
NtFreeVirtualMemory( NtCurrentProcess(), (void **)&teb, &size, MEM_RELEASE ); NtFreeVirtualMemory( NtCurrentProcess(), (void **)&teb, &size, MEM_RELEASE );
} }

View File

@ -1023,14 +1023,8 @@ NTSTATUS signal_alloc_thread( TEB **teb )
*/ */
void signal_free_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 ); NtFreeVirtualMemory( NtCurrentProcess(), (void **)&teb, &size, MEM_RELEASE );
} }

View File

@ -2983,14 +2983,8 @@ NTSTATUS signal_alloc_thread( TEB **teb )
*/ */
void signal_free_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 ); NtFreeVirtualMemory( NtCurrentProcess(), (void **)&teb, &size, MEM_RELEASE );
} }

View File

@ -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 * terminate_thread
*/ */
@ -456,7 +472,7 @@ void exit_thread( int status )
if (thread_data->pthread_id) if (thread_data->pthread_id)
{ {
pthread_join( thread_data->pthread_id, NULL ); 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; return STATUS_SUCCESS;
error: error:
if (teb) signal_free_thread( teb ); if (teb) free_thread_data( teb );
if (handle) NtClose( handle ); if (handle) NtClose( handle );
pthread_sigmask( SIG_SETMASK, &sigset, NULL ); pthread_sigmask( SIG_SETMASK, &sigset, NULL );
close( request_pipe[1] ); close( request_pipe[1] );