Alexandre Julliard : ntdll: Use a separate stack when starting new threads.

Alexandre Julliard julliard at winehq.org
Tue Nov 21 16:33:50 CST 2017


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

Author: Alexandre Julliard <julliard at winehq.org>
Date:   Tue Nov 21 13:50:43 2017 +0100

ntdll: Use a separate stack when starting new threads.

Based on a patch by Sebastian Lackner.

Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 dlls/ntdll/thread.c | 33 ++++++++++++++++++++++-----------
 1 file changed, 22 insertions(+), 11 deletions(-)

diff --git a/dlls/ntdll/thread.c b/dlls/ntdll/thread.c
index ce0ba68..f403b12 100644
--- a/dlls/ntdll/thread.c
+++ b/dlls/ntdll/thread.c
@@ -23,6 +23,7 @@
 
 #include <assert.h>
 #include <stdarg.h>
+#include <limits.h>
 #include <sys/types.h>
 #ifdef HAVE_SYS_MMAN_H
 #include <sys/mman.h>
@@ -468,6 +469,24 @@ void exit_thread( int status )
 
 
 /***********************************************************************
+ *           thread_startup
+ */
+static void thread_startup( void *param )
+{
+    struct startup_info *info = param;
+    PRTL_THREAD_START_ROUTINE func = info->entry_point;
+    void *arg = info->entry_arg;
+
+    attach_dlls( (void *)1 );
+
+    if (TRACE_ON(relay))
+        DPRINTF( "%04x:Starting thread proc %p (arg=%p)\n", GetCurrentThreadId(), func, arg );
+
+    call_thread_entry_point( (LPTHREAD_START_ROUTINE)func, arg );
+}
+
+
+/***********************************************************************
  *           start_thread
  *
  * Startup routine for a newly created thread.
@@ -476,8 +495,6 @@ static void start_thread( struct startup_info *info )
 {
     TEB *teb = info->teb;
     struct ntdll_thread_data *thread_data = (struct ntdll_thread_data *)&teb->GdiTebBatch;
-    PRTL_THREAD_START_ROUTINE func = info->entry_point;
-    void *arg = info->entry_arg;
     struct debug_info debug_info;
 
     debug_info.str_pos = debug_info.strings;
@@ -486,14 +503,9 @@ static void start_thread( struct startup_info *info )
     thread_data->pthread_id = pthread_self();
 
     signal_init_thread( teb );
-    server_init_thread( func );
+    server_init_thread( info->entry_point );
 
-    attach_dlls( (void *)1 );
-
-    if (TRACE_ON(relay))
-        DPRINTF( "%04x:Starting thread proc %p (arg=%p)\n", GetCurrentThreadId(), func, arg );
-
-    call_thread_entry_point( (LPTHREAD_START_ROUTINE)func, arg );
+    wine_switch_to_stack( thread_startup, info, teb->Tib.StackBase );
 }
 
 
@@ -603,8 +615,7 @@ NTSTATUS WINAPI RtlCreateUserThread( HANDLE process, const SECURITY_DESCRIPTOR *
     if ((status = virtual_alloc_thread_stack( teb, stack_reserve, stack_commit ))) goto error;
 
     pthread_attr_init( &attr );
-    pthread_attr_setstack( &attr, teb->DeallocationStack,
-                           (char *)teb->Tib.StackBase - (char *)teb->DeallocationStack );
+    pthread_attr_setstacksize( &attr, PTHREAD_STACK_MIN );
     pthread_attr_setscope( &attr, PTHREAD_SCOPE_SYSTEM ); /* force creating a kernel thread */
     interlocked_xchg_add( &nb_threads, 1 );
     if (pthread_create( &pthread_id, &attr, (void * (*)(void *))start_thread, info ))




More information about the wine-cvs mailing list