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
->ldt_flags
= NULL
;
175 process
->exe
.next
= NULL
;
176 process
->exe
.prev
= NULL
;
177 process
->exe
.file
= NULL
;
178 process
->exe
.dbg_offset
= 0;
179 process
->exe
.dbg_size
= 0;
180 gettimeofday( &process
->start_time
, NULL
);
181 if ((process
->next
= first_process
) != NULL
) process
->next
->prev
= process
;
182 first_process
= process
;
184 /* create the main thread */
185 if (!(thread
= create_thread( fd
, process
))) goto error
;
187 /* create the init done event */
188 if (!(process
->init_event
= create_event( NULL
, 0, 1, 0 ))) goto error
;
190 add_process_thread( process
, thread
);
191 release_object( process
);
195 if (thread
) release_object( thread
);
196 release_object( process
);
200 /* initialize the current process and fill in the request */
201 static void init_process( int ppid
, struct init_process_request
*req
)
203 struct process
*process
= current
->process
;
204 struct thread
*parent_thread
= get_thread_from_pid( ppid
);
205 struct process
*parent
= NULL
;
206 struct startup_info
*info
= NULL
;
210 parent
= parent_thread
->process
;
211 info
= parent_thread
->info
;
214 fatal_protocol_error( current
, "init_process: parent but no info\n" );
219 fatal_protocol_error( current
, "init_process: called twice?\n" );
224 /* set the process flags */
225 process
->create_flags
= info
? info
->create_flags
: CREATE_NEW_CONSOLE
;
227 /* create the handle table */
228 if (parent
&& info
->inherit_all
== 2) /* HACK! */
229 process
->handles
= grab_object( parent
->handles
);
230 else if (parent
&& info
->inherit_all
)
231 process
->handles
= copy_handle_table( process
, parent
);
233 process
->handles
= alloc_handle_table( process
, 0 );
234 if (!process
->handles
) goto error
;
236 /* retrieve the main exe file */
238 if (parent
&& info
->exe_file
)
240 process
->exe
.file
= (struct file
*)grab_object( info
->exe_file
);
241 if ((req
->exe_file
= alloc_handle( process
, process
->exe
.file
, GENERIC_READ
, 0 )) == -1)
245 /* set the process console */
246 if (!set_process_console( process
, parent
, info
, req
)) goto error
;
250 /* attach to the debugger if requested */
251 if (process
->create_flags
& (DEBUG_PROCESS
| DEBUG_ONLY_THIS_PROCESS
))
252 set_process_debugger( process
, parent_thread
);
253 else if (parent
&& parent
->debugger
&& !(parent
->create_flags
& DEBUG_ONLY_THIS_PROCESS
))
254 set_process_debugger( process
, parent
->debugger
);
257 /* thread will be actually suspended in init_done */
258 if (process
->create_flags
& CREATE_SUSPENDED
) current
->suspend
++;
262 req
->start_flags
= info
->start_flags
;
263 req
->cmd_show
= info
->cmd_show
;
264 strcpy( req
->filename
, info
->filename
);
265 info
->process
= (struct process
*)grab_object( process
);
266 info
->thread
= (struct thread
*)grab_object( current
);
267 wake_up( &info
->obj
, 0 );
271 req
->start_flags
= STARTF_USESTDHANDLES
;
273 req
->filename
[0] = 0;
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( int 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_strlen( req
, req
->filename
);
715 struct startup_info
*info
;
720 fatal_protocol_error( current
, "new_process: another process is being created\n" );
724 /* build the startup info for a new process */
725 if (!(info
= alloc_object( &startup_info_ops
, -1 ))) return;
726 info
->inherit_all
= req
->inherit_all
;
727 info
->create_flags
= req
->create_flags
;
728 info
->start_flags
= req
->start_flags
;
729 info
->hstdin
= req
->hstdin
;
730 info
->hstdout
= req
->hstdout
;
731 info
->hstderr
= req
->hstderr
;
732 info
->cmd_show
= req
->cmd_show
;
733 info
->exe_file
= NULL
;
734 info
->filename
= NULL
;
735 info
->process
= NULL
;
738 if ((req
->exe_file
!= -1) &&
739 !(info
->exe_file
= get_file_obj( current
->process
, req
->exe_file
, GENERIC_READ
)))
741 release_object( info
);
745 if (!(info
->filename
= memdup( req
->filename
, len
+1 )))
747 release_object( info
);
750 info
->filename
[len
] = 0;
754 if (socketpair( AF_UNIX
, SOCK_STREAM
, 0, sock
) == -1)
757 release_object( info
);
760 if (!create_process( sock
[0] ))
762 release_object( info
);
766 /* thread object will be released when the thread gets killed */
767 set_reply_fd( current
, sock
[1] );
769 current
->info
= info
;
772 /* Wait for the new process to start */
773 DECL_HANDLER(wait_process
)
777 fatal_protocol_error( current
, "wait_process: no process is being created\n" );
787 release_object( current
->info
);
788 current
->info
= NULL
;
792 struct object
*obj
= ¤t
->info
->obj
;
793 sleep_on( 1, &obj
, SELECT_TIMEOUT
, req
->timeout
, build_wait_process_reply
);
797 /* initialize a new process */
798 DECL_HANDLER(init_process
)
800 if (!current
->unix_pid
)
802 fatal_protocol_error( current
, "init_process: init_thread not called yet\n" );
805 current
->process
->ldt_copy
= req
->ldt_copy
;
806 current
->process
->ldt_flags
= req
->ldt_flags
;
807 init_process( req
->ppid
, req
);
810 /* signal the end of the process initialization */
811 DECL_HANDLER(init_process_done
)
813 struct process
*process
= current
->process
;
814 if (!process
->init_event
)
816 fatal_protocol_error( current
, "init_process_done: no event\n" );
819 process
->exe
.base
= req
->module
;
820 process
->exe
.name
= req
->name
;
821 generate_startup_debug_events( current
->process
, req
->entry
);
822 set_event( process
->init_event
);
823 release_object( process
->init_event
);
824 process
->init_event
= NULL
;
825 if (req
->gui
) process
->idle_event
= create_event( NULL
, 0, 1, 0 );
826 if (current
->suspend
+ current
->process
->suspend
> 0) stop_thread( current
);
827 req
->debugged
= (current
->process
->debugger
!= 0);
830 /* open a handle to a process */
831 DECL_HANDLER(open_process
)
833 struct process
*process
= get_process_from_id( req
->pid
);
837 req
->handle
= alloc_handle( current
->process
, process
, req
->access
, req
->inherit
);
838 release_object( process
);
842 /* terminate a process */
843 DECL_HANDLER(terminate_process
)
845 struct process
*process
;
847 if ((process
= get_process_from_handle( req
->handle
, PROCESS_TERMINATE
)))
849 req
->self
= (current
->process
== process
);
850 kill_process( process
, current
, req
->exit_code
);
851 release_object( process
);
855 /* fetch information about a process */
856 DECL_HANDLER(get_process_info
)
858 struct process
*process
;
860 if ((process
= get_process_from_handle( req
->handle
, PROCESS_QUERY_INFORMATION
)))
862 get_process_info( process
, req
);
863 release_object( process
);
867 /* set information about a process */
868 DECL_HANDLER(set_process_info
)
870 struct process
*process
;
872 if ((process
= get_process_from_handle( req
->handle
, PROCESS_SET_INFORMATION
)))
874 set_process_info( process
, req
);
875 release_object( process
);
879 /* read data from a process address space */
880 DECL_HANDLER(read_process_memory
)
882 struct process
*process
;
884 if ((process
= get_process_from_handle( req
->handle
, PROCESS_VM_READ
)))
886 read_process_memory( process
, req
->addr
, req
->len
,
887 get_req_size( req
, req
->data
, sizeof(int) ), req
->data
);
888 release_object( process
);
892 /* write data to a process address space */
893 DECL_HANDLER(write_process_memory
)
895 struct process
*process
;
897 if ((process
= get_process_from_handle( req
->handle
, PROCESS_VM_WRITE
)))
899 write_process_memory( process
, req
->addr
, req
->len
,
900 get_req_size( req
, req
->data
, sizeof(int) ),
901 req
->first_mask
, req
->last_mask
, req
->data
);
902 release_object( process
);
906 /* notify the server that a dll has been loaded */
907 DECL_HANDLER(load_dll
)
909 struct process_dll
*dll
;
910 struct file
*file
= NULL
;
912 if ((req
->handle
!= -1) &&
913 !(file
= get_file_obj( current
->process
, req
->handle
, GENERIC_READ
))) return;
915 if ((dll
= process_load_dll( current
->process
, file
, req
->base
)))
917 dll
->dbg_offset
= req
->dbg_offset
;
918 dll
->dbg_size
= req
->dbg_size
;
919 dll
->name
= req
->name
;
920 /* only generate event if initialization is done */
921 if (!current
->process
->init_event
)
922 generate_debug_event( current
, LOAD_DLL_DEBUG_EVENT
, dll
);
924 if (file
) release_object( file
);
927 /* notify the server that a dll is being unloaded */
928 DECL_HANDLER(unload_dll
)
930 process_unload_dll( current
->process
, req
->base
);
933 /* wait for a process to start waiting on input */
934 /* FIXME: only returns event for now, wait is done in the client */
935 DECL_HANDLER(wait_input_idle
)
937 struct process
*process
;
940 if ((process
= get_process_from_handle( req
->handle
, PROCESS_QUERY_INFORMATION
)))
942 if (process
->idle_event
&& process
!= current
->process
&& process
->queue
!= current
->queue
)
943 req
->event
= alloc_handle( current
->process
, process
->idle_event
,
944 EVENT_ALL_ACCESS
, 0 );
945 release_object( process
);