source: trunk/src/kernel32/windllpe2lx.cpp

Last change on this file was 21916, checked in by dmik, 14 years ago

Merge branch gcc-kmk to trunk.

File size: 6.4 KB
RevLine 
[10397]1/* $Id: windllpe2lx.cpp,v 1.15 2004-01-15 10:39:08 sandervl Exp $ */
[956]2
3/*
4 * Win32 PE2LX Dll class
5 *
6 * Copyright 1999 Sander van Leeuwen (sandervl@xs4all.nl)
[1274]7 * Copyright 1999 knut st. osmundsen (knut.stange.osmundsen@pmsc.no)
[956]8 *
9 * Project Odin Software License can be found in LICENSE.TXT
10 *
11 */
[1274]12
13/*******************************************************************************
14* Defined Constants And Macros *
15*******************************************************************************/
16#define INCL_DOSERRORS /* DOS Error values */
17#define INCL_DOSMODULEMGR /* DOS Module management */
[3059]18#define INCL_DOSSEMAPHORES
[1274]19
20/*******************************************************************************
21* Header Files *
22*******************************************************************************/
23#include <os2wrap.h> //Odin32 OS/2 api wrappers
24
[956]25#include <stdlib.h>
[1274]26
27#include <win32type.h>
[956]28#include <misc.h>
[21916]29#include "windllpe2lx.h"
30#include "winexepe2lx.h"
[956]31#include <wprocess.h>
[9540]32#include <odinpe.h>
[956]33
[1274]34#include "oslibmisc.h" // OSLibGetDllName
35#include "conwin.h" // Windows Header for console only
[956]36#include "console.h"
37
[6015]38#define DBG_LOCALLOG DBG_windllpe2lx
[2802]39#include "dbglocal.h"
[1274]40
[6301]41/*******************************************************************************
42* Global Variables *
43*******************************************************************************/
44extern BOOL fPeLoader;
[2802]45
[21916]46extern "C" {
47
[1274]48/**
49 * Register an Pe2Lx Dll module. Called from TIBFix code in Dll Pe2Lx module.
50 * @returns 1 on success.
51 * 0 on failure.
52 * @param Pe2LxVersion Pe2Lx version. High bit is Win32k indicator and must be masked off!
53 * @param hInstance Module handle (OS/2).
54 * @param dwAttachType 0 = attach dll
55 * 1 = detach dll
56 * @sketch Try find module.
57 * IF attach process THEN
58 * BEGIN
59 * END
60 * Init I/O.
61 * Get Lib name and match Pe2Lx version with kernel32 version.
62 * Write info to the log.
63 * Try create pe2lx dll object.
64 * Console devices initialization.
65 * Add reference and attach dll to process.
66 * ELSE
67 * BEGIN
68 * IF module found AND not freelibrary THEN
69 * fail (return 0) due to OS/2 bug.
70 * END
71 * return successfully (return 1)
72 * @status completely implemented.
73 * @author Sander van Leeuwen, knut st. osmundsen
74 */
75ULONG WIN32API RegisterPe2LxDll(ULONG ulPe2LxVersion, HINSTANCE hinstance, ULONG ulAttachType)
[956]76{
[1274]77 char *pszName;
[956]78
[2580]79 #if 1 /* temporary fix */
80 if (ulAttachType != 0UL)
81 return 0;
82 #endif
[956]83
[1274]84 Win32Pe2LxDll *pWinMod = (Win32Pe2LxDll *)Win32DllBase::findModule(hinstance);
85 if (ulAttachType == 0UL)
86 { /* Process attach */
[956]87
[1274]88 /* Get Lib name and match Pe2Lx version with kernel32 version. */
89 pszName = OSLibGetDllName(hinstance);
90 CheckVersion(ulPe2LxVersion & ~0x80000000UL, pszName);
[956]91
[1274]92 /* Write info to the log. */
93 dprintf(("RegisterPe2LxExe: ulPe2LxVersion = %#x\n", ulPe2LxVersion));
94 dprintf(("RegisterPe2LxExe: hinstance = %#x\n", hinstance));
95 dprintf(("RegisterPe2LxExe: ulAttachType = %#x (reason)\n", ulAttachType));
96 dprintf(("RegisterPe2LxExe: name = %s\n", OSLibGetDllName(hinstance)));
[956]97
[1274]98 /* Try create pe2lx dll object. */
[1325]99 pWinMod = new Win32Pe2LxDll(hinstance, (ulPe2LxVersion & 0x80000000UL) == 0x80000000UL);
100 if (pWinMod == NULL)
[1274]101 {
[1325]102 eprintf(("RegisterPe2LxDll: new returned a NULL-pointer\n"));
103 return 0;
[1274]104 }
[9540]105 if (pWinMod->init() != LDRERROR_SUCCESS)
[1274]106 {
[1325]107 eprintf(("RegisterPe2LxDll: init-method failed.\n"));
108 delete pWinMod;
109 return 0;
[1274]110 }
[1325]111
112 /* @@@PH 1998/03/17 Console devices initialization */
113 iConsoleDevicesRegister();
114
[6301]115 /*
116 * Before we attach the DLL we must make sure that we have a valid executable
117 * Should perhaps find a good way of checking for native LX binaries...
118 */
119 if (!WinExe && !fPeLoader)
120 {
121 dprintf(("RegisterPe2LxDll: tries to do an early exe init.\n"));
[6211]122 Win32Pe2LxExe::earlyInit();
[6301]123 }
[6211]124
[1325]125 /* Add reference and attach dll to process. */
126 pWinMod->AddRef();
127 pWinMod->attachProcess();
[1274]128 }
129 else
130 { /* process detach */
[3993]131 if (pWinMod != NULL)
[1274]132 return 0; /* don't unload (OS/2 dll unload bug) - see OS2.bugs in root dir. */
133 }
134
135 return 1; /* success */
[956]136}
[1274]137
[21916]138} // extern "C"
[1274]139
140/**
141 * Constructor - creates an pe2lx dll object from a module handle to a pe2lx dll module.
142 * @param hinstance Module handle.
143 * @param fWin32k TRUE: Win32k module.
144 * FALSE: Pe2Lx module.
145 * @status completely implemented.
146 * @author Sander van Leeuwen, knut st. osmundsen
147 */
[1325]148Win32Pe2LxDll::Win32Pe2LxDll(HINSTANCE hinstance, BOOL fWin32k)
[1274]149 : Win32ImageBase(hinstance),
150 Win32DllBase(hinstance, NULL),
151 Win32Pe2LxImage(hinstance, fWin32k)
[956]152{
[1274]153 dprintf(("Win32Pe2LxDll::Win32Pe2LxDll %s", szModule));
[6301]154 fDll = TRUE;
[956]155}
[1274]156
157
158/**
159 * Destructor - does nothing.
160 * @status completely implemented.
161 * @author Sander van Leeuwen
162 */
[956]163Win32Pe2LxDll::~Win32Pe2LxDll()
164{
[1274]165 dprintf(("Win32Pe2LxDll::~Win32Pe2LxDll %s", szModule));
[956]166}
[1274]167
168
169/**
[1325]170 * Init object.
171 * Must be called immedeately after objecte construction.
[9963]172 * @returns LDRERROR_SUCCESS on success.
173 * @returns Apporpriate LDRERROR_* on failure.
174 * @sketch call init method of the parten class.
175 * set dllEntryPoint
176 * @status completely implemented.
177 * @author knut st. osmundsen
[1325]178 */
[9963]179DWORD Win32Pe2LxDll::init()
[1325]180{
[9963]181 DWORD rc = Win32Pe2LxImage::init();
182 if (rc == LDRERROR_SUCCESS)
[1325]183 {
184 /* set entry point. */
185 dllEntryPoint = (WIN32DLLENTRY)entryPoint;
186 }
[9963]187 return rc;
[1325]188}
189
[6015]190
[1325]191/**
[6015]192 * Simple question: Pe2Lx DLL? Yes!
193 * @returns TRUE.
194 * @status completely implemented.
195 * @author knut st. osmundsen
196 */
197BOOL Win32Pe2LxDll::isPe2LxDll() const
198{
199 return TRUE;
200}
201
202
203/**
[1274]204 * Simple question: -Native LX dll?
205 * -No!
206 * @returns FALSE.
207 * @status completely implemented.
208 * @author Sander van Leeuwen
209 */
[6015]210BOOL Win32Pe2LxDll::isLxDll() const
[956]211{
[1274]212 return FALSE;
[956]213}
[1274]214
[6015]215
216
Note: See TracBrowser for help on using the repository browser.