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.

89 lines
2.2 KiB

  1. /***
  2. *userapi.cpp - RTC support
  3. *
  4. * Copyright (c) 1998-2001, Microsoft Corporation. All rights reserved.
  5. *
  6. *
  7. *Revision History:
  8. * 07-28-98 JWM Module incorporated into CRTs (from KFrei)
  9. * 07-30-98 JWM errnum is now type _RTC_ErrorNumber throughout.
  10. * 10-09-98 KBF moved _RTC_IsEnabled to init.cpp (it now works for
  11. * EXE/DLL combos)
  12. * 05-11-99 KBF Error if RTC support define not enabled
  13. * 05-26-99 KBF Updated for -RTCu, -RTClv cancelled
  14. *
  15. ****/
  16. #ifndef _RTC
  17. #error RunTime Check support not enabled!
  18. #endif
  19. #include "rtcpriv.h"
  20. static const char *_RTC_errlist[_RTC_ILLEGAL] =
  21. {
  22. "Stack pointer corruption",
  23. "Cast to smaller type causing loss of data",
  24. "Stack memory corruption",
  25. "Local variable used before initialization"
  26. #ifdef _RTC_ADVMEM
  27. ,
  28. "Accessing invalid memory",
  29. "Accessing memory from different heap blocks"
  30. #endif
  31. };
  32. static _RTC_error_fn _RTC_ErrorReportFunc = 0;
  33. int __cdecl
  34. _RTC_NumErrors(void)
  35. {
  36. return _RTC_ILLEGAL;
  37. }
  38. const char * __cdecl
  39. _RTC_GetErrDesc(_RTC_ErrorNumber errnum)
  40. {
  41. if (errnum < 0 || errnum >= _RTC_ILLEGAL)
  42. return 0;
  43. return _RTC_errlist[errnum];
  44. }
  45. int __cdecl
  46. _RTC_SetErrorType(_RTC_ErrorNumber errnum, int type)
  47. {
  48. if (errnum >= 0 && errnum < _RTC_ILLEGAL)
  49. {
  50. int res = _RTC_ErrorLevels[errnum];
  51. _RTC_ErrorLevels[errnum] = type;
  52. return res;
  53. } else
  54. return -1;
  55. }
  56. _RTC_error_fn __cdecl
  57. _RTC_SetErrorFunc(_RTC_error_fn func)
  58. {
  59. // We've got a global data structure: add this to the error func list
  60. _RTC_error_fn res;
  61. res = _RTC_ErrorReportFunc;
  62. _RTC_ErrorReportFunc = func;
  63. return res;
  64. }
  65. _RTC_error_fn
  66. _RTC_GetErrorFunc(LPCVOID addr)
  67. {
  68. #ifdef _RTC_ADVMEM
  69. MEMORY_BASIC_INFORMATION mbi;
  70. if (!_RTC_globptr || !VirtualQuery(addr, &mbi, sizeof(mbi)))
  71. return _RTC_ErrorReportFunc;
  72. for (_RTC_Funcs *fn = _RTC_globptr->callbacks; fn; fn = fn->next)
  73. if (fn->allocationBase == mbi.AllocationBase)
  74. return fn->err;
  75. #endif
  76. return _RTC_ErrorReportFunc;
  77. }