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

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

Activated Win32 TIB code and fixes some other things (see ChangeLog)

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