Fix the ListView_SetItemState macro.
[wine] / include / thread.h
1 /*
2  * Thread definitions
3  *
4  * Copyright 1996 Alexandre Julliard
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  */
20
21 #ifndef __WINE_THREAD_H
22 #define __WINE_THREAD_H
23
24 #include "winternl.h"
25 #include "wine/windef16.h"
26
27 struct _PDB;
28 struct __EXCEPTION_FRAME;
29 struct _SECURITY_ATTRIBUTES;
30 struct tagSYSLEVEL;
31 struct server_buffer_info;
32 struct fiber_data;
33
34 /* Thread exception block
35
36   flags in the comment:
37   1-- win95 field
38   d-- win95 debug version
39   -2- nt field
40   --3 wine special
41   --n wine unused
42   !-- or -!- likely or observed  collision
43   more problems (collected from mailing list):
44   psapi.dll 0x10/0x30 (expects nt fields)
45   ie4       0x40
46   PESHiELD  0x23/0x30 (win95)
47 */
48 typedef struct _TEB
49 {
50 /* start of NT_TIB */
51     struct __EXCEPTION_FRAME *except; /* 12- 00 Head of exception handling chain */
52     void        *stack_top;      /* 12-  04 Top of thread stack */
53     void        *stack_low;      /* 12-  08 Stack low-water mark */
54     HTASK16      htask16;        /* 1--  0c Win16 task handle */
55     WORD         stack_sel;      /* 1--  0e 16-bit stack selector */
56     struct fiber_data *fiber;    /* -2-  10 Current fiber data (Win95: selector manager list) */
57     DWORD        user_ptr;       /* 12n  14 User pointer */
58 /* end of NT_TIB */
59     struct _TEB *self;           /* 12-  18 Pointer to this structure */
60     WORD         tibflags;       /* 1!n  1c Flags (NT: EnvironmentPointer) */
61     WORD         mutex_count;    /* 1-n  1e Win16 mutex count */
62     DWORD        pid;            /* !2-  20 Process id (win95: debug context) */
63     DWORD        tid;            /* -2-  24 Thread id */
64     HQUEUE16     queue;          /* 1!-  28 Message queue (NT: DWORD ActiveRpcHandle)*/
65     WORD         pad1;           /* --n  2a */
66     LPVOID      *tls_ptr;        /* 1--  2c Pointer to TLS array */
67     struct _PDB *process;        /* 12-  30 owning process (win95: PDB; nt: NTPEB !!) */
68     DWORD        flags;          /* 1-n  34 */
69     DWORD        exit_code;      /* 1--  38 Termination status */
70     WORD         teb_sel;        /* 1--  3c Selector to TEB */
71     WORD         emu_sel;        /* 1-n  3e 80387 emulator selector */
72     DWORD        unknown1;       /* --n  40 */
73     DWORD        unknown2;       /* --n  44 */
74     void       (*startup)(void); /* --3  48 Thread startup routine */
75     int          thread_errno;   /* --3  4c Per-thread errno (was: ring0_thread) */
76     int          thread_h_errno; /* --3  50 Per-thread h_errno (was: ptr to tdbx structure) */
77     void        *signal_stack;   /* --3  54 Signal stack (was: stack_base) */
78     void        *exit_stack;     /* 1-n  58 Exit stack */
79     void        *emu_data;       /* --n  5c Related to 80387 emulation */
80     DWORD        last_error;     /* 1--  60 Last error code */
81     HANDLE       debug_cb;       /* 1-n  64 Debugger context block */
82     DWORD        debug_thread;   /* 1-n  68 Thread debugging this one (?) */
83     void        *pcontext;       /* 1-n  6c Thread register context */
84     DWORD        cur_stack;      /* --3  70 Current stack (was: unknown) */
85     DWORD        ThunkConnect;   /* 1-n  74 */
86     DWORD        NegStackBase;   /* 1-n  78 */
87     WORD         current_ss;     /* 1-n  7c Another 16-bit stack selector */
88     WORD         pad2;           /* --n  7e */
89     void        *ss_table;       /* --n  80 Pointer to info about 16-bit stack */
90     WORD         thunk_ss;       /* --n  84 Yet another 16-bit stack selector */
91     WORD         pad3;           /* --n  86 */
92     DWORD        pad4[15];       /* --n  88 */
93     ULONG        CurrentLocale;  /* -2-  C4 */
94     DWORD        pad5[48];       /* --n  C8 */
95     DWORD        delta_priority; /* 1-n 188 Priority delta */
96     DWORD        unknown4[7];    /* d-n 18c Unknown */
97     void        *create_data;    /* d-n 1a8 Pointer to creation structure */
98     DWORD        suspend_count;  /* d-n 1ac SuspendThread() counter */
99     void        *entry_point;    /* --3 1b0 Thread entry point (was: unknown) */
100     void        *entry_arg;      /* --3 1b4 Entry point arg (was: unknown) */
101     DWORD        unknown5[4];    /* --n 1b8 Unknown */
102     DWORD        sys_count[4];   /* --3 1c8 Syslevel mutex entry counters */
103     struct tagSYSLEVEL *sys_mutex[4];   /* --3 1d8 Syslevel mutex pointers */
104     DWORD        unknown6[5];    /* --n 1e8 Unknown */
105
106     /* The following are Wine-specific fields (NT: GDI stuff) */
107     UINT         code_page;      /* --3 1fc Thread code page */
108     DWORD        unused[2];      /* --3 200 Was server buffer */
109     DWORD        gs_sel;         /* --3 208 %gs selector for this thread */
110     int          request_fd;     /* --3 20c fd for sending server requests */
111     int          reply_fd;       /* --3 210 fd for receiving server replies */
112     int          wait_fd[2];     /* --3 214 fd for sleeping server requests */
113     void        *debug_info;     /* --3 21c Info for debugstr functions */
114     void        *pthread_data;   /* --3 220 Data for pthread emulation */
115     struct async_private *pending_list;   /* --3 224 list of pending async operations */
116     void        *driver_data;    /* --3 228 Graphics driver private data */
117     DWORD        alarms;         /* --3 22c Data for vm86 mode */
118     DWORD        vm86_pending;   /* --3 230 Data for vm86 mode */
119     void        *vm86_ptr;       /* --3 234 Data for vm86 mode */
120     /* here is plenty space for wine specific fields (don't forget to change pad6!!) */
121
122     /* the following are nt specific fields */
123     DWORD        pad6[624];                  /* --n 238 */
124     UNICODE_STRING StaticUnicodeString;      /* -2- bf8 used by advapi32 */
125     USHORT       StaticUnicodeBuffer[261];   /* -2- c00 used by advapi32 */
126     void        *stack_base;                 /* -2- e0c Base of the stack */
127     LPVOID       tls_array[64];              /* -2- e10 Thread local storage */
128     DWORD        pad8[3];                    /* --n f10 */
129     PVOID        ReservedForNtRpc;           /* -2- f1c used by rpcrt4 */
130     DWORD        pad9[24];                   /* --n f20 */
131     PVOID        ErrorInfo;                  /* -2- f80 used by ole32 (IErrorInfo*) */
132 } TEB;
133
134 /* Thread exception flags */
135 #define TEBF_WIN32  0x0001
136 #define TEBF_TRAP   0x0002
137
138 /* The per-thread signal stack size */
139 #define SIGNAL_STACK_SIZE  0x100000  /* 1Mb  FIXME: should be much smaller than that */
140
141
142 /* scheduler/thread.c */
143 extern void THREAD_Init(void);
144 extern TEB *THREAD_InitStack( TEB *teb, DWORD stack_size );
145 extern TEB *THREAD_IdToTEB( DWORD id );
146
147 /* scheduler/sysdeps.c */
148 extern int SYSDEPS_SpawnThread( TEB *teb );
149 extern void SYSDEPS_SetCurThread( TEB *teb );
150 extern int SYSDEPS_GetUnixTid(void);
151 extern void SYSDEPS_InitErrno(void);
152 extern void DECLSPEC_NORETURN SYSDEPS_ExitThread( int status );
153 extern void DECLSPEC_NORETURN SYSDEPS_AbortThread( int status );
154 extern void DECLSPEC_NORETURN SYSDEPS_SwitchToThreadStack( void (*func)(void) );
155
156 /* signal handling */
157 extern BOOL SIGNAL_Init(void);
158 extern void SIGNAL_Block(void);
159 extern void SIGNAL_Unblock(void);
160 extern void SIGNAL_Reset(void);
161
162 #endif  /* __WINE_THREAD_H */