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