blob: b073460402a30325933db9162887934678cd9e9c [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
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 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 */
40 void *base; /* dll base address (in process addr space) */
Alexandre Julliardaeb56602002-03-22 00:21:23 +000041 size_t size; /* dll size */
Alexandre Julliard05f0b712000-03-09 18:18:41 +000042 void *name; /* ptr to ptr to name (in process addr space) */
43 int dbg_offset; /* debug info offset */
44 int dbg_size; /* debug info size */
Alexandre Julliardaeb56602002-03-22 00:21:23 +000045 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 Julliard3da5f841999-05-16 16:54:54 +000060 int exit_code; /* process exit code */
61 int running_threads; /* number of threads running in this process */
62 struct timeval start_time; /* absolute time at process start */
63 struct timeval end_time; /* absolute time at process end */
64 int priority; /* priority class */
65 int affinity; /* process affinity mask */
66 int suspend; /* global process suspend count */
Alexandre Julliard01caa5e2005-07-12 20:27:09 +000067 unsigned int create_flags; /* process creation flags */
Alexandre Julliardce613492003-03-18 05:04:33 +000068 struct list locks; /* list of file locks owned by the process */
Alexandre Julliardbfce1512003-12-10 04:08:06 +000069 struct list classes; /* window classes owned by the process */
Eric Pouech0b83d4c2001-11-23 23:04:58 +000070 struct console_input*console; /* console input */
Alexandre Julliardca96de32002-05-25 21:15:03 +000071 enum startup_state startup_state; /* startup state */
Alexandre Julliard9d802152002-05-24 21:20:27 +000072 struct startup_info *startup_info; /* startup info while init is in progress */
Alexandre Julliardc5e433a2000-05-30 19:48:18 +000073 struct event *idle_event; /* event for input idle */
74 struct msg_queue *queue; /* main message queue */
Alexandre Julliard1bf96e02005-06-08 18:44:50 +000075 obj_handle_t winstation; /* main handle to process window station */
Alexandre Julliard78a3e632005-06-09 12:07:12 +000076 obj_handle_t desktop; /* handle to desktop to use for new threads */
Mike McCormack36cd6f52003-07-24 00:07:00 +000077 struct token *token; /* security token associated with this process */
Alexandre Julliarda9e0fb12005-03-02 10:20:09 +000078 struct list dlls; /* list of loaded dlls */
Alexandre Julliarde55d5932003-10-14 01:30:42 +000079 void *peb; /* PEB address in client address space */
Alexandre Julliard0a7c1f62000-01-27 02:54:17 +000080 void *ldt_copy; /* pointer to LDT copy in client addr space */
Alexandre Julliard3da5f841999-05-16 16:54:54 +000081};
Alexandre Julliard43c190e1999-05-15 10:48:19 +000082
83struct process_snapshot
84{
85 struct process *process; /* process ptr */
Alexandre Julliard07d84462000-04-16 19:45:05 +000086 int count; /* process refcount */
Alexandre Julliard43c190e1999-05-15 10:48:19 +000087 int threads; /* number of threads */
88 int priority; /* priority class */
Eric Pouech9fd54b22003-09-16 01:07:21 +000089 int handles; /* number of handles */
Alexandre Julliard43c190e1999-05-15 10:48:19 +000090};
91
Alexandre Julliard07d84462000-04-16 19:45:05 +000092struct module_snapshot
93{
94 void *base; /* module base addr */
Alexandre Julliardaeb56602002-03-22 00:21:23 +000095 size_t size; /* module size */
96 size_t namelen; /* length of file name */
Alexandre Julliardc30cefb2003-09-30 01:04:19 +000097 WCHAR *filename; /* module file name */
Alexandre Julliard07d84462000-04-16 19:45:05 +000098};
99
Alexandre Julliard43c190e1999-05-15 10:48:19 +0000100/* process functions */
101
Alexandre Julliard91befe12003-02-01 01:38:40 +0000102extern unsigned int alloc_ptid( void *ptr );
103extern void free_ptid( unsigned int id );
104extern void *get_ptid_entry( unsigned int id );
Alexandre Julliard5b4f3e82000-05-01 16:24:22 +0000105extern struct thread *create_process( int fd );
Alexandre Julliard11ad6a02005-07-13 19:43:35 +0000106extern size_t init_process( struct thread *thread );
Alexandre Julliard05026382005-03-01 10:56:18 +0000107extern struct thread *get_process_first_thread( struct process *process );
Alexandre Julliard54f22872002-10-03 19:54:57 +0000108extern struct process *get_process_from_id( process_id_t id );
Alexandre Julliard51885742002-05-30 20:12:58 +0000109extern struct process *get_process_from_handle( obj_handle_t handle, unsigned int access );
Alexandre Julliard3da5f841999-05-16 16:54:54 +0000110extern int process_set_debugger( struct process *process, struct thread *thread );
Eric Pouechfbccb382002-02-27 01:28:30 +0000111extern int debugger_detach( struct process* process, struct thread* debugger );
Alexandre Julliarde55d5932003-10-14 01:30:42 +0000112extern int set_process_debug_flag( struct process *process, int flag );
Eric Pouechfbccb382002-02-27 01:28:30 +0000113
Alexandre Julliard43c190e1999-05-15 10:48:19 +0000114extern void add_process_thread( struct process *process,
115 struct thread *thread );
116extern void remove_process_thread( struct process *process,
117 struct thread *thread );
Alexandre Julliard3da5f841999-05-16 16:54:54 +0000118extern void suspend_process( struct process *process );
119extern void resume_process( struct process *process );
Alexandre Julliard40043ed2002-08-16 20:02:15 +0000120extern void kill_all_processes( struct process *skip, int exit_code );
Alexandre Julliardf5242402001-02-28 21:45:23 +0000121extern void kill_process( struct process *process, struct thread *skip, int exit_code );
Eric Pouech3940d8a2001-12-04 20:17:43 +0000122extern void kill_console_processes( struct thread *renderer, int exit_code );
Alexandre Julliard17cf8101999-11-24 01:22:14 +0000123extern void kill_debugged_processes( struct thread *debugger, int exit_code );
Alexandre Julliard17de8292006-04-19 19:45:39 +0200124extern void break_process( struct process *process );
Eric Pouechfbccb382002-02-27 01:28:30 +0000125extern void detach_debugged_processes( struct thread *debugger );
Alexandre Julliard43c190e1999-05-15 10:48:19 +0000126extern struct process_snapshot *process_snap( int *count );
Alexandre Julliard07d84462000-04-16 19:45:05 +0000127extern struct module_snapshot *module_snap( struct process *process, int *count );
Eric Pouech93bfa0d2002-06-02 21:22:22 +0000128extern void enum_processes( int (*cb)(struct process*, void*), void *user);
Alexandre Julliardcb709312006-04-07 19:52:12 +0200129extern int read_process_memory( struct process *process, const void *ptr, size_t size, char *dest );
130extern int write_process_memory( struct process *process, void *ptr, size_t size, const char *src );
Alexandre Julliard43c190e1999-05-15 10:48:19 +0000131
Alexandre Julliard91befe12003-02-01 01:38:40 +0000132inline static process_id_t get_process_id( struct process *process ) { return process->id; }
133
Alexandre Julliardca96de32002-05-25 21:15:03 +0000134inline static int is_process_init_done( struct process *process )
135{
136 return process->startup_state == STARTUP_DONE;
137}
Alexandre Julliardff81d782000-03-08 12:01:30 +0000138
Alexandre Julliarde6374cb2006-02-16 12:13:01 +0100139inline static struct process_dll *get_process_exe_module( struct process *process )
140{
141 struct list *ptr = list_head( &process->dlls );
142 return ptr ? LIST_ENTRY( ptr, struct process_dll, entry ) : NULL;
143}
144
Alexandre Julliard43c190e1999-05-15 10:48:19 +0000145#endif /* __WINE_SERVER_PROCESS_H */