Changed wait_process and wait_debug_event requests to never block;
waiting is always done through WaitForSingleObject().
diff --git a/server/debugger.c b/server/debugger.c
index 32ca8d5..5edee7f4 100644
--- a/server/debugger.c
+++ b/server/debugger.c
@@ -241,37 +241,6 @@
return event;
}
-/* build a reply for the wait_debug_event request */
-static void build_wait_debug_reply( struct thread *thread, struct object *obj, int signaled )
-{
- struct wait_debug_event_request *req = get_req_ptr( thread );
-
- if (obj)
- {
- struct debug_ctx *debug_ctx = (struct debug_ctx *)obj;
- struct debug_event *event = find_event_to_send( debug_ctx );
- size_t size = get_req_data_size(req);
-
- /* the object that woke us has to be our debug context */
- assert( obj->ops == &debug_ctx_ops );
- assert( event );
-
- event->state = EVENT_SENT;
- event->sender->debug_event = event;
- req->pid = event->sender->process;
- req->tid = event->sender;
- if (size > sizeof(debug_event_t)) size = sizeof(debug_event_t);
- memcpy( get_req_data(req), &event->data, size );
- set_req_data_size( req, size );
- }
- else /* timeout or error */
- {
- set_req_data_size( req, 0 );
- req->pid = 0;
- req->tid = 0;
- }
-}
-
/* build a reply for the send_event request */
static void build_exception_event_reply( struct thread *thread, struct object *obj, int signaled )
{
@@ -357,29 +326,6 @@
while ((event = debug_ctx->event_head) != NULL) unlink_event( debug_ctx, event );
}
-/* wait for a debug event (or send a reply at once if one is pending) */
-static int wait_for_debug_event( int timeout )
-{
- struct debug_ctx *debug_ctx = current->debug_ctx;
- struct object *obj = &debug_ctx->obj;
- int flags = 0;
- struct timeval tv;
-
- if (!debug_ctx) /* current thread is not a debugger */
- {
- set_error( STATUS_INVALID_HANDLE );
- return 0;
- }
- if (timeout != -1)
- {
- flags = SELECT_TIMEOUT;
- gettimeofday( &tv, 0 );
- add_timeout( &tv, timeout );
- }
- else tv.tv_sec = tv.tv_usec = 0;
- return sleep_on( 1, &obj, flags, tv.tv_sec, tv.tv_usec, build_wait_debug_reply );
-}
-
/* continue a debug event */
static int continue_debug_event( struct process *process, struct thread *thread, int status )
{
@@ -539,11 +485,33 @@
/* Wait for a debug event */
DECL_HANDLER(wait_debug_event)
{
- if (!wait_for_debug_event( req->timeout ))
+ struct debug_ctx *debug_ctx = current->debug_ctx;
+ struct debug_event *event;
+
+ if (!debug_ctx) /* current thread is not a debugger */
{
- req->pid = NULL;
- req->tid = NULL;
+ set_error( STATUS_INVALID_HANDLE );
+ return;
+ }
+ req->wait = 0;
+ if ((event = find_event_to_send( debug_ctx )))
+ {
+ size_t size = get_req_data_size(req);
+ event->state = EVENT_SENT;
+ event->sender->debug_event = event;
+ req->pid = event->sender->process;
+ req->tid = event->sender;
+ if (size > sizeof(debug_event_t)) size = sizeof(debug_event_t);
+ memcpy( get_req_data(req), &event->data, size );
+ set_req_data_size( req, size );
+ }
+ else /* no event ready */
+ {
+ req->pid = 0;
+ req->tid = 0;
set_req_data_size( req, 0 );
+ if (req->get_handle)
+ req->wait = alloc_handle( current->process, debug_ctx, SYNCHRONIZE, FALSE );
}
}
diff --git a/server/process.c b/server/process.c
index bab1043..cd5889c 100644
--- a/server/process.c
+++ b/server/process.c
@@ -68,6 +68,7 @@
int cmd_show; /* main window show mode */
struct file *exe_file; /* file handle for main exe */
char *filename; /* file name for main exe */
+ struct thread *owner; /* owner thread (the one that created the new process) */
struct process *process; /* created process */
struct thread *thread; /* created thread */
};
@@ -319,6 +320,11 @@
if (info->exe_file) release_object( info->exe_file );
if (info->process) release_object( info->process );
if (info->thread) release_object( info->thread );
+ if (info->owner)
+ {
+ info->owner->info = NULL;
+ release_object( info->owner );
+ }
}
static void startup_info_dump( struct object *obj, int verbose )
@@ -337,33 +343,6 @@
}
-/* build a reply for the wait_process request */
-static void build_wait_process_reply( struct thread *thread, struct object *obj, int signaled )
-{
- struct wait_process_request *req = get_req_ptr( thread );
- if (obj)
- {
- struct startup_info *info = (struct startup_info *)obj;
- assert( obj->ops == &startup_info_ops );
-
- req->pid = get_process_id( info->process );
- req->tid = get_thread_id( info->thread );
- req->phandle = alloc_handle( thread->process, info->process,
- PROCESS_ALL_ACCESS, req->pinherit );
- req->thandle = alloc_handle( thread->process, info->thread,
- THREAD_ALL_ACCESS, req->tinherit );
- if (info->process->init_event)
- req->event = alloc_handle( thread->process, info->process->init_event,
- EVENT_ALL_ACCESS, 0 );
- else
- req->event = 0;
-
- /* FIXME: set_error */
- }
- release_object( thread->info );
- thread->info = NULL;
-}
-
/* get a process from an id (and increment the refcount) */
struct process *get_process_from_id( void *id )
{
@@ -731,52 +710,52 @@
info->cmd_show = req->cmd_show;
info->exe_file = NULL;
info->filename = NULL;
+ info->owner = (struct thread *)grab_object( current );
info->process = NULL;
info->thread = NULL;
if (req->exe_file &&
!(info->exe_file = get_file_obj( current->process, req->exe_file, GENERIC_READ )))
- {
- release_object( info );
- return;
- }
+ goto done;
- if (!(info->filename = mem_alloc( len + 1 )))
- {
- release_object( info );
- return;
- }
+ if (!(info->filename = mem_alloc( len + 1 ))) goto done;
+
memcpy( info->filename, get_req_data(req), len );
info->filename[len] = 0;
current->info = info;
+ req->info = alloc_handle( current->process, info, SYNCHRONIZE, FALSE );
+
+ done:
+ release_object( info );
}
-/* Wait for the new process to start */
-DECL_HANDLER(wait_process)
+/* Retrieve information about a newly started process */
+DECL_HANDLER(get_new_process_info)
{
- if (!current->info)
+ struct startup_info *info;
+
+ req->event = 0;
+
+ if ((info = (struct startup_info *)get_handle_obj( current->process, req->info,
+ 0, &startup_info_ops )))
{
- fatal_protocol_error( current, "wait_process: no process is being created\n" );
- return;
- }
- req->pid = 0;
- req->tid = 0;
- req->phandle = 0;
- req->thandle = 0;
- req->event = 0;
- if (req->cancel)
- {
- release_object( current->info );
- current->info = NULL;
+ req->pid = get_process_id( info->process );
+ req->tid = get_thread_id( info->thread );
+ req->phandle = alloc_handle( current->process, info->process,
+ PROCESS_ALL_ACCESS, req->pinherit );
+ req->thandle = alloc_handle( current->process, info->thread,
+ THREAD_ALL_ACCESS, req->tinherit );
+ if (info->process->init_event)
+ req->event = alloc_handle( current->process, info->process->init_event,
+ EVENT_ALL_ACCESS, 0 );
+ release_object( info );
}
else
{
- struct timeval timeout;
- struct object *obj = ¤t->info->obj;
- gettimeofday( &timeout, 0 );
- add_timeout( &timeout, req->timeout );
- sleep_on( 1, &obj, SELECT_TIMEOUT, timeout.tv_sec, timeout.tv_usec,
- build_wait_process_reply );
+ req->pid = 0;
+ req->tid = 0;
+ req->phandle = 0;
+ req->thandle = 0;
}
}
diff --git a/server/request.h b/server/request.h
index 6383cb1..4c627a8 100644
--- a/server/request.h
+++ b/server/request.h
@@ -71,7 +71,7 @@
/* ### make_requests begin ### */
DECL_HANDLER(new_process);
-DECL_HANDLER(wait_process);
+DECL_HANDLER(get_new_process_info);
DECL_HANDLER(new_thread);
DECL_HANDLER(boot_done);
DECL_HANDLER(init_process);
@@ -185,7 +185,7 @@
static const req_handler req_handlers[REQ_NB_REQUESTS] =
{
(req_handler)req_new_process,
- (req_handler)req_wait_process,
+ (req_handler)req_get_new_process_info,
(req_handler)req_new_thread,
(req_handler)req_boot_done,
(req_handler)req_init_process,
diff --git a/server/trace.c b/server/trace.c
index 76c7bdf..6779601 100644
--- a/server/trace.c
+++ b/server/trace.c
@@ -275,15 +275,19 @@
cur_pos += dump_varargs_string( req );
}
-static void dump_wait_process_request( const struct wait_process_request *req )
+static void dump_new_process_reply( const struct new_process_request *req )
{
- fprintf( stderr, " pinherit=%d,", req->pinherit );
- fprintf( stderr, " tinherit=%d,", req->tinherit );
- fprintf( stderr, " timeout=%d,", req->timeout );
- fprintf( stderr, " cancel=%d", req->cancel );
+ fprintf( stderr, " info=%d", req->info );
}
-static void dump_wait_process_reply( const struct wait_process_request *req )
+static void dump_get_new_process_info_request( const struct get_new_process_info_request *req )
+{
+ fprintf( stderr, " info=%d,", req->info );
+ fprintf( stderr, " pinherit=%d,", req->pinherit );
+ fprintf( stderr, " tinherit=%d", req->tinherit );
+}
+
+static void dump_get_new_process_info_reply( const struct get_new_process_info_request *req )
{
fprintf( stderr, " pid=%p,", req->pid );
fprintf( stderr, " phandle=%d,", req->phandle );
@@ -1050,13 +1054,14 @@
static void dump_wait_debug_event_request( const struct wait_debug_event_request *req )
{
- fprintf( stderr, " timeout=%d", req->timeout );
+ fprintf( stderr, " get_handle=%d", req->get_handle );
}
static void dump_wait_debug_event_reply( const struct wait_debug_event_request *req )
{
fprintf( stderr, " pid=%p,", req->pid );
fprintf( stderr, " tid=%p,", req->tid );
+ fprintf( stderr, " wait=%d,", req->wait );
fprintf( stderr, " event=" );
cur_pos += dump_varargs_debug_event( req );
}
@@ -1474,7 +1479,7 @@
static const dump_func req_dumpers[REQ_NB_REQUESTS] = {
(dump_func)dump_new_process_request,
- (dump_func)dump_wait_process_request,
+ (dump_func)dump_get_new_process_info_request,
(dump_func)dump_new_thread_request,
(dump_func)dump_boot_done_request,
(dump_func)dump_init_process_request,
@@ -1584,8 +1589,8 @@
};
static const dump_func reply_dumpers[REQ_NB_REQUESTS] = {
- (dump_func)0,
- (dump_func)dump_wait_process_reply,
+ (dump_func)dump_new_process_reply,
+ (dump_func)dump_get_new_process_info_reply,
(dump_func)dump_new_thread_reply,
(dump_func)0,
(dump_func)dump_init_process_reply,
@@ -1696,7 +1701,7 @@
static const char * const req_names[REQ_NB_REQUESTS] = {
"new_process",
- "wait_process",
+ "get_new_process_info",
"new_thread",
"boot_done",
"init_process",