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.

267 lines
7.6 KiB

  1. /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  2. Copyright (c) 1993 Microsoft Corporation
  3. Module Name :
  4. unmrshlp.c
  5. Abstract :
  6. This file contains the routines for unmarshalling an array's or a
  7. structure's embedded pointers.
  8. Author :
  9. David Kays dkays September 1993.
  10. Revision History :
  11. ---------------------------------------------------------------------*/
  12. #include "ndrp.h"
  13. #include "attack.h"
  14. #include "pointerq.h"
  15. PFORMAT_STRING
  16. NdrpEmbeddedPointerUnmarshall(
  17. PMIDL_STUB_MESSAGE pStubMsg,
  18. uchar * pMemory,
  19. PFORMAT_STRING pFormat,
  20. uchar fNewMemory )
  21. /*++
  22. Routine Description :
  23. Unmarshalls an array's or a structure's embedded pointers.
  24. Arguments :
  25. pStubMsg - Pointer to the stub message.
  26. pMemory - Pointer to the structure or array whose embedded pointers
  27. are being unmarshalled.
  28. pFormat - Pointer layout format string description.
  29. fNewMemory - TRUE if the array or structure was allocated during
  30. unmarshalling, FALSE otherwise.
  31. Return :
  32. Format string pointer after the pointer layout.
  33. --*/
  34. {
  35. uchar ** ppMemPtr;
  36. uchar ** ppBufPtr;
  37. uchar * pBufferMark;
  38. ULONG_PTR MaxCountSave;
  39. long OffsetSave;
  40. MaxCountSave = pStubMsg->MaxCount;
  41. OffsetSave = pStubMsg->Offset;
  42. pStubMsg->Memory = pMemory;
  43. POINTER_BUFFER_SWAP_CONTEXT SwapContext(pStubMsg);
  44. // Save BufferMark in a local.
  45. pBufferMark = pStubMsg->BufferMark;
  46. // Increment past FC_PP and FC_PAD.
  47. pFormat += 2;
  48. for (;;)
  49. {
  50. if ( *pFormat == FC_END )
  51. {
  52. return pFormat;
  53. }
  54. // Check for FC_FIXED_REPEAT or FC_VARIABLE_REPEAT.
  55. if ( *pFormat != FC_NO_REPEAT )
  56. {
  57. pStubMsg->MaxCount = MaxCountSave;
  58. pStubMsg->Offset = OffsetSave;
  59. pStubMsg->BufferMark = pBufferMark;
  60. pFormat = NdrpEmbeddedRepeatPointerUnmarshall( pStubMsg,
  61. pMemory,
  62. pFormat,
  63. fNewMemory );
  64. // Continue to the next pointer.
  65. continue;
  66. }
  67. // Compute the pointer to the current memory pointer to the data.
  68. ppMemPtr = (uchar **)( pMemory + *((signed short *)(pFormat + 2)) );
  69. // Compute the pointer to the pointer in the buffer.
  70. ppBufPtr = (uchar **)(pBufferMark + *((signed short *)(pFormat + 4)));
  71. // Increment to the pointer description.
  72. pFormat += 6;
  73. //
  74. // If the incomming encapsulating memory pointer was just allocated,
  75. // then explicitly null out the current pointer.
  76. //
  77. if ( fNewMemory )
  78. *ppMemPtr = 0;
  79. NdrpPointerUnmarshall(
  80. pStubMsg,
  81. (uchar**)ppMemPtr, // Memory rep written here
  82. *ppMemPtr,
  83. (long *)ppBufPtr, // Wire rep written here
  84. pFormat );
  85. // Increment to the next pointer description.
  86. pFormat += 4;
  87. }
  88. }
  89. PFORMAT_STRING
  90. NdrpEmbeddedRepeatPointerUnmarshall(
  91. PMIDL_STUB_MESSAGE pStubMsg,
  92. uchar * pMemory,
  93. PFORMAT_STRING pFormat,
  94. uchar fNewMemory )
  95. /*++
  96. Routine Description :
  97. Unmarshalls an array's embedded pointers.
  98. Arguments :
  99. pStubMsg - Pointer to the stub message.
  100. pMemory - Pointer to the array whose embedded pointers are being
  101. unmarshalled.
  102. pFormat - Pointer layout format string description.
  103. fNewMemory - TRUE if the array was allocated during unmarshalling,
  104. FALSE otherwise.
  105. Return :
  106. Format string pointer after the pointer layout.
  107. --*/
  108. {
  109. uchar ** ppMemPtr;
  110. uchar ** ppBufPtr;
  111. PFORMAT_STRING pFormatSave;
  112. uchar * pBufferMark;
  113. uchar * pArrayElement;
  114. ulong RepeatCount, RepeatIncrement, Pointers, PointersSave;
  115. CORRELATION_RESOURCE_SAVE;
  116. SAVE_CORRELATION_MEMORY();
  117. // Get the beginning of the contained structure in the buffer.
  118. pBufferMark = pStubMsg->BufferMark;
  119. // Get the repeat count.
  120. switch ( *pFormat )
  121. {
  122. case FC_FIXED_REPEAT :
  123. pFormat += 2;
  124. RepeatCount = *((ushort *)pFormat);
  125. break;
  126. case FC_VARIABLE_REPEAT :
  127. RepeatCount = (ulong)pStubMsg->MaxCount;
  128. //
  129. // Check if this variable repeat instance also has a variable
  130. // offset (this would be the case for a conformant varying array
  131. // of pointers, or structures which contain pointers). If so then
  132. // increment the format string to point to the actual first array
  133. // element which is being marshalled.
  134. //
  135. if ( pFormat[1] == FC_VARIABLE_OFFSET )
  136. pMemory += *((ushort *)(pFormat + 2)) * pStubMsg->Offset;
  137. // else pFormat[1] == FC_FIXED_OFFSET - do nothing
  138. break;
  139. default :
  140. NDR_ASSERT(0,"NdrpEmbeddedRepeatPointerUnmarshall : bad format");
  141. RpcRaiseException( RPC_S_INTERNAL_ERROR );
  142. return 0;
  143. }
  144. // Increment format string to increment field.
  145. pFormat += 2;
  146. // Get the increment amount between successive pointers.
  147. RepeatIncrement = *((ushort * &)pFormat)++;
  148. // Load up pointer to first element of embedded array.
  149. pArrayElement = pBufferMark + *((ushort * &)pFormat)++;
  150. // Get number of pointers in each array element.
  151. PointersSave = Pointers = *((ushort * &)pFormat)++;
  152. pFormatSave = pFormat;
  153. //
  154. // Loop over the number of shipped array elements.
  155. //
  156. for ( ; RepeatCount--;
  157. pBufferMark += RepeatIncrement,
  158. pMemory += RepeatIncrement,
  159. pArrayElement += RepeatIncrement )
  160. {
  161. pFormat = pFormatSave;
  162. Pointers = PointersSave;
  163. // Set the correlation check context to be the beginning of each element
  164. // in the array. This is necessary since other functions will assume that
  165. // the context points to the top of the flat part of the containing structure.
  166. // If the containing structure is embedded in another structure, the offset
  167. // for correlation checks will be relative to the topmost structure.
  168. pStubMsg->pCorrMemory = pArrayElement;
  169. //
  170. // Loop over the number of pointer per array element (which can
  171. // be greater than one for an array of structures).
  172. //
  173. for ( ; Pointers--; )
  174. {
  175. // Pointer to the pointer in memory.
  176. ppMemPtr = (uchar **)(pMemory + *((signed short * &)pFormat)++);
  177. // Pointer to the pointer's id in the buffer.
  178. ppBufPtr = (uchar **)(pBufferMark + *((signed short * &)pFormat)++);
  179. //
  180. // If the incomming encapsulating memory pointer was just
  181. // allocated, then explicitly null out the current pointer.
  182. //
  183. if ( fNewMemory )
  184. *ppMemPtr = 0;
  185. NdrpPointerUnmarshall(
  186. pStubMsg,
  187. (uchar**)ppMemPtr, // Memory rep written here
  188. *ppMemPtr,
  189. (long *)ppBufPtr, // Wire rep written here
  190. pFormat );
  191. // Increment past the pointer description.
  192. pFormat += 4;
  193. }
  194. }
  195. RESET_CORRELATION_MEMORY();
  196. // Return the format string pointer past the array's pointer description.
  197. return pFormatSave + PointersSave * 8;
  198. }