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

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

initterm update

File size: 7.7 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
92 /*-------------------------------------------------------------------------*/
93 /* If ulFlag is zero then the DLL is being loaded so initialization should */
94 /* be performed. If ulFlag is 1 then the DLL is being freed so */
95 /* termination should be performed. */
96 /*-------------------------------------------------------------------------*/
97
98 switch (ulFlag)
99 {
100 case 0 :
101 {
102 ParseLogStatusKERNEL32();
103
104 /*
105 * Init the win32k library.
106 * We will also need to tell win32k where the Odin32 environment is
107 * located. Currently that is within Open32. I'm quite sure that it's
108 * not relocated during run, so we're pretty well off.
109 */
110 if (!libWin32kInit())
111 {
112 rc = libWin32kSetEnvironment((PSZ)_O32_GetEnvironmentStrings(), 0, 0);
113 if (rc)
114 {
115 dprintf(("KERNEL32: initterm: libWin32kSetEnvironment failed with rc=%d\n", rc));
116 }
117 }
118
119 loadNr = globLoadNr++;
120
121 strcpy(kernel32Path, OSLibGetDllName(hModule));
122 char *endofpath = strrchr(kernel32Path, '\\');
123 *(endofpath+1) = 0;
124 dprintf(("kernel32 init %s %s (%x) Win32k - %s", __DATE__, __TIME__, inittermKernel32,
125 libWin32kInstalled() ? "Installed" : "Not Installed"));
126
127 OpenPrivateLogFiles();
128
129 if (InitializeSharedHeap() == FALSE)
130 return 0UL;
131
132 if (InitializeCodeHeap() == FALSE)
133 return 0UL;
134
135 PROFILE_LoadOdinIni();
136 dllHandle = RegisterLxDll(hModule, 0, (PVOID)&_Resource_PEResTab);
137 if (dllHandle == 0)
138 return 0UL;
139
140 //SvL: Kernel32 is a special case; pe.exe loads it, so increase
141 // the reference count here
142 Win32DllBase *module = Win32DllBase::findModule(dllHandle);
143 if (module)
144 {
145 module->AddRef();
146 module->DisableUnload();
147 }
148
149 /* knut: check for high memory support */
150 rc = DosQuerySysInfo(QSV_VIRTUALADDRESSLIMIT, QSV_VIRTUALADDRESSLIMIT, &ulSysinfo, sizeof(ulSysinfo));
151 if (rc == 0 && ulSysinfo > 512) //VirtualAddresslimit is in MB
152 {
153 flAllocMem = PAG_ANY; // high memory support. Let's use it!
154 ulMaxAddr = ulSysinfo * (1024*1024);
155 OSLibInitWSeBFileIO();
156 if (PROFILE_GetOdinIniInt(ODINSYSTEM_SECTION, HIGHMEM_KEY, 1) == 0) {
157 dprintf(("WARNING: OS/2 kernel supports high memory, but support is DISABLED because of HIGHMEM odin.ini key"));
158 flAllocMem = 0;
159 }
160 }
161 else
162 flAllocMem = 0; // no high memory support
163
164 OSLibDosSetInitialMaxFileHandles(ODIN_DEFAULT_MAX_FILEHANDLES);
165
166 //SvL: Do it here instead of during the exe object creation
167 //(std handles can be used in win32 dll initialization routines
168 HMInitialize(); /* store standard handles within HandleManager */
169 InitDirectories(); //Must be done before InitializeTIB (which loads NTDLL -> USER32)
170 InitializeTIB(TRUE); //Must be done after HMInitialize!
171 RegisterDevices();
172 Win32DllBase::setDefaultRenaming();
173 rc = DosQuerySysInfo(QSV_NUMPROCESSORS, QSV_NUMPROCESSORS, &ulSysinfo, sizeof(ulSysinfo));
174 if (rc != 0)
175 ulSysinfo = 1;
176
177 /* Setup codepage info */
178 CODEPAGE_Init();
179
180 InitSystemInfo(ulSysinfo);
181 //Set up environment as found in NT
182 InitEnvironment(ulSysinfo);
183
184 //InitDynamicRegistry creates/changes keys that may change (i.e. odin.ini
185 //keys that affect windows version)
186 InitDynamicRegistry();
187 break;
188 }
189
190 case 1 :
191 if (dllHandle)
192 {
193 UnregisterLxDll(dllHandle);
194 }
195 break;
196
197 default :
198 return 0UL;
199 }
200
201 /***********************************************************/
202 /* A non-zero value must be returned to indicate success. */
203 /***********************************************************/
204 return 1UL;
205}
206
207
208void APIENTRY cleanupKernel32(ULONG ulReason)
209{
210 dprintf(("kernel32 exit %d\n", ulReason));
211 //Flush and delete all open memory mapped files
212 Win32MemMap::deleteAll();
213 WinExe = NULL;
214
215 WriteOutProfiles();
216 DestroyTIB();
217 DestroySharedHeap();
218 DestroyCodeHeap();
219
220 //NOTE: Must be done after DestroyTIB
221 ClosePrivateLogFiles();
222 CloseLogFile();
223
224 /*
225 * Terminate win32k library.
226 */
227 libWin32kSetEnvironment(NULL, 0, 0);
228 libWin32kTerm();
229 return ;
230}
Note: See TracBrowser for help on using the repository browser.