source: trunk/src/kernel32/winexepe2lx.cpp@ 7029

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

Early creatation and initiation of executable object (WinExe).

File size: 5.8 KB
Line 
1/* $Id: winexepe2lx.cpp,v 1.10 2001-07-08 02:49:47 bird Exp $ */
2
3/*
4 * Win32 PE2LX Exe class
5 *
6 * Copyright 1998-1999 Sander van Leeuwen (sandervl@xs4all.nl)
7 * Copyright 1999-2000 knut st. osmundsen (knut.stange.osmundsen@mynd.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
18
19/*******************************************************************************
20* Header Files *
21*******************************************************************************/
22#include <os2wrap.h> //Odin32 OS/2 api wrappers
23
24#include <stdlib.h> //getenv
25
26#include <misc.h>
27#include <win32type.h>
28#include <win32k.h>
29#include "winexepe2lx.h"
30
31#include "cio.h" // I/O
32#include "oslibmisc.h" // OSLibGetDllName
33#include "conwin.h" // Windows Header for console only
34#include "console.h"
35
36#define DBG_LOCALLOG DBG_winexepe2lx
37#include "dbglocal.h"
38
39
40/*******************************************************************************
41* Global Variables *
42*******************************************************************************/
43BOOL Win32Pe2LxExe::fEarlyInit = FALSE;
44
45
46/**
47 * Register a Pe2Lx Executable module.
48 * This is called from the TIBFix code in the Pe2Lx exe. It creates the WinExe object from
49 * the instance handle passed in.
50 * @param ulPe2LxVersion Pe2Lx version number.
51 * @param hinstance Module handle.
52 * @param ulReserved Reserved.
53 * @sketch I/O init.
54 * Check that pe2lx version matches the version of kernel32.dll.
55 * Frees WinExe if is not NULL - should never happen!
56 * Write info to the log.
57 * Create Pe2Lx Exe object.
58 * Call start (which calls the entry point).
59 * @status completely implemented.
60 * @author Sander van Leeuwen, knut st. osmundsen
61 */
62void WIN32API RegisterPe2LxExe(ULONG ulPe2LxVersion, HINSTANCE hinstance, ULONG ulReserved)
63{
64 Win32Pe2LxExe *pWinPe2LxExe;
65
66 /* I/O init. */
67 if (getenv("WIN32_IOPL2"))
68 io_init1();
69
70 /* Check that pe2lx version matches the version of kernel32.dll. */
71 CheckVersion(ulPe2LxVersion & ~0x80000000UL, OSLibGetDllName(hinstance));
72
73 /* Write info to the log. */
74 dprintf(("RegisterPe2LxExe: ulPe2LxVersion = %#x\n", ulPe2LxVersion));
75 dprintf(("RegisterPe2LxExe: hinstance = %#x\n", hinstance));
76 dprintf(("RegisterPe2LxExe: ulReserved = %#x\n", ulReserved));
77 dprintf(("RegisterPe2LxExe: name = %s\n", OSLibGetDllName(hinstance)));
78
79 /* Might allready be initiated because of early init. */
80 if ( WinExe != NULL
81 && ( (ulPe2LxVersion & 0x80000000UL) != 0x80000000UL)
82 || !Win32Pe2LxExe::fEarlyInit)
83 {
84 delete WinExe;
85 WinExe = NULL;
86 }
87
88 if (WinExe == NULL)
89 {
90 /* Create Pe2Lx Exe object. */
91 pWinPe2LxExe = new Win32Pe2LxExe(hinstance, (ulPe2LxVersion & 0x80000000UL) == 0x80000000UL);
92 if (pWinPe2LxExe == NULL)
93 {
94 eprintf(("RegisterPe2LxExe: new returned a NULL-pointer\n"));
95 return;
96 }
97 if (!pWinPe2LxExe->init())
98 {
99 eprintf(("RegisterPe2LxExe: init-method failed.\n"));
100 delete pWinPe2LxExe;
101 return;
102 }
103 }
104 else
105 pWinPe2LxExe = (Win32Pe2LxExe*)WinExe;
106
107 /* Call start (which calls the entry point). */
108 /*DebugInt3();*/
109 pWinPe2LxExe->start();
110}
111
112
113/**
114 * Constructor - creates an pe2lx exe object from a module handle to a pe2lx exe module.
115 * @param hinstance Module handle.
116 * @param fWin32k TRUE: Win32k module.
117 * FALSE: Pe2Lx module.
118 * @status completely implmented.
119 * @author Sander van Leeuwen, knut st. osmundsen
120 * @remark Win32Pe2LxImage may throw an exception!
121 */
122Win32Pe2LxExe::Win32Pe2LxExe(HINSTANCE hinstance, BOOL fWin32k)
123 : Win32ImageBase(hinstance),
124 Win32ExeBase(hinstance),
125 Win32Pe2LxImage(hinstance, fWin32k)
126{
127}
128
129
130/**
131 * Destructor - does nothing.
132 * @status completely implemented.
133 * @author Sander van Leeuwen
134 */
135Win32Pe2LxExe::~Win32Pe2LxExe()
136{
137
138}
139
140
141/**
142 * Init object.
143 * Must be called immedeately after the object construction.
144 * @returns Success indicator. (TRUE == success)
145 * @sketch
146 * @status completely implemented.
147 * @author knut st. osmundsen
148 */
149BOOL Win32Pe2LxExe::init()
150{
151 if (Win32Pe2LxImage::init())
152 {
153 fConsoleApp = pNtHdrs->OptionalHeader.Subsystem == IMAGE_SUBSYSTEM_WINDOWS_CUI;
154
155 /* console app? */
156 if (fConsoleApp)
157 {
158 APIRET rc;
159
160 dprintf(("Console application!\n"));
161
162 rc = iConsoleInit(TRUE); /* initialize console subsystem */
163 if (rc != NO_ERROR) /* check for errors */
164 dprintf(("KERNEL32:Win32Image:Init ConsoleInit failed with %u.\n", rc));
165 }
166 }
167 else
168 return FALSE;
169 return TRUE;
170}
171
172
173
174/**
175 * Preinitiate the executable before RegisterPe2LxExe is called.
176 * This is done by the first Pe2Lx DLL which is loaded.
177 *
178 * @returns Success idicator.
179 * @status
180 * @author knut st. osmundsen (kosmunds@csc.no)
181 * @remark
182 */
183BOOL Win32Pe2LxExe::earlyInit()
184{
185 /*
186 * Try make an win32k loaded executable object.
187 */
188 Win32Pe2LxExe * pExe = new Win32Pe2LxExe((HINSTANCE)OSLibGetPIB(PIB_TASKHNDL), libWin32kInstalled());
189 if (pExe)
190 {
191 if (pExe->init())
192 {
193 WinExe = pExe;
194 return fEarlyInit = TRUE;
195 }
196 }
197
198 return FALSE;
199}
200
Note: See TracBrowser for help on using the repository browser.