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

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

Added terminate calls to win32k library. Hope this might help fix the lock problem Yuri and Ltning have.

File size: 8.8 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 );
61
62/*-------------------------------------------------------------------*/
63/* A clean up routine registered with DosExitList must be used if */
64/* runtime calls are required and the runtime is dynamically linked. */
65/* This will guarantee that this clean up routine is run before the */
66/* library DLL is terminated. */
67/*-------------------------------------------------------------------*/
68static void APIENTRY cleanup(ULONG reason);
69
70extern "C" {
71 //Win32 resource table (produced by wrc)
72 extern DWORD _Resource_PEResTab;
73}
74
75//Global DLL Data
76#pragma data_seg(_GLOBALDATA)
77int globLoadNr = 0;
78#pragma data_seg()
79
80/* Tue 03.03.1998: knut */
81ULONG flAllocMem = 0; /* flag to optimize DosAllocMem to use all the memory on SMP machines */
82ULONG ulMaxAddr = 0x20000000; /* end of user address space. */
83int loadNr = 0;
84char kernel32Path[CCHMAXPATH] = "";
85static HMODULE dllHandle = 0;
86
87/****************************************************************************/
88/* _DLL_InitTerm is the function that gets called by the operating system */
89/* loader when it loads and frees this DLL for each process that accesses */
90/* this DLL. However, it only gets called the first time the DLL is loaded */
91/* and the last time it is freed for a particular process. The system */
92/* linkage convention MUST be used because the operating system loader is */
93/* calling this function. */
94/****************************************************************************/
95ULONG DLLENTRYPOINT_CCONV DLLENTRYPOINT_NAME(ULONG hModule, ULONG ulFlag)
96{
97 size_t i;
98 APIRET rc;
99 ULONG ulSysinfo;
100
101 /*-------------------------------------------------------------------------*/
102 /* If ulFlag is zero then the DLL is being loaded so initialization should */
103 /* be performed. If ulFlag is 1 then the DLL is being freed so */
104 /* termination should be performed. */
105 /*-------------------------------------------------------------------------*/
106
107 switch (ulFlag)
108 {
109 case 0 :
110 {
111 ParseLogStatus();
112
113 /*
114 * Init the win32k library.
115 * We will also need to tell win32k where the Odin32 environment is
116 * located. Currently that is within Open32. I'm quite sure that it's
117 * not relocated during run, so we're pretty well off.
118 */
119 if (!libWin32kInit())
120 {
121 rc = libWin32kSetEnvironment((PSZ)_O32_GetEnvironmentStrings(), 0, 0);
122 if (rc)
123 {
124 dprintf(("KERNEL32: initterm: libWin32kSetEnvironment failed with rc=%d\n", rc));
125 }
126 }
127
128 loadNr = globLoadNr++;
129
130 strcpy(kernel32Path, OSLibGetDllName(hModule));
131 char *endofpath = strrchr(kernel32Path, '\\');
132 *(endofpath+1) = 0;
133 dprintf(("kernel32 init %s %s (%x) Win32k - %s", __DATE__, __TIME__, DLLENTRYPOINT_NAME,
134 libWin32kInstalled() ? "Installed" : "Not Installed"));
135 ctordtorInit();
136
137 CheckVersionFromHMOD(PE2LX_VERSION, hModule); /*PLF Wed 98-03-18 05:28:48*/
138
139 OpenPrivateLogFiles();
140
141 if (InitializeSharedHeap() == FALSE)
142 return 0UL;
143
144 if (InitializeCodeHeap() == FALSE)
145 return 0UL;
146
147 PROFILE_LoadOdinIni();
148 dllHandle = RegisterLxDll(hModule, 0, (PVOID)&_Resource_PEResTab);
149 if (dllHandle == 0)
150 return 0UL;
151
152 //SvL: Kernel32 is a special case; pe.exe loads it, so increase
153 // the reference count here
154 Win32DllBase *module = Win32DllBase::findModule(dllHandle);
155 if (module)
156 {
157 module->AddRef();
158 module->DisableUnload();
159 }
160
161 /*******************************************************************/
162 /* A DosExitList routine must be used to clean up if runtime calls */
163 /* are required and the runtime is dynamically linked. */
164 /*******************************************************************/
165
166 rc = DosExitList(EXITLIST_KERNEL32|EXLST_ADD, cleanup);
167 if (rc)
168 return 0UL;
169
170 /* knut: check for high memory support */
171 rc = DosQuerySysInfo(QSV_VIRTUALADDRESSLIMIT, QSV_VIRTUALADDRESSLIMIT, &ulSysinfo, sizeof(ulSysinfo));
172 if (rc == 0 && ulSysinfo > 512) //VirtualAddresslimit is in MB
173 {
174 flAllocMem = PAG_ANY; // high memory support. Let's use it!
175 ulMaxAddr = ulSysinfo * (1024*1024);
176 OSLibInitWSeBFileIO();
177 if (PROFILE_GetOdinIniInt(ODINSYSTEM_SECTION, HIGHMEM_KEY, 1) == 0) {
178 dprintf(("WARNING: OS/2 kernel supports high memory, but support is DISABLED because of HIGHMEM odin.ini key"));
179 flAllocMem = 0;
180 }
181 }
182 else
183 flAllocMem = 0; // no high memory support
184
185 OSLibDosSetInitialMaxFileHandles(ODIN_DEFAULT_MAX_FILEHANDLES);
186
187 //SvL: Do it here instead of during the exe object creation
188 //(std handles can be used in win32 dll initialization routines
189 HMInitialize(); /* store standard handles within HandleManager */
190 InitDirectories(); //Must be done before InitializeTIB (which loads NTDLL -> USER32)
191 InitializeTIB(TRUE); //Must be done after HMInitialize!
192 RegisterDevices();
193 Win32DllBase::setDefaultRenaming();
194 rc = DosQuerySysInfo(QSV_NUMPROCESSORS, QSV_NUMPROCESSORS, &ulSysinfo, sizeof(ulSysinfo));
195 if (rc != 0)
196 ulSysinfo = 1;
197
198 /* Setup codepage info */
199 CODEPAGE_Init();
200
201 InitSystemInfo(ulSysinfo);
202 //Set up environment as found in NT
203 InitEnvironment(ulSysinfo);
204
205 //InitDynamicRegistry creates/changes keys that may change (i.e. odin.ini
206 //keys that affect windows version)
207 InitDynamicRegistry();
208 break;
209 }
210
211 case 1 :
212 if (dllHandle)
213 {
214 UnregisterLxDll(dllHandle);
215 }
216 break;
217
218 default :
219 return 0UL;
220 }
221
222 /***********************************************************/
223 /* A non-zero value must be returned to indicate success. */
224 /***********************************************************/
225 return 1UL;
226}
227
228
229static void APIENTRY cleanup(ULONG ulReason)
230{
231 dprintf(("kernel32 exit %d\n", ulReason));
232 //Flush and delete all open memory mapped files
233 Win32MemMap::deleteAll();
234 WinExe = NULL;
235
236 WriteOutProfiles();
237 DestroyTIB();
238 DestroySharedHeap();
239 DestroyCodeHeap();
240 ctordtorTerm();
241
242 //NOTE: Must be done after DestroyTIB
243 ClosePrivateLogFiles();
244 CloseLogFile();
245
246 /*
247 * Terminate win32k library.
248 */
249 libWin32kSetEnvironment(NULL, 0, 0);
250 libWin32kTerm();
251
252 DosExitList(EXLST_EXIT, cleanup);
253 return ;
254}
Note: See TracBrowser for help on using the repository browser.