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_poll_event( struct object
*obj
, int event
);
40 static void process_destroy( struct object
*obj
);
42 static const struct object_ops process_ops
=
44 sizeof(struct process
), /* size */
45 process_dump
, /* dump */
46 add_queue
, /* add_queue */
47 remove_queue
, /* remove_queue */
48 process_signaled
, /* signaled */
49 no_satisfied
, /* satisfied */
50 NULL
, /* get_poll_events */
51 process_poll_event
, /* poll_event */
52 no_get_fd
, /* get_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 handle_t hstdin
; /* handle for stdin */
67 handle_t hstdout
; /* handle for stdout */
68 handle_t 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 thread
*owner
; /* owner thread (the one that created the new process) */
73 struct process
*process
; /* created process */
74 struct thread
*thread
; /* created thread */
77 static void startup_info_dump( struct object
*obj
, int verbose
);
78 static int startup_info_signaled( struct object
*obj
, struct thread
*thread
);
79 static void startup_info_destroy( struct object
*obj
);
81 static const struct object_ops startup_info_ops
=
83 sizeof(struct startup_info
), /* size */
84 startup_info_dump
, /* dump */
85 add_queue
, /* add_queue */
86 remove_queue
, /* remove_queue */
87 startup_info_signaled
, /* signaled */
88 no_satisfied
, /* satisfied */
89 NULL
, /* get_poll_events */
90 NULL
, /* poll_event */
91 no_get_fd
, /* get_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
, fd
))) return NULL
;
152 process
->next
= NULL
;
153 process
->prev
= NULL
;
154 process
->thread_list
= NULL
;
155 process
->debugger
= NULL
;
156 process
->handles
= NULL
;
157 process
->exit_code
= STILL_ACTIVE
;
158 process
->running_threads
= 0;
159 process
->priority
= NORMAL_PRIORITY_CLASS
;
160 process
->affinity
= 1;
161 process
->suspend
= 0;
162 process
->create_flags
= 0;
163 process
->console_in
= NULL
;
164 process
->console_out
= NULL
;
165 process
->init_event
= NULL
;
166 process
->idle_event
= NULL
;
167 process
->queue
= NULL
;
168 process
->atom_table
= NULL
;
169 process
->ldt_copy
= NULL
;
170 process
->exe
.next
= NULL
;
171 process
->exe
.prev
= NULL
;
172 process
->exe
.file
= NULL
;
173 process
->exe
.dbg_offset
= 0;
174 process
->exe
.dbg_size
= 0;
175 gettimeofday( &process
->start_time
, NULL
);
176 if ((process
->next
= first_process
) != NULL
) process
->next
->prev
= process
;
177 first_process
= process
;
179 /* create the init done event */
180 if (!(process
->init_event
= create_event( NULL
, 0, 1, 0 ))) goto error
;
182 /* create the main thread */
183 if (!(thread
= create_thread( dup(fd
), process
))) goto error
;
185 set_select_events( &process
->obj
, POLLIN
); /* start listening to events */
186 release_object( process
);
190 if (thread
) release_object( thread
);
191 release_object( process
);
195 /* initialize the current process and fill in the request */
196 static void init_process( int ppid
, struct init_process_request
*req
)
198 struct process
*process
= current
->process
;
199 struct thread
*parent_thread
= get_thread_from_pid( ppid
);
200 struct process
*parent
= NULL
;
201 struct startup_info
*info
= NULL
;
205 parent
= parent_thread
->process
;
206 info
= parent_thread
->info
;
209 fatal_protocol_error( current
, "init_process: parent but no info\n" );
214 fatal_protocol_error( current
, "init_process: called twice?\n" );
219 /* set the process flags */
220 process
->create_flags
= info
? info
->create_flags
: CREATE_NEW_CONSOLE
;
222 /* create the handle table */
223 if (parent
&& info
->inherit_all
)
224 process
->handles
= copy_handle_table( process
, parent
);
226 process
->handles
= alloc_handle_table( process
, 0 );
227 if (!process
->handles
) goto error
;
229 /* retrieve the main exe file */
231 if (parent
&& info
->exe_file
)
233 process
->exe
.file
= (struct file
*)grab_object( info
->exe_file
);
234 if (!(req
->exe_file
= alloc_handle( process
, process
->exe
.file
, GENERIC_READ
, 0 )))
238 /* set the process console */
239 if (!set_process_console( process
, parent
, info
, req
)) goto error
;
243 /* attach to the debugger if requested */
244 if (process
->create_flags
& (DEBUG_PROCESS
| DEBUG_ONLY_THIS_PROCESS
))
245 set_process_debugger( process
, parent_thread
);
246 else if (parent
&& parent
->debugger
&& !(parent
->create_flags
& DEBUG_ONLY_THIS_PROCESS
))
247 set_process_debugger( process
, parent
->debugger
);
250 /* thread will be actually suspended in init_done */
251 if (process
->create_flags
& CREATE_SUSPENDED
) current
->suspend
++;
255 size_t size
= strlen(info
->filename
);
256 if (size
> get_req_data_size(req
)) size
= get_req_data_size(req
);
257 req
->start_flags
= info
->start_flags
;
258 req
->cmd_show
= info
->cmd_show
;
259 memcpy( get_req_data(req
), info
->filename
, size
);
260 set_req_data_size( req
, size
);
261 info
->process
= (struct process
*)grab_object( process
);
262 info
->thread
= (struct thread
*)grab_object( current
);
263 wake_up( &info
->obj
, 0 );
267 req
->start_flags
= STARTF_USESTDHANDLES
;
269 set_req_data_size( req
, 0 );
271 req
->create_flags
= process
->create_flags
;
272 req
->server_start
= server_start_ticks
;
276 /* destroy a process when its refcount is 0 */
277 static void process_destroy( struct object
*obj
)
279 struct process
*process
= (struct process
*)obj
;
280 assert( obj
->ops
== &process_ops
);
282 /* we can't have a thread remaining */
283 assert( !process
->thread_list
);
284 if (process
->next
) process
->next
->prev
= process
->prev
;
285 if (process
->prev
) process
->prev
->next
= process
->next
;
286 else first_process
= process
->next
;
287 if (process
->init_event
) release_object( process
->init_event
);
288 if (process
->idle_event
) release_object( process
->idle_event
);
289 if (process
->queue
) release_object( process
->queue
);
290 if (process
->atom_table
) release_object( process
->atom_table
);
291 if (process
->exe
.file
) release_object( process
->exe
.file
);
294 /* dump a process on stdout for debugging purposes */
295 static void process_dump( struct object
*obj
, int verbose
)
297 struct process
*process
= (struct process
*)obj
;
298 assert( obj
->ops
== &process_ops
);
300 fprintf( stderr
, "Process next=%p prev=%p console=%p/%p handles=%p\n",
301 process
->next
, process
->prev
, process
->console_in
, process
->console_out
,
305 static int process_signaled( struct object
*obj
, struct thread
*thread
)
307 struct process
*process
= (struct process
*)obj
;
308 return !process
->running_threads
;
312 static void process_poll_event( struct object
*obj
, int event
)
314 struct process
*process
= (struct process
*)obj
;
315 assert( obj
->ops
== &process_ops
);
317 if (event
& (POLLERR
| POLLHUP
)) set_select_events( obj
, -1 );
318 else if (event
& POLLIN
) receive_fd( process
);
321 static void startup_info_destroy( struct object
*obj
)
323 struct startup_info
*info
= (struct startup_info
*)obj
;
324 assert( obj
->ops
== &startup_info_ops
);
325 if (info
->filename
) free( info
->filename
);
326 if (info
->exe_file
) release_object( info
->exe_file
);
327 if (info
->process
) release_object( info
->process
);
328 if (info
->thread
) release_object( info
->thread
);
331 info
->owner
->info
= NULL
;
332 release_object( info
->owner
);
336 static void startup_info_dump( struct object
*obj
, int verbose
)
338 struct startup_info
*info
= (struct startup_info
*)obj
;
339 assert( obj
->ops
== &startup_info_ops
);
341 fprintf( stderr
, "Startup info flags=%x in=%d out=%d err=%d name='%s'\n",
342 info
->start_flags
, info
->hstdin
, info
->hstdout
, info
->hstderr
, info
->filename
);
345 static int startup_info_signaled( struct object
*obj
, struct thread
*thread
)
347 struct startup_info
*info
= (struct startup_info
*)obj
;
348 return (info
->thread
!= NULL
);
352 /* get a process from an id (and increment the refcount) */
353 struct process
*get_process_from_id( void *id
)
355 struct process
*p
= first_process
;
356 while (p
&& (p
!= id
)) p
= p
->next
;
357 if (p
) grab_object( p
);
358 else set_error( STATUS_INVALID_PARAMETER
);
362 /* get a process from a handle (and increment the refcount) */
363 struct process
*get_process_from_handle( handle_t handle
, unsigned int access
)
365 return (struct process
*)get_handle_obj( current
->process
, handle
,
366 access
, &process_ops
);
369 /* add a dll to a process list */
370 static struct process_dll
*process_load_dll( struct process
*process
, struct file
*file
,
373 struct process_dll
*dll
;
375 /* make sure we don't already have one with the same base address */
376 for (dll
= process
->exe
.next
; dll
; dll
= dll
->next
) if (dll
->base
== base
)
378 set_error( STATUS_INVALID_PARAMETER
);
382 if ((dll
= mem_alloc( sizeof(*dll
) )))
384 dll
->prev
= &process
->exe
;
387 if (file
) dll
->file
= (struct file
*)grab_object( file
);
388 if ((dll
->next
= process
->exe
.next
)) dll
->next
->prev
= dll
;
389 process
->exe
.next
= dll
;
394 /* remove a dll from a process list */
395 static void process_unload_dll( struct process
*process
, void *base
)
397 struct process_dll
*dll
;
399 for (dll
= process
->exe
.next
; dll
; dll
= dll
->next
)
401 if (dll
->base
== base
)
403 if (dll
->file
) release_object( dll
->file
);
404 if (dll
->next
) dll
->next
->prev
= dll
->prev
;
405 if (dll
->prev
) dll
->prev
->next
= dll
->next
;
407 generate_debug_event( current
, UNLOAD_DLL_DEBUG_EVENT
, base
);
411 set_error( STATUS_INVALID_PARAMETER
);
414 /* a process has been killed (i.e. its last thread died) */
415 static void process_killed( struct process
*process
)
417 assert( !process
->thread_list
);
418 gettimeofday( &process
->end_time
, NULL
);
419 if (process
->handles
) release_object( process
->handles
);
420 process
->handles
= NULL
;
421 free_console( process
);
422 while (process
->exe
.next
)
424 struct process_dll
*dll
= process
->exe
.next
;
425 process
->exe
.next
= dll
->next
;
426 if (dll
->file
) release_object( dll
->file
);
429 if (process
->exe
.file
) release_object( process
->exe
.file
);
430 process
->exe
.file
= NULL
;
431 wake_up( &process
->obj
, 0 );
432 if (!--running_processes
)
434 /* last process died, close global handles */
435 close_global_handles();
436 /* this will cause the select loop to terminate */
437 if (!persistent_server
) close_master_socket();
441 /* add a thread to a process running threads list */
442 void add_process_thread( struct process
*process
, struct thread
*thread
)
444 thread
->proc_next
= process
->thread_list
;
445 thread
->proc_prev
= NULL
;
446 if (thread
->proc_next
) thread
->proc_next
->proc_prev
= thread
;
447 process
->thread_list
= thread
;
448 if (!process
->running_threads
++) running_processes
++;
449 grab_object( thread
);
452 /* remove a thread from a process running threads list */
453 void remove_process_thread( struct process
*process
, struct thread
*thread
)
455 assert( process
->running_threads
> 0 );
456 assert( process
->thread_list
);
458 if (thread
->proc_next
) thread
->proc_next
->proc_prev
= thread
->proc_prev
;
459 if (thread
->proc_prev
) thread
->proc_prev
->proc_next
= thread
->proc_next
;
460 else process
->thread_list
= thread
->proc_next
;
462 if (!--process
->running_threads
)
464 /* we have removed the last running thread, exit the process */
465 process
->exit_code
= thread
->exit_code
;
466 generate_debug_event( thread
, EXIT_PROCESS_DEBUG_EVENT
, process
);
467 process_killed( process
);
469 else generate_debug_event( thread
, EXIT_THREAD_DEBUG_EVENT
, thread
);
470 release_object( thread
);
473 /* suspend all the threads of a process */
474 void suspend_process( struct process
*process
)
476 if (!process
->suspend
++)
478 struct thread
*thread
= process
->thread_list
;
479 for (; thread
; thread
= thread
->proc_next
)
481 if (!thread
->suspend
) stop_thread( thread
);
486 /* resume all the threads of a process */
487 void resume_process( struct process
*process
)
489 assert (process
->suspend
> 0);
490 if (!--process
->suspend
)
492 struct thread
*thread
= process
->thread_list
;
493 for (; thread
; thread
= thread
->proc_next
)
495 if (!thread
->suspend
) continue_thread( thread
);
500 /* kill a process on the spot */
501 void kill_process( struct process
*process
, struct thread
*skip
, int exit_code
)
503 struct thread
*thread
= process
->thread_list
;
506 struct thread
*next
= thread
->proc_next
;
507 thread
->exit_code
= exit_code
;
508 if (thread
!= skip
) kill_thread( thread
, 1 );
513 /* kill all processes being debugged by a given thread */
514 void kill_debugged_processes( struct thread
*debugger
, int exit_code
)
516 for (;;) /* restart from the beginning of the list every time */
518 struct process
*process
= first_process
;
519 /* find the first process being debugged by 'debugger' and still running */
520 while (process
&& (process
->debugger
!= debugger
|| !process
->running_threads
))
521 process
= process
->next
;
522 if (!process
) return;
523 process
->debugger
= NULL
;
524 kill_process( process
, NULL
, exit_code
);
528 /* get all information about a process */
529 static void get_process_info( struct process
*process
, struct get_process_info_request
*req
)
532 req
->debugged
= (process
->debugger
!= 0);
533 req
->exit_code
= process
->exit_code
;
534 req
->priority
= process
->priority
;
535 req
->process_affinity
= process
->affinity
;
536 req
->system_affinity
= 1;
539 /* set all information about a process */
540 static void set_process_info( struct process
*process
,
541 struct set_process_info_request
*req
)
543 if (req
->mask
& SET_PROCESS_INFO_PRIORITY
)
544 process
->priority
= req
->priority
;
545 if (req
->mask
& SET_PROCESS_INFO_AFFINITY
)
547 if (req
->affinity
!= 1) set_error( STATUS_INVALID_PARAMETER
);
548 else process
->affinity
= req
->affinity
;
552 /* read data from a process memory space */
553 /* len is the total size (in ints), max is the size we can actually store in the output buffer */
554 /* we read the total size in all cases to check for permissions */
555 static void read_process_memory( struct process
*process
, const int *addr
,
556 size_t len
, size_t max
, int *dest
)
558 struct thread
*thread
= process
->thread_list
;
560 if ((unsigned int)addr
% sizeof(int)) /* address must be aligned */
562 set_error( STATUS_INVALID_PARAMETER
);
565 if (!thread
) /* process is dead */
567 set_error( STATUS_ACCESS_DENIED
);
570 if (suspend_for_ptrace( thread
))
572 while (len
> 0 && max
)
574 if (read_thread_int( thread
, addr
++, dest
++ ) == -1) goto done
;
578 /* check the rest for read permission */
581 int dummy
, page
= get_page_size() / sizeof(int);
586 if (read_thread_int( thread
, addr
- 1, &dummy
) == -1) goto done
;
588 if (len
&& (read_thread_int( thread
, addr
+ len
- 1, &dummy
) == -1)) goto done
;
591 resume_thread( thread
);
595 /* write data to a process memory space */
596 /* len is the total size (in ints), max is the size we can actually read from the input buffer */
597 /* we check the total size for write permissions */
598 static void write_process_memory( struct process
*process
, int *addr
, size_t len
,
599 size_t max
, unsigned int first_mask
,
600 unsigned int last_mask
, const int *src
)
602 struct thread
*thread
= process
->thread_list
;
604 if (!len
|| ((unsigned int)addr
% sizeof(int))) /* address must be aligned */
606 set_error( STATUS_INVALID_PARAMETER
);
609 if (!thread
) /* process is dead */
611 set_error( STATUS_ACCESS_DENIED
);
614 if (suspend_for_ptrace( thread
))
616 /* first word is special */
619 if (write_thread_int( thread
, addr
++, *src
++, first_mask
) == -1) goto done
;
623 else last_mask
&= first_mask
;
625 while (len
> 1 && max
)
627 if (write_thread_int( thread
, addr
++, *src
++, ~0 ) == -1) goto done
;
634 /* last word is special too */
635 if (write_thread_int( thread
, addr
, *src
, last_mask
) == -1) goto done
;
639 /* check the rest for write permission */
640 int page
= get_page_size() / sizeof(int);
645 if (write_thread_int( thread
, addr
- 1, 0, 0 ) == -1) goto done
;
647 if (len
&& (write_thread_int( thread
, addr
+ len
- 1, 0, 0 ) == -1)) goto done
;
650 resume_thread( thread
);
654 /* take a snapshot of currently running processes */
655 struct process_snapshot
*process_snap( int *count
)
657 struct process_snapshot
*snapshot
, *ptr
;
658 struct process
*process
;
659 if (!running_processes
) return NULL
;
660 if (!(snapshot
= mem_alloc( sizeof(*snapshot
) * running_processes
)))
663 for (process
= first_process
; process
; process
= process
->next
)
665 if (!process
->running_threads
) continue;
666 ptr
->process
= process
;
667 ptr
->threads
= process
->running_threads
;
668 ptr
->count
= process
->obj
.refcount
;
669 ptr
->priority
= process
->priority
;
670 grab_object( process
);
673 *count
= running_processes
;
677 /* take a snapshot of the modules of a process */
678 struct module_snapshot
*module_snap( struct process
*process
, int *count
)
680 struct module_snapshot
*snapshot
, *ptr
;
681 struct process_dll
*dll
;
684 for (dll
= &process
->exe
; dll
; dll
= dll
->next
) total
++;
685 if (!(snapshot
= mem_alloc( sizeof(*snapshot
) * total
))) return NULL
;
687 for (ptr
= snapshot
, dll
= &process
->exe
; dll
; dll
= dll
->next
, ptr
++)
689 ptr
->base
= dll
->base
;
696 /* create a new process */
697 DECL_HANDLER(new_process
)
699 size_t len
= get_req_data_size( req
);
700 struct startup_info
*info
;
704 fatal_protocol_error( current
, "new_process: another process is being created\n" );
708 /* build the startup info for a new process */
709 if (!(info
= alloc_object( &startup_info_ops
, -1 ))) return;
710 info
->inherit_all
= req
->inherit_all
;
711 info
->create_flags
= req
->create_flags
;
712 info
->start_flags
= req
->start_flags
;
713 info
->hstdin
= req
->hstdin
;
714 info
->hstdout
= req
->hstdout
;
715 info
->hstderr
= req
->hstderr
;
716 info
->cmd_show
= req
->cmd_show
;
717 info
->exe_file
= NULL
;
718 info
->filename
= NULL
;
719 info
->owner
= (struct thread
*)grab_object( current
);
720 info
->process
= NULL
;
724 !(info
->exe_file
= get_file_obj( current
->process
, req
->exe_file
, GENERIC_READ
)))
727 if (!(info
->filename
= mem_alloc( len
+ 1 ))) goto done
;
729 memcpy( info
->filename
, get_req_data(req
), len
);
730 info
->filename
[len
] = 0;
731 current
->info
= info
;
732 req
->info
= alloc_handle( current
->process
, info
, SYNCHRONIZE
, FALSE
);
735 release_object( info
);
738 /* Retrieve information about a newly started process */
739 DECL_HANDLER(get_new_process_info
)
741 struct startup_info
*info
;
745 if ((info
= (struct startup_info
*)get_handle_obj( current
->process
, req
->info
,
746 0, &startup_info_ops
)))
748 req
->pid
= get_process_id( info
->process
);
749 req
->tid
= get_thread_id( info
->thread
);
750 req
->phandle
= alloc_handle( current
->process
, info
->process
,
751 PROCESS_ALL_ACCESS
, req
->pinherit
);
752 req
->thandle
= alloc_handle( current
->process
, info
->thread
,
753 THREAD_ALL_ACCESS
, req
->tinherit
);
754 if (info
->process
->init_event
)
755 req
->event
= alloc_handle( current
->process
, info
->process
->init_event
,
756 EVENT_ALL_ACCESS
, 0 );
757 release_object( info
);
768 /* initialize a new process */
769 DECL_HANDLER(init_process
)
771 if (!current
->unix_pid
)
773 fatal_protocol_error( current
, "init_process: init_thread not called yet\n" );
776 current
->process
->ldt_copy
= req
->ldt_copy
;
777 init_process( req
->ppid
, req
);
780 /* signal the end of the process initialization */
781 DECL_HANDLER(init_process_done
)
784 struct process
*process
= current
->process
;
785 if (!process
->init_event
)
787 fatal_protocol_error( current
, "init_process_done: no event\n" );
790 process
->exe
.base
= req
->module
;
791 process
->exe
.name
= req
->name
;
793 if (req
->exe_file
&& (file
= get_file_obj( current
->process
, req
->exe_file
, GENERIC_READ
)))
795 if (process
->exe
.file
) release_object( process
->exe
.file
);
796 process
->exe
.file
= file
;
798 generate_startup_debug_events( current
->process
, req
->entry
);
799 set_event( process
->init_event
);
800 release_object( process
->init_event
);
801 process
->init_event
= NULL
;
802 if (req
->gui
) process
->idle_event
= create_event( NULL
, 0, 1, 0 );
803 if (current
->suspend
+ current
->process
->suspend
> 0) stop_thread( current
);
804 req
->debugged
= (current
->process
->debugger
!= 0);
807 /* open a handle to a process */
808 DECL_HANDLER(open_process
)
810 struct process
*process
= get_process_from_id( req
->pid
);
814 req
->handle
= alloc_handle( current
->process
, process
, req
->access
, req
->inherit
);
815 release_object( process
);
819 /* terminate a process */
820 DECL_HANDLER(terminate_process
)
822 struct process
*process
;
824 if ((process
= get_process_from_handle( req
->handle
, PROCESS_TERMINATE
)))
826 req
->self
= (current
->process
== process
);
827 kill_process( process
, current
, req
->exit_code
);
828 release_object( process
);
832 /* fetch information about a process */
833 DECL_HANDLER(get_process_info
)
835 struct process
*process
;
837 if ((process
= get_process_from_handle( req
->handle
, PROCESS_QUERY_INFORMATION
)))
839 get_process_info( process
, req
);
840 release_object( process
);
844 /* set information about a process */
845 DECL_HANDLER(set_process_info
)
847 struct process
*process
;
849 if ((process
= get_process_from_handle( req
->handle
, PROCESS_SET_INFORMATION
)))
851 set_process_info( process
, req
);
852 release_object( process
);
856 /* read data from a process address space */
857 DECL_HANDLER(read_process_memory
)
859 struct process
*process
;
861 if ((process
= get_process_from_handle( req
->handle
, PROCESS_VM_READ
)))
863 size_t maxlen
= get_req_data_size(req
) / sizeof(int);
864 read_process_memory( process
, req
->addr
, req
->len
, maxlen
, get_req_data(req
) );
865 release_object( process
);
869 /* write data to a process address space */
870 DECL_HANDLER(write_process_memory
)
872 struct process
*process
;
874 if ((process
= get_process_from_handle( req
->handle
, PROCESS_VM_WRITE
)))
876 size_t maxlen
= get_req_data_size(req
) / sizeof(int);
877 write_process_memory( process
, req
->addr
, req
->len
, maxlen
,
878 req
->first_mask
, req
->last_mask
, get_req_data(req
) );
879 release_object( process
);
883 /* notify the server that a dll has been loaded */
884 DECL_HANDLER(load_dll
)
886 struct process_dll
*dll
;
887 struct file
*file
= NULL
;
890 !(file
= get_file_obj( current
->process
, req
->handle
, GENERIC_READ
))) return;
892 if ((dll
= process_load_dll( current
->process
, file
, req
->base
)))
894 dll
->dbg_offset
= req
->dbg_offset
;
895 dll
->dbg_size
= req
->dbg_size
;
896 dll
->name
= req
->name
;
897 /* only generate event if initialization is done */
898 if (!current
->process
->init_event
)
899 generate_debug_event( current
, LOAD_DLL_DEBUG_EVENT
, dll
);
901 if (file
) release_object( file
);
904 /* notify the server that a dll is being unloaded */
905 DECL_HANDLER(unload_dll
)
907 process_unload_dll( current
->process
, req
->base
);
910 /* wait for a process to start waiting on input */
911 /* FIXME: only returns event for now, wait is done in the client */
912 DECL_HANDLER(wait_input_idle
)
914 struct process
*process
;
917 if ((process
= get_process_from_handle( req
->handle
, PROCESS_QUERY_INFORMATION
)))
919 if (process
->idle_event
&& process
!= current
->process
&& process
->queue
!= current
->queue
)
920 req
->event
= alloc_handle( current
->process
, process
->idle_event
,
921 EVENT_ALL_ACCESS
, 0 );
922 release_object( process
);