source: trunk/src/kernel32/initterm.c@ 21

Last change on this file since 21 was 4, checked in by ktk, 26 years ago

Import

File size: 5.9 KB
Line 
1/* $Id: initterm.c,v 1.1 1999-05-24 20:19:41 ktk Exp $ */
2
3/*
4 *
5 * Project Odin Software License can be found in LICENSE.TXT
6 *
7 */
8/*
9 * KERNEL32 DLL entry point
10 *
11 * Copyright 1998 Sander van Leeuwen
12 * Copyright 1998 Peter Fitzsimmons
13 *
14 */
15
16/*-------------------------------------------------------------*/
17/* INITERM.C -- Source for a custom dynamic link library */
18/* initialization and termination (_DLL_InitTerm) */
19/* function. */
20/* */
21/* When called to perform initialization, this sample function */
22/* gets storage for an array of integers, and initializes its */
23/* elements with random integers. At termination time, it */
24/* frees the array. Substitute your own special processing. */
25/*-------------------------------------------------------------*/
26
27
28/* Include files */
29#define INCL_DOSMODULEMGR
30#define INCL_DOSMISC
31#define INCL_DOSPROCESS
32#include <os2.h>
33#include <stdlib.h>
34#include <stdio.h>
35#include <string.h>
36#include <builtin.h>
37#include "misc.h"
38
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 _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 _CRT_term(void);
50void __ctordtorInit( void );
51void __ctordtorTerm( void );
52
53/*-------------------------------------------------------------------*/
54/* A clean up routine registered with DosExitList must be used if */
55/* runtime calls are required and the runtime is dynamically linked. */
56/* This will guarantee that this clean up routine is run before the */
57/* library DLL is terminated. */
58/*-------------------------------------------------------------------*/
59static void APIENTRY cleanup(ULONG reason);
60extern void APIENTRY Win32DllExitList(ULONG reason);
61
62/* Tue 03.03.1998: knut */
63/* flag to optimize DosAllocMem to use all the memory on SMP machines */
64ULONG flAllocMem;
65
66#ifndef PAG_ANY
67 #define PAG_ANY 0x00000400
68#endif
69
70#ifndef QSV_VIRTUALADDRESSLIMIT
71 #define QSV_VIRTUALADDRESSLIMIT 30
72#endif
73
74/****************************************************************************/
75/* _DLL_InitTerm is the function that gets called by the operating system */
76/* loader when it loads and frees this DLL for each process that accesses */
77/* this DLL. However, it only gets called the first time the DLL is loaded */
78/* and the last time it is freed for a particular process. The system */
79/* linkage convention MUST be used because the operating system loader is */
80/* calling this function. */
81/****************************************************************************/
82unsigned long _System _DLL_InitTerm(unsigned long hModule, unsigned long
83 ulFlag)
84{
85 size_t i;
86 APIRET rc;
87 ULONG sysinfo;
88
89 /*-------------------------------------------------------------------------*/
90 /* If ulFlag is zero then the DLL is being loaded so initialization should */
91 /* be performed. If ulFlag is 1 then the DLL is being freed so */
92 /* termination should be performed. */
93 /*-------------------------------------------------------------------------*/
94
95 switch (ulFlag)
96 {
97 case 0 :
98
99 /*******************************************************************/
100 /* The C run-time environment initialization function must be */
101 /* called before any calls to C run-time functions that are not */
102 /* inlined. */
103 /*******************************************************************/
104
105 if (_CRT_init() == -1)
106 return 0UL;
107 __ctordtorInit();
108
109 dprintf(("kernel32 init\n"));
110 CheckVersionFromHMOD(PE2LX_VERSION, hModule); /*PLF Wed 98-03-18 05:28:48*/
111 /*******************************************************************/
112 /* A DosExitList routine must be used to clean up if runtime calls */
113 /* are required and the runtime is dynamically linked. */
114 /*******************************************************************/
115
116 rc = DosExitList(0x0000FF00|EXLST_ADD, cleanup);
117 if (rc)
118 return 0UL;
119
120 rc = DosExitList(0x00002A00|EXLST_ADD, Win32DllExitList);
121 if (rc)
122 return 0UL;
123
124 /* knut: check for high memory support */
125 rc = DosQuerySysInfo(QSV_VIRTUALADDRESSLIMIT, QSV_VIRTUALADDRESSLIMIT, &sysinfo, sizeof(sysinfo));
126
127 if ( rc == 0 && sysinfo > 512 ) //VirtualAddresslimit is in MB
128 flAllocMem = PAG_ANY; // high memory support. Let's use it!
129 else flAllocMem = 0; // no high memory support
130
131 break;
132 case 1 :
133 break;
134 default :
135 return 0UL;
136 }
137
138 /***********************************************************/
139 /* A non-zero value must be returned to indicate success. */
140 /***********************************************************/
141 return 1UL;
142}
143
144
145static void APIENTRY cleanup(ULONG ulReason)
146{
147 dprintf(("kernel32 exit\n"));
148 _dump_allocated(10); /*PLF Wed 98-03-18 23:55:07*/
149 __ctordtorTerm();
150 _CRT_term();
151 DosExitList(EXLST_EXIT, cleanup);
152 return ;
153}
Note: See TracBrowser for help on using the repository browser.