| 1 | /* $Id: thread.h,v 1.7 1999-10-14 12:29:15 sandervl Exp $ */ | 
|---|
| 2 |  | 
|---|
| 3 | /* | 
|---|
| 4 | * Thread definitions | 
|---|
| 5 | * | 
|---|
| 6 | * Copyright 1996 Alexandre Julliard | 
|---|
| 7 | */ | 
|---|
| 8 |  | 
|---|
| 9 | #ifndef __WINE_THREAD_H | 
|---|
| 10 | #define __WINE_THREAD_H | 
|---|
| 11 |  | 
|---|
| 12 | #ifdef __WIN32OS2__ | 
|---|
| 13 | #define TLS_MINIMUM_AVAILABLE   64 | 
|---|
| 14 | #ifndef __OS2_H__ | 
|---|
| 15 | #include "config.h" | 
|---|
| 16 | #include "winbase.h" | 
|---|
| 17 | #endif | 
|---|
| 18 | #else | 
|---|
| 19 | #include "config.h" | 
|---|
| 20 | #include "winbase.h" | 
|---|
| 21 | #include "selectors.h"  /* for SET_FS */ | 
|---|
| 22 | #endif | 
|---|
| 23 |  | 
|---|
| 24 | struct _PDB; | 
|---|
| 25 |  | 
|---|
| 26 | /* Thread exception block */ | 
|---|
| 27 | typedef struct _TEB | 
|---|
| 28 | { | 
|---|
| 29 | void        *except;         /* 00 Head of exception handling chain */ | 
|---|
| 30 | void        *stack_top;      /* 04 Top of thread stack */ | 
|---|
| 31 | void        *stack_low;      /* 08 Stack low-water mark */ | 
|---|
| 32 | HTASK16      htask16;        /* 0c Win16 task handle */ | 
|---|
| 33 | WORD         stack_sel;      /* 0e 16-bit stack selector */ | 
|---|
| 34 | DWORD        selman_list;    /* 10 Selector manager list */ | 
|---|
| 35 | DWORD        user_ptr;       /* 14 User pointer */ | 
|---|
| 36 | struct _TEB *self;           /* 18 Pointer to this structure */ | 
|---|
| 37 | WORD         flags;          /* 1c Flags */ | 
|---|
| 38 | WORD         mutex_count;    /* 1e Win16 mutex count */ | 
|---|
| 39 | DWORD        debug_context;  /* 20 Debug context */ | 
|---|
| 40 | DWORD       *ppriority;      /* 24 Pointer to current priority */ | 
|---|
| 41 | HQUEUE16     queue;          /* 28 Message queue */ | 
|---|
| 42 | WORD         pad1;           /* 2a */ | 
|---|
| 43 | LPVOID      *tls_ptr;        /* 2c Pointer to TLS array */ | 
|---|
| 44 | struct _PDB *process;      /* 30 owning process (used by NT3.51 applets)*/ | 
|---|
| 45 | } TEB; | 
|---|
| 46 |  | 
|---|
| 47 | /* Thread exception flags */ | 
|---|
| 48 | #define TEBF_WIN32  0x0001 | 
|---|
| 49 | #define TEBF_TRAP   0x0002 | 
|---|
| 50 |  | 
|---|
| 51 | /* Thread database */ | 
|---|
| 52 | typedef struct _THDB | 
|---|
| 53 | { | 
|---|
| 54 | LONG           header[2];      /*  00 Kernel object header */ | 
|---|
| 55 | struct _PDB   *process;        /*  08 Process owning this thread */ | 
|---|
| 56 | HANDLE         event;          /*  0c Thread event */ | 
|---|
| 57 | TEB            teb;            /*  10 Thread exception block */ | 
|---|
| 58 | DWORD          flags;          /*  44 Flags */ | 
|---|
| 59 | DWORD          exit_code;      /*  48 Termination status */ | 
|---|
| 60 | WORD           teb_sel;        /*  4c Selector to TEB */ | 
|---|
| 61 | WORD           emu_sel;        /*  4e 80387 emulator selector */ | 
|---|
| 62 | int            thread_errno;   /*  50 Per-thread errno (was: unknown) */ | 
|---|
| 63 | void          *wait_list;      /*  54 Event waiting list */ | 
|---|
| 64 | int            thread_h_errno; /*  50 Per-thread h_errno (was: unknown) */ | 
|---|
| 65 | void          *ring0_thread;   /*  5c Pointer to ring 0 thread */ | 
|---|
| 66 | void          *ptdbx;          /*  60 Pointer to TDBX structure */ | 
|---|
| 67 | void          *stack_base;     /*  64 Base of the stack */ | 
|---|
| 68 | void          *exit_stack;     /*  68 Stack pointer on thread exit */ | 
|---|
| 69 | void          *emu_data;       /*  6c Related to 80387 emulation */ | 
|---|
| 70 | DWORD          last_error;     /*  70 Last error code */ | 
|---|
| 71 | void          *debugger_CB;    /*  74 Debugger context block */ | 
|---|
| 72 | DWORD          debug_thread;   /*  78 Thread debugging this one (?) */ | 
|---|
| 73 | void          *pcontext;       /*  7c Thread register context */ | 
|---|
| 74 | DWORD          cur_stack;      /*  80 Current stack (was: unknown) */ | 
|---|
| 75 | DWORD          unknown3[2];    /*  84 Unknown */ | 
|---|
| 76 | WORD           current_ss;     /*  8c Another 16-bit stack selector */ | 
|---|
| 77 | WORD           pad2;           /*  8e */ | 
|---|
| 78 | void          *ss_table;       /*  90 Pointer to info about 16-bit stack */ | 
|---|
| 79 | WORD           thunk_ss;       /*  94 Yet another 16-bit stack selector */ | 
|---|
| 80 | WORD           pad3;           /*  96 */ | 
|---|
| 81 | #ifdef __WIN32OS2__ | 
|---|
| 82 | LPVOID         tls_array[TLS_MINIMUM_AVAILABLE];  /*  98 Thread local storage */ | 
|---|
| 83 | #else | 
|---|
| 84 | LPVOID         tls_array[64];  /*  98 Thread local storage */ | 
|---|
| 85 | #endif | 
|---|
| 86 | DWORD          delta_priority; /* 198 Priority delta */ | 
|---|
| 87 | DWORD          unknown4[7];    /* 19c Unknown */ | 
|---|
| 88 | void          *create_data;    /* 1b8 Pointer to creation structure */ | 
|---|
| 89 | DWORD          suspend_count;  /* 1bc SuspendThread() counter */ | 
|---|
| 90 | void          *entry_point;    /* 1c0 Thread entry point (was: unknown) */ | 
|---|
| 91 | void          *entry_arg;      /* 1c4 Entry point arg (was: unknown) */ | 
|---|
| 92 | DWORD          unknown5[4];    /* 1c8 Unknown */ | 
|---|
| 93 | DWORD          sys_count[4];   /* 1d8 Syslevel mutex entry counters */ | 
|---|
| 94 | CRITICAL_SECTION *sys_mutex[4];/* 1e8 Syslevel mutex pointers */ | 
|---|
| 95 | DWORD          unknown6[2];    /* 1f8 Unknown */ | 
|---|
| 96 | /* The following are Wine-specific fields */ | 
|---|
| 97 | int            socket;         /* Socket for server communication */ | 
|---|
| 98 | unsigned int   seq;            /* Server sequence number */ | 
|---|
| 99 | void          *server_tid;     /* Server id for this thread */ | 
|---|
| 100 | void         (*startup)(void); /* Thread startup routine */ | 
|---|
| 101 | struct _THDB  *next;           /* Global thread list */ | 
|---|
| 102 | #ifdef __WIN32OS2__ | 
|---|
| 103 | DWORD          OrgTIBSel;      // Original OS/2 TIB selector (always the same, but let's not assume too much for future compatibility) | 
|---|
| 104 | ULONG          hmq;            // Thread message queue | 
|---|
| 105 | ULONG          hab;            // Thread Anchor block | 
|---|
| 106 | BOOL           fMsgTranslated; // TranslateMessage called for this message? | 
|---|
| 107 | ULONG          newWindow;      // Pointer to window object of window that was just created | 
|---|
| 108 | #endif | 
|---|
| 109 | } THDB; | 
|---|
| 110 |  | 
|---|
| 111 | /* The pseudo handle value returned by GetCurrentThread */ | 
|---|
| 112 | #define CURRENT_THREAD_PSEUDOHANDLE 0xfffffffe | 
|---|
| 113 |  | 
|---|
| 114 | #ifdef __i386__ | 
|---|
| 115 | /* On the i386, the current thread is in the %fs register */ | 
|---|
| 116 | # define SET_CUR_THREAD(thdb) SET_FS((thdb)->teb_sel) | 
|---|
| 117 | #else | 
|---|
| 118 | extern THDB *pCurrentThread; | 
|---|
| 119 | # define SET_CUR_THREAD(thdb) (pCurrentThread = (thdb)) | 
|---|
| 120 | #endif  /* __i386__ */ | 
|---|
| 121 |  | 
|---|
| 122 |  | 
|---|
| 123 | /* scheduler/thread.c */ | 
|---|
| 124 | extern THDB *THREAD_CreateInitialThread( struct _PDB *pdb, int server_fd ); | 
|---|
| 125 | extern THDB *THREAD_Create( struct _PDB *pdb, DWORD flags, | 
|---|
| 126 | DWORD stack_size, BOOL alloc_stack16, | 
|---|
| 127 | LPSECURITY_ATTRIBUTES sa, int *server_handle ); | 
|---|
| 128 | extern THDB *THREAD_Current(void); | 
|---|
| 129 | extern BOOL THREAD_IsWin16( THDB *thdb ); | 
|---|
| 130 | extern THDB *THREAD_IdToTHDB( DWORD id ); | 
|---|
| 131 |  | 
|---|
| 132 | /* scheduler/sysdeps.c */ | 
|---|
| 133 | extern int SYSDEPS_SpawnThread( THDB *thread ); | 
|---|
| 134 | extern void SYSDEPS_ExitThread(void); | 
|---|
| 135 | extern TEB * WINAPI NtCurrentTeb(void); | 
|---|
| 136 |  | 
|---|
| 137 | #endif  /* __WINE_THREAD_H */ | 
|---|