Alexandre Julliard | 43c190e | 1999-05-15 10:48:19 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Wine server processes |
| 3 | * |
| 4 | * Copyright (C) 1999 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 | 43c190e | 1999-05-15 10:48:19 +0000 | [diff] [blame] | 19 | */ |
| 20 | |
| 21 | #ifndef __WINE_SERVER_PROCESS_H |
| 22 | #define __WINE_SERVER_PROCESS_H |
| 23 | |
Alexandre Julliard | 43c190e | 1999-05-15 10:48:19 +0000 | [diff] [blame] | 24 | #include "object.h" |
| 25 | |
Turchanov Sergei | 43a27e3 | 2000-05-30 20:32:06 +0000 | [diff] [blame] | 26 | struct atom_table; |
Alexandre Julliard | 526a28d | 2002-10-02 23:49:30 +0000 | [diff] [blame] | 27 | struct handle_table; |
Alexandre Julliard | 9d80215 | 2002-05-24 21:20:27 +0000 | [diff] [blame] | 28 | struct startup_info; |
Alexandre Julliard | c5e433a | 2000-05-30 19:48:18 +0000 | [diff] [blame] | 29 | |
Alexandre Julliard | ca96de3 | 2002-05-25 21:15:03 +0000 | [diff] [blame] | 30 | /* process startup state */ |
| 31 | enum startup_state { STARTUP_IN_PROGRESS, STARTUP_DONE, STARTUP_ABORTED }; |
| 32 | |
Alexandre Julliard | 43c190e | 1999-05-15 10:48:19 +0000 | [diff] [blame] | 33 | /* process structures */ |
| 34 | |
Alexandre Julliard | 05f0b71 | 2000-03-09 18:18:41 +0000 | [diff] [blame] | 35 | struct process_dll |
| 36 | { |
Alexandre Julliard | a9e0fb1 | 2005-03-02 10:20:09 +0000 | [diff] [blame] | 37 | struct list entry; /* entry in per-process dll list */ |
Alexandre Julliard | 05f0b71 | 2000-03-09 18:18:41 +0000 | [diff] [blame] | 38 | struct file *file; /* dll file */ |
Alexandre Julliard | cb2788e | 2008-12-29 16:41:44 +0100 | [diff] [blame] | 39 | mod_handle_t base; /* dll base address (in process addr space) */ |
Alexandre Julliard | 947976f | 2008-12-29 17:10:11 +0100 | [diff] [blame] | 40 | client_ptr_t name; /* ptr to ptr to name (in process addr space) */ |
Alexandre Julliard | 77cf803 | 2008-12-09 11:50:05 +0100 | [diff] [blame] | 41 | data_size_t size; /* dll size */ |
Alexandre Julliard | 05f0b71 | 2000-03-09 18:18:41 +0000 | [diff] [blame] | 42 | int dbg_offset; /* debug info offset */ |
| 43 | int dbg_size; /* debug info size */ |
Alexandre Julliard | 0f273c1 | 2006-07-26 10:43:25 +0200 | [diff] [blame] | 44 | data_size_t namelen; /* length of dll file name */ |
Alexandre Julliard | c30cefb | 2003-09-30 01:04:19 +0000 | [diff] [blame] | 45 | WCHAR *filename; /* dll file name */ |
Alexandre Julliard | 05f0b71 | 2000-03-09 18:18:41 +0000 | [diff] [blame] | 46 | }; |
| 47 | |
Alexandre Julliard | 3da5f84 | 1999-05-16 16:54:54 +0000 | [diff] [blame] | 48 | struct process |
| 49 | { |
| 50 | struct object obj; /* object header */ |
Alexandre Julliard | 48c0d51 | 2005-02-25 19:31:26 +0000 | [diff] [blame] | 51 | struct list entry; /* entry in system-wide process list */ |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 52 | struct process *parent; /* parent process */ |
Alexandre Julliard | 0502638 | 2005-03-01 10:56:18 +0000 | [diff] [blame] | 53 | struct list thread_list; /* thread list */ |
Alexandre Julliard | 3da5f84 | 1999-05-16 16:54:54 +0000 | [diff] [blame] | 54 | struct thread *debugger; /* thread debugging this process */ |
Alexandre Julliard | 526a28d | 2002-10-02 23:49:30 +0000 | [diff] [blame] | 55 | struct handle_table *handles; /* handle entries */ |
Alexandre Julliard | e66207e | 2003-02-19 00:33:32 +0000 | [diff] [blame] | 56 | struct fd *msg_fd; /* fd for sendmsg/recvmsg */ |
Alexandre Julliard | 91befe1 | 2003-02-01 01:38:40 +0000 | [diff] [blame] | 57 | process_id_t id; /* id of the process */ |
| 58 | process_id_t group_id; /* group id of the process */ |
Alexandre Julliard | 68e850e | 2006-08-14 20:19:42 +0200 | [diff] [blame] | 59 | struct timeout_user *sigkill_timeout; /* timeout for final SIGKILL */ |
Alexandre Julliard | 653d2c4 | 2009-04-03 14:49:10 +0200 | [diff] [blame] | 60 | enum cpu_type cpu; /* client CPU type */ |
Alexandre Julliard | 68e850e | 2006-08-14 20:19:42 +0200 | [diff] [blame] | 61 | int unix_pid; /* Unix pid for final SIGKILL */ |
Alexandre Julliard | 3da5f84 | 1999-05-16 16:54:54 +0000 | [diff] [blame] | 62 | int exit_code; /* process exit code */ |
| 63 | int running_threads; /* number of threads running in this process */ |
Alexandre Julliard | aaf477f | 2007-04-17 20:08:59 +0200 | [diff] [blame] | 64 | timeout_t start_time; /* absolute time at process start */ |
| 65 | timeout_t end_time; /* absolute time at process end */ |
Alexandre Julliard | 913e792 | 2009-01-19 14:15:51 +0100 | [diff] [blame] | 66 | affinity_t affinity; /* process affinity mask */ |
Alexandre Julliard | 3da5f84 | 1999-05-16 16:54:54 +0000 | [diff] [blame] | 67 | int priority; /* priority class */ |
Alexandre Julliard | 3da5f84 | 1999-05-16 16:54:54 +0000 | [diff] [blame] | 68 | int suspend; /* global process suspend count */ |
Alexandre Julliard | 156b205 | 2007-06-06 20:33:13 +0200 | [diff] [blame] | 69 | int is_system; /* is it a system process? */ |
Alexandre Julliard | 01caa5e | 2005-07-12 20:27:09 +0000 | [diff] [blame] | 70 | unsigned int create_flags; /* process creation flags */ |
Alexandre Julliard | ce61349 | 2003-03-18 05:04:33 +0000 | [diff] [blame] | 71 | struct list locks; /* list of file locks owned by the process */ |
Alexandre Julliard | bfce151 | 2003-12-10 04:08:06 +0000 | [diff] [blame] | 72 | struct list classes; /* window classes owned by the process */ |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 73 | struct console_input*console; /* console input */ |
Alexandre Julliard | ca96de3 | 2002-05-25 21:15:03 +0000 | [diff] [blame] | 74 | enum startup_state startup_state; /* startup state */ |
Alexandre Julliard | 9d80215 | 2002-05-24 21:20:27 +0000 | [diff] [blame] | 75 | struct startup_info *startup_info; /* startup info while init is in progress */ |
Alexandre Julliard | c5e433a | 2000-05-30 19:48:18 +0000 | [diff] [blame] | 76 | struct event *idle_event; /* event for input idle */ |
Alexandre Julliard | 1bf96e0 | 2005-06-08 18:44:50 +0000 | [diff] [blame] | 77 | obj_handle_t winstation; /* main handle to process window station */ |
Alexandre Julliard | 78a3e63 | 2005-06-09 12:07:12 +0000 | [diff] [blame] | 78 | obj_handle_t desktop; /* handle to desktop to use for new threads */ |
Mike McCormack | 36cd6f5 | 2003-07-24 00:07:00 +0000 | [diff] [blame] | 79 | struct token *token; /* security token associated with this process */ |
Alexandre Julliard | a9e0fb1 | 2005-03-02 10:20:09 +0000 | [diff] [blame] | 80 | struct list dlls; /* list of loaded dlls */ |
Alexandre Julliard | fa86438 | 2008-12-30 23:02:33 +0100 | [diff] [blame] | 81 | client_ptr_t peb; /* PEB address in client address space */ |
Alexandre Julliard | 2cf868c | 2008-12-30 22:47:48 +0100 | [diff] [blame] | 82 | client_ptr_t ldt_copy; /* pointer to LDT copy in client addr space */ |
Alexandre Julliard | cd1c7fc | 2006-12-29 16:56:11 +0100 | [diff] [blame] | 83 | unsigned int trace_data; /* opaque data used by the process tracing mechanism */ |
Alexandre Julliard | 3da5f84 | 1999-05-16 16:54:54 +0000 | [diff] [blame] | 84 | }; |
Alexandre Julliard | 43c190e | 1999-05-15 10:48:19 +0000 | [diff] [blame] | 85 | |
| 86 | struct process_snapshot |
| 87 | { |
| 88 | struct process *process; /* process ptr */ |
Alexandre Julliard | 07d8446 | 2000-04-16 19:45:05 +0000 | [diff] [blame] | 89 | int count; /* process refcount */ |
Alexandre Julliard | 43c190e | 1999-05-15 10:48:19 +0000 | [diff] [blame] | 90 | int threads; /* number of threads */ |
| 91 | int priority; /* priority class */ |
Eric Pouech | 9fd54b2 | 2003-09-16 01:07:21 +0000 | [diff] [blame] | 92 | int handles; /* number of handles */ |
Alexandre Julliard | 43c190e | 1999-05-15 10:48:19 +0000 | [diff] [blame] | 93 | }; |
| 94 | |
Alexandre Julliard | bbc03d5 | 2010-05-04 20:26:53 +0200 | [diff] [blame] | 95 | #define CPU_FLAG(cpu) (1 << (cpu)) |
| 96 | #define CPU_64BIT_MASK CPU_FLAG(CPU_x86_64) |
| 97 | |
Alexandre Julliard | 43c190e | 1999-05-15 10:48:19 +0000 | [diff] [blame] | 98 | /* process functions */ |
| 99 | |
Alexandre Julliard | 91befe1 | 2003-02-01 01:38:40 +0000 | [diff] [blame] | 100 | extern unsigned int alloc_ptid( void *ptr ); |
| 101 | extern void free_ptid( unsigned int id ); |
| 102 | extern void *get_ptid_entry( unsigned int id ); |
Alexandre Julliard | c316f0e | 2006-07-19 14:00:10 +0200 | [diff] [blame] | 103 | extern struct thread *create_process( int fd, struct thread *parent_thread, int inherit_all ); |
Alexandre Julliard | 0f273c1 | 2006-07-26 10:43:25 +0200 | [diff] [blame] | 104 | extern data_size_t init_process( struct thread *thread ); |
Alexandre Julliard | 0502638 | 2005-03-01 10:56:18 +0000 | [diff] [blame] | 105 | extern struct thread *get_process_first_thread( struct process *process ); |
Alexandre Julliard | 54f2287 | 2002-10-03 19:54:57 +0000 | [diff] [blame] | 106 | extern struct process *get_process_from_id( process_id_t id ); |
Alexandre Julliard | 5188574 | 2002-05-30 20:12:58 +0000 | [diff] [blame] | 107 | extern struct process *get_process_from_handle( obj_handle_t handle, unsigned int access ); |
Alexandre Julliard | 3da5f84 | 1999-05-16 16:54:54 +0000 | [diff] [blame] | 108 | extern int process_set_debugger( struct process *process, struct thread *thread ); |
Eric Pouech | fbccb38 | 2002-02-27 01:28:30 +0000 | [diff] [blame] | 109 | extern int debugger_detach( struct process* process, struct thread* debugger ); |
Alexandre Julliard | e55d593 | 2003-10-14 01:30:42 +0000 | [diff] [blame] | 110 | extern int set_process_debug_flag( struct process *process, int flag ); |
Eric Pouech | fbccb38 | 2002-02-27 01:28:30 +0000 | [diff] [blame] | 111 | |
Alexandre Julliard | 43c190e | 1999-05-15 10:48:19 +0000 | [diff] [blame] | 112 | extern void add_process_thread( struct process *process, |
| 113 | struct thread *thread ); |
| 114 | extern void remove_process_thread( struct process *process, |
| 115 | struct thread *thread ); |
Alexandre Julliard | 3da5f84 | 1999-05-16 16:54:54 +0000 | [diff] [blame] | 116 | extern void suspend_process( struct process *process ); |
| 117 | extern void resume_process( struct process *process ); |
Alexandre Julliard | 81977b7 | 2006-09-21 11:14:45 +0200 | [diff] [blame] | 118 | extern void kill_process( struct process *process, int violent_death ); |
Eric Pouech | 3940d8a | 2001-12-04 20:17:43 +0000 | [diff] [blame] | 119 | extern void kill_console_processes( struct thread *renderer, int exit_code ); |
Alexandre Julliard | 17cf810 | 1999-11-24 01:22:14 +0000 | [diff] [blame] | 120 | extern void kill_debugged_processes( struct thread *debugger, int exit_code ); |
Alexandre Julliard | 17de829 | 2006-04-19 19:45:39 +0200 | [diff] [blame] | 121 | extern void break_process( struct process *process ); |
Eric Pouech | fbccb38 | 2002-02-27 01:28:30 +0000 | [diff] [blame] | 122 | extern void detach_debugged_processes( struct thread *debugger ); |
Alexandre Julliard | 43c190e | 1999-05-15 10:48:19 +0000 | [diff] [blame] | 123 | extern struct process_snapshot *process_snap( int *count ); |
Eric Pouech | 93bfa0d | 2002-06-02 21:22:22 +0000 | [diff] [blame] | 124 | extern void enum_processes( int (*cb)(struct process*, void*), void *user); |
Alexandre Julliard | cd1c7fc | 2006-12-29 16:56:11 +0100 | [diff] [blame] | 125 | |
Alexandre Julliard | 627ca40 | 2007-05-11 12:46:32 +0200 | [diff] [blame] | 126 | /* console functions */ |
| 127 | extern void inherit_console(struct thread *parent_thread, struct process *process, obj_handle_t hconin); |
| 128 | extern int free_console( struct process *process ); |
| 129 | extern struct thread *console_get_renderer( struct console_input *console ); |
| 130 | |
Alexandre Julliard | c273498 | 2006-12-29 20:38:49 +0100 | [diff] [blame] | 131 | /* process tracing mechanism to use */ |
| 132 | #ifdef __APPLE__ |
| 133 | #define USE_MACH |
Alexandre Julliard | f279252 | 2007-03-09 13:40:41 +0100 | [diff] [blame] | 134 | #elif defined(__sun) |
| 135 | #define USE_PROCFS |
Alexandre Julliard | c273498 | 2006-12-29 20:38:49 +0100 | [diff] [blame] | 136 | #else |
| 137 | #define USE_PTRACE |
| 138 | #endif |
| 139 | |
Alexandre Julliard | cd1c7fc | 2006-12-29 16:56:11 +0100 | [diff] [blame] | 140 | extern void init_tracing_mechanism(void); |
| 141 | extern void init_process_tracing( struct process *process ); |
| 142 | extern void finish_process_tracing( struct process *process ); |
Alexandre Julliard | 8e9c156 | 2008-12-30 14:11:58 +0100 | [diff] [blame] | 143 | extern int read_process_memory( struct process *process, client_ptr_t ptr, data_size_t size, char *dest ); |
| 144 | extern int write_process_memory( struct process *process, client_ptr_t ptr, data_size_t size, const char *src ); |
Alexandre Julliard | 43c190e | 1999-05-15 10:48:19 +0000 | [diff] [blame] | 145 | |
Andrew Talbot | b1788c8 | 2007-03-17 10:52:14 +0000 | [diff] [blame] | 146 | static inline process_id_t get_process_id( struct process *process ) { return process->id; } |
Alexandre Julliard | 91befe1 | 2003-02-01 01:38:40 +0000 | [diff] [blame] | 147 | |
Andrew Talbot | b1788c8 | 2007-03-17 10:52:14 +0000 | [diff] [blame] | 148 | static inline int is_process_init_done( struct process *process ) |
Alexandre Julliard | ca96de3 | 2002-05-25 21:15:03 +0000 | [diff] [blame] | 149 | { |
| 150 | return process->startup_state == STARTUP_DONE; |
| 151 | } |
Alexandre Julliard | ff81d78 | 2000-03-08 12:01:30 +0000 | [diff] [blame] | 152 | |
Andrew Talbot | b1788c8 | 2007-03-17 10:52:14 +0000 | [diff] [blame] | 153 | static inline struct process_dll *get_process_exe_module( struct process *process ) |
Alexandre Julliard | e6374cb | 2006-02-16 12:13:01 +0100 | [diff] [blame] | 154 | { |
| 155 | struct list *ptr = list_head( &process->dlls ); |
| 156 | return ptr ? LIST_ENTRY( ptr, struct process_dll, entry ) : NULL; |
| 157 | } |
| 158 | |
Alexandre Julliard | 43c190e | 1999-05-15 10:48:19 +0000 | [diff] [blame] | 159 | #endif /* __WINE_SERVER_PROCESS_H */ |