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 );
143 /* create a new process and its main thread */
144 struct thread
*create_process( int fd
)
146 struct process
*process
;
147 struct thread
*thread
= NULL
;
149 if (!(process
= alloc_object( &process_ops
, -1 )))
154 process
->next
= NULL
;
155 process
->prev
= NULL
;
156 process
->thread_list
= NULL
;
157 process
->debugger
= NULL
;
158 process
->handles
= NULL
;
159 process
->exit_code
= STILL_ACTIVE
;
160 process
->running_threads
= 0;
161 process
->priority
= NORMAL_PRIORITY_CLASS
;
162 process
->affinity
= 1;
163 process
->suspend
= 0;
164 process
->create_flags
= 0;
165 process
->console_in
= NULL
;
166 process
->console_out
= NULL
;
167 process
->init_event
= NULL
;
168 process
->ldt_copy
= NULL
;
169 process
->ldt_flags
= 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 main thread */
180 if (!(thread
= create_thread( fd
, process
))) goto error
;
182 /* create the init done event */
183 if (!(process
->init_event
= create_event( NULL
, 0, 1, 0 ))) goto error
;
185 add_process_thread( process
, thread
);
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
== 2) /* HACK! */
224 process
->handles
= grab_object( parent
->handles
);
225 else if (parent
&& info
->inherit_all
)
226 process
->handles
= copy_handle_table( process
, parent
);
228 process
->handles
= alloc_handle_table( process
, 0 );
229 if (!process
->handles
) goto error
;
231 /* retrieve the main exe file */
233 if (parent
&& info
->exe_file
)
235 process
->exe
.file
= (struct file
*)grab_object( info
->exe_file
);
236 if ((req
->exe_file
= alloc_handle( process
, process
->exe
.file
, GENERIC_READ
, 0 )) == -1)
240 /* set the process console */
241 if (!set_process_console( process
, parent
, info
, req
)) goto error
;
245 /* attach to the debugger if requested */
246 if (process
->create_flags
& (DEBUG_PROCESS
| DEBUG_ONLY_THIS_PROCESS
))
247 set_process_debugger( process
, parent_thread
);
248 else if (parent
&& parent
->debugger
&& !(parent
->create_flags
& DEBUG_ONLY_THIS_PROCESS
))
249 set_process_debugger( process
, parent
->debugger
);
252 /* thread will be actually suspended in init_done */
253 if (process
->create_flags
& CREATE_SUSPENDED
) current
->suspend
++;
257 req
->start_flags
= info
->start_flags
;
258 req
->cmd_show
= info
->cmd_show
;
259 strcpy( req
->filename
, info
->filename
);
260 info
->process
= (struct process
*)grab_object( process
);
261 info
->thread
= (struct thread
*)grab_object( current
);
262 wake_up( &info
->obj
, 0 );
266 req
->start_flags
= STARTF_USESTDHANDLES
;
268 req
->filename
[0] = 0;
273 /* destroy a process when its refcount is 0 */
274 static void process_destroy( struct object
*obj
)
276 struct process
*process
= (struct process
*)obj
;
277 assert( obj
->ops
== &process_ops
);
279 /* we can't have a thread remaining */
280 assert( !process
->thread_list
);
281 if (process
->next
) process
->next
->prev
= process
->prev
;
282 if (process
->prev
) process
->prev
->next
= process
->next
;
283 else first_process
= process
->next
;
284 if (process
->init_event
) release_object( process
->init_event
);
285 if (process
->exe
.file
) release_object( process
->exe
.file
);
288 /* dump a process on stdout for debugging purposes */
289 static void process_dump( struct object
*obj
, int verbose
)
291 struct process
*process
= (struct process
*)obj
;
292 assert( obj
->ops
== &process_ops
);
294 fprintf( stderr
, "Process next=%p prev=%p console=%p/%p handles=%p\n",
295 process
->next
, process
->prev
, process
->console_in
, process
->console_out
,
299 static int process_signaled( struct object
*obj
, struct thread
*thread
)
301 struct process
*process
= (struct process
*)obj
;
302 return !process
->running_threads
;
306 static void startup_info_destroy( struct object
*obj
)
308 struct startup_info
*info
= (struct startup_info
*)obj
;
309 assert( obj
->ops
== &startup_info_ops
);
310 if (info
->filename
) free( info
->filename
);
311 if (info
->exe_file
) release_object( info
->exe_file
);
312 if (info
->process
) release_object( info
->process
);
313 if (info
->thread
) release_object( info
->thread
);
316 static void startup_info_dump( struct object
*obj
, int verbose
)
318 struct startup_info
*info
= (struct startup_info
*)obj
;
319 assert( obj
->ops
== &startup_info_ops
);
321 fprintf( stderr
, "Startup info flags=%x in=%d out=%d err=%d name='%s'\n",
322 info
->start_flags
, info
->hstdin
, info
->hstdout
, info
->hstderr
, info
->filename
);
325 static int startup_info_signaled( struct object
*obj
, struct thread
*thread
)
327 struct startup_info
*info
= (struct startup_info
*)obj
;
328 return (info
->thread
!= NULL
);
332 /* build a reply for the wait_process request */
333 static void build_wait_process_reply( struct thread
*thread
, struct object
*obj
, int signaled
)
335 struct wait_process_request
*req
= get_req_ptr( thread
);
338 struct startup_info
*info
= (struct startup_info
*)obj
;
339 assert( obj
->ops
== &startup_info_ops
);
341 req
->pid
= get_process_id( info
->process
);
342 req
->tid
= get_thread_id( info
->thread
);
343 req
->phandle
= alloc_handle( thread
->process
, info
->process
,
344 PROCESS_ALL_ACCESS
, req
->pinherit
);
345 req
->thandle
= alloc_handle( thread
->process
, info
->thread
,
346 THREAD_ALL_ACCESS
, req
->tinherit
);
347 if (info
->process
->init_event
)
348 req
->event
= alloc_handle( thread
->process
, info
->process
->init_event
,
349 EVENT_ALL_ACCESS
, 0 );
353 /* FIXME: set_error */
355 release_object( thread
->info
);
359 /* get a process from an id (and increment the refcount) */
360 struct process
*get_process_from_id( void *id
)
362 struct process
*p
= first_process
;
363 while (p
&& (p
!= id
)) p
= p
->next
;
364 if (p
) grab_object( p
);
365 else set_error( STATUS_INVALID_PARAMETER
);
369 /* get a process from a handle (and increment the refcount) */
370 struct process
*get_process_from_handle( int handle
, unsigned int access
)
372 return (struct process
*)get_handle_obj( current
->process
, handle
,
373 access
, &process_ops
);
376 /* add a dll to a process list */
377 static struct process_dll
*process_load_dll( struct process
*process
, struct file
*file
,
380 struct process_dll
*dll
;
382 /* make sure we don't already have one with the same base address */
383 for (dll
= process
->exe
.next
; dll
; dll
= dll
->next
) if (dll
->base
== base
)
385 set_error( STATUS_INVALID_PARAMETER
);
389 if ((dll
= mem_alloc( sizeof(*dll
) )))
391 dll
->prev
= &process
->exe
;
394 if (file
) dll
->file
= (struct file
*)grab_object( file
);
395 if ((dll
->next
= process
->exe
.next
)) dll
->next
->prev
= dll
;
396 process
->exe
.next
= dll
;
401 /* remove a dll from a process list */
402 static void process_unload_dll( struct process
*process
, void *base
)
404 struct process_dll
*dll
;
406 for (dll
= process
->exe
.next
; dll
; dll
= dll
->next
)
408 if (dll
->base
== base
)
410 if (dll
->file
) release_object( dll
->file
);
411 if (dll
->next
) dll
->next
->prev
= dll
->prev
;
412 if (dll
->prev
) dll
->prev
->next
= dll
->next
;
414 generate_debug_event( current
, UNLOAD_DLL_DEBUG_EVENT
, base
);
418 set_error( STATUS_INVALID_PARAMETER
);
421 /* a process has been killed (i.e. its last thread died) */
422 static void process_killed( struct process
*process
)
424 assert( !process
->thread_list
);
425 gettimeofday( &process
->end_time
, NULL
);
426 if (process
->handles
) release_object( process
->handles
);
427 process
->handles
= NULL
;
428 free_console( process
);
429 while (process
->exe
.next
)
431 struct process_dll
*dll
= process
->exe
.next
;
432 process
->exe
.next
= dll
->next
;
433 if (dll
->file
) release_object( dll
->file
);
436 if (process
->exe
.file
) release_object( process
->exe
.file
);
437 process
->exe
.file
= NULL
;
438 wake_up( &process
->obj
, 0 );
439 if (!--running_processes
)
441 /* last process died, close global handles */
442 close_global_handles();
443 /* this will cause the select loop to terminate */
444 if (!persistent_server
) close_master_socket();
448 /* add a thread to a process running threads list */
449 void add_process_thread( struct process
*process
, struct thread
*thread
)
451 thread
->proc_next
= process
->thread_list
;
452 thread
->proc_prev
= NULL
;
453 if (thread
->proc_next
) thread
->proc_next
->proc_prev
= thread
;
454 process
->thread_list
= thread
;
455 if (!process
->running_threads
++) running_processes
++;
456 grab_object( thread
);
459 /* remove a thread from a process running threads list */
460 void remove_process_thread( struct process
*process
, struct thread
*thread
)
462 assert( process
->running_threads
> 0 );
463 assert( process
->thread_list
);
465 if (thread
->proc_next
) thread
->proc_next
->proc_prev
= thread
->proc_prev
;
466 if (thread
->proc_prev
) thread
->proc_prev
->proc_next
= thread
->proc_next
;
467 else process
->thread_list
= thread
->proc_next
;
469 if (!--process
->running_threads
)
471 /* we have removed the last running thread, exit the process */
472 process
->exit_code
= thread
->exit_code
;
473 generate_debug_event( thread
, EXIT_PROCESS_DEBUG_EVENT
, process
);
474 process_killed( process
);
476 else generate_debug_event( thread
, EXIT_THREAD_DEBUG_EVENT
, thread
);
477 release_object( thread
);
480 /* suspend all the threads of a process */
481 void suspend_process( struct process
*process
)
483 if (!process
->suspend
++)
485 struct thread
*thread
= process
->thread_list
;
486 for (; thread
; thread
= thread
->proc_next
)
488 if (!thread
->suspend
) stop_thread( thread
);
493 /* resume all the threads of a process */
494 void resume_process( struct process
*process
)
496 assert (process
->suspend
> 0);
497 if (!--process
->suspend
)
499 struct thread
*thread
= process
->thread_list
;
500 for (; thread
; thread
= thread
->proc_next
)
502 if (!thread
->suspend
) continue_thread( thread
);
507 /* kill a process on the spot */
508 static void kill_process( struct process
*process
, struct thread
*skip
, int exit_code
)
510 struct thread
*thread
= process
->thread_list
;
513 struct thread
*next
= thread
->proc_next
;
514 thread
->exit_code
= exit_code
;
515 if (thread
!= skip
) kill_thread( thread
, 1 );
520 /* kill all processes being debugged by a given thread */
521 void kill_debugged_processes( struct thread
*debugger
, int exit_code
)
523 for (;;) /* restart from the beginning of the list every time */
525 struct process
*process
= first_process
;
526 /* find the first process being debugged by 'debugger' and still running */
527 while (process
&& (process
->debugger
!= debugger
|| !process
->running_threads
))
528 process
= process
->next
;
529 if (!process
) return;
530 process
->debugger
= NULL
;
531 kill_process( process
, NULL
, exit_code
);
535 /* get all information about a process */
536 static void get_process_info( struct process
*process
, struct get_process_info_request
*req
)
539 req
->debugged
= (process
->debugger
!= 0);
540 req
->exit_code
= process
->exit_code
;
541 req
->priority
= process
->priority
;
542 req
->process_affinity
= process
->affinity
;
543 req
->system_affinity
= 1;
546 /* set all information about a process */
547 static void set_process_info( struct process
*process
,
548 struct set_process_info_request
*req
)
550 if (req
->mask
& SET_PROCESS_INFO_PRIORITY
)
551 process
->priority
= req
->priority
;
552 if (req
->mask
& SET_PROCESS_INFO_AFFINITY
)
554 if (req
->affinity
!= 1) set_error( STATUS_INVALID_PARAMETER
);
555 else process
->affinity
= req
->affinity
;
559 /* read data from a process memory space */
560 /* len is the total size (in ints), max is the size we can actually store in the output buffer */
561 /* we read the total size in all cases to check for permissions */
562 static void read_process_memory( struct process
*process
, const int *addr
,
563 size_t len
, size_t max
, int *dest
)
565 struct thread
*thread
= process
->thread_list
;
567 if ((unsigned int)addr
% sizeof(int)) /* address must be aligned */
569 set_error( STATUS_INVALID_PARAMETER
);
572 if (!thread
) /* process is dead */
574 set_error( STATUS_ACCESS_DENIED
);
577 if (suspend_for_ptrace( thread
))
579 while (len
> 0 && max
)
581 if (read_thread_int( thread
, addr
++, dest
++ ) == -1) goto done
;
585 /* check the rest for read permission */
588 int dummy
, page
= get_page_size() / sizeof(int);
593 if (read_thread_int( thread
, addr
- 1, &dummy
) == -1) goto done
;
595 if (len
&& (read_thread_int( thread
, addr
+ len
- 1, &dummy
) == -1)) goto done
;
598 resume_thread( thread
);
602 /* write data to a process memory space */
603 /* len is the total size (in ints), max is the size we can actually read from the input buffer */
604 /* we check the total size for write permissions */
605 static void write_process_memory( struct process
*process
, int *addr
, size_t len
,
606 size_t max
, unsigned int first_mask
,
607 unsigned int last_mask
, const int *src
)
609 struct thread
*thread
= process
->thread_list
;
611 if (!len
|| ((unsigned int)addr
% sizeof(int))) /* address must be aligned */
613 set_error( STATUS_INVALID_PARAMETER
);
616 if (!thread
) /* process is dead */
618 set_error( STATUS_ACCESS_DENIED
);
621 if (suspend_for_ptrace( thread
))
623 /* first word is special */
626 if (write_thread_int( thread
, addr
++, *src
++, first_mask
) == -1) goto done
;
630 else last_mask
&= first_mask
;
632 while (len
> 1 && max
)
634 if (write_thread_int( thread
, addr
++, *src
++, ~0 ) == -1) goto done
;
641 /* last word is special too */
642 if (write_thread_int( thread
, addr
, *src
, last_mask
) == -1) goto done
;
646 /* check the rest for write permission */
647 int page
= get_page_size() / sizeof(int);
652 if (write_thread_int( thread
, addr
- 1, 0, 0 ) == -1) goto done
;
654 if (len
&& (write_thread_int( thread
, addr
+ len
- 1, 0, 0 ) == -1)) goto done
;
657 resume_thread( thread
);
661 /* take a snapshot of currently running processes */
662 struct process_snapshot
*process_snap( int *count
)
664 struct process_snapshot
*snapshot
, *ptr
;
665 struct process
*process
;
666 if (!running_processes
) return NULL
;
667 if (!(snapshot
= mem_alloc( sizeof(*snapshot
) * running_processes
)))
670 for (process
= first_process
; process
; process
= process
->next
)
672 if (!process
->running_threads
) continue;
673 ptr
->process
= process
;
674 ptr
->threads
= process
->running_threads
;
675 ptr
->count
= process
->obj
.refcount
;
676 ptr
->priority
= process
->priority
;
677 grab_object( process
);
680 *count
= running_processes
;
684 /* take a snapshot of the modules of a process */
685 struct module_snapshot
*module_snap( struct process
*process
, int *count
)
687 struct module_snapshot
*snapshot
, *ptr
;
688 struct process_dll
*dll
;
691 for (dll
= &process
->exe
; dll
; dll
= dll
->next
) total
++;
692 if (!(snapshot
= mem_alloc( sizeof(*snapshot
) * total
))) return NULL
;
694 for (ptr
= snapshot
, dll
= &process
->exe
; dll
; dll
= dll
->next
, ptr
++)
696 ptr
->base
= dll
->base
;
703 /* create a new process */
704 DECL_HANDLER(new_process
)
706 size_t len
= get_req_strlen( req
, req
->filename
);
707 struct startup_info
*info
;
712 fatal_protocol_error( current
, "new_process: another process is being created\n" );
716 /* build the startup info for a new process */
717 if (!(info
= alloc_object( &startup_info_ops
, -1 ))) return;
718 info
->inherit_all
= req
->inherit_all
;
719 info
->create_flags
= req
->create_flags
;
720 info
->start_flags
= req
->start_flags
;
721 info
->hstdin
= req
->hstdin
;
722 info
->hstdout
= req
->hstdout
;
723 info
->hstderr
= req
->hstderr
;
724 info
->cmd_show
= req
->cmd_show
;
725 info
->exe_file
= NULL
;
726 info
->filename
= NULL
;
727 info
->process
= NULL
;
730 if ((req
->exe_file
!= -1) &&
731 !(info
->exe_file
= get_file_obj( current
->process
, req
->exe_file
, GENERIC_READ
)))
733 release_object( info
);
737 if (!(info
->filename
= memdup( req
->filename
, len
+1 )))
739 release_object( info
);
742 info
->filename
[len
] = 0;
746 if (socketpair( AF_UNIX
, SOCK_STREAM
, 0, sock
) == -1)
749 release_object( info
);
752 if (!create_process( sock
[0] ))
754 release_object( info
);
758 /* thread object will be released when the thread gets killed */
759 set_reply_fd( current
, sock
[1] );
761 current
->info
= info
;
764 /* Wait for the new process to start */
765 DECL_HANDLER(wait_process
)
769 fatal_protocol_error( current
, "wait_process: no process is being created\n" );
779 release_object( current
->info
);
780 current
->info
= NULL
;
784 struct object
*obj
= ¤t
->info
->obj
;
785 sleep_on( 1, &obj
, SELECT_TIMEOUT
, req
->timeout
, build_wait_process_reply
);
789 /* initialize a new process */
790 DECL_HANDLER(init_process
)
792 if (!current
->unix_pid
)
794 fatal_protocol_error( current
, "init_process: init_thread not called yet\n" );
797 current
->process
->ldt_copy
= req
->ldt_copy
;
798 current
->process
->ldt_flags
= req
->ldt_flags
;
799 init_process( req
->ppid
, req
);
802 /* signal the end of the process initialization */
803 DECL_HANDLER(init_process_done
)
805 struct process
*process
= current
->process
;
806 if (!process
->init_event
)
808 fatal_protocol_error( current
, "init_process_done: no event\n" );
811 process
->exe
.base
= req
->module
;
812 generate_startup_debug_events( current
->process
, req
->entry
);
813 set_event( process
->init_event
);
814 release_object( process
->init_event
);
815 process
->init_event
= NULL
;
816 if (current
->suspend
+ current
->process
->suspend
> 0) stop_thread( current
);
817 req
->debugged
= (current
->process
->debugger
!= 0);
820 /* open a handle to a process */
821 DECL_HANDLER(open_process
)
823 struct process
*process
= get_process_from_id( req
->pid
);
827 req
->handle
= alloc_handle( current
->process
, process
, req
->access
, req
->inherit
);
828 release_object( process
);
832 /* terminate a process */
833 DECL_HANDLER(terminate_process
)
835 struct process
*process
;
837 if ((process
= get_process_from_handle( req
->handle
, PROCESS_TERMINATE
)))
839 req
->self
= (current
->process
== process
);
840 kill_process( process
, current
, req
->exit_code
);
841 release_object( process
);
845 /* fetch information about a process */
846 DECL_HANDLER(get_process_info
)
848 struct process
*process
;
850 if ((process
= get_process_from_handle( req
->handle
, PROCESS_QUERY_INFORMATION
)))
852 get_process_info( process
, req
);
853 release_object( process
);
857 /* set information about a process */
858 DECL_HANDLER(set_process_info
)
860 struct process
*process
;
862 if ((process
= get_process_from_handle( req
->handle
, PROCESS_SET_INFORMATION
)))
864 set_process_info( process
, req
);
865 release_object( process
);
869 /* read data from a process address space */
870 DECL_HANDLER(read_process_memory
)
872 struct process
*process
;
874 if ((process
= get_process_from_handle( req
->handle
, PROCESS_VM_READ
)))
876 read_process_memory( process
, req
->addr
, req
->len
,
877 get_req_size( req
, req
->data
, sizeof(int) ), req
->data
);
878 release_object( process
);
882 /* write data to a process address space */
883 DECL_HANDLER(write_process_memory
)
885 struct process
*process
;
887 if ((process
= get_process_from_handle( req
->handle
, PROCESS_VM_WRITE
)))
889 write_process_memory( process
, req
->addr
, req
->len
,
890 get_req_size( req
, req
->data
, sizeof(int) ),
891 req
->first_mask
, req
->last_mask
, req
->data
);
892 release_object( process
);
896 /* notify the server that a dll has been loaded */
897 DECL_HANDLER(load_dll
)
899 struct process_dll
*dll
;
900 struct file
*file
= NULL
;
902 if ((req
->handle
!= -1) &&
903 !(file
= get_file_obj( current
->process
, req
->handle
, GENERIC_READ
))) return;
905 if ((dll
= process_load_dll( current
->process
, file
, req
->base
)))
907 dll
->dbg_offset
= req
->dbg_offset
;
908 dll
->dbg_size
= req
->dbg_size
;
909 dll
->name
= req
->name
;
910 /* only generate event if initialization is done */
911 if (!current
->process
->init_event
)
912 generate_debug_event( current
, LOAD_DLL_DEBUG_EVENT
, dll
);
914 if (file
) release_object( file
);
917 /* notify the server that a dll is being unloaded */
918 DECL_HANDLER(unload_dll
)
920 process_unload_dll( current
->process
, req
->base
);