Alexandre Julliard : ntdll: Determine the Unix tid for the server directly in ntdll.

Alexandre Julliard julliard at winehq.org
Wed Feb 18 10:15:26 CST 2009


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

Author: Alexandre Julliard <julliard at winehq.org>
Date:   Wed Feb 18 12:30:01 2009 +0100

ntdll: Determine the Unix tid for the server directly in ntdll.

---

 dlls/ntdll/Makefile.in  |    2 +-
 dlls/ntdll/ntdll_misc.h |    2 +-
 dlls/ntdll/server.c     |   36 +++++++++++++++++++++++++++++++++---
 dlls/ntdll/thread.c     |    4 ++--
 4 files changed, 37 insertions(+), 7 deletions(-)

diff --git a/dlls/ntdll/Makefile.in b/dlls/ntdll/Makefile.in
index ac85587..98fe921 100644
--- a/dlls/ntdll/Makefile.in
+++ b/dlls/ntdll/Makefile.in
@@ -5,7 +5,7 @@ SRCDIR    = @srcdir@
 VPATH     = @srcdir@
 MODULE    = ntdll.dll
 IMPORTLIB = ntdll
-EXTRALIBS = @IOKITLIB@
+EXTRALIBS = @IOKITLIB@ @LIBPTHREAD@
 EXTRADLLFLAGS = -Wl,--image-base,0x7bc00000
 
 C_SRCS = \
diff --git a/dlls/ntdll/ntdll_misc.h b/dlls/ntdll/ntdll_misc.h
index 444a211..b42303c 100644
--- a/dlls/ntdll/ntdll_misc.h
+++ b/dlls/ntdll/ntdll_misc.h
@@ -67,7 +67,7 @@ extern void virtual_init_threading(void);
 extern timeout_t server_start_time;
 extern void server_init_process(void);
 extern NTSTATUS server_init_process_done(void);
-extern size_t server_init_thread( int unix_pid, int unix_tid, void *entry_point );
+extern size_t server_init_thread( void *entry_point );
 extern void DECLSPEC_NORETURN server_protocol_error( const char *err, ... );
 extern void DECLSPEC_NORETURN server_protocol_perror( const char *err );
 extern void DECLSPEC_NORETURN server_exit_thread( int status );
diff --git a/dlls/ntdll/server.c b/dlls/ntdll/server.c
index 145540f..2a0b3e0 100644
--- a/dlls/ntdll/server.c
+++ b/dlls/ntdll/server.c
@@ -51,6 +51,10 @@
 #ifdef HAVE_SYS_UIO_H
 #include <sys/uio.h>
 #endif
+#ifdef HAVE_SYS_THR_H
+#include <sys/ucontext.h>
+#include <sys/thr.h>
+#endif
 #ifdef HAVE_UNISTD_H
 # include <unistd.h>
 #endif
@@ -927,6 +931,32 @@ static void send_server_task_port(void)
 }
 #endif  /* __APPLE__ */
 
+
+/***********************************************************************
+ *           get_unix_tid
+ *
+ * Retrieve the Unix tid to use on the server side for the current thread.
+ */
+static int get_unix_tid(void)
+{
+    int ret = -1;
+#if defined(linux) && defined(__i386__)
+    __asm__("int $0x80" : "=a" (ret) : "0" (224) /* SYS_gettid */);
+#elif defined(linux) && defined(__x86_64__)
+    __asm__("syscall" : "=a" (ret) : "0" (186) /* SYS_gettid */);
+#elif defined(__sun)
+    ret = pthread_self();
+#elif defined(__APPLE__)
+    ret = mach_thread_self();
+#elif defined(__FreeBSD__)
+    long lwpid;
+    thr_self( &lwpid );
+    ret = lwpid;
+#endif
+    return ret;
+}
+
+
 /***********************************************************************
  *           server_init_process
  *
@@ -1012,7 +1042,7 @@ NTSTATUS server_init_process_done(void)
  *
  * Send an init thread request. Return 0 if OK.
  */
-size_t server_init_thread( int unix_pid, int unix_tid, void *entry_point )
+size_t server_init_thread( void *entry_point )
 {
     int ret;
     int reply_pipe[2];
@@ -1046,8 +1076,8 @@ size_t server_init_thread( int unix_pid, int unix_tid, void *entry_point )
 
     SERVER_START_REQ( init_thread )
     {
-        req->unix_pid    = unix_pid;
-        req->unix_tid    = unix_tid;
+        req->unix_pid    = getpid();
+        req->unix_tid    = get_unix_tid();
         req->teb         = wine_server_client_ptr( NtCurrentTeb() );
         req->peb         = wine_server_client_ptr( NtCurrentTeb()->Peb );
         req->entry       = wine_server_client_ptr( entry_point );
diff --git a/dlls/ntdll/thread.c b/dlls/ntdll/thread.c
index 56d742d..f2806d9 100644
--- a/dlls/ntdll/thread.c
+++ b/dlls/ntdll/thread.c
@@ -306,7 +306,7 @@ HANDLE thread_init(void)
 
     /* setup the server connection */
     server_init_process();
-    info_size = server_init_thread( thread_info.pid, thread_info.tid, NULL );
+    info_size = server_init_thread( NULL );
 
     /* create the process heap */
     if (!(peb->ProcessHeap = RtlCreateHeap( HEAP_GROWABLE, NULL, 0, 0, NULL, NULL )))
@@ -426,7 +426,7 @@ static void start_thread( struct wine_pthread_thread_info *info )
 
     pthread_functions.init_current_teb( info );
     signal_init_thread();
-    server_init_thread( info->pid, info->tid, func );
+    server_init_thread( func );
     pthread_functions.init_thread( info );
     virtual_alloc_thread_stack( info->stack_base, info->stack_size );
     pthread_functions.sigprocmask( SIG_UNBLOCK, &server_block_set, NULL );




More information about the wine-cvs mailing list