source: trunk/src/kernel32/initterm.cpp@ 6373

Last change on this file since 6373 was 6340, checked in by sandervl, 24 years ago

Do not use imports not available in Warp 3's PMWINX (WaitForInputIdle)

File size: 9.1 KB
Line 
1/*
2 * KERNEL32 DLL entry point
3 *
4 * Copyright 1998 Sander van Leeuwen
5 * Copyright 1998 Peter Fitzsimmons
6 *
7 *
8 * Project Odin Software License can be found in LICENSE.TXT
9 *
10 */
11
12/*-------------------------------------------------------------*/
13/* INITERM.C -- Source for a custom dynamic link library */
14/* initialization and termination (_DLL_InitTerm) */
15/* function. */
16/* */
17/* When called to perform initialization, this sample function */
18/* gets storage for an array of integers, and initializes its */
19/* elements with random integers. At termination time, it */
20/* frees the array. Substitute your own special processing. */
21/*-------------------------------------------------------------*/
22
23
24/* Include files */
25#define INCL_DOSMODULEMGR
26#define INCL_DOSMISC
27#define INCL_DOSPROCESS
28#define INCL_DOSSEMAPHORES
29#include <os2wrap.h> //Odin32 OS/2 api wrappers
30#include <stdlib.h>
31#include <stdio.h>
32#include <string.h>
33#include <misc.h>
34#include <wprocess.h>
35#include "handlemanager.h"
36#include "profile.h"
37#include <options.h>
38#include "initterm.h"
39#include <win32type.h>
40#include <odinlx.h>
41#include "oslibmisc.h"
42#include <heapshared.h>
43#include <heapcode.h>
44#include "mmap.h"
45#include "directory.h"
46#include "hmdevio.h"
47#include <windllbase.h>
48#include "winexepe2lx.h"
49#include <exitlist.h>
50#include "oslibdos.h"
51#include <cpuhlp.h>
52#include <Win32k.h>
53#include <initdll.h>
54#include <codepage.h>
55#include <process.h>
56
57#define DBG_LOCALLOG DBG_initterm
58#include "dbglocal.h"
59
60PVOID SYSTEM _O32_GetEnvironmentStrings( VOID );
61BOOL fVersionWarp3 = FALSE;
62
63/*-------------------------------------------------------------------*/
64/* A clean up routine registered with DosExitList must be used if */
65/* runtime calls are required and the runtime is dynamically linked. */
66/* This will guarantee that this clean up routine is run before the */
67/* library DLL is terminated. */
68/*-------------------------------------------------------------------*/
69static void APIENTRY cleanup(ULONG reason);
70
71extern "C" {
72 //Win32 resource table (produced by wrc)
73 extern DWORD _Resource_PEResTab;
74}
75
76//Global DLL Data
77#pragma data_seg(_GLOBALDATA)
78int globLoadNr = 0;
79#pragma data_seg()
80
81/* Tue 03.03.1998: knut */
82ULONG flAllocMem = 0; /* flag to optimize DosAllocMem to use all the memory on SMP machines */
83ULONG ulMaxAddr = 0x20000000; /* end of user address space. */
84int loadNr = 0;
85char kernel32Path[CCHMAXPATH] = "";
86static HMODULE dllHandle = 0;
87
88/****************************************************************************/
89/* _DLL_InitTerm is the function that gets called by the operating system */
90/* loader when it loads and frees this DLL for each process that accesses */
91/* this DLL. However, it only gets called the first time the DLL is loaded */
92/* and the last time it is freed for a particular process. The system */
93/* linkage convention MUST be used because the operating system loader is */
94/* calling this function. */
95/****************************************************************************/
96ULONG DLLENTRYPOINT_CCONV DLLENTRYPOINT_NAME(ULONG hModule, ULONG ulFlag)
97{
98 size_t i;
99 APIRET rc;
100 ULONG ulSysinfo, version[2];
101
102 /*-------------------------------------------------------------------------*/
103 /* If ulFlag is zero then the DLL is being loaded so initialization should */
104 /* be performed. If ulFlag is 1 then the DLL is being freed so */
105 /* termination should be performed. */
106 /*-------------------------------------------------------------------------*/
107
108 switch (ulFlag)
109 {
110 case 0 :
111 {
112 ParseLogStatus();
113
114 /*
115 * Init the win32k library.
116 * We will also need to tell win32k where the Odin32 environment is
117 * located. Currently that is within Open32. I'm quite sure that it's
118 * not relocated during run, so we're pretty well off.
119 */
120 if (!libWin32kInit())
121 {
122 rc = libWin32kSetEnvironment((PSZ)_O32_GetEnvironmentStrings(), 0, 0);
123 if (rc)
124 {
125 dprintf(("KERNEL32: initterm: libWin32kSetEnvironment failed with rc=%d\n", rc));
126 }
127 }
128
129 loadNr = globLoadNr++;
130
131 strcpy(kernel32Path, OSLibGetDllName(hModule));
132 char *endofpath = strrchr(kernel32Path, '\\');
133 *(endofpath+1) = 0;
134 dprintf(("kernel32 init %s %s (%x) Win32k - %s", __DATE__, __TIME__, DLLENTRYPOINT_NAME,
135 libWin32kInstalled() ? "Installed" : "Not Installed"));
136 ctordtorInit();
137
138 CheckVersionFromHMOD(PE2LX_VERSION, hModule); /*PLF Wed 98-03-18 05:28:48*/
139
140 OpenPrivateLogFiles();
141
142 if (InitializeSharedHeap() == FALSE)
143 return 0UL;
144
145 if (InitializeCodeHeap() == FALSE)
146 return 0UL;
147
148 PROFILE_LoadOdinIni();
149 dllHandle = RegisterLxDll(hModule, 0, (PVOID)&_Resource_PEResTab);
150 if (dllHandle == 0)
151 return 0UL;
152
153 //SvL: Kernel32 is a special case; pe.exe loads it, so increase
154 // the reference count here
155 Win32DllBase *module = Win32DllBase::findModule(dllHandle);
156 if (module)
157 {
158 module->AddRef();
159 module->DisableUnload();
160 }
161
162 /*******************************************************************/
163 /* A DosExitList routine must be used to clean up if runtime calls */
164 /* are required and the runtime is dynamically linked. */
165 /*******************************************************************/
166
167 rc = DosExitList(EXITLIST_KERNEL32|EXLST_ADD, cleanup);
168 if (rc)
169 return 0UL;
170
171 /* knut: check for high memory support */
172 rc = DosQuerySysInfo(QSV_VIRTUALADDRESSLIMIT, QSV_VIRTUALADDRESSLIMIT, &ulSysinfo, sizeof(ulSysinfo));
173 if (rc == 0 && ulSysinfo > 512) //VirtualAddresslimit is in MB
174 {
175 flAllocMem = PAG_ANY; // high memory support. Let's use it!
176 ulMaxAddr = ulSysinfo * (1024*1024);
177 OSLibInitWSeBFileIO();
178 if (PROFILE_GetOdinIniInt(ODINSYSTEM_SECTION, HIGHMEM_KEY, 1) == 0) {
179 dprintf(("WARNING: OS/2 kernel supports high memory, but support is DISABLED because of HIGHMEM odin.ini key"));
180 flAllocMem = 0;
181 }
182 }
183 else
184 flAllocMem = 0; // no high memory support
185
186 OSLibDosSetInitialMaxFileHandles(ODIN_DEFAULT_MAX_FILEHANDLES);
187
188 //SvL: Do it here instead of during the exe object creation
189 //(std handles can be used in win32 dll initialization routines
190 HMInitialize(); /* store standard handles within HandleManager */
191 InitDirectories(); //Must be done before InitializeTIB (which loads NTDLL -> USER32)
192 InitializeTIB(TRUE); //Must be done after HMInitialize!
193 RegisterDevices();
194 Win32DllBase::setDefaultRenaming();
195 rc = DosQuerySysInfo(QSV_NUMPROCESSORS, QSV_NUMPROCESSORS, &ulSysinfo, sizeof(ulSysinfo));
196 if (rc != 0)
197 ulSysinfo = 1;
198
199 rc = DosQuerySysInfo(QSV_VERSION_MAJOR, QSV_VERSION_MINOR, version, sizeof(version));
200 if(rc == 0){
201 if(version[0] >= 20 && version[1] <= 30) {
202 fVersionWarp3 = TRUE;
203 }
204 }
205
206 /* Setup codepage info */
207 CODEPAGE_Init();
208
209 InitSystemInfo(ulSysinfo);
210 //Set up environment as found in NT
211 InitEnvironment(ulSysinfo);
212
213 //InitDynamicRegistry creates/changes keys that may change (i.e. odin.ini
214 //keys that affect windows version)
215 InitDynamicRegistry();
216 break;
217 }
218
219 case 1 :
220 if (dllHandle)
221 {
222 UnregisterLxDll(dllHandle);
223 }
224 break;
225
226 default :
227 return 0UL;
228 }
229
230 /***********************************************************/
231 /* A non-zero value must be returned to indicate success. */
232 /***********************************************************/
233 return 1UL;
234}
235
236
237static void APIENTRY cleanup(ULONG ulReason)
238{
239 dprintf(("kernel32 exit %d\n", ulReason));
240 //Flush and delete all open memory mapped files
241 Win32MemMap::deleteAll();
242 WinExe = NULL;
243
244 WriteOutProfiles();
245 DestroyTIB();
246 DestroySharedHeap();
247 DestroyCodeHeap();
248 ctordtorTerm();
249
250 //NOTE: Must be done after DestroyTIB
251 ClosePrivateLogFiles();
252 CloseLogFile();
253
254 /*
255 * Terminate win32k library.
256 */
257 libWin32kSetEnvironment(NULL, 0, 0);
258 libWin32kTerm();
259
260 DosExitList(EXLST_EXIT, cleanup);
261 return ;
262}
Note: See TracBrowser for help on using the repository browser.