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

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

No exception throwing. Constructors is moved into an init method.
TLS is now implemented, but not tested.

File size: 6.6 KB
Line 
1/* $Id: windllpe2lx.cpp,v 1.3 1999-10-17 01:49:08 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 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 */
128Win32Pe2LxDll::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 */
142Win32Pe2LxDll::~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 */
157BOOL 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 * Gets pointer to an exported procedure by procedure name.
171 * @returns Address of exported procedure. 0UL if not found.
172 * @param name Exported procedure name.
173 * @status completely implemented.
174 * @author Sander van Leeuwen
175 * @remark
176 */
177ULONG Win32Pe2LxDll::getApi(char *name)
178{
179 APIRET rc;
180 ULONG ulApiAddr;
181
182 rc = DosQueryProcAddr(hinstance, 0, name, (PFN *)&ulApiAddr);
183 return rc == NO_ERROR ? ulApiAddr : 0;
184}
185
186
187/**
188 * Gets pointer to an exported procedure by ordinal.
189 * @returns Pointer to an exported procedure. 0UL if not found.
190 * @param ordinal Export ordinal number.
191 * @status completely implemented.
192 * @author Sander van Leeuwen
193 * @remark FIXME:
194 * This function should be implemented for both Exe and Dll images!
195 * It could be done similar in both peldr image and pe2lx images by
196 * accessing PE structures.
197 */
198ULONG Win32Pe2LxDll::getApi(int ordinal)
199{
200 APIRET rc;
201 ULONG ulApiAddr;
202
203 rc = DosQueryProcAddr(hinstance, ordinal, NULL, (PFN *)&ulApiAddr);
204
205 return rc == NO_ERROR ? ulApiAddr : 0;
206}
207
208
209/**
210 * Simple question: -Native LX dll?
211 * -No!
212 * @returns FALSE.
213 * @status completely implemented.
214 * @author Sander van Leeuwen
215 */
216BOOL Win32Pe2LxDll::isLxDll()
217{
218 return FALSE;
219}
220
Note: See TracBrowser for help on using the repository browser.