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.

191 lines
6.3 KiB

  1. /*+--------------------------------------------------------------------------*/
  2. /* */
  3. /* Microsoft Windows */
  4. /* Copyright (C) Microsoft Corporation, 1993 */
  5. /* */
  6. /* File: propvar.h */
  7. /* */
  8. /* Contents: PROPVARIANT manipulation code */
  9. /* */
  10. /*---------------------------------------------------------------------------*/
  11. #ifndef _PROPVAR_HXX_
  12. #define _PROPVAR_HXX_
  13. #include "propset.hxx"
  14. // forward declarations
  15. class PMemoryAllocator;
  16. SERIALIZEDPROPERTYVALUE *
  17. RtlConvertVariantToProperty(
  18. IN PROPVARIANT const *pvar,
  19. IN USHORT CodePage,
  20. OUT SERIALIZEDPROPERTYVALUE *pprop,
  21. IN OUT ULONG *pcb,
  22. IN PROPID pid,
  23. IN BOOLEAN fVariantVector,
  24. OUT NTSTATUS *pstatus);
  25. VOID
  26. RtlConvertPropertyToVariant(
  27. IN SERIALIZEDPROPERTYVALUE const *pprop,
  28. IN USHORT CodePage,
  29. OUT PROPVARIANT *pvar,
  30. IN PMemoryAllocator *pma,
  31. OUT NTSTATUS *pstatus);
  32. VOID
  33. CleanupVariants(
  34. IN PROPVARIANT *pvar,
  35. IN ULONG cprop,
  36. IN PMemoryAllocator *pma);
  37. /*+--------------------------------------------------------------------------
  38. Function: SignalOverflow, SignalInvalidParameter, SignalStatus
  39. Synopsis: ASSERT and raise data corrupt/overflow/specified error
  40. Arguments: [szReason] -- string explanation
  41. [Status] -- Status to raise (SignalStatus only)
  42. Returns: None
  43. +--------------------------------------------------------------------------*/
  44. #define StatusOverflow(pstatus, szReason) \
  45. *(pstatus) = STATUS_BUFFER_OVERFLOW; \
  46. TraceStatus(szReason)
  47. #define StatusAccessDenied(pstatus, szReason) \
  48. *(pstatus) = STATUS_ACCESS_DENIED; \
  49. TraceStatus(szReason);
  50. #define StatusInvalidParameter(pstatus, szReason) \
  51. *(pstatus) = STATUS_INVALID_PARAMETER; \
  52. TraceStatus(szReason);
  53. #define StatusNoMemory(pstatus, szReason) \
  54. *(pstatus) = STATUS_INSUFFICIENT_RESOURCES;\
  55. TraceStatus(szReason);
  56. #define StatusDiskFull(pstatus, szReason) \
  57. *(pstatus) = STATUS_DISK_FULL; \
  58. TraceStatus(szReason);
  59. #define StatusError(pstatus, szReason, Status) \
  60. *(pstatus) = Status; \
  61. TraceStatus(szReason);
  62. #define StatusKBufferOverflow(pstatus, szReason) StatusNoMemory(pstatus, szReason)
  63. #define KERNELSELECT(k, u) u
  64. #define DBGPROPASSERT KERNELSELECT(DBGPROP, DBG)
  65. #if DBGPROPASSERT
  66. #define TraceStatus(szReason) \
  67. { \
  68. DebugTrace(0, DEBTRACE_ERROR, (szReason "\n")); \
  69. PROPASSERTMSG(szReason, !(DebugLevel & DEBTRACE_WARN)); \
  70. }
  71. #else
  72. #define TraceStatus(szReason)
  73. #endif
  74. #define AssertVarField(field, cb) \
  75. PROPASSERT(FIELD_OFFSET(PROPVARIANT, iVal) == FIELD_OFFSET(PROPVARIANT, field) && \
  76. sizeof(((PROPVARIANT *) 0)->field) == (cb))
  77. #define AssertVarVector(field, cbElem) \
  78. PROPASSERT(FIELD_OFFSET(PROPVARIANT, cai.cElems) == \
  79. FIELD_OFFSET(PROPVARIANT, field.cElems) && \
  80. FIELD_OFFSET(PROPVARIANT, cai.pElems) == \
  81. FIELD_OFFSET(PROPVARIANT, field.pElems) && \
  82. sizeof(((PROPVARIANT *) 0)->field.pElems[0]) == (cbElem))
  83. #define AssertByteField(field) AssertVarField(field, sizeof(BYTE))
  84. #define AssertShortField(field) AssertVarField(field, sizeof(SHORT))
  85. #define AssertLongField(field) AssertVarField(field, sizeof(LONG))
  86. #define AssertLongLongField(field) AssertVarField(field, sizeof(LONGLONG))
  87. #define AssertStringField(field) AssertVarField(field, sizeof(VOID *))
  88. #define AssertByteVector(field) AssertVarVector(field, sizeof(BYTE))
  89. #define AssertShortVector(field) AssertVarVector(field, sizeof(SHORT))
  90. #define AssertLongVector(field) AssertVarVector(field, sizeof(LONG))
  91. #define AssertLongLongVector(field) AssertVarVector(field, sizeof(LONGLONG))
  92. #define AssertStringVector(field) AssertVarVector(field, sizeof(VOID *))
  93. #define AssertVariantVector(field) AssertVarVector(field, sizeof(PROPVARIANT))
  94. #define BSTRLEN(bstrVal) *((ULONG *) bstrVal - 1)
  95. /*+-------------------------------------------------------------------
  96. Class: CBufferAllocator, private
  97. Synopsis: allocation from a buffer
  98. Notes: The Summary catalog APIs use a single buffer to serialize row
  99. values on input and deserialize them on output. This class
  100. encapsulates the memory allocation routines for these APIs.
  101. -----------------------------------------------------------------------*/
  102. class CBufferAllocator : public PMemoryAllocator
  103. {
  104. public:
  105. inline CBufferAllocator(ULONG cbBuffer, VOID *pvBuffer)
  106. {
  107. _cbFree = cbBuffer;
  108. _pvCur = _pvBuffer = pvBuffer;
  109. #if _X86_ /* stack variables on x86 are not aligned*/
  110. PROPASSERT(((ULONG) _pvCur & (sizeof(LONG) - 1)) == 0);
  111. #else /* RISC*/
  112. PROPASSERT(((ULONG) _pvCur & (sizeof(LONGLONG) - 1)) == 0);
  113. #endif /* X86/RISC*/
  114. }
  115. VOID *Allocate(ULONG cbSize);
  116. VOID Free(VOID *pv) { }
  117. inline ULONG GetFreeSize(VOID) { return(_cbFree); }
  118. private:
  119. ULONG _cbFree;
  120. VOID *_pvCur;
  121. VOID *_pvBuffer;
  122. };
  123. /*+-------------------------------------------------------------------
  124. Member: CBufferAllocator::Allocate, private
  125. Synopsis: allocation from a buffer
  126. Arguments: [cb] -- Count of bytes to be allocated.
  127. Returns: pointer to 'allocated' memory -- NULL if no space left
  128. ----------------------------------------------------------------------*/
  129. #define DEFINE_CBufferAllocator__Allocate \
  130. VOID * \
  131. CBufferAllocator::Allocate(ULONG cb) \
  132. { \
  133. VOID *pv; \
  134. \
  135. cb = (cb + sizeof(LONGLONG) - 1) & ~(sizeof(LONGLONG) - 1); \
  136. if (cb > _cbFree) \
  137. { \
  138. return(NULL); \
  139. } \
  140. pv = _pvCur; \
  141. _pvCur = (BYTE *) _pvCur + cb; \
  142. _cbFree -= cb; \
  143. return(pv); \
  144. }
  145. #endif /* #ifndef _PROPVAR_HXX_ */