Alexandre Julliard : server: Try harder to find a suitable thread for read/ write_process_memory.

Alexandre Julliard julliard at wine.codeweavers.com
Tue Jul 25 05:09:48 CDT 2006


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

Author: Alexandre Julliard <julliard at winehq.org>
Date:   Tue Jul 25 11:41:47 2006 +0200

server: Try harder to find a suitable thread for read/write_process_memory.

---

 server/ptrace.c |   29 +++++++++++++++++------------
 1 files changed, 17 insertions(+), 12 deletions(-)

diff --git a/server/ptrace.c b/server/ptrace.c
index c3d7249..ed35d2e 100644
--- a/server/ptrace.c
+++ b/server/ptrace.c
@@ -298,18 +298,27 @@ static int write_thread_int( struct thre
     return res;
 }
 
+/* return a thread of the process suitable for ptracing */
+static struct thread *get_ptrace_thread( struct process *process )
+{
+    struct thread *thread;
+
+    LIST_FOR_EACH_ENTRY( thread, &process->thread_list, struct thread, proc_entry )
+    {
+        if (thread->unix_pid != -1) return thread;
+    }
+    set_error( STATUS_ACCESS_DENIED );  /* process is dead */
+    return NULL;
+}
+
 /* read data from a process memory space */
 int read_process_memory( struct process *process, const void *ptr, size_t size, char *dest )
 {
-    struct thread *thread = get_process_first_thread( process );
+    struct thread *thread = get_ptrace_thread( process );
     unsigned int first_offset, last_offset, len;
     int data, *addr;
 
-    if (!thread)  /* process is dead */
-    {
-        set_error( STATUS_ACCESS_DENIED );
-        return 0;
-    }
+    if (!thread) return 0;
 
     first_offset = (unsigned long)ptr % sizeof(int);
     last_offset = (size + first_offset) % sizeof(int);
@@ -366,17 +375,13 @@ static int check_process_write_access( s
 /* write data to a process memory space */
 int write_process_memory( struct process *process, void *ptr, size_t size, const char *src )
 {
-    struct thread *thread = get_process_first_thread( process );
+    struct thread *thread = get_ptrace_thread( process );
     int ret = 0, data = 0;
     size_t len;
     int *addr;
     unsigned int first_mask, first_offset, last_mask, last_offset;
 
-    if (!thread)  /* process is dead */
-    {
-        set_error( STATUS_ACCESS_DENIED );
-        return 0;
-    }
+    if (!thread) return 0;
 
     /* compute the mask for the first int */
     first_mask = ~0;




More information about the wine-cvs mailing list