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_read_fd
, /* get_read_fd */
52 no_write_fd
, /* get_write_fd */
54 no_get_file_info
, /* get_file_info */
55 process_destroy
/* destroy */
58 /* process startup info */
62 struct object obj
; /* object header */
63 int inherit_all
; /* inherit all handles from parent */
64 int create_flags
; /* creation flags */
65 int start_flags
; /* flags from startup info */
66 int hstdin
; /* handle for stdin */
67 int hstdout
; /* handle for stdout */
68 int hstderr
; /* handle for stderr */
69 int cmd_show
; /* main window show mode */
70 struct file
*exe_file
; /* file handle for main exe */
71 char *filename
; /* file name for main exe */
72 struct process
*process
; /* created process */
73 struct thread
*thread
; /* created thread */
76 static void startup_info_dump( struct object
*obj
, int verbose
);
77 static int startup_info_signaled( struct object
*obj
, struct thread
*thread
);
78 static void startup_info_destroy( struct object
*obj
);
80 static const struct object_ops startup_info_ops
=
82 sizeof(struct startup_info
), /* size */
83 startup_info_dump
, /* dump */
84 add_queue
, /* add_queue */
85 remove_queue
, /* remove_queue */
86 startup_info_signaled
, /* signaled */
87 no_satisfied
, /* satisfied */
88 NULL
, /* get_poll_events */
89 NULL
, /* poll_event */
90 no_read_fd
, /* get_read_fd */
91 no_write_fd
, /* get_write_fd */
93 no_get_file_info
, /* get_file_info */
94 startup_info_destroy
/* destroy */
98 /* set the console and stdio handles for a newly created process */
99 static int set_process_console( struct process
*process
, struct process
*parent
,
100 struct startup_info
*info
, struct init_process_request
*req
)
102 if (process
->create_flags
& CREATE_NEW_CONSOLE
)
104 if (!alloc_console( process
)) return 0;
106 else if (parent
&& !(process
->create_flags
& DETACHED_PROCESS
))
108 if (parent
->console_in
) process
->console_in
= grab_object( parent
->console_in
);
109 if (parent
->console_out
) process
->console_out
= grab_object( parent
->console_out
);
113 if (!info
->inherit_all
&& !(info
->start_flags
& STARTF_USESTDHANDLES
))
115 /* duplicate the handle from the parent into this process */
116 req
->hstdin
= duplicate_handle( parent
, info
->hstdin
, process
,
117 0, TRUE
, DUPLICATE_SAME_ACCESS
);
118 req
->hstdout
= duplicate_handle( parent
, info
->hstdout
, process
,
119 0, TRUE
, DUPLICATE_SAME_ACCESS
);
120 req
->hstderr
= duplicate_handle( parent
, info
->hstderr
, process
,
121 0, TRUE
, DUPLICATE_SAME_ACCESS
);
125 req
->hstdin
= info
->hstdin
;
126 req
->hstdout
= info
->hstdout
;
127 req
->hstderr
= info
->hstderr
;
132 /* no parent, use handles to the console for stdio */
133 req
->hstdin
= alloc_handle( process
, process
->console_in
,
134 GENERIC_READ
| GENERIC_WRITE
| SYNCHRONIZE
, 1 );
135 req
->hstdout
= alloc_handle( process
, process
->console_out
,
136 GENERIC_READ
| GENERIC_WRITE
| SYNCHRONIZE
, 1 );
137 req
->hstderr
= alloc_handle( process
, process
->console_out
,
138 GENERIC_READ
| GENERIC_WRITE
| SYNCHRONIZE
, 1 );
140 /* some handles above may have been invalid; this is not an error */
141 if (get_error() == STATUS_INVALID_HANDLE
) clear_error();
145 /* create a new process and its main thread */
146 struct thread
*create_process( int fd
)
148 struct process
*process
;
149 struct thread
*thread
= NULL
;
151 if (!(process
= alloc_object( &process_ops
, -1 )))
156 process
->next
= NULL
;
157 process
->prev
= NULL
;
158 process
->thread_list
= NULL
;
159 process
->debugger
= NULL
;
160 process
->handles
= NULL
;
161 process
->exit_code
= STILL_ACTIVE
;
162 process
->running_threads
= 0;
163 process
->priority
= NORMAL_PRIORITY_CLASS
;
164 process
->affinity
= 1;
165 process
->suspend
= 0;
166 process
->create_flags
= 0;
167 process
->console_in
= NULL
;
168 process
->console_out
= NULL
;
169 process
->init_event
= NULL
;
170 process
->idle_event
= NULL
;
171 process
->queue
= NULL
;
172 process
->atom_table
= NULL
;
173 process
->ldt_copy
= NULL
;
174 process
->exe
.next
= NULL
;
175 process
->exe
.prev
= NULL
;
176 process
->exe
.file
= NULL
;
177 process
->exe
.dbg_offset
= 0;
178 process
->exe
.dbg_size
= 0;
179 gettimeofday( &process
->start_time
, NULL
);
180 if ((process
->next
= first_process
) != NULL
) process
->next
->prev
= process
;
181 first_process
= process
;
183 /* create the main thread */
184 if (!(thread
= create_thread( fd
, process
))) goto error
;
186 /* create the init done event */
187 if (!(process
->init_event
= create_event( NULL
, 0, 1, 0 ))) goto error
;
189 add_process_thread( process
, thread
);
190 release_object( process
);
194 if (thread
) release_object( thread
);
195 release_object( process
);
199 /* initialize the current process and fill in the request */
200 static void init_process( int ppid
, struct init_process_request
*req
)
202 struct process
*process
= current
->process
;
203 struct thread
*parent_thread
= get_thread_from_pid( ppid
);
204 struct process
*parent
= NULL
;
205 struct startup_info
*info
= NULL
;
209 parent
= parent_thread
->process
;
210 info
= parent_thread
->info
;
213 fatal_protocol_error( current
, "init_process: parent but no info\n" );
218 fatal_protocol_error( current
, "init_process: called twice?\n" );
223 /* set the process flags */
224 process
->create_flags
= info
? info
->create_flags
: CREATE_NEW_CONSOLE
;
226 /* create the handle table */
227 if (parent
&& info
->inherit_all
== 2) /* HACK! */
228 process
->handles
= grab_object( parent
->handles
);
229 else if (parent
&& info
->inherit_all
)
230 process
->handles
= copy_handle_table( process
, parent
);
232 process
->handles
= alloc_handle_table( process
, 0 );
233 if (!process
->handles
) goto error
;
235 /* retrieve the main exe file */
237 if (parent
&& info
->exe_file
)
239 process
->exe
.file
= (struct file
*)grab_object( info
->exe_file
);
240 if ((req
->exe_file
= alloc_handle( process
, process
->exe
.file
, GENERIC_READ
, 0 )) == -1)
244 /* set the process console */
245 if (!set_process_console( process
, parent
, info
, req
)) goto error
;
249 /* attach to the debugger if requested */
250 if (process
->create_flags
& (DEBUG_PROCESS
| DEBUG_ONLY_THIS_PROCESS
))
251 set_process_debugger( process
, parent_thread
);
252 else if (parent
&& parent
->debugger
&& !(parent
->create_flags
& DEBUG_ONLY_THIS_PROCESS
))
253 set_process_debugger( process
, parent
->debugger
);
256 /* thread will be actually suspended in init_done */
257 if (process
->create_flags
& CREATE_SUSPENDED
) current
->suspend
++;
261 size_t size
= strlen(info
->filename
);
262 if (size
> get_req_data_size(req
)) size
= get_req_data_size(req
);
263 req
->start_flags
= info
->start_flags
;
264 req
->cmd_show
= info
->cmd_show
;
265 memcpy( get_req_data(req
), info
->filename
, size
);
266 set_req_data_size( req
, size
);
267 info
->process
= (struct process
*)grab_object( process
);
268 info
->thread
= (struct thread
*)grab_object( current
);
269 wake_up( &info
->obj
, 0 );
273 req
->start_flags
= STARTF_USESTDHANDLES
;
275 set_req_data_size( req
, 0 );
277 req
->server_start
= server_start_ticks
;
281 /* destroy a process when its refcount is 0 */
282 static void process_destroy( struct object
*obj
)
284 struct process
*process
= (struct process
*)obj
;
285 assert( obj
->ops
== &process_ops
);
287 /* we can't have a thread remaining */
288 assert( !process
->thread_list
);
289 if (process
->next
) process
->next
->prev
= process
->prev
;
290 if (process
->prev
) process
->prev
->next
= process
->next
;
291 else first_process
= process
->next
;
292 if (process
->init_event
) release_object( process
->init_event
);
293 if (process
->idle_event
) release_object( process
->idle_event
);
294 if (process
->queue
) release_object( process
->queue
);
295 if (process
->atom_table
) release_object( process
->atom_table
);
296 if (process
->exe
.file
) release_object( process
->exe
.file
);
299 /* dump a process on stdout for debugging purposes */
300 static void process_dump( struct object
*obj
, int verbose
)
302 struct process
*process
= (struct process
*)obj
;
303 assert( obj
->ops
== &process_ops
);
305 fprintf( stderr
, "Process next=%p prev=%p console=%p/%p handles=%p\n",
306 process
->next
, process
->prev
, process
->console_in
, process
->console_out
,
310 static int process_signaled( struct object
*obj
, struct thread
*thread
)
312 struct process
*process
= (struct process
*)obj
;
313 return !process
->running_threads
;
317 static void startup_info_destroy( struct object
*obj
)
319 struct startup_info
*info
= (struct startup_info
*)obj
;
320 assert( obj
->ops
== &startup_info_ops
);
321 if (info
->filename
) free( info
->filename
);
322 if (info
->exe_file
) release_object( info
->exe_file
);
323 if (info
->process
) release_object( info
->process
);
324 if (info
->thread
) release_object( info
->thread
);
327 static void startup_info_dump( struct object
*obj
, int verbose
)
329 struct startup_info
*info
= (struct startup_info
*)obj
;
330 assert( obj
->ops
== &startup_info_ops
);
332 fprintf( stderr
, "Startup info flags=%x in=%d out=%d err=%d name='%s'\n",
333 info
->start_flags
, info
->hstdin
, info
->hstdout
, info
->hstderr
, info
->filename
);
336 static int startup_info_signaled( struct object
*obj
, struct thread
*thread
)
338 struct startup_info
*info
= (struct startup_info
*)obj
;
339 return (info
->thread
!= NULL
);
343 /* build a reply for the wait_process request */
344 static void build_wait_process_reply( struct thread
*thread
, struct object
*obj
, int signaled
)
346 struct wait_process_request
*req
= get_req_ptr( thread
);
349 struct startup_info
*info
= (struct startup_info
*)obj
;
350 assert( obj
->ops
== &startup_info_ops
);
352 req
->pid
= get_process_id( info
->process
);
353 req
->tid
= get_thread_id( info
->thread
);
354 req
->phandle
= alloc_handle( thread
->process
, info
->process
,
355 PROCESS_ALL_ACCESS
, req
->pinherit
);
356 req
->thandle
= alloc_handle( thread
->process
, info
->thread
,
357 THREAD_ALL_ACCESS
, req
->tinherit
);
358 if (info
->process
->init_event
)
359 req
->event
= alloc_handle( thread
->process
, info
->process
->init_event
,
360 EVENT_ALL_ACCESS
, 0 );
364 /* FIXME: set_error */
366 release_object( thread
->info
);
370 /* get a process from an id (and increment the refcount) */
371 struct process
*get_process_from_id( void *id
)
373 struct process
*p
= first_process
;
374 while (p
&& (p
!= id
)) p
= p
->next
;
375 if (p
) grab_object( p
);
376 else set_error( STATUS_INVALID_PARAMETER
);
380 /* get a process from a handle (and increment the refcount) */
381 struct process
*get_process_from_handle( int handle
, unsigned int access
)
383 return (struct process
*)get_handle_obj( current
->process
, handle
,
384 access
, &process_ops
);
387 /* add a dll to a process list */
388 static struct process_dll
*process_load_dll( struct process
*process
, struct file
*file
,
391 struct process_dll
*dll
;
393 /* make sure we don't already have one with the same base address */
394 for (dll
= process
->exe
.next
; dll
; dll
= dll
->next
) if (dll
->base
== base
)
396 set_error( STATUS_INVALID_PARAMETER
);
400 if ((dll
= mem_alloc( sizeof(*dll
) )))
402 dll
->prev
= &process
->exe
;
405 if (file
) dll
->file
= (struct file
*)grab_object( file
);
406 if ((dll
->next
= process
->exe
.next
)) dll
->next
->prev
= dll
;
407 process
->exe
.next
= dll
;
412 /* remove a dll from a process list */
413 static void process_unload_dll( struct process
*process
, void *base
)
415 struct process_dll
*dll
;
417 for (dll
= process
->exe
.next
; dll
; dll
= dll
->next
)
419 if (dll
->base
== base
)
421 if (dll
->file
) release_object( dll
->file
);
422 if (dll
->next
) dll
->next
->prev
= dll
->prev
;
423 if (dll
->prev
) dll
->prev
->next
= dll
->next
;
425 generate_debug_event( current
, UNLOAD_DLL_DEBUG_EVENT
, base
);
429 set_error( STATUS_INVALID_PARAMETER
);
432 /* a process has been killed (i.e. its last thread died) */
433 static void process_killed( struct process
*process
)
435 assert( !process
->thread_list
);
436 gettimeofday( &process
->end_time
, NULL
);
437 if (process
->handles
) release_object( process
->handles
);
438 process
->handles
= NULL
;
439 free_console( process
);
440 while (process
->exe
.next
)
442 struct process_dll
*dll
= process
->exe
.next
;
443 process
->exe
.next
= dll
->next
;
444 if (dll
->file
) release_object( dll
->file
);
447 if (process
->exe
.file
) release_object( process
->exe
.file
);
448 process
->exe
.file
= NULL
;
449 wake_up( &process
->obj
, 0 );
450 if (!--running_processes
)
452 /* last process died, close global handles */
453 close_global_handles();
454 /* this will cause the select loop to terminate */
455 if (!persistent_server
) close_master_socket();
459 /* add a thread to a process running threads list */
460 void add_process_thread( struct process
*process
, struct thread
*thread
)
462 thread
->proc_next
= process
->thread_list
;
463 thread
->proc_prev
= NULL
;
464 if (thread
->proc_next
) thread
->proc_next
->proc_prev
= thread
;
465 process
->thread_list
= thread
;
466 if (!process
->running_threads
++) running_processes
++;
467 grab_object( thread
);
470 /* remove a thread from a process running threads list */
471 void remove_process_thread( struct process
*process
, struct thread
*thread
)
473 assert( process
->running_threads
> 0 );
474 assert( process
->thread_list
);
476 if (thread
->proc_next
) thread
->proc_next
->proc_prev
= thread
->proc_prev
;
477 if (thread
->proc_prev
) thread
->proc_prev
->proc_next
= thread
->proc_next
;
478 else process
->thread_list
= thread
->proc_next
;
480 if (!--process
->running_threads
)
482 /* we have removed the last running thread, exit the process */
483 process
->exit_code
= thread
->exit_code
;
484 generate_debug_event( thread
, EXIT_PROCESS_DEBUG_EVENT
, process
);
485 process_killed( process
);
487 else generate_debug_event( thread
, EXIT_THREAD_DEBUG_EVENT
, thread
);
488 release_object( thread
);
491 /* suspend all the threads of a process */
492 void suspend_process( struct process
*process
)
494 if (!process
->suspend
++)
496 struct thread
*thread
= process
->thread_list
;
497 for (; thread
; thread
= thread
->proc_next
)
499 if (!thread
->suspend
) stop_thread( thread
);
504 /* resume all the threads of a process */
505 void resume_process( struct process
*process
)
507 assert (process
->suspend
> 0);
508 if (!--process
->suspend
)
510 struct thread
*thread
= process
->thread_list
;
511 for (; thread
; thread
= thread
->proc_next
)
513 if (!thread
->suspend
) continue_thread( thread
);
518 /* kill a process on the spot */
519 static void kill_process( struct process
*process
, struct thread
*skip
, int exit_code
)
521 struct thread
*thread
= process
->thread_list
;
524 struct thread
*next
= thread
->proc_next
;
525 thread
->exit_code
= exit_code
;
526 if (thread
!= skip
) kill_thread( thread
, 1 );
531 /* kill all processes being debugged by a given thread */
532 void kill_debugged_processes( struct thread
*debugger
, int exit_code
)
534 for (;;) /* restart from the beginning of the list every time */
536 struct process
*process
= first_process
;
537 /* find the first process being debugged by 'debugger' and still running */
538 while (process
&& (process
->debugger
!= debugger
|| !process
->running_threads
))
539 process
= process
->next
;
540 if (!process
) return;
541 process
->debugger
= NULL
;
542 kill_process( process
, NULL
, exit_code
);
546 /* get all information about a process */
547 static void get_process_info( struct process
*process
, struct get_process_info_request
*req
)
550 req
->debugged
= (process
->debugger
!= 0);
551 req
->exit_code
= process
->exit_code
;
552 req
->priority
= process
->priority
;
553 req
->process_affinity
= process
->affinity
;
554 req
->system_affinity
= 1;
557 /* set all information about a process */
558 static void set_process_info( struct process
*process
,
559 struct set_process_info_request
*req
)
561 if (req
->mask
& SET_PROCESS_INFO_PRIORITY
)
562 process
->priority
= req
->priority
;
563 if (req
->mask
& SET_PROCESS_INFO_AFFINITY
)
565 if (req
->affinity
!= 1) set_error( STATUS_INVALID_PARAMETER
);
566 else process
->affinity
= req
->affinity
;
570 /* read data from a process memory space */
571 /* len is the total size (in ints), max is the size we can actually store in the output buffer */
572 /* we read the total size in all cases to check for permissions */
573 static void read_process_memory( struct process
*process
, const int *addr
,
574 size_t len
, size_t max
, int *dest
)
576 struct thread
*thread
= process
->thread_list
;
578 if ((unsigned int)addr
% sizeof(int)) /* address must be aligned */
580 set_error( STATUS_INVALID_PARAMETER
);
583 if (!thread
) /* process is dead */
585 set_error( STATUS_ACCESS_DENIED
);
588 if (suspend_for_ptrace( thread
))
590 while (len
> 0 && max
)
592 if (read_thread_int( thread
, addr
++, dest
++ ) == -1) goto done
;
596 /* check the rest for read permission */
599 int dummy
, page
= get_page_size() / sizeof(int);
604 if (read_thread_int( thread
, addr
- 1, &dummy
) == -1) goto done
;
606 if (len
&& (read_thread_int( thread
, addr
+ len
- 1, &dummy
) == -1)) goto done
;
609 resume_thread( thread
);
613 /* write data to a process memory space */
614 /* len is the total size (in ints), max is the size we can actually read from the input buffer */
615 /* we check the total size for write permissions */
616 static void write_process_memory( struct process
*process
, int *addr
, size_t len
,
617 size_t max
, unsigned int first_mask
,
618 unsigned int last_mask
, const int *src
)
620 struct thread
*thread
= process
->thread_list
;
622 if (!len
|| ((unsigned int)addr
% sizeof(int))) /* address must be aligned */
624 set_error( STATUS_INVALID_PARAMETER
);
627 if (!thread
) /* process is dead */
629 set_error( STATUS_ACCESS_DENIED
);
632 if (suspend_for_ptrace( thread
))
634 /* first word is special */
637 if (write_thread_int( thread
, addr
++, *src
++, first_mask
) == -1) goto done
;
641 else last_mask
&= first_mask
;
643 while (len
> 1 && max
)
645 if (write_thread_int( thread
, addr
++, *src
++, ~0 ) == -1) goto done
;
652 /* last word is special too */
653 if (write_thread_int( thread
, addr
, *src
, last_mask
) == -1) goto done
;
657 /* check the rest for write permission */
658 int page
= get_page_size() / sizeof(int);
663 if (write_thread_int( thread
, addr
- 1, 0, 0 ) == -1) goto done
;
665 if (len
&& (write_thread_int( thread
, addr
+ len
- 1, 0, 0 ) == -1)) goto done
;
668 resume_thread( thread
);
672 /* take a snapshot of currently running processes */
673 struct process_snapshot
*process_snap( int *count
)
675 struct process_snapshot
*snapshot
, *ptr
;
676 struct process
*process
;
677 if (!running_processes
) return NULL
;
678 if (!(snapshot
= mem_alloc( sizeof(*snapshot
) * running_processes
)))
681 for (process
= first_process
; process
; process
= process
->next
)
683 if (!process
->running_threads
) continue;
684 ptr
->process
= process
;
685 ptr
->threads
= process
->running_threads
;
686 ptr
->count
= process
->obj
.refcount
;
687 ptr
->priority
= process
->priority
;
688 grab_object( process
);
691 *count
= running_processes
;
695 /* take a snapshot of the modules of a process */
696 struct module_snapshot
*module_snap( struct process
*process
, int *count
)
698 struct module_snapshot
*snapshot
, *ptr
;
699 struct process_dll
*dll
;
702 for (dll
= &process
->exe
; dll
; dll
= dll
->next
) total
++;
703 if (!(snapshot
= mem_alloc( sizeof(*snapshot
) * total
))) return NULL
;
705 for (ptr
= snapshot
, dll
= &process
->exe
; dll
; dll
= dll
->next
, ptr
++)
707 ptr
->base
= dll
->base
;
714 /* create a new process */
715 DECL_HANDLER(new_process
)
717 size_t len
= get_req_data_size( req
);
718 struct startup_info
*info
;
723 fatal_protocol_error( current
, "new_process: another process is being created\n" );
727 /* build the startup info for a new process */
728 if (!(info
= alloc_object( &startup_info_ops
, -1 ))) return;
729 info
->inherit_all
= req
->inherit_all
;
730 info
->create_flags
= req
->create_flags
;
731 info
->start_flags
= req
->start_flags
;
732 info
->hstdin
= req
->hstdin
;
733 info
->hstdout
= req
->hstdout
;
734 info
->hstderr
= req
->hstderr
;
735 info
->cmd_show
= req
->cmd_show
;
736 info
->exe_file
= NULL
;
737 info
->filename
= NULL
;
738 info
->process
= NULL
;
741 if ((req
->exe_file
!= -1) &&
742 !(info
->exe_file
= get_file_obj( current
->process
, req
->exe_file
, GENERIC_READ
)))
744 release_object( info
);
748 if (!(info
->filename
= mem_alloc( len
+ 1 )))
750 release_object( info
);
753 memcpy( info
->filename
, get_req_data(req
), len
);
754 info
->filename
[len
] = 0;
758 if (socketpair( AF_UNIX
, SOCK_STREAM
, 0, sock
) == -1)
761 release_object( info
);
764 if (!create_process( sock
[0] ))
766 release_object( info
);
770 /* thread object will be released when the thread gets killed */
771 set_reply_fd( current
, sock
[1] );
773 current
->info
= info
;
776 /* Wait for the new process to start */
777 DECL_HANDLER(wait_process
)
781 fatal_protocol_error( current
, "wait_process: no process is being created\n" );
791 release_object( current
->info
);
792 current
->info
= NULL
;
796 struct object
*obj
= ¤t
->info
->obj
;
797 sleep_on( 1, &obj
, SELECT_TIMEOUT
, req
->timeout
, build_wait_process_reply
);
801 /* initialize a new process */
802 DECL_HANDLER(init_process
)
804 if (!current
->unix_pid
)
806 fatal_protocol_error( current
, "init_process: init_thread not called yet\n" );
809 current
->process
->ldt_copy
= req
->ldt_copy
;
810 init_process( req
->ppid
, req
);
813 /* signal the end of the process initialization */
814 DECL_HANDLER(init_process_done
)
816 struct process
*process
= current
->process
;
817 if (!process
->init_event
)
819 fatal_protocol_error( current
, "init_process_done: no event\n" );
822 process
->exe
.base
= req
->module
;
823 process
->exe
.name
= req
->name
;
824 generate_startup_debug_events( current
->process
, req
->entry
);
825 set_event( process
->init_event
);
826 release_object( process
->init_event
);
827 process
->init_event
= NULL
;
828 if (req
->gui
) process
->idle_event
= create_event( NULL
, 0, 1, 0 );
829 if (current
->suspend
+ current
->process
->suspend
> 0) stop_thread( current
);
830 req
->debugged
= (current
->process
->debugger
!= 0);
833 /* open a handle to a process */
834 DECL_HANDLER(open_process
)
836 struct process
*process
= get_process_from_id( req
->pid
);
840 req
->handle
= alloc_handle( current
->process
, process
, req
->access
, req
->inherit
);
841 release_object( process
);
845 /* terminate a process */
846 DECL_HANDLER(terminate_process
)
848 struct process
*process
;
850 if ((process
= get_process_from_handle( req
->handle
, PROCESS_TERMINATE
)))
852 req
->self
= (current
->process
== process
);
853 kill_process( process
, current
, req
->exit_code
);
854 release_object( process
);
858 /* fetch information about a process */
859 DECL_HANDLER(get_process_info
)
861 struct process
*process
;
863 if ((process
= get_process_from_handle( req
->handle
, PROCESS_QUERY_INFORMATION
)))
865 get_process_info( process
, req
);
866 release_object( process
);
870 /* set information about a process */
871 DECL_HANDLER(set_process_info
)
873 struct process
*process
;
875 if ((process
= get_process_from_handle( req
->handle
, PROCESS_SET_INFORMATION
)))
877 set_process_info( process
, req
);
878 release_object( process
);
882 /* read data from a process address space */
883 DECL_HANDLER(read_process_memory
)
885 struct process
*process
;
887 if ((process
= get_process_from_handle( req
->handle
, PROCESS_VM_READ
)))
889 size_t maxlen
= get_req_data_size(req
) / sizeof(int);
890 read_process_memory( process
, req
->addr
, req
->len
, maxlen
, get_req_data(req
) );
891 release_object( process
);
895 /* write data to a process address space */
896 DECL_HANDLER(write_process_memory
)
898 struct process
*process
;
900 if ((process
= get_process_from_handle( req
->handle
, PROCESS_VM_WRITE
)))
902 size_t maxlen
= get_req_data_size(req
) / sizeof(int);
903 write_process_memory( process
, req
->addr
, req
->len
, maxlen
,
904 req
->first_mask
, req
->last_mask
, get_req_data(req
) );
905 release_object( process
);
909 /* notify the server that a dll has been loaded */
910 DECL_HANDLER(load_dll
)
912 struct process_dll
*dll
;
913 struct file
*file
= NULL
;
915 if ((req
->handle
!= -1) &&
916 !(file
= get_file_obj( current
->process
, req
->handle
, GENERIC_READ
))) return;
918 if ((dll
= process_load_dll( current
->process
, file
, req
->base
)))
920 dll
->dbg_offset
= req
->dbg_offset
;
921 dll
->dbg_size
= req
->dbg_size
;
922 dll
->name
= req
->name
;
923 /* only generate event if initialization is done */
924 if (!current
->process
->init_event
)
925 generate_debug_event( current
, LOAD_DLL_DEBUG_EVENT
, dll
);
927 if (file
) release_object( file
);
930 /* notify the server that a dll is being unloaded */
931 DECL_HANDLER(unload_dll
)
933 process_unload_dll( current
->process
, req
->base
);
936 /* wait for a process to start waiting on input */
937 /* FIXME: only returns event for now, wait is done in the client */
938 DECL_HANDLER(wait_input_idle
)
940 struct process
*process
;
943 if ((process
= get_process_from_handle( req
->handle
, PROCESS_QUERY_INFORMATION
)))
945 if (process
->idle_event
&& process
!= current
->process
&& process
->queue
!= current
->queue
)
946 req
->event
= alloc_handle( current
->process
, process
->idle_event
,
947 EVENT_ALL_ACCESS
, 0 );
948 release_object( process
);