home *** CD-ROM | disk | FTP | other *** search
/ DP Tool Club 15 / CD_ASCQ_15_070894.iso / vrac / memsz231.zip / EXCEPT.CPP < prev    next >
Text File  |  1994-01-25  |  15KB  |  398 lines

  1. /**************************************************************** EXCEPT.CPP
  2.  *                                                                         *
  3.  *                            Exception Handler                            *
  4.  *                                                                         *
  5.  ***************************************************************************/
  6.  
  7. #define INCL_BASE
  8. #define INCL_PM
  9. #include <os2.h>
  10.  
  11. #include <stdlib.h>
  12.  
  13. #include "debug.h"
  14. #include "restring.h"
  15. #include "memsize.h"
  16.  
  17. #include "except.h"
  18.  
  19.  
  20. /***************************************************************************
  21.  *                                                                         *
  22.  *  Exception Handler                                                      *
  23.  *                                                                         *
  24.  ***************************************************************************/
  25.  
  26. extern ULONG APIENTRY ExceptionHandler
  27. (
  28.   PEXCEPTIONREPORTRECORD pExceptionReportRecord,
  29.   PEXCEPTIONREGISTRATIONRECORD pExceptionRegistrationRecord,
  30.   PCONTEXTRECORD pContextRecord,
  31.   PVOID pDispatcherContext
  32. )
  33. {
  34.    static BOOL Active = FALSE ;
  35.    PLONG Base ;
  36.  
  37.    if ( pExceptionReportRecord->ExceptionNum == XCPT_ACCESS_VIOLATION ) {
  38.       if ( Active ) {
  39.          Log ( "ABORT: Recursion with exception handler." ) ;
  40.          DosExit ( EXIT_PROCESS, 0 ) ;
  41.       } /* endif */
  42.       Active = TRUE ;
  43.       Log
  44.       (
  45.         "ABORT: %s%s%s%s%s%sviolation trying to access address/selector %08lX.\n"
  46.         "  The registers were as follows:\n"
  47.         "    AX:%08lX  BX:%08lX  CX:%08lX  DX:%08lX\n"
  48.         "    FL:%08lX  DI:%08lX  SI:%08lX  BP:%08lX\n"
  49.         "    CS:%08lX  IP:%08lX  SS:%08lX  SP:%08lX\n"
  50.         "    DS:%08lX  ES:%08lX  FS:%08lX  GS:%08lX",
  51.         ( pExceptionReportRecord->ExceptionInfo[0] & XCPT_READ_ACCESS ) ? "Read " : "",
  52.         ( pExceptionReportRecord->ExceptionInfo[0] & XCPT_WRITE_ACCESS ) ? "Write " : "",
  53.         ( pExceptionReportRecord->ExceptionInfo[0] & XCPT_EXECUTE_ACCESS ) ? "Execute " : "",
  54.         ( pExceptionReportRecord->ExceptionInfo[0] & XCPT_SPACE_ACCESS ) ? "Space " : "",
  55.         ( pExceptionReportRecord->ExceptionInfo[0] & XCPT_LIMIT_ACCESS ) ? "Limit " : "",
  56.         ( pExceptionReportRecord->ExceptionInfo[0] & XCPT_UNKNOWN_ACCESS ) ? "Unknown " : "",
  57.         pExceptionReportRecord->ExceptionInfo[1],
  58.         pContextRecord->ctx_RegEax,
  59.         pContextRecord->ctx_RegEbx,
  60.         pContextRecord->ctx_RegEcx,
  61.         pContextRecord->ctx_RegEdx,
  62.         pContextRecord->ctx_EFlags,
  63.         pContextRecord->ctx_RegEdi,
  64.         pContextRecord->ctx_RegEsi,
  65.         pContextRecord->ctx_RegEbp,
  66.         pContextRecord->ctx_SegCs,
  67.         pContextRecord->ctx_RegEip,
  68.         pContextRecord->ctx_SegSs,
  69.         pContextRecord->ctx_RegEsp,
  70.         pContextRecord->ctx_SegDs,
  71.         pContextRecord->ctx_SegEs,
  72.         pContextRecord->ctx_SegFs,
  73.         pContextRecord->ctx_SegGs
  74.       ) ;
  75.  
  76.       ResourceString Exception ( LibraryHandle, IDS_EXCEPTION ) ;
  77.       Debug ( HWND_DESKTOP, PCHAR(Exception), _fullpath(PCHAR(NULL),LOGFILE,0) ) ;
  78.  
  79.       Base = (PLONG)pContextRecord->ctx_RegEbp ;
  80.       while ( Base && ( *Base > (LONG)Base ) ) {
  81.         Log ( "  Calling function was at %08lX.", *(Base+1) ) ;
  82.         Base = (PLONG)*Base ;
  83.       } /* endwhile */
  84.  
  85.       DosExit ( EXIT_PROCESS, 0 ) ;
  86.    }
  87.  
  88.    if ( pExceptionReportRecord->ExceptionNum == XCPT_PRIVILEGED_INSTRUCTION ) {
  89.       if ( Active ) {
  90.          Log ( "ABORT: Recursion with exception handler." ) ;
  91.          DosExit ( EXIT_PROCESS, 0 ) ;
  92.       } /* endif */
  93.       Active = TRUE ;
  94.       Log
  95.       (
  96.         "ABORT: A privileged instruction was encountered.\n"
  97.         "  The registers were as follows:\n"
  98.         "    AX:%08lX  BX:%08lX  CX:%08lX  DX:%08lX\n"
  99.         "    FL:%08lX  DI:%08lX  SI:%08lX  BP:%08lX\n"
  100.         "    CS:%08lX  IP:%08lX  SS:%08lX  SP:%08lX\n"
  101.         "    DS:%08lX  ES:%08lX  FS:%08lX  GS:%08lX",
  102.         pContextRecord->ctx_RegEax,
  103.         pContextRecord->ctx_RegEbx,
  104.         pContextRecord->ctx_RegEcx,
  105.         pContextRecord->ctx_RegEdx,
  106.         pContextRecord->ctx_EFlags,
  107.         pContextRecord->ctx_RegEdi,
  108.         pContextRecord->ctx_RegEsi,
  109.         pContextRecord->ctx_RegEbp,
  110.         pContextRecord->ctx_SegCs,
  111.         pContextRecord->ctx_RegEip,
  112.         pContextRecord->ctx_SegSs,
  113.         pContextRecord->ctx_RegEsp,
  114.         pContextRecord->ctx_SegDs,
  115.         pContextRecord->ctx_SegEs,
  116.         pContextRecord->ctx_SegFs,
  117.         pContextRecord->ctx_SegGs
  118.       ) ;
  119.  
  120.       ResourceString Exception ( LibraryHandle, IDS_EXCEPTION ) ;
  121.       Debug ( HWND_DESKTOP, PCHAR(Exception), _fullpath(PCHAR(NULL),LOGFILE,0) ) ;
  122.  
  123.       Base = (PLONG)pContextRecord->ctx_RegEbp ;
  124.       while ( Base && ( *Base > (LONG)Base ) ) {
  125.         Log ( "  Calling function was at %08lX.", *(Base+1) ) ;
  126.         Base = (PLONG)*Base ;
  127.       } /* endwhile */
  128.  
  129.       DosExit ( EXIT_PROCESS, 0 ) ;
  130.    }
  131.  
  132.    if ( pExceptionReportRecord->ExceptionNum == XCPT_ILLEGAL_INSTRUCTION ) {
  133.       if ( Active ) {
  134.          Log ( "ABORT: Recursion with exception handler." ) ;
  135.          DosExit ( EXIT_PROCESS, 0 ) ;
  136.       } /* endif */
  137.       Active = TRUE ;
  138.       Log
  139.       (
  140.         "ABORT: An illegal instruction was encountered.\n"
  141.         "  The registers were as follows:\n"
  142.         "    AX:%08lX  BX:%08lX  CX:%08lX  DX:%08lX\n"
  143.         "    FL:%08lX  DI:%08lX  SI:%08lX  BP:%08lX\n"
  144.         "    CS:%08lX  IP:%08lX  SS:%08lX  SP:%08lX\n"
  145.         "    DS:%08lX  ES:%08lX  FS:%08lX  GS:%08lX",
  146.         pContextRecord->ctx_RegEax,
  147.         pContextRecord->ctx_RegEbx,
  148.         pContextRecord->ctx_RegEcx,
  149.         pContextRecord->ctx_RegEdx,
  150.         pContextRecord->ctx_EFlags,
  151.         pContextRecord->ctx_RegEdi,
  152.         pContextRecord->ctx_RegEsi,
  153.         pContextRecord->ctx_RegEbp,
  154.         pContextRecord->ctx_SegCs,
  155.         pContextRecord->ctx_RegEip,
  156.         pContextRecord->ctx_SegSs,
  157.         pContextRecord->ctx_RegEsp,
  158.         pContextRecord->ctx_SegDs,
  159.         pContextRecord->ctx_SegEs,
  160.         pContextRecord->ctx_SegFs,
  161.         pContextRecord->ctx_SegGs
  162.       ) ;
  163.  
  164.       ResourceString Exception ( LibraryHandle, IDS_EXCEPTION ) ;
  165.       Debug ( HWND_DESKTOP, PCHAR(Exception), _fullpath(PCHAR(NULL),LOGFILE,0) ) ;
  166.  
  167.       Base = (PLONG)pContextRecord->ctx_RegEbp ;
  168.       while ( Base && ( *Base > (LONG)Base ) ) {
  169.         Log ( "  Calling function was at %08lX.", *(Base+1) ) ;
  170.         Base = (PLONG)*Base ;
  171.       } /* endwhile */
  172.  
  173.       DosExit ( EXIT_PROCESS, 0 ) ;
  174.    }
  175.  
  176.    if ( pExceptionReportRecord->ExceptionNum == XCPT_INTEGER_DIVIDE_BY_ZERO ) {
  177.       if ( Active ) {
  178.          Log ( "ABORT: Recursion with exception handler." ) ;
  179.          DosExit ( EXIT_PROCESS, 0 ) ;
  180.       } /* endif */
  181.       Active = TRUE ;
  182.       Log
  183.       (
  184.         "ABORT: An integer divide-by-zero error has occurred.\n"
  185.         "  The registers were as follows:\n"
  186.         "    AX:%08lX  BX:%08lX  CX:%08lX  DX:%08lX\n"
  187.         "    FL:%08lX  DI:%08lX  SI:%08lX  BP:%08lX\n"
  188.         "    CS:%08lX  IP:%08lX  SS:%08lX  SP:%08lX\n"
  189.         "    DS:%08lX  ES:%08lX  FS:%08lX  GS:%08lX",
  190.         pContextRecord->ctx_RegEax,
  191.         pContextRecord->ctx_RegEbx,
  192.         pContextRecord->ctx_RegEcx,
  193.         pContextRecord->ctx_RegEdx,
  194.         pContextRecord->ctx_EFlags,
  195.         pContextRecord->ctx_RegEdi,
  196.         pContextRecord->ctx_RegEsi,
  197.         pContextRecord->ctx_RegEbp,
  198.         pContextRecord->ctx_SegCs,
  199.         pContextRecord->ctx_RegEip,
  200.         pContextRecord->ctx_SegSs,
  201.         pContextRecord->ctx_RegEsp,
  202.         pContextRecord->ctx_SegDs,
  203.         pContextRecord->ctx_SegEs,
  204.         pContextRecord->ctx_SegFs,
  205.         pContextRecord->ctx_SegGs
  206.       ) ;
  207.  
  208.       ResourceString Exception ( LibraryHandle, IDS_EXCEPTION ) ;
  209.       Debug ( HWND_DESKTOP, PCHAR(Exception), _fullpath(PCHAR(NULL),LOGFILE,0) ) ;
  210.  
  211.       Base = (PLONG)pContextRecord->ctx_RegEbp ;
  212.       while ( Base && ( *Base > (LONG)Base ) ) {
  213.         Log ( "  Calling function was at %08lX.", *(Base+1) ) ;
  214.         Base = (PLONG)*Base ;
  215.       } /* endwhile */
  216.  
  217.       DosExit ( EXIT_PROCESS, 0 ) ;
  218.    }
  219.  
  220.    if ( pExceptionReportRecord->ExceptionNum == XCPT_INTEGER_OVERFLOW ) {
  221.       if ( Active ) {
  222.          Log ( "ABORT: Recursion with exception handler." ) ;
  223.          DosExit ( EXIT_PROCESS, 0 ) ;
  224.       } /* endif */
  225.       Active = TRUE ;
  226.       Log
  227.       (
  228.         "ABORT: An integer overflow has occurred.\n"
  229.         "  The registers were as follows:\n"
  230.         "    AX:%08lX  BX:%08lX  CX:%08lX  DX:%08lX\n"
  231.         "    FL:%08lX  DI:%08lX  SI:%08lX  BP:%08lX\n"
  232.         "    CS:%08lX  IP:%08lX  SS:%08lX  SP:%08lX\n"
  233.         "    DS:%08lX  ES:%08lX  FS:%08lX  GS:%08lX",
  234.         pContextRecord->ctx_RegEax,
  235.         pContextRecord->ctx_RegEbx,
  236.         pContextRecord->ctx_RegEcx,
  237.         pContextRecord->ctx_RegEdx,
  238.         pContextRecord->ctx_EFlags,
  239.         pContextRecord->ctx_RegEdi,
  240.         pContextRecord->ctx_RegEsi,
  241.         pContextRecord->ctx_RegEbp,
  242.         pContextRecord->ctx_SegCs,
  243.         pContextRecord->ctx_RegEip,
  244.         pContextRecord->ctx_SegSs,
  245.         pContextRecord->ctx_RegEsp,
  246.         pContextRecord->ctx_SegDs,
  247.         pContextRecord->ctx_SegEs,
  248.         pContextRecord->ctx_SegFs,
  249.         pContextRecord->ctx_SegGs
  250.       ) ;
  251.  
  252.       ResourceString Exception ( LibraryHandle, IDS_EXCEPTION ) ;
  253.       Debug ( HWND_DESKTOP, PCHAR(Exception), _fullpath(PCHAR(NULL),LOGFILE,0) ) ;
  254.  
  255.       Base = (PLONG)pContextRecord->ctx_RegEbp ;
  256.       while ( Base && ( *Base > (LONG)Base ) ) {
  257.         Log ( "  Calling function was at %08lX.", *(Base+1) ) ;
  258.         Base = (PLONG)*Base ;
  259.       } /* endwhile */
  260.  
  261.       DosExit ( EXIT_PROCESS, 0 ) ;
  262.    }
  263.  
  264.    if ( pExceptionReportRecord->ExceptionNum == XCPT_FLOAT_DIVIDE_BY_ZERO ) {
  265.       if ( Active ) {
  266.          Log ( "ABORT: Recursion with exception handler." ) ;
  267.          DosExit ( EXIT_PROCESS, 0 ) ;
  268.       } /* endif */
  269.       Active = TRUE ;
  270.       Log
  271.       (
  272.         "ABORT: A floating point divide by zero error has occurred.\n"
  273.         "  The registers were as follows:\n"
  274.         "    AX:%08lX  BX:%08lX  CX:%08lX  DX:%08lX\n"
  275.         "    FL:%08lX  DI:%08lX  SI:%08lX  BP:%08lX\n"
  276.         "    CS:%08lX  IP:%08lX  SS:%08lX  SP:%08lX\n"
  277.         "    DS:%08lX  ES:%08lX  FS:%08lX  GS:%08lX",
  278.         pContextRecord->ctx_RegEax,
  279.         pContextRecord->ctx_RegEbx,
  280.         pContextRecord->ctx_RegEcx,
  281.         pContextRecord->ctx_RegEdx,
  282.         pContextRecord->ctx_EFlags,
  283.         pContextRecord->ctx_RegEdi,
  284.         pContextRecord->ctx_RegEsi,
  285.         pContextRecord->ctx_RegEbp,
  286.         pContextRecord->ctx_SegCs,
  287.         pContextRecord->ctx_RegEip,
  288.         pContextRecord->ctx_SegSs,
  289.         pContextRecord->ctx_RegEsp,
  290.         pContextRecord->ctx_SegDs,
  291.         pContextRecord->ctx_SegEs,
  292.         pContextRecord->ctx_SegFs,
  293.         pContextRecord->ctx_SegGs
  294.       ) ;
  295.  
  296.       ResourceString Exception ( LibraryHandle, IDS_EXCEPTION ) ;
  297.       Debug ( HWND_DESKTOP, PCHAR(Exception), _fullpath(PCHAR(NULL),LOGFILE,0) ) ;
  298.  
  299.       Base = (PLONG)pContextRecord->ctx_RegEbp ;
  300.       while ( Base && ( *Base > (LONG)Base ) ) {
  301.         Log ( "  Calling function was at %08lX.", *(Base+1) ) ;
  302.         Base = (PLONG)*Base ;
  303.       } /* endwhile */
  304.  
  305.       DosExit ( EXIT_PROCESS, 0 ) ;
  306.    }
  307.  
  308.    if ( pExceptionReportRecord->ExceptionNum == XCPT_FLOAT_OVERFLOW ) {
  309.       if ( Active ) {
  310.          Log ( "ABORT: Recursion with exception handler." ) ;
  311.          DosExit ( EXIT_PROCESS, 0 ) ;
  312.       } /* endif */
  313.       Active = TRUE ;
  314.       Log
  315.       (
  316.         "ABORT: A floating point overflow error has occurred.\n"
  317.         "  The registers were as follows:\n"
  318.         "    AX:%08lX  BX:%08lX  CX:%08lX  DX:%08lX\n"
  319.         "    FL:%08lX  DI:%08lX  SI:%08lX  BP:%08lX\n"
  320.         "    CS:%08lX  IP:%08lX  SS:%08lX  SP:%08lX\n"
  321.         "    DS:%08lX  ES:%08lX  FS:%08lX  GS:%08lX",
  322.         pContextRecord->ctx_RegEax,
  323.         pContextRecord->ctx_RegEbx,
  324.         pContextRecord->ctx_RegEcx,
  325.         pContextRecord->ctx_RegEdx,
  326.         pContextRecord->ctx_EFlags,
  327.         pContextRecord->ctx_RegEdi,
  328.         pContextRecord->ctx_RegEsi,
  329.         pContextRecord->ctx_RegEbp,
  330.         pContextRecord->ctx_SegCs,
  331.         pContextRecord->ctx_RegEip,
  332.         pContextRecord->ctx_SegSs,
  333.         pContextRecord->ctx_RegEsp,
  334.         pContextRecord->ctx_SegDs,
  335.         pContextRecord->ctx_SegEs,
  336.         pContextRecord->ctx_SegFs,
  337.         pContextRecord->ctx_SegGs
  338.       ) ;
  339.  
  340.       ResourceString Exception ( LibraryHandle, IDS_EXCEPTION ) ;
  341.       Debug ( HWND_DESKTOP, PCHAR(Exception), _fullpath(PCHAR(NULL),LOGFILE,0) ) ;
  342.  
  343.       Base = (PLONG)pContextRecord->ctx_RegEbp ;
  344.       while ( Base && ( *Base > (LONG)Base ) ) {
  345.         Log ( "  Calling function was at %08lX.", *(Base+1) ) ;
  346.         Base = (PLONG)*Base ;
  347.       } /* endwhile */
  348.  
  349.       DosExit ( EXIT_PROCESS, 0 ) ;
  350.    }
  351.  
  352.    if ( pExceptionReportRecord->ExceptionNum == XCPT_FLOAT_UNDERFLOW ) {
  353.       if ( Active ) {
  354.          Log ( "ABORT: Recursion with exception handler." ) ;
  355.          DosExit ( EXIT_PROCESS, 0 ) ;
  356.       } /* endif */
  357.       Active = TRUE ;
  358.       Log
  359.       (
  360.         "ABORT: A floating point underflow error has occurred.\n"
  361.         "  The registers were as follows:\n"
  362.         "    AX:%08lX  BX:%08lX  CX:%08lX  DX:%08lX\n"
  363.         "    FL:%08lX  DI:%08lX  SI:%08lX  BP:%08lX\n"
  364.         "    CS:%08lX  IP:%08lX  SS:%08lX  SP:%08lX\n"
  365.         "    DS:%08lX  ES:%08lX  FS:%08lX  GS:%08lX",
  366.         pContextRecord->ctx_RegEax,
  367.         pContextRecord->ctx_RegEbx,
  368.         pContextRecord->ctx_RegEcx,
  369.         pContextRecord->ctx_RegEdx,
  370.         pContextRecord->ctx_EFlags,
  371.         pContextRecord->ctx_RegEdi,
  372.         pContextRecord->ctx_RegEsi,
  373.         pContextRecord->ctx_RegEbp,
  374.         pContextRecord->ctx_SegCs,
  375.         pContextRecord->ctx_RegEip,
  376.         pContextRecord->ctx_SegSs,
  377.         pContextRecord->ctx_RegEsp,
  378.         pContextRecord->ctx_SegDs,
  379.         pContextRecord->ctx_SegEs,
  380.         pContextRecord->ctx_SegFs,
  381.         pContextRecord->ctx_SegGs
  382.       ) ;
  383.  
  384.       ResourceString Exception ( LibraryHandle, IDS_EXCEPTION ) ;
  385.       Debug ( HWND_DESKTOP, PCHAR(Exception), _fullpath(PCHAR(NULL),LOGFILE,0) ) ;
  386.  
  387.       Base = (PLONG)pContextRecord->ctx_RegEbp ;
  388.       while ( Base && ( *Base > (LONG)Base ) ) {
  389.         Log ( "  Calling function was at %08lX.", *(Base+1) ) ;
  390.         Base = (PLONG)*Base ;
  391.       } /* endwhile */
  392.  
  393.       DosExit ( EXIT_PROCESS, 0 ) ;
  394.    }
  395.  
  396.    return ( XCPT_CONTINUE_SEARCH ) ;
  397. }
  398.