CVS: winex/scheduler client.c, 1.50, 1.51 process.c, 1.54, 1.55 sysdeps.c, 1.23, 1.24 syslevel.c, 1.12, 1.13

[email protected]
Newsgroups gmane.comp.emulators.winex.cvs
Message-ID <[email protected]>
Subject: winex/scheduler client.c,1.50,1.51 process.c,1.54,1.55 sysdeps.c,1.23,1.24 syslevel.c,1.12,1.13Update of /var/lib/cvsd/cvsroot/winex/scheduler
In directory agravaine:/tmp/cvs-serv30061/scheduler

Modified Files:
	client.c process.c sysdeps.c syslevel.c 
Log Message:

- disambiguate in-process tids (which all platforms have) with
  cross-process tids (which only some platforms have)
- store in-process tid in the TEB, and use that to fix thread cleanup on
  MacOS X
- modify shm server to handle platforms which don't have cross-process tids
- rename server unix_tid to unix_tid_or_pid for clarity
- implement MacOSX functionality on top of Mach to replace ptrace functionality on Linux:
   - suspend/resume thread
   - read/write process memory
   - get/set thread context



Index: client.c
===================================================================
RCS file: /var/lib/cvsd/cvsroot/winex/scheduler/client.c,v
retrieving revision 1.50
retrieving revision 1.51
diff -u -d -r1.50 -r1.51
--- client.c	28 Mar 2007 21:00:46 -0000	1.50
+++ client.c	30 Mar 2007 15:48:33 -0000	1.51
@@ -37,6 +37,11 @@
 #include <stdarg.h>
 #include <sys/poll.h>
 
+#ifdef __APPLE__
+#include <mach/mach.h>
+#include <servers/bootstrap.h>
+#endif
+
 #include "wine/winbase16.h"
 #include "thread.h"
 #include "wine/server.h"
@@ -1579,6 +1584,13 @@
     TEB *teb = NtCurrentTeb();
     int version, ret;
     int reply_pipe[2];
+    int unique_msg_id;
+    pid_t wineserver_pid;
+#ifdef __APPLE__
+    char PortName[BOOTSTRAP_MAX_NAME_LEN];
+    mach_port_t ServerPort;
+    mach_msg_header_t msg;
+#endif
 
     /* ignore SIGPIPE so that we get a EPIPE error instead  */
     signal( SIGPIPE, SIG_IGN );
@@ -1598,13 +1610,15 @@
 
     SERVER_START_REQ( init_thread )
     {
-        req->unix_tid    = wine_gettid();
+        req->unix_tid_or_pid    = wine_gettid_or_pid();
         req->teb         = teb;
         req->entry       = teb->entry_point;
         req->reply_fd    = reply_pipe[1];
         req->wait_fd     = teb->wait_fd[1];
         ret = wine_server_call( req );
         teb->pid = reply->pid;
+        wineserver_pid = reply->wineserver_pid;
+        unique_msg_id = reply->unique_msg_id;
         teb->tid = reply->tid;
         version  = reply->version;
         if (reply->boot) boot_thread_id = teb->tid;
@@ -1621,6 +1635,34 @@
                                "Or maybe the wrong wineserver is still running?\n",
                                version, SERVER_PROTOCOL_VERSION,
                                (version > SERVER_PROTOCOL_VERSION) ? "wine" : "wineserver" );
+
+#ifdef __APPLE__
+    /* Send port */
+    snprintf (PortName, sizeof (PortName),
+              "com.transgaming.server:%d", wineserver_pid);
+    if (bootstrap_look_up (bootstrap_port, PortName, &ServerPort) !=
+        KERN_SUCCESS)
+       server_protocol_error ("Unable to retrieve bootstrap port\n");
+
+    msg.msgh_bits = MACH_MSGH_BITS (MACH_MSG_TYPE_MOVE_SEND,
+                                    MACH_MSG_TYPE_COPY_SEND);
+    msg.msgh_size = sizeof (mach_msg_header_t);
+    msg.msgh_remote_port = ServerPort;
+    msg.msgh_local_port = mach_thread_self ();
+    msg.msgh_id = unique_msg_id;
+
+    mach_msg (&msg, MACH_SEND_MSG, msg.msgh_size, 0, MACH_PORT_NULL,
+              MACH_MSG_TIMEOUT_NONE, MACH_PORT_NULL);
+
+    SERVER_START_REQ(thread_port_sent)
+    {
+       req->unique_msg_id = unique_msg_id;
+       req->entry         = teb->entry_point;
+       req->is_process    = 0;
+       wine_server_call (req);
+    }
+    SERVER_END_REQ;
+#endif
 }
 
 

Index: process.c
===================================================================
RCS file: /var/lib/cvsd/cvsroot/winex/scheduler/process.c,v
retrieving revision 1.54
retrieving revision 1.55
diff -u -d -r1.54 -r1.55
--- process.c	29 Mar 2007 14:15:36 -0000	1.54
+++ process.c	30 Mar 2007 15:48:33 -0000	1.55
@@ -22,6 +22,14 @@
 #include <signal.h>
 #endif
 
+#ifdef __APPLE__
+#include <mach/mach_init.h>
+#include <mach/i386/thread_act.h>
+#include <mach/i386/thread_status.h>
+#include <mach/vm_map.h>
+#include <servers/bootstrap.h>
+#endif
+
 #include "wine/winbase16.h"
 #include "wine/winuser16.h"
 #include "wine/exception.h"
@@ -257,6 +265,7 @@
         proc( uCode, GetCurrentProcessId(), dwFlags, hModule );
 }
 
+
 /***********************************************************************
  *           process_init
  *
@@ -266,6 +275,13 @@
 {
     BOOL ret;
     int create_flags = 0;
+    int unique_msg_id;
+    pid_t wineserver_pid;
+#ifdef __APPLE__
+    char PortName[BOOTSTRAP_MAX_NAME_LEN];
+    mach_port_t ServerPort;
+    mach_msg_header_t msg;
+#endif
 
     /* Initialize the boot thread to have a TEB */
     THREAD_Init();
@@ -314,10 +330,42 @@
             current_startupinfo.hStdInput   = reply->hstdin;
             current_startupinfo.hStdOutput  = reply->hstdout;
             current_startupinfo.hStdError   = reply->hstderr;
+            wineserver_pid                  = reply->wineserver_pid;
+            unique_msg_id                   = reply->unique_msg_id;
         }
     }
     SERVER_END_REQ;
-    if (!ret) return FALSE;
+
+    if (!ret)
+       return FALSE;
+
+#ifdef __APPLE__
+    /* Send port */
+    snprintf (PortName, sizeof (PortName),
+              "com.transgaming.server:%d", wineserver_pid);
+    if (bootstrap_look_up (bootstrap_port, PortName, &ServerPort) !=
+        KERN_SUCCESS)
+       server_protocol_error ("Unable to retrieve bootstrap port\n");
+
+    msg.msgh_bits = MACH_MSGH_BITS (MACH_MSG_TYPE_MOVE_SEND,
+                                    MACH_MSG_TYPE_COPY_SEND);
+    msg.msgh_size = sizeof (mach_msg_header_t);
+    msg.msgh_remote_port = ServerPort;
+    msg.msgh_local_port = mach_task_self ();
+    msg.msgh_id = unique_msg_id;
+
+    mach_msg (&msg, MACH_SEND_MSG, msg.msgh_size, 0, MACH_PORT_NULL,
+              MACH_MSG_TIMEOUT_NONE, MACH_PORT_NULL);
+
+    SERVER_START_REQ(thread_port_sent)
+    {
+       req->unique_msg_id = unique_msg_id;
+       req->entry         = NULL;
+       req->is_process    = 1;
+       wine_server_call (req);
+    }
+    SERVER_END_REQ;
+#endif
 
     /* Create the process heap */
     current_process.heap = HeapCreate( HEAP_GROWABLE, 0, 0 );
@@ -548,7 +596,14 @@
 static void *start_process_pthread(void *param)
 {
     struct pthread_startup_info* psi = param;
-    pid_t new_unix_tid = wine_gettid();
+    pid_t new_unix_tid = wine_gettid_or_pid();
+    int unique_msg_id;
+    pid_t wineserver_pid;
+#ifdef __APPLE__
+    char PortName[BOOTSTRAP_MAX_NAME_LEN];
+    mach_port_t ServerPort;
+    mach_msg_header_t msg;
+#endif
 
     SYSDEPS_SetCurThread( psi->teb );
 
@@ -565,9 +620,39 @@
         req->old_unix_tid = psi->old_unix_tid;
         req->new_unix_tid = new_unix_tid;
         wine_server_call(req);
+        unique_msg_id = reply->unique_msg_id;
+        wineserver_pid = reply->wineserver_pid;
     }
     SERVER_END_REQ;
 
+#ifdef __APPLE__
+    /* Send port */
+    snprintf (PortName, sizeof (PortName),
+              "com.transgaming.server:%d", wineserver_pid);
+    if (bootstrap_look_up (bootstrap_port, PortName, &ServerPort) !=
+        KERN_SUCCESS)
+       server_protocol_error ("Unable to retrieve bootstrap port\n");
+
+    msg.msgh_bits = MACH_MSGH_BITS (MACH_MSG_TYPE_MOVE_SEND,
+                                    MACH_MSG_TYPE_COPY_SEND);
+    msg.msgh_size = sizeof (mach_msg_header_t);
+    msg.msgh_remote_port = ServerPort;
+    msg.msgh_local_port = mach_thread_self ();
+    msg.msgh_id = unique_msg_id;
+
+    mach_msg (&msg, MACH_SEND_MSG, msg.msgh_size, 0, MACH_PORT_NULL,
+              MACH_MSG_TIMEOUT_NONE, MACH_PORT_NULL);
+
+    SERVER_START_REQ(thread_port_sent)
+    {
+       req->unique_msg_id = unique_msg_id;
+       req->entry         = NULL;
+       req->is_process    = 0;
+       wine_server_call (req);
+    }
+    SERVER_END_REQ;
+#endif
+
     /* Just in case start_process returns due to exception, we setup a filter */
     __TRY
     {
@@ -743,7 +828,7 @@
 	TEB* teb = NtCurrentTeb();
 
         psi.teb = teb;
-	psi.old_unix_tid = wine_gettid();
+	psi.old_unix_tid = wine_gettid_or_pid();
 
 	CHECK_ERR( pthread_attr_init(&attr) );
 

Index: sysdeps.c
===================================================================
RCS file: /var/lib/cvsd/cvsroot/winex/scheduler/sysdeps.c,v
retrieving revision 1.23
retrieving revision 1.24
diff -u -d -r1.23 -r1.24
--- sysdeps.c	30 Mar 2007 15:48:03 -0000	1.23
+++ sysdeps.c	30 Mar 2007 15:48:33 -0000	1.24
@@ -45,6 +45,16 @@
 WINE_DEFAULT_DEBUG_CHANNEL(thread); 
 #endif
 
+#ifdef __APPLE__
+#include <mach/mach_init.h>
+#include <mach/thread_info.h>
+#ifdef __i386__
+#include <mach/i386/thread_act.h>
+#else
+#error "Need header for thread_info!"
+#endif
+#endif
+
 #if defined(linux) || defined(HAVE_CLONE)
 # ifdef HAVE_SCHED_H
 #  include <sched.h>
@@ -165,9 +175,11 @@
 void SYSDEPS_SetCurThread( TEB *teb )
 {
 #ifdef USE_PTHREADS
-    teb->unix_tid = wine_gettid();
+    teb->unix_tid_or_pid = wine_gettid_or_pid();
 #endif
 
+    teb->unix_inprocess_tid = wine_get_inprocess_tid();
+
 #if defined(__i386__)
     /* On the i386, the current thread is in the %fs register */
     SELECTOR_SetupFs( teb->teb_sel, teb );
@@ -567,18 +579,22 @@
 {
     TEB** tebp;
 
-/* On the Mac, we don't support wine_tkill currently - we'll just leak the dead thread stack memory 
-   FIXME!!! Requires Mark's new Mac cp threading code */
-#ifndef __APPLE__
-
     for (tebp = &dying_thread_list_head; *tebp != NULL; )
     {
         TEB* teb = *tebp;
         TEB* next = teb->next_dying_teb;
 
+#ifdef __APPLE__
+        thread_basic_info_data_t Info;
+        mach_msg_type_number_t Size = sizeof (Info);
+
+        if (thread_info (teb->unix_inprocess_tid, THREAD_BASIC_INFO,
+                         (thread_info_t)&Info, &Size))
+#else
         /* kill(pid, 0) is used to see if the pid exists.
          * (Yes, this strange usage is sanctioned.) */
-        if (wine_tkill(teb->unix_tid, 0) == -1 && errno == ESRCH)
+        if (wine_tkill(teb->unix_inprocess_tid, 0) == -1 && errno == ESRCH)
+#endif
         {
             if (use_memory_manager)
                 VIRTUAL_FreeMemory( teb->stack_base );
@@ -594,8 +610,6 @@
             tebp = &teb->next_dying_teb;
         }
     }
-#endif
-
 }
 
 void SYSDEPS_CleanThreads(void)

Index: syslevel.c
===================================================================
RCS file: /var/lib/cvsd/cvsroot/winex/scheduler/syslevel.c,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -d -r1.12 -r1.13
--- syslevel.c	30 Mar 2007 14:38:40 -0000	1.12
+++ syslevel.c	30 Mar 2007 15:48:33 -0000	1.13
@@ -78,7 +78,7 @@
     BOOL bDeadlockPossibility = FALSE;
 
     TRACE("(%p, level %d): thread %u (fs %04x, pid %ld) count before %ld\n",
-                  lock, lock->level, teb->tid, teb->teb_sel, (long) wine_gettid(),
+                  lock, lock->level, teb->tid, teb->teb_sel, (long) wine_get_inprocess_tid(),
                   teb->sys_count[lock->level] );
 
     for ( i = 3; i > lock->level; i-- )
@@ -95,7 +95,7 @@
     teb->sys_mutex[lock->level] = lock;
 
     TRACE("(%p, level %d): thread %u (fs %04x, pid %ld) count after  %ld\n",
-                  lock, lock->level, teb->tid, teb->teb_sel, (long) wine_gettid(),
+                  lock, lock->level, teb->tid, teb->teb_sel, (long) wine_get_inprocess_tid(),
                   teb->sys_count[lock->level] );
 
     if( bDeadlockPossibility )
@@ -116,7 +116,7 @@
     TEB *teb = NtCurrentTeb();
 
     TRACE("(%p, level %d): thread %u (fs %04x, pid %ld) count before %ld\n",
-                  lock, lock->level, teb->tid, teb->teb_sel, (long) wine_gettid(),
+                  lock, lock->level, teb->tid, teb->teb_sel, (long) wine_get_inprocess_tid(),
                   teb->sys_count[lock->level] );
 
     if ( teb->sys_count[lock->level] <= 0 || teb->sys_mutex[lock->level] != lock )
@@ -134,7 +134,7 @@
     LeaveCriticalSection( &lock->crst );
 
     TRACE("(%p, level %d): thread %u (fs %04x, pid %ld) count after  %ld\n",
-                  lock, lock->level, teb->tid, teb->teb_sel, (long) wine_gettid(),
+                  lock, lock->level, teb->tid, teb->teb_sel, (long) wine_get_inprocess_tid(),
                   teb->sys_count[lock->level] );
 }
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.