Source code of Windows XP (NT5)
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.

124 lines
2.7 KiB

  1. /*===================================================================
  2. Microsoft Confidential.
  3. Copyright 1997 Microsoft Corporation. All Rights Reserved.
  4. Component: RFS
  5. File: rfs.h
  6. Owner: EricN
  7. This the Resource failure objects.
  8. ===================================================================*/
  9. #ifdef _RFS
  10. #ifndef _RFS_CLS_H
  11. #define _RFS_CLS_H
  12. #include <io.h>
  13. #include <fcntl.h>
  14. #include <sys/stat.h>
  15. // for failure types
  16. #define COUNT 1
  17. #define MEM 2
  18. #define FILE_LINE 3
  19. // for logging
  20. #define MFSLOGFILE "\\temp\\mfs.log"
  21. #define MFSINIFILE "\\temp\\mfs.ini"
  22. //RFS MACROS for memory
  23. #define MFS_INIT(mem) (mem).Init()
  24. #define MFS_ON(mem) (mem).SetRFSOn(TRUE)
  25. #define MFS_OFF(mem) (mem).SetRFSOn(FALSE)
  26. #define MFS_SETTHREAD(mem) (mem).SetThreadID(GetCurrentThreadId())
  27. #define MFS_WRITEDATA(mem) (mem).WriteData()
  28. #define MFS_STARTLOOP \
  29. while(TRUE) \
  30. {
  31. #define MFS_ENDLOOP(mem) }
  32. #define MFS_ENDLOOP_HR(mem) if (hr == S_OK) break;}
  33. #define MFS_EXTERN(mem) extern MemRFS (mem)
  34. #define MFS_CHECKFAIL(mem, size, file, line) \
  35. if ((mem).FailAlloc(size, file, line)) \
  36. return NULL
  37. #define MFS_START(mem) \
  38. MFS_INIT(mem); \
  39. MFS_SETTHREAD(mem); \
  40. MFS_ON(mem); \
  41. MFS_STARTLOOP
  42. #define MFS_END_HR(mem) \
  43. MFS_ENDLOOP_HR(mem); \
  44. MFS_WRITEDATA(mem);
  45. //end macros
  46. //rfs class
  47. class RFS
  48. {
  49. public:
  50. RFS(DWORD dwFailOn, DWORD dwThreadID);
  51. void SetThreadID(DWORD);
  52. virtual HRESULT Init() = 0;
  53. protected:
  54. BOOL m_fFail;
  55. DWORD m_dwCurrentAlloc;
  56. //this will communicate with outside program
  57. BOOL DetermineFailure(LPCSTR szFile = NULL, int iLineNo = -1);
  58. void SetFailOn(DWORD, BYTE); //after a certain amount of memory or a specific request
  59. void SetFailOn(LPSTR, long); //on a specific line in a file
  60. virtual void WriteData();
  61. private:
  62. BYTE m_bType;
  63. DWORD m_dwFailOn;
  64. DWORD m_dwTtlNumAllocs;
  65. DWORD m_dwThreadID;
  66. char m_szFailIn[MAX_PATH];
  67. virtual BOOL FailAlloc(void *v = NULL, LPCSTR szFile = NULL, int iLineNo = -1) = 0; //implemeneted by derived class
  68. virtual void Log(LPSTR pszFileName, LPSTR pszMsg);
  69. };
  70. class MemRFS : public RFS
  71. {
  72. public:
  73. HRESULT Init();
  74. MemRFS(DWORD dwFailOn = 1, DWORD dwThreadID = -1);
  75. void SetRFSOn(BOOL);
  76. void SetFailOn(DWORD, BYTE); //after a certain amount of memory or a specific request
  77. void SetFailOn(LPSTR, long); //on a specific line in a file
  78. BOOL FailAlloc(void *v = NULL, LPCSTR szFile = NULL, int iLineNo = -1);
  79. void WriteData();
  80. };
  81. #endif //_rfs_cls_h
  82. #else
  83. //blank out macros for non rfs build
  84. #define MFS_ON
  85. #define MFS_OFF
  86. #define MFS_INIT
  87. #define MFS_STARTLOOP
  88. #define MFS_ENDLOOP
  89. #define MFS_ENDLOOP_HR
  90. #define MFS_EXTERN(mem)
  91. #define MFS_CHECKFAIL(mem, size, file, line)
  92. #define MFS_SETTHREAD
  93. #define MFS_WRITEDATA
  94. #define MFS_START(mem)
  95. #define MFS_END_HR(mem)
  96. #endif //_rfs