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 "ntdef.h" /* UNICODE_STRING */
25 #include "wine/windef16.h"
28 struct __EXCEPTION_FRAME;
29 struct _SECURITY_ATTRIBUTES;
31 struct server_buffer_info;
33 /* Thread exception block
37 d-- win95 debug version
41 !-- or -!- likely or observed collision
42 more problems (collected from mailing list):
43 psapi.dll 0x10/0x30 (expects nt fields)
45 PESHiELD 0x23/0x30 (win95)
50 struct __EXCEPTION_FRAME *except; /* 12- 00 Head of exception handling chain */
51 void *stack_top; /* 12- 04 Top of thread stack */
52 void *stack_low; /* 12- 08 Stack low-water mark */
53 HTASK16 htask16; /* 1-- 0c Win16 task handle */
54 WORD stack_sel; /* 1-- 0e 16-bit stack selector */
55 DWORD selman_list; /* 1-n 10 Selector manager list */
56 DWORD user_ptr; /* 12n 14 User pointer */
58 struct _TEB *self; /* 12- 18 Pointer to this structure */
59 WORD tibflags; /* 1!n 1c Flags (NT: EnvironmentPointer) */
60 WORD mutex_count; /* 1-n 1e Win16 mutex count */
61 void *pid; /* !2- 20 Process id (win95: debug context) */
62 void *tid; /* -2- 24 Thread id */
63 HQUEUE16 queue; /* 1!- 28 Message queue (NT: DWORD ActiveRpcHandle)*/
64 WORD pad1; /* --n 2a */
65 LPVOID *tls_ptr; /* 1-- 2c Pointer to TLS array */
66 struct _PDB *process; /* 12- 30 owning process (win95: PDB; nt: NTPEB !!) */
67 DWORD flags; /* 1-n 34 */
68 DWORD exit_code; /* 1-- 38 Termination status */
69 WORD teb_sel; /* 1-- 3c Selector to TEB */
70 WORD emu_sel; /* 1-n 3e 80387 emulator selector */
71 DWORD unknown1; /* --n 40 */
72 DWORD unknown2; /* --n 44 */
73 void (*startup)(void); /* --3 48 Thread startup routine */
74 int thread_errno; /* --3 4c Per-thread errno (was: ring0_thread) */
75 int thread_h_errno; /* --3 50 Per-thread h_errno (was: ptr to tdbx structure) */
76 void *stack_base; /* 1-- 54 Base of the stack */
77 void *signal_stack; /* --3 58 Signal stack (was: exit_stack) */
78 void *emu_data; /* --n 5c Related to 80387 emulation */
79 DWORD last_error; /* 1-- 60 Last error code */
80 HANDLE debug_cb; /* 1-n 64 Debugger context block */
81 DWORD debug_thread; /* 1-n 68 Thread debugging this one (?) */
82 void *pcontext; /* 1-n 6c Thread register context */
83 DWORD cur_stack; /* --3 70 Current stack (was: unknown) */
84 DWORD ThunkConnect; /* 1-n 74 */
85 DWORD NegStackBase; /* 1-n 78 */
86 WORD current_ss; /* 1-n 7c Another 16-bit stack selector */
87 WORD pad2; /* --n 7e */
88 void *ss_table; /* --n 80 Pointer to info about 16-bit stack */
89 WORD thunk_ss; /* --n 84 Yet another 16-bit stack selector */
90 WORD pad3; /* --n 86 */
91 DWORD pad4[15]; /* --n 88 */
92 ULONG CurrentLocale; /* -2- C4 */
93 DWORD pad5[48]; /* --n C8 */
94 DWORD delta_priority; /* 1-n 188 Priority delta */
95 DWORD unknown4[7]; /* d-n 18c Unknown */
96 void *create_data; /* d-n 1a8 Pointer to creation structure */
97 DWORD suspend_count; /* d-n 1ac SuspendThread() counter */
98 void *entry_point; /* --3 1b0 Thread entry point (was: unknown) */
99 void *entry_arg; /* --3 1b4 Entry point arg (was: unknown) */
100 DWORD unknown5[4]; /* --n 1b8 Unknown */
101 DWORD sys_count[4]; /* --3 1c8 Syslevel mutex entry counters */
102 struct tagSYSLEVEL *sys_mutex[4]; /* --3 1d8 Syslevel mutex pointers */
103 DWORD unknown6[5]; /* --n 1e8 Unknown */
105 /* The following are Wine-specific fields (NT: GDI stuff) */
106 DWORD unused[4]; /* --3 1fc Was server buffer */
107 int request_fd; /* --3 20c fd for sending server requests */
108 int reply_fd; /* --3 210 fd for receiving server replies */
109 int wait_fd[2]; /* --3 214 fd for sleeping server requests */
110 void *debug_info; /* --3 21c Info for debugstr functions */
111 void *pthread_data; /* --3 220 Data for pthread emulation */
112 struct async_private *pending_list; /* --3 224 list of pending async operations */
113 void *driver_data; /* --3 228 Graphics driver private data */
114 DWORD alarms; /* --3 22c Data for vm86 mode */
115 DWORD vm86_pending; /* --3 230 Data for vm86 mode */
116 void *vm86_ptr; /* --3 234 Data for vm86 mode */
117 /* here is plenty space for wine specific fields (don't forget to change pad6!!) */
119 /* the following are nt specific fields */
120 DWORD pad6[624]; /* --n 238 */
121 UNICODE_STRING StaticUnicodeString; /* -2- bf8 used by advapi32 */
122 USHORT StaticUnicodeBuffer[261]; /* -2- c00 used by advapi32 */
123 DWORD pad7; /* --n e0c */
124 LPVOID tls_array[64]; /* -2- e10 Thread local storage */
125 DWORD pad8[3]; /* --n f10 */
126 PVOID ReservedForNtRpc; /* -2- f1c used by rpcrt4 */
127 DWORD pad9[24]; /* --n f20 */
128 PVOID ErrorInfo; /* -2- f80 used by ole32 (IErrorInfo*) */
131 /* Thread exception flags */
132 #define TEBF_WIN32 0x0001
133 #define TEBF_TRAP 0x0002
135 /* The per-thread signal stack size */
136 #define SIGNAL_STACK_SIZE 16384
139 /* scheduler/thread.c */
140 extern void THREAD_Init(void);
141 extern TEB *THREAD_InitStack( TEB *teb, DWORD stack_size );
142 extern TEB *THREAD_IdToTEB( DWORD id );
144 /* scheduler/sysdeps.c */
145 extern int SYSDEPS_SpawnThread( TEB *teb );
146 extern void SYSDEPS_SetCurThread( TEB *teb );
147 extern void SYSDEPS_ExitThread( int status ) WINE_NORETURN;
148 extern void SYSDEPS_AbortThread( int status ) WINE_NORETURN;
149 extern void SYSDEPS_SwitchToThreadStack( void (*func)(void) ) WINE_NORETURN;
151 /* signal handling */
152 extern BOOL SIGNAL_Init(void);
153 extern void SIGNAL_Reset(void);
155 #endif /* __WINE_THREAD_H */