From 0c453bc7c63ecccd1a354bdc3cc267e855b8fb00 Mon Sep 17 00:00:00 2001 From: Alexandre Julliard Date: Fri, 21 Jul 2006 20:20:30 +0200 Subject: [PATCH] ntdll: Use NtAllocateVirtualMemory to allocate all TEBs except the first one. --- dlls/ntdll/ntdll_misc.h | 2 +- dlls/ntdll/thread.c | 16 ++++++++++++---- dlls/ntdll/virtual.c | 16 +++------------- 3 files changed, 16 insertions(+), 18 deletions(-) diff --git a/dlls/ntdll/ntdll_misc.h b/dlls/ntdll/ntdll_misc.h index 128cbc98cb6..7a0da37e7c1 100644 --- a/dlls/ntdll/ntdll_misc.h +++ b/dlls/ntdll/ntdll_misc.h @@ -106,7 +106,7 @@ extern NTSTATUS DIR_unmount_device( HANDLE handle ); extern NTSTATUS DIR_get_unix_cwd( char **cwd ); /* virtual memory */ -extern NTSTATUS VIRTUAL_alloc_teb( void **ret, size_t size, BOOL first ); +extern NTSTATUS VIRTUAL_alloc_teb( void **ret, size_t size ); extern NTSTATUS VIRTUAL_HandleFault(LPCVOID addr); extern BOOL VIRTUAL_HasMapping( LPCVOID addr ); extern void VIRTUAL_UseLargeAddressSpace(void); diff --git a/dlls/ntdll/thread.c b/dlls/ntdll/thread.c index 10cb72bad7f..cd75090cd87 100644 --- a/dlls/ntdll/thread.c +++ b/dlls/ntdll/thread.c @@ -21,6 +21,7 @@ #include "config.h" #include "wine/port.h" +#include #include #ifdef HAVE_SYS_MMAN_H #include @@ -59,6 +60,7 @@ static RTL_BITMAP tls_bitmap; static RTL_BITMAP tls_expansion_bitmap; static LIST_ENTRY tls_links; static size_t sigstack_total_size; +static ULONG sigstack_zero_bits; struct wine_pthread_functions pthread_functions = { NULL }; @@ -225,8 +227,10 @@ HANDLE thread_init(void) InitializeListHead( &tls_links ); 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 */ thread_info.teb_size = sigstack_total_size; - VIRTUAL_alloc_teb( &addr, thread_info.teb_size, TRUE ); + VIRTUAL_alloc_teb( &addr, thread_info.teb_size ); teb = addr; init_teb( teb ); thread_data = (struct ntdll_thread_data *)teb->SystemReserved2; @@ -376,7 +380,7 @@ NTSTATUS WINAPI RtlCreateUserThread( HANDLE process, const SECURITY_DESCRIPTOR * DWORD tid = 0; int request_pipe[2]; NTSTATUS status; - SIZE_T page_size = getpagesize(); + SIZE_T size, page_size = getpagesize(); if( ! is_current_process( process ) ) { @@ -411,9 +415,13 @@ NTSTATUS WINAPI RtlCreateUserThread( HANDLE process, const SECURITY_DESCRIPTOR * goto error; } - info->pthread_info.teb_size = sigstack_total_size; - if ((status = VIRTUAL_alloc_teb( &addr, info->pthread_info.teb_size, FALSE ))) goto error; + addr = NULL; + size = sigstack_total_size; + if ((status = NtAllocateVirtualMemory( NtCurrentProcess(), &addr, sigstack_zero_bits, + &size, MEM_COMMIT | MEM_TOP_DOWN, PAGE_READWRITE ))) + goto error; teb = addr; + info->pthread_info.teb_size = size; if ((status = init_teb( teb ))) goto error; teb->ClientId.UniqueProcess = (HANDLE)GetCurrentProcessId(); diff --git a/dlls/ntdll/virtual.c b/dlls/ntdll/virtual.c index 6227be6ceb9..0782da205fe 100644 --- a/dlls/ntdll/virtual.c +++ b/dlls/ntdll/virtual.c @@ -1151,31 +1151,21 @@ static inline void virtual_init(void) * * Allocate a memory view for a new TEB, properly aligned to a multiple of the size. */ -NTSTATUS VIRTUAL_alloc_teb( void **ret, size_t size, BOOL first ) +NTSTATUS VIRTUAL_alloc_teb( void **ret, size_t size ) { NTSTATUS status; struct file_view *view; - size_t align_size; - if (first) virtual_init(); + virtual_init(); *ret = NULL; - size = ROUND_SIZE( 0, size ); - align_size = page_size; - while (align_size < size) align_size *= 2; - - if (!first) RtlEnterCriticalSection( &csVirtual ); - - status = map_view( &view, NULL, align_size, align_size - 1, + status = map_view( &view, NULL, size, size - 1, VPROT_READ | VPROT_WRITE | VPROT_COMMITTED ); if (status == STATUS_SUCCESS) { view->flags |= VFLAG_VALLOC; *ret = view->base; } - - if (!first) RtlLeaveCriticalSection( &csVirtual ); - return status; }