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.

393 lines
9.7 KiB

  1. //+--------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1996
  5. //
  6. // File: propmac.hxx
  7. //
  8. // Contents: various macros used in property set code
  9. //
  10. //---------------------------------------------------------------------------
  11. #ifndef _PROPMAC_HXX_
  12. #define _PROPMAC_HXX_
  13. #include "../../byteordr.hxx"
  14. #define Prop_wcslen wcslen
  15. #define Prop_wcsnicmp _wcsnicmp
  16. #define Prop_wcscmp wcscmp
  17. #define Prop_wcscpy wcscpy
  18. //+---------------------------------------------------------------------------
  19. // Function: Add2Ptr
  20. //
  21. // Synopsis: Add an unscaled increment to a ptr regardless of type.
  22. //
  23. // Arguments: [pv] -- Initial ptr.
  24. // [cb] -- Increment
  25. //
  26. // Returns: Incremented ptr.
  27. //
  28. //----------------------------------------------------------------------------
  29. inline VOID *
  30. Add2Ptr(VOID const *pv, ULONG cb)
  31. {
  32. return((BYTE *) pv + cb);
  33. }
  34. //+---------------------------------------------------------------------------
  35. // Function: Add2ConstPtr
  36. //
  37. // Synopsis: Add an unscaled increment to a ptr regardless of type.
  38. //
  39. // Arguments: [pv] -- Initial ptr.
  40. // [cb] -- Increment
  41. //
  42. // Returns: Incremented ptr.
  43. //
  44. //----------------------------------------------------------------------------
  45. inline
  46. const VOID *
  47. Add2ConstPtr(const VOID *pv, ULONG cb)
  48. {
  49. return((const BYTE *) pv + cb);
  50. }
  51. //+--------------------------------------------------------------------------
  52. // Function: CopyFileTime, private
  53. //
  54. // Synopsis: Copy LARGE_INTEGER time to FILETIME structure
  55. //
  56. // Arguments: [pft] -- pointer to FILETIME
  57. // [pli] -- pointer to LARGE_INTEGER
  58. //
  59. // Returns: Nothing
  60. //---------------------------------------------------------------------------
  61. __inline VOID
  62. CopyFileTime(OUT FILETIME *pft, IN LARGE_INTEGER *pli)
  63. {
  64. *pft = * (FILETIME *) pli;
  65. }
  66. //+--------------------------------------------------------------------------
  67. // Function: ZeroFileTime, private
  68. //
  69. // Synopsis: Zero FILETIME structure
  70. //
  71. // Arguments: [pft] -- pointer to FILETIME
  72. //
  73. // Returns: Nothing
  74. //---------------------------------------------------------------------------
  75. __inline VOID
  76. ZeroFileTime(OUT FILETIME *pft)
  77. {
  78. pft->dwLowDateTime = pft->dwHighDateTime = 0;
  79. }
  80. #define DwordAlign(n) (((n) + sizeof(ULONG) - 1) & ~(sizeof(ULONG) - 1))
  81. #define DwordRemain(cb) ((sizeof(ULONG) - ((cb) % sizeof(ULONG))) % sizeof(ULONG))
  82. #define QuadAlign(n) (((n) + sizeof(LONGLONG) - 1) & ~(sizeof(LONGLONG) - 1))
  83. #include "propapi.h"
  84. #if DBG
  85. extern "C" LONG ExceptionFilter(struct _EXCEPTION_POINTERS *pep);
  86. #else // DBG
  87. #define ExceptionFilter(pep) EXCEPTION_EXECUTE_HANDLER
  88. #endif // DBG
  89. extern "C" UNICODECALLOUTS UnicodeCallouts;
  90. // The CMemSerStream and CDeMemSerStream have different requirements for
  91. // handling buffer overflow conditions. In the case of the driver this
  92. // is indicative of a corrupted stream and we would like to raise an
  93. // exception. On the other hand in Query implementation we deal with
  94. // streams whose sizes are precomputed in the user mode. Therefore we
  95. // do not wish to incur any additional penalty in handling such situations.
  96. // In debug builds this condition is asserted while in retail builds it is
  97. // ignored. The CMemSerStream and CMemDeSerStream implementation are
  98. // implemented using a macro HANDLE_OVERFLOW(fOverflow) which take the
  99. // appropriate action.
  100. #define HANDLE_OVERFLOW(fOverflow) \
  101. if (fOverflow) { \
  102. PropRaiseException(STATUS_BUFFER_OVERFLOW); \
  103. }
  104. #define newk(Tag, pCounter) new
  105. #if DBG
  106. extern "C" ULONG DebugLevel;
  107. extern "C" ULONG DebugIndent;
  108. #define DEBTRACE_ERROR (ULONG) 0x00000001
  109. #define DEBTRACE_WARN (ULONG) 0x00000002
  110. #define DEBTRACE_CREATESTREAM (ULONG) 0x00000004
  111. #define DEBTRACE_NTPROP (ULONG) 0x00000008
  112. #define DEBTRACE_MAPSTM (ULONG) 0x00000010
  113. #define DEBTRACE_PROPERTY (ULONG) 0x00000020
  114. #define DEBTRACE_SUMCAT (ULONG) 0x00000040
  115. #define DEBTRACE_PROPVALIDATE (ULONG) 0x00010000 // awfully noisy
  116. #define DEBTRACE_PROPPATCH (ULONG) 0x00020000 // awfully noisy
  117. extern ULONG DbgPrint(PCHAR Format, ...);
  118. #define DebugTrace(indent, flag, args) \
  119. if ((flag) == 0 || (DebugLevel & (flag))) \
  120. { \
  121. DebugIndent += (ULONG) (indent); \
  122. DbgPrint("NTDLL: %*s", DebugIndent, ""); \
  123. DbgPrint args; \
  124. } \
  125. else
  126. #ifdef _MSC_VER
  127. #pragma warning(disable:4512)
  128. #endif
  129. class CDebugTrace {
  130. public:
  131. inline CDebugTrace(CHAR *psz);
  132. inline ~CDebugTrace();
  133. private:
  134. CHAR const *const _psz;
  135. };
  136. #ifdef _MSC_VER
  137. #pragma warning(default:4512)
  138. #endif
  139. inline CDebugTrace::CDebugTrace(CHAR *psz): _psz(psz)
  140. {
  141. DebugTrace(+1, 0, ("Entering -- %s\n", _psz));
  142. }
  143. inline CDebugTrace::~CDebugTrace()
  144. {
  145. DebugTrace(-1, 0, ("Exiting -- %s\n", _psz));
  146. }
  147. #define DEBUG_TRACE(ProcName) CDebugTrace _trace_(#ProcName);
  148. #else
  149. #define DebugTrace(indent, flag, args)
  150. #define DEBUG_TRACE(ProcName)
  151. #endif
  152. //+-----------------------------------------------------------------------
  153. //+-----------------------------------------------------------------------
  154. //
  155. // Byte-swapping functions
  156. //
  157. //+-----------------------------------------------------------------------
  158. //+-----------------------------------------------------------------------
  159. // FmtID Byte-Swapped Comparisson. I.e, does rfmtid1 equal
  160. // a byte-swapped rfmtid2?
  161. inline BOOL IsEqualFMTIDByteSwap( REFFMTID rfmtid1, REFFMTID rfmtid2 )
  162. {
  163. return( rfmtid1.Data1 == ByteSwap(rfmtid2.Data1)
  164. &&
  165. rfmtid1.Data2 == ByteSwap(rfmtid2.Data2)
  166. &&
  167. rfmtid1.Data3 == ByteSwap(rfmtid2.Data3)
  168. &&
  169. !memcmp(&rfmtid1.Data4, &rfmtid2.Data4, sizeof(rfmtid1.Data4))
  170. );
  171. }
  172. // This define is for a special-case value of cbByteSwap in
  173. // PBSBuffer
  174. #define CBBYTESWAP_UID ((ULONG) -1)
  175. // The following byte-swapping functions mostly forward the call
  176. // to the ByteSwap overloads when compiled in a big-endian
  177. // system, and NOOP when compiled in a little-endian
  178. // system (because property sets are always little-endian).
  179. #ifdef BIGENDIAN
  180. // This is a big-endian build, property byte-swapping is enabled.
  181. // -----------
  182. // Swap a Byte
  183. // -----------
  184. // This exists primarily so that PropByteSwap(OLECHAR) will work
  185. // whether OLECHAR is Unicode or Ansi.
  186. inline BYTE PropByteSwap( char b )
  187. {
  188. return ByteSwap(b);
  189. }
  190. inline VOID PropByteSwap( char *pb )
  191. {
  192. ByteSwap(pb);
  193. }
  194. // -----------
  195. // Swap a Word
  196. // -----------
  197. inline WORD PropByteSwap( WORD w )
  198. {
  199. return ByteSwap(w);
  200. }
  201. inline VOID PropByteSwap( WORD *pw )
  202. {
  203. ByteSwap(pw);
  204. }
  205. inline SHORT PropByteSwap( SHORT s )
  206. {
  207. PROPASSERT( sizeof(WORD) == sizeof(SHORT) );
  208. return ByteSwap( (WORD) s );
  209. }
  210. inline VOID PropByteSwap( SHORT *ps )
  211. {
  212. PROPASSERT( sizeof(WORD) == sizeof(SHORT) );
  213. ByteSwap( (WORD*) ps );
  214. }
  215. // ------------
  216. // Swap a DWORD
  217. // ------------
  218. inline DWORD PropByteSwap( DWORD dw )
  219. {
  220. return ByteSwap(dw);
  221. }
  222. inline VOID PropByteSwap( DWORD *pdw )
  223. {
  224. ByteSwap(pdw);
  225. }
  226. inline LONG PropByteSwap( LONG l )
  227. {
  228. PROPASSERT( sizeof(DWORD) == sizeof(LONG) );
  229. return ByteSwap( (DWORD) l );
  230. }
  231. inline VOID PropByteSwap( LONG *pl )
  232. {
  233. PROPASSERT( sizeof(DWORD) == sizeof(LONG) );
  234. ByteSwap( (DWORD*) pl );
  235. }
  236. // -------------------------
  237. // Swap a LONGLONG (64 bits)
  238. // -------------------------
  239. inline LONGLONG PropByteSwap( LONGLONG ll )
  240. {
  241. return( ByteSwap(ll) );
  242. }
  243. inline VOID PropByteSwap( LONGLONG *pll )
  244. {
  245. // we have to deal with two DWORDs instead of one LONG LONG
  246. // because the pointer might not be 8 word aligned.
  247. // (it is DWORD (4 bytes) aligned though)
  248. PROPASSERT( sizeof(LONGLONG) == 2 * sizeof (DWORD));
  249. DWORD *pdw = (DWORD*)pll;
  250. DWORD dwTemp = ByteSwap( *pdw ); // temp = swapped(dw1)
  251. ByteSwap( pdw+1 ); // swap dw2
  252. *pdw = *(pdw+1); // dw1 = dw2(swapped)
  253. *(pdw+1) = dwTemp; // dw2 = temp
  254. return;
  255. }
  256. // -----------
  257. // Swap a GUID
  258. // -----------
  259. inline VOID PropByteSwap( GUID *pguid )
  260. {
  261. ByteSwap(pguid);
  262. return;
  263. }
  264. #else // Little Endian
  265. // This is a little-endian build, property byte-swapping is disabled.
  266. inline BYTE PropByteSwap( BYTE b )
  267. {
  268. return (b);
  269. }
  270. inline VOID PropByteSwap( BYTE *pb )
  271. {
  272. UNREFERENCED_PARM(pb);
  273. }
  274. inline WORD PropByteSwap( WORD w )
  275. {
  276. return (w);
  277. }
  278. inline VOID PropByteSwap( WORD *pw )
  279. {
  280. UNREFERENCED_PARM(pw);
  281. }
  282. inline SHORT PropByteSwap( SHORT s )
  283. {
  284. return (s);
  285. }
  286. inline VOID PropByteSwap( SHORT *ps )
  287. {
  288. UNREFERENCED_PARM(ps);
  289. }
  290. inline DWORD PropByteSwap( DWORD dw )
  291. {
  292. return (dw);
  293. }
  294. inline VOID PropByteSwap( DWORD *pdw )
  295. {
  296. UNREFERENCED_PARM(pdw);
  297. }
  298. inline LONG PropByteSwap( LONG l )
  299. {
  300. return (l);
  301. }
  302. inline VOID PropByteSwap( LONG *pl )
  303. {
  304. UNREFERENCED_PARM(pl);
  305. }
  306. inline LONGLONG PropByteSwap( LONGLONG ll )
  307. {
  308. return(ll);
  309. }
  310. inline VOID PropByteSwap( LONGLONG *pll )
  311. {
  312. UNREFERENCED_PARM(pll);
  313. }
  314. // -----------
  315. // Swap a GUID
  316. // -----------
  317. inline VOID PropByteSwap( GUID *pguid )
  318. {
  319. UNREFERENCED_PARM(pguid);
  320. }
  321. #endif // #else // Little Endian
  322. #endif// _PROPMAC_HXX_