From 7b767fb71c64315cf67f6ddd708051708f7a6637 Mon Sep 17 00:00:00 2001 From: Alexandre Julliard Date: Tue, 25 Jul 2006 11:41:47 +0200 Subject: [PATCH] server: Try harder to find a suitable thread for read/write_process_memory. --- server/ptrace.c | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/server/ptrace.c b/server/ptrace.c index c3d724966d0..ed35d2e50c3 100644 --- a/server/ptrace.c +++ b/server/ptrace.c @@ -298,18 +298,27 @@ static int write_thread_int( struct thread *thread, int *addr, int data, unsigne 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( struct thread *thread, int *addr, size_t /* 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;