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.

269 lines
4.8 KiB

  1. /*++
  2. Copyright (c) 2001 Microsoft Corporation
  3. Module Name:
  4. util.h
  5. Abstract:
  6. Definitions of Utility routines
  7. Author:
  8. Cliff Van Dyke (cliffv) 11-Apr-2001
  9. --*/
  10. #ifdef __cplusplus
  11. extern "C" {
  12. #endif
  13. /////////////////////////////////////////////////////////////////////////////
  14. //
  15. // Macros
  16. //
  17. /////////////////////////////////////////////////////////////////////////////
  18. //
  19. // Macros for locking the global resource
  20. //
  21. #define AzpLockResourceExclusive( _Resource ) \
  22. RtlAcquireResourceExclusive( _Resource, TRUE )
  23. #define AzpIsLockedExclusive( _Resource ) \
  24. ((_Resource)->NumberOfActive == -1 )
  25. #define AzpLockResourceShared( _Resource ) \
  26. RtlAcquireResourceShared( _Resource, TRUE )
  27. #define AzpLockResourceSharedToExclusive( _Resource ) \
  28. RtlConvertSharedToExclusive( _Resource )
  29. #define AzpIsLockedShared( _Resource ) \
  30. ((_Resource)->NumberOfActive != 0 )
  31. #define AzpUnlockResource( _Resource ) \
  32. RtlReleaseResource( _Resource )
  33. /////////////////////////////////////////////////////////////////////////////
  34. //
  35. // Structure definitions
  36. //
  37. /////////////////////////////////////////////////////////////////////////////
  38. //
  39. // Generic counted string.
  40. // Can't use UNICODE_STRING since that is limited to 32K characters.
  41. //
  42. typedef struct _AZP_STRING {
  43. //
  44. // Pointer to the string
  45. //
  46. LPWSTR String;
  47. //
  48. // Size of the string in bytes (including trailing zero)
  49. //
  50. ULONG StringSize;
  51. } AZP_STRING, *PAZP_STRING;
  52. //
  53. // Generic expandable array of pointers
  54. //
  55. typedef struct _AZP_PTR_ARRAY {
  56. //
  57. // Pointer to allocated array of pointers
  58. //
  59. PVOID *Array;
  60. //
  61. // Number of elements actually used in array
  62. //
  63. ULONG UsedCount;
  64. //
  65. // Number of elemets allocated in the array
  66. //
  67. ULONG AllocatedCount;
  68. #define AZP_PTR_ARRAY_INCREMENT 4 // Amount to grow the array by
  69. } AZP_PTR_ARRAY, *PAZP_PTR_ARRAY;
  70. /////////////////////////////////////////////////////////////////////////////
  71. //
  72. // Global definitions
  73. //
  74. /////////////////////////////////////////////////////////////////////////////
  75. extern LIST_ENTRY AzGlAllocatedBlocks;
  76. extern CRITICAL_SECTION AzGlAllocatorCritSect;
  77. /////////////////////////////////////////////////////////////////////////////
  78. //
  79. // Procedure definitions
  80. //
  81. /////////////////////////////////////////////////////////////////////////////
  82. PVOID
  83. AzpAllocateHeap(
  84. IN SIZE_T Size
  85. );
  86. VOID
  87. AzpFreeHeap(
  88. IN PVOID Buffer
  89. );
  90. VOID
  91. AzpInitString(
  92. OUT PAZP_STRING AzpString,
  93. IN LPWSTR String OPTIONAL
  94. );
  95. DWORD
  96. AzpDuplicateString(
  97. OUT PAZP_STRING AzpOutString,
  98. IN PAZP_STRING AzpInString
  99. );
  100. DWORD
  101. AzpCaptureString(
  102. OUT PAZP_STRING AzpString,
  103. IN LPCWSTR String,
  104. IN ULONG MaximumLength,
  105. IN BOOLEAN NullOk
  106. );
  107. DWORD
  108. AzpCaptureSid(
  109. OUT PAZP_STRING AzpString,
  110. IN PSID Sid
  111. );
  112. DWORD
  113. AzpCaptureUlong(
  114. IN PVOID PropertyValue,
  115. OUT PULONG UlongValue
  116. );
  117. BOOL
  118. AzpEqualStrings(
  119. IN PAZP_STRING AzpString1,
  120. IN PAZP_STRING AzpString2
  121. );
  122. LONG
  123. AzpCompareStrings(
  124. IN PAZP_STRING AzpString1,
  125. IN PAZP_STRING AzpString2
  126. );
  127. VOID
  128. AzpSwapStrings(
  129. IN OUT PAZP_STRING AzpString1,
  130. IN OUT PAZP_STRING AzpString2
  131. );
  132. VOID
  133. AzpFreeString(
  134. IN PAZP_STRING AzpString
  135. );
  136. #define AZP_ADD_ENDOFLIST 0xFFFFFFFF
  137. DWORD
  138. AzpAddPtr(
  139. IN PAZP_PTR_ARRAY AzpPtrArray,
  140. IN PVOID Pointer,
  141. IN ULONG Index
  142. );
  143. VOID
  144. AzpRemovePtrByIndex(
  145. IN PAZP_PTR_ARRAY AzpPtrArray,
  146. IN ULONG Index
  147. );
  148. VOID
  149. AzpRemovePtrByPtr(
  150. IN PAZP_PTR_ARRAY AzpPtrArray,
  151. IN PVOID Pointer
  152. );
  153. PVOID
  154. AzpGetStringProperty(
  155. IN PAZP_STRING AzpString
  156. );
  157. PVOID
  158. AzpGetUlongProperty(
  159. IN ULONG UlongValue
  160. );
  161. BOOL
  162. AzDllInitialize(VOID);
  163. BOOL
  164. AzDllUnInitialize(VOID);
  165. /////////////////////////////////////////////////////////////////////////////
  166. //
  167. // Debugging Support
  168. //
  169. /////////////////////////////////////////////////////////////////////////////
  170. #if DBG
  171. #define AZROLESDBG 1
  172. #endif // DBG
  173. #ifdef AZROLESDBG
  174. #define AzPrint(_x_) AzpPrintRoutine _x_
  175. VOID
  176. AzpPrintRoutine(
  177. IN DWORD DebugFlag,
  178. IN LPSTR FORMATSTRING, // PRINTF()-STYLE FORMAT STRING.
  179. ... // OTHER ARGUMENTS ARE POSSIBLE.
  180. );
  181. //
  182. // Values of DebugFlag
  183. //
  184. #define AZD_HANDLE 0x01 // Debug handle open/close
  185. #define AZD_OBJLIST 0x02 // Object list linking
  186. #define AZD_INVPARM 0x04 // Invalid Parameter
  187. #define AZD_PERSIST 0x08 // Persistence code
  188. #define AZD_PERSIST_MORE 0x10 // Persistence code (verbose mode)
  189. #define AZD_REF 0x20 // Debug object ref count
  190. #define AZD_ALL 0xFFFFFFFF
  191. //
  192. // Globals
  193. //
  194. extern CRITICAL_SECTION AzGlLogFileCritSect;
  195. extern ULONG AzGlDbFlag;
  196. // extern HANDLE AzGlLogFile;
  197. #else
  198. #define AzPrint(_x_)
  199. #endif
  200. #ifdef __cplusplus
  201. }
  202. #endif