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.

182 lines
5.0 KiB

  1. /*
  2. Copyright (c) 1998-2000 Microsoft Corporation. All rights reserved.
  3. */
  4. #ifndef _KernHelp_
  5. #define _KernHelp_
  6. // Use kernel mutex to implement critical section
  7. //
  8. typedef KMUTEX CRITICAL_SECTION;
  9. typedef CRITICAL_SECTION *LPCRITICAL_SECTION;
  10. VOID InitializeCriticalSection( LPCRITICAL_SECTION);
  11. VOID EnterCriticalSection( LPCRITICAL_SECTION);
  12. VOID LeaveCriticalSection( LPCRITICAL_SECTION);
  13. VOID DeleteCriticalSection( LPCRITICAL_SECTION);
  14. // We have very little registry work to do, so just encapsulate the
  15. // entire process
  16. //
  17. int GetRegValueDword(LPTSTR RegPath,LPTSTR ValueName,PULONG Value);
  18. ULONG GetTheCurrentTime();
  19. PVOID KernHelpGetSysAddrForMdl(PMDL pMdl);
  20. #ifndef _NEW_DELETE_OPERATORS_
  21. #define _NEW_DELETE_OPERATORS_
  22. /*****************************************************************************
  23. * operator new()
  24. *****************************************************************************
  25. * Overload new to allocate from PagedPool, with our pooltag.
  26. */
  27. inline void* __cdecl operator new
  28. (
  29. size_t iSize
  30. )
  31. {
  32. // @@BEGIN_DDKSPLIT -- This section will be removed in the DDK sample. See ddkreadme.txt for more info.
  33. PVOID result = ExAllocatePoolWithTag(PagedPool, iSize, 'ySmD');
  34. #if 0 // The following section will only take effect in the DDK sample.
  35. // @@END_DDKSPLIT
  36. // Replace 'ySkD' with a tag appropriate to your product.
  37. PVOID result = ExAllocatePoolWithTag(PagedPool, iSize, 'ySkD');
  38. // @@BEGIN_DDKSPLIT -- This section will be removed in the DDK sample.
  39. #endif
  40. // @@END_DDKSPLIT
  41. if (result)
  42. {
  43. RtlZeroMemory(result, iSize);
  44. }
  45. #if DBG
  46. else
  47. {
  48. _DbgPrintF(DEBUGLVL_TERSE, ("Couldn't allocate paged pool: %d bytes", iSize));
  49. }
  50. #endif // DBG
  51. return result;
  52. }
  53. /*****************************************************************************
  54. * operator new
  55. *****************************************************************************
  56. * Overload new to allocate with our pooltag.
  57. * Allocates from PagedPool or NonPagedPool, as specified.
  58. */
  59. inline PVOID operator new
  60. (
  61. size_t iSize,
  62. POOL_TYPE poolType
  63. )
  64. {
  65. // @@BEGIN_DDKSPLIT -- This section will be removed in the DDK sample. See ddkreadme.txt for more info.
  66. PVOID result = ExAllocatePoolWithTag(poolType, iSize, 'ySmD');
  67. #if 0 // The following section will only take effect in the DDK sample.
  68. // @@END_DDKSPLIT
  69. // Replace 'ySkD' with a tag appropriate to your product.
  70. PVOID result = ExAllocatePoolWithTag(PagedPool, iSize, 'ySkD');
  71. // @@BEGIN_DDKSPLIT -- This section will be removed in the DDK sample.
  72. #endif
  73. // @@END_DDKSPLIT
  74. if (result)
  75. {
  76. RtlZeroMemory(result, iSize);
  77. }
  78. #if DBG
  79. else
  80. {
  81. _DbgPrintF(DEBUGLVL_TERSE, ("Couldn't allocate poolType(%d): %d bytes", (ULONG)poolType, iSize));
  82. }
  83. #endif // DBG
  84. return result;
  85. }
  86. /*****************************************************************************
  87. * operator new()
  88. *****************************************************************************
  89. * Overload new to allocate with a specified allocation tag.
  90. * Allocates from PagedPool or NonPagedPool, as specified.
  91. */
  92. inline PVOID operator new
  93. (
  94. size_t iSize,
  95. POOL_TYPE poolType,
  96. ULONG tag
  97. )
  98. {
  99. PVOID result = ExAllocatePoolWithTag(poolType, iSize, tag);
  100. if (result)
  101. {
  102. RtlZeroMemory(result,iSize);
  103. }
  104. #if DBG
  105. else
  106. {
  107. _DbgPrintF(DEBUGLVL_TERSE, ("Couldn't allocate tagged poolType(%d): %d bytes",
  108. (ULONG)poolType, iSize));
  109. }
  110. #endif // DBG
  111. return result;
  112. }
  113. /*****************************************************************************
  114. * operator delete()
  115. *****************************************************************************
  116. * Delete function.
  117. */
  118. inline void __cdecl operator delete
  119. (
  120. PVOID pVoid
  121. )
  122. {
  123. ExFreePool(pVoid);
  124. }
  125. #endif //!_NEW_DELETE_OPERATORS_
  126. // Debug trace facility
  127. //
  128. #define DM_DEBUG_CRITICAL DEBUGLVL_ERROR // Used to include critical messages
  129. #define DM_DEBUG_NON_CRITICAL DEBUGLVL_TERSE // Used to include level 1 plus important non-critical messages
  130. #define DM_DEBUG_STATUS DEBUGLVL_VERBOSE // Used to include level 1 and level 2 plus status\state messages
  131. #define DM_DEBUG_FUNC_FLOW DEBUGLVL_BLAB // Used to include level 1, level 2 and level 3 plus function flow messages
  132. #define DM_DEBUG_ALL DEBUGLVL_BLAB // Used to include all debug messages
  133. #if DBG
  134. #define Trace
  135. #define Trace0(lvl, fstr) \
  136. _DbgPrintF(lvl, (fstr))
  137. #define Trace1(lvl, fstr, arg1) \
  138. _DbgPrintF(lvl, (fstr, arg1))
  139. #define Trace2(lvl, fstr, arg1, arg2) \
  140. _DbgPrintF(lvl, (fstr, arg1, arg2))
  141. #define Trace3(lvl, fstr, arg1, arg2, arg3) \
  142. _DbgPrintF(lvl, (fstr, arg1, arg2, arg3))
  143. #define Trace4(lvl, fstr, arg1, arg2, arg3, arg4) \
  144. _DbgPrintF(lvl, (fstr, arg1, arg2, arg3, arg4))
  145. #else
  146. #define Trace
  147. #define Trace0
  148. #define Trace1
  149. #define Trace2
  150. #define Trace3
  151. #define Trace4
  152. #endif
  153. #define assert ASSERT
  154. // Paramter validation unused
  155. //
  156. #define V_INAME(x)
  157. #define V_BUFPTR_READ(p,cb)
  158. #endif // _KernHelp_