From fb75c66897b28bd6a9c28cdd9e46db258b037ba2 Mon Sep 17 00:00:00 2001 From: Alexandre Julliard Date: Thu, 18 Jan 2007 12:20:10 +0100 Subject: [PATCH] ntdll: Avoid heap allocations during thread creation. --- dlls/ntdll/thread.c | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/dlls/ntdll/thread.c b/dlls/ntdll/thread.c index cf9618623ec..4a82e43149d 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_pthread_thread_info *info ) /* 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( HANDLE process, const SECURITY_DESCRIPTOR * 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( HANDLE process, const SECURITY_DESCRIPTOR * 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;