Commit 820c5927 authored by Alexandre Julliard's avatar Alexandre Julliard

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

parent 5cc97c4e
...@@ -428,7 +428,7 @@ static int debugger_attach( struct process *process, struct thread *debugger ) ...@@ -428,7 +428,7 @@ static int debugger_attach( struct process *process, struct thread *debugger )
goto error; goto error;
suspend_process( process ); suspend_process( process );
if (!attach_process( process ) || !set_process_debugger( process, debugger )) if (!set_process_debugger( process, debugger ))
{ {
resume_process( process ); resume_process( process );
return 0; return 0;
...@@ -485,7 +485,6 @@ int debugger_detach( struct process *process, struct thread *debugger ) ...@@ -485,7 +485,6 @@ int debugger_detach( struct process *process, struct thread *debugger )
/* remove relationships between process and its debugger */ /* remove relationships between process and its debugger */
process->debugger = NULL; process->debugger = NULL;
if (!set_process_debug_flag( process, 0 )) clear_error(); /* ignore error */ if (!set_process_debug_flag( process, 0 )) clear_error(); /* ignore error */
detach_process( process );
/* from this function */ /* from this function */
resume_process( process ); resume_process( process );
......
...@@ -90,7 +90,6 @@ static int handle_child_status( struct thread *thread, int pid, int status, int ...@@ -90,7 +90,6 @@ static int handle_child_status( struct thread *thread, int pid, int status, int
} }
if (thread && (WIFSIGNALED(status) || WIFEXITED(status))) if (thread && (WIFSIGNALED(status) || WIFEXITED(status)))
{ {
thread->attached = 0;
thread->unix_pid = -1; thread->unix_pid = -1;
thread->unix_tid = -1; thread->unix_tid = -1;
if (debug_level) if (debug_level)
...@@ -155,7 +154,6 @@ static int wait4_thread( struct thread *thread, int signal ) ...@@ -155,7 +154,6 @@ static int wait4_thread( struct thread *thread, int signal )
{ {
thread->unix_pid = -1; thread->unix_pid = -1;
thread->unix_tid = -1; thread->unix_tid = -1;
thread->attached = 0;
} }
else perror( "wait4" ); else perror( "wait4" );
stop_watchdog(); stop_watchdog();
...@@ -193,52 +191,11 @@ int send_thread_signal( struct thread *thread, int sig ) ...@@ -193,52 +191,11 @@ int send_thread_signal( struct thread *thread, int sig )
{ {
thread->unix_pid = -1; thread->unix_pid = -1;
thread->unix_tid = -1; thread->unix_tid = -1;
thread->attached = 0;
} }
} }
return (ret != -1); 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 */ /* suspend a thread to allow using ptrace on it */
/* you must do a resume_after_ptrace when finished with the thread */ /* you must do a resume_after_ptrace when finished with the thread */
int suspend_for_ptrace( struct thread *thread ) int suspend_for_ptrace( struct thread *thread )
...@@ -246,21 +203,11 @@ int suspend_for_ptrace( struct thread *thread ) ...@@ -246,21 +203,11 @@ int suspend_for_ptrace( struct thread *thread )
/* can't stop a thread while initialisation is in progress */ /* 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->unix_pid == -1 || !is_process_init_done(thread->process)) goto error;
if (thread->attached) /* this may fail if the client is already being debugged */
{ if (ptrace( PTRACE_ATTACH, get_ptrace_pid(thread), 0, 0 ) == -1)
if (!send_thread_signal( thread, SIGSTOP )) goto error;
}
else
{ {
/* this may fail if the client is already being debugged */ if (errno == ESRCH) thread->unix_pid = thread->unix_tid = -1; /* thread got killed */
if (!use_ptrace) goto error; 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 (wait4_thread( thread, SIGSTOP )) return 1; if (wait4_thread( thread, SIGSTOP )) return 1;
resume_after_ptrace( thread ); resume_after_ptrace( thread );
...@@ -273,13 +220,10 @@ int suspend_for_ptrace( struct thread *thread ) ...@@ -273,13 +220,10 @@ int suspend_for_ptrace( struct thread *thread )
void resume_after_ptrace( struct thread *thread ) void resume_after_ptrace( struct thread *thread )
{ {
if (thread->unix_pid == -1) return; if (thread->unix_pid == -1) return;
assert( thread->attached );
if (ptrace( PTRACE_DETACH, get_ptrace_pid(thread), (caddr_t)1, 0 ) == -1) 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 (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 */ /* read an int from a thread address space */
......
...@@ -139,7 +139,6 @@ inline static void init_thread_structure( struct thread *thread ) ...@@ -139,7 +139,6 @@ inline static void init_thread_structure( struct thread *thread )
thread->reply_fd = NULL; thread->reply_fd = NULL;
thread->wait_fd = NULL; thread->wait_fd = NULL;
thread->state = RUNNING; thread->state = RUNNING;
thread->attached = 0;
thread->exit_code = 0; thread->exit_code = 0;
thread->priority = THREAD_PRIORITY_NORMAL; thread->priority = THREAD_PRIORITY_NORMAL;
thread->affinity = 1; thread->affinity = 1;
......
...@@ -72,7 +72,6 @@ struct thread ...@@ -72,7 +72,6 @@ struct thread
struct fd *reply_fd; /* fd to send a reply to a client */ struct fd *reply_fd; /* fd to send a reply to a client */
struct fd *wait_fd; /* fd to use to wake a sleeping client */ struct fd *wait_fd; /* fd to use to wake a sleeping client */
enum run_state state; /* running state */ enum run_state state; /* running state */
int attached; /* is thread attached with ptrace? */
int exit_code; /* thread exit code */ int exit_code; /* thread exit code */
int unix_pid; /* Unix pid of client */ int unix_pid; /* Unix pid of client */
int unix_tid; /* Unix tid of client */ int unix_tid; /* Unix tid of client */
...@@ -122,8 +121,6 @@ extern struct token *thread_get_impersonation_token( struct thread *thread ); ...@@ -122,8 +121,6 @@ extern struct token *thread_get_impersonation_token( struct thread *thread );
extern void sigchld_callback(void); extern void sigchld_callback(void);
extern int get_ptrace_pid( struct thread *thread ); 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 int suspend_for_ptrace( struct thread *thread );
extern void resume_after_ptrace( struct thread *thread ); extern void resume_after_ptrace( struct thread *thread );
extern void *get_thread_ip( struct thread *thread ); extern void *get_thread_ip( struct thread *thread );
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment