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.

251 lines
4.1 KiB

  1. //
  2. // misc.h
  3. //
  4. // Author: Tom McGuire (tommcg) 2/97 - 9/97
  5. //
  6. // Copyright (C) Microsoft, 1997.
  7. //
  8. // MICROSOFT CONFIDENTIAL
  9. //
  10. #ifndef _PATCH_MISC_H_
  11. #define _PATCH_MISC_H_
  12. #ifdef __cplusplus
  13. extern "C" {
  14. #endif
  15. #pragma intrinsic( memcpy, memset, memcmp, strcpy, strcmp, strlen, strcat, abs, _rotl )
  16. #ifndef ROUNDUP2
  17. #define ROUNDUP2( x, n ) ((((ULONG)(x)) + (((ULONG)(n)) - 1 )) & ~(((ULONG)(n)) - 1 ))
  18. #endif
  19. #ifndef MIN
  20. #define MIN( a, b ) (((a)<(b))?(a):(b))
  21. #endif
  22. #ifndef bool
  23. typedef int bool;
  24. #endif
  25. #ifndef byte
  26. typedef unsigned char byte;
  27. #endif
  28. #define SUBALLOCATOR_ALIGNMENT 8
  29. #define MINIMUM_VM_ALLOCATION 0x10000
  30. #if defined( DEBUG ) || defined( DBG ) || defined( TESTCODE )
  31. #include <stdlib.h>
  32. #include <stdio.h>
  33. #endif
  34. #ifndef ASSERT
  35. BOOL
  36. Assert(
  37. LPCSTR szText,
  38. LPCSTR szFile,
  39. DWORD dwLine
  40. );
  41. #if defined( DEBUG ) || defined( DBG ) || defined( TESTCODE )
  42. #define ASSERT( a ) (( a ) ? 1 : Assert( #a, __FILE__, __LINE__ ))
  43. #else
  44. #define ASSERT( a )
  45. #endif
  46. #endif // ASSERT
  47. VOID
  48. InitializeCrc32Table(
  49. VOID
  50. );
  51. ULONG
  52. Crc32(
  53. IN ULONG InitialCrc,
  54. IN PVOID Buffer,
  55. IN ULONG ByteCount
  56. );
  57. BOOL
  58. SafeCompleteCrc32(
  59. IN PVOID Buffer,
  60. IN ULONG ByteCount,
  61. OUT PULONG CrcValue
  62. );
  63. BOOL
  64. SafeCompleteMD5(
  65. IN PVOID Buffer,
  66. IN ULONG ByteCount,
  67. OUT PMD5_HASH MD5Value
  68. );
  69. BOOL
  70. MyMapViewOfFileByHandle(
  71. IN HANDLE FileHandle,
  72. OUT ULONG *FileSize,
  73. OUT PVOID *MapBase
  74. );
  75. BOOL
  76. MyMapViewOfFileA(
  77. IN LPCSTR FileName,
  78. OUT ULONG *FileSize,
  79. OUT HANDLE *FileHandle,
  80. OUT PVOID *MapBase
  81. );
  82. BOOL
  83. MyCreateMappedFileA(
  84. IN LPCSTR FileName,
  85. IN ULONG InitialSize,
  86. OUT HANDLE *FileHandle,
  87. OUT PVOID *MapBase
  88. );
  89. BOOL
  90. MyCreateMappedFileByHandle(
  91. IN HANDLE FileHandle,
  92. IN ULONG InitialSize,
  93. OUT PVOID *MapBase
  94. );
  95. VOID
  96. MyUnmapCreatedMappedFile(
  97. IN HANDLE FileHandle,
  98. IN PVOID MapBase,
  99. IN ULONG FileSize,
  100. IN PFILETIME FileTime OPTIONAL
  101. );
  102. PVOID
  103. __fastcall
  104. MyVirtualAlloc(
  105. ULONG Size
  106. );
  107. VOID
  108. __fastcall
  109. MyVirtualFree(
  110. PVOID Allocation
  111. );
  112. HANDLE
  113. CreateSubAllocator(
  114. IN ULONG InitialCommitSize,
  115. IN ULONG GrowthCommitSize
  116. );
  117. PVOID
  118. __fastcall
  119. SubAllocate(
  120. IN HANDLE hAllocator,
  121. IN ULONG Size
  122. );
  123. VOID
  124. DestroySubAllocator(
  125. IN HANDLE hAllocator
  126. );
  127. LPSTR
  128. __fastcall
  129. MySubAllocStrDup(
  130. IN HANDLE SubAllocator,
  131. IN LPCSTR String
  132. );
  133. LPSTR
  134. MySubAllocStrDupAndCat(
  135. IN HANDLE SubAllocator,
  136. IN LPCSTR String1,
  137. IN LPCSTR String2,
  138. IN CHAR Separator
  139. );
  140. PVOID
  141. MyHeapAllocZero(
  142. IN ULONG Size
  143. );
  144. VOID
  145. MyHeapFree(
  146. IN PVOID Allocation
  147. );
  148. ULONG
  149. HashName(
  150. IN LPCSTR Name
  151. );
  152. ULONG
  153. HashNameCaseInsensitive(
  154. IN LPCSTR Name
  155. );
  156. VOID
  157. MyLowercase(
  158. IN OUT LPSTR String
  159. );
  160. VOID
  161. DwordToHexString(
  162. IN DWORD Value,
  163. OUT LPSTR Buffer // writes exactly 9 bytes including terminator
  164. );
  165. BOOL
  166. HashToHexString(
  167. IN PMD5_HASH HashValue,
  168. OUT LPSTR Buffer // must be at least 33 bytes
  169. );
  170. //
  171. // FILETIME units are 100ns intervals from 01/01/1601.
  172. //
  173. // ULONG units are seconds from 01/01/1970.
  174. //
  175. // There are 10,000,000 FILETIME units in one second.
  176. //
  177. // There are 11,644,473,600 seconds from 01/01/1601 to 01/01/1970.
  178. //
  179. #define FILETIME_UNITS_PER_SECOND 10000000
  180. #define FILETIME_TO_ULONG_OFFSET 11644473600
  181. VOID
  182. __inline
  183. UlongTimeToFileTime(
  184. IN ULONG UlongTime,
  185. OUT PFILETIME FileTime
  186. )
  187. {
  188. *(UNALIGNED DWORDLONG *)FileTime = ( UlongTime + FILETIME_TO_ULONG_OFFSET ) * FILETIME_UNITS_PER_SECOND;
  189. }
  190. ULONG
  191. __inline
  192. FileTimeToUlongTime(
  193. IN PFILETIME FileTime
  194. )
  195. {
  196. return (ULONG)(( *(UNALIGNED DWORDLONG *)FileTime / FILETIME_UNITS_PER_SECOND ) - FILETIME_TO_ULONG_OFFSET );
  197. }
  198. #ifdef __cplusplus
  199. }
  200. #endif
  201. #endif // _PATCH_MISC_H_