Tijl Coosemans : loader: Use thr_self syscall to get thread id on FreeBSD.

Alexandre Julliard julliard at wine.codeweavers.com
Thu Aug 9 08:23:17 CDT 2007


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

Author: Tijl Coosemans <tijl at ulyssis.org>
Date:   Wed Aug  8 00:25:24 2007 +0200

loader: Use thr_self syscall to get thread id on FreeBSD.

---

 configure           |   62 +++++++++++++++++++++++++++++++++++++++++++++++++++
 configure.ac        |    6 +++++
 include/config.h.in |    3 ++
 loader/pthread.c    |   10 ++++++++
 server/ptrace.c     |   19 +++++++++++----
 5 files changed, 95 insertions(+), 5 deletions(-)

diff --git a/configure b/configure
index d64ad13..e191aa1 100755
--- a/configure
+++ b/configure
@@ -7478,6 +7478,68 @@ done
 
 
 
+for ac_header in sys/thr.h
+do
+as_ac_Header=`echo "ac_cv_header_$ac_header" | $as_tr_sh`
+{ echo "$as_me:$LINENO: checking for $ac_header" >&5
+echo $ECHO_N "checking for $ac_header... $ECHO_C" >&6; }
+if { as_var=$as_ac_Header; eval "test \"\${$as_var+set}\" = set"; }; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+#include <sys/types.h>
+#if HAVE_UCONTEXT_H
+#include <ucontext.h>
+#endif
+
+#include <$ac_header>
+_ACEOF
+rm -f conftest.$ac_objext
+if { (ac_try="$ac_compile"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
+  (eval "$ac_compile") 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } && {
+	 test -z "$ac_c_werror_flag" ||
+	 test ! -s conftest.err
+       } && test -s conftest.$ac_objext; then
+  eval "$as_ac_Header=yes"
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+	eval "$as_ac_Header=no"
+fi
+
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+fi
+ac_res=`eval echo '${'$as_ac_Header'}'`
+	       { echo "$as_me:$LINENO: result: $ac_res" >&5
+echo "${ECHO_T}$ac_res" >&6; }
+if test `eval echo '${'$as_ac_Header'}'` = yes; then
+  cat >>confdefs.h <<_ACEOF
+#define `echo "HAVE_$ac_header" | $as_tr_cpp` 1
+_ACEOF
+
+fi
+
+done
+
+
+
 for ac_header in pthread_np.h
 do
 as_ac_Header=`echo "ac_cv_header_$ac_header" | $as_tr_sh`
diff --git a/configure.ac b/configure.ac
index 3e22c28..6b90cd2 100644
--- a/configure.ac
+++ b/configure.ac
@@ -325,6 +325,12 @@ AC_CHECK_HEADERS([resolv.h],,,
 
 AC_CHECK_HEADERS(ucontext.h,,,[#include <signal.h>])
 
+AC_CHECK_HEADERS([sys/thr.h],,,
+[#include <sys/types.h>
+#if HAVE_UCONTEXT_H
+#include <ucontext.h>
+#endif])
+
 AC_CHECK_HEADERS([pthread_np.h],,,
 [#ifdef HAVE_PTHREAD_H
 #include <pthread.h>
diff --git a/include/config.h.in b/include/config.h.in
index cf99681..0c4935c 100644
--- a/include/config.h.in
+++ b/include/config.h.in
@@ -813,6 +813,9 @@
 /* Define to 1 if you have the <sys/sysctl.h> header file. */
 #undef HAVE_SYS_SYSCTL_H
 
+/* Define to 1 if you have the <sys/thr.h> header file. */
+#undef HAVE_SYS_THR_H
+
 /* Define to 1 if you have the <sys/times.h> header file. */
 #undef HAVE_SYS_TIMES_H
 
diff --git a/loader/pthread.c b/loader/pthread.c
index 17be9e4..7414e98 100644
--- a/loader/pthread.c
+++ b/loader/pthread.c
@@ -37,6 +37,10 @@
 #ifdef HAVE_MACH_MACH_H
 #include <mach/mach.h>
 #endif
+#ifdef HAVE_SYS_THR_H
+#include <sys/ucontext.h>
+#include <sys/thr.h>
+#endif
 
 #include "wine/library.h"
 #include "wine/pthread.h"
@@ -149,6 +153,12 @@ static void init_current_teb( struct wine_pthread_thread_info *info )
     info->tid = pthread_self();  /* this should return the lwp id on solaris */
 #elif defined(__APPLE__)
     info->tid = mach_thread_self();
+#elif defined(__FreeBSD__)
+    {
+        long lwpid;
+        thr_self( &lwpid );
+        info->tid = (int) lwpid;
+    }
 #else
     info->tid = gettid();
 #endif
diff --git a/server/ptrace.c b/server/ptrace.c
index 99cb910..f1a9afb 100644
--- a/server/ptrace.c
+++ b/server/ptrace.c
@@ -156,9 +156,18 @@ void sigchld_callback(void)
     }
 }
 
-/* return the Unix pid to use in ptrace calls for a given thread */
+/* return the Unix pid to use in ptrace calls for a given process */
 static int get_ptrace_pid( struct thread *thread )
 {
+#ifdef linux  /* linux always uses thread id */
+    if (thread->unix_tid != -1) return thread->unix_tid;
+#endif
+    return thread->unix_pid;
+}
+
+/* return the Unix tid to use in ptrace calls for a given thread */
+static int get_ptrace_tid( struct thread *thread )
+{
     if (thread->unix_tid != -1) return thread->unix_tid;
     return thread->unix_pid;
 }
@@ -501,7 +510,7 @@ void get_selector_entry( struct thread *thread, int entry, unsigned int *base,
 /* retrieve the thread x86 registers */
 void get_thread_context( struct thread *thread, CONTEXT *context, unsigned int flags )
 {
-    int i, pid = get_ptrace_pid(thread);
+    int i, pid = get_ptrace_tid(thread);
     long data[8];
 
     /* all other regs are handled on the client side */
@@ -534,7 +543,7 @@ done:
 /* set the thread x86 registers */
 void set_thread_context( struct thread *thread, const CONTEXT *context, unsigned int flags )
 {
-    int pid = get_ptrace_pid( thread );
+    int pid = get_ptrace_tid( thread );
 
     /* all other regs are handled on the client side */
     assert( (flags | CONTEXT_i386) == CONTEXT_DEBUG_REGISTERS );
@@ -568,7 +577,7 @@ void set_thread_context( struct thread *thread, const CONTEXT *context, unsigned
 /* retrieve the thread x86 registers */
 void get_thread_context( struct thread *thread, CONTEXT *context, unsigned int flags )
 {
-    int pid = get_ptrace_pid(thread);
+    int pid = get_ptrace_tid(thread);
     struct dbreg dbregs;
 
     /* all other regs are handled on the client side */
@@ -603,7 +612,7 @@ void get_thread_context( struct thread *thread, CONTEXT *context, unsigned int f
 /* set the thread x86 registers */
 void set_thread_context( struct thread *thread, const CONTEXT *context, unsigned int flags )
 {
-    int pid = get_ptrace_pid(thread);
+    int pid = get_ptrace_tid(thread);
     struct dbreg dbregs;
 
     /* all other regs are handled on the client side */




More information about the wine-cvs mailing list