Alexandre Julliard : server: Removed the thread attached flag, since we always detach now.

Alexandre Julliard julliard at wine.codeweavers.com
Mon Apr 10 13:47:56 CDT 2006


Module: wine
Branch: refs/heads/master
Commit: 820c5927c86678344fe528bb8361ca498b1e519a
URL:    http://source.winehq.org/git/?p=wine.git;a=commit;h=820c5927c86678344fe528bb8361ca498b1e519a

Author: Alexandre Julliard <julliard at winehq.org>
Date:   Mon Apr 10 20:25:22 2006 +0200

server: Removed the thread attached flag, since we always detach now.

---

 server/debugger.c |    3 +-
 server/ptrace.c   |   64 +++--------------------------------------------------
 server/thread.c   |    1 -
 server/thread.h   |    3 --
 4 files changed, 5 insertions(+), 66 deletions(-)

diff --git a/server/debugger.c b/server/debugger.c
index c32b9b1..c212c0e 100644
--- a/server/debugger.c
+++ b/server/debugger.c
@@ -428,7 +428,7 @@ static int debugger_attach( struct proce
         goto error;
 
     suspend_process( process );
-    if (!attach_process( process ) || !set_process_debugger( process, debugger ))
+    if (!set_process_debugger( process, debugger ))
     {
         resume_process( process );
         return 0;
@@ -485,7 +485,6 @@ int debugger_detach( struct process *pro
     /* remove relationships between process and its debugger */
     process->debugger = NULL;
     if (!set_process_debug_flag( process, 0 )) clear_error();  /* ignore error */
-    detach_process( process );
 
     /* from this function */
     resume_process( process );
diff --git a/server/ptrace.c b/server/ptrace.c
index 51101d3..817b0ec 100644
--- a/server/ptrace.c
+++ b/server/ptrace.c
@@ -90,7 +90,6 @@ static int handle_child_status( struct t
     }
     if (thread && (WIFSIGNALED(status) || WIFEXITED(status)))
     {
-        thread->attached = 0;
         thread->unix_pid = -1;
         thread->unix_tid = -1;
         if (debug_level)
@@ -155,7 +154,6 @@ static int wait4_thread( struct thread *
             {
                 thread->unix_pid = -1;
                 thread->unix_tid = -1;
-                thread->attached = 0;
             }
             else perror( "wait4" );
             stop_watchdog();
@@ -193,52 +191,11 @@ int send_thread_signal( struct thread *t
         {
             thread->unix_pid = -1;
             thread->unix_tid = -1;
-            thread->attached = 0;
         }
     }
     return (ret != -1);
 }
 
-/* attach to a Unix process with ptrace */
-int attach_process( struct process *process )
-{
-    struct thread *thread;
-    int ret = 1;
-
-    if (list_empty( &process->thread_list ))  /* need at least one running thread */
-    {
-        set_error( STATUS_ACCESS_DENIED );
-        return 0;
-    }
-
-    LIST_FOR_EACH_ENTRY( thread, &process->thread_list, struct thread, proc_entry )
-    {
-        if (thread->attached) continue;
-        if (suspend_for_ptrace( thread )) resume_after_ptrace( thread );
-        else ret = 0;
-    }
-    return ret;
-}
-
-/* detach from a ptraced Unix process */
-void detach_process( struct process *process )
-{
-    struct thread *thread;
-
-    LIST_FOR_EACH_ENTRY( thread, &process->thread_list, struct thread, proc_entry )
-    {
-        if (thread->attached)
-        {
-            /* make sure it is stopped */
-            suspend_for_ptrace( thread );
-            if (thread->unix_pid == -1) return;
-            if (debug_level) fprintf( stderr, "%04x: *detached*\n", thread->id );
-            ptrace( PTRACE_DETACH, get_ptrace_pid(thread), (caddr_t)1, 0 );
-            thread->attached = 0;
-        }
-    }
-}
-
 /* suspend a thread to allow using ptrace on it */
 /* you must do a resume_after_ptrace when finished with the thread */
 int suspend_for_ptrace( struct thread *thread )
@@ -246,21 +203,11 @@ int suspend_for_ptrace( struct thread *t
     /* can't stop a thread while initialisation is in progress */
     if (thread->unix_pid == -1 || !is_process_init_done(thread->process)) goto error;
 
-    if (thread->attached)
-    {
-        if (!send_thread_signal( thread, SIGSTOP )) goto error;
-    }
-    else
+    /* this may fail if the client is already being debugged */
+    if (ptrace( PTRACE_ATTACH, get_ptrace_pid(thread), 0, 0 ) == -1)
     {
-        /* this may fail if the client is already being debugged */
-        if (!use_ptrace) goto error;
-        if (ptrace( PTRACE_ATTACH, get_ptrace_pid(thread), 0, 0 ) == -1)
-        {
-            if (errno == ESRCH) thread->unix_pid = thread->unix_tid = -1;  /* thread got killed */
-            goto error;
-        }
-        if (debug_level) fprintf( stderr, "%04x: *attached*\n", thread->id );
-        thread->attached = 1;
+        if (errno == ESRCH) thread->unix_pid = thread->unix_tid = -1;  /* thread got killed */
+        goto error;
     }
     if (wait4_thread( thread, SIGSTOP )) return 1;
     resume_after_ptrace( thread );
@@ -273,13 +220,10 @@ int suspend_for_ptrace( struct thread *t
 void resume_after_ptrace( struct thread *thread )
 {
     if (thread->unix_pid == -1) return;
-    assert( thread->attached );
     if (ptrace( PTRACE_DETACH, get_ptrace_pid(thread), (caddr_t)1, 0 ) == -1)
     {
         if (errno == ESRCH) thread->unix_pid = thread->unix_tid = -1;  /* thread got killed */
     }
-    if (debug_level) fprintf( stderr, "%04x: *detached*\n", thread->id );
-    thread->attached = 0;
 }
 
 /* read an int from a thread address space */
diff --git a/server/thread.c b/server/thread.c
index ccf8678..e5ef779 100644
--- a/server/thread.c
+++ b/server/thread.c
@@ -139,7 +139,6 @@ inline static void init_thread_structure
     thread->reply_fd        = NULL;
     thread->wait_fd         = NULL;
     thread->state           = RUNNING;
-    thread->attached        = 0;
     thread->exit_code       = 0;
     thread->priority        = THREAD_PRIORITY_NORMAL;
     thread->affinity        = 1;
diff --git a/server/thread.h b/server/thread.h
index 762def7..ec5a55e 100644
--- a/server/thread.h
+++ b/server/thread.h
@@ -72,7 +72,6 @@ struct thread
     struct fd             *reply_fd;      /* fd to send a reply to a client */
     struct fd             *wait_fd;       /* fd to use to wake a sleeping client */
     enum run_state         state;         /* running state */
-    int                    attached;      /* is thread attached with ptrace? */
     int                    exit_code;     /* thread exit code */
     int                    unix_pid;      /* Unix pid of client */
     int                    unix_tid;      /* Unix tid of client */
@@ -122,8 +121,6 @@ extern struct token *thread_get_imperson
 
 extern void sigchld_callback(void);
 extern int get_ptrace_pid( struct thread *thread );
-extern int attach_process( struct process *process );
-extern void detach_process( struct process *process );
 extern int suspend_for_ptrace( struct thread *thread );
 extern void resume_after_ptrace( struct thread *thread );
 extern void *get_thread_ip( struct thread *thread );




More information about the wine-cvs mailing list