Alexandre Julliard : ntdll: Avoid heap allocations during thread creation.

Alexandre Julliard julliard at wine.codeweavers.com
Thu Jan 18 06:45:10 CST 2007


Module: wine
Branch: master
Commit: fb75c66897b28bd6a9c28cdd9e46db258b037ba2
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=fb75c66897b28bd6a9c28cdd9e46db258b037ba2

Author: Alexandre Julliard <julliard at winehq.org>
Date:   Thu Jan 18 12:20:10 2007 +0100

ntdll: Avoid heap allocations during thread creation.

---

 dlls/ntdll/thread.c |   10 ++--------
 1 files changed, 2 insertions(+), 8 deletions(-)

diff --git a/dlls/ntdll/thread.c b/dlls/ntdll/thread.c
index cf96186..4a82e43 100644
--- a/dlls/ntdll/thread.c
+++ b/dlls/ntdll/thread.c
@@ -231,6 +231,7 @@ HANDLE thread_init(void)
     sigstack_total_size = get_signal_stack_total_size();
     while (1 << sigstack_zero_bits < sigstack_total_size) sigstack_zero_bits++;
     assert( 1 << sigstack_zero_bits == sigstack_total_size );  /* must be a power of 2 */
+    assert( sigstack_total_size >= sizeof(TEB) + sizeof(struct startup_info) );
     thread_info.teb_size = sigstack_total_size;
 
     addr = NULL;
@@ -344,7 +345,6 @@ static void start_thread( struct wine_pt
     /* setup the guard page */
     size = page_size;
     NtProtectVirtualMemory( NtCurrentProcess(), &teb->DeallocationStack, &size, PAGE_NOACCESS, NULL );
-    RtlFreeHeap( GetProcessHeap(), 0, info );
 
     RtlAcquirePebLock();
     InsertHeadList( &tls_links, &teb->TlsLinks );
@@ -418,12 +418,6 @@ NTSTATUS WINAPI RtlCreateUserThread( HAN
 
     if (status) goto error;
 
-    if (!(info = RtlAllocateHeap( GetProcessHeap(), 0, sizeof(*info) )))
-    {
-        status = STATUS_NO_MEMORY;
-        goto error;
-    }
-
     addr = NULL;
     size = sigstack_total_size;
     if ((status = NtAllocateVirtualMemory( NtCurrentProcess(), &addr, sigstack_zero_bits,
@@ -431,6 +425,7 @@ NTSTATUS WINAPI RtlCreateUserThread( HAN
         goto error;
     teb = addr;
     teb->Peb = NtCurrentTeb()->Peb;
+    info = (struct startup_info *)(teb + 1);
     info->pthread_info.teb_size = size;
     if ((status = init_teb( teb ))) goto error;
 
@@ -488,7 +483,6 @@ error:
         SIZE_T size = 0;
         NtFreeVirtualMemory( NtCurrentProcess(), &addr, &size, MEM_RELEASE );
     }
-    RtlFreeHeap( GetProcessHeap(), 0, info );
     if (handle) NtClose( handle );
     close( request_pipe[1] );
     return status;




More information about the wine-cvs mailing list