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.

49 lines
1.0 KiB

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