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

Last change on this file since 1768 was 1768, checked in by bird, 26 years ago

Added ulMaxAddr - user address space end address. (valid addresses are
below this address.)

File size: 6.0 KB
Line 
1/* $Id: initterm.cpp,v 1.25 1999-11-18 09:20:08 bird Exp $ */
2
3/*
4 * KERNEL32 DLL entry point
5 *
6 * Copyright 1998 Sander van Leeuwen
7 * Copyright 1998 Peter Fitzsimmons
8 *
9 *
10 * Project Odin Software License can be found in LICENSE.TXT
11 *
12 */
13
14/*-------------------------------------------------------------*/
15/* INITERM.C -- Source for a custom dynamic link library */
16/* initialization and termination (_DLL_InitTerm) */
17/* function. */
18/* */
19/* When called to perform initialization, this sample function */
20/* gets storage for an array of integers, and initializes its */
21/* elements with random integers. At termination time, it */
22/* frees the array. Substitute your own special processing. */
23/*-------------------------------------------------------------*/
24
25
26/* Include files */
27#define INCL_DOSMODULEMGR
28#define INCL_DOSMISC
29#define INCL_DOSPROCESS
30#define INCL_DOSSEMAPHORES
31#include <os2wrap.h> //Odin32 OS/2 api wrappers
32#include <stdlib.h>
33#include <stdio.h>
34#include <string.h>
35#include <misc.h>
36#include <wprocess.h>
37#include "handlemanager.h"
38#include "profile.h"
39#include "initterm.h"
40#include <win32type.h>
41#include <odinlx.h>
42#include "oslibmisc.h"
43#include <heapshared.h>
44#include "mmap.h"
45#include "directory.h"
46#include "hmdevio.h"
47
48/*-------------------------------------------------------------------*/
49/* A clean up routine registered with DosExitList must be used if */
50/* runtime calls are required and the runtime is dynamically linked. */
51/* This will guarantee that this clean up routine is run before the */
52/* library DLL is terminated. */
53/*-------------------------------------------------------------------*/
54static void APIENTRY cleanup(ULONG reason);
55extern void APIENTRY Win32DllExitList(ULONG reason);
56
57extern "C" {
58void CDECL _ctordtorInit( void );
59void CDECL _ctordtorTerm( void );
60}
61
62//Global DLL Data
63#pragma data_seg(_GLOBALDATA)
64int globLoadNr = 0;
65#pragma data_seg()
66
67/* Tue 03.03.1998: knut */
68ULONG flAllocMem = 0; /* flag to optimize DosAllocMem to use all the memory on SMP machines */
69ULONG ulMaxAddr = 0x20000000; /* end of user address space. */
70int loadNr = 0;
71char kernel32Path[CCHMAXPATH] = "";
72
73/****************************************************************************/
74/* _DLL_InitTerm is the function that gets called by the operating system */
75/* loader when it loads and frees this DLL for each process that accesses */
76/* this DLL. However, it only gets called the first time the DLL is loaded */
77/* and the last time it is freed for a particular process. The system */
78/* linkage convention MUST be used because the operating system loader is */
79/* calling this function. */
80/****************************************************************************/
81unsigned long SYSTEM _DLL_InitTerm(unsigned long hModule, unsigned long
82 ulFlag)
83{
84 size_t i;
85 APIRET rc;
86 ULONG ulSysinfo;
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 loadNr = globLoadNr++;
99
100 strcpy(kernel32Path, OSLibGetDllName(hModule));
101 char *endofpath = strrchr(kernel32Path, '\\');
102 *(endofpath+1) = 0;
103 dprintf(("kernel32 init\n"));
104 _ctordtorInit();
105
106 CheckVersionFromHMOD(PE2LX_VERSION, hModule); /*PLF Wed 98-03-18 05:28:48*/
107
108 if(InitializeSharedHeap() == FALSE)
109 return 0UL;
110
111 PROFILE_LoadOdinIni();
112 if(RegisterLxDll(hModule, 0, 0) == FALSE)
113 return 0UL;
114
115 /*******************************************************************/
116 /* A DosExitList routine must be used to clean up if runtime calls */
117 /* are required and the runtime is dynamically linked. */
118 /*******************************************************************/
119
120 rc = DosExitList(0x0000F000|EXLST_ADD, cleanup);
121 if (rc)
122 return 0UL;
123
124 /* knut: check for high memory support */
125 rc = DosQuerySysInfo(QSV_VIRTUALADDRESSLIMIT, QSV_VIRTUALADDRESSLIMIT, &ulSysinfo, sizeof(ulSysinfo));
126 if (rc == 0 && ulSysinfo > 512) //VirtualAddresslimit is in MB
127 {
128 flAllocMem = PAG_ANY; // high memory support. Let's use it!
129 ulMaxAddr = ulSysinfo * (1024*1024);
130 }
131 else
132 flAllocMem = 0; // no high memory support
133
134 InitializeTIB(TRUE);
135 //SvL: Do it here instead of during the exe object creation
136 //(std handles can be used in win32 dll initialization routines
137 HMInitialize(); /* store standard handles within HandleManager */
138 InitDirectories();
139 RegisterDevices();
140 break;
141 }
142 case 1 :
143 UnregisterLxDll(hModule);
144 break;
145 default :
146 return 0UL;
147 }
148
149 /***********************************************************/
150 /* A non-zero value must be returned to indicate success. */
151 /***********************************************************/
152 return 1UL;
153}
154
155
156static void APIENTRY cleanup(ULONG ulReason)
157{
158 dprintf(("kernel32 exit %d\n", ulReason));
159 //Flush and delete all open memory mapped files
160 Win32MemMap::deleteAll();
161
162 WriteOutProfiles();
163 DestroyTIB();
164 DestroySharedHeap();
165 _ctordtorTerm();
166
167 //NOTE: Must be done after DestroyTIB
168 CloseLogFile();
169
170 DosExitList(EXLST_EXIT, cleanup);
171 return ;
172}
Note: See TracBrowser for help on using the repository browser.