4 * Copyright 1996 Alexandre Julliard
7 #ifndef __WINE_THREAD_H
8 #define __WINE_THREAD_H
13 #include "selectors.h" /* for SET_FS */
17 /* Thread exception block */
20 void *except; /* 00 Head of exception handling chain */
21 void *stack_top; /* 04 Top of thread stack */
22 void *stack_low; /* 08 Stack low-water mark */
23 HTASK16 htask16; /* 0c Win16 task handle */
24 WORD stack_sel; /* 0e 16-bit stack selector */
25 DWORD selman_list; /* 10 Selector manager list */
26 DWORD user_ptr; /* 14 User pointer */
27 struct _TEB *self; /* 18 Pointer to this structure */
28 WORD flags; /* 1c Flags */
29 WORD mutex_count; /* 1e Win16 mutex count */
30 DWORD debug_context; /* 20 Debug context */
31 DWORD *ppriority; /* 24 Pointer to current priority */
32 HQUEUE16 queue; /* 28 Message queue */
34 LPVOID *tls_ptr; /* 2c Pointer to TLS array */
35 struct _PDB32 *process; /* 30 owning process (used by NT3.51 applets)*/
38 /* Event waiting structure */
41 DWORD count; /* Count of valid objects */
42 DWORD signaled; /* Index of signaled object (or WAIT_FAILED)*/
43 BOOL32 wait_all; /* Wait for all objects flag */
44 K32OBJ *objs[MAXIMUM_WAIT_OBJECTS]; /* Object pointers */
50 K32OBJ header; /* 00 Kernel object header */
51 struct _PDB32 *process; /* 08 Process owning this thread */
52 K32OBJ *event; /* 0c Thread event */
53 TEB teb; /* 10 Thread exception block */
54 DWORD flags; /* 44 Flags */
55 DWORD exit_code; /* 48 Termination status */
56 WORD teb_sel; /* 4c Selector to TEB */
57 WORD emu_sel; /* 4e 80387 emulator selector */
58 int thread_errno; /* 50 Per-thread errno (was: unknown) */
59 WAIT_STRUCT *wait_list; /* 54 Event waiting list */
60 int thread_h_errno; /* 50 Per-thread h_errno (was: unknown) */
61 void *ring0_thread; /* 5c Pointer to ring 0 thread */
62 void *ptdbx; /* 60 Pointer to TDBX structure */
63 void *stack_base; /* 64 Base of the stack */
64 void *exit_stack; /* 68 Stack pointer on thread exit */
65 void *emu_data; /* 6c Related to 80387 emulation */
66 DWORD last_error; /* 70 Last error code */
67 void *debugger_CB; /* 74 Debugger context block */
68 DWORD debug_thread; /* 78 Thread debugging this one (?) */
69 void *pcontext; /* 7c Thread register context */
70 DWORD cur_stack; /* 80 Current stack (was: unknown) */
71 DWORD unknown3[2]; /* 84 Unknown */
72 WORD current_ss; /* 8c Another 16-bit stack selector */
74 void *ss_table; /* 90 Pointer to info about 16-bit stack */
75 WORD thunk_ss; /* 94 Yet another 16-bit stack selector */
77 LPVOID tls_array[64]; /* 98 Thread local storage */
78 DWORD delta_priority; /* 198 Priority delta */
79 DWORD unknown4[7]; /* 19c Unknown */
80 void *create_data; /* 1b8 Pointer to creation structure */
81 DWORD suspend_count; /* 1bc SuspendThread() counter */
82 void *entry_point; /* 1c0 Thread entry point (was: unknown) */
83 void *entry_arg; /* 1c4 Entry point arg (was: unknown) */
84 int unix_pid; /* 1c8 Unix thread pid (was: unknown) */
85 DWORD unknown5[6]; /* 1cc Unknown */
86 K32OBJ *crit_section; /* 1e4 Some critical section */
87 K32OBJ *win16_mutex; /* 1e8 Pointer to Win16 mutex */
88 K32OBJ *win32_mutex; /* 1ec Pointer to KERNEL32 mutex */
89 K32OBJ *crit_section2; /* 1f0 Another critical section */
90 K32OBJ *mutex_list; /* 1f4 List of owned mutex (was: unknown)*/
91 DWORD unknown6[2]; /* 1f8 Unknown */
92 /* The following are Wine-specific fields */
93 CONTEXT context; /* 200 Thread context */
94 WAIT_STRUCT wait_struct; /* Event wait structure */
97 /* Thread queue entry */
98 typedef struct _THREAD_ENTRY
101 struct _THREAD_ENTRY *next;
104 /* A thread queue is a circular list; a THREAD_QUEUE is a pointer */
105 /* to the end of the queue (i.e. where we add elements) */
106 typedef THREAD_ENTRY *THREAD_QUEUE;
108 /* THDB <-> Thread id conversion macros */
109 #define THREAD_OBFUSCATOR ((DWORD)0xdeadbeef)
110 #define THREAD_ID_TO_THDB(id) ((THDB *)((id) ^ THREAD_OBFUSCATOR))
111 #define THDB_TO_THREAD_ID(thdb) ((DWORD)(thdb) ^ THREAD_OBFUSCATOR)
114 /* On the i386, the current thread is in the %fs register */
115 # define SET_CUR_THREAD(thdb) SET_FS((thdb)->teb_sel)
117 extern THDB *pCurrentThread;
118 # define SET_CUR_THREAD(thdb) (pCurrentThread = (thdb))
119 #endif /* __i386__ */
122 /* scheduler/thread.c */
123 extern THDB *THREAD_Create( struct _PDB32 *pdb, DWORD stack_size,
124 BOOL32 alloc_stack16,
125 LPTHREAD_START_ROUTINE start_addr, LPVOID param );
126 extern THDB *THREAD_Current(void);
127 extern THDB *THREAD_GetPtr( HANDLE32 handle, DWORD access );
128 extern void THREAD_AddQueue( THREAD_QUEUE *queue, THDB *thread );
129 extern void THREAD_RemoveQueue( THREAD_QUEUE *queue, THDB *thread );
130 extern DWORD THREAD_TlsAlloc( THDB *thread );
132 /* scheduler/event.c */
133 extern void EVENT_Set( K32OBJ *obj );
134 extern K32OBJ *EVENT_Create( BOOL32 manual_reset, BOOL32 initial_state );
136 /* scheduler/mutex.c */
137 extern void MUTEX_Abandon( K32OBJ *obj );
139 /* scheduler/synchro.c */
140 extern void SYNC_WaitForCondition( WAIT_STRUCT *wait, DWORD timeout );
141 extern void SYNC_WakeUp( THREAD_QUEUE *queue, DWORD max );
142 extern void SYNC_SetupSignals(void);
144 /* scheduler/sysdeps.c */
145 extern int SYSDEPS_SpawnThread( THDB *thread );
146 extern void SYSDEPS_ExitThread(void);
147 extern TEB * WINAPI NtCurrentTeb(void);
149 #endif /* __WINE_THREAD_H */