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.

252 lines
7.6 KiB

  1. /*++
  2. Copyright (c) 1998-1999 Microsoft Corporation
  3. Module Name:
  4. misc.h
  5. Abstract:
  6. This module contains miscellaneous constants & declarations.
  7. Author:
  8. Keith Moore (keithmo) 10-Jun-1998
  9. Henry Sanders (henrysa) 17-Jun-1998 Merge with old httputil.h
  10. Paul McDaniel (paulmcd) 30-Mar-1999 added refcounted eresource
  11. Revision History:
  12. --*/
  13. #ifndef _MISC_H_
  14. #define _MISC_H_
  15. extern ULONG HttpChars[256];
  16. #define HTTP_CHAR 0x001
  17. #define HTTP_UPCASE 0x002
  18. #define HTTP_LOCASE 0x004
  19. #define HTTP_ALPHA (HTTP_UPCASE | HTTP_LOCASE)
  20. #define HTTP_DIGIT 0x008
  21. #define HTTP_CTL 0x010
  22. #define HTTP_LWS 0x020
  23. #define HTTP_HEX 0x040
  24. #define HTTP_SEPERATOR 0x080
  25. #define HTTP_TOKEN 0x100
  26. #define URL_LEGAL 0x200
  27. #define URL_TOKEN (HTTP_ALPHA | HTTP_DIGIT | URL_LEGAL)
  28. #define IS_HTTP_UPCASE(c) (HttpChars[(UCHAR)(c)] & HTTP_UPCASE)
  29. #define IS_HTTP_LOCASE(c) (HttpChars[(UCHAR)(c)] & HTTP_UPCASE)
  30. #define IS_HTTP_ALPHA(c) (HttpChars[(UCHAR)(c)] & HTTP_ALPHA)
  31. #define IS_HTTP_DIGIT(c) (HttpChars[(UCHAR)(c)] & HTTP_DIGIT)
  32. #define IS_HTTP_HEX(c) (HttpChars[(UCHAR)(c)] & HTTP_HEX)
  33. #define IS_HTTP_CTL(c) (HttpChars[(UCHAR)(c)] & HTTP_CTL)
  34. #define IS_HTTP_LWS(c) (HttpChars[(UCHAR)(c)] & HTTP_LWS)
  35. #define IS_HTTP_SEPERATOR(c) (HttpChars[(UCHAR)(c)] & HTTP_SEPERATOR)
  36. #define IS_HTTP_TOKEN(c) (HttpChars[(UCHAR)(c)] & HTTP_TOKEN)
  37. #define IS_URL_TOKEN(c) (HttpChars[(UCHAR)(c)] & URL_TOKEN)
  38. NTSTATUS
  39. InitializeHttpUtil(
  40. VOID
  41. );
  42. //
  43. // Our presumed cache-line size.
  44. //
  45. #define CACHE_LINE_SIZE 32
  46. //
  47. // Alignment macros.
  48. //
  49. #define ROUND_UP( val, pow2 ) \
  50. ( ( (ULONG_PTR)(val) + (pow2) - 1 ) & ~( (pow2) - 1 ) )
  51. //
  52. // Calculate the dimension of an array.
  53. //
  54. #define DIMENSION(x) ( sizeof(x) / sizeof(x[0]) )
  55. //
  56. // nice MIN/MAX macros
  57. //
  58. #define MIN(a,b) ( ((a) > (b)) ? (b) : (a) )
  59. #define MAX(a,b) ( ((a) > (b)) ? (a) : (b) )
  60. //
  61. // Macros for swapping the bytes in a long and a short.
  62. //
  63. #if (defined(_M_IX86) && (_MSC_FULL_VER > 13009037)) || ((defined(_M_AMD64) || defined(_M_IA64)) && (_MSC_FULL_VER > 13009175))
  64. #define SWAP_LONG(l) _byteswap_ulong((unsigned long)l)
  65. #define SWAP_SHORT(s) _byteswap_ushort((unsigned short)s)
  66. #else
  67. #define SWAP_LONG(l) \
  68. ( ( ((l) >> 24) & 0x000000FFL ) | \
  69. ( ((l) >> 8) & 0x0000FF00L ) | \
  70. ( ((l) << 8) & 0x00FF0000L ) | \
  71. ( ((l) << 24) & 0xFF000000L ) )
  72. #define SWAP_SHORT(s) \
  73. ( ( ((s) >> 8) & 0x00FF ) | \
  74. ( ((s) << 8) & 0xFF00 ) )
  75. #endif
  76. //
  77. // Context values stored in PFILE_OBJECT->FsContext2 to identify a handle
  78. // as either a control channel or an app pool.
  79. //
  80. #define UL_CONTROL_CHANNEL_CONTEXT ((PVOID)'LRTC')
  81. #define UL_CONTROL_CHANNEL_CONTEXT_X ((PVOID)'rtcX')
  82. #define UL_APP_POOL_CONTEXT ((PVOID)'PPPA')
  83. #define UL_APP_POOL_CONTEXT_X ((PVOID)'ppaX')
  84. #define IS_CONTROL_CHANNEL( pFileObject ) \
  85. ( (pFileObject)->FsContext2 == UL_CONTROL_CHANNEL_CONTEXT )
  86. #define MARK_VALID_CONTROL_CHANNEL( pFileObject ) \
  87. ( (pFileObject)->FsContext2 = UL_CONTROL_CHANNEL_CONTEXT )
  88. #define MARK_INVALID_CONTROL_CHANNEL( pFileObject ) \
  89. ( (pFileObject)->FsContext2 = UL_CONTROL_CHANNEL_CONTEXT_X )
  90. #define GET_CONTROL_CHANNEL( pFileObject ) \
  91. ((PUL_CONTROL_CHANNEL)((pFileObject)->FsContext))
  92. #define GET_PP_CONTROL_CHANNEL( pFileObject ) \
  93. ((PUL_CONTROL_CHANNEL *)&((pFileObject)->FsContext))
  94. #define IS_APP_POOL( pFileObject ) \
  95. ( (pFileObject)->FsContext2 == UL_APP_POOL_CONTEXT )
  96. #define IS_EX_APP_POOL( pFileObject ) \
  97. ( (pFileObject)->FsContext2 == UL_APP_POOL_CONTEXT_X )
  98. #define MARK_VALID_APP_POOL( pFileObject ) \
  99. ( (pFileObject)->FsContext2 = UL_APP_POOL_CONTEXT )
  100. #define MARK_INVALID_APP_POOL( pFileObject ) \
  101. ( (pFileObject)->FsContext2 = UL_APP_POOL_CONTEXT_X )
  102. #define GET_APP_POOL_PROCESS( pFileObject ) \
  103. ((PUL_APP_POOL_PROCESS)((pFileObject)->FsContext))
  104. #define GET_PP_APP_POOL_PROCESS( pFileObject ) \
  105. ((PUL_APP_POOL_PROCESS *)&((pFileObject)->FsContext))
  106. #define IS_VALID_UL_NONPAGED_RESOURCE(pResource) \
  107. (((pResource) != NULL) && \
  108. ((pResource)->Signature == UL_NONPAGED_RESOURCE_SIGNATURE) && \
  109. ((pResource)->RefCount > 0))
  110. typedef struct _UL_NONPAGED_RESOURCE
  111. {
  112. //
  113. // NonPagedPool
  114. //
  115. SINGLE_LIST_ENTRY LookasideEntry; // must be first, links
  116. // into the lookaside list
  117. ULONG Signature; // UL_NONPAGED_RESOURCE_SIGNATURE
  118. LONG RefCount; // the reference count
  119. UL_ERESOURCE Resource; // the actual resource
  120. } UL_NONPAGED_RESOURCE, * PUL_NONPAGED_RESOURCE;
  121. #define UL_NONPAGED_RESOURCE_SIGNATURE ((ULONG)'RNLU')
  122. #define UL_NONPAGED_RESOURCE_SIGNATURE_X MAKE_FREE_SIGNATURE(UL_NONPAGED_RESOURCE_SIGNATURE)
  123. PUL_NONPAGED_RESOURCE
  124. UlResourceNew(
  125. );
  126. VOID
  127. UlReferenceResource(
  128. PUL_NONPAGED_RESOURCE pResource
  129. REFERENCE_DEBUG_FORMAL_PARAMS
  130. );
  131. VOID
  132. UlDereferenceResource(
  133. PUL_NONPAGED_RESOURCE pResource
  134. REFERENCE_DEBUG_FORMAL_PARAMS
  135. );
  136. #define REFERENCE_RESOURCE( pres ) \
  137. UlReferenceResource( \
  138. (pres) \
  139. REFERENCE_DEBUG_ACTUAL_PARAMS \
  140. )
  141. #define DEREFERENCE_RESOURCE( pres ) \
  142. UlDereferenceResource( \
  143. (pres) \
  144. REFERENCE_DEBUG_ACTUAL_PARAMS \
  145. )
  146. PVOID
  147. UlResourceAllocatePool(
  148. IN POOL_TYPE PoolType,
  149. IN SIZE_T ByteLength,
  150. IN ULONG Tag
  151. );
  152. VOID
  153. UlResourceFreePool(
  154. IN PVOID pBuffer
  155. );
  156. //
  157. // Miscellaneous validators.
  158. //
  159. #define IS_VALID_DEVICE_OBJECT( pDeviceObject ) \
  160. ( ((pDeviceObject) != NULL) && \
  161. ((pDeviceObject)->Type == IO_TYPE_DEVICE) && \
  162. ((pDeviceObject)->Size == sizeof(DEVICE_OBJECT)) )
  163. #define IS_VALID_FILE_OBJECT( pFileObject ) \
  164. ( ((pFileObject) != NULL) && \
  165. ((pFileObject)->Type == IO_TYPE_FILE) && \
  166. ((pFileObject)->Size == sizeof(FILE_OBJECT)) )
  167. #define IS_VALID_IRP( pIrp ) \
  168. ( ((pIrp) != NULL) && \
  169. ((pIrp)->Type == IO_TYPE_IRP) && \
  170. ((pIrp)->Size == IoSizeOfIrp((pIrp)->StackCount)) )
  171. NTSTATUS
  172. TimeFieldsToHttpDate(
  173. IN PTIME_FIELDS pTime,
  174. OUT PWSTR pBuffer,
  175. IN ULONG BufferLength
  176. );
  177. #endif // _MISC_H_