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 |
Jonathan Ernst | 360a3f9 | 2006-05-18 14:49:52 +0200 | [diff] [blame] | 18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, 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" |
Alexandre Julliard | bfce151 | 2003-12-10 04:08:06 +0000 | [diff] [blame] | 49 | #include "user.h" |
Robert Shearman | d2ea92d | 2005-04-22 21:17:15 +0000 | [diff] [blame] | 50 | #include "security.h" |
Alexandre Julliard | 642d313 | 1998-07-12 19:29:36 +0000 | [diff] [blame] | 51 | |
Alexandre Julliard | f692d44 | 1999-03-21 19:23:54 +0000 | [diff] [blame] | 52 | /* process structure */ |
Alexandre Julliard | 43c190e | 1999-05-15 10:48:19 +0000 | [diff] [blame] | 53 | |
Alexandre Julliard | 48c0d51 | 2005-02-25 19:31:26 +0000 | [diff] [blame] | 54 | static struct list process_list = LIST_INIT(process_list); |
Alexandre Julliard | 156b205 | 2007-06-06 20:33:13 +0200 | [diff] [blame] | 55 | static int running_processes, user_processes; |
| 56 | static struct event *user_process_event; /* signaled when all user processes have exited */ |
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 */ |
Rob Shearman | c1707d8 | 2007-10-03 13:10:37 +0100 | [diff] [blame] | 77 | default_get_sd, /* get_sd */ |
| 78 | default_set_sd, /* set_sd */ |
Vitaliy Margolen | baffcb9 | 2005-11-22 14:55:42 +0000 | [diff] [blame] | 79 | no_lookup_name, /* lookup_name */ |
Alexandre Julliard | 7e71c1d | 2007-03-22 11:44:29 +0100 | [diff] [blame] | 80 | no_open_file, /* open_file */ |
Alexandre Julliard | b9b1ea9 | 2005-06-09 15:39:52 +0000 | [diff] [blame] | 81 | no_close_handle, /* close_handle */ |
Alexandre Julliard | 863637b | 2003-01-30 00:26:44 +0000 | [diff] [blame] | 82 | process_destroy /* destroy */ |
| 83 | }; |
| 84 | |
| 85 | static const struct fd_ops process_fd_ops = |
| 86 | { |
Alexandre Julliard | 1dca5e2 | 2000-01-01 00:56:27 +0000 | [diff] [blame] | 87 | NULL, /* get_poll_events */ |
Alexandre Julliard | f524240 | 2001-02-28 21:45:23 +0000 | [diff] [blame] | 88 | process_poll_event, /* poll_event */ |
Alexandre Julliard | 3f05759 | 2007-04-12 20:21:53 +0200 | [diff] [blame] | 89 | NULL, /* flush */ |
| 90 | NULL, /* get_fd_type */ |
Alexandre Julliard | 6357143 | 2007-04-16 14:45:03 +0200 | [diff] [blame] | 91 | NULL, /* ioctl */ |
Alexandre Julliard | 3f05759 | 2007-04-12 20:21:53 +0200 | [diff] [blame] | 92 | NULL, /* queue_async */ |
Alexandre Julliard | 72bff2e | 2007-04-10 17:07:27 +0200 | [diff] [blame] | 93 | NULL, /* reselect_async */ |
Alexandre Julliard | 3f05759 | 2007-04-12 20:21:53 +0200 | [diff] [blame] | 94 | NULL /* cancel async */ |
Alexandre Julliard | 642d313 | 1998-07-12 19:29:36 +0000 | [diff] [blame] | 95 | }; |
| 96 | |
Alexandre Julliard | 5b4f3e8 | 2000-05-01 16:24:22 +0000 | [diff] [blame] | 97 | /* process startup info */ |
| 98 | |
| 99 | struct startup_info |
Alexandre Julliard | 2fe5777 | 2000-01-25 01:40:27 +0000 | [diff] [blame] | 100 | { |
Alexandre Julliard | 5b4f3e8 | 2000-05-01 16:24:22 +0000 | [diff] [blame] | 101 | struct object obj; /* object header */ |
Alexandre Julliard | 5188574 | 2002-05-30 20:12:58 +0000 | [diff] [blame] | 102 | obj_handle_t hstdin; /* handle for stdin */ |
| 103 | obj_handle_t hstdout; /* handle for stdout */ |
| 104 | obj_handle_t hstderr; /* handle for stderr */ |
Alexandre Julliard | d27624b | 2000-05-03 18:42:40 +0000 | [diff] [blame] | 105 | struct file *exe_file; /* file handle for main exe */ |
Alexandre Julliard | 5b4f3e8 | 2000-05-01 16:24:22 +0000 | [diff] [blame] | 106 | struct process *process; /* created process */ |
Alexandre Julliard | 0f273c1 | 2006-07-26 10:43:25 +0200 | [diff] [blame] | 107 | data_size_t data_size; /* size of startup data */ |
Alexandre Julliard | 841f898 | 2003-10-04 04:09:41 +0000 | [diff] [blame] | 108 | void *data; /* data for startup info */ |
Alexandre Julliard | 5b4f3e8 | 2000-05-01 16:24:22 +0000 | [diff] [blame] | 109 | }; |
| 110 | |
| 111 | static void startup_info_dump( struct object *obj, int verbose ); |
| 112 | static int startup_info_signaled( struct object *obj, struct thread *thread ); |
| 113 | static void startup_info_destroy( struct object *obj ); |
| 114 | |
| 115 | static const struct object_ops startup_info_ops = |
| 116 | { |
| 117 | sizeof(struct startup_info), /* size */ |
| 118 | startup_info_dump, /* dump */ |
| 119 | add_queue, /* add_queue */ |
| 120 | remove_queue, /* remove_queue */ |
| 121 | startup_info_signaled, /* signaled */ |
| 122 | no_satisfied, /* satisfied */ |
Mike McCormack | f92fff6 | 2005-04-24 17:35:52 +0000 | [diff] [blame] | 123 | no_signal, /* signal */ |
Alexandre Julliard | 1ab243b | 2000-12-19 02:12:45 +0000 | [diff] [blame] | 124 | no_get_fd, /* get_fd */ |
Alexandre Julliard | 28beba3 | 2005-12-12 14:57:40 +0100 | [diff] [blame] | 125 | no_map_access, /* map_access */ |
Rob Shearman | c1707d8 | 2007-10-03 13:10:37 +0100 | [diff] [blame] | 126 | default_get_sd, /* get_sd */ |
| 127 | default_set_sd, /* set_sd */ |
Vitaliy Margolen | baffcb9 | 2005-11-22 14:55:42 +0000 | [diff] [blame] | 128 | no_lookup_name, /* lookup_name */ |
Alexandre Julliard | 7e71c1d | 2007-03-22 11:44:29 +0100 | [diff] [blame] | 129 | no_open_file, /* open_file */ |
Alexandre Julliard | b9b1ea9 | 2005-06-09 15:39:52 +0000 | [diff] [blame] | 130 | no_close_handle, /* close_handle */ |
Alexandre Julliard | 5b4f3e8 | 2000-05-01 16:24:22 +0000 | [diff] [blame] | 131 | startup_info_destroy /* destroy */ |
| 132 | }; |
| 133 | |
Alexandre Julliard | f692d44 | 1999-03-21 19:23:54 +0000 | [diff] [blame] | 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 | 68e850e | 2006-08-14 20:19:42 +0200 | [diff] [blame] | 228 | /* final cleanup once we are sure a process is really dead */ |
| 229 | static void process_died( struct process *process ) |
| 230 | { |
| 231 | if (debug_level) fprintf( stderr, "%04x: *process killed*\n", process->id ); |
Alexandre Julliard | 156b205 | 2007-06-06 20:33:13 +0200 | [diff] [blame] | 232 | if (!process->is_system) |
| 233 | { |
| 234 | if (!--user_processes && user_process_event) |
| 235 | set_event( user_process_event ); |
| 236 | } |
Alexandre Julliard | 68e850e | 2006-08-14 20:19:42 +0200 | [diff] [blame] | 237 | release_object( process ); |
| 238 | if (!--running_processes) close_master_socket(); |
| 239 | } |
| 240 | |
| 241 | /* callback for process sigkill timeout */ |
| 242 | static void process_sigkill( void *private ) |
| 243 | { |
| 244 | struct process *process = private; |
| 245 | |
| 246 | process->sigkill_timeout = NULL; |
| 247 | kill( process->unix_pid, SIGKILL ); |
| 248 | process_died( process ); |
| 249 | } |
| 250 | |
| 251 | /* start the sigkill timer for a process upon exit */ |
| 252 | static void start_sigkill_timer( struct process *process ) |
| 253 | { |
| 254 | grab_object( process ); |
| 255 | if (process->unix_pid != -1 && process->msg_fd) |
Alexandre Julliard | aaf477f | 2007-04-17 20:08:59 +0200 | [diff] [blame] | 256 | process->sigkill_timeout = add_timeout_user( -TICKS_PER_SEC, process_sigkill, process ); |
| 257 | else |
| 258 | process_died( process ); |
Alexandre Julliard | 68e850e | 2006-08-14 20:19:42 +0200 | [diff] [blame] | 259 | } |
| 260 | |
Alexandre Julliard | 2fe5777 | 2000-01-25 01:40:27 +0000 | [diff] [blame] | 261 | /* create a new process and its main thread */ |
Alexandre Julliard | c316f0e | 2006-07-19 14:00:10 +0200 | [diff] [blame] | 262 | /* if the function fails the fd is closed */ |
| 263 | struct thread *create_process( int fd, struct thread *parent_thread, int inherit_all ) |
Alexandre Julliard | 642d313 | 1998-07-12 19:29:36 +0000 | [diff] [blame] | 264 | { |
Alexandre Julliard | eb2e77f | 1999-06-04 19:49:54 +0000 | [diff] [blame] | 265 | struct process *process; |
Alexandre Julliard | 2fe5777 | 2000-01-25 01:40:27 +0000 | [diff] [blame] | 266 | struct thread *thread = NULL; |
Alexandre Julliard | 8859d77 | 2001-03-01 22:13:49 +0000 | [diff] [blame] | 267 | int request_pipe[2]; |
Alexandre Julliard | eb2e77f | 1999-06-04 19:49:54 +0000 | [diff] [blame] | 268 | |
Alexandre Julliard | c316f0e | 2006-07-19 14:00:10 +0200 | [diff] [blame] | 269 | if (!(process = alloc_object( &process_ops ))) |
| 270 | { |
| 271 | close( fd ); |
| 272 | goto error; |
| 273 | } |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 274 | process->parent = NULL; |
Alexandre Julliard | 3da5f84 | 1999-05-16 16:54:54 +0000 | [diff] [blame] | 275 | process->debugger = NULL; |
Alexandre Julliard | eb2e77f | 1999-06-04 19:49:54 +0000 | [diff] [blame] | 276 | process->handles = NULL; |
Alexandre Julliard | e66207e | 2003-02-19 00:33:32 +0000 | [diff] [blame] | 277 | process->msg_fd = NULL; |
Alexandre Julliard | 68e850e | 2006-08-14 20:19:42 +0200 | [diff] [blame] | 278 | process->sigkill_timeout = NULL; |
| 279 | process->unix_pid = -1; |
Dave Pickles | 717bf7e | 2000-02-13 16:04:14 +0000 | [diff] [blame] | 280 | process->exit_code = STILL_ACTIVE; |
Alexandre Julliard | 767e6f6 | 1998-08-09 12:47:43 +0000 | [diff] [blame] | 281 | process->running_threads = 0; |
Eric Pouech | b3badc7 | 2005-09-06 10:25:11 +0000 | [diff] [blame] | 282 | process->priority = PROCESS_PRIOCLASS_NORMAL; |
Alexandre Julliard | 62a8b43 | 1999-01-19 17:48:23 +0000 | [diff] [blame] | 283 | process->affinity = 1; |
Alexandre Julliard | 3da5f84 | 1999-05-16 16:54:54 +0000 | [diff] [blame] | 284 | process->suspend = 0; |
Alexandre Julliard | 156b205 | 2007-06-06 20:33:13 +0200 | [diff] [blame] | 285 | process->is_system = 0; |
Alexandre Julliard | d083a7b | 1999-11-29 02:10:56 +0000 | [diff] [blame] | 286 | process->create_flags = 0; |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 287 | process->console = NULL; |
Alexandre Julliard | ca96de3 | 2002-05-25 21:15:03 +0000 | [diff] [blame] | 288 | process->startup_state = STARTUP_IN_PROGRESS; |
Alexandre Julliard | 9d80215 | 2002-05-24 21:20:27 +0000 | [diff] [blame] | 289 | process->startup_info = NULL; |
Alexandre Julliard | c5e433a | 2000-05-30 19:48:18 +0000 | [diff] [blame] | 290 | process->idle_event = NULL; |
| 291 | process->queue = NULL; |
Alexandre Julliard | e55d593 | 2003-10-14 01:30:42 +0000 | [diff] [blame] | 292 | process->peb = NULL; |
Alexandre Julliard | 0a7c1f6 | 2000-01-27 02:54:17 +0000 | [diff] [blame] | 293 | process->ldt_copy = NULL; |
Alexandre Julliard | 1bf96e0 | 2005-06-08 18:44:50 +0000 | [diff] [blame] | 294 | process->winstation = 0; |
Alexandre Julliard | 78a3e63 | 2005-06-09 12:07:12 +0000 | [diff] [blame] | 295 | process->desktop = 0; |
Rob Shearman | ec86243 | 2007-05-28 18:41:51 +0100 | [diff] [blame] | 296 | process->token = NULL; |
Alexandre Julliard | cd1c7fc | 2006-12-29 16:56:11 +0100 | [diff] [blame] | 297 | process->trace_data = 0; |
Alexandre Julliard | 0502638 | 2005-03-01 10:56:18 +0000 | [diff] [blame] | 298 | list_init( &process->thread_list ); |
Alexandre Julliard | ce61349 | 2003-03-18 05:04:33 +0000 | [diff] [blame] | 299 | list_init( &process->locks ); |
Alexandre Julliard | bfce151 | 2003-12-10 04:08:06 +0000 | [diff] [blame] | 300 | list_init( &process->classes ); |
Alexandre Julliard | a9e0fb1 | 2005-03-02 10:20:09 +0000 | [diff] [blame] | 301 | list_init( &process->dlls ); |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 302 | |
Alexandre Julliard | 753c870 | 2006-08-10 16:42:09 +0200 | [diff] [blame] | 303 | process->start_time = current_time; |
Alexandre Julliard | aaf477f | 2007-04-17 20:08:59 +0200 | [diff] [blame] | 304 | process->end_time = 0; |
Alexandre Julliard | 48c0d51 | 2005-02-25 19:31:26 +0000 | [diff] [blame] | 305 | list_add_head( &process_list, &process->entry ); |
Alexandre Julliard | eb2e77f | 1999-06-04 19:49:54 +0000 | [diff] [blame] | 306 | |
Alexandre Julliard | c316f0e | 2006-07-19 14:00:10 +0200 | [diff] [blame] | 307 | if (!(process->id = process->group_id = alloc_ptid( process ))) |
| 308 | { |
| 309 | close( fd ); |
| 310 | goto error; |
| 311 | } |
Alexandre Julliard | f85437c | 2007-04-10 22:25:07 +0200 | [diff] [blame] | 312 | if (!(process->msg_fd = create_anonymous_fd( &process_fd_ops, fd, &process->obj, 0 ))) goto error; |
Alexandre Julliard | 91befe1 | 2003-02-01 01:38:40 +0000 | [diff] [blame] | 313 | |
Alexandre Julliard | c316f0e | 2006-07-19 14:00:10 +0200 | [diff] [blame] | 314 | /* create the handle table */ |
Rob Shearman | ec86243 | 2007-05-28 18:41:51 +0100 | [diff] [blame] | 315 | if (!parent_thread) |
| 316 | { |
| 317 | process->handles = alloc_handle_table( process, 0 ); |
| 318 | process->token = token_create_admin(); |
| 319 | } |
Alexandre Julliard | c316f0e | 2006-07-19 14:00:10 +0200 | [diff] [blame] | 320 | else |
| 321 | { |
| 322 | struct process *parent = parent_thread->process; |
| 323 | process->parent = (struct process *)grab_object( parent ); |
| 324 | process->handles = inherit_all ? copy_handle_table( process, parent ) |
| 325 | : alloc_handle_table( process, 0 ); |
Rob Shearman | ec86243 | 2007-05-28 18:41:51 +0100 | [diff] [blame] | 326 | /* Note: for security reasons, starting a new process does not attempt |
| 327 | * to use the current impersonation token for the new process */ |
| 328 | process->token = token_duplicate( parent->token, TRUE, 0 ); |
Alexandre Julliard | c316f0e | 2006-07-19 14:00:10 +0200 | [diff] [blame] | 329 | } |
Rob Shearman | ec86243 | 2007-05-28 18:41:51 +0100 | [diff] [blame] | 330 | if (!process->handles || !process->token) goto error; |
Alexandre Julliard | c316f0e | 2006-07-19 14:00:10 +0200 | [diff] [blame] | 331 | |
Alexandre Julliard | 7f74824 | 2000-12-26 00:30:30 +0000 | [diff] [blame] | 332 | /* create the main thread */ |
Alexandre Julliard | 8859d77 | 2001-03-01 22:13:49 +0000 | [diff] [blame] | 333 | if (pipe( request_pipe ) == -1) |
| 334 | { |
| 335 | file_set_error(); |
| 336 | goto error; |
| 337 | } |
Alexandre Julliard | 4144b5b | 2002-06-20 23:21:27 +0000 | [diff] [blame] | 338 | if (send_client_fd( process, request_pipe[1], 0 ) == -1) |
| 339 | { |
| 340 | close( request_pipe[0] ); |
| 341 | close( request_pipe[1] ); |
| 342 | goto error; |
| 343 | } |
Alexandre Julliard | 8859d77 | 2001-03-01 22:13:49 +0000 | [diff] [blame] | 344 | close( request_pipe[1] ); |
| 345 | if (!(thread = create_thread( request_pipe[0], process ))) goto error; |
Alexandre Julliard | 7f74824 | 2000-12-26 00:30:30 +0000 | [diff] [blame] | 346 | |
Alexandre Julliard | e66207e | 2003-02-19 00:33:32 +0000 | [diff] [blame] | 347 | set_fd_events( process->msg_fd, POLLIN ); /* start listening to events */ |
Alexandre Julliard | 2fe5777 | 2000-01-25 01:40:27 +0000 | [diff] [blame] | 348 | release_object( process ); |
| 349 | return thread; |
Alexandre Julliard | f692d44 | 1999-03-21 19:23:54 +0000 | [diff] [blame] | 350 | |
| 351 | error: |
Alexandre Julliard | 4144b5b | 2002-06-20 23:21:27 +0000 | [diff] [blame] | 352 | if (process) release_object( process ); |
| 353 | /* if we failed to start our first process, close everything down */ |
| 354 | if (!running_processes) close_master_socket(); |
Alexandre Julliard | f692d44 | 1999-03-21 19:23:54 +0000 | [diff] [blame] | 355 | return NULL; |
Alexandre Julliard | 642d313 | 1998-07-12 19:29:36 +0000 | [diff] [blame] | 356 | } |
| 357 | |
Alexandre Julliard | 5b4f3e8 | 2000-05-01 16:24:22 +0000 | [diff] [blame] | 358 | /* initialize the current process and fill in the request */ |
Alexandre Julliard | 0f273c1 | 2006-07-26 10:43:25 +0200 | [diff] [blame] | 359 | data_size_t init_process( struct thread *thread ) |
Alexandre Julliard | 5b4f3e8 | 2000-05-01 16:24:22 +0000 | [diff] [blame] | 360 | { |
Alexandre Julliard | 0424f38 | 2005-07-13 12:12:43 +0000 | [diff] [blame] | 361 | struct process *process = thread->process; |
Alexandre Julliard | c316f0e | 2006-07-19 14:00:10 +0200 | [diff] [blame] | 362 | struct startup_info *info = process->startup_info; |
Alexandre Julliard | 0424f38 | 2005-07-13 12:12:43 +0000 | [diff] [blame] | 363 | |
Alexandre Julliard | cd1c7fc | 2006-12-29 16:56:11 +0100 | [diff] [blame] | 364 | init_process_tracing( process ); |
Alexandre Julliard | 11ad6a0 | 2005-07-13 19:43:35 +0000 | [diff] [blame] | 365 | if (!info) return 0; |
Alexandre Julliard | 11ad6a0 | 2005-07-13 19:43:35 +0000 | [diff] [blame] | 366 | return info->data_size; |
Alexandre Julliard | 5b4f3e8 | 2000-05-01 16:24:22 +0000 | [diff] [blame] | 367 | } |
| 368 | |
Alexandre Julliard | 642d313 | 1998-07-12 19:29:36 +0000 | [diff] [blame] | 369 | /* destroy a process when its refcount is 0 */ |
Alexandre Julliard | 338e757 | 1998-12-27 15:28:54 +0000 | [diff] [blame] | 370 | static void process_destroy( struct object *obj ) |
Alexandre Julliard | 642d313 | 1998-07-12 19:29:36 +0000 | [diff] [blame] | 371 | { |
| 372 | struct process *process = (struct process *)obj; |
| 373 | assert( obj->ops == &process_ops ); |
| 374 | |
Alexandre Julliard | 767e6f6 | 1998-08-09 12:47:43 +0000 | [diff] [blame] | 375 | /* we can't have a thread remaining */ |
Alexandre Julliard | 0502638 | 2005-03-01 10:56:18 +0000 | [diff] [blame] | 376 | assert( list_empty( &process->thread_list )); |
Alexandre Julliard | 9d80215 | 2002-05-24 21:20:27 +0000 | [diff] [blame] | 377 | |
Alexandre Julliard | 68e850e | 2006-08-14 20:19:42 +0200 | [diff] [blame] | 378 | assert( !process->sigkill_timeout ); /* timeout should hold a reference to the process */ |
| 379 | |
Alexandre Julliard | 9d80215 | 2002-05-24 21:20:27 +0000 | [diff] [blame] | 380 | set_process_startup_state( process, STARTUP_ABORTED ); |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 381 | if (process->console) release_object( process->console ); |
| 382 | if (process->parent) release_object( process->parent ); |
Alexandre Julliard | e66207e | 2003-02-19 00:33:32 +0000 | [diff] [blame] | 383 | if (process->msg_fd) release_object( process->msg_fd ); |
Alexandre Julliard | 48c0d51 | 2005-02-25 19:31:26 +0000 | [diff] [blame] | 384 | list_remove( &process->entry ); |
Alexandre Julliard | c5e433a | 2000-05-30 19:48:18 +0000 | [diff] [blame] | 385 | if (process->idle_event) release_object( process->idle_event ); |
| 386 | if (process->queue) release_object( process->queue ); |
Alexandre Julliard | 91befe1 | 2003-02-01 01:38:40 +0000 | [diff] [blame] | 387 | if (process->id) free_ptid( process->id ); |
Mike McCormack | 36cd6f5 | 2003-07-24 00:07:00 +0000 | [diff] [blame] | 388 | if (process->token) release_object( process->token ); |
Alexandre Julliard | 642d313 | 1998-07-12 19:29:36 +0000 | [diff] [blame] | 389 | } |
| 390 | |
Alexandre Julliard | 767e6f6 | 1998-08-09 12:47:43 +0000 | [diff] [blame] | 391 | /* dump a process on stdout for debugging purposes */ |
Alexandre Julliard | 338e757 | 1998-12-27 15:28:54 +0000 | [diff] [blame] | 392 | static void process_dump( struct object *obj, int verbose ) |
Alexandre Julliard | 767e6f6 | 1998-08-09 12:47:43 +0000 | [diff] [blame] | 393 | { |
| 394 | struct process *process = (struct process *)obj; |
| 395 | assert( obj->ops == &process_ops ); |
| 396 | |
Alexandre Julliard | 48c0d51 | 2005-02-25 19:31:26 +0000 | [diff] [blame] | 397 | fprintf( stderr, "Process id=%04x handles=%p\n", process->id, process->handles ); |
Alexandre Julliard | 767e6f6 | 1998-08-09 12:47:43 +0000 | [diff] [blame] | 398 | } |
| 399 | |
Alexandre Julliard | 85ed45e | 1998-08-22 19:03:56 +0000 | [diff] [blame] | 400 | static int process_signaled( struct object *obj, struct thread *thread ) |
| 401 | { |
| 402 | struct process *process = (struct process *)obj; |
Alexandre Julliard | dbc033a | 1999-03-13 08:58:24 +0000 | [diff] [blame] | 403 | return !process->running_threads; |
Alexandre Julliard | 85ed45e | 1998-08-22 19:03:56 +0000 | [diff] [blame] | 404 | } |
| 405 | |
Alexandre Julliard | 46d1b3e | 2005-12-12 15:03:07 +0100 | [diff] [blame] | 406 | static unsigned int process_map_access( struct object *obj, unsigned int access ) |
| 407 | { |
| 408 | if (access & GENERIC_READ) access |= STANDARD_RIGHTS_READ | SYNCHRONIZE; |
| 409 | if (access & GENERIC_WRITE) access |= STANDARD_RIGHTS_WRITE | SYNCHRONIZE; |
| 410 | if (access & GENERIC_EXECUTE) access |= STANDARD_RIGHTS_EXECUTE; |
| 411 | if (access & GENERIC_ALL) access |= PROCESS_ALL_ACCESS; |
| 412 | return access & ~(GENERIC_READ | GENERIC_WRITE | GENERIC_EXECUTE | GENERIC_ALL); |
| 413 | } |
| 414 | |
Alexandre Julliard | cf27a7f | 2003-02-14 20:27:09 +0000 | [diff] [blame] | 415 | static void process_poll_event( struct fd *fd, int event ) |
Alexandre Julliard | f524240 | 2001-02-28 21:45:23 +0000 | [diff] [blame] | 416 | { |
Alexandre Julliard | cf27a7f | 2003-02-14 20:27:09 +0000 | [diff] [blame] | 417 | struct process *process = get_fd_user( fd ); |
| 418 | assert( process->obj.ops == &process_ops ); |
Alexandre Julliard | f524240 | 2001-02-28 21:45:23 +0000 | [diff] [blame] | 419 | |
Alexandre Julliard | 68e850e | 2006-08-14 20:19:42 +0200 | [diff] [blame] | 420 | if (event & (POLLERR | POLLHUP)) |
| 421 | { |
| 422 | release_object( process->msg_fd ); |
| 423 | process->msg_fd = NULL; |
| 424 | if (process->sigkill_timeout) /* already waiting for it to die */ |
| 425 | { |
| 426 | remove_timeout_user( process->sigkill_timeout ); |
| 427 | process->sigkill_timeout = NULL; |
| 428 | process_died( process ); |
| 429 | } |
Alexandre Julliard | 81977b7 | 2006-09-21 11:14:45 +0200 | [diff] [blame] | 430 | else kill_process( process, 0 ); |
Alexandre Julliard | 68e850e | 2006-08-14 20:19:42 +0200 | [diff] [blame] | 431 | } |
Alexandre Julliard | f524240 | 2001-02-28 21:45:23 +0000 | [diff] [blame] | 432 | else if (event & POLLIN) receive_fd( process ); |
| 433 | } |
| 434 | |
Alexandre Julliard | 5b4f3e8 | 2000-05-01 16:24:22 +0000 | [diff] [blame] | 435 | static void startup_info_destroy( struct object *obj ) |
| 436 | { |
| 437 | struct startup_info *info = (struct startup_info *)obj; |
| 438 | assert( obj->ops == &startup_info_ops ); |
Michael Stefaniuc | 5ceccec | 2006-10-09 23:34:36 +0200 | [diff] [blame] | 439 | free( info->data ); |
Alexandre Julliard | d27624b | 2000-05-03 18:42:40 +0000 | [diff] [blame] | 440 | if (info->exe_file) release_object( info->exe_file ); |
Alexandre Julliard | 5b4f3e8 | 2000-05-01 16:24:22 +0000 | [diff] [blame] | 441 | if (info->process) release_object( info->process ); |
Alexandre Julliard | 5b4f3e8 | 2000-05-01 16:24:22 +0000 | [diff] [blame] | 442 | } |
| 443 | |
| 444 | static void startup_info_dump( struct object *obj, int verbose ) |
| 445 | { |
| 446 | struct startup_info *info = (struct startup_info *)obj; |
| 447 | assert( obj->ops == &startup_info_ops ); |
| 448 | |
Alexandre Julliard | c316f0e | 2006-07-19 14:00:10 +0200 | [diff] [blame] | 449 | fprintf( stderr, "Startup info in=%p out=%p err=%p\n", |
| 450 | info->hstdin, info->hstdout, info->hstderr ); |
Alexandre Julliard | 5b4f3e8 | 2000-05-01 16:24:22 +0000 | [diff] [blame] | 451 | } |
| 452 | |
| 453 | static int startup_info_signaled( struct object *obj, struct thread *thread ) |
| 454 | { |
| 455 | struct startup_info *info = (struct startup_info *)obj; |
Alexandre Julliard | 4926610 | 2006-02-21 19:30:17 +0100 | [diff] [blame] | 456 | return info->process && info->process->startup_state != STARTUP_IN_PROGRESS; |
Alexandre Julliard | 5b4f3e8 | 2000-05-01 16:24:22 +0000 | [diff] [blame] | 457 | } |
| 458 | |
Alexandre Julliard | 642d313 | 1998-07-12 19:29:36 +0000 | [diff] [blame] | 459 | /* get a process from an id (and increment the refcount) */ |
Alexandre Julliard | 54f2287 | 2002-10-03 19:54:57 +0000 | [diff] [blame] | 460 | struct process *get_process_from_id( process_id_t id ) |
Alexandre Julliard | 642d313 | 1998-07-12 19:29:36 +0000 | [diff] [blame] | 461 | { |
Alexandre Julliard | 91befe1 | 2003-02-01 01:38:40 +0000 | [diff] [blame] | 462 | struct object *obj = get_ptid_entry( id ); |
| 463 | |
| 464 | if (obj && obj->ops == &process_ops) return (struct process *)grab_object( obj ); |
| 465 | set_error( STATUS_INVALID_PARAMETER ); |
| 466 | return NULL; |
Alexandre Julliard | 642d313 | 1998-07-12 19:29:36 +0000 | [diff] [blame] | 467 | } |
Alexandre Julliard | 767e6f6 | 1998-08-09 12:47:43 +0000 | [diff] [blame] | 468 | |
| 469 | /* get a process from a handle (and increment the refcount) */ |
Alexandre Julliard | 5188574 | 2002-05-30 20:12:58 +0000 | [diff] [blame] | 470 | 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] | 471 | { |
| 472 | return (struct process *)get_handle_obj( current->process, handle, |
| 473 | access, &process_ops ); |
| 474 | } |
| 475 | |
Alexandre Julliard | a9e0fb1 | 2005-03-02 10:20:09 +0000 | [diff] [blame] | 476 | /* find a dll from its base address */ |
| 477 | static inline struct process_dll *find_process_dll( struct process *process, void *base ) |
| 478 | { |
| 479 | struct process_dll *dll; |
| 480 | |
Alexandre Julliard | a9e0fb1 | 2005-03-02 10:20:09 +0000 | [diff] [blame] | 481 | LIST_FOR_EACH_ENTRY( dll, &process->dlls, struct process_dll, entry ) |
| 482 | { |
| 483 | if (dll->base == base) return dll; |
| 484 | } |
| 485 | return NULL; |
| 486 | } |
| 487 | |
Alexandre Julliard | 05f0b71 | 2000-03-09 18:18:41 +0000 | [diff] [blame] | 488 | /* add a dll to a process list */ |
| 489 | static struct process_dll *process_load_dll( struct process *process, struct file *file, |
Alexandre Julliard | 0f273c1 | 2006-07-26 10:43:25 +0200 | [diff] [blame] | 490 | void *base, const WCHAR *filename, data_size_t name_len ) |
Alexandre Julliard | 05f0b71 | 2000-03-09 18:18:41 +0000 | [diff] [blame] | 491 | { |
| 492 | struct process_dll *dll; |
| 493 | |
| 494 | /* 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] | 495 | if (find_process_dll( process, base )) |
Alexandre Julliard | 05f0b71 | 2000-03-09 18:18:41 +0000 | [diff] [blame] | 496 | { |
| 497 | set_error( STATUS_INVALID_PARAMETER ); |
| 498 | return NULL; |
| 499 | } |
| 500 | |
| 501 | if ((dll = mem_alloc( sizeof(*dll) ))) |
| 502 | { |
Alexandre Julliard | 05f0b71 | 2000-03-09 18:18:41 +0000 | [diff] [blame] | 503 | dll->file = NULL; |
| 504 | dll->base = base; |
Alexandre Julliard | aeb5660 | 2002-03-22 00:21:23 +0000 | [diff] [blame] | 505 | dll->filename = NULL; |
| 506 | dll->namelen = name_len; |
| 507 | if (name_len && !(dll->filename = memdup( filename, name_len ))) |
| 508 | { |
| 509 | free( dll ); |
| 510 | return NULL; |
| 511 | } |
Alexandre Julliard | 5bd5136 | 2007-01-12 14:42:43 +0100 | [diff] [blame] | 512 | if (file) dll->file = grab_file_unless_removable( file ); |
Alexandre Julliard | e6374cb | 2006-02-16 12:13:01 +0100 | [diff] [blame] | 513 | list_add_tail( &process->dlls, &dll->entry ); |
Alexandre Julliard | 05f0b71 | 2000-03-09 18:18:41 +0000 | [diff] [blame] | 514 | } |
| 515 | return dll; |
| 516 | } |
| 517 | |
| 518 | /* remove a dll from a process list */ |
| 519 | static void process_unload_dll( struct process *process, void *base ) |
| 520 | { |
Alexandre Julliard | a9e0fb1 | 2005-03-02 10:20:09 +0000 | [diff] [blame] | 521 | struct process_dll *dll = find_process_dll( process, base ); |
Alexandre Julliard | 05f0b71 | 2000-03-09 18:18:41 +0000 | [diff] [blame] | 522 | |
Alexandre Julliard | e6374cb | 2006-02-16 12:13:01 +0100 | [diff] [blame] | 523 | 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] | 524 | { |
Alexandre Julliard | a9e0fb1 | 2005-03-02 10:20:09 +0000 | [diff] [blame] | 525 | if (dll->file) release_object( dll->file ); |
Michael Stefaniuc | 5ceccec | 2006-10-09 23:34:36 +0200 | [diff] [blame] | 526 | free( dll->filename ); |
Alexandre Julliard | a9e0fb1 | 2005-03-02 10:20:09 +0000 | [diff] [blame] | 527 | list_remove( &dll->entry ); |
| 528 | free( dll ); |
| 529 | generate_debug_event( current, UNLOAD_DLL_DEBUG_EVENT, base ); |
Alexandre Julliard | 05f0b71 | 2000-03-09 18:18:41 +0000 | [diff] [blame] | 530 | } |
Alexandre Julliard | a9e0fb1 | 2005-03-02 10:20:09 +0000 | [diff] [blame] | 531 | else set_error( STATUS_INVALID_PARAMETER ); |
Alexandre Julliard | 05f0b71 | 2000-03-09 18:18:41 +0000 | [diff] [blame] | 532 | } |
| 533 | |
Alexandre Julliard | 81977b7 | 2006-09-21 11:14:45 +0200 | [diff] [blame] | 534 | /* terminate a process with the given exit code */ |
| 535 | static void terminate_process( struct process *process, struct thread *skip, int exit_code ) |
| 536 | { |
Alexandre Julliard | 110a6fe | 2006-11-10 12:18:54 +0100 | [diff] [blame] | 537 | struct list *ptr; |
Alexandre Julliard | 81977b7 | 2006-09-21 11:14:45 +0200 | [diff] [blame] | 538 | |
Alexandre Julliard | d6f8284 | 2006-11-13 12:53:09 +0100 | [diff] [blame] | 539 | if (skip && skip->process == process) /* move it to the end of the list */ |
Alexandre Julliard | 110a6fe | 2006-11-10 12:18:54 +0100 | [diff] [blame] | 540 | { |
| 541 | assert( skip->state != TERMINATED ); |
| 542 | list_remove( &skip->proc_entry ); |
| 543 | list_add_tail( &process->thread_list, &skip->proc_entry ); |
| 544 | } |
| 545 | |
| 546 | grab_object( process ); /* make sure it doesn't get freed when threads die */ |
| 547 | while ((ptr = list_head( &process->thread_list ))) |
Alexandre Julliard | 81977b7 | 2006-09-21 11:14:45 +0200 | [diff] [blame] | 548 | { |
| 549 | struct thread *thread = LIST_ENTRY( ptr, struct thread, proc_entry ); |
| 550 | |
| 551 | if (exit_code) thread->exit_code = exit_code; |
Alexandre Julliard | 110a6fe | 2006-11-10 12:18:54 +0100 | [diff] [blame] | 552 | if (thread == skip) break; |
| 553 | kill_thread( thread, 1 ); |
Alexandre Julliard | 81977b7 | 2006-09-21 11:14:45 +0200 | [diff] [blame] | 554 | } |
Alexandre Julliard | 110a6fe | 2006-11-10 12:18:54 +0100 | [diff] [blame] | 555 | release_object( process ); |
Alexandre Julliard | 81977b7 | 2006-09-21 11:14:45 +0200 | [diff] [blame] | 556 | } |
| 557 | |
Alexandre Julliard | 40043ed | 2002-08-16 20:02:15 +0000 | [diff] [blame] | 558 | /* kill all processes */ |
| 559 | void kill_all_processes( struct process *skip, int exit_code ) |
| 560 | { |
| 561 | for (;;) |
| 562 | { |
Alexandre Julliard | 48c0d51 | 2005-02-25 19:31:26 +0000 | [diff] [blame] | 563 | struct process *process; |
Alexandre Julliard | 40043ed | 2002-08-16 20:02:15 +0000 | [diff] [blame] | 564 | |
Alexandre Julliard | 48c0d51 | 2005-02-25 19:31:26 +0000 | [diff] [blame] | 565 | LIST_FOR_EACH_ENTRY( process, &process_list, struct process, entry ) |
| 566 | { |
| 567 | if (process == skip) continue; |
| 568 | if (process->running_threads) break; |
| 569 | } |
| 570 | if (&process->entry == &process_list) break; /* no process found */ |
Alexandre Julliard | 81977b7 | 2006-09-21 11:14:45 +0200 | [diff] [blame] | 571 | terminate_process( process, NULL, exit_code ); |
Alexandre Julliard | 40043ed | 2002-08-16 20:02:15 +0000 | [diff] [blame] | 572 | } |
| 573 | } |
| 574 | |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 575 | /* kill all processes being attached to a console renderer */ |
Eric Pouech | 3940d8a | 2001-12-04 20:17:43 +0000 | [diff] [blame] | 576 | void kill_console_processes( struct thread *renderer, int exit_code ) |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 577 | { |
| 578 | for (;;) /* restart from the beginning of the list every time */ |
| 579 | { |
Alexandre Julliard | 48c0d51 | 2005-02-25 19:31:26 +0000 | [diff] [blame] | 580 | struct process *process; |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 581 | |
| 582 | /* find the first process being attached to 'renderer' and still running */ |
Alexandre Julliard | 48c0d51 | 2005-02-25 19:31:26 +0000 | [diff] [blame] | 583 | LIST_FOR_EACH_ENTRY( process, &process_list, struct process, entry ) |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 584 | { |
Alexandre Julliard | 48c0d51 | 2005-02-25 19:31:26 +0000 | [diff] [blame] | 585 | if (process == renderer->process) continue; |
| 586 | if (!process->running_threads) continue; |
Alexandre Julliard | 627ca40 | 2007-05-11 12:46:32 +0200 | [diff] [blame] | 587 | if (process->console && console_get_renderer( process->console ) == renderer) break; |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 588 | } |
Alexandre Julliard | 48c0d51 | 2005-02-25 19:31:26 +0000 | [diff] [blame] | 589 | if (&process->entry == &process_list) break; /* no process found */ |
Alexandre Julliard | 81977b7 | 2006-09-21 11:14:45 +0200 | [diff] [blame] | 590 | terminate_process( process, NULL, exit_code ); |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 591 | } |
| 592 | } |
| 593 | |
Alexandre Julliard | 767e6f6 | 1998-08-09 12:47:43 +0000 | [diff] [blame] | 594 | /* a process has been killed (i.e. its last thread died) */ |
Alexandre Julliard | 05f0b71 | 2000-03-09 18:18:41 +0000 | [diff] [blame] | 595 | static void process_killed( struct process *process ) |
Alexandre Julliard | 767e6f6 | 1998-08-09 12:47:43 +0000 | [diff] [blame] | 596 | { |
Alexandre Julliard | 36b85d0 | 2005-06-29 19:29:15 +0000 | [diff] [blame] | 597 | struct handle_table *handles; |
Alexandre Julliard | a9e0fb1 | 2005-03-02 10:20:09 +0000 | [diff] [blame] | 598 | struct list *ptr; |
| 599 | |
Alexandre Julliard | 0502638 | 2005-03-01 10:56:18 +0000 | [diff] [blame] | 600 | assert( list_empty( &process->thread_list )); |
Alexandre Julliard | 753c870 | 2006-08-10 16:42:09 +0200 | [diff] [blame] | 601 | process->end_time = current_time; |
Alexandre Julliard | f978f61 | 2006-03-06 21:02:24 +0100 | [diff] [blame] | 602 | close_process_desktop( process ); |
Alexandre Julliard | 36b85d0 | 2005-06-29 19:29:15 +0000 | [diff] [blame] | 603 | handles = process->handles; |
Alexandre Julliard | eb2e77f | 1999-06-04 19:49:54 +0000 | [diff] [blame] | 604 | process->handles = NULL; |
Alexandre Julliard | 36b85d0 | 2005-06-29 19:29:15 +0000 | [diff] [blame] | 605 | if (handles) release_object( handles ); |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 606 | |
| 607 | /* close the console attached to this process, if any */ |
Alexandre Julliard | eb2e77f | 1999-06-04 19:49:54 +0000 | [diff] [blame] | 608 | free_console( process ); |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 609 | |
Alexandre Julliard | a9e0fb1 | 2005-03-02 10:20:09 +0000 | [diff] [blame] | 610 | while ((ptr = list_head( &process->dlls ))) |
Alexandre Julliard | 05f0b71 | 2000-03-09 18:18:41 +0000 | [diff] [blame] | 611 | { |
Alexandre Julliard | a9e0fb1 | 2005-03-02 10:20:09 +0000 | [diff] [blame] | 612 | struct process_dll *dll = LIST_ENTRY( ptr, struct process_dll, entry ); |
Alexandre Julliard | 05f0b71 | 2000-03-09 18:18:41 +0000 | [diff] [blame] | 613 | if (dll->file) release_object( dll->file ); |
Michael Stefaniuc | 5ceccec | 2006-10-09 23:34:36 +0200 | [diff] [blame] | 614 | free( dll->filename ); |
Alexandre Julliard | a9e0fb1 | 2005-03-02 10:20:09 +0000 | [diff] [blame] | 615 | list_remove( &dll->entry ); |
Alexandre Julliard | 05f0b71 | 2000-03-09 18:18:41 +0000 | [diff] [blame] | 616 | free( dll ); |
| 617 | } |
Alexandre Julliard | bfce151 | 2003-12-10 04:08:06 +0000 | [diff] [blame] | 618 | destroy_process_classes( process ); |
Alexandre Julliard | 5f22e7c | 2005-06-14 19:23:56 +0000 | [diff] [blame] | 619 | remove_process_locks( process ); |
Alexandre Julliard | 9d80215 | 2002-05-24 21:20:27 +0000 | [diff] [blame] | 620 | set_process_startup_state( process, STARTUP_ABORTED ); |
Alexandre Julliard | cd1c7fc | 2006-12-29 16:56:11 +0100 | [diff] [blame] | 621 | finish_process_tracing( process ); |
Alexandre Julliard | 68e850e | 2006-08-14 20:19:42 +0200 | [diff] [blame] | 622 | start_sigkill_timer( process ); |
Alexandre Julliard | 85ed45e | 1998-08-22 19:03:56 +0000 | [diff] [blame] | 623 | wake_up( &process->obj, 0 ); |
Alexandre Julliard | 767e6f6 | 1998-08-09 12:47:43 +0000 | [diff] [blame] | 624 | } |
| 625 | |
Alexandre Julliard | 767e6f6 | 1998-08-09 12:47:43 +0000 | [diff] [blame] | 626 | /* add a thread to a process running threads list */ |
| 627 | void add_process_thread( struct process *process, struct thread *thread ) |
| 628 | { |
Thomas Kho | 4ff4ba3 | 2006-07-20 22:44:36 -0500 | [diff] [blame] | 629 | list_add_tail( &process->thread_list, &thread->proc_entry ); |
Alexandre Julliard | 156b205 | 2007-06-06 20:33:13 +0200 | [diff] [blame] | 630 | if (!process->running_threads++) |
| 631 | { |
| 632 | running_processes++; |
| 633 | if (!process->is_system) |
| 634 | { |
| 635 | if (!user_processes++ && user_process_event) |
| 636 | reset_event( user_process_event ); |
| 637 | } |
| 638 | } |
Alexandre Julliard | 767e6f6 | 1998-08-09 12:47:43 +0000 | [diff] [blame] | 639 | grab_object( thread ); |
| 640 | } |
| 641 | |
| 642 | /* remove a thread from a process running threads list */ |
| 643 | void remove_process_thread( struct process *process, struct thread *thread ) |
| 644 | { |
| 645 | assert( process->running_threads > 0 ); |
Alexandre Julliard | 0502638 | 2005-03-01 10:56:18 +0000 | [diff] [blame] | 646 | assert( !list_empty( &process->thread_list )); |
Alexandre Julliard | 767e6f6 | 1998-08-09 12:47:43 +0000 | [diff] [blame] | 647 | |
Alexandre Julliard | 0502638 | 2005-03-01 10:56:18 +0000 | [diff] [blame] | 648 | list_remove( &thread->proc_entry ); |
Alexandre Julliard | 767e6f6 | 1998-08-09 12:47:43 +0000 | [diff] [blame] | 649 | |
| 650 | if (!--process->running_threads) |
| 651 | { |
| 652 | /* we have removed the last running thread, exit the process */ |
Alexandre Julliard | 05f0b71 | 2000-03-09 18:18:41 +0000 | [diff] [blame] | 653 | process->exit_code = thread->exit_code; |
| 654 | generate_debug_event( thread, EXIT_PROCESS_DEBUG_EVENT, process ); |
| 655 | process_killed( process ); |
Alexandre Julliard | 767e6f6 | 1998-08-09 12:47:43 +0000 | [diff] [blame] | 656 | } |
Alexandre Julliard | 05f0b71 | 2000-03-09 18:18:41 +0000 | [diff] [blame] | 657 | else generate_debug_event( thread, EXIT_THREAD_DEBUG_EVENT, thread ); |
Alexandre Julliard | 767e6f6 | 1998-08-09 12:47:43 +0000 | [diff] [blame] | 658 | release_object( thread ); |
| 659 | } |
| 660 | |
Alexandre Julliard | 3da5f84 | 1999-05-16 16:54:54 +0000 | [diff] [blame] | 661 | /* suspend all the threads of a process */ |
| 662 | void suspend_process( struct process *process ) |
| 663 | { |
| 664 | if (!process->suspend++) |
| 665 | { |
Alexandre Julliard | 0502638 | 2005-03-01 10:56:18 +0000 | [diff] [blame] | 666 | struct list *ptr, *next; |
| 667 | |
| 668 | LIST_FOR_EACH_SAFE( ptr, next, &process->thread_list ) |
Alexandre Julliard | 3da5f84 | 1999-05-16 16:54:54 +0000 | [diff] [blame] | 669 | { |
Alexandre Julliard | 0502638 | 2005-03-01 10:56:18 +0000 | [diff] [blame] | 670 | struct thread *thread = LIST_ENTRY( ptr, struct thread, proc_entry ); |
Alexandre Julliard | 0a70783 | 1999-11-08 05:31:47 +0000 | [diff] [blame] | 671 | if (!thread->suspend) stop_thread( thread ); |
Alexandre Julliard | 3da5f84 | 1999-05-16 16:54:54 +0000 | [diff] [blame] | 672 | } |
| 673 | } |
| 674 | } |
| 675 | |
| 676 | /* resume all the threads of a process */ |
| 677 | void resume_process( struct process *process ) |
| 678 | { |
| 679 | assert (process->suspend > 0); |
| 680 | if (!--process->suspend) |
| 681 | { |
Alexandre Julliard | 0502638 | 2005-03-01 10:56:18 +0000 | [diff] [blame] | 682 | struct list *ptr, *next; |
| 683 | |
| 684 | LIST_FOR_EACH_SAFE( ptr, next, &process->thread_list ) |
Alexandre Julliard | 3da5f84 | 1999-05-16 16:54:54 +0000 | [diff] [blame] | 685 | { |
Alexandre Julliard | 0502638 | 2005-03-01 10:56:18 +0000 | [diff] [blame] | 686 | struct thread *thread = LIST_ENTRY( ptr, struct thread, proc_entry ); |
Alexandre Julliard | d04ccb8 | 2003-03-04 22:18:43 +0000 | [diff] [blame] | 687 | if (!thread->suspend) wake_thread( thread ); |
Alexandre Julliard | 3da5f84 | 1999-05-16 16:54:54 +0000 | [diff] [blame] | 688 | } |
| 689 | } |
| 690 | } |
| 691 | |
Alexandre Julliard | 767e6f6 | 1998-08-09 12:47:43 +0000 | [diff] [blame] | 692 | /* kill a process on the spot */ |
Alexandre Julliard | 81977b7 | 2006-09-21 11:14:45 +0200 | [diff] [blame] | 693 | void kill_process( struct process *process, int violent_death ) |
Alexandre Julliard | 767e6f6 | 1998-08-09 12:47:43 +0000 | [diff] [blame] | 694 | { |
Alexandre Julliard | 81977b7 | 2006-09-21 11:14:45 +0200 | [diff] [blame] | 695 | if (violent_death) terminate_process( process, NULL, 1 ); |
| 696 | else |
Alexandre Julliard | 12f29b5 | 2000-03-17 15:16:57 +0000 | [diff] [blame] | 697 | { |
Alexandre Julliard | 110a6fe | 2006-11-10 12:18:54 +0100 | [diff] [blame] | 698 | struct list *ptr; |
Alexandre Julliard | 0502638 | 2005-03-01 10:56:18 +0000 | [diff] [blame] | 699 | |
Alexandre Julliard | 110a6fe | 2006-11-10 12:18:54 +0100 | [diff] [blame] | 700 | grab_object( process ); /* make sure it doesn't get freed when threads die */ |
| 701 | while ((ptr = list_head( &process->thread_list ))) |
Alexandre Julliard | 81977b7 | 2006-09-21 11:14:45 +0200 | [diff] [blame] | 702 | { |
| 703 | struct thread *thread = LIST_ENTRY( ptr, struct thread, proc_entry ); |
| 704 | kill_thread( thread, 0 ); |
| 705 | } |
Alexandre Julliard | 110a6fe | 2006-11-10 12:18:54 +0100 | [diff] [blame] | 706 | release_object( process ); |
Alexandre Julliard | 12f29b5 | 2000-03-17 15:16:57 +0000 | [diff] [blame] | 707 | } |
Alexandre Julliard | 767e6f6 | 1998-08-09 12:47:43 +0000 | [diff] [blame] | 708 | } |
| 709 | |
Alexandre Julliard | 17cf810 | 1999-11-24 01:22:14 +0000 | [diff] [blame] | 710 | /* kill all processes being debugged by a given thread */ |
| 711 | void kill_debugged_processes( struct thread *debugger, int exit_code ) |
| 712 | { |
| 713 | for (;;) /* restart from the beginning of the list every time */ |
| 714 | { |
Alexandre Julliard | 48c0d51 | 2005-02-25 19:31:26 +0000 | [diff] [blame] | 715 | struct process *process; |
| 716 | |
Alexandre Julliard | 17cf810 | 1999-11-24 01:22:14 +0000 | [diff] [blame] | 717 | /* find the first process being debugged by 'debugger' and still running */ |
Alexandre Julliard | 48c0d51 | 2005-02-25 19:31:26 +0000 | [diff] [blame] | 718 | LIST_FOR_EACH_ENTRY( process, &process_list, struct process, entry ) |
| 719 | { |
| 720 | if (!process->running_threads) continue; |
| 721 | if (process->debugger == debugger) break; |
| 722 | } |
| 723 | if (&process->entry == &process_list) break; /* no process found */ |
Alexandre Julliard | 17cf810 | 1999-11-24 01:22:14 +0000 | [diff] [blame] | 724 | process->debugger = NULL; |
Alexandre Julliard | 81977b7 | 2006-09-21 11:14:45 +0200 | [diff] [blame] | 725 | terminate_process( process, NULL, exit_code ); |
Alexandre Julliard | 17cf810 | 1999-11-24 01:22:14 +0000 | [diff] [blame] | 726 | } |
| 727 | } |
| 728 | |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 729 | |
Alexandre Julliard | 17de829 | 2006-04-19 19:45:39 +0200 | [diff] [blame] | 730 | /* trigger a breakpoint event in a given process */ |
| 731 | void break_process( struct process *process ) |
| 732 | { |
| 733 | struct thread *thread; |
| 734 | |
| 735 | suspend_process( process ); |
| 736 | |
| 737 | LIST_FOR_EACH_ENTRY( thread, &process->thread_list, struct thread, proc_entry ) |
| 738 | { |
| 739 | if (thread->context) /* inside an exception event already */ |
| 740 | { |
| 741 | break_thread( thread ); |
| 742 | goto done; |
| 743 | } |
| 744 | } |
| 745 | if ((thread = get_process_first_thread( process ))) thread->debug_break = 1; |
| 746 | else set_error( STATUS_ACCESS_DENIED ); |
| 747 | done: |
| 748 | resume_process( process ); |
| 749 | } |
| 750 | |
| 751 | |
Eric Pouech | fbccb38 | 2002-02-27 01:28:30 +0000 | [diff] [blame] | 752 | /* detach a debugger from all its debuggees */ |
| 753 | void detach_debugged_processes( struct thread *debugger ) |
| 754 | { |
| 755 | struct process *process; |
Alexandre Julliard | 48c0d51 | 2005-02-25 19:31:26 +0000 | [diff] [blame] | 756 | |
| 757 | LIST_FOR_EACH_ENTRY( process, &process_list, struct process, entry ) |
Eric Pouech | fbccb38 | 2002-02-27 01:28:30 +0000 | [diff] [blame] | 758 | { |
| 759 | if (process->debugger == debugger && process->running_threads) |
| 760 | { |
| 761 | debugger_detach( process, debugger ); |
| 762 | } |
| 763 | } |
| 764 | } |
| 765 | |
| 766 | |
Eric Pouech | 93bfa0d | 2002-06-02 21:22:22 +0000 | [diff] [blame] | 767 | void enum_processes( int (*cb)(struct process*, void*), void *user ) |
| 768 | { |
Alexandre Julliard | 48c0d51 | 2005-02-25 19:31:26 +0000 | [diff] [blame] | 769 | struct list *ptr, *next; |
| 770 | |
| 771 | LIST_FOR_EACH_SAFE( ptr, next, &process_list ) |
Eric Pouech | 93bfa0d | 2002-06-02 21:22:22 +0000 | [diff] [blame] | 772 | { |
Alexandre Julliard | 48c0d51 | 2005-02-25 19:31:26 +0000 | [diff] [blame] | 773 | struct process *process = LIST_ENTRY( ptr, struct process, entry ); |
Eric Pouech | 93bfa0d | 2002-06-02 21:22:22 +0000 | [diff] [blame] | 774 | if ((cb)(process, user)) break; |
| 775 | } |
| 776 | } |
| 777 | |
Alexandre Julliard | e55d593 | 2003-10-14 01:30:42 +0000 | [diff] [blame] | 778 | /* set the debugged flag in the process PEB */ |
| 779 | int set_process_debug_flag( struct process *process, int flag ) |
| 780 | { |
Alexandre Julliard | 959bbf8 | 2006-04-07 18:41:58 +0200 | [diff] [blame] | 781 | char data = (flag != 0); |
Alexandre Julliard | e55d593 | 2003-10-14 01:30:42 +0000 | [diff] [blame] | 782 | |
| 783 | /* BeingDebugged flag is the byte at offset 2 in the PEB */ |
Alexandre Julliard | 959bbf8 | 2006-04-07 18:41:58 +0200 | [diff] [blame] | 784 | return write_process_memory( process, (char *)process->peb + 2, 1, &data ); |
Alexandre Julliard | 8b8828f | 1999-11-12 21:39:14 +0000 | [diff] [blame] | 785 | } |
| 786 | |
Alexandre Julliard | fdc92ba | 1999-02-14 18:03:15 +0000 | [diff] [blame] | 787 | /* take a snapshot of currently running processes */ |
| 788 | struct process_snapshot *process_snap( int *count ) |
| 789 | { |
| 790 | struct process_snapshot *snapshot, *ptr; |
| 791 | struct process *process; |
Alexandre Julliard | 498b781 | 2006-08-15 20:31:54 +0200 | [diff] [blame] | 792 | |
Alexandre Julliard | fdc92ba | 1999-02-14 18:03:15 +0000 | [diff] [blame] | 793 | if (!running_processes) return NULL; |
| 794 | if (!(snapshot = mem_alloc( sizeof(*snapshot) * running_processes ))) |
| 795 | return NULL; |
| 796 | ptr = snapshot; |
Alexandre Julliard | 48c0d51 | 2005-02-25 19:31:26 +0000 | [diff] [blame] | 797 | LIST_FOR_EACH_ENTRY( process, &process_list, struct process, entry ) |
Alexandre Julliard | fdc92ba | 1999-02-14 18:03:15 +0000 | [diff] [blame] | 798 | { |
| 799 | if (!process->running_threads) continue; |
| 800 | ptr->process = process; |
| 801 | ptr->threads = process->running_threads; |
Alexandre Julliard | 07d8446 | 2000-04-16 19:45:05 +0000 | [diff] [blame] | 802 | ptr->count = process->obj.refcount; |
Alexandre Julliard | fdc92ba | 1999-02-14 18:03:15 +0000 | [diff] [blame] | 803 | ptr->priority = process->priority; |
Eric Pouech | 9fd54b2 | 2003-09-16 01:07:21 +0000 | [diff] [blame] | 804 | ptr->handles = get_handle_table_count(process); |
Alexandre Julliard | fdc92ba | 1999-02-14 18:03:15 +0000 | [diff] [blame] | 805 | grab_object( process ); |
| 806 | ptr++; |
| 807 | } |
Alexandre Julliard | 498b781 | 2006-08-15 20:31:54 +0200 | [diff] [blame] | 808 | |
| 809 | if (!(*count = ptr - snapshot)) |
| 810 | { |
| 811 | free( snapshot ); |
| 812 | snapshot = NULL; |
| 813 | } |
Alexandre Julliard | fdc92ba | 1999-02-14 18:03:15 +0000 | [diff] [blame] | 814 | return snapshot; |
| 815 | } |
Alexandre Julliard | 43c190e | 1999-05-15 10:48:19 +0000 | [diff] [blame] | 816 | |
Alexandre Julliard | 07d8446 | 2000-04-16 19:45:05 +0000 | [diff] [blame] | 817 | /* take a snapshot of the modules of a process */ |
| 818 | struct module_snapshot *module_snap( struct process *process, int *count ) |
| 819 | { |
| 820 | struct module_snapshot *snapshot, *ptr; |
| 821 | struct process_dll *dll; |
Alexandre Julliard | e6374cb | 2006-02-16 12:13:01 +0100 | [diff] [blame] | 822 | int total = 0; |
Alexandre Julliard | 07d8446 | 2000-04-16 19:45:05 +0000 | [diff] [blame] | 823 | |
Alexandre Julliard | a9e0fb1 | 2005-03-02 10:20:09 +0000 | [diff] [blame] | 824 | LIST_FOR_EACH_ENTRY( dll, &process->dlls, struct process_dll, entry ) total++; |
Alexandre Julliard | 07d8446 | 2000-04-16 19:45:05 +0000 | [diff] [blame] | 825 | if (!(snapshot = mem_alloc( sizeof(*snapshot) * total ))) return NULL; |
| 826 | |
Alexandre Julliard | e6374cb | 2006-02-16 12:13:01 +0100 | [diff] [blame] | 827 | ptr = snapshot; |
Alexandre Julliard | a9e0fb1 | 2005-03-02 10:20:09 +0000 | [diff] [blame] | 828 | LIST_FOR_EACH_ENTRY( dll, &process->dlls, struct process_dll, entry ) |
Alexandre Julliard | 07d8446 | 2000-04-16 19:45:05 +0000 | [diff] [blame] | 829 | { |
Alexandre Julliard | aeb5660 | 2002-03-22 00:21:23 +0000 | [diff] [blame] | 830 | ptr->base = dll->base; |
| 831 | ptr->size = dll->size; |
| 832 | ptr->namelen = dll->namelen; |
| 833 | ptr->filename = memdup( dll->filename, dll->namelen ); |
Alexandre Julliard | a9e0fb1 | 2005-03-02 10:20:09 +0000 | [diff] [blame] | 834 | ptr++; |
Alexandre Julliard | 07d8446 | 2000-04-16 19:45:05 +0000 | [diff] [blame] | 835 | } |
| 836 | *count = total; |
| 837 | return snapshot; |
| 838 | } |
| 839 | |
| 840 | |
Alexandre Julliard | 43c190e | 1999-05-15 10:48:19 +0000 | [diff] [blame] | 841 | /* create a new process */ |
| 842 | DECL_HANDLER(new_process) |
| 843 | { |
Alexandre Julliard | 5b4f3e8 | 2000-05-01 16:24:22 +0000 | [diff] [blame] | 844 | struct startup_info *info; |
Alexandre Julliard | c316f0e | 2006-07-19 14:00:10 +0200 | [diff] [blame] | 845 | struct thread *thread; |
| 846 | struct process *process; |
| 847 | struct process *parent = current->process; |
| 848 | int socket_fd = thread_get_inflight_fd( current, req->socket_fd ); |
| 849 | |
| 850 | if (socket_fd == -1) |
| 851 | { |
| 852 | set_error( STATUS_INVALID_PARAMETER ); |
| 853 | return; |
| 854 | } |
| 855 | if (fcntl( socket_fd, F_SETFL, O_NONBLOCK ) == -1) |
| 856 | { |
| 857 | set_error( STATUS_INVALID_HANDLE ); |
| 858 | close( socket_fd ); |
| 859 | return; |
| 860 | } |
Alexandre Julliard | 43c190e | 1999-05-15 10:48:19 +0000 | [diff] [blame] | 861 | |
Alexandre Julliard | 5b4f3e8 | 2000-05-01 16:24:22 +0000 | [diff] [blame] | 862 | /* build the startup info for a new process */ |
Alexandre Julliard | e66207e | 2003-02-19 00:33:32 +0000 | [diff] [blame] | 863 | if (!(info = alloc_object( &startup_info_ops ))) return; |
Alexandre Julliard | 5b4f3e8 | 2000-05-01 16:24:22 +0000 | [diff] [blame] | 864 | info->hstdin = req->hstdin; |
| 865 | info->hstdout = req->hstdout; |
| 866 | info->hstderr = req->hstderr; |
Alexandre Julliard | d27624b | 2000-05-03 18:42:40 +0000 | [diff] [blame] | 867 | info->exe_file = NULL; |
Alexandre Julliard | 5b4f3e8 | 2000-05-01 16:24:22 +0000 | [diff] [blame] | 868 | info->process = NULL; |
Alexandre Julliard | 6543a65 | 2002-03-29 18:28:56 +0000 | [diff] [blame] | 869 | info->data_size = get_req_data_size(); |
| 870 | info->data = NULL; |
Alexandre Julliard | 6a72dc5 | 2000-04-14 13:42:00 +0000 | [diff] [blame] | 871 | |
Alexandre Julliard | 8081e5a | 2001-01-05 04:08:07 +0000 | [diff] [blame] | 872 | if (req->exe_file && |
Alexandre Julliard | a510a7e | 2005-12-12 16:46:17 +0100 | [diff] [blame] | 873 | !(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] | 874 | goto done; |
Alexandre Julliard | d27624b | 2000-05-03 18:42:40 +0000 | [diff] [blame] | 875 | |
Alexandre Julliard | 841f898 | 2003-10-04 04:09:41 +0000 | [diff] [blame] | 876 | if (!(info->data = memdup( get_req_data(), info->data_size ))) goto done; |
Alexandre Julliard | c316f0e | 2006-07-19 14:00:10 +0200 | [diff] [blame] | 877 | |
| 878 | if (!(thread = create_process( socket_fd, current, req->inherit_all ))) goto done; |
| 879 | process = thread->process; |
| 880 | process->create_flags = req->create_flags; |
| 881 | process->startup_info = (struct startup_info *)grab_object( info ); |
| 882 | |
| 883 | /* connect to the window station */ |
| 884 | connect_process_winstation( process, current ); |
| 885 | |
| 886 | /* thread will be actually suspended in init_done */ |
| 887 | if (req->create_flags & CREATE_SUSPENDED) thread->suspend++; |
| 888 | |
| 889 | /* set the process console */ |
| 890 | if (!(req->create_flags & (DETACHED_PROCESS | CREATE_NEW_CONSOLE))) |
| 891 | { |
| 892 | /* FIXME: some better error checking should be done... |
| 893 | * like if hConOut and hConIn are console handles, then they should be on the same |
| 894 | * physical console |
| 895 | */ |
| 896 | inherit_console( current, process, req->inherit_all ? req->hstdin : 0 ); |
| 897 | } |
| 898 | |
| 899 | if (!req->inherit_all && !(req->create_flags & CREATE_NEW_CONSOLE)) |
| 900 | { |
| 901 | info->hstdin = duplicate_handle( parent, req->hstdin, process, |
| 902 | 0, OBJ_INHERIT, DUPLICATE_SAME_ACCESS ); |
| 903 | info->hstdout = duplicate_handle( parent, req->hstdout, process, |
| 904 | 0, OBJ_INHERIT, DUPLICATE_SAME_ACCESS ); |
| 905 | info->hstderr = duplicate_handle( parent, req->hstderr, process, |
| 906 | 0, OBJ_INHERIT, DUPLICATE_SAME_ACCESS ); |
| 907 | /* some handles above may have been invalid; this is not an error */ |
| 908 | if (get_error() == STATUS_INVALID_HANDLE || |
| 909 | get_error() == STATUS_OBJECT_TYPE_MISMATCH) clear_error(); |
| 910 | } |
| 911 | |
| 912 | /* attach to the debugger if requested */ |
| 913 | if (req->create_flags & (DEBUG_PROCESS | DEBUG_ONLY_THIS_PROCESS)) |
| 914 | set_process_debugger( process, current ); |
| 915 | else if (parent->debugger && !(parent->create_flags & DEBUG_ONLY_THIS_PROCESS)) |
| 916 | set_process_debugger( process, parent->debugger ); |
| 917 | |
| 918 | if (!(req->create_flags & CREATE_NEW_PROCESS_GROUP)) |
| 919 | process->group_id = parent->group_id; |
| 920 | |
| 921 | info->process = (struct process *)grab_object( process ); |
Alexandre Julliard | 24560e7 | 2005-12-09 13:58:25 +0100 | [diff] [blame] | 922 | reply->info = alloc_handle( current->process, info, SYNCHRONIZE, 0 ); |
Alexandre Julliard | c316f0e | 2006-07-19 14:00:10 +0200 | [diff] [blame] | 923 | reply->pid = get_process_id( process ); |
| 924 | reply->tid = get_thread_id( thread ); |
| 925 | reply->phandle = alloc_handle( parent, process, req->process_access, req->process_attr ); |
| 926 | reply->thandle = alloc_handle( parent, thread, req->thread_access, req->thread_attr ); |
Alexandre Julliard | e9936d9 | 2001-01-26 00:22:26 +0000 | [diff] [blame] | 927 | |
| 928 | done: |
| 929 | release_object( info ); |
Alexandre Julliard | 5b4f3e8 | 2000-05-01 16:24:22 +0000 | [diff] [blame] | 930 | } |
Alexandre Julliard | 6a72dc5 | 2000-04-14 13:42:00 +0000 | [diff] [blame] | 931 | |
Alexandre Julliard | e9936d9 | 2001-01-26 00:22:26 +0000 | [diff] [blame] | 932 | /* Retrieve information about a newly started process */ |
| 933 | DECL_HANDLER(get_new_process_info) |
Alexandre Julliard | 5b4f3e8 | 2000-05-01 16:24:22 +0000 | [diff] [blame] | 934 | { |
Alexandre Julliard | e9936d9 | 2001-01-26 00:22:26 +0000 | [diff] [blame] | 935 | struct startup_info *info; |
| 936 | |
Alexandre Julliard | e9936d9 | 2001-01-26 00:22:26 +0000 | [diff] [blame] | 937 | if ((info = (struct startup_info *)get_handle_obj( current->process, req->info, |
| 938 | 0, &startup_info_ops ))) |
Alexandre Julliard | 5b4f3e8 | 2000-05-01 16:24:22 +0000 | [diff] [blame] | 939 | { |
Alexandre Julliard | ca96de3 | 2002-05-25 21:15:03 +0000 | [diff] [blame] | 940 | reply->success = is_process_init_done( info->process ); |
Alexandre Julliard | c316f0e | 2006-07-19 14:00:10 +0200 | [diff] [blame] | 941 | reply->exit_code = info->process->exit_code; |
Alexandre Julliard | e9936d9 | 2001-01-26 00:22:26 +0000 | [diff] [blame] | 942 | release_object( info ); |
Alexandre Julliard | 5b4f3e8 | 2000-05-01 16:24:22 +0000 | [diff] [blame] | 943 | } |
Alexandre Julliard | 43c190e | 1999-05-15 10:48:19 +0000 | [diff] [blame] | 944 | } |
| 945 | |
Alexandre Julliard | 6543a65 | 2002-03-29 18:28:56 +0000 | [diff] [blame] | 946 | /* Retrieve the new process startup info */ |
| 947 | DECL_HANDLER(get_startup_info) |
| 948 | { |
Alexandre Julliard | 01caa5e | 2005-07-12 20:27:09 +0000 | [diff] [blame] | 949 | struct process *process = current->process; |
| 950 | struct startup_info *info = process->startup_info; |
Alexandre Julliard | 0f273c1 | 2006-07-26 10:43:25 +0200 | [diff] [blame] | 951 | data_size_t size; |
Alexandre Julliard | 6543a65 | 2002-03-29 18:28:56 +0000 | [diff] [blame] | 952 | |
Alexandre Julliard | 01caa5e | 2005-07-12 20:27:09 +0000 | [diff] [blame] | 953 | if (!info) return; |
| 954 | |
Alexandre Julliard | 01caa5e | 2005-07-12 20:27:09 +0000 | [diff] [blame] | 955 | if (info->exe_file && |
| 956 | !(reply->exe_file = alloc_handle( process, info->exe_file, GENERIC_READ, 0 ))) return; |
| 957 | |
Alexandre Julliard | c316f0e | 2006-07-19 14:00:10 +0200 | [diff] [blame] | 958 | reply->hstdin = info->hstdin; |
| 959 | reply->hstdout = info->hstdout; |
| 960 | reply->hstderr = info->hstderr; |
Alexandre Julliard | 01caa5e | 2005-07-12 20:27:09 +0000 | [diff] [blame] | 961 | |
| 962 | /* we return the data directly without making a copy so this can only be called once */ |
| 963 | size = info->data_size; |
| 964 | if (size > get_reply_max_size()) size = get_reply_max_size(); |
| 965 | set_reply_data_ptr( info->data, size ); |
| 966 | info->data = NULL; |
| 967 | info->data_size = 0; |
Alexandre Julliard | 6543a65 | 2002-03-29 18:28:56 +0000 | [diff] [blame] | 968 | } |
| 969 | |
Alexandre Julliard | ec7bb23 | 1999-11-12 03:35:25 +0000 | [diff] [blame] | 970 | /* signal the end of the process initialization */ |
| 971 | DECL_HANDLER(init_process_done) |
| 972 | { |
Alexandre Julliard | 2b0033d | 2006-02-08 15:07:16 +0100 | [diff] [blame] | 973 | struct process_dll *dll; |
Alexandre Julliard | ec7bb23 | 1999-11-12 03:35:25 +0000 | [diff] [blame] | 974 | struct process *process = current->process; |
Alexandre Julliard | ac2e4f1 | 2001-10-25 19:52:12 +0000 | [diff] [blame] | 975 | |
Alexandre Julliard | 9d80215 | 2002-05-24 21:20:27 +0000 | [diff] [blame] | 976 | if (is_process_init_done(process)) |
Alexandre Julliard | ec7bb23 | 1999-11-12 03:35:25 +0000 | [diff] [blame] | 977 | { |
Alexandre Julliard | 5558652 | 2006-06-08 10:26:02 +0200 | [diff] [blame] | 978 | set_error( STATUS_INVALID_PARAMETER ); |
Alexandre Julliard | 9d80215 | 2002-05-24 21:20:27 +0000 | [diff] [blame] | 979 | return; |
| 980 | } |
Alexandre Julliard | e6374cb | 2006-02-16 12:13:01 +0100 | [diff] [blame] | 981 | if (!(dll = find_process_dll( process, req->module ))) |
Alexandre Julliard | 2b0033d | 2006-02-08 15:07:16 +0100 | [diff] [blame] | 982 | { |
Alexandre Julliard | e27358e | 2006-02-21 20:08:19 +0100 | [diff] [blame] | 983 | set_error( STATUS_DLL_NOT_FOUND ); |
| 984 | return; |
Alexandre Julliard | 2b0033d | 2006-02-08 15:07:16 +0100 | [diff] [blame] | 985 | } |
Alexandre Julliard | e6374cb | 2006-02-16 12:13:01 +0100 | [diff] [blame] | 986 | |
| 987 | /* main exe is the first in the dll list */ |
| 988 | list_remove( &dll->entry ); |
| 989 | list_add_head( &process->dlls, &dll->entry ); |
Alexandre Julliard | aeb5660 | 2002-03-22 00:21:23 +0000 | [diff] [blame] | 990 | |
Alexandre Julliard | 9d80215 | 2002-05-24 21:20:27 +0000 | [diff] [blame] | 991 | generate_startup_debug_events( process, req->entry ); |
| 992 | set_process_startup_state( process, STARTUP_DONE ); |
| 993 | |
Vitaliy Margolen | f676bc8 | 2005-12-02 15:55:48 +0100 | [diff] [blame] | 994 | 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] | 995 | if (current->suspend + process->suspend > 0) stop_thread( current ); |
Alexandre Julliard | e55d593 | 2003-10-14 01:30:42 +0000 | [diff] [blame] | 996 | if (process->debugger) set_process_debug_flag( process, 1 ); |
Alexandre Julliard | ec7bb23 | 1999-11-12 03:35:25 +0000 | [diff] [blame] | 997 | } |
| 998 | |
Alexandre Julliard | 43c190e | 1999-05-15 10:48:19 +0000 | [diff] [blame] | 999 | /* open a handle to a process */ |
| 1000 | DECL_HANDLER(open_process) |
| 1001 | { |
Alexandre Julliard | 43c190e | 1999-05-15 10:48:19 +0000 | [diff] [blame] | 1002 | struct process *process = get_process_from_id( req->pid ); |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 1003 | reply->handle = 0; |
Alexandre Julliard | 43c190e | 1999-05-15 10:48:19 +0000 | [diff] [blame] | 1004 | if (process) |
| 1005 | { |
Alexandre Julliard | 24560e7 | 2005-12-09 13:58:25 +0100 | [diff] [blame] | 1006 | reply->handle = alloc_handle( current->process, process, req->access, req->attributes ); |
Alexandre Julliard | 43c190e | 1999-05-15 10:48:19 +0000 | [diff] [blame] | 1007 | release_object( process ); |
| 1008 | } |
Alexandre Julliard | 43c190e | 1999-05-15 10:48:19 +0000 | [diff] [blame] | 1009 | } |
| 1010 | |
| 1011 | /* terminate a process */ |
| 1012 | DECL_HANDLER(terminate_process) |
| 1013 | { |
| 1014 | struct process *process; |
| 1015 | |
| 1016 | if ((process = get_process_from_handle( req->handle, PROCESS_TERMINATE ))) |
| 1017 | { |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 1018 | reply->self = (current->process == process); |
Alexandre Julliard | 81977b7 | 2006-09-21 11:14:45 +0200 | [diff] [blame] | 1019 | terminate_process( process, current, req->exit_code ); |
Alexandre Julliard | 43c190e | 1999-05-15 10:48:19 +0000 | [diff] [blame] | 1020 | release_object( process ); |
| 1021 | } |
Alexandre Julliard | 43c190e | 1999-05-15 10:48:19 +0000 | [diff] [blame] | 1022 | } |
| 1023 | |
| 1024 | /* fetch information about a process */ |
| 1025 | DECL_HANDLER(get_process_info) |
| 1026 | { |
| 1027 | struct process *process; |
Alexandre Julliard | 43c190e | 1999-05-15 10:48:19 +0000 | [diff] [blame] | 1028 | |
| 1029 | if ((process = get_process_from_handle( req->handle, PROCESS_QUERY_INFORMATION ))) |
| 1030 | { |
Alexandre Julliard | e55d593 | 2003-10-14 01:30:42 +0000 | [diff] [blame] | 1031 | reply->pid = get_process_id( process ); |
Eric Pouech | b0fd2ad | 2004-06-14 17:02:00 +0000 | [diff] [blame] | 1032 | reply->ppid = process->parent ? get_process_id( process->parent ) : 0; |
Alexandre Julliard | e55d593 | 2003-10-14 01:30:42 +0000 | [diff] [blame] | 1033 | reply->exit_code = process->exit_code; |
| 1034 | reply->priority = process->priority; |
Eric Pouech | b09582a | 2005-09-27 10:52:10 +0000 | [diff] [blame] | 1035 | reply->affinity = process->affinity; |
Eric Pouech | b0fd2ad | 2004-06-14 17:02:00 +0000 | [diff] [blame] | 1036 | reply->peb = process->peb; |
Alexandre Julliard | aaf477f | 2007-04-17 20:08:59 +0200 | [diff] [blame] | 1037 | reply->start_time = process->start_time; |
| 1038 | reply->end_time = process->end_time; |
Alexandre Julliard | 43c190e | 1999-05-15 10:48:19 +0000 | [diff] [blame] | 1039 | release_object( process ); |
| 1040 | } |
Alexandre Julliard | 43c190e | 1999-05-15 10:48:19 +0000 | [diff] [blame] | 1041 | } |
| 1042 | |
| 1043 | /* set information about a process */ |
| 1044 | DECL_HANDLER(set_process_info) |
| 1045 | { |
| 1046 | struct process *process; |
| 1047 | |
| 1048 | if ((process = get_process_from_handle( req->handle, PROCESS_SET_INFORMATION ))) |
| 1049 | { |
Alexandre Julliard | e55d593 | 2003-10-14 01:30:42 +0000 | [diff] [blame] | 1050 | if (req->mask & SET_PROCESS_INFO_PRIORITY) process->priority = req->priority; |
| 1051 | if (req->mask & SET_PROCESS_INFO_AFFINITY) |
| 1052 | { |
| 1053 | if (req->affinity != 1) set_error( STATUS_INVALID_PARAMETER ); |
| 1054 | else process->affinity = req->affinity; |
| 1055 | } |
Alexandre Julliard | 43c190e | 1999-05-15 10:48:19 +0000 | [diff] [blame] | 1056 | release_object( process ); |
| 1057 | } |
Alexandre Julliard | 43c190e | 1999-05-15 10:48:19 +0000 | [diff] [blame] | 1058 | } |
Alexandre Julliard | 8b8828f | 1999-11-12 21:39:14 +0000 | [diff] [blame] | 1059 | |
| 1060 | /* read data from a process address space */ |
| 1061 | DECL_HANDLER(read_process_memory) |
| 1062 | { |
| 1063 | struct process *process; |
Alexandre Julliard | 0f273c1 | 2006-07-26 10:43:25 +0200 | [diff] [blame] | 1064 | data_size_t len = get_reply_max_size(); |
Alexandre Julliard | 8b8828f | 1999-11-12 21:39:14 +0000 | [diff] [blame] | 1065 | |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 1066 | if (!(process = get_process_from_handle( req->handle, PROCESS_VM_READ ))) return; |
| 1067 | |
| 1068 | if (len) |
Alexandre Julliard | 8b8828f | 1999-11-12 21:39:14 +0000 | [diff] [blame] | 1069 | { |
Alexandre Julliard | 0b492c7 | 2006-04-07 19:43:44 +0200 | [diff] [blame] | 1070 | char *buffer = mem_alloc( len ); |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 1071 | if (buffer) |
| 1072 | { |
Alexandre Julliard | 0b492c7 | 2006-04-07 19:43:44 +0200 | [diff] [blame] | 1073 | if (read_process_memory( process, req->addr, len, buffer )) |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 1074 | set_reply_data_ptr( buffer, len ); |
Alexandre Julliard | 0b492c7 | 2006-04-07 19:43:44 +0200 | [diff] [blame] | 1075 | else |
| 1076 | free( buffer ); |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 1077 | } |
Alexandre Julliard | 8b8828f | 1999-11-12 21:39:14 +0000 | [diff] [blame] | 1078 | } |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 1079 | release_object( process ); |
Alexandre Julliard | 8b8828f | 1999-11-12 21:39:14 +0000 | [diff] [blame] | 1080 | } |
Alexandre Julliard | eef7025 | 1999-11-13 19:54:54 +0000 | [diff] [blame] | 1081 | |
| 1082 | /* write data to a process address space */ |
| 1083 | DECL_HANDLER(write_process_memory) |
| 1084 | { |
| 1085 | struct process *process; |
| 1086 | |
| 1087 | if ((process = get_process_from_handle( req->handle, PROCESS_VM_WRITE ))) |
| 1088 | { |
Alexandre Julliard | 0f273c1 | 2006-07-26 10:43:25 +0200 | [diff] [blame] | 1089 | data_size_t len = get_req_data_size(); |
Alexandre Julliard | 959bbf8 | 2006-04-07 18:41:58 +0200 | [diff] [blame] | 1090 | if (len) write_process_memory( process, req->addr, len, get_req_data() ); |
| 1091 | else set_error( STATUS_INVALID_PARAMETER ); |
Alexandre Julliard | eef7025 | 1999-11-13 19:54:54 +0000 | [diff] [blame] | 1092 | release_object( process ); |
| 1093 | } |
| 1094 | } |
Alexandre Julliard | 05f0b71 | 2000-03-09 18:18:41 +0000 | [diff] [blame] | 1095 | |
| 1096 | /* notify the server that a dll has been loaded */ |
| 1097 | DECL_HANDLER(load_dll) |
| 1098 | { |
| 1099 | struct process_dll *dll; |
| 1100 | struct file *file = NULL; |
| 1101 | |
Alexandre Julliard | a510a7e | 2005-12-12 16:46:17 +0100 | [diff] [blame] | 1102 | 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] | 1103 | return; |
Alexandre Julliard | 8081e5a | 2001-01-05 04:08:07 +0000 | [diff] [blame] | 1104 | |
Alexandre Julliard | aeb5660 | 2002-03-22 00:21:23 +0000 | [diff] [blame] | 1105 | if ((dll = process_load_dll( current->process, file, req->base, |
| 1106 | get_req_data(), get_req_data_size() ))) |
Alexandre Julliard | 05f0b71 | 2000-03-09 18:18:41 +0000 | [diff] [blame] | 1107 | { |
Alexandre Julliard | aeb5660 | 2002-03-22 00:21:23 +0000 | [diff] [blame] | 1108 | dll->size = req->size; |
Alexandre Julliard | 05f0b71 | 2000-03-09 18:18:41 +0000 | [diff] [blame] | 1109 | dll->dbg_offset = req->dbg_offset; |
| 1110 | dll->dbg_size = req->dbg_size; |
| 1111 | dll->name = req->name; |
| 1112 | /* only generate event if initialization is done */ |
Alexandre Julliard | 9d80215 | 2002-05-24 21:20:27 +0000 | [diff] [blame] | 1113 | if (is_process_init_done( current->process )) |
Alexandre Julliard | 05f0b71 | 2000-03-09 18:18:41 +0000 | [diff] [blame] | 1114 | generate_debug_event( current, LOAD_DLL_DEBUG_EVENT, dll ); |
| 1115 | } |
| 1116 | if (file) release_object( file ); |
| 1117 | } |
| 1118 | |
| 1119 | /* notify the server that a dll is being unloaded */ |
| 1120 | DECL_HANDLER(unload_dll) |
| 1121 | { |
| 1122 | process_unload_dll( current->process, req->base ); |
| 1123 | } |
Alexandre Julliard | c5e433a | 2000-05-30 19:48:18 +0000 | [diff] [blame] | 1124 | |
Eric Pouech | 2359b57 | 2003-01-09 00:01:28 +0000 | [diff] [blame] | 1125 | /* retrieve information about a module in a process */ |
| 1126 | DECL_HANDLER(get_dll_info) |
| 1127 | { |
| 1128 | struct process *process; |
| 1129 | |
| 1130 | if ((process = get_process_from_handle( req->handle, PROCESS_QUERY_INFORMATION ))) |
| 1131 | { |
Alexandre Julliard | a9e0fb1 | 2005-03-02 10:20:09 +0000 | [diff] [blame] | 1132 | struct process_dll *dll = find_process_dll( process, req->base_address ); |
Eric Pouech | 2359b57 | 2003-01-09 00:01:28 +0000 | [diff] [blame] | 1133 | |
Alexandre Julliard | a9e0fb1 | 2005-03-02 10:20:09 +0000 | [diff] [blame] | 1134 | if (dll) |
Eric Pouech | 2359b57 | 2003-01-09 00:01:28 +0000 | [diff] [blame] | 1135 | { |
Alexandre Julliard | a9e0fb1 | 2005-03-02 10:20:09 +0000 | [diff] [blame] | 1136 | reply->size = dll->size; |
Robert Shearman | c516571 | 2005-05-25 18:41:09 +0000 | [diff] [blame] | 1137 | reply->entry_point = NULL; /* FIXME */ |
Alexandre Julliard | a9e0fb1 | 2005-03-02 10:20:09 +0000 | [diff] [blame] | 1138 | if (dll->filename) |
Eric Pouech | 2359b57 | 2003-01-09 00:01:28 +0000 | [diff] [blame] | 1139 | { |
Alexandre Julliard | 0f273c1 | 2006-07-26 10:43:25 +0200 | [diff] [blame] | 1140 | data_size_t len = min( dll->namelen, get_reply_max_size() ); |
Alexandre Julliard | a9e0fb1 | 2005-03-02 10:20:09 +0000 | [diff] [blame] | 1141 | set_reply_data( dll->filename, len ); |
Eric Pouech | 2359b57 | 2003-01-09 00:01:28 +0000 | [diff] [blame] | 1142 | } |
| 1143 | } |
Alexandre Julliard | a9e0fb1 | 2005-03-02 10:20:09 +0000 | [diff] [blame] | 1144 | else |
| 1145 | set_error( STATUS_DLL_NOT_FOUND ); |
| 1146 | |
Eric Pouech | 2359b57 | 2003-01-09 00:01:28 +0000 | [diff] [blame] | 1147 | release_object( process ); |
| 1148 | } |
| 1149 | } |
| 1150 | |
Alexandre Julliard | ce40ef1 | 2006-07-26 11:48:25 +0200 | [diff] [blame] | 1151 | /* retrieve the process idle event */ |
| 1152 | DECL_HANDLER(get_process_idle_event) |
Alexandre Julliard | c5e433a | 2000-05-30 19:48:18 +0000 | [diff] [blame] | 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 | { |
Alexandre Julliard | 2790923 | 2005-10-12 21:10:52 +0000 | [diff] [blame] | 1159 | if (process->idle_event && process != current->process) |
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 | } |
Alexandre Julliard | 156b205 | 2007-06-06 20:33:13 +0200 | [diff] [blame] | 1165 | |
| 1166 | /* make the current process a system process */ |
| 1167 | DECL_HANDLER(make_process_system) |
| 1168 | { |
| 1169 | struct process *process = current->process; |
| 1170 | |
| 1171 | if (!user_process_event) |
| 1172 | { |
| 1173 | if (!(user_process_event = create_event( NULL, NULL, 0, 1, 0 ))) return; |
| 1174 | make_object_static( (struct object *)user_process_event ); |
| 1175 | } |
| 1176 | |
| 1177 | if (!(reply->event = alloc_handle( current->process, user_process_event, EVENT_ALL_ACCESS, 0 ))) |
| 1178 | return; |
| 1179 | |
| 1180 | if (!process->is_system) |
| 1181 | { |
| 1182 | process->is_system = 1; |
| 1183 | if (!--user_processes) set_event( user_process_event ); |
| 1184 | } |
| 1185 | } |