home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / except2x.zip / trapperq.c < prev    next >
Text File  |  1993-12-02  |  3KB  |  68 lines

  1. /**********************************************************************/
  2. /*                           IBM Internal Use Only                    */
  3. /**********************************************************************/
  4. /*                                                                    */
  5. /*  TRAPPERQ                                                          */
  6. /*                                                                    */
  7. /* Program demonstration EXCEPTQ.DLL usage                            */
  8. /* TrapperQ is preferable to Trapper which uses EXCEPT.DLL            */
  9. /* Compiled with IBM C/2 see SAMPLE.C for 32 bit C-SET/2 sample       */
  10. /**********************************************************************/
  11. /* Version: 2.2             |   Marc Fiammante (FIAMMANT at LGEVM2)   */
  12. /**********************************************************************/
  13. /*                                                                    */
  14. /**********************************************************************/
  15. /* History:                                                           */
  16. /* --------                                                           */
  17. /*                                                                    */
  18. /* created: Marc Fiammante December 1992                              */
  19. /**********************************************************************/
  20. #include <mt\stdio.h>
  21. #include <mt\conio.h>
  22. #include <mt\process.h>
  23. #define INCL_BASE
  24. #include <os2.h>
  25. USHORT rc;
  26. PCHAR  Test;
  27. struct _EXCEPTIONREGISTRATIONRECORD
  28.    {
  29.       struct _EXCEPTIONREGISTRATIONRECORD * prev_structure;
  30.       PFN Handler;
  31.    };
  32. typedef struct _EXCEPTIONREGISTRATIONRECORD EXCEPTIONREGISTRATIONRECORD;
  33. typedef struct _EXCEPTIONREGISTRATIONRECORD * PEXCEPTIONREGISTRATIONRECORD;
  34. USHORT EXPENTRY SETEXCEPT(PEXCEPTIONREGISTRATIONRECORD);
  35. USHORT EXPENTRY UNSETEXCEPT(PEXCEPTIONREGISTRATIONRECORD);
  36. TID Tid;
  37. #define STACKSIZE 0x2000
  38. SEL   SelStack;
  39. PCHAR StackPtr;
  40. void   Thread(unsigned far *args);         /* Playing   thread function   */
  41. void cdecl main() {
  42.     EXCEPTIONREGISTRATIONRECORD ExceptReg;
  43.     printf("Setting exception handler\n");
  44.     rc=SETEXCEPT(&ExceptReg);
  45.     DosAllocSeg(STACKSIZE,&SelStack,1);
  46.     StackPtr=MAKEP(SelStack,0);
  47.     Tid=_beginthread(
  48.        Thread,
  49.        (VOID FAR *)StackPtr,
  50.        STACKSIZE,
  51.        NULL);
  52.       getch();
  53.     rc=UNSETEXCEPT(&ExceptReg);
  54. }
  55. void TrapFct(PCHAR Parm) { /* Demonstrates stack walk */
  56.     PCHAR  Test;
  57.     printf("Generating the TRAP from thread\n");
  58.     Test=Parm;
  59.     *Test=0;
  60. }
  61. void   Thread(unsigned far *args) {
  62.     EXCEPTIONREGISTRATIONRECORD ExceptReg;
  63.     printf("Setting exception handler from the thread\n");
  64.     rc=SETEXCEPT(&ExceptReg);
  65.     TrapFct(NULL);
  66.     rc=UNSETEXCEPT(&ExceptReg);
  67. }
  68.