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.

272 lines
8.4 KiB

  1. #pragma once
  2. #include <AutoWrap.h>
  3. #include <InjRT.h>
  4. #define MIFAULT_VERSION "MiFault Version 0.1"
  5. namespace MiFaultLib {
  6. #if 0
  7. }
  8. #endif
  9. typedef void (WINAPI *FP_CleanupParsedArgs)(void*);
  10. struct Arg {
  11. const char* Name;
  12. const char* Value;
  13. };
  14. // There are not COM interfaces, but they are interfaces, so we use
  15. // "I_" instead of "I" as a prefix.
  16. class I_Args {
  17. public:
  18. virtual const size_t WINAPI GetCount() = 0;
  19. // The index must be valid
  20. virtual const Arg WINAPI GetArg(size_t index) = 0;
  21. // Returns NULL if there is no such named argument
  22. // virtual const char* WINAPI GetArg(const char* name) = 0;
  23. // GetParsedArgs
  24. //
  25. // Returns a pointer to parsed arguments or NULL if none is set.
  26. // If you ned to denote empty parsed arguments, make sure to set
  27. // the parsed arguments to some data structure.
  28. virtual void* WINAPI GetParsedArgs() = 0;
  29. // SetParsedArgs
  30. //
  31. // This function should be called once to set the args. Returns
  32. // false and does nothing if the args have already been set.
  33. // ParsedArgs and pfnCleanup must not be NULL, otherwise an
  34. // assertion will fail. If you have the concept of empty
  35. // args, you should put some struct here to signify that.
  36. virtual bool WINAPI SetParsedArgs(
  37. IN void* ParsedArgs,
  38. IN FP_CleanupParsedArgs pfnCleanup
  39. ) = 0;
  40. // Lock/Unlock (OPTIONAL)
  41. //
  42. // Synchronization mechanism that can be used for setting parsed
  43. // arguments. A fault function can use this do synchronize with
  44. // other fault function when modifying the parsed arguments for
  45. // this paramters block.
  46. //
  47. // Calling these functions is optional. However, if you use
  48. // them, make sure that they are properly matched up.
  49. virtual void WINAPI Lock() = 0;
  50. virtual void WINAPI Unlock() = 0;
  51. // Done (OPTIONAL)
  52. //
  53. // Can be used to indicate that the fault function is done using
  54. // the argument information. The fault function cannot access
  55. // any data corresponding to these arguments. Calling this
  56. // function is optional. It simply tells the MiFault library
  57. // that the fault function has no references to the arguments so
  58. // that the MiFault library can free up the data, if
  59. // appropriate.
  60. //
  61. // You cannot access the parsed args after this because they
  62. // could get freed.
  63. //
  64. // You cannot call any functions on this interface after calling
  65. // Done(). Think of it like a super-Release() on a COM
  66. // interface.
  67. //
  68. // Note that Get*Args() will always give you the same I_Args
  69. // (well, different ones for function and group args, of
  70. // course), so you cannot call that function again to get a
  71. // valid I_Arg after calling Done().
  72. virtual void WINAPI Done() = 0;
  73. };
  74. class I_Trigger
  75. {
  76. public:
  77. virtual const char* WINAPI GetGroupName() = 0;
  78. virtual const char* WINAPI GetTagName() = 0;
  79. virtual const char* WINAPI GetFunctionName() = 0;
  80. virtual const size_t WINAPI GetFunctionIndex() = 0;
  81. virtual I_Args* WINAPI GetFunctionArgs() = 0;
  82. virtual I_Args* WINAPI GetGroupArgs() = 0;
  83. // Done (OPTIONAL)
  84. //
  85. // Can be used to indicate that the fault function is done using
  86. // the trigger and argument information. The fault function
  87. // cannot access data corresponding to this trigger after
  88. // calling this. Calling this function is optional. It simply
  89. // tells the MiFault library that the fault function has no
  90. // references to the trigger or its arguments so that the
  91. // MiFault library can free up the data, if appropriate.
  92. //
  93. // You cannot call any functions on this interface after calling
  94. // Done(). Nor can you dereference I_Arg pointers you got from
  95. // the trigger. Think of it like a super-Release() on a COM
  96. // interface.
  97. //
  98. // Note that GetTriggerInfo() will always give you the same
  99. // I_Trigger, so you cannot call it again to get a valid
  100. // I_Trigger after calling Done().
  101. virtual void WINAPI Done() = 0;
  102. };
  103. class I_Lib {
  104. public:
  105. // GetTriggerInfo
  106. //
  107. // Returns thread state currently associated with a trigger.
  108. // This function must only be called from within a fault
  109. // function.
  110. virtual I_Trigger* WINAPI GetTrigger() = 0;
  111. virtual void __cdecl Trace(unsigned int level, const char* format, ...) = 0;
  112. virtual void* WINAPI GetOriginalFunctionAddress() = 0;
  113. virtual void* WINAPI GetPublishedFunctionAddress(const char* FunctionName) = 0;
  114. // We don't really want the fault function library to have acccess
  115. // to magellan. Rather, we want to provide it with some sort of
  116. // logging facility and possibly a config system... Maybe what we
  117. // want is just to give people pointers to a couple of these...
  118. // Support function if fault function wants to use Magellan
  119. // virtual CSetPointManager* WINAPI GetSetPointManager() = 0;
  120. // virtual const CWrapperFunction* WINAPI GetWrapperFunctions() = 0;
  121. };
  122. #define MiFF_DEBUG4 0x08000000
  123. #define MiFF_DEBUG3 0x04000000
  124. #define MiFF_DEBUG2 0x02000000
  125. #define MiFF_DEBUG 0x01000000
  126. #define MiFF_INFO4 0x00800000
  127. #define MiFF_INFO3 0x00400000
  128. #define MiFF_INFO2 0x00200000
  129. #define MiFF_INFO 0x00100000
  130. #define MiFF_WARNING 0x00040000
  131. #define MiFF_ERROR 0x00020000
  132. #define MiFF_FATAL 0x00010000
  133. // ----------------------------------------------------------------------------
  134. //
  135. // The fault function library should provide:
  136. //
  137. // MiFaultFunctionsStartup
  138. //
  139. // User-provided function to initialize user-provided fault function
  140. // component. It is called before any fault functions are running.
  141. // The version is just a string that should be compared to
  142. // MIFAULT_VERSION. If they do not match, false should be returned.
  143. bool
  144. WINAPI
  145. MiFaultFunctionsStartup(
  146. const char* version,
  147. I_Lib* pLib
  148. );
  149. // MiFaultFunctionsShutdown
  150. //
  151. // User-provided function to cleanup user-provided fault function
  152. // component state. It might not be called all before the fault
  153. // function library's DllMain. If called, this function will only
  154. // be called when no fault functions are running.
  155. void
  156. WINAPI
  157. MiFaultFunctionsShutdown(
  158. );
  159. // ----------------------------------------------------------------------------
  160. // Sample Fault Function:
  161. //
  162. // using namespace MiFaultLib
  163. //
  164. // CFooFuncArgs* GetFooFuncArgs()
  165. // {
  166. // I_Args* pArgs = pLib->GetTrigger()->GetFunctionArgs();
  167. // CFooFuncArgs* pParsedArgs = (CFooFuncArgs*)pArgs->GetParsedArgs();
  168. // if (!pParsedArgs)
  169. // {
  170. // const size_t count = pArgs->GetCount();
  171. //
  172. // pParsedArgs = new CFooFuncArgs;
  173. //
  174. // for (size_t i = 0; i < count; i++)
  175. // {
  176. // Arg arg = pArgs->GetArg(i);
  177. // // build up parsed args...
  178. // }
  179. // if (!pArgs->SetParsedArgs(pParsedArgs, CFooFuncArgs::Cleanup))
  180. // {
  181. // // someone else set the args while we were building the args
  182. // delete pParsedArgs;
  183. // pParsedArgs = pArgs->GetParsedArgs();
  184. // }
  185. // }
  186. // return pParsedArgs;
  187. // }
  188. //
  189. // CBarGroupArgs* GetBarGroupArgs()
  190. // {
  191. // I_Args* pArgs = pLib->GetTrigger()->GetGroupArgs();
  192. // CBarGroupArgs* pParsedArgs = (CBarGroupArgs*)pArgs->GetParsedArgs();
  193. // if (!pParsedArgs)
  194. // {
  195. // const size_t count = pArgs->GetCount();
  196. //
  197. // pParsedArgs = new CBarGroupArgs;
  198. //
  199. // for (size_t i = 0; i < count; i++)
  200. // {
  201. // // ... get args and build up parsed args ...
  202. // }
  203. // if (!pArgs->SetParsedArgs(pParsedArgs, CBarGroupArgs::Cleanup))
  204. // {
  205. // // someone else set the args while we were building the args
  206. // delete pParsedArgs;
  207. // pParsedArgs = pArgs->GetParsedArgs();
  208. // }
  209. // }
  210. // return pParsedArgs;
  211. // }
  212. //
  213. // void FF_Bar_Foo()
  214. // {
  215. // CFooFuncArgs* pFuncArgs = GetFooFuncArgs();
  216. // CBarGroupArgs* pGroupArgs = GetBarGroupArgs();
  217. //
  218. // // Do fault code...
  219. //
  220. // // No need to cleanup args...library will do that using the
  221. // // cleanup function pointer.
  222. // }
  223. #if 0
  224. {
  225. #endif
  226. }