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

Last change on this file since 1274 was 1274, checked in by bird, 26 years ago

New Pe2Lx implementation.

File size: 6.4 KB
Line 
1/* $Id: windllpe2lx.cpp,v 1.2 1999-10-14 01:37:55 bird 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 */
65ULONG 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 try
91 {
92 pWinMod = new Win32Pe2LxDll(hinstance, (ulPe2LxVersion & 0x80000000UL) == 0x80000000UL);
93 if (pWinMod == NULL)
94 throw ((ULONG)ERROR_NOT_ENOUGH_MEMORY);
95
96 /* @@@PH 1998/03/17 Console devices initialization */
97 iConsoleDevicesRegister();
98
99 /* Add reference and attach dll to process. */
100 pWinMod->AddRef();
101 pWinMod->attachProcess();
102 }
103 catch(ULONG ul)
104 {
105 eprintf(("RegisterPe2LxDLL: Failed to create module object, ul=%d\n", ul));
106 DebugInt3();
107 return 0; /* fail dll load */
108 }
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 #if 0 /* Runtime environment could already be gone, so don't do this */
116 dprintf(("KERNEL32: Dll Removed by FreeLibrary or ExitProcess\n"));
117 #endif
118 }
119
120 return 1; /* success */
121}
122
123
124/**
125 * Constructor - creates an pe2lx dll object from a module handle to a pe2lx dll module.
126 * @param hinstance Module handle.
127 * @param fWin32k TRUE: Win32k module.
128 * FALSE: Pe2Lx module.
129 * @status completely implemented.
130 * @author Sander van Leeuwen, knut st. osmundsen
131 */
132Win32Pe2LxDll::Win32Pe2LxDll(HINSTANCE hinstance, BOOL fWin32k) throw(ULONG)
133 : Win32ImageBase(hinstance),
134 Win32DllBase(hinstance, NULL),
135 Win32Pe2LxImage(hinstance, fWin32k)
136{
137 dprintf(("Win32Pe2LxDll::Win32Pe2LxDll %s", szModule));
138 /* set entry point. */
139 dllEntryPoint = (WIN32DLLENTRY)entryPoint;
140}
141
142
143/**
144 * Destructor - does nothing.
145 * @status completely implemented.
146 * @author Sander van Leeuwen
147 */
148Win32Pe2LxDll::~Win32Pe2LxDll()
149{
150 dprintf(("Win32Pe2LxDll::~Win32Pe2LxDll %s", szModule));
151}
152
153
154/**
155 * Gets pointer to an exported procedure by procedure name.
156 * @returns Address of exported procedure. 0UL if not found.
157 * @param name Exported procedure name.
158 * @status completely implemented.
159 * @author Sander van Leeuwen
160 * @remark
161 */
162ULONG Win32Pe2LxDll::getApi(char *name)
163{
164 APIRET rc;
165 ULONG ulApiAddr;
166
167 rc = DosQueryProcAddr(hinstance, 0, name, (PFN *)&ulApiAddr);
168 return rc == NO_ERROR ? ulApiAddr : 0;
169}
170
171
172/**
173 * Gets pointer to an exported procedure by ordinal.
174 * @returns Pointer to an exported procedure. 0UL if not found.
175 * @param ordinal Export ordinal number.
176 * @status completely implemented.
177 * @author Sander van Leeuwen
178 * @remark FIXME:
179 * This function should be implemented for both Exe and Dll images!
180 * It could be done similar in both peldr image and pe2lx images by
181 * accessing PE structures.
182 */
183ULONG Win32Pe2LxDll::getApi(int ordinal)
184{
185 APIRET rc;
186 ULONG ulApiAddr;
187
188 rc = DosQueryProcAddr(hinstance, ordinal, NULL, (PFN *)&ulApiAddr);
189
190 return rc == NO_ERROR ? ulApiAddr : 0;
191}
192
193
194/**
195 * Simple question: -Native LX dll?
196 * -No!
197 * @returns FALSE.
198 * @status completely implemented.
199 * @author Sander van Leeuwen
200 */
201BOOL Win32Pe2LxDll::isLxDll()
202{
203 return FALSE;
204}
205
Note: See TracBrowser for help on using the repository browser.