Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

52 lines
1.1 KiB

  1. /* CheckPtr.c
  2. Pointer validation routine
  3. Written by t-jasonf.
  4. */
  5. #include "windows.h"
  6. #include "dde.h"
  7. #include "ole.h"
  8. #include "cmacs.h"
  9. #include "srvr.h"
  10. /* CheckPointer()
  11. Parameters :
  12. LPVOID lp - pointer to check
  13. int nREADWRITE - READ_ACCESS or WRITE_ACCESS
  14. Returns:
  15. 0 if process does not have that kind of access to memory at lp.
  16. 1 if process does have access.
  17. */
  18. WORD CheckPointer (void *lp, int nReadWrite)
  19. {
  20. char ch;
  21. WORD iRet;
  22. try
  23. {
  24. switch (nReadWrite)
  25. {
  26. case READ_ACCESS:
  27. ch = *((volatile char *)lp);
  28. break;
  29. case WRITE_ACCESS:
  30. ch = *((volatile char *)lp);
  31. *((volatile char *)lp) = ch;
  32. break;
  33. }
  34. iRet = 1;
  35. }
  36. except ( /*
  37. GetExceptionCode == STATUS_ACCESS_VIOLATION
  38. ? EXCEPTION_EXECUTE_HANDLER
  39. : EXCEPTION_CONTINUE_SEARCH
  40. */
  41. EXCEPTION_EXECUTE_HANDLER
  42. )
  43. {
  44. iRet = 0;
  45. }
  46. return iRet;
  47. }