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

Last change on this file since 1432 was 1432, checked in by sandervl, 26 years ago

Shared memory mapping changes

File size: 5.6 KB
Line 
1/* $Id: initterm.cpp,v 1.17 1999-10-24 22:51:21 sandervl 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#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 "initterm.h"
39#include <win32type.h>
40#include <odinlx.h>
41#include "oslibmisc.h"
42#include "heapshared.h"
43
44/*-------------------------------------------------------------------*/
45/* A clean up routine registered with DosExitList must be used if */
46/* runtime calls are required and the runtime is dynamically linked. */
47/* This will guarantee that this clean up routine is run before the */
48/* library DLL is terminated. */
49/*-------------------------------------------------------------------*/
50static void APIENTRY cleanup(ULONG reason);
51extern void APIENTRY Win32DllExitList(ULONG reason);
52
53extern "C" {
54void CDECL _ctordtorInit( void );
55void CDECL _ctordtorTerm( void );
56}
57
58//Global DLL Data
59#pragma data_seg(_GLOBALDATA)
60int globLoadNr = 0;
61#pragma data_seg()
62
63/* Tue 03.03.1998: knut */
64/* flag to optimize DosAllocMem to use all the memory on SMP machines */
65ULONG flAllocMem = 0;
66int loadNr = 0;
67char kernel32Path[CCHMAXPATH] = "";
68
69/****************************************************************************/
70/* _DLL_InitTerm is the function that gets called by the operating system */
71/* loader when it loads and frees this DLL for each process that accesses */
72/* this DLL. However, it only gets called the first time the DLL is loaded */
73/* and the last time it is freed for a particular process. The system */
74/* linkage convention MUST be used because the operating system loader is */
75/* calling this function. */
76/****************************************************************************/
77unsigned long SYSTEM _DLL_InitTerm(unsigned long hModule, unsigned long
78 ulFlag)
79{
80 size_t i;
81 APIRET rc;
82 ULONG sysinfo;
83
84 /*-------------------------------------------------------------------------*/
85 /* If ulFlag is zero then the DLL is being loaded so initialization should */
86 /* be performed. If ulFlag is 1 then the DLL is being freed so */
87 /* termination should be performed. */
88 /*-------------------------------------------------------------------------*/
89
90 switch (ulFlag)
91 {
92 case 0 :
93 {
94 loadNr = globLoadNr++;
95
96 strcpy(kernel32Path, OSLibGetDllName(hModule));
97 char *endofpath = strrchr(kernel32Path, '\\');
98 *(endofpath+1) = 0;
99 dprintf(("kernel32 init\n"));
100 _ctordtorInit();
101
102 CheckVersionFromHMOD(PE2LX_VERSION, hModule); /*PLF Wed 98-03-18 05:28:48*/
103
104 if(InitializeSharedHeap() == FALSE)
105 return 0UL;
106
107 if(RegisterLxDll(hModule, 0, 0) == FALSE)
108 return 0UL;
109
110 /*******************************************************************/
111 /* A DosExitList routine must be used to clean up if runtime calls */
112 /* are required and the runtime is dynamically linked. */
113 /*******************************************************************/
114
115 rc = DosExitList(0x0000F000|EXLST_ADD, cleanup);
116 if (rc)
117 return 0UL;
118
119 /* knut: check for high memory support */
120 rc = DosQuerySysInfo(QSV_VIRTUALADDRESSLIMIT, QSV_VIRTUALADDRESSLIMIT, &sysinfo, sizeof(sysinfo));
121
122 if ( rc == 0 && sysinfo > 512 ) //VirtualAddresslimit is in MB
123 flAllocMem = PAG_ANY; // high memory support. Let's use it!
124 else flAllocMem = 0; // no high memory support
125
126 InitializeTIB(TRUE);
127 //SvL: Do it here instead of during the exe object creation
128 //(std handles can be used in win32 dll initialization routines
129 HMInitialize(); /* store standard handles within HandleManager */
130 PROFILE_LoadOdinIni();
131 break;
132 }
133 case 1 :
134 UnregisterLxDll(hModule);
135 break;
136 default :
137 return 0UL;
138 }
139
140 /***********************************************************/
141 /* A non-zero value must be returned to indicate success. */
142 /***********************************************************/
143 return 1UL;
144}
145
146
147static void APIENTRY cleanup(ULONG ulReason)
148{
149 dprintf(("kernel32 exit %d\n", ulReason));
150 WriteOutProfiles();
151 DestroyTIB();
152 //NOTE: Must be done after DestroyTIB
153 CloseLogFile();
154 _ctordtorTerm();
155 DosExitList(EXLST_EXIT, cleanup);
156 return ;
157}
Note: See TracBrowser for help on using the repository browser.