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