Add shell support for deleting files using the Delete key.
[wine/dcerpc.git] / server / process.c
blob21a50caf338a9b876ecf12c2b119738044021a29
1 /*
2 * Server-side process management
4 * Copyright (C) 1998 Alexandre Julliard
5 */
7 #include "config.h"
9 #include <assert.h>
10 #include <errno.h>
11 #include <limits.h>
12 #include <signal.h>
13 #include <string.h>
14 #include <stdio.h>
15 #include <stdlib.h>
16 #include <sys/time.h>
17 #ifdef HAVE_SYS_SOCKET_H
18 # include <sys/socket.h>
19 #endif
20 #include <unistd.h>
22 #include "winbase.h"
23 #include "winnt.h"
25 #include "handle.h"
26 #include "process.h"
27 #include "thread.h"
28 #include "request.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_get_fd, /* get_fd */
52 no_flush, /* flush */
53 no_get_file_info, /* get_file_info */
54 process_destroy /* destroy */
57 /* process startup info */
59 struct startup_info
61 struct object obj; /* object header */
62 int inherit_all; /* inherit all handles from parent */
63 int create_flags; /* creation flags */
64 int start_flags; /* flags from startup info */
65 handle_t hstdin; /* handle for stdin */
66 handle_t hstdout; /* handle for stdout */
67 handle_t hstderr; /* handle for stderr */
68 int cmd_show; /* main window show mode */
69 struct file *exe_file; /* file handle for main exe */
70 char *filename; /* file name for main exe */
71 struct thread *owner; /* owner thread (the one that created the new process) */
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_get_fd, /* get_fd */
91 no_flush, /* flush */
92 no_get_file_info, /* get_file_info */
93 startup_info_destroy /* destroy */
97 /* set the console and stdio handles for a newly created process */
98 static int set_process_console( struct process *process, struct process *parent,
99 struct startup_info *info, struct init_process_request *req )
101 if (process->create_flags & CREATE_NEW_CONSOLE)
103 if (!alloc_console( process )) return 0;
105 else if (parent && !(process->create_flags & DETACHED_PROCESS))
107 if (parent->console_in) process->console_in = grab_object( parent->console_in );
108 if (parent->console_out) process->console_out = grab_object( parent->console_out );
110 if (parent)
112 if (!info->inherit_all && !(info->start_flags & STARTF_USESTDHANDLES))
114 /* duplicate the handle from the parent into this process */
115 req->hstdin = duplicate_handle( parent, info->hstdin, process,
116 0, TRUE, DUPLICATE_SAME_ACCESS );
117 req->hstdout = duplicate_handle( parent, info->hstdout, process,
118 0, TRUE, DUPLICATE_SAME_ACCESS );
119 req->hstderr = duplicate_handle( parent, info->hstderr, process,
120 0, TRUE, DUPLICATE_SAME_ACCESS );
122 else
124 req->hstdin = info->hstdin;
125 req->hstdout = info->hstdout;
126 req->hstderr = info->hstderr;
129 else
131 /* no parent, use handles to the console for stdio */
132 req->hstdin = alloc_handle( process, process->console_in,
133 GENERIC_READ | GENERIC_WRITE | SYNCHRONIZE, 1 );
134 req->hstdout = alloc_handle( process, process->console_out,
135 GENERIC_READ | GENERIC_WRITE | SYNCHRONIZE, 1 );
136 req->hstderr = alloc_handle( process, process->console_out,
137 GENERIC_READ | GENERIC_WRITE | SYNCHRONIZE, 1 );
139 /* some handles above may have been invalid; this is not an error */
140 if (get_error() == STATUS_INVALID_HANDLE) clear_error();
141 return 1;
144 /* create a new process and its main thread */
145 struct thread *create_process( int fd )
147 struct process *process;
148 struct thread *thread = NULL;
150 if (!(process = alloc_object( &process_ops, -1 )))
152 close( fd );
153 return NULL;
155 process->next = NULL;
156 process->prev = NULL;
157 process->thread_list = NULL;
158 process->debugger = NULL;
159 process->handles = NULL;
160 process->exit_code = STILL_ACTIVE;
161 process->running_threads = 0;
162 process->priority = NORMAL_PRIORITY_CLASS;
163 process->affinity = 1;
164 process->suspend = 0;
165 process->create_flags = 0;
166 process->console_in = NULL;
167 process->console_out = NULL;
168 process->init_event = NULL;
169 process->idle_event = NULL;
170 process->queue = NULL;
171 process->atom_table = NULL;
172 process->ldt_copy = NULL;
173 process->exe.next = NULL;
174 process->exe.prev = NULL;
175 process->exe.file = NULL;
176 process->exe.dbg_offset = 0;
177 process->exe.dbg_size = 0;
178 gettimeofday( &process->start_time, NULL );
179 if ((process->next = first_process) != NULL) process->next->prev = process;
180 first_process = process;
182 /* create the init done event */
183 if (!(process->init_event = create_event( NULL, 0, 1, 0 ))) goto error;
185 /* create the main thread */
186 if (!(thread = create_thread( fd, process ))) goto error;
188 release_object( process );
189 return thread;
191 error:
192 if (thread) release_object( thread );
193 release_object( process );
194 return NULL;
197 /* initialize the current process and fill in the request */
198 static void init_process( int ppid, struct init_process_request *req )
200 struct process *process = current->process;
201 struct thread *parent_thread = get_thread_from_pid( ppid );
202 struct process *parent = NULL;
203 struct startup_info *info = NULL;
205 if (parent_thread)
207 parent = parent_thread->process;
208 info = parent_thread->info;
209 if (!info)
211 fatal_protocol_error( current, "init_process: parent but no info\n" );
212 return;
214 if (info->thread)
216 fatal_protocol_error( current, "init_process: called twice?\n" );
217 return;
221 /* set the process flags */
222 process->create_flags = info ? info->create_flags : CREATE_NEW_CONSOLE;
224 /* create the handle table */
225 if (parent && info->inherit_all)
226 process->handles = copy_handle_table( process, parent );
227 else
228 process->handles = alloc_handle_table( process, 0 );
229 if (!process->handles) goto error;
231 /* retrieve the main exe file */
232 req->exe_file = 0;
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 )))
237 goto error;
240 /* set the process console */
241 if (!set_process_console( process, parent, info, req )) goto error;
243 if (parent)
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++;
255 if (info)
257 size_t size = strlen(info->filename);
258 if (size > get_req_data_size(req)) size = get_req_data_size(req);
259 req->start_flags = info->start_flags;
260 req->cmd_show = info->cmd_show;
261 memcpy( get_req_data(req), info->filename, size );
262 set_req_data_size( req, size );
263 info->process = (struct process *)grab_object( process );
264 info->thread = (struct thread *)grab_object( current );
265 wake_up( &info->obj, 0 );
267 else
269 req->start_flags = STARTF_USESTDHANDLES;
270 req->cmd_show = 0;
271 set_req_data_size( req, 0 );
273 req->create_flags = process->create_flags;
274 req->server_start = server_start_ticks;
275 error:
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,
304 process->handles );
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 );
322 if (info->owner)
324 info->owner->info = NULL;
325 release_object( info->owner );
329 static void startup_info_dump( struct object *obj, int verbose )
331 struct startup_info *info = (struct startup_info *)obj;
332 assert( obj->ops == &startup_info_ops );
334 fprintf( stderr, "Startup info flags=%x in=%d out=%d err=%d name='%s'\n",
335 info->start_flags, info->hstdin, info->hstdout, info->hstderr, info->filename );
338 static int startup_info_signaled( struct object *obj, struct thread *thread )
340 struct startup_info *info = (struct startup_info *)obj;
341 return (info->thread != NULL);
345 /* get a process from an id (and increment the refcount) */
346 struct process *get_process_from_id( void *id )
348 struct process *p = first_process;
349 while (p && (p != id)) p = p->next;
350 if (p) grab_object( p );
351 else set_error( STATUS_INVALID_PARAMETER );
352 return p;
355 /* get a process from a handle (and increment the refcount) */
356 struct process *get_process_from_handle( handle_t handle, unsigned int access )
358 return (struct process *)get_handle_obj( current->process, handle,
359 access, &process_ops );
362 /* add a dll to a process list */
363 static struct process_dll *process_load_dll( struct process *process, struct file *file,
364 void *base )
366 struct process_dll *dll;
368 /* make sure we don't already have one with the same base address */
369 for (dll = process->exe.next; dll; dll = dll->next) if (dll->base == base)
371 set_error( STATUS_INVALID_PARAMETER );
372 return NULL;
375 if ((dll = mem_alloc( sizeof(*dll) )))
377 dll->prev = &process->exe;
378 dll->file = NULL;
379 dll->base = base;
380 if (file) dll->file = (struct file *)grab_object( file );
381 if ((dll->next = process->exe.next)) dll->next->prev = dll;
382 process->exe.next = dll;
384 return dll;
387 /* remove a dll from a process list */
388 static void process_unload_dll( struct process *process, void *base )
390 struct process_dll *dll;
392 for (dll = process->exe.next; dll; dll = dll->next)
394 if (dll->base == base)
396 if (dll->file) release_object( dll->file );
397 if (dll->next) dll->next->prev = dll->prev;
398 if (dll->prev) dll->prev->next = dll->next;
399 free( dll );
400 generate_debug_event( current, UNLOAD_DLL_DEBUG_EVENT, base );
401 return;
404 set_error( STATUS_INVALID_PARAMETER );
407 /* a process has been killed (i.e. its last thread died) */
408 static void process_killed( struct process *process )
410 assert( !process->thread_list );
411 gettimeofday( &process->end_time, NULL );
412 if (process->handles) release_object( process->handles );
413 process->handles = NULL;
414 free_console( process );
415 while (process->exe.next)
417 struct process_dll *dll = process->exe.next;
418 process->exe.next = dll->next;
419 if (dll->file) release_object( dll->file );
420 free( dll );
422 if (process->exe.file) release_object( process->exe.file );
423 process->exe.file = NULL;
424 wake_up( &process->obj, 0 );
425 if (!--running_processes)
427 /* last process died, close global handles */
428 close_global_handles();
429 /* this will cause the select loop to terminate */
430 if (!persistent_server) close_master_socket();
434 /* add a thread to a process running threads list */
435 void add_process_thread( struct process *process, struct thread *thread )
437 thread->proc_next = process->thread_list;
438 thread->proc_prev = NULL;
439 if (thread->proc_next) thread->proc_next->proc_prev = thread;
440 process->thread_list = thread;
441 if (!process->running_threads++) running_processes++;
442 grab_object( thread );
445 /* remove a thread from a process running threads list */
446 void remove_process_thread( struct process *process, struct thread *thread )
448 assert( process->running_threads > 0 );
449 assert( process->thread_list );
451 if (thread->proc_next) thread->proc_next->proc_prev = thread->proc_prev;
452 if (thread->proc_prev) thread->proc_prev->proc_next = thread->proc_next;
453 else process->thread_list = thread->proc_next;
455 if (!--process->running_threads)
457 /* we have removed the last running thread, exit the process */
458 process->exit_code = thread->exit_code;
459 generate_debug_event( thread, EXIT_PROCESS_DEBUG_EVENT, process );
460 process_killed( process );
462 else generate_debug_event( thread, EXIT_THREAD_DEBUG_EVENT, thread );
463 release_object( thread );
466 /* suspend all the threads of a process */
467 void suspend_process( struct process *process )
469 if (!process->suspend++)
471 struct thread *thread = process->thread_list;
472 for (; thread; thread = thread->proc_next)
474 if (!thread->suspend) stop_thread( thread );
479 /* resume all the threads of a process */
480 void resume_process( struct process *process )
482 assert (process->suspend > 0);
483 if (!--process->suspend)
485 struct thread *thread = process->thread_list;
486 for (; thread; thread = thread->proc_next)
488 if (!thread->suspend) continue_thread( thread );
493 /* kill a process on the spot */
494 static void kill_process( struct process *process, struct thread *skip, int exit_code )
496 struct thread *thread = process->thread_list;
497 while (thread)
499 struct thread *next = thread->proc_next;
500 thread->exit_code = exit_code;
501 if (thread != skip) kill_thread( thread, 1 );
502 thread = next;
506 /* kill all processes being debugged by a given thread */
507 void kill_debugged_processes( struct thread *debugger, int exit_code )
509 for (;;) /* restart from the beginning of the list every time */
511 struct process *process = first_process;
512 /* find the first process being debugged by 'debugger' and still running */
513 while (process && (process->debugger != debugger || !process->running_threads))
514 process = process->next;
515 if (!process) return;
516 process->debugger = NULL;
517 kill_process( process, NULL, exit_code );
521 /* get all information about a process */
522 static void get_process_info( struct process *process, struct get_process_info_request *req )
524 req->pid = process;
525 req->debugged = (process->debugger != 0);
526 req->exit_code = process->exit_code;
527 req->priority = process->priority;
528 req->process_affinity = process->affinity;
529 req->system_affinity = 1;
532 /* set all information about a process */
533 static void set_process_info( struct process *process,
534 struct set_process_info_request *req )
536 if (req->mask & SET_PROCESS_INFO_PRIORITY)
537 process->priority = req->priority;
538 if (req->mask & SET_PROCESS_INFO_AFFINITY)
540 if (req->affinity != 1) set_error( STATUS_INVALID_PARAMETER );
541 else process->affinity = req->affinity;
545 /* read data from a process memory space */
546 /* len is the total size (in ints), max is the size we can actually store in the output buffer */
547 /* we read the total size in all cases to check for permissions */
548 static void read_process_memory( struct process *process, const int *addr,
549 size_t len, size_t max, int *dest )
551 struct thread *thread = process->thread_list;
553 if ((unsigned int)addr % sizeof(int)) /* address must be aligned */
555 set_error( STATUS_INVALID_PARAMETER );
556 return;
558 if (!thread) /* process is dead */
560 set_error( STATUS_ACCESS_DENIED );
561 return;
563 if (suspend_for_ptrace( thread ))
565 while (len > 0 && max)
567 if (read_thread_int( thread, addr++, dest++ ) == -1) goto done;
568 max--;
569 len--;
571 /* check the rest for read permission */
572 if (len > 0)
574 int dummy, page = get_page_size() / sizeof(int);
575 while (len >= page)
577 addr += page;
578 len -= page;
579 if (read_thread_int( thread, addr - 1, &dummy ) == -1) goto done;
581 if (len && (read_thread_int( thread, addr + len - 1, &dummy ) == -1)) goto done;
583 done:
584 resume_thread( thread );
588 /* write data to a process memory space */
589 /* len is the total size (in ints), max is the size we can actually read from the input buffer */
590 /* we check the total size for write permissions */
591 static void write_process_memory( struct process *process, int *addr, size_t len,
592 size_t max, unsigned int first_mask,
593 unsigned int last_mask, const int *src )
595 struct thread *thread = process->thread_list;
597 if (!len || ((unsigned int)addr % sizeof(int))) /* address must be aligned */
599 set_error( STATUS_INVALID_PARAMETER );
600 return;
602 if (!thread) /* process is dead */
604 set_error( STATUS_ACCESS_DENIED );
605 return;
607 if (suspend_for_ptrace( thread ))
609 /* first word is special */
610 if (len > 1)
612 if (write_thread_int( thread, addr++, *src++, first_mask ) == -1) goto done;
613 len--;
614 max--;
616 else last_mask &= first_mask;
618 while (len > 1 && max)
620 if (write_thread_int( thread, addr++, *src++, ~0 ) == -1) goto done;
621 max--;
622 len--;
625 if (max)
627 /* last word is special too */
628 if (write_thread_int( thread, addr, *src, last_mask ) == -1) goto done;
630 else
632 /* check the rest for write permission */
633 int page = get_page_size() / sizeof(int);
634 while (len >= page)
636 addr += page;
637 len -= page;
638 if (write_thread_int( thread, addr - 1, 0, 0 ) == -1) goto done;
640 if (len && (write_thread_int( thread, addr + len - 1, 0, 0 ) == -1)) goto done;
642 done:
643 resume_thread( thread );
647 /* take a snapshot of currently running processes */
648 struct process_snapshot *process_snap( int *count )
650 struct process_snapshot *snapshot, *ptr;
651 struct process *process;
652 if (!running_processes) return NULL;
653 if (!(snapshot = mem_alloc( sizeof(*snapshot) * running_processes )))
654 return NULL;
655 ptr = snapshot;
656 for (process = first_process; process; process = process->next)
658 if (!process->running_threads) continue;
659 ptr->process = process;
660 ptr->threads = process->running_threads;
661 ptr->count = process->obj.refcount;
662 ptr->priority = process->priority;
663 grab_object( process );
664 ptr++;
666 *count = running_processes;
667 return snapshot;
670 /* take a snapshot of the modules of a process */
671 struct module_snapshot *module_snap( struct process *process, int *count )
673 struct module_snapshot *snapshot, *ptr;
674 struct process_dll *dll;
675 int total = 0;
677 for (dll = &process->exe; dll; dll = dll->next) total++;
678 if (!(snapshot = mem_alloc( sizeof(*snapshot) * total ))) return NULL;
680 for (ptr = snapshot, dll = &process->exe; dll; dll = dll->next, ptr++)
682 ptr->base = dll->base;
684 *count = total;
685 return snapshot;
689 /* create a new process */
690 DECL_HANDLER(new_process)
692 size_t len = get_req_data_size( req );
693 struct startup_info *info;
695 if (current->info)
697 fatal_protocol_error( current, "new_process: another process is being created\n" );
698 return;
701 /* build the startup info for a new process */
702 if (!(info = alloc_object( &startup_info_ops, -1 ))) return;
703 info->inherit_all = req->inherit_all;
704 info->create_flags = req->create_flags;
705 info->start_flags = req->start_flags;
706 info->hstdin = req->hstdin;
707 info->hstdout = req->hstdout;
708 info->hstderr = req->hstderr;
709 info->cmd_show = req->cmd_show;
710 info->exe_file = NULL;
711 info->filename = NULL;
712 info->owner = (struct thread *)grab_object( current );
713 info->process = NULL;
714 info->thread = NULL;
716 if (req->exe_file &&
717 !(info->exe_file = get_file_obj( current->process, req->exe_file, GENERIC_READ )))
718 goto done;
720 if (!(info->filename = mem_alloc( len + 1 ))) goto done;
722 memcpy( info->filename, get_req_data(req), len );
723 info->filename[len] = 0;
724 current->info = info;
725 req->info = alloc_handle( current->process, info, SYNCHRONIZE, FALSE );
727 done:
728 release_object( info );
731 /* Retrieve information about a newly started process */
732 DECL_HANDLER(get_new_process_info)
734 struct startup_info *info;
736 req->event = 0;
738 if ((info = (struct startup_info *)get_handle_obj( current->process, req->info,
739 0, &startup_info_ops )))
741 req->pid = get_process_id( info->process );
742 req->tid = get_thread_id( info->thread );
743 req->phandle = alloc_handle( current->process, info->process,
744 PROCESS_ALL_ACCESS, req->pinherit );
745 req->thandle = alloc_handle( current->process, info->thread,
746 THREAD_ALL_ACCESS, req->tinherit );
747 if (info->process->init_event)
748 req->event = alloc_handle( current->process, info->process->init_event,
749 EVENT_ALL_ACCESS, 0 );
750 release_object( info );
752 else
754 req->pid = 0;
755 req->tid = 0;
756 req->phandle = 0;
757 req->thandle = 0;
761 /* initialize a new process */
762 DECL_HANDLER(init_process)
764 if (!current->unix_pid)
766 fatal_protocol_error( current, "init_process: init_thread not called yet\n" );
767 return;
769 current->process->ldt_copy = req->ldt_copy;
770 init_process( req->ppid, req );
773 /* signal the end of the process initialization */
774 DECL_HANDLER(init_process_done)
776 struct file *file;
777 struct process *process = current->process;
778 if (!process->init_event)
780 fatal_protocol_error( current, "init_process_done: no event\n" );
781 return;
783 process->exe.base = req->module;
784 process->exe.name = req->name;
786 if (req->exe_file && (file = get_file_obj( current->process, req->exe_file, GENERIC_READ )))
788 if (process->exe.file) release_object( process->exe.file );
789 process->exe.file = file;
791 generate_startup_debug_events( current->process, req->entry );
792 set_event( process->init_event );
793 release_object( process->init_event );
794 process->init_event = NULL;
795 if (req->gui) process->idle_event = create_event( NULL, 0, 1, 0 );
796 if (current->suspend + current->process->suspend > 0) stop_thread( current );
797 req->debugged = (current->process->debugger != 0);
800 /* open a handle to a process */
801 DECL_HANDLER(open_process)
803 struct process *process = get_process_from_id( req->pid );
804 req->handle = 0;
805 if (process)
807 req->handle = alloc_handle( current->process, process, req->access, req->inherit );
808 release_object( process );
812 /* terminate a process */
813 DECL_HANDLER(terminate_process)
815 struct process *process;
817 if ((process = get_process_from_handle( req->handle, PROCESS_TERMINATE )))
819 req->self = (current->process == process);
820 kill_process( process, current, req->exit_code );
821 release_object( process );
825 /* fetch information about a process */
826 DECL_HANDLER(get_process_info)
828 struct process *process;
830 if ((process = get_process_from_handle( req->handle, PROCESS_QUERY_INFORMATION )))
832 get_process_info( process, req );
833 release_object( process );
837 /* set information about a process */
838 DECL_HANDLER(set_process_info)
840 struct process *process;
842 if ((process = get_process_from_handle( req->handle, PROCESS_SET_INFORMATION )))
844 set_process_info( process, req );
845 release_object( process );
849 /* read data from a process address space */
850 DECL_HANDLER(read_process_memory)
852 struct process *process;
854 if ((process = get_process_from_handle( req->handle, PROCESS_VM_READ )))
856 size_t maxlen = get_req_data_size(req) / sizeof(int);
857 read_process_memory( process, req->addr, req->len, maxlen, get_req_data(req) );
858 release_object( process );
862 /* write data to a process address space */
863 DECL_HANDLER(write_process_memory)
865 struct process *process;
867 if ((process = get_process_from_handle( req->handle, PROCESS_VM_WRITE )))
869 size_t maxlen = get_req_data_size(req) / sizeof(int);
870 write_process_memory( process, req->addr, req->len, maxlen,
871 req->first_mask, req->last_mask, get_req_data(req) );
872 release_object( process );
876 /* notify the server that a dll has been loaded */
877 DECL_HANDLER(load_dll)
879 struct process_dll *dll;
880 struct file *file = NULL;
882 if (req->handle &&
883 !(file = get_file_obj( current->process, req->handle, GENERIC_READ ))) return;
885 if ((dll = process_load_dll( current->process, file, req->base )))
887 dll->dbg_offset = req->dbg_offset;
888 dll->dbg_size = req->dbg_size;
889 dll->name = req->name;
890 /* only generate event if initialization is done */
891 if (!current->process->init_event)
892 generate_debug_event( current, LOAD_DLL_DEBUG_EVENT, dll );
894 if (file) release_object( file );
897 /* notify the server that a dll is being unloaded */
898 DECL_HANDLER(unload_dll)
900 process_unload_dll( current->process, req->base );
903 /* wait for a process to start waiting on input */
904 /* FIXME: only returns event for now, wait is done in the client */
905 DECL_HANDLER(wait_input_idle)
907 struct process *process;
909 req->event = 0;
910 if ((process = get_process_from_handle( req->handle, PROCESS_QUERY_INFORMATION )))
912 if (process->idle_event && process != current->process && process->queue != current->queue)
913 req->event = alloc_handle( current->process, process->idle_event,
914 EVENT_ALL_ACCESS, 0 );
915 release_object( process );