Better implementation of inline functions SetLastError and
[wine.git] / include / thread.h
blob882b1e1df641b443a8f7ae7ee5929ab16fc1c524
1 /*
2 * Thread definitions
4 * Copyright 1996 Alexandre Julliard
5 */
7 #ifndef __WINE_THREAD_H
8 #define __WINE_THREAD_H
10 #include "config.h"
11 #include "winbase.h"
12 #include "syslevel.h"
13 #include "ntdef.h" /* UNICODE_STRING */
15 struct _PDB;
16 struct __EXCEPTION_FRAME;
18 /* Thread exception block
20 flags in the comment:
21 1-- win95 field
22 d-- win95 debug version
23 -2- nt field
24 --3 wine special
25 --n wine unused
26 !-- or -!- likely or observed collision
27 more problems (collected from mailing list):
28 psapi.dll 0x10/0x30 (expects nt fields)
29 ie4 0x40
30 PESHiELD 0x23/0x30 (win95)
32 typedef struct _TEB
34 /* start of NT_TIB */
35 struct __EXCEPTION_FRAME *except; /* 12- 00 Head of exception handling chain */
36 void *stack_top; /* 12- 04 Top of thread stack */
37 void *stack_low; /* 12- 08 Stack low-water mark */
38 HTASK16 htask16; /* 1-- 0c Win16 task handle */
39 WORD stack_sel; /* 1-- 0e 16-bit stack selector */
40 DWORD selman_list; /* 1-n 10 Selector manager list */
41 DWORD user_ptr; /* 12n 14 User pointer */
42 /* end of NT_TIB */
43 struct _TEB *self; /* 12- 18 Pointer to this structure */
44 WORD tibflags; /* 1!n 1c Flags (NT: EnvironmentPointer) */
45 WORD mutex_count; /* 1-n 1e Win16 mutex count */
46 DWORD debug_context; /* 1!n 20 Debug context (NT: PVOID UniqueProcess) */
47 void *tid; /* -2- 24 Thread id */
48 HQUEUE16 queue; /* 1!- 28 Message queue (NT: DWORD ActiveRpcHandle)*/
49 WORD pad1; /* --n 2a */
50 LPVOID *tls_ptr; /* 1-- 2c Pointer to TLS array */
51 struct _PDB *process; /* 12- 30 owning process (win95: PDB; nt: NTPEB !!) */
52 DWORD flags; /* 1-n 34 */
53 DWORD exit_code; /* 1-- 38 Termination status */
54 WORD teb_sel; /* 1-- 3c Selector to TEB */
55 WORD emu_sel; /* 1-n 3e 80387 emulator selector */
56 DWORD unknown1; /* --n 40 */
57 DWORD unknown2; /* --n 44 */
58 void (*startup)(void); /* --3 48 Thread startup routine */
59 int thread_errno; /* --3 4c Per-thread errno (was: ring0_thread) */
60 int thread_h_errno; /* --3 50 Per-thread h_errno (was: ptr to tdbx structure) */
61 void *stack_base; /* 1-- 54 Base of the stack */
62 void *signal_stack; /* --3 58 Signal stack (was: exit_stack) */
63 void *emu_data; /* --n 5c Related to 80387 emulation */
64 DWORD last_error; /* 1-- 60 Last error code */
65 HANDLE debug_cb; /* 1-n 64 Debugger context block */
66 DWORD debug_thread; /* 1-n 68 Thread debugging this one (?) */
67 void *pcontext; /* 1-n 6c Thread register context */
68 DWORD cur_stack; /* --3 70 Current stack (was: unknown) */
69 DWORD ThunkConnect; /* 1-n 74 */
70 DWORD NegStackBase; /* 1-n 78 */
71 WORD current_ss; /* 1-n 7c Another 16-bit stack selector */
72 WORD pad2; /* --n 7e */
73 void *ss_table; /* --n 80 Pointer to info about 16-bit stack */
74 WORD thunk_ss; /* --n 84 Yet another 16-bit stack selector */
75 WORD pad3; /* --n 86 */
76 DWORD pad4[15]; /* --n 88 */
77 ULONG CurrentLocale; /* -2n C4 */
78 DWORD pad5[48]; /* --n C8 */
79 DWORD delta_priority; /* 1-n 188 Priority delta */
80 DWORD unknown4[7]; /* d-n 18c Unknown */
81 void *create_data; /* d-n 1a8 Pointer to creation structure */
82 DWORD suspend_count; /* d-n 1ac SuspendThread() counter */
83 void *entry_point; /* --3 1b0 Thread entry point (was: unknown) */
84 void *entry_arg; /* --3 1b4 Entry point arg (was: unknown) */
85 DWORD unknown5[4]; /* --n 1b8 Unknown */
86 DWORD sys_count[4]; /* --3 1c8 Syslevel mutex entry counters */
87 SYSLEVEL *sys_mutex[4]; /* --3 1d8 Syslevel mutex pointers */
88 DWORD unknown6[5]; /* --n 1e8 Unknown */
90 /* The following are Wine-specific fields (NT: GDI stuff) */
91 struct _TEB *next; /* --3 1fc Global thread list */
92 DWORD cleanup; /* --3 200 Cleanup service handle */
93 int socket; /* --3 204 Socket for server communication */
94 void *buffer; /* --3 208 Buffer shared with server */
95 int buffer_size; /* --3 20c Size of server buffer */
96 void *debug_info; /* --3 210 Info for debugstr functions */
97 /* here is plenty space for wine specific fields (don't forget to change pad6!!) */
99 /* the following are nt specific fields */
100 DWORD pad6[633]; /* --n 214 */
101 UNICODE_STRING StaticUnicodeString; /* -2- bf8 used by advapi32 */
102 USHORT StaticUnicodeBuffer[261]; /* -2- c00 used by advapi32 */
103 DWORD pad7; /* --n e0c */
104 LPVOID tls_array[64]; /* -2- e10 Thread local storage */
105 DWORD pad8[3]; /* --n f10 */
106 PVOID ReservedForNtRpc; /* -2- f1c used by rpcrt4 */
107 DWORD pad9[24]; /* --n f20 */
108 PVOID ReservedForOle; /* -2- f80 used by ole32 */
109 } TEB;
111 /* Thread exception flags */
112 #define TEBF_WIN32 0x0001
113 #define TEBF_TRAP 0x0002
115 /* The pseudo handle value returned by GetCurrentThread */
116 #define CURRENT_THREAD_PSEUDOHANDLE 0xfffffffe
118 /* The per-thread signal stack size */
119 #define SIGNAL_STACK_SIZE 16384
122 /* scheduler/thread.c */
123 extern TEB *THREAD_CreateInitialThread( struct _PDB *pdb, int server_fd );
124 extern TEB *THREAD_Create( struct _PDB *pdb, int fd, DWORD flags,
125 DWORD stack_size, BOOL alloc_stack16,
126 LPSECURITY_ATTRIBUTES sa, int *server_handle );
127 extern BOOL THREAD_IsWin16( TEB *thdb );
128 extern TEB *THREAD_IdToTEB( DWORD id );
130 /* scheduler/sysdeps.c */
131 extern int SYSDEPS_SpawnThread( TEB *teb );
132 extern void SYSDEPS_SetCurThread( TEB *teb );
133 extern void SYSDEPS_ExitThread(void);
135 #endif /* __WINE_THREAD_H */