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

Last change on this file since 6211 was 6211, checked in by bird, 24 years ago

Early creatation and initiation of executable object (WinExe).

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