2 * Server-side process management
4 * Copyright (C) 1998 Alexandre Julliard
17 #ifdef HAVE_SYS_SOCKET_H
18 # include <sys/socket.h>
30 /* process structure */
32 static struct process
*first_process
;
33 static int running_processes
;
35 /* process operations */
37 static void process_dump( struct object
*obj
, int verbose
);
38 static int process_signaled( struct object
*obj
, struct thread
*thread
);
39 static void process_destroy( struct object
*obj
);
41 static const struct object_ops process_ops
=
43 sizeof(struct process
), /* size */
44 process_dump
, /* dump */
45 add_queue
, /* add_queue */
46 remove_queue
, /* remove_queue */
47 process_signaled
, /* signaled */
48 no_satisfied
, /* satisfied */
49 NULL
, /* get_poll_events */
50 NULL
, /* poll_event */
51 no_get_fd
, /* get_fd */
53 no_get_file_info
, /* get_file_info */
54 process_destroy
/* destroy */
57 /* process startup info */
61 struct object obj
; /* object header */
62 int inherit_all
; /* inherit all handles from parent */
63 int create_flags
; /* creation flags */
64 int start_flags
; /* flags from startup info */
65 handle_t hstdin
; /* handle for stdin */
66 handle_t hstdout
; /* handle for stdout */
67 handle_t hstderr
; /* handle for stderr */
68 int cmd_show
; /* main window show mode */
69 struct file
*exe_file
; /* file handle for main exe */
70 char *filename
; /* file name for main exe */
71 struct process
*process
; /* created process */
72 struct thread
*thread
; /* created thread */
75 static void startup_info_dump( struct object
*obj
, int verbose
);
76 static int startup_info_signaled( struct object
*obj
, struct thread
*thread
);
77 static void startup_info_destroy( struct object
*obj
);
79 static const struct object_ops startup_info_ops
=
81 sizeof(struct startup_info
), /* size */
82 startup_info_dump
, /* dump */
83 add_queue
, /* add_queue */
84 remove_queue
, /* remove_queue */
85 startup_info_signaled
, /* signaled */
86 no_satisfied
, /* satisfied */
87 NULL
, /* get_poll_events */
88 NULL
, /* poll_event */
89 no_get_fd
, /* get_fd */
91 no_get_file_info
, /* get_file_info */
92 startup_info_destroy
/* destroy */
96 /* set the console and stdio handles for a newly created process */
97 static int set_process_console( struct process
*process
, struct process
*parent
,
98 struct startup_info
*info
, struct init_process_request
*req
)
100 if (process
->create_flags
& CREATE_NEW_CONSOLE
)
102 if (!alloc_console( process
)) return 0;
104 else if (parent
&& !(process
->create_flags
& DETACHED_PROCESS
))
106 if (parent
->console_in
) process
->console_in
= grab_object( parent
->console_in
);
107 if (parent
->console_out
) process
->console_out
= grab_object( parent
->console_out
);
111 if (!info
->inherit_all
&& !(info
->start_flags
& STARTF_USESTDHANDLES
))
113 /* duplicate the handle from the parent into this process */
114 req
->hstdin
= duplicate_handle( parent
, info
->hstdin
, process
,
115 0, TRUE
, DUPLICATE_SAME_ACCESS
);
116 req
->hstdout
= duplicate_handle( parent
, info
->hstdout
, process
,
117 0, TRUE
, DUPLICATE_SAME_ACCESS
);
118 req
->hstderr
= duplicate_handle( parent
, info
->hstderr
, process
,
119 0, TRUE
, DUPLICATE_SAME_ACCESS
);
123 req
->hstdin
= info
->hstdin
;
124 req
->hstdout
= info
->hstdout
;
125 req
->hstderr
= info
->hstderr
;
130 /* no parent, use handles to the console for stdio */
131 req
->hstdin
= alloc_handle( process
, process
->console_in
,
132 GENERIC_READ
| GENERIC_WRITE
| SYNCHRONIZE
, 1 );
133 req
->hstdout
= alloc_handle( process
, process
->console_out
,
134 GENERIC_READ
| GENERIC_WRITE
| SYNCHRONIZE
, 1 );
135 req
->hstderr
= alloc_handle( process
, process
->console_out
,
136 GENERIC_READ
| GENERIC_WRITE
| SYNCHRONIZE
, 1 );
138 /* some handles above may have been invalid; this is not an error */
139 if (get_error() == STATUS_INVALID_HANDLE
) clear_error();
143 /* create a new process and its main thread */
144 struct thread
*create_process( int fd
)
146 struct process
*process
;
147 struct thread
*thread
= NULL
;
149 if (!(process
= alloc_object( &process_ops
, -1 )))
154 process
->next
= NULL
;
155 process
->prev
= NULL
;
156 process
->thread_list
= NULL
;
157 process
->debugger
= NULL
;
158 process
->handles
= NULL
;
159 process
->exit_code
= STILL_ACTIVE
;
160 process
->running_threads
= 0;
161 process
->priority
= NORMAL_PRIORITY_CLASS
;
162 process
->affinity
= 1;
163 process
->suspend
= 0;
164 process
->create_flags
= 0;
165 process
->console_in
= NULL
;
166 process
->console_out
= NULL
;
167 process
->init_event
= NULL
;
168 process
->idle_event
= NULL
;
169 process
->queue
= NULL
;
170 process
->atom_table
= NULL
;
171 process
->ldt_copy
= NULL
;
172 process
->exe
.next
= NULL
;
173 process
->exe
.prev
= NULL
;
174 process
->exe
.file
= NULL
;
175 process
->exe
.dbg_offset
= 0;
176 process
->exe
.dbg_size
= 0;
177 gettimeofday( &process
->start_time
, NULL
);
178 if ((process
->next
= first_process
) != NULL
) process
->next
->prev
= process
;
179 first_process
= process
;
181 /* create the init done event */
182 if (!(process
->init_event
= create_event( NULL
, 0, 1, 0 ))) goto error
;
184 /* create the main thread */
185 if (!(thread
= create_thread( fd
, process
))) goto error
;
187 release_object( process
);
191 if (thread
) release_object( thread
);
192 release_object( process
);
196 /* initialize the current process and fill in the request */
197 static void init_process( int ppid
, struct init_process_request
*req
)
199 struct process
*process
= current
->process
;
200 struct thread
*parent_thread
= get_thread_from_pid( ppid
);
201 struct process
*parent
= NULL
;
202 struct startup_info
*info
= NULL
;
206 parent
= parent_thread
->process
;
207 info
= parent_thread
->info
;
210 fatal_protocol_error( current
, "init_process: parent but no info\n" );
215 fatal_protocol_error( current
, "init_process: called twice?\n" );
220 /* set the process flags */
221 process
->create_flags
= info
? info
->create_flags
: CREATE_NEW_CONSOLE
;
223 /* create the handle table */
224 if (parent
&& info
->inherit_all
== 2) /* HACK! */
225 process
->handles
= grab_object( parent
->handles
);
226 else if (parent
&& info
->inherit_all
)
227 process
->handles
= copy_handle_table( process
, parent
);
229 process
->handles
= alloc_handle_table( process
, 0 );
230 if (!process
->handles
) goto error
;
232 /* retrieve the main exe file */
234 if (parent
&& info
->exe_file
)
236 process
->exe
.file
= (struct file
*)grab_object( info
->exe_file
);
237 if (!(req
->exe_file
= alloc_handle( process
, process
->exe
.file
, GENERIC_READ
, 0 )))
241 /* set the process console */
242 if (!set_process_console( process
, parent
, info
, req
)) goto error
;
246 /* attach to the debugger if requested */
247 if (process
->create_flags
& (DEBUG_PROCESS
| DEBUG_ONLY_THIS_PROCESS
))
248 set_process_debugger( process
, parent_thread
);
249 else if (parent
&& parent
->debugger
&& !(parent
->create_flags
& DEBUG_ONLY_THIS_PROCESS
))
250 set_process_debugger( process
, parent
->debugger
);
253 /* thread will be actually suspended in init_done */
254 if (process
->create_flags
& CREATE_SUSPENDED
) current
->suspend
++;
258 size_t size
= strlen(info
->filename
);
259 if (size
> get_req_data_size(req
)) size
= get_req_data_size(req
);
260 req
->start_flags
= info
->start_flags
;
261 req
->cmd_show
= info
->cmd_show
;
262 memcpy( get_req_data(req
), info
->filename
, size
);
263 set_req_data_size( req
, size
);
264 info
->process
= (struct process
*)grab_object( process
);
265 info
->thread
= (struct thread
*)grab_object( current
);
266 wake_up( &info
->obj
, 0 );
270 req
->start_flags
= STARTF_USESTDHANDLES
;
272 set_req_data_size( req
, 0 );
274 req
->server_start
= server_start_ticks
;
278 /* destroy a process when its refcount is 0 */
279 static void process_destroy( struct object
*obj
)
281 struct process
*process
= (struct process
*)obj
;
282 assert( obj
->ops
== &process_ops
);
284 /* we can't have a thread remaining */
285 assert( !process
->thread_list
);
286 if (process
->next
) process
->next
->prev
= process
->prev
;
287 if (process
->prev
) process
->prev
->next
= process
->next
;
288 else first_process
= process
->next
;
289 if (process
->init_event
) release_object( process
->init_event
);
290 if (process
->idle_event
) release_object( process
->idle_event
);
291 if (process
->queue
) release_object( process
->queue
);
292 if (process
->atom_table
) release_object( process
->atom_table
);
293 if (process
->exe
.file
) release_object( process
->exe
.file
);
296 /* dump a process on stdout for debugging purposes */
297 static void process_dump( struct object
*obj
, int verbose
)
299 struct process
*process
= (struct process
*)obj
;
300 assert( obj
->ops
== &process_ops
);
302 fprintf( stderr
, "Process next=%p prev=%p console=%p/%p handles=%p\n",
303 process
->next
, process
->prev
, process
->console_in
, process
->console_out
,
307 static int process_signaled( struct object
*obj
, struct thread
*thread
)
309 struct process
*process
= (struct process
*)obj
;
310 return !process
->running_threads
;
314 static void startup_info_destroy( struct object
*obj
)
316 struct startup_info
*info
= (struct startup_info
*)obj
;
317 assert( obj
->ops
== &startup_info_ops
);
318 if (info
->filename
) free( info
->filename
);
319 if (info
->exe_file
) release_object( info
->exe_file
);
320 if (info
->process
) release_object( info
->process
);
321 if (info
->thread
) release_object( info
->thread
);
324 static void startup_info_dump( struct object
*obj
, int verbose
)
326 struct startup_info
*info
= (struct startup_info
*)obj
;
327 assert( obj
->ops
== &startup_info_ops
);
329 fprintf( stderr
, "Startup info flags=%x in=%d out=%d err=%d name='%s'\n",
330 info
->start_flags
, info
->hstdin
, info
->hstdout
, info
->hstderr
, info
->filename
);
333 static int startup_info_signaled( struct object
*obj
, struct thread
*thread
)
335 struct startup_info
*info
= (struct startup_info
*)obj
;
336 return (info
->thread
!= NULL
);
340 /* build a reply for the wait_process request */
341 static void build_wait_process_reply( struct thread
*thread
, struct object
*obj
, int signaled
)
343 struct wait_process_request
*req
= get_req_ptr( thread
);
346 struct startup_info
*info
= (struct startup_info
*)obj
;
347 assert( obj
->ops
== &startup_info_ops
);
349 req
->pid
= get_process_id( info
->process
);
350 req
->tid
= get_thread_id( info
->thread
);
351 req
->phandle
= alloc_handle( thread
->process
, info
->process
,
352 PROCESS_ALL_ACCESS
, req
->pinherit
);
353 req
->thandle
= alloc_handle( thread
->process
, info
->thread
,
354 THREAD_ALL_ACCESS
, req
->tinherit
);
355 if (info
->process
->init_event
)
356 req
->event
= alloc_handle( thread
->process
, info
->process
->init_event
,
357 EVENT_ALL_ACCESS
, 0 );
361 /* FIXME: set_error */
363 release_object( thread
->info
);
367 /* get a process from an id (and increment the refcount) */
368 struct process
*get_process_from_id( void *id
)
370 struct process
*p
= first_process
;
371 while (p
&& (p
!= id
)) p
= p
->next
;
372 if (p
) grab_object( p
);
373 else set_error( STATUS_INVALID_PARAMETER
);
377 /* get a process from a handle (and increment the refcount) */
378 struct process
*get_process_from_handle( handle_t handle
, unsigned int access
)
380 return (struct process
*)get_handle_obj( current
->process
, handle
,
381 access
, &process_ops
);
384 /* add a dll to a process list */
385 static struct process_dll
*process_load_dll( struct process
*process
, struct file
*file
,
388 struct process_dll
*dll
;
390 /* make sure we don't already have one with the same base address */
391 for (dll
= process
->exe
.next
; dll
; dll
= dll
->next
) if (dll
->base
== base
)
393 set_error( STATUS_INVALID_PARAMETER
);
397 if ((dll
= mem_alloc( sizeof(*dll
) )))
399 dll
->prev
= &process
->exe
;
402 if (file
) dll
->file
= (struct file
*)grab_object( file
);
403 if ((dll
->next
= process
->exe
.next
)) dll
->next
->prev
= dll
;
404 process
->exe
.next
= dll
;
409 /* remove a dll from a process list */
410 static void process_unload_dll( struct process
*process
, void *base
)
412 struct process_dll
*dll
;
414 for (dll
= process
->exe
.next
; dll
; dll
= dll
->next
)
416 if (dll
->base
== base
)
418 if (dll
->file
) release_object( dll
->file
);
419 if (dll
->next
) dll
->next
->prev
= dll
->prev
;
420 if (dll
->prev
) dll
->prev
->next
= dll
->next
;
422 generate_debug_event( current
, UNLOAD_DLL_DEBUG_EVENT
, base
);
426 set_error( STATUS_INVALID_PARAMETER
);
429 /* a process has been killed (i.e. its last thread died) */
430 static void process_killed( struct process
*process
)
432 assert( !process
->thread_list
);
433 gettimeofday( &process
->end_time
, NULL
);
434 if (process
->handles
) release_object( process
->handles
);
435 process
->handles
= NULL
;
436 free_console( process
);
437 while (process
->exe
.next
)
439 struct process_dll
*dll
= process
->exe
.next
;
440 process
->exe
.next
= dll
->next
;
441 if (dll
->file
) release_object( dll
->file
);
444 if (process
->exe
.file
) release_object( process
->exe
.file
);
445 process
->exe
.file
= NULL
;
446 wake_up( &process
->obj
, 0 );
447 if (!--running_processes
)
449 /* last process died, close global handles */
450 close_global_handles();
451 /* this will cause the select loop to terminate */
452 if (!persistent_server
) close_master_socket();
456 /* add a thread to a process running threads list */
457 void add_process_thread( struct process
*process
, struct thread
*thread
)
459 thread
->proc_next
= process
->thread_list
;
460 thread
->proc_prev
= NULL
;
461 if (thread
->proc_next
) thread
->proc_next
->proc_prev
= thread
;
462 process
->thread_list
= thread
;
463 if (!process
->running_threads
++) running_processes
++;
464 grab_object( thread
);
467 /* remove a thread from a process running threads list */
468 void remove_process_thread( struct process
*process
, struct thread
*thread
)
470 assert( process
->running_threads
> 0 );
471 assert( process
->thread_list
);
473 if (thread
->proc_next
) thread
->proc_next
->proc_prev
= thread
->proc_prev
;
474 if (thread
->proc_prev
) thread
->proc_prev
->proc_next
= thread
->proc_next
;
475 else process
->thread_list
= thread
->proc_next
;
477 if (!--process
->running_threads
)
479 /* we have removed the last running thread, exit the process */
480 process
->exit_code
= thread
->exit_code
;
481 generate_debug_event( thread
, EXIT_PROCESS_DEBUG_EVENT
, process
);
482 process_killed( process
);
484 else generate_debug_event( thread
, EXIT_THREAD_DEBUG_EVENT
, thread
);
485 release_object( thread
);
488 /* suspend all the threads of a process */
489 void suspend_process( struct process
*process
)
491 if (!process
->suspend
++)
493 struct thread
*thread
= process
->thread_list
;
494 for (; thread
; thread
= thread
->proc_next
)
496 if (!thread
->suspend
) stop_thread( thread
);
501 /* resume all the threads of a process */
502 void resume_process( struct process
*process
)
504 assert (process
->suspend
> 0);
505 if (!--process
->suspend
)
507 struct thread
*thread
= process
->thread_list
;
508 for (; thread
; thread
= thread
->proc_next
)
510 if (!thread
->suspend
) continue_thread( thread
);
515 /* kill a process on the spot */
516 static void kill_process( struct process
*process
, struct thread
*skip
, int exit_code
)
518 struct thread
*thread
= process
->thread_list
;
521 struct thread
*next
= thread
->proc_next
;
522 thread
->exit_code
= exit_code
;
523 if (thread
!= skip
) kill_thread( thread
, 1 );
528 /* kill all processes being debugged by a given thread */
529 void kill_debugged_processes( struct thread
*debugger
, int exit_code
)
531 for (;;) /* restart from the beginning of the list every time */
533 struct process
*process
= first_process
;
534 /* find the first process being debugged by 'debugger' and still running */
535 while (process
&& (process
->debugger
!= debugger
|| !process
->running_threads
))
536 process
= process
->next
;
537 if (!process
) return;
538 process
->debugger
= NULL
;
539 kill_process( process
, NULL
, exit_code
);
543 /* get all information about a process */
544 static void get_process_info( struct process
*process
, struct get_process_info_request
*req
)
547 req
->debugged
= (process
->debugger
!= 0);
548 req
->exit_code
= process
->exit_code
;
549 req
->priority
= process
->priority
;
550 req
->process_affinity
= process
->affinity
;
551 req
->system_affinity
= 1;
554 /* set all information about a process */
555 static void set_process_info( struct process
*process
,
556 struct set_process_info_request
*req
)
558 if (req
->mask
& SET_PROCESS_INFO_PRIORITY
)
559 process
->priority
= req
->priority
;
560 if (req
->mask
& SET_PROCESS_INFO_AFFINITY
)
562 if (req
->affinity
!= 1) set_error( STATUS_INVALID_PARAMETER
);
563 else process
->affinity
= req
->affinity
;
567 /* read data from a process memory space */
568 /* len is the total size (in ints), max is the size we can actually store in the output buffer */
569 /* we read the total size in all cases to check for permissions */
570 static void read_process_memory( struct process
*process
, const int *addr
,
571 size_t len
, size_t max
, int *dest
)
573 struct thread
*thread
= process
->thread_list
;
575 if ((unsigned int)addr
% sizeof(int)) /* address must be aligned */
577 set_error( STATUS_INVALID_PARAMETER
);
580 if (!thread
) /* process is dead */
582 set_error( STATUS_ACCESS_DENIED
);
585 if (suspend_for_ptrace( thread
))
587 while (len
> 0 && max
)
589 if (read_thread_int( thread
, addr
++, dest
++ ) == -1) goto done
;
593 /* check the rest for read permission */
596 int dummy
, page
= get_page_size() / sizeof(int);
601 if (read_thread_int( thread
, addr
- 1, &dummy
) == -1) goto done
;
603 if (len
&& (read_thread_int( thread
, addr
+ len
- 1, &dummy
) == -1)) goto done
;
606 resume_thread( thread
);
610 /* write data to a process memory space */
611 /* len is the total size (in ints), max is the size we can actually read from the input buffer */
612 /* we check the total size for write permissions */
613 static void write_process_memory( struct process
*process
, int *addr
, size_t len
,
614 size_t max
, unsigned int first_mask
,
615 unsigned int last_mask
, const int *src
)
617 struct thread
*thread
= process
->thread_list
;
619 if (!len
|| ((unsigned int)addr
% sizeof(int))) /* address must be aligned */
621 set_error( STATUS_INVALID_PARAMETER
);
624 if (!thread
) /* process is dead */
626 set_error( STATUS_ACCESS_DENIED
);
629 if (suspend_for_ptrace( thread
))
631 /* first word is special */
634 if (write_thread_int( thread
, addr
++, *src
++, first_mask
) == -1) goto done
;
638 else last_mask
&= first_mask
;
640 while (len
> 1 && max
)
642 if (write_thread_int( thread
, addr
++, *src
++, ~0 ) == -1) goto done
;
649 /* last word is special too */
650 if (write_thread_int( thread
, addr
, *src
, last_mask
) == -1) goto done
;
654 /* check the rest for write permission */
655 int page
= get_page_size() / sizeof(int);
660 if (write_thread_int( thread
, addr
- 1, 0, 0 ) == -1) goto done
;
662 if (len
&& (write_thread_int( thread
, addr
+ len
- 1, 0, 0 ) == -1)) goto done
;
665 resume_thread( thread
);
669 /* take a snapshot of currently running processes */
670 struct process_snapshot
*process_snap( int *count
)
672 struct process_snapshot
*snapshot
, *ptr
;
673 struct process
*process
;
674 if (!running_processes
) return NULL
;
675 if (!(snapshot
= mem_alloc( sizeof(*snapshot
) * running_processes
)))
678 for (process
= first_process
; process
; process
= process
->next
)
680 if (!process
->running_threads
) continue;
681 ptr
->process
= process
;
682 ptr
->threads
= process
->running_threads
;
683 ptr
->count
= process
->obj
.refcount
;
684 ptr
->priority
= process
->priority
;
685 grab_object( process
);
688 *count
= running_processes
;
692 /* take a snapshot of the modules of a process */
693 struct module_snapshot
*module_snap( struct process
*process
, int *count
)
695 struct module_snapshot
*snapshot
, *ptr
;
696 struct process_dll
*dll
;
699 for (dll
= &process
->exe
; dll
; dll
= dll
->next
) total
++;
700 if (!(snapshot
= mem_alloc( sizeof(*snapshot
) * total
))) return NULL
;
702 for (ptr
= snapshot
, dll
= &process
->exe
; dll
; dll
= dll
->next
, ptr
++)
704 ptr
->base
= dll
->base
;
711 /* create a new process */
712 DECL_HANDLER(new_process
)
714 size_t len
= get_req_data_size( req
);
715 struct startup_info
*info
;
719 fatal_protocol_error( current
, "new_process: another process is being created\n" );
723 /* build the startup info for a new process */
724 if (!(info
= alloc_object( &startup_info_ops
, -1 ))) return;
725 info
->inherit_all
= req
->inherit_all
;
726 info
->create_flags
= req
->create_flags
;
727 info
->start_flags
= req
->start_flags
;
728 info
->hstdin
= req
->hstdin
;
729 info
->hstdout
= req
->hstdout
;
730 info
->hstderr
= req
->hstderr
;
731 info
->cmd_show
= req
->cmd_show
;
732 info
->exe_file
= NULL
;
733 info
->filename
= NULL
;
734 info
->process
= NULL
;
738 !(info
->exe_file
= get_file_obj( current
->process
, req
->exe_file
, GENERIC_READ
)))
740 release_object( info
);
744 if (!(info
->filename
= mem_alloc( len
+ 1 )))
746 release_object( info
);
749 memcpy( info
->filename
, get_req_data(req
), len
);
750 info
->filename
[len
] = 0;
751 current
->info
= info
;
754 /* Wait for the new process to start */
755 DECL_HANDLER(wait_process
)
759 fatal_protocol_error( current
, "wait_process: no process is being created\n" );
769 release_object( current
->info
);
770 current
->info
= NULL
;
774 struct timeval timeout
;
775 struct object
*obj
= ¤t
->info
->obj
;
776 gettimeofday( &timeout
, 0 );
777 add_timeout( &timeout
, req
->timeout
);
778 sleep_on( 1, &obj
, SELECT_TIMEOUT
, timeout
.tv_sec
, timeout
.tv_usec
,
779 build_wait_process_reply
);
783 /* initialize a new process */
784 DECL_HANDLER(init_process
)
786 if (!current
->unix_pid
)
788 fatal_protocol_error( current
, "init_process: init_thread not called yet\n" );
791 current
->process
->ldt_copy
= req
->ldt_copy
;
792 init_process( req
->ppid
, req
);
795 /* signal the end of the process initialization */
796 DECL_HANDLER(init_process_done
)
799 struct process
*process
= current
->process
;
800 if (!process
->init_event
)
802 fatal_protocol_error( current
, "init_process_done: no event\n" );
805 process
->exe
.base
= req
->module
;
806 process
->exe
.name
= req
->name
;
808 if (req
->exe_file
&& (file
= get_file_obj( current
->process
, req
->exe_file
, GENERIC_READ
)))
810 if (process
->exe
.file
) release_object( process
->exe
.file
);
811 process
->exe
.file
= file
;
813 generate_startup_debug_events( current
->process
, req
->entry
);
814 set_event( process
->init_event
);
815 release_object( process
->init_event
);
816 process
->init_event
= NULL
;
817 if (req
->gui
) process
->idle_event
= create_event( NULL
, 0, 1, 0 );
818 if (current
->suspend
+ current
->process
->suspend
> 0) stop_thread( current
);
819 req
->debugged
= (current
->process
->debugger
!= 0);
822 /* open a handle to a process */
823 DECL_HANDLER(open_process
)
825 struct process
*process
= get_process_from_id( req
->pid
);
829 req
->handle
= alloc_handle( current
->process
, process
, req
->access
, req
->inherit
);
830 release_object( process
);
834 /* terminate a process */
835 DECL_HANDLER(terminate_process
)
837 struct process
*process
;
839 if ((process
= get_process_from_handle( req
->handle
, PROCESS_TERMINATE
)))
841 req
->self
= (current
->process
== process
);
842 kill_process( process
, current
, req
->exit_code
);
843 release_object( process
);
847 /* fetch information about a process */
848 DECL_HANDLER(get_process_info
)
850 struct process
*process
;
852 if ((process
= get_process_from_handle( req
->handle
, PROCESS_QUERY_INFORMATION
)))
854 get_process_info( process
, req
);
855 release_object( process
);
859 /* set information about a process */
860 DECL_HANDLER(set_process_info
)
862 struct process
*process
;
864 if ((process
= get_process_from_handle( req
->handle
, PROCESS_SET_INFORMATION
)))
866 set_process_info( process
, req
);
867 release_object( process
);
871 /* read data from a process address space */
872 DECL_HANDLER(read_process_memory
)
874 struct process
*process
;
876 if ((process
= get_process_from_handle( req
->handle
, PROCESS_VM_READ
)))
878 size_t maxlen
= get_req_data_size(req
) / sizeof(int);
879 read_process_memory( process
, req
->addr
, req
->len
, maxlen
, get_req_data(req
) );
880 release_object( process
);
884 /* write data to a process address space */
885 DECL_HANDLER(write_process_memory
)
887 struct process
*process
;
889 if ((process
= get_process_from_handle( req
->handle
, PROCESS_VM_WRITE
)))
891 size_t maxlen
= get_req_data_size(req
) / sizeof(int);
892 write_process_memory( process
, req
->addr
, req
->len
, maxlen
,
893 req
->first_mask
, req
->last_mask
, get_req_data(req
) );
894 release_object( process
);
898 /* notify the server that a dll has been loaded */
899 DECL_HANDLER(load_dll
)
901 struct process_dll
*dll
;
902 struct file
*file
= NULL
;
905 !(file
= get_file_obj( current
->process
, req
->handle
, GENERIC_READ
))) return;
907 if ((dll
= process_load_dll( current
->process
, file
, req
->base
)))
909 dll
->dbg_offset
= req
->dbg_offset
;
910 dll
->dbg_size
= req
->dbg_size
;
911 dll
->name
= req
->name
;
912 /* only generate event if initialization is done */
913 if (!current
->process
->init_event
)
914 generate_debug_event( current
, LOAD_DLL_DEBUG_EVENT
, dll
);
916 if (file
) release_object( file
);
919 /* notify the server that a dll is being unloaded */
920 DECL_HANDLER(unload_dll
)
922 process_unload_dll( current
->process
, req
->base
);
925 /* wait for a process to start waiting on input */
926 /* FIXME: only returns event for now, wait is done in the client */
927 DECL_HANDLER(wait_input_idle
)
929 struct process
*process
;
932 if ((process
= get_process_from_handle( req
->handle
, PROCESS_QUERY_INFORMATION
)))
934 if (process
->idle_event
&& process
!= current
->process
&& process
->queue
!= current
->queue
)
935 req
->event
= alloc_handle( current
->process
, process
->idle_event
,
936 EVENT_ALL_ACCESS
, 0 );
937 release_object( process
);