4 * Copyright 1996 Alexandre Julliard
7 #ifndef __WINE_THREAD_H
8 #define __WINE_THREAD_H
13 #include "selectors.h" /* for SET_FS */
16 struct __EXCEPTION_FRAME;
18 /* Thread exception block */
21 struct __EXCEPTION_FRAME *except; /* 00 Head of exception handling chain */
22 void *stack_top; /* 04 Top of thread stack */
23 void *stack_low; /* 08 Stack low-water mark */
24 HTASK16 htask16; /* 0c Win16 task handle */
25 WORD stack_sel; /* 0e 16-bit stack selector */
26 DWORD selman_list; /* 10 Selector manager list */
27 DWORD user_ptr; /* 14 User pointer */
28 struct _TEB *self; /* 18 Pointer to this structure */
29 WORD flags; /* 1c Flags */
30 WORD mutex_count; /* 1e Win16 mutex count */
31 DWORD debug_context; /* 20 Debug context */
32 void *tid; /* 24 Thread id */
33 HQUEUE16 queue; /* 28 Message queue */
35 LPVOID *tls_ptr; /* 2c Pointer to TLS array */
36 struct _PDB *process; /* 30 owning process (used by NT3.51 applets)*/
37 int socket; /* 34 Socket for server communication */
38 DWORD exit_code; /* 38 Termination status */
39 WORD teb_sel; /* 3c Selector to TEB */
40 WORD emu_sel; /* 3e 80387 emulator selector */
41 void *buffer; /* 40 Buffer shared with server */
42 int buffer_size; /* 44 Size of server buffer */
43 void (*startup)(void); /* 48 Thread startup routine */
44 int thread_errno; /* 4c Per-thread errno (was: ring0_thread) */
45 int thread_h_errno; /* 50 Per-thread h_errno (was: ptr to tdbx structure) */
46 void *stack_base; /* 54 Base of the stack */
47 void *signal_stack; /* 58 Signal stack (was: exit_stack) */
48 void *emu_data; /* 5c Related to 80387 emulation */
49 DWORD last_error; /* 60 Last error code */
50 HANDLE event; /* 64 Thread event (was: debugger context block) */
51 DWORD debug_thread; /* 68 Thread debugging this one (?) */
52 void *pcontext; /* 6c Thread register context */
53 DWORD cur_stack; /* 70 Current stack (was: unknown) */
54 DWORD unknown3[2]; /* 74 Unknown */
55 WORD current_ss; /* 7c Another 16-bit stack selector */
57 void *ss_table; /* 80 Pointer to info about 16-bit stack */
58 WORD thunk_ss; /* 84 Yet another 16-bit stack selector */
60 LPVOID tls_array[64]; /* 88 Thread local storage */
61 DWORD delta_priority; /* 188 Priority delta */
62 DWORD unknown4[7]; /* 18c Unknown */
63 void *create_data; /* 1a8 Pointer to creation structure */
64 DWORD suspend_count; /* 1ac SuspendThread() counter */
65 void *entry_point; /* 1b0 Thread entry point (was: unknown) */
66 void *entry_arg; /* 1b4 Entry point arg (was: unknown) */
67 DWORD unknown5[4]; /* 1b8 Unknown */
68 DWORD sys_count[4]; /* 1c8 Syslevel mutex entry counters */
69 SYSLEVEL *sys_mutex[4]; /* 1d8 Syslevel mutex pointers */
70 DWORD unknown6[2]; /* 1e8 Unknown */
71 /* The following are Wine-specific fields */
72 struct _TEB *next; /* Global thread list */
73 DWORD cleanup; /* Cleanup service handle */
76 /* Thread exception flags */
77 #define TEBF_WIN32 0x0001
78 #define TEBF_TRAP 0x0002
80 /* The pseudo handle value returned by GetCurrentThread */
81 #define CURRENT_THREAD_PSEUDOHANDLE 0xfffffffe
83 /* The per-thread signal stack size */
84 #define SIGNAL_STACK_SIZE 16384
87 /* scheduler/thread.c */
88 extern TEB *THREAD_CreateInitialThread( struct _PDB *pdb, int server_fd );
89 extern TEB *THREAD_Create( struct _PDB *pdb, DWORD flags,
90 DWORD stack_size, BOOL alloc_stack16,
91 LPSECURITY_ATTRIBUTES sa, int *server_handle );
92 extern BOOL THREAD_IsWin16( TEB *thdb );
93 extern TEB *THREAD_IdToTEB( DWORD id );
95 /* scheduler/sysdeps.c */
96 extern int SYSDEPS_SpawnThread( TEB *teb );
97 extern void SYSDEPS_SetCurThread( TEB *teb );
98 extern void SYSDEPS_ExitThread(void);
100 #define SetLastError(err) ((void)(NtCurrentTeb()->last_error = (err)))
101 #define GetCurrentThreadId() ((DWORD)NtCurrentTeb()->tid)
103 #endif /* __WINE_THREAD_H */