server: add new threads to end of thread_list

Thomas Kho tkho at ucla.edu
Thu Jul 20 22:44:36 CDT 2006


server: add new threads to end of thread_list

The head of a process' thread_list should be best-effort an initialized
thread. Currently, new threads are prepended to thread_list which causes
write_process_memory to break if the request is interleaved between a
new_thread request and the corresponding init_thread. This occurs because
write_process_memory queries the unix_pid via the first thread in thread_list
(the new thread) which is not yet initialized with a unix pid.

An alternative solution is to introduce this code in
[read|write]_process_memory or to move the unix_pid into the process
struct. I'd be happy to do either if it's more appropriate, but I think
this change better reflects the semantics of get_process_first_thread.

This patch:
1. Appends new threads to the end of thread_list so that the first thread
   is very likely initialized.
2. Changes get_process_first_thread to try to return the first initialized
   thread before defaulting to the first (and uninitialized) thread

Thomas Kho

---

 server/process.c |   15 +++++++++++----
 1 files changed, 11 insertions(+), 4 deletions(-)

diff --git a/server/process.c b/server/process.c
index 2b8a5dc..132f4e8 100644
--- a/server/process.c
+++ b/server/process.c
@@ -207,9 +207,16 @@ void *get_ptid_entry( unsigned int id )
 /* return the main thread of the process */
 struct thread *get_process_first_thread( struct process *process )
 {
-    struct list *ptr = list_head( &process->thread_list );
-    if (!ptr) return NULL;
-    return LIST_ENTRY( ptr, struct thread, proc_entry );
+    struct thread *thread = NULL, *cur;
+
+    LIST_FOR_EACH_ENTRY( cur, &process->thread_list, struct thread, proc_entry )
+    {
+        if (cur->unix_pid != -1) /* initialized thread */
+            return cur;
+        else if (!thread)
+            thread = cur;
+    }
+    return thread;
 }
 
 /* set the state of the process startup info */
@@ -543,7 +550,7 @@ static void process_killed( struct proce
 /* add a thread to a process running threads list */
 void add_process_thread( struct process *process, struct thread *thread )
 {
-    list_add_head( &process->thread_list, &thread->proc_entry );
+    list_add_tail( &process->thread_list, &thread->proc_entry );
     if (!process->running_threads++) running_processes++;
     grab_object( thread );
 }



More information about the wine-patches mailing list