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

Last change on this file since 529 was 529, checked in by phaller, 26 years ago

Fix: removed ODINCRT remains

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