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

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

Put back ctordtorinit/Term

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