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