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

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

Changes for logging & getversionsize/struct

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