err.h
Upload User: xhy777
Upload Date: 2007-02-14
Package Size: 24088k
Code Size: 11k
Category:

Windows Kernel

Development Platform:

Visual C++

  1. //
  2. // err.h: Declares data, defines and struct types for error handling
  3. //          module.
  4. //
  5. //
  6. #ifndef __ERR_H__
  7. #define __ERR_H__
  8. // Requires comm.h to be included prior to this
  9. //
  10. /////////////////////////////////////////////////////  INCLUDES
  11. /////////////////////////////////////////////////////  DEFINES
  12. #ifdef DEBUG
  13. // Dump flags used in g_uDumpFlags
  14. //
  15. #define DF_RECLIST      0x0001
  16. #define DF_RECITEM      0x0002
  17. #define DF_RECNODE      0x0004
  18. #define DF_CREATETWIN   0x0008
  19. #define DF_ATOMS        0x0010
  20. #define DF_CRL          0x0020
  21. #define DF_CBS          0x0040
  22. #define DF_CPATH        0x0080
  23. #define DF_PATHS        0x0100
  24. #define DF_UPDATECOUNT  0x0200
  25. #define DF_TWINPAIR     0x0400
  26. #define DF_FOLDERTWIN   0x0800
  27. #define DF_CHOOSESIDE   0x1000
  28. // Break flags used in g_uBreakFlags
  29. //
  30. #define BF_ONOPEN       0x0001
  31. #define BF_ONCLOSE      0x0002
  32. #define BF_ONRUNONCE    0x0004
  33. #define BF_ONVALIDATE   0x0010
  34. #define BF_ONTHREADATT  0x0100
  35. #define BF_ONTHREADDET  0x0200
  36. #define BF_ONPROCESSATT 0x0400
  37. #define BF_ONPROCESSDET 0x0800
  38. #endif
  39. // Trace flags used in g_uTraceFlags (defined in retail on purpose)
  40. //
  41. #define TF_ALWAYS       0x0000
  42. #define TF_WARNING      0x0001
  43. #define TF_ERROR        0x0002
  44. #define TF_GENERAL      0x0004      // Standard briefcase trace messages
  45. #define TF_FUNC         0x0008      // Trace function calls
  46. #define TF_CACHE        0x0010      // Cache-specific trace messages
  47. #define TF_ATOM         0x0020      // Atom-specific trace messages
  48. #define TF_PROGRESS     0x0040      // Progress bar deltas
  49. //---------------------------------------------------------------------------
  50. // HRESULT error codes
  51. //---------------------------------------------------------------------------
  52. // Map a TWINRESULT error value into a HRESULT
  53. // Note: TR_SUCCESS should not be mapped
  54. // Note: This assumes that TWINRESULT errors fall in the range -32k to 32k.
  55. //
  56. #define TR_DELTAVALUE           1000
  57. #define FACILITY_TR             0x018a          // magic number
  58. #define HRESULT_FROM_TR(x)      (TR_SUCCESS == (x) ? NOERROR : 
  59.                                                    ((HRESULT) ((((x) + TR_DELTAVALUE) & 0x0000FFFF) | (FACILITY_TR << 16) | 0x80000000)))
  60. #define IS_ENGINE_ERROR(hr)     IsFlagSet(hr, ((FACILITY_TR << 16) | 0x80000000))
  61. #define GET_TR(hr)              ((TWINRESULT)((hr) & 0x0000FFFF) - TR_DELTAVALUE)
  62. HRESULT PUBLIC MapToOfficialHresult(HRESULT hres);
  63. // SCODE values that correspond to TWINRESULT values
  64. #define E_TR_RH_LOAD_FAILED         MAKE_SCODE(SEVERITY_ERROR, FACILITY_TR, TR_DELTAVALUE + TR_RH_LOAD_FAILED)
  65. #define E_TR_SRC_OPEN_FAILED        MAKE_SCODE(SEVERITY_ERROR, FACILITY_TR, TR_DELTAVALUE + TR_SRC_OPEN_FAILED)
  66. #define E_TR_SRC_READ_FAILED        MAKE_SCODE(SEVERITY_ERROR, FACILITY_TR, TR_DELTAVALUE + TR_SRC_READ_FAILED)
  67. #define E_TR_DEST_OPEN_FAILED       MAKE_SCODE(SEVERITY_ERROR, FACILITY_TR, TR_DELTAVALUE + TR_DEST_OPEN_FAILED)
  68. #define E_TR_DEST_WRITE_FAILED      MAKE_SCODE(SEVERITY_ERROR, FACILITY_TR, TR_DELTAVALUE + TR_DEST_WRITE_FAILED)
  69. #define E_TR_ABORT                  MAKE_SCODE(SEVERITY_ERROR, FACILITY_TR, TR_DELTAVALUE + TR_ABORT)
  70. #define E_TR_UNAVAILABLE_VOLUME     MAKE_SCODE(SEVERITY_ERROR, FACILITY_TR, TR_DELTAVALUE + TR_UNAVAILABLE_VOLUME)
  71. #define E_TR_OUT_OF_MEMORY          MAKE_SCODE(SEVERITY_ERROR, FACILITY_TR, TR_DELTAVALUE + TR_OUT_OF_MEMORY)
  72. #define E_TR_FILE_CHANGED           MAKE_SCODE(SEVERITY_ERROR, FACILITY_TR, TR_DELTAVALUE + TR_FILE_CHANGED)
  73. #define E_TR_DUPLICATE_TWIN         MAKE_SCODE(SEVERITY_ERROR, FACILITY_TR, TR_DELTAVALUE + TR_DUPLICATE_TWIN)
  74. #define E_TR_DELETED_TWIN           MAKE_SCODE(SEVERITY_ERROR, FACILITY_TR, TR_DELTAVALUE + TR_DELETED_TWIN)
  75. #define E_TR_HAS_FOLDER_TWIN_SRC    MAKE_SCODE(SEVERITY_ERROR, FACILITY_TR, TR_DELTAVALUE + TR_HAS_FOLDER_TWIN_SRC)
  76. #define E_TR_INVALID_PARAMETER      MAKE_SCODE(SEVERITY_ERROR, FACILITY_TR, TR_DELTAVALUE + TR_INVALID_PARAMETER)
  77. #define E_TR_SAME_FOLDER            MAKE_SCODE(SEVERITY_ERROR, FACILITY_TR, TR_DELTAVALUE + TR_SAME_FOLDER)
  78. #define E_TR_SUBTREE_CYCLE_FOUND    MAKE_SCODE(SEVERITY_ERROR, FACILITY_TR, TR_DELTAVALUE + TR_SUBTREE_CYCLE_FOUND)
  79. #define E_TR_NO_MERGE_HANDLER       MAKE_SCODE(SEVERITY_ERROR, FACILITY_TR, TR_DELTAVALUE + TR_NO_MERGE_HANDLER)
  80. #define E_TR_MERGE_INCOMPLETE       MAKE_SCODE(SEVERITY_ERROR, FACILITY_TR, TR_DELTAVALUE + TR_MERGE_INCOMPLETE)
  81. #define E_TR_TOO_DIFFERENT          MAKE_SCODE(SEVERITY_ERROR, FACILITY_TR, TR_DELTAVALUE + TR_TOO_DIFFERENT)
  82. #define E_TR_BRIEFCASE_LOCKED       MAKE_SCODE(SEVERITY_ERROR, FACILITY_TR, TR_DELTAVALUE + TR_BRIEFCASE_LOCKED)
  83. #define E_TR_BRIEFCASE_OPEN_FAILED  MAKE_SCODE(SEVERITY_ERROR, FACILITY_TR, TR_DELTAVALUE + TR_BRIEFCASE_OPEN_FAILED)
  84. #define E_TR_BRIEFCASE_READ_FAILED  MAKE_SCODE(SEVERITY_ERROR, FACILITY_TR, TR_DELTAVALUE + TR_BRIEFCASE_READ_FAILED)
  85. #define E_TR_BRIEFCASE_WRITE_FAILED MAKE_SCODE(SEVERITY_ERROR, FACILITY_TR, TR_DELTAVALUE + TR_BRIEFCASE_WRITE_FAILED)
  86. #define E_TR_CORRUPT_BRIEFCASE      MAKE_SCODE(SEVERITY_ERROR, FACILITY_TR, TR_DELTAVALUE + TR_CORRUPT_BRIEFCASE)
  87. #define E_TR_NEWER_BRIEFCASE        MAKE_SCODE(SEVERITY_ERROR, FACILITY_TR, TR_DELTAVALUE + TR_NEWER_BRIEFCASE)
  88. #define E_TR_NO_MORE                MAKE_SCODE(SEVERITY_ERROR, FACILITY_TR, TR_DELTAVALUE + TR_NO_MORE)
  89. /////////////////////////////////////////////////////  MACROS
  90. // Error table for lookup strings.  Usually an array of these
  91. // structures is created and placed in the readonly data segment.
  92. //
  93. typedef struct _SETbl
  94.     {
  95.     HRESULT hres;       // standard result
  96.     UINT    ids;        // String ID of message
  97.     UINT    uStyle;     // MB_ flags
  98.     } SETbl, * PSETBL;
  99. typedef SETbl const *  PCSETBL;
  100. int PUBLIC SEMsgBox(HWND hwnd, UINT idsCaption, SCODE sc, PCSETBL pseTable, UINT cArraySize);
  101. // Retry loop
  102. //
  103. #define RETRY_BEGIN(bInit)      {BOOL bMyRetry; do { bMyRetry = (bInit);
  104. #define RETRY_END()             } while (bMyRetry); }
  105. #define RETRY_SET()             bMyRetry = TRUE
  106. #define RETRY_CLEAR()           bMyRetry = FALSE
  107. // Debugging macros
  108. //
  109. #ifdef DEBUG
  110. #define DEBUG_CASE_STRING(x)    case x: return TEXT( #x )
  111. #define ASSERTSEG
  112. // Use this macro to declare message text that will be placed
  113. // in the CODE segment (useful if DS is getting full)
  114. //
  115. // Ex: DEBUGTEXT(szMsg, "Invalid whatever: %d");
  116. //
  117. #define DEBUGTEXT(sz, msg)      /* ;Internal */ 
  118.     static const TCHAR ASSERTSEG sz[] = msg;
  119. void PUBLIC BrfAssertFailed(LPCTSTR szFile, int line);
  120. void CPUBLIC BrfAssertMsg(BOOL f, LPCTSTR pszMsg, ...);
  121. void CPUBLIC BrfDebugMsg(UINT mask, LPCTSTR pszMsg, ...);
  122. // ASSERT(f)  -- Generate "assertion failed in line x of file.c"
  123. //               message if f is NOT true.
  124. //
  125. #define ASSERT(f)                                                       
  126.     {                                                                   
  127.         DEBUGTEXT(szFile, TEXT(__FILE__));                              
  128.         if (!(f))                                                       
  129.             BrfAssertFailed(szFile, __LINE__);                          
  130.     }
  131. #define ASSERT_E(f)  ASSERT(f)
  132. // ASSERT_MSG(f, msg, args...)  -- Generate wsprintf-formatted msg w/params
  133. //                          if f is NOT true.
  134. //
  135. #define ASSERT_MSG   BrfAssertMsg
  136. // DEBUG_MSG(mask, msg, args...) - Generate wsprintf-formatted msg using
  137. //                          specified debug mask.  System debug mask
  138. //                          governs whether message is output.
  139. //
  140. #define DEBUG_MSG    BrfDebugMsg
  141. #define TRACE_MSG    DEBUG_MSG
  142. // VERIFYSZ(f, msg, arg)  -- Generate wsprintf-formatted msg w/ 1 param
  143. //                          if f is NOT true 
  144. //
  145. #define VERIFYSZ(f, szFmt, x)   ASSERT_MSG(f, szFmt, x)
  146. // VERIFYSZ2(f, msg, arg1, arg2)  -- Generate wsprintf-formatted msg w/ 2
  147. //                          param if f is NOT true 
  148. //
  149. #define VERIFYSZ2(f, szFmt, x1, x2)   ASSERT_MSG(f, szFmt, x1, x2)
  150. // DBG_ENTER(szFn)  -- Generates a function entry debug spew for
  151. //                          a function 
  152. //
  153. #define DBG_ENTER(szFn)                  
  154.     TRACE_MSG(TF_FUNC, TEXT(" > ") szFn TEXT("()"))
  155. // DBG_ENTER_SZ(szFn, sz)  -- Generates a function entry debug spew for
  156. //                          a function that accepts a string as one of its
  157. //                          parameters.
  158. //
  159. #define DBG_ENTER_SZ(szFn, sz)                  
  160.     TRACE_MSG(TF_FUNC, TEXT(" > ") szFn TEXT("(..., "%s",...)"), Dbg_SafeStr(sz))
  161. // DBG_ENTER_DTOBJ(szFn, pdtobj, szBuf)  -- Generates a function entry 
  162. //                          debug spew for a function that accepts a 
  163. //                          string as one of its parameters.
  164. //
  165. #define DBG_ENTER_DTOBJ(szFn, pdtobj, szBuf) 
  166.     TRACE_MSG(TF_FUNC, TEXT(" > ") szFn TEXT("(..., %s,...)"), Dbg_DataObjStr(pdtobj, szBuf))
  167. // DBG_ENTER_RIID(szFn, riid)  -- Generates a function entry debug spew for
  168. //                          a function that accepts an riid as one of its
  169. //                          parameters.
  170. //
  171. #define DBG_ENTER_RIID(szFn, riid)                  
  172.     TRACE_MSG(TF_FUNC, TEXT(" > ") szFn TEXT("(..., %s,...)"), Dbg_GetRiidName(riid))
  173. // DBG_EXIT(szFn)  -- Generates a function exit debug spew 
  174. //
  175. #define DBG_EXIT(szFn)                              
  176.         TRACE_MSG(TF_FUNC, TEXT(" < ") szFn TEXT("()"))
  177. // DBG_EXIT_US(szFn, us)  -- Generates a function exit debug spew for
  178. //                          functions that return a USHORT.
  179. //
  180. #define DBG_EXIT_US(szFn, us)                       
  181.         TRACE_MSG(TF_FUNC, TEXT(" < ") szFn TEXT("() with %#x"), (USHORT)us)
  182. // DBG_EXIT_UL(szFn, ul)  -- Generates a function exit debug spew for
  183. //                          functions that return a ULONG.
  184. //
  185. #define DBG_EXIT_UL(szFn, ul)                   
  186.         TRACE_MSG(TF_FUNC, TEXT(" < ") szFn TEXT("() with %#lx"), (ULONG)ul)
  187. // DBG_EXIT_PTR(szFn, pv)  -- Generates a function exit debug spew for
  188. //                          functions that return a pointer.
  189. //
  190. #define DBG_EXIT_PTR(szFn, pv)                   
  191.         TRACE_MSG(TF_FUNC, TEXT(" < ") szFn TEXT("() with %#lx"), (LPVOID)pv)
  192. // DBG_EXIT_HRES(szFn, hres)  -- Generates a function exit debug spew for
  193. //                          functions that return an HRESULT.
  194. //
  195. #define DBG_EXIT_HRES(szFn, hres)                   
  196.         TRACE_MSG(TF_FUNC, TEXT(" < ") szFn TEXT("() with %s"), Dbg_GetScode(hres))
  197. #else
  198. #define ASSERT(f)
  199. #define ASSERT_E(f)      (f)
  200. #define ASSERT_MSG   1 ? (void)0 : (void)
  201. #define DEBUG_MSG    1 ? (void)0 : (void)
  202. #define TRACE_MSG    1 ? (void)0 : (void)
  203. #define VERIFYSZ(f, szFmt, x)     (f)
  204. #define DBG_ENTER(szFn)
  205. #define DBG_ENTER_SZ(szFn, sz)
  206. #define DBG_ENTER_DTOBJ(szFn, pdtobj, sz)
  207. #define DBG_ENTER_RIID(szFn, riid)   
  208. #define DBG_EXIT(szFn)                            
  209. #define DBG_EXIT_US(szFn, us)
  210. #define DBG_EXIT_UL(szFn, ul)
  211. #define DBG_EXIT_PTR(szFn, ptr)                            
  212. #define DBG_EXIT_HRES(szFn, hres)   
  213. #endif
  214. /////////////////////////////////////////////////////  TYPEDEFS
  215. /////////////////////////////////////////////////////  EXPORTED DATA
  216. /////////////////////////////////////////////////////  PUBLIC PROTOTYPES
  217. #ifdef DEBUG
  218. void PUBLIC DEBUG_BREAK(UINT flag);
  219. LPCTSTR PUBLIC Dbg_GetRiidName(REFIID riid);
  220. LPCTSTR PUBLIC Dbg_GetScode(HRESULT hres);
  221. LPCTSTR PUBLIC Dbg_SafeStr(LPCTSTR psz);
  222. LPCTSTR PUBLIC Dbg_DataObjStr(LPDATAOBJECT pdtobj, LPTSTR pszBuf);
  223. #endif
  224. #endif // __ERR_H__