blob: 250c5cea035c5609dcb0a64258efce08dcf4282c [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
Alexandre Julliardc5e433a2000-05-30 19:48:18 +000026struct msg_queue;
Turchanov Sergei43a27e32000-05-30 20:32:06 +000027struct atom_table;
Alexandre Julliard526a28d2002-10-02 23:49:30 +000028struct handle_table;
Alexandre Julliard9d802152002-05-24 21:20:27 +000029struct startup_info;
Alexandre Julliardc5e433a2000-05-30 19:48:18 +000030
Alexandre Julliardca96de32002-05-25 21:15:03 +000031/* process startup state */
32enum startup_state { STARTUP_IN_PROGRESS, STARTUP_DONE, STARTUP_ABORTED };
33
Alexandre Julliard43c190e1999-05-15 10:48:19 +000034/* process structures */
35
Alexandre Julliard05f0b712000-03-09 18:18:41 +000036struct process_dll
37{
Alexandre Julliarda9e0fb12005-03-02 10:20:09 +000038 struct list entry; /* entry in per-process dll list */
Alexandre Julliard05f0b712000-03-09 18:18:41 +000039 struct file *file; /* dll file */
Alexandre Julliardcb2788e2008-12-29 16:41:44 +010040 mod_handle_t base; /* dll base address (in process addr space) */
Alexandre Julliard947976f2008-12-29 17:10:11 +010041 client_ptr_t name; /* ptr to ptr to name (in process addr space) */
Alexandre Julliard77cf8032008-12-09 11:50:05 +010042 data_size_t size; /* dll size */
Alexandre Julliard05f0b712000-03-09 18:18:41 +000043 int dbg_offset; /* debug info offset */
44 int dbg_size; /* debug info size */
Alexandre Julliard0f273c12006-07-26 10:43:25 +020045 data_size_t namelen; /* length of dll file name */
Alexandre Julliardc30cefb2003-09-30 01:04:19 +000046 WCHAR *filename; /* dll file name */
Alexandre Julliard05f0b712000-03-09 18:18:41 +000047};
48
Alexandre Julliard3da5f841999-05-16 16:54:54 +000049struct process
50{
51 struct object obj; /* object header */
Alexandre Julliard48c0d512005-02-25 19:31:26 +000052 struct list entry; /* entry in system-wide process list */
Eric Pouech0b83d4c2001-11-23 23:04:58 +000053 struct process *parent; /* parent process */
Alexandre Julliard05026382005-03-01 10:56:18 +000054 struct list thread_list; /* thread list */
Alexandre Julliard3da5f841999-05-16 16:54:54 +000055 struct thread *debugger; /* thread debugging this process */
Alexandre Julliard526a28d2002-10-02 23:49:30 +000056 struct handle_table *handles; /* handle entries */
Alexandre Julliarde66207e2003-02-19 00:33:32 +000057 struct fd *msg_fd; /* fd for sendmsg/recvmsg */
Alexandre Julliard91befe12003-02-01 01:38:40 +000058 process_id_t id; /* id of the process */
59 process_id_t group_id; /* group id of the process */
Alexandre Julliard68e850e2006-08-14 20:19:42 +020060 struct timeout_user *sigkill_timeout; /* timeout for final SIGKILL */
Alexandre Julliard653d2c42009-04-03 14:49:10 +020061 enum cpu_type cpu; /* client CPU type */
Alexandre Julliard68e850e2006-08-14 20:19:42 +020062 int unix_pid; /* Unix pid for final SIGKILL */
Alexandre Julliard3da5f841999-05-16 16:54:54 +000063 int exit_code; /* process exit code */
64 int running_threads; /* number of threads running in this process */
Alexandre Julliardaaf477f2007-04-17 20:08:59 +020065 timeout_t start_time; /* absolute time at process start */
66 timeout_t end_time; /* absolute time at process end */
Alexandre Julliard913e7922009-01-19 14:15:51 +010067 affinity_t affinity; /* process affinity mask */
Alexandre Julliard3da5f841999-05-16 16:54:54 +000068 int priority; /* priority class */
Alexandre Julliard3da5f841999-05-16 16:54:54 +000069 int suspend; /* global process suspend count */
Alexandre Julliard156b2052007-06-06 20:33:13 +020070 int is_system; /* is it a system process? */
Alexandre Julliard01caa5e2005-07-12 20:27:09 +000071 unsigned int create_flags; /* process creation flags */
Alexandre Julliardce613492003-03-18 05:04:33 +000072 struct list locks; /* list of file locks owned by the process */
Alexandre Julliardbfce1512003-12-10 04:08:06 +000073 struct list classes; /* window classes owned by the process */
Eric Pouech0b83d4c2001-11-23 23:04:58 +000074 struct console_input*console; /* console input */
Alexandre Julliardca96de32002-05-25 21:15:03 +000075 enum startup_state startup_state; /* startup state */
Alexandre Julliard9d802152002-05-24 21:20:27 +000076 struct startup_info *startup_info; /* startup info while init is in progress */
Alexandre Julliardc5e433a2000-05-30 19:48:18 +000077 struct event *idle_event; /* event for input idle */
78 struct msg_queue *queue; /* main message queue */
Alexandre Julliard1bf96e02005-06-08 18:44:50 +000079 obj_handle_t winstation; /* main handle to process window station */
Alexandre Julliard78a3e632005-06-09 12:07:12 +000080 obj_handle_t desktop; /* handle to desktop to use for new threads */
Mike McCormack36cd6f52003-07-24 00:07:00 +000081 struct token *token; /* security token associated with this process */
Alexandre Julliarda9e0fb12005-03-02 10:20:09 +000082 struct list dlls; /* list of loaded dlls */
Alexandre Julliardfa864382008-12-30 23:02:33 +010083 client_ptr_t peb; /* PEB address in client address space */
Alexandre Julliard2cf868c2008-12-30 22:47:48 +010084 client_ptr_t ldt_copy; /* pointer to LDT copy in client addr space */
Alexandre Julliardcd1c7fc2006-12-29 16:56:11 +010085 unsigned int trace_data; /* opaque data used by the process tracing mechanism */
Alexandre Julliard3da5f841999-05-16 16:54:54 +000086};
Alexandre Julliard43c190e1999-05-15 10:48:19 +000087
88struct process_snapshot
89{
90 struct process *process; /* process ptr */
Alexandre Julliard07d84462000-04-16 19:45:05 +000091 int count; /* process refcount */
Alexandre Julliard43c190e1999-05-15 10:48:19 +000092 int threads; /* number of threads */
93 int priority; /* priority class */
Eric Pouech9fd54b22003-09-16 01:07:21 +000094 int handles; /* number of handles */
Alexandre Julliard43c190e1999-05-15 10:48:19 +000095};
96
97/* process functions */
98
Alexandre Julliard91befe12003-02-01 01:38:40 +000099extern unsigned int alloc_ptid( void *ptr );
100extern void free_ptid( unsigned int id );
101extern void *get_ptid_entry( unsigned int id );
Alexandre Julliardc316f0e2006-07-19 14:00:10 +0200102extern struct thread *create_process( int fd, struct thread *parent_thread, int inherit_all );
Alexandre Julliard0f273c12006-07-26 10:43:25 +0200103extern data_size_t init_process( struct thread *thread );
Alexandre Julliard05026382005-03-01 10:56:18 +0000104extern struct thread *get_process_first_thread( struct process *process );
Alexandre Julliard54f22872002-10-03 19:54:57 +0000105extern struct process *get_process_from_id( process_id_t id );
Alexandre Julliard51885742002-05-30 20:12:58 +0000106extern struct process *get_process_from_handle( obj_handle_t handle, unsigned int access );
Alexandre Julliard3da5f841999-05-16 16:54:54 +0000107extern int process_set_debugger( struct process *process, struct thread *thread );
Eric Pouechfbccb382002-02-27 01:28:30 +0000108extern int debugger_detach( struct process* process, struct thread* debugger );
Alexandre Julliarde55d5932003-10-14 01:30:42 +0000109extern int set_process_debug_flag( struct process *process, int flag );
Eric Pouechfbccb382002-02-27 01:28:30 +0000110
Alexandre Julliard43c190e1999-05-15 10:48:19 +0000111extern void add_process_thread( struct process *process,
112 struct thread *thread );
113extern void remove_process_thread( struct process *process,
114 struct thread *thread );
Alexandre Julliard3da5f841999-05-16 16:54:54 +0000115extern void suspend_process( struct process *process );
116extern void resume_process( struct process *process );
Alexandre Julliard81977b72006-09-21 11:14:45 +0200117extern void kill_process( struct process *process, int violent_death );
Eric Pouech3940d8a2001-12-04 20:17:43 +0000118extern void kill_console_processes( struct thread *renderer, int exit_code );
Alexandre Julliard17cf8101999-11-24 01:22:14 +0000119extern void kill_debugged_processes( struct thread *debugger, int exit_code );
Alexandre Julliard17de8292006-04-19 19:45:39 +0200120extern void break_process( struct process *process );
Eric Pouechfbccb382002-02-27 01:28:30 +0000121extern void detach_debugged_processes( struct thread *debugger );
Alexandre Julliard43c190e1999-05-15 10:48:19 +0000122extern struct process_snapshot *process_snap( int *count );
Eric Pouech93bfa0d2002-06-02 21:22:22 +0000123extern void enum_processes( int (*cb)(struct process*, void*), void *user);
Alexandre Julliardcd1c7fc2006-12-29 16:56:11 +0100124
Alexandre Julliard627ca402007-05-11 12:46:32 +0200125/* console functions */
126extern void inherit_console(struct thread *parent_thread, struct process *process, obj_handle_t hconin);
127extern int free_console( struct process *process );
128extern struct thread *console_get_renderer( struct console_input *console );
129
Alexandre Julliardc2734982006-12-29 20:38:49 +0100130/* process tracing mechanism to use */
131#ifdef __APPLE__
132#define USE_MACH
Alexandre Julliardf2792522007-03-09 13:40:41 +0100133#elif defined(__sun)
134#define USE_PROCFS
Alexandre Julliardc2734982006-12-29 20:38:49 +0100135#else
136#define USE_PTRACE
137#endif
138
Alexandre Julliardcd1c7fc2006-12-29 16:56:11 +0100139extern void init_tracing_mechanism(void);
140extern void init_process_tracing( struct process *process );
141extern void finish_process_tracing( struct process *process );
Alexandre Julliard8e9c1562008-12-30 14:11:58 +0100142extern int read_process_memory( struct process *process, client_ptr_t ptr, data_size_t size, char *dest );
143extern 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 +0000144
Andrew Talbotb1788c82007-03-17 10:52:14 +0000145static inline process_id_t get_process_id( struct process *process ) { return process->id; }
Alexandre Julliard91befe12003-02-01 01:38:40 +0000146
Andrew Talbotb1788c82007-03-17 10:52:14 +0000147static inline int is_process_init_done( struct process *process )
Alexandre Julliardca96de32002-05-25 21:15:03 +0000148{
149 return process->startup_state == STARTUP_DONE;
150}
Alexandre Julliardff81d782000-03-08 12:01:30 +0000151
Andrew Talbotb1788c82007-03-17 10:52:14 +0000152static inline struct process_dll *get_process_exe_module( struct process *process )
Alexandre Julliarde6374cb2006-02-16 12:13:01 +0100153{
154 struct list *ptr = list_head( &process->dlls );
155 return ptr ? LIST_ENTRY( ptr, struct process_dll, entry ) : NULL;
156}
157
Alexandre Julliard43c190e1999-05-15 10:48:19 +0000158#endif /* __WINE_SERVER_PROCESS_H */