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