| 1 | /* $Id: initterm.cpp,v 1.64 2001-10-15 17:10:54 sandervl 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 | BOOL  fVersionWarp3 = FALSE; | 
|---|
| 62 | BOOL  fCustomBuild  = FALSE; | 
|---|
| 63 |  | 
|---|
| 64 | //Global DLL Data | 
|---|
| 65 | #pragma data_seg(_GLOBALDATA) | 
|---|
| 66 | int globLoadNr = 0; | 
|---|
| 67 | #pragma data_seg() | 
|---|
| 68 |  | 
|---|
| 69 | static BOOL fInit = FALSE; | 
|---|
| 70 |  | 
|---|
| 71 | /*-------------------------------------------------------------------*/ | 
|---|
| 72 | /* A clean up routine registered with DosExitList must be used if    */ | 
|---|
| 73 | /* runtime calls are required and the runtime is dynamically linked. */ | 
|---|
| 74 | /* This will guarantee that this clean up routine is run before the  */ | 
|---|
| 75 | /* library DLL is terminated.                                        */ | 
|---|
| 76 | /*-------------------------------------------------------------------*/ | 
|---|
| 77 | static void APIENTRY cleanup(ULONG reason); | 
|---|
| 78 |  | 
|---|
| 79 | /****************************************************************************/ | 
|---|
| 80 | /* _DLL_InitTerm is the function that gets called by the operating system   */ | 
|---|
| 81 | /* loader when it loads and frees this DLL for each process that accesses   */ | 
|---|
| 82 | /* this DLL.  However, it only gets called the first time the DLL is loaded */ | 
|---|
| 83 | /* and the last time it is freed for a particular process.  The system      */ | 
|---|
| 84 | /* linkage convention MUST be used because the operating system loader is   */ | 
|---|
| 85 | /* calling this function.                                                   */ | 
|---|
| 86 | /****************************************************************************/ | 
|---|
| 87 | ULONG DLLENTRYPOINT_CCONV DLLENTRYPOINT_NAME(ULONG hModule, ULONG ulFlag) | 
|---|
| 88 | { | 
|---|
| 89 | size_t i; | 
|---|
| 90 | APIRET rc; | 
|---|
| 91 | ULONG  ulSysinfo, version[2]; | 
|---|
| 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 | ctordtorInit(); | 
|---|
| 108 |  | 
|---|
| 109 | CheckVersionFromHMOD(PE2LX_VERSION, hModule); /*PLF Wed  98-03-18 05:28:48*/ | 
|---|
| 110 |  | 
|---|
| 111 | /*******************************************************************/ | 
|---|
| 112 | /* A DosExitList routine must be used to clean up if runtime calls */ | 
|---|
| 113 | /* are required and the runtime is dynamically linked.             */ | 
|---|
| 114 | /*******************************************************************/ | 
|---|
| 115 |  | 
|---|
| 116 | rc = DosExitList(EXITLIST_KERNEL32|EXLST_ADD, cleanup); | 
|---|
| 117 | if (rc) | 
|---|
| 118 | return 0UL; | 
|---|
| 119 |  | 
|---|
| 120 | rc = DosQuerySysInfo(QSV_VERSION_MAJOR, QSV_VERSION_MINOR, version, sizeof(version)); | 
|---|
| 121 | if(rc == 0){ | 
|---|
| 122 | if(version[0] >= 20 && version[1] <= 30) { | 
|---|
| 123 | fVersionWarp3 = TRUE; | 
|---|
| 124 | } | 
|---|
| 125 | } | 
|---|
| 126 |  | 
|---|
| 127 | rc = inittermKernel32(hModule, ulFlag); | 
|---|
| 128 | break; | 
|---|
| 129 | } | 
|---|
| 130 |  | 
|---|
| 131 | case 1 : | 
|---|
| 132 | rc = inittermKernel32(hModule, ulFlag); | 
|---|
| 133 | break; | 
|---|
| 134 |  | 
|---|
| 135 | default  : | 
|---|
| 136 | return 0UL; | 
|---|
| 137 | } | 
|---|
| 138 |  | 
|---|
| 139 | /***********************************************************/ | 
|---|
| 140 | /* A non-zero value must be returned to indicate success.  */ | 
|---|
| 141 | /***********************************************************/ | 
|---|
| 142 | return 1UL; | 
|---|
| 143 | } | 
|---|
| 144 | //****************************************************************************** | 
|---|
| 145 | //****************************************************************************** | 
|---|
| 146 | static void APIENTRY cleanup(ULONG ulReason) | 
|---|
| 147 | { | 
|---|
| 148 | cleanupKernel32(ulReason); | 
|---|
| 149 |  | 
|---|
| 150 | ctordtorTerm(); | 
|---|
| 151 |  | 
|---|
| 152 | DosExitList(EXLST_EXIT, cleanup); | 
|---|
| 153 | return ; | 
|---|
| 154 | } | 
|---|
| 155 | //****************************************************************************** | 
|---|
| 156 | ULONG APIENTRY O32__DLL_InitTerm(ULONG handle, ULONG flag); | 
|---|
| 157 | //****************************************************************************** | 
|---|
| 158 | ULONG APIENTRY InitializeKernel32() | 
|---|
| 159 | { | 
|---|
| 160 | HMODULE hModule; | 
|---|
| 161 |  | 
|---|
| 162 | if(!fInit) { | 
|---|
| 163 | loadNr = globLoadNr++; | 
|---|
| 164 | } | 
|---|
| 165 | DosQueryModuleHandle("WGSS50", &hModule); | 
|---|
| 166 | O32__DLL_InitTerm(hModule, 0); | 
|---|
| 167 | DosQueryModuleHandle("KERNEL32", &hModule); | 
|---|
| 168 | return DLLENTRYPOINT_NAME(hModule, 0); | 
|---|
| 169 | } | 
|---|
| 170 | //****************************************************************************** | 
|---|
| 171 | //****************************************************************************** | 
|---|