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 size_t size
= strlen(info
->filename
);
263 if (size
> get_req_data_size(req
)) size
= get_req_data_size(req
);
264 req
->start_flags
= info
->start_flags
;
265 req
->cmd_show
= info
->cmd_show
;
266 memcpy( get_req_data(req
), info
->filename
, size
);
267 set_req_data_size( req
, size
);
268 info
->process
= (struct process
*)grab_object( process
);
269 info
->thread
= (struct thread
*)grab_object( current
);
270 wake_up( &info
->obj
, 0 );
274 req
->start_flags
= STARTF_USESTDHANDLES
;
276 set_req_data_size( req
, 0 );
278 req
->server_start
= server_start_ticks
;
282 /* destroy a process when its refcount is 0 */
283 static void process_destroy( struct object
*obj
)
285 struct process
*process
= (struct process
*)obj
;
286 assert( obj
->ops
== &process_ops
);
288 /* we can't have a thread remaining */
289 assert( !process
->thread_list
);
290 if (process
->next
) process
->next
->prev
= process
->prev
;
291 if (process
->prev
) process
->prev
->next
= process
->next
;
292 else first_process
= process
->next
;
293 if (process
->init_event
) release_object( process
->init_event
);
294 if (process
->idle_event
) release_object( process
->idle_event
);
295 if (process
->queue
) release_object( process
->queue
);
296 if (process
->atom_table
) release_object( process
->atom_table
);
297 if (process
->exe
.file
) release_object( process
->exe
.file
);
300 /* dump a process on stdout for debugging purposes */
301 static void process_dump( struct object
*obj
, int verbose
)
303 struct process
*process
= (struct process
*)obj
;
304 assert( obj
->ops
== &process_ops
);
306 fprintf( stderr
, "Process next=%p prev=%p console=%p/%p handles=%p\n",
307 process
->next
, process
->prev
, process
->console_in
, process
->console_out
,
311 static int process_signaled( struct object
*obj
, struct thread
*thread
)
313 struct process
*process
= (struct process
*)obj
;
314 return !process
->running_threads
;
318 static void startup_info_destroy( struct object
*obj
)
320 struct startup_info
*info
= (struct startup_info
*)obj
;
321 assert( obj
->ops
== &startup_info_ops
);
322 if (info
->filename
) free( info
->filename
);
323 if (info
->exe_file
) release_object( info
->exe_file
);
324 if (info
->process
) release_object( info
->process
);
325 if (info
->thread
) release_object( info
->thread
);
328 static void startup_info_dump( struct object
*obj
, int verbose
)
330 struct startup_info
*info
= (struct startup_info
*)obj
;
331 assert( obj
->ops
== &startup_info_ops
);
333 fprintf( stderr
, "Startup info flags=%x in=%d out=%d err=%d name='%s'\n",
334 info
->start_flags
, info
->hstdin
, info
->hstdout
, info
->hstderr
, info
->filename
);
337 static int startup_info_signaled( struct object
*obj
, struct thread
*thread
)
339 struct startup_info
*info
= (struct startup_info
*)obj
;
340 return (info
->thread
!= NULL
);
344 /* build a reply for the wait_process request */
345 static void build_wait_process_reply( struct thread
*thread
, struct object
*obj
, int signaled
)
347 struct wait_process_request
*req
= get_req_ptr( thread
);
350 struct startup_info
*info
= (struct startup_info
*)obj
;
351 assert( obj
->ops
== &startup_info_ops
);
353 req
->pid
= get_process_id( info
->process
);
354 req
->tid
= get_thread_id( info
->thread
);
355 req
->phandle
= alloc_handle( thread
->process
, info
->process
,
356 PROCESS_ALL_ACCESS
, req
->pinherit
);
357 req
->thandle
= alloc_handle( thread
->process
, info
->thread
,
358 THREAD_ALL_ACCESS
, req
->tinherit
);
359 if (info
->process
->init_event
)
360 req
->event
= alloc_handle( thread
->process
, info
->process
->init_event
,
361 EVENT_ALL_ACCESS
, 0 );
365 /* FIXME: set_error */
367 release_object( thread
->info
);
371 /* get a process from an id (and increment the refcount) */
372 struct process
*get_process_from_id( void *id
)
374 struct process
*p
= first_process
;
375 while (p
&& (p
!= id
)) p
= p
->next
;
376 if (p
) grab_object( p
);
377 else set_error( STATUS_INVALID_PARAMETER
);
381 /* get a process from a handle (and increment the refcount) */
382 struct process
*get_process_from_handle( int handle
, unsigned int access
)
384 return (struct process
*)get_handle_obj( current
->process
, handle
,
385 access
, &process_ops
);
388 /* add a dll to a process list */
389 static struct process_dll
*process_load_dll( struct process
*process
, struct file
*file
,
392 struct process_dll
*dll
;
394 /* make sure we don't already have one with the same base address */
395 for (dll
= process
->exe
.next
; dll
; dll
= dll
->next
) if (dll
->base
== base
)
397 set_error( STATUS_INVALID_PARAMETER
);
401 if ((dll
= mem_alloc( sizeof(*dll
) )))
403 dll
->prev
= &process
->exe
;
406 if (file
) dll
->file
= (struct file
*)grab_object( file
);
407 if ((dll
->next
= process
->exe
.next
)) dll
->next
->prev
= dll
;
408 process
->exe
.next
= dll
;
413 /* remove a dll from a process list */
414 static void process_unload_dll( struct process
*process
, void *base
)
416 struct process_dll
*dll
;
418 for (dll
= process
->exe
.next
; dll
; dll
= dll
->next
)
420 if (dll
->base
== base
)
422 if (dll
->file
) release_object( dll
->file
);
423 if (dll
->next
) dll
->next
->prev
= dll
->prev
;
424 if (dll
->prev
) dll
->prev
->next
= dll
->next
;
426 generate_debug_event( current
, UNLOAD_DLL_DEBUG_EVENT
, base
);
430 set_error( STATUS_INVALID_PARAMETER
);
433 /* a process has been killed (i.e. its last thread died) */
434 static void process_killed( struct process
*process
)
436 assert( !process
->thread_list
);
437 gettimeofday( &process
->end_time
, NULL
);
438 if (process
->handles
) release_object( process
->handles
);
439 process
->handles
= NULL
;
440 free_console( process
);
441 while (process
->exe
.next
)
443 struct process_dll
*dll
= process
->exe
.next
;
444 process
->exe
.next
= dll
->next
;
445 if (dll
->file
) release_object( dll
->file
);
448 if (process
->exe
.file
) release_object( process
->exe
.file
);
449 process
->exe
.file
= NULL
;
450 wake_up( &process
->obj
, 0 );
451 if (!--running_processes
)
453 /* last process died, close global handles */
454 close_global_handles();
455 /* this will cause the select loop to terminate */
456 if (!persistent_server
) close_master_socket();
460 /* add a thread to a process running threads list */
461 void add_process_thread( struct process
*process
, struct thread
*thread
)
463 thread
->proc_next
= process
->thread_list
;
464 thread
->proc_prev
= NULL
;
465 if (thread
->proc_next
) thread
->proc_next
->proc_prev
= thread
;
466 process
->thread_list
= thread
;
467 if (!process
->running_threads
++) running_processes
++;
468 grab_object( thread
);
471 /* remove a thread from a process running threads list */
472 void remove_process_thread( struct process
*process
, struct thread
*thread
)
474 assert( process
->running_threads
> 0 );
475 assert( process
->thread_list
);
477 if (thread
->proc_next
) thread
->proc_next
->proc_prev
= thread
->proc_prev
;
478 if (thread
->proc_prev
) thread
->proc_prev
->proc_next
= thread
->proc_next
;
479 else process
->thread_list
= thread
->proc_next
;
481 if (!--process
->running_threads
)
483 /* we have removed the last running thread, exit the process */
484 process
->exit_code
= thread
->exit_code
;
485 generate_debug_event( thread
, EXIT_PROCESS_DEBUG_EVENT
, process
);
486 process_killed( process
);
488 else generate_debug_event( thread
, EXIT_THREAD_DEBUG_EVENT
, thread
);
489 release_object( thread
);
492 /* suspend all the threads of a process */
493 void suspend_process( struct process
*process
)
495 if (!process
->suspend
++)
497 struct thread
*thread
= process
->thread_list
;
498 for (; thread
; thread
= thread
->proc_next
)
500 if (!thread
->suspend
) stop_thread( thread
);
505 /* resume all the threads of a process */
506 void resume_process( struct process
*process
)
508 assert (process
->suspend
> 0);
509 if (!--process
->suspend
)
511 struct thread
*thread
= process
->thread_list
;
512 for (; thread
; thread
= thread
->proc_next
)
514 if (!thread
->suspend
) continue_thread( thread
);
519 /* kill a process on the spot */
520 static void kill_process( struct process
*process
, struct thread
*skip
, int exit_code
)
522 struct thread
*thread
= process
->thread_list
;
525 struct thread
*next
= thread
->proc_next
;
526 thread
->exit_code
= exit_code
;
527 if (thread
!= skip
) kill_thread( thread
, 1 );
532 /* kill all processes being debugged by a given thread */
533 void kill_debugged_processes( struct thread
*debugger
, int exit_code
)
535 for (;;) /* restart from the beginning of the list every time */
537 struct process
*process
= first_process
;
538 /* find the first process being debugged by 'debugger' and still running */
539 while (process
&& (process
->debugger
!= debugger
|| !process
->running_threads
))
540 process
= process
->next
;
541 if (!process
) return;
542 process
->debugger
= NULL
;
543 kill_process( process
, NULL
, exit_code
);
547 /* get all information about a process */
548 static void get_process_info( struct process
*process
, struct get_process_info_request
*req
)
551 req
->debugged
= (process
->debugger
!= 0);
552 req
->exit_code
= process
->exit_code
;
553 req
->priority
= process
->priority
;
554 req
->process_affinity
= process
->affinity
;
555 req
->system_affinity
= 1;
558 /* set all information about a process */
559 static void set_process_info( struct process
*process
,
560 struct set_process_info_request
*req
)
562 if (req
->mask
& SET_PROCESS_INFO_PRIORITY
)
563 process
->priority
= req
->priority
;
564 if (req
->mask
& SET_PROCESS_INFO_AFFINITY
)
566 if (req
->affinity
!= 1) set_error( STATUS_INVALID_PARAMETER
);
567 else process
->affinity
= req
->affinity
;
571 /* read data from a process memory space */
572 /* len is the total size (in ints), max is the size we can actually store in the output buffer */
573 /* we read the total size in all cases to check for permissions */
574 static void read_process_memory( struct process
*process
, const int *addr
,
575 size_t len
, size_t max
, int *dest
)
577 struct thread
*thread
= process
->thread_list
;
579 if ((unsigned int)addr
% sizeof(int)) /* address must be aligned */
581 set_error( STATUS_INVALID_PARAMETER
);
584 if (!thread
) /* process is dead */
586 set_error( STATUS_ACCESS_DENIED
);
589 if (suspend_for_ptrace( thread
))
591 while (len
> 0 && max
)
593 if (read_thread_int( thread
, addr
++, dest
++ ) == -1) goto done
;
597 /* check the rest for read permission */
600 int dummy
, page
= get_page_size() / sizeof(int);
605 if (read_thread_int( thread
, addr
- 1, &dummy
) == -1) goto done
;
607 if (len
&& (read_thread_int( thread
, addr
+ len
- 1, &dummy
) == -1)) goto done
;
610 resume_thread( thread
);
614 /* write data to a process memory space */
615 /* len is the total size (in ints), max is the size we can actually read from the input buffer */
616 /* we check the total size for write permissions */
617 static void write_process_memory( struct process
*process
, int *addr
, size_t len
,
618 size_t max
, unsigned int first_mask
,
619 unsigned int last_mask
, const int *src
)
621 struct thread
*thread
= process
->thread_list
;
623 if (!len
|| ((unsigned int)addr
% sizeof(int))) /* address must be aligned */
625 set_error( STATUS_INVALID_PARAMETER
);
628 if (!thread
) /* process is dead */
630 set_error( STATUS_ACCESS_DENIED
);
633 if (suspend_for_ptrace( thread
))
635 /* first word is special */
638 if (write_thread_int( thread
, addr
++, *src
++, first_mask
) == -1) goto done
;
642 else last_mask
&= first_mask
;
644 while (len
> 1 && max
)
646 if (write_thread_int( thread
, addr
++, *src
++, ~0 ) == -1) goto done
;
653 /* last word is special too */
654 if (write_thread_int( thread
, addr
, *src
, last_mask
) == -1) goto done
;
658 /* check the rest for write permission */
659 int page
= get_page_size() / sizeof(int);
664 if (write_thread_int( thread
, addr
- 1, 0, 0 ) == -1) goto done
;
666 if (len
&& (write_thread_int( thread
, addr
+ len
- 1, 0, 0 ) == -1)) goto done
;
669 resume_thread( thread
);
673 /* take a snapshot of currently running processes */
674 struct process_snapshot
*process_snap( int *count
)
676 struct process_snapshot
*snapshot
, *ptr
;
677 struct process
*process
;
678 if (!running_processes
) return NULL
;
679 if (!(snapshot
= mem_alloc( sizeof(*snapshot
) * running_processes
)))
682 for (process
= first_process
; process
; process
= process
->next
)
684 if (!process
->running_threads
) continue;
685 ptr
->process
= process
;
686 ptr
->threads
= process
->running_threads
;
687 ptr
->count
= process
->obj
.refcount
;
688 ptr
->priority
= process
->priority
;
689 grab_object( process
);
692 *count
= running_processes
;
696 /* take a snapshot of the modules of a process */
697 struct module_snapshot
*module_snap( struct process
*process
, int *count
)
699 struct module_snapshot
*snapshot
, *ptr
;
700 struct process_dll
*dll
;
703 for (dll
= &process
->exe
; dll
; dll
= dll
->next
) total
++;
704 if (!(snapshot
= mem_alloc( sizeof(*snapshot
) * total
))) return NULL
;
706 for (ptr
= snapshot
, dll
= &process
->exe
; dll
; dll
= dll
->next
, ptr
++)
708 ptr
->base
= dll
->base
;
715 /* create a new process */
716 DECL_HANDLER(new_process
)
718 size_t len
= get_req_data_size( req
);
719 struct startup_info
*info
;
724 fatal_protocol_error( current
, "new_process: another process is being created\n" );
728 /* build the startup info for a new process */
729 if (!(info
= alloc_object( &startup_info_ops
, -1 ))) return;
730 info
->inherit_all
= req
->inherit_all
;
731 info
->create_flags
= req
->create_flags
;
732 info
->start_flags
= req
->start_flags
;
733 info
->hstdin
= req
->hstdin
;
734 info
->hstdout
= req
->hstdout
;
735 info
->hstderr
= req
->hstderr
;
736 info
->cmd_show
= req
->cmd_show
;
737 info
->exe_file
= NULL
;
738 info
->filename
= NULL
;
739 info
->process
= NULL
;
742 if ((req
->exe_file
!= -1) &&
743 !(info
->exe_file
= get_file_obj( current
->process
, req
->exe_file
, GENERIC_READ
)))
745 release_object( info
);
749 if (!(info
->filename
= mem_alloc( len
+ 1 )))
751 release_object( info
);
754 memcpy( info
->filename
, get_req_data(req
), len
);
755 info
->filename
[len
] = 0;
759 if (socketpair( AF_UNIX
, SOCK_STREAM
, 0, sock
) == -1)
762 release_object( info
);
765 if (!create_process( sock
[0] ))
767 release_object( info
);
771 /* thread object will be released when the thread gets killed */
772 set_reply_fd( current
, sock
[1] );
774 current
->info
= info
;
777 /* Wait for the new process to start */
778 DECL_HANDLER(wait_process
)
782 fatal_protocol_error( current
, "wait_process: no process is being created\n" );
792 release_object( current
->info
);
793 current
->info
= NULL
;
797 struct object
*obj
= ¤t
->info
->obj
;
798 sleep_on( 1, &obj
, SELECT_TIMEOUT
, req
->timeout
, build_wait_process_reply
);
802 /* initialize a new process */
803 DECL_HANDLER(init_process
)
805 if (!current
->unix_pid
)
807 fatal_protocol_error( current
, "init_process: init_thread not called yet\n" );
810 current
->process
->ldt_copy
= req
->ldt_copy
;
811 current
->process
->ldt_flags
= req
->ldt_flags
;
812 init_process( req
->ppid
, req
);
815 /* signal the end of the process initialization */
816 DECL_HANDLER(init_process_done
)
818 struct process
*process
= current
->process
;
819 if (!process
->init_event
)
821 fatal_protocol_error( current
, "init_process_done: no event\n" );
824 process
->exe
.base
= req
->module
;
825 process
->exe
.name
= req
->name
;
826 generate_startup_debug_events( current
->process
, req
->entry
);
827 set_event( process
->init_event
);
828 release_object( process
->init_event
);
829 process
->init_event
= NULL
;
830 if (req
->gui
) process
->idle_event
= create_event( NULL
, 0, 1, 0 );
831 if (current
->suspend
+ current
->process
->suspend
> 0) stop_thread( current
);
832 req
->debugged
= (current
->process
->debugger
!= 0);
835 /* open a handle to a process */
836 DECL_HANDLER(open_process
)
838 struct process
*process
= get_process_from_id( req
->pid
);
842 req
->handle
= alloc_handle( current
->process
, process
, req
->access
, req
->inherit
);
843 release_object( process
);
847 /* terminate a process */
848 DECL_HANDLER(terminate_process
)
850 struct process
*process
;
852 if ((process
= get_process_from_handle( req
->handle
, PROCESS_TERMINATE
)))
854 req
->self
= (current
->process
== process
);
855 kill_process( process
, current
, req
->exit_code
);
856 release_object( process
);
860 /* fetch information about a process */
861 DECL_HANDLER(get_process_info
)
863 struct process
*process
;
865 if ((process
= get_process_from_handle( req
->handle
, PROCESS_QUERY_INFORMATION
)))
867 get_process_info( process
, req
);
868 release_object( process
);
872 /* set information about a process */
873 DECL_HANDLER(set_process_info
)
875 struct process
*process
;
877 if ((process
= get_process_from_handle( req
->handle
, PROCESS_SET_INFORMATION
)))
879 set_process_info( process
, req
);
880 release_object( process
);
884 /* read data from a process address space */
885 DECL_HANDLER(read_process_memory
)
887 struct process
*process
;
889 if ((process
= get_process_from_handle( req
->handle
, PROCESS_VM_READ
)))
891 size_t maxlen
= get_req_data_size(req
) / sizeof(int);
892 read_process_memory( process
, req
->addr
, req
->len
, maxlen
, get_req_data(req
) );
893 release_object( process
);
897 /* write data to a process address space */
898 DECL_HANDLER(write_process_memory
)
900 struct process
*process
;
902 if ((process
= get_process_from_handle( req
->handle
, PROCESS_VM_WRITE
)))
904 size_t maxlen
= get_req_data_size(req
) / sizeof(int);
905 write_process_memory( process
, req
->addr
, req
->len
, maxlen
,
906 req
->first_mask
, req
->last_mask
, get_req_data(req
) );
907 release_object( process
);
911 /* notify the server that a dll has been loaded */
912 DECL_HANDLER(load_dll
)
914 struct process_dll
*dll
;
915 struct file
*file
= NULL
;
917 if ((req
->handle
!= -1) &&
918 !(file
= get_file_obj( current
->process
, req
->handle
, GENERIC_READ
))) return;
920 if ((dll
= process_load_dll( current
->process
, file
, req
->base
)))
922 dll
->dbg_offset
= req
->dbg_offset
;
923 dll
->dbg_size
= req
->dbg_size
;
924 dll
->name
= req
->name
;
925 /* only generate event if initialization is done */
926 if (!current
->process
->init_event
)
927 generate_debug_event( current
, LOAD_DLL_DEBUG_EVENT
, dll
);
929 if (file
) release_object( file
);
932 /* notify the server that a dll is being unloaded */
933 DECL_HANDLER(unload_dll
)
935 process_unload_dll( current
->process
, req
->base
);
938 /* wait for a process to start waiting on input */
939 /* FIXME: only returns event for now, wait is done in the client */
940 DECL_HANDLER(wait_input_idle
)
942 struct process
*process
;
945 if ((process
= get_process_from_handle( req
->handle
, PROCESS_QUERY_INFORMATION
)))
947 if (process
->idle_event
&& process
!= current
->process
&& process
->queue
!= current
->queue
)
948 req
->event
= alloc_handle( current
->process
, process
->idle_event
,
949 EVENT_ALL_ACCESS
, 0 );
950 release_object( process
);