1 | /* $Id: windllpe2lx.cpp,v 1.4 1999-11-26 00:05:19 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 |
|
---|
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 | //DebugInt3();
|
---|
70 |
|
---|
71 | Win32Pe2LxDll *pWinMod = (Win32Pe2LxDll *)Win32DllBase::findModule(hinstance);
|
---|
72 | if (ulAttachType == 0UL)
|
---|
73 | { /* Process attach */
|
---|
74 |
|
---|
75 | /* Init I/O */
|
---|
76 | if (getenv("WIN32_IOPL2"))
|
---|
77 | io_init1();
|
---|
78 |
|
---|
79 | /* Get Lib name and match Pe2Lx version with kernel32 version. */
|
---|
80 | pszName = OSLibGetDllName(hinstance);
|
---|
81 | CheckVersion(ulPe2LxVersion & ~0x80000000UL, pszName);
|
---|
82 |
|
---|
83 | /* Write info to the log. */
|
---|
84 | dprintf(("RegisterPe2LxExe: ulPe2LxVersion = %#x\n", ulPe2LxVersion));
|
---|
85 | dprintf(("RegisterPe2LxExe: hinstance = %#x\n", hinstance));
|
---|
86 | dprintf(("RegisterPe2LxExe: ulAttachType = %#x (reason)\n", ulAttachType));
|
---|
87 | dprintf(("RegisterPe2LxExe: name = %s\n", OSLibGetDllName(hinstance)));
|
---|
88 |
|
---|
89 | /* Try create pe2lx dll object. */
|
---|
90 | pWinMod = new Win32Pe2LxDll(hinstance, (ulPe2LxVersion & 0x80000000UL) == 0x80000000UL);
|
---|
91 | if (pWinMod == NULL)
|
---|
92 | {
|
---|
93 | eprintf(("RegisterPe2LxDll: new returned a NULL-pointer\n"));
|
---|
94 | return 0;
|
---|
95 | }
|
---|
96 | if (!pWinMod->init())
|
---|
97 | {
|
---|
98 | eprintf(("RegisterPe2LxDll: init-method failed.\n"));
|
---|
99 | delete pWinMod;
|
---|
100 | return 0;
|
---|
101 | }
|
---|
102 |
|
---|
103 | /* @@@PH 1998/03/17 Console devices initialization */
|
---|
104 | iConsoleDevicesRegister();
|
---|
105 |
|
---|
106 | /* Add reference and attach dll to process. */
|
---|
107 | pWinMod->AddRef();
|
---|
108 | pWinMod->attachProcess();
|
---|
109 | }
|
---|
110 | else
|
---|
111 | { /* process detach */
|
---|
112 | if (pWinMod != NULL && !fFreeLibrary)
|
---|
113 | return 0; /* don't unload (OS/2 dll unload bug) - see OS2.bugs in root dir. */
|
---|
114 | }
|
---|
115 |
|
---|
116 | return 1; /* success */
|
---|
117 | }
|
---|
118 |
|
---|
119 |
|
---|
120 | /**
|
---|
121 | * Constructor - creates an pe2lx dll object from a module handle to a pe2lx dll module.
|
---|
122 | * @param hinstance Module handle.
|
---|
123 | * @param fWin32k TRUE: Win32k module.
|
---|
124 | * FALSE: Pe2Lx module.
|
---|
125 | * @status completely implemented.
|
---|
126 | * @author Sander van Leeuwen, knut st. osmundsen
|
---|
127 | */
|
---|
128 | Win32Pe2LxDll::Win32Pe2LxDll(HINSTANCE hinstance, BOOL fWin32k)
|
---|
129 | : Win32ImageBase(hinstance),
|
---|
130 | Win32DllBase(hinstance, NULL),
|
---|
131 | Win32Pe2LxImage(hinstance, fWin32k)
|
---|
132 | {
|
---|
133 | dprintf(("Win32Pe2LxDll::Win32Pe2LxDll %s", szModule));
|
---|
134 | }
|
---|
135 |
|
---|
136 |
|
---|
137 | /**
|
---|
138 | * Destructor - does nothing.
|
---|
139 | * @status completely implemented.
|
---|
140 | * @author Sander van Leeuwen
|
---|
141 | */
|
---|
142 | Win32Pe2LxDll::~Win32Pe2LxDll()
|
---|
143 | {
|
---|
144 | dprintf(("Win32Pe2LxDll::~Win32Pe2LxDll %s", szModule));
|
---|
145 | }
|
---|
146 |
|
---|
147 |
|
---|
148 | /**
|
---|
149 | * Init object.
|
---|
150 | * Must be called immedeately after objecte construction.
|
---|
151 | * @returns Success indicator. (TRUE == success)
|
---|
152 | * @sketch call init method of the parten class.
|
---|
153 | * set dllEntryPoint
|
---|
154 | * @status completely implemented.
|
---|
155 | * @author knut st. osmundsen
|
---|
156 | */
|
---|
157 | BOOL Win32Pe2LxDll::init()
|
---|
158 | {
|
---|
159 | if (Win32Pe2LxImage::init())
|
---|
160 | {
|
---|
161 | /* set entry point. */
|
---|
162 | dllEntryPoint = (WIN32DLLENTRY)entryPoint;
|
---|
163 | }
|
---|
164 | else
|
---|
165 | return FALSE;
|
---|
166 | return TRUE;
|
---|
167 | }
|
---|
168 |
|
---|
169 | /**
|
---|
170 | * Simple question: -Native LX dll?
|
---|
171 | * -No!
|
---|
172 | * @returns FALSE.
|
---|
173 | * @status completely implemented.
|
---|
174 | * @author Sander van Leeuwen
|
---|
175 | */
|
---|
176 | BOOL Win32Pe2LxDll::isLxDll()
|
---|
177 | {
|
---|
178 | return FALSE;
|
---|
179 | }
|
---|
180 |
|
---|