source: trunk/src/kernel32/windllpe2lx.cpp@ 22018

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

Merge branch gcc-kmk to trunk.

File size: 6.4 KB
Line 
1/* $Id: windllpe2lx.cpp,v 1.15 2004-01-15 10:39:08 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 "winexepe2lx.h"
31#include <wprocess.h>
32#include <odinpe.h>
33
34#include "oslibmisc.h" // OSLibGetDllName
35#include "conwin.h" // Windows Header for console only
36#include "console.h"
37
38#define DBG_LOCALLOG DBG_windllpe2lx
39#include "dbglocal.h"
40
41/*******************************************************************************
42* Global Variables *
43*******************************************************************************/
44extern BOOL fPeLoader;
45
46extern "C" {
47
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)
76{
77 char *pszName;
78
79 #if 1 /* temporary fix */
80 if (ulAttachType != 0UL)
81 return 0;
82 #endif
83
84 Win32Pe2LxDll *pWinMod = (Win32Pe2LxDll *)Win32DllBase::findModule(hinstance);
85 if (ulAttachType == 0UL)
86 { /* Process attach */
87
88 /* Get Lib name and match Pe2Lx version with kernel32 version. */
89 pszName = OSLibGetDllName(hinstance);
90 CheckVersion(ulPe2LxVersion & ~0x80000000UL, pszName);
91
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)));
97
98 /* Try create pe2lx dll object. */
99 pWinMod = new Win32Pe2LxDll(hinstance, (ulPe2LxVersion & 0x80000000UL) == 0x80000000UL);
100 if (pWinMod == NULL)
101 {
102 eprintf(("RegisterPe2LxDll: new returned a NULL-pointer\n"));
103 return 0;
104 }
105 if (pWinMod->init() != LDRERROR_SUCCESS)
106 {
107 eprintf(("RegisterPe2LxDll: init-method failed.\n"));
108 delete pWinMod;
109 return 0;
110 }
111
112 /* @@@PH 1998/03/17 Console devices initialization */
113 iConsoleDevicesRegister();
114
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"));
122 Win32Pe2LxExe::earlyInit();
123 }
124
125 /* Add reference and attach dll to process. */
126 pWinMod->AddRef();
127 pWinMod->attachProcess();
128 }
129 else
130 { /* process detach */
131 if (pWinMod != NULL)
132 return 0; /* don't unload (OS/2 dll unload bug) - see OS2.bugs in root dir. */
133 }
134
135 return 1; /* success */
136}
137
138} // extern "C"
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 */
148Win32Pe2LxDll::Win32Pe2LxDll(HINSTANCE hinstance, BOOL fWin32k)
149 : Win32ImageBase(hinstance),
150 Win32DllBase(hinstance, NULL),
151 Win32Pe2LxImage(hinstance, fWin32k)
152{
153 dprintf(("Win32Pe2LxDll::Win32Pe2LxDll %s", szModule));
154 fDll = TRUE;
155}
156
157
158/**
159 * Destructor - does nothing.
160 * @status completely implemented.
161 * @author Sander van Leeuwen
162 */
163Win32Pe2LxDll::~Win32Pe2LxDll()
164{
165 dprintf(("Win32Pe2LxDll::~Win32Pe2LxDll %s", szModule));
166}
167
168
169/**
170 * Init object.
171 * Must be called immedeately after objecte construction.
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
178 */
179DWORD Win32Pe2LxDll::init()
180{
181 DWORD rc = Win32Pe2LxImage::init();
182 if (rc == LDRERROR_SUCCESS)
183 {
184 /* set entry point. */
185 dllEntryPoint = (WIN32DLLENTRY)entryPoint;
186 }
187 return rc;
188}
189
190
191/**
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/**
204 * Simple question: -Native LX dll?
205 * -No!
206 * @returns FALSE.
207 * @status completely implemented.
208 * @author Sander van Leeuwen
209 */
210BOOL Win32Pe2LxDll::isLxDll() const
211{
212 return FALSE;
213}
214
215
216
Note: See TracBrowser for help on using the repository browser.