| 1 | /* $Id: windllpe2lx.cpp,v 1.7 2000-03-09 19:03:21 sandervl Exp $ */ | 
|---|
| 2 |  | 
|---|
| 3 | /* | 
|---|
| 4 | * Win32 PE2LX Dll class | 
|---|
| 5 | * | 
|---|
| 6 | * Copyright 1999 Sander van Leeuwen (sandervl@xs4all.nl) | 
|---|
| 7 | * Copyright 1999 knut st. osmundsen (knut.stange.osmundsen@pmsc.no) | 
|---|
| 8 | * | 
|---|
| 9 | * Project Odin Software License can be found in LICENSE.TXT | 
|---|
| 10 | * | 
|---|
| 11 | */ | 
|---|
| 12 |  | 
|---|
| 13 | /******************************************************************************* | 
|---|
| 14 | *   Defined Constants And Macros                                               * | 
|---|
| 15 | *******************************************************************************/ | 
|---|
| 16 | #define INCL_DOSERRORS      /* DOS Error values */ | 
|---|
| 17 | #define INCL_DOSMODULEMGR   /* DOS Module management */ | 
|---|
| 18 | #define INCL_DOSSEMAPHORES | 
|---|
| 19 |  | 
|---|
| 20 | /******************************************************************************* | 
|---|
| 21 | *   Header Files                                                               * | 
|---|
| 22 | *******************************************************************************/ | 
|---|
| 23 | #include <os2wrap.h>        //Odin32 OS/2 api wrappers | 
|---|
| 24 |  | 
|---|
| 25 | #include <stdlib.h> | 
|---|
| 26 |  | 
|---|
| 27 | #include <win32type.h> | 
|---|
| 28 | #include <misc.h> | 
|---|
| 29 | #include <windllpe2lx.h> | 
|---|
| 30 | #include <wprocess.h> | 
|---|
| 31 |  | 
|---|
| 32 | #include "cio.h"            // I/O | 
|---|
| 33 | #include "oslibmisc.h"      // OSLibGetDllName | 
|---|
| 34 | #include "conwin.h"         // Windows Header for console only | 
|---|
| 35 | #include "console.h" | 
|---|
| 36 |  | 
|---|
| 37 | #define DBG_LOCALLOG    DBG_windllpe2lx | 
|---|
| 38 | #include "dbglocal.h" | 
|---|
| 39 |  | 
|---|
| 40 |  | 
|---|
| 41 | /** | 
|---|
| 42 | * Register an Pe2Lx Dll module. Called from TIBFix code in Dll Pe2Lx module. | 
|---|
| 43 | * @returns   1 on success. | 
|---|
| 44 | *            0 on failure. | 
|---|
| 45 | * @param     Pe2LxVersion  Pe2Lx version. High bit is Win32k indicator and must be masked off! | 
|---|
| 46 | * @param     hInstance     Module handle (OS/2). | 
|---|
| 47 | * @param     dwAttachType  0 = attach dll | 
|---|
| 48 | *                          1 = detach dll | 
|---|
| 49 | * @sketch    Try find module. | 
|---|
| 50 | *            IF attach process THEN | 
|---|
| 51 | *            BEGIN | 
|---|
| 52 | *            END | 
|---|
| 53 | *                Init I/O. | 
|---|
| 54 | *                Get Lib name and match Pe2Lx version with kernel32 version. | 
|---|
| 55 | *                Write info to the log. | 
|---|
| 56 | *                Try create pe2lx dll object. | 
|---|
| 57 | *                Console devices initialization. | 
|---|
| 58 | *                Add reference and attach dll to process. | 
|---|
| 59 | *            ELSE | 
|---|
| 60 | *            BEGIN | 
|---|
| 61 | *                IF module found AND not freelibrary THEN | 
|---|
| 62 | *                    fail (return 0) due to OS/2 bug. | 
|---|
| 63 | *            END | 
|---|
| 64 | *            return successfully (return 1) | 
|---|
| 65 | * @status    completely implemented. | 
|---|
| 66 | * @author    Sander van Leeuwen, knut st. osmundsen | 
|---|
| 67 | */ | 
|---|
| 68 | ULONG WIN32API RegisterPe2LxDll(ULONG ulPe2LxVersion, HINSTANCE hinstance, ULONG ulAttachType) | 
|---|
| 69 | { | 
|---|
| 70 | char *pszName; | 
|---|
| 71 |  | 
|---|
| 72 | #if 1 /* temporary fix */ | 
|---|
| 73 | if (ulAttachType != 0UL) | 
|---|
| 74 | return 0; | 
|---|
| 75 | #endif | 
|---|
| 76 |  | 
|---|
| 77 | Win32Pe2LxDll *pWinMod = (Win32Pe2LxDll *)Win32DllBase::findModule(hinstance); | 
|---|
| 78 | if (ulAttachType == 0UL) | 
|---|
| 79 | {   /* Process attach */ | 
|---|
| 80 |  | 
|---|
| 81 | /* Init I/O */ | 
|---|
| 82 | if (getenv("WIN32_IOPL2")) | 
|---|
| 83 | io_init1(); | 
|---|
| 84 |  | 
|---|
| 85 | /* Get Lib name and match Pe2Lx version with kernel32 version. */ | 
|---|
| 86 | pszName = OSLibGetDllName(hinstance); | 
|---|
| 87 | CheckVersion(ulPe2LxVersion & ~0x80000000UL, pszName); | 
|---|
| 88 |  | 
|---|
| 89 | /* Write info to the log. */ | 
|---|
| 90 | dprintf(("RegisterPe2LxExe: ulPe2LxVersion = %#x\n", ulPe2LxVersion)); | 
|---|
| 91 | dprintf(("RegisterPe2LxExe: hinstance = %#x\n", hinstance)); | 
|---|
| 92 | dprintf(("RegisterPe2LxExe: ulAttachType = %#x (reason)\n", ulAttachType)); | 
|---|
| 93 | dprintf(("RegisterPe2LxExe: name = %s\n", OSLibGetDllName(hinstance))); | 
|---|
| 94 |  | 
|---|
| 95 | /* Try create pe2lx dll object. */ | 
|---|
| 96 | pWinMod = new Win32Pe2LxDll(hinstance, (ulPe2LxVersion & 0x80000000UL) == 0x80000000UL); | 
|---|
| 97 | if (pWinMod == NULL) | 
|---|
| 98 | { | 
|---|
| 99 | eprintf(("RegisterPe2LxDll: new returned a NULL-pointer\n")); | 
|---|
| 100 | return 0; | 
|---|
| 101 | } | 
|---|
| 102 | if (!pWinMod->init()) | 
|---|
| 103 | { | 
|---|
| 104 | eprintf(("RegisterPe2LxDll: init-method failed.\n")); | 
|---|
| 105 | delete pWinMod; | 
|---|
| 106 | return 0; | 
|---|
| 107 | } | 
|---|
| 108 |  | 
|---|
| 109 | /* @@@PH 1998/03/17 Console devices initialization */ | 
|---|
| 110 | iConsoleDevicesRegister(); | 
|---|
| 111 |  | 
|---|
| 112 | /* Add reference and attach dll to process. */ | 
|---|
| 113 | pWinMod->AddRef(); | 
|---|
| 114 | pWinMod->attachProcess(); | 
|---|
| 115 | } | 
|---|
| 116 | else | 
|---|
| 117 | {   /* process detach */ | 
|---|
| 118 | if (pWinMod != NULL && !fFreeLibrary) | 
|---|
| 119 | return 0;   /* don't unload (OS/2 dll unload bug) - see OS2.bugs in root dir. */ | 
|---|
| 120 | } | 
|---|
| 121 |  | 
|---|
| 122 | return 1;   /* success */ | 
|---|
| 123 | } | 
|---|
| 124 |  | 
|---|
| 125 |  | 
|---|
| 126 | /** | 
|---|
| 127 | * Constructor - creates an pe2lx dll object from a module handle to a pe2lx dll module. | 
|---|
| 128 | * @param     hinstance   Module handle. | 
|---|
| 129 | * @param     fWin32k     TRUE:  Win32k module. | 
|---|
| 130 | *                        FALSE: Pe2Lx module. | 
|---|
| 131 | * @status    completely implemented. | 
|---|
| 132 | * @author    Sander van Leeuwen, knut st. osmundsen | 
|---|
| 133 | */ | 
|---|
| 134 | Win32Pe2LxDll::Win32Pe2LxDll(HINSTANCE hinstance, BOOL fWin32k) | 
|---|
| 135 | : Win32ImageBase(hinstance), | 
|---|
| 136 | Win32DllBase(hinstance, NULL), | 
|---|
| 137 | Win32Pe2LxImage(hinstance, fWin32k) | 
|---|
| 138 | { | 
|---|
| 139 | dprintf(("Win32Pe2LxDll::Win32Pe2LxDll %s", szModule)); | 
|---|
| 140 | } | 
|---|
| 141 |  | 
|---|
| 142 |  | 
|---|
| 143 | /** | 
|---|
| 144 | * Destructor - does nothing. | 
|---|
| 145 | * @status    completely implemented. | 
|---|
| 146 | * @author    Sander van Leeuwen | 
|---|
| 147 | */ | 
|---|
| 148 | Win32Pe2LxDll::~Win32Pe2LxDll() | 
|---|
| 149 | { | 
|---|
| 150 | dprintf(("Win32Pe2LxDll::~Win32Pe2LxDll %s", szModule)); | 
|---|
| 151 | } | 
|---|
| 152 |  | 
|---|
| 153 |  | 
|---|
| 154 | /** | 
|---|
| 155 | * Init object. | 
|---|
| 156 | * Must be called immedeately after objecte construction. | 
|---|
| 157 | * @returns   Success indicator. (TRUE == success) | 
|---|
| 158 | * @sketch    call init method of the parten class. | 
|---|
| 159 | *            set dllEntryPoint | 
|---|
| 160 | * @status    completely implemented. | 
|---|
| 161 | * @author    knut st. osmundsen | 
|---|
| 162 | */ | 
|---|
| 163 | BOOL Win32Pe2LxDll::init() | 
|---|
| 164 | { | 
|---|
| 165 | if (Win32Pe2LxImage::init()) | 
|---|
| 166 | { | 
|---|
| 167 | /* set entry point. */ | 
|---|
| 168 | dllEntryPoint = (WIN32DLLENTRY)entryPoint; | 
|---|
| 169 | } | 
|---|
| 170 | else | 
|---|
| 171 | return FALSE; | 
|---|
| 172 | return TRUE; | 
|---|
| 173 | } | 
|---|
| 174 |  | 
|---|
| 175 | /** | 
|---|
| 176 | * Simple question: -Native LX dll? | 
|---|
| 177 | *                  -No! | 
|---|
| 178 | * @returns   FALSE. | 
|---|
| 179 | * @status    completely implemented. | 
|---|
| 180 | * @author    Sander van Leeuwen | 
|---|
| 181 | */ | 
|---|
| 182 | BOOL Win32Pe2LxDll::isLxDll() | 
|---|
| 183 | { | 
|---|
| 184 | return FALSE; | 
|---|
| 185 | } | 
|---|
| 186 |  | 
|---|