Alexandre Julliard | 767e6f6 | 1998-08-09 12:47:43 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Wine server threads |
| 3 | * |
| 4 | * Copyright (C) 1998 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 | 767e6f6 | 1998-08-09 12:47:43 +0000 | [diff] [blame] | 19 | */ |
| 20 | |
| 21 | #ifndef __WINE_SERVER_THREAD_H |
| 22 | #define __WINE_SERVER_THREAD_H |
| 23 | |
Alexandre Julliard | 43c190e | 1999-05-15 10:48:19 +0000 | [diff] [blame] | 24 | #include "object.h" |
Alexandre Julliard | 767e6f6 | 1998-08-09 12:47:43 +0000 | [diff] [blame] | 25 | |
| 26 | /* thread structure */ |
| 27 | |
| 28 | struct process; |
Alexandre Julliard | 85ed45e | 1998-08-22 19:03:56 +0000 | [diff] [blame] | 29 | struct thread_wait; |
Alexandre Julliard | 62a8b43 | 1999-01-19 17:48:23 +0000 | [diff] [blame] | 30 | struct thread_apc; |
Alexandre Julliard | 57e1131 | 1999-05-16 16:59:38 +0000 | [diff] [blame] | 31 | struct debug_ctx; |
Alexandre Julliard | f6507ed | 2000-04-06 22:05:16 +0000 | [diff] [blame] | 32 | struct debug_event; |
Alexandre Julliard | c5e433a | 2000-05-30 19:48:18 +0000 | [diff] [blame] | 33 | struct msg_queue; |
Alexandre Julliard | 85ed45e | 1998-08-22 19:03:56 +0000 | [diff] [blame] | 34 | |
Alexandre Julliard | 0a70783 | 1999-11-08 05:31:47 +0000 | [diff] [blame] | 35 | enum run_state |
| 36 | { |
| 37 | RUNNING, /* running normally */ |
Alexandre Julliard | 0a70783 | 1999-11-08 05:31:47 +0000 | [diff] [blame] | 38 | TERMINATED /* terminated */ |
| 39 | }; |
| 40 | |
Alexandre Julliard | f524240 | 2001-02-28 21:45:23 +0000 | [diff] [blame] | 41 | /* descriptor for fds currently in flight from client to server */ |
| 42 | struct inflight_fd |
| 43 | { |
| 44 | int client; /* fd on the client side (or -1 if entry is free) */ |
| 45 | int server; /* fd on the server side */ |
| 46 | }; |
| 47 | #define MAX_INFLIGHT_FDS 16 /* max number of fds in flight per thread */ |
| 48 | |
Alexandre Julliard | 767e6f6 | 1998-08-09 12:47:43 +0000 | [diff] [blame] | 49 | struct thread |
| 50 | { |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 51 | struct object obj; /* object header */ |
Alexandre Julliard | 73209eb | 2005-02-25 19:33:35 +0000 | [diff] [blame] | 52 | struct list entry; /* entry in system-wide thread list */ |
Alexandre Julliard | 0502638 | 2005-03-01 10:56:18 +0000 | [diff] [blame] | 53 | struct list proc_entry; /* entry in per-process thread list */ |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 54 | struct process *process; |
Alexandre Julliard | 91befe1 | 2003-02-01 01:38:40 +0000 | [diff] [blame] | 55 | thread_id_t id; /* thread id */ |
Alexandre Julliard | 20894e2 | 2005-02-25 16:58:43 +0000 | [diff] [blame] | 56 | struct list mutex_list; /* list of currently owned mutexes */ |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 57 | struct debug_ctx *debug_ctx; /* debugger context if this thread is a debugger */ |
| 58 | struct debug_event *debug_event; /* debug event being sent to debugger */ |
Alexandre Julliard | 17de829 | 2006-04-19 19:45:39 +0200 | [diff] [blame] | 59 | int debug_break; /* debug breakpoint pending? */ |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 60 | struct msg_queue *queue; /* message queue */ |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 61 | struct thread_wait *wait; /* current wait condition if sleeping */ |
Alexandre Julliard | 81b6a1f | 2005-02-25 14:01:40 +0000 | [diff] [blame] | 62 | struct list system_apc; /* queue of system async procedure calls */ |
| 63 | struct list user_apc; /* queue of user async procedure calls */ |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 64 | struct inflight_fd inflight[MAX_INFLIGHT_FDS]; /* fds currently in flight */ |
| 65 | unsigned int error; /* current error code */ |
| 66 | union generic_request req; /* current request */ |
| 67 | void *req_data; /* variable-size data for request */ |
| 68 | unsigned int req_toread; /* amount of data still to read in request */ |
| 69 | void *reply_data; /* variable-size data for reply */ |
| 70 | unsigned int reply_size; /* size of reply data */ |
| 71 | unsigned int reply_towrite; /* amount of data still to write in reply */ |
Alexandre Julliard | e66207e | 2003-02-19 00:33:32 +0000 | [diff] [blame] | 72 | struct fd *request_fd; /* fd for receiving client requests */ |
| 73 | struct fd *reply_fd; /* fd to send a reply to a client */ |
| 74 | struct fd *wait_fd; /* fd to use to wake a sleeping client */ |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 75 | enum run_state state; /* running state */ |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 76 | int exit_code; /* thread exit code */ |
| 77 | int unix_pid; /* Unix pid of client */ |
Alexandre Julliard | a8497bd | 2003-03-22 21:00:09 +0000 | [diff] [blame] | 78 | int unix_tid; /* Unix tid of client */ |
Alexandre Julliard | 5316dd0 | 2009-04-08 19:38:02 +0200 | [diff] [blame] | 79 | context_t *context; /* current context if in an exception handler */ |
| 80 | context_t *suspend_context; /* current context if suspended */ |
Alexandre Julliard | fa86438 | 2008-12-30 23:02:33 +0100 | [diff] [blame] | 81 | client_ptr_t teb; /* TEB address (in client address space) */ |
Alexandre Julliard | 913e792 | 2009-01-19 14:15:51 +0100 | [diff] [blame] | 82 | affinity_t affinity; /* affinity mask */ |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 83 | int priority; /* priority level */ |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 84 | int suspend; /* suspend count */ |
Alexandre Julliard | 1bf96e0 | 2005-06-08 18:44:50 +0000 | [diff] [blame] | 85 | obj_handle_t desktop; /* desktop handle */ |
Alexandre Julliard | 92fec7b | 2005-06-28 19:37:52 +0000 | [diff] [blame] | 86 | int desktop_users; /* number of objects using the thread desktop */ |
Alexandre Julliard | aaf477f | 2007-04-17 20:08:59 +0200 | [diff] [blame] | 87 | timeout_t creation_time; /* Thread creation time */ |
| 88 | timeout_t exit_time; /* Thread exit time */ |
Mike McCormack | 36cd6f5 | 2003-07-24 00:07:00 +0000 | [diff] [blame] | 89 | struct token *token; /* security token associated with this thread */ |
Alexandre Julliard | 767e6f6 | 1998-08-09 12:47:43 +0000 | [diff] [blame] | 90 | }; |
| 91 | |
Alexandre Julliard | 07d8446 | 2000-04-16 19:45:05 +0000 | [diff] [blame] | 92 | struct thread_snapshot |
| 93 | { |
| 94 | struct thread *thread; /* thread ptr */ |
| 95 | int count; /* thread refcount */ |
| 96 | int priority; /* priority class */ |
| 97 | }; |
| 98 | |
Alexandre Julliard | 767e6f6 | 1998-08-09 12:47:43 +0000 | [diff] [blame] | 99 | extern struct thread *current; |
| 100 | |
| 101 | /* thread functions */ |
| 102 | |
Alexandre Julliard | 5b4f3e8 | 2000-05-01 16:24:22 +0000 | [diff] [blame] | 103 | extern struct thread *create_thread( int fd, struct process *process ); |
Alexandre Julliard | 54f2287 | 2002-10-03 19:54:57 +0000 | [diff] [blame] | 104 | extern struct thread *get_thread_from_id( thread_id_t id ); |
Alexandre Julliard | 5188574 | 2002-05-30 20:12:58 +0000 | [diff] [blame] | 105 | extern struct thread *get_thread_from_handle( obj_handle_t handle, unsigned int access ); |
Alexandre Julliard | 48b74b3 | 2006-12-29 16:53:33 +0100 | [diff] [blame] | 106 | extern struct thread *get_thread_from_tid( int tid ); |
Alexandre Julliard | 578c100 | 1999-11-14 21:23:21 +0000 | [diff] [blame] | 107 | extern struct thread *get_thread_from_pid( int pid ); |
Alexandre Julliard | d04ccb8 | 2003-03-04 22:18:43 +0000 | [diff] [blame] | 108 | extern void stop_thread( struct thread *thread ); |
Peter Hunnisett | a3c5ad4 | 2003-02-28 21:50:47 +0000 | [diff] [blame] | 109 | extern int wake_thread( struct thread *thread ); |
Alexandre Julliard | a8b8d9c | 1999-01-01 16:59:27 +0000 | [diff] [blame] | 110 | extern int add_queue( struct object *obj, struct wait_queue_entry *entry ); |
Alexandre Julliard | c6e45ed | 1998-12-27 08:35:39 +0000 | [diff] [blame] | 111 | extern void remove_queue( struct object *obj, struct wait_queue_entry *entry ); |
Alexandre Julliard | 12f29b5 | 2000-03-17 15:16:57 +0000 | [diff] [blame] | 112 | extern void kill_thread( struct thread *thread, int violent_death ); |
Alexandre Julliard | 17de829 | 2006-04-19 19:45:39 +0200 | [diff] [blame] | 113 | extern void break_thread( struct thread *thread ); |
Alexandre Julliard | 85ed45e | 1998-08-22 19:03:56 +0000 | [diff] [blame] | 114 | extern void wake_up( struct object *obj, int max ); |
Alexandre Julliard | 5c8421d | 2007-01-04 13:40:09 +0100 | [diff] [blame] | 115 | extern int thread_queue_apc( struct thread *thread, struct object *owner, const apc_call_t *call_data ); |
| 116 | extern void thread_cancel_apc( struct thread *thread, struct object *owner, enum apc_type type ); |
Alexandre Julliard | f524240 | 2001-02-28 21:45:23 +0000 | [diff] [blame] | 117 | extern int thread_add_inflight_fd( struct thread *thread, int client, int server ); |
| 118 | extern int thread_get_inflight_fd( struct thread *thread, int client ); |
Alexandre Julliard | 07d8446 | 2000-04-16 19:45:05 +0000 | [diff] [blame] | 119 | extern struct thread_snapshot *thread_snap( int *count ); |
Robert Shearman | d2ea92d | 2005-04-22 21:17:15 +0000 | [diff] [blame] | 120 | extern struct token *thread_get_impersonation_token( struct thread *thread ); |
Alexandre Julliard | 2f3fa85 | 2010-02-02 15:58:02 +0100 | [diff] [blame] | 121 | extern int set_thread_affinity( struct thread *thread, affinity_t affinity ); |
Alexandre Julliard | 767e6f6 | 1998-08-09 12:47:43 +0000 | [diff] [blame] | 122 | |
Alexandre Julliard | 578c100 | 1999-11-14 21:23:21 +0000 | [diff] [blame] | 123 | /* ptrace functions */ |
| 124 | |
Alexandre Julliard | 9037f4b | 2003-03-26 01:32:18 +0000 | [diff] [blame] | 125 | extern void sigchld_callback(void); |
Alexandre Julliard | 5316dd0 | 2009-04-08 19:38:02 +0200 | [diff] [blame] | 126 | extern void get_thread_context( struct thread *thread, context_t *context, unsigned int flags ); |
| 127 | extern void set_thread_context( struct thread *thread, const context_t *context, unsigned int flags ); |
Alexandre Julliard | 02a53c1 | 2003-02-25 04:17:22 +0000 | [diff] [blame] | 128 | extern int send_thread_signal( struct thread *thread, int sig ); |
Alexandre Julliard | cb70931 | 2006-04-07 19:52:12 +0200 | [diff] [blame] | 129 | extern void get_selector_entry( struct thread *thread, int entry, unsigned int *base, |
| 130 | unsigned int *limit, unsigned char *flags ); |
Alexandre Julliard | 578c100 | 1999-11-14 21:23:21 +0000 | [diff] [blame] | 131 | |
Alexandre Julliard | 908464d | 2000-11-01 03:11:12 +0000 | [diff] [blame] | 132 | extern unsigned int global_error; /* global error code for when no thread is current */ |
Alexandre Julliard | 578c100 | 1999-11-14 21:23:21 +0000 | [diff] [blame] | 133 | |
Alexandre Julliard | 908464d | 2000-11-01 03:11:12 +0000 | [diff] [blame] | 134 | static inline unsigned int get_error(void) { return current ? current->error : global_error; } |
| 135 | static inline void set_error( unsigned int err ) { global_error = err; if (current) current->error = err; } |
Alexandre Julliard | d5b4232 | 2003-12-10 01:12:18 +0000 | [diff] [blame] | 136 | static inline void clear_error(void) { set_error(0); } |
| 137 | static inline void set_win32_error( unsigned int err ) { set_error( 0xc0010000 | err ); } |
Alexandre Julliard | 767e6f6 | 1998-08-09 12:47:43 +0000 | [diff] [blame] | 138 | |
Alexandre Julliard | 91befe1 | 2003-02-01 01:38:40 +0000 | [diff] [blame] | 139 | static inline thread_id_t get_thread_id( struct thread *thread ) { return thread->id; } |
Alexandre Julliard | ff81d78 | 2000-03-08 12:01:30 +0000 | [diff] [blame] | 140 | |
Alexandre Julliard | 767e6f6 | 1998-08-09 12:47:43 +0000 | [diff] [blame] | 141 | #endif /* __WINE_SERVER_THREAD_H */ |