Alexandre Julliard : ntdll: Use NtAllocateVirtualMemory to allocate all TEBs except the first one.

Alexandre Julliard julliard at wine.codeweavers.com
Fri Jul 21 13:49:21 CDT 2006


Module: wine
Branch: refs/heads/master
Commit: 0c453bc7c63ecccd1a354bdc3cc267e855b8fb00
URL:    http://source.winehq.org/git/?p=wine.git;a=commit;h=0c453bc7c63ecccd1a354bdc3cc267e855b8fb00

Author: Alexandre Julliard <julliard at winehq.org>
Date:   Fri Jul 21 20:20:30 2006 +0200

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 128cbc9..7a0da37 100644
--- a/dlls/ntdll/ntdll_misc.h
+++ b/dlls/ntdll/ntdll_misc.h
@@ -106,7 +106,7 @@ extern NTSTATUS DIR_unmount_device( HAND
 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 10cb72b..cd75090 100644
--- a/dlls/ntdll/thread.c
+++ b/dlls/ntdll/thread.c
@@ -21,6 +21,7 @@
 #include "config.h"
 #include "wine/port.h"
 
+#include <assert.h>
 #include <sys/types.h>
 #ifdef HAVE_SYS_MMAN_H
 #include <sys/mman.h>
@@ -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( HAN
     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( HAN
         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 6227be6..0782da2 100644
--- a/dlls/ntdll/virtual.c
+++ b/dlls/ntdll/virtual.c
@@ -1151,31 +1151,21 @@ #endif  /* page_mask */
  *
  * 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;
 }
 




More information about the wine-cvs mailing list