blob: cee7be938166794f67c38719abacd2ccaa916b6d [file] [log] [blame]
Alexandre Julliard43c190e1999-05-15 10:48:19 +00001/*
2 * Wine server processes
3 *
4 * Copyright (C) 1999 Alexandre Julliard
Alexandre Julliard0799c1a2002-03-09 23:29:33 +00005 *
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 Ernst360a3f92006-05-18 14:49:52 +020018 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
Alexandre Julliard43c190e1999-05-15 10:48:19 +000019 */
20
21#ifndef __WINE_SERVER_PROCESS_H
22#define __WINE_SERVER_PROCESS_H
23
Alexandre Julliard43c190e1999-05-15 10:48:19 +000024#include "object.h"
25
Turchanov Sergei43a27e32000-05-30 20:32:06 +000026struct atom_table;
Alexandre Julliard526a28d2002-10-02 23:49:30 +000027struct handle_table;
Alexandre Julliard9d802152002-05-24 21:20:27 +000028struct startup_info;
Alexandre Julliardc5e433a2000-05-30 19:48:18 +000029
Alexandre Julliardca96de32002-05-25 21:15:03 +000030/* process startup state */
31enum startup_state { STARTUP_IN_PROGRESS, STARTUP_DONE, STARTUP_ABORTED };
32
Alexandre Julliard43c190e1999-05-15 10:48:19 +000033/* process structures */
34
Alexandre Julliard05f0b712000-03-09 18:18:41 +000035struct process_dll
36{
Alexandre Julliarda9e0fb12005-03-02 10:20:09 +000037 struct list entry; /* entry in per-process dll list */
Alexandre Julliard05f0b712000-03-09 18:18:41 +000038 struct file *file; /* dll file */
Alexandre Julliardcb2788e2008-12-29 16:41:44 +010039 mod_handle_t base; /* dll base address (in process addr space) */
Alexandre Julliard947976f2008-12-29 17:10:11 +010040 client_ptr_t name; /* ptr to ptr to name (in process addr space) */
Alexandre Julliard77cf8032008-12-09 11:50:05 +010041 data_size_t size; /* dll size */
Alexandre Julliard05f0b712000-03-09 18:18:41 +000042 int dbg_offset; /* debug info offset */
43 int dbg_size; /* debug info size */
Alexandre Julliard0f273c12006-07-26 10:43:25 +020044 data_size_t namelen; /* length of dll file name */
Alexandre Julliardc30cefb2003-09-30 01:04:19 +000045 WCHAR *filename; /* dll file name */
Alexandre Julliard05f0b712000-03-09 18:18:41 +000046};
47
Alexandre Julliard3da5f841999-05-16 16:54:54 +000048struct process
49{
50 struct object obj; /* object header */
Alexandre Julliard48c0d512005-02-25 19:31:26 +000051 struct list entry; /* entry in system-wide process list */
Eric Pouech0b83d4c2001-11-23 23:04:58 +000052 struct process *parent; /* parent process */
Alexandre Julliard05026382005-03-01 10:56:18 +000053 struct list thread_list; /* thread list */
Alexandre Julliard3da5f841999-05-16 16:54:54 +000054 struct thread *debugger; /* thread debugging this process */
Alexandre Julliard526a28d2002-10-02 23:49:30 +000055 struct handle_table *handles; /* handle entries */
Alexandre Julliarde66207e2003-02-19 00:33:32 +000056 struct fd *msg_fd; /* fd for sendmsg/recvmsg */
Alexandre Julliard91befe12003-02-01 01:38:40 +000057 process_id_t id; /* id of the process */
58 process_id_t group_id; /* group id of the process */
Alexandre Julliard68e850e2006-08-14 20:19:42 +020059 struct timeout_user *sigkill_timeout; /* timeout for final SIGKILL */
Alexandre Julliard653d2c42009-04-03 14:49:10 +020060 enum cpu_type cpu; /* client CPU type */
Alexandre Julliard68e850e2006-08-14 20:19:42 +020061 int unix_pid; /* Unix pid for final SIGKILL */
Alexandre Julliard3da5f841999-05-16 16:54:54 +000062 int exit_code; /* process exit code */
63 int running_threads; /* number of threads running in this process */
Alexandre Julliardaaf477f2007-04-17 20:08:59 +020064 timeout_t start_time; /* absolute time at process start */
65 timeout_t end_time; /* absolute time at process end */
Alexandre Julliard913e7922009-01-19 14:15:51 +010066 affinity_t affinity; /* process affinity mask */
Alexandre Julliard3da5f841999-05-16 16:54:54 +000067 int priority; /* priority class */
Alexandre Julliard3da5f841999-05-16 16:54:54 +000068 int suspend; /* global process suspend count */
Alexandre Julliard156b2052007-06-06 20:33:13 +020069 int is_system; /* is it a system process? */
Alexandre Julliard01caa5e2005-07-12 20:27:09 +000070 unsigned int create_flags; /* process creation flags */
Alexandre Julliardce613492003-03-18 05:04:33 +000071 struct list locks; /* list of file locks owned by the process */
Alexandre Julliardbfce1512003-12-10 04:08:06 +000072 struct list classes; /* window classes owned by the process */
Eric Pouech0b83d4c2001-11-23 23:04:58 +000073 struct console_input*console; /* console input */
Alexandre Julliardca96de32002-05-25 21:15:03 +000074 enum startup_state startup_state; /* startup state */
Alexandre Julliard9d802152002-05-24 21:20:27 +000075 struct startup_info *startup_info; /* startup info while init is in progress */
Alexandre Julliardc5e433a2000-05-30 19:48:18 +000076 struct event *idle_event; /* event for input idle */
Alexandre Julliard1bf96e02005-06-08 18:44:50 +000077 obj_handle_t winstation; /* main handle to process window station */
Alexandre Julliard78a3e632005-06-09 12:07:12 +000078 obj_handle_t desktop; /* handle to desktop to use for new threads */
Mike McCormack36cd6f52003-07-24 00:07:00 +000079 struct token *token; /* security token associated with this process */
Alexandre Julliarda9e0fb12005-03-02 10:20:09 +000080 struct list dlls; /* list of loaded dlls */
Alexandre Julliardfa864382008-12-30 23:02:33 +010081 client_ptr_t peb; /* PEB address in client address space */
Alexandre Julliard2cf868c2008-12-30 22:47:48 +010082 client_ptr_t ldt_copy; /* pointer to LDT copy in client addr space */
Alexandre Julliardcd1c7fc2006-12-29 16:56:11 +010083 unsigned int trace_data; /* opaque data used by the process tracing mechanism */
Alexandre Julliard3da5f841999-05-16 16:54:54 +000084};
Alexandre Julliard43c190e1999-05-15 10:48:19 +000085
86struct process_snapshot
87{
88 struct process *process; /* process ptr */
Alexandre Julliard07d84462000-04-16 19:45:05 +000089 int count; /* process refcount */
Alexandre Julliard43c190e1999-05-15 10:48:19 +000090 int threads; /* number of threads */
91 int priority; /* priority class */
Eric Pouech9fd54b22003-09-16 01:07:21 +000092 int handles; /* number of handles */
Alexandre Julliard43c190e1999-05-15 10:48:19 +000093};
94
Alexandre Julliardbbc03d52010-05-04 20:26:53 +020095#define CPU_FLAG(cpu) (1 << (cpu))
96#define CPU_64BIT_MASK CPU_FLAG(CPU_x86_64)
97
Alexandre Julliard43c190e1999-05-15 10:48:19 +000098/* process functions */
99
Alexandre Julliard91befe12003-02-01 01:38:40 +0000100extern unsigned int alloc_ptid( void *ptr );
101extern void free_ptid( unsigned int id );
102extern void *get_ptid_entry( unsigned int id );
Alexandre Julliardc316f0e2006-07-19 14:00:10 +0200103extern struct thread *create_process( int fd, struct thread *parent_thread, int inherit_all );
Alexandre Julliard0f273c12006-07-26 10:43:25 +0200104extern data_size_t init_process( struct thread *thread );
Alexandre Julliard05026382005-03-01 10:56:18 +0000105extern struct thread *get_process_first_thread( struct process *process );
Alexandre Julliard54f22872002-10-03 19:54:57 +0000106extern struct process *get_process_from_id( process_id_t id );
Alexandre Julliard51885742002-05-30 20:12:58 +0000107extern struct process *get_process_from_handle( obj_handle_t handle, unsigned int access );
Alexandre Julliard3da5f841999-05-16 16:54:54 +0000108extern int process_set_debugger( struct process *process, struct thread *thread );
Eric Pouechfbccb382002-02-27 01:28:30 +0000109extern int debugger_detach( struct process* process, struct thread* debugger );
Alexandre Julliarde55d5932003-10-14 01:30:42 +0000110extern int set_process_debug_flag( struct process *process, int flag );
Eric Pouechfbccb382002-02-27 01:28:30 +0000111
Alexandre Julliard43c190e1999-05-15 10:48:19 +0000112extern void add_process_thread( struct process *process,
113 struct thread *thread );
114extern void remove_process_thread( struct process *process,
115 struct thread *thread );
Alexandre Julliard3da5f841999-05-16 16:54:54 +0000116extern void suspend_process( struct process *process );
117extern void resume_process( struct process *process );
Alexandre Julliard81977b72006-09-21 11:14:45 +0200118extern void kill_process( struct process *process, int violent_death );
Eric Pouech3940d8a2001-12-04 20:17:43 +0000119extern void kill_console_processes( struct thread *renderer, int exit_code );
Alexandre Julliard17cf8101999-11-24 01:22:14 +0000120extern void kill_debugged_processes( struct thread *debugger, int exit_code );
Alexandre Julliard17de8292006-04-19 19:45:39 +0200121extern void break_process( struct process *process );
Eric Pouechfbccb382002-02-27 01:28:30 +0000122extern void detach_debugged_processes( struct thread *debugger );
Alexandre Julliard43c190e1999-05-15 10:48:19 +0000123extern struct process_snapshot *process_snap( int *count );
Eric Pouech93bfa0d2002-06-02 21:22:22 +0000124extern void enum_processes( int (*cb)(struct process*, void*), void *user);
Alexandre Julliardcd1c7fc2006-12-29 16:56:11 +0100125
Alexandre Julliard627ca402007-05-11 12:46:32 +0200126/* console functions */
127extern void inherit_console(struct thread *parent_thread, struct process *process, obj_handle_t hconin);
128extern int free_console( struct process *process );
129extern struct thread *console_get_renderer( struct console_input *console );
130
Alexandre Julliardc2734982006-12-29 20:38:49 +0100131/* process tracing mechanism to use */
132#ifdef __APPLE__
133#define USE_MACH
Alexandre Julliardf2792522007-03-09 13:40:41 +0100134#elif defined(__sun)
135#define USE_PROCFS
Alexandre Julliardc2734982006-12-29 20:38:49 +0100136#else
137#define USE_PTRACE
138#endif
139
Alexandre Julliardcd1c7fc2006-12-29 16:56:11 +0100140extern void init_tracing_mechanism(void);
141extern void init_process_tracing( struct process *process );
142extern void finish_process_tracing( struct process *process );
Alexandre Julliard8e9c1562008-12-30 14:11:58 +0100143extern int read_process_memory( struct process *process, client_ptr_t ptr, data_size_t size, char *dest );
144extern int write_process_memory( struct process *process, client_ptr_t ptr, data_size_t size, const char *src );
Alexandre Julliard43c190e1999-05-15 10:48:19 +0000145
Andrew Talbotb1788c82007-03-17 10:52:14 +0000146static inline process_id_t get_process_id( struct process *process ) { return process->id; }
Alexandre Julliard91befe12003-02-01 01:38:40 +0000147
Andrew Talbotb1788c82007-03-17 10:52:14 +0000148static inline int is_process_init_done( struct process *process )
Alexandre Julliardca96de32002-05-25 21:15:03 +0000149{
150 return process->startup_state == STARTUP_DONE;
151}
Alexandre Julliardff81d782000-03-08 12:01:30 +0000152
Andrew Talbotb1788c82007-03-17 10:52:14 +0000153static inline struct process_dll *get_process_exe_module( struct process *process )
Alexandre Julliarde6374cb2006-02-16 12:13:01 +0100154{
155 struct list *ptr = list_head( &process->dlls );
156 return ptr ? LIST_ENTRY( ptr, struct process_dll, entry ) : NULL;
157}
158
Alexandre Julliard43c190e1999-05-15 10:48:19 +0000159#endif /* __WINE_SERVER_PROCESS_H */