| 1 | /* $Id: windllpe2lx.cpp,v 1.5 2000-01-31 09:40:07 bird 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 |
|
|---|
| 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 |
|
|---|
| 38 | /**
|
|---|
| 39 | * Register an Pe2Lx Dll module. Called from TIBFix code in Dll Pe2Lx module.
|
|---|
| 40 | * @returns 1 on success.
|
|---|
| 41 | * 0 on failure.
|
|---|
| 42 | * @param Pe2LxVersion Pe2Lx version. High bit is Win32k indicator and must be masked off!
|
|---|
| 43 | * @param hInstance Module handle (OS/2).
|
|---|
| 44 | * @param dwAttachType 0 = attach dll
|
|---|
| 45 | * 1 = detach dll
|
|---|
| 46 | * @sketch Try find module.
|
|---|
| 47 | * IF attach process THEN
|
|---|
| 48 | * BEGIN
|
|---|
| 49 | * END
|
|---|
| 50 | * Init I/O.
|
|---|
| 51 | * Get Lib name and match Pe2Lx version with kernel32 version.
|
|---|
| 52 | * Write info to the log.
|
|---|
| 53 | * Try create pe2lx dll object.
|
|---|
| 54 | * Console devices initialization.
|
|---|
| 55 | * Add reference and attach dll to process.
|
|---|
| 56 | * ELSE
|
|---|
| 57 | * BEGIN
|
|---|
| 58 | * IF module found AND not freelibrary THEN
|
|---|
| 59 | * fail (return 0) due to OS/2 bug.
|
|---|
| 60 | * END
|
|---|
| 61 | * return successfully (return 1)
|
|---|
| 62 | * @status completely implemented.
|
|---|
| 63 | * @author Sander van Leeuwen, knut st. osmundsen
|
|---|
| 64 | */
|
|---|
| 65 | ULONG WIN32API RegisterPe2LxDll(ULONG ulPe2LxVersion, HINSTANCE hinstance, ULONG ulAttachType)
|
|---|
| 66 | {
|
|---|
| 67 | char *pszName;
|
|---|
| 68 |
|
|---|
| 69 | #if 1 /* temporary fix */
|
|---|
| 70 | if (ulAttachType != 0UL)
|
|---|
| 71 | return 0;
|
|---|
| 72 | #endif
|
|---|
| 73 |
|
|---|
| 74 | Win32Pe2LxDll *pWinMod = (Win32Pe2LxDll *)Win32DllBase::findModule(hinstance);
|
|---|
| 75 | if (ulAttachType == 0UL)
|
|---|
| 76 | { /* Process attach */
|
|---|
| 77 |
|
|---|
| 78 | /* Init I/O */
|
|---|
| 79 | if (getenv("WIN32_IOPL2"))
|
|---|
| 80 | io_init1();
|
|---|
| 81 |
|
|---|
| 82 | /* Get Lib name and match Pe2Lx version with kernel32 version. */
|
|---|
| 83 | pszName = OSLibGetDllName(hinstance);
|
|---|
| 84 | CheckVersion(ulPe2LxVersion & ~0x80000000UL, pszName);
|
|---|
| 85 |
|
|---|
| 86 | /* Write info to the log. */
|
|---|
| 87 | dprintf(("RegisterPe2LxExe: ulPe2LxVersion = %#x\n", ulPe2LxVersion));
|
|---|
| 88 | dprintf(("RegisterPe2LxExe: hinstance = %#x\n", hinstance));
|
|---|
| 89 | dprintf(("RegisterPe2LxExe: ulAttachType = %#x (reason)\n", ulAttachType));
|
|---|
| 90 | dprintf(("RegisterPe2LxExe: name = %s\n", OSLibGetDllName(hinstance)));
|
|---|
| 91 |
|
|---|
| 92 | /* Try create pe2lx dll object. */
|
|---|
| 93 | pWinMod = new Win32Pe2LxDll(hinstance, (ulPe2LxVersion & 0x80000000UL) == 0x80000000UL);
|
|---|
| 94 | if (pWinMod == NULL)
|
|---|
| 95 | {
|
|---|
| 96 | eprintf(("RegisterPe2LxDll: new returned a NULL-pointer\n"));
|
|---|
| 97 | return 0;
|
|---|
| 98 | }
|
|---|
| 99 | if (!pWinMod->init())
|
|---|
| 100 | {
|
|---|
| 101 | eprintf(("RegisterPe2LxDll: init-method failed.\n"));
|
|---|
| 102 | delete pWinMod;
|
|---|
| 103 | return 0;
|
|---|
| 104 | }
|
|---|
| 105 |
|
|---|
| 106 | /* @@@PH 1998/03/17 Console devices initialization */
|
|---|
| 107 | iConsoleDevicesRegister();
|
|---|
| 108 |
|
|---|
| 109 | /* Add reference and attach dll to process. */
|
|---|
| 110 | pWinMod->AddRef();
|
|---|
| 111 | pWinMod->attachProcess();
|
|---|
| 112 | }
|
|---|
| 113 | else
|
|---|
| 114 | { /* process detach */
|
|---|
| 115 | if (pWinMod != NULL && !fFreeLibrary)
|
|---|
| 116 | return 0; /* don't unload (OS/2 dll unload bug) - see OS2.bugs in root dir. */
|
|---|
| 117 | }
|
|---|
| 118 |
|
|---|
| 119 | return 1; /* success */
|
|---|
| 120 | }
|
|---|
| 121 |
|
|---|
| 122 |
|
|---|
| 123 | /**
|
|---|
| 124 | * Constructor - creates an pe2lx dll object from a module handle to a pe2lx dll module.
|
|---|
| 125 | * @param hinstance Module handle.
|
|---|
| 126 | * @param fWin32k TRUE: Win32k module.
|
|---|
| 127 | * FALSE: Pe2Lx module.
|
|---|
| 128 | * @status completely implemented.
|
|---|
| 129 | * @author Sander van Leeuwen, knut st. osmundsen
|
|---|
| 130 | */
|
|---|
| 131 | Win32Pe2LxDll::Win32Pe2LxDll(HINSTANCE hinstance, BOOL fWin32k)
|
|---|
| 132 | : Win32ImageBase(hinstance),
|
|---|
| 133 | Win32DllBase(hinstance, NULL),
|
|---|
| 134 | Win32Pe2LxImage(hinstance, fWin32k)
|
|---|
| 135 | {
|
|---|
| 136 | dprintf(("Win32Pe2LxDll::Win32Pe2LxDll %s", szModule));
|
|---|
| 137 | }
|
|---|
| 138 |
|
|---|
| 139 |
|
|---|
| 140 | /**
|
|---|
| 141 | * Destructor - does nothing.
|
|---|
| 142 | * @status completely implemented.
|
|---|
| 143 | * @author Sander van Leeuwen
|
|---|
| 144 | */
|
|---|
| 145 | Win32Pe2LxDll::~Win32Pe2LxDll()
|
|---|
| 146 | {
|
|---|
| 147 | dprintf(("Win32Pe2LxDll::~Win32Pe2LxDll %s", szModule));
|
|---|
| 148 | }
|
|---|
| 149 |
|
|---|
| 150 |
|
|---|
| 151 | /**
|
|---|
| 152 | * Init object.
|
|---|
| 153 | * Must be called immedeately after objecte construction.
|
|---|
| 154 | * @returns Success indicator. (TRUE == success)
|
|---|
| 155 | * @sketch call init method of the parten class.
|
|---|
| 156 | * set dllEntryPoint
|
|---|
| 157 | * @status completely implemented.
|
|---|
| 158 | * @author knut st. osmundsen
|
|---|
| 159 | */
|
|---|
| 160 | BOOL Win32Pe2LxDll::init()
|
|---|
| 161 | {
|
|---|
| 162 | if (Win32Pe2LxImage::init())
|
|---|
| 163 | {
|
|---|
| 164 | /* set entry point. */
|
|---|
| 165 | dllEntryPoint = (WIN32DLLENTRY)entryPoint;
|
|---|
| 166 | }
|
|---|
| 167 | else
|
|---|
| 168 | return FALSE;
|
|---|
| 169 | return TRUE;
|
|---|
| 170 | }
|
|---|
| 171 |
|
|---|
| 172 | /**
|
|---|
| 173 | * Simple question: -Native LX dll?
|
|---|
| 174 | * -No!
|
|---|
| 175 | * @returns FALSE.
|
|---|
| 176 | * @status completely implemented.
|
|---|
| 177 | * @author Sander van Leeuwen
|
|---|
| 178 | */
|
|---|
| 179 | BOOL Win32Pe2LxDll::isLxDll()
|
|---|
| 180 | {
|
|---|
| 181 | return FALSE;
|
|---|
| 182 | }
|
|---|
| 183 |
|
|---|