source: trunk/src/kernel32/initkernel32.cpp@ 6397

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

updates

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