| 1 | /* | 
|---|
| 2 | * Process help functions | 
|---|
| 3 | * | 
|---|
| 4 | * Copyright (C) 1999 Sander van Leeuwen | 
|---|
| 5 | * | 
|---|
| 6 | * Project Odin Software License can be found in LICENSE.TXT | 
|---|
| 7 | * | 
|---|
| 8 | */ | 
|---|
| 9 |  | 
|---|
| 10 | #ifndef _WPROCESS_H__ | 
|---|
| 11 | #define _WPROCESS_H__ | 
|---|
| 12 |  | 
|---|
| 13 | #define WIN32_TIBSEL | 
|---|
| 14 |  | 
|---|
| 15 | #ifndef OS2_INCLUDED | 
|---|
| 16 | #include <winprocess.h> | 
|---|
| 17 | #else | 
|---|
| 18 | #include <winconst.h> | 
|---|
| 19 | typedef ULONG PDB; | 
|---|
| 20 | #endif | 
|---|
| 21 | #include <thread.h> | 
|---|
| 22 | #include <FastInfoBlocks.h> | 
|---|
| 23 |  | 
|---|
| 24 | #define SELECTOR_OS2_FS         0x150b | 
|---|
| 25 |  | 
|---|
| 26 | #define MAKE_THREADID(processid, threadid)      ((processid << 16) | threadid) | 
|---|
| 27 | #define ODIN_TO_OS2_THREADID(threadid)          (threadid & 0xFFFF) | 
|---|
| 28 |  | 
|---|
| 29 | #define ODIN_GetCurrentThreadId()    MAKE_THREADID(fibGetPid(), fibGetTid()) | 
|---|
| 30 | #define ODIN_GetCurrentProcessId()   fibGetPid() | 
|---|
| 31 |  | 
|---|
| 32 | #ifdef __cplusplus | 
|---|
| 33 | extern "C" { | 
|---|
| 34 | #endif | 
|---|
| 35 |  | 
|---|
| 36 | TEB   *WIN32API CreateTEB(HANDLE hThread, DWORD dwThreadId); | 
|---|
| 37 | TEB   *WIN32API InitializeMainThread(); | 
|---|
| 38 |  | 
|---|
| 39 | //****************************************************************************** | 
|---|
| 40 | // Set up the TEB structure of the CURRENT (!) thread | 
|---|
| 41 | //****************************************************************************** | 
|---|
| 42 | BOOL   WIN32API InitializeThread(TEB *teb, BOOL fMainThread DEF_VAL(FALSE)); | 
|---|
| 43 |  | 
|---|
| 44 | void   WIN32API DestroyTEB(TEB *teb); | 
|---|
| 45 | ULONG  WIN32API GetProcessTIBSel(); | 
|---|
| 46 |  | 
|---|
| 47 | #define TIB_SWITCH_DEFAULT      0  //executable type determines whether or not FS is changed | 
|---|
| 48 | #define TIB_SWITCH_FORCE_WIN32  1  //always switch to win32 TIB (FS is changed) | 
|---|
| 49 | // | 
|---|
| 50 | //Switch to WIN32 TIB (FS selector) | 
|---|
| 51 | //NOTE: This is not done for Odin32 applications (LX), unless | 
|---|
| 52 | //      fForceSwitch is TRUE) | 
|---|
| 53 | USHORT WIN32API SetWin32TIB(BOOL fForceSwitch DEF_VAL(TIB_SWITCH_DEFAULT)); | 
|---|
| 54 | void   WIN32API RestoreOS2TIB(); | 
|---|
| 55 |  | 
|---|
| 56 | void   SetPDBInstance(HINSTANCE hInstance); | 
|---|
| 57 |  | 
|---|
| 58 | extern BOOL fExeStarted; | 
|---|
| 59 | extern BOOL fFreeLibrary; | 
|---|
| 60 | extern BOOL fIsOS2Image;   //TRUE  -> Odin32 OS/2 application (not converted!) | 
|---|
| 61 | //FALSE -> otherwise | 
|---|
| 62 | extern BOOL fSwitchTIBSel; // TRUE  -> switch TIB selectors | 
|---|
| 63 | // FALSE -> don't | 
|---|
| 64 | extern BOOL fForceWin32TIB;// TRUE  -> SEH support enabled | 
|---|
| 65 | // FALSE -> not enabled | 
|---|
| 66 | extern BOOL fExitProcess; | 
|---|
| 67 |  | 
|---|
| 68 | //Flat pointer to thread TIB structure | 
|---|
| 69 | extern DWORD  *TIBFlatPtr; | 
|---|
| 70 |  | 
|---|
| 71 | extern PDB ProcessPDB; | 
|---|
| 72 |  | 
|---|
| 73 | #define NtCurrentTeb GetThreadTEB | 
|---|
| 74 | TEB  *WIN32API GetThreadTEB(void); | 
|---|
| 75 | TEB  *WIN32API GetTEBFromThreadId(ULONG threadId); | 
|---|
| 76 | TEB  *WIN32API GetTEBFromThreadHandle(HANDLE hThread); | 
|---|
| 77 |  | 
|---|
| 78 | #ifndef OS2_INCLUDED | 
|---|
| 79 | inline PDB * PROCESS_Current(void) | 
|---|
| 80 | { | 
|---|
| 81 | return NtCurrentTeb()->process; | 
|---|
| 82 | } | 
|---|
| 83 | #endif | 
|---|
| 84 |  | 
|---|
| 85 | ULONG InitCommandLine(const char *pszPeExe); | 
|---|
| 86 | BOOL  InitLoaders(); | 
|---|
| 87 |  | 
|---|
| 88 | UINT WIN32API GetProcModuleFileNameA(ULONG lpvAddress, LPSTR lpszFileName, UINT cchFileNameMax); | 
|---|
| 89 |  | 
|---|
| 90 | #ifdef __cplusplus | 
|---|
| 91 | } // extern "C" | 
|---|
| 92 | #endif | 
|---|
| 93 |  | 
|---|
| 94 | #endif | 
|---|