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.

65 lines
2.6 KiB

  1. //---------------------------------------------------------------------------
  2. // errors.cpp - support for error handling/reporting
  3. //---------------------------------------------------------------------------
  4. #include "stdafx.h"
  5. #include <time.h>
  6. #include "utils.h"
  7. #include "errors.h"
  8. //---------------------------------------------------------------------------
  9. DWORD _tls_ErrorInfoIndex = 0xffffffff; // index to tls pObjectPool
  10. //---------------------------------------------------------------------------
  11. TMERRINFO *GetParseErrorInfo(BOOL fOkToCreate)
  12. {
  13. TMERRINFO *ei = NULL;
  14. if (_tls_ErrorInfoIndex != 0xffffffff) // init-ed in ProcessAttach()
  15. {
  16. ei = (TMERRINFO *)TlsGetValue(_tls_ErrorInfoIndex);
  17. if ((! ei) && (fOkToCreate)) // not yet initialized
  18. {
  19. //---- create a thread-local TMERRINFO ----
  20. ei = new TMERRINFO;
  21. TlsSetValue(_tls_ErrorInfoIndex, ei);
  22. }
  23. }
  24. return ei;
  25. }
  26. //---------------------------------------------------------------------------
  27. HRESULT MakeParseError(DWORD dwParseErrCode, OPTIONAL LPCWSTR pszMsgParam1,
  28. OPTIONAL LPCWSTR pszMsgParam2, OPTIONAL LPCWSTR pszSourceName,
  29. OPTIONAL LPCWSTR pszSourceLine, int iLineNum)
  30. {
  31. TMERRINFO *pErrInfo = GetParseErrorInfo(TRUE);
  32. if (pErrInfo) // record err info for later use
  33. {
  34. pErrInfo->dwParseErrCode = dwParseErrCode;
  35. pErrInfo->iLineNum = iLineNum;
  36. SafeStringCchCopyW(pErrInfo->szMsgParam1, ARRAYSIZE(pErrInfo->szMsgParam1), pszMsgParam1);
  37. SafeStringCchCopyW(pErrInfo->szMsgParam2, ARRAYSIZE(pErrInfo->szMsgParam2), pszMsgParam2);
  38. SafeStringCchCopyW(pErrInfo->szFileName, ARRAYSIZE(pErrInfo->szFileName), pszSourceName);
  39. SafeStringCchCopyW(pErrInfo->szSourceLine, ARRAYSIZE(pErrInfo->szSourceLine), pszSourceLine);
  40. }
  41. return HRESULT_FROM_WIN32(ERROR_UNKNOWN_PROPERTY); // special code for parse failed
  42. }
  43. //---------------------------------------------------------------------------
  44. HRESULT MakeError32(HRESULT hr)
  45. {
  46. return HRESULT_FROM_WIN32(hr);
  47. }
  48. //---------------------------------------------------------------------------
  49. HRESULT MakeErrorLast()
  50. {
  51. HRESULT hr = GetLastError();
  52. return HRESULT_FROM_WIN32(hr);
  53. }
  54. //---------------------------------------------------------------------------
  55. HRESULT MakeErrorParserLast()
  56. {
  57. return HRESULT_FROM_WIN32(ERROR_UNKNOWN_PROPERTY); // parse error info has already been set
  58. }
  59. //---------------------------------------------------------------------------