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