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 | *******************************************************************************/
|
---|
44 | extern BOOL fPeLoader;
|
---|
45 |
|
---|
46 | /**
|
---|
47 | * Register an Pe2Lx Dll module. Called from TIBFix code in Dll Pe2Lx module.
|
---|
48 | * @returns 1 on success.
|
---|
49 | * 0 on failure.
|
---|
50 | * @param Pe2LxVersion Pe2Lx version. High bit is Win32k indicator and must be masked off!
|
---|
51 | * @param hInstance Module handle (OS/2).
|
---|
52 | * @param dwAttachType 0 = attach dll
|
---|
53 | * 1 = detach dll
|
---|
54 | * @sketch Try find module.
|
---|
55 | * IF attach process THEN
|
---|
56 | * BEGIN
|
---|
57 | * END
|
---|
58 | * Init I/O.
|
---|
59 | * Get Lib name and match Pe2Lx version with kernel32 version.
|
---|
60 | * Write info to the log.
|
---|
61 | * Try create pe2lx dll object.
|
---|
62 | * Console devices initialization.
|
---|
63 | * Add reference and attach dll to process.
|
---|
64 | * ELSE
|
---|
65 | * BEGIN
|
---|
66 | * IF module found AND not freelibrary THEN
|
---|
67 | * fail (return 0) due to OS/2 bug.
|
---|
68 | * END
|
---|
69 | * return successfully (return 1)
|
---|
70 | * @status completely implemented.
|
---|
71 | * @author Sander van Leeuwen, knut st. osmundsen
|
---|
72 | */
|
---|
73 | ULONG WIN32API RegisterPe2LxDll(ULONG ulPe2LxVersion, HINSTANCE hinstance, ULONG ulAttachType)
|
---|
74 | {
|
---|
75 | char *pszName;
|
---|
76 |
|
---|
77 | #if 1 /* temporary fix */
|
---|
78 | if (ulAttachType != 0UL)
|
---|
79 | return 0;
|
---|
80 | #endif
|
---|
81 |
|
---|
82 | Win32Pe2LxDll *pWinMod = (Win32Pe2LxDll *)Win32DllBase::findModule(hinstance);
|
---|
83 | if (ulAttachType == 0UL)
|
---|
84 | { /* Process attach */
|
---|
85 |
|
---|
86 | /* Get Lib name and match Pe2Lx version with kernel32 version. */
|
---|
87 | pszName = OSLibGetDllName(hinstance);
|
---|
88 | CheckVersion(ulPe2LxVersion & ~0x80000000UL, pszName);
|
---|
89 |
|
---|
90 | /* Write info to the log. */
|
---|
91 | dprintf(("RegisterPe2LxExe: ulPe2LxVersion = %#x\n", ulPe2LxVersion));
|
---|
92 | dprintf(("RegisterPe2LxExe: hinstance = %#x\n", hinstance));
|
---|
93 | dprintf(("RegisterPe2LxExe: ulAttachType = %#x (reason)\n", ulAttachType));
|
---|
94 | dprintf(("RegisterPe2LxExe: name = %s\n", OSLibGetDllName(hinstance)));
|
---|
95 |
|
---|
96 | /* Try create pe2lx dll object. */
|
---|
97 | pWinMod = new Win32Pe2LxDll(hinstance, (ulPe2LxVersion & 0x80000000UL) == 0x80000000UL);
|
---|
98 | if (pWinMod == NULL)
|
---|
99 | {
|
---|
100 | eprintf(("RegisterPe2LxDll: new returned a NULL-pointer\n"));
|
---|
101 | return 0;
|
---|
102 | }
|
---|
103 | if (pWinMod->init() != LDRERROR_SUCCESS)
|
---|
104 | {
|
---|
105 | eprintf(("RegisterPe2LxDll: init-method failed.\n"));
|
---|
106 | delete pWinMod;
|
---|
107 | return 0;
|
---|
108 | }
|
---|
109 |
|
---|
110 | /* @@@PH 1998/03/17 Console devices initialization */
|
---|
111 | iConsoleDevicesRegister();
|
---|
112 |
|
---|
113 | /*
|
---|
114 | * Before we attach the DLL we must make sure that we have a valid executable
|
---|
115 | * Should perhaps find a good way of checking for native LX binaries...
|
---|
116 | */
|
---|
117 | if (!WinExe && !fPeLoader)
|
---|
118 | {
|
---|
119 | dprintf(("RegisterPe2LxDll: tries to do an early exe init.\n"));
|
---|
120 | Win32Pe2LxExe::earlyInit();
|
---|
121 | }
|
---|
122 |
|
---|
123 | /* Add reference and attach dll to process. */
|
---|
124 | pWinMod->AddRef();
|
---|
125 | pWinMod->attachProcess();
|
---|
126 | }
|
---|
127 | else
|
---|
128 | { /* process detach */
|
---|
129 | if (pWinMod != NULL)
|
---|
130 | return 0; /* don't unload (OS/2 dll unload bug) - see OS2.bugs in root dir. */
|
---|
131 | }
|
---|
132 |
|
---|
133 | return 1; /* success */
|
---|
134 | }
|
---|
135 |
|
---|
136 |
|
---|
137 | /**
|
---|
138 | * Constructor - creates an pe2lx dll object from a module handle to a pe2lx dll module.
|
---|
139 | * @param hinstance Module handle.
|
---|
140 | * @param fWin32k TRUE: Win32k module.
|
---|
141 | * FALSE: Pe2Lx module.
|
---|
142 | * @status completely implemented.
|
---|
143 | * @author Sander van Leeuwen, knut st. osmundsen
|
---|
144 | */
|
---|
145 | Win32Pe2LxDll::Win32Pe2LxDll(HINSTANCE hinstance, BOOL fWin32k)
|
---|
146 | : Win32ImageBase(hinstance),
|
---|
147 | Win32DllBase(hinstance, NULL),
|
---|
148 | Win32Pe2LxImage(hinstance, fWin32k)
|
---|
149 | {
|
---|
150 | dprintf(("Win32Pe2LxDll::Win32Pe2LxDll %s", szModule));
|
---|
151 | fDll = TRUE;
|
---|
152 | }
|
---|
153 |
|
---|
154 |
|
---|
155 | /**
|
---|
156 | * Destructor - does nothing.
|
---|
157 | * @status completely implemented.
|
---|
158 | * @author Sander van Leeuwen
|
---|
159 | */
|
---|
160 | Win32Pe2LxDll::~Win32Pe2LxDll()
|
---|
161 | {
|
---|
162 | dprintf(("Win32Pe2LxDll::~Win32Pe2LxDll %s", szModule));
|
---|
163 | }
|
---|
164 |
|
---|
165 |
|
---|
166 | /**
|
---|
167 | * Init object.
|
---|
168 | * Must be called immedeately after objecte construction.
|
---|
169 | * @returns LDRERROR_SUCCESS on success.
|
---|
170 | * @returns Apporpriate LDRERROR_* on failure.
|
---|
171 | * @sketch call init method of the parten class.
|
---|
172 | * set dllEntryPoint
|
---|
173 | * @status completely implemented.
|
---|
174 | * @author knut st. osmundsen
|
---|
175 | */
|
---|
176 | DWORD Win32Pe2LxDll::init()
|
---|
177 | {
|
---|
178 | DWORD rc = Win32Pe2LxImage::init();
|
---|
179 | if (rc == LDRERROR_SUCCESS)
|
---|
180 | {
|
---|
181 | /* set entry point. */
|
---|
182 | dllEntryPoint = (WIN32DLLENTRY)entryPoint;
|
---|
183 | }
|
---|
184 | return rc;
|
---|
185 | }
|
---|
186 |
|
---|
187 |
|
---|
188 | /**
|
---|
189 | * Simple question: Pe2Lx DLL? Yes!
|
---|
190 | * @returns TRUE.
|
---|
191 | * @status completely implemented.
|
---|
192 | * @author knut st. osmundsen
|
---|
193 | */
|
---|
194 | BOOL Win32Pe2LxDll::isPe2LxDll() const
|
---|
195 | {
|
---|
196 | return TRUE;
|
---|
197 | }
|
---|
198 |
|
---|
199 |
|
---|
200 | /**
|
---|
201 | * Simple question: -Native LX dll?
|
---|
202 | * -No!
|
---|
203 | * @returns FALSE.
|
---|
204 | * @status completely implemented.
|
---|
205 | * @author Sander van Leeuwen
|
---|
206 | */
|
---|
207 | BOOL Win32Pe2LxDll::isLxDll() const
|
---|
208 | {
|
---|
209 | return FALSE;
|
---|
210 | }
|
---|
211 |
|
---|
212 |
|
---|
213 |
|
---|