|
|
Microsoft OS/2 SDK 2.0 05-30-1990
/*==============================================================*\
* Vmm_init.c - routines for initialization and exit processing *
* Created 1990, Microsoft, IBM Corp. *
*--------------------------------------------------------------*
* *
* This module contains the code for application initialization*
* as well as the code for exit list processing *
* *
*--------------------------------------------------------------*
* *
* This source file contains the following functions: *
* *
* Init() - initialization routines *
* ExitProc(usTermCode) - exit list processing procedure *
* GPFHandler(parg) - GPFault and guard page excep handler *
* *
\*==============================================================*/
/*--------------------------------------------------------------*\
* Include files, macros, defined constants, and externs *
\*--------------------------------------------------------------*/
#define LINT_ARGS
#define INCL_WIN
#define INCL_DOSPROCESS
#define INCL_DOSSIGNALS
#define INCL_DOSMISC
#define INCL_DOSMEMMGR
#include <os2.h>
#include <string.h>
#include "vmm_main.h"
#include "vmm_xtrn.h"
/*--------------------------------------------------------------*\
* Entry point declarations *
\*--------------------------------------------------------------*/
ULONG GPFHandler(PXCPT parg);
/*--------------------------------------------------------------*\
* Global variables *
\*--------------------------------------------------------------*/
extern HWND hwndMain;
EHS ehs = {0, &GPFHandler};
/****************************************************************\
* Initialization routine *
*--------------------------------------------------------------*
* *
* Name: Init() *
* *
* Purpose: Performs initialization functions required *
* before the main window can be created. *
* *
* Usage: Called once before the main window is created. *
* *
* Method: *
* - installs the routine ExitProc into the *
* DosExitList chain *
* - registers all window classes *
* - performs any command line processing *
* *
* Returns: *
* TRUE - initialization is successful *
* FALSE - initialization failed *
\****************************************************************/
BOOL Init(VOID)
{
/* Add ExitProc to the exit list to handle the exit processing */
#ifndef VER630
if(DosExitList(EXLST_ADD, (PFNEXITLIST)ExitProc))
{
return FALSE;
}
#endif
#ifdef LATER
/* initialize the print dialog structures */
InitPrintingDialogs();
#endif
/* load application name from resource file */
if(WinLoadString(hab, NULL, IDS_APPNAME, MAXAPPNAMELEN, szAppName) == 0)
{
return FALSE;
}
/* register the main client window class */
if(WinRegisterClass(hab,
(PSZ)szAppName,
(PFNWP)MainWndProc,
CS_SIZEREDRAW | CS_SYNCPAINT | CS_CLIPCHILDREN,
0) == 0)
{
return FALSE;
}
if(DosSetExceptionHandler(&ehs) != 0)
{
return FALSE;
}
/*--------------------------------------------------*\
* Add any command line processing here *
\*--------------------------------------------------*/
/* Turn off hard-error popup after GP-FAULT. No return codes
checked as it is cosmetic and if it doesn't work the only side
effect will be to have the default hard-error popup show up. */
DosError(FERR_DISABLEEXCEPTION | FERR_DISABLEHARDERR);
return TRUE;
} /* Init() */
/****************************************************************\
* Exit list processing procedure *
*--------------------------------------------------------------*
* *
* Name: ExitProc(usTermCode) *
* *
* Purpose: Cleans up certain resources when the application *
* terminates *
* *
* Usage: Routine is called by DosExitList when the *
* application exits *
* *
* Method: global resources, such as the main window and *
* message queue, are destroyed and any system *
* resources used are freed *
* *
* Returns: Returns EXLST_EXIT to the DosExitList handler *
* *
\****************************************************************/
VOID PASCAL FAR ExitProc(usTermCode)
USHORT usTermCode; /* code for the reason for termination */
{
WinDestroyWindow(hwndMainFrame);
/*--------------------------------------------------*\
* Any other system resources used *
* (e.g. memory or files) should be freed here *
\*--------------------------------------------------*/
WinDestroyMsgQueue(hmq);
WinTerminate(hab);
DosUnsetExceptionHandler(&ehs);
DosExitList(EXLST_EXIT, 0L); /* termination complete */
/* This routine currently doesn't use the usTermCode parameter so *\
* it is referenced here to prevent an 'Unreferenced Parameter' *
\* warning at compile time */
usTermCode;
} /* ExitProc() */
/****************************************************************\
* Do nothing Guard Page Exception Handler *
*--------------------------------------------------------------*
* *
* Name: GPFHandler(PXCPT) *
* *
* Purpose: To notify user when a guard page entered exception *
* occurs *
* *
* Usage: Routine is called when a guard page is accessed *
* *
* Method: Whenever a guard page is accessed, a message *
* box is put on the screen indicating this *
* *
* Returns: Returns HANDLED if guard page exception, *
* otherwise, returns NOT_HANDLED *
\****************************************************************/
ULONG GPFHandler(parg)
PXCPT parg;
{
ULONG flMemAttrs;
ULONG ulMemSize;
/* Notify the user when they have accessed a guard page, and let
the system default guard page handler handle the exception. */
if(parg->ExceptionNum == XCPT_GPF)
{
WinMessageBox(HWND_DESKTOP,
hwndMain,
"Guard Page Accessed.\n\n"
"Calling Default Handler.\n",
szAppName,
13,
MB_OK | MB_ICONASTERISK);
WinInvalidateRect(hwndMain,NULL,TRUE);
return(NOT_HANDLED);
}
if(parg->ExceptionNum == XCPT_GP)
{
if (parg->ExceptionInfo[0] & XCPTF_PF)
{
ulMemSize = 1L;
DosQueryMem((PVOID)(parg->pExceptionContext->EC_cr2),
&ulMemSize,&flMemAttrs);
/* If the exception is due to accessing a page that has
been allocated but not committed, then commit the page.
Otherwise, GP Fault. */
if (((flMemAttrs & PAG_FREE) || (flMemAttrs & PAG_COMMIT)) == 0)
{
WinMessageBox(HWND_DESKTOP,
hwndMain,
"The memory to be written to has not been"
" committed. \n\rAttempting to committ memory"
" before write.",
szAppName,
13,
MB_OK | MB_ICONASTERISK);
if (DosSetMem((PVOID)(parg->pExceptionContext->EC_cr2),
1L,PAG_DEFAULT | PAG_COMMIT) != 0L)
return(NOT_HANDLED);
else
return(HANDLED);
}
}
/* At this point, we have a GP Fault. We cannot
recover, so raise the terminate process exception and
return (GP Fault) exception handled. */
WinMessageBox(HWND_DESKTOP,
hwndMain,
"A non-recoverable General Protection Error "
"has occured.\n\rProgram Terminating.",
szAppName,
13,
MB_OK | MB_ICONHAND);
return(NOT_HANDLED);
}
/* The exception is not one that we handle, so pass it on as
NOT_HANDLED. */
return(NOT_HANDLED);
}
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.