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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, 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 static 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);
825 if (!fMustAlloc && *pPointer)
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 unsigned char *saved_memory = pStubMsg->Memory;
1046 pStubMsg->Memory = pMemory;
1047 PointerMarshall(pStubMsg, bufptr, *(unsigned char**)memptr, info+4);
1048 pStubMsg->Memory = saved_memory;
1051 pFormat += 8 * count;
1054 STD_OVERFLOW_CHECK(pStubMsg);
1059 /***********************************************************************
1060 * EmbeddedPointerUnmarshall
1062 static unsigned char * EmbeddedPointerUnmarshall(PMIDL_STUB_MESSAGE pStubMsg,
1063 unsigned char **ppMemory,
1064 PFORMAT_STRING pFormat,
1065 unsigned char fMustAlloc)
1067 unsigned char *Mark = pStubMsg->BufferMark;
1068 unsigned long Offset = pStubMsg->Offset;
1069 unsigned ofs, rep, count, stride, xofs;
1072 TRACE("(%p,%p,%p,%d)\n", pStubMsg, ppMemory, pFormat, fMustAlloc);
1074 if (*pFormat != RPC_FC_PP) return NULL;
1077 while (pFormat[0] != RPC_FC_END) {
1078 TRACE("pFormat[0] = 0x%x\n", pFormat[0]);
1079 switch (pFormat[0]) {
1081 FIXME("unknown repeat type %d\n", pFormat[0]);
1082 case RPC_FC_NO_REPEAT:
1090 case RPC_FC_FIXED_REPEAT:
1091 rep = *(const WORD*)&pFormat[2];
1092 stride = *(const WORD*)&pFormat[4];
1093 ofs = *(const WORD*)&pFormat[6];
1094 count = *(const WORD*)&pFormat[8];
1098 case RPC_FC_VARIABLE_REPEAT:
1099 rep = pStubMsg->MaxCount;
1100 stride = *(const WORD*)&pFormat[2];
1101 ofs = *(const WORD*)&pFormat[4];
1102 count = *(const WORD*)&pFormat[6];
1103 xofs = (pFormat[1] == RPC_FC_VARIABLE_OFFSET) ? Offset * stride : 0;
1107 /* ofs doesn't seem to matter in this context */
1108 for (i = 0; i < rep; i++) {
1109 PFORMAT_STRING info = pFormat;
1110 unsigned char *membase = *ppMemory + (i * stride);
1111 unsigned char *bufbase = Mark + (i * stride);
1113 for (u=0; u<count; u++,info+=8) {
1114 unsigned char *memptr = membase + *(const SHORT*)&info[0];
1115 unsigned char *bufptr = bufbase + *(const SHORT*)&info[2];
1116 PointerUnmarshall(pStubMsg, bufptr, (unsigned char**)memptr, info+4, TRUE);
1119 pFormat += 8 * count;
1125 /***********************************************************************
1126 * EmbeddedPointerBufferSize
1128 static void EmbeddedPointerBufferSize(PMIDL_STUB_MESSAGE pStubMsg,
1129 unsigned char *pMemory,
1130 PFORMAT_STRING pFormat)
1132 unsigned long Offset = pStubMsg->Offset;
1133 unsigned ofs, rep, count, stride, xofs;
1136 TRACE("(%p,%p,%p)\n", pStubMsg, pMemory, pFormat);
1138 if (pStubMsg->IgnoreEmbeddedPointers) return;
1140 if (*pFormat != RPC_FC_PP) return;
1143 while (pFormat[0] != RPC_FC_END) {
1144 switch (pFormat[0]) {
1146 FIXME("unknown repeat type %d\n", pFormat[0]);
1147 case RPC_FC_NO_REPEAT:
1155 case RPC_FC_FIXED_REPEAT:
1156 rep = *(const WORD*)&pFormat[2];
1157 stride = *(const WORD*)&pFormat[4];
1158 ofs = *(const WORD*)&pFormat[6];
1159 count = *(const WORD*)&pFormat[8];
1163 case RPC_FC_VARIABLE_REPEAT:
1164 rep = pStubMsg->MaxCount;
1165 stride = *(const WORD*)&pFormat[2];
1166 ofs = *(const WORD*)&pFormat[4];
1167 count = *(const WORD*)&pFormat[6];
1168 xofs = (pFormat[1] == RPC_FC_VARIABLE_OFFSET) ? Offset * stride : 0;
1172 /* ofs doesn't seem to matter in this context */
1173 for (i = 0; i < rep; i++) {
1174 PFORMAT_STRING info = pFormat;
1175 unsigned char *membase = pMemory + (i * stride);
1177 for (u=0; u<count; u++,info+=8) {
1178 unsigned char *memptr = membase + *(const SHORT*)&info[0];
1179 unsigned char *saved_memory = pStubMsg->Memory;
1181 pStubMsg->Memory = pMemory;
1182 PointerBufferSize(pStubMsg, *(unsigned char**)memptr, info+4);
1183 pStubMsg->Memory = saved_memory;
1186 pFormat += 8 * count;
1190 /***********************************************************************
1191 * EmbeddedPointerMemorySize
1193 static unsigned long EmbeddedPointerMemorySize(PMIDL_STUB_MESSAGE pStubMsg,
1194 PFORMAT_STRING pFormat)
1196 unsigned long Offset = pStubMsg->Offset;
1197 unsigned char *Mark = pStubMsg->BufferMark;
1198 unsigned ofs, rep, count, stride, xofs;
1201 FIXME("(%p,%p): stub\n", pStubMsg, pFormat);
1203 if (*pFormat != RPC_FC_PP) return 0;
1206 while (pFormat[0] != RPC_FC_END) {
1207 switch (pFormat[0]) {
1209 FIXME("unknown repeat type %d\n", pFormat[0]);
1210 case RPC_FC_NO_REPEAT:
1218 case RPC_FC_FIXED_REPEAT:
1219 rep = *(const WORD*)&pFormat[2];
1220 stride = *(const WORD*)&pFormat[4];
1221 ofs = *(const WORD*)&pFormat[6];
1222 count = *(const WORD*)&pFormat[8];
1226 case RPC_FC_VARIABLE_REPEAT:
1227 rep = pStubMsg->MaxCount;
1228 stride = *(const WORD*)&pFormat[2];
1229 ofs = *(const WORD*)&pFormat[4];
1230 count = *(const WORD*)&pFormat[6];
1231 xofs = (pFormat[1] == RPC_FC_VARIABLE_OFFSET) ? Offset * stride : 0;
1235 /* ofs doesn't seem to matter in this context */
1236 for (i = 0; i < rep; i++) {
1237 PFORMAT_STRING info = pFormat;
1238 unsigned char *bufbase = Mark + (i * stride);
1240 for (u=0; u<count; u++,info+=8) {
1241 unsigned char *bufptr = bufbase + *(const SHORT*)&info[2];
1242 PointerMemorySize(pStubMsg, bufptr, info+4);
1245 pFormat += 8 * count;
1251 /***********************************************************************
1252 * EmbeddedPointerFree
1254 static void EmbeddedPointerFree(PMIDL_STUB_MESSAGE pStubMsg,
1255 unsigned char *pMemory,
1256 PFORMAT_STRING pFormat)
1258 unsigned long Offset = pStubMsg->Offset;
1259 unsigned ofs, rep, count, stride, xofs;
1262 TRACE("(%p,%p,%p)\n", pStubMsg, pMemory, pFormat);
1263 if (*pFormat != RPC_FC_PP) return;
1266 while (pFormat[0] != RPC_FC_END) {
1267 switch (pFormat[0]) {
1269 FIXME("unknown repeat type %d\n", pFormat[0]);
1270 case RPC_FC_NO_REPEAT:
1278 case RPC_FC_FIXED_REPEAT:
1279 rep = *(const WORD*)&pFormat[2];
1280 stride = *(const WORD*)&pFormat[4];
1281 ofs = *(const WORD*)&pFormat[6];
1282 count = *(const WORD*)&pFormat[8];
1286 case RPC_FC_VARIABLE_REPEAT:
1287 rep = pStubMsg->MaxCount;
1288 stride = *(const WORD*)&pFormat[2];
1289 ofs = *(const WORD*)&pFormat[4];
1290 count = *(const WORD*)&pFormat[6];
1291 xofs = (pFormat[1] == RPC_FC_VARIABLE_OFFSET) ? Offset * stride : 0;
1295 /* ofs doesn't seem to matter in this context */
1296 for (i = 0; i < rep; i++) {
1297 PFORMAT_STRING info = pFormat;
1298 unsigned char *membase = pMemory + (i * stride);
1300 for (u=0; u<count; u++,info+=8) {
1301 unsigned char *memptr = membase + *(const SHORT*)&info[0];
1302 unsigned char *saved_memory = pStubMsg->Memory;
1304 pStubMsg->Memory = pMemory;
1305 PointerFree(pStubMsg, *(unsigned char**)memptr, info+4);
1306 pStubMsg->Memory = saved_memory;
1309 pFormat += 8 * count;
1313 /***********************************************************************
1314 * NdrPointerMarshall [RPCRT4.@]
1316 unsigned char * WINAPI NdrPointerMarshall(PMIDL_STUB_MESSAGE pStubMsg,
1317 unsigned char *pMemory,
1318 PFORMAT_STRING pFormat)
1320 unsigned char *Buffer;
1322 TRACE("(%p,%p,%p)\n", pStubMsg, pMemory, pFormat);
1324 /* incremement the buffer here instead of in PointerMarshall,
1325 * as that is used by embedded pointers which already handle the incrementing
1326 * the buffer, and shouldn't write any additional pointer data to the wire */
1327 if (*pFormat != RPC_FC_RP)
1329 ALIGN_POINTER(pStubMsg->Buffer, 4);
1330 Buffer = pStubMsg->Buffer;
1331 pStubMsg->Buffer += 4;
1334 Buffer = pStubMsg->Buffer;
1336 PointerMarshall(pStubMsg, Buffer, pMemory, pFormat);
1338 STD_OVERFLOW_CHECK(pStubMsg);
1343 /***********************************************************************
1344 * NdrPointerUnmarshall [RPCRT4.@]
1346 unsigned char * WINAPI NdrPointerUnmarshall(PMIDL_STUB_MESSAGE pStubMsg,
1347 unsigned char **ppMemory,
1348 PFORMAT_STRING pFormat,
1349 unsigned char fMustAlloc)
1351 unsigned char *Buffer;
1353 TRACE("(%p,%p,%p,%d)\n", pStubMsg, ppMemory, pFormat, fMustAlloc);
1355 /* incremement the buffer here instead of in PointerUnmarshall,
1356 * as that is used by embedded pointers which already handle the incrementing
1357 * the buffer, and shouldn't read any additional pointer data from the
1359 if (*pFormat != RPC_FC_RP)
1361 ALIGN_POINTER(pStubMsg->Buffer, 4);
1362 Buffer = pStubMsg->Buffer;
1363 pStubMsg->Buffer += 4;
1366 Buffer = pStubMsg->Buffer;
1368 PointerUnmarshall(pStubMsg, Buffer, ppMemory, pFormat, fMustAlloc);
1373 /***********************************************************************
1374 * NdrPointerBufferSize [RPCRT4.@]
1376 void WINAPI NdrPointerBufferSize(PMIDL_STUB_MESSAGE pStubMsg,
1377 unsigned char *pMemory,
1378 PFORMAT_STRING pFormat)
1380 TRACE("(%p,%p,%p)\n", pStubMsg, pMemory, pFormat);
1382 /* incremement the buffer length here instead of in PointerBufferSize,
1383 * as that is used by embedded pointers which already handle the buffer
1384 * length, and shouldn't write anything more to the wire */
1385 if (*pFormat != RPC_FC_RP)
1387 ALIGN_LENGTH(pStubMsg->BufferLength, 4);
1388 pStubMsg->BufferLength += 4;
1391 PointerBufferSize(pStubMsg, pMemory, pFormat);
1394 /***********************************************************************
1395 * NdrPointerMemorySize [RPCRT4.@]
1397 unsigned long WINAPI NdrPointerMemorySize(PMIDL_STUB_MESSAGE pStubMsg,
1398 PFORMAT_STRING pFormat)
1400 /* unsigned size = *(LPWORD)(pFormat+2); */
1401 FIXME("(%p,%p): stub\n", pStubMsg, pFormat);
1402 PointerMemorySize(pStubMsg, pStubMsg->Buffer, pFormat);
1406 /***********************************************************************
1407 * NdrPointerFree [RPCRT4.@]
1409 void WINAPI NdrPointerFree(PMIDL_STUB_MESSAGE pStubMsg,
1410 unsigned char *pMemory,
1411 PFORMAT_STRING pFormat)
1413 TRACE("(%p,%p,%p)\n", pStubMsg, pMemory, pFormat);
1414 PointerFree(pStubMsg, pMemory, pFormat);
1417 /***********************************************************************
1418 * NdrSimpleTypeMarshall [RPCRT4.@]
1420 void WINAPI NdrSimpleTypeMarshall( PMIDL_STUB_MESSAGE pStubMsg, unsigned char* pMemory,
1421 unsigned char FormatChar )
1426 /***********************************************************************
1427 * NdrSimpleTypeUnmarshall [RPCRT4.@]
1429 void WINAPI NdrSimpleTypeUnmarshall( PMIDL_STUB_MESSAGE pStubMsg, unsigned char* pMemory,
1430 unsigned char FormatChar )
1435 /***********************************************************************
1436 * NdrSimpleStructMarshall [RPCRT4.@]
1438 unsigned char * WINAPI NdrSimpleStructMarshall(PMIDL_STUB_MESSAGE pStubMsg,
1439 unsigned char *pMemory,
1440 PFORMAT_STRING pFormat)
1442 unsigned size = *(const WORD*)(pFormat+2);
1443 TRACE("(%p,%p,%p)\n", pStubMsg, pMemory, pFormat);
1445 ALIGN_POINTER(pStubMsg->Buffer, pFormat[1] + 1);
1447 memcpy(pStubMsg->Buffer, pMemory, size);
1448 pStubMsg->BufferMark = pStubMsg->Buffer;
1449 pStubMsg->Buffer += size;
1451 if (pFormat[0] != RPC_FC_STRUCT)
1452 EmbeddedPointerMarshall(pStubMsg, pMemory, pFormat+4);
1454 STD_OVERFLOW_CHECK(pStubMsg);
1459 /***********************************************************************
1460 * NdrSimpleStructUnmarshall [RPCRT4.@]
1462 unsigned char * WINAPI NdrSimpleStructUnmarshall(PMIDL_STUB_MESSAGE pStubMsg,
1463 unsigned char **ppMemory,
1464 PFORMAT_STRING pFormat,
1465 unsigned char fMustAlloc)
1467 unsigned size = *(const WORD*)(pFormat+2);
1468 TRACE("(%p,%p,%p,%d)\n", pStubMsg, ppMemory, pFormat, fMustAlloc);
1470 ALIGN_POINTER(pStubMsg->Buffer, pFormat[1] + 1);
1473 *ppMemory = NdrAllocate(pStubMsg, size);
1474 memcpy(*ppMemory, pStubMsg->Buffer, size);
1476 if (!pStubMsg->IsClient && !*ppMemory)
1477 /* for servers, we just point straight into the RPC buffer */
1478 *ppMemory = pStubMsg->Buffer;
1480 /* for clients, memory should be provided by caller */
1481 memcpy(*ppMemory, pStubMsg->Buffer, size);
1484 pStubMsg->BufferMark = pStubMsg->Buffer;
1485 pStubMsg->Buffer += size;
1487 if (pFormat[0] != RPC_FC_STRUCT)
1488 EmbeddedPointerUnmarshall(pStubMsg, ppMemory, pFormat+4, fMustAlloc);
1493 /***********************************************************************
1494 * NdrSimpleStructBufferSize [RPCRT4.@]
1496 void WINAPI NdrSimpleStructBufferSize(PMIDL_STUB_MESSAGE pStubMsg,
1497 unsigned char *pMemory,
1498 PFORMAT_STRING pFormat)
1500 unsigned size = *(const WORD*)(pFormat+2);
1501 TRACE("(%p,%p,%p)\n", pStubMsg, pMemory, pFormat);
1503 ALIGN_LENGTH(pStubMsg->BufferLength, pFormat[1] + 1);
1505 pStubMsg->BufferLength += size;
1506 if (pFormat[0] != RPC_FC_STRUCT)
1507 EmbeddedPointerBufferSize(pStubMsg, pMemory, pFormat+4);
1510 /***********************************************************************
1511 * NdrSimpleStructMemorySize [RPCRT4.@]
1513 unsigned long WINAPI NdrSimpleStructMemorySize(PMIDL_STUB_MESSAGE pStubMsg,
1514 PFORMAT_STRING pFormat)
1516 unsigned short size = *(LPWORD)(pFormat+2);
1518 TRACE("(%p,%p)\n", pStubMsg, pFormat);
1520 ALIGN_POINTER(pStubMsg->Buffer, pFormat[1] + 1);
1521 pStubMsg->MemorySize += size;
1522 pStubMsg->Buffer += size;
1524 if (pFormat[0] != RPC_FC_STRUCT)
1525 EmbeddedPointerMemorySize(pStubMsg, pFormat+4);
1529 /***********************************************************************
1530 * NdrSimpleStructFree [RPCRT4.@]
1532 void WINAPI NdrSimpleStructFree(PMIDL_STUB_MESSAGE pStubMsg,
1533 unsigned char *pMemory,
1534 PFORMAT_STRING pFormat)
1536 TRACE("(%p,%p,%p)\n", pStubMsg, pMemory, pFormat);
1537 if (pFormat[0] != RPC_FC_STRUCT)
1538 EmbeddedPointerFree(pStubMsg, pMemory, pFormat+4);
1542 static unsigned long EmbeddedComplexSize(PMIDL_STUB_MESSAGE pStubMsg,
1543 PFORMAT_STRING pFormat)
1547 case RPC_FC_PSTRUCT:
1548 case RPC_FC_CSTRUCT:
1549 case RPC_FC_BOGUS_STRUCT:
1550 return *(const WORD*)&pFormat[2];
1551 case RPC_FC_USER_MARSHAL:
1552 return *(const WORD*)&pFormat[4];
1553 case RPC_FC_NON_ENCAPSULATED_UNION:
1555 if (pStubMsg->fHasNewCorrDesc)
1560 pFormat += *(const SHORT*)pFormat;
1561 return *(const SHORT*)pFormat;
1563 return sizeof(void *);
1565 FIXME("unhandled embedded type %02x\n", *pFormat);
1571 static unsigned long EmbeddedComplexMemorySize(PMIDL_STUB_MESSAGE pStubMsg,
1572 PFORMAT_STRING pFormat)
1574 NDR_MEMORYSIZE m = NdrMemorySizer[*pFormat & NDR_TABLE_MASK];
1578 FIXME("no memorysizer for data type=%02x\n", *pFormat);
1582 return m(pStubMsg, pFormat);
1586 static unsigned char * ComplexMarshall(PMIDL_STUB_MESSAGE pStubMsg,
1587 unsigned char *pMemory,
1588 PFORMAT_STRING pFormat,
1589 PFORMAT_STRING pPointer)
1591 PFORMAT_STRING desc;
1595 while (*pFormat != RPC_FC_END) {
1599 TRACE("short=%d <= %p\n", *(WORD*)pMemory, pMemory);
1600 memcpy(pStubMsg->Buffer, pMemory, 2);
1601 pStubMsg->Buffer += 2;
1607 TRACE("long=%ld <= %p\n", *(DWORD*)pMemory, pMemory);
1608 memcpy(pStubMsg->Buffer, pMemory, 4);
1609 pStubMsg->Buffer += 4;
1612 case RPC_FC_POINTER:
1613 TRACE("pointer=%p <= %p\n", *(unsigned char**)pMemory, pMemory);
1614 NdrPointerMarshall(pStubMsg, *(unsigned char**)pMemory, pPointer);
1618 case RPC_FC_ALIGNM4:
1619 ALIGN_POINTER(pMemory, 4);
1621 case RPC_FC_ALIGNM8:
1622 ALIGN_POINTER(pMemory, 8);
1624 case RPC_FC_STRUCTPAD2:
1627 case RPC_FC_EMBEDDED_COMPLEX:
1628 pMemory += pFormat[1];
1630 desc = pFormat + *(const SHORT*)pFormat;
1631 size = EmbeddedComplexSize(pStubMsg, desc);
1632 TRACE("embedded complex (size=%ld) <= %p\n", size, pMemory);
1633 m = NdrMarshaller[*desc & NDR_TABLE_MASK];
1634 if (m) m(pStubMsg, pMemory, desc);
1635 else FIXME("no marshaller for embedded type %02x\n", *desc);
1642 FIXME("unhandled format %02x\n", *pFormat);
1650 static unsigned char * ComplexUnmarshall(PMIDL_STUB_MESSAGE pStubMsg,
1651 unsigned char *pMemory,
1652 PFORMAT_STRING pFormat,
1653 PFORMAT_STRING pPointer,
1654 unsigned char fMustAlloc)
1656 PFORMAT_STRING desc;
1660 while (*pFormat != RPC_FC_END) {
1664 memcpy(pMemory, pStubMsg->Buffer, 2);
1665 TRACE("short=%d => %p\n", *(WORD*)pMemory, pMemory);
1666 pStubMsg->Buffer += 2;
1672 memcpy(pMemory, pStubMsg->Buffer, 4);
1673 TRACE("long=%ld => %p\n", *(DWORD*)pMemory, pMemory);
1674 pStubMsg->Buffer += 4;
1677 case RPC_FC_POINTER:
1678 TRACE("pointer => %p\n", pMemory);
1679 NdrPointerUnmarshall(pStubMsg, (unsigned char**)pMemory, pPointer, TRUE);
1683 case RPC_FC_ALIGNM4:
1684 ALIGN_POINTER(pMemory, 4);
1686 case RPC_FC_ALIGNM8:
1687 ALIGN_POINTER(pMemory, 8);
1689 case RPC_FC_STRUCTPAD2:
1692 case RPC_FC_EMBEDDED_COMPLEX:
1693 pMemory += pFormat[1];
1695 desc = pFormat + *(const SHORT*)pFormat;
1696 size = EmbeddedComplexSize(pStubMsg, desc);
1697 TRACE("embedded complex (size=%ld) => %p\n", size, pMemory);
1698 m = NdrUnmarshaller[*desc & NDR_TABLE_MASK];
1699 memset(pMemory, 0, size); /* just in case */
1700 if (m) m(pStubMsg, &pMemory, desc, fMustAlloc);
1701 else FIXME("no unmarshaller for embedded type %02x\n", *desc);
1708 FIXME("unhandled format %d\n", *pFormat);
1716 static unsigned char * ComplexBufferSize(PMIDL_STUB_MESSAGE pStubMsg,
1717 unsigned char *pMemory,
1718 PFORMAT_STRING pFormat,
1719 PFORMAT_STRING pPointer)
1721 PFORMAT_STRING desc;
1725 while (*pFormat != RPC_FC_END) {
1729 pStubMsg->BufferLength += 2;
1735 pStubMsg->BufferLength += 4;
1738 case RPC_FC_POINTER:
1739 NdrPointerBufferSize(pStubMsg, *(unsigned char**)pMemory, pPointer);
1743 case RPC_FC_ALIGNM4:
1744 ALIGN_POINTER(pMemory, 4);
1746 case RPC_FC_ALIGNM8:
1747 ALIGN_POINTER(pMemory, 8);
1749 case RPC_FC_STRUCTPAD2:
1752 case RPC_FC_EMBEDDED_COMPLEX:
1753 pMemory += pFormat[1];
1755 desc = pFormat + *(const SHORT*)pFormat;
1756 size = EmbeddedComplexSize(pStubMsg, desc);
1757 m = NdrBufferSizer[*desc & NDR_TABLE_MASK];
1758 if (m) m(pStubMsg, pMemory, desc);
1759 else FIXME("no buffersizer for embedded type %02x\n", *desc);
1766 FIXME("unhandled format %d\n", *pFormat);
1774 static unsigned char * ComplexFree(PMIDL_STUB_MESSAGE pStubMsg,
1775 unsigned char *pMemory,
1776 PFORMAT_STRING pFormat,
1777 PFORMAT_STRING pPointer)
1779 PFORMAT_STRING desc;
1783 while (*pFormat != RPC_FC_END) {
1794 case RPC_FC_POINTER:
1795 NdrPointerFree(pStubMsg, *(unsigned char**)pMemory, pPointer);
1799 case RPC_FC_ALIGNM4:
1800 ALIGN_POINTER(pMemory, 4);
1802 case RPC_FC_ALIGNM8:
1803 ALIGN_POINTER(pMemory, 8);
1805 case RPC_FC_STRUCTPAD2:
1808 case RPC_FC_EMBEDDED_COMPLEX:
1809 pMemory += pFormat[1];
1811 desc = pFormat + *(const SHORT*)pFormat;
1812 size = EmbeddedComplexSize(pStubMsg, desc);
1813 m = NdrFreer[*desc & NDR_TABLE_MASK];
1814 if (m) m(pStubMsg, pMemory, desc);
1815 else FIXME("no freer for embedded type %02x\n", *desc);
1822 FIXME("unhandled format %d\n", *pFormat);
1830 static unsigned long ComplexStructMemorySize(PMIDL_STUB_MESSAGE pStubMsg,
1831 PFORMAT_STRING pFormat)
1833 PFORMAT_STRING desc;
1834 unsigned long size = 0;
1836 while (*pFormat != RPC_FC_END) {
1841 pStubMsg->Buffer += 2;
1846 pStubMsg->Buffer += 4;
1848 case RPC_FC_POINTER:
1850 pStubMsg->Buffer += 4;
1852 case RPC_FC_ALIGNM4:
1853 ALIGN_LENGTH(size, 4);
1854 ALIGN_POINTER(pStubMsg->Buffer, 4);
1856 case RPC_FC_ALIGNM8:
1857 ALIGN_LENGTH(size, 8);
1858 ALIGN_POINTER(pStubMsg->Buffer, 8);
1860 case RPC_FC_STRUCTPAD2:
1862 pStubMsg->Buffer += 2;
1864 case RPC_FC_EMBEDDED_COMPLEX:
1867 desc = pFormat + *(const SHORT*)pFormat;
1868 size += EmbeddedComplexMemorySize(pStubMsg, desc);
1874 FIXME("unhandled format %d\n", *pFormat);
1882 /***********************************************************************
1883 * NdrComplexStructMarshall [RPCRT4.@]
1885 unsigned char * WINAPI NdrComplexStructMarshall(PMIDL_STUB_MESSAGE pStubMsg,
1886 unsigned char *pMemory,
1887 PFORMAT_STRING pFormat)
1889 PFORMAT_STRING conf_array = NULL;
1890 PFORMAT_STRING pointer_desc = NULL;
1891 unsigned char *OldMemory = pStubMsg->Memory;
1893 TRACE("(%p,%p,%p)\n", pStubMsg, pMemory, pFormat);
1895 ALIGN_POINTER(pStubMsg->Buffer, pFormat[1] + 1);
1898 if (*(const WORD*)pFormat) conf_array = pFormat + *(const WORD*)pFormat;
1900 if (*(const WORD*)pFormat) pointer_desc = pFormat + *(const WORD*)pFormat;
1903 pStubMsg->Memory = pMemory;
1905 ComplexMarshall(pStubMsg, pMemory, pFormat, pointer_desc);
1908 NdrConformantArrayMarshall(pStubMsg, pMemory, conf_array);
1910 pStubMsg->Memory = OldMemory;
1912 STD_OVERFLOW_CHECK(pStubMsg);
1917 /***********************************************************************
1918 * NdrComplexStructUnmarshall [RPCRT4.@]
1920 unsigned char * WINAPI NdrComplexStructUnmarshall(PMIDL_STUB_MESSAGE pStubMsg,
1921 unsigned char **ppMemory,
1922 PFORMAT_STRING pFormat,
1923 unsigned char fMustAlloc)
1925 unsigned size = *(const WORD*)(pFormat+2);
1926 PFORMAT_STRING conf_array = NULL;
1927 PFORMAT_STRING pointer_desc = NULL;
1928 unsigned char *pMemory;
1930 TRACE("(%p,%p,%p,%d)\n", pStubMsg, ppMemory, pFormat, fMustAlloc);
1932 ALIGN_POINTER(pStubMsg->Buffer, pFormat[1] + 1);
1934 if (fMustAlloc || !*ppMemory)
1936 *ppMemory = NdrAllocate(pStubMsg, size);
1937 memset(*ppMemory, 0, size);
1941 if (*(const WORD*)pFormat) conf_array = pFormat + *(const WORD*)pFormat;
1943 if (*(const WORD*)pFormat) pointer_desc = pFormat + *(const WORD*)pFormat;
1946 pMemory = ComplexUnmarshall(pStubMsg, *ppMemory, pFormat, pointer_desc, fMustAlloc);
1949 NdrConformantArrayUnmarshall(pStubMsg, &pMemory, conf_array, fMustAlloc);
1954 /***********************************************************************
1955 * NdrComplexStructBufferSize [RPCRT4.@]
1957 void WINAPI NdrComplexStructBufferSize(PMIDL_STUB_MESSAGE pStubMsg,
1958 unsigned char *pMemory,
1959 PFORMAT_STRING pFormat)
1961 PFORMAT_STRING conf_array = NULL;
1962 PFORMAT_STRING pointer_desc = NULL;
1963 unsigned char *OldMemory = pStubMsg->Memory;
1965 TRACE("(%p,%p,%p)\n", pStubMsg, pMemory, pFormat);
1967 ALIGN_LENGTH(pStubMsg->BufferLength, pFormat[1] + 1);
1970 if (*(const WORD*)pFormat) conf_array = pFormat + *(const WORD*)pFormat;
1972 if (*(const WORD*)pFormat) pointer_desc = pFormat + *(const WORD*)pFormat;
1975 pStubMsg->Memory = pMemory;
1977 pMemory = ComplexBufferSize(pStubMsg, pMemory, pFormat, pointer_desc);
1980 NdrConformantArrayBufferSize(pStubMsg, pMemory, conf_array);
1982 pStubMsg->Memory = OldMemory;
1985 /***********************************************************************
1986 * NdrComplexStructMemorySize [RPCRT4.@]
1988 unsigned long WINAPI NdrComplexStructMemorySize(PMIDL_STUB_MESSAGE pStubMsg,
1989 PFORMAT_STRING pFormat)
1991 unsigned size = *(const WORD*)(pFormat+2);
1992 PFORMAT_STRING conf_array = NULL;
1993 PFORMAT_STRING pointer_desc = NULL;
1995 TRACE("(%p,%p)\n", pStubMsg, pFormat);
1997 ALIGN_POINTER(pStubMsg->Buffer, pFormat[1] + 1);
2000 if (*(const WORD*)pFormat) conf_array = pFormat + *(const WORD*)pFormat;
2002 if (*(const WORD*)pFormat) pointer_desc = pFormat + *(const WORD*)pFormat;
2005 ComplexStructMemorySize(pStubMsg, pFormat);
2008 NdrConformantArrayMemorySize(pStubMsg, conf_array);
2013 /***********************************************************************
2014 * NdrComplexStructFree [RPCRT4.@]
2016 void WINAPI NdrComplexStructFree(PMIDL_STUB_MESSAGE pStubMsg,
2017 unsigned char *pMemory,
2018 PFORMAT_STRING pFormat)
2020 PFORMAT_STRING conf_array = NULL;
2021 PFORMAT_STRING pointer_desc = NULL;
2022 unsigned char *OldMemory = pStubMsg->Memory;
2024 TRACE("(%p,%p,%p)\n", pStubMsg, pMemory, pFormat);
2027 if (*(const WORD*)pFormat) conf_array = pFormat + *(const WORD*)pFormat;
2029 if (*(const WORD*)pFormat) pointer_desc = pFormat + *(const WORD*)pFormat;
2032 pStubMsg->Memory = pMemory;
2034 pMemory = ComplexFree(pStubMsg, pMemory, pFormat, pointer_desc);
2037 NdrConformantArrayFree(pStubMsg, pMemory, conf_array);
2039 pStubMsg->Memory = OldMemory;
2042 /***********************************************************************
2043 * NdrConformantArrayMarshall [RPCRT4.@]
2045 unsigned char * WINAPI NdrConformantArrayMarshall(PMIDL_STUB_MESSAGE pStubMsg,
2046 unsigned char *pMemory,
2047 PFORMAT_STRING pFormat)
2049 DWORD size = 0, esize = *(const WORD*)(pFormat+2);
2050 unsigned char alignment = pFormat[1] + 1;
2052 TRACE("(%p,%p,%p)\n", pStubMsg, pMemory, pFormat);
2053 if (pFormat[0] != RPC_FC_CARRAY) FIXME("format=%d\n", pFormat[0]);
2055 pFormat = ComputeConformance(pStubMsg, pMemory, pFormat+4, 0);
2056 size = pStubMsg->MaxCount;
2058 WriteConformance(pStubMsg);
2060 ALIGN_POINTER(pStubMsg->Buffer, alignment);
2062 memcpy(pStubMsg->Buffer, pMemory, size*esize);
2063 pStubMsg->BufferMark = pStubMsg->Buffer;
2064 pStubMsg->Buffer += size*esize;
2066 EmbeddedPointerMarshall(pStubMsg, pMemory, pFormat);
2068 STD_OVERFLOW_CHECK(pStubMsg);
2073 /***********************************************************************
2074 * NdrConformantArrayUnmarshall [RPCRT4.@]
2076 unsigned char * WINAPI NdrConformantArrayUnmarshall(PMIDL_STUB_MESSAGE pStubMsg,
2077 unsigned char **ppMemory,
2078 PFORMAT_STRING pFormat,
2079 unsigned char fMustAlloc)
2081 DWORD size = 0, esize = *(const WORD*)(pFormat+2);
2082 unsigned char alignment = pFormat[1] + 1;
2084 TRACE("(%p,%p,%p,%d)\n", pStubMsg, ppMemory, pFormat, fMustAlloc);
2085 if (pFormat[0] != RPC_FC_CARRAY) FIXME("format=%d\n", pFormat[0]);
2087 pFormat = ReadConformance(pStubMsg, pFormat+4);
2088 size = pStubMsg->MaxCount;
2090 if (fMustAlloc || !*ppMemory)
2091 *ppMemory = NdrAllocate(pStubMsg, size*esize);
2093 ALIGN_POINTER(pStubMsg->Buffer, alignment);
2095 memcpy(*ppMemory, pStubMsg->Buffer, size*esize);
2097 pStubMsg->BufferMark = pStubMsg->Buffer;
2098 pStubMsg->Buffer += size*esize;
2100 EmbeddedPointerUnmarshall(pStubMsg, ppMemory, pFormat, fMustAlloc);
2105 /***********************************************************************
2106 * NdrConformantArrayBufferSize [RPCRT4.@]
2108 void WINAPI NdrConformantArrayBufferSize(PMIDL_STUB_MESSAGE pStubMsg,
2109 unsigned char *pMemory,
2110 PFORMAT_STRING pFormat)
2112 DWORD size = 0, esize = *(const WORD*)(pFormat+2);
2113 unsigned char alignment = pFormat[1] + 1;
2115 TRACE("(%p,%p,%p)\n", pStubMsg, pMemory, pFormat);
2116 if (pFormat[0] != RPC_FC_CARRAY) FIXME("format=%d\n", pFormat[0]);
2118 pFormat = ComputeConformance(pStubMsg, pMemory, pFormat+4, 0);
2119 size = pStubMsg->MaxCount;
2121 SizeConformance(pStubMsg);
2123 ALIGN_LENGTH(pStubMsg->BufferLength, alignment);
2125 /* conformance value plus array */
2126 pStubMsg->BufferLength += size*esize;
2128 EmbeddedPointerBufferSize(pStubMsg, pMemory, pFormat);
2131 /***********************************************************************
2132 * NdrConformantArrayMemorySize [RPCRT4.@]
2134 unsigned long WINAPI NdrConformantArrayMemorySize(PMIDL_STUB_MESSAGE pStubMsg,
2135 PFORMAT_STRING pFormat)
2137 DWORD size = 0, esize = *(const WORD*)(pFormat+2);
2138 unsigned char alignment = pFormat[1] + 1;
2140 TRACE("(%p,%p)\n", pStubMsg, pFormat);
2141 if (pFormat[0] != RPC_FC_CARRAY) FIXME("format=%d\n", pFormat[0]);
2143 pFormat = ReadConformance(pStubMsg, pFormat+4);
2144 size = pStubMsg->MaxCount;
2145 pStubMsg->MemorySize += size*esize;
2147 ALIGN_POINTER(pStubMsg->Buffer, alignment);
2148 pStubMsg->BufferMark = pStubMsg->Buffer;
2149 pStubMsg->Buffer += size*esize;
2151 EmbeddedPointerMemorySize(pStubMsg, pFormat);
2153 return pStubMsg->MemorySize;
2156 /***********************************************************************
2157 * NdrConformantArrayFree [RPCRT4.@]
2159 void WINAPI NdrConformantArrayFree(PMIDL_STUB_MESSAGE pStubMsg,
2160 unsigned char *pMemory,
2161 PFORMAT_STRING pFormat)
2163 TRACE("(%p,%p,%p)\n", pStubMsg, pMemory, pFormat);
2164 if (pFormat[0] != RPC_FC_CARRAY) FIXME("format=%d\n", pFormat[0]);
2166 EmbeddedPointerFree(pStubMsg, pMemory, pFormat);
2170 /***********************************************************************
2171 * NdrConformantVaryingArrayMarshall [RPCRT4.@]
2173 unsigned char* WINAPI NdrConformantVaryingArrayMarshall( PMIDL_STUB_MESSAGE pStubMsg,
2174 unsigned char* pMemory,
2175 PFORMAT_STRING pFormat )
2177 unsigned char alignment = pFormat[1] + 1;
2178 DWORD esize = *(const WORD*)(pFormat+2);
2180 TRACE("(%p, %p, %p)\n", pStubMsg, pMemory, pFormat);
2182 if (pFormat[0] != RPC_FC_CVARRAY)
2184 ERR("invalid format type %x\n", pFormat[0]);
2185 RpcRaiseException(RPC_S_INTERNAL_ERROR);
2189 pFormat = ComputeConformance(pStubMsg, pMemory, pFormat+4, 0);
2190 pFormat = ComputeVariance(pStubMsg, pMemory, pFormat, 0);
2192 WriteConformance(pStubMsg);
2193 WriteVariance(pStubMsg);
2195 ALIGN_POINTER(pStubMsg->Buffer, alignment);
2197 memcpy(pStubMsg->Buffer, pMemory + pStubMsg->Offset, pStubMsg->ActualCount*esize);
2198 pStubMsg->BufferMark = pStubMsg->Buffer;
2199 pStubMsg->Buffer += pStubMsg->ActualCount*esize;
2201 EmbeddedPointerMarshall(pStubMsg, pMemory, pFormat);
2203 STD_OVERFLOW_CHECK(pStubMsg);
2209 /***********************************************************************
2210 * NdrConformantVaryingArrayUnmarshall [RPCRT4.@]
2212 unsigned char* WINAPI NdrConformantVaryingArrayUnmarshall( PMIDL_STUB_MESSAGE pStubMsg,
2213 unsigned char** ppMemory,
2214 PFORMAT_STRING pFormat,
2215 unsigned char fMustAlloc )
2217 unsigned char alignment = pFormat[1] + 1;
2218 DWORD esize = *(const WORD*)(pFormat+2);
2220 TRACE("(%p, %p, %p, %d)\n", pStubMsg, ppMemory, pFormat, fMustAlloc);
2222 if (pFormat[0] != RPC_FC_CVARRAY)
2224 ERR("invalid format type %x\n", pFormat[0]);
2225 RpcRaiseException(RPC_S_INTERNAL_ERROR);
2229 pFormat = ReadConformance(pStubMsg, pFormat);
2230 pFormat = ReadVariance(pStubMsg, pFormat);
2232 ALIGN_POINTER(pStubMsg->Buffer, alignment);
2234 if (!*ppMemory || fMustAlloc)
2235 *ppMemory = NdrAllocate(pStubMsg, pStubMsg->MaxCount * esize);
2236 memcpy(*ppMemory + pStubMsg->Offset, pStubMsg->Buffer, pStubMsg->ActualCount * esize);
2237 pStubMsg->Buffer += pStubMsg->ActualCount * esize;
2239 EmbeddedPointerUnmarshall(pStubMsg, ppMemory, pFormat, fMustAlloc);
2245 /***********************************************************************
2246 * NdrConformantVaryingArrayFree [RPCRT4.@]
2248 void WINAPI NdrConformantVaryingArrayFree( PMIDL_STUB_MESSAGE pStubMsg,
2249 unsigned char* pMemory,
2250 PFORMAT_STRING pFormat )
2252 TRACE("(%p,%p,%p)\n", pStubMsg, pMemory, pFormat);
2254 if (pFormat[0] != RPC_FC_CVARRAY)
2256 ERR("invalid format type %x\n", pFormat[0]);
2257 RpcRaiseException(RPC_S_INTERNAL_ERROR);
2261 pFormat = ComputeConformance(pStubMsg, pMemory, pFormat+4, 0);
2262 pFormat = ComputeVariance(pStubMsg, pMemory, pFormat, 0);
2264 EmbeddedPointerFree(pStubMsg, pMemory, pFormat);
2268 /***********************************************************************
2269 * NdrConformantVaryingArrayBufferSize [RPCRT4.@]
2271 void WINAPI NdrConformantVaryingArrayBufferSize( PMIDL_STUB_MESSAGE pStubMsg,
2272 unsigned char* pMemory, PFORMAT_STRING pFormat )
2274 unsigned char alignment = pFormat[1] + 1;
2275 DWORD esize = *(const WORD*)(pFormat+2);
2277 TRACE("(%p, %p, %p)\n", pStubMsg, pMemory, pFormat);
2279 if (pFormat[0] != RPC_FC_CVARRAY)
2281 ERR("invalid format type %x\n", pFormat[0]);
2282 RpcRaiseException(RPC_S_INTERNAL_ERROR);
2287 pFormat = ComputeConformance(pStubMsg, pMemory, pFormat+4, 0);
2288 /* compute length */
2289 pFormat = ComputeVariance(pStubMsg, pMemory, pFormat, 0);
2291 SizeConformance(pStubMsg);
2292 SizeVariance(pStubMsg);
2294 ALIGN_LENGTH(pStubMsg->BufferLength, alignment);
2296 pStubMsg->BufferLength += pStubMsg->ActualCount*esize;
2298 EmbeddedPointerBufferSize(pStubMsg, pMemory, pFormat);
2302 /***********************************************************************
2303 * NdrConformantVaryingArrayMemorySize [RPCRT4.@]
2305 unsigned long WINAPI NdrConformantVaryingArrayMemorySize( PMIDL_STUB_MESSAGE pStubMsg,
2306 PFORMAT_STRING pFormat )
2313 /***********************************************************************
2314 * NdrComplexArrayMarshall [RPCRT4.@]
2316 unsigned char * WINAPI NdrComplexArrayMarshall(PMIDL_STUB_MESSAGE pStubMsg,
2317 unsigned char *pMemory,
2318 PFORMAT_STRING pFormat)
2320 ULONG i, count, def;
2321 BOOL variance_present;
2322 unsigned char alignment;
2324 TRACE("(%p,%p,%p)\n", pStubMsg, pMemory, pFormat);
2326 if (pFormat[0] != RPC_FC_BOGUS_ARRAY)
2328 ERR("invalid format type %x\n", pFormat[0]);
2329 RpcRaiseException(RPC_S_INTERNAL_ERROR);
2333 alignment = pFormat[1] + 1;
2335 def = *(const WORD*)&pFormat[2];
2338 pFormat = ComputeConformance(pStubMsg, pMemory, pFormat, def);
2339 TRACE("conformance = %ld\n", pStubMsg->MaxCount);
2341 variance_present = IsConformanceOrVariancePresent(pFormat);
2342 pFormat = ComputeVariance(pStubMsg, pMemory, pFormat, pStubMsg->MaxCount);
2343 TRACE("variance = %ld\n", pStubMsg->ActualCount);
2345 WriteConformance(pStubMsg);
2346 if (variance_present)
2347 WriteVariance(pStubMsg);
2349 ALIGN_POINTER(pStubMsg->Buffer, alignment);
2351 count = pStubMsg->ActualCount;
2352 for (i = 0; i < count; i++)
2353 pMemory = ComplexMarshall(pStubMsg, pMemory, pFormat, NULL);
2355 STD_OVERFLOW_CHECK(pStubMsg);
2360 /***********************************************************************
2361 * NdrComplexArrayUnmarshall [RPCRT4.@]
2363 unsigned char * WINAPI NdrComplexArrayUnmarshall(PMIDL_STUB_MESSAGE pStubMsg,
2364 unsigned char **ppMemory,
2365 PFORMAT_STRING pFormat,
2366 unsigned char fMustAlloc)
2368 ULONG i, count, esize;
2369 unsigned char alignment;
2370 unsigned char *pMemory;
2371 unsigned char *Buffer;
2373 TRACE("(%p,%p,%p,%d)\n", pStubMsg, ppMemory, pFormat, fMustAlloc);
2375 if (pFormat[0] != RPC_FC_BOGUS_ARRAY)
2377 ERR("invalid format type %x\n", pFormat[0]);
2378 RpcRaiseException(RPC_S_INTERNAL_ERROR);
2382 alignment = pFormat[1] + 1;
2386 pFormat = ReadConformance(pStubMsg, pFormat);
2387 pFormat = ReadVariance(pStubMsg, pFormat);
2389 Buffer = pStubMsg->Buffer;
2390 esize = ComplexStructMemorySize(pStubMsg, pFormat);
2391 pStubMsg->Buffer = Buffer;
2393 if (fMustAlloc || !*ppMemory)
2395 *ppMemory = NdrAllocate(pStubMsg, pStubMsg->MaxCount * esize);
2396 memset(*ppMemory, 0, pStubMsg->MaxCount * esize);
2399 ALIGN_POINTER(pStubMsg->Buffer, alignment);
2401 pMemory = *ppMemory;
2402 count = pStubMsg->ActualCount;
2403 for (i = 0; i < count; i++)
2404 pMemory = ComplexUnmarshall(pStubMsg, pMemory, pFormat, NULL, fMustAlloc);
2409 /***********************************************************************
2410 * NdrComplexArrayBufferSize [RPCRT4.@]
2412 void WINAPI NdrComplexArrayBufferSize(PMIDL_STUB_MESSAGE pStubMsg,
2413 unsigned char *pMemory,
2414 PFORMAT_STRING pFormat)
2416 ULONG i, count, def;
2417 unsigned char alignment;
2418 BOOL variance_present;
2420 TRACE("(%p,%p,%p)\n", pStubMsg, pMemory, pFormat);
2422 if (pFormat[0] != RPC_FC_BOGUS_ARRAY)
2424 ERR("invalid format type %x\n", pFormat[0]);
2425 RpcRaiseException(RPC_S_INTERNAL_ERROR);
2429 alignment = pFormat[1] + 1;
2431 def = *(const WORD*)&pFormat[2];
2434 pFormat = ComputeConformance(pStubMsg, pMemory, pFormat, def);
2435 TRACE("conformance = %ld\n", pStubMsg->MaxCount);
2436 SizeConformance(pStubMsg);
2438 variance_present = IsConformanceOrVariancePresent(pFormat);
2439 pFormat = ComputeVariance(pStubMsg, pMemory, pFormat, pStubMsg->MaxCount);
2440 TRACE("variance = %ld\n", pStubMsg->ActualCount);
2442 if (variance_present)
2443 SizeVariance(pStubMsg);
2445 ALIGN_LENGTH(pStubMsg->BufferLength, alignment);
2447 count = pStubMsg->ActualCount;
2448 for (i = 0; i < count; i++)
2449 pMemory = ComplexBufferSize(pStubMsg, pMemory, pFormat, NULL);
2452 /***********************************************************************
2453 * NdrComplexArrayMemorySize [RPCRT4.@]
2455 unsigned long WINAPI NdrComplexArrayMemorySize(PMIDL_STUB_MESSAGE pStubMsg,
2456 PFORMAT_STRING pFormat)
2458 ULONG i, count, esize;
2459 unsigned char alignment;
2460 unsigned char *Buffer;
2461 unsigned long SavedMemorySize;
2462 unsigned long MemorySize;
2464 TRACE("(%p,%p)\n", pStubMsg, pFormat);
2466 if (pFormat[0] != RPC_FC_BOGUS_ARRAY)
2468 ERR("invalid format type %x\n", pFormat[0]);
2469 RpcRaiseException(RPC_S_INTERNAL_ERROR);
2473 alignment = pFormat[1] + 1;
2477 pFormat = ReadConformance(pStubMsg, pFormat);
2478 pFormat = ReadVariance(pStubMsg, pFormat);
2480 ALIGN_POINTER(pStubMsg->Buffer, alignment);
2482 SavedMemorySize = pStubMsg->MemorySize;
2484 Buffer = pStubMsg->Buffer;
2485 esize = ComplexStructMemorySize(pStubMsg, pFormat);
2486 pStubMsg->Buffer = Buffer;
2488 MemorySize = esize * pStubMsg->MaxCount;
2490 count = pStubMsg->ActualCount;
2491 for (i = 0; i < count; i++)
2492 ComplexStructMemorySize(pStubMsg, pFormat);
2494 pStubMsg->MemorySize = SavedMemorySize;
2496 pStubMsg->MemorySize += MemorySize;
2500 /***********************************************************************
2501 * NdrComplexArrayFree [RPCRT4.@]
2503 void WINAPI NdrComplexArrayFree(PMIDL_STUB_MESSAGE pStubMsg,
2504 unsigned char *pMemory,
2505 PFORMAT_STRING pFormat)
2507 ULONG i, count, def;
2509 TRACE("(%p,%p,%p)\n", pStubMsg, pMemory, pFormat);
2511 if (pFormat[0] != RPC_FC_BOGUS_ARRAY)
2513 ERR("invalid format type %x\n", pFormat[0]);
2514 RpcRaiseException(RPC_S_INTERNAL_ERROR);
2518 def = *(const WORD*)&pFormat[2];
2521 pFormat = ComputeConformance(pStubMsg, pMemory, pFormat, def);
2522 TRACE("conformance = %ld\n", pStubMsg->MaxCount);
2524 pFormat = ComputeVariance(pStubMsg, pMemory, pFormat, pStubMsg->MaxCount);
2525 TRACE("variance = %ld\n", pStubMsg->ActualCount);
2527 count = pStubMsg->ActualCount;
2528 for (i = 0; i < count; i++)
2529 pMemory = ComplexFree(pStubMsg, pMemory, pFormat, NULL);
2532 unsigned long UserMarshalFlags(PMIDL_STUB_MESSAGE pStubMsg)
2534 return MAKELONG(pStubMsg->dwDestContext,
2535 pStubMsg->RpcMsg->DataRepresentation);
2538 #define USER_MARSHAL_PTR_PREFIX \
2539 ( (DWORD)'U' | ( (DWORD)'s' << 8 ) | \
2540 ( (DWORD)'e' << 16 ) | ( (DWORD)'r' << 24 ) )
2542 /***********************************************************************
2543 * NdrUserMarshalMarshall [RPCRT4.@]
2545 unsigned char * WINAPI NdrUserMarshalMarshall(PMIDL_STUB_MESSAGE pStubMsg,
2546 unsigned char *pMemory,
2547 PFORMAT_STRING pFormat)
2549 unsigned flags = pFormat[1];
2550 unsigned index = *(const WORD*)&pFormat[2];
2551 unsigned long uflag = UserMarshalFlags(pStubMsg);
2552 TRACE("(%p,%p,%p)\n", pStubMsg, pMemory, pFormat);
2553 TRACE("index=%d\n", index);
2555 if (flags & USER_MARSHAL_POINTER)
2557 ALIGN_POINTER(pStubMsg->Buffer, 4);
2558 NDR_LOCAL_UINT32_WRITE(pStubMsg->Buffer, USER_MARSHAL_PTR_PREFIX);
2559 pStubMsg->Buffer += 4;
2560 ALIGN_POINTER(pStubMsg->Buffer, 8);
2563 ALIGN_POINTER(pStubMsg->Buffer, (flags & 0xf) + 1);
2566 pStubMsg->StubDesc->aUserMarshalQuadruple[index].pfnMarshall(
2567 &uflag, pStubMsg->Buffer, pMemory);
2569 STD_OVERFLOW_CHECK(pStubMsg);
2574 /***********************************************************************
2575 * NdrUserMarshalUnmarshall [RPCRT4.@]
2577 unsigned char * WINAPI NdrUserMarshalUnmarshall(PMIDL_STUB_MESSAGE pStubMsg,
2578 unsigned char **ppMemory,
2579 PFORMAT_STRING pFormat,
2580 unsigned char fMustAlloc)
2582 unsigned flags = pFormat[1];
2583 unsigned index = *(const WORD*)&pFormat[2];
2584 DWORD memsize = *(const WORD*)&pFormat[4];
2585 unsigned long uflag = UserMarshalFlags(pStubMsg);
2586 TRACE("(%p,%p,%p,%d)\n", pStubMsg, ppMemory, pFormat, fMustAlloc);
2587 TRACE("index=%d\n", index);
2589 if (flags & USER_MARSHAL_POINTER)
2591 ALIGN_POINTER(pStubMsg->Buffer, 4);
2592 /* skip pointer prefix */
2593 pStubMsg->Buffer += 4;
2594 ALIGN_POINTER(pStubMsg->Buffer, 8);
2597 ALIGN_POINTER(pStubMsg->Buffer, (flags & 0xf) + 1);
2599 if (fMustAlloc || !*ppMemory)
2600 *ppMemory = NdrAllocate(pStubMsg, memsize);
2603 pStubMsg->StubDesc->aUserMarshalQuadruple[index].pfnUnmarshall(
2604 &uflag, pStubMsg->Buffer, *ppMemory);
2609 /***********************************************************************
2610 * NdrUserMarshalBufferSize [RPCRT4.@]
2612 void WINAPI NdrUserMarshalBufferSize(PMIDL_STUB_MESSAGE pStubMsg,
2613 unsigned char *pMemory,
2614 PFORMAT_STRING pFormat)
2616 unsigned flags = pFormat[1];
2617 unsigned index = *(const WORD*)&pFormat[2];
2618 DWORD bufsize = *(const WORD*)&pFormat[6];
2619 unsigned long uflag = UserMarshalFlags(pStubMsg);
2620 TRACE("(%p,%p,%p)\n", pStubMsg, pMemory, pFormat);
2621 TRACE("index=%d\n", index);
2623 if (flags & USER_MARSHAL_POINTER)
2625 ALIGN_LENGTH(pStubMsg->BufferLength, 4);
2626 /* skip pointer prefix */
2627 pStubMsg->BufferLength += 4;
2628 ALIGN_LENGTH(pStubMsg->BufferLength, 8);
2631 ALIGN_LENGTH(pStubMsg->BufferLength, (flags & 0xf) + 1);
2634 TRACE("size=%ld\n", bufsize);
2635 pStubMsg->BufferLength += bufsize;
2639 pStubMsg->BufferLength =
2640 pStubMsg->StubDesc->aUserMarshalQuadruple[index].pfnBufferSize(
2641 &uflag, pStubMsg->BufferLength, pMemory);
2644 /***********************************************************************
2645 * NdrUserMarshalMemorySize [RPCRT4.@]
2647 unsigned long WINAPI NdrUserMarshalMemorySize(PMIDL_STUB_MESSAGE pStubMsg,
2648 PFORMAT_STRING pFormat)
2650 unsigned flags = pFormat[1];
2651 unsigned index = *(const WORD*)&pFormat[2];
2652 DWORD memsize = *(const WORD*)&pFormat[4];
2653 DWORD bufsize = *(const WORD*)&pFormat[6];
2655 TRACE("(%p,%p)\n", pStubMsg, pFormat);
2656 TRACE("index=%d\n", index);
2658 pStubMsg->MemorySize += memsize;
2660 if (flags & USER_MARSHAL_POINTER)
2662 ALIGN_POINTER(pStubMsg->Buffer, 4);
2663 /* skip pointer prefix */
2664 pStubMsg->Buffer += 4;
2665 ALIGN_POINTER(pStubMsg->Buffer, 8);
2668 ALIGN_POINTER(pStubMsg->Buffer, (flags & 0xf) + 1);
2670 pStubMsg->Buffer += bufsize;
2672 return pStubMsg->MemorySize;
2675 /***********************************************************************
2676 * NdrUserMarshalFree [RPCRT4.@]
2678 void WINAPI NdrUserMarshalFree(PMIDL_STUB_MESSAGE pStubMsg,
2679 unsigned char *pMemory,
2680 PFORMAT_STRING pFormat)
2682 /* unsigned flags = pFormat[1]; */
2683 unsigned index = *(const WORD*)&pFormat[2];
2684 unsigned long uflag = UserMarshalFlags(pStubMsg);
2685 TRACE("(%p,%p,%p)\n", pStubMsg, pMemory, pFormat);
2686 TRACE("index=%d\n", index);
2688 pStubMsg->StubDesc->aUserMarshalQuadruple[index].pfnFree(
2692 /***********************************************************************
2693 * NdrClearOutParameters [RPCRT4.@]
2695 void WINAPI NdrClearOutParameters(PMIDL_STUB_MESSAGE pStubMsg,
2696 PFORMAT_STRING pFormat,
2699 FIXME("(%p,%p,%p): stub\n", pStubMsg, pFormat, ArgAddr);
2702 /***********************************************************************
2703 * NdrConvert [RPCRT4.@]
2705 void WINAPI NdrConvert( PMIDL_STUB_MESSAGE pStubMsg, PFORMAT_STRING pFormat )
2707 FIXME("(pStubMsg == ^%p, pFormat == ^%p): stub.\n", pStubMsg, pFormat);
2708 /* FIXME: since this stub doesn't do any converting, the proper behavior
2709 is to raise an exception */
2712 /***********************************************************************
2713 * NdrConvert2 [RPCRT4.@]
2715 void WINAPI NdrConvert2( PMIDL_STUB_MESSAGE pStubMsg, PFORMAT_STRING pFormat, long NumberParams )
2717 FIXME("(pStubMsg == ^%p, pFormat == ^%p, NumberParams == %ld): stub.\n",
2718 pStubMsg, pFormat, NumberParams);
2719 /* FIXME: since this stub doesn't do any converting, the proper behavior
2720 is to raise an exception */
2723 typedef struct _NDR_CSTRUCT_FORMAT
2726 unsigned char alignment;
2727 unsigned short memory_size;
2728 short offset_to_array_description;
2729 } NDR_CSTRUCT_FORMAT, NDR_CVSTRUCT_FORMAT;
2731 /***********************************************************************
2732 * NdrConformantStructMarshall [RPCRT4.@]
2734 unsigned char * WINAPI NdrConformantStructMarshall(PMIDL_STUB_MESSAGE pStubMsg,
2735 unsigned char *pMemory,
2736 PFORMAT_STRING pFormat)
2738 const NDR_CSTRUCT_FORMAT * pCStructFormat = (NDR_CSTRUCT_FORMAT*)pFormat;
2739 PFORMAT_STRING pCArrayFormat;
2742 TRACE("(%p, %p, %p)\n", pStubMsg, pMemory, pFormat);
2744 pFormat += sizeof(NDR_CSTRUCT_FORMAT);
2745 if ((pCStructFormat->type != RPC_FC_CPSTRUCT) && (pCStructFormat->type != RPC_FC_CSTRUCT))
2747 ERR("invalid format type %x\n", pCStructFormat->type);
2748 RpcRaiseException(RPC_S_INTERNAL_ERROR);
2752 pCArrayFormat = (unsigned char*)&pCStructFormat->offset_to_array_description +
2753 pCStructFormat->offset_to_array_description;
2754 if (*pCArrayFormat != RPC_FC_CARRAY)
2756 ERR("invalid array format type %x\n", pCStructFormat->type);
2757 RpcRaiseException(RPC_S_INTERNAL_ERROR);
2760 esize = *(const WORD*)(pCArrayFormat+2);
2762 ComputeConformance(pStubMsg, pMemory + pCStructFormat->memory_size,
2763 pCArrayFormat + 4, 0);
2765 WriteConformance(pStubMsg);
2767 ALIGN_POINTER(pStubMsg->Buffer, pCStructFormat->alignment + 1);
2769 TRACE("memory_size = %d\n", pCStructFormat->memory_size);
2771 /* copy constant sized part of struct */
2772 pStubMsg->BufferMark = pStubMsg->Buffer;
2773 memcpy(pStubMsg->Buffer, pMemory, pCStructFormat->memory_size + pStubMsg->MaxCount * esize);
2774 pStubMsg->Buffer += pCStructFormat->memory_size + pStubMsg->MaxCount * esize;
2776 if (pCStructFormat->type == RPC_FC_CPSTRUCT)
2777 EmbeddedPointerMarshall(pStubMsg, pMemory, pFormat);
2779 STD_OVERFLOW_CHECK(pStubMsg);
2784 /***********************************************************************
2785 * NdrConformantStructUnmarshall [RPCRT4.@]
2787 unsigned char * WINAPI NdrConformantStructUnmarshall(PMIDL_STUB_MESSAGE pStubMsg,
2788 unsigned char **ppMemory,
2789 PFORMAT_STRING pFormat,
2790 unsigned char fMustAlloc)
2792 const NDR_CSTRUCT_FORMAT * pCStructFormat = (NDR_CSTRUCT_FORMAT*)pFormat;
2793 PFORMAT_STRING pCArrayFormat;
2796 TRACE("(%p, %p, %p, %d)\n", pStubMsg, ppMemory, pFormat, fMustAlloc);
2798 pFormat += sizeof(NDR_CSTRUCT_FORMAT);
2799 if ((pCStructFormat->type != RPC_FC_CPSTRUCT) && (pCStructFormat->type != RPC_FC_CSTRUCT))
2801 ERR("invalid format type %x\n", pCStructFormat->type);
2802 RpcRaiseException(RPC_S_INTERNAL_ERROR);
2805 pCArrayFormat = (unsigned char*)&pCStructFormat->offset_to_array_description +
2806 pCStructFormat->offset_to_array_description;
2807 if (*pCArrayFormat != RPC_FC_CARRAY)
2809 ERR("invalid array format type %x\n", pCStructFormat->type);
2810 RpcRaiseException(RPC_S_INTERNAL_ERROR);
2813 esize = *(const WORD*)(pCArrayFormat+2);
2815 pCArrayFormat = ReadConformance(pStubMsg, pCArrayFormat + 4);
2817 ALIGN_POINTER(pStubMsg->Buffer, pCStructFormat->alignment + 1);
2819 TRACE("memory_size = %d\n", pCStructFormat->memory_size);
2821 /* work out how much memory to allocate if we need to do so */
2822 if (!*ppMemory || fMustAlloc)
2824 SIZE_T size = pCStructFormat->memory_size + pStubMsg->MaxCount * esize;
2825 *ppMemory = NdrAllocate(pStubMsg, size);
2828 /* now copy the data */
2829 pStubMsg->BufferMark = pStubMsg->Buffer;
2830 memcpy(*ppMemory, pStubMsg->Buffer, pCStructFormat->memory_size + pStubMsg->MaxCount * esize);
2831 pStubMsg->Buffer += pCStructFormat->memory_size + pStubMsg->MaxCount * esize;
2833 if (pCStructFormat->type == RPC_FC_CPSTRUCT)
2834 EmbeddedPointerUnmarshall(pStubMsg, ppMemory, pFormat, fMustAlloc);
2839 /***********************************************************************
2840 * NdrConformantStructBufferSize [RPCRT4.@]
2842 void WINAPI NdrConformantStructBufferSize(PMIDL_STUB_MESSAGE pStubMsg,
2843 unsigned char *pMemory,
2844 PFORMAT_STRING pFormat)
2846 const NDR_CSTRUCT_FORMAT * pCStructFormat = (NDR_CSTRUCT_FORMAT*)pFormat;
2847 PFORMAT_STRING pCArrayFormat;
2850 TRACE("(%p, %p, %p)\n", pStubMsg, pMemory, pFormat);
2852 pFormat += sizeof(NDR_CSTRUCT_FORMAT);
2853 if ((pCStructFormat->type != RPC_FC_CPSTRUCT) && (pCStructFormat->type != RPC_FC_CSTRUCT))
2855 ERR("invalid format type %x\n", pCStructFormat->type);
2856 RpcRaiseException(RPC_S_INTERNAL_ERROR);
2859 pCArrayFormat = (unsigned char*)&pCStructFormat->offset_to_array_description +
2860 pCStructFormat->offset_to_array_description;
2861 if (*pCArrayFormat != RPC_FC_CARRAY)
2863 ERR("invalid array format type %x\n", pCStructFormat->type);
2864 RpcRaiseException(RPC_S_INTERNAL_ERROR);
2867 esize = *(const WORD*)(pCArrayFormat+2);
2869 pCArrayFormat = ComputeConformance(pStubMsg, pMemory + pCStructFormat->memory_size, pCArrayFormat+4, 0);
2870 SizeConformance(pStubMsg);
2872 ALIGN_LENGTH(pStubMsg->BufferLength, pCStructFormat->alignment + 1);
2874 TRACE("memory_size = %d\n", pCStructFormat->memory_size);
2876 pStubMsg->BufferLength += pCStructFormat->memory_size + esize * pStubMsg->MaxCount;
2878 if (pCStructFormat->type == RPC_FC_CPSTRUCT)
2879 EmbeddedPointerBufferSize(pStubMsg, pMemory, pFormat);
2882 /***********************************************************************
2883 * NdrConformantStructMemorySize [RPCRT4.@]
2885 unsigned long WINAPI NdrConformantStructMemorySize(PMIDL_STUB_MESSAGE pStubMsg,
2886 PFORMAT_STRING pFormat)
2892 /***********************************************************************
2893 * NdrConformantStructFree [RPCRT4.@]
2895 void WINAPI NdrConformantStructFree(PMIDL_STUB_MESSAGE pStubMsg,
2896 unsigned char *pMemory,
2897 PFORMAT_STRING pFormat)
2902 /***********************************************************************
2903 * NdrConformantVaryingStructMarshall [RPCRT4.@]
2905 unsigned char * WINAPI NdrConformantVaryingStructMarshall(PMIDL_STUB_MESSAGE pStubMsg,
2906 unsigned char *pMemory,
2907 PFORMAT_STRING pFormat)
2909 const NDR_CVSTRUCT_FORMAT * pCVStructFormat = (NDR_CVSTRUCT_FORMAT*)pFormat;
2910 PFORMAT_STRING pCVArrayFormat;
2913 TRACE("(%p, %p, %p)\n", pStubMsg, pMemory, pFormat);
2915 pFormat += sizeof(NDR_CVSTRUCT_FORMAT);
2916 if (pCVStructFormat->type != RPC_FC_CVSTRUCT)
2918 ERR("invalid format type %x\n", pCVStructFormat->type);
2919 RpcRaiseException(RPC_S_INTERNAL_ERROR);
2923 pCVArrayFormat = (unsigned char*)&pCVStructFormat->offset_to_array_description +
2924 pCVStructFormat->offset_to_array_description;
2925 switch (*pCVArrayFormat)
2927 case RPC_FC_CVARRAY:
2928 esize = *(const WORD*)(pCVArrayFormat+2);
2930 pCVArrayFormat = ComputeConformance(pStubMsg, pMemory + pCVStructFormat->memory_size,
2931 pCVArrayFormat + 4, 0);
2932 pCVArrayFormat = ComputeVariance(pStubMsg, pMemory + pCVStructFormat->memory_size,
2935 case RPC_FC_C_CSTRING:
2936 TRACE("string=%s\n", debugstr_a((char*)pMemory + pCVStructFormat->memory_size));
2937 pStubMsg->ActualCount = strlen((char*)pMemory + pCVStructFormat->memory_size)+1;
2938 esize = sizeof(char);
2939 if (pCVArrayFormat[1] == RPC_FC_STRING_SIZED)
2940 pCVArrayFormat = ComputeConformance(pStubMsg, pMemory + pCVStructFormat->memory_size,
2941 pCVArrayFormat + 2, 0);
2943 pStubMsg->MaxCount = pStubMsg->ActualCount;
2945 case RPC_FC_C_WSTRING:
2946 TRACE("string=%s\n", debugstr_w((LPWSTR)pMemory + pCVStructFormat->memory_size));
2947 pStubMsg->ActualCount = strlenW((LPWSTR)pMemory + pCVStructFormat->memory_size)+1;
2948 esize = sizeof(WCHAR);
2949 if (pCVArrayFormat[1] == RPC_FC_STRING_SIZED)
2950 pCVArrayFormat = ComputeConformance(pStubMsg, pMemory + pCVStructFormat->memory_size,
2951 pCVArrayFormat + 2, 0);
2953 pStubMsg->MaxCount = pStubMsg->ActualCount;
2956 ERR("invalid array format type %x\n", *pCVArrayFormat);
2957 RpcRaiseException(RPC_S_INTERNAL_ERROR);
2961 WriteConformance(pStubMsg);
2963 ALIGN_POINTER(pStubMsg->Buffer, pCVStructFormat->alignment + 1);
2965 TRACE("memory_size = %d\n", pCVStructFormat->memory_size);
2967 /* write constant sized part */
2968 pStubMsg->BufferMark = pStubMsg->Buffer;
2969 memcpy(pStubMsg->Buffer, pMemory, pCVStructFormat->memory_size);
2970 pStubMsg->Buffer += pCVStructFormat->memory_size;
2972 WriteVariance(pStubMsg);
2974 /* write array part */
2975 memcpy(pStubMsg->Buffer, pMemory + pCVStructFormat->memory_size, pStubMsg->ActualCount * esize);
2976 pStubMsg->Buffer += pStubMsg->ActualCount * esize;
2978 EmbeddedPointerMarshall(pStubMsg, pMemory, pFormat);
2980 STD_OVERFLOW_CHECK(pStubMsg);
2985 /***********************************************************************
2986 * NdrConformantVaryingStructUnmarshall [RPCRT4.@]
2988 unsigned char * WINAPI NdrConformantVaryingStructUnmarshall(PMIDL_STUB_MESSAGE pStubMsg,
2989 unsigned char **ppMemory,
2990 PFORMAT_STRING pFormat,
2991 unsigned char fMustAlloc)
2993 const NDR_CVSTRUCT_FORMAT * pCVStructFormat = (NDR_CVSTRUCT_FORMAT*)pFormat;
2994 PFORMAT_STRING pCVArrayFormat;
2996 unsigned char cvarray_type;
2998 TRACE("(%p, %p, %p, %d)\n", pStubMsg, ppMemory, pFormat, fMustAlloc);
3000 pFormat += sizeof(NDR_CVSTRUCT_FORMAT);
3001 if (pCVStructFormat->type != RPC_FC_CVSTRUCT)
3003 ERR("invalid format type %x\n", pCVStructFormat->type);
3004 RpcRaiseException(RPC_S_INTERNAL_ERROR);
3008 pCVArrayFormat = (unsigned char*)&pCVStructFormat->offset_to_array_description +
3009 pCVStructFormat->offset_to_array_description;
3010 cvarray_type = *pCVArrayFormat;
3011 switch (cvarray_type)
3013 case RPC_FC_CVARRAY:
3014 esize = *(const WORD*)(pCVArrayFormat+2);
3015 pCVArrayFormat = ReadConformance(pStubMsg, pCVArrayFormat + 4);
3017 case RPC_FC_C_CSTRING:
3018 esize = sizeof(char);
3019 if (pCVArrayFormat[1] == RPC_FC_STRING_SIZED)
3020 pCVArrayFormat = ReadConformance(pStubMsg, pCVArrayFormat + 2);
3022 pCVArrayFormat = ReadConformance(pStubMsg, NULL);
3024 case RPC_FC_C_WSTRING:
3025 esize = sizeof(WCHAR);
3026 if (pCVArrayFormat[1] == RPC_FC_STRING_SIZED)
3027 pCVArrayFormat = ReadConformance(pStubMsg, pCVArrayFormat + 2);
3029 pCVArrayFormat = ReadConformance(pStubMsg, NULL);
3032 ERR("invalid array format type %x\n", *pCVArrayFormat);
3033 RpcRaiseException(RPC_S_INTERNAL_ERROR);
3037 ALIGN_POINTER(pStubMsg->Buffer, pCVStructFormat->alignment + 1);
3039 TRACE("memory_size = %d\n", pCVStructFormat->memory_size);
3041 /* work out how much memory to allocate if we need to do so */
3042 if (!*ppMemory || fMustAlloc)
3044 SIZE_T size = pCVStructFormat->memory_size + pStubMsg->MaxCount * esize;
3045 *ppMemory = NdrAllocate(pStubMsg, size);
3048 /* copy the constant data */
3049 pStubMsg->BufferMark = pStubMsg->Buffer;
3050 memcpy(*ppMemory, pStubMsg->Buffer, pCVStructFormat->memory_size);
3051 pStubMsg->Buffer += pCVStructFormat->memory_size;
3053 pCVArrayFormat = ReadVariance(pStubMsg, pCVArrayFormat);
3055 /* copy the array data */
3056 memcpy(*ppMemory + pCVStructFormat->memory_size, pStubMsg->Buffer,
3057 pStubMsg->ActualCount * esize);
3058 pStubMsg->Buffer += pStubMsg->ActualCount * esize;
3060 if (cvarray_type == RPC_FC_C_CSTRING)
3061 TRACE("string=%s\n", debugstr_a((char *)(*ppMemory + pCVStructFormat->memory_size)));
3062 else if (cvarray_type == RPC_FC_C_WSTRING)
3063 TRACE("string=%s\n", debugstr_w((WCHAR *)(*ppMemory + pCVStructFormat->memory_size)));
3065 EmbeddedPointerUnmarshall(pStubMsg, ppMemory, pFormat, fMustAlloc);
3070 /***********************************************************************
3071 * NdrConformantVaryingStructBufferSize [RPCRT4.@]
3073 void WINAPI NdrConformantVaryingStructBufferSize(PMIDL_STUB_MESSAGE pStubMsg,
3074 unsigned char *pMemory,
3075 PFORMAT_STRING pFormat)
3077 const NDR_CVSTRUCT_FORMAT * pCVStructFormat = (NDR_CVSTRUCT_FORMAT*)pFormat;
3078 PFORMAT_STRING pCVArrayFormat;
3081 TRACE("(%p, %p, %p)\n", pStubMsg, pMemory, pFormat);
3083 pFormat += sizeof(NDR_CVSTRUCT_FORMAT);
3084 if (pCVStructFormat->type != RPC_FC_CVSTRUCT)
3086 ERR("invalid format type %x\n", pCVStructFormat->type);
3087 RpcRaiseException(RPC_S_INTERNAL_ERROR);
3091 pCVArrayFormat = (unsigned char*)&pCVStructFormat->offset_to_array_description +
3092 pCVStructFormat->offset_to_array_description;
3093 switch (*pCVArrayFormat)
3095 case RPC_FC_CVARRAY:
3096 esize = *(const WORD*)(pCVArrayFormat+2);
3098 pCVArrayFormat = ComputeConformance(pStubMsg, pMemory + pCVStructFormat->memory_size,
3099 pCVArrayFormat + 4, 0);
3100 pCVArrayFormat = ComputeVariance(pStubMsg, pMemory + pCVStructFormat->memory_size,
3101 pCVArrayFormat + 4, 0);
3103 case RPC_FC_C_CSTRING:
3104 TRACE("string=%s\n", debugstr_a((char*)pMemory + pCVStructFormat->memory_size));
3105 pStubMsg->ActualCount = strlen((char*)pMemory + pCVStructFormat->memory_size)+1;
3106 esize = sizeof(char);
3107 if (pCVArrayFormat[1] == RPC_FC_STRING_SIZED)
3108 pCVArrayFormat = ComputeConformance(pStubMsg, pMemory + pCVStructFormat->memory_size,
3109 pCVArrayFormat + 2, 0);
3111 pStubMsg->MaxCount = pStubMsg->ActualCount;
3113 case RPC_FC_C_WSTRING:
3114 TRACE("string=%s\n", debugstr_w((LPWSTR)pMemory + pCVStructFormat->memory_size));
3115 pStubMsg->ActualCount = strlenW((LPWSTR)pMemory + pCVStructFormat->memory_size)+1;
3116 esize = sizeof(WCHAR);
3117 if (pCVArrayFormat[1] == RPC_FC_STRING_SIZED)
3118 pCVArrayFormat = ComputeConformance(pStubMsg, pMemory + pCVStructFormat->memory_size,
3119 pCVArrayFormat + 2, 0);
3121 pStubMsg->MaxCount = pStubMsg->ActualCount;
3124 ERR("invalid array format type %x\n", *pCVArrayFormat);
3125 RpcRaiseException(RPC_S_INTERNAL_ERROR);
3129 SizeConformance(pStubMsg);
3131 ALIGN_LENGTH(pStubMsg->BufferLength, pCVStructFormat->alignment + 1);
3133 TRACE("memory_size = %d\n", pCVStructFormat->memory_size);
3135 pStubMsg->BufferLength += pCVStructFormat->memory_size;
3136 SizeVariance(pStubMsg);
3137 pStubMsg->BufferLength += esize * pStubMsg->MaxCount;
3139 EmbeddedPointerBufferSize(pStubMsg, pMemory, pFormat);
3142 /***********************************************************************
3143 * NdrConformantVaryingStructMemorySize [RPCRT4.@]
3145 unsigned long WINAPI NdrConformantVaryingStructMemorySize(PMIDL_STUB_MESSAGE pStubMsg,
3146 PFORMAT_STRING pFormat)
3148 const NDR_CVSTRUCT_FORMAT * pCVStructFormat = (NDR_CVSTRUCT_FORMAT*)pFormat;
3149 PFORMAT_STRING pCVArrayFormat;
3151 unsigned char cvarray_type;
3153 TRACE("(%p, %p)\n", pStubMsg, pFormat);
3155 pFormat += sizeof(NDR_CVSTRUCT_FORMAT);
3156 if (pCVStructFormat->type != RPC_FC_CVSTRUCT)
3158 ERR("invalid format type %x\n", pCVStructFormat->type);
3159 RpcRaiseException(RPC_S_INTERNAL_ERROR);
3163 pCVArrayFormat = (unsigned char*)&pCVStructFormat->offset_to_array_description +
3164 pCVStructFormat->offset_to_array_description;
3165 cvarray_type = *pCVArrayFormat;
3166 switch (cvarray_type)
3168 case RPC_FC_CVARRAY:
3169 esize = *(const WORD*)(pCVArrayFormat+2);
3170 pCVArrayFormat = ReadConformance(pStubMsg, pCVArrayFormat + 4);
3172 case RPC_FC_C_CSTRING:
3173 esize = sizeof(char);
3174 if (pCVArrayFormat[1] == RPC_FC_STRING_SIZED)
3175 pCVArrayFormat = ReadConformance(pStubMsg, pCVArrayFormat + 2);
3177 pCVArrayFormat = ReadConformance(pStubMsg, NULL);
3179 case RPC_FC_C_WSTRING:
3180 esize = sizeof(WCHAR);
3181 if (pCVArrayFormat[1] == RPC_FC_STRING_SIZED)
3182 pCVArrayFormat = ReadConformance(pStubMsg, pCVArrayFormat + 2);
3184 pCVArrayFormat = ReadConformance(pStubMsg, NULL);
3187 ERR("invalid array format type %x\n", *pCVArrayFormat);
3188 RpcRaiseException(RPC_S_INTERNAL_ERROR);
3192 ALIGN_POINTER(pStubMsg->Buffer, pCVStructFormat->alignment + 1);
3194 TRACE("memory_size = %d\n", pCVStructFormat->memory_size);
3196 pStubMsg->Buffer += pCVStructFormat->memory_size;
3197 pCVArrayFormat = ReadVariance(pStubMsg, pCVArrayFormat);
3198 pStubMsg->Buffer += pCVStructFormat->memory_size + pStubMsg->ActualCount * esize;
3200 pStubMsg->MemorySize += pCVStructFormat->memory_size + pStubMsg->MaxCount * esize;
3202 EmbeddedPointerMemorySize(pStubMsg, pFormat);
3204 return pCVStructFormat->memory_size + pStubMsg->MaxCount * esize;
3207 /***********************************************************************
3208 * NdrConformantVaryingStructFree [RPCRT4.@]
3210 void WINAPI NdrConformantVaryingStructFree(PMIDL_STUB_MESSAGE pStubMsg,
3211 unsigned char *pMemory,
3212 PFORMAT_STRING pFormat)
3214 const NDR_CVSTRUCT_FORMAT * pCVStructFormat = (NDR_CVSTRUCT_FORMAT*)pFormat;
3215 PFORMAT_STRING pCVArrayFormat;
3218 TRACE("(%p, %p, %p)\n", pStubMsg, pMemory, pFormat);
3220 pFormat += sizeof(NDR_CVSTRUCT_FORMAT);
3221 if (pCVStructFormat->type != RPC_FC_CVSTRUCT)
3223 ERR("invalid format type %x\n", pCVStructFormat->type);
3224 RpcRaiseException(RPC_S_INTERNAL_ERROR);
3228 pCVArrayFormat = (unsigned char*)&pCVStructFormat->offset_to_array_description +
3229 pCVStructFormat->offset_to_array_description;
3230 switch (*pCVArrayFormat)
3232 case RPC_FC_CVARRAY:
3233 esize = *(const WORD*)(pCVArrayFormat+2);
3235 pCVArrayFormat = ComputeConformance(pStubMsg, pMemory + pCVStructFormat->memory_size,
3236 pCVArrayFormat + 4, 0);
3237 pCVArrayFormat = ComputeVariance(pStubMsg, pMemory + pCVStructFormat->memory_size,
3240 case RPC_FC_C_CSTRING:
3241 TRACE("string=%s\n", debugstr_a((char*)pMemory + pCVStructFormat->memory_size));
3242 pStubMsg->ActualCount = strlen((char*)pMemory + pCVStructFormat->memory_size)+1;
3243 esize = sizeof(char);
3244 if (pCVArrayFormat[1] == RPC_FC_STRING_SIZED)
3245 pCVArrayFormat = ComputeConformance(pStubMsg, pMemory + pCVStructFormat->memory_size,
3246 pCVArrayFormat + 2, 0);
3248 pStubMsg->MaxCount = pStubMsg->ActualCount;
3250 case RPC_FC_C_WSTRING:
3251 TRACE("string=%s\n", debugstr_w((LPWSTR)pMemory + pCVStructFormat->memory_size));
3252 pStubMsg->ActualCount = strlenW((LPWSTR)pMemory + pCVStructFormat->memory_size)+1;
3253 esize = sizeof(WCHAR);
3254 if (pCVArrayFormat[1] == RPC_FC_STRING_SIZED)
3255 pCVArrayFormat = ComputeConformance(pStubMsg, pMemory + pCVStructFormat->memory_size,
3256 pCVArrayFormat + 2, 0);
3258 pStubMsg->MaxCount = pStubMsg->ActualCount;
3261 ERR("invalid array format type %x\n", *pCVArrayFormat);
3262 RpcRaiseException(RPC_S_INTERNAL_ERROR);
3266 TRACE("memory_size = %d\n", pCVStructFormat->memory_size);
3268 EmbeddedPointerFree(pStubMsg, pMemory, pFormat);
3274 unsigned char alignment;
3275 unsigned short total_size;
3276 } NDR_SMFARRAY_FORMAT;
3281 unsigned char alignment;
3282 unsigned long total_size;
3283 } NDR_LGFARRAY_FORMAT;
3285 /***********************************************************************
3286 * NdrFixedArrayMarshall [RPCRT4.@]
3288 unsigned char * WINAPI NdrFixedArrayMarshall(PMIDL_STUB_MESSAGE pStubMsg,
3289 unsigned char *pMemory,
3290 PFORMAT_STRING pFormat)
3292 const NDR_SMFARRAY_FORMAT *pSmFArrayFormat = (const NDR_SMFARRAY_FORMAT *)pFormat;
3293 unsigned long total_size;
3295 TRACE("(%p, %p, %p)\n", pStubMsg, pMemory, pFormat);
3297 if ((pSmFArrayFormat->type != RPC_FC_SMFARRAY) &&
3298 (pSmFArrayFormat->type != RPC_FC_LGFARRAY))
3300 ERR("invalid format type %x\n", pSmFArrayFormat->type);
3301 RpcRaiseException(RPC_S_INTERNAL_ERROR);
3305 ALIGN_POINTER(pStubMsg->Buffer, pSmFArrayFormat->alignment + 1);
3307 if (pSmFArrayFormat->type == RPC_FC_SMFARRAY)
3309 total_size = pSmFArrayFormat->total_size;
3310 pFormat = (unsigned char *)(pSmFArrayFormat + 1);
3314 const NDR_LGFARRAY_FORMAT *pLgFArrayFormat = (const NDR_LGFARRAY_FORMAT *)pFormat;
3315 total_size = pLgFArrayFormat->total_size;
3316 pFormat = (unsigned char *)(pLgFArrayFormat + 1);
3318 memcpy(pStubMsg->Buffer, pMemory, total_size);
3319 pStubMsg->Buffer += total_size;
3321 pFormat = EmbeddedPointerMarshall(pStubMsg, pMemory, pFormat);
3326 /***********************************************************************
3327 * NdrFixedArrayUnmarshall [RPCRT4.@]
3329 unsigned char * WINAPI NdrFixedArrayUnmarshall(PMIDL_STUB_MESSAGE pStubMsg,
3330 unsigned char **ppMemory,
3331 PFORMAT_STRING pFormat,
3332 unsigned char fMustAlloc)
3334 const NDR_SMFARRAY_FORMAT *pSmFArrayFormat = (const NDR_SMFARRAY_FORMAT *)pFormat;
3335 unsigned long total_size;
3337 TRACE("(%p, %p, %p, %d)\n", pStubMsg, ppMemory, pFormat, fMustAlloc);
3339 if ((pSmFArrayFormat->type != RPC_FC_SMFARRAY) &&
3340 (pSmFArrayFormat->type != RPC_FC_LGFARRAY))
3342 ERR("invalid format type %x\n", pSmFArrayFormat->type);
3343 RpcRaiseException(RPC_S_INTERNAL_ERROR);
3347 ALIGN_POINTER(pStubMsg->Buffer, pSmFArrayFormat->alignment + 1);
3349 if (pSmFArrayFormat->type == RPC_FC_SMFARRAY)
3351 total_size = pSmFArrayFormat->total_size;
3352 pFormat = (unsigned char *)(pSmFArrayFormat + 1);
3356 const NDR_LGFARRAY_FORMAT *pLgFArrayFormat = (const NDR_LGFARRAY_FORMAT *)pFormat;
3357 total_size = pLgFArrayFormat->total_size;
3358 pFormat = (unsigned char *)(pLgFArrayFormat + 1);
3361 if (fMustAlloc || !*ppMemory)
3362 *ppMemory = NdrAllocate(pStubMsg, total_size);
3363 memcpy(*ppMemory, pStubMsg->Buffer, total_size);
3364 pStubMsg->Buffer += total_size;
3366 pFormat = EmbeddedPointerUnmarshall(pStubMsg, ppMemory, pFormat, fMustAlloc);
3371 /***********************************************************************
3372 * NdrFixedArrayBufferSize [RPCRT4.@]
3374 void WINAPI NdrFixedArrayBufferSize(PMIDL_STUB_MESSAGE pStubMsg,
3375 unsigned char *pMemory,
3376 PFORMAT_STRING pFormat)
3378 const NDR_SMFARRAY_FORMAT *pSmFArrayFormat = (const NDR_SMFARRAY_FORMAT *)pFormat;
3379 unsigned long total_size;
3381 TRACE("(%p, %p, %p)\n", pStubMsg, pMemory, pFormat);
3383 if ((pSmFArrayFormat->type != RPC_FC_SMFARRAY) &&
3384 (pSmFArrayFormat->type != RPC_FC_LGFARRAY))
3386 ERR("invalid format type %x\n", pSmFArrayFormat->type);
3387 RpcRaiseException(RPC_S_INTERNAL_ERROR);
3391 ALIGN_LENGTH(pStubMsg->BufferLength, pSmFArrayFormat->alignment + 1);
3393 if (pSmFArrayFormat->type == RPC_FC_SMFARRAY)
3395 total_size = pSmFArrayFormat->total_size;
3396 pFormat = (unsigned char *)(pSmFArrayFormat + 1);
3400 const NDR_LGFARRAY_FORMAT *pLgFArrayFormat = (const NDR_LGFARRAY_FORMAT *)pFormat;
3401 total_size = pLgFArrayFormat->total_size;
3402 pFormat = (unsigned char *)(pLgFArrayFormat + 1);
3404 pStubMsg->BufferLength += total_size;
3406 EmbeddedPointerBufferSize(pStubMsg, pMemory, pFormat);
3409 /***********************************************************************
3410 * NdrFixedArrayMemorySize [RPCRT4.@]
3412 unsigned long WINAPI NdrFixedArrayMemorySize(PMIDL_STUB_MESSAGE pStubMsg,
3413 PFORMAT_STRING pFormat)
3415 const NDR_SMFARRAY_FORMAT *pSmFArrayFormat = (const NDR_SMFARRAY_FORMAT *)pFormat;
3416 unsigned long total_size;
3418 TRACE("(%p, %p)\n", pStubMsg, pFormat);
3420 if ((pSmFArrayFormat->type != RPC_FC_SMFARRAY) &&
3421 (pSmFArrayFormat->type != RPC_FC_LGFARRAY))
3423 ERR("invalid format type %x\n", pSmFArrayFormat->type);
3424 RpcRaiseException(RPC_S_INTERNAL_ERROR);
3428 ALIGN_POINTER(pStubMsg->Buffer, pSmFArrayFormat->alignment + 1);
3430 if (pSmFArrayFormat->type == RPC_FC_SMFARRAY)
3432 total_size = pSmFArrayFormat->total_size;
3433 pFormat = (unsigned char *)(pSmFArrayFormat + 1);
3437 const NDR_LGFARRAY_FORMAT *pLgFArrayFormat = (const NDR_LGFARRAY_FORMAT *)pFormat;
3438 total_size = pLgFArrayFormat->total_size;
3439 pFormat = (unsigned char *)(pLgFArrayFormat + 1);
3441 pStubMsg->Buffer += total_size;
3442 pStubMsg->MemorySize += total_size;
3444 EmbeddedPointerMemorySize(pStubMsg, pFormat);
3449 /***********************************************************************
3450 * NdrFixedArrayFree [RPCRT4.@]
3452 void WINAPI NdrFixedArrayFree(PMIDL_STUB_MESSAGE pStubMsg,
3453 unsigned char *pMemory,
3454 PFORMAT_STRING pFormat)
3456 const NDR_SMFARRAY_FORMAT *pSmFArrayFormat = (const NDR_SMFARRAY_FORMAT *)pFormat;
3458 TRACE("(%p, %p, %p)\n", pStubMsg, pMemory, pFormat);
3460 if ((pSmFArrayFormat->type != RPC_FC_SMFARRAY) &&
3461 (pSmFArrayFormat->type != RPC_FC_LGFARRAY))
3463 ERR("invalid format type %x\n", pSmFArrayFormat->type);
3464 RpcRaiseException(RPC_S_INTERNAL_ERROR);
3468 if (pSmFArrayFormat->type == RPC_FC_SMFARRAY)
3469 pFormat = (unsigned char *)(pSmFArrayFormat + 1);
3472 const NDR_LGFARRAY_FORMAT *pLgFArrayFormat = (const NDR_LGFARRAY_FORMAT *)pFormat;
3473 pFormat = (unsigned char *)(pLgFArrayFormat + 1);
3476 EmbeddedPointerFree(pStubMsg, pMemory, pFormat);
3479 /***********************************************************************
3480 * NdrVaryingArrayMarshall [RPCRT4.@]
3482 unsigned char * WINAPI NdrVaryingArrayMarshall(PMIDL_STUB_MESSAGE pStubMsg,
3483 unsigned char *pMemory,
3484 PFORMAT_STRING pFormat)
3490 /***********************************************************************
3491 * NdrVaryingArrayUnmarshall [RPCRT4.@]
3493 unsigned char * WINAPI NdrVaryingArrayUnmarshall(PMIDL_STUB_MESSAGE pStubMsg,
3494 unsigned char **ppMemory,
3495 PFORMAT_STRING pFormat,
3496 unsigned char fMustAlloc)
3502 /***********************************************************************
3503 * NdrVaryingArrayBufferSize [RPCRT4.@]
3505 void WINAPI NdrVaryingArrayBufferSize(PMIDL_STUB_MESSAGE pStubMsg,
3506 unsigned char *pMemory,
3507 PFORMAT_STRING pFormat)
3512 /***********************************************************************
3513 * NdrVaryingArrayMemorySize [RPCRT4.@]
3515 unsigned long WINAPI NdrVaryingArrayMemorySize(PMIDL_STUB_MESSAGE pStubMsg,
3516 PFORMAT_STRING pFormat)
3522 /***********************************************************************
3523 * NdrVaryingArrayFree [RPCRT4.@]
3525 void WINAPI NdrVaryingArrayFree(PMIDL_STUB_MESSAGE pStubMsg,
3526 unsigned char *pMemory,
3527 PFORMAT_STRING pFormat)
3532 /***********************************************************************
3533 * NdrEncapsulatedUnionMarshall [RPCRT4.@]
3535 unsigned char * WINAPI NdrEncapsulatedUnionMarshall(PMIDL_STUB_MESSAGE pStubMsg,
3536 unsigned char *pMemory,
3537 PFORMAT_STRING pFormat)
3543 /***********************************************************************
3544 * NdrEncapsulatedUnionUnmarshall [RPCRT4.@]
3546 unsigned char * WINAPI NdrEncapsulatedUnionUnmarshall(PMIDL_STUB_MESSAGE pStubMsg,
3547 unsigned char **ppMemory,
3548 PFORMAT_STRING pFormat,
3549 unsigned char fMustAlloc)
3555 /***********************************************************************
3556 * NdrEncapsulatedUnionBufferSize [RPCRT4.@]
3558 void WINAPI NdrEncapsulatedUnionBufferSize(PMIDL_STUB_MESSAGE pStubMsg,
3559 unsigned char *pMemory,
3560 PFORMAT_STRING pFormat)
3565 /***********************************************************************
3566 * NdrEncapsulatedUnionMemorySize [RPCRT4.@]
3568 unsigned long WINAPI NdrEncapsulatedUnionMemorySize(PMIDL_STUB_MESSAGE pStubMsg,
3569 PFORMAT_STRING pFormat)
3575 /***********************************************************************
3576 * NdrEncapsulatedUnionFree [RPCRT4.@]
3578 void WINAPI NdrEncapsulatedUnionFree(PMIDL_STUB_MESSAGE pStubMsg,
3579 unsigned char *pMemory,
3580 PFORMAT_STRING pFormat)
3585 static PFORMAT_STRING get_arm_offset_from_union_arm_selector(PMIDL_STUB_MESSAGE pStubMsg,
3586 unsigned long discriminant,
3587 PFORMAT_STRING pFormat)
3589 unsigned short num_arms, arm, type;
3591 num_arms = *(const SHORT*)pFormat & 0x0fff;
3593 for(arm = 0; arm < num_arms; arm++)
3595 if(discriminant == *(const ULONG*)pFormat)
3603 type = *(const unsigned short*)pFormat;
3604 TRACE("type %04x\n", type);
3605 if(arm == num_arms) /* default arm extras */
3609 ERR("no arm for 0x%lx and no default case\n", discriminant);
3610 RpcRaiseException(RPC_S_INVALID_TAG);
3615 TRACE("falling back to empty default case for 0x%lx\n", discriminant);
3622 static PFORMAT_STRING get_non_encapsulated_union_arm(PMIDL_STUB_MESSAGE pStubMsg,
3624 PFORMAT_STRING pFormat)
3626 pFormat += *(const SHORT*)pFormat;
3629 return get_arm_offset_from_union_arm_selector(pStubMsg, value, pFormat);
3632 /***********************************************************************
3633 * NdrNonEncapsulatedUnionMarshall [RPCRT4.@]
3635 unsigned char * WINAPI NdrNonEncapsulatedUnionMarshall(PMIDL_STUB_MESSAGE pStubMsg,
3636 unsigned char *pMemory,
3637 PFORMAT_STRING pFormat)
3639 unsigned short type;
3640 unsigned char switch_type;
3642 TRACE("(%p, %p, %p)\n", pStubMsg, pMemory, pFormat);
3645 switch_type = *pFormat;
3648 pFormat = ComputeConformance(pStubMsg, pMemory, pFormat, 0);
3649 TRACE("got switch value 0x%lx\n", pStubMsg->MaxCount);
3650 /* Marshall discriminant */
3651 NdrBaseTypeMarshall(pStubMsg, (unsigned char *)&pStubMsg->MaxCount, &switch_type);
3653 pFormat = get_non_encapsulated_union_arm(pStubMsg, pStubMsg->MaxCount, pFormat);
3657 type = *(const unsigned short*)pFormat;
3658 if((type & 0xff00) == 0x8000)
3660 unsigned char basetype = LOBYTE(type);
3661 return NdrBaseTypeMarshall(pStubMsg, pMemory, &basetype);
3665 PFORMAT_STRING desc = pFormat + *(const SHORT*)pFormat;
3666 NDR_MARSHALL m = NdrMarshaller[*desc & NDR_TABLE_MASK];
3669 unsigned char *saved_buffer = NULL;
3676 saved_buffer = pStubMsg->Buffer;
3677 pStubMsg->Buffer += 4; /* for pointer ID */
3678 PointerMarshall(pStubMsg, saved_buffer, *(unsigned char **)pMemory, desc);
3681 m(pStubMsg, pMemory, desc);
3684 else FIXME("no marshaller for embedded type %02x\n", *desc);
3689 static long unmarshall_discriminant(PMIDL_STUB_MESSAGE pStubMsg,
3690 PFORMAT_STRING *ppFormat)
3692 long discriminant = 0;
3700 discriminant = *(UCHAR *)pStubMsg->Buffer;
3701 pStubMsg->Buffer += sizeof(UCHAR);
3706 ALIGN_POINTER(pStubMsg->Buffer, sizeof(USHORT));
3707 discriminant = *(USHORT *)pStubMsg->Buffer;
3708 pStubMsg->Buffer += sizeof(USHORT);
3712 ALIGN_POINTER(pStubMsg->Buffer, sizeof(ULONG));
3713 discriminant = *(ULONG *)pStubMsg->Buffer;
3714 pStubMsg->Buffer += sizeof(ULONG);
3717 FIXME("Unhandled base type: 0x%02x\n", **ppFormat);
3721 if (pStubMsg->fHasNewCorrDesc)
3725 return discriminant;
3728 /**********************************************************************
3729 * NdrNonEncapsulatedUnionUnmarshall[RPCRT4.@]
3731 unsigned char * WINAPI NdrNonEncapsulatedUnionUnmarshall(PMIDL_STUB_MESSAGE pStubMsg,
3732 unsigned char **ppMemory,
3733 PFORMAT_STRING pFormat,
3734 unsigned char fMustAlloc)
3737 unsigned short type, size;
3739 TRACE("(%p, %p, %p, %d)\n", pStubMsg, ppMemory, pFormat, fMustAlloc);
3742 /* Unmarshall discriminant */
3743 discriminant = unmarshall_discriminant(pStubMsg, &pFormat);
3744 TRACE("unmarshalled discriminant %lx\n", discriminant);
3746 pFormat += *(const SHORT*)pFormat;
3748 size = *(const unsigned short*)pFormat;
3751 pFormat = get_arm_offset_from_union_arm_selector(pStubMsg, discriminant, pFormat);
3755 if(!*ppMemory || fMustAlloc)
3756 *ppMemory = NdrAllocate(pStubMsg, size);
3758 type = *(const unsigned short*)pFormat;
3759 if((type & 0xff00) == 0x8000)
3761 unsigned char basetype = LOBYTE(type);
3762 return NdrBaseTypeUnmarshall(pStubMsg, ppMemory, &basetype, fMustAlloc);
3766 PFORMAT_STRING desc = pFormat + *(const SHORT*)pFormat;
3767 NDR_UNMARSHALL m = NdrUnmarshaller[*desc & NDR_TABLE_MASK];
3770 unsigned char *saved_buffer = NULL;
3777 ALIGN_POINTER(pStubMsg->Buffer, 4);
3778 saved_buffer = pStubMsg->Buffer;
3779 pStubMsg->Buffer += 4; /* for pointer ID */
3780 PointerUnmarshall(pStubMsg, saved_buffer, *(unsigned char ***)ppMemory, desc, TRUE);
3783 m(pStubMsg, ppMemory, desc, fMustAlloc);
3786 else FIXME("no marshaller for embedded type %02x\n", *desc);
3791 /***********************************************************************
3792 * NdrNonEncapsulatedUnionBufferSize [RPCRT4.@]
3794 void WINAPI NdrNonEncapsulatedUnionBufferSize(PMIDL_STUB_MESSAGE pStubMsg,
3795 unsigned char *pMemory,
3796 PFORMAT_STRING pFormat)
3798 unsigned short type;
3799 unsigned char switch_type;
3801 TRACE("(%p, %p, %p)\n", pStubMsg, pMemory, pFormat);
3804 switch_type = *pFormat;
3807 pFormat = ComputeConformance(pStubMsg, pMemory, pFormat, 0);
3808 TRACE("got switch value 0x%lx\n", pStubMsg->MaxCount);
3809 /* Add discriminant size */
3810 NdrBaseTypeBufferSize(pStubMsg, (unsigned char *)&pStubMsg->MaxCount, &switch_type);
3812 pFormat = get_non_encapsulated_union_arm(pStubMsg, pStubMsg->MaxCount, pFormat);
3816 type = *(const unsigned short*)pFormat;
3817 if((type & 0xff00) == 0x8000)
3819 unsigned char basetype = LOBYTE(type);
3820 NdrBaseTypeBufferSize(pStubMsg, pMemory, &basetype);
3824 PFORMAT_STRING desc = pFormat + *(const SHORT*)pFormat;
3825 NDR_BUFFERSIZE m = NdrBufferSizer[*desc & NDR_TABLE_MASK];
3834 ALIGN_LENGTH(pStubMsg->BufferLength, 4);
3835 pStubMsg->BufferLength += 4; /* for pointer ID */
3836 PointerBufferSize(pStubMsg, *(unsigned char **)pMemory, desc);
3839 m(pStubMsg, pMemory, desc);
3842 else FIXME("no buffersizer for embedded type %02x\n", *desc);
3847 /***********************************************************************
3848 * NdrNonEncapsulatedUnionMemorySize [RPCRT4.@]
3850 unsigned long WINAPI NdrNonEncapsulatedUnionMemorySize(PMIDL_STUB_MESSAGE pStubMsg,
3851 PFORMAT_STRING pFormat)
3853 unsigned long discriminant;
3854 unsigned short type, size;
3857 /* Unmarshall discriminant */
3858 discriminant = unmarshall_discriminant(pStubMsg, &pFormat);
3859 TRACE("unmarshalled discriminant 0x%lx\n", discriminant);
3861 pFormat += *(const SHORT*)pFormat;
3863 size = *(const unsigned short*)pFormat;
3866 pFormat = get_arm_offset_from_union_arm_selector(pStubMsg, discriminant, pFormat);
3870 pStubMsg->Memory += size;
3872 type = *(const unsigned short*)pFormat;
3873 if((type & 0xff00) == 0x8000)
3875 return NdrBaseTypeMemorySize(pStubMsg, pFormat);
3879 PFORMAT_STRING desc = pFormat + *(const SHORT*)pFormat;
3880 NDR_MEMORYSIZE m = NdrMemorySizer[*desc & NDR_TABLE_MASK];
3881 unsigned char *saved_buffer;
3890 ALIGN_POINTER(pStubMsg->Buffer, 4);
3891 saved_buffer = pStubMsg->Buffer;
3892 pStubMsg->Buffer += 4;
3893 ALIGN_LENGTH(pStubMsg->MemorySize, 4);
3894 pStubMsg->MemorySize += 4;
3895 PointerMemorySize(pStubMsg, saved_buffer, pFormat);
3898 return m(pStubMsg, desc);
3901 else FIXME("no marshaller for embedded type %02x\n", *desc);
3904 TRACE("size %d\n", size);
3908 /***********************************************************************
3909 * NdrNonEncapsulatedUnionFree [RPCRT4.@]
3911 void WINAPI NdrNonEncapsulatedUnionFree(PMIDL_STUB_MESSAGE pStubMsg,
3912 unsigned char *pMemory,
3913 PFORMAT_STRING pFormat)
3918 /***********************************************************************
3919 * NdrByteCountPointerMarshall [RPCRT4.@]
3921 unsigned char * WINAPI NdrByteCountPointerMarshall(PMIDL_STUB_MESSAGE pStubMsg,
3922 unsigned char *pMemory,
3923 PFORMAT_STRING pFormat)
3929 /***********************************************************************
3930 * NdrByteCountPointerUnmarshall [RPCRT4.@]
3932 unsigned char * WINAPI NdrByteCountPointerUnmarshall(PMIDL_STUB_MESSAGE pStubMsg,
3933 unsigned char **ppMemory,
3934 PFORMAT_STRING pFormat,
3935 unsigned char fMustAlloc)
3941 /***********************************************************************
3942 * NdrByteCountPointerBufferSize [RPCRT4.@]
3944 void WINAPI NdrByteCountPointerBufferSize(PMIDL_STUB_MESSAGE pStubMsg,
3945 unsigned char *pMemory,
3946 PFORMAT_STRING pFormat)
3951 /***********************************************************************
3952 * NdrByteCountPointerMemorySize [RPCRT4.@]
3954 unsigned long WINAPI NdrByteCountPointerMemorySize(PMIDL_STUB_MESSAGE pStubMsg,
3955 PFORMAT_STRING pFormat)
3961 /***********************************************************************
3962 * NdrByteCountPointerFree [RPCRT4.@]
3964 void WINAPI NdrByteCountPointerFree(PMIDL_STUB_MESSAGE pStubMsg,
3965 unsigned char *pMemory,
3966 PFORMAT_STRING pFormat)
3971 /***********************************************************************
3972 * NdrXmitOrRepAsMarshall [RPCRT4.@]
3974 unsigned char * WINAPI NdrXmitOrRepAsMarshall(PMIDL_STUB_MESSAGE pStubMsg,
3975 unsigned char *pMemory,
3976 PFORMAT_STRING pFormat)
3982 /***********************************************************************
3983 * NdrXmitOrRepAsUnmarshall [RPCRT4.@]
3985 unsigned char * WINAPI NdrXmitOrRepAsUnmarshall(PMIDL_STUB_MESSAGE pStubMsg,
3986 unsigned char **ppMemory,
3987 PFORMAT_STRING pFormat,
3988 unsigned char fMustAlloc)
3994 /***********************************************************************
3995 * NdrXmitOrRepAsBufferSize [RPCRT4.@]
3997 void WINAPI NdrXmitOrRepAsBufferSize(PMIDL_STUB_MESSAGE pStubMsg,
3998 unsigned char *pMemory,
3999 PFORMAT_STRING pFormat)
4004 /***********************************************************************
4005 * NdrXmitOrRepAsMemorySize [RPCRT4.@]
4007 unsigned long WINAPI NdrXmitOrRepAsMemorySize(PMIDL_STUB_MESSAGE pStubMsg,
4008 PFORMAT_STRING pFormat)
4014 /***********************************************************************
4015 * NdrXmitOrRepAsFree [RPCRT4.@]
4017 void WINAPI NdrXmitOrRepAsFree(PMIDL_STUB_MESSAGE pStubMsg,
4018 unsigned char *pMemory,
4019 PFORMAT_STRING pFormat)
4024 /***********************************************************************
4025 * NdrBaseTypeMarshall [internal]
4027 static unsigned char *WINAPI NdrBaseTypeMarshall(
4028 PMIDL_STUB_MESSAGE pStubMsg,
4029 unsigned char *pMemory,
4030 PFORMAT_STRING pFormat)
4032 TRACE("pStubMsg %p, pMemory %p, type 0x%02x\n", pStubMsg, pMemory, *pFormat);
4040 *(UCHAR *)pStubMsg->Buffer = *(UCHAR *)pMemory;
4041 pStubMsg->Buffer += sizeof(UCHAR);
4042 TRACE("value: 0x%02x\n", *(UCHAR *)pMemory);
4047 ALIGN_POINTER(pStubMsg->Buffer, sizeof(USHORT));
4048 *(USHORT *)pStubMsg->Buffer = *(USHORT *)pMemory;
4049 pStubMsg->Buffer += sizeof(USHORT);
4050 TRACE("value: 0x%04x\n", *(USHORT *)pMemory);
4054 case RPC_FC_ERROR_STATUS_T:
4056 ALIGN_POINTER(pStubMsg->Buffer, sizeof(ULONG));
4057 *(ULONG *)pStubMsg->Buffer = *(ULONG *)pMemory;
4058 pStubMsg->Buffer += sizeof(ULONG);
4059 TRACE("value: 0x%08lx\n", *(ULONG *)pMemory);
4062 ALIGN_POINTER(pStubMsg->Buffer, sizeof(float));
4063 *(float *)pStubMsg->Buffer = *(float *)pMemory;
4064 pStubMsg->Buffer += sizeof(float);
4067 ALIGN_POINTER(pStubMsg->Buffer, sizeof(double));
4068 *(double *)pStubMsg->Buffer = *(double *)pMemory;
4069 pStubMsg->Buffer += sizeof(double);
4072 ALIGN_POINTER(pStubMsg->Buffer, sizeof(ULONGLONG));
4073 *(ULONGLONG *)pStubMsg->Buffer = *(ULONGLONG *)pMemory;
4074 pStubMsg->Buffer += sizeof(ULONGLONG);
4075 TRACE("value: %s\n", wine_dbgstr_longlong(*(ULONGLONG*)pMemory));
4078 /* only 16-bits on the wire, so do a sanity check */
4079 if (*(UINT *)pMemory > USHRT_MAX)
4080 RpcRaiseException(RPC_X_ENUM_VALUE_OUT_OF_RANGE);
4081 ALIGN_POINTER(pStubMsg->Buffer, sizeof(USHORT));
4082 *(USHORT *)pStubMsg->Buffer = *(UINT *)pMemory;
4083 pStubMsg->Buffer += sizeof(USHORT);
4084 TRACE("value: 0x%04x\n", *(UINT *)pMemory);
4087 FIXME("Unhandled base type: 0x%02x\n", *pFormat);
4090 STD_OVERFLOW_CHECK(pStubMsg);
4092 /* FIXME: what is the correct return value? */
4096 /***********************************************************************
4097 * NdrBaseTypeUnmarshall [internal]
4099 static unsigned char *WINAPI NdrBaseTypeUnmarshall(
4100 PMIDL_STUB_MESSAGE pStubMsg,
4101 unsigned char **ppMemory,
4102 PFORMAT_STRING pFormat,
4103 unsigned char fMustAlloc)
4105 TRACE("pStubMsg: %p, ppMemory: %p, type: 0x%02x, fMustAlloc: %s\n", pStubMsg, ppMemory, *pFormat, fMustAlloc ? "true" : "false");
4107 if (fMustAlloc || !*ppMemory)
4109 unsigned char *Buffer = pStubMsg->Buffer;
4110 unsigned long MemorySize = pStubMsg->MemorySize;
4111 *ppMemory = NdrAllocate(pStubMsg, NdrBaseTypeMemorySize(pStubMsg, pFormat));
4112 pStubMsg->MemorySize = MemorySize;
4113 pStubMsg->Buffer = Buffer;
4116 TRACE("*ppMemory: %p\n", *ppMemory);
4118 #define BASE_TYPE_UNMARSHALL(type) \
4119 ALIGN_POINTER(pStubMsg->Buffer, sizeof(type)); \
4120 **(type **)ppMemory = *(type *)pStubMsg->Buffer; \
4121 pStubMsg->Buffer += sizeof(type);
4129 BASE_TYPE_UNMARSHALL(UCHAR);
4130 TRACE("value: 0x%02x\n", **(UCHAR **)ppMemory);
4135 BASE_TYPE_UNMARSHALL(USHORT);
4136 TRACE("value: 0x%04x\n", **(USHORT **)ppMemory);
4140 case RPC_FC_ERROR_STATUS_T:
4142 BASE_TYPE_UNMARSHALL(ULONG);
4143 TRACE("value: 0x%08lx\n", **(ULONG **)ppMemory);
4146 BASE_TYPE_UNMARSHALL(float);
4147 TRACE("value: %f\n", **(float **)ppMemory);
4150 BASE_TYPE_UNMARSHALL(double);
4151 TRACE("value: %f\n", **(double **)ppMemory);
4154 BASE_TYPE_UNMARSHALL(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);
4167 #undef BASE_TYPE_UNMARSHALL
4169 /* FIXME: what is the correct return value? */
4174 /***********************************************************************
4175 * NdrBaseTypeBufferSize [internal]
4177 static void WINAPI NdrBaseTypeBufferSize(
4178 PMIDL_STUB_MESSAGE pStubMsg,
4179 unsigned char *pMemory,
4180 PFORMAT_STRING pFormat)
4182 TRACE("pStubMsg %p, pMemory %p, type 0x%02x\n", pStubMsg, pMemory, *pFormat);
4190 pStubMsg->BufferLength += sizeof(UCHAR);
4196 ALIGN_LENGTH(pStubMsg->BufferLength, sizeof(USHORT));
4197 pStubMsg->BufferLength += sizeof(USHORT);
4202 ALIGN_LENGTH(pStubMsg->BufferLength, sizeof(ULONG));
4203 pStubMsg->BufferLength += sizeof(ULONG);
4206 ALIGN_LENGTH(pStubMsg->BufferLength, sizeof(float));
4207 pStubMsg->BufferLength += sizeof(float);
4210 ALIGN_LENGTH(pStubMsg->BufferLength, sizeof(double));
4211 pStubMsg->BufferLength += sizeof(double);
4214 ALIGN_LENGTH(pStubMsg->BufferLength, sizeof(ULONGLONG));
4215 pStubMsg->BufferLength += sizeof(ULONGLONG);
4217 case RPC_FC_ERROR_STATUS_T:
4218 ALIGN_LENGTH(pStubMsg->BufferLength, sizeof(error_status_t));
4219 pStubMsg->BufferLength += sizeof(error_status_t);
4222 FIXME("Unhandled base type: 0x%02x\n", *pFormat);
4226 /***********************************************************************
4227 * NdrBaseTypeMemorySize [internal]
4229 static unsigned long WINAPI NdrBaseTypeMemorySize(
4230 PMIDL_STUB_MESSAGE pStubMsg,
4231 PFORMAT_STRING pFormat)
4239 pStubMsg->Buffer += sizeof(UCHAR);
4240 pStubMsg->MemorySize += sizeof(UCHAR);
4241 return sizeof(UCHAR);
4245 pStubMsg->Buffer += sizeof(USHORT);
4246 pStubMsg->MemorySize += sizeof(USHORT);
4247 return sizeof(USHORT);
4250 pStubMsg->Buffer += sizeof(ULONG);
4251 pStubMsg->MemorySize += sizeof(ULONG);
4252 return sizeof(ULONG);
4254 pStubMsg->Buffer += sizeof(float);
4255 pStubMsg->MemorySize += sizeof(float);
4256 return sizeof(float);
4258 pStubMsg->Buffer += sizeof(double);
4259 pStubMsg->MemorySize += sizeof(double);
4260 return sizeof(double);
4262 pStubMsg->Buffer += sizeof(ULONGLONG);
4263 pStubMsg->MemorySize += sizeof(ULONGLONG);
4264 return sizeof(ULONGLONG);
4265 case RPC_FC_ERROR_STATUS_T:
4266 pStubMsg->Buffer += sizeof(error_status_t);
4267 pStubMsg->MemorySize += sizeof(error_status_t);
4268 return sizeof(error_status_t);
4271 pStubMsg->Buffer += sizeof(INT);
4272 pStubMsg->MemorySize += sizeof(INT);
4275 FIXME("Unhandled base type: 0x%02x\n", *pFormat);
4280 /***********************************************************************
4281 * NdrBaseTypeFree [internal]
4283 static void WINAPI NdrBaseTypeFree(PMIDL_STUB_MESSAGE pStubMsg,
4284 unsigned char *pMemory,
4285 PFORMAT_STRING pFormat)
4287 TRACE("pStubMsg %p pMemory %p type 0x%02x\n", pStubMsg, pMemory, *pFormat);
4292 /***********************************************************************
4293 * NdrClientContextMarshall
4295 void WINAPI NdrClientContextMarshall(PMIDL_STUB_MESSAGE pStubMsg,
4296 NDR_CCONTEXT ContextHandle,
4299 FIXME("(%p, %p, %d): stub\n", pStubMsg, ContextHandle, fCheck);
4302 /***********************************************************************
4303 * NdrClientContextUnmarshall
4305 void WINAPI NdrClientContextUnmarshall(PMIDL_STUB_MESSAGE pStubMsg,
4306 NDR_CCONTEXT * pContextHandle,
4307 RPC_BINDING_HANDLE BindHandle)
4309 FIXME("(%p, %p, %p): stub\n", pStubMsg, pContextHandle, BindHandle);
4312 void WINAPI NdrServerContextMarshall(PMIDL_STUB_MESSAGE pStubMsg,
4313 NDR_SCONTEXT ContextHandle,
4314 NDR_RUNDOWN RundownRoutine )
4316 FIXME("(%p, %p, %p): stub\n", pStubMsg, ContextHandle, RundownRoutine);
4319 NDR_SCONTEXT WINAPI NdrServerContextUnmarshall(PMIDL_STUB_MESSAGE pStubMsg)
4321 FIXME("(%p): stub\n", pStubMsg);
4325 void WINAPI NdrContextHandleSize(PMIDL_STUB_MESSAGE pStubMsg,
4326 unsigned char* pMemory,
4327 PFORMAT_STRING pFormat)
4329 FIXME("(%p, %p, %p): stub\n", pStubMsg, pMemory, pFormat);
4332 NDR_SCONTEXT WINAPI NdrContextHandleInitialize(PMIDL_STUB_MESSAGE pStubMsg,
4333 PFORMAT_STRING pFormat)
4335 FIXME("(%p, %p): stub\n", pStubMsg, pFormat);
4339 void WINAPI NdrServerContextNewMarshall(PMIDL_STUB_MESSAGE pStubMsg,
4340 NDR_SCONTEXT ContextHandle,
4341 NDR_RUNDOWN RundownRoutine,
4342 PFORMAT_STRING pFormat)
4344 FIXME("(%p, %p, %p, %p): stub\n", pStubMsg, ContextHandle, RundownRoutine, pFormat);
4347 NDR_SCONTEXT WINAPI NdrServerContextNewUnmarshall(PMIDL_STUB_MESSAGE pStubMsg,
4348 PFORMAT_STRING pFormat)
4350 FIXME("(%p, %p): stub\n", pStubMsg, pFormat);
4354 RPC_BINDING_HANDLE WINAPI NDRCContextBinding(NDR_CCONTEXT CContext)
4356 FIXME("(%p): stub\n", CContext);
4360 void WINAPI NDRCContextMarshall(NDR_CCONTEXT CContext, void *pBuff)
4362 FIXME("(%p %p): stub\n", CContext, pBuff);
4365 void WINAPI NDRCContextUnmarshall(NDR_CCONTEXT *CContext,
4366 RPC_BINDING_HANDLE hBinding,
4368 unsigned long DataRepresentation)
4370 FIXME("(%p %p %p %08lx): stub\n", CContext, hBinding, pBuff, DataRepresentation);
4373 void WINAPI NDRSContextMarshall(NDR_SCONTEXT CContext,
4375 NDR_RUNDOWN userRunDownIn)
4377 FIXME("(%p %p %p): stub\n", CContext, pBuff, userRunDownIn);
4380 void WINAPI NDRSContextMarshallEx(RPC_BINDING_HANDLE hBinding,
4381 NDR_SCONTEXT CContext,
4383 NDR_RUNDOWN userRunDownIn)
4385 FIXME("(%p %p %p %p): stub\n", hBinding, CContext, pBuff, userRunDownIn);
4388 void WINAPI NDRSContextMarshall2(RPC_BINDING_HANDLE hBinding,
4389 NDR_SCONTEXT CContext,
4391 NDR_RUNDOWN userRunDownIn,
4393 unsigned long Flags)
4395 FIXME("(%p %p %p %p %p %lu): stub\n",
4396 hBinding, CContext, pBuff, userRunDownIn, CtxGuard, Flags);
4399 NDR_SCONTEXT WINAPI NDRSContextUnmarshall(void *pBuff,
4400 unsigned long DataRepresentation)
4402 FIXME("(%p %08lx): stub\n", pBuff, DataRepresentation);
4406 NDR_SCONTEXT WINAPI NDRSContextUnmarshallEx(RPC_BINDING_HANDLE hBinding,
4408 unsigned long DataRepresentation)
4410 FIXME("(%p %p %08lx): stub\n", hBinding, pBuff, DataRepresentation);
4414 NDR_SCONTEXT WINAPI NDRSContextUnmarshall2(RPC_BINDING_HANDLE hBinding,
4416 unsigned long DataRepresentation,
4418 unsigned long Flags)
4420 FIXME("(%p %p %08lx %p %lu): stub\n",
4421 hBinding, pBuff, DataRepresentation, CtxGuard, Flags);