Changeset 704


Ignore:
Timestamp:
Aug 26, 1999, 9:48:14 AM (26 years ago)
Author:
sandervl
Message:

Exception handler support for memory mapped exe/dll loading

File:
1 edited

Legend:

Unmodified
Added
Removed
  • TabularUnified trunk/src/peldr/pe.cpp

    r544 r704  
    1 /* $Id: pe.cpp,v 1.6 1999-08-18 12:24:32 sandervl Exp $ */
     1/* $Id: pe.cpp,v 1.7 1999-08-26 07:48:14 sandervl Exp $ */
    22
    33/*
     
    2929#include <wprocess.h>
    3030#include "pe.h"
     31#include "exceptions.h"
     32#include "..\kernel32\exceptutil.h"
    3133
    3234char INFO_BANNER[]      = "Usage: PE winexe commandline";
     
    5153                                              ULONG idWindow,
    5254                                              ULONG flStyle);
     55typedef void (* KRNL32EXCEPTPROC) (void *exceptframe);
    5356
    5457WININITIALIZEPROC      MyWinInitialize      = 0;
     
    5760WINDESTROYMSGQUEUEPROC MyWinDestroyMsgQueue = 0;
    5861WINMESSAGEBOXPROC      MyWinMessageBox      = 0;
     62KRNL32EXCEPTPROC       Krnl32SetExceptionHandler = 0;
     63KRNL32EXCEPTPROC       Krnl32UnsetExceptionHandler = 0;
    5964
    6065WIN32CTOR              CreateWin32Exe       = 0;
     
    6267int main(int argc, char *argv[])
    6368{
    64  HAB    hab;                             /* PM anchor block handle       */
    65  HMQ    hmq;                             /* Message queue handle         */
     69 HAB    hab = 0;                             /* PM anchor block handle       */
     70 HMQ    hmq = 0;                             /* Message queue handle         */
    6671 char  *szCmdLine;
    6772 char   exeName[CCHMAXPATH];
     
    7075 Win32Exe *WinExe;
    7176 APIRET  rc;
    72  HMODULE hmodPMWin, hmodKernel32;
     77 HMODULE hmodPMWin = 0, hmodKernel32 = 0;
     78 WINEXCEPTION_FRAME exceptFrame;
     79 ULONG curdisk, curlogdisk, flength = CCHMAXPATH;
    7380
    7481  rc = DosLoadModule(exeName, sizeof(exeName), "PMWIN.DLL", &hmodPMWin);
     
    8188  rc = DosLoadModule(exeName, sizeof(exeName), "KERNEL32.DLL", &hmodKernel32);
    8289  rc = DosQueryProcAddr(hmodKernel32, 0, "CreateWin32Exe", (PFN *)&CreateWin32Exe);
     90  rc = DosQueryProcAddr(hmodKernel32, 0, "OS2SetExceptionHandler", (PFN *)&Krnl32SetExceptionHandler);
     91  rc = DosQueryProcAddr(hmodKernel32, 0, "OS2UnsetExceptionHandler", (PFN *)&Krnl32UnsetExceptionHandler);
    8392
    8493  if ((hab = MyWinInitialize(0)) == 0L) /* Initialize PM     */
    85         return(1);
     94        goto fail;
    8695
    8796  hmq = MyWinCreateMsgQueue(hab, 0);
     
    8998  if(argc < 2) {
    9099        MyWinMessageBox(HWND_DESKTOP, NULL, INFO_BANNER, szErrorTitle, 0, MB_OK | MB_ERROR | MB_MOVEABLE);
    91         return(0);
     100        goto fail;
    92101  }
    93102
     
    100109  if(WinExe == NULL) {
    101110        MyWinMessageBox(HWND_DESKTOP, HWND_DESKTOP, szMemErrorMsg, szErrorTitle, 0, MB_OK | MB_ERROR | MB_MOVEABLE);
    102         return(1);
     111        goto fail;
    103112  }
    104113  rc = DosGetInfoBlocks(&ptib, &ppib);
     
    106115        MyWinMessageBox(HWND_DESKTOP, HWND_DESKTOP, szInteralErrorMsg, szErrorTitle, 0, MB_OK | MB_ERROR | MB_MOVEABLE);
    107116        delete WinExe;
    108         return(1);
     117        goto fail;
    109118  }
    110119  szCmdLine = ppib->pib_pchcmd;
     
    115124  while(*szCmdLine == ' ' && *szCmdLine )       //skip spaces
    116125        szCmdLine++;
    117 
    118   ULONG curdisk, curlogdisk, flength = CCHMAXPATH;
    119126
    120127  DosQueryCurrentDisk(&curdisk, &curlogdisk);
     
    128135  WinExe->setCommandLine(szCmdLine);
    129136
     137  Krnl32SetExceptionHandler(&exceptFrame);
    130138  if(WinExe->init(ReserveMem()) == FALSE) {
    131139        delete WinExe;
    132         return(1);
     140        goto fail;
    133141  }
     142  Krnl32UnsetExceptionHandler(&exceptFrame);
    134143  WinExe->start();
    135144
     
    141150  DosFreeModule(hmodPMWin);
    142151  DosFreeModule(hmodKernel32);
    143   return(0);
     152  return 0;
     153
     154fail:
     155  if(hmq) MyWinDestroyMsgQueue( hmq );             /* Tidy up...                   */
     156  if(hab) MyWinTerminate( hab );                   /* Terminate the application    */
     157
     158  if(hmodPMWin)         DosFreeModule(hmodPMWin);
     159  if(hmodKernel32)      DosFreeModule(hmodKernel32);
     160  return(1);
    144161}
    145162//******************************************************************************
Note: See TracChangeset for help on using the changeset viewer.