4 * Copyright 2002 Greg Turner
5 * Copyright 2003-2006 CodeWeavers
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 * - Non-conformant strings
25 * - Encapsulated unions
26 * - Byte count pointers
27 * - transmit_as/represent as
28 * - Multi-dimensional arrays
29 * - Conversion functions (NdrConvert)
30 * - Checks for integer overflow when calculating array sizes
31 * - Checks for out-of-memory conditions
48 #include "wine/unicode.h"
49 #include "wine/rpcfc.h"
51 #include "wine/debug.h"
53 WINE_DEFAULT_DEBUG_CHANNEL(ole);
56 # define LITTLE_ENDIAN_UINT32_WRITE(pchar, uint32) \
57 (*((UINT32 *)(pchar)) = (uint32))
59 # define LITTLE_ENDIAN_UINT32_READ(pchar) \
60 (*((UINT32 *)(pchar)))
62 /* these would work for i386 too, but less efficient */
63 # define LITTLE_ENDIAN_UINT32_WRITE(pchar, uint32) \
64 (*(pchar) = LOBYTE(LOWORD(uint32)), \
65 *((pchar)+1) = HIBYTE(LOWORD(uint32)), \
66 *((pchar)+2) = LOBYTE(HIWORD(uint32)), \
67 *((pchar)+3) = HIBYTE(HIWORD(uint32)), \
68 (uint32)) /* allow as r-value */
70 # define LITTLE_ENDIAN_UINT32_READ(pchar) \
72 MAKEWORD(*(pchar), *((pchar)+1)), \
73 MAKEWORD(*((pchar)+2), *((pchar)+3))))
76 #define BIG_ENDIAN_UINT32_WRITE(pchar, uint32) \
77 (*((pchar)+3) = LOBYTE(LOWORD(uint32)), \
78 *((pchar)+2) = HIBYTE(LOWORD(uint32)), \
79 *((pchar)+1) = LOBYTE(HIWORD(uint32)), \
80 *(pchar) = HIBYTE(HIWORD(uint32)), \
81 (uint32)) /* allow as r-value */
83 #define BIG_ENDIAN_UINT32_READ(pchar) \
85 MAKEWORD(*((pchar)+3), *((pchar)+2)), \
86 MAKEWORD(*((pchar)+1), *(pchar))))
88 #ifdef NDR_LOCAL_IS_BIG_ENDIAN
89 # define NDR_LOCAL_UINT32_WRITE(pchar, uint32) \
90 BIG_ENDIAN_UINT32_WRITE(pchar, uint32)
91 # define NDR_LOCAL_UINT32_READ(pchar) \
92 BIG_ENDIAN_UINT32_READ(pchar)
94 # define NDR_LOCAL_UINT32_WRITE(pchar, uint32) \
95 LITTLE_ENDIAN_UINT32_WRITE(pchar, uint32)
96 # define NDR_LOCAL_UINT32_READ(pchar) \
97 LITTLE_ENDIAN_UINT32_READ(pchar)
100 /* _Align must be the desired alignment,
101 * e.g. ALIGN_LENGTH(len, 4) to align on a dword boundary. */
102 #define ALIGNED_LENGTH(_Len, _Align) (((_Len)+(_Align)-1)&~((_Align)-1))
103 #define ALIGNED_POINTER(_Ptr, _Align) ((LPVOID)ALIGNED_LENGTH((ULONG_PTR)(_Ptr), _Align))
104 #define ALIGN_LENGTH(_Len, _Align) _Len = ALIGNED_LENGTH(_Len, _Align)
105 #define ALIGN_POINTER(_Ptr, _Align) _Ptr = ALIGNED_POINTER(_Ptr, _Align)
107 #define STD_OVERFLOW_CHECK(_Msg) do { \
108 TRACE("buffer=%d/%ld\n", _Msg->Buffer - (unsigned char *)_Msg->RpcMsg->Buffer, _Msg->BufferLength); \
109 if (_Msg->Buffer > (unsigned char *)_Msg->RpcMsg->Buffer + _Msg->BufferLength) \
110 ERR("buffer overflow %d bytes\n", _Msg->Buffer - ((unsigned char *)_Msg->RpcMsg->Buffer + _Msg->BufferLength)); \
113 #define NDR_TABLE_SIZE 128
114 #define NDR_TABLE_MASK 127
116 static unsigned char *WINAPI NdrBaseTypeMarshall(PMIDL_STUB_MESSAGE, unsigned char *, PFORMAT_STRING);
117 static unsigned char *WINAPI NdrBaseTypeUnmarshall(PMIDL_STUB_MESSAGE, unsigned char **, PFORMAT_STRING, unsigned char);
118 static void WINAPI NdrBaseTypeBufferSize(PMIDL_STUB_MESSAGE, unsigned char *, PFORMAT_STRING);
119 static void WINAPI NdrBaseTypeFree(PMIDL_STUB_MESSAGE, unsigned char *, PFORMAT_STRING);
120 static unsigned long WINAPI NdrBaseTypeMemorySize(PMIDL_STUB_MESSAGE, PFORMAT_STRING);
122 const NDR_MARSHALL NdrMarshaller[NDR_TABLE_SIZE] = {
124 NdrBaseTypeMarshall, NdrBaseTypeMarshall, NdrBaseTypeMarshall,
125 NdrBaseTypeMarshall, NdrBaseTypeMarshall, NdrBaseTypeMarshall, NdrBaseTypeMarshall,
126 NdrBaseTypeMarshall, NdrBaseTypeMarshall, NdrBaseTypeMarshall, NdrBaseTypeMarshall,
127 NdrBaseTypeMarshall, NdrBaseTypeMarshall, NdrBaseTypeMarshall, NdrBaseTypeMarshall,
131 NdrPointerMarshall, NdrPointerMarshall,
132 NdrPointerMarshall, NdrPointerMarshall,
134 NdrSimpleStructMarshall, NdrSimpleStructMarshall,
135 NdrConformantStructMarshall, NdrConformantStructMarshall,
136 NdrConformantVaryingStructMarshall,
137 NdrComplexStructMarshall,
139 NdrConformantArrayMarshall,
140 NdrConformantVaryingArrayMarshall,
141 NdrFixedArrayMarshall, NdrFixedArrayMarshall,
142 NdrVaryingArrayMarshall, NdrVaryingArrayMarshall,
143 NdrComplexArrayMarshall,
145 NdrConformantStringMarshall, 0, 0,
146 NdrConformantStringMarshall,
147 NdrNonConformantStringMarshall, 0, 0, 0,
149 NdrEncapsulatedUnionMarshall,
150 NdrNonEncapsulatedUnionMarshall,
151 NdrByteCountPointerMarshall,
152 NdrXmitOrRepAsMarshall, NdrXmitOrRepAsMarshall,
154 NdrInterfacePointerMarshall,
157 NdrUserMarshalMarshall
159 const NDR_UNMARSHALL NdrUnmarshaller[NDR_TABLE_SIZE] = {
161 NdrBaseTypeUnmarshall, NdrBaseTypeUnmarshall, NdrBaseTypeUnmarshall,
162 NdrBaseTypeUnmarshall, NdrBaseTypeUnmarshall, NdrBaseTypeUnmarshall, NdrBaseTypeUnmarshall,
163 NdrBaseTypeUnmarshall, NdrBaseTypeUnmarshall, NdrBaseTypeUnmarshall, NdrBaseTypeUnmarshall,
164 NdrBaseTypeUnmarshall, NdrBaseTypeUnmarshall, NdrBaseTypeUnmarshall, NdrBaseTypeUnmarshall,
166 NdrBaseTypeUnmarshall,
168 NdrPointerUnmarshall, NdrPointerUnmarshall,
169 NdrPointerUnmarshall, NdrPointerUnmarshall,
171 NdrSimpleStructUnmarshall, NdrSimpleStructUnmarshall,
172 NdrConformantStructUnmarshall, NdrConformantStructUnmarshall,
173 NdrConformantVaryingStructUnmarshall,
174 NdrComplexStructUnmarshall,
176 NdrConformantArrayUnmarshall,
177 NdrConformantVaryingArrayUnmarshall,
178 NdrFixedArrayUnmarshall, NdrFixedArrayUnmarshall,
179 NdrVaryingArrayUnmarshall, NdrVaryingArrayUnmarshall,
180 NdrComplexArrayUnmarshall,
182 NdrConformantStringUnmarshall, 0, 0,
183 NdrConformantStringUnmarshall,
184 NdrNonConformantStringUnmarshall, 0, 0, 0,
186 NdrEncapsulatedUnionUnmarshall,
187 NdrNonEncapsulatedUnionUnmarshall,
188 NdrByteCountPointerUnmarshall,
189 NdrXmitOrRepAsUnmarshall, NdrXmitOrRepAsUnmarshall,
191 NdrInterfacePointerUnmarshall,
194 NdrUserMarshalUnmarshall
196 const NDR_BUFFERSIZE NdrBufferSizer[NDR_TABLE_SIZE] = {
198 NdrBaseTypeBufferSize, NdrBaseTypeBufferSize, NdrBaseTypeBufferSize,
199 NdrBaseTypeBufferSize, NdrBaseTypeBufferSize, NdrBaseTypeBufferSize, NdrBaseTypeBufferSize,
200 NdrBaseTypeBufferSize, NdrBaseTypeBufferSize, NdrBaseTypeBufferSize, NdrBaseTypeBufferSize,
201 NdrBaseTypeBufferSize, NdrBaseTypeBufferSize, NdrBaseTypeBufferSize, NdrBaseTypeBufferSize,
203 NdrBaseTypeBufferSize,
205 NdrPointerBufferSize, NdrPointerBufferSize,
206 NdrPointerBufferSize, NdrPointerBufferSize,
208 NdrSimpleStructBufferSize, NdrSimpleStructBufferSize,
209 NdrConformantStructBufferSize, NdrConformantStructBufferSize,
210 NdrConformantVaryingStructBufferSize,
211 NdrComplexStructBufferSize,
213 NdrConformantArrayBufferSize,
214 NdrConformantVaryingArrayBufferSize,
215 NdrFixedArrayBufferSize, NdrFixedArrayBufferSize,
216 NdrVaryingArrayBufferSize, NdrVaryingArrayBufferSize,
217 NdrComplexArrayBufferSize,
219 NdrConformantStringBufferSize, 0, 0,
220 NdrConformantStringBufferSize,
221 NdrNonConformantStringBufferSize, 0, 0, 0,
223 NdrEncapsulatedUnionBufferSize,
224 NdrNonEncapsulatedUnionBufferSize,
225 NdrByteCountPointerBufferSize,
226 NdrXmitOrRepAsBufferSize, NdrXmitOrRepAsBufferSize,
228 NdrInterfacePointerBufferSize,
231 NdrUserMarshalBufferSize
233 const NDR_MEMORYSIZE NdrMemorySizer[NDR_TABLE_SIZE] = {
235 NdrBaseTypeMemorySize, NdrBaseTypeMemorySize, NdrBaseTypeMemorySize,
236 NdrBaseTypeMemorySize, NdrBaseTypeMemorySize, NdrBaseTypeMemorySize, NdrBaseTypeMemorySize,
237 NdrBaseTypeMemorySize, NdrBaseTypeMemorySize, NdrBaseTypeMemorySize, NdrBaseTypeMemorySize,
238 NdrBaseTypeMemorySize, NdrBaseTypeMemorySize, NdrBaseTypeMemorySize, NdrBaseTypeMemorySize,
240 NdrBaseTypeMemorySize,
242 NdrPointerMemorySize, NdrPointerMemorySize,
243 NdrPointerMemorySize, NdrPointerMemorySize,
245 NdrSimpleStructMemorySize, NdrSimpleStructMemorySize,
246 NdrConformantStructMemorySize, NdrConformantStructMemorySize,
247 NdrConformantVaryingStructMemorySize,
248 NdrComplexStructMemorySize,
250 NdrConformantArrayMemorySize,
251 NdrConformantVaryingArrayMemorySize,
252 NdrFixedArrayMemorySize, NdrFixedArrayMemorySize,
253 NdrVaryingArrayMemorySize, NdrVaryingArrayMemorySize,
254 NdrComplexArrayMemorySize,
256 NdrConformantStringMemorySize, 0, 0,
257 NdrConformantStringMemorySize,
258 NdrNonConformantStringMemorySize, 0, 0, 0,
260 NdrEncapsulatedUnionMemorySize,
261 NdrNonEncapsulatedUnionMemorySize,
262 NdrByteCountPointerMemorySize,
263 NdrXmitOrRepAsMemorySize, NdrXmitOrRepAsMemorySize,
265 NdrInterfacePointerMemorySize,
268 NdrUserMarshalMemorySize
270 const NDR_FREE NdrFreer[NDR_TABLE_SIZE] = {
272 NdrBaseTypeFree, NdrBaseTypeFree, NdrBaseTypeFree,
273 NdrBaseTypeFree, NdrBaseTypeFree, NdrBaseTypeFree, NdrBaseTypeFree,
274 NdrBaseTypeFree, NdrBaseTypeFree, NdrBaseTypeFree, NdrBaseTypeFree,
275 NdrBaseTypeFree, NdrBaseTypeFree, NdrBaseTypeFree, NdrBaseTypeFree,
279 NdrPointerFree, NdrPointerFree,
280 NdrPointerFree, NdrPointerFree,
282 NdrSimpleStructFree, NdrSimpleStructFree,
283 NdrConformantStructFree, NdrConformantStructFree,
284 NdrConformantVaryingStructFree,
285 NdrComplexStructFree,
287 NdrConformantArrayFree,
288 NdrConformantVaryingArrayFree,
289 NdrFixedArrayFree, NdrFixedArrayFree,
290 NdrVaryingArrayFree, NdrVaryingArrayFree,
296 NdrEncapsulatedUnionFree,
297 NdrNonEncapsulatedUnionFree,
299 NdrXmitOrRepAsFree, NdrXmitOrRepAsFree,
301 NdrInterfacePointerFree,
307 void * WINAPI NdrAllocate(MIDL_STUB_MESSAGE *pStubMsg, size_t len)
309 /* hmm, this is probably supposed to do more? */
310 return pStubMsg->pfnAllocate(len);
313 static void WINAPI NdrFree(MIDL_STUB_MESSAGE *pStubMsg, unsigned char *Pointer)
315 pStubMsg->pfnFree(Pointer);
318 static inline BOOL IsConformanceOrVariancePresent(PFORMAT_STRING pFormat)
320 return (*(const ULONG *)pFormat != -1);
323 PFORMAT_STRING ReadConformance(MIDL_STUB_MESSAGE *pStubMsg, PFORMAT_STRING pFormat)
325 ALIGN_POINTER(pStubMsg->Buffer, 4);
326 pStubMsg->MaxCount = NDR_LOCAL_UINT32_READ(pStubMsg->Buffer);
327 pStubMsg->Buffer += 4;
328 TRACE("unmarshalled conformance is %ld\n", pStubMsg->MaxCount);
329 if (pStubMsg->fHasNewCorrDesc)
335 static inline PFORMAT_STRING ReadVariance(MIDL_STUB_MESSAGE *pStubMsg, PFORMAT_STRING pFormat)
337 if (pFormat && !IsConformanceOrVariancePresent(pFormat))
339 pStubMsg->Offset = 0;
340 pStubMsg->ActualCount = pStubMsg->MaxCount;
344 ALIGN_POINTER(pStubMsg->Buffer, 4);
345 pStubMsg->Offset = NDR_LOCAL_UINT32_READ(pStubMsg->Buffer);
346 pStubMsg->Buffer += 4;
347 TRACE("offset is %ld\n", pStubMsg->Offset);
348 pStubMsg->ActualCount = NDR_LOCAL_UINT32_READ(pStubMsg->Buffer);
349 pStubMsg->Buffer += 4;
350 TRACE("variance is %ld\n", pStubMsg->ActualCount);
353 if (pStubMsg->fHasNewCorrDesc)
359 /* writes the conformance value to the buffer */
360 static inline void WriteConformance(MIDL_STUB_MESSAGE *pStubMsg)
362 ALIGN_POINTER(pStubMsg->Buffer, 4);
363 NDR_LOCAL_UINT32_WRITE(pStubMsg->Buffer, pStubMsg->MaxCount);
364 pStubMsg->Buffer += 4;
367 /* writes the variance values to the buffer */
368 static inline void WriteVariance(MIDL_STUB_MESSAGE *pStubMsg)
370 ALIGN_POINTER(pStubMsg->Buffer, 4);
371 NDR_LOCAL_UINT32_WRITE(pStubMsg->Buffer, pStubMsg->Offset);
372 pStubMsg->Buffer += 4;
373 NDR_LOCAL_UINT32_WRITE(pStubMsg->Buffer, pStubMsg->ActualCount);
374 pStubMsg->Buffer += 4;
377 /* requests buffer space for the conformance value */
378 static inline void SizeConformance(MIDL_STUB_MESSAGE *pStubMsg)
380 ALIGN_LENGTH(pStubMsg->BufferLength, 4);
381 pStubMsg->BufferLength += 4;
384 /* requests buffer space for the variance values */
385 static inline void SizeVariance(MIDL_STUB_MESSAGE *pStubMsg)
387 ALIGN_LENGTH(pStubMsg->BufferLength, 4);
388 pStubMsg->BufferLength += 8;
391 PFORMAT_STRING ComputeConformanceOrVariance(
392 MIDL_STUB_MESSAGE *pStubMsg, unsigned char *pMemory,
393 PFORMAT_STRING pFormat, ULONG_PTR def, ULONG *pCount)
395 BYTE dtype = pFormat[0] & 0xf;
396 short ofs = *(short *)&pFormat[2];
400 if (!IsConformanceOrVariancePresent(pFormat)) {
401 /* null descriptor */
406 switch (pFormat[0] & 0xf0) {
407 case RPC_FC_NORMAL_CONFORMANCE:
408 TRACE("normal conformance, ofs=%d\n", ofs);
411 case RPC_FC_POINTER_CONFORMANCE:
412 TRACE("pointer conformance, ofs=%d\n", ofs);
413 ptr = pStubMsg->Memory;
415 case RPC_FC_TOP_LEVEL_CONFORMANCE:
416 TRACE("toplevel conformance, ofs=%d\n", ofs);
417 if (pStubMsg->StackTop) {
418 ptr = pStubMsg->StackTop;
421 /* -Os mode, *pCount is already set */
425 case RPC_FC_CONSTANT_CONFORMANCE:
426 data = ofs | ((DWORD)pFormat[1] << 16);
427 TRACE("constant conformance, val=%ld\n", data);
430 case RPC_FC_TOP_LEVEL_MULTID_CONFORMANCE:
431 FIXME("toplevel multidimensional conformance, ofs=%d\n", ofs);
432 if (pStubMsg->StackTop) {
433 ptr = pStubMsg->StackTop;
441 FIXME("unknown conformance type %x\n", pFormat[0] & 0xf0);
444 switch (pFormat[1]) {
445 case RPC_FC_DEREFERENCE:
446 ptr = *(LPVOID*)((char *)ptr + ofs);
448 case RPC_FC_CALLBACK:
450 unsigned char *old_stack_top = pStubMsg->StackTop;
451 pStubMsg->StackTop = ptr;
453 /* ofs is index into StubDesc->apfnExprEval */
454 TRACE("callback conformance into apfnExprEval[%d]\n", ofs);
455 pStubMsg->StubDesc->apfnExprEval[ofs](pStubMsg);
457 pStubMsg->StackTop = old_stack_top;
461 ptr = (char *)ptr + ofs;
474 data = *(USHORT*)ptr;
485 FIXME("unknown conformance data type %x\n", dtype);
488 TRACE("dereferenced data type %x at %p, got %ld\n", dtype, ptr, data);
491 switch (pFormat[1]) {
495 case RPC_FC_DEREFERENCE:
496 /* already handled */
511 FIXME("unknown conformance op %d\n", pFormat[1]);
516 TRACE("resulting conformance is %ld\n", *pCount);
517 if (pStubMsg->fHasNewCorrDesc)
525 * NdrConformantString:
527 * What MS calls a ConformantString is, in DCE terminology,
528 * a Varying-Conformant String.
530 * maxlen: DWORD (max # of CHARTYPE characters, inclusive of '\0')
531 * offset: DWORD (actual string data begins at (offset) CHARTYPE's
532 * into unmarshalled string)
533 * length: DWORD (# of CHARTYPE characters, inclusive of '\0')
535 * data: CHARTYPE[maxlen]
537 * ], where CHARTYPE is the appropriate character type (specified externally)
541 /***********************************************************************
542 * NdrConformantStringMarshall [RPCRT4.@]
544 unsigned char *WINAPI NdrConformantStringMarshall(MIDL_STUB_MESSAGE *pStubMsg,
545 unsigned char *pszMessage, PFORMAT_STRING pFormat)
549 TRACE("(pStubMsg == ^%p, pszMessage == ^%p, pFormat == ^%p)\n", pStubMsg, pszMessage, pFormat);
551 if (*pFormat == RPC_FC_C_CSTRING) {
552 TRACE("string=%s\n", debugstr_a((char*)pszMessage));
553 pStubMsg->ActualCount = strlen((char*)pszMessage)+1;
556 else if (*pFormat == RPC_FC_C_WSTRING) {
557 TRACE("string=%s\n", debugstr_w((LPWSTR)pszMessage));
558 pStubMsg->ActualCount = strlenW((LPWSTR)pszMessage)+1;
562 ERR("Unhandled string type: %#x\n", *pFormat);
563 /* FIXME: raise an exception. */
567 if (pFormat[1] == RPC_FC_STRING_SIZED)
568 pFormat = ComputeConformance(pStubMsg, pszMessage, pFormat + 2, 0);
570 pStubMsg->MaxCount = pStubMsg->ActualCount;
571 pStubMsg->Offset = 0;
572 WriteConformance(pStubMsg);
573 WriteVariance(pStubMsg);
575 memcpy(pStubMsg->Buffer, pszMessage, pStubMsg->ActualCount*esize); /* the string itself */
576 pStubMsg->Buffer += pStubMsg->ActualCount*esize;
578 STD_OVERFLOW_CHECK(pStubMsg);
581 return NULL; /* is this always right? */
584 /***********************************************************************
585 * NdrConformantStringBufferSize [RPCRT4.@]
587 void WINAPI NdrConformantStringBufferSize(PMIDL_STUB_MESSAGE pStubMsg,
588 unsigned char* pMemory, PFORMAT_STRING pFormat)
590 TRACE("(pStubMsg == ^%p, pMemory == ^%p, pFormat == ^%p)\n", pStubMsg, pMemory, pFormat);
592 SizeConformance(pStubMsg);
593 SizeVariance(pStubMsg);
595 if (*pFormat == RPC_FC_C_CSTRING) {
596 /* we need + 1 octet for '\0' */
597 TRACE("string=%s\n", debugstr_a((char*)pMemory));
598 pStubMsg->BufferLength += strlen((char*)pMemory) + 1;
600 else if (*pFormat == RPC_FC_C_WSTRING) {
601 /* we need + 2 octets for L'\0' */
602 TRACE("string=%s\n", debugstr_w((LPWSTR)pMemory));
603 pStubMsg->BufferLength += strlenW((LPWSTR)pMemory)*2 + 2;
606 ERR("Unhandled string type: %#x\n", *pFormat);
607 /* FIXME: raise an exception */
611 /************************************************************************
612 * NdrConformantStringMemorySize [RPCRT4.@]
614 unsigned long WINAPI NdrConformantStringMemorySize( PMIDL_STUB_MESSAGE pStubMsg,
615 PFORMAT_STRING pFormat )
617 unsigned long rslt = 0;
619 TRACE("(pStubMsg == ^%p, pFormat == ^%p)\n", pStubMsg, pFormat);
621 assert(pStubMsg && pFormat);
623 if (*pFormat == RPC_FC_C_CSTRING) {
624 rslt = NDR_LOCAL_UINT32_READ(pStubMsg->Buffer); /* maxlen */
626 else if (*pFormat == RPC_FC_C_WSTRING) {
627 rslt = NDR_LOCAL_UINT32_READ(pStubMsg->Buffer)*2; /* maxlen */
630 ERR("Unhandled string type: %#x\n", *pFormat);
631 /* FIXME: raise an exception */
634 if (pFormat[1] != RPC_FC_PAD) {
635 FIXME("sized string format=%d\n", pFormat[1]);
638 TRACE(" --> %lu\n", rslt);
642 /************************************************************************
643 * NdrConformantStringUnmarshall [RPCRT4.@]
645 unsigned char *WINAPI NdrConformantStringUnmarshall( PMIDL_STUB_MESSAGE pStubMsg,
646 unsigned char** ppMemory, PFORMAT_STRING pFormat, unsigned char fMustAlloc )
648 unsigned long len, esize;
650 TRACE("(pStubMsg == ^%p, *pMemory == ^%p, pFormat == ^%p, fMustAlloc == %u)\n",
651 pStubMsg, *ppMemory, pFormat, fMustAlloc);
653 assert(pFormat && ppMemory && pStubMsg);
655 ReadConformance(pStubMsg, NULL);
656 ReadVariance(pStubMsg, NULL);
658 if (*pFormat == RPC_FC_C_CSTRING) esize = 1;
659 else if (*pFormat == RPC_FC_C_WSTRING) esize = 2;
661 ERR("Unhandled string type: %#x\n", *pFormat);
662 /* FIXME: raise an exception */
666 len = pStubMsg->ActualCount;
668 if (fMustAlloc || !*ppMemory)
669 *ppMemory = NdrAllocate(pStubMsg, len*esize);
671 memcpy(*ppMemory, pStubMsg->Buffer, len*esize);
673 pStubMsg->Buffer += len*esize;
675 if (*pFormat == RPC_FC_C_CSTRING) {
676 TRACE("string=%s\n", debugstr_a((char*)*ppMemory));
678 else if (*pFormat == RPC_FC_C_WSTRING) {
679 TRACE("string=%s\n", debugstr_w((LPWSTR)*ppMemory));
682 return NULL; /* FIXME: is this always right? */
685 /***********************************************************************
686 * NdrNonConformantStringMarshall [RPCRT4.@]
688 unsigned char * WINAPI NdrNonConformantStringMarshall(PMIDL_STUB_MESSAGE pStubMsg,
689 unsigned char *pMemory,
690 PFORMAT_STRING pFormat)
696 /***********************************************************************
697 * NdrNonConformantStringUnmarshall [RPCRT4.@]
699 unsigned char * WINAPI NdrNonConformantStringUnmarshall(PMIDL_STUB_MESSAGE pStubMsg,
700 unsigned char **ppMemory,
701 PFORMAT_STRING pFormat,
702 unsigned char fMustAlloc)
708 /***********************************************************************
709 * NdrNonConformantStringBufferSize [RPCRT4.@]
711 void WINAPI NdrNonConformantStringBufferSize(PMIDL_STUB_MESSAGE pStubMsg,
712 unsigned char *pMemory,
713 PFORMAT_STRING pFormat)
718 /***********************************************************************
719 * NdrNonConformantStringMemorySize [RPCRT4.@]
721 unsigned long WINAPI NdrNonConformantStringMemorySize(PMIDL_STUB_MESSAGE pStubMsg,
722 PFORMAT_STRING pFormat)
728 static inline void dump_pointer_attr(unsigned char attr)
730 if (attr & RPC_FC_P_ALLOCALLNODES)
731 TRACE(" RPC_FC_P_ALLOCALLNODES");
732 if (attr & RPC_FC_P_DONTFREE)
733 TRACE(" RPC_FC_P_DONTFREE");
734 if (attr & RPC_FC_P_ONSTACK)
735 TRACE(" RPC_FC_P_ONSTACK");
736 if (attr & RPC_FC_P_SIMPLEPOINTER)
737 TRACE(" RPC_FC_P_SIMPLEPOINTER");
738 if (attr & RPC_FC_P_DEREF)
739 TRACE(" RPC_FC_P_DEREF");
743 /***********************************************************************
746 static void PointerMarshall(PMIDL_STUB_MESSAGE pStubMsg,
747 unsigned char *Buffer,
748 unsigned char *Pointer,
749 PFORMAT_STRING pFormat)
751 unsigned type = pFormat[0], attr = pFormat[1];
755 TRACE("(%p,%p,%p,%p)\n", pStubMsg, Buffer, Pointer, pFormat);
756 TRACE("type=0x%x, attr=", type); dump_pointer_attr(attr);
758 if (attr & RPC_FC_P_SIMPLEPOINTER) desc = pFormat;
759 else desc = pFormat + *(const SHORT*)pFormat;
762 case RPC_FC_RP: /* ref pointer (always non-null) */
763 #if 0 /* this causes problems for InstallShield so is disabled - we need more tests */
765 RpcRaiseException(RPC_X_NULL_REF_POINTER);
768 case RPC_FC_UP: /* unique pointer */
769 case RPC_FC_OP: /* object pointer - same as unique here */
770 TRACE("writing %p to buffer\n", Pointer);
771 NDR_LOCAL_UINT32_WRITE(Buffer, (unsigned long)Pointer);
775 FIXME("unhandled ptr type=%02x\n", type);
776 RpcRaiseException(RPC_X_BAD_STUB_DATA);
779 TRACE("calling marshaller for type 0x%x\n", (int)*desc);
782 if (attr & RPC_FC_P_DEREF) {
783 Pointer = *(unsigned char**)Pointer;
784 TRACE("deref => %p\n", Pointer);
786 m = NdrMarshaller[*desc & NDR_TABLE_MASK];
787 if (m) m(pStubMsg, Pointer, desc);
788 else FIXME("no marshaller for data type=%02x\n", *desc);
791 STD_OVERFLOW_CHECK(pStubMsg);
794 /***********************************************************************
797 static void PointerUnmarshall(PMIDL_STUB_MESSAGE pStubMsg,
798 unsigned char *Buffer,
799 unsigned char **pPointer,
800 PFORMAT_STRING pFormat,
801 unsigned char fMustAlloc)
803 unsigned type = pFormat[0], attr = pFormat[1];
806 DWORD pointer_id = 0;
808 TRACE("(%p,%p,%p,%p,%d)\n", pStubMsg, Buffer, pPointer, pFormat, fMustAlloc);
809 TRACE("type=0x%x, attr=", type); dump_pointer_attr(attr);
811 if (attr & RPC_FC_P_SIMPLEPOINTER) desc = pFormat;
812 else desc = pFormat + *(const SHORT*)pFormat;
815 case RPC_FC_RP: /* ref pointer (always non-null) */
818 case RPC_FC_UP: /* unique pointer */
819 pointer_id = NDR_LOCAL_UINT32_READ(Buffer);
820 TRACE("pointer_id is 0x%08lx\n", pointer_id);
822 case RPC_FC_OP: /* object pointer - we must free data before overwriting it */
823 pointer_id = NDR_LOCAL_UINT32_READ(Buffer);
824 TRACE("pointer_id is 0x%08lx\n", pointer_id);
826 FIXME("free object pointer %p\n", *pPointer);
830 FIXME("unhandled ptr type=%02x\n", type);
831 RpcRaiseException(RPC_X_BAD_STUB_DATA);
835 if (attr & RPC_FC_P_DEREF) {
836 if (!*pPointer || fMustAlloc)
837 *pPointer = NdrAllocate(pStubMsg, sizeof(void *));
838 pPointer = *(unsigned char***)pPointer;
839 TRACE("deref => %p\n", pPointer);
841 m = NdrUnmarshaller[*desc & NDR_TABLE_MASK];
842 if (m) m(pStubMsg, pPointer, desc, fMustAlloc);
843 else FIXME("no unmarshaller for data type=%02x\n", *desc);
846 TRACE("pointer=%p\n", *pPointer);
849 /***********************************************************************
852 static void PointerBufferSize(PMIDL_STUB_MESSAGE pStubMsg,
853 unsigned char *Pointer,
854 PFORMAT_STRING pFormat)
856 unsigned type = pFormat[0], attr = pFormat[1];
860 TRACE("(%p,%p,%p)\n", pStubMsg, Pointer, pFormat);
861 TRACE("type=0x%x, attr=", type); dump_pointer_attr(attr);
863 if (attr & RPC_FC_P_SIMPLEPOINTER) desc = pFormat;
864 else desc = pFormat + *(const SHORT*)pFormat;
867 case RPC_FC_RP: /* ref pointer (always non-null) */
871 /* NULL pointer has no further representation */
877 FIXME("unhandled ptr type=%02x\n", type);
878 RpcRaiseException(RPC_X_BAD_STUB_DATA);
881 if (attr & RPC_FC_P_DEREF) {
882 Pointer = *(unsigned char**)Pointer;
883 TRACE("deref => %p\n", Pointer);
886 m = NdrBufferSizer[*desc & NDR_TABLE_MASK];
887 if (m) m(pStubMsg, Pointer, desc);
888 else FIXME("no buffersizer for data type=%02x\n", *desc);
891 /***********************************************************************
892 * PointerMemorySize [RPCRT4.@]
894 static unsigned long PointerMemorySize(PMIDL_STUB_MESSAGE pStubMsg,
895 unsigned char *Buffer,
896 PFORMAT_STRING pFormat)
898 unsigned type = pFormat[0], attr = pFormat[1];
902 FIXME("(%p,%p,%p): stub\n", pStubMsg, Buffer, pFormat);
903 TRACE("type=0x%x, attr=", type); dump_pointer_attr(attr);
905 if (attr & RPC_FC_P_SIMPLEPOINTER) desc = pFormat;
906 else desc = pFormat + *(const SHORT*)pFormat;
909 case RPC_FC_RP: /* ref pointer (always non-null) */
912 FIXME("unhandled ptr type=%02x\n", type);
913 RpcRaiseException(RPC_X_BAD_STUB_DATA);
916 if (attr & RPC_FC_P_DEREF) {
920 m = NdrMemorySizer[*desc & NDR_TABLE_MASK];
921 if (m) m(pStubMsg, desc);
922 else FIXME("no memorysizer for data type=%02x\n", *desc);
927 /***********************************************************************
928 * PointerFree [RPCRT4.@]
930 static void PointerFree(PMIDL_STUB_MESSAGE pStubMsg,
931 unsigned char *Pointer,
932 PFORMAT_STRING pFormat)
934 unsigned type = pFormat[0], attr = pFormat[1];
938 TRACE("(%p,%p,%p)\n", pStubMsg, Pointer, pFormat);
939 TRACE("type=0x%x, attr=", type); dump_pointer_attr(attr);
940 if (attr & RPC_FC_P_DONTFREE) return;
942 if (attr & RPC_FC_P_SIMPLEPOINTER) desc = pFormat;
943 else desc = pFormat + *(const SHORT*)pFormat;
945 if (!Pointer) return;
947 if (attr & RPC_FC_P_DEREF) {
948 Pointer = *(unsigned char**)Pointer;
949 TRACE("deref => %p\n", Pointer);
952 m = NdrFreer[*desc & NDR_TABLE_MASK];
953 if (m) m(pStubMsg, Pointer, desc);
955 /* hmm... is this sensible?
956 * perhaps we should check if the memory comes from NdrAllocate,
957 * and deallocate only if so - checking if the pointer is between
958 * BufferStart and BufferEnd is probably no good since the buffer
959 * may be reallocated when the server wants to marshal the reply */
961 case RPC_FC_BOGUS_STRUCT:
962 case RPC_FC_BOGUS_ARRAY:
963 case RPC_FC_USER_MARSHAL:
968 FIXME("unhandled data type=%02x\n", *desc);
970 case RPC_FC_C_CSTRING:
971 case RPC_FC_C_WSTRING:
972 if (pStubMsg->ReuseBuffer) goto notfree;
978 if (attr & RPC_FC_P_ONSTACK) {
979 TRACE("not freeing stack ptr %p\n", Pointer);
982 TRACE("freeing %p\n", Pointer);
983 NdrFree(pStubMsg, Pointer);
986 TRACE("not freeing %p\n", Pointer);
989 /***********************************************************************
990 * EmbeddedPointerMarshall
992 static unsigned char * EmbeddedPointerMarshall(PMIDL_STUB_MESSAGE pStubMsg,
993 unsigned char *pMemory,
994 PFORMAT_STRING pFormat)
996 unsigned char *Mark = pStubMsg->BufferMark;
997 unsigned long Offset = pStubMsg->Offset;
998 unsigned ofs, rep, count, stride, xofs;
1001 TRACE("(%p,%p,%p)\n", pStubMsg, pMemory, pFormat);
1003 if (*pFormat != RPC_FC_PP) return NULL;
1006 while (pFormat[0] != RPC_FC_END) {
1007 switch (pFormat[0]) {
1009 FIXME("unknown repeat type %d\n", pFormat[0]);
1010 case RPC_FC_NO_REPEAT:
1018 case RPC_FC_FIXED_REPEAT:
1019 rep = *(const WORD*)&pFormat[2];
1020 stride = *(const WORD*)&pFormat[4];
1021 ofs = *(const WORD*)&pFormat[6];
1022 count = *(const WORD*)&pFormat[8];
1026 case RPC_FC_VARIABLE_REPEAT:
1027 rep = pStubMsg->MaxCount;
1028 stride = *(const WORD*)&pFormat[2];
1029 ofs = *(const WORD*)&pFormat[4];
1030 count = *(const WORD*)&pFormat[6];
1031 xofs = (pFormat[1] == RPC_FC_VARIABLE_OFFSET) ? Offset * stride : 0;
1035 for (i = 0; i < rep; i++) {
1036 PFORMAT_STRING info = pFormat;
1037 unsigned char *membase = pMemory + (i * stride);
1038 unsigned char *bufbase = Mark + (i * stride);
1040 /* ofs doesn't seem to matter in this context */
1041 for (u=0; u<count; u++,info+=8) {
1042 unsigned char *memptr = membase + *(const SHORT*)&info[0];
1043 unsigned char *bufptr = bufbase + *(const SHORT*)&info[2];
1044 PointerMarshall(pStubMsg, bufptr, *(unsigned char**)memptr, info+4);
1047 pFormat += 8 * count;
1050 STD_OVERFLOW_CHECK(pStubMsg);
1055 /***********************************************************************
1056 * EmbeddedPointerUnmarshall
1058 static unsigned char * EmbeddedPointerUnmarshall(PMIDL_STUB_MESSAGE pStubMsg,
1059 unsigned char **ppMemory,
1060 PFORMAT_STRING pFormat,
1061 unsigned char fMustAlloc)
1063 unsigned char *Mark = pStubMsg->BufferMark;
1064 unsigned long Offset = pStubMsg->Offset;
1065 unsigned ofs, rep, count, stride, xofs;
1068 TRACE("(%p,%p,%p,%d)\n", pStubMsg, ppMemory, pFormat, fMustAlloc);
1070 if (*pFormat != RPC_FC_PP) return NULL;
1073 while (pFormat[0] != RPC_FC_END) {
1074 TRACE("pFormat[0] = 0x%x\n", pFormat[0]);
1075 switch (pFormat[0]) {
1077 FIXME("unknown repeat type %d\n", pFormat[0]);
1078 case RPC_FC_NO_REPEAT:
1086 case RPC_FC_FIXED_REPEAT:
1087 rep = *(const WORD*)&pFormat[2];
1088 stride = *(const WORD*)&pFormat[4];
1089 ofs = *(const WORD*)&pFormat[6];
1090 count = *(const WORD*)&pFormat[8];
1094 case RPC_FC_VARIABLE_REPEAT:
1095 rep = pStubMsg->MaxCount;
1096 stride = *(const WORD*)&pFormat[2];
1097 ofs = *(const WORD*)&pFormat[4];
1098 count = *(const WORD*)&pFormat[6];
1099 xofs = (pFormat[1] == RPC_FC_VARIABLE_OFFSET) ? Offset * stride : 0;
1103 /* ofs doesn't seem to matter in this context */
1104 for (i = 0; i < rep; i++) {
1105 PFORMAT_STRING info = pFormat;
1106 unsigned char *membase = *ppMemory + (i * stride);
1107 unsigned char *bufbase = Mark + (i * stride);
1109 for (u=0; u<count; u++,info+=8) {
1110 unsigned char *memptr = membase + *(const SHORT*)&info[0];
1111 unsigned char *bufptr = bufbase + *(const SHORT*)&info[2];
1112 PointerUnmarshall(pStubMsg, bufptr, (unsigned char**)memptr, info+4, TRUE);
1115 pFormat += 8 * count;
1121 /***********************************************************************
1122 * EmbeddedPointerBufferSize
1124 static void EmbeddedPointerBufferSize(PMIDL_STUB_MESSAGE pStubMsg,
1125 unsigned char *pMemory,
1126 PFORMAT_STRING pFormat)
1128 unsigned long Offset = pStubMsg->Offset;
1129 unsigned ofs, rep, count, stride, xofs;
1132 TRACE("(%p,%p,%p)\n", pStubMsg, pMemory, pFormat);
1134 if (pStubMsg->IgnoreEmbeddedPointers) return;
1136 if (*pFormat != RPC_FC_PP) return;
1139 while (pFormat[0] != RPC_FC_END) {
1140 switch (pFormat[0]) {
1142 FIXME("unknown repeat type %d\n", pFormat[0]);
1143 case RPC_FC_NO_REPEAT:
1151 case RPC_FC_FIXED_REPEAT:
1152 rep = *(const WORD*)&pFormat[2];
1153 stride = *(const WORD*)&pFormat[4];
1154 ofs = *(const WORD*)&pFormat[6];
1155 count = *(const WORD*)&pFormat[8];
1159 case RPC_FC_VARIABLE_REPEAT:
1160 rep = pStubMsg->MaxCount;
1161 stride = *(const WORD*)&pFormat[2];
1162 ofs = *(const WORD*)&pFormat[4];
1163 count = *(const WORD*)&pFormat[6];
1164 xofs = (pFormat[1] == RPC_FC_VARIABLE_OFFSET) ? Offset * stride : 0;
1168 /* ofs doesn't seem to matter in this context */
1169 for (i = 0; i < rep; i++) {
1170 PFORMAT_STRING info = pFormat;
1171 unsigned char *membase = pMemory + (i * stride);
1173 for (u=0; u<count; u++,info+=8) {
1174 unsigned char *memptr = membase + *(const SHORT*)&info[0];
1175 PointerBufferSize(pStubMsg, *(unsigned char**)memptr, info+4);
1178 pFormat += 8 * count;
1182 /***********************************************************************
1183 * EmbeddedPointerMemorySize
1185 static unsigned long EmbeddedPointerMemorySize(PMIDL_STUB_MESSAGE pStubMsg,
1186 PFORMAT_STRING pFormat)
1188 unsigned long Offset = pStubMsg->Offset;
1189 unsigned char *Mark = pStubMsg->BufferMark;
1190 unsigned ofs, rep, count, stride, xofs;
1193 FIXME("(%p,%p): stub\n", pStubMsg, pFormat);
1195 if (*pFormat != RPC_FC_PP) return 0;
1198 while (pFormat[0] != RPC_FC_END) {
1199 switch (pFormat[0]) {
1201 FIXME("unknown repeat type %d\n", pFormat[0]);
1202 case RPC_FC_NO_REPEAT:
1210 case RPC_FC_FIXED_REPEAT:
1211 rep = *(const WORD*)&pFormat[2];
1212 stride = *(const WORD*)&pFormat[4];
1213 ofs = *(const WORD*)&pFormat[6];
1214 count = *(const WORD*)&pFormat[8];
1218 case RPC_FC_VARIABLE_REPEAT:
1219 rep = pStubMsg->MaxCount;
1220 stride = *(const WORD*)&pFormat[2];
1221 ofs = *(const WORD*)&pFormat[4];
1222 count = *(const WORD*)&pFormat[6];
1223 xofs = (pFormat[1] == RPC_FC_VARIABLE_OFFSET) ? Offset * stride : 0;
1227 /* ofs doesn't seem to matter in this context */
1228 for (i = 0; i < rep; i++) {
1229 PFORMAT_STRING info = pFormat;
1230 unsigned char *bufbase = Mark + (i * stride);
1232 for (u=0; u<count; u++,info+=8) {
1233 unsigned char *bufptr = bufbase + *(const SHORT*)&info[2];
1234 PointerMemorySize(pStubMsg, bufptr, info+4);
1237 pFormat += 8 * count;
1243 /***********************************************************************
1244 * EmbeddedPointerFree
1246 static void EmbeddedPointerFree(PMIDL_STUB_MESSAGE pStubMsg,
1247 unsigned char *pMemory,
1248 PFORMAT_STRING pFormat)
1250 unsigned long Offset = pStubMsg->Offset;
1251 unsigned ofs, rep, count, stride, xofs;
1254 TRACE("(%p,%p,%p)\n", pStubMsg, pMemory, pFormat);
1255 if (*pFormat != RPC_FC_PP) return;
1258 while (pFormat[0] != RPC_FC_END) {
1259 switch (pFormat[0]) {
1261 FIXME("unknown repeat type %d\n", pFormat[0]);
1262 case RPC_FC_NO_REPEAT:
1270 case RPC_FC_FIXED_REPEAT:
1271 rep = *(const WORD*)&pFormat[2];
1272 stride = *(const WORD*)&pFormat[4];
1273 ofs = *(const WORD*)&pFormat[6];
1274 count = *(const WORD*)&pFormat[8];
1278 case RPC_FC_VARIABLE_REPEAT:
1279 rep = pStubMsg->MaxCount;
1280 stride = *(const WORD*)&pFormat[2];
1281 ofs = *(const WORD*)&pFormat[4];
1282 count = *(const WORD*)&pFormat[6];
1283 xofs = (pFormat[1] == RPC_FC_VARIABLE_OFFSET) ? Offset * stride : 0;
1287 /* ofs doesn't seem to matter in this context */
1288 for (i = 0; i < rep; i++) {
1289 PFORMAT_STRING info = pFormat;
1290 unsigned char *membase = pMemory + (i * stride);
1292 for (u=0; u<count; u++,info+=8) {
1293 unsigned char *memptr = membase + *(const SHORT*)&info[0];
1294 PointerFree(pStubMsg, *(unsigned char**)memptr, info+4);
1297 pFormat += 8 * count;
1301 /***********************************************************************
1302 * NdrPointerMarshall [RPCRT4.@]
1304 unsigned char * WINAPI NdrPointerMarshall(PMIDL_STUB_MESSAGE pStubMsg,
1305 unsigned char *pMemory,
1306 PFORMAT_STRING pFormat)
1308 unsigned char *Buffer;
1310 TRACE("(%p,%p,%p)\n", pStubMsg, pMemory, pFormat);
1312 /* incremement the buffer here instead of in PointerMarshall,
1313 * as that is used by embedded pointers which already handle the incrementing
1314 * the buffer, and shouldn't write any additional pointer data to the wire */
1315 if (*pFormat != RPC_FC_RP)
1317 ALIGN_POINTER(pStubMsg->Buffer, 4);
1318 Buffer = pStubMsg->Buffer;
1319 pStubMsg->Buffer += 4;
1322 Buffer = pStubMsg->Buffer;
1324 PointerMarshall(pStubMsg, Buffer, pMemory, pFormat);
1326 STD_OVERFLOW_CHECK(pStubMsg);
1331 /***********************************************************************
1332 * NdrPointerUnmarshall [RPCRT4.@]
1334 unsigned char * WINAPI NdrPointerUnmarshall(PMIDL_STUB_MESSAGE pStubMsg,
1335 unsigned char **ppMemory,
1336 PFORMAT_STRING pFormat,
1337 unsigned char fMustAlloc)
1339 unsigned char *Buffer;
1341 TRACE("(%p,%p,%p,%d)\n", pStubMsg, ppMemory, pFormat, fMustAlloc);
1343 /* incremement the buffer here instead of in PointerUnmarshall,
1344 * as that is used by embedded pointers which already handle the incrementing
1345 * the buffer, and shouldn't read any additional pointer data from the
1347 if (*pFormat != RPC_FC_RP)
1349 ALIGN_POINTER(pStubMsg->Buffer, 4);
1350 Buffer = pStubMsg->Buffer;
1351 pStubMsg->Buffer += 4;
1354 Buffer = pStubMsg->Buffer;
1356 PointerUnmarshall(pStubMsg, Buffer, ppMemory, pFormat, fMustAlloc);
1361 /***********************************************************************
1362 * NdrPointerBufferSize [RPCRT4.@]
1364 void WINAPI NdrPointerBufferSize(PMIDL_STUB_MESSAGE pStubMsg,
1365 unsigned char *pMemory,
1366 PFORMAT_STRING pFormat)
1368 TRACE("(%p,%p,%p)\n", pStubMsg, pMemory, pFormat);
1370 /* incremement the buffer length here instead of in PointerBufferSize,
1371 * as that is used by embedded pointers which already handle the buffer
1372 * length, and shouldn't write anything more to the wire */
1373 if (*pFormat != RPC_FC_RP)
1375 ALIGN_LENGTH(pStubMsg->BufferLength, 4);
1376 pStubMsg->BufferLength += 4;
1379 PointerBufferSize(pStubMsg, pMemory, pFormat);
1382 /***********************************************************************
1383 * NdrPointerMemorySize [RPCRT4.@]
1385 unsigned long WINAPI NdrPointerMemorySize(PMIDL_STUB_MESSAGE pStubMsg,
1386 PFORMAT_STRING pFormat)
1388 /* unsigned size = *(LPWORD)(pFormat+2); */
1389 FIXME("(%p,%p): stub\n", pStubMsg, pFormat);
1390 PointerMemorySize(pStubMsg, pStubMsg->Buffer, pFormat);
1394 /***********************************************************************
1395 * NdrPointerFree [RPCRT4.@]
1397 void WINAPI NdrPointerFree(PMIDL_STUB_MESSAGE pStubMsg,
1398 unsigned char *pMemory,
1399 PFORMAT_STRING pFormat)
1401 TRACE("(%p,%p,%p)\n", pStubMsg, pMemory, pFormat);
1402 PointerFree(pStubMsg, pMemory, pFormat);
1405 /***********************************************************************
1406 * NdrSimpleStructMarshall [RPCRT4.@]
1408 unsigned char * WINAPI NdrSimpleStructMarshall(PMIDL_STUB_MESSAGE pStubMsg,
1409 unsigned char *pMemory,
1410 PFORMAT_STRING pFormat)
1412 unsigned size = *(const WORD*)(pFormat+2);
1413 TRACE("(%p,%p,%p)\n", pStubMsg, pMemory, pFormat);
1415 ALIGN_POINTER(pStubMsg->Buffer, pFormat[1] + 1);
1417 memcpy(pStubMsg->Buffer, pMemory, size);
1418 pStubMsg->BufferMark = pStubMsg->Buffer;
1419 pStubMsg->Buffer += size;
1421 if (pFormat[0] != RPC_FC_STRUCT)
1422 EmbeddedPointerMarshall(pStubMsg, pMemory, pFormat+4);
1424 STD_OVERFLOW_CHECK(pStubMsg);
1429 /***********************************************************************
1430 * NdrSimpleStructUnmarshall [RPCRT4.@]
1432 unsigned char * WINAPI NdrSimpleStructUnmarshall(PMIDL_STUB_MESSAGE pStubMsg,
1433 unsigned char **ppMemory,
1434 PFORMAT_STRING pFormat,
1435 unsigned char fMustAlloc)
1437 unsigned size = *(const WORD*)(pFormat+2);
1438 TRACE("(%p,%p,%p,%d)\n", pStubMsg, ppMemory, pFormat, fMustAlloc);
1440 ALIGN_POINTER(pStubMsg->Buffer, pFormat[1] + 1);
1443 *ppMemory = NdrAllocate(pStubMsg, size);
1444 memcpy(*ppMemory, pStubMsg->Buffer, size);
1446 if (!pStubMsg->IsClient && !*ppMemory)
1447 /* for servers, we just point straight into the RPC buffer */
1448 *ppMemory = pStubMsg->Buffer;
1450 /* for clients, memory should be provided by caller */
1451 memcpy(*ppMemory, pStubMsg->Buffer, size);
1454 pStubMsg->BufferMark = pStubMsg->Buffer;
1455 pStubMsg->Buffer += size;
1457 if (pFormat[0] != RPC_FC_STRUCT)
1458 EmbeddedPointerUnmarshall(pStubMsg, ppMemory, pFormat+4, fMustAlloc);
1464 /***********************************************************************
1465 * NdrSimpleStructUnmarshall [RPCRT4.@]
1467 void WINAPI NdrSimpleTypeMarshall( PMIDL_STUB_MESSAGE pStubMsg, unsigned char* pMemory,
1468 unsigned char FormatChar )
1474 /***********************************************************************
1475 * NdrSimpleStructUnmarshall [RPCRT4.@]
1477 void WINAPI NdrSimpleTypeUnmarshall( PMIDL_STUB_MESSAGE pStubMsg, unsigned char* pMemory,
1478 unsigned char FormatChar )
1484 /***********************************************************************
1485 * NdrSimpleStructBufferSize [RPCRT4.@]
1487 void WINAPI NdrSimpleStructBufferSize(PMIDL_STUB_MESSAGE pStubMsg,
1488 unsigned char *pMemory,
1489 PFORMAT_STRING pFormat)
1491 unsigned size = *(const WORD*)(pFormat+2);
1492 TRACE("(%p,%p,%p)\n", pStubMsg, pMemory, pFormat);
1494 ALIGN_LENGTH(pStubMsg->BufferLength, pFormat[1] + 1);
1496 pStubMsg->BufferLength += size;
1497 if (pFormat[0] != RPC_FC_STRUCT)
1498 EmbeddedPointerBufferSize(pStubMsg, pMemory, pFormat+4);
1501 /***********************************************************************
1502 * NdrSimpleStructMemorySize [RPCRT4.@]
1504 unsigned long WINAPI NdrSimpleStructMemorySize(PMIDL_STUB_MESSAGE pStubMsg,
1505 PFORMAT_STRING pFormat)
1507 unsigned short size = *(LPWORD)(pFormat+2);
1509 TRACE("(%p,%p)\n", pStubMsg, pFormat);
1511 ALIGN_POINTER(pStubMsg->Buffer, pFormat[1] + 1);
1512 pStubMsg->MemorySize += size;
1513 pStubMsg->Buffer += size;
1515 if (pFormat[0] != RPC_FC_STRUCT)
1516 EmbeddedPointerMemorySize(pStubMsg, pFormat+4);
1520 /***********************************************************************
1521 * NdrSimpleStructFree [RPCRT4.@]
1523 void WINAPI NdrSimpleStructFree(PMIDL_STUB_MESSAGE pStubMsg,
1524 unsigned char *pMemory,
1525 PFORMAT_STRING pFormat)
1527 TRACE("(%p,%p,%p)\n", pStubMsg, pMemory, pFormat);
1528 if (pFormat[0] != RPC_FC_STRUCT)
1529 EmbeddedPointerFree(pStubMsg, pMemory, pFormat+4);
1533 static unsigned long EmbeddedComplexSize(PMIDL_STUB_MESSAGE pStubMsg,
1534 PFORMAT_STRING pFormat)
1538 case RPC_FC_PSTRUCT:
1539 case RPC_FC_CSTRUCT:
1540 case RPC_FC_BOGUS_STRUCT:
1541 return *(const WORD*)&pFormat[2];
1542 case RPC_FC_USER_MARSHAL:
1543 return *(const WORD*)&pFormat[4];
1544 case RPC_FC_NON_ENCAPSULATED_UNION:
1546 if (pStubMsg->fHasNewCorrDesc)
1551 pFormat += *(const SHORT*)pFormat;
1552 return *(const SHORT*)pFormat;
1554 return sizeof(void *);
1556 FIXME("unhandled embedded type %02x\n", *pFormat);
1562 static unsigned long EmbeddedComplexMemorySize(PMIDL_STUB_MESSAGE pStubMsg,
1563 PFORMAT_STRING pFormat)
1565 NDR_MEMORYSIZE m = NdrMemorySizer[*pFormat & NDR_TABLE_MASK];
1569 FIXME("no memorysizer for data type=%02x\n", *pFormat);
1573 return m(pStubMsg, pFormat);
1577 static unsigned char * ComplexMarshall(PMIDL_STUB_MESSAGE pStubMsg,
1578 unsigned char *pMemory,
1579 PFORMAT_STRING pFormat,
1580 PFORMAT_STRING pPointer)
1582 PFORMAT_STRING desc;
1586 while (*pFormat != RPC_FC_END) {
1590 TRACE("short=%d <= %p\n", *(WORD*)pMemory, pMemory);
1591 memcpy(pStubMsg->Buffer, pMemory, 2);
1592 pStubMsg->Buffer += 2;
1598 TRACE("long=%ld <= %p\n", *(DWORD*)pMemory, pMemory);
1599 memcpy(pStubMsg->Buffer, pMemory, 4);
1600 pStubMsg->Buffer += 4;
1603 case RPC_FC_POINTER:
1604 TRACE("pointer=%p <= %p\n", *(unsigned char**)pMemory, pMemory);
1605 NdrPointerMarshall(pStubMsg, *(unsigned char**)pMemory, pPointer);
1609 case RPC_FC_ALIGNM4:
1610 ALIGN_POINTER(pMemory, 4);
1612 case RPC_FC_ALIGNM8:
1613 ALIGN_POINTER(pMemory, 8);
1615 case RPC_FC_STRUCTPAD2:
1618 case RPC_FC_EMBEDDED_COMPLEX:
1619 pMemory += pFormat[1];
1621 desc = pFormat + *(const SHORT*)pFormat;
1622 size = EmbeddedComplexSize(pStubMsg, desc);
1623 TRACE("embedded complex (size=%ld) <= %p\n", size, pMemory);
1624 m = NdrMarshaller[*desc & NDR_TABLE_MASK];
1625 if (m) m(pStubMsg, pMemory, desc);
1626 else FIXME("no marshaller for embedded type %02x\n", *desc);
1633 FIXME("unhandled format %02x\n", *pFormat);
1641 static unsigned char * ComplexUnmarshall(PMIDL_STUB_MESSAGE pStubMsg,
1642 unsigned char *pMemory,
1643 PFORMAT_STRING pFormat,
1644 PFORMAT_STRING pPointer,
1645 unsigned char fMustAlloc)
1647 PFORMAT_STRING desc;
1651 while (*pFormat != RPC_FC_END) {
1655 memcpy(pMemory, pStubMsg->Buffer, 2);
1656 TRACE("short=%d => %p\n", *(WORD*)pMemory, pMemory);
1657 pStubMsg->Buffer += 2;
1663 memcpy(pMemory, pStubMsg->Buffer, 4);
1664 TRACE("long=%ld => %p\n", *(DWORD*)pMemory, pMemory);
1665 pStubMsg->Buffer += 4;
1668 case RPC_FC_POINTER:
1669 TRACE("pointer => %p\n", pMemory);
1670 NdrPointerUnmarshall(pStubMsg, (unsigned char**)pMemory, pPointer, TRUE);
1674 case RPC_FC_ALIGNM4:
1675 ALIGN_POINTER(pMemory, 4);
1677 case RPC_FC_ALIGNM8:
1678 ALIGN_POINTER(pMemory, 8);
1680 case RPC_FC_STRUCTPAD2:
1683 case RPC_FC_EMBEDDED_COMPLEX:
1684 pMemory += pFormat[1];
1686 desc = pFormat + *(const SHORT*)pFormat;
1687 size = EmbeddedComplexSize(pStubMsg, desc);
1688 TRACE("embedded complex (size=%ld) => %p\n", size, pMemory);
1689 m = NdrUnmarshaller[*desc & NDR_TABLE_MASK];
1690 memset(pMemory, 0, size); /* just in case */
1691 if (m) m(pStubMsg, &pMemory, desc, fMustAlloc);
1692 else FIXME("no unmarshaller for embedded type %02x\n", *desc);
1699 FIXME("unhandled format %d\n", *pFormat);
1707 static unsigned char * ComplexBufferSize(PMIDL_STUB_MESSAGE pStubMsg,
1708 unsigned char *pMemory,
1709 PFORMAT_STRING pFormat,
1710 PFORMAT_STRING pPointer)
1712 PFORMAT_STRING desc;
1716 while (*pFormat != RPC_FC_END) {
1720 pStubMsg->BufferLength += 2;
1726 pStubMsg->BufferLength += 4;
1729 case RPC_FC_POINTER:
1730 NdrPointerBufferSize(pStubMsg, *(unsigned char**)pMemory, pPointer);
1734 case RPC_FC_ALIGNM4:
1735 ALIGN_POINTER(pMemory, 4);
1737 case RPC_FC_ALIGNM8:
1738 ALIGN_POINTER(pMemory, 8);
1740 case RPC_FC_STRUCTPAD2:
1743 case RPC_FC_EMBEDDED_COMPLEX:
1744 pMemory += pFormat[1];
1746 desc = pFormat + *(const SHORT*)pFormat;
1747 size = EmbeddedComplexSize(pStubMsg, desc);
1748 m = NdrBufferSizer[*desc & NDR_TABLE_MASK];
1749 if (m) m(pStubMsg, pMemory, desc);
1750 else FIXME("no buffersizer for embedded type %02x\n", *desc);
1757 FIXME("unhandled format %d\n", *pFormat);
1765 static unsigned char * ComplexFree(PMIDL_STUB_MESSAGE pStubMsg,
1766 unsigned char *pMemory,
1767 PFORMAT_STRING pFormat,
1768 PFORMAT_STRING pPointer)
1770 PFORMAT_STRING desc;
1774 while (*pFormat != RPC_FC_END) {
1785 case RPC_FC_POINTER:
1786 NdrPointerFree(pStubMsg, *(unsigned char**)pMemory, pPointer);
1790 case RPC_FC_ALIGNM4:
1791 ALIGN_POINTER(pMemory, 4);
1793 case RPC_FC_ALIGNM8:
1794 ALIGN_POINTER(pMemory, 8);
1796 case RPC_FC_STRUCTPAD2:
1799 case RPC_FC_EMBEDDED_COMPLEX:
1800 pMemory += pFormat[1];
1802 desc = pFormat + *(const SHORT*)pFormat;
1803 size = EmbeddedComplexSize(pStubMsg, desc);
1804 m = NdrFreer[*desc & NDR_TABLE_MASK];
1805 if (m) m(pStubMsg, pMemory, desc);
1806 else FIXME("no freer for embedded type %02x\n", *desc);
1813 FIXME("unhandled format %d\n", *pFormat);
1821 static unsigned long ComplexStructMemorySize(PMIDL_STUB_MESSAGE pStubMsg,
1822 PFORMAT_STRING pFormat)
1824 PFORMAT_STRING desc;
1825 unsigned long size = 0;
1827 while (*pFormat != RPC_FC_END) {
1832 pStubMsg->Buffer += 2;
1837 pStubMsg->Buffer += 4;
1839 case RPC_FC_POINTER:
1841 pStubMsg->Buffer += 4;
1843 case RPC_FC_ALIGNM4:
1844 ALIGN_LENGTH(size, 4);
1845 ALIGN_POINTER(pStubMsg->Buffer, 4);
1847 case RPC_FC_ALIGNM8:
1848 ALIGN_LENGTH(size, 8);
1849 ALIGN_POINTER(pStubMsg->Buffer, 8);
1851 case RPC_FC_STRUCTPAD2:
1853 pStubMsg->Buffer += 2;
1855 case RPC_FC_EMBEDDED_COMPLEX:
1858 desc = pFormat + *(const SHORT*)pFormat;
1859 size += EmbeddedComplexMemorySize(pStubMsg, desc);
1865 FIXME("unhandled format %d\n", *pFormat);
1873 /***********************************************************************
1874 * NdrComplexStructMarshall [RPCRT4.@]
1876 unsigned char * WINAPI NdrComplexStructMarshall(PMIDL_STUB_MESSAGE pStubMsg,
1877 unsigned char *pMemory,
1878 PFORMAT_STRING pFormat)
1880 PFORMAT_STRING conf_array = NULL;
1881 PFORMAT_STRING pointer_desc = NULL;
1882 unsigned char *OldMemory = pStubMsg->Memory;
1884 TRACE("(%p,%p,%p)\n", pStubMsg, pMemory, pFormat);
1886 ALIGN_POINTER(pStubMsg->Buffer, pFormat[1] + 1);
1889 if (*(const WORD*)pFormat) conf_array = pFormat + *(const WORD*)pFormat;
1891 if (*(const WORD*)pFormat) pointer_desc = pFormat + *(const WORD*)pFormat;
1894 pStubMsg->Memory = pMemory;
1896 ComplexMarshall(pStubMsg, pMemory, pFormat, pointer_desc);
1899 NdrConformantArrayMarshall(pStubMsg, pMemory, conf_array);
1901 pStubMsg->Memory = OldMemory;
1903 STD_OVERFLOW_CHECK(pStubMsg);
1908 /***********************************************************************
1909 * NdrComplexStructUnmarshall [RPCRT4.@]
1911 unsigned char * WINAPI NdrComplexStructUnmarshall(PMIDL_STUB_MESSAGE pStubMsg,
1912 unsigned char **ppMemory,
1913 PFORMAT_STRING pFormat,
1914 unsigned char fMustAlloc)
1916 unsigned size = *(const WORD*)(pFormat+2);
1917 PFORMAT_STRING conf_array = NULL;
1918 PFORMAT_STRING pointer_desc = NULL;
1919 unsigned char *pMemory;
1921 TRACE("(%p,%p,%p,%d)\n", pStubMsg, ppMemory, pFormat, fMustAlloc);
1923 ALIGN_POINTER(pStubMsg->Buffer, pFormat[1] + 1);
1925 if (fMustAlloc || !*ppMemory)
1927 *ppMemory = NdrAllocate(pStubMsg, size);
1928 memset(*ppMemory, 0, size);
1932 if (*(const WORD*)pFormat) conf_array = pFormat + *(const WORD*)pFormat;
1934 if (*(const WORD*)pFormat) pointer_desc = pFormat + *(const WORD*)pFormat;
1937 pMemory = ComplexUnmarshall(pStubMsg, *ppMemory, pFormat, pointer_desc, fMustAlloc);
1940 NdrConformantArrayUnmarshall(pStubMsg, &pMemory, conf_array, fMustAlloc);
1945 /***********************************************************************
1946 * NdrComplexStructBufferSize [RPCRT4.@]
1948 void WINAPI NdrComplexStructBufferSize(PMIDL_STUB_MESSAGE pStubMsg,
1949 unsigned char *pMemory,
1950 PFORMAT_STRING pFormat)
1952 PFORMAT_STRING conf_array = NULL;
1953 PFORMAT_STRING pointer_desc = NULL;
1954 unsigned char *OldMemory = pStubMsg->Memory;
1956 TRACE("(%p,%p,%p)\n", pStubMsg, pMemory, pFormat);
1958 ALIGN_LENGTH(pStubMsg->BufferLength, pFormat[1] + 1);
1961 if (*(const WORD*)pFormat) conf_array = pFormat + *(const WORD*)pFormat;
1963 if (*(const WORD*)pFormat) pointer_desc = pFormat + *(const WORD*)pFormat;
1966 pStubMsg->Memory = pMemory;
1968 pMemory = ComplexBufferSize(pStubMsg, pMemory, pFormat, pointer_desc);
1971 NdrConformantArrayBufferSize(pStubMsg, pMemory, conf_array);
1973 pStubMsg->Memory = OldMemory;
1976 /***********************************************************************
1977 * NdrComplexStructMemorySize [RPCRT4.@]
1979 unsigned long WINAPI NdrComplexStructMemorySize(PMIDL_STUB_MESSAGE pStubMsg,
1980 PFORMAT_STRING pFormat)
1982 unsigned size = *(const WORD*)(pFormat+2);
1983 PFORMAT_STRING conf_array = NULL;
1984 PFORMAT_STRING pointer_desc = NULL;
1986 TRACE("(%p,%p)\n", pStubMsg, pFormat);
1988 ALIGN_POINTER(pStubMsg->Buffer, pFormat[1] + 1);
1991 if (*(const WORD*)pFormat) conf_array = pFormat + *(const WORD*)pFormat;
1993 if (*(const WORD*)pFormat) pointer_desc = pFormat + *(const WORD*)pFormat;
1996 ComplexStructMemorySize(pStubMsg, pFormat);
1999 NdrConformantArrayMemorySize(pStubMsg, conf_array);
2004 /***********************************************************************
2005 * NdrComplexStructFree [RPCRT4.@]
2007 void WINAPI NdrComplexStructFree(PMIDL_STUB_MESSAGE pStubMsg,
2008 unsigned char *pMemory,
2009 PFORMAT_STRING pFormat)
2011 PFORMAT_STRING conf_array = NULL;
2012 PFORMAT_STRING pointer_desc = NULL;
2013 unsigned char *OldMemory = pStubMsg->Memory;
2015 TRACE("(%p,%p,%p)\n", pStubMsg, pMemory, pFormat);
2018 if (*(const WORD*)pFormat) conf_array = pFormat + *(const WORD*)pFormat;
2020 if (*(const WORD*)pFormat) pointer_desc = pFormat + *(const WORD*)pFormat;
2023 pStubMsg->Memory = pMemory;
2025 pMemory = ComplexFree(pStubMsg, pMemory, pFormat, pointer_desc);
2028 NdrConformantArrayFree(pStubMsg, pMemory, conf_array);
2030 pStubMsg->Memory = OldMemory;
2033 /***********************************************************************
2034 * NdrConformantArrayMarshall [RPCRT4.@]
2036 unsigned char * WINAPI NdrConformantArrayMarshall(PMIDL_STUB_MESSAGE pStubMsg,
2037 unsigned char *pMemory,
2038 PFORMAT_STRING pFormat)
2040 DWORD size = 0, esize = *(const WORD*)(pFormat+2);
2041 unsigned char alignment = pFormat[1] + 1;
2043 TRACE("(%p,%p,%p)\n", pStubMsg, pMemory, pFormat);
2044 if (pFormat[0] != RPC_FC_CARRAY) FIXME("format=%d\n", pFormat[0]);
2046 pFormat = ComputeConformance(pStubMsg, pMemory, pFormat+4, 0);
2047 size = pStubMsg->MaxCount;
2049 WriteConformance(pStubMsg);
2051 ALIGN_POINTER(pStubMsg->Buffer, alignment);
2053 memcpy(pStubMsg->Buffer, pMemory, size*esize);
2054 pStubMsg->BufferMark = pStubMsg->Buffer;
2055 pStubMsg->Buffer += size*esize;
2057 EmbeddedPointerMarshall(pStubMsg, pMemory, pFormat);
2059 STD_OVERFLOW_CHECK(pStubMsg);
2064 /***********************************************************************
2065 * NdrConformantArrayUnmarshall [RPCRT4.@]
2067 unsigned char * WINAPI NdrConformantArrayUnmarshall(PMIDL_STUB_MESSAGE pStubMsg,
2068 unsigned char **ppMemory,
2069 PFORMAT_STRING pFormat,
2070 unsigned char fMustAlloc)
2072 DWORD size = 0, esize = *(const WORD*)(pFormat+2);
2073 unsigned char alignment = pFormat[1] + 1;
2075 TRACE("(%p,%p,%p,%d)\n", pStubMsg, ppMemory, pFormat, fMustAlloc);
2076 if (pFormat[0] != RPC_FC_CARRAY) FIXME("format=%d\n", pFormat[0]);
2078 pFormat = ReadConformance(pStubMsg, pFormat+4);
2079 size = pStubMsg->MaxCount;
2081 if (fMustAlloc || !*ppMemory)
2082 *ppMemory = NdrAllocate(pStubMsg, size*esize);
2084 ALIGN_POINTER(pStubMsg->Buffer, alignment);
2086 memcpy(*ppMemory, pStubMsg->Buffer, size*esize);
2088 pStubMsg->BufferMark = pStubMsg->Buffer;
2089 pStubMsg->Buffer += size*esize;
2091 EmbeddedPointerUnmarshall(pStubMsg, ppMemory, pFormat, fMustAlloc);
2096 /***********************************************************************
2097 * NdrConformantArrayBufferSize [RPCRT4.@]
2099 void WINAPI NdrConformantArrayBufferSize(PMIDL_STUB_MESSAGE pStubMsg,
2100 unsigned char *pMemory,
2101 PFORMAT_STRING pFormat)
2103 DWORD size = 0, esize = *(const WORD*)(pFormat+2);
2104 unsigned char alignment = pFormat[1] + 1;
2106 TRACE("(%p,%p,%p)\n", pStubMsg, pMemory, pFormat);
2107 if (pFormat[0] != RPC_FC_CARRAY) FIXME("format=%d\n", pFormat[0]);
2109 pFormat = ComputeConformance(pStubMsg, pMemory, pFormat+4, 0);
2110 size = pStubMsg->MaxCount;
2112 SizeConformance(pStubMsg);
2114 ALIGN_LENGTH(pStubMsg->BufferLength, alignment);
2116 /* conformance value plus array */
2117 pStubMsg->BufferLength += size*esize;
2119 EmbeddedPointerBufferSize(pStubMsg, pMemory, pFormat);
2122 /***********************************************************************
2123 * NdrConformantArrayMemorySize [RPCRT4.@]
2125 unsigned long WINAPI NdrConformantArrayMemorySize(PMIDL_STUB_MESSAGE pStubMsg,
2126 PFORMAT_STRING pFormat)
2128 DWORD size = 0, esize = *(const WORD*)(pFormat+2);
2129 unsigned char alignment = pFormat[1] + 1;
2131 TRACE("(%p,%p)\n", pStubMsg, pFormat);
2132 if (pFormat[0] != RPC_FC_CARRAY) FIXME("format=%d\n", pFormat[0]);
2134 pFormat = ReadConformance(pStubMsg, pFormat+4);
2135 size = pStubMsg->MaxCount;
2136 pStubMsg->MemorySize += size*esize;
2138 ALIGN_POINTER(pStubMsg->Buffer, alignment);
2139 pStubMsg->BufferMark = pStubMsg->Buffer;
2140 pStubMsg->Buffer += size*esize;
2142 EmbeddedPointerMemorySize(pStubMsg, pFormat);
2144 return pStubMsg->MemorySize;
2147 /***********************************************************************
2148 * NdrConformantArrayFree [RPCRT4.@]
2150 void WINAPI NdrConformantArrayFree(PMIDL_STUB_MESSAGE pStubMsg,
2151 unsigned char *pMemory,
2152 PFORMAT_STRING pFormat)
2154 TRACE("(%p,%p,%p)\n", pStubMsg, pMemory, pFormat);
2155 if (pFormat[0] != RPC_FC_CARRAY) FIXME("format=%d\n", pFormat[0]);
2157 EmbeddedPointerFree(pStubMsg, pMemory, pFormat);
2161 /***********************************************************************
2162 * NdrConformantVaryingArrayMarshall [RPCRT4.@]
2164 unsigned char* WINAPI NdrConformantVaryingArrayMarshall( PMIDL_STUB_MESSAGE pStubMsg,
2165 unsigned char* pMemory,
2166 PFORMAT_STRING pFormat )
2168 unsigned char alignment = pFormat[1] + 1;
2169 DWORD esize = *(const WORD*)(pFormat+2);
2171 TRACE("(%p, %p, %p)\n", pStubMsg, pMemory, pFormat);
2173 if (pFormat[0] != RPC_FC_CVARRAY)
2175 ERR("invalid format type %x\n", pFormat[0]);
2176 RpcRaiseException(RPC_S_INTERNAL_ERROR);
2180 pFormat = ComputeConformance(pStubMsg, pMemory, pFormat+4, 0);
2181 pFormat = ComputeVariance(pStubMsg, pMemory, pFormat, 0);
2183 WriteConformance(pStubMsg);
2184 WriteVariance(pStubMsg);
2186 ALIGN_POINTER(pStubMsg->Buffer, alignment);
2188 memcpy(pStubMsg->Buffer, pMemory + pStubMsg->Offset, pStubMsg->ActualCount*esize);
2189 pStubMsg->BufferMark = pStubMsg->Buffer;
2190 pStubMsg->Buffer += pStubMsg->ActualCount*esize;
2192 EmbeddedPointerMarshall(pStubMsg, pMemory, pFormat);
2194 STD_OVERFLOW_CHECK(pStubMsg);
2200 /***********************************************************************
2201 * NdrConformantVaryingArrayUnmarshall [RPCRT4.@]
2203 unsigned char* WINAPI NdrConformantVaryingArrayUnmarshall( PMIDL_STUB_MESSAGE pStubMsg,
2204 unsigned char** ppMemory,
2205 PFORMAT_STRING pFormat,
2206 unsigned char fMustAlloc )
2208 unsigned char alignment = pFormat[1] + 1;
2209 DWORD esize = *(const WORD*)(pFormat+2);
2211 TRACE("(%p, %p, %p, %d)\n", pStubMsg, ppMemory, pFormat, fMustAlloc);
2213 if (pFormat[0] != RPC_FC_CVARRAY)
2215 ERR("invalid format type %x\n", pFormat[0]);
2216 RpcRaiseException(RPC_S_INTERNAL_ERROR);
2220 pFormat = ReadConformance(pStubMsg, pFormat);
2221 pFormat = ReadVariance(pStubMsg, pFormat);
2223 ALIGN_POINTER(pStubMsg->Buffer, alignment);
2225 if (!*ppMemory || fMustAlloc)
2226 *ppMemory = NdrAllocate(pStubMsg, pStubMsg->MaxCount * esize);
2227 memcpy(*ppMemory + pStubMsg->Offset, pStubMsg->Buffer, pStubMsg->ActualCount * esize);
2228 pStubMsg->Buffer += pStubMsg->ActualCount * esize;
2230 EmbeddedPointerUnmarshall(pStubMsg, ppMemory, pFormat, fMustAlloc);
2236 /***********************************************************************
2237 * NdrConformantVaryingArrayFree [RPCRT4.@]
2239 void WINAPI NdrConformantVaryingArrayFree( PMIDL_STUB_MESSAGE pStubMsg,
2240 unsigned char* pMemory,
2241 PFORMAT_STRING pFormat )
2243 TRACE("(%p,%p,%p)\n", pStubMsg, pMemory, pFormat);
2245 if (pFormat[0] != RPC_FC_CVARRAY)
2247 ERR("invalid format type %x\n", pFormat[0]);
2248 RpcRaiseException(RPC_S_INTERNAL_ERROR);
2252 pFormat = ComputeConformance(pStubMsg, pMemory, pFormat+4, 0);
2253 pFormat = ComputeVariance(pStubMsg, pMemory, pFormat, 0);
2255 EmbeddedPointerFree(pStubMsg, pMemory, pFormat);
2259 /***********************************************************************
2260 * NdrConformantVaryingArrayBufferSize [RPCRT4.@]
2262 void WINAPI NdrConformantVaryingArrayBufferSize( PMIDL_STUB_MESSAGE pStubMsg,
2263 unsigned char* pMemory, PFORMAT_STRING pFormat )
2265 unsigned char alignment = pFormat[1] + 1;
2266 DWORD esize = *(const WORD*)(pFormat+2);
2268 TRACE("(%p, %p, %p)\n", pStubMsg, pMemory, pFormat);
2270 if (pFormat[0] != RPC_FC_CVARRAY)
2272 ERR("invalid format type %x\n", pFormat[0]);
2273 RpcRaiseException(RPC_S_INTERNAL_ERROR);
2278 pFormat = ComputeConformance(pStubMsg, pMemory, pFormat+4, 0);
2279 /* compute length */
2280 pFormat = ComputeVariance(pStubMsg, pMemory, pFormat, 0);
2282 SizeConformance(pStubMsg);
2283 SizeVariance(pStubMsg);
2285 ALIGN_LENGTH(pStubMsg->BufferLength, alignment);
2287 pStubMsg->BufferLength += pStubMsg->ActualCount*esize;
2289 EmbeddedPointerBufferSize(pStubMsg, pMemory, pFormat);
2293 /***********************************************************************
2294 * NdrConformantVaryingArrayMemorySize [RPCRT4.@]
2296 unsigned long WINAPI NdrConformantVaryingArrayMemorySize( PMIDL_STUB_MESSAGE pStubMsg,
2297 PFORMAT_STRING pFormat )
2304 /***********************************************************************
2305 * NdrComplexArrayMarshall [RPCRT4.@]
2307 unsigned char * WINAPI NdrComplexArrayMarshall(PMIDL_STUB_MESSAGE pStubMsg,
2308 unsigned char *pMemory,
2309 PFORMAT_STRING pFormat)
2311 ULONG i, count, def;
2312 BOOL variance_present;
2313 unsigned char alignment;
2315 TRACE("(%p,%p,%p)\n", pStubMsg, pMemory, pFormat);
2317 if (pFormat[0] != RPC_FC_BOGUS_ARRAY)
2319 ERR("invalid format type %x\n", pFormat[0]);
2320 RpcRaiseException(RPC_S_INTERNAL_ERROR);
2324 alignment = pFormat[1] + 1;
2326 def = *(const WORD*)&pFormat[2];
2329 pFormat = ComputeConformance(pStubMsg, pMemory, pFormat, def);
2330 TRACE("conformance = %ld\n", pStubMsg->MaxCount);
2332 variance_present = IsConformanceOrVariancePresent(pFormat);
2333 pFormat = ComputeVariance(pStubMsg, pMemory, pFormat, pStubMsg->MaxCount);
2334 TRACE("variance = %ld\n", pStubMsg->ActualCount);
2336 WriteConformance(pStubMsg);
2337 if (variance_present)
2338 WriteVariance(pStubMsg);
2340 ALIGN_POINTER(pStubMsg->Buffer, alignment);
2342 count = pStubMsg->ActualCount;
2343 for (i = 0; i < count; i++)
2344 pMemory = ComplexMarshall(pStubMsg, pMemory, pFormat, NULL);
2346 STD_OVERFLOW_CHECK(pStubMsg);
2351 /***********************************************************************
2352 * NdrComplexArrayUnmarshall [RPCRT4.@]
2354 unsigned char * WINAPI NdrComplexArrayUnmarshall(PMIDL_STUB_MESSAGE pStubMsg,
2355 unsigned char **ppMemory,
2356 PFORMAT_STRING pFormat,
2357 unsigned char fMustAlloc)
2359 ULONG i, count, esize;
2360 unsigned char alignment;
2361 unsigned char *pMemory;
2362 unsigned char *Buffer;
2364 TRACE("(%p,%p,%p,%d)\n", pStubMsg, ppMemory, pFormat, fMustAlloc);
2366 if (pFormat[0] != RPC_FC_BOGUS_ARRAY)
2368 ERR("invalid format type %x\n", pFormat[0]);
2369 RpcRaiseException(RPC_S_INTERNAL_ERROR);
2373 alignment = pFormat[1] + 1;
2377 pFormat = ReadConformance(pStubMsg, pFormat);
2378 pFormat = ReadVariance(pStubMsg, pFormat);
2380 Buffer = pStubMsg->Buffer;
2381 esize = ComplexStructMemorySize(pStubMsg, pFormat);
2382 pStubMsg->Buffer = Buffer;
2384 if (fMustAlloc || !*ppMemory)
2386 *ppMemory = NdrAllocate(pStubMsg, pStubMsg->MaxCount * esize);
2387 memset(*ppMemory, 0, pStubMsg->MaxCount * esize);
2390 ALIGN_POINTER(pStubMsg->Buffer, alignment);
2392 pMemory = *ppMemory;
2393 count = pStubMsg->ActualCount;
2394 for (i = 0; i < count; i++)
2395 pMemory = ComplexUnmarshall(pStubMsg, pMemory, pFormat, NULL, fMustAlloc);
2400 /***********************************************************************
2401 * NdrComplexArrayBufferSize [RPCRT4.@]
2403 void WINAPI NdrComplexArrayBufferSize(PMIDL_STUB_MESSAGE pStubMsg,
2404 unsigned char *pMemory,
2405 PFORMAT_STRING pFormat)
2407 ULONG i, count, def;
2408 unsigned char alignment;
2409 BOOL variance_present;
2411 TRACE("(%p,%p,%p)\n", pStubMsg, pMemory, pFormat);
2413 if (pFormat[0] != RPC_FC_BOGUS_ARRAY)
2415 ERR("invalid format type %x\n", pFormat[0]);
2416 RpcRaiseException(RPC_S_INTERNAL_ERROR);
2420 alignment = pFormat[1] + 1;
2422 def = *(const WORD*)&pFormat[2];
2425 pFormat = ComputeConformance(pStubMsg, pMemory, pFormat, def);
2426 TRACE("conformance = %ld\n", pStubMsg->MaxCount);
2427 SizeConformance(pStubMsg);
2429 variance_present = IsConformanceOrVariancePresent(pFormat);
2430 pFormat = ComputeVariance(pStubMsg, pMemory, pFormat, pStubMsg->MaxCount);
2431 TRACE("variance = %ld\n", pStubMsg->ActualCount);
2433 if (variance_present)
2434 SizeVariance(pStubMsg);
2436 ALIGN_LENGTH(pStubMsg->BufferLength, alignment);
2438 count = pStubMsg->ActualCount;
2439 for (i = 0; i < count; i++)
2440 pMemory = ComplexBufferSize(pStubMsg, pMemory, pFormat, NULL);
2443 /***********************************************************************
2444 * NdrComplexArrayMemorySize [RPCRT4.@]
2446 unsigned long WINAPI NdrComplexArrayMemorySize(PMIDL_STUB_MESSAGE pStubMsg,
2447 PFORMAT_STRING pFormat)
2449 ULONG i, count, esize;
2450 unsigned char alignment;
2451 unsigned char *Buffer;
2452 unsigned long SavedMemorySize;
2453 unsigned long MemorySize;
2455 TRACE("(%p,%p)\n", pStubMsg, pFormat);
2457 if (pFormat[0] != RPC_FC_BOGUS_ARRAY)
2459 ERR("invalid format type %x\n", pFormat[0]);
2460 RpcRaiseException(RPC_S_INTERNAL_ERROR);
2464 alignment = pFormat[1] + 1;
2468 pFormat = ReadConformance(pStubMsg, pFormat);
2469 pFormat = ReadVariance(pStubMsg, pFormat);
2471 ALIGN_POINTER(pStubMsg->Buffer, alignment);
2473 SavedMemorySize = pStubMsg->MemorySize;
2475 Buffer = pStubMsg->Buffer;
2476 esize = ComplexStructMemorySize(pStubMsg, pFormat);
2477 pStubMsg->Buffer = Buffer;
2479 MemorySize = esize * pStubMsg->MaxCount;
2481 count = pStubMsg->ActualCount;
2482 for (i = 0; i < count; i++)
2483 ComplexStructMemorySize(pStubMsg, pFormat);
2485 pStubMsg->MemorySize = SavedMemorySize;
2487 pStubMsg->MemorySize += MemorySize;
2491 /***********************************************************************
2492 * NdrComplexArrayFree [RPCRT4.@]
2494 void WINAPI NdrComplexArrayFree(PMIDL_STUB_MESSAGE pStubMsg,
2495 unsigned char *pMemory,
2496 PFORMAT_STRING pFormat)
2498 ULONG i, count, def;
2500 TRACE("(%p,%p,%p)\n", pStubMsg, pMemory, pFormat);
2502 if (pFormat[0] != RPC_FC_BOGUS_ARRAY)
2504 ERR("invalid format type %x\n", pFormat[0]);
2505 RpcRaiseException(RPC_S_INTERNAL_ERROR);
2509 def = *(const WORD*)&pFormat[2];
2512 pFormat = ComputeConformance(pStubMsg, pMemory, pFormat, def);
2513 TRACE("conformance = %ld\n", pStubMsg->MaxCount);
2515 pFormat = ComputeVariance(pStubMsg, pMemory, pFormat, pStubMsg->MaxCount);
2516 TRACE("variance = %ld\n", pStubMsg->ActualCount);
2518 count = pStubMsg->ActualCount;
2519 for (i = 0; i < count; i++)
2520 pMemory = ComplexFree(pStubMsg, pMemory, pFormat, NULL);
2523 unsigned long UserMarshalFlags(PMIDL_STUB_MESSAGE pStubMsg)
2525 return MAKELONG(pStubMsg->dwDestContext,
2526 pStubMsg->RpcMsg->DataRepresentation);
2529 #define USER_MARSHAL_PTR_PREFIX \
2530 ( (DWORD)'U' | ( (DWORD)'s' << 8 ) | \
2531 ( (DWORD)'e' << 16 ) | ( (DWORD)'r' << 24 ) )
2533 /***********************************************************************
2534 * NdrUserMarshalMarshall [RPCRT4.@]
2536 unsigned char * WINAPI NdrUserMarshalMarshall(PMIDL_STUB_MESSAGE pStubMsg,
2537 unsigned char *pMemory,
2538 PFORMAT_STRING pFormat)
2540 unsigned flags = pFormat[1];
2541 unsigned index = *(const WORD*)&pFormat[2];
2542 unsigned long uflag = UserMarshalFlags(pStubMsg);
2543 TRACE("(%p,%p,%p)\n", pStubMsg, pMemory, pFormat);
2544 TRACE("index=%d\n", index);
2546 if (flags & USER_MARSHAL_POINTER)
2548 ALIGN_POINTER(pStubMsg->Buffer, 4);
2549 NDR_LOCAL_UINT32_WRITE(pStubMsg->Buffer, USER_MARSHAL_PTR_PREFIX);
2550 pStubMsg->Buffer += 4;
2551 ALIGN_POINTER(pStubMsg->Buffer, 8);
2554 ALIGN_POINTER(pStubMsg->Buffer, (flags & 0xf) + 1);
2557 pStubMsg->StubDesc->aUserMarshalQuadruple[index].pfnMarshall(
2558 &uflag, pStubMsg->Buffer, pMemory);
2560 STD_OVERFLOW_CHECK(pStubMsg);
2565 /***********************************************************************
2566 * NdrUserMarshalUnmarshall [RPCRT4.@]
2568 unsigned char * WINAPI NdrUserMarshalUnmarshall(PMIDL_STUB_MESSAGE pStubMsg,
2569 unsigned char **ppMemory,
2570 PFORMAT_STRING pFormat,
2571 unsigned char fMustAlloc)
2573 unsigned flags = pFormat[1];
2574 unsigned index = *(const WORD*)&pFormat[2];
2575 DWORD memsize = *(const WORD*)&pFormat[4];
2576 unsigned long uflag = UserMarshalFlags(pStubMsg);
2577 TRACE("(%p,%p,%p,%d)\n", pStubMsg, ppMemory, pFormat, fMustAlloc);
2578 TRACE("index=%d\n", index);
2580 if (flags & USER_MARSHAL_POINTER)
2582 ALIGN_POINTER(pStubMsg->Buffer, 4);
2583 /* skip pointer prefix */
2584 pStubMsg->Buffer += 4;
2585 ALIGN_POINTER(pStubMsg->Buffer, 8);
2588 ALIGN_POINTER(pStubMsg->Buffer, (flags & 0xf) + 1);
2590 if (fMustAlloc || !*ppMemory)
2591 *ppMemory = NdrAllocate(pStubMsg, memsize);
2594 pStubMsg->StubDesc->aUserMarshalQuadruple[index].pfnUnmarshall(
2595 &uflag, pStubMsg->Buffer, *ppMemory);
2600 /***********************************************************************
2601 * NdrUserMarshalBufferSize [RPCRT4.@]
2603 void WINAPI NdrUserMarshalBufferSize(PMIDL_STUB_MESSAGE pStubMsg,
2604 unsigned char *pMemory,
2605 PFORMAT_STRING pFormat)
2607 unsigned flags = pFormat[1];
2608 unsigned index = *(const WORD*)&pFormat[2];
2609 DWORD bufsize = *(const WORD*)&pFormat[6];
2610 unsigned long uflag = UserMarshalFlags(pStubMsg);
2611 TRACE("(%p,%p,%p)\n", pStubMsg, pMemory, pFormat);
2612 TRACE("index=%d\n", index);
2614 if (flags & USER_MARSHAL_POINTER)
2616 ALIGN_LENGTH(pStubMsg->BufferLength, 4);
2617 /* skip pointer prefix */
2618 pStubMsg->BufferLength += 4;
2619 ALIGN_LENGTH(pStubMsg->BufferLength, 8);
2622 ALIGN_LENGTH(pStubMsg->BufferLength, (flags & 0xf) + 1);
2625 TRACE("size=%ld\n", bufsize);
2626 pStubMsg->BufferLength += bufsize;
2630 pStubMsg->BufferLength =
2631 pStubMsg->StubDesc->aUserMarshalQuadruple[index].pfnBufferSize(
2632 &uflag, pStubMsg->BufferLength, pMemory);
2635 /***********************************************************************
2636 * NdrUserMarshalMemorySize [RPCRT4.@]
2638 unsigned long WINAPI NdrUserMarshalMemorySize(PMIDL_STUB_MESSAGE pStubMsg,
2639 PFORMAT_STRING pFormat)
2641 unsigned flags = pFormat[1];
2642 unsigned index = *(const WORD*)&pFormat[2];
2643 DWORD memsize = *(const WORD*)&pFormat[4];
2644 DWORD bufsize = *(const WORD*)&pFormat[6];
2646 TRACE("(%p,%p)\n", pStubMsg, pFormat);
2647 TRACE("index=%d\n", index);
2649 pStubMsg->MemorySize += memsize;
2651 if (flags & USER_MARSHAL_POINTER)
2653 ALIGN_POINTER(pStubMsg->Buffer, 4);
2654 /* skip pointer prefix */
2655 pStubMsg->Buffer += 4;
2656 ALIGN_POINTER(pStubMsg->Buffer, 8);
2659 ALIGN_POINTER(pStubMsg->Buffer, (flags & 0xf) + 1);
2661 pStubMsg->Buffer += bufsize;
2663 return pStubMsg->MemorySize;
2666 /***********************************************************************
2667 * NdrUserMarshalFree [RPCRT4.@]
2669 void WINAPI NdrUserMarshalFree(PMIDL_STUB_MESSAGE pStubMsg,
2670 unsigned char *pMemory,
2671 PFORMAT_STRING pFormat)
2673 /* unsigned flags = pFormat[1]; */
2674 unsigned index = *(const WORD*)&pFormat[2];
2675 unsigned long uflag = UserMarshalFlags(pStubMsg);
2676 TRACE("(%p,%p,%p)\n", pStubMsg, pMemory, pFormat);
2677 TRACE("index=%d\n", index);
2679 pStubMsg->StubDesc->aUserMarshalQuadruple[index].pfnFree(
2683 /***********************************************************************
2684 * NdrClearOutParameters [RPCRT4.@]
2686 void WINAPI NdrClearOutParameters(PMIDL_STUB_MESSAGE pStubMsg,
2687 PFORMAT_STRING pFormat,
2690 FIXME("(%p,%p,%p): stub\n", pStubMsg, pFormat, ArgAddr);
2693 /***********************************************************************
2694 * NdrConvert [RPCRT4.@]
2696 void WINAPI NdrConvert( PMIDL_STUB_MESSAGE pStubMsg, PFORMAT_STRING pFormat )
2698 FIXME("(pStubMsg == ^%p, pFormat == ^%p): stub.\n", pStubMsg, pFormat);
2699 /* FIXME: since this stub doesn't do any converting, the proper behavior
2700 is to raise an exception */
2703 /***********************************************************************
2704 * NdrConvert2 [RPCRT4.@]
2706 void WINAPI NdrConvert2( PMIDL_STUB_MESSAGE pStubMsg, PFORMAT_STRING pFormat, long NumberParams )
2708 FIXME("(pStubMsg == ^%p, pFormat == ^%p, NumberParams == %ld): stub.\n",
2709 pStubMsg, pFormat, NumberParams);
2710 /* FIXME: since this stub doesn't do any converting, the proper behavior
2711 is to raise an exception */
2714 typedef struct _NDR_CSTRUCT_FORMAT
2717 unsigned char alignment;
2718 unsigned short memory_size;
2719 short offset_to_array_description;
2720 } NDR_CSTRUCT_FORMAT, NDR_CVSTRUCT_FORMAT;
2722 /***********************************************************************
2723 * NdrConformantStructMarshall [RPCRT4.@]
2725 unsigned char * WINAPI NdrConformantStructMarshall(PMIDL_STUB_MESSAGE pStubMsg,
2726 unsigned char *pMemory,
2727 PFORMAT_STRING pFormat)
2729 const NDR_CSTRUCT_FORMAT * pCStructFormat = (NDR_CSTRUCT_FORMAT*)pFormat;
2730 PFORMAT_STRING pCArrayFormat;
2733 TRACE("(%p, %p, %p)\n", pStubMsg, pMemory, pFormat);
2735 pFormat += sizeof(NDR_CSTRUCT_FORMAT);
2736 if ((pCStructFormat->type != RPC_FC_CPSTRUCT) && (pCStructFormat->type != RPC_FC_CSTRUCT))
2738 ERR("invalid format type %x\n", pCStructFormat->type);
2739 RpcRaiseException(RPC_S_INTERNAL_ERROR);
2743 pCArrayFormat = (unsigned char*)&pCStructFormat->offset_to_array_description +
2744 pCStructFormat->offset_to_array_description;
2745 if (*pCArrayFormat != RPC_FC_CARRAY)
2747 ERR("invalid array format type %x\n", pCStructFormat->type);
2748 RpcRaiseException(RPC_S_INTERNAL_ERROR);
2751 esize = *(const WORD*)(pCArrayFormat+2);
2753 ComputeConformance(pStubMsg, pMemory + pCStructFormat->memory_size,
2754 pCArrayFormat + 4, 0);
2756 WriteConformance(pStubMsg);
2758 ALIGN_POINTER(pStubMsg->Buffer, pCStructFormat->alignment + 1);
2760 TRACE("memory_size = %d\n", pCStructFormat->memory_size);
2762 /* copy constant sized part of struct */
2763 pStubMsg->BufferMark = pStubMsg->Buffer;
2764 memcpy(pStubMsg->Buffer, pMemory, pCStructFormat->memory_size + pStubMsg->MaxCount * esize);
2765 pStubMsg->Buffer += pCStructFormat->memory_size + pStubMsg->MaxCount * esize;
2767 if (pCStructFormat->type == RPC_FC_CPSTRUCT)
2768 EmbeddedPointerMarshall(pStubMsg, pMemory, pFormat);
2770 STD_OVERFLOW_CHECK(pStubMsg);
2775 /***********************************************************************
2776 * NdrConformantStructUnmarshall [RPCRT4.@]
2778 unsigned char * WINAPI NdrConformantStructUnmarshall(PMIDL_STUB_MESSAGE pStubMsg,
2779 unsigned char **ppMemory,
2780 PFORMAT_STRING pFormat,
2781 unsigned char fMustAlloc)
2783 const NDR_CSTRUCT_FORMAT * pCStructFormat = (NDR_CSTRUCT_FORMAT*)pFormat;
2784 PFORMAT_STRING pCArrayFormat;
2787 TRACE("(%p, %p, %p, %d)\n", pStubMsg, ppMemory, pFormat, fMustAlloc);
2789 pFormat += sizeof(NDR_CSTRUCT_FORMAT);
2790 if ((pCStructFormat->type != RPC_FC_CPSTRUCT) && (pCStructFormat->type != RPC_FC_CSTRUCT))
2792 ERR("invalid format type %x\n", pCStructFormat->type);
2793 RpcRaiseException(RPC_S_INTERNAL_ERROR);
2796 pCArrayFormat = (unsigned char*)&pCStructFormat->offset_to_array_description +
2797 pCStructFormat->offset_to_array_description;
2798 if (*pCArrayFormat != RPC_FC_CARRAY)
2800 ERR("invalid array format type %x\n", pCStructFormat->type);
2801 RpcRaiseException(RPC_S_INTERNAL_ERROR);
2804 esize = *(const WORD*)(pCArrayFormat+2);
2806 pCArrayFormat = ReadConformance(pStubMsg, pCArrayFormat + 4);
2808 ALIGN_POINTER(pStubMsg->Buffer, pCStructFormat->alignment + 1);
2810 TRACE("memory_size = %d\n", pCStructFormat->memory_size);
2812 /* work out how much memory to allocate if we need to do so */
2813 if (!*ppMemory || fMustAlloc)
2815 SIZE_T size = pCStructFormat->memory_size + pStubMsg->MaxCount * esize;
2816 *ppMemory = NdrAllocate(pStubMsg, size);
2819 /* now copy the data */
2820 pStubMsg->BufferMark = pStubMsg->Buffer;
2821 memcpy(*ppMemory, pStubMsg->Buffer, pCStructFormat->memory_size + pStubMsg->MaxCount * esize);
2822 pStubMsg->Buffer += pCStructFormat->memory_size + pStubMsg->MaxCount * esize;
2824 if (pCStructFormat->type == RPC_FC_CPSTRUCT)
2825 EmbeddedPointerUnmarshall(pStubMsg, ppMemory, pFormat, fMustAlloc);
2830 /***********************************************************************
2831 * NdrConformantStructBufferSize [RPCRT4.@]
2833 void WINAPI NdrConformantStructBufferSize(PMIDL_STUB_MESSAGE pStubMsg,
2834 unsigned char *pMemory,
2835 PFORMAT_STRING pFormat)
2837 const NDR_CSTRUCT_FORMAT * pCStructFormat = (NDR_CSTRUCT_FORMAT*)pFormat;
2838 PFORMAT_STRING pCArrayFormat;
2841 TRACE("(%p, %p, %p)\n", pStubMsg, pMemory, pFormat);
2843 pFormat += sizeof(NDR_CSTRUCT_FORMAT);
2844 if ((pCStructFormat->type != RPC_FC_CPSTRUCT) && (pCStructFormat->type != RPC_FC_CSTRUCT))
2846 ERR("invalid format type %x\n", pCStructFormat->type);
2847 RpcRaiseException(RPC_S_INTERNAL_ERROR);
2850 pCArrayFormat = (unsigned char*)&pCStructFormat->offset_to_array_description +
2851 pCStructFormat->offset_to_array_description;
2852 if (*pCArrayFormat != RPC_FC_CARRAY)
2854 ERR("invalid array format type %x\n", pCStructFormat->type);
2855 RpcRaiseException(RPC_S_INTERNAL_ERROR);
2858 esize = *(const WORD*)(pCArrayFormat+2);
2860 pCArrayFormat = ComputeConformance(pStubMsg, pMemory + pCStructFormat->memory_size, pCArrayFormat+4, 0);
2861 SizeConformance(pStubMsg);
2863 ALIGN_LENGTH(pStubMsg->BufferLength, pCStructFormat->alignment + 1);
2865 TRACE("memory_size = %d\n", pCStructFormat->memory_size);
2867 pStubMsg->BufferLength += pCStructFormat->memory_size + esize * pStubMsg->MaxCount;
2869 if (pCStructFormat->type == RPC_FC_CPSTRUCT)
2870 EmbeddedPointerBufferSize(pStubMsg, pMemory, pFormat);
2873 /***********************************************************************
2874 * NdrConformantStructMemorySize [RPCRT4.@]
2876 unsigned long WINAPI NdrConformantStructMemorySize(PMIDL_STUB_MESSAGE pStubMsg,
2877 PFORMAT_STRING pFormat)
2883 /***********************************************************************
2884 * NdrConformantStructFree [RPCRT4.@]
2886 void WINAPI NdrConformantStructFree(PMIDL_STUB_MESSAGE pStubMsg,
2887 unsigned char *pMemory,
2888 PFORMAT_STRING pFormat)
2893 /***********************************************************************
2894 * NdrConformantVaryingStructMarshall [RPCRT4.@]
2896 unsigned char * WINAPI NdrConformantVaryingStructMarshall(PMIDL_STUB_MESSAGE pStubMsg,
2897 unsigned char *pMemory,
2898 PFORMAT_STRING pFormat)
2900 const NDR_CVSTRUCT_FORMAT * pCVStructFormat = (NDR_CVSTRUCT_FORMAT*)pFormat;
2901 PFORMAT_STRING pCVArrayFormat;
2904 TRACE("(%p, %p, %p)\n", pStubMsg, pMemory, pFormat);
2906 pFormat += sizeof(NDR_CVSTRUCT_FORMAT);
2907 if (pCVStructFormat->type != RPC_FC_CVSTRUCT)
2909 ERR("invalid format type %x\n", pCVStructFormat->type);
2910 RpcRaiseException(RPC_S_INTERNAL_ERROR);
2914 pCVArrayFormat = (unsigned char*)&pCVStructFormat->offset_to_array_description +
2915 pCVStructFormat->offset_to_array_description;
2916 switch (*pCVArrayFormat)
2918 case RPC_FC_CVARRAY:
2919 esize = *(const WORD*)(pCVArrayFormat+2);
2921 pCVArrayFormat = ComputeConformance(pStubMsg, pMemory + pCVStructFormat->memory_size,
2922 pCVArrayFormat + 4, 0);
2923 pCVArrayFormat = ComputeVariance(pStubMsg, pMemory + pCVStructFormat->memory_size,
2926 case RPC_FC_C_CSTRING:
2927 TRACE("string=%s\n", debugstr_a((char*)pMemory + pCVStructFormat->memory_size));
2928 pStubMsg->ActualCount = strlen((char*)pMemory + pCVStructFormat->memory_size)+1;
2929 esize = sizeof(char);
2930 if (pCVArrayFormat[1] == RPC_FC_STRING_SIZED)
2931 pCVArrayFormat = ComputeConformance(pStubMsg, pMemory + pCVStructFormat->memory_size,
2932 pCVArrayFormat + 2, 0);
2934 pStubMsg->MaxCount = pStubMsg->ActualCount;
2936 case RPC_FC_C_WSTRING:
2937 TRACE("string=%s\n", debugstr_w((LPWSTR)pMemory + pCVStructFormat->memory_size));
2938 pStubMsg->ActualCount = strlenW((LPWSTR)pMemory + pCVStructFormat->memory_size)+1;
2939 esize = sizeof(WCHAR);
2940 if (pCVArrayFormat[1] == RPC_FC_STRING_SIZED)
2941 pCVArrayFormat = ComputeConformance(pStubMsg, pMemory + pCVStructFormat->memory_size,
2942 pCVArrayFormat + 2, 0);
2944 pStubMsg->MaxCount = pStubMsg->ActualCount;
2947 ERR("invalid array format type %x\n", *pCVArrayFormat);
2948 RpcRaiseException(RPC_S_INTERNAL_ERROR);
2952 WriteConformance(pStubMsg);
2954 ALIGN_POINTER(pStubMsg->Buffer, pCVStructFormat->alignment + 1);
2956 TRACE("memory_size = %d\n", pCVStructFormat->memory_size);
2958 /* write constant sized part */
2959 pStubMsg->BufferMark = pStubMsg->Buffer;
2960 memcpy(pStubMsg->Buffer, pMemory, pCVStructFormat->memory_size);
2961 pStubMsg->Buffer += pCVStructFormat->memory_size;
2963 WriteVariance(pStubMsg);
2965 /* write array part */
2966 memcpy(pStubMsg->Buffer, pMemory + pCVStructFormat->memory_size, pStubMsg->ActualCount * esize);
2967 pStubMsg->Buffer += pStubMsg->ActualCount * esize;
2969 EmbeddedPointerMarshall(pStubMsg, pMemory, pFormat);
2971 STD_OVERFLOW_CHECK(pStubMsg);
2976 /***********************************************************************
2977 * NdrConformantVaryingStructUnmarshall [RPCRT4.@]
2979 unsigned char * WINAPI NdrConformantVaryingStructUnmarshall(PMIDL_STUB_MESSAGE pStubMsg,
2980 unsigned char **ppMemory,
2981 PFORMAT_STRING pFormat,
2982 unsigned char fMustAlloc)
2984 const NDR_CVSTRUCT_FORMAT * pCVStructFormat = (NDR_CVSTRUCT_FORMAT*)pFormat;
2985 PFORMAT_STRING pCVArrayFormat;
2987 unsigned char cvarray_type;
2989 TRACE("(%p, %p, %p, %d)\n", pStubMsg, ppMemory, pFormat, fMustAlloc);
2991 pFormat += sizeof(NDR_CVSTRUCT_FORMAT);
2992 if (pCVStructFormat->type != RPC_FC_CVSTRUCT)
2994 ERR("invalid format type %x\n", pCVStructFormat->type);
2995 RpcRaiseException(RPC_S_INTERNAL_ERROR);
2999 pCVArrayFormat = (unsigned char*)&pCVStructFormat->offset_to_array_description +
3000 pCVStructFormat->offset_to_array_description;
3001 cvarray_type = *pCVArrayFormat;
3002 switch (cvarray_type)
3004 case RPC_FC_CVARRAY:
3005 esize = *(const WORD*)(pCVArrayFormat+2);
3006 pCVArrayFormat = ReadConformance(pStubMsg, pCVArrayFormat + 4);
3008 case RPC_FC_C_CSTRING:
3009 esize = sizeof(char);
3010 if (pCVArrayFormat[1] == RPC_FC_STRING_SIZED)
3011 pCVArrayFormat = ReadConformance(pStubMsg, pCVArrayFormat + 2);
3013 pCVArrayFormat = ReadConformance(pStubMsg, NULL);
3015 case RPC_FC_C_WSTRING:
3016 esize = sizeof(WCHAR);
3017 if (pCVArrayFormat[1] == RPC_FC_STRING_SIZED)
3018 pCVArrayFormat = ReadConformance(pStubMsg, pCVArrayFormat + 2);
3020 pCVArrayFormat = ReadConformance(pStubMsg, NULL);
3023 ERR("invalid array format type %x\n", *pCVArrayFormat);
3024 RpcRaiseException(RPC_S_INTERNAL_ERROR);
3028 ALIGN_POINTER(pStubMsg->Buffer, pCVStructFormat->alignment + 1);
3030 TRACE("memory_size = %d\n", pCVStructFormat->memory_size);
3032 /* work out how much memory to allocate if we need to do so */
3033 if (!*ppMemory || fMustAlloc)
3035 SIZE_T size = pCVStructFormat->memory_size + pStubMsg->MaxCount * esize;
3036 *ppMemory = NdrAllocate(pStubMsg, size);
3039 /* copy the constant data */
3040 pStubMsg->BufferMark = pStubMsg->Buffer;
3041 memcpy(*ppMemory, pStubMsg->Buffer, pCVStructFormat->memory_size);
3042 pStubMsg->Buffer += pCVStructFormat->memory_size;
3044 pCVArrayFormat = ReadVariance(pStubMsg, pCVArrayFormat);
3046 /* copy the array data */
3047 memcpy(*ppMemory + pCVStructFormat->memory_size, pStubMsg->Buffer,
3048 pStubMsg->ActualCount * esize);
3049 pStubMsg->Buffer += pStubMsg->ActualCount * esize;
3051 if (cvarray_type == RPC_FC_C_CSTRING)
3052 TRACE("string=%s\n", debugstr_a((char *)(*ppMemory + pCVStructFormat->memory_size)));
3053 else if (cvarray_type == RPC_FC_C_WSTRING)
3054 TRACE("string=%s\n", debugstr_w((WCHAR *)(*ppMemory + pCVStructFormat->memory_size)));
3056 EmbeddedPointerUnmarshall(pStubMsg, ppMemory, pFormat, fMustAlloc);
3061 /***********************************************************************
3062 * NdrConformantVaryingStructBufferSize [RPCRT4.@]
3064 void WINAPI NdrConformantVaryingStructBufferSize(PMIDL_STUB_MESSAGE pStubMsg,
3065 unsigned char *pMemory,
3066 PFORMAT_STRING pFormat)
3068 const NDR_CVSTRUCT_FORMAT * pCVStructFormat = (NDR_CVSTRUCT_FORMAT*)pFormat;
3069 PFORMAT_STRING pCVArrayFormat;
3072 TRACE("(%p, %p, %p)\n", pStubMsg, pMemory, pFormat);
3074 pFormat += sizeof(NDR_CVSTRUCT_FORMAT);
3075 if (pCVStructFormat->type != RPC_FC_CVSTRUCT)
3077 ERR("invalid format type %x\n", pCVStructFormat->type);
3078 RpcRaiseException(RPC_S_INTERNAL_ERROR);
3082 pCVArrayFormat = (unsigned char*)&pCVStructFormat->offset_to_array_description +
3083 pCVStructFormat->offset_to_array_description;
3084 switch (*pCVArrayFormat)
3086 case RPC_FC_CVARRAY:
3087 esize = *(const WORD*)(pCVArrayFormat+2);
3089 pCVArrayFormat = ComputeConformance(pStubMsg, pMemory + pCVStructFormat->memory_size,
3090 pCVArrayFormat + 4, 0);
3091 pCVArrayFormat = ComputeVariance(pStubMsg, pMemory + pCVStructFormat->memory_size,
3092 pCVArrayFormat + 4, 0);
3094 case RPC_FC_C_CSTRING:
3095 TRACE("string=%s\n", debugstr_a((char*)pMemory + pCVStructFormat->memory_size));
3096 pStubMsg->ActualCount = strlen((char*)pMemory + pCVStructFormat->memory_size)+1;
3097 esize = sizeof(char);
3098 if (pCVArrayFormat[1] == RPC_FC_STRING_SIZED)
3099 pCVArrayFormat = ComputeConformance(pStubMsg, pMemory + pCVStructFormat->memory_size,
3100 pCVArrayFormat + 2, 0);
3102 pStubMsg->MaxCount = pStubMsg->ActualCount;
3104 case RPC_FC_C_WSTRING:
3105 TRACE("string=%s\n", debugstr_w((LPWSTR)pMemory + pCVStructFormat->memory_size));
3106 pStubMsg->ActualCount = strlenW((LPWSTR)pMemory + pCVStructFormat->memory_size)+1;
3107 esize = sizeof(WCHAR);
3108 if (pCVArrayFormat[1] == RPC_FC_STRING_SIZED)
3109 pCVArrayFormat = ComputeConformance(pStubMsg, pMemory + pCVStructFormat->memory_size,
3110 pCVArrayFormat + 2, 0);
3112 pStubMsg->MaxCount = pStubMsg->ActualCount;
3115 ERR("invalid array format type %x\n", *pCVArrayFormat);
3116 RpcRaiseException(RPC_S_INTERNAL_ERROR);
3120 SizeConformance(pStubMsg);
3122 ALIGN_LENGTH(pStubMsg->BufferLength, pCVStructFormat->alignment + 1);
3124 TRACE("memory_size = %d\n", pCVStructFormat->memory_size);
3126 pStubMsg->BufferLength += pCVStructFormat->memory_size;
3127 SizeVariance(pStubMsg);
3128 pStubMsg->BufferLength += esize * pStubMsg->MaxCount;
3130 EmbeddedPointerBufferSize(pStubMsg, pMemory, pFormat);
3133 /***********************************************************************
3134 * NdrConformantVaryingStructMemorySize [RPCRT4.@]
3136 unsigned long WINAPI NdrConformantVaryingStructMemorySize(PMIDL_STUB_MESSAGE pStubMsg,
3137 PFORMAT_STRING pFormat)
3139 const NDR_CVSTRUCT_FORMAT * pCVStructFormat = (NDR_CVSTRUCT_FORMAT*)pFormat;
3140 PFORMAT_STRING pCVArrayFormat;
3142 unsigned char cvarray_type;
3144 TRACE("(%p, %p)\n", pStubMsg, pFormat);
3146 pFormat += sizeof(NDR_CVSTRUCT_FORMAT);
3147 if (pCVStructFormat->type != RPC_FC_CVSTRUCT)
3149 ERR("invalid format type %x\n", pCVStructFormat->type);
3150 RpcRaiseException(RPC_S_INTERNAL_ERROR);
3154 pCVArrayFormat = (unsigned char*)&pCVStructFormat->offset_to_array_description +
3155 pCVStructFormat->offset_to_array_description;
3156 cvarray_type = *pCVArrayFormat;
3157 switch (cvarray_type)
3159 case RPC_FC_CVARRAY:
3160 esize = *(const WORD*)(pCVArrayFormat+2);
3161 pCVArrayFormat = ReadConformance(pStubMsg, pCVArrayFormat + 4);
3163 case RPC_FC_C_CSTRING:
3164 esize = sizeof(char);
3165 if (pCVArrayFormat[1] == RPC_FC_STRING_SIZED)
3166 pCVArrayFormat = ReadConformance(pStubMsg, pCVArrayFormat + 2);
3168 pCVArrayFormat = ReadConformance(pStubMsg, NULL);
3170 case RPC_FC_C_WSTRING:
3171 esize = sizeof(WCHAR);
3172 if (pCVArrayFormat[1] == RPC_FC_STRING_SIZED)
3173 pCVArrayFormat = ReadConformance(pStubMsg, pCVArrayFormat + 2);
3175 pCVArrayFormat = ReadConformance(pStubMsg, NULL);
3178 ERR("invalid array format type %x\n", *pCVArrayFormat);
3179 RpcRaiseException(RPC_S_INTERNAL_ERROR);
3183 ALIGN_POINTER(pStubMsg->Buffer, pCVStructFormat->alignment + 1);
3185 TRACE("memory_size = %d\n", pCVStructFormat->memory_size);
3187 pStubMsg->Buffer += pCVStructFormat->memory_size;
3188 pCVArrayFormat = ReadVariance(pStubMsg, pCVArrayFormat);
3189 pStubMsg->Buffer += pCVStructFormat->memory_size + pStubMsg->ActualCount * esize;
3191 pStubMsg->MemorySize += pCVStructFormat->memory_size + pStubMsg->MaxCount * esize;
3193 EmbeddedPointerMemorySize(pStubMsg, pFormat);
3195 return pCVStructFormat->memory_size + pStubMsg->MaxCount * esize;
3198 /***********************************************************************
3199 * NdrConformantVaryingStructFree [RPCRT4.@]
3201 void WINAPI NdrConformantVaryingStructFree(PMIDL_STUB_MESSAGE pStubMsg,
3202 unsigned char *pMemory,
3203 PFORMAT_STRING pFormat)
3205 const NDR_CVSTRUCT_FORMAT * pCVStructFormat = (NDR_CVSTRUCT_FORMAT*)pFormat;
3206 PFORMAT_STRING pCVArrayFormat;
3209 TRACE("(%p, %p, %p)\n", pStubMsg, pMemory, pFormat);
3211 pFormat += sizeof(NDR_CVSTRUCT_FORMAT);
3212 if (pCVStructFormat->type != RPC_FC_CVSTRUCT)
3214 ERR("invalid format type %x\n", pCVStructFormat->type);
3215 RpcRaiseException(RPC_S_INTERNAL_ERROR);
3219 pCVArrayFormat = (unsigned char*)&pCVStructFormat->offset_to_array_description +
3220 pCVStructFormat->offset_to_array_description;
3221 switch (*pCVArrayFormat)
3223 case RPC_FC_CVARRAY:
3224 esize = *(const WORD*)(pCVArrayFormat+2);
3226 pCVArrayFormat = ComputeConformance(pStubMsg, pMemory + pCVStructFormat->memory_size,
3227 pCVArrayFormat + 4, 0);
3228 pCVArrayFormat = ComputeVariance(pStubMsg, pMemory + pCVStructFormat->memory_size,
3231 case RPC_FC_C_CSTRING:
3232 TRACE("string=%s\n", debugstr_a((char*)pMemory + pCVStructFormat->memory_size));
3233 pStubMsg->ActualCount = strlen((char*)pMemory + pCVStructFormat->memory_size)+1;
3234 esize = sizeof(char);
3235 if (pCVArrayFormat[1] == RPC_FC_STRING_SIZED)
3236 pCVArrayFormat = ComputeConformance(pStubMsg, pMemory + pCVStructFormat->memory_size,
3237 pCVArrayFormat + 2, 0);
3239 pStubMsg->MaxCount = pStubMsg->ActualCount;
3241 case RPC_FC_C_WSTRING:
3242 TRACE("string=%s\n", debugstr_w((LPWSTR)pMemory + pCVStructFormat->memory_size));
3243 pStubMsg->ActualCount = strlenW((LPWSTR)pMemory + pCVStructFormat->memory_size)+1;
3244 esize = sizeof(WCHAR);
3245 if (pCVArrayFormat[1] == RPC_FC_STRING_SIZED)
3246 pCVArrayFormat = ComputeConformance(pStubMsg, pMemory + pCVStructFormat->memory_size,
3247 pCVArrayFormat + 2, 0);
3249 pStubMsg->MaxCount = pStubMsg->ActualCount;
3252 ERR("invalid array format type %x\n", *pCVArrayFormat);
3253 RpcRaiseException(RPC_S_INTERNAL_ERROR);
3257 TRACE("memory_size = %d\n", pCVStructFormat->memory_size);
3259 EmbeddedPointerFree(pStubMsg, pMemory, pFormat);
3265 unsigned char alignment;
3266 unsigned short total_size;
3267 } NDR_SMFARRAY_FORMAT;
3272 unsigned char alignment;
3273 unsigned long total_size;
3274 } NDR_LGFARRAY_FORMAT;
3276 /***********************************************************************
3277 * NdrFixedArrayMarshall [RPCRT4.@]
3279 unsigned char * WINAPI NdrFixedArrayMarshall(PMIDL_STUB_MESSAGE pStubMsg,
3280 unsigned char *pMemory,
3281 PFORMAT_STRING pFormat)
3283 const NDR_SMFARRAY_FORMAT *pSmFArrayFormat = (const NDR_SMFARRAY_FORMAT *)pFormat;
3284 unsigned long total_size;
3286 TRACE("(%p, %p, %p)\n", pStubMsg, pMemory, pFormat);
3288 if ((pSmFArrayFormat->type != RPC_FC_SMFARRAY) &&
3289 (pSmFArrayFormat->type != RPC_FC_LGFARRAY))
3291 ERR("invalid format type %x\n", pSmFArrayFormat->type);
3292 RpcRaiseException(RPC_S_INTERNAL_ERROR);
3296 ALIGN_POINTER(pStubMsg->Buffer, pSmFArrayFormat->alignment + 1);
3298 if (pSmFArrayFormat->type == RPC_FC_SMFARRAY)
3300 total_size = pSmFArrayFormat->total_size;
3301 pFormat = (unsigned char *)(pSmFArrayFormat + 1);
3305 const NDR_LGFARRAY_FORMAT *pLgFArrayFormat = (const NDR_LGFARRAY_FORMAT *)pFormat;
3306 total_size = pLgFArrayFormat->total_size;
3307 pFormat = (unsigned char *)(pLgFArrayFormat + 1);
3309 memcpy(pStubMsg->Buffer, pMemory, total_size);
3310 pStubMsg->Buffer += total_size;
3312 pFormat = EmbeddedPointerMarshall(pStubMsg, pMemory, pFormat);
3317 /***********************************************************************
3318 * NdrFixedArrayUnmarshall [RPCRT4.@]
3320 unsigned char * WINAPI NdrFixedArrayUnmarshall(PMIDL_STUB_MESSAGE pStubMsg,
3321 unsigned char **ppMemory,
3322 PFORMAT_STRING pFormat,
3323 unsigned char fMustAlloc)
3325 const NDR_SMFARRAY_FORMAT *pSmFArrayFormat = (const NDR_SMFARRAY_FORMAT *)pFormat;
3326 unsigned long total_size;
3328 TRACE("(%p, %p, %p, %d)\n", pStubMsg, ppMemory, pFormat, fMustAlloc);
3330 if ((pSmFArrayFormat->type != RPC_FC_SMFARRAY) &&
3331 (pSmFArrayFormat->type != RPC_FC_LGFARRAY))
3333 ERR("invalid format type %x\n", pSmFArrayFormat->type);
3334 RpcRaiseException(RPC_S_INTERNAL_ERROR);
3338 ALIGN_POINTER(pStubMsg->Buffer, pSmFArrayFormat->alignment + 1);
3340 if (pSmFArrayFormat->type == RPC_FC_SMFARRAY)
3342 total_size = pSmFArrayFormat->total_size;
3343 pFormat = (unsigned char *)(pSmFArrayFormat + 1);
3347 const NDR_LGFARRAY_FORMAT *pLgFArrayFormat = (const NDR_LGFARRAY_FORMAT *)pFormat;
3348 total_size = pLgFArrayFormat->total_size;
3349 pFormat = (unsigned char *)(pLgFArrayFormat + 1);
3352 if (fMustAlloc || !*ppMemory)
3353 *ppMemory = NdrAllocate(pStubMsg, total_size);
3354 memcpy(*ppMemory, pStubMsg->Buffer, total_size);
3355 pStubMsg->Buffer += total_size;
3357 pFormat = EmbeddedPointerUnmarshall(pStubMsg, ppMemory, pFormat, fMustAlloc);
3362 /***********************************************************************
3363 * NdrFixedArrayBufferSize [RPCRT4.@]
3365 void WINAPI NdrFixedArrayBufferSize(PMIDL_STUB_MESSAGE pStubMsg,
3366 unsigned char *pMemory,
3367 PFORMAT_STRING pFormat)
3369 const NDR_SMFARRAY_FORMAT *pSmFArrayFormat = (const NDR_SMFARRAY_FORMAT *)pFormat;
3370 unsigned long total_size;
3372 TRACE("(%p, %p, %p)\n", pStubMsg, pMemory, pFormat);
3374 if ((pSmFArrayFormat->type != RPC_FC_SMFARRAY) &&
3375 (pSmFArrayFormat->type != RPC_FC_LGFARRAY))
3377 ERR("invalid format type %x\n", pSmFArrayFormat->type);
3378 RpcRaiseException(RPC_S_INTERNAL_ERROR);
3382 ALIGN_LENGTH(pStubMsg->BufferLength, pSmFArrayFormat->alignment + 1);
3384 if (pSmFArrayFormat->type == RPC_FC_SMFARRAY)
3386 total_size = pSmFArrayFormat->total_size;
3387 pFormat = (unsigned char *)(pSmFArrayFormat + 1);
3391 const NDR_LGFARRAY_FORMAT *pLgFArrayFormat = (const NDR_LGFARRAY_FORMAT *)pFormat;
3392 total_size = pLgFArrayFormat->total_size;
3393 pFormat = (unsigned char *)(pLgFArrayFormat + 1);
3395 pStubMsg->BufferLength += total_size;
3397 EmbeddedPointerBufferSize(pStubMsg, pMemory, pFormat);
3400 /***********************************************************************
3401 * NdrFixedArrayMemorySize [RPCRT4.@]
3403 unsigned long WINAPI NdrFixedArrayMemorySize(PMIDL_STUB_MESSAGE pStubMsg,
3404 PFORMAT_STRING pFormat)
3406 const NDR_SMFARRAY_FORMAT *pSmFArrayFormat = (const NDR_SMFARRAY_FORMAT *)pFormat;
3407 unsigned long total_size;
3409 TRACE("(%p, %p)\n", pStubMsg, pFormat);
3411 if ((pSmFArrayFormat->type != RPC_FC_SMFARRAY) &&
3412 (pSmFArrayFormat->type != RPC_FC_LGFARRAY))
3414 ERR("invalid format type %x\n", pSmFArrayFormat->type);
3415 RpcRaiseException(RPC_S_INTERNAL_ERROR);
3419 ALIGN_POINTER(pStubMsg->Buffer, pSmFArrayFormat->alignment + 1);
3421 if (pSmFArrayFormat->type == RPC_FC_SMFARRAY)
3423 total_size = pSmFArrayFormat->total_size;
3424 pFormat = (unsigned char *)(pSmFArrayFormat + 1);
3428 const NDR_LGFARRAY_FORMAT *pLgFArrayFormat = (const NDR_LGFARRAY_FORMAT *)pFormat;
3429 total_size = pLgFArrayFormat->total_size;
3430 pFormat = (unsigned char *)(pLgFArrayFormat + 1);
3432 pStubMsg->Buffer += total_size;
3433 pStubMsg->MemorySize += total_size;
3435 EmbeddedPointerMemorySize(pStubMsg, pFormat);
3440 /***********************************************************************
3441 * NdrFixedArrayFree [RPCRT4.@]
3443 void WINAPI NdrFixedArrayFree(PMIDL_STUB_MESSAGE pStubMsg,
3444 unsigned char *pMemory,
3445 PFORMAT_STRING pFormat)
3447 const NDR_SMFARRAY_FORMAT *pSmFArrayFormat = (const NDR_SMFARRAY_FORMAT *)pFormat;
3449 TRACE("(%p, %p, %p)\n", pStubMsg, pMemory, pFormat);
3451 if ((pSmFArrayFormat->type != RPC_FC_SMFARRAY) &&
3452 (pSmFArrayFormat->type != RPC_FC_LGFARRAY))
3454 ERR("invalid format type %x\n", pSmFArrayFormat->type);
3455 RpcRaiseException(RPC_S_INTERNAL_ERROR);
3459 if (pSmFArrayFormat->type == RPC_FC_SMFARRAY)
3460 pFormat = (unsigned char *)(pSmFArrayFormat + 1);
3463 const NDR_LGFARRAY_FORMAT *pLgFArrayFormat = (const NDR_LGFARRAY_FORMAT *)pFormat;
3464 pFormat = (unsigned char *)(pLgFArrayFormat + 1);
3467 EmbeddedPointerFree(pStubMsg, pMemory, pFormat);
3470 /***********************************************************************
3471 * NdrVaryingArrayMarshall [RPCRT4.@]
3473 unsigned char * WINAPI NdrVaryingArrayMarshall(PMIDL_STUB_MESSAGE pStubMsg,
3474 unsigned char *pMemory,
3475 PFORMAT_STRING pFormat)
3481 /***********************************************************************
3482 * NdrVaryingArrayUnmarshall [RPCRT4.@]
3484 unsigned char * WINAPI NdrVaryingArrayUnmarshall(PMIDL_STUB_MESSAGE pStubMsg,
3485 unsigned char **ppMemory,
3486 PFORMAT_STRING pFormat,
3487 unsigned char fMustAlloc)
3493 /***********************************************************************
3494 * NdrVaryingArrayBufferSize [RPCRT4.@]
3496 void WINAPI NdrVaryingArrayBufferSize(PMIDL_STUB_MESSAGE pStubMsg,
3497 unsigned char *pMemory,
3498 PFORMAT_STRING pFormat)
3503 /***********************************************************************
3504 * NdrVaryingArrayMemorySize [RPCRT4.@]
3506 unsigned long WINAPI NdrVaryingArrayMemorySize(PMIDL_STUB_MESSAGE pStubMsg,
3507 PFORMAT_STRING pFormat)
3513 /***********************************************************************
3514 * NdrVaryingArrayFree [RPCRT4.@]
3516 void WINAPI NdrVaryingArrayFree(PMIDL_STUB_MESSAGE pStubMsg,
3517 unsigned char *pMemory,
3518 PFORMAT_STRING pFormat)
3523 /***********************************************************************
3524 * NdrEncapsulatedUnionMarshall [RPCRT4.@]
3526 unsigned char * WINAPI NdrEncapsulatedUnionMarshall(PMIDL_STUB_MESSAGE pStubMsg,
3527 unsigned char *pMemory,
3528 PFORMAT_STRING pFormat)
3534 /***********************************************************************
3535 * NdrEncapsulatedUnionUnmarshall [RPCRT4.@]
3537 unsigned char * WINAPI NdrEncapsulatedUnionUnmarshall(PMIDL_STUB_MESSAGE pStubMsg,
3538 unsigned char **ppMemory,
3539 PFORMAT_STRING pFormat,
3540 unsigned char fMustAlloc)
3546 /***********************************************************************
3547 * NdrEncapsulatedUnionBufferSize [RPCRT4.@]
3549 void WINAPI NdrEncapsulatedUnionBufferSize(PMIDL_STUB_MESSAGE pStubMsg,
3550 unsigned char *pMemory,
3551 PFORMAT_STRING pFormat)
3556 /***********************************************************************
3557 * NdrEncapsulatedUnionMemorySize [RPCRT4.@]
3559 unsigned long WINAPI NdrEncapsulatedUnionMemorySize(PMIDL_STUB_MESSAGE pStubMsg,
3560 PFORMAT_STRING pFormat)
3566 /***********************************************************************
3567 * NdrEncapsulatedUnionFree [RPCRT4.@]
3569 void WINAPI NdrEncapsulatedUnionFree(PMIDL_STUB_MESSAGE pStubMsg,
3570 unsigned char *pMemory,
3571 PFORMAT_STRING pFormat)
3576 static PFORMAT_STRING get_arm_offset_from_union_arm_selector(PMIDL_STUB_MESSAGE pStubMsg,
3577 unsigned long discriminant,
3578 PFORMAT_STRING pFormat)
3580 unsigned short num_arms, arm, type;
3582 num_arms = *(const SHORT*)pFormat & 0x0fff;
3584 for(arm = 0; arm < num_arms; arm++)
3586 if(discriminant == *(const ULONG*)pFormat)
3594 type = *(const unsigned short*)pFormat;
3595 TRACE("type %04x\n", type);
3596 if(arm == num_arms) /* default arm extras */
3600 ERR("no arm for 0x%lx and no default case\n", discriminant);
3601 RpcRaiseException(RPC_S_INVALID_TAG);
3606 TRACE("falling back to empty default case for 0x%lx\n", discriminant);
3613 static PFORMAT_STRING get_non_encapsulated_union_arm(PMIDL_STUB_MESSAGE pStubMsg,
3615 PFORMAT_STRING pFormat)
3617 pFormat += *(const SHORT*)pFormat;
3620 return get_arm_offset_from_union_arm_selector(pStubMsg, value, pFormat);
3623 /***********************************************************************
3624 * NdrNonEncapsulatedUnionMarshall [RPCRT4.@]
3626 unsigned char * WINAPI NdrNonEncapsulatedUnionMarshall(PMIDL_STUB_MESSAGE pStubMsg,
3627 unsigned char *pMemory,
3628 PFORMAT_STRING pFormat)
3630 unsigned short type;
3631 unsigned char switch_type;
3633 TRACE("(%p, %p, %p)\n", pStubMsg, pMemory, pFormat);
3636 switch_type = *pFormat;
3639 pFormat = ComputeConformance(pStubMsg, pMemory, pFormat, 0);
3640 TRACE("got switch value 0x%lx\n", pStubMsg->MaxCount);
3641 /* Marshall discriminant */
3642 NdrBaseTypeMarshall(pStubMsg, (unsigned char *)&pStubMsg->MaxCount, &switch_type);
3644 pFormat = get_non_encapsulated_union_arm(pStubMsg, pStubMsg->MaxCount, pFormat);
3648 type = *(const unsigned short*)pFormat;
3649 if((type & 0xff00) == 0x8000)
3651 unsigned char basetype = LOBYTE(type);
3652 return NdrBaseTypeMarshall(pStubMsg, pMemory, &basetype);
3656 PFORMAT_STRING desc = pFormat + *(const SHORT*)pFormat;
3657 NDR_MARSHALL m = NdrMarshaller[*desc & NDR_TABLE_MASK];
3660 unsigned char *saved_buffer = NULL;
3667 saved_buffer = pStubMsg->Buffer;
3668 pStubMsg->Buffer += 4; /* for pointer ID */
3669 PointerMarshall(pStubMsg, saved_buffer, *(unsigned char **)pMemory, desc);
3672 m(pStubMsg, pMemory, desc);
3675 else FIXME("no marshaller for embedded type %02x\n", *desc);
3680 static long unmarshall_discriminant(PMIDL_STUB_MESSAGE pStubMsg,
3681 PFORMAT_STRING *ppFormat)
3683 long discriminant = 0;
3691 discriminant = *(UCHAR *)pStubMsg->Buffer;
3692 pStubMsg->Buffer += sizeof(UCHAR);
3697 ALIGN_POINTER(pStubMsg->Buffer, sizeof(USHORT));
3698 discriminant = *(USHORT *)pStubMsg->Buffer;
3699 pStubMsg->Buffer += sizeof(USHORT);
3703 ALIGN_POINTER(pStubMsg->Buffer, sizeof(ULONG));
3704 discriminant = *(ULONG *)pStubMsg->Buffer;
3705 pStubMsg->Buffer += sizeof(ULONG);
3708 FIXME("Unhandled base type: 0x%02x\n", **ppFormat);
3712 if (pStubMsg->fHasNewCorrDesc)
3716 return discriminant;
3719 /**********************************************************************
3720 * NdrNonEncapsulatedUnionUnmarshall[RPCRT4.@]
3722 unsigned char * WINAPI NdrNonEncapsulatedUnionUnmarshall(PMIDL_STUB_MESSAGE pStubMsg,
3723 unsigned char **ppMemory,
3724 PFORMAT_STRING pFormat,
3725 unsigned char fMustAlloc)
3728 unsigned short type, size;
3730 TRACE("(%p, %p, %p, %d)\n", pStubMsg, ppMemory, pFormat, fMustAlloc);
3733 /* Unmarshall discriminant */
3734 discriminant = unmarshall_discriminant(pStubMsg, &pFormat);
3735 TRACE("unmarshalled discriminant %lx\n", discriminant);
3737 pFormat += *(const SHORT*)pFormat;
3739 size = *(const unsigned short*)pFormat;
3742 pFormat = get_arm_offset_from_union_arm_selector(pStubMsg, discriminant, pFormat);
3746 if(!*ppMemory || fMustAlloc)
3747 *ppMemory = NdrAllocate(pStubMsg, size);
3749 type = *(const unsigned short*)pFormat;
3750 if((type & 0xff00) == 0x8000)
3752 unsigned char basetype = LOBYTE(type);
3753 return NdrBaseTypeUnmarshall(pStubMsg, ppMemory, &basetype, fMustAlloc);
3757 PFORMAT_STRING desc = pFormat + *(const SHORT*)pFormat;
3758 NDR_UNMARSHALL m = NdrUnmarshaller[*desc & NDR_TABLE_MASK];
3761 unsigned char *saved_buffer = NULL;
3768 ALIGN_POINTER(pStubMsg->Buffer, 4);
3769 saved_buffer = pStubMsg->Buffer;
3770 pStubMsg->Buffer += 4; /* for pointer ID */
3771 PointerUnmarshall(pStubMsg, saved_buffer, *(unsigned char ***)ppMemory, desc, TRUE);
3774 m(pStubMsg, ppMemory, desc, fMustAlloc);
3777 else FIXME("no marshaller for embedded type %02x\n", *desc);
3782 /***********************************************************************
3783 * NdrNonEncapsulatedUnionBufferSize [RPCRT4.@]
3785 void WINAPI NdrNonEncapsulatedUnionBufferSize(PMIDL_STUB_MESSAGE pStubMsg,
3786 unsigned char *pMemory,
3787 PFORMAT_STRING pFormat)
3789 unsigned short type;
3790 unsigned char switch_type;
3792 TRACE("(%p, %p, %p)\n", pStubMsg, pMemory, pFormat);
3795 switch_type = *pFormat;
3798 pFormat = ComputeConformance(pStubMsg, pMemory, pFormat, 0);
3799 TRACE("got switch value 0x%lx\n", pStubMsg->MaxCount);
3800 /* Add discriminant size */
3801 NdrBaseTypeBufferSize(pStubMsg, (unsigned char *)&pStubMsg->MaxCount, &switch_type);
3803 pFormat = get_non_encapsulated_union_arm(pStubMsg, pStubMsg->MaxCount, pFormat);
3807 type = *(const unsigned short*)pFormat;
3808 if((type & 0xff00) == 0x8000)
3810 unsigned char basetype = LOBYTE(type);
3811 NdrBaseTypeBufferSize(pStubMsg, pMemory, &basetype);
3815 PFORMAT_STRING desc = pFormat + *(const SHORT*)pFormat;
3816 NDR_BUFFERSIZE m = NdrBufferSizer[*desc & NDR_TABLE_MASK];
3825 ALIGN_LENGTH(pStubMsg->BufferLength, 4);
3826 pStubMsg->BufferLength += 4; /* for pointer ID */
3827 PointerBufferSize(pStubMsg, *(unsigned char **)pMemory, desc);
3830 m(pStubMsg, pMemory, desc);
3833 else FIXME("no buffersizer for embedded type %02x\n", *desc);
3838 /***********************************************************************
3839 * NdrNonEncapsulatedUnionMemorySize [RPCRT4.@]
3841 unsigned long WINAPI NdrNonEncapsulatedUnionMemorySize(PMIDL_STUB_MESSAGE pStubMsg,
3842 PFORMAT_STRING pFormat)
3844 unsigned long discriminant;
3845 unsigned short type, size;
3848 /* Unmarshall discriminant */
3849 discriminant = unmarshall_discriminant(pStubMsg, &pFormat);
3850 TRACE("unmarshalled discriminant 0x%lx\n", discriminant);
3852 pFormat += *(const SHORT*)pFormat;
3854 size = *(const unsigned short*)pFormat;
3857 pFormat = get_arm_offset_from_union_arm_selector(pStubMsg, discriminant, pFormat);
3861 pStubMsg->Memory += size;
3863 type = *(const unsigned short*)pFormat;
3864 if((type & 0xff00) == 0x8000)
3866 return NdrBaseTypeMemorySize(pStubMsg, pFormat);
3870 PFORMAT_STRING desc = pFormat + *(const SHORT*)pFormat;
3871 NDR_MEMORYSIZE m = NdrMemorySizer[*desc & NDR_TABLE_MASK];
3872 unsigned char *saved_buffer;
3881 ALIGN_POINTER(pStubMsg->Buffer, 4);
3882 saved_buffer = pStubMsg->Buffer;
3883 pStubMsg->Buffer += 4;
3884 ALIGN_LENGTH(pStubMsg->MemorySize, 4);
3885 pStubMsg->MemorySize += 4;
3886 PointerMemorySize(pStubMsg, saved_buffer, pFormat);
3889 return m(pStubMsg, desc);
3892 else FIXME("no marshaller for embedded type %02x\n", *desc);
3895 TRACE("size %d\n", size);
3899 /***********************************************************************
3900 * NdrNonEncapsulatedUnionFree [RPCRT4.@]
3902 void WINAPI NdrNonEncapsulatedUnionFree(PMIDL_STUB_MESSAGE pStubMsg,
3903 unsigned char *pMemory,
3904 PFORMAT_STRING pFormat)
3909 /***********************************************************************
3910 * NdrByteCountPointerMarshall [RPCRT4.@]
3912 unsigned char * WINAPI NdrByteCountPointerMarshall(PMIDL_STUB_MESSAGE pStubMsg,
3913 unsigned char *pMemory,
3914 PFORMAT_STRING pFormat)
3920 /***********************************************************************
3921 * NdrByteCountPointerUnmarshall [RPCRT4.@]
3923 unsigned char * WINAPI NdrByteCountPointerUnmarshall(PMIDL_STUB_MESSAGE pStubMsg,
3924 unsigned char **ppMemory,
3925 PFORMAT_STRING pFormat,
3926 unsigned char fMustAlloc)
3932 /***********************************************************************
3933 * NdrByteCountPointerBufferSize [RPCRT4.@]
3935 void WINAPI NdrByteCountPointerBufferSize(PMIDL_STUB_MESSAGE pStubMsg,
3936 unsigned char *pMemory,
3937 PFORMAT_STRING pFormat)
3942 /***********************************************************************
3943 * NdrByteCountPointerMemorySize [RPCRT4.@]
3945 unsigned long WINAPI NdrByteCountPointerMemorySize(PMIDL_STUB_MESSAGE pStubMsg,
3946 PFORMAT_STRING pFormat)
3952 /***********************************************************************
3953 * NdrByteCountPointerFree [RPCRT4.@]
3955 void WINAPI NdrByteCountPointerFree(PMIDL_STUB_MESSAGE pStubMsg,
3956 unsigned char *pMemory,
3957 PFORMAT_STRING pFormat)
3962 /***********************************************************************
3963 * NdrXmitOrRepAsMarshall [RPCRT4.@]
3965 unsigned char * WINAPI NdrXmitOrRepAsMarshall(PMIDL_STUB_MESSAGE pStubMsg,
3966 unsigned char *pMemory,
3967 PFORMAT_STRING pFormat)
3973 /***********************************************************************
3974 * NdrXmitOrRepAsUnmarshall [RPCRT4.@]
3976 unsigned char * WINAPI NdrXmitOrRepAsUnmarshall(PMIDL_STUB_MESSAGE pStubMsg,
3977 unsigned char **ppMemory,
3978 PFORMAT_STRING pFormat,
3979 unsigned char fMustAlloc)
3985 /***********************************************************************
3986 * NdrXmitOrRepAsBufferSize [RPCRT4.@]
3988 void WINAPI NdrXmitOrRepAsBufferSize(PMIDL_STUB_MESSAGE pStubMsg,
3989 unsigned char *pMemory,
3990 PFORMAT_STRING pFormat)
3995 /***********************************************************************
3996 * NdrXmitOrRepAsMemorySize [RPCRT4.@]
3998 unsigned long WINAPI NdrXmitOrRepAsMemorySize(PMIDL_STUB_MESSAGE pStubMsg,
3999 PFORMAT_STRING pFormat)
4005 /***********************************************************************
4006 * NdrXmitOrRepAsFree [RPCRT4.@]
4008 void WINAPI NdrXmitOrRepAsFree(PMIDL_STUB_MESSAGE pStubMsg,
4009 unsigned char *pMemory,
4010 PFORMAT_STRING pFormat)
4015 /***********************************************************************
4016 * NdrBaseTypeMarshall [internal]
4018 static unsigned char *WINAPI NdrBaseTypeMarshall(
4019 PMIDL_STUB_MESSAGE pStubMsg,
4020 unsigned char *pMemory,
4021 PFORMAT_STRING pFormat)
4023 TRACE("pStubMsg %p, pMemory %p, type 0x%02x\n", pStubMsg, pMemory, *pFormat);
4031 *(UCHAR *)pStubMsg->Buffer = *(UCHAR *)pMemory;
4032 pStubMsg->Buffer += sizeof(UCHAR);
4033 TRACE("value: 0x%02x\n", *(UCHAR *)pMemory);
4038 ALIGN_POINTER(pStubMsg->Buffer, sizeof(USHORT));
4039 *(USHORT *)pStubMsg->Buffer = *(USHORT *)pMemory;
4040 pStubMsg->Buffer += sizeof(USHORT);
4041 TRACE("value: 0x%04x\n", *(USHORT *)pMemory);
4045 case RPC_FC_ERROR_STATUS_T:
4047 ALIGN_POINTER(pStubMsg->Buffer, sizeof(ULONG));
4048 *(ULONG *)pStubMsg->Buffer = *(ULONG *)pMemory;
4049 pStubMsg->Buffer += sizeof(ULONG);
4050 TRACE("value: 0x%08lx\n", *(ULONG *)pMemory);
4053 ALIGN_POINTER(pStubMsg->Buffer, sizeof(float));
4054 *(float *)pStubMsg->Buffer = *(float *)pMemory;
4055 pStubMsg->Buffer += sizeof(float);
4058 ALIGN_POINTER(pStubMsg->Buffer, sizeof(double));
4059 *(double *)pStubMsg->Buffer = *(double *)pMemory;
4060 pStubMsg->Buffer += sizeof(double);
4063 ALIGN_POINTER(pStubMsg->Buffer, sizeof(ULONGLONG));
4064 *(ULONGLONG *)pStubMsg->Buffer = *(ULONGLONG *)pMemory;
4065 pStubMsg->Buffer += sizeof(ULONGLONG);
4066 TRACE("value: %s\n", wine_dbgstr_longlong(*(ULONGLONG*)pMemory));
4069 /* only 16-bits on the wire, so do a sanity check */
4070 if (*(UINT *)pMemory > USHRT_MAX)
4071 RpcRaiseException(RPC_X_ENUM_VALUE_OUT_OF_RANGE);
4072 ALIGN_POINTER(pStubMsg->Buffer, sizeof(USHORT));
4073 *(USHORT *)pStubMsg->Buffer = *(UINT *)pMemory;
4074 pStubMsg->Buffer += sizeof(USHORT);
4075 TRACE("value: 0x%04x\n", *(UINT *)pMemory);
4078 FIXME("Unhandled base type: 0x%02x\n", *pFormat);
4081 STD_OVERFLOW_CHECK(pStubMsg);
4083 /* FIXME: what is the correct return value? */
4087 /***********************************************************************
4088 * NdrBaseTypeUnmarshall [internal]
4090 static unsigned char *WINAPI NdrBaseTypeUnmarshall(
4091 PMIDL_STUB_MESSAGE pStubMsg,
4092 unsigned char **ppMemory,
4093 PFORMAT_STRING pFormat,
4094 unsigned char fMustAlloc)
4096 TRACE("pStubMsg: %p, ppMemory: %p, type: 0x%02x, fMustAlloc: %s\n", pStubMsg, ppMemory, *pFormat, fMustAlloc ? "true" : "false");
4098 if (fMustAlloc || !*ppMemory)
4100 unsigned char *Buffer = pStubMsg->Buffer;
4101 unsigned long MemorySize = pStubMsg->MemorySize;
4102 *ppMemory = NdrAllocate(pStubMsg, NdrBaseTypeMemorySize(pStubMsg, pFormat));
4103 pStubMsg->MemorySize = MemorySize;
4104 pStubMsg->Buffer = Buffer;
4107 TRACE("*ppMemory: %p\n", *ppMemory);
4115 **(UCHAR **)ppMemory = *(UCHAR *)pStubMsg->Buffer;
4116 pStubMsg->Buffer += sizeof(UCHAR);
4117 TRACE("value: 0x%02x\n", **(UCHAR **)ppMemory);
4122 ALIGN_POINTER(pStubMsg->Buffer, sizeof(USHORT));
4123 **(USHORT **)ppMemory = *(USHORT *)pStubMsg->Buffer;
4124 pStubMsg->Buffer += sizeof(USHORT);
4125 TRACE("value: 0x%04x\n", **(USHORT **)ppMemory);
4129 case RPC_FC_ERROR_STATUS_T:
4131 ALIGN_POINTER(pStubMsg->Buffer, sizeof(ULONG));
4132 **(ULONG **)ppMemory = *(ULONG *)pStubMsg->Buffer;
4133 pStubMsg->Buffer += sizeof(ULONG);
4134 TRACE("value: 0x%08lx\n", **(ULONG **)ppMemory);
4137 ALIGN_POINTER(pStubMsg->Buffer, sizeof(float));
4138 **(float **)ppMemory = *(float *)pStubMsg->Buffer;
4139 pStubMsg->Buffer += sizeof(float);
4140 TRACE("value: %f\n", **(float **)ppMemory);
4143 ALIGN_POINTER(pStubMsg->Buffer, sizeof(double));
4144 **(double **)ppMemory = *(double*)pStubMsg->Buffer;
4145 pStubMsg->Buffer += sizeof(double);
4146 TRACE("value: %f\n", **(double **)ppMemory);
4149 ALIGN_POINTER(pStubMsg->Buffer, sizeof(ULONGLONG));
4150 **(ULONGLONG **)ppMemory = *(ULONGLONG *)pStubMsg->Buffer;
4151 pStubMsg->Buffer += sizeof(ULONGLONG);
4152 TRACE("value: %s\n", wine_dbgstr_longlong(**(ULONGLONG **)ppMemory));
4155 ALIGN_POINTER(pStubMsg->Buffer, sizeof(USHORT));
4156 /* 16-bits on the wire, but int in memory */
4157 **(UINT **)ppMemory = *(USHORT *)pStubMsg->Buffer;
4158 pStubMsg->Buffer += sizeof(USHORT);
4159 TRACE("value: 0x%08x\n", **(UINT **)ppMemory);
4162 FIXME("Unhandled base type: 0x%02x\n", *pFormat);
4165 /* FIXME: what is the correct return value? */
4170 /***********************************************************************
4171 * NdrBaseTypeBufferSize [internal]
4173 static void WINAPI NdrBaseTypeBufferSize(
4174 PMIDL_STUB_MESSAGE pStubMsg,
4175 unsigned char *pMemory,
4176 PFORMAT_STRING pFormat)
4178 TRACE("pStubMsg %p, pMemory %p, type 0x%02x\n", pStubMsg, pMemory, *pFormat);
4186 pStubMsg->BufferLength += sizeof(UCHAR);
4192 ALIGN_LENGTH(pStubMsg->BufferLength, sizeof(USHORT));
4193 pStubMsg->BufferLength += sizeof(USHORT);
4198 ALIGN_LENGTH(pStubMsg->BufferLength, sizeof(ULONG));
4199 pStubMsg->BufferLength += sizeof(ULONG);
4202 ALIGN_LENGTH(pStubMsg->BufferLength, sizeof(float));
4203 pStubMsg->BufferLength += sizeof(float);
4206 ALIGN_LENGTH(pStubMsg->BufferLength, sizeof(double));
4207 pStubMsg->BufferLength += sizeof(double);
4210 ALIGN_LENGTH(pStubMsg->BufferLength, sizeof(ULONGLONG));
4211 pStubMsg->BufferLength += sizeof(ULONGLONG);
4213 case RPC_FC_ERROR_STATUS_T:
4214 ALIGN_LENGTH(pStubMsg->BufferLength, sizeof(error_status_t));
4215 pStubMsg->BufferLength += sizeof(error_status_t);
4218 FIXME("Unhandled base type: 0x%02x\n", *pFormat);
4222 /***********************************************************************
4223 * NdrBaseTypeMemorySize [internal]
4225 static unsigned long WINAPI NdrBaseTypeMemorySize(
4226 PMIDL_STUB_MESSAGE pStubMsg,
4227 PFORMAT_STRING pFormat)
4235 pStubMsg->Buffer += sizeof(UCHAR);
4236 pStubMsg->MemorySize += sizeof(UCHAR);
4237 return sizeof(UCHAR);
4241 pStubMsg->Buffer += sizeof(USHORT);
4242 pStubMsg->MemorySize += sizeof(USHORT);
4243 return sizeof(USHORT);
4246 pStubMsg->Buffer += sizeof(ULONG);
4247 pStubMsg->MemorySize += sizeof(ULONG);
4248 return sizeof(ULONG);
4250 pStubMsg->Buffer += sizeof(float);
4251 pStubMsg->MemorySize += sizeof(float);
4252 return sizeof(float);
4254 pStubMsg->Buffer += sizeof(double);
4255 pStubMsg->MemorySize += sizeof(double);
4256 return sizeof(double);
4258 pStubMsg->Buffer += sizeof(ULONGLONG);
4259 pStubMsg->MemorySize += sizeof(ULONGLONG);
4260 return sizeof(ULONGLONG);
4261 case RPC_FC_ERROR_STATUS_T:
4262 pStubMsg->Buffer += sizeof(error_status_t);
4263 pStubMsg->MemorySize += sizeof(error_status_t);
4264 return sizeof(error_status_t);
4267 pStubMsg->Buffer += sizeof(INT);
4268 pStubMsg->MemorySize += sizeof(INT);
4271 FIXME("Unhandled base type: 0x%02x\n", *pFormat);
4276 /***********************************************************************
4277 * NdrBaseTypeFree [internal]
4279 static void WINAPI NdrBaseTypeFree(PMIDL_STUB_MESSAGE pStubMsg,
4280 unsigned char *pMemory,
4281 PFORMAT_STRING pFormat)
4283 TRACE("pStubMsg %p pMemory %p type 0x%02x\n", pStubMsg, pMemory, *pFormat);
4288 /***********************************************************************
4289 * NdrClientContextMarshall
4291 void WINAPI NdrClientContextMarshall(PMIDL_STUB_MESSAGE pStubMsg,
4292 NDR_CCONTEXT ContextHandle,
4295 FIXME("(%p, %p, %d): stub\n", pStubMsg, ContextHandle, fCheck);
4298 /***********************************************************************
4299 * NdrClientContextUnmarshall
4301 void WINAPI NdrClientContextUnmarshall(PMIDL_STUB_MESSAGE pStubMsg,
4302 NDR_CCONTEXT * pContextHandle,
4303 RPC_BINDING_HANDLE BindHandle)
4305 FIXME("(%p, %p, %p): stub\n", pStubMsg, pContextHandle, BindHandle);
4308 void WINAPI NdrServerContextMarshall(PMIDL_STUB_MESSAGE pStubMsg,
4309 NDR_SCONTEXT ContextHandle,
4310 NDR_RUNDOWN RundownRoutine )
4312 FIXME("(%p, %p, %p): stub\n", pStubMsg, ContextHandle, RundownRoutine);
4315 NDR_SCONTEXT WINAPI NdrServerContextUnmarshall(PMIDL_STUB_MESSAGE pStubMsg)
4317 FIXME("(%p): stub\n", pStubMsg);
4321 void WINAPI NdrContextHandleSize(PMIDL_STUB_MESSAGE pStubMsg,
4322 unsigned char* pMemory,
4323 PFORMAT_STRING pFormat)
4325 FIXME("(%p, %p, %p): stub\n", pStubMsg, pMemory, pFormat);
4328 NDR_SCONTEXT WINAPI NdrContextHandleInitialize(PMIDL_STUB_MESSAGE pStubMsg,
4329 PFORMAT_STRING pFormat)
4331 FIXME("(%p, %p): stub\n", pStubMsg, pFormat);
4335 void WINAPI NdrServerContextNewMarshall(PMIDL_STUB_MESSAGE pStubMsg,
4336 NDR_SCONTEXT ContextHandle,
4337 NDR_RUNDOWN RundownRoutine,
4338 PFORMAT_STRING pFormat)
4340 FIXME("(%p, %p, %p, %p): stub\n", pStubMsg, ContextHandle, RundownRoutine, pFormat);
4343 NDR_SCONTEXT WINAPI NdrServerContextNewUnmarshall(PMIDL_STUB_MESSAGE pStubMsg,
4344 PFORMAT_STRING pFormat)
4346 FIXME("(%p, %p): stub\n", pStubMsg, pFormat);
4350 RPC_BINDING_HANDLE WINAPI NDRCContextBinding(NDR_CCONTEXT CContext)
4352 FIXME("(%p): stub\n", CContext);