process.h 7.4 KB
Newer Older
1 2 3 4
/*
 * Wine server processes
 *
 * Copyright (C) 1999 Alexandre Julliard
5 6 7 8 9 10 11 12 13 14 15 16 17
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 20 21 22 23 24 25
 */

#ifndef __WINE_SERVER_PROCESS_H
#define __WINE_SERVER_PROCESS_H

#include "object.h"

26
struct atom_table;
27
struct handle_table;
28
struct startup_info;
29

30 31 32
/* process startup state */
enum startup_state { STARTUP_IN_PROGRESS, STARTUP_DONE, STARTUP_ABORTED };

33 34
/* process structures */

35 36
struct process_dll
{
37
    struct list          entry;           /* entry in per-process dll list */
38
    struct mapping      *mapping;         /* dll file */
39
    mod_handle_t         base;            /* dll base address (in process addr space) */
40
    client_ptr_t         name;            /* ptr to ptr to name (in process addr space) */
41
    data_size_t          size;            /* dll size */
42 43
    int                  dbg_offset;      /* debug info offset */
    int                  dbg_size;        /* debug info size */
44
    data_size_t          namelen;         /* length of dll file name */
45
    WCHAR               *filename;        /* dll file name */
46 47
};

48 49 50
struct process
{
    struct object        obj;             /* object header */
51
    struct list          entry;           /* entry in system-wide process list */
52
    struct process      *parent;          /* parent process */
53
    struct list          thread_list;     /* thread list */
54
    struct thread       *debugger;        /* thread debugging this process */
55
    struct handle_table *handles;         /* handle entries */
56
    struct fd           *msg_fd;          /* fd for sendmsg/recvmsg */
57 58
    process_id_t         id;              /* id of the process */
    process_id_t         group_id;        /* group id of the process */
59
    struct timeout_user *sigkill_timeout; /* timeout for final SIGKILL */
60
    enum cpu_type        cpu;             /* client CPU type */
61
    int                  unix_pid;        /* Unix pid for final SIGKILL */
62 63
    int                  exit_code;       /* process exit code */
    int                  running_threads; /* number of threads running in this process */
64 65
    timeout_t            start_time;      /* absolute time at process start */
    timeout_t            end_time;        /* absolute time at process end */
66
    affinity_t           affinity;        /* process affinity mask */
67 68
    int                  priority;        /* priority class */
    int                  suspend;         /* global process suspend count */
69 70
    unsigned int         is_system:1;     /* is it a system process? */
    unsigned int         debug_children:1;/* also debug all child processes */
71
    struct list          locks;           /* list of file locks owned by the process */
72
    struct list          classes;         /* window classes owned by the process */
73
    struct console_input*console;         /* console input */
74
    enum startup_state   startup_state;   /* startup state */
75
    struct startup_info *startup_info;    /* startup info while init is in progress */
76
    struct event        *idle_event;      /* event for input idle */
77
    obj_handle_t         winstation;      /* main handle to process window station */
78
    obj_handle_t         desktop;         /* handle to desktop to use for new threads */
79
    struct token        *token;           /* security token associated with this process */
80
    struct list          dlls;            /* list of loaded dlls */
81
    client_ptr_t         peb;             /* PEB address in client address space */
82
    client_ptr_t         ldt_copy;        /* pointer to LDT copy in client addr space */
83
    unsigned int         trace_data;      /* opaque data used by the process tracing mechanism */
84
};
85 86 87 88

struct process_snapshot
{
    struct process *process;  /* process ptr */
89
    int             count;    /* process refcount */
90 91
    int             threads;  /* number of threads */
    int             priority; /* priority class */
92
    int             handles;  /* number of handles */
93 94
};

95 96 97
#define CPU_FLAG(cpu) (1 << (cpu))
#define CPU_64BIT_MASK CPU_FLAG(CPU_x86_64)

98 99
/* process functions */

100 101 102
extern unsigned int alloc_ptid( void *ptr );
extern void free_ptid( unsigned int id );
extern void *get_ptid_entry( unsigned int id );
103
extern struct thread *create_process( int fd, struct thread *parent_thread, int inherit_all );
104
extern data_size_t init_process( struct thread *thread );
105
extern struct thread *get_process_first_thread( struct process *process );
106
extern struct process *get_process_from_id( process_id_t id );
107
extern struct process *get_process_from_handle( obj_handle_t handle, unsigned int access );
108
extern int process_set_debugger( struct process *process, struct thread *thread );
109
extern int debugger_detach( struct process* process, struct thread* debugger );
110
extern int set_process_debug_flag( struct process *process, int flag );
111

112 113 114 115
extern void add_process_thread( struct process *process,
                                struct thread *thread );
extern void remove_process_thread( struct process *process,
                                   struct thread *thread );
116 117
extern void suspend_process( struct process *process );
extern void resume_process( struct process *process );
118
extern void kill_process( struct process *process, int violent_death );
119
extern void kill_console_processes( struct thread *renderer, int exit_code );
120
extern void kill_debugged_processes( struct thread *debugger, int exit_code );
121
extern void break_process( struct process *process );
122
extern void detach_debugged_processes( struct thread *debugger );
123
extern struct process_snapshot *process_snap( int *count );
124
extern void enum_processes( int (*cb)(struct process*, void*), void *user);
125

126 127 128 129 130
/* console functions */
extern void inherit_console(struct thread *parent_thread, struct process *process, obj_handle_t hconin);
extern int free_console( struct process *process );
extern struct thread *console_get_renderer( struct console_input *console );

131 132 133
/* process tracing mechanism to use */
#ifdef __APPLE__
#define USE_MACH
134 135
#elif defined(__sun)
#define USE_PROCFS
136 137 138 139
#else
#define USE_PTRACE
#endif

140 141 142
extern void init_tracing_mechanism(void);
extern void init_process_tracing( struct process *process );
extern void finish_process_tracing( struct process *process );
143 144
extern int read_process_memory( struct process *process, client_ptr_t ptr, data_size_t size, char *dest );
extern int write_process_memory( struct process *process, client_ptr_t ptr, data_size_t size, const char *src );
145

146
static inline process_id_t get_process_id( struct process *process ) { return process->id; }
147

148
static inline int is_process_init_done( struct process *process )
149 150 151
{
    return process->startup_state == STARTUP_DONE;
}
152

153
static inline struct process_dll *get_process_exe_module( struct process *process )
154 155 156 157 158
{
    struct list *ptr = list_head( &process->dlls );
    return ptr ? LIST_ENTRY( ptr, struct process_dll, entry ) : NULL;
}

159
#endif  /* __WINE_SERVER_PROCESS_H */