Tweak 'Will there be a Windows version of Wine?':
[wine.git] / include / thread.h
blob79665cb3af6f17bbe1fe6b736e83e5a41174ed72
1 /*
2 * Thread definitions
4 * Copyright 1996 Alexandre Julliard
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.
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.
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
21 #ifndef __WINE_THREAD_H
22 #define __WINE_THREAD_H
24 #include "winternl.h"
25 #include "wine/windef16.h"
27 struct __EXCEPTION_FRAME;
28 struct _SECURITY_ATTRIBUTES;
29 struct tagSYSLEVEL;
30 struct server_buffer_info;
31 struct fiber_data;
33 struct debug_info
35 char *str_pos; /* current position in strings buffer */
36 char *out_pos; /* current position in output buffer */
37 char strings[1024]; /* buffer for temporary strings */
38 char output[1024]; /* current output line */
41 /* Thread exception block
43 flags in the comment:
44 1-- win95 field
45 d-- win95 debug version
46 -2- nt field
47 --3 wine special
48 --n wine unused
49 !-- or -!- likely or observed collision
50 more problems (collected from mailing list):
51 psapi.dll 0x10/0x30 (expects nt fields)
52 ie4 0x40
53 PESHiELD 0x23/0x30 (win95)
55 typedef struct _TEB
57 /* start of NT_TIB */
58 struct __EXCEPTION_FRAME *except; /* 12- 00 Head of exception handling chain */
59 void *stack_top; /* 12- 04 Top of thread stack */
60 void *stack_low; /* 12- 08 Stack low-water mark */
61 HTASK16 htask16; /* 1-- 0c Win16 task handle */
62 WORD stack_sel; /* 1-- 0e 16-bit stack selector */
63 struct fiber_data *fiber; /* -2- 10 Current fiber data (Win95: selector manager list) */
64 DWORD user_ptr; /* 12n 14 User pointer */
65 /* end of NT_TIB */
66 struct _TEB *self; /* 12- 18 Pointer to this structure */
67 WORD tibflags; /* 1!n 1c Flags (NT: EnvironmentPointer) */
68 WORD mutex_count; /* 1-n 1e Win16 mutex count */
69 DWORD pid; /* !2- 20 Process id (win95: debug context) */
70 DWORD tid; /* -2- 24 Thread id */
71 HQUEUE16 queue; /* 1!- 28 Message queue (NT: DWORD ActiveRpcHandle)*/
72 WORD pad1; /* --n 2a */
73 LPVOID *tls_ptr; /* 1-- 2c Pointer to TLS array */
74 PEB *Peb; /* 12- 30 owning process PEB */
75 DWORD flags; /* 1-n 34 */
76 DWORD exit_code; /* 1-- 38 Termination status */
77 WORD teb_sel; /* 1-- 3c Selector to TEB */
78 WORD emu_sel; /* 1-n 3e 80387 emulator selector */
79 DWORD unknown1; /* --n 40 */
80 DWORD unknown2; /* --n 44 */
81 DWORD unknown3; /* --n 48 */
82 int thread_errno; /* --3 4c Per-thread errno (was: ring0_thread) */
83 int thread_h_errno; /* --3 50 Per-thread h_errno (was: ptr to tdbx structure) */
84 void *signal_stack; /* --3 54 Signal stack (was: stack_base) */
85 void *exit_stack; /* 1-n 58 Exit stack */
86 void *emu_data; /* --n 5c Related to 80387 emulation */
87 DWORD last_error; /* 1-- 60 Last error code */
88 HANDLE debug_cb; /* 1-n 64 Debugger context block */
89 DWORD debug_thread; /* 1-n 68 Thread debugging this one (?) */
90 void *pcontext; /* 1-n 6c Thread register context */
91 DWORD cur_stack; /* --3 70 Current stack (was: unknown) */
92 DWORD ThunkConnect; /* 1-n 74 */
93 DWORD NegStackBase; /* 1-n 78 */
94 WORD current_ss; /* 1-n 7c Another 16-bit stack selector */
95 WORD pad2; /* --n 7e */
96 void *ss_table; /* --n 80 Pointer to info about 16-bit stack */
97 WORD thunk_ss; /* --n 84 Yet another 16-bit stack selector */
98 WORD pad3; /* --n 86 */
99 DWORD pad4[15]; /* --n 88 */
100 ULONG CurrentLocale; /* -2- C4 */
101 DWORD pad5[48]; /* --n C8 */
102 DWORD delta_priority; /* 1-n 188 Priority delta */
103 DWORD unknown4[7]; /* d-n 18c Unknown */
104 void *create_data; /* d-n 1a8 Pointer to creation structure */
105 DWORD suspend_count; /* d-n 1ac SuspendThread() counter */
106 void *entry_point; /* --3 1b0 Thread entry point (was: unknown) */
107 void *entry_arg; /* --3 1b4 Entry point arg (was: unknown) */
108 DWORD unknown5[4]; /* --n 1b8 Unknown */
109 DWORD sys_count[4]; /* --3 1c8 Syslevel mutex entry counters */
110 struct tagSYSLEVEL *sys_mutex[4]; /* --3 1d8 Syslevel mutex pointers */
111 DWORD unknown6[5]; /* --n 1e8 Unknown */
113 /* The following are Wine-specific fields (NT: GDI stuff) */
114 UINT code_page; /* --3 1fc Thread code page */
115 DWORD unused[2]; /* --3 200 Was server buffer */
116 DWORD gs_sel; /* --3 208 %gs selector for this thread */
117 int request_fd; /* --3 20c fd for sending server requests */
118 int reply_fd; /* --3 210 fd for receiving server replies */
119 int wait_fd[2]; /* --3 214 fd for sleeping server requests */
120 struct debug_info *debug_info; /* --3 21c Info for debugstr functions */
121 void *pthread_data; /* --3 220 Data for pthread emulation */
122 struct async_private *pending_list; /* --3 224 list of pending async operations */
123 void *driver_data; /* --3 228 Graphics driver private data */
124 DWORD dpmi_vif; /* --3 22c Protected mode virtual interrupt flag */
125 DWORD vm86_pending; /* --3 230 Data for vm86 mode */
126 void *vm86_ptr; /* --3 234 Data for vm86 mode */
127 /* here is plenty space for wine specific fields (don't forget to change pad6!!) */
129 /* the following are nt specific fields */
130 DWORD pad6[624]; /* --n 238 */
131 UNICODE_STRING StaticUnicodeString; /* -2- bf8 used by advapi32 */
132 USHORT StaticUnicodeBuffer[261]; /* -2- c00 used by advapi32 */
133 void *stack_base; /* -2- e0c Base of the stack */
134 LPVOID tls_array[64]; /* -2- e10 Thread local storage */
135 DWORD pad8[3]; /* --n f10 */
136 PVOID ReservedForNtRpc; /* -2- f1c used by rpcrt4 */
137 DWORD pad9[24]; /* --n f20 */
138 PVOID ErrorInfo; /* -2- f80 used by ole32 (IErrorInfo*) */
139 } TEB;
141 /* Thread exception flags */
142 #define TEBF_WIN32 0x0001
143 #define TEBF_TRAP 0x0002
145 /* The per-thread signal stack size */
146 #define SIGNAL_STACK_SIZE 0x100000 /* 1Mb FIXME: should be much smaller than that */
149 /* scheduler/thread.c */
150 extern void THREAD_Init(void);
151 extern TEB *THREAD_InitStack( TEB *teb, DWORD stack_size );
152 extern TEB *THREAD_IdToTEB( DWORD id );
154 /* scheduler/sysdeps.c */
155 extern int SYSDEPS_SpawnThread( void (*func)(TEB *), TEB *teb );
156 extern void SYSDEPS_SetCurThread( TEB *teb );
157 extern int SYSDEPS_GetUnixTid(void);
158 extern void DECLSPEC_NORETURN SYSDEPS_ExitThread( int status );
159 extern void DECLSPEC_NORETURN SYSDEPS_AbortThread( int status );
160 extern void DECLSPEC_NORETURN SYSDEPS_SwitchToThreadStack( void (*func)(void *), void *arg );
162 /* signal handling */
163 extern BOOL SIGNAL_Init(void);
164 extern void SIGNAL_Block(void);
165 extern void SIGNAL_Unblock(void);
166 extern void SIGNAL_Reset(void);
168 #endif /* __WINE_THREAD_H */