loader: FreeBSD: use thr_self syscall to get thread id

Tijl Coosemans tijl at ulyssis.org
Tue Aug 7 17:25:24 CDT 2007


---
 configure.ac     |    6 ++++++
 loader/pthread.c |   11 +++++++++++
 server/ptrace.c  |   10 ++++++++++
 3 files changed, 27 insertions(+), 0 deletions(-)
-------------- next part --------------
diff --git a/configure.ac b/configure.ac
index 06a5794..b7db988 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/loader/pthread.c b/loader/pthread.c
index 17be9e4..129faf2 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"
@@ -129,6 +133,10 @@ static int create_thread( struct wine_pthread_thread_info *info )
  */
 static void init_current_teb( struct wine_pthread_thread_info *info )
 {
+#if defined(__FreeBSD__)
+    long lwpid;
+#endif
+
 #ifdef __i386__
     /* On the i386, the current thread is in the %fs register */
     LDT_ENTRY fs_entry;
@@ -149,6 +157,9 @@ 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__)
+    thr_self( &lwpid );
+    info->tid = (int) lwpid;
 #else
     info->tid = gettid();
 #endif
diff --git a/server/ptrace.c b/server/ptrace.c
index 99cb910..84f2fac 100644
--- a/server/ptrace.c
+++ b/server/ptrace.c
@@ -159,8 +159,12 @@ void sigchld_callback(void)
 /* return the Unix pid to use in ptrace calls for a given thread */
 static int get_ptrace_pid( struct thread *thread )
 {
+#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__OpenBSD__) || defined(__NetBSD__)
+    return thread->unix_pid;
+#else
     if (thread->unix_tid != -1) return thread->unix_tid;
     return thread->unix_pid;
+#endif
 }
 
 /* wait for a ptraced child to get a certain signal */
@@ -576,6 +580,9 @@ void get_thread_context( struct thread *thread, CONTEXT *context, unsigned int f
 
     if (!suspend_for_ptrace( thread )) return;
 
+#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
+    if (thread->unix_tid != -1) pid = thread->unix_tid;
+#endif
     if (ptrace( PTRACE_GETDBREGS, pid, (caddr_t) &dbregs, 0 ) == -1) file_set_error();
     else
     {
@@ -631,6 +638,9 @@ void set_thread_context( struct thread *thread, const CONTEXT *context, unsigned
     dbregs.dr6 = context->Dr6;
     dbregs.dr7 = context->Dr7;
 #endif
+#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
+    if (thread->unix_tid != -1) pid = thread->unix_tid;
+#endif
     if (ptrace( PTRACE_SETDBREGS, pid, (caddr_t) &dbregs, 0 ) == -1) file_set_error();
     else if (thread->context)  /* update the cached values */
     {


More information about the wine-patches mailing list