blob: a1d03d39a8a76bee9ac5b062b672f231772ab4b5 [file] [log] [blame]
Alexandre Julliard642d3131998-07-12 19:29:36 +00001/*
2 * Server-side process management
3 *
4 * Copyright (C) 1998 Alexandre Julliard
Alexandre Julliard0799c1a2002-03-09 23:29:33 +00005 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Alexandre Julliard642d3131998-07-12 19:29:36 +000019 */
20
Patrik Stridvallfb32c7b2000-01-29 21:02:19 +000021#include "config.h"
Alexandre Julliard5769d1d2002-04-26 19:05:15 +000022#include "wine/port.h"
Patrik Stridvallfb32c7b2000-01-29 21:02:19 +000023
Alexandre Julliard642d3131998-07-12 19:29:36 +000024#include <assert.h>
Alexandre Julliard767e6f61998-08-09 12:47:43 +000025#include <limits.h>
Alexandre Julliard3da5f841999-05-16 16:54:54 +000026#include <signal.h>
Alexandre Julliard85ed45e1998-08-22 19:03:56 +000027#include <string.h>
Alexandre Julliarde37c6e12003-09-05 23:08:26 +000028#include <stdarg.h>
Alexandre Julliard767e6f61998-08-09 12:47:43 +000029#include <stdio.h>
Alexandre Julliard642d3131998-07-12 19:29:36 +000030#include <stdlib.h>
Alexandre Julliard767e6f61998-08-09 12:47:43 +000031#include <sys/time.h>
Patrik Stridvallfb32c7b2000-01-29 21:02:19 +000032#ifdef HAVE_SYS_SOCKET_H
33# include <sys/socket.h>
34#endif
Alexandre Julliard767e6f61998-08-09 12:47:43 +000035#include <unistd.h>
Steven Edwards57279182005-03-04 12:38:36 +000036#ifdef HAVE_POLL_H
37#include <poll.h>
38#endif
Alexandre Julliard767e6f61998-08-09 12:47:43 +000039
Alexandre Julliarde37c6e12003-09-05 23:08:26 +000040#include "windef.h"
Alexandre Julliard767e6f61998-08-09 12:47:43 +000041#include "winnt.h"
Alexandre Julliard642d3131998-07-12 19:29:36 +000042
Alexandre Julliard863637b2003-01-30 00:26:44 +000043#include "file.h"
Alexandre Julliard43c190e1999-05-15 10:48:19 +000044#include "handle.h"
45#include "process.h"
46#include "thread.h"
Alexandre Julliard5bc78081999-06-22 17:26:53 +000047#include "request.h"
Eric Pouech0b83d4c2001-11-23 23:04:58 +000048#include "console.h"
Alexandre Julliardbfce1512003-12-10 04:08:06 +000049#include "user.h"
Robert Shearmand2ea92d2005-04-22 21:17:15 +000050#include "security.h"
Alexandre Julliard642d3131998-07-12 19:29:36 +000051
Alexandre Julliardf692d441999-03-21 19:23:54 +000052/* process structure */
Alexandre Julliard43c190e1999-05-15 10:48:19 +000053
Alexandre Julliard48c0d512005-02-25 19:31:26 +000054static struct list process_list = LIST_INIT(process_list);
Alexandre Julliardfdc92ba1999-02-14 18:03:15 +000055static int running_processes;
Alexandre Julliard642d3131998-07-12 19:29:36 +000056
57/* process operations */
58
Alexandre Julliard338e7571998-12-27 15:28:54 +000059static void process_dump( struct object *obj, int verbose );
Alexandre Julliard85ed45e1998-08-22 19:03:56 +000060static int process_signaled( struct object *obj, struct thread *thread );
Alexandre Julliardcf27a7f2003-02-14 20:27:09 +000061static void process_poll_event( struct fd *fd, int event );
Alexandre Julliard338e7571998-12-27 15:28:54 +000062static void process_destroy( struct object *obj );
Alexandre Julliard642d3131998-07-12 19:29:36 +000063
64static const struct object_ops process_ops =
65{
Alexandre Julliard1dca5e22000-01-01 00:56:27 +000066 sizeof(struct process), /* size */
67 process_dump, /* dump */
68 add_queue, /* add_queue */
69 remove_queue, /* remove_queue */
70 process_signaled, /* signaled */
71 no_satisfied, /* satisfied */
Alexandre Julliardb9b1ea92005-06-09 15:39:52 +000072 no_signal, /* signal */
Alexandre Julliard863637b2003-01-30 00:26:44 +000073 no_get_fd, /* get_fd */
Alexandre Julliardb9b1ea92005-06-09 15:39:52 +000074 no_close_handle, /* close_handle */
Alexandre Julliard863637b2003-01-30 00:26:44 +000075 process_destroy /* destroy */
76};
77
78static const struct fd_ops process_fd_ops =
79{
Alexandre Julliard1dca5e22000-01-01 00:56:27 +000080 NULL, /* get_poll_events */
Alexandre Julliardf5242402001-02-28 21:45:23 +000081 process_poll_event, /* poll_event */
Alexandre Julliard1dca5e22000-01-01 00:56:27 +000082 no_flush, /* flush */
83 no_get_file_info, /* get_file_info */
Eric Pouech46344472005-01-14 19:54:38 +000084 no_queue_async, /* queue_async */
85 no_cancel_async /* cancel async */
Alexandre Julliard642d3131998-07-12 19:29:36 +000086};
87
Alexandre Julliard5b4f3e82000-05-01 16:24:22 +000088/* process startup info */
89
90struct startup_info
Alexandre Julliard2fe57772000-01-25 01:40:27 +000091{
Alexandre Julliard5b4f3e82000-05-01 16:24:22 +000092 struct object obj; /* object header */
Alexandre Julliard77c8b1d2003-02-24 20:51:50 +000093 struct list entry; /* entry in list of startup infos */
Alexandre Julliard5b4f3e82000-05-01 16:24:22 +000094 int inherit_all; /* inherit all handles from parent */
Alexandre Julliard01caa5e2005-07-12 20:27:09 +000095 unsigned int create_flags; /* creation flags */
Alexandre Julliardbaf0a062003-03-11 01:48:53 +000096 int unix_pid; /* Unix pid of new process */
Alexandre Julliard51885742002-05-30 20:12:58 +000097 obj_handle_t hstdin; /* handle for stdin */
98 obj_handle_t hstdout; /* handle for stdout */
99 obj_handle_t hstderr; /* handle for stderr */
Alexandre Julliardd27624b2000-05-03 18:42:40 +0000100 struct file *exe_file; /* file handle for main exe */
Alexandre Julliarde9936d92001-01-26 00:22:26 +0000101 struct thread *owner; /* owner thread (the one that created the new process) */
Alexandre Julliard5b4f3e82000-05-01 16:24:22 +0000102 struct process *process; /* created process */
103 struct thread *thread; /* created thread */
Alexandre Julliard6543a652002-03-29 18:28:56 +0000104 size_t data_size; /* size of startup data */
Alexandre Julliard841f8982003-10-04 04:09:41 +0000105 void *data; /* data for startup info */
Alexandre Julliard5b4f3e82000-05-01 16:24:22 +0000106};
107
108static void startup_info_dump( struct object *obj, int verbose );
109static int startup_info_signaled( struct object *obj, struct thread *thread );
110static void startup_info_destroy( struct object *obj );
111
112static const struct object_ops startup_info_ops =
113{
114 sizeof(struct startup_info), /* size */
115 startup_info_dump, /* dump */
116 add_queue, /* add_queue */
117 remove_queue, /* remove_queue */
118 startup_info_signaled, /* signaled */
119 no_satisfied, /* satisfied */
Mike McCormackf92fff62005-04-24 17:35:52 +0000120 no_signal, /* signal */
Alexandre Julliard1ab243b2000-12-19 02:12:45 +0000121 no_get_fd, /* get_fd */
Alexandre Julliardb9b1ea92005-06-09 15:39:52 +0000122 no_close_handle, /* close_handle */
Alexandre Julliard5b4f3e82000-05-01 16:24:22 +0000123 startup_info_destroy /* destroy */
124};
125
Alexandre Julliardf692d441999-03-21 19:23:54 +0000126
Alexandre Julliard77c8b1d2003-02-24 20:51:50 +0000127static struct list startup_info_list = LIST_INIT(startup_info_list);
128
Alexandre Julliard91befe12003-02-01 01:38:40 +0000129struct ptid_entry
130{
131 void *ptr; /* entry ptr */
132 unsigned int next; /* next free entry */
133};
134
135static struct ptid_entry *ptid_entries; /* array of ptid entries */
136static unsigned int used_ptid_entries; /* number of entries in use */
137static unsigned int alloc_ptid_entries; /* number of allocated entries */
138static unsigned int next_free_ptid; /* next free entry */
139static unsigned int last_free_ptid; /* last free entry */
140
141#define PTID_OFFSET 8 /* offset for first ptid value */
142
143/* allocate a new process or thread id */
144unsigned int alloc_ptid( void *ptr )
145{
146 struct ptid_entry *entry;
147 unsigned int id;
148
149 if (used_ptid_entries < alloc_ptid_entries)
150 {
151 id = used_ptid_entries + PTID_OFFSET;
152 entry = &ptid_entries[used_ptid_entries++];
153 }
154 else if (next_free_ptid)
155 {
156 id = next_free_ptid;
157 entry = &ptid_entries[id - PTID_OFFSET];
158 if (!(next_free_ptid = entry->next)) last_free_ptid = 0;
159 }
160 else /* need to grow the array */
161 {
162 unsigned int count = alloc_ptid_entries + (alloc_ptid_entries / 2);
163 if (!count) count = 64;
164 if (!(entry = realloc( ptid_entries, count * sizeof(*entry) )))
165 {
166 set_error( STATUS_NO_MEMORY );
167 return 0;
168 }
169 ptid_entries = entry;
170 alloc_ptid_entries = count;
171 id = used_ptid_entries + PTID_OFFSET;
172 entry = &ptid_entries[used_ptid_entries++];
173 }
174
175 entry->ptr = ptr;
176 return id;
177}
178
179/* free a process or thread id */
180void free_ptid( unsigned int id )
181{
182 struct ptid_entry *entry = &ptid_entries[id - PTID_OFFSET];
183
184 entry->ptr = NULL;
185 entry->next = 0;
186
187 /* append to end of free list so that we don't reuse it too early */
188 if (last_free_ptid) ptid_entries[last_free_ptid - PTID_OFFSET].next = id;
189 else next_free_ptid = id;
190
191 last_free_ptid = id;
192}
193
194/* retrieve the pointer corresponding to a process or thread id */
195void *get_ptid_entry( unsigned int id )
196{
197 if (id < PTID_OFFSET) return NULL;
198 if (id - PTID_OFFSET >= used_ptid_entries) return NULL;
199 return ptid_entries[id - PTID_OFFSET].ptr;
200}
201
Alexandre Julliard05026382005-03-01 10:56:18 +0000202/* return the main thread of the process */
203struct thread *get_process_first_thread( struct process *process )
204{
205 struct list *ptr = list_head( &process->thread_list );
206 if (!ptr) return NULL;
207 return LIST_ENTRY( ptr, struct thread, proc_entry );
208}
209
Alexandre Julliard9d802152002-05-24 21:20:27 +0000210/* set the state of the process startup info */
211static void set_process_startup_state( struct process *process, enum startup_state state )
212{
Alexandre Julliardca96de32002-05-25 21:15:03 +0000213 if (process->startup_state == STARTUP_IN_PROGRESS) process->startup_state = state;
214 if (process->startup_info)
215 {
216 wake_up( &process->startup_info->obj, 0 );
217 release_object( process->startup_info );
218 process->startup_info = NULL;
219 }
Alexandre Julliard9d802152002-05-24 21:20:27 +0000220}
221
Alexandre Julliard2fe57772000-01-25 01:40:27 +0000222/* create a new process and its main thread */
Alexandre Julliard5b4f3e82000-05-01 16:24:22 +0000223struct thread *create_process( int fd )
Alexandre Julliard642d3131998-07-12 19:29:36 +0000224{
Alexandre Julliardeb2e77f1999-06-04 19:49:54 +0000225 struct process *process;
Alexandre Julliard2fe57772000-01-25 01:40:27 +0000226 struct thread *thread = NULL;
Alexandre Julliard8859d772001-03-01 22:13:49 +0000227 int request_pipe[2];
Alexandre Julliardeb2e77f1999-06-04 19:49:54 +0000228
Alexandre Julliarde66207e2003-02-19 00:33:32 +0000229 if (!(process = alloc_object( &process_ops ))) goto error;
Eric Pouech0b83d4c2001-11-23 23:04:58 +0000230 process->parent = NULL;
Alexandre Julliard3da5f841999-05-16 16:54:54 +0000231 process->debugger = NULL;
Alexandre Julliardeb2e77f1999-06-04 19:49:54 +0000232 process->handles = NULL;
Alexandre Julliarde66207e2003-02-19 00:33:32 +0000233 process->msg_fd = NULL;
Dave Pickles717bf7e2000-02-13 16:04:14 +0000234 process->exit_code = STILL_ACTIVE;
Alexandre Julliard767e6f61998-08-09 12:47:43 +0000235 process->running_threads = 0;
Alexandre Julliard62a8b431999-01-19 17:48:23 +0000236 process->priority = NORMAL_PRIORITY_CLASS;
237 process->affinity = 1;
Alexandre Julliard3da5f841999-05-16 16:54:54 +0000238 process->suspend = 0;
Alexandre Julliardd083a7b1999-11-29 02:10:56 +0000239 process->create_flags = 0;
Eric Pouech0b83d4c2001-11-23 23:04:58 +0000240 process->console = NULL;
Alexandre Julliardca96de32002-05-25 21:15:03 +0000241 process->startup_state = STARTUP_IN_PROGRESS;
Alexandre Julliard9d802152002-05-24 21:20:27 +0000242 process->startup_info = NULL;
Alexandre Julliardc5e433a2000-05-30 19:48:18 +0000243 process->idle_event = NULL;
244 process->queue = NULL;
Alexandre Julliarde55d5932003-10-14 01:30:42 +0000245 process->peb = NULL;
Alexandre Julliard0a7c1f62000-01-27 02:54:17 +0000246 process->ldt_copy = NULL;
Alexandre Julliard1bf96e02005-06-08 18:44:50 +0000247 process->winstation = 0;
Alexandre Julliard78a3e632005-06-09 12:07:12 +0000248 process->desktop = 0;
Alexandre Julliard05f0b712000-03-09 18:18:41 +0000249 process->exe.file = NULL;
250 process->exe.dbg_offset = 0;
251 process->exe.dbg_size = 0;
Alexandre Julliardaeb56602002-03-22 00:21:23 +0000252 process->exe.namelen = 0;
253 process->exe.filename = NULL;
Robert Shearmand2ea92d2005-04-22 21:17:15 +0000254 process->token = token_create_admin();
Alexandre Julliard05026382005-03-01 10:56:18 +0000255 list_init( &process->thread_list );
Alexandre Julliardce613492003-03-18 05:04:33 +0000256 list_init( &process->locks );
Alexandre Julliardbfce1512003-12-10 04:08:06 +0000257 list_init( &process->classes );
Alexandre Julliarda9e0fb12005-03-02 10:20:09 +0000258 list_init( &process->dlls );
Eric Pouech0b83d4c2001-11-23 23:04:58 +0000259
Alexandre Julliard767e6f61998-08-09 12:47:43 +0000260 gettimeofday( &process->start_time, NULL );
Alexandre Julliard48c0d512005-02-25 19:31:26 +0000261 list_add_head( &process_list, &process->entry );
Alexandre Julliardeb2e77f1999-06-04 19:49:54 +0000262
Alexandre Julliard01caa5e2005-07-12 20:27:09 +0000263 if (!(process->id = process->group_id = alloc_ptid( process ))) goto error;
Alexandre Julliard580da242003-03-12 22:38:14 +0000264 if (!(process->msg_fd = create_anonymous_fd( &process_fd_ops, fd, &process->obj ))) goto error;
Alexandre Julliard91befe12003-02-01 01:38:40 +0000265
Alexandre Julliard7f748242000-12-26 00:30:30 +0000266 /* create the main thread */
Alexandre Julliard8859d772001-03-01 22:13:49 +0000267 if (pipe( request_pipe ) == -1)
268 {
269 file_set_error();
270 goto error;
271 }
Alexandre Julliard4144b5b2002-06-20 23:21:27 +0000272 if (send_client_fd( process, request_pipe[1], 0 ) == -1)
273 {
274 close( request_pipe[0] );
275 close( request_pipe[1] );
276 goto error;
277 }
Alexandre Julliard8859d772001-03-01 22:13:49 +0000278 close( request_pipe[1] );
279 if (!(thread = create_thread( request_pipe[0], process ))) goto error;
Alexandre Julliard7f748242000-12-26 00:30:30 +0000280
Alexandre Julliarde66207e2003-02-19 00:33:32 +0000281 set_fd_events( process->msg_fd, POLLIN ); /* start listening to events */
Alexandre Julliard2fe57772000-01-25 01:40:27 +0000282 release_object( process );
283 return thread;
Alexandre Julliardf692d441999-03-21 19:23:54 +0000284
285 error:
Alexandre Julliard4144b5b2002-06-20 23:21:27 +0000286 if (process) release_object( process );
287 /* if we failed to start our first process, close everything down */
288 if (!running_processes) close_master_socket();
Alexandre Julliardf692d441999-03-21 19:23:54 +0000289 return NULL;
Alexandre Julliard642d3131998-07-12 19:29:36 +0000290}
291
Alexandre Julliard77c8b1d2003-02-24 20:51:50 +0000292/* find the startup info for a given Unix process */
Alexandre Julliardbaf0a062003-03-11 01:48:53 +0000293inline static struct startup_info *find_startup_info( int unix_pid )
Alexandre Julliard77c8b1d2003-02-24 20:51:50 +0000294{
295 struct list *ptr;
296
297 LIST_FOR_EACH( ptr, &startup_info_list )
298 {
299 struct startup_info *info = LIST_ENTRY( ptr, struct startup_info, entry );
300 if (info->unix_pid == unix_pid) return info;
301 }
302 return NULL;
303}
304
Alexandre Julliard5b4f3e82000-05-01 16:24:22 +0000305/* initialize the current process and fill in the request */
Alexandre Julliard11ad6a02005-07-13 19:43:35 +0000306size_t init_process( struct thread *thread )
Alexandre Julliard5b4f3e82000-05-01 16:24:22 +0000307{
Alexandre Julliard0424f382005-07-13 12:12:43 +0000308 struct process *process = thread->process;
Alexandre Julliard77c8b1d2003-02-24 20:51:50 +0000309 struct thread *parent_thread = NULL;
Alexandre Julliard5b4f3e82000-05-01 16:24:22 +0000310 struct process *parent = NULL;
Alexandre Julliard0424f382005-07-13 12:12:43 +0000311 struct startup_info *info;
Alexandre Julliard5b4f3e82000-05-01 16:24:22 +0000312
Alexandre Julliard11ad6a02005-07-13 19:43:35 +0000313 if (process->startup_info) return process->startup_info->data_size; /* already initialized */
Alexandre Julliard0424f382005-07-13 12:12:43 +0000314
315 if ((info = find_startup_info( thread->unix_pid )))
Alexandre Julliard5b4f3e82000-05-01 16:24:22 +0000316 {
Alexandre Julliard11ad6a02005-07-13 19:43:35 +0000317 if (info->thread) return info->data_size; /* already initialized */
Alexandre Julliard0424f382005-07-13 12:12:43 +0000318
319 info->thread = (struct thread *)grab_object( thread );
320 info->process = (struct process *)grab_object( process );
321 process->startup_info = (struct startup_info *)grab_object( info );
322
Alexandre Julliard77c8b1d2003-02-24 20:51:50 +0000323 parent_thread = info->owner;
324 parent = parent_thread->process;
Eric Pouech0b83d4c2001-11-23 23:04:58 +0000325 process->parent = (struct process *)grab_object( parent );
Alexandre Julliard0424f382005-07-13 12:12:43 +0000326
327 /* set the process flags */
328 process->create_flags = info->create_flags;
329
330 if (info->inherit_all) process->handles = copy_handle_table( process, parent );
Alexandre Julliard5b4f3e82000-05-01 16:24:22 +0000331 }
332
Alexandre Julliard5b4f3e82000-05-01 16:24:22 +0000333 /* create the handle table */
Alexandre Julliard0424f382005-07-13 12:12:43 +0000334 if (!process->handles) process->handles = alloc_handle_table( process, 0 );
335 if (!process->handles)
336 {
337 fatal_protocol_error( thread, "Failed to allocate handle table\n" );
Alexandre Julliard11ad6a02005-07-13 19:43:35 +0000338 return 0;
Alexandre Julliard0424f382005-07-13 12:12:43 +0000339 }
Alexandre Julliard5b4f3e82000-05-01 16:24:22 +0000340
Alexandre Julliard1bf96e02005-06-08 18:44:50 +0000341 /* connect to the window station and desktop */
342 connect_process_winstation( process, NULL, 0 );
Alexandre Julliard78a3e632005-06-09 12:07:12 +0000343 connect_process_desktop( process, NULL, 0 );
Alexandre Julliard0424f382005-07-13 12:12:43 +0000344 thread->desktop = process->desktop;
345
Alexandre Julliard11ad6a02005-07-13 19:43:35 +0000346 if (!info) return 0;
Alexandre Julliard0424f382005-07-13 12:12:43 +0000347
348 /* retrieve the main exe file */
349 if (info->exe_file) process->exe.file = (struct file *)grab_object( info->exe_file );
350
351 /* thread will be actually suspended in init_done */
352 if (info->create_flags & CREATE_SUSPENDED) thread->suspend++;
Alexandre Julliard1bf96e02005-06-08 18:44:50 +0000353
Alexandre Julliard5b4f3e82000-05-01 16:24:22 +0000354 /* set the process console */
Alexandre Julliard0424f382005-07-13 12:12:43 +0000355 if (!(info->create_flags & (DETACHED_PROCESS | CREATE_NEW_CONSOLE)))
Alexandre Julliard01caa5e2005-07-12 20:27:09 +0000356 {
357 /* FIXME: some better error checking should be done...
358 * like if hConOut and hConIn are console handles, then they should be on the same
359 * physical console
360 */
361 inherit_console( parent_thread, process, info->inherit_all ? info->hstdin : 0 );
362 }
Alexandre Julliard5b4f3e82000-05-01 16:24:22 +0000363
Alexandre Julliard0424f382005-07-13 12:12:43 +0000364 /* attach to the debugger if requested */
365 if (process->create_flags & (DEBUG_PROCESS | DEBUG_ONLY_THIS_PROCESS))
366 set_process_debugger( process, parent_thread );
367 else if (parent->debugger && !(parent->create_flags & DEBUG_ONLY_THIS_PROCESS))
368 set_process_debugger( process, parent->debugger );
Alexandre Julliard5b4f3e82000-05-01 16:24:22 +0000369
Alexandre Julliard0424f382005-07-13 12:12:43 +0000370 if (!(process->create_flags & CREATE_NEW_PROCESS_GROUP))
371 process->group_id = parent->group_id;
Alexandre Julliard11ad6a02005-07-13 19:43:35 +0000372
373 return info->data_size;
Alexandre Julliard5b4f3e82000-05-01 16:24:22 +0000374}
375
Alexandre Julliard642d3131998-07-12 19:29:36 +0000376/* destroy a process when its refcount is 0 */
Alexandre Julliard338e7571998-12-27 15:28:54 +0000377static void process_destroy( struct object *obj )
Alexandre Julliard642d3131998-07-12 19:29:36 +0000378{
379 struct process *process = (struct process *)obj;
380 assert( obj->ops == &process_ops );
381
Alexandre Julliard767e6f61998-08-09 12:47:43 +0000382 /* we can't have a thread remaining */
Alexandre Julliard05026382005-03-01 10:56:18 +0000383 assert( list_empty( &process->thread_list ));
Alexandre Julliard9d802152002-05-24 21:20:27 +0000384
385 set_process_startup_state( process, STARTUP_ABORTED );
Eric Pouech0b83d4c2001-11-23 23:04:58 +0000386 if (process->console) release_object( process->console );
387 if (process->parent) release_object( process->parent );
Alexandre Julliarde66207e2003-02-19 00:33:32 +0000388 if (process->msg_fd) release_object( process->msg_fd );
Alexandre Julliard48c0d512005-02-25 19:31:26 +0000389 list_remove( &process->entry );
Alexandre Julliardc5e433a2000-05-30 19:48:18 +0000390 if (process->idle_event) release_object( process->idle_event );
391 if (process->queue) release_object( process->queue );
Alexandre Julliard05f0b712000-03-09 18:18:41 +0000392 if (process->exe.file) release_object( process->exe.file );
Alexandre Julliardaeb56602002-03-22 00:21:23 +0000393 if (process->exe.filename) free( process->exe.filename );
Alexandre Julliard91befe12003-02-01 01:38:40 +0000394 if (process->id) free_ptid( process->id );
Mike McCormack36cd6f52003-07-24 00:07:00 +0000395 if (process->token) release_object( process->token );
Alexandre Julliard642d3131998-07-12 19:29:36 +0000396}
397
Alexandre Julliard767e6f61998-08-09 12:47:43 +0000398/* dump a process on stdout for debugging purposes */
Alexandre Julliard338e7571998-12-27 15:28:54 +0000399static void process_dump( struct object *obj, int verbose )
Alexandre Julliard767e6f61998-08-09 12:47:43 +0000400{
401 struct process *process = (struct process *)obj;
402 assert( obj->ops == &process_ops );
403
Alexandre Julliard48c0d512005-02-25 19:31:26 +0000404 fprintf( stderr, "Process id=%04x handles=%p\n", process->id, process->handles );
Alexandre Julliard767e6f61998-08-09 12:47:43 +0000405}
406
Alexandre Julliard85ed45e1998-08-22 19:03:56 +0000407static int process_signaled( struct object *obj, struct thread *thread )
408{
409 struct process *process = (struct process *)obj;
Alexandre Julliarddbc033a1999-03-13 08:58:24 +0000410 return !process->running_threads;
Alexandre Julliard85ed45e1998-08-22 19:03:56 +0000411}
412
Alexandre Julliardcf27a7f2003-02-14 20:27:09 +0000413static void process_poll_event( struct fd *fd, int event )
Alexandre Julliardf5242402001-02-28 21:45:23 +0000414{
Alexandre Julliardcf27a7f2003-02-14 20:27:09 +0000415 struct process *process = get_fd_user( fd );
416 assert( process->obj.ops == &process_ops );
Alexandre Julliardf5242402001-02-28 21:45:23 +0000417
Alexandre Julliarde66207e2003-02-19 00:33:32 +0000418 if (event & (POLLERR | POLLHUP)) set_fd_events( fd, -1 );
Alexandre Julliardf5242402001-02-28 21:45:23 +0000419 else if (event & POLLIN) receive_fd( process );
420}
421
Alexandre Julliard5b4f3e82000-05-01 16:24:22 +0000422static void startup_info_destroy( struct object *obj )
423{
424 struct startup_info *info = (struct startup_info *)obj;
425 assert( obj->ops == &startup_info_ops );
Alexandre Julliard77c8b1d2003-02-24 20:51:50 +0000426 list_remove( &info->entry );
Alexandre Julliard6543a652002-03-29 18:28:56 +0000427 if (info->data) free( info->data );
Alexandre Julliardd27624b2000-05-03 18:42:40 +0000428 if (info->exe_file) release_object( info->exe_file );
Alexandre Julliard5b4f3e82000-05-01 16:24:22 +0000429 if (info->process) release_object( info->process );
430 if (info->thread) release_object( info->thread );
Alexandre Julliard77c8b1d2003-02-24 20:51:50 +0000431 if (info->owner) release_object( info->owner );
Alexandre Julliard5b4f3e82000-05-01 16:24:22 +0000432}
433
434static void startup_info_dump( struct object *obj, int verbose )
435{
436 struct startup_info *info = (struct startup_info *)obj;
437 assert( obj->ops == &startup_info_ops );
438
Alexandre Julliardb3332d72002-10-19 01:00:59 +0000439 fprintf( stderr, "Startup info flags=%x in=%p out=%p err=%p\n",
Alexandre Julliardca96de32002-05-25 21:15:03 +0000440 info->create_flags, info->hstdin, info->hstdout, info->hstderr );
Alexandre Julliard5b4f3e82000-05-01 16:24:22 +0000441}
442
443static int startup_info_signaled( struct object *obj, struct thread *thread )
444{
445 struct startup_info *info = (struct startup_info *)obj;
Alexandre Julliardca96de32002-05-25 21:15:03 +0000446 return info->process && is_process_init_done(info->process);
Alexandre Julliard5b4f3e82000-05-01 16:24:22 +0000447}
448
Alexandre Julliard642d3131998-07-12 19:29:36 +0000449/* get a process from an id (and increment the refcount) */
Alexandre Julliard54f22872002-10-03 19:54:57 +0000450struct process *get_process_from_id( process_id_t id )
Alexandre Julliard642d3131998-07-12 19:29:36 +0000451{
Alexandre Julliard91befe12003-02-01 01:38:40 +0000452 struct object *obj = get_ptid_entry( id );
453
454 if (obj && obj->ops == &process_ops) return (struct process *)grab_object( obj );
455 set_error( STATUS_INVALID_PARAMETER );
456 return NULL;
Alexandre Julliard642d3131998-07-12 19:29:36 +0000457}
Alexandre Julliard767e6f61998-08-09 12:47:43 +0000458
459/* get a process from a handle (and increment the refcount) */
Alexandre Julliard51885742002-05-30 20:12:58 +0000460struct process *get_process_from_handle( obj_handle_t handle, unsigned int access )
Alexandre Julliard767e6f61998-08-09 12:47:43 +0000461{
462 return (struct process *)get_handle_obj( current->process, handle,
463 access, &process_ops );
464}
465
Alexandre Julliarda9e0fb12005-03-02 10:20:09 +0000466/* find a dll from its base address */
467static inline struct process_dll *find_process_dll( struct process *process, void *base )
468{
469 struct process_dll *dll;
470
471 if (process->exe.base == base) return &process->exe;
472
473 LIST_FOR_EACH_ENTRY( dll, &process->dlls, struct process_dll, entry )
474 {
475 if (dll->base == base) return dll;
476 }
477 return NULL;
478}
479
Alexandre Julliard05f0b712000-03-09 18:18:41 +0000480/* add a dll to a process list */
481static struct process_dll *process_load_dll( struct process *process, struct file *file,
Alexandre Julliardc30cefb2003-09-30 01:04:19 +0000482 void *base, const WCHAR *filename, size_t name_len )
Alexandre Julliard05f0b712000-03-09 18:18:41 +0000483{
484 struct process_dll *dll;
485
486 /* make sure we don't already have one with the same base address */
Alexandre Julliarda9e0fb12005-03-02 10:20:09 +0000487 if (find_process_dll( process, base ))
Alexandre Julliard05f0b712000-03-09 18:18:41 +0000488 {
489 set_error( STATUS_INVALID_PARAMETER );
490 return NULL;
491 }
492
493 if ((dll = mem_alloc( sizeof(*dll) )))
494 {
Alexandre Julliard05f0b712000-03-09 18:18:41 +0000495 dll->file = NULL;
496 dll->base = base;
Alexandre Julliardaeb56602002-03-22 00:21:23 +0000497 dll->filename = NULL;
498 dll->namelen = name_len;
499 if (name_len && !(dll->filename = memdup( filename, name_len )))
500 {
501 free( dll );
502 return NULL;
503 }
Alexandre Julliard05f0b712000-03-09 18:18:41 +0000504 if (file) dll->file = (struct file *)grab_object( file );
Alexandre Julliarda9e0fb12005-03-02 10:20:09 +0000505 list_add_head( &process->dlls, &dll->entry );
Alexandre Julliard05f0b712000-03-09 18:18:41 +0000506 }
507 return dll;
508}
509
510/* remove a dll from a process list */
511static void process_unload_dll( struct process *process, void *base )
512{
Alexandre Julliarda9e0fb12005-03-02 10:20:09 +0000513 struct process_dll *dll = find_process_dll( process, base );
Alexandre Julliard05f0b712000-03-09 18:18:41 +0000514
Alexandre Julliarda9e0fb12005-03-02 10:20:09 +0000515 if (dll && dll != &process->exe)
Alexandre Julliard05f0b712000-03-09 18:18:41 +0000516 {
Alexandre Julliarda9e0fb12005-03-02 10:20:09 +0000517 if (dll->file) release_object( dll->file );
518 if (dll->filename) free( dll->filename );
519 list_remove( &dll->entry );
520 free( dll );
521 generate_debug_event( current, UNLOAD_DLL_DEBUG_EVENT, base );
Alexandre Julliard05f0b712000-03-09 18:18:41 +0000522 }
Alexandre Julliarda9e0fb12005-03-02 10:20:09 +0000523 else set_error( STATUS_INVALID_PARAMETER );
Alexandre Julliard05f0b712000-03-09 18:18:41 +0000524}
525
Alexandre Julliard40043ed2002-08-16 20:02:15 +0000526/* kill all processes */
527void kill_all_processes( struct process *skip, int exit_code )
528{
529 for (;;)
530 {
Alexandre Julliard48c0d512005-02-25 19:31:26 +0000531 struct process *process;
Alexandre Julliard40043ed2002-08-16 20:02:15 +0000532
Alexandre Julliard48c0d512005-02-25 19:31:26 +0000533 LIST_FOR_EACH_ENTRY( process, &process_list, struct process, entry )
534 {
535 if (process == skip) continue;
536 if (process->running_threads) break;
537 }
538 if (&process->entry == &process_list) break; /* no process found */
Alexandre Julliard40043ed2002-08-16 20:02:15 +0000539 kill_process( process, NULL, exit_code );
540 }
541}
542
Eric Pouech0b83d4c2001-11-23 23:04:58 +0000543/* kill all processes being attached to a console renderer */
Eric Pouech3940d8a2001-12-04 20:17:43 +0000544void kill_console_processes( struct thread *renderer, int exit_code )
Eric Pouech0b83d4c2001-11-23 23:04:58 +0000545{
546 for (;;) /* restart from the beginning of the list every time */
547 {
Alexandre Julliard48c0d512005-02-25 19:31:26 +0000548 struct process *process;
Eric Pouech0b83d4c2001-11-23 23:04:58 +0000549
550 /* find the first process being attached to 'renderer' and still running */
Alexandre Julliard48c0d512005-02-25 19:31:26 +0000551 LIST_FOR_EACH_ENTRY( process, &process_list, struct process, entry )
Eric Pouech0b83d4c2001-11-23 23:04:58 +0000552 {
Alexandre Julliard48c0d512005-02-25 19:31:26 +0000553 if (process == renderer->process) continue;
554 if (!process->running_threads) continue;
555 if (process->console && process->console->renderer == renderer) break;
Eric Pouech0b83d4c2001-11-23 23:04:58 +0000556 }
Alexandre Julliard48c0d512005-02-25 19:31:26 +0000557 if (&process->entry == &process_list) break; /* no process found */
Eric Pouech0b83d4c2001-11-23 23:04:58 +0000558 kill_process( process, NULL, exit_code );
559 }
560}
561
Alexandre Julliard767e6f61998-08-09 12:47:43 +0000562/* a process has been killed (i.e. its last thread died) */
Alexandre Julliard05f0b712000-03-09 18:18:41 +0000563static void process_killed( struct process *process )
Alexandre Julliard767e6f61998-08-09 12:47:43 +0000564{
Alexandre Julliard36b85d02005-06-29 19:29:15 +0000565 struct handle_table *handles;
Alexandre Julliarda9e0fb12005-03-02 10:20:09 +0000566 struct list *ptr;
567
Alexandre Julliard05026382005-03-01 10:56:18 +0000568 assert( list_empty( &process->thread_list ));
Alexandre Julliard767e6f61998-08-09 12:47:43 +0000569 gettimeofday( &process->end_time, NULL );
Alexandre Julliard36b85d02005-06-29 19:29:15 +0000570 handles = process->handles;
Alexandre Julliardeb2e77f1999-06-04 19:49:54 +0000571 process->handles = NULL;
Alexandre Julliard36b85d02005-06-29 19:29:15 +0000572 if (handles) release_object( handles );
Eric Pouech0b83d4c2001-11-23 23:04:58 +0000573
574 /* close the console attached to this process, if any */
Alexandre Julliardeb2e77f1999-06-04 19:49:54 +0000575 free_console( process );
Eric Pouech0b83d4c2001-11-23 23:04:58 +0000576
Alexandre Julliarda9e0fb12005-03-02 10:20:09 +0000577 while ((ptr = list_head( &process->dlls )))
Alexandre Julliard05f0b712000-03-09 18:18:41 +0000578 {
Alexandre Julliarda9e0fb12005-03-02 10:20:09 +0000579 struct process_dll *dll = LIST_ENTRY( ptr, struct process_dll, entry );
Alexandre Julliard05f0b712000-03-09 18:18:41 +0000580 if (dll->file) release_object( dll->file );
Alexandre Julliardaeb56602002-03-22 00:21:23 +0000581 if (dll->filename) free( dll->filename );
Alexandre Julliarda9e0fb12005-03-02 10:20:09 +0000582 list_remove( &dll->entry );
Alexandre Julliard05f0b712000-03-09 18:18:41 +0000583 free( dll );
584 }
Alexandre Julliardbfce1512003-12-10 04:08:06 +0000585 destroy_process_classes( process );
Alexandre Julliard5f22e7c2005-06-14 19:23:56 +0000586 remove_process_locks( process );
Alexandre Julliard9d802152002-05-24 21:20:27 +0000587 set_process_startup_state( process, STARTUP_ABORTED );
Alexandre Julliard05f0b712000-03-09 18:18:41 +0000588 if (process->exe.file) release_object( process->exe.file );
589 process->exe.file = NULL;
Alexandre Julliard85ed45e1998-08-22 19:03:56 +0000590 wake_up( &process->obj, 0 );
Alexandre Julliard4144b5b2002-06-20 23:21:27 +0000591 if (!--running_processes) close_master_socket();
Alexandre Julliard767e6f61998-08-09 12:47:43 +0000592}
593
Alexandre Julliard767e6f61998-08-09 12:47:43 +0000594/* add a thread to a process running threads list */
595void add_process_thread( struct process *process, struct thread *thread )
596{
Alexandre Julliard05026382005-03-01 10:56:18 +0000597 list_add_head( &process->thread_list, &thread->proc_entry );
Alexandre Julliardfdc92ba1999-02-14 18:03:15 +0000598 if (!process->running_threads++) running_processes++;
Alexandre Julliard767e6f61998-08-09 12:47:43 +0000599 grab_object( thread );
600}
601
602/* remove a thread from a process running threads list */
603void remove_process_thread( struct process *process, struct thread *thread )
604{
605 assert( process->running_threads > 0 );
Alexandre Julliard05026382005-03-01 10:56:18 +0000606 assert( !list_empty( &process->thread_list ));
Alexandre Julliard767e6f61998-08-09 12:47:43 +0000607
Alexandre Julliard05026382005-03-01 10:56:18 +0000608 list_remove( &thread->proc_entry );
Alexandre Julliard767e6f61998-08-09 12:47:43 +0000609
610 if (!--process->running_threads)
611 {
612 /* we have removed the last running thread, exit the process */
Alexandre Julliard05f0b712000-03-09 18:18:41 +0000613 process->exit_code = thread->exit_code;
614 generate_debug_event( thread, EXIT_PROCESS_DEBUG_EVENT, process );
615 process_killed( process );
Alexandre Julliard767e6f61998-08-09 12:47:43 +0000616 }
Alexandre Julliard05f0b712000-03-09 18:18:41 +0000617 else generate_debug_event( thread, EXIT_THREAD_DEBUG_EVENT, thread );
Alexandre Julliard767e6f61998-08-09 12:47:43 +0000618 release_object( thread );
619}
620
Alexandre Julliard3da5f841999-05-16 16:54:54 +0000621/* suspend all the threads of a process */
622void suspend_process( struct process *process )
623{
624 if (!process->suspend++)
625 {
Alexandre Julliard05026382005-03-01 10:56:18 +0000626 struct list *ptr, *next;
627
628 LIST_FOR_EACH_SAFE( ptr, next, &process->thread_list )
Alexandre Julliard3da5f841999-05-16 16:54:54 +0000629 {
Alexandre Julliard05026382005-03-01 10:56:18 +0000630 struct thread *thread = LIST_ENTRY( ptr, struct thread, proc_entry );
Alexandre Julliard0a707831999-11-08 05:31:47 +0000631 if (!thread->suspend) stop_thread( thread );
Alexandre Julliard3da5f841999-05-16 16:54:54 +0000632 }
633 }
634}
635
636/* resume all the threads of a process */
637void resume_process( struct process *process )
638{
639 assert (process->suspend > 0);
640 if (!--process->suspend)
641 {
Alexandre Julliard05026382005-03-01 10:56:18 +0000642 struct list *ptr, *next;
643
644 LIST_FOR_EACH_SAFE( ptr, next, &process->thread_list )
Alexandre Julliard3da5f841999-05-16 16:54:54 +0000645 {
Alexandre Julliard05026382005-03-01 10:56:18 +0000646 struct thread *thread = LIST_ENTRY( ptr, struct thread, proc_entry );
Alexandre Julliardd04ccb82003-03-04 22:18:43 +0000647 if (!thread->suspend) wake_thread( thread );
Alexandre Julliard3da5f841999-05-16 16:54:54 +0000648 }
649 }
650}
651
Alexandre Julliard767e6f61998-08-09 12:47:43 +0000652/* kill a process on the spot */
Alexandre Julliardf5242402001-02-28 21:45:23 +0000653void kill_process( struct process *process, struct thread *skip, int exit_code )
Alexandre Julliard767e6f61998-08-09 12:47:43 +0000654{
Alexandre Julliard05026382005-03-01 10:56:18 +0000655 struct list *ptr, *next;
Eric Pouech0b83d4c2001-11-23 23:04:58 +0000656
Alexandre Julliard05026382005-03-01 10:56:18 +0000657 LIST_FOR_EACH_SAFE( ptr, next, &process->thread_list )
Alexandre Julliard12f29b52000-03-17 15:16:57 +0000658 {
Alexandre Julliard05026382005-03-01 10:56:18 +0000659 struct thread *thread = LIST_ENTRY( ptr, struct thread, proc_entry );
660
Alexandre Julliard12f29b52000-03-17 15:16:57 +0000661 thread->exit_code = exit_code;
662 if (thread != skip) kill_thread( thread, 1 );
Alexandre Julliard12f29b52000-03-17 15:16:57 +0000663 }
Alexandre Julliard767e6f61998-08-09 12:47:43 +0000664}
665
Alexandre Julliard17cf8101999-11-24 01:22:14 +0000666/* kill all processes being debugged by a given thread */
667void kill_debugged_processes( struct thread *debugger, int exit_code )
668{
669 for (;;) /* restart from the beginning of the list every time */
670 {
Alexandre Julliard48c0d512005-02-25 19:31:26 +0000671 struct process *process;
672
Alexandre Julliard17cf8101999-11-24 01:22:14 +0000673 /* find the first process being debugged by 'debugger' and still running */
Alexandre Julliard48c0d512005-02-25 19:31:26 +0000674 LIST_FOR_EACH_ENTRY( process, &process_list, struct process, entry )
675 {
676 if (!process->running_threads) continue;
677 if (process->debugger == debugger) break;
678 }
679 if (&process->entry == &process_list) break; /* no process found */
Alexandre Julliard17cf8101999-11-24 01:22:14 +0000680 process->debugger = NULL;
Alexandre Julliard12f29b52000-03-17 15:16:57 +0000681 kill_process( process, NULL, exit_code );
Alexandre Julliard17cf8101999-11-24 01:22:14 +0000682 }
683}
684
Eric Pouech0b83d4c2001-11-23 23:04:58 +0000685
Eric Pouechfbccb382002-02-27 01:28:30 +0000686/* detach a debugger from all its debuggees */
687void detach_debugged_processes( struct thread *debugger )
688{
689 struct process *process;
Alexandre Julliard48c0d512005-02-25 19:31:26 +0000690
691 LIST_FOR_EACH_ENTRY( process, &process_list, struct process, entry )
Eric Pouechfbccb382002-02-27 01:28:30 +0000692 {
693 if (process->debugger == debugger && process->running_threads)
694 {
695 debugger_detach( process, debugger );
696 }
697 }
698}
699
700
Eric Pouech93bfa0d2002-06-02 21:22:22 +0000701void enum_processes( int (*cb)(struct process*, void*), void *user )
702{
Alexandre Julliard48c0d512005-02-25 19:31:26 +0000703 struct list *ptr, *next;
704
705 LIST_FOR_EACH_SAFE( ptr, next, &process_list )
Eric Pouech93bfa0d2002-06-02 21:22:22 +0000706 {
Alexandre Julliard48c0d512005-02-25 19:31:26 +0000707 struct process *process = LIST_ENTRY( ptr, struct process, entry );
Eric Pouech93bfa0d2002-06-02 21:22:22 +0000708 if ((cb)(process, user)) break;
709 }
710}
711
712
Alexandre Julliard8b8828f1999-11-12 21:39:14 +0000713/* read data from a process memory space */
Alexandre Julliard9caa71e2001-11-30 18:46:42 +0000714/* len is the total size (in ints) */
715static int read_process_memory( struct process *process, const int *addr, size_t len, int *dest )
Alexandre Julliard8b8828f1999-11-12 21:39:14 +0000716{
Alexandre Julliard05026382005-03-01 10:56:18 +0000717 struct thread *thread = get_process_first_thread( process );
Alexandre Julliard8b8828f1999-11-12 21:39:14 +0000718
Alexandre Julliard9caa71e2001-11-30 18:46:42 +0000719 assert( !((unsigned int)addr % sizeof(int)) ); /* address must be aligned */
720
Alexandre Julliard00641d52000-03-08 16:41:37 +0000721 if (!thread) /* process is dead */
722 {
723 set_error( STATUS_ACCESS_DENIED );
Alexandre Julliard9caa71e2001-11-30 18:46:42 +0000724 return 0;
Alexandre Julliard00641d52000-03-08 16:41:37 +0000725 }
Alexandre Julliard98aacc72000-03-15 19:46:14 +0000726 if (suspend_for_ptrace( thread ))
Alexandre Julliard8b8828f1999-11-12 21:39:14 +0000727 {
Alexandre Julliard9caa71e2001-11-30 18:46:42 +0000728 while (len > 0)
Alexandre Julliard8b8828f1999-11-12 21:39:14 +0000729 {
Alexandre Julliard9caa71e2001-11-30 18:46:42 +0000730 if (read_thread_int( thread, addr++, dest++ ) == -1) break;
Alexandre Julliardeef70251999-11-13 19:54:54 +0000731 len--;
732 }
Alexandre Julliardd04ccb82003-03-04 22:18:43 +0000733 resume_after_ptrace( thread );
Alexandre Julliard8b8828f1999-11-12 21:39:14 +0000734 }
Alexandre Julliard9caa71e2001-11-30 18:46:42 +0000735 return !len;
736}
737
738/* make sure we can write to the whole address range */
739/* len is the total size (in ints) */
740static int check_process_write_access( struct thread *thread, int *addr, size_t len )
741{
742 int page = get_page_size() / sizeof(int);
743
744 for (;;)
745 {
746 if (write_thread_int( thread, addr, 0, 0 ) == -1) return 0;
747 if (len <= page) break;
748 addr += page;
749 len -= page;
750 }
751 return (write_thread_int( thread, addr + len - 1, 0, 0 ) != -1);
Alexandre Julliardeef70251999-11-13 19:54:54 +0000752}
753
754/* write data to a process memory space */
755/* len is the total size (in ints), max is the size we can actually read from the input buffer */
756/* we check the total size for write permissions */
Alexandre Julliarde55d5932003-10-14 01:30:42 +0000757static int write_process_memory( struct process *process, int *addr, size_t len,
758 unsigned int first_mask, unsigned int last_mask, const int *src )
Alexandre Julliardeef70251999-11-13 19:54:54 +0000759{
Alexandre Julliard05026382005-03-01 10:56:18 +0000760 struct thread *thread = get_process_first_thread( process );
Alexandre Julliarde55d5932003-10-14 01:30:42 +0000761 int ret = 0;
Alexandre Julliardeef70251999-11-13 19:54:54 +0000762
Alexandre Julliard9caa71e2001-11-30 18:46:42 +0000763 assert( !((unsigned int)addr % sizeof(int) )); /* address must be aligned */
764
Alexandre Julliard00641d52000-03-08 16:41:37 +0000765 if (!thread) /* process is dead */
766 {
767 set_error( STATUS_ACCESS_DENIED );
Alexandre Julliarde55d5932003-10-14 01:30:42 +0000768 return 0;
Alexandre Julliard00641d52000-03-08 16:41:37 +0000769 }
Alexandre Julliard98aacc72000-03-15 19:46:14 +0000770 if (suspend_for_ptrace( thread ))
Alexandre Julliardeef70251999-11-13 19:54:54 +0000771 {
Alexandre Julliard9caa71e2001-11-30 18:46:42 +0000772 if (!check_process_write_access( thread, addr, len ))
773 {
774 set_error( STATUS_ACCESS_DENIED );
Peter Hunnisetta3c5ad42003-02-28 21:50:47 +0000775 goto done;
Alexandre Julliard9caa71e2001-11-30 18:46:42 +0000776 }
Alexandre Julliardeef70251999-11-13 19:54:54 +0000777 /* first word is special */
778 if (len > 1)
779 {
Alexandre Julliard578c1001999-11-14 21:23:21 +0000780 if (write_thread_int( thread, addr++, *src++, first_mask ) == -1) goto done;
Alexandre Julliardeef70251999-11-13 19:54:54 +0000781 len--;
Alexandre Julliardeef70251999-11-13 19:54:54 +0000782 }
783 else last_mask &= first_mask;
784
Alexandre Julliard9caa71e2001-11-30 18:46:42 +0000785 while (len > 1)
Alexandre Julliardeef70251999-11-13 19:54:54 +0000786 {
Alexandre Julliard578c1001999-11-14 21:23:21 +0000787 if (write_thread_int( thread, addr++, *src++, ~0 ) == -1) goto done;
Alexandre Julliardeef70251999-11-13 19:54:54 +0000788 len--;
789 }
790
Alexandre Julliard9caa71e2001-11-30 18:46:42 +0000791 /* last word is special too */
792 if (write_thread_int( thread, addr, *src, last_mask ) == -1) goto done;
Alexandre Julliarde55d5932003-10-14 01:30:42 +0000793 ret = 1;
Alexandre Julliard9caa71e2001-11-30 18:46:42 +0000794
Alexandre Julliard98aacc72000-03-15 19:46:14 +0000795 done:
Alexandre Julliardd04ccb82003-03-04 22:18:43 +0000796 resume_after_ptrace( thread );
Alexandre Julliardeef70251999-11-13 19:54:54 +0000797 }
Alexandre Julliarde55d5932003-10-14 01:30:42 +0000798 return ret;
799}
800
801/* set the debugged flag in the process PEB */
802int set_process_debug_flag( struct process *process, int flag )
803{
804 int mask = 0, data = 0;
805
806 /* BeingDebugged flag is the byte at offset 2 in the PEB */
807 memset( (char *)&mask + 2, 0xff, 1 );
808 memset( (char *)&data + 2, flag, 1 );
809 return write_process_memory( process, process->peb, 1, mask, mask, &data );
Alexandre Julliard8b8828f1999-11-12 21:39:14 +0000810}
811
Alexandre Julliardfdc92ba1999-02-14 18:03:15 +0000812/* take a snapshot of currently running processes */
813struct process_snapshot *process_snap( int *count )
814{
815 struct process_snapshot *snapshot, *ptr;
816 struct process *process;
817 if (!running_processes) return NULL;
818 if (!(snapshot = mem_alloc( sizeof(*snapshot) * running_processes )))
819 return NULL;
820 ptr = snapshot;
Alexandre Julliard48c0d512005-02-25 19:31:26 +0000821 LIST_FOR_EACH_ENTRY( process, &process_list, struct process, entry )
Alexandre Julliardfdc92ba1999-02-14 18:03:15 +0000822 {
823 if (!process->running_threads) continue;
824 ptr->process = process;
825 ptr->threads = process->running_threads;
Alexandre Julliard07d84462000-04-16 19:45:05 +0000826 ptr->count = process->obj.refcount;
Alexandre Julliardfdc92ba1999-02-14 18:03:15 +0000827 ptr->priority = process->priority;
Eric Pouech9fd54b22003-09-16 01:07:21 +0000828 ptr->handles = get_handle_table_count(process);
Alexandre Julliardfdc92ba1999-02-14 18:03:15 +0000829 grab_object( process );
830 ptr++;
831 }
832 *count = running_processes;
833 return snapshot;
834}
Alexandre Julliard43c190e1999-05-15 10:48:19 +0000835
Alexandre Julliard07d84462000-04-16 19:45:05 +0000836/* take a snapshot of the modules of a process */
837struct module_snapshot *module_snap( struct process *process, int *count )
838{
839 struct module_snapshot *snapshot, *ptr;
840 struct process_dll *dll;
Alexandre Julliarda9e0fb12005-03-02 10:20:09 +0000841 int total = 1;
Alexandre Julliard07d84462000-04-16 19:45:05 +0000842
Alexandre Julliarda9e0fb12005-03-02 10:20:09 +0000843 LIST_FOR_EACH_ENTRY( dll, &process->dlls, struct process_dll, entry ) total++;
Alexandre Julliard07d84462000-04-16 19:45:05 +0000844 if (!(snapshot = mem_alloc( sizeof(*snapshot) * total ))) return NULL;
845
Alexandre Julliarda9e0fb12005-03-02 10:20:09 +0000846 /* first entry is main exe */
847 snapshot->base = process->exe.base;
848 snapshot->size = process->exe.size;
849 snapshot->namelen = process->exe.namelen;
850 snapshot->filename = memdup( process->exe.filename, process->exe.namelen );
851 ptr = snapshot + 1;
852
853 LIST_FOR_EACH_ENTRY( dll, &process->dlls, struct process_dll, entry )
Alexandre Julliard07d84462000-04-16 19:45:05 +0000854 {
Alexandre Julliardaeb56602002-03-22 00:21:23 +0000855 ptr->base = dll->base;
856 ptr->size = dll->size;
857 ptr->namelen = dll->namelen;
858 ptr->filename = memdup( dll->filename, dll->namelen );
Alexandre Julliarda9e0fb12005-03-02 10:20:09 +0000859 ptr++;
Alexandre Julliard07d84462000-04-16 19:45:05 +0000860 }
861 *count = total;
862 return snapshot;
863}
864
865
Alexandre Julliard43c190e1999-05-15 10:48:19 +0000866/* create a new process */
867DECL_HANDLER(new_process)
868{
Alexandre Julliard5b4f3e82000-05-01 16:24:22 +0000869 struct startup_info *info;
Alexandre Julliard43c190e1999-05-15 10:48:19 +0000870
Alexandre Julliard5b4f3e82000-05-01 16:24:22 +0000871 /* build the startup info for a new process */
Alexandre Julliarde66207e2003-02-19 00:33:32 +0000872 if (!(info = alloc_object( &startup_info_ops ))) return;
Alexandre Julliard77c8b1d2003-02-24 20:51:50 +0000873 list_add_head( &startup_info_list, &info->entry );
Alexandre Julliard5b4f3e82000-05-01 16:24:22 +0000874 info->inherit_all = req->inherit_all;
875 info->create_flags = req->create_flags;
Alexandre Julliard77c8b1d2003-02-24 20:51:50 +0000876 info->unix_pid = req->unix_pid;
Alexandre Julliard5b4f3e82000-05-01 16:24:22 +0000877 info->hstdin = req->hstdin;
878 info->hstdout = req->hstdout;
879 info->hstderr = req->hstderr;
Alexandre Julliardd27624b2000-05-03 18:42:40 +0000880 info->exe_file = NULL;
Alexandre Julliarde9936d92001-01-26 00:22:26 +0000881 info->owner = (struct thread *)grab_object( current );
Alexandre Julliard5b4f3e82000-05-01 16:24:22 +0000882 info->process = NULL;
883 info->thread = NULL;
Alexandre Julliard6543a652002-03-29 18:28:56 +0000884 info->data_size = get_req_data_size();
885 info->data = NULL;
Alexandre Julliard6a72dc52000-04-14 13:42:00 +0000886
Alexandre Julliard8081e5a2001-01-05 04:08:07 +0000887 if (req->exe_file &&
Alexandre Julliardd27624b2000-05-03 18:42:40 +0000888 !(info->exe_file = get_file_obj( current->process, req->exe_file, GENERIC_READ )))
Alexandre Julliarde9936d92001-01-26 00:22:26 +0000889 goto done;
Alexandre Julliardd27624b2000-05-03 18:42:40 +0000890
Alexandre Julliard841f8982003-10-04 04:09:41 +0000891 if (!(info->data = memdup( get_req_data(), info->data_size ))) goto done;
Alexandre Julliard9caa71e2001-11-30 18:46:42 +0000892 reply->info = alloc_handle( current->process, info, SYNCHRONIZE, FALSE );
Alexandre Julliarde9936d92001-01-26 00:22:26 +0000893
894 done:
895 release_object( info );
Alexandre Julliard5b4f3e82000-05-01 16:24:22 +0000896}
Alexandre Julliard6a72dc52000-04-14 13:42:00 +0000897
Alexandre Julliarde9936d92001-01-26 00:22:26 +0000898/* Retrieve information about a newly started process */
899DECL_HANDLER(get_new_process_info)
Alexandre Julliard5b4f3e82000-05-01 16:24:22 +0000900{
Alexandre Julliarde9936d92001-01-26 00:22:26 +0000901 struct startup_info *info;
902
Alexandre Julliarde9936d92001-01-26 00:22:26 +0000903 if ((info = (struct startup_info *)get_handle_obj( current->process, req->info,
904 0, &startup_info_ops )))
Alexandre Julliard5b4f3e82000-05-01 16:24:22 +0000905 {
Alexandre Julliard9caa71e2001-11-30 18:46:42 +0000906 reply->pid = get_process_id( info->process );
907 reply->tid = get_thread_id( info->thread );
908 reply->phandle = alloc_handle( current->process, info->process,
909 PROCESS_ALL_ACCESS, req->pinherit );
910 reply->thandle = alloc_handle( current->process, info->thread,
911 THREAD_ALL_ACCESS, req->tinherit );
Alexandre Julliardca96de32002-05-25 21:15:03 +0000912 reply->success = is_process_init_done( info->process );
Alexandre Julliarde9936d92001-01-26 00:22:26 +0000913 release_object( info );
Alexandre Julliard5b4f3e82000-05-01 16:24:22 +0000914 }
915 else
916 {
Alexandre Julliard9caa71e2001-11-30 18:46:42 +0000917 reply->pid = 0;
918 reply->tid = 0;
919 reply->phandle = 0;
920 reply->thandle = 0;
Alexandre Julliard9d802152002-05-24 21:20:27 +0000921 reply->success = 0;
Alexandre Julliard5b4f3e82000-05-01 16:24:22 +0000922 }
Alexandre Julliard43c190e1999-05-15 10:48:19 +0000923}
924
Alexandre Julliard6543a652002-03-29 18:28:56 +0000925/* Retrieve the new process startup info */
926DECL_HANDLER(get_startup_info)
927{
Alexandre Julliard01caa5e2005-07-12 20:27:09 +0000928 struct process *process = current->process;
929 struct startup_info *info = process->startup_info;
930 size_t size;
Alexandre Julliard6543a652002-03-29 18:28:56 +0000931
Alexandre Julliard01caa5e2005-07-12 20:27:09 +0000932 if (!info) return;
933
934 reply->create_flags = info->create_flags;
935
936 if (info->exe_file &&
937 !(reply->exe_file = alloc_handle( process, info->exe_file, GENERIC_READ, 0 ))) return;
938
939 if (!info->inherit_all && !(info->create_flags & CREATE_NEW_CONSOLE))
Alexandre Julliard6543a652002-03-29 18:28:56 +0000940 {
Alexandre Julliard01caa5e2005-07-12 20:27:09 +0000941 struct process *parent_process = info->owner->process;
942 reply->hstdin = duplicate_handle( parent_process, info->hstdin, process,
943 0, TRUE, DUPLICATE_SAME_ACCESS );
944 reply->hstdout = duplicate_handle( parent_process, info->hstdout, process,
945 0, TRUE, DUPLICATE_SAME_ACCESS );
946 reply->hstderr = duplicate_handle( parent_process, info->hstderr, process,
947 0, TRUE, DUPLICATE_SAME_ACCESS );
948 /* some handles above may have been invalid; this is not an error */
949 if (get_error() == STATUS_INVALID_HANDLE ||
950 get_error() == STATUS_OBJECT_TYPE_MISMATCH) clear_error();
Alexandre Julliard6543a652002-03-29 18:28:56 +0000951 }
Alexandre Julliard01caa5e2005-07-12 20:27:09 +0000952 else
953 {
954 reply->hstdin = info->hstdin;
955 reply->hstdout = info->hstdout;
956 reply->hstderr = info->hstderr;
957 }
958
959 /* we return the data directly without making a copy so this can only be called once */
960 size = info->data_size;
961 if (size > get_reply_max_size()) size = get_reply_max_size();
962 set_reply_data_ptr( info->data, size );
963 info->data = NULL;
964 info->data_size = 0;
Alexandre Julliard6543a652002-03-29 18:28:56 +0000965}
966
Alexandre Julliardec7bb231999-11-12 03:35:25 +0000967/* signal the end of the process initialization */
968DECL_HANDLER(init_process_done)
969{
Alexandre Julliardac2e4f12001-10-25 19:52:12 +0000970 struct file *file = NULL;
Alexandre Julliardec7bb231999-11-12 03:35:25 +0000971 struct process *process = current->process;
Alexandre Julliardac2e4f12001-10-25 19:52:12 +0000972
Alexandre Julliard9d802152002-05-24 21:20:27 +0000973 if (is_process_init_done(process))
Alexandre Julliardec7bb231999-11-12 03:35:25 +0000974 {
Alexandre Julliard9d802152002-05-24 21:20:27 +0000975 fatal_protocol_error( current, "init_process_done: called twice\n" );
976 return;
977 }
978 if (!req->module)
979 {
980 fatal_protocol_error( current, "init_process_done: module base address cannot be 0\n" );
Alexandre Julliardec7bb231999-11-12 03:35:25 +0000981 return;
982 }
Alexandre Julliard05f0b712000-03-09 18:18:41 +0000983 process->exe.base = req->module;
Alexandre Julliardaeb56602002-03-22 00:21:23 +0000984 process->exe.size = req->module_size;
Alexandre Julliarda37dec02000-06-08 00:57:24 +0000985 process->exe.name = req->name;
Alexandre Julliardad29b902001-01-05 22:24:15 +0000986
Alexandre Julliardca96de32002-05-25 21:15:03 +0000987 if (req->exe_file) file = get_file_obj( process, req->exe_file, GENERIC_READ );
Alexandre Julliardac2e4f12001-10-25 19:52:12 +0000988 if (process->exe.file) release_object( process->exe.file );
989 process->exe.file = file;
990
Alexandre Julliardaeb56602002-03-22 00:21:23 +0000991 if ((process->exe.namelen = get_req_data_size()))
992 process->exe.filename = memdup( get_req_data(), process->exe.namelen );
993
Alexandre Julliard9d802152002-05-24 21:20:27 +0000994 generate_startup_debug_events( process, req->entry );
995 set_process_startup_state( process, STARTUP_DONE );
996
Alexandre Julliardc5e433a2000-05-30 19:48:18 +0000997 if (req->gui) process->idle_event = create_event( NULL, 0, 1, 0 );
Alexandre Julliardca96de32002-05-25 21:15:03 +0000998 if (current->suspend + process->suspend > 0) stop_thread( current );
Alexandre Julliarde55d5932003-10-14 01:30:42 +0000999 if (process->debugger) set_process_debug_flag( process, 1 );
Alexandre Julliardec7bb231999-11-12 03:35:25 +00001000}
1001
Alexandre Julliard43c190e1999-05-15 10:48:19 +00001002/* open a handle to a process */
1003DECL_HANDLER(open_process)
1004{
Alexandre Julliard43c190e1999-05-15 10:48:19 +00001005 struct process *process = get_process_from_id( req->pid );
Alexandre Julliard9caa71e2001-11-30 18:46:42 +00001006 reply->handle = 0;
Alexandre Julliard43c190e1999-05-15 10:48:19 +00001007 if (process)
1008 {
Alexandre Julliard9caa71e2001-11-30 18:46:42 +00001009 reply->handle = alloc_handle( current->process, process, req->access, req->inherit );
Alexandre Julliard43c190e1999-05-15 10:48:19 +00001010 release_object( process );
1011 }
Alexandre Julliard43c190e1999-05-15 10:48:19 +00001012}
1013
1014/* terminate a process */
1015DECL_HANDLER(terminate_process)
1016{
1017 struct process *process;
1018
1019 if ((process = get_process_from_handle( req->handle, PROCESS_TERMINATE )))
1020 {
Alexandre Julliard9caa71e2001-11-30 18:46:42 +00001021 reply->self = (current->process == process);
Alexandre Julliard12f29b52000-03-17 15:16:57 +00001022 kill_process( process, current, req->exit_code );
Alexandre Julliard43c190e1999-05-15 10:48:19 +00001023 release_object( process );
1024 }
Alexandre Julliard43c190e1999-05-15 10:48:19 +00001025}
1026
1027/* fetch information about a process */
1028DECL_HANDLER(get_process_info)
1029{
1030 struct process *process;
Alexandre Julliard43c190e1999-05-15 10:48:19 +00001031
1032 if ((process = get_process_from_handle( req->handle, PROCESS_QUERY_INFORMATION )))
1033 {
Alexandre Julliarde55d5932003-10-14 01:30:42 +00001034 reply->pid = get_process_id( process );
Eric Pouechb0fd2ad2004-06-14 17:02:00 +00001035 reply->ppid = process->parent ? get_process_id( process->parent ) : 0;
Alexandre Julliarde55d5932003-10-14 01:30:42 +00001036 reply->exit_code = process->exit_code;
1037 reply->priority = process->priority;
1038 reply->process_affinity = process->affinity;
1039 reply->system_affinity = 1;
Eric Pouechb0fd2ad2004-06-14 17:02:00 +00001040 reply->peb = process->peb;
Alexandre Julliard43c190e1999-05-15 10:48:19 +00001041 release_object( process );
1042 }
Alexandre Julliard43c190e1999-05-15 10:48:19 +00001043}
1044
1045/* set information about a process */
1046DECL_HANDLER(set_process_info)
1047{
1048 struct process *process;
1049
1050 if ((process = get_process_from_handle( req->handle, PROCESS_SET_INFORMATION )))
1051 {
Alexandre Julliarde55d5932003-10-14 01:30:42 +00001052 if (req->mask & SET_PROCESS_INFO_PRIORITY) process->priority = req->priority;
1053 if (req->mask & SET_PROCESS_INFO_AFFINITY)
1054 {
1055 if (req->affinity != 1) set_error( STATUS_INVALID_PARAMETER );
1056 else process->affinity = req->affinity;
1057 }
Alexandre Julliard43c190e1999-05-15 10:48:19 +00001058 release_object( process );
1059 }
Alexandre Julliard43c190e1999-05-15 10:48:19 +00001060}
Alexandre Julliard8b8828f1999-11-12 21:39:14 +00001061
1062/* read data from a process address space */
1063DECL_HANDLER(read_process_memory)
1064{
1065 struct process *process;
Alexandre Julliard9caa71e2001-11-30 18:46:42 +00001066 size_t len = get_reply_max_size();
Alexandre Julliard8b8828f1999-11-12 21:39:14 +00001067
Alexandre Julliard9caa71e2001-11-30 18:46:42 +00001068 if (!(process = get_process_from_handle( req->handle, PROCESS_VM_READ ))) return;
1069
1070 if (len)
Alexandre Julliard8b8828f1999-11-12 21:39:14 +00001071 {
Alexandre Julliard9caa71e2001-11-30 18:46:42 +00001072 unsigned int start_offset = (unsigned int)req->addr % sizeof(int);
1073 unsigned int nb_ints = (len + start_offset + sizeof(int) - 1) / sizeof(int);
1074 const int *start = (int *)((char *)req->addr - start_offset);
1075 int *buffer = mem_alloc( nb_ints * sizeof(int) );
1076 if (buffer)
1077 {
1078 if (read_process_memory( process, start, nb_ints, buffer ))
1079 {
1080 /* move start of requested data to start of buffer */
1081 if (start_offset) memmove( buffer, (char *)buffer + start_offset, len );
1082 set_reply_data_ptr( buffer, len );
1083 }
1084 else len = 0;
1085 }
Alexandre Julliard8b8828f1999-11-12 21:39:14 +00001086 }
Alexandre Julliard9caa71e2001-11-30 18:46:42 +00001087 release_object( process );
Alexandre Julliard8b8828f1999-11-12 21:39:14 +00001088}
Alexandre Julliardeef70251999-11-13 19:54:54 +00001089
1090/* write data to a process address space */
1091DECL_HANDLER(write_process_memory)
1092{
1093 struct process *process;
1094
1095 if ((process = get_process_from_handle( req->handle, PROCESS_VM_WRITE )))
1096 {
Alexandre Julliard9caa71e2001-11-30 18:46:42 +00001097 size_t len = get_req_data_size();
1098 if ((len % sizeof(int)) || ((unsigned int)req->addr % sizeof(int)))
1099 set_error( STATUS_INVALID_PARAMETER );
1100 else
1101 {
1102 if (len) write_process_memory( process, req->addr, len / sizeof(int),
1103 req->first_mask, req->last_mask, get_req_data() );
1104 }
Alexandre Julliardeef70251999-11-13 19:54:54 +00001105 release_object( process );
1106 }
1107}
Alexandre Julliard05f0b712000-03-09 18:18:41 +00001108
1109/* notify the server that a dll has been loaded */
1110DECL_HANDLER(load_dll)
1111{
1112 struct process_dll *dll;
1113 struct file *file = NULL;
1114
Alexandre Julliard670711e2004-04-06 23:13:47 +00001115 if (req->handle && !(file = get_file_obj( current->process, req->handle, GENERIC_READ )))
1116 return;
Alexandre Julliard8081e5a2001-01-05 04:08:07 +00001117
Alexandre Julliardaeb56602002-03-22 00:21:23 +00001118 if ((dll = process_load_dll( current->process, file, req->base,
1119 get_req_data(), get_req_data_size() )))
Alexandre Julliard05f0b712000-03-09 18:18:41 +00001120 {
Alexandre Julliardaeb56602002-03-22 00:21:23 +00001121 dll->size = req->size;
Alexandre Julliard05f0b712000-03-09 18:18:41 +00001122 dll->dbg_offset = req->dbg_offset;
1123 dll->dbg_size = req->dbg_size;
1124 dll->name = req->name;
1125 /* only generate event if initialization is done */
Alexandre Julliard9d802152002-05-24 21:20:27 +00001126 if (is_process_init_done( current->process ))
Alexandre Julliard05f0b712000-03-09 18:18:41 +00001127 generate_debug_event( current, LOAD_DLL_DEBUG_EVENT, dll );
1128 }
1129 if (file) release_object( file );
1130}
1131
1132/* notify the server that a dll is being unloaded */
1133DECL_HANDLER(unload_dll)
1134{
1135 process_unload_dll( current->process, req->base );
1136}
Alexandre Julliardc5e433a2000-05-30 19:48:18 +00001137
Eric Pouech2359b572003-01-09 00:01:28 +00001138/* retrieve information about a module in a process */
1139DECL_HANDLER(get_dll_info)
1140{
1141 struct process *process;
1142
1143 if ((process = get_process_from_handle( req->handle, PROCESS_QUERY_INFORMATION )))
1144 {
Alexandre Julliarda9e0fb12005-03-02 10:20:09 +00001145 struct process_dll *dll = find_process_dll( process, req->base_address );
Eric Pouech2359b572003-01-09 00:01:28 +00001146
Alexandre Julliarda9e0fb12005-03-02 10:20:09 +00001147 if (dll)
Eric Pouech2359b572003-01-09 00:01:28 +00001148 {
Alexandre Julliarda9e0fb12005-03-02 10:20:09 +00001149 reply->size = dll->size;
Robert Shearmanc5165712005-05-25 18:41:09 +00001150 reply->entry_point = NULL; /* FIXME */
Alexandre Julliarda9e0fb12005-03-02 10:20:09 +00001151 if (dll->filename)
Eric Pouech2359b572003-01-09 00:01:28 +00001152 {
Alexandre Julliarda9e0fb12005-03-02 10:20:09 +00001153 size_t len = min( dll->namelen, get_reply_max_size() );
1154 set_reply_data( dll->filename, len );
Eric Pouech2359b572003-01-09 00:01:28 +00001155 }
1156 }
Alexandre Julliarda9e0fb12005-03-02 10:20:09 +00001157 else
1158 set_error( STATUS_DLL_NOT_FOUND );
1159
Eric Pouech2359b572003-01-09 00:01:28 +00001160 release_object( process );
1161 }
1162}
1163
Alexandre Julliardc5e433a2000-05-30 19:48:18 +00001164/* wait for a process to start waiting on input */
1165/* FIXME: only returns event for now, wait is done in the client */
1166DECL_HANDLER(wait_input_idle)
1167{
1168 struct process *process;
1169
Alexandre Julliard9caa71e2001-11-30 18:46:42 +00001170 reply->event = 0;
Alexandre Julliardc5e433a2000-05-30 19:48:18 +00001171 if ((process = get_process_from_handle( req->handle, PROCESS_QUERY_INFORMATION )))
1172 {
1173 if (process->idle_event && process != current->process && process->queue != current->queue)
Alexandre Julliard9caa71e2001-11-30 18:46:42 +00001174 reply->event = alloc_handle( current->process, process->idle_event,
1175 EVENT_ALL_ACCESS, 0 );
Alexandre Julliardc5e433a2000-05-30 19:48:18 +00001176 release_object( process );
1177 }
1178}