From 2f2898b571a01114041bf523cf1e36402e4203f3 Mon Sep 17 00:00:00 2001 From: Ulrich Weigand Date: Tue, 16 Mar 1999 16:28:36 +0000 Subject: [PATCH] Handle suspend/resume_thread requests in phase STARTING correctly. Set initial suspend count for threads created with CREATE_SUSPENDED. Set 'inheritable' flag for process/thread handles. --- include/server.h | 7 ++++++- include/server/thread.h | 5 +++-- scheduler/client.c | 7 ++++++- server/request.c | 8 ++++++-- server/thread.c | 11 ++++++----- server/trace.c | 5 ++++- 6 files changed, 31 insertions(+), 12 deletions(-) diff --git a/include/server.h b/include/server.h index fcce2a57b8e..50bc466c507 100644 --- a/include/server.h +++ b/include/server.h @@ -44,6 +44,9 @@ struct cmsg_fd struct new_thread_request { void* pid; /* process id for the new thread (or 0 if none yet) */ + int suspend; /* new thread should be suspended on creation */ + int tinherit; /* inherit flag for thread handle */ + int pinherit; /* inherit flag for process handle */ }; struct new_thread_reply { @@ -656,7 +659,9 @@ extern unsigned int CLIENT_WaitReply( int *len, int *passed_fd, extern unsigned int CLIENT_WaitSimpleReply( void *reply, int len, int *passed_fd ); struct _THDB; -extern int CLIENT_NewThread( struct _THDB *thdb, int *thandle, int *phandle ); +extern int CLIENT_NewThread( struct _THDB *thdb, + LPSECURITY_ATTRIBUTES psa, LPSECURITY_ATTRIBUTES tsa, + int *thandle, int *phandle ); extern int CLIENT_SetDebug( int level ); extern int CLIENT_InitThread(void); #endif /* __WINE_SERVER__ */ diff --git a/include/server/thread.h b/include/server/thread.h index d5f8f00859b..50e25844495 100644 --- a/include/server/thread.h +++ b/include/server/thread.h @@ -50,8 +50,9 @@ extern struct thread *current; /* thread functions */ -extern struct thread *create_thread( int fd, void *pid, int *thread_handle, - int *process_handle ); +extern struct thread *create_thread( int fd, void *pid, int suspend, + int thread_inherit, int process_inherit, + int *thread_handle, int *process_handle ); extern struct thread *get_thread_from_id( void *id ); extern struct thread *get_thread_from_handle( int handle, unsigned int access ); extern void get_thread_info( struct thread *thread, diff --git a/scheduler/client.c b/scheduler/client.c index c380fa64c85..54ce0d845d6 100644 --- a/scheduler/client.c +++ b/scheduler/client.c @@ -276,7 +276,9 @@ unsigned int CLIENT_WaitSimpleReply( void *reply, int len, int *passed_fd ) * * Send a new thread request. */ -int CLIENT_NewThread( THDB *thdb, int *thandle, int *phandle ) +int CLIENT_NewThread( THDB *thdb, + LPSECURITY_ATTRIBUTES psa, LPSECURITY_ATTRIBUTES tsa, + int *thandle, int *phandle ) { struct new_thread_request request; struct new_thread_reply reply; @@ -289,6 +291,9 @@ int CLIENT_NewThread( THDB *thdb, int *thandle, int *phandle ) } request.pid = thdb->process->server_pid; + request.suspend = (thdb->flags & CREATE_SUSPENDED)? TRUE : FALSE; + request.tinherit = (tsa && (tsa->nLength>=sizeof(*tsa)) && tsa->bInheritHandle); + request.pinherit = (psa && (psa->nLength>=sizeof(*psa)) && psa->bInheritHandle); CLIENT_SendRequest( REQ_NEW_THREAD, fd[1], 1, &request, sizeof(request) ); if (CLIENT_WaitSimpleReply( &reply, sizeof(reply), NULL )) goto error; thdb->server_tid = reply.tid; diff --git a/server/request.c b/server/request.c index e25b7bbda57..31554f5aca1 100644 --- a/server/request.c +++ b/server/request.c @@ -9,6 +9,7 @@ #include #include #include +#include #include #include #include @@ -113,8 +114,9 @@ DECL_HANDLER(new_thread) err = ERROR_TOO_MANY_OPEN_FILES; goto done; } - if (!(new_thread = create_thread( new_fd, req->pid, &reply.thandle, - &reply.phandle ))) + if (!(new_thread = create_thread( new_fd, req->pid, req->suspend, + req->tinherit, req->pinherit, + &reply.thandle, &reply.phandle ))) { close( new_fd ); err = ERROR_OUTOFMEMORY; @@ -153,6 +155,8 @@ DECL_HANDLER(init_thread) current->name[len] = '\0'; CLEAR_ERROR(); done: + if (current->suspend > 0 && current->unix_pid) + kill( current->unix_pid, SIGSTOP ); send_reply( current, -1, 0 ); } diff --git a/server/thread.c b/server/thread.c index cd07d0af47d..296c27b41e0 100644 --- a/server/thread.c +++ b/server/thread.c @@ -75,8 +75,9 @@ static struct thread *first_thread; /* create a new thread */ -struct thread *create_thread( int fd, void *pid, int *thread_handle, - int *process_handle ) +struct thread *create_thread( int fd, void *pid, int suspend, + int thread_inherit, int process_inherit, + int *thread_handle, int *process_handle ) { struct thread *thread; struct process *process; @@ -107,7 +108,7 @@ struct thread *create_thread( int fd, void *pid, int *thread_handle, thread->prev = NULL; thread->priority = THREAD_PRIORITY_NORMAL; thread->affinity = 1; - thread->suspend = 0; + thread->suspend = suspend? 1 : 0; if (first_thread) first_thread->prev = thread; first_thread = thread; @@ -117,13 +118,13 @@ struct thread *create_thread( int fd, void *pid, int *thread_handle, if (current) { if ((*thread_handle = alloc_handle( current->process, thread, - THREAD_ALL_ACCESS, 0 )) == -1) + THREAD_ALL_ACCESS, thread_inherit )) == -1) goto error; } if (current && !pid) { if ((*process_handle = alloc_handle( current->process, process, - PROCESS_ALL_ACCESS, 0 )) == -1) + PROCESS_ALL_ACCESS, process_inherit )) == -1) goto error; } diff --git a/server/trace.c b/server/trace.c index 8a35b817530..a091d8c9c46 100644 --- a/server/trace.c +++ b/server/trace.c @@ -8,7 +8,10 @@ static int dump_new_thread_request( struct new_thread_request *req, int len ) { - fprintf( stderr, " pid=%p", req->pid ); + fprintf( stderr, " pid=%p,", req->pid ); + fprintf( stderr, " suspend=%d,", req->suspend ); + fprintf( stderr, " tinherit=%d,", req->tinherit ); + fprintf( stderr, " pinherit=%d", req->pinherit ); return (int)sizeof(*req); }