Commit 0c453bc7 authored by Alexandre Julliard's avatar Alexandre Julliard

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

parent b636e4db
...@@ -106,7 +106,7 @@ extern NTSTATUS DIR_unmount_device( HANDLE handle ); ...@@ -106,7 +106,7 @@ extern NTSTATUS DIR_unmount_device( HANDLE handle );
extern NTSTATUS DIR_get_unix_cwd( char **cwd ); extern NTSTATUS DIR_get_unix_cwd( char **cwd );
/* virtual memory */ /* 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 NTSTATUS VIRTUAL_HandleFault(LPCVOID addr);
extern BOOL VIRTUAL_HasMapping( LPCVOID addr ); extern BOOL VIRTUAL_HasMapping( LPCVOID addr );
extern void VIRTUAL_UseLargeAddressSpace(void); extern void VIRTUAL_UseLargeAddressSpace(void);
......
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
#include "config.h" #include "config.h"
#include "wine/port.h" #include "wine/port.h"
#include <assert.h>
#include <sys/types.h> #include <sys/types.h>
#ifdef HAVE_SYS_MMAN_H #ifdef HAVE_SYS_MMAN_H
#include <sys/mman.h> #include <sys/mman.h>
...@@ -59,6 +60,7 @@ static RTL_BITMAP tls_bitmap; ...@@ -59,6 +60,7 @@ static RTL_BITMAP tls_bitmap;
static RTL_BITMAP tls_expansion_bitmap; static RTL_BITMAP tls_expansion_bitmap;
static LIST_ENTRY tls_links; static LIST_ENTRY tls_links;
static size_t sigstack_total_size; static size_t sigstack_total_size;
static ULONG sigstack_zero_bits;
struct wine_pthread_functions pthread_functions = { NULL }; struct wine_pthread_functions pthread_functions = { NULL };
...@@ -225,8 +227,10 @@ HANDLE thread_init(void) ...@@ -225,8 +227,10 @@ HANDLE thread_init(void)
InitializeListHead( &tls_links ); InitializeListHead( &tls_links );
sigstack_total_size = get_signal_stack_total_size(); 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; 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; teb = addr;
init_teb( teb ); init_teb( teb );
thread_data = (struct ntdll_thread_data *)teb->SystemReserved2; thread_data = (struct ntdll_thread_data *)teb->SystemReserved2;
...@@ -376,7 +380,7 @@ NTSTATUS WINAPI RtlCreateUserThread( HANDLE process, const SECURITY_DESCRIPTOR * ...@@ -376,7 +380,7 @@ NTSTATUS WINAPI RtlCreateUserThread( HANDLE process, const SECURITY_DESCRIPTOR *
DWORD tid = 0; DWORD tid = 0;
int request_pipe[2]; int request_pipe[2];
NTSTATUS status; NTSTATUS status;
SIZE_T page_size = getpagesize(); SIZE_T size, page_size = getpagesize();
if( ! is_current_process( process ) ) if( ! is_current_process( process ) )
{ {
...@@ -411,9 +415,13 @@ NTSTATUS WINAPI RtlCreateUserThread( HANDLE process, const SECURITY_DESCRIPTOR * ...@@ -411,9 +415,13 @@ NTSTATUS WINAPI RtlCreateUserThread( HANDLE process, const SECURITY_DESCRIPTOR *
goto error; goto error;
} }
info->pthread_info.teb_size = sigstack_total_size; addr = NULL;
if ((status = VIRTUAL_alloc_teb( &addr, info->pthread_info.teb_size, FALSE ))) goto error; size = sigstack_total_size;
if ((status = NtAllocateVirtualMemory( NtCurrentProcess(), &addr, sigstack_zero_bits,
&size, MEM_COMMIT | MEM_TOP_DOWN, PAGE_READWRITE )))
goto error;
teb = addr; teb = addr;
info->pthread_info.teb_size = size;
if ((status = init_teb( teb ))) goto error; if ((status = init_teb( teb ))) goto error;
teb->ClientId.UniqueProcess = (HANDLE)GetCurrentProcessId(); teb->ClientId.UniqueProcess = (HANDLE)GetCurrentProcessId();
......
...@@ -1151,31 +1151,21 @@ static inline void virtual_init(void) ...@@ -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. * 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; NTSTATUS status;
struct file_view *view; struct file_view *view;
size_t align_size;
if (first) virtual_init(); virtual_init();
*ret = NULL; *ret = NULL;
size = ROUND_SIZE( 0, size ); status = map_view( &view, NULL, size, size - 1,
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,
VPROT_READ | VPROT_WRITE | VPROT_COMMITTED ); VPROT_READ | VPROT_WRITE | VPROT_COMMITTED );
if (status == STATUS_SUCCESS) if (status == STATUS_SUCCESS)
{ {
view->flags |= VFLAG_VALLOC; view->flags |= VFLAG_VALLOC;
*ret = view->base; *ret = view->base;
} }
if (!first) RtlLeaveCriticalSection( &csVirtual );
return status; return status;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment