blob: 4e9b61f711a861f0852d0ed10ffacdc00a53fa04 [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 Julliard02e90081998-01-04 17:49:09 +000010#include "k32obj.h"
11#include "windows.h"
Alexandre Julliard349a9531997-02-02 19:01:52 +000012#include "winnt.h"
Alexandre Julliard02e90081998-01-04 17:49:09 +000013#include "selectors.h" /* for SET_FS */
Alexandre Julliard9ea19e51997-01-01 17:29:55 +000014
15/* Thread exception block */
16typedef struct _TEB
17{
18 void *except; /* 00 Head of exception handling chain */
19 void *stack_top; /* 04 Top of thread stack */
20 void *stack_low; /* 08 Stack low-water mark */
21 HTASK16 htask16; /* 0c Win16 task handle */
22 WORD stack_sel; /* 0e 16-bit stack selector */
23 DWORD selman_list; /* 10 Selector manager list */
24 DWORD user_ptr; /* 14 User pointer */
25 struct _TEB *self; /* 18 Pointer to this structure */
26 WORD flags; /* 1c Flags */
27 WORD mutex_count; /* 1e Win16 mutex count */
28 DWORD debug_context; /* 20 Debug context */
29 DWORD *ppriority; /* 24 Pointer to current priority */
30 HQUEUE16 queue; /* 28 Message queue */
31 WORD pad1; /* 2a */
32 LPVOID *tls_ptr; /* 2c Pointer to TLS array */
33} TEB;
34
Alexandre Julliard02e90081998-01-04 17:49:09 +000035/* Event waiting structure */
36typedef struct
37{
38 DWORD count; /* Count of valid objects */
39 DWORD signaled; /* Index of signaled object (or WAIT_FAILED)*/
40 BOOL32 wait_all; /* Wait for all objects flag */
41 K32OBJ *objs[MAXIMUM_WAIT_OBJECTS]; /* Object pointers */
42} WAIT_STRUCT;
43
44struct _PDB32;
45
Alexandre Julliard9ea19e51997-01-01 17:29:55 +000046/* Thread database */
47typedef struct _THDB
48{
Alexandre Julliard02e90081998-01-04 17:49:09 +000049 K32OBJ header; /* 00 Kernel object header */
50 struct _PDB32 *process; /* 08 Process owning this thread */
51 K32OBJ *event; /* 0c Thread event */
52 TEB teb; /* 10 Thread exception block */
53 struct _PDB32 *process2; /* 40 Same as offset 08 (?) */
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 DWORD unknown1; /* 50 Unknown */
59 WAIT_STRUCT *wait_list; /* 54 Event waiting list */
60 DWORD unknown2; /* 58 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 unknown3[3]; /* 80 Unknown */
71 WORD current_ss; /* 8c Another 16-bit stack selector */
72 WORD pad2; /* 8e */
73 void *ss_table; /* 90 Pointer to info about 16-bit stack */
74 WORD thunk_ss; /* 94 Yet another 16-bit stack selector */
75 WORD pad3; /* 96 */
76 LPVOID tls_array[64]; /* 98 Thread local storage */
77 DWORD delta_priority; /* 198 Priority delta */
78 DWORD unknown4[7]; /* 19c Unknown */
79 void *create_data; /* 1b8 Pointer to creation structure */
80 DWORD suspend_count; /* 1bc SuspendThread() counter */
81 void *entry_point; /* 1c0 Thread entry point (was: unknown) */
82 void *entry_arg; /* 1c4 Entry point arg (was: unknown) */
83 int unix_pid; /* 1c8 Unix thread pid (was: unknown) */
84 DWORD unknown5[6]; /* 1cc Unknown */
85 K32OBJ *crit_section; /* 1e4 Some critical section */
86 K32OBJ *win16_mutex; /* 1e8 Pointer to Win16 mutex */
87 K32OBJ *win32_mutex; /* 1ec Pointer to KERNEL32 mutex */
88 K32OBJ *crit_section2; /* 1f0 Another critical section */
89 DWORD unknown6[3]; /* 1f4 Unknown */
Alexandre Julliard349a9531997-02-02 19:01:52 +000090 /* The following are Wine-specific fields */
Alexandre Julliard02e90081998-01-04 17:49:09 +000091 CONTEXT context; /* 200 Thread context */
92 WAIT_STRUCT wait_struct; /* Event wait structure */
Alexandre Julliard9ea19e51997-01-01 17:29:55 +000093} THDB;
94
Alexandre Julliard02e90081998-01-04 17:49:09 +000095/* Thread queue entry */
96typedef struct _THREAD_ENTRY
97{
98 THDB *thread;
99 struct _THREAD_ENTRY *next;
100} THREAD_ENTRY;
Alexandre Julliard9ea19e51997-01-01 17:29:55 +0000101
Alexandre Julliard02e90081998-01-04 17:49:09 +0000102/* A thread queue is a circular list; a THREAD_QUEUE is a pointer */
103/* to the end of the queue (i.e. where we add elements) */
104typedef THREAD_ENTRY *THREAD_QUEUE;
Alexandre Julliard9ea19e51997-01-01 17:29:55 +0000105
Alexandre Julliard02e90081998-01-04 17:49:09 +0000106/* THDB <-> Thread id conversion macros */
107#define THREAD_OBFUSCATOR ((DWORD)0xdeadbeef)
108#define THREAD_ID_TO_THDB(id) ((THDB *)((id) ^ THREAD_OBFUSCATOR))
109#define THDB_TO_THREAD_ID(thdb) ((DWORD)(thdb) ^ THREAD_OBFUSCATOR)
110
111#ifdef __i386__
112/* On the i386, the current thread is in the %fs register */
113# define SET_CUR_THREAD(thdb) SET_FS((thdb)->teb_sel)
114#else
Alexandre Julliard9ea19e51997-01-01 17:29:55 +0000115extern THDB *pCurrentThread;
Alexandre Julliard02e90081998-01-04 17:49:09 +0000116# define SET_CUR_THREAD(thdb) (pCurrentThread = (thdb))
117#endif /* __i386__ */
118
119
120/* scheduler/thread.c */
121extern THDB *THREAD_Create( struct _PDB32 *pdb, DWORD stack_size,
122 LPTHREAD_START_ROUTINE start_addr, LPVOID param );
123extern THDB *THREAD_Current(void);
124extern void THREAD_AddQueue( THREAD_QUEUE *queue, THDB *thread );
125extern void THREAD_RemoveQueue( THREAD_QUEUE *queue, THDB *thread );
126
127/* scheduler/synchro.c */
128extern void SYNC_WaitForCondition( WAIT_STRUCT *wait, DWORD timeout );
129extern void SYNC_WakeUp( THREAD_QUEUE *queue, DWORD max );
Alexandre Julliard9ea19e51997-01-01 17:29:55 +0000130
131#endif /* __WINE_THREAD_H */