blob: 9939f322c83f1847193e9daae0680dca4e8a144e [file] [log] [blame]
Alexandre Julliard9ea19e51997-01-01 17:29:55 +00001/*
2 * Thread definitions
3 *
4 * Copyright 1996 Alexandre Julliard
5 */
6
7#ifndef __WINE_THREAD_H
8#define __WINE_THREAD_H
9
Alexandre Julliardd30dfd21998-09-27 18:28:36 +000010#include "config.h"
Patrik Stridvall6cc47d42000-03-08 18:26:56 +000011
Juergen Schmied74341022000-01-15 22:22:27 +000012#include "ntdef.h" /* UNICODE_STRING */
Alexandre Julliard9ea19e51997-01-01 17:29:55 +000013
Alexandre Julliarda3960291999-02-26 11:11:13 +000014struct _PDB;
Alexandre Julliarddd93d251999-05-09 16:12:19 +000015struct __EXCEPTION_FRAME;
Patrik Stridvall6cc47d42000-03-08 18:26:56 +000016struct _SECURITY_ATTRIBUTES;
17struct tagSYSLEVEL;
Alexandre Julliarda11d7b11998-03-01 20:05:02 +000018
Juergen Schmied74341022000-01-15 22:22:27 +000019/* Thread exception block
20
21 flags in the comment:
22 1-- win95 field
23 d-- win95 debug version
24 -2- nt field
25 --3 wine special
26 --n wine unused
27 !-- or -!- likely or observed collision
28 more problems (collected from mailing list):
29 psapi.dll 0x10/0x30 (expects nt fields)
30 ie4 0x40
31 PESHiELD 0x23/0x30 (win95)
32*/
Alexandre Julliard9ea19e51997-01-01 17:29:55 +000033typedef struct _TEB
34{
Juergen Schmied74341022000-01-15 22:22:27 +000035/* start of NT_TIB */
36 struct __EXCEPTION_FRAME *except; /* 12- 00 Head of exception handling chain */
37 void *stack_top; /* 12- 04 Top of thread stack */
38 void *stack_low; /* 12- 08 Stack low-water mark */
39 HTASK16 htask16; /* 1-- 0c Win16 task handle */
40 WORD stack_sel; /* 1-- 0e 16-bit stack selector */
41 DWORD selman_list; /* 1-n 10 Selector manager list */
42 DWORD user_ptr; /* 12n 14 User pointer */
43/* end of NT_TIB */
44 struct _TEB *self; /* 12- 18 Pointer to this structure */
45 WORD tibflags; /* 1!n 1c Flags (NT: EnvironmentPointer) */
46 WORD mutex_count; /* 1-n 1e Win16 mutex count */
Alexandre Julliard114830e2000-04-11 20:01:59 +000047 void *pid; /* !2- 20 Process id (win95: debug context) */
Juergen Schmied74341022000-01-15 22:22:27 +000048 void *tid; /* -2- 24 Thread id */
49 HQUEUE16 queue; /* 1!- 28 Message queue (NT: DWORD ActiveRpcHandle)*/
50 WORD pad1; /* --n 2a */
51 LPVOID *tls_ptr; /* 1-- 2c Pointer to TLS array */
52 struct _PDB *process; /* 12- 30 owning process (win95: PDB; nt: NTPEB !!) */
53 DWORD flags; /* 1-n 34 */
54 DWORD exit_code; /* 1-- 38 Termination status */
55 WORD teb_sel; /* 1-- 3c Selector to TEB */
56 WORD emu_sel; /* 1-n 3e 80387 emulator selector */
57 DWORD unknown1; /* --n 40 */
58 DWORD unknown2; /* --n 44 */
59 void (*startup)(void); /* --3 48 Thread startup routine */
60 int thread_errno; /* --3 4c Per-thread errno (was: ring0_thread) */
61 int thread_h_errno; /* --3 50 Per-thread h_errno (was: ptr to tdbx structure) */
62 void *stack_base; /* 1-- 54 Base of the stack */
63 void *signal_stack; /* --3 58 Signal stack (was: exit_stack) */
64 void *emu_data; /* --n 5c Related to 80387 emulation */
65 DWORD last_error; /* 1-- 60 Last error code */
Ulrich Weigand7d43bce2000-01-30 21:16:45 +000066 HANDLE debug_cb; /* 1-n 64 Debugger context block */
Juergen Schmied74341022000-01-15 22:22:27 +000067 DWORD debug_thread; /* 1-n 68 Thread debugging this one (?) */
68 void *pcontext; /* 1-n 6c Thread register context */
69 DWORD cur_stack; /* --3 70 Current stack (was: unknown) */
70 DWORD ThunkConnect; /* 1-n 74 */
71 DWORD NegStackBase; /* 1-n 78 */
72 WORD current_ss; /* 1-n 7c Another 16-bit stack selector */
73 WORD pad2; /* --n 7e */
74 void *ss_table; /* --n 80 Pointer to info about 16-bit stack */
75 WORD thunk_ss; /* --n 84 Yet another 16-bit stack selector */
76 WORD pad3; /* --n 86 */
77 DWORD pad4[15]; /* --n 88 */
78 ULONG CurrentLocale; /* -2n C4 */
79 DWORD pad5[48]; /* --n C8 */
80 DWORD delta_priority; /* 1-n 188 Priority delta */
81 DWORD unknown4[7]; /* d-n 18c Unknown */
82 void *create_data; /* d-n 1a8 Pointer to creation structure */
83 DWORD suspend_count; /* d-n 1ac SuspendThread() counter */
84 void *entry_point; /* --3 1b0 Thread entry point (was: unknown) */
85 void *entry_arg; /* --3 1b4 Entry point arg (was: unknown) */
86 DWORD unknown5[4]; /* --n 1b8 Unknown */
87 DWORD sys_count[4]; /* --3 1c8 Syslevel mutex entry counters */
Patrik Stridvall6cc47d42000-03-08 18:26:56 +000088 struct tagSYSLEVEL *sys_mutex[4]; /* --3 1d8 Syslevel mutex pointers */
Juergen Schmied74341022000-01-15 22:22:27 +000089 DWORD unknown6[5]; /* --n 1e8 Unknown */
90
91 /* The following are Wine-specific fields (NT: GDI stuff) */
92 struct _TEB *next; /* --3 1fc Global thread list */
93 DWORD cleanup; /* --3 200 Cleanup service handle */
94 int socket; /* --3 204 Socket for server communication */
95 void *buffer; /* --3 208 Buffer shared with server */
96 int buffer_size; /* --3 20c Size of server buffer */
Alexandre Julliard8bc1d832000-01-29 19:46:50 +000097 void *debug_info; /* --3 210 Info for debugstr functions */
Ove Kaavenf19f07d2000-04-14 14:47:02 +000098 void *pthread_data; /* --3 214 Data for pthread emulation */
Juergen Schmied74341022000-01-15 22:22:27 +000099 /* here is plenty space for wine specific fields (don't forget to change pad6!!) */
100
101 /* the following are nt specific fields */
Ove Kaavenf19f07d2000-04-14 14:47:02 +0000102 DWORD pad6[632]; /* --n 218 */
Juergen Schmied74341022000-01-15 22:22:27 +0000103 UNICODE_STRING StaticUnicodeString; /* -2- bf8 used by advapi32 */
104 USHORT StaticUnicodeBuffer[261]; /* -2- c00 used by advapi32 */
105 DWORD pad7; /* --n e0c */
106 LPVOID tls_array[64]; /* -2- e10 Thread local storage */
107 DWORD pad8[3]; /* --n f10 */
108 PVOID ReservedForNtRpc; /* -2- f1c used by rpcrt4 */
109 DWORD pad9[24]; /* --n f20 */
110 PVOID ReservedForOle; /* -2- f80 used by ole32 */
Alexandre Julliard9ea19e51997-01-01 17:29:55 +0000111} TEB;
112
Ulrich Weigandca1c7471998-11-24 20:47:17 +0000113/* Thread exception flags */
114#define TEBF_WIN32 0x0001
115#define TEBF_TRAP 0x0002
116
Alexandre Julliardd131a171999-05-23 20:02:04 +0000117/* The per-thread signal stack size */
118#define SIGNAL_STACK_SIZE 16384
119
Alexandre Julliard02e90081998-01-04 17:49:09 +0000120
121/* scheduler/thread.c */
Alexandre Julliard8c21dfc2000-05-01 21:21:31 +0000122extern void THREAD_Init(void);
Alexandre Julliard5b4f3e82000-05-01 16:24:22 +0000123extern TEB *THREAD_Create( struct _PDB *pdb, int fd, DWORD stack_size, BOOL alloc_stack16 );
Alexandre Julliard8c21dfc2000-05-01 21:21:31 +0000124extern TEB *THREAD_InitStack( TEB *teb, DWORD stack_size, BOOL alloc_stack16 );
Alexandre Julliard0a860a01999-06-22 11:43:42 +0000125extern BOOL THREAD_IsWin16( TEB *thdb );
126extern TEB *THREAD_IdToTEB( DWORD id );
Alexandre Julliard02e90081998-01-04 17:49:09 +0000127
Alexandre Julliard0623a6f1998-01-18 18:01:49 +0000128/* scheduler/sysdeps.c */
Alexandre Julliard0a860a01999-06-22 11:43:42 +0000129extern int SYSDEPS_SpawnThread( TEB *teb );
130extern void SYSDEPS_SetCurThread( TEB *teb );
Alexandre Julliard12f29b52000-03-17 15:16:57 +0000131extern void SYSDEPS_ExitThread( int status ) WINE_NORETURN;
Alexandre Julliard0623a6f1998-01-18 18:01:49 +0000132
Alexandre Julliard9ea19e51997-01-01 17:29:55 +0000133#endif /* __WINE_THREAD_H */