home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / vc98 / crt / src / platform / sehsupp.c < prev    next >
C/C++ Source or Header  |  1998-06-17  |  1KB  |  55 lines

  1. /***
  2. *sehsupp.c - helper functions for Structured Exception Handling support
  3. *
  4. *       Copyright (C) 1993-1997, Microsoft Corporation. All rights reserved.
  5. *
  6. *Purpose:
  7. *       Contains _rt_probe_read.  Helper for the SEH runtime support
  8. *       routines (longjmp in particular).  Much of the SEH code is written
  9. *       in asm, so these routines are available when probing memory in ways
  10. *       that must be guarded with __try/__except in case of access violation.
  11. *
  12. *******************************************************************************/
  13.  
  14. #ifndef WIN32_LEAN_AND_MEAN
  15. #define WIN32_LEAN_AND_MEAN 1
  16. #endif  /* WIN32_LEAN_AND_MEAN */
  17.  
  18. #include <windows.h>
  19.  
  20. /***
  21. *BOOL __stdcall _rt_probe_read4 - Check if a DWORD is readable
  22. *
  23. *Purpose:
  24. *  Internal support function called by longjmp.  Check if a DWORD is
  25. *  readable under a __try/__except.
  26. *
  27. *Entry:
  28. *  DWORD * p - Pointer to DWORD to be probed
  29. *
  30. *Exit:
  31. *  Success: TRUE - Able to read
  32. *  Failure: FALSE - Access violation while reading
  33. *
  34. ******************************************************************************/
  35.  
  36. BOOL __stdcall _rt_probe_read4(
  37.     DWORD * ptr)
  38. {
  39.     BOOL readable;
  40.  
  41.     __try
  42.     {
  43.         *(volatile DWORD *)ptr;
  44.         readable = TRUE;
  45.     }
  46.     __except (GetExceptionCode() == EXCEPTION_ACCESS_VIOLATION
  47.                 ? EXCEPTION_EXECUTE_HANDLER
  48.                 : EXCEPTION_CONTINUE_SEARCH)
  49.     {
  50.         readable = FALSE;
  51.     }
  52.  
  53.     return readable;
  54. }
  55.