Alexandre Julliard | 642d313 | 1998-07-12 19:29:36 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Server-side process management |
| 3 | * |
| 4 | * Copyright (C) 1998 Alexandre Julliard |
Alexandre Julliard | 0799c1a | 2002-03-09 23:29:33 +0000 | [diff] [blame] | 5 | * |
| 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 Julliard | 642d313 | 1998-07-12 19:29:36 +0000 | [diff] [blame] | 19 | */ |
| 20 | |
Patrik Stridvall | fb32c7b | 2000-01-29 21:02:19 +0000 | [diff] [blame] | 21 | #include "config.h" |
Alexandre Julliard | 5769d1d | 2002-04-26 19:05:15 +0000 | [diff] [blame] | 22 | #include "wine/port.h" |
Patrik Stridvall | fb32c7b | 2000-01-29 21:02:19 +0000 | [diff] [blame] | 23 | |
Alexandre Julliard | 642d313 | 1998-07-12 19:29:36 +0000 | [diff] [blame] | 24 | #include <assert.h> |
Alexandre Julliard | 767e6f6 | 1998-08-09 12:47:43 +0000 | [diff] [blame] | 25 | #include <limits.h> |
Alexandre Julliard | 3da5f84 | 1999-05-16 16:54:54 +0000 | [diff] [blame] | 26 | #include <signal.h> |
Alexandre Julliard | 85ed45e | 1998-08-22 19:03:56 +0000 | [diff] [blame] | 27 | #include <string.h> |
Alexandre Julliard | 767e6f6 | 1998-08-09 12:47:43 +0000 | [diff] [blame] | 28 | #include <stdio.h> |
Alexandre Julliard | 642d313 | 1998-07-12 19:29:36 +0000 | [diff] [blame] | 29 | #include <stdlib.h> |
Alexandre Julliard | 767e6f6 | 1998-08-09 12:47:43 +0000 | [diff] [blame] | 30 | #include <sys/time.h> |
Patrik Stridvall | fb32c7b | 2000-01-29 21:02:19 +0000 | [diff] [blame] | 31 | #ifdef HAVE_SYS_SOCKET_H |
| 32 | # include <sys/socket.h> |
| 33 | #endif |
Alexandre Julliard | 767e6f6 | 1998-08-09 12:47:43 +0000 | [diff] [blame] | 34 | #include <unistd.h> |
| 35 | |
Alexandre Julliard | 767e6f6 | 1998-08-09 12:47:43 +0000 | [diff] [blame] | 36 | #include "winbase.h" |
| 37 | #include "winnt.h" |
Alexandre Julliard | 642d313 | 1998-07-12 19:29:36 +0000 | [diff] [blame] | 38 | |
Alexandre Julliard | 863637b | 2003-01-30 00:26:44 +0000 | [diff] [blame] | 39 | #include "file.h" |
Alexandre Julliard | 43c190e | 1999-05-15 10:48:19 +0000 | [diff] [blame] | 40 | #include "handle.h" |
| 41 | #include "process.h" |
| 42 | #include "thread.h" |
Alexandre Julliard | 5bc7808 | 1999-06-22 17:26:53 +0000 | [diff] [blame] | 43 | #include "request.h" |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 44 | #include "console.h" |
Alexandre Julliard | 642d313 | 1998-07-12 19:29:36 +0000 | [diff] [blame] | 45 | |
Alexandre Julliard | f692d44 | 1999-03-21 19:23:54 +0000 | [diff] [blame] | 46 | /* process structure */ |
Alexandre Julliard | 43c190e | 1999-05-15 10:48:19 +0000 | [diff] [blame] | 47 | |
Alexandre Julliard | eb2e77f | 1999-06-04 19:49:54 +0000 | [diff] [blame] | 48 | static struct process *first_process; |
Alexandre Julliard | fdc92ba | 1999-02-14 18:03:15 +0000 | [diff] [blame] | 49 | static int running_processes; |
Alexandre Julliard | 642d313 | 1998-07-12 19:29:36 +0000 | [diff] [blame] | 50 | |
| 51 | /* process operations */ |
| 52 | |
Alexandre Julliard | 338e757 | 1998-12-27 15:28:54 +0000 | [diff] [blame] | 53 | static void process_dump( struct object *obj, int verbose ); |
Alexandre Julliard | 85ed45e | 1998-08-22 19:03:56 +0000 | [diff] [blame] | 54 | static int process_signaled( struct object *obj, struct thread *thread ); |
Alexandre Julliard | cf27a7f | 2003-02-14 20:27:09 +0000 | [diff] [blame] | 55 | static void process_poll_event( struct fd *fd, int event ); |
Alexandre Julliard | 338e757 | 1998-12-27 15:28:54 +0000 | [diff] [blame] | 56 | static void process_destroy( struct object *obj ); |
Alexandre Julliard | 642d313 | 1998-07-12 19:29:36 +0000 | [diff] [blame] | 57 | |
| 58 | static const struct object_ops process_ops = |
| 59 | { |
Alexandre Julliard | 1dca5e2 | 2000-01-01 00:56:27 +0000 | [diff] [blame] | 60 | sizeof(struct process), /* size */ |
| 61 | process_dump, /* dump */ |
| 62 | add_queue, /* add_queue */ |
| 63 | remove_queue, /* remove_queue */ |
| 64 | process_signaled, /* signaled */ |
| 65 | no_satisfied, /* satisfied */ |
Alexandre Julliard | 863637b | 2003-01-30 00:26:44 +0000 | [diff] [blame] | 66 | no_get_fd, /* get_fd */ |
Alexandre Julliard | 863637b | 2003-01-30 00:26:44 +0000 | [diff] [blame] | 67 | process_destroy /* destroy */ |
| 68 | }; |
| 69 | |
| 70 | static const struct fd_ops process_fd_ops = |
| 71 | { |
Alexandre Julliard | 1dca5e2 | 2000-01-01 00:56:27 +0000 | [diff] [blame] | 72 | NULL, /* get_poll_events */ |
Alexandre Julliard | f524240 | 2001-02-28 21:45:23 +0000 | [diff] [blame] | 73 | process_poll_event, /* poll_event */ |
Alexandre Julliard | 1dca5e2 | 2000-01-01 00:56:27 +0000 | [diff] [blame] | 74 | no_flush, /* flush */ |
| 75 | no_get_file_info, /* get_file_info */ |
Alexandre Julliard | 863637b | 2003-01-30 00:26:44 +0000 | [diff] [blame] | 76 | no_queue_async /* queue_async */ |
Alexandre Julliard | 642d313 | 1998-07-12 19:29:36 +0000 | [diff] [blame] | 77 | }; |
| 78 | |
Alexandre Julliard | 5b4f3e8 | 2000-05-01 16:24:22 +0000 | [diff] [blame] | 79 | /* process startup info */ |
| 80 | |
| 81 | struct startup_info |
Alexandre Julliard | 2fe5777 | 2000-01-25 01:40:27 +0000 | [diff] [blame] | 82 | { |
Alexandre Julliard | 5b4f3e8 | 2000-05-01 16:24:22 +0000 | [diff] [blame] | 83 | struct object obj; /* object header */ |
Alexandre Julliard | 77c8b1d | 2003-02-24 20:51:50 +0000 | [diff] [blame] | 84 | struct list entry; /* entry in list of startup infos */ |
Alexandre Julliard | 5b4f3e8 | 2000-05-01 16:24:22 +0000 | [diff] [blame] | 85 | int inherit_all; /* inherit all handles from parent */ |
Alexandre Julliard | 6543a65 | 2002-03-29 18:28:56 +0000 | [diff] [blame] | 86 | int use_handles; /* use stdio handles */ |
Alexandre Julliard | 5b4f3e8 | 2000-05-01 16:24:22 +0000 | [diff] [blame] | 87 | int create_flags; /* creation flags */ |
Alexandre Julliard | baf0a06 | 2003-03-11 01:48:53 +0000 | [diff] [blame] | 88 | int unix_pid; /* Unix pid of new process */ |
Alexandre Julliard | 5188574 | 2002-05-30 20:12:58 +0000 | [diff] [blame] | 89 | obj_handle_t hstdin; /* handle for stdin */ |
| 90 | obj_handle_t hstdout; /* handle for stdout */ |
| 91 | obj_handle_t hstderr; /* handle for stderr */ |
Alexandre Julliard | d27624b | 2000-05-03 18:42:40 +0000 | [diff] [blame] | 92 | struct file *exe_file; /* file handle for main exe */ |
Alexandre Julliard | e9936d9 | 2001-01-26 00:22:26 +0000 | [diff] [blame] | 93 | struct thread *owner; /* owner thread (the one that created the new process) */ |
Alexandre Julliard | 5b4f3e8 | 2000-05-01 16:24:22 +0000 | [diff] [blame] | 94 | struct process *process; /* created process */ |
| 95 | struct thread *thread; /* created thread */ |
Alexandre Julliard | 6543a65 | 2002-03-29 18:28:56 +0000 | [diff] [blame] | 96 | size_t data_size; /* size of startup data */ |
| 97 | startup_info_t *data; /* data for startup info */ |
Alexandre Julliard | 5b4f3e8 | 2000-05-01 16:24:22 +0000 | [diff] [blame] | 98 | }; |
| 99 | |
| 100 | static void startup_info_dump( struct object *obj, int verbose ); |
| 101 | static int startup_info_signaled( struct object *obj, struct thread *thread ); |
| 102 | static void startup_info_destroy( struct object *obj ); |
| 103 | |
| 104 | static const struct object_ops startup_info_ops = |
| 105 | { |
| 106 | sizeof(struct startup_info), /* size */ |
| 107 | startup_info_dump, /* dump */ |
| 108 | add_queue, /* add_queue */ |
| 109 | remove_queue, /* remove_queue */ |
| 110 | startup_info_signaled, /* signaled */ |
| 111 | no_satisfied, /* satisfied */ |
Alexandre Julliard | 1ab243b | 2000-12-19 02:12:45 +0000 | [diff] [blame] | 112 | no_get_fd, /* get_fd */ |
Alexandre Julliard | 5b4f3e8 | 2000-05-01 16:24:22 +0000 | [diff] [blame] | 113 | startup_info_destroy /* destroy */ |
| 114 | }; |
| 115 | |
Alexandre Julliard | f692d44 | 1999-03-21 19:23:54 +0000 | [diff] [blame] | 116 | |
Alexandre Julliard | 77c8b1d | 2003-02-24 20:51:50 +0000 | [diff] [blame] | 117 | static struct list startup_info_list = LIST_INIT(startup_info_list); |
| 118 | |
Alexandre Julliard | 91befe1 | 2003-02-01 01:38:40 +0000 | [diff] [blame] | 119 | struct ptid_entry |
| 120 | { |
| 121 | void *ptr; /* entry ptr */ |
| 122 | unsigned int next; /* next free entry */ |
| 123 | }; |
| 124 | |
| 125 | static struct ptid_entry *ptid_entries; /* array of ptid entries */ |
| 126 | static unsigned int used_ptid_entries; /* number of entries in use */ |
| 127 | static unsigned int alloc_ptid_entries; /* number of allocated entries */ |
| 128 | static unsigned int next_free_ptid; /* next free entry */ |
| 129 | static unsigned int last_free_ptid; /* last free entry */ |
| 130 | |
| 131 | #define PTID_OFFSET 8 /* offset for first ptid value */ |
| 132 | |
| 133 | /* allocate a new process or thread id */ |
| 134 | unsigned int alloc_ptid( void *ptr ) |
| 135 | { |
| 136 | struct ptid_entry *entry; |
| 137 | unsigned int id; |
| 138 | |
| 139 | if (used_ptid_entries < alloc_ptid_entries) |
| 140 | { |
| 141 | id = used_ptid_entries + PTID_OFFSET; |
| 142 | entry = &ptid_entries[used_ptid_entries++]; |
| 143 | } |
| 144 | else if (next_free_ptid) |
| 145 | { |
| 146 | id = next_free_ptid; |
| 147 | entry = &ptid_entries[id - PTID_OFFSET]; |
| 148 | if (!(next_free_ptid = entry->next)) last_free_ptid = 0; |
| 149 | } |
| 150 | else /* need to grow the array */ |
| 151 | { |
| 152 | unsigned int count = alloc_ptid_entries + (alloc_ptid_entries / 2); |
| 153 | if (!count) count = 64; |
| 154 | if (!(entry = realloc( ptid_entries, count * sizeof(*entry) ))) |
| 155 | { |
| 156 | set_error( STATUS_NO_MEMORY ); |
| 157 | return 0; |
| 158 | } |
| 159 | ptid_entries = entry; |
| 160 | alloc_ptid_entries = count; |
| 161 | id = used_ptid_entries + PTID_OFFSET; |
| 162 | entry = &ptid_entries[used_ptid_entries++]; |
| 163 | } |
| 164 | |
| 165 | entry->ptr = ptr; |
| 166 | return id; |
| 167 | } |
| 168 | |
| 169 | /* free a process or thread id */ |
| 170 | void free_ptid( unsigned int id ) |
| 171 | { |
| 172 | struct ptid_entry *entry = &ptid_entries[id - PTID_OFFSET]; |
| 173 | |
| 174 | entry->ptr = NULL; |
| 175 | entry->next = 0; |
| 176 | |
| 177 | /* append to end of free list so that we don't reuse it too early */ |
| 178 | if (last_free_ptid) ptid_entries[last_free_ptid - PTID_OFFSET].next = id; |
| 179 | else next_free_ptid = id; |
| 180 | |
| 181 | last_free_ptid = id; |
| 182 | } |
| 183 | |
| 184 | /* retrieve the pointer corresponding to a process or thread id */ |
| 185 | void *get_ptid_entry( unsigned int id ) |
| 186 | { |
| 187 | if (id < PTID_OFFSET) return NULL; |
| 188 | if (id - PTID_OFFSET >= used_ptid_entries) return NULL; |
| 189 | return ptid_entries[id - PTID_OFFSET].ptr; |
| 190 | } |
| 191 | |
Alexandre Julliard | 9d80215 | 2002-05-24 21:20:27 +0000 | [diff] [blame] | 192 | /* set the state of the process startup info */ |
| 193 | static void set_process_startup_state( struct process *process, enum startup_state state ) |
| 194 | { |
Alexandre Julliard | ca96de3 | 2002-05-25 21:15:03 +0000 | [diff] [blame] | 195 | if (process->startup_state == STARTUP_IN_PROGRESS) process->startup_state = state; |
| 196 | if (process->startup_info) |
| 197 | { |
| 198 | wake_up( &process->startup_info->obj, 0 ); |
| 199 | release_object( process->startup_info ); |
| 200 | process->startup_info = NULL; |
| 201 | } |
Alexandre Julliard | 9d80215 | 2002-05-24 21:20:27 +0000 | [diff] [blame] | 202 | } |
| 203 | |
Alexandre Julliard | 2fe5777 | 2000-01-25 01:40:27 +0000 | [diff] [blame] | 204 | /* set the console and stdio handles for a newly created process */ |
Eric Pouech | 3940d8a | 2001-12-04 20:17:43 +0000 | [diff] [blame] | 205 | static int set_process_console( struct process *process, struct thread *parent_thread, |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 206 | struct startup_info *info, struct init_process_reply *reply ) |
Alexandre Julliard | 2fe5777 | 2000-01-25 01:40:27 +0000 | [diff] [blame] | 207 | { |
Alexandre Julliard | 2fe5777 | 2000-01-25 01:40:27 +0000 | [diff] [blame] | 208 | if (process->create_flags & CREATE_NEW_CONSOLE) |
| 209 | { |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 210 | /* let the process init do the allocation */ |
| 211 | return 1; |
Alexandre Julliard | 2fe5777 | 2000-01-25 01:40:27 +0000 | [diff] [blame] | 212 | } |
Alexandre Julliard | 9d80215 | 2002-05-24 21:20:27 +0000 | [diff] [blame] | 213 | else if (info && !(process->create_flags & DETACHED_PROCESS)) |
Alexandre Julliard | 2fe5777 | 2000-01-25 01:40:27 +0000 | [diff] [blame] | 214 | { |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 215 | /* FIXME: some better error checking should be done... |
| 216 | * like if hConOut and hConIn are console handles, then they should be on the same |
| 217 | * physical console |
| 218 | */ |
Eric Pouech | 3940d8a | 2001-12-04 20:17:43 +0000 | [diff] [blame] | 219 | inherit_console( parent_thread, process, |
Alexandre Julliard | 6543a65 | 2002-03-29 18:28:56 +0000 | [diff] [blame] | 220 | (info->inherit_all || info->use_handles) ? info->hstdin : 0 ); |
Alexandre Julliard | 2fe5777 | 2000-01-25 01:40:27 +0000 | [diff] [blame] | 221 | } |
Alexandre Julliard | 9d80215 | 2002-05-24 21:20:27 +0000 | [diff] [blame] | 222 | if (info) |
Alexandre Julliard | 2fe5777 | 2000-01-25 01:40:27 +0000 | [diff] [blame] | 223 | { |
Eric Pouech | 412d37f | 2003-06-21 02:07:10 +0000 | [diff] [blame] | 224 | reply->hstdin = info->hstdin; |
| 225 | reply->hstdout = info->hstdout; |
| 226 | reply->hstderr = info->hstderr; |
Alexandre Julliard | 2fe5777 | 2000-01-25 01:40:27 +0000 | [diff] [blame] | 227 | } |
Eric Pouech | 412d37f | 2003-06-21 02:07:10 +0000 | [diff] [blame] | 228 | else reply->hstdin = reply->hstdout = reply->hstderr = 0; |
Alexandre Julliard | c5e433a | 2000-05-30 19:48:18 +0000 | [diff] [blame] | 229 | /* some handles above may have been invalid; this is not an error */ |
| 230 | if (get_error() == STATUS_INVALID_HANDLE) clear_error(); |
Alexandre Julliard | 2fe5777 | 2000-01-25 01:40:27 +0000 | [diff] [blame] | 231 | return 1; |
| 232 | } |
| 233 | |
| 234 | /* create a new process and its main thread */ |
Alexandre Julliard | 5b4f3e8 | 2000-05-01 16:24:22 +0000 | [diff] [blame] | 235 | struct thread *create_process( int fd ) |
Alexandre Julliard | 642d313 | 1998-07-12 19:29:36 +0000 | [diff] [blame] | 236 | { |
Alexandre Julliard | eb2e77f | 1999-06-04 19:49:54 +0000 | [diff] [blame] | 237 | struct process *process; |
Alexandre Julliard | 2fe5777 | 2000-01-25 01:40:27 +0000 | [diff] [blame] | 238 | struct thread *thread = NULL; |
Alexandre Julliard | 8859d77 | 2001-03-01 22:13:49 +0000 | [diff] [blame] | 239 | int request_pipe[2]; |
Alexandre Julliard | eb2e77f | 1999-06-04 19:49:54 +0000 | [diff] [blame] | 240 | |
Alexandre Julliard | e66207e | 2003-02-19 00:33:32 +0000 | [diff] [blame] | 241 | if (!(process = alloc_object( &process_ops ))) goto error; |
Alexandre Julliard | f692d44 | 1999-03-21 19:23:54 +0000 | [diff] [blame] | 242 | process->next = NULL; |
Alexandre Julliard | 767e6f6 | 1998-08-09 12:47:43 +0000 | [diff] [blame] | 243 | process->prev = NULL; |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 244 | process->parent = NULL; |
Alexandre Julliard | 767e6f6 | 1998-08-09 12:47:43 +0000 | [diff] [blame] | 245 | process->thread_list = NULL; |
Alexandre Julliard | 3da5f84 | 1999-05-16 16:54:54 +0000 | [diff] [blame] | 246 | process->debugger = NULL; |
Alexandre Julliard | eb2e77f | 1999-06-04 19:49:54 +0000 | [diff] [blame] | 247 | process->handles = NULL; |
Alexandre Julliard | e66207e | 2003-02-19 00:33:32 +0000 | [diff] [blame] | 248 | process->msg_fd = NULL; |
Dave Pickles | 717bf7e | 2000-02-13 16:04:14 +0000 | [diff] [blame] | 249 | process->exit_code = STILL_ACTIVE; |
Alexandre Julliard | 767e6f6 | 1998-08-09 12:47:43 +0000 | [diff] [blame] | 250 | process->running_threads = 0; |
Alexandre Julliard | 62a8b43 | 1999-01-19 17:48:23 +0000 | [diff] [blame] | 251 | process->priority = NORMAL_PRIORITY_CLASS; |
| 252 | process->affinity = 1; |
Alexandre Julliard | 3da5f84 | 1999-05-16 16:54:54 +0000 | [diff] [blame] | 253 | process->suspend = 0; |
Alexandre Julliard | d083a7b | 1999-11-29 02:10:56 +0000 | [diff] [blame] | 254 | process->create_flags = 0; |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 255 | process->console = NULL; |
Alexandre Julliard | ca96de3 | 2002-05-25 21:15:03 +0000 | [diff] [blame] | 256 | process->startup_state = STARTUP_IN_PROGRESS; |
Alexandre Julliard | 9d80215 | 2002-05-24 21:20:27 +0000 | [diff] [blame] | 257 | process->startup_info = NULL; |
Alexandre Julliard | c5e433a | 2000-05-30 19:48:18 +0000 | [diff] [blame] | 258 | process->idle_event = NULL; |
| 259 | process->queue = NULL; |
Turchanov Sergei | 43a27e3 | 2000-05-30 20:32:06 +0000 | [diff] [blame] | 260 | process->atom_table = NULL; |
Alexandre Julliard | 0a7c1f6 | 2000-01-27 02:54:17 +0000 | [diff] [blame] | 261 | process->ldt_copy = NULL; |
Alexandre Julliard | 05f0b71 | 2000-03-09 18:18:41 +0000 | [diff] [blame] | 262 | process->exe.next = NULL; |
| 263 | process->exe.prev = NULL; |
| 264 | process->exe.file = NULL; |
| 265 | process->exe.dbg_offset = 0; |
| 266 | process->exe.dbg_size = 0; |
Alexandre Julliard | aeb5660 | 2002-03-22 00:21:23 +0000 | [diff] [blame] | 267 | process->exe.namelen = 0; |
| 268 | process->exe.filename = NULL; |
Alexandre Julliard | 54f2287 | 2002-10-03 19:54:57 +0000 | [diff] [blame] | 269 | process->group_id = 0; |
Mike McCormack | 36cd6f5 | 2003-07-24 00:07:00 +0000 | [diff] [blame^] | 270 | process->token = create_token(); |
Alexandre Julliard | ce61349 | 2003-03-18 05:04:33 +0000 | [diff] [blame] | 271 | list_init( &process->locks ); |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 272 | |
Alexandre Julliard | 767e6f6 | 1998-08-09 12:47:43 +0000 | [diff] [blame] | 273 | gettimeofday( &process->start_time, NULL ); |
Alexandre Julliard | 2fe5777 | 2000-01-25 01:40:27 +0000 | [diff] [blame] | 274 | if ((process->next = first_process) != NULL) process->next->prev = process; |
| 275 | first_process = process; |
Alexandre Julliard | eb2e77f | 1999-06-04 19:49:54 +0000 | [diff] [blame] | 276 | |
Alexandre Julliard | 91befe1 | 2003-02-01 01:38:40 +0000 | [diff] [blame] | 277 | if (!(process->id = alloc_ptid( process ))) goto error; |
Alexandre Julliard | 580da24 | 2003-03-12 22:38:14 +0000 | [diff] [blame] | 278 | if (!(process->msg_fd = create_anonymous_fd( &process_fd_ops, fd, &process->obj ))) goto error; |
Alexandre Julliard | 91befe1 | 2003-02-01 01:38:40 +0000 | [diff] [blame] | 279 | |
Alexandre Julliard | 7f74824 | 2000-12-26 00:30:30 +0000 | [diff] [blame] | 280 | /* create the main thread */ |
Alexandre Julliard | 8859d77 | 2001-03-01 22:13:49 +0000 | [diff] [blame] | 281 | if (pipe( request_pipe ) == -1) |
| 282 | { |
| 283 | file_set_error(); |
| 284 | goto error; |
| 285 | } |
Alexandre Julliard | 4144b5b | 2002-06-20 23:21:27 +0000 | [diff] [blame] | 286 | if (send_client_fd( process, request_pipe[1], 0 ) == -1) |
| 287 | { |
| 288 | close( request_pipe[0] ); |
| 289 | close( request_pipe[1] ); |
| 290 | goto error; |
| 291 | } |
Alexandre Julliard | 8859d77 | 2001-03-01 22:13:49 +0000 | [diff] [blame] | 292 | close( request_pipe[1] ); |
| 293 | if (!(thread = create_thread( request_pipe[0], process ))) goto error; |
Alexandre Julliard | 7f74824 | 2000-12-26 00:30:30 +0000 | [diff] [blame] | 294 | |
Alexandre Julliard | e66207e | 2003-02-19 00:33:32 +0000 | [diff] [blame] | 295 | set_fd_events( process->msg_fd, POLLIN ); /* start listening to events */ |
Alexandre Julliard | 2fe5777 | 2000-01-25 01:40:27 +0000 | [diff] [blame] | 296 | release_object( process ); |
| 297 | return thread; |
Alexandre Julliard | f692d44 | 1999-03-21 19:23:54 +0000 | [diff] [blame] | 298 | |
| 299 | error: |
Alexandre Julliard | 4144b5b | 2002-06-20 23:21:27 +0000 | [diff] [blame] | 300 | if (process) release_object( process ); |
| 301 | /* if we failed to start our first process, close everything down */ |
| 302 | if (!running_processes) close_master_socket(); |
Alexandre Julliard | f692d44 | 1999-03-21 19:23:54 +0000 | [diff] [blame] | 303 | return NULL; |
Alexandre Julliard | 642d313 | 1998-07-12 19:29:36 +0000 | [diff] [blame] | 304 | } |
| 305 | |
Alexandre Julliard | 77c8b1d | 2003-02-24 20:51:50 +0000 | [diff] [blame] | 306 | /* find the startup info for a given Unix process */ |
Alexandre Julliard | baf0a06 | 2003-03-11 01:48:53 +0000 | [diff] [blame] | 307 | inline static struct startup_info *find_startup_info( int unix_pid ) |
Alexandre Julliard | 77c8b1d | 2003-02-24 20:51:50 +0000 | [diff] [blame] | 308 | { |
| 309 | struct list *ptr; |
| 310 | |
| 311 | LIST_FOR_EACH( ptr, &startup_info_list ) |
| 312 | { |
| 313 | struct startup_info *info = LIST_ENTRY( ptr, struct startup_info, entry ); |
| 314 | if (info->unix_pid == unix_pid) return info; |
| 315 | } |
| 316 | return NULL; |
| 317 | } |
| 318 | |
Alexandre Julliard | 5b4f3e8 | 2000-05-01 16:24:22 +0000 | [diff] [blame] | 319 | /* initialize the current process and fill in the request */ |
Alexandre Julliard | 77c8b1d | 2003-02-24 20:51:50 +0000 | [diff] [blame] | 320 | static struct startup_info *init_process( struct init_process_reply *reply ) |
Alexandre Julliard | 5b4f3e8 | 2000-05-01 16:24:22 +0000 | [diff] [blame] | 321 | { |
| 322 | struct process *process = current->process; |
Alexandre Julliard | 77c8b1d | 2003-02-24 20:51:50 +0000 | [diff] [blame] | 323 | struct thread *parent_thread = NULL; |
Alexandre Julliard | 5b4f3e8 | 2000-05-01 16:24:22 +0000 | [diff] [blame] | 324 | struct process *parent = NULL; |
Alexandre Julliard | 77c8b1d | 2003-02-24 20:51:50 +0000 | [diff] [blame] | 325 | struct startup_info *info = find_startup_info( current->unix_pid ); |
Alexandre Julliard | 5b4f3e8 | 2000-05-01 16:24:22 +0000 | [diff] [blame] | 326 | |
Alexandre Julliard | 77c8b1d | 2003-02-24 20:51:50 +0000 | [diff] [blame] | 327 | if (info) |
Alexandre Julliard | 5b4f3e8 | 2000-05-01 16:24:22 +0000 | [diff] [blame] | 328 | { |
Alexandre Julliard | 77c8b1d | 2003-02-24 20:51:50 +0000 | [diff] [blame] | 329 | if (info->thread) |
Alexandre Julliard | 5b4f3e8 | 2000-05-01 16:24:22 +0000 | [diff] [blame] | 330 | { |
| 331 | fatal_protocol_error( current, "init_process: called twice?\n" ); |
Alexandre Julliard | 6543a65 | 2002-03-29 18:28:56 +0000 | [diff] [blame] | 332 | return NULL; |
Alexandre Julliard | 5b4f3e8 | 2000-05-01 16:24:22 +0000 | [diff] [blame] | 333 | } |
Alexandre Julliard | 77c8b1d | 2003-02-24 20:51:50 +0000 | [diff] [blame] | 334 | parent_thread = info->owner; |
| 335 | parent = parent_thread->process; |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 336 | process->parent = (struct process *)grab_object( parent ); |
Alexandre Julliard | 5b4f3e8 | 2000-05-01 16:24:22 +0000 | [diff] [blame] | 337 | } |
| 338 | |
| 339 | /* set the process flags */ |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 340 | process->create_flags = info ? info->create_flags : 0; |
Alexandre Julliard | 5b4f3e8 | 2000-05-01 16:24:22 +0000 | [diff] [blame] | 341 | |
| 342 | /* create the handle table */ |
Alexandre Julliard | 9d80215 | 2002-05-24 21:20:27 +0000 | [diff] [blame] | 343 | if (info && info->inherit_all) |
Alexandre Julliard | 5b4f3e8 | 2000-05-01 16:24:22 +0000 | [diff] [blame] | 344 | process->handles = copy_handle_table( process, parent ); |
| 345 | else |
| 346 | process->handles = alloc_handle_table( process, 0 ); |
Alexandre Julliard | 6543a65 | 2002-03-29 18:28:56 +0000 | [diff] [blame] | 347 | if (!process->handles) return NULL; |
Alexandre Julliard | 5b4f3e8 | 2000-05-01 16:24:22 +0000 | [diff] [blame] | 348 | |
| 349 | /* retrieve the main exe file */ |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 350 | reply->exe_file = 0; |
Alexandre Julliard | 9d80215 | 2002-05-24 21:20:27 +0000 | [diff] [blame] | 351 | if (info && info->exe_file) |
Alexandre Julliard | 5b4f3e8 | 2000-05-01 16:24:22 +0000 | [diff] [blame] | 352 | { |
Alexandre Julliard | d27624b | 2000-05-03 18:42:40 +0000 | [diff] [blame] | 353 | process->exe.file = (struct file *)grab_object( info->exe_file ); |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 354 | if (!(reply->exe_file = alloc_handle( process, process->exe.file, GENERIC_READ, 0 ))) |
Alexandre Julliard | 6543a65 | 2002-03-29 18:28:56 +0000 | [diff] [blame] | 355 | return NULL; |
Alexandre Julliard | 5b4f3e8 | 2000-05-01 16:24:22 +0000 | [diff] [blame] | 356 | } |
| 357 | |
| 358 | /* set the process console */ |
Alexandre Julliard | 6543a65 | 2002-03-29 18:28:56 +0000 | [diff] [blame] | 359 | if (!set_process_console( process, parent_thread, info, reply )) return NULL; |
Alexandre Julliard | 5b4f3e8 | 2000-05-01 16:24:22 +0000 | [diff] [blame] | 360 | |
Alexandre Julliard | 54f2287 | 2002-10-03 19:54:57 +0000 | [diff] [blame] | 361 | process->group_id = get_process_id( process ); |
Alexandre Julliard | 5b4f3e8 | 2000-05-01 16:24:22 +0000 | [diff] [blame] | 362 | if (parent) |
| 363 | { |
| 364 | /* attach to the debugger if requested */ |
| 365 | if (process->create_flags & (DEBUG_PROCESS | DEBUG_ONLY_THIS_PROCESS)) |
| 366 | set_process_debugger( process, parent_thread ); |
Alexandre Julliard | 9d80215 | 2002-05-24 21:20:27 +0000 | [diff] [blame] | 367 | else if (parent->debugger && !(parent->create_flags & DEBUG_ONLY_THIS_PROCESS)) |
Alexandre Julliard | 5b4f3e8 | 2000-05-01 16:24:22 +0000 | [diff] [blame] | 368 | set_process_debugger( process, parent->debugger ); |
Eric Pouech | 93bfa0d | 2002-06-02 21:22:22 +0000 | [diff] [blame] | 369 | if (!(process->create_flags & CREATE_NEW_PROCESS_GROUP)) |
| 370 | process->group_id = parent->group_id; |
Alexandre Julliard | 5b4f3e8 | 2000-05-01 16:24:22 +0000 | [diff] [blame] | 371 | } |
| 372 | |
| 373 | /* thread will be actually suspended in init_done */ |
| 374 | if (process->create_flags & CREATE_SUSPENDED) current->suspend++; |
| 375 | |
| 376 | if (info) |
| 377 | { |
Alexandre Julliard | 6543a65 | 2002-03-29 18:28:56 +0000 | [diff] [blame] | 378 | reply->info_size = info->data_size; |
Alexandre Julliard | 5b4f3e8 | 2000-05-01 16:24:22 +0000 | [diff] [blame] | 379 | info->process = (struct process *)grab_object( process ); |
| 380 | info->thread = (struct thread *)grab_object( current ); |
Alexandre Julliard | 5b4f3e8 | 2000-05-01 16:24:22 +0000 | [diff] [blame] | 381 | } |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 382 | reply->create_flags = process->create_flags; |
| 383 | reply->server_start = server_start_ticks; |
Alexandre Julliard | 6543a65 | 2002-03-29 18:28:56 +0000 | [diff] [blame] | 384 | return info ? (struct startup_info *)grab_object( info ) : NULL; |
Alexandre Julliard | 5b4f3e8 | 2000-05-01 16:24:22 +0000 | [diff] [blame] | 385 | } |
| 386 | |
Alexandre Julliard | 642d313 | 1998-07-12 19:29:36 +0000 | [diff] [blame] | 387 | /* destroy a process when its refcount is 0 */ |
Alexandre Julliard | 338e757 | 1998-12-27 15:28:54 +0000 | [diff] [blame] | 388 | static void process_destroy( struct object *obj ) |
Alexandre Julliard | 642d313 | 1998-07-12 19:29:36 +0000 | [diff] [blame] | 389 | { |
| 390 | struct process *process = (struct process *)obj; |
| 391 | assert( obj->ops == &process_ops ); |
| 392 | |
Alexandre Julliard | 767e6f6 | 1998-08-09 12:47:43 +0000 | [diff] [blame] | 393 | /* we can't have a thread remaining */ |
| 394 | assert( !process->thread_list ); |
Alexandre Julliard | 9d80215 | 2002-05-24 21:20:27 +0000 | [diff] [blame] | 395 | |
| 396 | set_process_startup_state( process, STARTUP_ABORTED ); |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 397 | if (process->console) release_object( process->console ); |
| 398 | if (process->parent) release_object( process->parent ); |
Alexandre Julliard | e66207e | 2003-02-19 00:33:32 +0000 | [diff] [blame] | 399 | if (process->msg_fd) release_object( process->msg_fd ); |
Alexandre Julliard | 642d313 | 1998-07-12 19:29:36 +0000 | [diff] [blame] | 400 | if (process->next) process->next->prev = process->prev; |
| 401 | if (process->prev) process->prev->next = process->next; |
| 402 | else first_process = process->next; |
Alexandre Julliard | c5e433a | 2000-05-30 19:48:18 +0000 | [diff] [blame] | 403 | if (process->idle_event) release_object( process->idle_event ); |
| 404 | if (process->queue) release_object( process->queue ); |
Turchanov Sergei | 43a27e3 | 2000-05-30 20:32:06 +0000 | [diff] [blame] | 405 | if (process->atom_table) release_object( process->atom_table ); |
Alexandre Julliard | 05f0b71 | 2000-03-09 18:18:41 +0000 | [diff] [blame] | 406 | if (process->exe.file) release_object( process->exe.file ); |
Alexandre Julliard | aeb5660 | 2002-03-22 00:21:23 +0000 | [diff] [blame] | 407 | if (process->exe.filename) free( process->exe.filename ); |
Alexandre Julliard | 91befe1 | 2003-02-01 01:38:40 +0000 | [diff] [blame] | 408 | if (process->id) free_ptid( process->id ); |
Mike McCormack | 36cd6f5 | 2003-07-24 00:07:00 +0000 | [diff] [blame^] | 409 | if (process->token) release_object( process->token ); |
Alexandre Julliard | 642d313 | 1998-07-12 19:29:36 +0000 | [diff] [blame] | 410 | } |
| 411 | |
Alexandre Julliard | 767e6f6 | 1998-08-09 12:47:43 +0000 | [diff] [blame] | 412 | /* dump a process on stdout for debugging purposes */ |
Alexandre Julliard | 338e757 | 1998-12-27 15:28:54 +0000 | [diff] [blame] | 413 | static void process_dump( struct object *obj, int verbose ) |
Alexandre Julliard | 767e6f6 | 1998-08-09 12:47:43 +0000 | [diff] [blame] | 414 | { |
| 415 | struct process *process = (struct process *)obj; |
| 416 | assert( obj->ops == &process_ops ); |
| 417 | |
Alexandre Julliard | 91befe1 | 2003-02-01 01:38:40 +0000 | [diff] [blame] | 418 | fprintf( stderr, "Process id=%04x next=%p prev=%p handles=%p\n", |
| 419 | process->id, process->next, process->prev, process->handles ); |
Alexandre Julliard | 767e6f6 | 1998-08-09 12:47:43 +0000 | [diff] [blame] | 420 | } |
| 421 | |
Alexandre Julliard | 85ed45e | 1998-08-22 19:03:56 +0000 | [diff] [blame] | 422 | static int process_signaled( struct object *obj, struct thread *thread ) |
| 423 | { |
| 424 | struct process *process = (struct process *)obj; |
Alexandre Julliard | dbc033a | 1999-03-13 08:58:24 +0000 | [diff] [blame] | 425 | return !process->running_threads; |
Alexandre Julliard | 85ed45e | 1998-08-22 19:03:56 +0000 | [diff] [blame] | 426 | } |
| 427 | |
Alexandre Julliard | cf27a7f | 2003-02-14 20:27:09 +0000 | [diff] [blame] | 428 | static void process_poll_event( struct fd *fd, int event ) |
Alexandre Julliard | f524240 | 2001-02-28 21:45:23 +0000 | [diff] [blame] | 429 | { |
Alexandre Julliard | cf27a7f | 2003-02-14 20:27:09 +0000 | [diff] [blame] | 430 | struct process *process = get_fd_user( fd ); |
| 431 | assert( process->obj.ops == &process_ops ); |
Alexandre Julliard | f524240 | 2001-02-28 21:45:23 +0000 | [diff] [blame] | 432 | |
Alexandre Julliard | e66207e | 2003-02-19 00:33:32 +0000 | [diff] [blame] | 433 | if (event & (POLLERR | POLLHUP)) set_fd_events( fd, -1 ); |
Alexandre Julliard | f524240 | 2001-02-28 21:45:23 +0000 | [diff] [blame] | 434 | else if (event & POLLIN) receive_fd( process ); |
| 435 | } |
| 436 | |
Alexandre Julliard | 5b4f3e8 | 2000-05-01 16:24:22 +0000 | [diff] [blame] | 437 | static void startup_info_destroy( struct object *obj ) |
| 438 | { |
| 439 | struct startup_info *info = (struct startup_info *)obj; |
| 440 | assert( obj->ops == &startup_info_ops ); |
Alexandre Julliard | 77c8b1d | 2003-02-24 20:51:50 +0000 | [diff] [blame] | 441 | list_remove( &info->entry ); |
Alexandre Julliard | 6543a65 | 2002-03-29 18:28:56 +0000 | [diff] [blame] | 442 | if (info->data) free( info->data ); |
Alexandre Julliard | d27624b | 2000-05-03 18:42:40 +0000 | [diff] [blame] | 443 | if (info->exe_file) release_object( info->exe_file ); |
Alexandre Julliard | 5b4f3e8 | 2000-05-01 16:24:22 +0000 | [diff] [blame] | 444 | if (info->process) release_object( info->process ); |
| 445 | if (info->thread) release_object( info->thread ); |
Alexandre Julliard | 77c8b1d | 2003-02-24 20:51:50 +0000 | [diff] [blame] | 446 | if (info->owner) release_object( info->owner ); |
Alexandre Julliard | 5b4f3e8 | 2000-05-01 16:24:22 +0000 | [diff] [blame] | 447 | } |
| 448 | |
| 449 | static void startup_info_dump( struct object *obj, int verbose ) |
| 450 | { |
| 451 | struct startup_info *info = (struct startup_info *)obj; |
| 452 | assert( obj->ops == &startup_info_ops ); |
| 453 | |
Alexandre Julliard | b3332d7 | 2002-10-19 01:00:59 +0000 | [diff] [blame] | 454 | fprintf( stderr, "Startup info flags=%x in=%p out=%p err=%p\n", |
Alexandre Julliard | ca96de3 | 2002-05-25 21:15:03 +0000 | [diff] [blame] | 455 | info->create_flags, info->hstdin, info->hstdout, info->hstderr ); |
Alexandre Julliard | 5b4f3e8 | 2000-05-01 16:24:22 +0000 | [diff] [blame] | 456 | } |
| 457 | |
| 458 | static int startup_info_signaled( struct object *obj, struct thread *thread ) |
| 459 | { |
| 460 | struct startup_info *info = (struct startup_info *)obj; |
Alexandre Julliard | ca96de3 | 2002-05-25 21:15:03 +0000 | [diff] [blame] | 461 | return info->process && is_process_init_done(info->process); |
Alexandre Julliard | 5b4f3e8 | 2000-05-01 16:24:22 +0000 | [diff] [blame] | 462 | } |
| 463 | |
Alexandre Julliard | 642d313 | 1998-07-12 19:29:36 +0000 | [diff] [blame] | 464 | /* get a process from an id (and increment the refcount) */ |
Alexandre Julliard | 54f2287 | 2002-10-03 19:54:57 +0000 | [diff] [blame] | 465 | struct process *get_process_from_id( process_id_t id ) |
Alexandre Julliard | 642d313 | 1998-07-12 19:29:36 +0000 | [diff] [blame] | 466 | { |
Alexandre Julliard | 91befe1 | 2003-02-01 01:38:40 +0000 | [diff] [blame] | 467 | struct object *obj = get_ptid_entry( id ); |
| 468 | |
| 469 | if (obj && obj->ops == &process_ops) return (struct process *)grab_object( obj ); |
| 470 | set_error( STATUS_INVALID_PARAMETER ); |
| 471 | return NULL; |
Alexandre Julliard | 642d313 | 1998-07-12 19:29:36 +0000 | [diff] [blame] | 472 | } |
Alexandre Julliard | 767e6f6 | 1998-08-09 12:47:43 +0000 | [diff] [blame] | 473 | |
| 474 | /* get a process from a handle (and increment the refcount) */ |
Alexandre Julliard | 5188574 | 2002-05-30 20:12:58 +0000 | [diff] [blame] | 475 | struct process *get_process_from_handle( obj_handle_t handle, unsigned int access ) |
Alexandre Julliard | 767e6f6 | 1998-08-09 12:47:43 +0000 | [diff] [blame] | 476 | { |
| 477 | return (struct process *)get_handle_obj( current->process, handle, |
| 478 | access, &process_ops ); |
| 479 | } |
| 480 | |
Alexandre Julliard | 05f0b71 | 2000-03-09 18:18:41 +0000 | [diff] [blame] | 481 | /* add a dll to a process list */ |
| 482 | static struct process_dll *process_load_dll( struct process *process, struct file *file, |
Alexandre Julliard | aeb5660 | 2002-03-22 00:21:23 +0000 | [diff] [blame] | 483 | void *base, const char *filename, size_t name_len ) |
Alexandre Julliard | 05f0b71 | 2000-03-09 18:18:41 +0000 | [diff] [blame] | 484 | { |
| 485 | struct process_dll *dll; |
| 486 | |
| 487 | /* make sure we don't already have one with the same base address */ |
| 488 | for (dll = process->exe.next; dll; dll = dll->next) if (dll->base == base) |
| 489 | { |
| 490 | set_error( STATUS_INVALID_PARAMETER ); |
| 491 | return NULL; |
| 492 | } |
| 493 | |
| 494 | if ((dll = mem_alloc( sizeof(*dll) ))) |
| 495 | { |
| 496 | dll->prev = &process->exe; |
| 497 | dll->file = NULL; |
| 498 | dll->base = base; |
Alexandre Julliard | aeb5660 | 2002-03-22 00:21:23 +0000 | [diff] [blame] | 499 | dll->filename = NULL; |
| 500 | dll->namelen = name_len; |
| 501 | if (name_len && !(dll->filename = memdup( filename, name_len ))) |
| 502 | { |
| 503 | free( dll ); |
| 504 | return NULL; |
| 505 | } |
Alexandre Julliard | 05f0b71 | 2000-03-09 18:18:41 +0000 | [diff] [blame] | 506 | if (file) dll->file = (struct file *)grab_object( file ); |
| 507 | if ((dll->next = process->exe.next)) dll->next->prev = dll; |
| 508 | process->exe.next = dll; |
| 509 | } |
| 510 | return dll; |
| 511 | } |
| 512 | |
| 513 | /* remove a dll from a process list */ |
| 514 | static void process_unload_dll( struct process *process, void *base ) |
| 515 | { |
| 516 | struct process_dll *dll; |
| 517 | |
| 518 | for (dll = process->exe.next; dll; dll = dll->next) |
| 519 | { |
| 520 | if (dll->base == base) |
| 521 | { |
| 522 | if (dll->file) release_object( dll->file ); |
| 523 | if (dll->next) dll->next->prev = dll->prev; |
| 524 | if (dll->prev) dll->prev->next = dll->next; |
Alexandre Julliard | aeb5660 | 2002-03-22 00:21:23 +0000 | [diff] [blame] | 525 | if (dll->filename) free( dll->filename ); |
Alexandre Julliard | 05f0b71 | 2000-03-09 18:18:41 +0000 | [diff] [blame] | 526 | free( dll ); |
| 527 | generate_debug_event( current, UNLOAD_DLL_DEBUG_EVENT, base ); |
| 528 | return; |
| 529 | } |
| 530 | } |
| 531 | set_error( STATUS_INVALID_PARAMETER ); |
| 532 | } |
| 533 | |
Alexandre Julliard | 40043ed | 2002-08-16 20:02:15 +0000 | [diff] [blame] | 534 | /* kill all processes */ |
| 535 | void kill_all_processes( struct process *skip, int exit_code ) |
| 536 | { |
| 537 | for (;;) |
| 538 | { |
| 539 | struct process *process = first_process; |
| 540 | |
| 541 | while (process && (!process->running_threads || process == skip)) |
| 542 | process = process->next; |
| 543 | if (!process) break; |
| 544 | kill_process( process, NULL, exit_code ); |
| 545 | } |
| 546 | } |
| 547 | |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 548 | /* kill all processes being attached to a console renderer */ |
Eric Pouech | 3940d8a | 2001-12-04 20:17:43 +0000 | [diff] [blame] | 549 | void kill_console_processes( struct thread *renderer, int exit_code ) |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 550 | { |
| 551 | for (;;) /* restart from the beginning of the list every time */ |
| 552 | { |
| 553 | struct process *process = first_process; |
| 554 | |
| 555 | /* find the first process being attached to 'renderer' and still running */ |
| 556 | while (process && |
Eric Pouech | 3940d8a | 2001-12-04 20:17:43 +0000 | [diff] [blame] | 557 | (process == renderer->process || !process->console || |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 558 | process->console->renderer != renderer || !process->running_threads)) |
| 559 | { |
| 560 | process = process->next; |
| 561 | } |
| 562 | if (!process) break; |
| 563 | kill_process( process, NULL, exit_code ); |
| 564 | } |
| 565 | } |
| 566 | |
Alexandre Julliard | 767e6f6 | 1998-08-09 12:47:43 +0000 | [diff] [blame] | 567 | /* a process has been killed (i.e. its last thread died) */ |
Alexandre Julliard | 05f0b71 | 2000-03-09 18:18:41 +0000 | [diff] [blame] | 568 | static void process_killed( struct process *process ) |
Alexandre Julliard | 767e6f6 | 1998-08-09 12:47:43 +0000 | [diff] [blame] | 569 | { |
| 570 | assert( !process->thread_list ); |
Alexandre Julliard | 767e6f6 | 1998-08-09 12:47:43 +0000 | [diff] [blame] | 571 | gettimeofday( &process->end_time, NULL ); |
Alexandre Julliard | 5b4f3e8 | 2000-05-01 16:24:22 +0000 | [diff] [blame] | 572 | if (process->handles) release_object( process->handles ); |
Alexandre Julliard | eb2e77f | 1999-06-04 19:49:54 +0000 | [diff] [blame] | 573 | process->handles = NULL; |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 574 | |
| 575 | /* close the console attached to this process, if any */ |
Alexandre Julliard | eb2e77f | 1999-06-04 19:49:54 +0000 | [diff] [blame] | 576 | free_console( process ); |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 577 | |
Alexandre Julliard | 05f0b71 | 2000-03-09 18:18:41 +0000 | [diff] [blame] | 578 | while (process->exe.next) |
| 579 | { |
| 580 | struct process_dll *dll = process->exe.next; |
| 581 | process->exe.next = dll->next; |
| 582 | if (dll->file) release_object( dll->file ); |
Alexandre Julliard | aeb5660 | 2002-03-22 00:21:23 +0000 | [diff] [blame] | 583 | if (dll->filename) free( dll->filename ); |
Alexandre Julliard | 05f0b71 | 2000-03-09 18:18:41 +0000 | [diff] [blame] | 584 | free( dll ); |
| 585 | } |
Alexandre Julliard | 9d80215 | 2002-05-24 21:20:27 +0000 | [diff] [blame] | 586 | set_process_startup_state( process, STARTUP_ABORTED ); |
Alexandre Julliard | 05f0b71 | 2000-03-09 18:18:41 +0000 | [diff] [blame] | 587 | if (process->exe.file) release_object( process->exe.file ); |
| 588 | process->exe.file = NULL; |
Alexandre Julliard | 85ed45e | 1998-08-22 19:03:56 +0000 | [diff] [blame] | 589 | wake_up( &process->obj, 0 ); |
Alexandre Julliard | 4144b5b | 2002-06-20 23:21:27 +0000 | [diff] [blame] | 590 | if (!--running_processes) close_master_socket(); |
Alexandre Julliard | 767e6f6 | 1998-08-09 12:47:43 +0000 | [diff] [blame] | 591 | } |
| 592 | |
Alexandre Julliard | 767e6f6 | 1998-08-09 12:47:43 +0000 | [diff] [blame] | 593 | /* add a thread to a process running threads list */ |
| 594 | void add_process_thread( struct process *process, struct thread *thread ) |
| 595 | { |
| 596 | thread->proc_next = process->thread_list; |
| 597 | thread->proc_prev = NULL; |
| 598 | if (thread->proc_next) thread->proc_next->proc_prev = thread; |
| 599 | process->thread_list = thread; |
Alexandre Julliard | fdc92ba | 1999-02-14 18:03:15 +0000 | [diff] [blame] | 600 | if (!process->running_threads++) running_processes++; |
Alexandre Julliard | 767e6f6 | 1998-08-09 12:47:43 +0000 | [diff] [blame] | 601 | grab_object( thread ); |
| 602 | } |
| 603 | |
| 604 | /* remove a thread from a process running threads list */ |
| 605 | void remove_process_thread( struct process *process, struct thread *thread ) |
| 606 | { |
| 607 | assert( process->running_threads > 0 ); |
| 608 | assert( process->thread_list ); |
| 609 | |
| 610 | if (thread->proc_next) thread->proc_next->proc_prev = thread->proc_prev; |
| 611 | if (thread->proc_prev) thread->proc_prev->proc_next = thread->proc_next; |
| 612 | else process->thread_list = thread->proc_next; |
| 613 | |
| 614 | if (!--process->running_threads) |
| 615 | { |
| 616 | /* we have removed the last running thread, exit the process */ |
Alexandre Julliard | 05f0b71 | 2000-03-09 18:18:41 +0000 | [diff] [blame] | 617 | process->exit_code = thread->exit_code; |
| 618 | generate_debug_event( thread, EXIT_PROCESS_DEBUG_EVENT, process ); |
| 619 | process_killed( process ); |
Alexandre Julliard | 767e6f6 | 1998-08-09 12:47:43 +0000 | [diff] [blame] | 620 | } |
Alexandre Julliard | 05f0b71 | 2000-03-09 18:18:41 +0000 | [diff] [blame] | 621 | else generate_debug_event( thread, EXIT_THREAD_DEBUG_EVENT, thread ); |
Alexandre Julliard | 767e6f6 | 1998-08-09 12:47:43 +0000 | [diff] [blame] | 622 | release_object( thread ); |
| 623 | } |
| 624 | |
Alexandre Julliard | 3da5f84 | 1999-05-16 16:54:54 +0000 | [diff] [blame] | 625 | /* suspend all the threads of a process */ |
| 626 | void suspend_process( struct process *process ) |
| 627 | { |
| 628 | if (!process->suspend++) |
| 629 | { |
| 630 | struct thread *thread = process->thread_list; |
Alexandre Julliard | ad16fc9 | 2002-04-06 00:03:33 +0000 | [diff] [blame] | 631 | while (thread) |
Alexandre Julliard | 3da5f84 | 1999-05-16 16:54:54 +0000 | [diff] [blame] | 632 | { |
Alexandre Julliard | ad16fc9 | 2002-04-06 00:03:33 +0000 | [diff] [blame] | 633 | struct thread *next = thread->proc_next; |
Alexandre Julliard | 0a70783 | 1999-11-08 05:31:47 +0000 | [diff] [blame] | 634 | if (!thread->suspend) stop_thread( thread ); |
Alexandre Julliard | ad16fc9 | 2002-04-06 00:03:33 +0000 | [diff] [blame] | 635 | thread = next; |
Alexandre Julliard | 3da5f84 | 1999-05-16 16:54:54 +0000 | [diff] [blame] | 636 | } |
| 637 | } |
| 638 | } |
| 639 | |
| 640 | /* resume all the threads of a process */ |
| 641 | void resume_process( struct process *process ) |
| 642 | { |
| 643 | assert (process->suspend > 0); |
| 644 | if (!--process->suspend) |
| 645 | { |
| 646 | struct thread *thread = process->thread_list; |
Alexandre Julliard | ad16fc9 | 2002-04-06 00:03:33 +0000 | [diff] [blame] | 647 | while (thread) |
Alexandre Julliard | 3da5f84 | 1999-05-16 16:54:54 +0000 | [diff] [blame] | 648 | { |
Alexandre Julliard | ad16fc9 | 2002-04-06 00:03:33 +0000 | [diff] [blame] | 649 | struct thread *next = thread->proc_next; |
Alexandre Julliard | d04ccb8 | 2003-03-04 22:18:43 +0000 | [diff] [blame] | 650 | if (!thread->suspend) wake_thread( thread ); |
Alexandre Julliard | ad16fc9 | 2002-04-06 00:03:33 +0000 | [diff] [blame] | 651 | thread = next; |
Alexandre Julliard | 3da5f84 | 1999-05-16 16:54:54 +0000 | [diff] [blame] | 652 | } |
| 653 | } |
| 654 | } |
| 655 | |
Alexandre Julliard | 767e6f6 | 1998-08-09 12:47:43 +0000 | [diff] [blame] | 656 | /* kill a process on the spot */ |
Alexandre Julliard | f524240 | 2001-02-28 21:45:23 +0000 | [diff] [blame] | 657 | void kill_process( struct process *process, struct thread *skip, int exit_code ) |
Alexandre Julliard | 767e6f6 | 1998-08-09 12:47:43 +0000 | [diff] [blame] | 658 | { |
Alexandre Julliard | 12f29b5 | 2000-03-17 15:16:57 +0000 | [diff] [blame] | 659 | struct thread *thread = process->thread_list; |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 660 | |
Alexandre Julliard | 12f29b5 | 2000-03-17 15:16:57 +0000 | [diff] [blame] | 661 | while (thread) |
| 662 | { |
| 663 | struct thread *next = thread->proc_next; |
| 664 | thread->exit_code = exit_code; |
| 665 | if (thread != skip) kill_thread( thread, 1 ); |
| 666 | thread = next; |
| 667 | } |
Alexandre Julliard | 767e6f6 | 1998-08-09 12:47:43 +0000 | [diff] [blame] | 668 | } |
| 669 | |
Alexandre Julliard | 17cf810 | 1999-11-24 01:22:14 +0000 | [diff] [blame] | 670 | /* kill all processes being debugged by a given thread */ |
| 671 | void kill_debugged_processes( struct thread *debugger, int exit_code ) |
| 672 | { |
| 673 | for (;;) /* restart from the beginning of the list every time */ |
| 674 | { |
| 675 | struct process *process = first_process; |
| 676 | /* find the first process being debugged by 'debugger' and still running */ |
| 677 | while (process && (process->debugger != debugger || !process->running_threads)) |
| 678 | process = process->next; |
| 679 | if (!process) return; |
| 680 | process->debugger = NULL; |
Alexandre Julliard | 12f29b5 | 2000-03-17 15:16:57 +0000 | [diff] [blame] | 681 | kill_process( process, NULL, exit_code ); |
Alexandre Julliard | 17cf810 | 1999-11-24 01:22:14 +0000 | [diff] [blame] | 682 | } |
| 683 | } |
| 684 | |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 685 | |
Eric Pouech | fbccb38 | 2002-02-27 01:28:30 +0000 | [diff] [blame] | 686 | /* detach a debugger from all its debuggees */ |
| 687 | void detach_debugged_processes( struct thread *debugger ) |
| 688 | { |
| 689 | struct process *process; |
| 690 | for (process = first_process; process; process = process->next) |
| 691 | { |
| 692 | if (process->debugger == debugger && process->running_threads) |
| 693 | { |
| 694 | debugger_detach( process, debugger ); |
| 695 | } |
| 696 | } |
| 697 | } |
| 698 | |
| 699 | |
Eric Pouech | 93bfa0d | 2002-06-02 21:22:22 +0000 | [diff] [blame] | 700 | void enum_processes( int (*cb)(struct process*, void*), void *user ) |
| 701 | { |
| 702 | struct process *process; |
| 703 | for (process = first_process; process; process = process->next) |
| 704 | { |
| 705 | if ((cb)(process, user)) break; |
| 706 | } |
| 707 | } |
| 708 | |
| 709 | |
Alexandre Julliard | 767e6f6 | 1998-08-09 12:47:43 +0000 | [diff] [blame] | 710 | /* get all information about a process */ |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 711 | static void get_process_info( struct process *process, struct get_process_info_reply *reply ) |
Alexandre Julliard | 767e6f6 | 1998-08-09 12:47:43 +0000 | [diff] [blame] | 712 | { |
Eric Pouech | fbccb38 | 2002-02-27 01:28:30 +0000 | [diff] [blame] | 713 | reply->pid = get_process_id( process ); |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 714 | reply->debugged = (process->debugger != 0); |
| 715 | reply->exit_code = process->exit_code; |
| 716 | reply->priority = process->priority; |
| 717 | reply->process_affinity = process->affinity; |
| 718 | reply->system_affinity = 1; |
Alexandre Julliard | 62a8b43 | 1999-01-19 17:48:23 +0000 | [diff] [blame] | 719 | } |
| 720 | |
| 721 | /* set all information about a process */ |
Alexandre Julliard | 43c190e | 1999-05-15 10:48:19 +0000 | [diff] [blame] | 722 | static void set_process_info( struct process *process, |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 723 | const struct set_process_info_request *req ) |
Alexandre Julliard | 62a8b43 | 1999-01-19 17:48:23 +0000 | [diff] [blame] | 724 | { |
| 725 | if (req->mask & SET_PROCESS_INFO_PRIORITY) |
| 726 | process->priority = req->priority; |
| 727 | if (req->mask & SET_PROCESS_INFO_AFFINITY) |
| 728 | { |
Alexandre Julliard | cb1fc73 | 2000-01-24 21:58:06 +0000 | [diff] [blame] | 729 | if (req->affinity != 1) set_error( STATUS_INVALID_PARAMETER ); |
Alexandre Julliard | 62a8b43 | 1999-01-19 17:48:23 +0000 | [diff] [blame] | 730 | else process->affinity = req->affinity; |
| 731 | } |
| 732 | } |
| 733 | |
Alexandre Julliard | 8b8828f | 1999-11-12 21:39:14 +0000 | [diff] [blame] | 734 | /* read data from a process memory space */ |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 735 | /* len is the total size (in ints) */ |
| 736 | static int read_process_memory( struct process *process, const int *addr, size_t len, int *dest ) |
Alexandre Julliard | 8b8828f | 1999-11-12 21:39:14 +0000 | [diff] [blame] | 737 | { |
| 738 | struct thread *thread = process->thread_list; |
Alexandre Julliard | 8b8828f | 1999-11-12 21:39:14 +0000 | [diff] [blame] | 739 | |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 740 | assert( !((unsigned int)addr % sizeof(int)) ); /* address must be aligned */ |
| 741 | |
Alexandre Julliard | 00641d5 | 2000-03-08 16:41:37 +0000 | [diff] [blame] | 742 | if (!thread) /* process is dead */ |
| 743 | { |
| 744 | set_error( STATUS_ACCESS_DENIED ); |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 745 | return 0; |
Alexandre Julliard | 00641d5 | 2000-03-08 16:41:37 +0000 | [diff] [blame] | 746 | } |
Alexandre Julliard | 98aacc7 | 2000-03-15 19:46:14 +0000 | [diff] [blame] | 747 | if (suspend_for_ptrace( thread )) |
Alexandre Julliard | 8b8828f | 1999-11-12 21:39:14 +0000 | [diff] [blame] | 748 | { |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 749 | while (len > 0) |
Alexandre Julliard | 8b8828f | 1999-11-12 21:39:14 +0000 | [diff] [blame] | 750 | { |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 751 | if (read_thread_int( thread, addr++, dest++ ) == -1) break; |
Alexandre Julliard | eef7025 | 1999-11-13 19:54:54 +0000 | [diff] [blame] | 752 | len--; |
| 753 | } |
Alexandre Julliard | d04ccb8 | 2003-03-04 22:18:43 +0000 | [diff] [blame] | 754 | resume_after_ptrace( thread ); |
Alexandre Julliard | 8b8828f | 1999-11-12 21:39:14 +0000 | [diff] [blame] | 755 | } |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 756 | return !len; |
| 757 | } |
| 758 | |
| 759 | /* make sure we can write to the whole address range */ |
| 760 | /* len is the total size (in ints) */ |
| 761 | static int check_process_write_access( struct thread *thread, int *addr, size_t len ) |
| 762 | { |
| 763 | int page = get_page_size() / sizeof(int); |
| 764 | |
| 765 | for (;;) |
| 766 | { |
| 767 | if (write_thread_int( thread, addr, 0, 0 ) == -1) return 0; |
| 768 | if (len <= page) break; |
| 769 | addr += page; |
| 770 | len -= page; |
| 771 | } |
| 772 | return (write_thread_int( thread, addr + len - 1, 0, 0 ) != -1); |
Alexandre Julliard | eef7025 | 1999-11-13 19:54:54 +0000 | [diff] [blame] | 773 | } |
| 774 | |
| 775 | /* write data to a process memory space */ |
| 776 | /* len is the total size (in ints), max is the size we can actually read from the input buffer */ |
| 777 | /* we check the total size for write permissions */ |
| 778 | static void write_process_memory( struct process *process, int *addr, size_t len, |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 779 | unsigned int first_mask, unsigned int last_mask, const int *src ) |
Alexandre Julliard | eef7025 | 1999-11-13 19:54:54 +0000 | [diff] [blame] | 780 | { |
| 781 | struct thread *thread = process->thread_list; |
Alexandre Julliard | eef7025 | 1999-11-13 19:54:54 +0000 | [diff] [blame] | 782 | |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 783 | assert( !((unsigned int)addr % sizeof(int) )); /* address must be aligned */ |
| 784 | |
Alexandre Julliard | 00641d5 | 2000-03-08 16:41:37 +0000 | [diff] [blame] | 785 | if (!thread) /* process is dead */ |
| 786 | { |
| 787 | set_error( STATUS_ACCESS_DENIED ); |
| 788 | return; |
| 789 | } |
Alexandre Julliard | 98aacc7 | 2000-03-15 19:46:14 +0000 | [diff] [blame] | 790 | if (suspend_for_ptrace( thread )) |
Alexandre Julliard | eef7025 | 1999-11-13 19:54:54 +0000 | [diff] [blame] | 791 | { |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 792 | if (!check_process_write_access( thread, addr, len )) |
| 793 | { |
| 794 | set_error( STATUS_ACCESS_DENIED ); |
Peter Hunnisett | a3c5ad4 | 2003-02-28 21:50:47 +0000 | [diff] [blame] | 795 | goto done; |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 796 | } |
Alexandre Julliard | eef7025 | 1999-11-13 19:54:54 +0000 | [diff] [blame] | 797 | /* first word is special */ |
| 798 | if (len > 1) |
| 799 | { |
Alexandre Julliard | 578c100 | 1999-11-14 21:23:21 +0000 | [diff] [blame] | 800 | if (write_thread_int( thread, addr++, *src++, first_mask ) == -1) goto done; |
Alexandre Julliard | eef7025 | 1999-11-13 19:54:54 +0000 | [diff] [blame] | 801 | len--; |
Alexandre Julliard | eef7025 | 1999-11-13 19:54:54 +0000 | [diff] [blame] | 802 | } |
| 803 | else last_mask &= first_mask; |
| 804 | |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 805 | while (len > 1) |
Alexandre Julliard | eef7025 | 1999-11-13 19:54:54 +0000 | [diff] [blame] | 806 | { |
Alexandre Julliard | 578c100 | 1999-11-14 21:23:21 +0000 | [diff] [blame] | 807 | if (write_thread_int( thread, addr++, *src++, ~0 ) == -1) goto done; |
Alexandre Julliard | eef7025 | 1999-11-13 19:54:54 +0000 | [diff] [blame] | 808 | len--; |
| 809 | } |
| 810 | |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 811 | /* last word is special too */ |
| 812 | if (write_thread_int( thread, addr, *src, last_mask ) == -1) goto done; |
| 813 | |
Alexandre Julliard | 98aacc7 | 2000-03-15 19:46:14 +0000 | [diff] [blame] | 814 | done: |
Alexandre Julliard | d04ccb8 | 2003-03-04 22:18:43 +0000 | [diff] [blame] | 815 | resume_after_ptrace( thread ); |
Alexandre Julliard | eef7025 | 1999-11-13 19:54:54 +0000 | [diff] [blame] | 816 | } |
Alexandre Julliard | 8b8828f | 1999-11-12 21:39:14 +0000 | [diff] [blame] | 817 | } |
| 818 | |
Alexandre Julliard | fdc92ba | 1999-02-14 18:03:15 +0000 | [diff] [blame] | 819 | /* take a snapshot of currently running processes */ |
| 820 | struct process_snapshot *process_snap( int *count ) |
| 821 | { |
| 822 | struct process_snapshot *snapshot, *ptr; |
| 823 | struct process *process; |
| 824 | if (!running_processes) return NULL; |
| 825 | if (!(snapshot = mem_alloc( sizeof(*snapshot) * running_processes ))) |
| 826 | return NULL; |
| 827 | ptr = snapshot; |
| 828 | for (process = first_process; process; process = process->next) |
| 829 | { |
| 830 | if (!process->running_threads) continue; |
| 831 | ptr->process = process; |
| 832 | ptr->threads = process->running_threads; |
Alexandre Julliard | 07d8446 | 2000-04-16 19:45:05 +0000 | [diff] [blame] | 833 | ptr->count = process->obj.refcount; |
Alexandre Julliard | fdc92ba | 1999-02-14 18:03:15 +0000 | [diff] [blame] | 834 | ptr->priority = process->priority; |
| 835 | grab_object( process ); |
| 836 | ptr++; |
| 837 | } |
| 838 | *count = running_processes; |
| 839 | return snapshot; |
| 840 | } |
Alexandre Julliard | 43c190e | 1999-05-15 10:48:19 +0000 | [diff] [blame] | 841 | |
Alexandre Julliard | 07d8446 | 2000-04-16 19:45:05 +0000 | [diff] [blame] | 842 | /* take a snapshot of the modules of a process */ |
| 843 | struct module_snapshot *module_snap( struct process *process, int *count ) |
| 844 | { |
| 845 | struct module_snapshot *snapshot, *ptr; |
| 846 | struct process_dll *dll; |
| 847 | int total = 0; |
| 848 | |
| 849 | for (dll = &process->exe; dll; dll = dll->next) total++; |
| 850 | if (!(snapshot = mem_alloc( sizeof(*snapshot) * total ))) return NULL; |
| 851 | |
| 852 | for (ptr = snapshot, dll = &process->exe; dll; dll = dll->next, ptr++) |
| 853 | { |
Alexandre Julliard | aeb5660 | 2002-03-22 00:21:23 +0000 | [diff] [blame] | 854 | ptr->base = dll->base; |
| 855 | ptr->size = dll->size; |
| 856 | ptr->namelen = dll->namelen; |
| 857 | ptr->filename = memdup( dll->filename, dll->namelen ); |
Alexandre Julliard | 07d8446 | 2000-04-16 19:45:05 +0000 | [diff] [blame] | 858 | } |
| 859 | *count = total; |
| 860 | return snapshot; |
| 861 | } |
| 862 | |
| 863 | |
Alexandre Julliard | 43c190e | 1999-05-15 10:48:19 +0000 | [diff] [blame] | 864 | /* create a new process */ |
| 865 | DECL_HANDLER(new_process) |
| 866 | { |
Alexandre Julliard | 5b4f3e8 | 2000-05-01 16:24:22 +0000 | [diff] [blame] | 867 | struct startup_info *info; |
Alexandre Julliard | 43c190e | 1999-05-15 10:48:19 +0000 | [diff] [blame] | 868 | |
Alexandre Julliard | 5b4f3e8 | 2000-05-01 16:24:22 +0000 | [diff] [blame] | 869 | /* build the startup info for a new process */ |
Alexandre Julliard | e66207e | 2003-02-19 00:33:32 +0000 | [diff] [blame] | 870 | if (!(info = alloc_object( &startup_info_ops ))) return; |
Alexandre Julliard | 77c8b1d | 2003-02-24 20:51:50 +0000 | [diff] [blame] | 871 | list_add_head( &startup_info_list, &info->entry ); |
Alexandre Julliard | 5b4f3e8 | 2000-05-01 16:24:22 +0000 | [diff] [blame] | 872 | info->inherit_all = req->inherit_all; |
Alexandre Julliard | 6543a65 | 2002-03-29 18:28:56 +0000 | [diff] [blame] | 873 | info->use_handles = req->use_handles; |
Alexandre Julliard | 5b4f3e8 | 2000-05-01 16:24:22 +0000 | [diff] [blame] | 874 | info->create_flags = req->create_flags; |
Alexandre Julliard | 77c8b1d | 2003-02-24 20:51:50 +0000 | [diff] [blame] | 875 | info->unix_pid = req->unix_pid; |
Alexandre Julliard | 5b4f3e8 | 2000-05-01 16:24:22 +0000 | [diff] [blame] | 876 | info->hstdin = req->hstdin; |
| 877 | info->hstdout = req->hstdout; |
| 878 | info->hstderr = req->hstderr; |
Alexandre Julliard | d27624b | 2000-05-03 18:42:40 +0000 | [diff] [blame] | 879 | info->exe_file = NULL; |
Alexandre Julliard | e9936d9 | 2001-01-26 00:22:26 +0000 | [diff] [blame] | 880 | info->owner = (struct thread *)grab_object( current ); |
Alexandre Julliard | 5b4f3e8 | 2000-05-01 16:24:22 +0000 | [diff] [blame] | 881 | info->process = NULL; |
| 882 | info->thread = NULL; |
Alexandre Julliard | 6543a65 | 2002-03-29 18:28:56 +0000 | [diff] [blame] | 883 | info->data_size = get_req_data_size(); |
| 884 | info->data = NULL; |
Alexandre Julliard | 6a72dc5 | 2000-04-14 13:42:00 +0000 | [diff] [blame] | 885 | |
Alexandre Julliard | 8081e5a | 2001-01-05 04:08:07 +0000 | [diff] [blame] | 886 | if (req->exe_file && |
Alexandre Julliard | d27624b | 2000-05-03 18:42:40 +0000 | [diff] [blame] | 887 | !(info->exe_file = get_file_obj( current->process, req->exe_file, GENERIC_READ ))) |
Alexandre Julliard | e9936d9 | 2001-01-26 00:22:26 +0000 | [diff] [blame] | 888 | goto done; |
Alexandre Julliard | d27624b | 2000-05-03 18:42:40 +0000 | [diff] [blame] | 889 | |
Alexandre Julliard | 6543a65 | 2002-03-29 18:28:56 +0000 | [diff] [blame] | 890 | if (!(info->data = mem_alloc( info->data_size ))) goto done; |
| 891 | memcpy( info->data, get_req_data(), info->data_size ); |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 892 | reply->info = alloc_handle( current->process, info, SYNCHRONIZE, FALSE ); |
Alexandre Julliard | e9936d9 | 2001-01-26 00:22:26 +0000 | [diff] [blame] | 893 | |
| 894 | done: |
| 895 | release_object( info ); |
Alexandre Julliard | 5b4f3e8 | 2000-05-01 16:24:22 +0000 | [diff] [blame] | 896 | } |
Alexandre Julliard | 6a72dc5 | 2000-04-14 13:42:00 +0000 | [diff] [blame] | 897 | |
Alexandre Julliard | e9936d9 | 2001-01-26 00:22:26 +0000 | [diff] [blame] | 898 | /* Retrieve information about a newly started process */ |
| 899 | DECL_HANDLER(get_new_process_info) |
Alexandre Julliard | 5b4f3e8 | 2000-05-01 16:24:22 +0000 | [diff] [blame] | 900 | { |
Alexandre Julliard | e9936d9 | 2001-01-26 00:22:26 +0000 | [diff] [blame] | 901 | struct startup_info *info; |
| 902 | |
Alexandre Julliard | e9936d9 | 2001-01-26 00:22:26 +0000 | [diff] [blame] | 903 | if ((info = (struct startup_info *)get_handle_obj( current->process, req->info, |
| 904 | 0, &startup_info_ops ))) |
Alexandre Julliard | 5b4f3e8 | 2000-05-01 16:24:22 +0000 | [diff] [blame] | 905 | { |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 906 | 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 Julliard | ca96de3 | 2002-05-25 21:15:03 +0000 | [diff] [blame] | 912 | reply->success = is_process_init_done( info->process ); |
Alexandre Julliard | e9936d9 | 2001-01-26 00:22:26 +0000 | [diff] [blame] | 913 | release_object( info ); |
Alexandre Julliard | 5b4f3e8 | 2000-05-01 16:24:22 +0000 | [diff] [blame] | 914 | } |
| 915 | else |
| 916 | { |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 917 | reply->pid = 0; |
| 918 | reply->tid = 0; |
| 919 | reply->phandle = 0; |
| 920 | reply->thandle = 0; |
Alexandre Julliard | 9d80215 | 2002-05-24 21:20:27 +0000 | [diff] [blame] | 921 | reply->success = 0; |
Alexandre Julliard | 5b4f3e8 | 2000-05-01 16:24:22 +0000 | [diff] [blame] | 922 | } |
Alexandre Julliard | 43c190e | 1999-05-15 10:48:19 +0000 | [diff] [blame] | 923 | } |
| 924 | |
Alexandre Julliard | 6543a65 | 2002-03-29 18:28:56 +0000 | [diff] [blame] | 925 | /* Retrieve the new process startup info */ |
| 926 | DECL_HANDLER(get_startup_info) |
| 927 | { |
| 928 | struct startup_info *info; |
| 929 | |
Alexandre Julliard | 9d80215 | 2002-05-24 21:20:27 +0000 | [diff] [blame] | 930 | if ((info = current->process->startup_info)) |
Alexandre Julliard | 6543a65 | 2002-03-29 18:28:56 +0000 | [diff] [blame] | 931 | { |
| 932 | size_t size = info->data_size; |
| 933 | if (size > get_reply_max_size()) size = get_reply_max_size(); |
Alexandre Julliard | 9d80215 | 2002-05-24 21:20:27 +0000 | [diff] [blame] | 934 | |
| 935 | /* we return the data directly without making a copy so this can only be called once */ |
| 936 | set_reply_data_ptr( info->data, size ); |
| 937 | info->data = NULL; |
| 938 | info->data_size = 0; |
Alexandre Julliard | 6543a65 | 2002-03-29 18:28:56 +0000 | [diff] [blame] | 939 | } |
| 940 | } |
| 941 | |
| 942 | |
Alexandre Julliard | 43c190e | 1999-05-15 10:48:19 +0000 | [diff] [blame] | 943 | /* initialize a new process */ |
| 944 | DECL_HANDLER(init_process) |
| 945 | { |
Alexandre Julliard | 02a53c1 | 2003-02-25 04:17:22 +0000 | [diff] [blame] | 946 | if (current->unix_pid == -1) |
Alexandre Julliard | 43c190e | 1999-05-15 10:48:19 +0000 | [diff] [blame] | 947 | { |
Alexandre Julliard | ebe29ef | 1999-06-26 08:43:26 +0000 | [diff] [blame] | 948 | fatal_protocol_error( current, "init_process: init_thread not called yet\n" ); |
Alexandre Julliard | 43c190e | 1999-05-15 10:48:19 +0000 | [diff] [blame] | 949 | return; |
| 950 | } |
Alexandre Julliard | 9d80215 | 2002-05-24 21:20:27 +0000 | [diff] [blame] | 951 | if (current->process->startup_info) |
Alexandre Julliard | 6543a65 | 2002-03-29 18:28:56 +0000 | [diff] [blame] | 952 | { |
Alexandre Julliard | 9d80215 | 2002-05-24 21:20:27 +0000 | [diff] [blame] | 953 | fatal_protocol_error( current, "init_process: called twice\n" ); |
| 954 | return; |
Alexandre Julliard | 6543a65 | 2002-03-29 18:28:56 +0000 | [diff] [blame] | 955 | } |
Alexandre Julliard | 9d80215 | 2002-05-24 21:20:27 +0000 | [diff] [blame] | 956 | reply->info_size = 0; |
| 957 | current->process->ldt_copy = req->ldt_copy; |
Alexandre Julliard | 77c8b1d | 2003-02-24 20:51:50 +0000 | [diff] [blame] | 958 | current->process->startup_info = init_process( reply ); |
Alexandre Julliard | 43c190e | 1999-05-15 10:48:19 +0000 | [diff] [blame] | 959 | } |
| 960 | |
Alexandre Julliard | ec7bb23 | 1999-11-12 03:35:25 +0000 | [diff] [blame] | 961 | /* signal the end of the process initialization */ |
| 962 | DECL_HANDLER(init_process_done) |
| 963 | { |
Alexandre Julliard | ac2e4f1 | 2001-10-25 19:52:12 +0000 | [diff] [blame] | 964 | struct file *file = NULL; |
Alexandre Julliard | ec7bb23 | 1999-11-12 03:35:25 +0000 | [diff] [blame] | 965 | struct process *process = current->process; |
Alexandre Julliard | ac2e4f1 | 2001-10-25 19:52:12 +0000 | [diff] [blame] | 966 | |
Alexandre Julliard | 9d80215 | 2002-05-24 21:20:27 +0000 | [diff] [blame] | 967 | if (is_process_init_done(process)) |
Alexandre Julliard | ec7bb23 | 1999-11-12 03:35:25 +0000 | [diff] [blame] | 968 | { |
Alexandre Julliard | 9d80215 | 2002-05-24 21:20:27 +0000 | [diff] [blame] | 969 | fatal_protocol_error( current, "init_process_done: called twice\n" ); |
| 970 | return; |
| 971 | } |
| 972 | if (!req->module) |
| 973 | { |
| 974 | fatal_protocol_error( current, "init_process_done: module base address cannot be 0\n" ); |
Alexandre Julliard | ec7bb23 | 1999-11-12 03:35:25 +0000 | [diff] [blame] | 975 | return; |
| 976 | } |
Alexandre Julliard | 05f0b71 | 2000-03-09 18:18:41 +0000 | [diff] [blame] | 977 | process->exe.base = req->module; |
Alexandre Julliard | aeb5660 | 2002-03-22 00:21:23 +0000 | [diff] [blame] | 978 | process->exe.size = req->module_size; |
Alexandre Julliard | a37dec0 | 2000-06-08 00:57:24 +0000 | [diff] [blame] | 979 | process->exe.name = req->name; |
Alexandre Julliard | ad29b90 | 2001-01-05 22:24:15 +0000 | [diff] [blame] | 980 | |
Alexandre Julliard | ca96de3 | 2002-05-25 21:15:03 +0000 | [diff] [blame] | 981 | if (req->exe_file) file = get_file_obj( process, req->exe_file, GENERIC_READ ); |
Alexandre Julliard | ac2e4f1 | 2001-10-25 19:52:12 +0000 | [diff] [blame] | 982 | if (process->exe.file) release_object( process->exe.file ); |
| 983 | process->exe.file = file; |
| 984 | |
Alexandre Julliard | aeb5660 | 2002-03-22 00:21:23 +0000 | [diff] [blame] | 985 | if ((process->exe.namelen = get_req_data_size())) |
| 986 | process->exe.filename = memdup( get_req_data(), process->exe.namelen ); |
| 987 | |
Alexandre Julliard | 9d80215 | 2002-05-24 21:20:27 +0000 | [diff] [blame] | 988 | generate_startup_debug_events( process, req->entry ); |
| 989 | set_process_startup_state( process, STARTUP_DONE ); |
| 990 | |
Alexandre Julliard | c5e433a | 2000-05-30 19:48:18 +0000 | [diff] [blame] | 991 | if (req->gui) process->idle_event = create_event( NULL, 0, 1, 0 ); |
Alexandre Julliard | ca96de3 | 2002-05-25 21:15:03 +0000 | [diff] [blame] | 992 | if (current->suspend + process->suspend > 0) stop_thread( current ); |
| 993 | reply->debugged = (process->debugger != 0); |
Alexandre Julliard | ec7bb23 | 1999-11-12 03:35:25 +0000 | [diff] [blame] | 994 | } |
| 995 | |
Alexandre Julliard | 43c190e | 1999-05-15 10:48:19 +0000 | [diff] [blame] | 996 | /* open a handle to a process */ |
| 997 | DECL_HANDLER(open_process) |
| 998 | { |
Alexandre Julliard | 43c190e | 1999-05-15 10:48:19 +0000 | [diff] [blame] | 999 | struct process *process = get_process_from_id( req->pid ); |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 1000 | reply->handle = 0; |
Alexandre Julliard | 43c190e | 1999-05-15 10:48:19 +0000 | [diff] [blame] | 1001 | if (process) |
| 1002 | { |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 1003 | reply->handle = alloc_handle( current->process, process, req->access, req->inherit ); |
Alexandre Julliard | 43c190e | 1999-05-15 10:48:19 +0000 | [diff] [blame] | 1004 | release_object( process ); |
| 1005 | } |
Alexandre Julliard | 43c190e | 1999-05-15 10:48:19 +0000 | [diff] [blame] | 1006 | } |
| 1007 | |
| 1008 | /* terminate a process */ |
| 1009 | DECL_HANDLER(terminate_process) |
| 1010 | { |
| 1011 | struct process *process; |
| 1012 | |
| 1013 | if ((process = get_process_from_handle( req->handle, PROCESS_TERMINATE ))) |
| 1014 | { |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 1015 | reply->self = (current->process == process); |
Alexandre Julliard | 12f29b5 | 2000-03-17 15:16:57 +0000 | [diff] [blame] | 1016 | kill_process( process, current, req->exit_code ); |
Alexandre Julliard | 43c190e | 1999-05-15 10:48:19 +0000 | [diff] [blame] | 1017 | release_object( process ); |
| 1018 | } |
Alexandre Julliard | 43c190e | 1999-05-15 10:48:19 +0000 | [diff] [blame] | 1019 | } |
| 1020 | |
| 1021 | /* fetch information about a process */ |
| 1022 | DECL_HANDLER(get_process_info) |
| 1023 | { |
| 1024 | struct process *process; |
Alexandre Julliard | 43c190e | 1999-05-15 10:48:19 +0000 | [diff] [blame] | 1025 | |
| 1026 | if ((process = get_process_from_handle( req->handle, PROCESS_QUERY_INFORMATION ))) |
| 1027 | { |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 1028 | get_process_info( process, reply ); |
Alexandre Julliard | 43c190e | 1999-05-15 10:48:19 +0000 | [diff] [blame] | 1029 | release_object( process ); |
| 1030 | } |
Alexandre Julliard | 43c190e | 1999-05-15 10:48:19 +0000 | [diff] [blame] | 1031 | } |
| 1032 | |
| 1033 | /* set information about a process */ |
| 1034 | DECL_HANDLER(set_process_info) |
| 1035 | { |
| 1036 | struct process *process; |
| 1037 | |
| 1038 | if ((process = get_process_from_handle( req->handle, PROCESS_SET_INFORMATION ))) |
| 1039 | { |
| 1040 | set_process_info( process, req ); |
| 1041 | release_object( process ); |
| 1042 | } |
Alexandre Julliard | 43c190e | 1999-05-15 10:48:19 +0000 | [diff] [blame] | 1043 | } |
Alexandre Julliard | 8b8828f | 1999-11-12 21:39:14 +0000 | [diff] [blame] | 1044 | |
| 1045 | /* read data from a process address space */ |
| 1046 | DECL_HANDLER(read_process_memory) |
| 1047 | { |
| 1048 | struct process *process; |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 1049 | size_t len = get_reply_max_size(); |
Alexandre Julliard | 8b8828f | 1999-11-12 21:39:14 +0000 | [diff] [blame] | 1050 | |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 1051 | if (!(process = get_process_from_handle( req->handle, PROCESS_VM_READ ))) return; |
| 1052 | |
| 1053 | if (len) |
Alexandre Julliard | 8b8828f | 1999-11-12 21:39:14 +0000 | [diff] [blame] | 1054 | { |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 1055 | unsigned int start_offset = (unsigned int)req->addr % sizeof(int); |
| 1056 | unsigned int nb_ints = (len + start_offset + sizeof(int) - 1) / sizeof(int); |
| 1057 | const int *start = (int *)((char *)req->addr - start_offset); |
| 1058 | int *buffer = mem_alloc( nb_ints * sizeof(int) ); |
| 1059 | if (buffer) |
| 1060 | { |
| 1061 | if (read_process_memory( process, start, nb_ints, buffer )) |
| 1062 | { |
| 1063 | /* move start of requested data to start of buffer */ |
| 1064 | if (start_offset) memmove( buffer, (char *)buffer + start_offset, len ); |
| 1065 | set_reply_data_ptr( buffer, len ); |
| 1066 | } |
| 1067 | else len = 0; |
| 1068 | } |
Alexandre Julliard | 8b8828f | 1999-11-12 21:39:14 +0000 | [diff] [blame] | 1069 | } |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 1070 | release_object( process ); |
Alexandre Julliard | 8b8828f | 1999-11-12 21:39:14 +0000 | [diff] [blame] | 1071 | } |
Alexandre Julliard | eef7025 | 1999-11-13 19:54:54 +0000 | [diff] [blame] | 1072 | |
| 1073 | /* write data to a process address space */ |
| 1074 | DECL_HANDLER(write_process_memory) |
| 1075 | { |
| 1076 | struct process *process; |
| 1077 | |
| 1078 | if ((process = get_process_from_handle( req->handle, PROCESS_VM_WRITE ))) |
| 1079 | { |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 1080 | size_t len = get_req_data_size(); |
| 1081 | if ((len % sizeof(int)) || ((unsigned int)req->addr % sizeof(int))) |
| 1082 | set_error( STATUS_INVALID_PARAMETER ); |
| 1083 | else |
| 1084 | { |
| 1085 | if (len) write_process_memory( process, req->addr, len / sizeof(int), |
| 1086 | req->first_mask, req->last_mask, get_req_data() ); |
| 1087 | } |
Alexandre Julliard | eef7025 | 1999-11-13 19:54:54 +0000 | [diff] [blame] | 1088 | release_object( process ); |
| 1089 | } |
| 1090 | } |
Alexandre Julliard | 05f0b71 | 2000-03-09 18:18:41 +0000 | [diff] [blame] | 1091 | |
| 1092 | /* notify the server that a dll has been loaded */ |
| 1093 | DECL_HANDLER(load_dll) |
| 1094 | { |
| 1095 | struct process_dll *dll; |
| 1096 | struct file *file = NULL; |
| 1097 | |
Alexandre Julliard | 8081e5a | 2001-01-05 04:08:07 +0000 | [diff] [blame] | 1098 | if (req->handle && |
Alexandre Julliard | 05f0b71 | 2000-03-09 18:18:41 +0000 | [diff] [blame] | 1099 | !(file = get_file_obj( current->process, req->handle, GENERIC_READ ))) return; |
Alexandre Julliard | 8081e5a | 2001-01-05 04:08:07 +0000 | [diff] [blame] | 1100 | |
Alexandre Julliard | aeb5660 | 2002-03-22 00:21:23 +0000 | [diff] [blame] | 1101 | if ((dll = process_load_dll( current->process, file, req->base, |
| 1102 | get_req_data(), get_req_data_size() ))) |
Alexandre Julliard | 05f0b71 | 2000-03-09 18:18:41 +0000 | [diff] [blame] | 1103 | { |
Alexandre Julliard | aeb5660 | 2002-03-22 00:21:23 +0000 | [diff] [blame] | 1104 | dll->size = req->size; |
Alexandre Julliard | 05f0b71 | 2000-03-09 18:18:41 +0000 | [diff] [blame] | 1105 | dll->dbg_offset = req->dbg_offset; |
| 1106 | dll->dbg_size = req->dbg_size; |
| 1107 | dll->name = req->name; |
| 1108 | /* only generate event if initialization is done */ |
Alexandre Julliard | 9d80215 | 2002-05-24 21:20:27 +0000 | [diff] [blame] | 1109 | if (is_process_init_done( current->process )) |
Alexandre Julliard | 05f0b71 | 2000-03-09 18:18:41 +0000 | [diff] [blame] | 1110 | generate_debug_event( current, LOAD_DLL_DEBUG_EVENT, dll ); |
| 1111 | } |
| 1112 | if (file) release_object( file ); |
| 1113 | } |
| 1114 | |
| 1115 | /* notify the server that a dll is being unloaded */ |
| 1116 | DECL_HANDLER(unload_dll) |
| 1117 | { |
| 1118 | process_unload_dll( current->process, req->base ); |
| 1119 | } |
Alexandre Julliard | c5e433a | 2000-05-30 19:48:18 +0000 | [diff] [blame] | 1120 | |
Eric Pouech | 2359b57 | 2003-01-09 00:01:28 +0000 | [diff] [blame] | 1121 | /* retrieve information about a module in a process */ |
| 1122 | DECL_HANDLER(get_dll_info) |
| 1123 | { |
| 1124 | struct process *process; |
| 1125 | |
| 1126 | if ((process = get_process_from_handle( req->handle, PROCESS_QUERY_INFORMATION ))) |
| 1127 | { |
| 1128 | struct process_dll *dll; |
| 1129 | |
| 1130 | for (dll = &process->exe; dll; dll = dll->next) |
| 1131 | { |
| 1132 | if (dll->base == req->base_address) |
| 1133 | { |
| 1134 | reply->size = dll->size; |
| 1135 | reply->entry_point = 0; /* FIXME */ |
| 1136 | if (dll->filename) |
| 1137 | { |
| 1138 | size_t len = min( dll->namelen, get_reply_max_size() ); |
| 1139 | set_reply_data( dll->filename, len ); |
| 1140 | } |
| 1141 | break; |
| 1142 | } |
| 1143 | } |
| 1144 | if (!dll) |
| 1145 | set_error(STATUS_DLL_NOT_FOUND); |
| 1146 | release_object( process ); |
| 1147 | } |
| 1148 | } |
| 1149 | |
Alexandre Julliard | c5e433a | 2000-05-30 19:48:18 +0000 | [diff] [blame] | 1150 | /* wait for a process to start waiting on input */ |
| 1151 | /* FIXME: only returns event for now, wait is done in the client */ |
| 1152 | DECL_HANDLER(wait_input_idle) |
| 1153 | { |
| 1154 | struct process *process; |
| 1155 | |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 1156 | reply->event = 0; |
Alexandre Julliard | c5e433a | 2000-05-30 19:48:18 +0000 | [diff] [blame] | 1157 | if ((process = get_process_from_handle( req->handle, PROCESS_QUERY_INFORMATION ))) |
| 1158 | { |
| 1159 | if (process->idle_event && process != current->process && process->queue != current->queue) |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 1160 | reply->event = alloc_handle( current->process, process->idle_event, |
| 1161 | EVENT_ALL_ACCESS, 0 ); |
Alexandre Julliard | c5e433a | 2000-05-30 19:48:18 +0000 | [diff] [blame] | 1162 | release_object( process ); |
| 1163 | } |
| 1164 | } |