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

//---------------------------------------------------------------------------
// errors.cpp - support for error handling/reporting
//---------------------------------------------------------------------------
#include "stdafx.h"
#include <time.h>
#include "utils.h"
#include "errors.h"
//---------------------------------------------------------------------------
DWORD _tls_ErrorInfoIndex = 0xffffffff; // index to tls pObjectPool
//---------------------------------------------------------------------------
TMERRINFO *GetParseErrorInfo(BOOL fOkToCreate)
{
TMERRINFO *ei = NULL;
if (_tls_ErrorInfoIndex != 0xffffffff) // init-ed in ProcessAttach()
{
ei = (TMERRINFO *)TlsGetValue(_tls_ErrorInfoIndex);
if ((! ei) && (fOkToCreate)) // not yet initialized
{
//---- create a thread-local TMERRINFO ----
ei = new TMERRINFO;
TlsSetValue(_tls_ErrorInfoIndex, ei);
}
}
return ei;
}
//---------------------------------------------------------------------------
HRESULT MakeParseError(DWORD dwParseErrCode, OPTIONAL LPCWSTR pszMsgParam1,
OPTIONAL LPCWSTR pszMsgParam2, OPTIONAL LPCWSTR pszSourceName,
OPTIONAL LPCWSTR pszSourceLine, int iLineNum)
{
TMERRINFO *pErrInfo = GetParseErrorInfo(TRUE);
if (pErrInfo) // record err info for later use
{
pErrInfo->dwParseErrCode = dwParseErrCode;
pErrInfo->iLineNum = iLineNum;
SafeStringCchCopyW(pErrInfo->szMsgParam1, ARRAYSIZE(pErrInfo->szMsgParam1), pszMsgParam1);
SafeStringCchCopyW(pErrInfo->szMsgParam2, ARRAYSIZE(pErrInfo->szMsgParam2), pszMsgParam2);
SafeStringCchCopyW(pErrInfo->szFileName, ARRAYSIZE(pErrInfo->szFileName), pszSourceName);
SafeStringCchCopyW(pErrInfo->szSourceLine, ARRAYSIZE(pErrInfo->szSourceLine), pszSourceLine);
}
return HRESULT_FROM_WIN32(ERROR_UNKNOWN_PROPERTY); // special code for parse failed
}
//---------------------------------------------------------------------------
HRESULT MakeError32(HRESULT hr)
{
return HRESULT_FROM_WIN32(hr);
}
//---------------------------------------------------------------------------
HRESULT MakeErrorLast()
{
HRESULT hr = GetLastError();
return HRESULT_FROM_WIN32(hr);
}
//---------------------------------------------------------------------------
HRESULT MakeErrorParserLast()
{
return HRESULT_FROM_WIN32(ERROR_UNKNOWN_PROPERTY); // parse error info has already been set
}
//---------------------------------------------------------------------------