4 * Copyright 2002 Greg Turner
5 * Copyright 2003-2006 CodeWeavers
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 * - Non-conformant strings
25 * - Encapsulated unions
26 * - Byte count pointers
27 * - transmit_as/represent as
28 * - Multi-dimensional arrays
29 * - Conversion functions (NdrConvert)
30 * - Checks for integer overflow when calculating array sizes
31 * - Checks for out-of-memory conditions
48 #include "wine/unicode.h"
49 #include "wine/rpcfc.h"
51 #include "wine/debug.h"
53 WINE_DEFAULT_DEBUG_CHANNEL(ole);
56 # define LITTLE_ENDIAN_UINT32_WRITE(pchar, uint32) \
57 (*((UINT32 *)(pchar)) = (uint32))
59 # define LITTLE_ENDIAN_UINT32_READ(pchar) \
60 (*((UINT32 *)(pchar)))
62 /* these would work for i386 too, but less efficient */
63 # define LITTLE_ENDIAN_UINT32_WRITE(pchar, uint32) \
64 (*(pchar) = LOBYTE(LOWORD(uint32)), \
65 *((pchar)+1) = HIBYTE(LOWORD(uint32)), \
66 *((pchar)+2) = LOBYTE(HIWORD(uint32)), \
67 *((pchar)+3) = HIBYTE(HIWORD(uint32)), \
68 (uint32)) /* allow as r-value */
70 # define LITTLE_ENDIAN_UINT32_READ(pchar) \
72 MAKEWORD(*(pchar), *((pchar)+1)), \
73 MAKEWORD(*((pchar)+2), *((pchar)+3))))
76 #define BIG_ENDIAN_UINT32_WRITE(pchar, uint32) \
77 (*((pchar)+3) = LOBYTE(LOWORD(uint32)), \
78 *((pchar)+2) = HIBYTE(LOWORD(uint32)), \
79 *((pchar)+1) = LOBYTE(HIWORD(uint32)), \
80 *(pchar) = HIBYTE(HIWORD(uint32)), \
81 (uint32)) /* allow as r-value */
83 #define BIG_ENDIAN_UINT32_READ(pchar) \
85 MAKEWORD(*((pchar)+3), *((pchar)+2)), \
86 MAKEWORD(*((pchar)+1), *(pchar))))
88 #ifdef NDR_LOCAL_IS_BIG_ENDIAN
89 # define NDR_LOCAL_UINT32_WRITE(pchar, uint32) \
90 BIG_ENDIAN_UINT32_WRITE(pchar, uint32)
91 # define NDR_LOCAL_UINT32_READ(pchar) \
92 BIG_ENDIAN_UINT32_READ(pchar)
94 # define NDR_LOCAL_UINT32_WRITE(pchar, uint32) \
95 LITTLE_ENDIAN_UINT32_WRITE(pchar, uint32)
96 # define NDR_LOCAL_UINT32_READ(pchar) \
97 LITTLE_ENDIAN_UINT32_READ(pchar)
100 /* _Align must be the desired alignment,
101 * e.g. ALIGN_LENGTH(len, 4) to align on a dword boundary. */
102 #define ALIGNED_LENGTH(_Len, _Align) (((_Len)+(_Align)-1)&~((_Align)-1))
103 #define ALIGNED_POINTER(_Ptr, _Align) ((LPVOID)ALIGNED_LENGTH((ULONG_PTR)(_Ptr), _Align))
104 #define ALIGN_LENGTH(_Len, _Align) _Len = ALIGNED_LENGTH(_Len, _Align)
105 #define ALIGN_POINTER(_Ptr, _Align) _Ptr = ALIGNED_POINTER(_Ptr, _Align)
107 #define STD_OVERFLOW_CHECK(_Msg) do { \
108 TRACE("buffer=%d/%ld\n", _Msg->Buffer - (unsigned char *)_Msg->RpcMsg->Buffer, _Msg->BufferLength); \
109 if (_Msg->Buffer > (unsigned char *)_Msg->RpcMsg->Buffer + _Msg->BufferLength) \
110 ERR("buffer overflow %d bytes\n", _Msg->Buffer - ((unsigned char *)_Msg->RpcMsg->Buffer + _Msg->BufferLength)); \
113 #define NDR_TABLE_SIZE 128
114 #define NDR_TABLE_MASK 127
116 static unsigned char *WINAPI NdrBaseTypeMarshall(PMIDL_STUB_MESSAGE, unsigned char *, PFORMAT_STRING);
117 static unsigned char *WINAPI NdrBaseTypeUnmarshall(PMIDL_STUB_MESSAGE, unsigned char **, PFORMAT_STRING, unsigned char);
118 static void WINAPI NdrBaseTypeBufferSize(PMIDL_STUB_MESSAGE, unsigned char *, PFORMAT_STRING);
119 static void WINAPI NdrBaseTypeFree(PMIDL_STUB_MESSAGE, unsigned char *, PFORMAT_STRING);
120 static unsigned long WINAPI NdrBaseTypeMemorySize(PMIDL_STUB_MESSAGE, PFORMAT_STRING);
122 const NDR_MARSHALL NdrMarshaller[NDR_TABLE_SIZE] = {
124 NdrBaseTypeMarshall, NdrBaseTypeMarshall, NdrBaseTypeMarshall,
125 NdrBaseTypeMarshall, NdrBaseTypeMarshall, NdrBaseTypeMarshall, NdrBaseTypeMarshall,
126 NdrBaseTypeMarshall, NdrBaseTypeMarshall, NdrBaseTypeMarshall, NdrBaseTypeMarshall,
127 NdrBaseTypeMarshall, NdrBaseTypeMarshall, NdrBaseTypeMarshall, NdrBaseTypeMarshall,
131 NdrPointerMarshall, NdrPointerMarshall,
132 NdrPointerMarshall, NdrPointerMarshall,
134 NdrSimpleStructMarshall, NdrSimpleStructMarshall,
135 NdrConformantStructMarshall, NdrConformantStructMarshall,
136 NdrConformantVaryingStructMarshall,
137 NdrComplexStructMarshall,
139 NdrConformantArrayMarshall,
140 NdrConformantVaryingArrayMarshall,
141 NdrFixedArrayMarshall, NdrFixedArrayMarshall,
142 NdrVaryingArrayMarshall, NdrVaryingArrayMarshall,
143 NdrComplexArrayMarshall,
145 NdrConformantStringMarshall, 0, 0,
146 NdrConformantStringMarshall,
147 NdrNonConformantStringMarshall, 0, 0, 0,
149 NdrEncapsulatedUnionMarshall,
150 NdrNonEncapsulatedUnionMarshall,
151 NdrByteCountPointerMarshall,
152 NdrXmitOrRepAsMarshall, NdrXmitOrRepAsMarshall,
154 NdrInterfacePointerMarshall,
157 NdrUserMarshalMarshall
159 const NDR_UNMARSHALL NdrUnmarshaller[NDR_TABLE_SIZE] = {
161 NdrBaseTypeUnmarshall, NdrBaseTypeUnmarshall, NdrBaseTypeUnmarshall,
162 NdrBaseTypeUnmarshall, NdrBaseTypeUnmarshall, NdrBaseTypeUnmarshall, NdrBaseTypeUnmarshall,
163 NdrBaseTypeUnmarshall, NdrBaseTypeUnmarshall, NdrBaseTypeUnmarshall, NdrBaseTypeUnmarshall,
164 NdrBaseTypeUnmarshall, NdrBaseTypeUnmarshall, NdrBaseTypeUnmarshall, NdrBaseTypeUnmarshall,
166 NdrBaseTypeUnmarshall,
168 NdrPointerUnmarshall, NdrPointerUnmarshall,
169 NdrPointerUnmarshall, NdrPointerUnmarshall,
171 NdrSimpleStructUnmarshall, NdrSimpleStructUnmarshall,
172 NdrConformantStructUnmarshall, NdrConformantStructUnmarshall,
173 NdrConformantVaryingStructUnmarshall,
174 NdrComplexStructUnmarshall,
176 NdrConformantArrayUnmarshall,
177 NdrConformantVaryingArrayUnmarshall,
178 NdrFixedArrayUnmarshall, NdrFixedArrayUnmarshall,
179 NdrVaryingArrayUnmarshall, NdrVaryingArrayUnmarshall,
180 NdrComplexArrayUnmarshall,
182 NdrConformantStringUnmarshall, 0, 0,
183 NdrConformantStringUnmarshall,
184 NdrNonConformantStringUnmarshall, 0, 0, 0,
186 NdrEncapsulatedUnionUnmarshall,
187 NdrNonEncapsulatedUnionUnmarshall,
188 NdrByteCountPointerUnmarshall,
189 NdrXmitOrRepAsUnmarshall, NdrXmitOrRepAsUnmarshall,
191 NdrInterfacePointerUnmarshall,
194 NdrUserMarshalUnmarshall
196 const NDR_BUFFERSIZE NdrBufferSizer[NDR_TABLE_SIZE] = {
198 NdrBaseTypeBufferSize, NdrBaseTypeBufferSize, NdrBaseTypeBufferSize,
199 NdrBaseTypeBufferSize, NdrBaseTypeBufferSize, NdrBaseTypeBufferSize, NdrBaseTypeBufferSize,
200 NdrBaseTypeBufferSize, NdrBaseTypeBufferSize, NdrBaseTypeBufferSize, NdrBaseTypeBufferSize,
201 NdrBaseTypeBufferSize, NdrBaseTypeBufferSize, NdrBaseTypeBufferSize, NdrBaseTypeBufferSize,
203 NdrBaseTypeBufferSize,
205 NdrPointerBufferSize, NdrPointerBufferSize,
206 NdrPointerBufferSize, NdrPointerBufferSize,
208 NdrSimpleStructBufferSize, NdrSimpleStructBufferSize,
209 NdrConformantStructBufferSize, NdrConformantStructBufferSize,
210 NdrConformantVaryingStructBufferSize,
211 NdrComplexStructBufferSize,
213 NdrConformantArrayBufferSize,
214 NdrConformantVaryingArrayBufferSize,
215 NdrFixedArrayBufferSize, NdrFixedArrayBufferSize,
216 NdrVaryingArrayBufferSize, NdrVaryingArrayBufferSize,
217 NdrComplexArrayBufferSize,
219 NdrConformantStringBufferSize, 0, 0,
220 NdrConformantStringBufferSize,
221 NdrNonConformantStringBufferSize, 0, 0, 0,
223 NdrEncapsulatedUnionBufferSize,
224 NdrNonEncapsulatedUnionBufferSize,
225 NdrByteCountPointerBufferSize,
226 NdrXmitOrRepAsBufferSize, NdrXmitOrRepAsBufferSize,
228 NdrInterfacePointerBufferSize,
231 NdrUserMarshalBufferSize
233 const NDR_MEMORYSIZE NdrMemorySizer[NDR_TABLE_SIZE] = {
235 NdrBaseTypeMemorySize, NdrBaseTypeMemorySize, NdrBaseTypeMemorySize,
236 NdrBaseTypeMemorySize, NdrBaseTypeMemorySize, NdrBaseTypeMemorySize, NdrBaseTypeMemorySize,
237 NdrBaseTypeMemorySize, NdrBaseTypeMemorySize, NdrBaseTypeMemorySize, NdrBaseTypeMemorySize,
238 NdrBaseTypeMemorySize, NdrBaseTypeMemorySize, NdrBaseTypeMemorySize, NdrBaseTypeMemorySize,
240 NdrBaseTypeMemorySize,
242 NdrPointerMemorySize, NdrPointerMemorySize,
243 NdrPointerMemorySize, NdrPointerMemorySize,
245 NdrSimpleStructMemorySize, NdrSimpleStructMemorySize,
246 NdrConformantStructMemorySize, NdrConformantStructMemorySize,
247 NdrConformantVaryingStructMemorySize,
248 NdrComplexStructMemorySize,
250 NdrConformantArrayMemorySize,
251 NdrConformantVaryingArrayMemorySize,
252 NdrFixedArrayMemorySize, NdrFixedArrayMemorySize,
253 NdrVaryingArrayMemorySize, NdrVaryingArrayMemorySize,
254 NdrComplexArrayMemorySize,
256 NdrConformantStringMemorySize, 0, 0,
257 NdrConformantStringMemorySize,
258 NdrNonConformantStringMemorySize, 0, 0, 0,
260 NdrEncapsulatedUnionMemorySize,
261 NdrNonEncapsulatedUnionMemorySize,
262 NdrByteCountPointerMemorySize,
263 NdrXmitOrRepAsMemorySize, NdrXmitOrRepAsMemorySize,
265 NdrInterfacePointerMemorySize,
268 NdrUserMarshalMemorySize
270 const NDR_FREE NdrFreer[NDR_TABLE_SIZE] = {
272 NdrBaseTypeFree, NdrBaseTypeFree, NdrBaseTypeFree,
273 NdrBaseTypeFree, NdrBaseTypeFree, NdrBaseTypeFree, NdrBaseTypeFree,
274 NdrBaseTypeFree, NdrBaseTypeFree, NdrBaseTypeFree, NdrBaseTypeFree,
275 NdrBaseTypeFree, NdrBaseTypeFree, NdrBaseTypeFree, NdrBaseTypeFree,
279 NdrPointerFree, NdrPointerFree,
280 NdrPointerFree, NdrPointerFree,
282 NdrSimpleStructFree, NdrSimpleStructFree,
283 NdrConformantStructFree, NdrConformantStructFree,
284 NdrConformantVaryingStructFree,
285 NdrComplexStructFree,
287 NdrConformantArrayFree,
288 NdrConformantVaryingArrayFree,
289 NdrFixedArrayFree, NdrFixedArrayFree,
290 NdrVaryingArrayFree, NdrVaryingArrayFree,
296 NdrEncapsulatedUnionFree,
297 NdrNonEncapsulatedUnionFree,
299 NdrXmitOrRepAsFree, NdrXmitOrRepAsFree,
301 NdrInterfacePointerFree,
307 void * WINAPI NdrAllocate(MIDL_STUB_MESSAGE *pStubMsg, size_t len)
309 /* hmm, this is probably supposed to do more? */
310 return pStubMsg->pfnAllocate(len);
313 static void WINAPI NdrFree(MIDL_STUB_MESSAGE *pStubMsg, unsigned char *Pointer)
315 pStubMsg->pfnFree(Pointer);
318 static inline BOOL IsConformanceOrVariancePresent(PFORMAT_STRING pFormat)
320 return (*(const ULONG *)pFormat != -1);
323 PFORMAT_STRING ReadConformance(MIDL_STUB_MESSAGE *pStubMsg, PFORMAT_STRING pFormat)
325 ALIGN_POINTER(pStubMsg->Buffer, 4);
326 pStubMsg->MaxCount = NDR_LOCAL_UINT32_READ(pStubMsg->Buffer);
327 pStubMsg->Buffer += 4;
328 TRACE("unmarshalled conformance is %ld\n", pStubMsg->MaxCount);
329 if (pStubMsg->fHasNewCorrDesc)
335 static inline PFORMAT_STRING ReadVariance(MIDL_STUB_MESSAGE *pStubMsg, PFORMAT_STRING pFormat)
337 if (pFormat && !IsConformanceOrVariancePresent(pFormat))
339 pStubMsg->Offset = 0;
340 pStubMsg->ActualCount = pStubMsg->MaxCount;
344 ALIGN_POINTER(pStubMsg->Buffer, 4);
345 pStubMsg->Offset = NDR_LOCAL_UINT32_READ(pStubMsg->Buffer);
346 pStubMsg->Buffer += 4;
347 TRACE("offset is %ld\n", pStubMsg->Offset);
348 pStubMsg->ActualCount = NDR_LOCAL_UINT32_READ(pStubMsg->Buffer);
349 pStubMsg->Buffer += 4;
350 TRACE("variance is %ld\n", pStubMsg->ActualCount);
353 if (pStubMsg->fHasNewCorrDesc)
359 /* writes the conformance value to the buffer */
360 static inline void WriteConformance(MIDL_STUB_MESSAGE *pStubMsg)
362 ALIGN_POINTER(pStubMsg->Buffer, 4);
363 NDR_LOCAL_UINT32_WRITE(pStubMsg->Buffer, pStubMsg->MaxCount);
364 pStubMsg->Buffer += 4;
367 /* writes the variance values to the buffer */
368 static inline void WriteVariance(MIDL_STUB_MESSAGE *pStubMsg)
370 ALIGN_POINTER(pStubMsg->Buffer, 4);
371 NDR_LOCAL_UINT32_WRITE(pStubMsg->Buffer, pStubMsg->Offset);
372 pStubMsg->Buffer += 4;
373 NDR_LOCAL_UINT32_WRITE(pStubMsg->Buffer, pStubMsg->ActualCount);
374 pStubMsg->Buffer += 4;
377 /* requests buffer space for the conformance value */
378 static inline void SizeConformance(MIDL_STUB_MESSAGE *pStubMsg)
380 ALIGN_LENGTH(pStubMsg->BufferLength, 4);
381 pStubMsg->BufferLength += 4;
384 /* requests buffer space for the variance values */
385 static inline void SizeVariance(MIDL_STUB_MESSAGE *pStubMsg)
387 ALIGN_LENGTH(pStubMsg->BufferLength, 4);
388 pStubMsg->BufferLength += 8;
391 PFORMAT_STRING ComputeConformanceOrVariance(
392 MIDL_STUB_MESSAGE *pStubMsg, unsigned char *pMemory,
393 PFORMAT_STRING pFormat, ULONG_PTR def, ULONG *pCount)
395 BYTE dtype = pFormat[0] & 0xf;
396 short ofs = *(short *)&pFormat[2];
400 if (!IsConformanceOrVariancePresent(pFormat)) {
401 /* null descriptor */
406 switch (pFormat[0] & 0xf0) {
407 case RPC_FC_NORMAL_CONFORMANCE:
408 TRACE("normal conformance, ofs=%d\n", ofs);
411 case RPC_FC_POINTER_CONFORMANCE:
412 TRACE("pointer conformance, ofs=%d\n", ofs);
413 ptr = pStubMsg->Memory;
415 case RPC_FC_TOP_LEVEL_CONFORMANCE:
416 TRACE("toplevel conformance, ofs=%d\n", ofs);
417 if (pStubMsg->StackTop) {
418 ptr = pStubMsg->StackTop;
421 /* -Os mode, *pCount is already set */
425 case RPC_FC_CONSTANT_CONFORMANCE:
426 data = ofs | ((DWORD)pFormat[1] << 16);
427 TRACE("constant conformance, val=%ld\n", data);
430 case RPC_FC_TOP_LEVEL_MULTID_CONFORMANCE:
431 FIXME("toplevel multidimensional conformance, ofs=%d\n", ofs);
432 if (pStubMsg->StackTop) {
433 ptr = pStubMsg->StackTop;
441 FIXME("unknown conformance type %x\n", pFormat[0] & 0xf0);
444 switch (pFormat[1]) {
445 case RPC_FC_DEREFERENCE:
446 ptr = *(LPVOID*)((char *)ptr + ofs);
448 case RPC_FC_CALLBACK:
450 unsigned char *old_stack_top = pStubMsg->StackTop;
451 pStubMsg->StackTop = ptr;
453 /* ofs is index into StubDesc->apfnExprEval */
454 TRACE("callback conformance into apfnExprEval[%d]\n", ofs);
455 pStubMsg->StubDesc->apfnExprEval[ofs](pStubMsg);
457 pStubMsg->StackTop = old_stack_top;
461 ptr = (char *)ptr + ofs;
474 data = *(USHORT*)ptr;
485 FIXME("unknown conformance data type %x\n", dtype);
488 TRACE("dereferenced data type %x at %p, got %ld\n", dtype, ptr, data);
491 switch (pFormat[1]) {
495 case RPC_FC_DEREFERENCE:
496 /* already handled */
511 FIXME("unknown conformance op %d\n", pFormat[1]);
516 TRACE("resulting conformance is %ld\n", *pCount);
517 if (pStubMsg->fHasNewCorrDesc)
525 * NdrConformantString:
527 * What MS calls a ConformantString is, in DCE terminology,
528 * a Varying-Conformant String.
530 * maxlen: DWORD (max # of CHARTYPE characters, inclusive of '\0')
531 * offset: DWORD (actual string data begins at (offset) CHARTYPE's
532 * into unmarshalled string)
533 * length: DWORD (# of CHARTYPE characters, inclusive of '\0')
535 * data: CHARTYPE[maxlen]
537 * ], where CHARTYPE is the appropriate character type (specified externally)
541 /***********************************************************************
542 * NdrConformantStringMarshall [RPCRT4.@]
544 unsigned char *WINAPI NdrConformantStringMarshall(MIDL_STUB_MESSAGE *pStubMsg,
545 unsigned char *pszMessage, PFORMAT_STRING pFormat)
549 TRACE("(pStubMsg == ^%p, pszMessage == ^%p, pFormat == ^%p)\n", pStubMsg, pszMessage, pFormat);
551 if (*pFormat == RPC_FC_C_CSTRING) {
552 TRACE("string=%s\n", debugstr_a((char*)pszMessage));
553 pStubMsg->ActualCount = strlen((char*)pszMessage)+1;
556 else if (*pFormat == RPC_FC_C_WSTRING) {
557 TRACE("string=%s\n", debugstr_w((LPWSTR)pszMessage));
558 pStubMsg->ActualCount = strlenW((LPWSTR)pszMessage)+1;
562 ERR("Unhandled string type: %#x\n", *pFormat);
563 /* FIXME: raise an exception. */
567 if (pFormat[1] == RPC_FC_STRING_SIZED)
568 pFormat = ComputeConformance(pStubMsg, pszMessage, pFormat + 2, 0);
570 pStubMsg->MaxCount = pStubMsg->ActualCount;
571 pStubMsg->Offset = 0;
572 WriteConformance(pStubMsg);
573 WriteVariance(pStubMsg);
575 memcpy(pStubMsg->Buffer, pszMessage, pStubMsg->ActualCount*esize); /* the string itself */
576 pStubMsg->Buffer += pStubMsg->ActualCount*esize;
578 STD_OVERFLOW_CHECK(pStubMsg);
581 return NULL; /* is this always right? */
584 /***********************************************************************
585 * NdrConformantStringBufferSize [RPCRT4.@]
587 void WINAPI NdrConformantStringBufferSize(PMIDL_STUB_MESSAGE pStubMsg,
588 unsigned char* pMemory, PFORMAT_STRING pFormat)
590 TRACE("(pStubMsg == ^%p, pMemory == ^%p, pFormat == ^%p)\n", pStubMsg, pMemory, pFormat);
592 SizeConformance(pStubMsg);
593 SizeVariance(pStubMsg);
595 if (*pFormat == RPC_FC_C_CSTRING) {
596 /* we need + 1 octet for '\0' */
597 TRACE("string=%s\n", debugstr_a((char*)pMemory));
598 pStubMsg->BufferLength += strlen((char*)pMemory) + 1;
600 else if (*pFormat == RPC_FC_C_WSTRING) {
601 /* we need + 2 octets for L'\0' */
602 TRACE("string=%s\n", debugstr_w((LPWSTR)pMemory));
603 pStubMsg->BufferLength += strlenW((LPWSTR)pMemory)*2 + 2;
606 ERR("Unhandled string type: %#x\n", *pFormat);
607 /* FIXME: raise an exception */
611 /************************************************************************
612 * NdrConformantStringMemorySize [RPCRT4.@]
614 unsigned long WINAPI NdrConformantStringMemorySize( PMIDL_STUB_MESSAGE pStubMsg,
615 PFORMAT_STRING pFormat )
617 unsigned long rslt = 0;
619 TRACE("(pStubMsg == ^%p, pFormat == ^%p)\n", pStubMsg, pFormat);
621 assert(pStubMsg && pFormat);
623 if (*pFormat == RPC_FC_C_CSTRING) {
624 rslt = NDR_LOCAL_UINT32_READ(pStubMsg->Buffer); /* maxlen */
626 else if (*pFormat == RPC_FC_C_WSTRING) {
627 rslt = NDR_LOCAL_UINT32_READ(pStubMsg->Buffer)*2; /* maxlen */
630 ERR("Unhandled string type: %#x\n", *pFormat);
631 /* FIXME: raise an exception */
634 if (pFormat[1] != RPC_FC_PAD) {
635 FIXME("sized string format=%d\n", pFormat[1]);
638 TRACE(" --> %lu\n", rslt);
642 /************************************************************************
643 * NdrConformantStringUnmarshall [RPCRT4.@]
645 unsigned char *WINAPI NdrConformantStringUnmarshall( PMIDL_STUB_MESSAGE pStubMsg,
646 unsigned char** ppMemory, PFORMAT_STRING pFormat, unsigned char fMustAlloc )
648 unsigned long len, esize;
650 TRACE("(pStubMsg == ^%p, *pMemory == ^%p, pFormat == ^%p, fMustAlloc == %u)\n",
651 pStubMsg, *ppMemory, pFormat, fMustAlloc);
653 assert(pFormat && ppMemory && pStubMsg);
655 ReadConformance(pStubMsg, NULL);
656 ReadVariance(pStubMsg, NULL);
658 if (*pFormat == RPC_FC_C_CSTRING) esize = 1;
659 else if (*pFormat == RPC_FC_C_WSTRING) esize = 2;
661 ERR("Unhandled string type: %#x\n", *pFormat);
662 /* FIXME: raise an exception */
666 len = pStubMsg->ActualCount;
668 if (fMustAlloc || !*ppMemory)
669 *ppMemory = NdrAllocate(pStubMsg, len*esize);
671 memcpy(*ppMemory, pStubMsg->Buffer, len*esize);
673 pStubMsg->Buffer += len*esize;
675 if (*pFormat == RPC_FC_C_CSTRING) {
676 TRACE("string=%s\n", debugstr_a((char*)*ppMemory));
678 else if (*pFormat == RPC_FC_C_WSTRING) {
679 TRACE("string=%s\n", debugstr_w((LPWSTR)*ppMemory));
682 return NULL; /* FIXME: is this always right? */
685 /***********************************************************************
686 * NdrNonConformantStringMarshall [RPCRT4.@]
688 unsigned char * WINAPI NdrNonConformantStringMarshall(PMIDL_STUB_MESSAGE pStubMsg,
689 unsigned char *pMemory,
690 PFORMAT_STRING pFormat)
696 /***********************************************************************
697 * NdrNonConformantStringUnmarshall [RPCRT4.@]
699 unsigned char * WINAPI NdrNonConformantStringUnmarshall(PMIDL_STUB_MESSAGE pStubMsg,
700 unsigned char **ppMemory,
701 PFORMAT_STRING pFormat,
702 unsigned char fMustAlloc)
708 /***********************************************************************
709 * NdrNonConformantStringBufferSize [RPCRT4.@]
711 void WINAPI NdrNonConformantStringBufferSize(PMIDL_STUB_MESSAGE pStubMsg,
712 unsigned char *pMemory,
713 PFORMAT_STRING pFormat)
718 /***********************************************************************
719 * NdrNonConformantStringMemorySize [RPCRT4.@]
721 unsigned long WINAPI NdrNonConformantStringMemorySize(PMIDL_STUB_MESSAGE pStubMsg,
722 PFORMAT_STRING pFormat)
728 static inline void dump_pointer_attr(unsigned char attr)
730 if (attr & RPC_FC_P_ALLOCALLNODES)
731 TRACE(" RPC_FC_P_ALLOCALLNODES");
732 if (attr & RPC_FC_P_DONTFREE)
733 TRACE(" RPC_FC_P_DONTFREE");
734 if (attr & RPC_FC_P_ONSTACK)
735 TRACE(" RPC_FC_P_ONSTACK");
736 if (attr & RPC_FC_P_SIMPLEPOINTER)
737 TRACE(" RPC_FC_P_SIMPLEPOINTER");
738 if (attr & RPC_FC_P_DEREF)
739 TRACE(" RPC_FC_P_DEREF");
743 /***********************************************************************
746 static void PointerMarshall(PMIDL_STUB_MESSAGE pStubMsg,
747 unsigned char *Buffer,
748 unsigned char *Pointer,
749 PFORMAT_STRING pFormat)
751 unsigned type = pFormat[0], attr = pFormat[1];
755 TRACE("(%p,%p,%p,%p)\n", pStubMsg, Buffer, Pointer, pFormat);
756 TRACE("type=0x%x, attr=", type); dump_pointer_attr(attr);
758 if (attr & RPC_FC_P_SIMPLEPOINTER) desc = pFormat;
759 else desc = pFormat + *(const SHORT*)pFormat;
762 case RPC_FC_RP: /* ref pointer (always non-null) */
763 #if 0 /* this causes problems for InstallShield so is disabled - we need more tests */
765 RpcRaiseException(RPC_X_NULL_REF_POINTER);
768 case RPC_FC_UP: /* unique pointer */
769 case RPC_FC_OP: /* object pointer - same as unique here */
770 TRACE("writing %p to buffer\n", Pointer);
771 NDR_LOCAL_UINT32_WRITE(Buffer, (unsigned long)Pointer);
775 FIXME("unhandled ptr type=%02x\n", type);
776 RpcRaiseException(RPC_X_BAD_STUB_DATA);
779 TRACE("calling marshaller for type 0x%x\n", (int)*desc);
782 if (attr & RPC_FC_P_DEREF) {
783 Pointer = *(unsigned char**)Pointer;
784 TRACE("deref => %p\n", Pointer);
786 m = NdrMarshaller[*desc & NDR_TABLE_MASK];
787 if (m) m(pStubMsg, Pointer, desc);
788 else FIXME("no marshaller for data type=%02x\n", *desc);
791 STD_OVERFLOW_CHECK(pStubMsg);
794 /***********************************************************************
797 static void PointerUnmarshall(PMIDL_STUB_MESSAGE pStubMsg,
798 unsigned char *Buffer,
799 unsigned char **pPointer,
800 PFORMAT_STRING pFormat,
801 unsigned char fMustAlloc)
803 unsigned type = pFormat[0], attr = pFormat[1];
806 DWORD pointer_id = 0;
808 TRACE("(%p,%p,%p,%p,%d)\n", pStubMsg, Buffer, pPointer, pFormat, fMustAlloc);
809 TRACE("type=0x%x, attr=", type); dump_pointer_attr(attr);
811 if (attr & RPC_FC_P_SIMPLEPOINTER) desc = pFormat;
812 else desc = pFormat + *(const SHORT*)pFormat;
815 case RPC_FC_RP: /* ref pointer (always non-null) */
818 case RPC_FC_UP: /* unique pointer */
819 pointer_id = NDR_LOCAL_UINT32_READ(Buffer);
820 TRACE("pointer_id is 0x%08lx\n", pointer_id);
822 case RPC_FC_OP: /* object pointer - we must free data before overwriting it */
823 pointer_id = NDR_LOCAL_UINT32_READ(Buffer);
824 TRACE("pointer_id is 0x%08lx\n", pointer_id);
826 FIXME("free object pointer %p\n", *pPointer);
830 FIXME("unhandled ptr type=%02x\n", type);
831 RpcRaiseException(RPC_X_BAD_STUB_DATA);
835 if (attr & RPC_FC_P_DEREF) {
836 if (!*pPointer || fMustAlloc)
837 *pPointer = NdrAllocate(pStubMsg, sizeof(void *));
838 pPointer = *(unsigned char***)pPointer;
839 TRACE("deref => %p\n", pPointer);
841 m = NdrUnmarshaller[*desc & NDR_TABLE_MASK];
842 if (m) m(pStubMsg, pPointer, desc, fMustAlloc);
843 else FIXME("no unmarshaller for data type=%02x\n", *desc);
846 TRACE("pointer=%p\n", *pPointer);
849 /***********************************************************************
852 static void PointerBufferSize(PMIDL_STUB_MESSAGE pStubMsg,
853 unsigned char *Pointer,
854 PFORMAT_STRING pFormat)
856 unsigned type = pFormat[0], attr = pFormat[1];
860 TRACE("(%p,%p,%p)\n", pStubMsg, Pointer, pFormat);
861 TRACE("type=0x%x, attr=", type); dump_pointer_attr(attr);
863 if (attr & RPC_FC_P_SIMPLEPOINTER) desc = pFormat;
864 else desc = pFormat + *(const SHORT*)pFormat;
867 case RPC_FC_RP: /* ref pointer (always non-null) */
871 /* NULL pointer has no further representation */
877 FIXME("unhandled ptr type=%02x\n", type);
878 RpcRaiseException(RPC_X_BAD_STUB_DATA);
881 if (attr & RPC_FC_P_DEREF) {
882 Pointer = *(unsigned char**)Pointer;
883 TRACE("deref => %p\n", Pointer);
886 m = NdrBufferSizer[*desc & NDR_TABLE_MASK];
887 if (m) m(pStubMsg, Pointer, desc);
888 else FIXME("no buffersizer for data type=%02x\n", *desc);
891 /***********************************************************************
892 * PointerMemorySize [RPCRT4.@]
894 static unsigned long PointerMemorySize(PMIDL_STUB_MESSAGE pStubMsg,
895 unsigned char *Buffer,
896 PFORMAT_STRING pFormat)
898 unsigned type = pFormat[0], attr = pFormat[1];
902 FIXME("(%p,%p,%p): stub\n", pStubMsg, Buffer, pFormat);
903 TRACE("type=0x%x, attr=", type); dump_pointer_attr(attr);
905 if (attr & RPC_FC_P_SIMPLEPOINTER) desc = pFormat;
906 else desc = pFormat + *(const SHORT*)pFormat;
909 case RPC_FC_RP: /* ref pointer (always non-null) */
912 FIXME("unhandled ptr type=%02x\n", type);
913 RpcRaiseException(RPC_X_BAD_STUB_DATA);
916 if (attr & RPC_FC_P_DEREF) {
920 m = NdrMemorySizer[*desc & NDR_TABLE_MASK];
921 if (m) m(pStubMsg, desc);
922 else FIXME("no memorysizer for data type=%02x\n", *desc);
927 /***********************************************************************
928 * PointerFree [RPCRT4.@]
930 static void PointerFree(PMIDL_STUB_MESSAGE pStubMsg,
931 unsigned char *Pointer,
932 PFORMAT_STRING pFormat)
934 unsigned type = pFormat[0], attr = pFormat[1];
938 TRACE("(%p,%p,%p)\n", pStubMsg, Pointer, pFormat);
939 TRACE("type=0x%x, attr=", type); dump_pointer_attr(attr);
940 if (attr & RPC_FC_P_DONTFREE) return;
942 if (attr & RPC_FC_P_SIMPLEPOINTER) desc = pFormat;
943 else desc = pFormat + *(const SHORT*)pFormat;
945 if (!Pointer) return;
947 if (attr & RPC_FC_P_DEREF) {
948 Pointer = *(unsigned char**)Pointer;
949 TRACE("deref => %p\n", Pointer);
952 m = NdrFreer[*desc & NDR_TABLE_MASK];
953 if (m) m(pStubMsg, Pointer, desc);
955 /* hmm... is this sensible?
956 * perhaps we should check if the memory comes from NdrAllocate,
957 * and deallocate only if so - checking if the pointer is between
958 * BufferStart and BufferEnd is probably no good since the buffer
959 * may be reallocated when the server wants to marshal the reply */
961 case RPC_FC_BOGUS_STRUCT:
962 case RPC_FC_BOGUS_ARRAY:
963 case RPC_FC_USER_MARSHAL:
968 FIXME("unhandled data type=%02x\n", *desc);
970 case RPC_FC_C_CSTRING:
971 case RPC_FC_C_WSTRING:
972 if (pStubMsg->ReuseBuffer) goto notfree;
978 if (attr & RPC_FC_P_ONSTACK) {
979 TRACE("not freeing stack ptr %p\n", Pointer);
982 TRACE("freeing %p\n", Pointer);
983 NdrFree(pStubMsg, Pointer);
986 TRACE("not freeing %p\n", Pointer);
989 /***********************************************************************
990 * EmbeddedPointerMarshall
992 static unsigned char * EmbeddedPointerMarshall(PMIDL_STUB_MESSAGE pStubMsg,
993 unsigned char *pMemory,
994 PFORMAT_STRING pFormat)
996 unsigned char *Mark = pStubMsg->BufferMark;
997 unsigned long Offset = pStubMsg->Offset;
998 unsigned ofs, rep, count, stride, xofs;
1001 TRACE("(%p,%p,%p)\n", pStubMsg, pMemory, pFormat);
1003 if (*pFormat != RPC_FC_PP) return NULL;
1006 while (pFormat[0] != RPC_FC_END) {
1007 switch (pFormat[0]) {
1009 FIXME("unknown repeat type %d\n", pFormat[0]);
1010 case RPC_FC_NO_REPEAT:
1018 case RPC_FC_FIXED_REPEAT:
1019 rep = *(const WORD*)&pFormat[2];
1020 stride = *(const WORD*)&pFormat[4];
1021 ofs = *(const WORD*)&pFormat[6];
1022 count = *(const WORD*)&pFormat[8];
1026 case RPC_FC_VARIABLE_REPEAT:
1027 rep = pStubMsg->MaxCount;
1028 stride = *(const WORD*)&pFormat[2];
1029 ofs = *(const WORD*)&pFormat[4];
1030 count = *(const WORD*)&pFormat[6];
1031 xofs = (pFormat[1] == RPC_FC_VARIABLE_OFFSET) ? Offset * stride : 0;
1035 for (i = 0; i < rep; i++) {
1036 PFORMAT_STRING info = pFormat;
1037 unsigned char *membase = pMemory + (i * stride);
1038 unsigned char *bufbase = Mark + (i * stride);
1040 /* ofs doesn't seem to matter in this context */
1041 for (u=0; u<count; u++,info+=8) {
1042 unsigned char *memptr = membase + *(const SHORT*)&info[0];
1043 unsigned char *bufptr = bufbase + *(const SHORT*)&info[2];
1044 PointerMarshall(pStubMsg, bufptr, *(unsigned char**)memptr, info+4);
1047 pFormat += 8 * count;
1050 STD_OVERFLOW_CHECK(pStubMsg);
1055 /***********************************************************************
1056 * EmbeddedPointerUnmarshall
1058 static unsigned char * EmbeddedPointerUnmarshall(PMIDL_STUB_MESSAGE pStubMsg,
1059 unsigned char **ppMemory,
1060 PFORMAT_STRING pFormat,
1061 unsigned char fMustAlloc)
1063 unsigned char *Mark = pStubMsg->BufferMark;
1064 unsigned long Offset = pStubMsg->Offset;
1065 unsigned ofs, rep, count, stride, xofs;
1068 TRACE("(%p,%p,%p,%d)\n", pStubMsg, ppMemory, pFormat, fMustAlloc);
1070 if (*pFormat != RPC_FC_PP) return NULL;
1073 while (pFormat[0] != RPC_FC_END) {
1074 TRACE("pFormat[0] = 0x%x\n", pFormat[0]);
1075 switch (pFormat[0]) {
1077 FIXME("unknown repeat type %d\n", pFormat[0]);
1078 case RPC_FC_NO_REPEAT:
1086 case RPC_FC_FIXED_REPEAT:
1087 rep = *(const WORD*)&pFormat[2];
1088 stride = *(const WORD*)&pFormat[4];
1089 ofs = *(const WORD*)&pFormat[6];
1090 count = *(const WORD*)&pFormat[8];
1094 case RPC_FC_VARIABLE_REPEAT:
1095 rep = pStubMsg->MaxCount;
1096 stride = *(const WORD*)&pFormat[2];
1097 ofs = *(const WORD*)&pFormat[4];
1098 count = *(const WORD*)&pFormat[6];
1099 xofs = (pFormat[1] == RPC_FC_VARIABLE_OFFSET) ? Offset * stride : 0;
1103 /* ofs doesn't seem to matter in this context */
1104 for (i = 0; i < rep; i++) {
1105 PFORMAT_STRING info = pFormat;
1106 unsigned char *membase = *ppMemory + (i * stride);
1107 unsigned char *bufbase = Mark + (i * stride);
1109 for (u=0; u<count; u++,info+=8) {
1110 unsigned char *memptr = membase + *(const SHORT*)&info[0];
1111 unsigned char *bufptr = bufbase + *(const SHORT*)&info[2];
1112 *(void **)memptr = NULL;
1113 PointerUnmarshall(pStubMsg, bufptr, (unsigned char**)memptr, info+4, fMustAlloc);
1116 pFormat += 8 * count;
1122 /***********************************************************************
1123 * EmbeddedPointerBufferSize
1125 static void EmbeddedPointerBufferSize(PMIDL_STUB_MESSAGE pStubMsg,
1126 unsigned char *pMemory,
1127 PFORMAT_STRING pFormat)
1129 unsigned long Offset = pStubMsg->Offset;
1130 unsigned ofs, rep, count, stride, xofs;
1133 TRACE("(%p,%p,%p)\n", pStubMsg, pMemory, pFormat);
1135 if (pStubMsg->IgnoreEmbeddedPointers) return;
1137 if (*pFormat != RPC_FC_PP) return;
1140 while (pFormat[0] != RPC_FC_END) {
1141 switch (pFormat[0]) {
1143 FIXME("unknown repeat type %d\n", pFormat[0]);
1144 case RPC_FC_NO_REPEAT:
1152 case RPC_FC_FIXED_REPEAT:
1153 rep = *(const WORD*)&pFormat[2];
1154 stride = *(const WORD*)&pFormat[4];
1155 ofs = *(const WORD*)&pFormat[6];
1156 count = *(const WORD*)&pFormat[8];
1160 case RPC_FC_VARIABLE_REPEAT:
1161 rep = pStubMsg->MaxCount;
1162 stride = *(const WORD*)&pFormat[2];
1163 ofs = *(const WORD*)&pFormat[4];
1164 count = *(const WORD*)&pFormat[6];
1165 xofs = (pFormat[1] == RPC_FC_VARIABLE_OFFSET) ? Offset * stride : 0;
1169 /* ofs doesn't seem to matter in this context */
1170 for (i = 0; i < rep; i++) {
1171 PFORMAT_STRING info = pFormat;
1172 unsigned char *membase = pMemory + (i * stride);
1174 for (u=0; u<count; u++,info+=8) {
1175 unsigned char *memptr = membase + *(const SHORT*)&info[0];
1176 PointerBufferSize(pStubMsg, *(unsigned char**)memptr, info+4);
1179 pFormat += 8 * count;
1183 /***********************************************************************
1184 * EmbeddedPointerMemorySize
1186 static unsigned long EmbeddedPointerMemorySize(PMIDL_STUB_MESSAGE pStubMsg,
1187 PFORMAT_STRING pFormat)
1189 unsigned long Offset = pStubMsg->Offset;
1190 unsigned char *Mark = pStubMsg->BufferMark;
1191 unsigned ofs, rep, count, stride, xofs;
1194 FIXME("(%p,%p): stub\n", pStubMsg, pFormat);
1196 if (*pFormat != RPC_FC_PP) return 0;
1199 while (pFormat[0] != RPC_FC_END) {
1200 switch (pFormat[0]) {
1202 FIXME("unknown repeat type %d\n", pFormat[0]);
1203 case RPC_FC_NO_REPEAT:
1211 case RPC_FC_FIXED_REPEAT:
1212 rep = *(const WORD*)&pFormat[2];
1213 stride = *(const WORD*)&pFormat[4];
1214 ofs = *(const WORD*)&pFormat[6];
1215 count = *(const WORD*)&pFormat[8];
1219 case RPC_FC_VARIABLE_REPEAT:
1220 rep = pStubMsg->MaxCount;
1221 stride = *(const WORD*)&pFormat[2];
1222 ofs = *(const WORD*)&pFormat[4];
1223 count = *(const WORD*)&pFormat[6];
1224 xofs = (pFormat[1] == RPC_FC_VARIABLE_OFFSET) ? Offset * stride : 0;
1228 /* ofs doesn't seem to matter in this context */
1229 for (i = 0; i < rep; i++) {
1230 PFORMAT_STRING info = pFormat;
1231 unsigned char *bufbase = Mark + (i * stride);
1233 for (u=0; u<count; u++,info+=8) {
1234 unsigned char *bufptr = bufbase + *(const SHORT*)&info[2];
1235 PointerMemorySize(pStubMsg, bufptr, info+4);
1238 pFormat += 8 * count;
1244 /***********************************************************************
1245 * EmbeddedPointerFree
1247 static void EmbeddedPointerFree(PMIDL_STUB_MESSAGE pStubMsg,
1248 unsigned char *pMemory,
1249 PFORMAT_STRING pFormat)
1251 unsigned long Offset = pStubMsg->Offset;
1252 unsigned ofs, rep, count, stride, xofs;
1255 TRACE("(%p,%p,%p)\n", pStubMsg, pMemory, pFormat);
1256 if (*pFormat != RPC_FC_PP) return;
1259 while (pFormat[0] != RPC_FC_END) {
1260 switch (pFormat[0]) {
1262 FIXME("unknown repeat type %d\n", pFormat[0]);
1263 case RPC_FC_NO_REPEAT:
1271 case RPC_FC_FIXED_REPEAT:
1272 rep = *(const WORD*)&pFormat[2];
1273 stride = *(const WORD*)&pFormat[4];
1274 ofs = *(const WORD*)&pFormat[6];
1275 count = *(const WORD*)&pFormat[8];
1279 case RPC_FC_VARIABLE_REPEAT:
1280 rep = pStubMsg->MaxCount;
1281 stride = *(const WORD*)&pFormat[2];
1282 ofs = *(const WORD*)&pFormat[4];
1283 count = *(const WORD*)&pFormat[6];
1284 xofs = (pFormat[1] == RPC_FC_VARIABLE_OFFSET) ? Offset * stride : 0;
1288 /* ofs doesn't seem to matter in this context */
1289 for (i = 0; i < rep; i++) {
1290 PFORMAT_STRING info = pFormat;
1291 unsigned char *membase = pMemory + (i * stride);
1293 for (u=0; u<count; u++,info+=8) {
1294 unsigned char *memptr = membase + *(const SHORT*)&info[0];
1295 PointerFree(pStubMsg, *(unsigned char**)memptr, info+4);
1298 pFormat += 8 * count;
1302 /***********************************************************************
1303 * NdrPointerMarshall [RPCRT4.@]
1305 unsigned char * WINAPI NdrPointerMarshall(PMIDL_STUB_MESSAGE pStubMsg,
1306 unsigned char *pMemory,
1307 PFORMAT_STRING pFormat)
1309 unsigned char *Buffer;
1311 TRACE("(%p,%p,%p)\n", pStubMsg, pMemory, pFormat);
1313 /* incremement the buffer here instead of in PointerMarshall,
1314 * as that is used by embedded pointers which already handle the incrementing
1315 * the buffer, and shouldn't write any additional pointer data to the wire */
1316 if (*pFormat != RPC_FC_RP)
1318 ALIGN_POINTER(pStubMsg->Buffer, 4);
1319 Buffer = pStubMsg->Buffer;
1320 pStubMsg->Buffer += 4;
1323 Buffer = pStubMsg->Buffer;
1325 PointerMarshall(pStubMsg, Buffer, pMemory, pFormat);
1327 STD_OVERFLOW_CHECK(pStubMsg);
1332 /***********************************************************************
1333 * NdrPointerUnmarshall [RPCRT4.@]
1335 unsigned char * WINAPI NdrPointerUnmarshall(PMIDL_STUB_MESSAGE pStubMsg,
1336 unsigned char **ppMemory,
1337 PFORMAT_STRING pFormat,
1338 unsigned char fMustAlloc)
1340 unsigned char *Buffer;
1342 TRACE("(%p,%p,%p,%d)\n", pStubMsg, ppMemory, pFormat, fMustAlloc);
1344 /* incremement the buffer here instead of in PointerUnmarshall,
1345 * as that is used by embedded pointers which already handle the incrementing
1346 * the buffer, and shouldn't read any additional pointer data from the
1348 if (*pFormat != RPC_FC_RP)
1350 ALIGN_POINTER(pStubMsg->Buffer, 4);
1351 Buffer = pStubMsg->Buffer;
1352 pStubMsg->Buffer += 4;
1355 Buffer = pStubMsg->Buffer;
1357 PointerUnmarshall(pStubMsg, Buffer, ppMemory, pFormat, fMustAlloc);
1362 /***********************************************************************
1363 * NdrPointerBufferSize [RPCRT4.@]
1365 void WINAPI NdrPointerBufferSize(PMIDL_STUB_MESSAGE pStubMsg,
1366 unsigned char *pMemory,
1367 PFORMAT_STRING pFormat)
1369 TRACE("(%p,%p,%p)\n", pStubMsg, pMemory, pFormat);
1371 /* incremement the buffer length here instead of in PointerBufferSize,
1372 * as that is used by embedded pointers which already handle the buffer
1373 * length, and shouldn't write anything more to the wire */
1374 if (*pFormat != RPC_FC_RP)
1376 ALIGN_LENGTH(pStubMsg->BufferLength, 4);
1377 pStubMsg->BufferLength += 4;
1380 PointerBufferSize(pStubMsg, pMemory, pFormat);
1383 /***********************************************************************
1384 * NdrPointerMemorySize [RPCRT4.@]
1386 unsigned long WINAPI NdrPointerMemorySize(PMIDL_STUB_MESSAGE pStubMsg,
1387 PFORMAT_STRING pFormat)
1389 /* unsigned size = *(LPWORD)(pFormat+2); */
1390 FIXME("(%p,%p): stub\n", pStubMsg, pFormat);
1391 PointerMemorySize(pStubMsg, pStubMsg->Buffer, pFormat);
1395 /***********************************************************************
1396 * NdrPointerFree [RPCRT4.@]
1398 void WINAPI NdrPointerFree(PMIDL_STUB_MESSAGE pStubMsg,
1399 unsigned char *pMemory,
1400 PFORMAT_STRING pFormat)
1402 TRACE("(%p,%p,%p)\n", pStubMsg, pMemory, pFormat);
1403 PointerFree(pStubMsg, pMemory, pFormat);
1406 /***********************************************************************
1407 * NdrSimpleStructMarshall [RPCRT4.@]
1409 unsigned char * WINAPI NdrSimpleStructMarshall(PMIDL_STUB_MESSAGE pStubMsg,
1410 unsigned char *pMemory,
1411 PFORMAT_STRING pFormat)
1413 unsigned size = *(const WORD*)(pFormat+2);
1414 TRACE("(%p,%p,%p)\n", pStubMsg, pMemory, pFormat);
1416 ALIGN_POINTER(pStubMsg->Buffer, pFormat[1] + 1);
1418 memcpy(pStubMsg->Buffer, pMemory, size);
1419 pStubMsg->BufferMark = pStubMsg->Buffer;
1420 pStubMsg->Buffer += size;
1422 if (pFormat[0] != RPC_FC_STRUCT)
1423 EmbeddedPointerMarshall(pStubMsg, pMemory, pFormat+4);
1425 STD_OVERFLOW_CHECK(pStubMsg);
1430 /***********************************************************************
1431 * NdrSimpleStructUnmarshall [RPCRT4.@]
1433 unsigned char * WINAPI NdrSimpleStructUnmarshall(PMIDL_STUB_MESSAGE pStubMsg,
1434 unsigned char **ppMemory,
1435 PFORMAT_STRING pFormat,
1436 unsigned char fMustAlloc)
1438 unsigned size = *(const WORD*)(pFormat+2);
1439 TRACE("(%p,%p,%p,%d)\n", pStubMsg, ppMemory, pFormat, fMustAlloc);
1441 ALIGN_POINTER(pStubMsg->Buffer, pFormat[1] + 1);
1444 *ppMemory = NdrAllocate(pStubMsg, size);
1445 memcpy(*ppMemory, pStubMsg->Buffer, size);
1447 if (!pStubMsg->IsClient && !*ppMemory)
1448 /* for servers, we just point straight into the RPC buffer */
1449 *ppMemory = pStubMsg->Buffer;
1451 /* for clients, memory should be provided by caller */
1452 memcpy(*ppMemory, pStubMsg->Buffer, size);
1455 pStubMsg->BufferMark = pStubMsg->Buffer;
1456 pStubMsg->Buffer += size;
1458 if (pFormat[0] != RPC_FC_STRUCT)
1459 EmbeddedPointerUnmarshall(pStubMsg, ppMemory, pFormat+4, fMustAlloc);
1465 /***********************************************************************
1466 * NdrSimpleStructUnmarshall [RPCRT4.@]
1468 void WINAPI NdrSimpleTypeMarshall( PMIDL_STUB_MESSAGE pStubMsg, unsigned char* pMemory,
1469 unsigned char FormatChar )
1475 /***********************************************************************
1476 * NdrSimpleStructUnmarshall [RPCRT4.@]
1478 void WINAPI NdrSimpleTypeUnmarshall( PMIDL_STUB_MESSAGE pStubMsg, unsigned char* pMemory,
1479 unsigned char FormatChar )
1485 /***********************************************************************
1486 * NdrSimpleStructBufferSize [RPCRT4.@]
1488 void WINAPI NdrSimpleStructBufferSize(PMIDL_STUB_MESSAGE pStubMsg,
1489 unsigned char *pMemory,
1490 PFORMAT_STRING pFormat)
1492 unsigned size = *(const WORD*)(pFormat+2);
1493 TRACE("(%p,%p,%p)\n", pStubMsg, pMemory, pFormat);
1495 ALIGN_LENGTH(pStubMsg->BufferLength, pFormat[1] + 1);
1497 pStubMsg->BufferLength += size;
1498 if (pFormat[0] != RPC_FC_STRUCT)
1499 EmbeddedPointerBufferSize(pStubMsg, pMemory, pFormat+4);
1502 /***********************************************************************
1503 * NdrSimpleStructMemorySize [RPCRT4.@]
1505 unsigned long WINAPI NdrSimpleStructMemorySize(PMIDL_STUB_MESSAGE pStubMsg,
1506 PFORMAT_STRING pFormat)
1508 unsigned short size = *(LPWORD)(pFormat+2);
1510 TRACE("(%p,%p)\n", pStubMsg, pFormat);
1512 ALIGN_POINTER(pStubMsg->Buffer, pFormat[1] + 1);
1513 pStubMsg->MemorySize += size;
1514 pStubMsg->Buffer += size;
1516 if (pFormat[0] != RPC_FC_STRUCT)
1517 EmbeddedPointerMemorySize(pStubMsg, pFormat+4);
1521 /***********************************************************************
1522 * NdrSimpleStructFree [RPCRT4.@]
1524 void WINAPI NdrSimpleStructFree(PMIDL_STUB_MESSAGE pStubMsg,
1525 unsigned char *pMemory,
1526 PFORMAT_STRING pFormat)
1528 TRACE("(%p,%p,%p)\n", pStubMsg, pMemory, pFormat);
1529 if (pFormat[0] != RPC_FC_STRUCT)
1530 EmbeddedPointerFree(pStubMsg, pMemory, pFormat+4);
1534 static unsigned long EmbeddedComplexSize(PMIDL_STUB_MESSAGE pStubMsg,
1535 PFORMAT_STRING pFormat)
1539 case RPC_FC_PSTRUCT:
1540 case RPC_FC_CSTRUCT:
1541 case RPC_FC_BOGUS_STRUCT:
1542 return *(const WORD*)&pFormat[2];
1543 case RPC_FC_USER_MARSHAL:
1544 return *(const WORD*)&pFormat[4];
1545 case RPC_FC_NON_ENCAPSULATED_UNION:
1547 if (pStubMsg->fHasNewCorrDesc)
1552 pFormat += *(const SHORT*)pFormat;
1553 return *(const SHORT*)pFormat;
1555 return sizeof(void *);
1557 FIXME("unhandled embedded type %02x\n", *pFormat);
1563 static unsigned long EmbeddedComplexMemorySize(PMIDL_STUB_MESSAGE pStubMsg,
1564 PFORMAT_STRING pFormat)
1566 NDR_MEMORYSIZE m = NdrMemorySizer[*pFormat & NDR_TABLE_MASK];
1570 FIXME("no memorysizer for data type=%02x\n", *pFormat);
1574 return m(pStubMsg, pFormat);
1578 static unsigned char * ComplexMarshall(PMIDL_STUB_MESSAGE pStubMsg,
1579 unsigned char *pMemory,
1580 PFORMAT_STRING pFormat,
1581 PFORMAT_STRING pPointer)
1583 PFORMAT_STRING desc;
1587 while (*pFormat != RPC_FC_END) {
1591 TRACE("short=%d <= %p\n", *(WORD*)pMemory, pMemory);
1592 memcpy(pStubMsg->Buffer, pMemory, 2);
1593 pStubMsg->Buffer += 2;
1599 TRACE("long=%ld <= %p\n", *(DWORD*)pMemory, pMemory);
1600 memcpy(pStubMsg->Buffer, pMemory, 4);
1601 pStubMsg->Buffer += 4;
1604 case RPC_FC_POINTER:
1605 TRACE("pointer=%p <= %p\n", *(unsigned char**)pMemory, pMemory);
1606 NdrPointerMarshall(pStubMsg, *(unsigned char**)pMemory, pPointer);
1610 case RPC_FC_ALIGNM4:
1611 ALIGN_POINTER(pMemory, 4);
1613 case RPC_FC_ALIGNM8:
1614 ALIGN_POINTER(pMemory, 8);
1616 case RPC_FC_STRUCTPAD2:
1619 case RPC_FC_EMBEDDED_COMPLEX:
1620 pMemory += pFormat[1];
1622 desc = pFormat + *(const SHORT*)pFormat;
1623 size = EmbeddedComplexSize(pStubMsg, desc);
1624 TRACE("embedded complex (size=%ld) <= %p\n", size, pMemory);
1625 m = NdrMarshaller[*desc & NDR_TABLE_MASK];
1626 if (m) m(pStubMsg, pMemory, desc);
1627 else FIXME("no marshaller for embedded type %02x\n", *desc);
1634 FIXME("unhandled format %02x\n", *pFormat);
1642 static unsigned char * ComplexUnmarshall(PMIDL_STUB_MESSAGE pStubMsg,
1643 unsigned char *pMemory,
1644 PFORMAT_STRING pFormat,
1645 PFORMAT_STRING pPointer,
1646 unsigned char fMustAlloc)
1648 PFORMAT_STRING desc;
1652 while (*pFormat != RPC_FC_END) {
1656 memcpy(pMemory, pStubMsg->Buffer, 2);
1657 TRACE("short=%d => %p\n", *(WORD*)pMemory, pMemory);
1658 pStubMsg->Buffer += 2;
1664 memcpy(pMemory, pStubMsg->Buffer, 4);
1665 TRACE("long=%ld => %p\n", *(DWORD*)pMemory, pMemory);
1666 pStubMsg->Buffer += 4;
1669 case RPC_FC_POINTER:
1670 *(unsigned char**)pMemory = NULL;
1671 TRACE("pointer => %p\n", pMemory);
1672 NdrPointerUnmarshall(pStubMsg, (unsigned char**)pMemory, pPointer, fMustAlloc);
1676 case RPC_FC_ALIGNM4:
1677 ALIGN_POINTER(pMemory, 4);
1679 case RPC_FC_ALIGNM8:
1680 ALIGN_POINTER(pMemory, 8);
1682 case RPC_FC_STRUCTPAD2:
1685 case RPC_FC_EMBEDDED_COMPLEX:
1686 pMemory += pFormat[1];
1688 desc = pFormat + *(const SHORT*)pFormat;
1689 size = EmbeddedComplexSize(pStubMsg, desc);
1690 TRACE("embedded complex (size=%ld) => %p\n", size, pMemory);
1691 m = NdrUnmarshaller[*desc & NDR_TABLE_MASK];
1692 memset(pMemory, 0, size); /* just in case */
1693 if (m) m(pStubMsg, &pMemory, desc, fMustAlloc);
1694 else FIXME("no unmarshaller for embedded type %02x\n", *desc);
1701 FIXME("unhandled format %d\n", *pFormat);
1709 static unsigned char * ComplexBufferSize(PMIDL_STUB_MESSAGE pStubMsg,
1710 unsigned char *pMemory,
1711 PFORMAT_STRING pFormat,
1712 PFORMAT_STRING pPointer)
1714 PFORMAT_STRING desc;
1718 while (*pFormat != RPC_FC_END) {
1722 pStubMsg->BufferLength += 2;
1728 pStubMsg->BufferLength += 4;
1731 case RPC_FC_POINTER:
1732 NdrPointerBufferSize(pStubMsg, *(unsigned char**)pMemory, pPointer);
1736 case RPC_FC_ALIGNM4:
1737 ALIGN_POINTER(pMemory, 4);
1739 case RPC_FC_ALIGNM8:
1740 ALIGN_POINTER(pMemory, 8);
1742 case RPC_FC_STRUCTPAD2:
1745 case RPC_FC_EMBEDDED_COMPLEX:
1746 pMemory += pFormat[1];
1748 desc = pFormat + *(const SHORT*)pFormat;
1749 size = EmbeddedComplexSize(pStubMsg, desc);
1750 m = NdrBufferSizer[*desc & NDR_TABLE_MASK];
1751 if (m) m(pStubMsg, pMemory, desc);
1752 else FIXME("no buffersizer for embedded type %02x\n", *desc);
1759 FIXME("unhandled format %d\n", *pFormat);
1767 static unsigned char * ComplexFree(PMIDL_STUB_MESSAGE pStubMsg,
1768 unsigned char *pMemory,
1769 PFORMAT_STRING pFormat,
1770 PFORMAT_STRING pPointer)
1772 PFORMAT_STRING desc;
1776 while (*pFormat != RPC_FC_END) {
1787 case RPC_FC_POINTER:
1788 NdrPointerFree(pStubMsg, *(unsigned char**)pMemory, pPointer);
1792 case RPC_FC_ALIGNM4:
1793 ALIGN_POINTER(pMemory, 4);
1795 case RPC_FC_ALIGNM8:
1796 ALIGN_POINTER(pMemory, 8);
1798 case RPC_FC_STRUCTPAD2:
1801 case RPC_FC_EMBEDDED_COMPLEX:
1802 pMemory += pFormat[1];
1804 desc = pFormat + *(const SHORT*)pFormat;
1805 size = EmbeddedComplexSize(pStubMsg, desc);
1806 m = NdrFreer[*desc & NDR_TABLE_MASK];
1807 if (m) m(pStubMsg, pMemory, desc);
1808 else FIXME("no freer for embedded type %02x\n", *desc);
1815 FIXME("unhandled format %d\n", *pFormat);
1823 static unsigned long ComplexStructMemorySize(PMIDL_STUB_MESSAGE pStubMsg,
1824 PFORMAT_STRING pFormat)
1826 PFORMAT_STRING desc;
1827 unsigned long size = 0;
1829 while (*pFormat != RPC_FC_END) {
1834 pStubMsg->Buffer += 2;
1839 pStubMsg->Buffer += 4;
1841 case RPC_FC_POINTER:
1843 pStubMsg->Buffer += 4;
1845 case RPC_FC_ALIGNM4:
1846 ALIGN_LENGTH(size, 4);
1847 ALIGN_POINTER(pStubMsg->Buffer, 4);
1849 case RPC_FC_ALIGNM8:
1850 ALIGN_LENGTH(size, 8);
1851 ALIGN_POINTER(pStubMsg->Buffer, 8);
1853 case RPC_FC_STRUCTPAD2:
1855 pStubMsg->Buffer += 2;
1857 case RPC_FC_EMBEDDED_COMPLEX:
1860 desc = pFormat + *(const SHORT*)pFormat;
1861 size += EmbeddedComplexMemorySize(pStubMsg, desc);
1867 FIXME("unhandled format %d\n", *pFormat);
1875 /***********************************************************************
1876 * NdrComplexStructMarshall [RPCRT4.@]
1878 unsigned char * WINAPI NdrComplexStructMarshall(PMIDL_STUB_MESSAGE pStubMsg,
1879 unsigned char *pMemory,
1880 PFORMAT_STRING pFormat)
1882 PFORMAT_STRING conf_array = NULL;
1883 PFORMAT_STRING pointer_desc = NULL;
1884 unsigned char *OldMemory = pStubMsg->Memory;
1886 TRACE("(%p,%p,%p)\n", pStubMsg, pMemory, pFormat);
1888 ALIGN_POINTER(pStubMsg->Buffer, pFormat[1] + 1);
1891 if (*(const WORD*)pFormat) conf_array = pFormat + *(const WORD*)pFormat;
1893 if (*(const WORD*)pFormat) pointer_desc = pFormat + *(const WORD*)pFormat;
1896 pStubMsg->Memory = pMemory;
1898 ComplexMarshall(pStubMsg, pMemory, pFormat, pointer_desc);
1901 NdrConformantArrayMarshall(pStubMsg, pMemory, conf_array);
1903 pStubMsg->Memory = OldMemory;
1905 STD_OVERFLOW_CHECK(pStubMsg);
1910 /***********************************************************************
1911 * NdrComplexStructUnmarshall [RPCRT4.@]
1913 unsigned char * WINAPI NdrComplexStructUnmarshall(PMIDL_STUB_MESSAGE pStubMsg,
1914 unsigned char **ppMemory,
1915 PFORMAT_STRING pFormat,
1916 unsigned char fMustAlloc)
1918 unsigned size = *(const WORD*)(pFormat+2);
1919 PFORMAT_STRING conf_array = NULL;
1920 PFORMAT_STRING pointer_desc = NULL;
1921 unsigned char *pMemory;
1923 TRACE("(%p,%p,%p,%d)\n", pStubMsg, ppMemory, pFormat, fMustAlloc);
1925 ALIGN_POINTER(pStubMsg->Buffer, pFormat[1] + 1);
1927 if (fMustAlloc || !*ppMemory)
1929 *ppMemory = NdrAllocate(pStubMsg, size);
1930 memset(*ppMemory, 0, size);
1934 if (*(const WORD*)pFormat) conf_array = pFormat + *(const WORD*)pFormat;
1936 if (*(const WORD*)pFormat) pointer_desc = pFormat + *(const WORD*)pFormat;
1939 pMemory = ComplexUnmarshall(pStubMsg, *ppMemory, pFormat, pointer_desc, fMustAlloc);
1942 NdrConformantArrayUnmarshall(pStubMsg, &pMemory, conf_array, fMustAlloc);
1947 /***********************************************************************
1948 * NdrComplexStructBufferSize [RPCRT4.@]
1950 void WINAPI NdrComplexStructBufferSize(PMIDL_STUB_MESSAGE pStubMsg,
1951 unsigned char *pMemory,
1952 PFORMAT_STRING pFormat)
1954 PFORMAT_STRING conf_array = NULL;
1955 PFORMAT_STRING pointer_desc = NULL;
1956 unsigned char *OldMemory = pStubMsg->Memory;
1958 TRACE("(%p,%p,%p)\n", pStubMsg, pMemory, pFormat);
1960 ALIGN_LENGTH(pStubMsg->BufferLength, pFormat[1] + 1);
1963 if (*(const WORD*)pFormat) conf_array = pFormat + *(const WORD*)pFormat;
1965 if (*(const WORD*)pFormat) pointer_desc = pFormat + *(const WORD*)pFormat;
1968 pStubMsg->Memory = pMemory;
1970 pMemory = ComplexBufferSize(pStubMsg, pMemory, pFormat, pointer_desc);
1973 NdrConformantArrayBufferSize(pStubMsg, pMemory, conf_array);
1975 pStubMsg->Memory = OldMemory;
1978 /***********************************************************************
1979 * NdrComplexStructMemorySize [RPCRT4.@]
1981 unsigned long WINAPI NdrComplexStructMemorySize(PMIDL_STUB_MESSAGE pStubMsg,
1982 PFORMAT_STRING pFormat)
1984 unsigned size = *(const WORD*)(pFormat+2);
1985 PFORMAT_STRING conf_array = NULL;
1986 PFORMAT_STRING pointer_desc = NULL;
1988 TRACE("(%p,%p)\n", pStubMsg, pFormat);
1990 ALIGN_POINTER(pStubMsg->Buffer, pFormat[1] + 1);
1993 if (*(const WORD*)pFormat) conf_array = pFormat + *(const WORD*)pFormat;
1995 if (*(const WORD*)pFormat) pointer_desc = pFormat + *(const WORD*)pFormat;
1998 ComplexStructMemorySize(pStubMsg, pFormat);
2001 NdrConformantArrayMemorySize(pStubMsg, conf_array);
2006 /***********************************************************************
2007 * NdrComplexStructFree [RPCRT4.@]
2009 void WINAPI NdrComplexStructFree(PMIDL_STUB_MESSAGE pStubMsg,
2010 unsigned char *pMemory,
2011 PFORMAT_STRING pFormat)
2013 PFORMAT_STRING conf_array = NULL;
2014 PFORMAT_STRING pointer_desc = NULL;
2015 unsigned char *OldMemory = pStubMsg->Memory;
2017 TRACE("(%p,%p,%p)\n", pStubMsg, pMemory, pFormat);
2020 if (*(const WORD*)pFormat) conf_array = pFormat + *(const WORD*)pFormat;
2022 if (*(const WORD*)pFormat) pointer_desc = pFormat + *(const WORD*)pFormat;
2025 pStubMsg->Memory = pMemory;
2027 pMemory = ComplexFree(pStubMsg, pMemory, pFormat, pointer_desc);
2030 NdrConformantArrayFree(pStubMsg, pMemory, conf_array);
2032 pStubMsg->Memory = OldMemory;
2035 /***********************************************************************
2036 * NdrConformantArrayMarshall [RPCRT4.@]
2038 unsigned char * WINAPI NdrConformantArrayMarshall(PMIDL_STUB_MESSAGE pStubMsg,
2039 unsigned char *pMemory,
2040 PFORMAT_STRING pFormat)
2042 DWORD size = 0, esize = *(const WORD*)(pFormat+2);
2043 unsigned char alignment = pFormat[1] + 1;
2045 TRACE("(%p,%p,%p)\n", pStubMsg, pMemory, pFormat);
2046 if (pFormat[0] != RPC_FC_CARRAY) FIXME("format=%d\n", pFormat[0]);
2048 pFormat = ComputeConformance(pStubMsg, pMemory, pFormat+4, 0);
2049 size = pStubMsg->MaxCount;
2051 WriteConformance(pStubMsg);
2053 ALIGN_POINTER(pStubMsg->Buffer, alignment);
2055 memcpy(pStubMsg->Buffer, pMemory, size*esize);
2056 pStubMsg->BufferMark = pStubMsg->Buffer;
2057 pStubMsg->Buffer += size*esize;
2059 EmbeddedPointerMarshall(pStubMsg, pMemory, pFormat);
2061 STD_OVERFLOW_CHECK(pStubMsg);
2066 /***********************************************************************
2067 * NdrConformantArrayUnmarshall [RPCRT4.@]
2069 unsigned char * WINAPI NdrConformantArrayUnmarshall(PMIDL_STUB_MESSAGE pStubMsg,
2070 unsigned char **ppMemory,
2071 PFORMAT_STRING pFormat,
2072 unsigned char fMustAlloc)
2074 DWORD size = 0, esize = *(const WORD*)(pFormat+2);
2075 unsigned char alignment = pFormat[1] + 1;
2077 TRACE("(%p,%p,%p,%d)\n", pStubMsg, ppMemory, pFormat, fMustAlloc);
2078 if (pFormat[0] != RPC_FC_CARRAY) FIXME("format=%d\n", pFormat[0]);
2080 pFormat = ReadConformance(pStubMsg, pFormat+4);
2081 size = pStubMsg->MaxCount;
2083 if (fMustAlloc || !*ppMemory)
2084 *ppMemory = NdrAllocate(pStubMsg, size*esize);
2086 ALIGN_POINTER(pStubMsg->Buffer, alignment);
2088 memcpy(*ppMemory, pStubMsg->Buffer, size*esize);
2090 pStubMsg->BufferMark = pStubMsg->Buffer;
2091 pStubMsg->Buffer += size*esize;
2093 EmbeddedPointerUnmarshall(pStubMsg, ppMemory, pFormat, fMustAlloc);
2098 /***********************************************************************
2099 * NdrConformantArrayBufferSize [RPCRT4.@]
2101 void WINAPI NdrConformantArrayBufferSize(PMIDL_STUB_MESSAGE pStubMsg,
2102 unsigned char *pMemory,
2103 PFORMAT_STRING pFormat)
2105 DWORD size = 0, esize = *(const WORD*)(pFormat+2);
2106 unsigned char alignment = pFormat[1] + 1;
2108 TRACE("(%p,%p,%p)\n", pStubMsg, pMemory, pFormat);
2109 if (pFormat[0] != RPC_FC_CARRAY) FIXME("format=%d\n", pFormat[0]);
2111 pFormat = ComputeConformance(pStubMsg, pMemory, pFormat+4, 0);
2112 size = pStubMsg->MaxCount;
2114 SizeConformance(pStubMsg);
2116 ALIGN_LENGTH(pStubMsg->BufferLength, alignment);
2118 /* conformance value plus array */
2119 pStubMsg->BufferLength += size*esize;
2121 EmbeddedPointerBufferSize(pStubMsg, pMemory, pFormat);
2124 /***********************************************************************
2125 * NdrConformantArrayMemorySize [RPCRT4.@]
2127 unsigned long WINAPI NdrConformantArrayMemorySize(PMIDL_STUB_MESSAGE pStubMsg,
2128 PFORMAT_STRING pFormat)
2130 DWORD size = 0, esize = *(const WORD*)(pFormat+2);
2131 unsigned char alignment = pFormat[1] + 1;
2133 TRACE("(%p,%p)\n", pStubMsg, pFormat);
2134 if (pFormat[0] != RPC_FC_CARRAY) FIXME("format=%d\n", pFormat[0]);
2136 pFormat = ReadConformance(pStubMsg, pFormat+4);
2137 size = pStubMsg->MaxCount;
2138 pStubMsg->MemorySize += size*esize;
2140 ALIGN_POINTER(pStubMsg->Buffer, alignment);
2141 pStubMsg->BufferMark = pStubMsg->Buffer;
2142 pStubMsg->Buffer += size*esize;
2144 EmbeddedPointerMemorySize(pStubMsg, pFormat);
2146 return pStubMsg->MemorySize;
2149 /***********************************************************************
2150 * NdrConformantArrayFree [RPCRT4.@]
2152 void WINAPI NdrConformantArrayFree(PMIDL_STUB_MESSAGE pStubMsg,
2153 unsigned char *pMemory,
2154 PFORMAT_STRING pFormat)
2156 TRACE("(%p,%p,%p)\n", pStubMsg, pMemory, pFormat);
2157 if (pFormat[0] != RPC_FC_CARRAY) FIXME("format=%d\n", pFormat[0]);
2159 EmbeddedPointerFree(pStubMsg, pMemory, pFormat);
2163 /***********************************************************************
2164 * NdrConformantVaryingArrayMarshall [RPCRT4.@]
2166 unsigned char* WINAPI NdrConformantVaryingArrayMarshall( PMIDL_STUB_MESSAGE pStubMsg,
2167 unsigned char* pMemory,
2168 PFORMAT_STRING pFormat )
2170 unsigned char alignment = pFormat[1] + 1;
2171 DWORD esize = *(const WORD*)(pFormat+2);
2173 TRACE("(%p, %p, %p)\n", pStubMsg, pMemory, pFormat);
2175 if (pFormat[0] != RPC_FC_CVARRAY)
2177 ERR("invalid format type %x\n", pFormat[0]);
2178 RpcRaiseException(RPC_S_INTERNAL_ERROR);
2182 pFormat = ComputeConformance(pStubMsg, pMemory, pFormat+4, 0);
2183 pFormat = ComputeVariance(pStubMsg, pMemory, pFormat, 0);
2185 WriteConformance(pStubMsg);
2186 WriteVariance(pStubMsg);
2188 ALIGN_POINTER(pStubMsg->Buffer, alignment);
2190 memcpy(pStubMsg->Buffer, pMemory + pStubMsg->Offset, pStubMsg->ActualCount*esize);
2191 pStubMsg->BufferMark = pStubMsg->Buffer;
2192 pStubMsg->Buffer += pStubMsg->ActualCount*esize;
2194 EmbeddedPointerMarshall(pStubMsg, pMemory, pFormat);
2196 STD_OVERFLOW_CHECK(pStubMsg);
2202 /***********************************************************************
2203 * NdrConformantVaryingArrayUnmarshall [RPCRT4.@]
2205 unsigned char* WINAPI NdrConformantVaryingArrayUnmarshall( PMIDL_STUB_MESSAGE pStubMsg,
2206 unsigned char** ppMemory,
2207 PFORMAT_STRING pFormat,
2208 unsigned char fMustAlloc )
2210 unsigned char alignment = pFormat[1] + 1;
2211 DWORD esize = *(const WORD*)(pFormat+2);
2213 TRACE("(%p, %p, %p, %d)\n", pStubMsg, ppMemory, pFormat, fMustAlloc);
2215 if (pFormat[0] != RPC_FC_CVARRAY)
2217 ERR("invalid format type %x\n", pFormat[0]);
2218 RpcRaiseException(RPC_S_INTERNAL_ERROR);
2222 pFormat = ReadConformance(pStubMsg, pFormat);
2223 pFormat = ReadVariance(pStubMsg, pFormat);
2225 ALIGN_POINTER(pStubMsg->Buffer, alignment);
2227 if (!*ppMemory || fMustAlloc)
2228 *ppMemory = NdrAllocate(pStubMsg, pStubMsg->MaxCount * esize);
2229 memcpy(*ppMemory + pStubMsg->Offset, pStubMsg->Buffer, pStubMsg->ActualCount * esize);
2230 pStubMsg->Buffer += pStubMsg->ActualCount * esize;
2232 EmbeddedPointerUnmarshall(pStubMsg, ppMemory, pFormat, fMustAlloc);
2238 /***********************************************************************
2239 * NdrConformantVaryingArrayFree [RPCRT4.@]
2241 void WINAPI NdrConformantVaryingArrayFree( PMIDL_STUB_MESSAGE pStubMsg,
2242 unsigned char* pMemory,
2243 PFORMAT_STRING pFormat )
2245 TRACE("(%p,%p,%p)\n", pStubMsg, pMemory, pFormat);
2247 if (pFormat[0] != RPC_FC_CVARRAY)
2249 ERR("invalid format type %x\n", pFormat[0]);
2250 RpcRaiseException(RPC_S_INTERNAL_ERROR);
2254 pFormat = ComputeConformance(pStubMsg, pMemory, pFormat+4, 0);
2255 pFormat = ComputeVariance(pStubMsg, pMemory, pFormat, 0);
2257 EmbeddedPointerFree(pStubMsg, pMemory, pFormat);
2261 /***********************************************************************
2262 * NdrConformantVaryingArrayBufferSize [RPCRT4.@]
2264 void WINAPI NdrConformantVaryingArrayBufferSize( PMIDL_STUB_MESSAGE pStubMsg,
2265 unsigned char* pMemory, PFORMAT_STRING pFormat )
2267 unsigned char alignment = pFormat[1] + 1;
2268 DWORD esize = *(const WORD*)(pFormat+2);
2270 TRACE("(%p, %p, %p)\n", pStubMsg, pMemory, pFormat);
2272 if (pFormat[0] != RPC_FC_CVARRAY)
2274 ERR("invalid format type %x\n", pFormat[0]);
2275 RpcRaiseException(RPC_S_INTERNAL_ERROR);
2280 pFormat = ComputeConformance(pStubMsg, pMemory, pFormat+4, 0);
2281 /* compute length */
2282 pFormat = ComputeVariance(pStubMsg, pMemory, pFormat, 0);
2284 SizeConformance(pStubMsg);
2285 SizeVariance(pStubMsg);
2287 ALIGN_LENGTH(pStubMsg->BufferLength, alignment);
2289 pStubMsg->BufferLength += pStubMsg->ActualCount*esize;
2291 EmbeddedPointerBufferSize(pStubMsg, pMemory, pFormat);
2295 /***********************************************************************
2296 * NdrConformantVaryingArrayMemorySize [RPCRT4.@]
2298 unsigned long WINAPI NdrConformantVaryingArrayMemorySize( PMIDL_STUB_MESSAGE pStubMsg,
2299 PFORMAT_STRING pFormat )
2306 /***********************************************************************
2307 * NdrComplexArrayMarshall [RPCRT4.@]
2309 unsigned char * WINAPI NdrComplexArrayMarshall(PMIDL_STUB_MESSAGE pStubMsg,
2310 unsigned char *pMemory,
2311 PFORMAT_STRING pFormat)
2313 ULONG i, count, def;
2314 BOOL variance_present;
2315 unsigned char alignment;
2317 TRACE("(%p,%p,%p)\n", pStubMsg, pMemory, pFormat);
2319 if (pFormat[0] != RPC_FC_BOGUS_ARRAY)
2321 ERR("invalid format type %x\n", pFormat[0]);
2322 RpcRaiseException(RPC_S_INTERNAL_ERROR);
2326 alignment = pFormat[1] + 1;
2328 def = *(const WORD*)&pFormat[2];
2331 pFormat = ComputeConformance(pStubMsg, pMemory, pFormat, def);
2332 TRACE("conformance = %ld\n", pStubMsg->MaxCount);
2334 variance_present = IsConformanceOrVariancePresent(pFormat);
2335 pFormat = ComputeVariance(pStubMsg, pMemory, pFormat, pStubMsg->MaxCount);
2336 TRACE("variance = %ld\n", pStubMsg->ActualCount);
2338 WriteConformance(pStubMsg);
2339 if (variance_present)
2340 WriteVariance(pStubMsg);
2342 ALIGN_POINTER(pStubMsg->Buffer, alignment);
2344 count = pStubMsg->ActualCount;
2345 for (i = 0; i < count; i++)
2346 pMemory = ComplexMarshall(pStubMsg, pMemory, pFormat, NULL);
2348 STD_OVERFLOW_CHECK(pStubMsg);
2353 /***********************************************************************
2354 * NdrComplexArrayUnmarshall [RPCRT4.@]
2356 unsigned char * WINAPI NdrComplexArrayUnmarshall(PMIDL_STUB_MESSAGE pStubMsg,
2357 unsigned char **ppMemory,
2358 PFORMAT_STRING pFormat,
2359 unsigned char fMustAlloc)
2361 ULONG i, count, esize;
2362 unsigned char alignment;
2363 unsigned char *pMemory;
2364 unsigned char *Buffer;
2366 TRACE("(%p,%p,%p,%d)\n", pStubMsg, ppMemory, pFormat, fMustAlloc);
2368 if (pFormat[0] != RPC_FC_BOGUS_ARRAY)
2370 ERR("invalid format type %x\n", pFormat[0]);
2371 RpcRaiseException(RPC_S_INTERNAL_ERROR);
2375 alignment = pFormat[1] + 1;
2379 pFormat = ReadConformance(pStubMsg, pFormat);
2380 pFormat = ReadVariance(pStubMsg, pFormat);
2382 Buffer = pStubMsg->Buffer;
2383 esize = ComplexStructMemorySize(pStubMsg, pFormat);
2384 pStubMsg->Buffer = Buffer;
2386 if (fMustAlloc || !*ppMemory)
2388 *ppMemory = NdrAllocate(pStubMsg, pStubMsg->MaxCount * esize);
2389 memset(*ppMemory, 0, pStubMsg->MaxCount * esize);
2392 ALIGN_POINTER(pStubMsg->Buffer, alignment);
2394 pMemory = *ppMemory;
2395 count = pStubMsg->ActualCount;
2396 for (i = 0; i < count; i++)
2397 pMemory = ComplexUnmarshall(pStubMsg, pMemory, pFormat, NULL, fMustAlloc);
2402 /***********************************************************************
2403 * NdrComplexArrayBufferSize [RPCRT4.@]
2405 void WINAPI NdrComplexArrayBufferSize(PMIDL_STUB_MESSAGE pStubMsg,
2406 unsigned char *pMemory,
2407 PFORMAT_STRING pFormat)
2409 ULONG i, count, def;
2410 unsigned char alignment;
2411 BOOL variance_present;
2413 TRACE("(%p,%p,%p)\n", pStubMsg, pMemory, pFormat);
2415 if (pFormat[0] != RPC_FC_BOGUS_ARRAY)
2417 ERR("invalid format type %x\n", pFormat[0]);
2418 RpcRaiseException(RPC_S_INTERNAL_ERROR);
2422 alignment = pFormat[1] + 1;
2424 def = *(const WORD*)&pFormat[2];
2427 pFormat = ComputeConformance(pStubMsg, pMemory, pFormat, def);
2428 TRACE("conformance = %ld\n", pStubMsg->MaxCount);
2429 SizeConformance(pStubMsg);
2431 variance_present = IsConformanceOrVariancePresent(pFormat);
2432 pFormat = ComputeVariance(pStubMsg, pMemory, pFormat, pStubMsg->MaxCount);
2433 TRACE("variance = %ld\n", pStubMsg->ActualCount);
2435 if (variance_present)
2436 SizeVariance(pStubMsg);
2438 ALIGN_LENGTH(pStubMsg->BufferLength, alignment);
2440 count = pStubMsg->ActualCount;
2441 for (i = 0; i < count; i++)
2442 pMemory = ComplexBufferSize(pStubMsg, pMemory, pFormat, NULL);
2445 /***********************************************************************
2446 * NdrComplexArrayMemorySize [RPCRT4.@]
2448 unsigned long WINAPI NdrComplexArrayMemorySize(PMIDL_STUB_MESSAGE pStubMsg,
2449 PFORMAT_STRING pFormat)
2451 ULONG i, count, esize;
2452 unsigned char alignment;
2453 unsigned char *Buffer;
2454 unsigned long SavedMemorySize;
2455 unsigned long MemorySize;
2457 TRACE("(%p,%p)\n", pStubMsg, pFormat);
2459 if (pFormat[0] != RPC_FC_BOGUS_ARRAY)
2461 ERR("invalid format type %x\n", pFormat[0]);
2462 RpcRaiseException(RPC_S_INTERNAL_ERROR);
2466 alignment = pFormat[1] + 1;
2470 pFormat = ReadConformance(pStubMsg, pFormat);
2471 pFormat = ReadVariance(pStubMsg, pFormat);
2473 ALIGN_POINTER(pStubMsg->Buffer, alignment);
2475 SavedMemorySize = pStubMsg->MemorySize;
2477 Buffer = pStubMsg->Buffer;
2478 esize = ComplexStructMemorySize(pStubMsg, pFormat);
2479 pStubMsg->Buffer = Buffer;
2481 MemorySize = esize * pStubMsg->MaxCount;
2483 count = pStubMsg->ActualCount;
2484 for (i = 0; i < count; i++)
2485 ComplexStructMemorySize(pStubMsg, pFormat);
2487 pStubMsg->MemorySize = SavedMemorySize;
2489 pStubMsg->MemorySize += MemorySize;
2493 /***********************************************************************
2494 * NdrComplexArrayFree [RPCRT4.@]
2496 void WINAPI NdrComplexArrayFree(PMIDL_STUB_MESSAGE pStubMsg,
2497 unsigned char *pMemory,
2498 PFORMAT_STRING pFormat)
2500 ULONG i, count, def;
2502 TRACE("(%p,%p,%p)\n", pStubMsg, pMemory, pFormat);
2504 if (pFormat[0] != RPC_FC_BOGUS_ARRAY)
2506 ERR("invalid format type %x\n", pFormat[0]);
2507 RpcRaiseException(RPC_S_INTERNAL_ERROR);
2511 def = *(const WORD*)&pFormat[2];
2514 pFormat = ComputeConformance(pStubMsg, pMemory, pFormat, def);
2515 TRACE("conformance = %ld\n", pStubMsg->MaxCount);
2517 pFormat = ComputeVariance(pStubMsg, pMemory, pFormat, pStubMsg->MaxCount);
2518 TRACE("variance = %ld\n", pStubMsg->ActualCount);
2520 count = pStubMsg->ActualCount;
2521 for (i = 0; i < count; i++)
2522 pMemory = ComplexFree(pStubMsg, pMemory, pFormat, NULL);
2525 unsigned long UserMarshalFlags(PMIDL_STUB_MESSAGE pStubMsg)
2527 return MAKELONG(pStubMsg->dwDestContext,
2528 pStubMsg->RpcMsg->DataRepresentation);
2531 #define USER_MARSHAL_PTR_PREFIX \
2532 ( (DWORD)'U' | ( (DWORD)'s' << 8 ) | \
2533 ( (DWORD)'e' << 16 ) | ( (DWORD)'r' << 24 ) )
2535 /***********************************************************************
2536 * NdrUserMarshalMarshall [RPCRT4.@]
2538 unsigned char * WINAPI NdrUserMarshalMarshall(PMIDL_STUB_MESSAGE pStubMsg,
2539 unsigned char *pMemory,
2540 PFORMAT_STRING pFormat)
2542 unsigned flags = pFormat[1];
2543 unsigned index = *(const WORD*)&pFormat[2];
2544 unsigned long uflag = UserMarshalFlags(pStubMsg);
2545 TRACE("(%p,%p,%p)\n", pStubMsg, pMemory, pFormat);
2546 TRACE("index=%d\n", index);
2548 if (flags & USER_MARSHAL_POINTER)
2550 ALIGN_POINTER(pStubMsg->Buffer, 4);
2551 NDR_LOCAL_UINT32_WRITE(pStubMsg->Buffer, USER_MARSHAL_PTR_PREFIX);
2552 pStubMsg->Buffer += 4;
2553 ALIGN_POINTER(pStubMsg->Buffer, 8);
2556 ALIGN_POINTER(pStubMsg->Buffer, (flags & 0xf) + 1);
2559 pStubMsg->StubDesc->aUserMarshalQuadruple[index].pfnMarshall(
2560 &uflag, pStubMsg->Buffer, pMemory);
2562 STD_OVERFLOW_CHECK(pStubMsg);
2567 /***********************************************************************
2568 * NdrUserMarshalUnmarshall [RPCRT4.@]
2570 unsigned char * WINAPI NdrUserMarshalUnmarshall(PMIDL_STUB_MESSAGE pStubMsg,
2571 unsigned char **ppMemory,
2572 PFORMAT_STRING pFormat,
2573 unsigned char fMustAlloc)
2575 unsigned flags = pFormat[1];
2576 unsigned index = *(const WORD*)&pFormat[2];
2577 DWORD memsize = *(const WORD*)&pFormat[4];
2578 unsigned long uflag = UserMarshalFlags(pStubMsg);
2579 TRACE("(%p,%p,%p,%d)\n", pStubMsg, ppMemory, pFormat, fMustAlloc);
2580 TRACE("index=%d\n", index);
2582 if (flags & USER_MARSHAL_POINTER)
2584 ALIGN_POINTER(pStubMsg->Buffer, 4);
2585 /* skip pointer prefix */
2586 pStubMsg->Buffer += 4;
2587 ALIGN_POINTER(pStubMsg->Buffer, 8);
2590 ALIGN_POINTER(pStubMsg->Buffer, (flags & 0xf) + 1);
2592 if (fMustAlloc || !*ppMemory)
2593 *ppMemory = NdrAllocate(pStubMsg, memsize);
2596 pStubMsg->StubDesc->aUserMarshalQuadruple[index].pfnUnmarshall(
2597 &uflag, pStubMsg->Buffer, *ppMemory);
2602 /***********************************************************************
2603 * NdrUserMarshalBufferSize [RPCRT4.@]
2605 void WINAPI NdrUserMarshalBufferSize(PMIDL_STUB_MESSAGE pStubMsg,
2606 unsigned char *pMemory,
2607 PFORMAT_STRING pFormat)
2609 unsigned flags = pFormat[1];
2610 unsigned index = *(const WORD*)&pFormat[2];
2611 DWORD bufsize = *(const WORD*)&pFormat[6];
2612 unsigned long uflag = UserMarshalFlags(pStubMsg);
2613 TRACE("(%p,%p,%p)\n", pStubMsg, pMemory, pFormat);
2614 TRACE("index=%d\n", index);
2616 if (flags & USER_MARSHAL_POINTER)
2618 ALIGN_LENGTH(pStubMsg->BufferLength, 4);
2619 /* skip pointer prefix */
2620 pStubMsg->BufferLength += 4;
2621 ALIGN_LENGTH(pStubMsg->BufferLength, 8);
2624 ALIGN_LENGTH(pStubMsg->BufferLength, (flags & 0xf) + 1);
2627 TRACE("size=%ld\n", bufsize);
2628 pStubMsg->BufferLength += bufsize;
2632 pStubMsg->BufferLength =
2633 pStubMsg->StubDesc->aUserMarshalQuadruple[index].pfnBufferSize(
2634 &uflag, pStubMsg->BufferLength, pMemory);
2637 /***********************************************************************
2638 * NdrUserMarshalMemorySize [RPCRT4.@]
2640 unsigned long WINAPI NdrUserMarshalMemorySize(PMIDL_STUB_MESSAGE pStubMsg,
2641 PFORMAT_STRING pFormat)
2643 unsigned flags = pFormat[1];
2644 unsigned index = *(const WORD*)&pFormat[2];
2645 DWORD memsize = *(const WORD*)&pFormat[4];
2646 DWORD bufsize = *(const WORD*)&pFormat[6];
2648 TRACE("(%p,%p)\n", pStubMsg, pFormat);
2649 TRACE("index=%d\n", index);
2651 pStubMsg->MemorySize += memsize;
2653 if (flags & USER_MARSHAL_POINTER)
2655 ALIGN_POINTER(pStubMsg->Buffer, 4);
2656 /* skip pointer prefix */
2657 pStubMsg->Buffer += 4;
2658 ALIGN_POINTER(pStubMsg->Buffer, 8);
2661 ALIGN_POINTER(pStubMsg->Buffer, (flags & 0xf) + 1);
2663 pStubMsg->Buffer += bufsize;
2665 return pStubMsg->MemorySize;
2668 /***********************************************************************
2669 * NdrUserMarshalFree [RPCRT4.@]
2671 void WINAPI NdrUserMarshalFree(PMIDL_STUB_MESSAGE pStubMsg,
2672 unsigned char *pMemory,
2673 PFORMAT_STRING pFormat)
2675 /* unsigned flags = pFormat[1]; */
2676 unsigned index = *(const WORD*)&pFormat[2];
2677 unsigned long uflag = UserMarshalFlags(pStubMsg);
2678 TRACE("(%p,%p,%p)\n", pStubMsg, pMemory, pFormat);
2679 TRACE("index=%d\n", index);
2681 pStubMsg->StubDesc->aUserMarshalQuadruple[index].pfnFree(
2685 /***********************************************************************
2686 * NdrClearOutParameters [RPCRT4.@]
2688 void WINAPI NdrClearOutParameters(PMIDL_STUB_MESSAGE pStubMsg,
2689 PFORMAT_STRING pFormat,
2692 FIXME("(%p,%p,%p): stub\n", pStubMsg, pFormat, ArgAddr);
2695 /***********************************************************************
2696 * NdrConvert [RPCRT4.@]
2698 void WINAPI NdrConvert( PMIDL_STUB_MESSAGE pStubMsg, PFORMAT_STRING pFormat )
2700 FIXME("(pStubMsg == ^%p, pFormat == ^%p): stub.\n", pStubMsg, pFormat);
2701 /* FIXME: since this stub doesn't do any converting, the proper behavior
2702 is to raise an exception */
2705 /***********************************************************************
2706 * NdrConvert2 [RPCRT4.@]
2708 void WINAPI NdrConvert2( PMIDL_STUB_MESSAGE pStubMsg, PFORMAT_STRING pFormat, long NumberParams )
2710 FIXME("(pStubMsg == ^%p, pFormat == ^%p, NumberParams == %ld): stub.\n",
2711 pStubMsg, pFormat, NumberParams);
2712 /* FIXME: since this stub doesn't do any converting, the proper behavior
2713 is to raise an exception */
2716 typedef struct _NDR_CSTRUCT_FORMAT
2719 unsigned char alignment;
2720 unsigned short memory_size;
2721 short offset_to_array_description;
2722 } NDR_CSTRUCT_FORMAT, NDR_CVSTRUCT_FORMAT;
2724 /***********************************************************************
2725 * NdrConformantStructMarshall [RPCRT4.@]
2727 unsigned char * WINAPI NdrConformantStructMarshall(PMIDL_STUB_MESSAGE pStubMsg,
2728 unsigned char *pMemory,
2729 PFORMAT_STRING pFormat)
2731 const NDR_CSTRUCT_FORMAT * pCStructFormat = (NDR_CSTRUCT_FORMAT*)pFormat;
2732 PFORMAT_STRING pCArrayFormat;
2735 TRACE("(%p, %p, %p)\n", pStubMsg, pMemory, pFormat);
2737 pFormat += sizeof(NDR_CSTRUCT_FORMAT);
2738 if ((pCStructFormat->type != RPC_FC_CPSTRUCT) && (pCStructFormat->type != RPC_FC_CSTRUCT))
2740 ERR("invalid format type %x\n", pCStructFormat->type);
2741 RpcRaiseException(RPC_S_INTERNAL_ERROR);
2745 pCArrayFormat = (unsigned char*)&pCStructFormat->offset_to_array_description +
2746 pCStructFormat->offset_to_array_description;
2747 if (*pCArrayFormat != RPC_FC_CARRAY)
2749 ERR("invalid array format type %x\n", pCStructFormat->type);
2750 RpcRaiseException(RPC_S_INTERNAL_ERROR);
2753 esize = *(const WORD*)(pCArrayFormat+2);
2755 ComputeConformance(pStubMsg, pMemory + pCStructFormat->memory_size,
2756 pCArrayFormat + 4, 0);
2758 WriteConformance(pStubMsg);
2760 ALIGN_POINTER(pStubMsg->Buffer, pCStructFormat->alignment + 1);
2762 TRACE("memory_size = %d\n", pCStructFormat->memory_size);
2764 /* copy constant sized part of struct */
2765 pStubMsg->BufferMark = pStubMsg->Buffer;
2766 memcpy(pStubMsg->Buffer, pMemory, pCStructFormat->memory_size + pStubMsg->MaxCount * esize);
2767 pStubMsg->Buffer += pCStructFormat->memory_size + pStubMsg->MaxCount * esize;
2769 if (pCStructFormat->type == RPC_FC_CPSTRUCT)
2770 EmbeddedPointerMarshall(pStubMsg, pMemory, pFormat);
2772 STD_OVERFLOW_CHECK(pStubMsg);
2777 /***********************************************************************
2778 * NdrConformantStructUnmarshall [RPCRT4.@]
2780 unsigned char * WINAPI NdrConformantStructUnmarshall(PMIDL_STUB_MESSAGE pStubMsg,
2781 unsigned char **ppMemory,
2782 PFORMAT_STRING pFormat,
2783 unsigned char fMustAlloc)
2785 const NDR_CSTRUCT_FORMAT * pCStructFormat = (NDR_CSTRUCT_FORMAT*)pFormat;
2786 PFORMAT_STRING pCArrayFormat;
2789 TRACE("(%p, %p, %p, %d)\n", pStubMsg, ppMemory, pFormat, fMustAlloc);
2791 pFormat += sizeof(NDR_CSTRUCT_FORMAT);
2792 if ((pCStructFormat->type != RPC_FC_CPSTRUCT) && (pCStructFormat->type != RPC_FC_CSTRUCT))
2794 ERR("invalid format type %x\n", pCStructFormat->type);
2795 RpcRaiseException(RPC_S_INTERNAL_ERROR);
2798 pCArrayFormat = (unsigned char*)&pCStructFormat->offset_to_array_description +
2799 pCStructFormat->offset_to_array_description;
2800 if (*pCArrayFormat != RPC_FC_CARRAY)
2802 ERR("invalid array format type %x\n", pCStructFormat->type);
2803 RpcRaiseException(RPC_S_INTERNAL_ERROR);
2806 esize = *(const WORD*)(pCArrayFormat+2);
2808 pCArrayFormat = ReadConformance(pStubMsg, pCArrayFormat + 4);
2810 ALIGN_POINTER(pStubMsg->Buffer, pCStructFormat->alignment + 1);
2812 TRACE("memory_size = %d\n", pCStructFormat->memory_size);
2814 /* work out how much memory to allocate if we need to do so */
2815 if (!*ppMemory || fMustAlloc)
2817 SIZE_T size = pCStructFormat->memory_size + pStubMsg->MaxCount * esize;
2818 *ppMemory = NdrAllocate(pStubMsg, size);
2821 /* now copy the data */
2822 pStubMsg->BufferMark = pStubMsg->Buffer;
2823 memcpy(*ppMemory, pStubMsg->Buffer, pCStructFormat->memory_size + pStubMsg->MaxCount * esize);
2824 pStubMsg->Buffer += pCStructFormat->memory_size + pStubMsg->MaxCount * esize;
2826 if (pCStructFormat->type == RPC_FC_CPSTRUCT)
2827 EmbeddedPointerUnmarshall(pStubMsg, ppMemory, pFormat, fMustAlloc);
2832 /***********************************************************************
2833 * NdrConformantStructBufferSize [RPCRT4.@]
2835 void WINAPI NdrConformantStructBufferSize(PMIDL_STUB_MESSAGE pStubMsg,
2836 unsigned char *pMemory,
2837 PFORMAT_STRING pFormat)
2839 const NDR_CSTRUCT_FORMAT * pCStructFormat = (NDR_CSTRUCT_FORMAT*)pFormat;
2840 PFORMAT_STRING pCArrayFormat;
2843 TRACE("(%p, %p, %p)\n", pStubMsg, pMemory, pFormat);
2845 pFormat += sizeof(NDR_CSTRUCT_FORMAT);
2846 if ((pCStructFormat->type != RPC_FC_CPSTRUCT) && (pCStructFormat->type != RPC_FC_CSTRUCT))
2848 ERR("invalid format type %x\n", pCStructFormat->type);
2849 RpcRaiseException(RPC_S_INTERNAL_ERROR);
2852 pCArrayFormat = (unsigned char*)&pCStructFormat->offset_to_array_description +
2853 pCStructFormat->offset_to_array_description;
2854 if (*pCArrayFormat != RPC_FC_CARRAY)
2856 ERR("invalid array format type %x\n", pCStructFormat->type);
2857 RpcRaiseException(RPC_S_INTERNAL_ERROR);
2860 esize = *(const WORD*)(pCArrayFormat+2);
2862 pCArrayFormat = ComputeConformance(pStubMsg, pMemory + pCStructFormat->memory_size, pCArrayFormat+4, 0);
2863 SizeConformance(pStubMsg);
2865 ALIGN_LENGTH(pStubMsg->BufferLength, pCStructFormat->alignment + 1);
2867 TRACE("memory_size = %d\n", pCStructFormat->memory_size);
2869 pStubMsg->BufferLength += pCStructFormat->memory_size + esize * pStubMsg->MaxCount;
2871 if (pCStructFormat->type == RPC_FC_CPSTRUCT)
2872 EmbeddedPointerBufferSize(pStubMsg, pMemory, pFormat);
2875 /***********************************************************************
2876 * NdrConformantStructMemorySize [RPCRT4.@]
2878 unsigned long WINAPI NdrConformantStructMemorySize(PMIDL_STUB_MESSAGE pStubMsg,
2879 PFORMAT_STRING pFormat)
2885 /***********************************************************************
2886 * NdrConformantStructFree [RPCRT4.@]
2888 void WINAPI NdrConformantStructFree(PMIDL_STUB_MESSAGE pStubMsg,
2889 unsigned char *pMemory,
2890 PFORMAT_STRING pFormat)
2895 /***********************************************************************
2896 * NdrConformantVaryingStructMarshall [RPCRT4.@]
2898 unsigned char * WINAPI NdrConformantVaryingStructMarshall(PMIDL_STUB_MESSAGE pStubMsg,
2899 unsigned char *pMemory,
2900 PFORMAT_STRING pFormat)
2902 const NDR_CVSTRUCT_FORMAT * pCVStructFormat = (NDR_CVSTRUCT_FORMAT*)pFormat;
2903 PFORMAT_STRING pCVArrayFormat;
2906 TRACE("(%p, %p, %p)\n", pStubMsg, pMemory, pFormat);
2908 pFormat += sizeof(NDR_CVSTRUCT_FORMAT);
2909 if (pCVStructFormat->type != RPC_FC_CVSTRUCT)
2911 ERR("invalid format type %x\n", pCVStructFormat->type);
2912 RpcRaiseException(RPC_S_INTERNAL_ERROR);
2916 pCVArrayFormat = (unsigned char*)&pCVStructFormat->offset_to_array_description +
2917 pCVStructFormat->offset_to_array_description;
2918 switch (*pCVArrayFormat)
2920 case RPC_FC_CVARRAY:
2921 esize = *(const WORD*)(pCVArrayFormat+2);
2923 pCVArrayFormat = ComputeConformance(pStubMsg, pMemory + pCVStructFormat->memory_size,
2924 pCVArrayFormat + 4, 0);
2925 pCVArrayFormat = ComputeVariance(pStubMsg, pMemory + pCVStructFormat->memory_size,
2928 case RPC_FC_C_CSTRING:
2929 TRACE("string=%s\n", debugstr_a((char*)pMemory + pCVStructFormat->memory_size));
2930 pStubMsg->ActualCount = strlen((char*)pMemory + pCVStructFormat->memory_size)+1;
2931 esize = sizeof(char);
2932 if (pCVArrayFormat[1] == RPC_FC_STRING_SIZED)
2933 pCVArrayFormat = ComputeConformance(pStubMsg, pMemory + pCVStructFormat->memory_size,
2934 pCVArrayFormat + 2, 0);
2936 pStubMsg->MaxCount = pStubMsg->ActualCount;
2938 case RPC_FC_C_WSTRING:
2939 TRACE("string=%s\n", debugstr_w((LPWSTR)pMemory + pCVStructFormat->memory_size));
2940 pStubMsg->ActualCount = strlenW((LPWSTR)pMemory + pCVStructFormat->memory_size)+1;
2941 esize = sizeof(WCHAR);
2942 if (pCVArrayFormat[1] == RPC_FC_STRING_SIZED)
2943 pCVArrayFormat = ComputeConformance(pStubMsg, pMemory + pCVStructFormat->memory_size,
2944 pCVArrayFormat + 2, 0);
2946 pStubMsg->MaxCount = pStubMsg->ActualCount;
2949 ERR("invalid array format type %x\n", *pCVArrayFormat);
2950 RpcRaiseException(RPC_S_INTERNAL_ERROR);
2954 WriteConformance(pStubMsg);
2956 ALIGN_POINTER(pStubMsg->Buffer, pCVStructFormat->alignment + 1);
2958 TRACE("memory_size = %d\n", pCVStructFormat->memory_size);
2960 /* write constant sized part */
2961 pStubMsg->BufferMark = pStubMsg->Buffer;
2962 memcpy(pStubMsg->Buffer, pMemory, pCVStructFormat->memory_size);
2963 pStubMsg->Buffer += pCVStructFormat->memory_size;
2965 WriteVariance(pStubMsg);
2967 /* write array part */
2968 memcpy(pStubMsg->Buffer, pMemory + pCVStructFormat->memory_size, pStubMsg->ActualCount * esize);
2969 pStubMsg->Buffer += pStubMsg->ActualCount * esize;
2971 EmbeddedPointerMarshall(pStubMsg, pMemory, pFormat);
2973 STD_OVERFLOW_CHECK(pStubMsg);
2978 /***********************************************************************
2979 * NdrConformantVaryingStructUnmarshall [RPCRT4.@]
2981 unsigned char * WINAPI NdrConformantVaryingStructUnmarshall(PMIDL_STUB_MESSAGE pStubMsg,
2982 unsigned char **ppMemory,
2983 PFORMAT_STRING pFormat,
2984 unsigned char fMustAlloc)
2986 const NDR_CVSTRUCT_FORMAT * pCVStructFormat = (NDR_CVSTRUCT_FORMAT*)pFormat;
2987 PFORMAT_STRING pCVArrayFormat;
2989 unsigned char cvarray_type;
2991 TRACE("(%p, %p, %p, %d)\n", pStubMsg, ppMemory, pFormat, fMustAlloc);
2993 pFormat += sizeof(NDR_CVSTRUCT_FORMAT);
2994 if (pCVStructFormat->type != RPC_FC_CVSTRUCT)
2996 ERR("invalid format type %x\n", pCVStructFormat->type);
2997 RpcRaiseException(RPC_S_INTERNAL_ERROR);
3001 pCVArrayFormat = (unsigned char*)&pCVStructFormat->offset_to_array_description +
3002 pCVStructFormat->offset_to_array_description;
3003 cvarray_type = *pCVArrayFormat;
3004 switch (cvarray_type)
3006 case RPC_FC_CVARRAY:
3007 esize = *(const WORD*)(pCVArrayFormat+2);
3008 pCVArrayFormat = ReadConformance(pStubMsg, pCVArrayFormat + 4);
3010 case RPC_FC_C_CSTRING:
3011 esize = sizeof(char);
3012 if (pCVArrayFormat[1] == RPC_FC_STRING_SIZED)
3013 pCVArrayFormat = ReadConformance(pStubMsg, pCVArrayFormat + 2);
3015 pCVArrayFormat = ReadConformance(pStubMsg, NULL);
3017 case RPC_FC_C_WSTRING:
3018 esize = sizeof(WCHAR);
3019 if (pCVArrayFormat[1] == RPC_FC_STRING_SIZED)
3020 pCVArrayFormat = ReadConformance(pStubMsg, pCVArrayFormat + 2);
3022 pCVArrayFormat = ReadConformance(pStubMsg, NULL);
3025 ERR("invalid array format type %x\n", *pCVArrayFormat);
3026 RpcRaiseException(RPC_S_INTERNAL_ERROR);
3030 ALIGN_POINTER(pStubMsg->Buffer, pCVStructFormat->alignment + 1);
3032 TRACE("memory_size = %d\n", pCVStructFormat->memory_size);
3034 /* work out how much memory to allocate if we need to do so */
3035 if (!*ppMemory || fMustAlloc)
3037 SIZE_T size = pCVStructFormat->memory_size + pStubMsg->MaxCount * esize;
3038 *ppMemory = NdrAllocate(pStubMsg, size);
3041 /* copy the constant data */
3042 pStubMsg->BufferMark = pStubMsg->Buffer;
3043 memcpy(*ppMemory, pStubMsg->Buffer, pCVStructFormat->memory_size);
3044 pStubMsg->Buffer += pCVStructFormat->memory_size;
3046 pCVArrayFormat = ReadVariance(pStubMsg, pCVArrayFormat);
3048 /* copy the array data */
3049 memcpy(*ppMemory + pCVStructFormat->memory_size, pStubMsg->Buffer,
3050 pStubMsg->ActualCount * esize);
3051 pStubMsg->Buffer += pStubMsg->ActualCount * esize;
3053 if (cvarray_type == RPC_FC_C_CSTRING)
3054 TRACE("string=%s\n", debugstr_a((char *)(*ppMemory + pCVStructFormat->memory_size)));
3055 else if (cvarray_type == RPC_FC_C_WSTRING)
3056 TRACE("string=%s\n", debugstr_w((WCHAR *)(*ppMemory + pCVStructFormat->memory_size)));
3058 EmbeddedPointerUnmarshall(pStubMsg, ppMemory, pFormat, fMustAlloc);
3063 /***********************************************************************
3064 * NdrConformantVaryingStructBufferSize [RPCRT4.@]
3066 void WINAPI NdrConformantVaryingStructBufferSize(PMIDL_STUB_MESSAGE pStubMsg,
3067 unsigned char *pMemory,
3068 PFORMAT_STRING pFormat)
3070 const NDR_CVSTRUCT_FORMAT * pCVStructFormat = (NDR_CVSTRUCT_FORMAT*)pFormat;
3071 PFORMAT_STRING pCVArrayFormat;
3074 TRACE("(%p, %p, %p)\n", pStubMsg, pMemory, pFormat);
3076 pFormat += sizeof(NDR_CVSTRUCT_FORMAT);
3077 if (pCVStructFormat->type != RPC_FC_CVSTRUCT)
3079 ERR("invalid format type %x\n", pCVStructFormat->type);
3080 RpcRaiseException(RPC_S_INTERNAL_ERROR);
3084 pCVArrayFormat = (unsigned char*)&pCVStructFormat->offset_to_array_description +
3085 pCVStructFormat->offset_to_array_description;
3086 switch (*pCVArrayFormat)
3088 case RPC_FC_CVARRAY:
3089 esize = *(const WORD*)(pCVArrayFormat+2);
3091 pCVArrayFormat = ComputeConformance(pStubMsg, pMemory + pCVStructFormat->memory_size,
3092 pCVArrayFormat + 4, 0);
3093 pCVArrayFormat = ComputeVariance(pStubMsg, pMemory + pCVStructFormat->memory_size,
3094 pCVArrayFormat + 4, 0);
3096 case RPC_FC_C_CSTRING:
3097 TRACE("string=%s\n", debugstr_a((char*)pMemory + pCVStructFormat->memory_size));
3098 pStubMsg->ActualCount = strlen((char*)pMemory + pCVStructFormat->memory_size)+1;
3099 esize = sizeof(char);
3100 if (pCVArrayFormat[1] == RPC_FC_STRING_SIZED)
3101 pCVArrayFormat = ComputeConformance(pStubMsg, pMemory + pCVStructFormat->memory_size,
3102 pCVArrayFormat + 2, 0);
3104 pStubMsg->MaxCount = pStubMsg->ActualCount;
3106 case RPC_FC_C_WSTRING:
3107 TRACE("string=%s\n", debugstr_w((LPWSTR)pMemory + pCVStructFormat->memory_size));
3108 pStubMsg->ActualCount = strlenW((LPWSTR)pMemory + pCVStructFormat->memory_size)+1;
3109 esize = sizeof(WCHAR);
3110 if (pCVArrayFormat[1] == RPC_FC_STRING_SIZED)
3111 pCVArrayFormat = ComputeConformance(pStubMsg, pMemory + pCVStructFormat->memory_size,
3112 pCVArrayFormat + 2, 0);
3114 pStubMsg->MaxCount = pStubMsg->ActualCount;
3117 ERR("invalid array format type %x\n", *pCVArrayFormat);
3118 RpcRaiseException(RPC_S_INTERNAL_ERROR);
3122 SizeConformance(pStubMsg);
3124 ALIGN_LENGTH(pStubMsg->BufferLength, pCVStructFormat->alignment + 1);
3126 TRACE("memory_size = %d\n", pCVStructFormat->memory_size);
3128 pStubMsg->BufferLength += pCVStructFormat->memory_size;
3129 SizeVariance(pStubMsg);
3130 pStubMsg->BufferLength += esize * pStubMsg->MaxCount;
3132 EmbeddedPointerBufferSize(pStubMsg, pMemory, pFormat);
3135 /***********************************************************************
3136 * NdrConformantVaryingStructMemorySize [RPCRT4.@]
3138 unsigned long WINAPI NdrConformantVaryingStructMemorySize(PMIDL_STUB_MESSAGE pStubMsg,
3139 PFORMAT_STRING pFormat)
3141 const NDR_CVSTRUCT_FORMAT * pCVStructFormat = (NDR_CVSTRUCT_FORMAT*)pFormat;
3142 PFORMAT_STRING pCVArrayFormat;
3144 unsigned char cvarray_type;
3146 TRACE("(%p, %p)\n", pStubMsg, pFormat);
3148 pFormat += sizeof(NDR_CVSTRUCT_FORMAT);
3149 if (pCVStructFormat->type != RPC_FC_CVSTRUCT)
3151 ERR("invalid format type %x\n", pCVStructFormat->type);
3152 RpcRaiseException(RPC_S_INTERNAL_ERROR);
3156 pCVArrayFormat = (unsigned char*)&pCVStructFormat->offset_to_array_description +
3157 pCVStructFormat->offset_to_array_description;
3158 cvarray_type = *pCVArrayFormat;
3159 switch (cvarray_type)
3161 case RPC_FC_CVARRAY:
3162 esize = *(const WORD*)(pCVArrayFormat+2);
3163 pCVArrayFormat = ReadConformance(pStubMsg, pCVArrayFormat + 4);
3165 case RPC_FC_C_CSTRING:
3166 esize = sizeof(char);
3167 if (pCVArrayFormat[1] == RPC_FC_STRING_SIZED)
3168 pCVArrayFormat = ReadConformance(pStubMsg, pCVArrayFormat + 2);
3170 pCVArrayFormat = ReadConformance(pStubMsg, NULL);
3172 case RPC_FC_C_WSTRING:
3173 esize = sizeof(WCHAR);
3174 if (pCVArrayFormat[1] == RPC_FC_STRING_SIZED)
3175 pCVArrayFormat = ReadConformance(pStubMsg, pCVArrayFormat + 2);
3177 pCVArrayFormat = ReadConformance(pStubMsg, NULL);
3180 ERR("invalid array format type %x\n", *pCVArrayFormat);
3181 RpcRaiseException(RPC_S_INTERNAL_ERROR);
3185 ALIGN_POINTER(pStubMsg->Buffer, pCVStructFormat->alignment + 1);
3187 TRACE("memory_size = %d\n", pCVStructFormat->memory_size);
3189 pStubMsg->Buffer += pCVStructFormat->memory_size;
3190 pCVArrayFormat = ReadVariance(pStubMsg, pCVArrayFormat);
3191 pStubMsg->Buffer += pCVStructFormat->memory_size + pStubMsg->ActualCount * esize;
3193 pStubMsg->MemorySize += pCVStructFormat->memory_size + pStubMsg->MaxCount * esize;
3195 EmbeddedPointerMemorySize(pStubMsg, pFormat);
3197 return pCVStructFormat->memory_size + pStubMsg->MaxCount * esize;
3200 /***********************************************************************
3201 * NdrConformantVaryingStructFree [RPCRT4.@]
3203 void WINAPI NdrConformantVaryingStructFree(PMIDL_STUB_MESSAGE pStubMsg,
3204 unsigned char *pMemory,
3205 PFORMAT_STRING pFormat)
3207 const NDR_CVSTRUCT_FORMAT * pCVStructFormat = (NDR_CVSTRUCT_FORMAT*)pFormat;
3208 PFORMAT_STRING pCVArrayFormat;
3211 TRACE("(%p, %p, %p)\n", pStubMsg, pMemory, pFormat);
3213 pFormat += sizeof(NDR_CVSTRUCT_FORMAT);
3214 if (pCVStructFormat->type != RPC_FC_CVSTRUCT)
3216 ERR("invalid format type %x\n", pCVStructFormat->type);
3217 RpcRaiseException(RPC_S_INTERNAL_ERROR);
3221 pCVArrayFormat = (unsigned char*)&pCVStructFormat->offset_to_array_description +
3222 pCVStructFormat->offset_to_array_description;
3223 switch (*pCVArrayFormat)
3225 case RPC_FC_CVARRAY:
3226 esize = *(const WORD*)(pCVArrayFormat+2);
3228 pCVArrayFormat = ComputeConformance(pStubMsg, pMemory + pCVStructFormat->memory_size,
3229 pCVArrayFormat + 4, 0);
3230 pCVArrayFormat = ComputeVariance(pStubMsg, pMemory + pCVStructFormat->memory_size,
3233 case RPC_FC_C_CSTRING:
3234 TRACE("string=%s\n", debugstr_a((char*)pMemory + pCVStructFormat->memory_size));
3235 pStubMsg->ActualCount = strlen((char*)pMemory + pCVStructFormat->memory_size)+1;
3236 esize = sizeof(char);
3237 if (pCVArrayFormat[1] == RPC_FC_STRING_SIZED)
3238 pCVArrayFormat = ComputeConformance(pStubMsg, pMemory + pCVStructFormat->memory_size,
3239 pCVArrayFormat + 2, 0);
3241 pStubMsg->MaxCount = pStubMsg->ActualCount;
3243 case RPC_FC_C_WSTRING:
3244 TRACE("string=%s\n", debugstr_w((LPWSTR)pMemory + pCVStructFormat->memory_size));
3245 pStubMsg->ActualCount = strlenW((LPWSTR)pMemory + pCVStructFormat->memory_size)+1;
3246 esize = sizeof(WCHAR);
3247 if (pCVArrayFormat[1] == RPC_FC_STRING_SIZED)
3248 pCVArrayFormat = ComputeConformance(pStubMsg, pMemory + pCVStructFormat->memory_size,
3249 pCVArrayFormat + 2, 0);
3251 pStubMsg->MaxCount = pStubMsg->ActualCount;
3254 ERR("invalid array format type %x\n", *pCVArrayFormat);
3255 RpcRaiseException(RPC_S_INTERNAL_ERROR);
3259 TRACE("memory_size = %d\n", pCVStructFormat->memory_size);
3261 EmbeddedPointerFree(pStubMsg, pMemory, pFormat);
3267 unsigned char alignment;
3268 unsigned short total_size;
3269 } NDR_SMFARRAY_FORMAT;
3274 unsigned char alignment;
3275 unsigned long total_size;
3276 } NDR_LGFARRAY_FORMAT;
3278 /***********************************************************************
3279 * NdrFixedArrayMarshall [RPCRT4.@]
3281 unsigned char * WINAPI NdrFixedArrayMarshall(PMIDL_STUB_MESSAGE pStubMsg,
3282 unsigned char *pMemory,
3283 PFORMAT_STRING pFormat)
3285 const NDR_SMFARRAY_FORMAT *pSmFArrayFormat = (const NDR_SMFARRAY_FORMAT *)pFormat;
3286 unsigned long total_size;
3288 TRACE("(%p, %p, %p)\n", pStubMsg, pMemory, pFormat);
3290 if ((pSmFArrayFormat->type != RPC_FC_SMFARRAY) &&
3291 (pSmFArrayFormat->type != RPC_FC_LGFARRAY))
3293 ERR("invalid format type %x\n", pSmFArrayFormat->type);
3294 RpcRaiseException(RPC_S_INTERNAL_ERROR);
3298 ALIGN_POINTER(pStubMsg->Buffer, pSmFArrayFormat->alignment + 1);
3300 if (pSmFArrayFormat->type == RPC_FC_SMFARRAY)
3302 total_size = pSmFArrayFormat->total_size;
3303 pFormat = (unsigned char *)(pSmFArrayFormat + 1);
3307 const NDR_LGFARRAY_FORMAT *pLgFArrayFormat = (const NDR_LGFARRAY_FORMAT *)pFormat;
3308 total_size = pLgFArrayFormat->total_size;
3309 pFormat = (unsigned char *)(pLgFArrayFormat + 1);
3311 memcpy(pStubMsg->Buffer, pMemory, total_size);
3312 pStubMsg->Buffer += total_size;
3314 pFormat = EmbeddedPointerMarshall(pStubMsg, pMemory, pFormat);
3319 /***********************************************************************
3320 * NdrFixedArrayUnmarshall [RPCRT4.@]
3322 unsigned char * WINAPI NdrFixedArrayUnmarshall(PMIDL_STUB_MESSAGE pStubMsg,
3323 unsigned char **ppMemory,
3324 PFORMAT_STRING pFormat,
3325 unsigned char fMustAlloc)
3327 const NDR_SMFARRAY_FORMAT *pSmFArrayFormat = (const NDR_SMFARRAY_FORMAT *)pFormat;
3328 unsigned long total_size;
3330 TRACE("(%p, %p, %p, %d)\n", pStubMsg, ppMemory, pFormat, fMustAlloc);
3332 if ((pSmFArrayFormat->type != RPC_FC_SMFARRAY) &&
3333 (pSmFArrayFormat->type != RPC_FC_LGFARRAY))
3335 ERR("invalid format type %x\n", pSmFArrayFormat->type);
3336 RpcRaiseException(RPC_S_INTERNAL_ERROR);
3340 ALIGN_POINTER(pStubMsg->Buffer, pSmFArrayFormat->alignment + 1);
3342 if (pSmFArrayFormat->type == RPC_FC_SMFARRAY)
3344 total_size = pSmFArrayFormat->total_size;
3345 pFormat = (unsigned char *)(pSmFArrayFormat + 1);
3349 const NDR_LGFARRAY_FORMAT *pLgFArrayFormat = (const NDR_LGFARRAY_FORMAT *)pFormat;
3350 total_size = pLgFArrayFormat->total_size;
3351 pFormat = (unsigned char *)(pLgFArrayFormat + 1);
3354 if (fMustAlloc || !*ppMemory)
3355 *ppMemory = NdrAllocate(pStubMsg, total_size);
3356 memcpy(*ppMemory, pStubMsg->Buffer, total_size);
3357 pStubMsg->Buffer += total_size;
3359 pFormat = EmbeddedPointerUnmarshall(pStubMsg, ppMemory, pFormat, fMustAlloc);
3364 /***********************************************************************
3365 * NdrFixedArrayBufferSize [RPCRT4.@]
3367 void WINAPI NdrFixedArrayBufferSize(PMIDL_STUB_MESSAGE pStubMsg,
3368 unsigned char *pMemory,
3369 PFORMAT_STRING pFormat)
3371 const NDR_SMFARRAY_FORMAT *pSmFArrayFormat = (const NDR_SMFARRAY_FORMAT *)pFormat;
3372 unsigned long total_size;
3374 TRACE("(%p, %p, %p)\n", pStubMsg, pMemory, pFormat);
3376 if ((pSmFArrayFormat->type != RPC_FC_SMFARRAY) &&
3377 (pSmFArrayFormat->type != RPC_FC_LGFARRAY))
3379 ERR("invalid format type %x\n", pSmFArrayFormat->type);
3380 RpcRaiseException(RPC_S_INTERNAL_ERROR);
3384 ALIGN_LENGTH(pStubMsg->BufferLength, pSmFArrayFormat->alignment + 1);
3386 if (pSmFArrayFormat->type == RPC_FC_SMFARRAY)
3388 total_size = pSmFArrayFormat->total_size;
3389 pFormat = (unsigned char *)(pSmFArrayFormat + 1);
3393 const NDR_LGFARRAY_FORMAT *pLgFArrayFormat = (const NDR_LGFARRAY_FORMAT *)pFormat;
3394 total_size = pLgFArrayFormat->total_size;
3395 pFormat = (unsigned char *)(pLgFArrayFormat + 1);
3397 pStubMsg->BufferLength += total_size;
3399 EmbeddedPointerBufferSize(pStubMsg, pMemory, pFormat);
3402 /***********************************************************************
3403 * NdrFixedArrayMemorySize [RPCRT4.@]
3405 unsigned long WINAPI NdrFixedArrayMemorySize(PMIDL_STUB_MESSAGE pStubMsg,
3406 PFORMAT_STRING pFormat)
3408 const NDR_SMFARRAY_FORMAT *pSmFArrayFormat = (const NDR_SMFARRAY_FORMAT *)pFormat;
3409 unsigned long total_size;
3411 TRACE("(%p, %p)\n", pStubMsg, pFormat);
3413 if ((pSmFArrayFormat->type != RPC_FC_SMFARRAY) &&
3414 (pSmFArrayFormat->type != RPC_FC_LGFARRAY))
3416 ERR("invalid format type %x\n", pSmFArrayFormat->type);
3417 RpcRaiseException(RPC_S_INTERNAL_ERROR);
3421 ALIGN_POINTER(pStubMsg->Buffer, pSmFArrayFormat->alignment + 1);
3423 if (pSmFArrayFormat->type == RPC_FC_SMFARRAY)
3425 total_size = pSmFArrayFormat->total_size;
3426 pFormat = (unsigned char *)(pSmFArrayFormat + 1);
3430 const NDR_LGFARRAY_FORMAT *pLgFArrayFormat = (const NDR_LGFARRAY_FORMAT *)pFormat;
3431 total_size = pLgFArrayFormat->total_size;
3432 pFormat = (unsigned char *)(pLgFArrayFormat + 1);
3434 pStubMsg->Buffer += total_size;
3435 pStubMsg->MemorySize += total_size;
3437 EmbeddedPointerMemorySize(pStubMsg, pFormat);
3442 /***********************************************************************
3443 * NdrFixedArrayFree [RPCRT4.@]
3445 void WINAPI NdrFixedArrayFree(PMIDL_STUB_MESSAGE pStubMsg,
3446 unsigned char *pMemory,
3447 PFORMAT_STRING pFormat)
3449 const NDR_SMFARRAY_FORMAT *pSmFArrayFormat = (const NDR_SMFARRAY_FORMAT *)pFormat;
3451 TRACE("(%p, %p, %p)\n", pStubMsg, pMemory, pFormat);
3453 if ((pSmFArrayFormat->type != RPC_FC_SMFARRAY) &&
3454 (pSmFArrayFormat->type != RPC_FC_LGFARRAY))
3456 ERR("invalid format type %x\n", pSmFArrayFormat->type);
3457 RpcRaiseException(RPC_S_INTERNAL_ERROR);
3461 if (pSmFArrayFormat->type == RPC_FC_SMFARRAY)
3462 pFormat = (unsigned char *)(pSmFArrayFormat + 1);
3465 const NDR_LGFARRAY_FORMAT *pLgFArrayFormat = (const NDR_LGFARRAY_FORMAT *)pFormat;
3466 pFormat = (unsigned char *)(pLgFArrayFormat + 1);
3469 EmbeddedPointerFree(pStubMsg, pMemory, pFormat);
3472 /***********************************************************************
3473 * NdrVaryingArrayMarshall [RPCRT4.@]
3475 unsigned char * WINAPI NdrVaryingArrayMarshall(PMIDL_STUB_MESSAGE pStubMsg,
3476 unsigned char *pMemory,
3477 PFORMAT_STRING pFormat)
3483 /***********************************************************************
3484 * NdrVaryingArrayUnmarshall [RPCRT4.@]
3486 unsigned char * WINAPI NdrVaryingArrayUnmarshall(PMIDL_STUB_MESSAGE pStubMsg,
3487 unsigned char **ppMemory,
3488 PFORMAT_STRING pFormat,
3489 unsigned char fMustAlloc)
3495 /***********************************************************************
3496 * NdrVaryingArrayBufferSize [RPCRT4.@]
3498 void WINAPI NdrVaryingArrayBufferSize(PMIDL_STUB_MESSAGE pStubMsg,
3499 unsigned char *pMemory,
3500 PFORMAT_STRING pFormat)
3505 /***********************************************************************
3506 * NdrVaryingArrayMemorySize [RPCRT4.@]
3508 unsigned long WINAPI NdrVaryingArrayMemorySize(PMIDL_STUB_MESSAGE pStubMsg,
3509 PFORMAT_STRING pFormat)
3515 /***********************************************************************
3516 * NdrVaryingArrayFree [RPCRT4.@]
3518 void WINAPI NdrVaryingArrayFree(PMIDL_STUB_MESSAGE pStubMsg,
3519 unsigned char *pMemory,
3520 PFORMAT_STRING pFormat)
3525 /***********************************************************************
3526 * NdrEncapsulatedUnionMarshall [RPCRT4.@]
3528 unsigned char * WINAPI NdrEncapsulatedUnionMarshall(PMIDL_STUB_MESSAGE pStubMsg,
3529 unsigned char *pMemory,
3530 PFORMAT_STRING pFormat)
3536 /***********************************************************************
3537 * NdrEncapsulatedUnionUnmarshall [RPCRT4.@]
3539 unsigned char * WINAPI NdrEncapsulatedUnionUnmarshall(PMIDL_STUB_MESSAGE pStubMsg,
3540 unsigned char **ppMemory,
3541 PFORMAT_STRING pFormat,
3542 unsigned char fMustAlloc)
3548 /***********************************************************************
3549 * NdrEncapsulatedUnionBufferSize [RPCRT4.@]
3551 void WINAPI NdrEncapsulatedUnionBufferSize(PMIDL_STUB_MESSAGE pStubMsg,
3552 unsigned char *pMemory,
3553 PFORMAT_STRING pFormat)
3558 /***********************************************************************
3559 * NdrEncapsulatedUnionMemorySize [RPCRT4.@]
3561 unsigned long WINAPI NdrEncapsulatedUnionMemorySize(PMIDL_STUB_MESSAGE pStubMsg,
3562 PFORMAT_STRING pFormat)
3568 /***********************************************************************
3569 * NdrEncapsulatedUnionFree [RPCRT4.@]
3571 void WINAPI NdrEncapsulatedUnionFree(PMIDL_STUB_MESSAGE pStubMsg,
3572 unsigned char *pMemory,
3573 PFORMAT_STRING pFormat)
3578 static PFORMAT_STRING get_arm_offset_from_union_arm_selector(PMIDL_STUB_MESSAGE pStubMsg,
3579 unsigned long discriminant,
3580 PFORMAT_STRING pFormat)
3582 unsigned short num_arms, arm, type;
3584 num_arms = *(const SHORT*)pFormat & 0x0fff;
3586 for(arm = 0; arm < num_arms; arm++)
3588 if(discriminant == *(const ULONG*)pFormat)
3596 type = *(const unsigned short*)pFormat;
3597 TRACE("type %04x\n", type);
3598 if(arm == num_arms) /* default arm extras */
3602 ERR("no arm for 0x%lx and no default case\n", discriminant);
3603 RpcRaiseException(RPC_S_INVALID_TAG);
3608 TRACE("falling back to empty default case for 0x%lx\n", discriminant);
3615 static PFORMAT_STRING get_non_encapsulated_union_arm(PMIDL_STUB_MESSAGE pStubMsg,
3617 PFORMAT_STRING pFormat)
3619 pFormat += *(const SHORT*)pFormat;
3622 return get_arm_offset_from_union_arm_selector(pStubMsg, value, pFormat);
3625 /***********************************************************************
3626 * NdrNonEncapsulatedUnionMarshall [RPCRT4.@]
3628 unsigned char * WINAPI NdrNonEncapsulatedUnionMarshall(PMIDL_STUB_MESSAGE pStubMsg,
3629 unsigned char *pMemory,
3630 PFORMAT_STRING pFormat)
3632 unsigned short type;
3633 unsigned char switch_type;
3635 TRACE("(%p, %p, %p)\n", pStubMsg, pMemory, pFormat);
3638 switch_type = *pFormat;
3641 pFormat = ComputeConformance(pStubMsg, pMemory, pFormat, 0);
3642 TRACE("got switch value 0x%lx\n", pStubMsg->MaxCount);
3643 /* Marshall discriminant */
3644 NdrBaseTypeMarshall(pStubMsg, (unsigned char *)&pStubMsg->MaxCount, &switch_type);
3646 pFormat = get_non_encapsulated_union_arm(pStubMsg, pStubMsg->MaxCount, pFormat);
3650 type = *(const unsigned short*)pFormat;
3651 if((type & 0xff00) == 0x8000)
3653 unsigned char basetype = LOBYTE(type);
3654 return NdrBaseTypeMarshall(pStubMsg, pMemory, &basetype);
3658 PFORMAT_STRING desc = pFormat + *(const SHORT*)pFormat;
3659 NDR_MARSHALL m = NdrMarshaller[*desc & NDR_TABLE_MASK];
3662 unsigned char *saved_buffer = NULL;
3669 saved_buffer = pStubMsg->Buffer;
3670 pStubMsg->Buffer += 4; /* for pointer ID */
3671 PointerMarshall(pStubMsg, saved_buffer, *(unsigned char **)pMemory, desc);
3674 m(pStubMsg, pMemory, desc);
3677 else FIXME("no marshaller for embedded type %02x\n", *desc);
3682 static long unmarshall_discriminant(PMIDL_STUB_MESSAGE pStubMsg,
3683 PFORMAT_STRING *ppFormat)
3685 long discriminant = 0;
3693 discriminant = *(UCHAR *)pStubMsg->Buffer;
3694 pStubMsg->Buffer += sizeof(UCHAR);
3699 ALIGN_POINTER(pStubMsg->Buffer, sizeof(USHORT));
3700 discriminant = *(USHORT *)pStubMsg->Buffer;
3701 pStubMsg->Buffer += sizeof(USHORT);
3705 ALIGN_POINTER(pStubMsg->Buffer, sizeof(ULONG));
3706 discriminant = *(ULONG *)pStubMsg->Buffer;
3707 pStubMsg->Buffer += sizeof(ULONG);
3710 FIXME("Unhandled base type: 0x%02x\n", **ppFormat);
3714 if (pStubMsg->fHasNewCorrDesc)
3718 return discriminant;
3721 /**********************************************************************
3722 * NdrNonEncapsulatedUnionUnmarshall[RPCRT4.@]
3724 unsigned char * WINAPI NdrNonEncapsulatedUnionUnmarshall(PMIDL_STUB_MESSAGE pStubMsg,
3725 unsigned char **ppMemory,
3726 PFORMAT_STRING pFormat,
3727 unsigned char fMustAlloc)
3730 unsigned short type, size;
3732 TRACE("(%p, %p, %p, %d)\n", pStubMsg, ppMemory, pFormat, fMustAlloc);
3735 /* Unmarshall discriminant */
3736 discriminant = unmarshall_discriminant(pStubMsg, &pFormat);
3737 TRACE("unmarshalled discriminant %lx\n", discriminant);
3739 pFormat += *(const SHORT*)pFormat;
3741 size = *(const unsigned short*)pFormat;
3744 pFormat = get_arm_offset_from_union_arm_selector(pStubMsg, discriminant, pFormat);
3748 if(!*ppMemory || fMustAlloc)
3749 *ppMemory = NdrAllocate(pStubMsg, size);
3751 type = *(const unsigned short*)pFormat;
3752 if((type & 0xff00) == 0x8000)
3754 unsigned char basetype = LOBYTE(type);
3755 return NdrBaseTypeUnmarshall(pStubMsg, ppMemory, &basetype, fMustAlloc);
3759 PFORMAT_STRING desc = pFormat + *(const SHORT*)pFormat;
3760 NDR_UNMARSHALL m = NdrUnmarshaller[*desc & NDR_TABLE_MASK];
3763 unsigned char *saved_buffer = NULL;
3770 **(void***)ppMemory = NULL;
3771 ALIGN_POINTER(pStubMsg->Buffer, 4);
3772 saved_buffer = pStubMsg->Buffer;
3773 pStubMsg->Buffer += 4; /* for pointer ID */
3774 PointerUnmarshall(pStubMsg, saved_buffer, *(unsigned char ***)ppMemory, desc, fMustAlloc);
3777 m(pStubMsg, ppMemory, desc, fMustAlloc);
3780 else FIXME("no marshaller for embedded type %02x\n", *desc);
3785 /***********************************************************************
3786 * NdrNonEncapsulatedUnionBufferSize [RPCRT4.@]
3788 void WINAPI NdrNonEncapsulatedUnionBufferSize(PMIDL_STUB_MESSAGE pStubMsg,
3789 unsigned char *pMemory,
3790 PFORMAT_STRING pFormat)
3792 unsigned short type;
3793 unsigned char switch_type;
3795 TRACE("(%p, %p, %p)\n", pStubMsg, pMemory, pFormat);
3798 switch_type = *pFormat;
3801 pFormat = ComputeConformance(pStubMsg, pMemory, pFormat, 0);
3802 TRACE("got switch value 0x%lx\n", pStubMsg->MaxCount);
3803 /* Add discriminant size */
3804 NdrBaseTypeBufferSize(pStubMsg, (unsigned char *)&pStubMsg->MaxCount, &switch_type);
3806 pFormat = get_non_encapsulated_union_arm(pStubMsg, pStubMsg->MaxCount, pFormat);
3810 type = *(const unsigned short*)pFormat;
3811 if((type & 0xff00) == 0x8000)
3813 unsigned char basetype = LOBYTE(type);
3814 NdrBaseTypeBufferSize(pStubMsg, pMemory, &basetype);
3818 PFORMAT_STRING desc = pFormat + *(const SHORT*)pFormat;
3819 NDR_BUFFERSIZE m = NdrBufferSizer[*desc & NDR_TABLE_MASK];
3828 ALIGN_LENGTH(pStubMsg->BufferLength, 4);
3829 pStubMsg->BufferLength += 4; /* for pointer ID */
3830 PointerBufferSize(pStubMsg, *(unsigned char **)pMemory, desc);
3833 m(pStubMsg, pMemory, desc);
3836 else FIXME("no buffersizer for embedded type %02x\n", *desc);
3841 /***********************************************************************
3842 * NdrNonEncapsulatedUnionMemorySize [RPCRT4.@]
3844 unsigned long WINAPI NdrNonEncapsulatedUnionMemorySize(PMIDL_STUB_MESSAGE pStubMsg,
3845 PFORMAT_STRING pFormat)
3847 unsigned long discriminant;
3848 unsigned short type, size;
3851 /* Unmarshall discriminant */
3852 discriminant = unmarshall_discriminant(pStubMsg, &pFormat);
3853 TRACE("unmarshalled discriminant 0x%lx\n", discriminant);
3855 pFormat += *(const SHORT*)pFormat;
3857 size = *(const unsigned short*)pFormat;
3860 pFormat = get_arm_offset_from_union_arm_selector(pStubMsg, discriminant, pFormat);
3864 pStubMsg->Memory += size;
3866 type = *(const unsigned short*)pFormat;
3867 if((type & 0xff00) == 0x8000)
3869 return NdrBaseTypeMemorySize(pStubMsg, pFormat);
3873 PFORMAT_STRING desc = pFormat + *(const SHORT*)pFormat;
3874 NDR_MEMORYSIZE m = NdrMemorySizer[*desc & NDR_TABLE_MASK];
3875 unsigned char *saved_buffer;
3884 ALIGN_POINTER(pStubMsg->Buffer, 4);
3885 saved_buffer = pStubMsg->Buffer;
3886 pStubMsg->Buffer += 4;
3887 ALIGN_LENGTH(pStubMsg->MemorySize, 4);
3888 pStubMsg->MemorySize += 4;
3889 PointerMemorySize(pStubMsg, saved_buffer, pFormat);
3892 return m(pStubMsg, desc);
3895 else FIXME("no marshaller for embedded type %02x\n", *desc);
3898 TRACE("size %d\n", size);
3902 /***********************************************************************
3903 * NdrNonEncapsulatedUnionFree [RPCRT4.@]
3905 void WINAPI NdrNonEncapsulatedUnionFree(PMIDL_STUB_MESSAGE pStubMsg,
3906 unsigned char *pMemory,
3907 PFORMAT_STRING pFormat)
3912 /***********************************************************************
3913 * NdrByteCountPointerMarshall [RPCRT4.@]
3915 unsigned char * WINAPI NdrByteCountPointerMarshall(PMIDL_STUB_MESSAGE pStubMsg,
3916 unsigned char *pMemory,
3917 PFORMAT_STRING pFormat)
3923 /***********************************************************************
3924 * NdrByteCountPointerUnmarshall [RPCRT4.@]
3926 unsigned char * WINAPI NdrByteCountPointerUnmarshall(PMIDL_STUB_MESSAGE pStubMsg,
3927 unsigned char **ppMemory,
3928 PFORMAT_STRING pFormat,
3929 unsigned char fMustAlloc)
3935 /***********************************************************************
3936 * NdrByteCountPointerBufferSize [RPCRT4.@]
3938 void WINAPI NdrByteCountPointerBufferSize(PMIDL_STUB_MESSAGE pStubMsg,
3939 unsigned char *pMemory,
3940 PFORMAT_STRING pFormat)
3945 /***********************************************************************
3946 * NdrByteCountPointerMemorySize [RPCRT4.@]
3948 unsigned long WINAPI NdrByteCountPointerMemorySize(PMIDL_STUB_MESSAGE pStubMsg,
3949 PFORMAT_STRING pFormat)
3955 /***********************************************************************
3956 * NdrByteCountPointerFree [RPCRT4.@]
3958 void WINAPI NdrByteCountPointerFree(PMIDL_STUB_MESSAGE pStubMsg,
3959 unsigned char *pMemory,
3960 PFORMAT_STRING pFormat)
3965 /***********************************************************************
3966 * NdrXmitOrRepAsMarshall [RPCRT4.@]
3968 unsigned char * WINAPI NdrXmitOrRepAsMarshall(PMIDL_STUB_MESSAGE pStubMsg,
3969 unsigned char *pMemory,
3970 PFORMAT_STRING pFormat)
3976 /***********************************************************************
3977 * NdrXmitOrRepAsUnmarshall [RPCRT4.@]
3979 unsigned char * WINAPI NdrXmitOrRepAsUnmarshall(PMIDL_STUB_MESSAGE pStubMsg,
3980 unsigned char **ppMemory,
3981 PFORMAT_STRING pFormat,
3982 unsigned char fMustAlloc)
3988 /***********************************************************************
3989 * NdrXmitOrRepAsBufferSize [RPCRT4.@]
3991 void WINAPI NdrXmitOrRepAsBufferSize(PMIDL_STUB_MESSAGE pStubMsg,
3992 unsigned char *pMemory,
3993 PFORMAT_STRING pFormat)
3998 /***********************************************************************
3999 * NdrXmitOrRepAsMemorySize [RPCRT4.@]
4001 unsigned long WINAPI NdrXmitOrRepAsMemorySize(PMIDL_STUB_MESSAGE pStubMsg,
4002 PFORMAT_STRING pFormat)
4008 /***********************************************************************
4009 * NdrXmitOrRepAsFree [RPCRT4.@]
4011 void WINAPI NdrXmitOrRepAsFree(PMIDL_STUB_MESSAGE pStubMsg,
4012 unsigned char *pMemory,
4013 PFORMAT_STRING pFormat)
4018 /***********************************************************************
4019 * NdrBaseTypeMarshall [internal]
4021 static unsigned char *WINAPI NdrBaseTypeMarshall(
4022 PMIDL_STUB_MESSAGE pStubMsg,
4023 unsigned char *pMemory,
4024 PFORMAT_STRING pFormat)
4026 TRACE("pStubMsg %p, pMemory %p, type 0x%02x\n", pStubMsg, pMemory, *pFormat);
4034 *(UCHAR *)pStubMsg->Buffer = *(UCHAR *)pMemory;
4035 pStubMsg->Buffer += sizeof(UCHAR);
4036 TRACE("value: 0x%02x\n", *(UCHAR *)pMemory);
4041 ALIGN_POINTER(pStubMsg->Buffer, sizeof(USHORT));
4042 *(USHORT *)pStubMsg->Buffer = *(USHORT *)pMemory;
4043 pStubMsg->Buffer += sizeof(USHORT);
4044 TRACE("value: 0x%04x\n", *(USHORT *)pMemory);
4048 case RPC_FC_ERROR_STATUS_T:
4050 ALIGN_POINTER(pStubMsg->Buffer, sizeof(ULONG));
4051 *(ULONG *)pStubMsg->Buffer = *(ULONG *)pMemory;
4052 pStubMsg->Buffer += sizeof(ULONG);
4053 TRACE("value: 0x%08lx\n", *(ULONG *)pMemory);
4056 ALIGN_POINTER(pStubMsg->Buffer, sizeof(float));
4057 *(float *)pStubMsg->Buffer = *(float *)pMemory;
4058 pStubMsg->Buffer += sizeof(float);
4061 ALIGN_POINTER(pStubMsg->Buffer, sizeof(double));
4062 *(double *)pStubMsg->Buffer = *(double *)pMemory;
4063 pStubMsg->Buffer += sizeof(double);
4066 ALIGN_POINTER(pStubMsg->Buffer, sizeof(ULONGLONG));
4067 *(ULONGLONG *)pStubMsg->Buffer = *(ULONGLONG *)pMemory;
4068 pStubMsg->Buffer += sizeof(ULONGLONG);
4069 TRACE("value: %s\n", wine_dbgstr_longlong(*(ULONGLONG*)pMemory));
4072 /* only 16-bits on the wire, so do a sanity check */
4073 if (*(UINT *)pMemory > USHRT_MAX)
4074 RpcRaiseException(RPC_X_ENUM_VALUE_OUT_OF_RANGE);
4075 ALIGN_POINTER(pStubMsg->Buffer, sizeof(USHORT));
4076 *(USHORT *)pStubMsg->Buffer = *(UINT *)pMemory;
4077 pStubMsg->Buffer += sizeof(USHORT);
4078 TRACE("value: 0x%04x\n", *(UINT *)pMemory);
4081 FIXME("Unhandled base type: 0x%02x\n", *pFormat);
4084 STD_OVERFLOW_CHECK(pStubMsg);
4086 /* FIXME: what is the correct return value? */
4090 /***********************************************************************
4091 * NdrBaseTypeUnmarshall [internal]
4093 static unsigned char *WINAPI NdrBaseTypeUnmarshall(
4094 PMIDL_STUB_MESSAGE pStubMsg,
4095 unsigned char **ppMemory,
4096 PFORMAT_STRING pFormat,
4097 unsigned char fMustAlloc)
4099 TRACE("pStubMsg: %p, ppMemory: %p, type: 0x%02x, fMustAlloc: %s\n", pStubMsg, ppMemory, *pFormat, fMustAlloc ? "true" : "false");
4101 if (fMustAlloc || !*ppMemory)
4103 unsigned char *Buffer = pStubMsg->Buffer;
4104 unsigned long MemorySize = pStubMsg->MemorySize;
4105 *ppMemory = NdrAllocate(pStubMsg, NdrBaseTypeMemorySize(pStubMsg, pFormat));
4106 pStubMsg->MemorySize = MemorySize;
4107 pStubMsg->Buffer = Buffer;
4110 TRACE("*ppMemory: %p\n", *ppMemory);
4118 **(UCHAR **)ppMemory = *(UCHAR *)pStubMsg->Buffer;
4119 pStubMsg->Buffer += sizeof(UCHAR);
4120 TRACE("value: 0x%02x\n", **(UCHAR **)ppMemory);
4125 ALIGN_POINTER(pStubMsg->Buffer, sizeof(USHORT));
4126 **(USHORT **)ppMemory = *(USHORT *)pStubMsg->Buffer;
4127 pStubMsg->Buffer += sizeof(USHORT);
4128 TRACE("value: 0x%04x\n", **(USHORT **)ppMemory);
4132 case RPC_FC_ERROR_STATUS_T:
4134 ALIGN_POINTER(pStubMsg->Buffer, sizeof(ULONG));
4135 **(ULONG **)ppMemory = *(ULONG *)pStubMsg->Buffer;
4136 pStubMsg->Buffer += sizeof(ULONG);
4137 TRACE("value: 0x%08lx\n", **(ULONG **)ppMemory);
4140 ALIGN_POINTER(pStubMsg->Buffer, sizeof(float));
4141 **(float **)ppMemory = *(float *)pStubMsg->Buffer;
4142 pStubMsg->Buffer += sizeof(float);
4143 TRACE("value: %f\n", **(float **)ppMemory);
4146 ALIGN_POINTER(pStubMsg->Buffer, sizeof(double));
4147 **(double **)ppMemory = *(double*)pStubMsg->Buffer;
4148 pStubMsg->Buffer += sizeof(double);
4149 TRACE("value: %f\n", **(double **)ppMemory);
4152 ALIGN_POINTER(pStubMsg->Buffer, sizeof(ULONGLONG));
4153 **(ULONGLONG **)ppMemory = *(ULONGLONG *)pStubMsg->Buffer;
4154 pStubMsg->Buffer += sizeof(ULONGLONG);
4155 TRACE("value: %s\n", wine_dbgstr_longlong(**(ULONGLONG **)ppMemory));
4158 ALIGN_POINTER(pStubMsg->Buffer, sizeof(USHORT));
4159 /* 16-bits on the wire, but int in memory */
4160 **(UINT **)ppMemory = *(USHORT *)pStubMsg->Buffer;
4161 pStubMsg->Buffer += sizeof(USHORT);
4162 TRACE("value: 0x%08x\n", **(UINT **)ppMemory);
4165 FIXME("Unhandled base type: 0x%02x\n", *pFormat);
4168 /* FIXME: what is the correct return value? */
4173 /***********************************************************************
4174 * NdrBaseTypeBufferSize [internal]
4176 static void WINAPI NdrBaseTypeBufferSize(
4177 PMIDL_STUB_MESSAGE pStubMsg,
4178 unsigned char *pMemory,
4179 PFORMAT_STRING pFormat)
4181 TRACE("pStubMsg %p, pMemory %p, type 0x%02x\n", pStubMsg, pMemory, *pFormat);
4189 pStubMsg->BufferLength += sizeof(UCHAR);
4195 ALIGN_LENGTH(pStubMsg->BufferLength, sizeof(USHORT));
4196 pStubMsg->BufferLength += sizeof(USHORT);
4201 ALIGN_LENGTH(pStubMsg->BufferLength, sizeof(ULONG));
4202 pStubMsg->BufferLength += sizeof(ULONG);
4205 ALIGN_LENGTH(pStubMsg->BufferLength, sizeof(float));
4206 pStubMsg->BufferLength += sizeof(float);
4209 ALIGN_LENGTH(pStubMsg->BufferLength, sizeof(double));
4210 pStubMsg->BufferLength += sizeof(double);
4213 ALIGN_LENGTH(pStubMsg->BufferLength, sizeof(ULONGLONG));
4214 pStubMsg->BufferLength += sizeof(ULONGLONG);
4216 case RPC_FC_ERROR_STATUS_T:
4217 ALIGN_LENGTH(pStubMsg->BufferLength, sizeof(error_status_t));
4218 pStubMsg->BufferLength += sizeof(error_status_t);
4221 FIXME("Unhandled base type: 0x%02x\n", *pFormat);
4225 /***********************************************************************
4226 * NdrBaseTypeMemorySize [internal]
4228 static unsigned long WINAPI NdrBaseTypeMemorySize(
4229 PMIDL_STUB_MESSAGE pStubMsg,
4230 PFORMAT_STRING pFormat)
4238 pStubMsg->Buffer += sizeof(UCHAR);
4239 pStubMsg->MemorySize += sizeof(UCHAR);
4240 return sizeof(UCHAR);
4244 pStubMsg->Buffer += sizeof(USHORT);
4245 pStubMsg->MemorySize += sizeof(USHORT);
4246 return sizeof(USHORT);
4249 pStubMsg->Buffer += sizeof(ULONG);
4250 pStubMsg->MemorySize += sizeof(ULONG);
4251 return sizeof(ULONG);
4253 pStubMsg->Buffer += sizeof(float);
4254 pStubMsg->MemorySize += sizeof(float);
4255 return sizeof(float);
4257 pStubMsg->Buffer += sizeof(double);
4258 pStubMsg->MemorySize += sizeof(double);
4259 return sizeof(double);
4261 pStubMsg->Buffer += sizeof(ULONGLONG);
4262 pStubMsg->MemorySize += sizeof(ULONGLONG);
4263 return sizeof(ULONGLONG);
4264 case RPC_FC_ERROR_STATUS_T:
4265 pStubMsg->Buffer += sizeof(error_status_t);
4266 pStubMsg->MemorySize += sizeof(error_status_t);
4267 return sizeof(error_status_t);
4270 pStubMsg->Buffer += sizeof(INT);
4271 pStubMsg->MemorySize += sizeof(INT);
4274 FIXME("Unhandled base type: 0x%02x\n", *pFormat);
4279 /***********************************************************************
4280 * NdrBaseTypeFree [internal]
4282 static void WINAPI NdrBaseTypeFree(PMIDL_STUB_MESSAGE pStubMsg,
4283 unsigned char *pMemory,
4284 PFORMAT_STRING pFormat)
4286 TRACE("pStubMsg %p pMemory %p type 0x%02x\n", pStubMsg, pMemory, *pFormat);
4291 /***********************************************************************
4292 * NdrClientContextMarshall
4294 void WINAPI NdrClientContextMarshall(PMIDL_STUB_MESSAGE pStubMsg,
4295 NDR_CCONTEXT ContextHandle,
4298 FIXME("(%p, %p, %d): stub\n", pStubMsg, ContextHandle, fCheck);
4301 /***********************************************************************
4302 * NdrClientContextUnmarshall
4304 void WINAPI NdrClientContextUnmarshall(PMIDL_STUB_MESSAGE pStubMsg,
4305 NDR_CCONTEXT * pContextHandle,
4306 RPC_BINDING_HANDLE BindHandle)
4308 FIXME("(%p, %p, %p): stub\n", pStubMsg, pContextHandle, BindHandle);
4311 void WINAPI NdrServerContextMarshall(PMIDL_STUB_MESSAGE pStubMsg,
4312 NDR_SCONTEXT ContextHandle,
4313 NDR_RUNDOWN RundownRoutine )
4315 FIXME("(%p, %p, %p): stub\n", pStubMsg, ContextHandle, RundownRoutine);
4318 NDR_SCONTEXT WINAPI NdrServerContextUnmarshall(PMIDL_STUB_MESSAGE pStubMsg)
4320 FIXME("(%p): stub\n", pStubMsg);
4324 void WINAPI NdrContextHandleSize(PMIDL_STUB_MESSAGE pStubMsg,
4325 unsigned char* pMemory,
4326 PFORMAT_STRING pFormat)
4328 FIXME("(%p, %p, %p): stub\n", pStubMsg, pMemory, pFormat);
4331 NDR_SCONTEXT WINAPI NdrContextHandleInitialize(PMIDL_STUB_MESSAGE pStubMsg,
4332 PFORMAT_STRING pFormat)
4334 FIXME("(%p, %p): stub\n", pStubMsg, pFormat);
4338 void WINAPI NdrServerContextNewMarshall(PMIDL_STUB_MESSAGE pStubMsg,
4339 NDR_SCONTEXT ContextHandle,
4340 NDR_RUNDOWN RundownRoutine,
4341 PFORMAT_STRING pFormat)
4343 FIXME("(%p, %p, %p, %p): stub\n", pStubMsg, ContextHandle, RundownRoutine, pFormat);
4346 NDR_SCONTEXT WINAPI NdrServerContextNewUnmarshall(PMIDL_STUB_MESSAGE pStubMsg,
4347 PFORMAT_STRING pFormat)
4349 FIXME("(%p, %p): stub\n", pStubMsg, pFormat);
4353 RPC_BINDING_HANDLE WINAPI NDRCContextBinding(NDR_CCONTEXT CContext)
4355 FIXME("(%p): stub\n", CContext);