4 * Copyright 2002 Greg Turner
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 * - figure out whether we *really* got this right
22 * - check for errors and throw exceptions
39 #include "wine/unicode.h"
40 #include "wine/rpcfc.h"
42 #include "wine/debug.h"
44 WINE_DEFAULT_DEBUG_CHANNEL(ole);
47 # define LITTLE_ENDIAN_UINT32_WRITE(pchar, uint32) \
48 (*((UINT32 *)(pchar)) = (uint32))
50 # define LITTLE_ENDIAN_UINT32_READ(pchar) \
51 (*((UINT32 *)(pchar)))
53 /* these would work for i386 too, but less efficient */
54 # define LITTLE_ENDIAN_UINT32_WRITE(pchar, uint32) \
55 (*(pchar) = LOBYTE(LOWORD(uint32)), \
56 *((pchar)+1) = HIBYTE(LOWORD(uint32)), \
57 *((pchar)+2) = LOBYTE(HIWORD(uint32)), \
58 *((pchar)+3) = HIBYTE(HIWORD(uint32)), \
59 (uint32)) /* allow as r-value */
61 # define LITTLE_ENDIAN_UINT32_READ(pchar) \
63 MAKEWORD(*(pchar), *((pchar)+1)), \
64 MAKEWORD(*((pchar)+2), *((pchar)+3))))
67 #define BIG_ENDIAN_UINT32_WRITE(pchar, uint32) \
68 (*((pchar)+3) = LOBYTE(LOWORD(uint32)), \
69 *((pchar)+2) = HIBYTE(LOWORD(uint32)), \
70 *((pchar)+1) = LOBYTE(HIWORD(uint32)), \
71 *(pchar) = HIBYTE(HIWORD(uint32)), \
72 (uint32)) /* allow as r-value */
74 #define BIG_ENDIAN_UINT32_READ(pchar) \
76 MAKEWORD(*((pchar)+3), *((pchar)+2)), \
77 MAKEWORD(*((pchar)+1), *(pchar))))
79 #ifdef NDR_LOCAL_IS_BIG_ENDIAN
80 # define NDR_LOCAL_UINT32_WRITE(pchar, uint32) \
81 BIG_ENDIAN_UINT32_WRITE(pchar, uint32)
82 # define NDR_LOCAL_UINT32_READ(pchar) \
83 BIG_ENDIAN_UINT32_READ(pchar)
85 # define NDR_LOCAL_UINT32_WRITE(pchar, uint32) \
86 LITTLE_ENDIAN_UINT32_WRITE(pchar, uint32)
87 # define NDR_LOCAL_UINT32_READ(pchar) \
88 LITTLE_ENDIAN_UINT32_READ(pchar)
91 /* _Align must be the desired alignment,
92 * e.g. ALIGN_LENGTH(len, 4) to align on a dword boundary. */
93 #define ALIGNED_LENGTH(_Len, _Align) (((_Len)+(_Align)-1)&~((_Align)-1))
94 #define ALIGNED_POINTER(_Ptr, _Align) ((LPVOID)ALIGNED_LENGTH((ULONG_PTR)(_Ptr), _Align))
95 #define ALIGN_LENGTH(_Len, _Align) _Len = ALIGNED_LENGTH(_Len, _Align)
96 #define ALIGN_POINTER(_Ptr, _Align) _Ptr = ALIGNED_POINTER(_Ptr, _Align)
98 #define STD_OVERFLOW_CHECK(_Msg) do { \
99 TRACE("buffer=%d/%ld\n", _Msg->Buffer - (unsigned char *)_Msg->RpcMsg->Buffer, _Msg->BufferLength); \
100 if (_Msg->Buffer > (unsigned char *)_Msg->RpcMsg->Buffer + _Msg->BufferLength) \
101 ERR("buffer overflow %d bytes\n", _Msg->Buffer - ((unsigned char *)_Msg->RpcMsg->Buffer + _Msg->BufferLength)); \
104 #define NDR_TABLE_SIZE 128
105 #define NDR_TABLE_MASK 127
107 static unsigned char *WINAPI NdrBaseTypeMarshall(PMIDL_STUB_MESSAGE, unsigned char *, PFORMAT_STRING);
108 static unsigned char *WINAPI NdrBaseTypeUnmarshall(PMIDL_STUB_MESSAGE, unsigned char **, PFORMAT_STRING, unsigned char);
109 static void WINAPI NdrBaseTypeBufferSize(PMIDL_STUB_MESSAGE, unsigned char *, PFORMAT_STRING);
110 static void WINAPI NdrBaseTypeFree(PMIDL_STUB_MESSAGE, unsigned char *, PFORMAT_STRING);
111 static unsigned long WINAPI NdrBaseTypeMemorySize(PMIDL_STUB_MESSAGE, PFORMAT_STRING);
113 const NDR_MARSHALL NdrMarshaller[NDR_TABLE_SIZE] = {
115 NdrBaseTypeMarshall, NdrBaseTypeMarshall, NdrBaseTypeMarshall,
116 NdrBaseTypeMarshall, NdrBaseTypeMarshall, NdrBaseTypeMarshall, NdrBaseTypeMarshall,
117 NdrBaseTypeMarshall, NdrBaseTypeMarshall, NdrBaseTypeMarshall, NdrBaseTypeMarshall,
118 NdrBaseTypeMarshall, NdrBaseTypeMarshall, NdrBaseTypeMarshall, NdrBaseTypeMarshall,
122 NdrPointerMarshall, NdrPointerMarshall,
123 NdrPointerMarshall, NdrPointerMarshall,
125 NdrSimpleStructMarshall, NdrSimpleStructMarshall,
126 NdrConformantStructMarshall, NdrConformantStructMarshall,
127 NdrConformantVaryingStructMarshall,
128 NdrComplexStructMarshall,
130 NdrConformantArrayMarshall,
131 NdrConformantVaryingArrayMarshall,
132 NdrFixedArrayMarshall, NdrFixedArrayMarshall,
133 NdrVaryingArrayMarshall, NdrVaryingArrayMarshall,
134 NdrComplexArrayMarshall,
136 NdrConformantStringMarshall, 0, 0,
137 NdrConformantStringMarshall,
138 NdrNonConformantStringMarshall, 0, 0, 0,
140 NdrEncapsulatedUnionMarshall,
141 NdrNonEncapsulatedUnionMarshall,
142 NdrByteCountPointerMarshall,
143 NdrXmitOrRepAsMarshall, NdrXmitOrRepAsMarshall,
145 NdrInterfacePointerMarshall,
148 NdrUserMarshalMarshall
150 const NDR_UNMARSHALL NdrUnmarshaller[NDR_TABLE_SIZE] = {
152 NdrBaseTypeUnmarshall, NdrBaseTypeUnmarshall, NdrBaseTypeUnmarshall,
153 NdrBaseTypeUnmarshall, NdrBaseTypeUnmarshall, NdrBaseTypeUnmarshall, NdrBaseTypeUnmarshall,
154 NdrBaseTypeUnmarshall, NdrBaseTypeUnmarshall, NdrBaseTypeUnmarshall, NdrBaseTypeUnmarshall,
155 NdrBaseTypeUnmarshall, NdrBaseTypeUnmarshall, NdrBaseTypeUnmarshall, NdrBaseTypeUnmarshall,
157 NdrBaseTypeUnmarshall,
159 NdrPointerUnmarshall, NdrPointerUnmarshall,
160 NdrPointerUnmarshall, NdrPointerUnmarshall,
162 NdrSimpleStructUnmarshall, NdrSimpleStructUnmarshall,
163 NdrConformantStructUnmarshall, NdrConformantStructUnmarshall,
164 NdrConformantVaryingStructUnmarshall,
165 NdrComplexStructUnmarshall,
167 NdrConformantArrayUnmarshall,
168 NdrConformantVaryingArrayUnmarshall,
169 NdrFixedArrayUnmarshall, NdrFixedArrayUnmarshall,
170 NdrVaryingArrayUnmarshall, NdrVaryingArrayUnmarshall,
171 NdrComplexArrayUnmarshall,
173 NdrConformantStringUnmarshall, 0, 0,
174 NdrConformantStringUnmarshall,
175 NdrNonConformantStringUnmarshall, 0, 0, 0,
177 NdrEncapsulatedUnionUnmarshall,
178 NdrNonEncapsulatedUnionUnmarshall,
179 NdrByteCountPointerUnmarshall,
180 NdrXmitOrRepAsUnmarshall, NdrXmitOrRepAsUnmarshall,
182 NdrInterfacePointerUnmarshall,
185 NdrUserMarshalUnmarshall
187 const NDR_BUFFERSIZE NdrBufferSizer[NDR_TABLE_SIZE] = {
189 NdrBaseTypeBufferSize, NdrBaseTypeBufferSize, NdrBaseTypeBufferSize,
190 NdrBaseTypeBufferSize, NdrBaseTypeBufferSize, NdrBaseTypeBufferSize, NdrBaseTypeBufferSize,
191 NdrBaseTypeBufferSize, NdrBaseTypeBufferSize, NdrBaseTypeBufferSize, NdrBaseTypeBufferSize,
192 NdrBaseTypeBufferSize, NdrBaseTypeBufferSize, NdrBaseTypeBufferSize, NdrBaseTypeBufferSize,
194 NdrBaseTypeBufferSize,
196 NdrPointerBufferSize, NdrPointerBufferSize,
197 NdrPointerBufferSize, NdrPointerBufferSize,
199 NdrSimpleStructBufferSize, NdrSimpleStructBufferSize,
200 NdrConformantStructBufferSize, NdrConformantStructBufferSize,
201 NdrConformantVaryingStructBufferSize,
202 NdrComplexStructBufferSize,
204 NdrConformantArrayBufferSize,
205 NdrConformantVaryingArrayBufferSize,
206 NdrFixedArrayBufferSize, NdrFixedArrayBufferSize,
207 NdrVaryingArrayBufferSize, NdrVaryingArrayBufferSize,
208 NdrComplexArrayBufferSize,
210 NdrConformantStringBufferSize, 0, 0,
211 NdrConformantStringBufferSize,
212 NdrNonConformantStringBufferSize, 0, 0, 0,
214 NdrEncapsulatedUnionBufferSize,
215 NdrNonEncapsulatedUnionBufferSize,
216 NdrByteCountPointerBufferSize,
217 NdrXmitOrRepAsBufferSize, NdrXmitOrRepAsBufferSize,
219 NdrInterfacePointerBufferSize,
222 NdrUserMarshalBufferSize
224 const NDR_MEMORYSIZE NdrMemorySizer[NDR_TABLE_SIZE] = {
226 NdrBaseTypeMemorySize, NdrBaseTypeMemorySize, NdrBaseTypeMemorySize,
227 NdrBaseTypeMemorySize, NdrBaseTypeMemorySize, NdrBaseTypeMemorySize, NdrBaseTypeMemorySize,
228 NdrBaseTypeMemorySize, NdrBaseTypeMemorySize, NdrBaseTypeMemorySize, NdrBaseTypeMemorySize,
229 NdrBaseTypeMemorySize, NdrBaseTypeMemorySize, NdrBaseTypeMemorySize, NdrBaseTypeMemorySize,
231 NdrBaseTypeMemorySize,
233 NdrPointerMemorySize, NdrPointerMemorySize,
234 NdrPointerMemorySize, NdrPointerMemorySize,
236 NdrSimpleStructMemorySize, NdrSimpleStructMemorySize,
237 NdrConformantStructMemorySize, NdrConformantStructMemorySize,
238 NdrConformantVaryingStructMemorySize,
239 NdrComplexStructMemorySize,
241 NdrConformantArrayMemorySize,
242 NdrConformantVaryingArrayMemorySize,
243 NdrFixedArrayMemorySize, NdrFixedArrayMemorySize,
244 NdrVaryingArrayMemorySize, NdrVaryingArrayMemorySize,
245 NdrComplexArrayMemorySize,
247 NdrConformantStringMemorySize, 0, 0,
248 NdrConformantStringMemorySize,
249 NdrNonConformantStringMemorySize, 0, 0, 0,
251 NdrEncapsulatedUnionMemorySize,
252 NdrNonEncapsulatedUnionMemorySize,
253 NdrByteCountPointerMemorySize,
254 NdrXmitOrRepAsMemorySize, NdrXmitOrRepAsMemorySize,
256 NdrInterfacePointerMemorySize,
259 NdrUserMarshalMemorySize
261 const NDR_FREE NdrFreer[NDR_TABLE_SIZE] = {
263 NdrBaseTypeFree, NdrBaseTypeFree, NdrBaseTypeFree,
264 NdrBaseTypeFree, NdrBaseTypeFree, NdrBaseTypeFree, NdrBaseTypeFree,
265 NdrBaseTypeFree, NdrBaseTypeFree, NdrBaseTypeFree, NdrBaseTypeFree,
266 NdrBaseTypeFree, NdrBaseTypeFree, NdrBaseTypeFree, NdrBaseTypeFree,
270 NdrPointerFree, NdrPointerFree,
271 NdrPointerFree, NdrPointerFree,
273 NdrSimpleStructFree, NdrSimpleStructFree,
274 NdrConformantStructFree, NdrConformantStructFree,
275 NdrConformantVaryingStructFree,
276 NdrComplexStructFree,
278 NdrConformantArrayFree,
279 NdrConformantVaryingArrayFree,
280 NdrFixedArrayFree, NdrFixedArrayFree,
281 NdrVaryingArrayFree, NdrVaryingArrayFree,
287 NdrEncapsulatedUnionFree,
288 NdrNonEncapsulatedUnionFree,
290 NdrXmitOrRepAsFree, NdrXmitOrRepAsFree,
292 NdrInterfacePointerFree,
298 void * WINAPI NdrAllocate(MIDL_STUB_MESSAGE *pStubMsg, size_t len)
300 /* hmm, this is probably supposed to do more? */
301 return pStubMsg->pfnAllocate(len);
304 static void WINAPI NdrFree(MIDL_STUB_MESSAGE *pStubMsg, unsigned char *Pointer)
306 pStubMsg->pfnFree(Pointer);
309 static inline BOOL IsConformanceOrVariancePresent(PFORMAT_STRING pFormat)
311 return (*(const ULONG *)pFormat != -1);
314 PFORMAT_STRING ReadConformance(MIDL_STUB_MESSAGE *pStubMsg, PFORMAT_STRING pFormat)
316 ALIGN_POINTER(pStubMsg->Buffer, 4);
317 pStubMsg->MaxCount = NDR_LOCAL_UINT32_READ(pStubMsg->Buffer);
318 pStubMsg->Buffer += 4;
319 TRACE("unmarshalled conformance is %ld\n", pStubMsg->MaxCount);
320 if (pStubMsg->fHasNewCorrDesc)
326 static inline PFORMAT_STRING ReadVariance(MIDL_STUB_MESSAGE *pStubMsg, PFORMAT_STRING pFormat)
328 if (pFormat && !IsConformanceOrVariancePresent(pFormat))
330 pStubMsg->Offset = 0;
331 pStubMsg->ActualCount = pStubMsg->MaxCount;
335 ALIGN_POINTER(pStubMsg->Buffer, 4);
336 pStubMsg->Offset = NDR_LOCAL_UINT32_READ(pStubMsg->Buffer);
337 pStubMsg->Buffer += 4;
338 TRACE("offset is %ld\n", pStubMsg->Offset);
339 pStubMsg->ActualCount = NDR_LOCAL_UINT32_READ(pStubMsg->Buffer);
340 pStubMsg->Buffer += 4;
341 TRACE("variance is %ld\n", pStubMsg->ActualCount);
344 if (pStubMsg->fHasNewCorrDesc)
350 /* writes the conformance value to the buffer */
351 static inline void WriteConformance(MIDL_STUB_MESSAGE *pStubMsg)
353 ALIGN_POINTER(pStubMsg->Buffer, 4);
354 NDR_LOCAL_UINT32_WRITE(pStubMsg->Buffer, pStubMsg->MaxCount);
355 pStubMsg->Buffer += 4;
358 /* writes the variance values to the buffer */
359 static inline void WriteVariance(MIDL_STUB_MESSAGE *pStubMsg)
361 ALIGN_POINTER(pStubMsg->Buffer, 4);
362 NDR_LOCAL_UINT32_WRITE(pStubMsg->Buffer, pStubMsg->Offset);
363 pStubMsg->Buffer += 4;
364 NDR_LOCAL_UINT32_WRITE(pStubMsg->Buffer, pStubMsg->ActualCount);
365 pStubMsg->Buffer += 4;
368 /* requests buffer space for the conformance value */
369 static inline void SizeConformance(MIDL_STUB_MESSAGE *pStubMsg)
371 ALIGN_LENGTH(pStubMsg->BufferLength, 4);
372 pStubMsg->BufferLength += 4;
375 /* requests buffer space for the variance values */
376 static inline void SizeVariance(MIDL_STUB_MESSAGE *pStubMsg)
378 ALIGN_LENGTH(pStubMsg->BufferLength, 4);
379 pStubMsg->BufferLength += 8;
382 PFORMAT_STRING ComputeConformanceOrVariance(
383 MIDL_STUB_MESSAGE *pStubMsg, unsigned char *pMemory,
384 PFORMAT_STRING pFormat, ULONG_PTR def, ULONG *pCount)
386 BYTE dtype = pFormat[0] & 0xf;
387 short ofs = *(short *)&pFormat[2];
391 if (!IsConformanceOrVariancePresent(pFormat)) {
392 /* null descriptor */
397 switch (pFormat[0] & 0xf0) {
398 case RPC_FC_NORMAL_CONFORMANCE:
399 TRACE("normal conformance, ofs=%d\n", ofs);
402 case RPC_FC_POINTER_CONFORMANCE:
403 TRACE("pointer conformance, ofs=%d\n", ofs);
404 ptr = pStubMsg->Memory;
406 case RPC_FC_TOP_LEVEL_CONFORMANCE:
407 TRACE("toplevel conformance, ofs=%d\n", ofs);
408 if (pStubMsg->StackTop) {
409 ptr = pStubMsg->StackTop;
412 /* -Os mode, *pCount is already set */
416 case RPC_FC_CONSTANT_CONFORMANCE:
417 data = ofs | ((DWORD)pFormat[1] << 16);
418 TRACE("constant conformance, val=%ld\n", data);
421 case RPC_FC_TOP_LEVEL_MULTID_CONFORMANCE:
422 FIXME("toplevel multidimensional conformance, ofs=%d\n", ofs);
423 if (pStubMsg->StackTop) {
424 ptr = pStubMsg->StackTop;
432 FIXME("unknown conformance type %x\n", pFormat[0] & 0xf0);
435 switch (pFormat[1]) {
436 case RPC_FC_DEREFERENCE:
437 ptr = *(LPVOID*)((char *)ptr + ofs);
439 case RPC_FC_CALLBACK:
441 unsigned char *old_stack_top = pStubMsg->StackTop;
442 pStubMsg->StackTop = ptr;
444 /* ofs is index into StubDesc->apfnExprEval */
445 TRACE("callback conformance into apfnExprEval[%d]\n", ofs);
446 pStubMsg->StubDesc->apfnExprEval[ofs](pStubMsg);
448 pStubMsg->StackTop = old_stack_top;
452 ptr = (char *)ptr + ofs;
465 data = *(USHORT*)ptr;
476 FIXME("unknown conformance data type %x\n", dtype);
479 TRACE("dereferenced data type %x at %p, got %ld\n", dtype, ptr, data);
482 switch (pFormat[1]) {
486 case RPC_FC_DEREFERENCE:
487 /* already handled */
502 FIXME("unknown conformance op %d\n", pFormat[1]);
507 TRACE("resulting conformance is %ld\n", *pCount);
508 if (pStubMsg->fHasNewCorrDesc)
516 * NdrConformantString:
518 * What MS calls a ConformantString is, in DCE terminology,
519 * a Varying-Conformant String.
521 * maxlen: DWORD (max # of CHARTYPE characters, inclusive of '\0')
522 * offset: DWORD (actual string data begins at (offset) CHARTYPE's
523 * into unmarshalled string)
524 * length: DWORD (# of CHARTYPE characters, inclusive of '\0')
526 * data: CHARTYPE[maxlen]
528 * ], where CHARTYPE is the appropriate character type (specified externally)
532 /***********************************************************************
533 * NdrConformantStringMarshall [RPCRT4.@]
535 unsigned char *WINAPI NdrConformantStringMarshall(MIDL_STUB_MESSAGE *pStubMsg,
536 unsigned char *pszMessage, PFORMAT_STRING pFormat)
540 TRACE("(pStubMsg == ^%p, pszMessage == ^%p, pFormat == ^%p)\n", pStubMsg, pszMessage, pFormat);
542 if (*pFormat == RPC_FC_C_CSTRING) {
543 TRACE("string=%s\n", debugstr_a((char*)pszMessage));
544 pStubMsg->ActualCount = strlen((char*)pszMessage)+1;
547 else if (*pFormat == RPC_FC_C_WSTRING) {
548 TRACE("string=%s\n", debugstr_w((LPWSTR)pszMessage));
549 pStubMsg->ActualCount = strlenW((LPWSTR)pszMessage)+1;
553 ERR("Unhandled string type: %#x\n", *pFormat);
554 /* FIXME: raise an exception. */
558 if (pFormat[1] == RPC_FC_STRING_SIZED)
559 pFormat = ComputeConformance(pStubMsg, pszMessage, pFormat + 2, 0);
561 pStubMsg->MaxCount = pStubMsg->ActualCount;
562 pStubMsg->Offset = 0;
563 WriteConformance(pStubMsg);
564 WriteVariance(pStubMsg);
566 memcpy(pStubMsg->Buffer, pszMessage, pStubMsg->ActualCount*esize); /* the string itself */
567 pStubMsg->Buffer += pStubMsg->ActualCount*esize;
569 STD_OVERFLOW_CHECK(pStubMsg);
572 return NULL; /* is this always right? */
575 /***********************************************************************
576 * NdrConformantStringBufferSize [RPCRT4.@]
578 void WINAPI NdrConformantStringBufferSize(PMIDL_STUB_MESSAGE pStubMsg,
579 unsigned char* pMemory, PFORMAT_STRING pFormat)
581 TRACE("(pStubMsg == ^%p, pMemory == ^%p, pFormat == ^%p)\n", pStubMsg, pMemory, pFormat);
583 SizeConformance(pStubMsg);
584 SizeVariance(pStubMsg);
586 if (*pFormat == RPC_FC_C_CSTRING) {
587 /* we need + 1 octet for '\0' */
588 TRACE("string=%s\n", debugstr_a((char*)pMemory));
589 pStubMsg->BufferLength += strlen((char*)pMemory) + 1;
591 else if (*pFormat == RPC_FC_C_WSTRING) {
592 /* we need + 2 octets for L'\0' */
593 TRACE("string=%s\n", debugstr_w((LPWSTR)pMemory));
594 pStubMsg->BufferLength += strlenW((LPWSTR)pMemory)*2 + 2;
597 ERR("Unhandled string type: %#x\n", *pFormat);
598 /* FIXME: raise an exception */
602 /************************************************************************
603 * NdrConformantStringMemorySize [RPCRT4.@]
605 unsigned long WINAPI NdrConformantStringMemorySize( PMIDL_STUB_MESSAGE pStubMsg,
606 PFORMAT_STRING pFormat )
608 unsigned long rslt = 0;
610 TRACE("(pStubMsg == ^%p, pFormat == ^%p)\n", pStubMsg, pFormat);
612 assert(pStubMsg && pFormat);
614 if (*pFormat == RPC_FC_C_CSTRING) {
615 rslt = NDR_LOCAL_UINT32_READ(pStubMsg->Buffer); /* maxlen */
617 else if (*pFormat == RPC_FC_C_WSTRING) {
618 rslt = NDR_LOCAL_UINT32_READ(pStubMsg->Buffer)*2; /* maxlen */
621 ERR("Unhandled string type: %#x\n", *pFormat);
622 /* FIXME: raise an exception */
625 if (pFormat[1] != RPC_FC_PAD) {
626 FIXME("sized string format=%d\n", pFormat[1]);
629 TRACE(" --> %lu\n", rslt);
633 /************************************************************************
634 * NdrConformantStringUnmarshall [RPCRT4.@]
636 unsigned char *WINAPI NdrConformantStringUnmarshall( PMIDL_STUB_MESSAGE pStubMsg,
637 unsigned char** ppMemory, PFORMAT_STRING pFormat, unsigned char fMustAlloc )
639 unsigned long len, esize;
641 TRACE("(pStubMsg == ^%p, *pMemory == ^%p, pFormat == ^%p, fMustAlloc == %u)\n",
642 pStubMsg, *ppMemory, pFormat, fMustAlloc);
644 assert(pFormat && ppMemory && pStubMsg);
646 ReadConformance(pStubMsg, NULL);
647 ReadVariance(pStubMsg, NULL);
649 if (*pFormat == RPC_FC_C_CSTRING) esize = 1;
650 else if (*pFormat == RPC_FC_C_WSTRING) esize = 2;
652 ERR("Unhandled string type: %#x\n", *pFormat);
653 /* FIXME: raise an exception */
657 len = pStubMsg->ActualCount;
659 if (fMustAlloc || !*ppMemory)
660 *ppMemory = NdrAllocate(pStubMsg, len*esize);
662 memcpy(*ppMemory, pStubMsg->Buffer, len*esize);
664 pStubMsg->Buffer += len*esize;
666 if (*pFormat == RPC_FC_C_CSTRING) {
667 TRACE("string=%s\n", debugstr_a((char*)*ppMemory));
669 else if (*pFormat == RPC_FC_C_WSTRING) {
670 TRACE("string=%s\n", debugstr_w((LPWSTR)*ppMemory));
673 return NULL; /* FIXME: is this always right? */
676 /***********************************************************************
677 * NdrNonConformantStringMarshall [RPCRT4.@]
679 unsigned char * WINAPI NdrNonConformantStringMarshall(PMIDL_STUB_MESSAGE pStubMsg,
680 unsigned char *pMemory,
681 PFORMAT_STRING pFormat)
687 /***********************************************************************
688 * NdrNonConformantStringUnmarshall [RPCRT4.@]
690 unsigned char * WINAPI NdrNonConformantStringUnmarshall(PMIDL_STUB_MESSAGE pStubMsg,
691 unsigned char **ppMemory,
692 PFORMAT_STRING pFormat,
693 unsigned char fMustAlloc)
699 /***********************************************************************
700 * NdrNonConformantStringBufferSize [RPCRT4.@]
702 void WINAPI NdrNonConformantStringBufferSize(PMIDL_STUB_MESSAGE pStubMsg,
703 unsigned char *pMemory,
704 PFORMAT_STRING pFormat)
709 /***********************************************************************
710 * NdrNonConformantStringMemorySize [RPCRT4.@]
712 unsigned long WINAPI NdrNonConformantStringMemorySize(PMIDL_STUB_MESSAGE pStubMsg,
713 PFORMAT_STRING pFormat)
719 static inline void dump_pointer_attr(unsigned char attr)
721 if (attr & RPC_FC_P_ALLOCALLNODES)
722 TRACE(" RPC_FC_P_ALLOCALLNODES");
723 if (attr & RPC_FC_P_DONTFREE)
724 TRACE(" RPC_FC_P_DONTFREE");
725 if (attr & RPC_FC_P_ONSTACK)
726 TRACE(" RPC_FC_P_ONSTACK");
727 if (attr & RPC_FC_P_SIMPLEPOINTER)
728 TRACE(" RPC_FC_P_SIMPLEPOINTER");
729 if (attr & RPC_FC_P_DEREF)
730 TRACE(" RPC_FC_P_DEREF");
734 /***********************************************************************
737 void WINAPI PointerMarshall(PMIDL_STUB_MESSAGE pStubMsg,
738 unsigned char *Buffer,
739 unsigned char *Pointer,
740 PFORMAT_STRING pFormat)
742 unsigned type = pFormat[0], attr = pFormat[1];
746 TRACE("(%p,%p,%p,%p)\n", pStubMsg, Buffer, Pointer, pFormat);
747 TRACE("type=0x%x, attr=", type); dump_pointer_attr(attr);
749 if (attr & RPC_FC_P_SIMPLEPOINTER) desc = pFormat;
750 else desc = pFormat + *(const SHORT*)pFormat;
753 case RPC_FC_RP: /* ref pointer (always non-null) */
754 #if 0 /* this causes problems for InstallShield so is disabled - we need more tests */
756 RpcRaiseException(RPC_X_NULL_REF_POINTER);
759 case RPC_FC_UP: /* unique pointer */
760 case RPC_FC_OP: /* object pointer - same as unique here */
761 TRACE("writing %p to buffer\n", Pointer);
762 NDR_LOCAL_UINT32_WRITE(Buffer, (unsigned long)Pointer);
766 FIXME("unhandled ptr type=%02x\n", type);
767 RpcRaiseException(RPC_X_BAD_STUB_DATA);
770 TRACE("calling marshaller for type 0x%x\n", (int)*desc);
773 if (attr & RPC_FC_P_DEREF) {
774 Pointer = *(unsigned char**)Pointer;
775 TRACE("deref => %p\n", Pointer);
777 m = NdrMarshaller[*desc & NDR_TABLE_MASK];
778 if (m) m(pStubMsg, Pointer, desc);
779 else FIXME("no marshaller for data type=%02x\n", *desc);
782 STD_OVERFLOW_CHECK(pStubMsg);
785 /***********************************************************************
788 void WINAPI PointerUnmarshall(PMIDL_STUB_MESSAGE pStubMsg,
789 unsigned char *Buffer,
790 unsigned char **pPointer,
791 PFORMAT_STRING pFormat,
792 unsigned char fMustAlloc)
794 unsigned type = pFormat[0], attr = pFormat[1];
797 DWORD pointer_id = 0;
799 TRACE("(%p,%p,%p,%p,%d)\n", pStubMsg, Buffer, pPointer, pFormat, fMustAlloc);
800 TRACE("type=0x%x, attr=", type); dump_pointer_attr(attr);
802 if (attr & RPC_FC_P_SIMPLEPOINTER) desc = pFormat;
803 else desc = pFormat + *(const SHORT*)pFormat;
806 case RPC_FC_RP: /* ref pointer (always non-null) */
809 case RPC_FC_UP: /* unique pointer */
810 pointer_id = NDR_LOCAL_UINT32_READ(Buffer);
811 TRACE("pointer_id is 0x%08lx\n", pointer_id);
813 case RPC_FC_OP: /* object pointer - we must free data before overwriting it */
814 pointer_id = NDR_LOCAL_UINT32_READ(Buffer);
815 TRACE("pointer_id is 0x%08lx\n", pointer_id);
817 FIXME("free object pointer %p\n", *pPointer);
821 FIXME("unhandled ptr type=%02x\n", type);
822 RpcRaiseException(RPC_X_BAD_STUB_DATA);
826 if (attr & RPC_FC_P_DEREF) {
827 if (!*pPointer || fMustAlloc)
828 *pPointer = NdrAllocate(pStubMsg, sizeof(void *));
829 pPointer = *(unsigned char***)pPointer;
830 TRACE("deref => %p\n", pPointer);
832 m = NdrUnmarshaller[*desc & NDR_TABLE_MASK];
833 if (m) m(pStubMsg, pPointer, desc, fMustAlloc);
834 else FIXME("no unmarshaller for data type=%02x\n", *desc);
837 TRACE("pointer=%p\n", *pPointer);
840 /***********************************************************************
843 void WINAPI PointerBufferSize(PMIDL_STUB_MESSAGE pStubMsg,
844 unsigned char *Pointer,
845 PFORMAT_STRING pFormat)
847 unsigned type = pFormat[0], attr = pFormat[1];
851 TRACE("(%p,%p,%p)\n", pStubMsg, Pointer, pFormat);
852 TRACE("type=0x%x, attr=", type); dump_pointer_attr(attr);
854 if (attr & RPC_FC_P_SIMPLEPOINTER) desc = pFormat;
855 else desc = pFormat + *(const SHORT*)pFormat;
858 case RPC_FC_RP: /* ref pointer (always non-null) */
862 /* NULL pointer has no further representation */
868 FIXME("unhandled ptr type=%02x\n", type);
869 RpcRaiseException(RPC_X_BAD_STUB_DATA);
872 if (attr & RPC_FC_P_DEREF) {
873 Pointer = *(unsigned char**)Pointer;
874 TRACE("deref => %p\n", Pointer);
877 m = NdrBufferSizer[*desc & NDR_TABLE_MASK];
878 if (m) m(pStubMsg, Pointer, desc);
879 else FIXME("no buffersizer for data type=%02x\n", *desc);
882 /***********************************************************************
883 * PointerMemorySize [RPCRT4.@]
885 unsigned long WINAPI PointerMemorySize(PMIDL_STUB_MESSAGE pStubMsg,
886 unsigned char *Buffer,
887 PFORMAT_STRING pFormat)
889 unsigned type = pFormat[0], attr = pFormat[1];
893 FIXME("(%p,%p,%p): stub\n", pStubMsg, Buffer, pFormat);
894 TRACE("type=0x%x, attr=", type); dump_pointer_attr(attr);
896 if (attr & RPC_FC_P_SIMPLEPOINTER) desc = pFormat;
897 else desc = pFormat + *(const SHORT*)pFormat;
900 case RPC_FC_RP: /* ref pointer (always non-null) */
903 FIXME("unhandled ptr type=%02x\n", type);
904 RpcRaiseException(RPC_X_BAD_STUB_DATA);
907 if (attr & RPC_FC_P_DEREF) {
911 m = NdrMemorySizer[*desc & NDR_TABLE_MASK];
912 if (m) m(pStubMsg, desc);
913 else FIXME("no memorysizer for data type=%02x\n", *desc);
918 /***********************************************************************
919 * PointerFree [RPCRT4.@]
921 void WINAPI PointerFree(PMIDL_STUB_MESSAGE pStubMsg,
922 unsigned char *Pointer,
923 PFORMAT_STRING pFormat)
925 unsigned type = pFormat[0], attr = pFormat[1];
929 TRACE("(%p,%p,%p)\n", pStubMsg, Pointer, pFormat);
930 TRACE("type=0x%x, attr=", type); dump_pointer_attr(attr);
931 if (attr & RPC_FC_P_DONTFREE) return;
933 if (attr & RPC_FC_P_SIMPLEPOINTER) desc = pFormat;
934 else desc = pFormat + *(const SHORT*)pFormat;
936 if (!Pointer) return;
938 if (attr & RPC_FC_P_DEREF) {
939 Pointer = *(unsigned char**)Pointer;
940 TRACE("deref => %p\n", Pointer);
943 m = NdrFreer[*desc & NDR_TABLE_MASK];
944 if (m) m(pStubMsg, Pointer, desc);
946 /* hmm... is this sensible?
947 * perhaps we should check if the memory comes from NdrAllocate,
948 * and deallocate only if so - checking if the pointer is between
949 * BufferStart and BufferEnd is probably no good since the buffer
950 * may be reallocated when the server wants to marshal the reply */
952 case RPC_FC_BOGUS_STRUCT:
953 case RPC_FC_BOGUS_ARRAY:
954 case RPC_FC_USER_MARSHAL:
959 FIXME("unhandled data type=%02x\n", *desc);
961 case RPC_FC_C_CSTRING:
962 case RPC_FC_C_WSTRING:
963 if (pStubMsg->ReuseBuffer) goto notfree;
969 if (attr & RPC_FC_P_ONSTACK) {
970 TRACE("not freeing stack ptr %p\n", Pointer);
973 TRACE("freeing %p\n", Pointer);
974 NdrFree(pStubMsg, Pointer);
977 TRACE("not freeing %p\n", Pointer);
980 /***********************************************************************
981 * EmbeddedPointerMarshall
983 unsigned char * WINAPI EmbeddedPointerMarshall(PMIDL_STUB_MESSAGE pStubMsg,
984 unsigned char *pMemory,
985 PFORMAT_STRING pFormat)
987 unsigned char *Mark = pStubMsg->BufferMark;
988 unsigned long Offset = pStubMsg->Offset;
989 unsigned ofs, rep, count, stride, xofs;
992 TRACE("(%p,%p,%p)\n", pStubMsg, pMemory, pFormat);
994 if (*pFormat != RPC_FC_PP) return NULL;
997 while (pFormat[0] != RPC_FC_END) {
998 switch (pFormat[0]) {
1000 FIXME("unknown repeat type %d\n", pFormat[0]);
1001 case RPC_FC_NO_REPEAT:
1009 case RPC_FC_FIXED_REPEAT:
1010 rep = *(const WORD*)&pFormat[2];
1011 stride = *(const WORD*)&pFormat[4];
1012 ofs = *(const WORD*)&pFormat[6];
1013 count = *(const WORD*)&pFormat[8];
1017 case RPC_FC_VARIABLE_REPEAT:
1018 rep = pStubMsg->MaxCount;
1019 stride = *(const WORD*)&pFormat[2];
1020 ofs = *(const WORD*)&pFormat[4];
1021 count = *(const WORD*)&pFormat[6];
1022 xofs = (pFormat[1] == RPC_FC_VARIABLE_OFFSET) ? Offset * stride : 0;
1026 for (i = 0; i < rep; i++) {
1027 PFORMAT_STRING info = pFormat;
1028 unsigned char *membase = pMemory + (i * stride);
1029 unsigned char *bufbase = Mark + (i * stride);
1031 /* ofs doesn't seem to matter in this context */
1032 for (u=0; u<count; u++,info+=8) {
1033 unsigned char *memptr = membase + *(const SHORT*)&info[0];
1034 unsigned char *bufptr = bufbase + *(const SHORT*)&info[2];
1035 PointerMarshall(pStubMsg, bufptr, *(unsigned char**)memptr, info+4);
1038 pFormat += 8 * count;
1041 STD_OVERFLOW_CHECK(pStubMsg);
1046 /***********************************************************************
1047 * EmbeddedPointerUnmarshall
1049 unsigned char * WINAPI EmbeddedPointerUnmarshall(PMIDL_STUB_MESSAGE pStubMsg,
1050 unsigned char **ppMemory,
1051 PFORMAT_STRING pFormat,
1052 unsigned char fMustAlloc)
1054 unsigned char *Mark = pStubMsg->BufferMark;
1055 unsigned long Offset = pStubMsg->Offset;
1056 unsigned ofs, rep, count, stride, xofs;
1059 TRACE("(%p,%p,%p,%d)\n", pStubMsg, ppMemory, pFormat, fMustAlloc);
1061 if (*pFormat != RPC_FC_PP) return NULL;
1064 while (pFormat[0] != RPC_FC_END) {
1065 TRACE("pFormat[0] = 0x%x\n", pFormat[0]);
1066 switch (pFormat[0]) {
1068 FIXME("unknown repeat type %d\n", pFormat[0]);
1069 case RPC_FC_NO_REPEAT:
1077 case RPC_FC_FIXED_REPEAT:
1078 rep = *(const WORD*)&pFormat[2];
1079 stride = *(const WORD*)&pFormat[4];
1080 ofs = *(const WORD*)&pFormat[6];
1081 count = *(const WORD*)&pFormat[8];
1085 case RPC_FC_VARIABLE_REPEAT:
1086 rep = pStubMsg->MaxCount;
1087 stride = *(const WORD*)&pFormat[2];
1088 ofs = *(const WORD*)&pFormat[4];
1089 count = *(const WORD*)&pFormat[6];
1090 xofs = (pFormat[1] == RPC_FC_VARIABLE_OFFSET) ? Offset * stride : 0;
1094 /* ofs doesn't seem to matter in this context */
1095 for (i = 0; i < rep; i++) {
1096 PFORMAT_STRING info = pFormat;
1097 unsigned char *membase = *ppMemory + (i * stride);
1098 unsigned char *bufbase = Mark + (i * stride);
1100 for (u=0; u<count; u++,info+=8) {
1101 unsigned char *memptr = membase + *(const SHORT*)&info[0];
1102 unsigned char *bufptr = bufbase + *(const SHORT*)&info[2];
1103 *(void **)memptr = NULL;
1104 PointerUnmarshall(pStubMsg, bufptr, (unsigned char**)memptr, info+4, fMustAlloc);
1107 pFormat += 8 * count;
1113 /***********************************************************************
1114 * EmbeddedPointerBufferSize
1116 void WINAPI EmbeddedPointerBufferSize(PMIDL_STUB_MESSAGE pStubMsg,
1117 unsigned char *pMemory,
1118 PFORMAT_STRING pFormat)
1120 unsigned long Offset = pStubMsg->Offset;
1121 unsigned ofs, rep, count, stride, xofs;
1124 TRACE("(%p,%p,%p)\n", pStubMsg, pMemory, pFormat);
1126 if (pStubMsg->IgnoreEmbeddedPointers) return;
1128 if (*pFormat != RPC_FC_PP) return;
1131 while (pFormat[0] != RPC_FC_END) {
1132 switch (pFormat[0]) {
1134 FIXME("unknown repeat type %d\n", pFormat[0]);
1135 case RPC_FC_NO_REPEAT:
1143 case RPC_FC_FIXED_REPEAT:
1144 rep = *(const WORD*)&pFormat[2];
1145 stride = *(const WORD*)&pFormat[4];
1146 ofs = *(const WORD*)&pFormat[6];
1147 count = *(const WORD*)&pFormat[8];
1151 case RPC_FC_VARIABLE_REPEAT:
1152 rep = pStubMsg->MaxCount;
1153 stride = *(const WORD*)&pFormat[2];
1154 ofs = *(const WORD*)&pFormat[4];
1155 count = *(const WORD*)&pFormat[6];
1156 xofs = (pFormat[1] == RPC_FC_VARIABLE_OFFSET) ? Offset * stride : 0;
1160 /* ofs doesn't seem to matter in this context */
1161 for (i = 0; i < rep; i++) {
1162 PFORMAT_STRING info = pFormat;
1163 unsigned char *membase = pMemory + (i * stride);
1165 for (u=0; u<count; u++,info+=8) {
1166 unsigned char *memptr = membase + *(const SHORT*)&info[0];
1167 PointerBufferSize(pStubMsg, *(unsigned char**)memptr, info+4);
1170 pFormat += 8 * count;
1174 /***********************************************************************
1175 * EmbeddedPointerMemorySize
1177 unsigned long WINAPI EmbeddedPointerMemorySize(PMIDL_STUB_MESSAGE pStubMsg,
1178 PFORMAT_STRING pFormat)
1180 unsigned long Offset = pStubMsg->Offset;
1181 unsigned char *Mark = pStubMsg->BufferMark;
1182 unsigned ofs, rep, count, stride, xofs;
1185 FIXME("(%p,%p): stub\n", pStubMsg, pFormat);
1187 if (*pFormat != RPC_FC_PP) return 0;
1190 while (pFormat[0] != RPC_FC_END) {
1191 switch (pFormat[0]) {
1193 FIXME("unknown repeat type %d\n", pFormat[0]);
1194 case RPC_FC_NO_REPEAT:
1202 case RPC_FC_FIXED_REPEAT:
1203 rep = *(const WORD*)&pFormat[2];
1204 stride = *(const WORD*)&pFormat[4];
1205 ofs = *(const WORD*)&pFormat[6];
1206 count = *(const WORD*)&pFormat[8];
1210 case RPC_FC_VARIABLE_REPEAT:
1211 rep = pStubMsg->MaxCount;
1212 stride = *(const WORD*)&pFormat[2];
1213 ofs = *(const WORD*)&pFormat[4];
1214 count = *(const WORD*)&pFormat[6];
1215 xofs = (pFormat[1] == RPC_FC_VARIABLE_OFFSET) ? Offset * stride : 0;
1219 /* ofs doesn't seem to matter in this context */
1220 for (i = 0; i < rep; i++) {
1221 PFORMAT_STRING info = pFormat;
1222 unsigned char *bufbase = Mark + (i * stride);
1224 for (u=0; u<count; u++,info+=8) {
1225 unsigned char *bufptr = bufbase + *(const SHORT*)&info[2];
1226 PointerMemorySize(pStubMsg, bufptr, info+4);
1229 pFormat += 8 * count;
1235 /***********************************************************************
1236 * EmbeddedPointerFree
1238 void WINAPI EmbeddedPointerFree(PMIDL_STUB_MESSAGE pStubMsg,
1239 unsigned char *pMemory,
1240 PFORMAT_STRING pFormat)
1242 unsigned long Offset = pStubMsg->Offset;
1243 unsigned ofs, rep, count, stride, xofs;
1246 TRACE("(%p,%p,%p)\n", pStubMsg, pMemory, pFormat);
1247 if (*pFormat != RPC_FC_PP) return;
1250 while (pFormat[0] != RPC_FC_END) {
1251 switch (pFormat[0]) {
1253 FIXME("unknown repeat type %d\n", pFormat[0]);
1254 case RPC_FC_NO_REPEAT:
1262 case RPC_FC_FIXED_REPEAT:
1263 rep = *(const WORD*)&pFormat[2];
1264 stride = *(const WORD*)&pFormat[4];
1265 ofs = *(const WORD*)&pFormat[6];
1266 count = *(const WORD*)&pFormat[8];
1270 case RPC_FC_VARIABLE_REPEAT:
1271 rep = pStubMsg->MaxCount;
1272 stride = *(const WORD*)&pFormat[2];
1273 ofs = *(const WORD*)&pFormat[4];
1274 count = *(const WORD*)&pFormat[6];
1275 xofs = (pFormat[1] == RPC_FC_VARIABLE_OFFSET) ? Offset * stride : 0;
1279 /* ofs doesn't seem to matter in this context */
1280 for (i = 0; i < rep; i++) {
1281 PFORMAT_STRING info = pFormat;
1282 unsigned char *membase = pMemory + (i * stride);
1284 for (u=0; u<count; u++,info+=8) {
1285 unsigned char *memptr = membase + *(const SHORT*)&info[0];
1286 PointerFree(pStubMsg, *(unsigned char**)memptr, info+4);
1289 pFormat += 8 * count;
1293 /***********************************************************************
1294 * NdrPointerMarshall [RPCRT4.@]
1296 unsigned char * WINAPI NdrPointerMarshall(PMIDL_STUB_MESSAGE pStubMsg,
1297 unsigned char *pMemory,
1298 PFORMAT_STRING pFormat)
1300 unsigned char *Buffer;
1302 TRACE("(%p,%p,%p)\n", pStubMsg, pMemory, pFormat);
1304 /* incremement the buffer here instead of in PointerMarshall,
1305 * as that is used by embedded pointers which already handle the incrementing
1306 * the buffer, and shouldn't write any additional pointer data to the wire */
1307 if (*pFormat != RPC_FC_RP)
1309 ALIGN_POINTER(pStubMsg->Buffer, 4);
1310 Buffer = pStubMsg->Buffer;
1311 pStubMsg->Buffer += 4;
1314 Buffer = pStubMsg->Buffer;
1316 PointerMarshall(pStubMsg, Buffer, pMemory, pFormat);
1318 STD_OVERFLOW_CHECK(pStubMsg);
1323 /***********************************************************************
1324 * NdrPointerUnmarshall [RPCRT4.@]
1326 unsigned char * WINAPI NdrPointerUnmarshall(PMIDL_STUB_MESSAGE pStubMsg,
1327 unsigned char **ppMemory,
1328 PFORMAT_STRING pFormat,
1329 unsigned char fMustAlloc)
1331 unsigned char *Buffer;
1333 TRACE("(%p,%p,%p,%d)\n", pStubMsg, ppMemory, pFormat, fMustAlloc);
1335 /* incremement the buffer here instead of in PointerUnmarshall,
1336 * as that is used by embedded pointers which already handle the incrementing
1337 * the buffer, and shouldn't read any additional pointer data from the
1339 if (*pFormat != RPC_FC_RP)
1341 ALIGN_POINTER(pStubMsg->Buffer, 4);
1342 Buffer = pStubMsg->Buffer;
1343 pStubMsg->Buffer += 4;
1346 Buffer = pStubMsg->Buffer;
1348 PointerUnmarshall(pStubMsg, Buffer, ppMemory, pFormat, fMustAlloc);
1353 /***********************************************************************
1354 * NdrPointerBufferSize [RPCRT4.@]
1356 void WINAPI NdrPointerBufferSize(PMIDL_STUB_MESSAGE pStubMsg,
1357 unsigned char *pMemory,
1358 PFORMAT_STRING pFormat)
1360 TRACE("(%p,%p,%p)\n", pStubMsg, pMemory, pFormat);
1362 /* incremement the buffer length here instead of in PointerBufferSize,
1363 * as that is used by embedded pointers which already handle the buffer
1364 * length, and shouldn't write anything more to the wire */
1365 if (*pFormat != RPC_FC_RP)
1367 ALIGN_LENGTH(pStubMsg->BufferLength, 4);
1368 pStubMsg->BufferLength += 4;
1371 PointerBufferSize(pStubMsg, pMemory, pFormat);
1374 /***********************************************************************
1375 * NdrPointerMemorySize [RPCRT4.@]
1377 unsigned long WINAPI NdrPointerMemorySize(PMIDL_STUB_MESSAGE pStubMsg,
1378 PFORMAT_STRING pFormat)
1380 /* unsigned size = *(LPWORD)(pFormat+2); */
1381 FIXME("(%p,%p): stub\n", pStubMsg, pFormat);
1382 PointerMemorySize(pStubMsg, pStubMsg->Buffer, pFormat);
1386 /***********************************************************************
1387 * NdrPointerFree [RPCRT4.@]
1389 void WINAPI NdrPointerFree(PMIDL_STUB_MESSAGE pStubMsg,
1390 unsigned char *pMemory,
1391 PFORMAT_STRING pFormat)
1393 TRACE("(%p,%p,%p)\n", pStubMsg, pMemory, pFormat);
1394 PointerFree(pStubMsg, pMemory, pFormat);
1397 /***********************************************************************
1398 * NdrSimpleStructMarshall [RPCRT4.@]
1400 unsigned char * WINAPI NdrSimpleStructMarshall(PMIDL_STUB_MESSAGE pStubMsg,
1401 unsigned char *pMemory,
1402 PFORMAT_STRING pFormat)
1404 unsigned size = *(const WORD*)(pFormat+2);
1405 TRACE("(%p,%p,%p)\n", pStubMsg, pMemory, pFormat);
1407 ALIGN_POINTER(pStubMsg->Buffer, pFormat[1] + 1);
1409 memcpy(pStubMsg->Buffer, pMemory, size);
1410 pStubMsg->BufferMark = pStubMsg->Buffer;
1411 pStubMsg->Buffer += size;
1413 if (pFormat[0] != RPC_FC_STRUCT)
1414 EmbeddedPointerMarshall(pStubMsg, pMemory, pFormat+4);
1416 STD_OVERFLOW_CHECK(pStubMsg);
1421 /***********************************************************************
1422 * NdrSimpleStructUnmarshall [RPCRT4.@]
1424 unsigned char * WINAPI NdrSimpleStructUnmarshall(PMIDL_STUB_MESSAGE pStubMsg,
1425 unsigned char **ppMemory,
1426 PFORMAT_STRING pFormat,
1427 unsigned char fMustAlloc)
1429 unsigned size = *(const WORD*)(pFormat+2);
1430 TRACE("(%p,%p,%p,%d)\n", pStubMsg, ppMemory, pFormat, fMustAlloc);
1432 ALIGN_POINTER(pStubMsg->Buffer, pFormat[1] + 1);
1435 *ppMemory = NdrAllocate(pStubMsg, size);
1436 memcpy(*ppMemory, pStubMsg->Buffer, size);
1438 if (pStubMsg->ReuseBuffer && !*ppMemory)
1439 /* for servers, we may just point straight into the RPC buffer, I think
1440 * (I guess that's what MS does since MIDL code doesn't try to free) */
1441 *ppMemory = pStubMsg->Buffer;
1443 /* for clients, memory should be provided by caller */
1444 memcpy(*ppMemory, pStubMsg->Buffer, size);
1447 pStubMsg->BufferMark = pStubMsg->Buffer;
1448 pStubMsg->Buffer += size;
1450 if (pFormat[0] != RPC_FC_STRUCT)
1451 EmbeddedPointerUnmarshall(pStubMsg, ppMemory, pFormat+4, fMustAlloc);
1457 /***********************************************************************
1458 * NdrSimpleStructUnmarshall [RPCRT4.@]
1460 void WINAPI NdrSimpleTypeMarshall( PMIDL_STUB_MESSAGE pStubMsg, unsigned char* pMemory,
1461 unsigned char FormatChar )
1467 /***********************************************************************
1468 * NdrSimpleStructUnmarshall [RPCRT4.@]
1470 void WINAPI NdrSimpleTypeUnmarshall( PMIDL_STUB_MESSAGE pStubMsg, unsigned char* pMemory,
1471 unsigned char FormatChar )
1477 /***********************************************************************
1478 * NdrSimpleStructBufferSize [RPCRT4.@]
1480 void WINAPI NdrSimpleStructBufferSize(PMIDL_STUB_MESSAGE pStubMsg,
1481 unsigned char *pMemory,
1482 PFORMAT_STRING pFormat)
1484 unsigned size = *(const WORD*)(pFormat+2);
1485 TRACE("(%p,%p,%p)\n", pStubMsg, pMemory, pFormat);
1487 ALIGN_LENGTH(pStubMsg->BufferLength, pFormat[1] + 1);
1489 pStubMsg->BufferLength += size;
1490 if (pFormat[0] != RPC_FC_STRUCT)
1491 EmbeddedPointerBufferSize(pStubMsg, pMemory, pFormat+4);
1494 /***********************************************************************
1495 * NdrSimpleStructMemorySize [RPCRT4.@]
1497 unsigned long WINAPI NdrSimpleStructMemorySize(PMIDL_STUB_MESSAGE pStubMsg,
1498 PFORMAT_STRING pFormat)
1500 unsigned short size = *(LPWORD)(pFormat+2);
1502 TRACE("(%p,%p)\n", pStubMsg, pFormat);
1504 ALIGN_POINTER(pStubMsg->Buffer, pFormat[1] + 1);
1505 pStubMsg->MemorySize += size;
1506 pStubMsg->Buffer += size;
1508 if (pFormat[0] != RPC_FC_STRUCT)
1509 EmbeddedPointerMemorySize(pStubMsg, pFormat+4);
1513 /***********************************************************************
1514 * NdrSimpleStructFree [RPCRT4.@]
1516 void WINAPI NdrSimpleStructFree(PMIDL_STUB_MESSAGE pStubMsg,
1517 unsigned char *pMemory,
1518 PFORMAT_STRING pFormat)
1520 TRACE("(%p,%p,%p)\n", pStubMsg, pMemory, pFormat);
1521 if (pFormat[0] != RPC_FC_STRUCT)
1522 EmbeddedPointerFree(pStubMsg, pMemory, pFormat+4);
1526 static unsigned long EmbeddedComplexSize(PMIDL_STUB_MESSAGE pStubMsg,
1527 PFORMAT_STRING pFormat)
1531 case RPC_FC_PSTRUCT:
1532 case RPC_FC_CSTRUCT:
1533 case RPC_FC_BOGUS_STRUCT:
1534 return *(const WORD*)&pFormat[2];
1535 case RPC_FC_USER_MARSHAL:
1536 return *(const WORD*)&pFormat[4];
1537 case RPC_FC_NON_ENCAPSULATED_UNION:
1539 if (pStubMsg->fHasNewCorrDesc)
1544 pFormat += *(const SHORT*)pFormat;
1545 return *(const SHORT*)pFormat;
1547 FIXME("unhandled embedded type %02x\n", *pFormat);
1553 static unsigned long EmbeddedComplexMemorySize(PMIDL_STUB_MESSAGE pStubMsg,
1554 PFORMAT_STRING pFormat)
1556 NDR_MEMORYSIZE m = NdrMemorySizer[*pFormat & NDR_TABLE_MASK];
1560 FIXME("no memorysizer for data type=%02x\n", *pFormat);
1564 return m(pStubMsg, pFormat);
1568 static unsigned char * ComplexMarshall(PMIDL_STUB_MESSAGE pStubMsg,
1569 unsigned char *pMemory,
1570 PFORMAT_STRING pFormat,
1571 PFORMAT_STRING pPointer)
1573 PFORMAT_STRING desc;
1577 while (*pFormat != RPC_FC_END) {
1581 TRACE("short=%d <= %p\n", *(WORD*)pMemory, pMemory);
1582 memcpy(pStubMsg->Buffer, pMemory, 2);
1583 pStubMsg->Buffer += 2;
1589 TRACE("long=%ld <= %p\n", *(DWORD*)pMemory, pMemory);
1590 memcpy(pStubMsg->Buffer, pMemory, 4);
1591 pStubMsg->Buffer += 4;
1594 case RPC_FC_POINTER:
1595 TRACE("pointer=%p <= %p\n", *(unsigned char**)pMemory, pMemory);
1596 NdrPointerMarshall(pStubMsg, *(unsigned char**)pMemory, pPointer);
1600 case RPC_FC_ALIGNM4:
1601 ALIGN_POINTER(pMemory, 4);
1603 case RPC_FC_ALIGNM8:
1604 ALIGN_POINTER(pMemory, 8);
1606 case RPC_FC_STRUCTPAD2:
1609 case RPC_FC_EMBEDDED_COMPLEX:
1610 pMemory += pFormat[1];
1612 desc = pFormat + *(const SHORT*)pFormat;
1613 size = EmbeddedComplexSize(pStubMsg, desc);
1614 TRACE("embedded complex (size=%ld) <= %p\n", size, pMemory);
1615 m = NdrMarshaller[*desc & NDR_TABLE_MASK];
1616 if (m) m(pStubMsg, pMemory, desc);
1617 else FIXME("no marshaller for embedded type %02x\n", *desc);
1624 FIXME("unhandled format %02x\n", *pFormat);
1632 static unsigned char * ComplexUnmarshall(PMIDL_STUB_MESSAGE pStubMsg,
1633 unsigned char *pMemory,
1634 PFORMAT_STRING pFormat,
1635 PFORMAT_STRING pPointer,
1636 unsigned char fMustAlloc)
1638 PFORMAT_STRING desc;
1642 while (*pFormat != RPC_FC_END) {
1646 memcpy(pMemory, pStubMsg->Buffer, 2);
1647 TRACE("short=%d => %p\n", *(WORD*)pMemory, pMemory);
1648 pStubMsg->Buffer += 2;
1654 memcpy(pMemory, pStubMsg->Buffer, 4);
1655 TRACE("long=%ld => %p\n", *(DWORD*)pMemory, pMemory);
1656 pStubMsg->Buffer += 4;
1659 case RPC_FC_POINTER:
1660 *(unsigned char**)pMemory = NULL;
1661 TRACE("pointer => %p\n", pMemory);
1662 NdrPointerUnmarshall(pStubMsg, (unsigned char**)pMemory, pPointer, fMustAlloc);
1666 case RPC_FC_ALIGNM4:
1667 ALIGN_POINTER(pMemory, 4);
1669 case RPC_FC_ALIGNM8:
1670 ALIGN_POINTER(pMemory, 8);
1672 case RPC_FC_STRUCTPAD2:
1675 case RPC_FC_EMBEDDED_COMPLEX:
1676 pMemory += pFormat[1];
1678 desc = pFormat + *(const SHORT*)pFormat;
1679 size = EmbeddedComplexSize(pStubMsg, desc);
1680 TRACE("embedded complex (size=%ld) => %p\n", size, pMemory);
1681 m = NdrUnmarshaller[*desc & NDR_TABLE_MASK];
1682 memset(pMemory, 0, size); /* just in case */
1683 if (m) m(pStubMsg, &pMemory, desc, fMustAlloc);
1684 else FIXME("no unmarshaller for embedded type %02x\n", *desc);
1691 FIXME("unhandled format %d\n", *pFormat);
1699 static unsigned char * ComplexBufferSize(PMIDL_STUB_MESSAGE pStubMsg,
1700 unsigned char *pMemory,
1701 PFORMAT_STRING pFormat,
1702 PFORMAT_STRING pPointer)
1704 PFORMAT_STRING desc;
1708 while (*pFormat != RPC_FC_END) {
1712 pStubMsg->BufferLength += 2;
1718 pStubMsg->BufferLength += 4;
1721 case RPC_FC_POINTER:
1722 NdrPointerBufferSize(pStubMsg, *(unsigned char**)pMemory, pPointer);
1726 case RPC_FC_ALIGNM4:
1727 ALIGN_POINTER(pMemory, 4);
1729 case RPC_FC_ALIGNM8:
1730 ALIGN_POINTER(pMemory, 8);
1732 case RPC_FC_STRUCTPAD2:
1735 case RPC_FC_EMBEDDED_COMPLEX:
1736 pMemory += pFormat[1];
1738 desc = pFormat + *(const SHORT*)pFormat;
1739 size = EmbeddedComplexSize(pStubMsg, desc);
1740 m = NdrBufferSizer[*desc & NDR_TABLE_MASK];
1741 if (m) m(pStubMsg, pMemory, desc);
1742 else FIXME("no buffersizer for embedded type %02x\n", *desc);
1749 FIXME("unhandled format %d\n", *pFormat);
1757 static unsigned char * ComplexFree(PMIDL_STUB_MESSAGE pStubMsg,
1758 unsigned char *pMemory,
1759 PFORMAT_STRING pFormat,
1760 PFORMAT_STRING pPointer)
1762 PFORMAT_STRING desc;
1766 while (*pFormat != RPC_FC_END) {
1777 case RPC_FC_POINTER:
1778 NdrPointerFree(pStubMsg, *(unsigned char**)pMemory, pPointer);
1782 case RPC_FC_ALIGNM4:
1783 ALIGN_POINTER(pMemory, 4);
1785 case RPC_FC_ALIGNM8:
1786 ALIGN_POINTER(pMemory, 8);
1788 case RPC_FC_STRUCTPAD2:
1791 case RPC_FC_EMBEDDED_COMPLEX:
1792 pMemory += pFormat[1];
1794 desc = pFormat + *(const SHORT*)pFormat;
1795 size = EmbeddedComplexSize(pStubMsg, desc);
1796 m = NdrFreer[*desc & NDR_TABLE_MASK];
1797 if (m) m(pStubMsg, pMemory, desc);
1798 else FIXME("no freer for embedded type %02x\n", *desc);
1805 FIXME("unhandled format %d\n", *pFormat);
1813 static unsigned long ComplexStructMemorySize(PMIDL_STUB_MESSAGE pStubMsg,
1814 PFORMAT_STRING pFormat)
1816 PFORMAT_STRING desc;
1817 unsigned long size = 0;
1819 while (*pFormat != RPC_FC_END) {
1824 pStubMsg->Buffer += 2;
1829 pStubMsg->Buffer += 4;
1831 case RPC_FC_POINTER:
1833 pStubMsg->Buffer += 4;
1835 case RPC_FC_ALIGNM4:
1836 ALIGN_LENGTH(size, 4);
1837 ALIGN_POINTER(pStubMsg->Buffer, 4);
1839 case RPC_FC_ALIGNM8:
1840 ALIGN_LENGTH(size, 8);
1841 ALIGN_POINTER(pStubMsg->Buffer, 8);
1843 case RPC_FC_STRUCTPAD2:
1845 pStubMsg->Buffer += 2;
1847 case RPC_FC_EMBEDDED_COMPLEX:
1850 desc = pFormat + *(const SHORT*)pFormat;
1851 size += EmbeddedComplexMemorySize(pStubMsg, desc);
1857 FIXME("unhandled format %d\n", *pFormat);
1865 /***********************************************************************
1866 * NdrComplexStructMarshall [RPCRT4.@]
1868 unsigned char * WINAPI NdrComplexStructMarshall(PMIDL_STUB_MESSAGE pStubMsg,
1869 unsigned char *pMemory,
1870 PFORMAT_STRING pFormat)
1872 PFORMAT_STRING conf_array = NULL;
1873 PFORMAT_STRING pointer_desc = NULL;
1874 unsigned char *OldMemory = pStubMsg->Memory;
1876 TRACE("(%p,%p,%p)\n", pStubMsg, pMemory, pFormat);
1878 ALIGN_POINTER(pStubMsg->Buffer, pFormat[1] + 1);
1881 if (*(const WORD*)pFormat) conf_array = pFormat + *(const WORD*)pFormat;
1883 if (*(const WORD*)pFormat) pointer_desc = pFormat + *(const WORD*)pFormat;
1886 pStubMsg->Memory = pMemory;
1888 ComplexMarshall(pStubMsg, pMemory, pFormat, pointer_desc);
1891 NdrConformantArrayMarshall(pStubMsg, pMemory, conf_array);
1893 pStubMsg->Memory = OldMemory;
1895 STD_OVERFLOW_CHECK(pStubMsg);
1900 /***********************************************************************
1901 * NdrComplexStructUnmarshall [RPCRT4.@]
1903 unsigned char * WINAPI NdrComplexStructUnmarshall(PMIDL_STUB_MESSAGE pStubMsg,
1904 unsigned char **ppMemory,
1905 PFORMAT_STRING pFormat,
1906 unsigned char fMustAlloc)
1908 unsigned size = *(const WORD*)(pFormat+2);
1909 PFORMAT_STRING conf_array = NULL;
1910 PFORMAT_STRING pointer_desc = NULL;
1911 unsigned char *pMemory;
1913 TRACE("(%p,%p,%p,%d)\n", pStubMsg, ppMemory, pFormat, fMustAlloc);
1915 ALIGN_POINTER(pStubMsg->Buffer, pFormat[1] + 1);
1917 if (fMustAlloc || !*ppMemory)
1919 *ppMemory = NdrAllocate(pStubMsg, size);
1920 memset(*ppMemory, 0, size);
1924 if (*(const WORD*)pFormat) conf_array = pFormat + *(const WORD*)pFormat;
1926 if (*(const WORD*)pFormat) pointer_desc = pFormat + *(const WORD*)pFormat;
1929 pMemory = ComplexUnmarshall(pStubMsg, *ppMemory, pFormat, pointer_desc, fMustAlloc);
1932 NdrConformantArrayUnmarshall(pStubMsg, &pMemory, conf_array, fMustAlloc);
1937 /***********************************************************************
1938 * NdrComplexStructBufferSize [RPCRT4.@]
1940 void WINAPI NdrComplexStructBufferSize(PMIDL_STUB_MESSAGE pStubMsg,
1941 unsigned char *pMemory,
1942 PFORMAT_STRING pFormat)
1944 PFORMAT_STRING conf_array = NULL;
1945 PFORMAT_STRING pointer_desc = NULL;
1946 unsigned char *OldMemory = pStubMsg->Memory;
1948 TRACE("(%p,%p,%p)\n", pStubMsg, pMemory, pFormat);
1950 ALIGN_LENGTH(pStubMsg->BufferLength, pFormat[1] + 1);
1953 if (*(const WORD*)pFormat) conf_array = pFormat + *(const WORD*)pFormat;
1955 if (*(const WORD*)pFormat) pointer_desc = pFormat + *(const WORD*)pFormat;
1958 pStubMsg->Memory = pMemory;
1960 pMemory = ComplexBufferSize(pStubMsg, pMemory, pFormat, pointer_desc);
1963 NdrConformantArrayBufferSize(pStubMsg, pMemory, conf_array);
1965 pStubMsg->Memory = OldMemory;
1968 /***********************************************************************
1969 * NdrComplexStructMemorySize [RPCRT4.@]
1971 unsigned long WINAPI NdrComplexStructMemorySize(PMIDL_STUB_MESSAGE pStubMsg,
1972 PFORMAT_STRING pFormat)
1974 unsigned size = *(const WORD*)(pFormat+2);
1975 PFORMAT_STRING conf_array = NULL;
1976 PFORMAT_STRING pointer_desc = NULL;
1978 TRACE("(%p,%p)\n", pStubMsg, pFormat);
1980 ALIGN_POINTER(pStubMsg->Buffer, pFormat[1] + 1);
1983 if (*(const WORD*)pFormat) conf_array = pFormat + *(const WORD*)pFormat;
1985 if (*(const WORD*)pFormat) pointer_desc = pFormat + *(const WORD*)pFormat;
1988 ComplexStructMemorySize(pStubMsg, pFormat);
1991 NdrConformantArrayMemorySize(pStubMsg, conf_array);
1996 /***********************************************************************
1997 * NdrComplexStructFree [RPCRT4.@]
1999 void WINAPI NdrComplexStructFree(PMIDL_STUB_MESSAGE pStubMsg,
2000 unsigned char *pMemory,
2001 PFORMAT_STRING pFormat)
2003 PFORMAT_STRING conf_array = NULL;
2004 PFORMAT_STRING pointer_desc = NULL;
2005 unsigned char *OldMemory = pStubMsg->Memory;
2007 TRACE("(%p,%p,%p)\n", pStubMsg, pMemory, pFormat);
2010 if (*(const WORD*)pFormat) conf_array = pFormat + *(const WORD*)pFormat;
2012 if (*(const WORD*)pFormat) pointer_desc = pFormat + *(const WORD*)pFormat;
2015 pStubMsg->Memory = pMemory;
2017 pMemory = ComplexFree(pStubMsg, pMemory, pFormat, pointer_desc);
2020 NdrConformantArrayFree(pStubMsg, pMemory, conf_array);
2022 pStubMsg->Memory = OldMemory;
2025 /***********************************************************************
2026 * NdrConformantArrayMarshall [RPCRT4.@]
2028 unsigned char * WINAPI NdrConformantArrayMarshall(PMIDL_STUB_MESSAGE pStubMsg,
2029 unsigned char *pMemory,
2030 PFORMAT_STRING pFormat)
2032 DWORD size = 0, esize = *(const WORD*)(pFormat+2);
2033 unsigned char alignment = pFormat[1] + 1;
2035 TRACE("(%p,%p,%p)\n", pStubMsg, pMemory, pFormat);
2036 if (pFormat[0] != RPC_FC_CARRAY) FIXME("format=%d\n", pFormat[0]);
2038 pFormat = ComputeConformance(pStubMsg, pMemory, pFormat+4, 0);
2039 size = pStubMsg->MaxCount;
2041 WriteConformance(pStubMsg);
2043 ALIGN_POINTER(pStubMsg->Buffer, alignment);
2045 memcpy(pStubMsg->Buffer, pMemory, size*esize);
2046 pStubMsg->BufferMark = pStubMsg->Buffer;
2047 pStubMsg->Buffer += size*esize;
2049 EmbeddedPointerMarshall(pStubMsg, pMemory, pFormat);
2051 STD_OVERFLOW_CHECK(pStubMsg);
2056 /***********************************************************************
2057 * NdrConformantArrayUnmarshall [RPCRT4.@]
2059 unsigned char * WINAPI NdrConformantArrayUnmarshall(PMIDL_STUB_MESSAGE pStubMsg,
2060 unsigned char **ppMemory,
2061 PFORMAT_STRING pFormat,
2062 unsigned char fMustAlloc)
2064 DWORD size = 0, esize = *(const WORD*)(pFormat+2);
2065 unsigned char alignment = pFormat[1] + 1;
2067 TRACE("(%p,%p,%p,%d)\n", pStubMsg, ppMemory, pFormat, fMustAlloc);
2068 if (pFormat[0] != RPC_FC_CARRAY) FIXME("format=%d\n", pFormat[0]);
2070 pFormat = ReadConformance(pStubMsg, pFormat+4);
2071 size = pStubMsg->MaxCount;
2073 if (fMustAlloc || !*ppMemory)
2074 *ppMemory = NdrAllocate(pStubMsg, size*esize);
2076 ALIGN_POINTER(pStubMsg->Buffer, alignment);
2078 memcpy(*ppMemory, pStubMsg->Buffer, size*esize);
2080 pStubMsg->BufferMark = pStubMsg->Buffer;
2081 pStubMsg->Buffer += size*esize;
2083 EmbeddedPointerUnmarshall(pStubMsg, ppMemory, pFormat, fMustAlloc);
2088 /***********************************************************************
2089 * NdrConformantArrayBufferSize [RPCRT4.@]
2091 void WINAPI NdrConformantArrayBufferSize(PMIDL_STUB_MESSAGE pStubMsg,
2092 unsigned char *pMemory,
2093 PFORMAT_STRING pFormat)
2095 DWORD size = 0, esize = *(const WORD*)(pFormat+2);
2096 unsigned char alignment = pFormat[1] + 1;
2098 TRACE("(%p,%p,%p)\n", pStubMsg, pMemory, pFormat);
2099 if (pFormat[0] != RPC_FC_CARRAY) FIXME("format=%d\n", pFormat[0]);
2101 pFormat = ComputeConformance(pStubMsg, pMemory, pFormat+4, 0);
2102 size = pStubMsg->MaxCount;
2104 SizeConformance(pStubMsg);
2106 ALIGN_LENGTH(pStubMsg->BufferLength, alignment);
2108 /* conformance value plus array */
2109 pStubMsg->BufferLength += size*esize;
2111 EmbeddedPointerBufferSize(pStubMsg, pMemory, pFormat);
2114 /***********************************************************************
2115 * NdrConformantArrayMemorySize [RPCRT4.@]
2117 unsigned long WINAPI NdrConformantArrayMemorySize(PMIDL_STUB_MESSAGE pStubMsg,
2118 PFORMAT_STRING pFormat)
2120 DWORD size = 0, esize = *(const WORD*)(pFormat+2);
2121 unsigned char *buffer;
2123 TRACE("(%p,%p)\n", pStubMsg, pFormat);
2124 if (pFormat[0] != RPC_FC_CARRAY) FIXME("format=%d\n", pFormat[0]);
2126 buffer = pStubMsg->Buffer;
2127 pFormat = ReadConformance(pStubMsg, pFormat+4);
2128 pStubMsg->Buffer = buffer;
2129 size = pStubMsg->MaxCount;
2134 /***********************************************************************
2135 * NdrConformantArrayFree [RPCRT4.@]
2137 void WINAPI NdrConformantArrayFree(PMIDL_STUB_MESSAGE pStubMsg,
2138 unsigned char *pMemory,
2139 PFORMAT_STRING pFormat)
2141 TRACE("(%p,%p,%p)\n", pStubMsg, pMemory, pFormat);
2142 if (pFormat[0] != RPC_FC_CARRAY) FIXME("format=%d\n", pFormat[0]);
2144 EmbeddedPointerFree(pStubMsg, pMemory, pFormat);
2148 /***********************************************************************
2149 * NdrConformantVaryingArrayMarshall [RPCRT4.@]
2151 unsigned char* WINAPI NdrConformantVaryingArrayMarshall( PMIDL_STUB_MESSAGE pStubMsg,
2152 unsigned char* pMemory,
2153 PFORMAT_STRING pFormat )
2155 unsigned char alignment = pFormat[1] + 1;
2156 DWORD esize = *(const WORD*)(pFormat+2);
2158 TRACE("(%p, %p, %p)\n", pStubMsg, pMemory, pFormat);
2160 if (pFormat[0] != RPC_FC_CVARRAY)
2162 ERR("invalid format type %x\n", pFormat[0]);
2163 RpcRaiseException(RPC_S_INTERNAL_ERROR);
2167 pFormat = ComputeConformance(pStubMsg, pMemory, pFormat+4, 0);
2168 pFormat = ComputeVariance(pStubMsg, pMemory, pFormat, 0);
2170 WriteConformance(pStubMsg);
2171 WriteVariance(pStubMsg);
2173 ALIGN_POINTER(pStubMsg->Buffer, alignment);
2175 memcpy(pStubMsg->Buffer, pMemory + pStubMsg->Offset, pStubMsg->ActualCount*esize);
2176 pStubMsg->BufferMark = pStubMsg->Buffer;
2177 pStubMsg->Buffer += pStubMsg->ActualCount*esize;
2179 EmbeddedPointerMarshall(pStubMsg, pMemory, pFormat);
2181 STD_OVERFLOW_CHECK(pStubMsg);
2187 /***********************************************************************
2188 * NdrConformantVaryingArrayUnmarshall [RPCRT4.@]
2190 unsigned char* WINAPI NdrConformantVaryingArrayUnmarshall( PMIDL_STUB_MESSAGE pStubMsg,
2191 unsigned char** ppMemory,
2192 PFORMAT_STRING pFormat,
2193 unsigned char fMustAlloc )
2195 unsigned char alignment = pFormat[1] + 1;
2196 DWORD esize = *(const WORD*)(pFormat+2);
2198 TRACE("(%p, %p, %p, %d)\n", pStubMsg, ppMemory, pFormat, fMustAlloc);
2200 if (pFormat[0] != RPC_FC_CVARRAY)
2202 ERR("invalid format type %x\n", pFormat[0]);
2203 RpcRaiseException(RPC_S_INTERNAL_ERROR);
2207 pFormat = ReadConformance(pStubMsg, pFormat);
2208 pFormat = ReadVariance(pStubMsg, pFormat);
2210 ALIGN_POINTER(pStubMsg->Buffer, alignment);
2212 if (!*ppMemory || fMustAlloc)
2213 *ppMemory = NdrAllocate(pStubMsg, pStubMsg->MaxCount * esize);
2214 memcpy(*ppMemory + pStubMsg->Offset, pStubMsg->Buffer, pStubMsg->ActualCount * esize);
2215 pStubMsg->Buffer += pStubMsg->ActualCount * esize;
2217 EmbeddedPointerUnmarshall(pStubMsg, ppMemory, pFormat, fMustAlloc);
2223 /***********************************************************************
2224 * NdrConformantVaryingArrayFree [RPCRT4.@]
2226 void WINAPI NdrConformantVaryingArrayFree( PMIDL_STUB_MESSAGE pStubMsg,
2227 unsigned char* pMemory,
2228 PFORMAT_STRING pFormat )
2230 TRACE("(%p,%p,%p)\n", pStubMsg, pMemory, pFormat);
2232 if (pFormat[0] != RPC_FC_CVARRAY)
2234 ERR("invalid format type %x\n", pFormat[0]);
2235 RpcRaiseException(RPC_S_INTERNAL_ERROR);
2239 pFormat = ComputeConformance(pStubMsg, pMemory, pFormat+4, 0);
2240 pFormat = ComputeVariance(pStubMsg, pMemory, pFormat, 0);
2242 EmbeddedPointerFree(pStubMsg, pMemory, pFormat);
2246 /***********************************************************************
2247 * NdrConformantVaryingArrayBufferSize [RPCRT4.@]
2249 void WINAPI NdrConformantVaryingArrayBufferSize( PMIDL_STUB_MESSAGE pStubMsg,
2250 unsigned char* pMemory, PFORMAT_STRING pFormat )
2252 unsigned char alignment = pFormat[1] + 1;
2253 DWORD esize = *(const WORD*)(pFormat+2);
2255 TRACE("(%p, %p, %p)\n", pStubMsg, pMemory, pFormat);
2257 if (pFormat[0] != RPC_FC_CVARRAY)
2259 ERR("invalid format type %x\n", pFormat[0]);
2260 RpcRaiseException(RPC_S_INTERNAL_ERROR);
2265 pFormat = ComputeConformance(pStubMsg, pMemory, pFormat+4, 0);
2266 /* compute length */
2267 pFormat = ComputeVariance(pStubMsg, pMemory, pFormat, 0);
2269 SizeConformance(pStubMsg);
2270 SizeVariance(pStubMsg);
2272 ALIGN_LENGTH(pStubMsg->BufferLength, alignment);
2274 pStubMsg->BufferLength += pStubMsg->ActualCount*esize;
2276 EmbeddedPointerBufferSize(pStubMsg, pMemory, pFormat);
2280 /***********************************************************************
2281 * NdrConformantVaryingArrayMemorySize [RPCRT4.@]
2283 unsigned long WINAPI NdrConformantVaryingArrayMemorySize( PMIDL_STUB_MESSAGE pStubMsg,
2284 PFORMAT_STRING pFormat )
2291 /***********************************************************************
2292 * NdrComplexArrayMarshall [RPCRT4.@]
2294 unsigned char * WINAPI NdrComplexArrayMarshall(PMIDL_STUB_MESSAGE pStubMsg,
2295 unsigned char *pMemory,
2296 PFORMAT_STRING pFormat)
2298 ULONG i, count, def;
2299 BOOL variance_present;
2300 unsigned char alignment;
2302 TRACE("(%p,%p,%p)\n", pStubMsg, pMemory, pFormat);
2304 if (pFormat[0] != RPC_FC_BOGUS_ARRAY)
2306 ERR("invalid format type %x\n", pFormat[0]);
2307 RpcRaiseException(RPC_S_INTERNAL_ERROR);
2311 alignment = pFormat[1] + 1;
2313 def = *(const WORD*)&pFormat[2];
2316 pFormat = ComputeConformance(pStubMsg, pMemory, pFormat, def);
2317 TRACE("conformance = %ld\n", pStubMsg->MaxCount);
2319 variance_present = IsConformanceOrVariancePresent(pFormat);
2320 pFormat = ComputeVariance(pStubMsg, pMemory, pFormat, pStubMsg->MaxCount);
2321 TRACE("variance = %ld\n", pStubMsg->ActualCount);
2323 WriteConformance(pStubMsg);
2324 if (variance_present)
2325 WriteVariance(pStubMsg);
2327 ALIGN_POINTER(pStubMsg->Buffer, alignment);
2329 count = pStubMsg->ActualCount;
2330 for (i = 0; i < count; i++)
2331 pMemory = ComplexMarshall(pStubMsg, pMemory, pFormat, NULL);
2333 STD_OVERFLOW_CHECK(pStubMsg);
2338 /***********************************************************************
2339 * NdrComplexArrayUnmarshall [RPCRT4.@]
2341 unsigned char * WINAPI NdrComplexArrayUnmarshall(PMIDL_STUB_MESSAGE pStubMsg,
2342 unsigned char **ppMemory,
2343 PFORMAT_STRING pFormat,
2344 unsigned char fMustAlloc)
2346 ULONG i, count, esize;
2347 unsigned char alignment;
2348 unsigned char *pMemory;
2349 unsigned char *Buffer;
2351 TRACE("(%p,%p,%p,%d)\n", pStubMsg, ppMemory, pFormat, fMustAlloc);
2353 if (pFormat[0] != RPC_FC_BOGUS_ARRAY)
2355 ERR("invalid format type %x\n", pFormat[0]);
2356 RpcRaiseException(RPC_S_INTERNAL_ERROR);
2360 alignment = pFormat[1] + 1;
2364 pFormat = ReadConformance(pStubMsg, pFormat);
2365 pFormat = ReadVariance(pStubMsg, pFormat);
2367 Buffer = pStubMsg->Buffer;
2368 esize = ComplexStructMemorySize(pStubMsg, pFormat);
2369 pStubMsg->Buffer = Buffer;
2371 if (fMustAlloc || !*ppMemory)
2373 *ppMemory = NdrAllocate(pStubMsg, pStubMsg->MaxCount * esize);
2374 memset(*ppMemory, 0, pStubMsg->MaxCount * esize);
2377 ALIGN_POINTER(pStubMsg->Buffer, alignment);
2379 pMemory = *ppMemory;
2380 count = pStubMsg->ActualCount;
2381 for (i = 0; i < count; i++)
2382 pMemory = ComplexUnmarshall(pStubMsg, pMemory, pFormat, NULL, fMustAlloc);
2387 /***********************************************************************
2388 * NdrComplexArrayBufferSize [RPCRT4.@]
2390 void WINAPI NdrComplexArrayBufferSize(PMIDL_STUB_MESSAGE pStubMsg,
2391 unsigned char *pMemory,
2392 PFORMAT_STRING pFormat)
2394 ULONG i, count, def;
2395 unsigned char alignment;
2396 BOOL variance_present;
2398 TRACE("(%p,%p,%p)\n", pStubMsg, pMemory, pFormat);
2400 if (pFormat[0] != RPC_FC_BOGUS_ARRAY)
2402 ERR("invalid format type %x\n", pFormat[0]);
2403 RpcRaiseException(RPC_S_INTERNAL_ERROR);
2407 alignment = pFormat[1] + 1;
2409 def = *(const WORD*)&pFormat[2];
2412 pFormat = ComputeConformance(pStubMsg, pMemory, pFormat, def);
2413 TRACE("conformance = %ld\n", pStubMsg->MaxCount);
2414 SizeConformance(pStubMsg);
2416 variance_present = IsConformanceOrVariancePresent(pFormat);
2417 pFormat = ComputeVariance(pStubMsg, pMemory, pFormat, pStubMsg->MaxCount);
2418 TRACE("variance = %ld\n", pStubMsg->ActualCount);
2420 if (variance_present)
2421 SizeVariance(pStubMsg);
2423 ALIGN_LENGTH(pStubMsg->BufferLength, alignment);
2425 count = pStubMsg->ActualCount;
2426 for (i = 0; i < count; i++)
2427 pMemory = ComplexBufferSize(pStubMsg, pMemory, pFormat, NULL);
2430 /***********************************************************************
2431 * NdrComplexArrayMemorySize [RPCRT4.@]
2433 unsigned long WINAPI NdrComplexArrayMemorySize(PMIDL_STUB_MESSAGE pStubMsg,
2434 PFORMAT_STRING pFormat)
2436 ULONG i, count, esize;
2437 unsigned char alignment;
2438 unsigned char *Buffer;
2439 unsigned long SavedMemorySize;
2440 unsigned long MemorySize;
2442 TRACE("(%p,%p)\n", pStubMsg, pFormat);
2444 if (pFormat[0] != RPC_FC_BOGUS_ARRAY)
2446 ERR("invalid format type %x\n", pFormat[0]);
2447 RpcRaiseException(RPC_S_INTERNAL_ERROR);
2451 alignment = pFormat[1] + 1;
2455 pFormat = ReadConformance(pStubMsg, pFormat);
2456 pFormat = ReadVariance(pStubMsg, pFormat);
2458 ALIGN_POINTER(pStubMsg->Buffer, alignment);
2460 SavedMemorySize = pStubMsg->MemorySize;
2462 Buffer = pStubMsg->Buffer;
2463 esize = ComplexStructMemorySize(pStubMsg, pFormat);
2464 pStubMsg->Buffer = Buffer;
2466 MemorySize = esize * pStubMsg->MaxCount;
2468 count = pStubMsg->ActualCount;
2469 for (i = 0; i < count; i++)
2470 ComplexStructMemorySize(pStubMsg, pFormat);
2472 pStubMsg->MemorySize = SavedMemorySize;
2474 pStubMsg->MemorySize += MemorySize;
2478 /***********************************************************************
2479 * NdrComplexArrayFree [RPCRT4.@]
2481 void WINAPI NdrComplexArrayFree(PMIDL_STUB_MESSAGE pStubMsg,
2482 unsigned char *pMemory,
2483 PFORMAT_STRING pFormat)
2485 ULONG i, count, def;
2487 TRACE("(%p,%p,%p)\n", pStubMsg, pMemory, pFormat);
2489 if (pFormat[0] != RPC_FC_BOGUS_ARRAY)
2491 ERR("invalid format type %x\n", pFormat[0]);
2492 RpcRaiseException(RPC_S_INTERNAL_ERROR);
2496 def = *(const WORD*)&pFormat[2];
2499 pFormat = ComputeConformance(pStubMsg, pMemory, pFormat, def);
2500 TRACE("conformance = %ld\n", pStubMsg->MaxCount);
2502 pFormat = ComputeVariance(pStubMsg, pMemory, pFormat, pStubMsg->MaxCount);
2503 TRACE("variance = %ld\n", pStubMsg->ActualCount);
2505 count = pStubMsg->ActualCount;
2506 for (i = 0; i < count; i++)
2507 pMemory = ComplexFree(pStubMsg, pMemory, pFormat, NULL);
2510 unsigned long UserMarshalFlags(PMIDL_STUB_MESSAGE pStubMsg)
2512 return MAKELONG(pStubMsg->dwDestContext,
2513 pStubMsg->RpcMsg->DataRepresentation);
2516 /***********************************************************************
2517 * NdrUserMarshalMarshall [RPCRT4.@]
2519 unsigned char * WINAPI NdrUserMarshalMarshall(PMIDL_STUB_MESSAGE pStubMsg,
2520 unsigned char *pMemory,
2521 PFORMAT_STRING pFormat)
2523 /* unsigned flags = pFormat[1]; */
2524 unsigned index = *(const WORD*)&pFormat[2];
2525 unsigned long uflag = UserMarshalFlags(pStubMsg);
2526 TRACE("(%p,%p,%p)\n", pStubMsg, pMemory, pFormat);
2527 TRACE("index=%d\n", index);
2530 pStubMsg->StubDesc->aUserMarshalQuadruple[index].pfnMarshall(
2531 &uflag, pStubMsg->Buffer, pMemory);
2533 STD_OVERFLOW_CHECK(pStubMsg);
2538 /***********************************************************************
2539 * NdrUserMarshalUnmarshall [RPCRT4.@]
2541 unsigned char * WINAPI NdrUserMarshalUnmarshall(PMIDL_STUB_MESSAGE pStubMsg,
2542 unsigned char **ppMemory,
2543 PFORMAT_STRING pFormat,
2544 unsigned char fMustAlloc)
2546 /* unsigned flags = pFormat[1];*/
2547 unsigned index = *(const WORD*)&pFormat[2];
2548 DWORD memsize = *(const WORD*)&pFormat[4];
2549 unsigned long uflag = UserMarshalFlags(pStubMsg);
2550 TRACE("(%p,%p,%p,%d)\n", pStubMsg, ppMemory, pFormat, fMustAlloc);
2551 TRACE("index=%d\n", index);
2553 if (fMustAlloc || !*ppMemory)
2554 *ppMemory = NdrAllocate(pStubMsg, memsize);
2557 pStubMsg->StubDesc->aUserMarshalQuadruple[index].pfnUnmarshall(
2558 &uflag, pStubMsg->Buffer, *ppMemory);
2563 /***********************************************************************
2564 * NdrUserMarshalBufferSize [RPCRT4.@]
2566 void WINAPI NdrUserMarshalBufferSize(PMIDL_STUB_MESSAGE pStubMsg,
2567 unsigned char *pMemory,
2568 PFORMAT_STRING pFormat)
2570 /* unsigned flags = pFormat[1];*/
2571 unsigned index = *(const WORD*)&pFormat[2];
2572 DWORD bufsize = *(const WORD*)&pFormat[6];
2573 unsigned long uflag = UserMarshalFlags(pStubMsg);
2574 TRACE("(%p,%p,%p)\n", pStubMsg, pMemory, pFormat);
2575 TRACE("index=%d\n", index);
2578 TRACE("size=%ld\n", bufsize);
2579 pStubMsg->BufferLength += bufsize;
2583 pStubMsg->BufferLength =
2584 pStubMsg->StubDesc->aUserMarshalQuadruple[index].pfnBufferSize(
2585 &uflag, pStubMsg->BufferLength, pMemory);
2588 /***********************************************************************
2589 * NdrUserMarshalMemorySize [RPCRT4.@]
2591 unsigned long WINAPI NdrUserMarshalMemorySize(PMIDL_STUB_MESSAGE pStubMsg,
2592 PFORMAT_STRING pFormat)
2594 unsigned index = *(const WORD*)&pFormat[2];
2595 /* DWORD memsize = *(const WORD*)&pFormat[4]; */
2596 FIXME("(%p,%p): stub\n", pStubMsg, pFormat);
2597 TRACE("index=%d\n", index);
2602 /***********************************************************************
2603 * NdrUserMarshalFree [RPCRT4.@]
2605 void WINAPI NdrUserMarshalFree(PMIDL_STUB_MESSAGE pStubMsg,
2606 unsigned char *pMemory,
2607 PFORMAT_STRING pFormat)
2609 /* unsigned flags = pFormat[1]; */
2610 unsigned index = *(const WORD*)&pFormat[2];
2611 unsigned long uflag = UserMarshalFlags(pStubMsg);
2612 TRACE("(%p,%p,%p)\n", pStubMsg, pMemory, pFormat);
2613 TRACE("index=%d\n", index);
2615 pStubMsg->StubDesc->aUserMarshalQuadruple[index].pfnFree(
2619 /***********************************************************************
2620 * NdrClearOutParameters [RPCRT4.@]
2622 void WINAPI NdrClearOutParameters(PMIDL_STUB_MESSAGE pStubMsg,
2623 PFORMAT_STRING pFormat,
2626 FIXME("(%p,%p,%p): stub\n", pStubMsg, pFormat, ArgAddr);
2629 /***********************************************************************
2630 * NdrConvert [RPCRT4.@]
2632 void WINAPI NdrConvert( PMIDL_STUB_MESSAGE pStubMsg, PFORMAT_STRING pFormat )
2634 FIXME("(pStubMsg == ^%p, pFormat == ^%p): stub.\n", pStubMsg, pFormat);
2635 /* FIXME: since this stub doesn't do any converting, the proper behavior
2636 is to raise an exception */
2639 /***********************************************************************
2640 * NdrConvert2 [RPCRT4.@]
2642 void WINAPI NdrConvert2( PMIDL_STUB_MESSAGE pStubMsg, PFORMAT_STRING pFormat, long NumberParams )
2644 FIXME("(pStubMsg == ^%p, pFormat == ^%p, NumberParams == %ld): stub.\n",
2645 pStubMsg, pFormat, NumberParams);
2646 /* FIXME: since this stub doesn't do any converting, the proper behavior
2647 is to raise an exception */
2650 typedef struct _NDR_CSTRUCT_FORMAT
2653 unsigned char alignment;
2654 unsigned short memory_size;
2655 short offset_to_array_description;
2656 } NDR_CSTRUCT_FORMAT, NDR_CVSTRUCT_FORMAT;
2658 /***********************************************************************
2659 * NdrConformantStructMarshall [RPCRT4.@]
2661 unsigned char * WINAPI NdrConformantStructMarshall(PMIDL_STUB_MESSAGE pStubMsg,
2662 unsigned char *pMemory,
2663 PFORMAT_STRING pFormat)
2665 const NDR_CSTRUCT_FORMAT * pCStructFormat = (NDR_CSTRUCT_FORMAT*)pFormat;
2666 PFORMAT_STRING pCArrayFormat;
2669 TRACE("(%p, %p, %p)\n", pStubMsg, pMemory, pFormat);
2671 pFormat += sizeof(NDR_CSTRUCT_FORMAT);
2672 if ((pCStructFormat->type != RPC_FC_CPSTRUCT) && (pCStructFormat->type != RPC_FC_CSTRUCT))
2674 ERR("invalid format type %x\n", pCStructFormat->type);
2675 RpcRaiseException(RPC_S_INTERNAL_ERROR);
2679 pCArrayFormat = (unsigned char*)&pCStructFormat->offset_to_array_description +
2680 pCStructFormat->offset_to_array_description;
2681 if (*pCArrayFormat != RPC_FC_CARRAY)
2683 ERR("invalid array format type %x\n", pCStructFormat->type);
2684 RpcRaiseException(RPC_S_INTERNAL_ERROR);
2687 esize = *(const WORD*)(pCArrayFormat+2);
2689 ComputeConformance(pStubMsg, pMemory + pCStructFormat->memory_size,
2690 pCArrayFormat + 4, 0);
2692 WriteConformance(pStubMsg);
2694 ALIGN_POINTER(pStubMsg->Buffer, pCStructFormat->alignment + 1);
2696 TRACE("memory_size = %d\n", pCStructFormat->memory_size);
2698 /* copy constant sized part of struct */
2699 pStubMsg->BufferMark = pStubMsg->Buffer;
2700 memcpy(pStubMsg->Buffer, pMemory, pCStructFormat->memory_size + pStubMsg->MaxCount * esize);
2701 pStubMsg->Buffer += pCStructFormat->memory_size + pStubMsg->MaxCount * esize;
2703 if (pCStructFormat->type == RPC_FC_CPSTRUCT)
2704 EmbeddedPointerMarshall(pStubMsg, pMemory, pFormat);
2706 STD_OVERFLOW_CHECK(pStubMsg);
2711 /***********************************************************************
2712 * NdrConformantStructUnmarshall [RPCRT4.@]
2714 unsigned char * WINAPI NdrConformantStructUnmarshall(PMIDL_STUB_MESSAGE pStubMsg,
2715 unsigned char **ppMemory,
2716 PFORMAT_STRING pFormat,
2717 unsigned char fMustAlloc)
2719 const NDR_CSTRUCT_FORMAT * pCStructFormat = (NDR_CSTRUCT_FORMAT*)pFormat;
2720 PFORMAT_STRING pCArrayFormat;
2723 TRACE("(%p, %p, %p, %d)\n", pStubMsg, ppMemory, pFormat, fMustAlloc);
2725 pFormat += sizeof(NDR_CSTRUCT_FORMAT);
2726 if ((pCStructFormat->type != RPC_FC_CPSTRUCT) && (pCStructFormat->type != RPC_FC_CSTRUCT))
2728 ERR("invalid format type %x\n", pCStructFormat->type);
2729 RpcRaiseException(RPC_S_INTERNAL_ERROR);
2732 pCArrayFormat = (unsigned char*)&pCStructFormat->offset_to_array_description +
2733 pCStructFormat->offset_to_array_description;
2734 if (*pCArrayFormat != RPC_FC_CARRAY)
2736 ERR("invalid array format type %x\n", pCStructFormat->type);
2737 RpcRaiseException(RPC_S_INTERNAL_ERROR);
2740 esize = *(const WORD*)(pCArrayFormat+2);
2742 pCArrayFormat = ReadConformance(pStubMsg, pCArrayFormat + 4);
2744 ALIGN_POINTER(pStubMsg->Buffer, pCStructFormat->alignment + 1);
2746 TRACE("memory_size = %d\n", pCStructFormat->memory_size);
2748 /* work out how much memory to allocate if we need to do so */
2749 if (!*ppMemory || fMustAlloc)
2751 SIZE_T size = pCStructFormat->memory_size + pStubMsg->MaxCount * esize;
2752 *ppMemory = NdrAllocate(pStubMsg, size);
2755 /* now copy the data */
2756 pStubMsg->BufferMark = pStubMsg->Buffer;
2757 memcpy(*ppMemory, pStubMsg->Buffer, pCStructFormat->memory_size + pStubMsg->MaxCount * esize);
2758 pStubMsg->Buffer += pCStructFormat->memory_size + pStubMsg->MaxCount * esize;
2760 if (pCStructFormat->type == RPC_FC_CPSTRUCT)
2761 EmbeddedPointerUnmarshall(pStubMsg, ppMemory, pFormat, fMustAlloc);
2766 /***********************************************************************
2767 * NdrConformantStructBufferSize [RPCRT4.@]
2769 void WINAPI NdrConformantStructBufferSize(PMIDL_STUB_MESSAGE pStubMsg,
2770 unsigned char *pMemory,
2771 PFORMAT_STRING pFormat)
2773 const NDR_CSTRUCT_FORMAT * pCStructFormat = (NDR_CSTRUCT_FORMAT*)pFormat;
2774 PFORMAT_STRING pCArrayFormat;
2777 TRACE("(%p, %p, %p)\n", pStubMsg, pMemory, pFormat);
2779 pFormat += sizeof(NDR_CSTRUCT_FORMAT);
2780 if ((pCStructFormat->type != RPC_FC_CPSTRUCT) && (pCStructFormat->type != RPC_FC_CSTRUCT))
2782 ERR("invalid format type %x\n", pCStructFormat->type);
2783 RpcRaiseException(RPC_S_INTERNAL_ERROR);
2786 pCArrayFormat = (unsigned char*)&pCStructFormat->offset_to_array_description +
2787 pCStructFormat->offset_to_array_description;
2788 if (*pCArrayFormat != RPC_FC_CARRAY)
2790 ERR("invalid array format type %x\n", pCStructFormat->type);
2791 RpcRaiseException(RPC_S_INTERNAL_ERROR);
2794 esize = *(const WORD*)(pCArrayFormat+2);
2796 pCArrayFormat = ComputeConformance(pStubMsg, pMemory + pCStructFormat->memory_size, pCArrayFormat+4, 0);
2797 SizeConformance(pStubMsg);
2799 ALIGN_LENGTH(pStubMsg->BufferLength, pCStructFormat->alignment + 1);
2801 TRACE("memory_size = %d\n", pCStructFormat->memory_size);
2803 pStubMsg->BufferLength += pCStructFormat->memory_size + esize * pStubMsg->MaxCount;
2805 if (pCStructFormat->type == RPC_FC_CPSTRUCT)
2806 EmbeddedPointerBufferSize(pStubMsg, pMemory, pFormat);
2809 /***********************************************************************
2810 * NdrConformantStructMemorySize [RPCRT4.@]
2812 unsigned long WINAPI NdrConformantStructMemorySize(PMIDL_STUB_MESSAGE pStubMsg,
2813 PFORMAT_STRING pFormat)
2819 /***********************************************************************
2820 * NdrConformantStructFree [RPCRT4.@]
2822 void WINAPI NdrConformantStructFree(PMIDL_STUB_MESSAGE pStubMsg,
2823 unsigned char *pMemory,
2824 PFORMAT_STRING pFormat)
2829 /***********************************************************************
2830 * NdrConformantVaryingStructMarshall [RPCRT4.@]
2832 unsigned char * WINAPI NdrConformantVaryingStructMarshall(PMIDL_STUB_MESSAGE pStubMsg,
2833 unsigned char *pMemory,
2834 PFORMAT_STRING pFormat)
2836 const NDR_CVSTRUCT_FORMAT * pCVStructFormat = (NDR_CVSTRUCT_FORMAT*)pFormat;
2837 PFORMAT_STRING pCVArrayFormat;
2840 TRACE("(%p, %p, %p)\n", pStubMsg, pMemory, pFormat);
2842 pFormat += sizeof(NDR_CVSTRUCT_FORMAT);
2843 if (pCVStructFormat->type != RPC_FC_CVSTRUCT)
2845 ERR("invalid format type %x\n", pCVStructFormat->type);
2846 RpcRaiseException(RPC_S_INTERNAL_ERROR);
2850 pCVArrayFormat = (unsigned char*)&pCVStructFormat->offset_to_array_description +
2851 pCVStructFormat->offset_to_array_description;
2852 switch (*pCVArrayFormat)
2854 case RPC_FC_CVARRAY:
2855 esize = *(const WORD*)(pCVArrayFormat+2);
2857 pCVArrayFormat = ComputeConformance(pStubMsg, pMemory + pCVStructFormat->memory_size,
2858 pCVArrayFormat + 4, 0);
2859 pCVArrayFormat = ComputeVariance(pStubMsg, pMemory + pCVStructFormat->memory_size,
2862 case RPC_FC_C_CSTRING:
2863 TRACE("string=%s\n", debugstr_a((char*)pMemory + pCVStructFormat->memory_size));
2864 pStubMsg->ActualCount = strlen((char*)pMemory + pCVStructFormat->memory_size)+1;
2865 esize = sizeof(char);
2866 if (pCVArrayFormat[1] == RPC_FC_STRING_SIZED)
2867 pCVArrayFormat = ComputeConformance(pStubMsg, pMemory + pCVStructFormat->memory_size,
2868 pCVArrayFormat + 2, 0);
2870 pStubMsg->MaxCount = pStubMsg->ActualCount;
2872 case RPC_FC_C_WSTRING:
2873 TRACE("string=%s\n", debugstr_w((LPWSTR)pMemory + pCVStructFormat->memory_size));
2874 pStubMsg->ActualCount = strlenW((LPWSTR)pMemory + pCVStructFormat->memory_size)+1;
2875 esize = sizeof(WCHAR);
2876 if (pCVArrayFormat[1] == RPC_FC_STRING_SIZED)
2877 pCVArrayFormat = ComputeConformance(pStubMsg, pMemory + pCVStructFormat->memory_size,
2878 pCVArrayFormat + 2, 0);
2880 pStubMsg->MaxCount = pStubMsg->ActualCount;
2883 ERR("invalid array format type %x\n", *pCVArrayFormat);
2884 RpcRaiseException(RPC_S_INTERNAL_ERROR);
2888 WriteConformance(pStubMsg);
2890 ALIGN_POINTER(pStubMsg->Buffer, pCVStructFormat->alignment + 1);
2892 TRACE("memory_size = %d\n", pCVStructFormat->memory_size);
2894 /* write constant sized part */
2895 pStubMsg->BufferMark = pStubMsg->Buffer;
2896 memcpy(pStubMsg->Buffer, pMemory, pCVStructFormat->memory_size);
2897 pStubMsg->Buffer += pCVStructFormat->memory_size;
2899 WriteVariance(pStubMsg);
2901 /* write array part */
2902 memcpy(pStubMsg->Buffer, pMemory + pCVStructFormat->memory_size, pStubMsg->ActualCount * esize);
2903 pStubMsg->Buffer += pStubMsg->ActualCount * esize;
2905 EmbeddedPointerMarshall(pStubMsg, pMemory, pFormat);
2907 STD_OVERFLOW_CHECK(pStubMsg);
2912 /***********************************************************************
2913 * NdrConformantVaryingStructUnmarshall [RPCRT4.@]
2915 unsigned char * WINAPI NdrConformantVaryingStructUnmarshall(PMIDL_STUB_MESSAGE pStubMsg,
2916 unsigned char **ppMemory,
2917 PFORMAT_STRING pFormat,
2918 unsigned char fMustAlloc)
2920 const NDR_CVSTRUCT_FORMAT * pCVStructFormat = (NDR_CVSTRUCT_FORMAT*)pFormat;
2921 PFORMAT_STRING pCVArrayFormat;
2923 unsigned char cvarray_type;
2925 TRACE("(%p, %p, %p, %d)\n", pStubMsg, ppMemory, pFormat, fMustAlloc);
2927 pFormat += sizeof(NDR_CVSTRUCT_FORMAT);
2928 if (pCVStructFormat->type != RPC_FC_CVSTRUCT)
2930 ERR("invalid format type %x\n", pCVStructFormat->type);
2931 RpcRaiseException(RPC_S_INTERNAL_ERROR);
2935 pCVArrayFormat = (unsigned char*)&pCVStructFormat->offset_to_array_description +
2936 pCVStructFormat->offset_to_array_description;
2937 cvarray_type = *pCVArrayFormat;
2938 switch (cvarray_type)
2940 case RPC_FC_CVARRAY:
2941 esize = *(const WORD*)(pCVArrayFormat+2);
2942 pCVArrayFormat = ReadConformance(pStubMsg, pCVArrayFormat + 4);
2944 case RPC_FC_C_CSTRING:
2945 esize = sizeof(char);
2946 if (pCVArrayFormat[1] == RPC_FC_STRING_SIZED)
2947 pCVArrayFormat = ReadConformance(pStubMsg, pCVArrayFormat + 2);
2949 pCVArrayFormat = ReadConformance(pStubMsg, NULL);
2951 case RPC_FC_C_WSTRING:
2952 esize = sizeof(WCHAR);
2953 if (pCVArrayFormat[1] == RPC_FC_STRING_SIZED)
2954 pCVArrayFormat = ReadConformance(pStubMsg, pCVArrayFormat + 2);
2956 pCVArrayFormat = ReadConformance(pStubMsg, NULL);
2959 ERR("invalid array format type %x\n", *pCVArrayFormat);
2960 RpcRaiseException(RPC_S_INTERNAL_ERROR);
2964 ALIGN_POINTER(pStubMsg->Buffer, pCVStructFormat->alignment + 1);
2966 TRACE("memory_size = %d\n", pCVStructFormat->memory_size);
2968 /* work out how much memory to allocate if we need to do so */
2969 if (!*ppMemory || fMustAlloc)
2971 SIZE_T size = pCVStructFormat->memory_size + pStubMsg->MaxCount * esize;
2972 *ppMemory = NdrAllocate(pStubMsg, size);
2975 /* copy the constant data */
2976 pStubMsg->BufferMark = pStubMsg->Buffer;
2977 memcpy(*ppMemory, pStubMsg->Buffer, pCVStructFormat->memory_size);
2978 pStubMsg->Buffer += pCVStructFormat->memory_size;
2980 pCVArrayFormat = ReadVariance(pStubMsg, pCVArrayFormat);
2982 /* copy the array data */
2983 memcpy(*ppMemory + pCVStructFormat->memory_size, pStubMsg->Buffer,
2984 pStubMsg->ActualCount * esize);
2985 pStubMsg->Buffer += pStubMsg->ActualCount * esize;
2987 if (cvarray_type == RPC_FC_C_CSTRING)
2988 TRACE("string=%s\n", debugstr_a((char *)(*ppMemory + pCVStructFormat->memory_size)));
2989 else if (cvarray_type == RPC_FC_C_WSTRING)
2990 TRACE("string=%s\n", debugstr_w((WCHAR *)(*ppMemory + pCVStructFormat->memory_size)));
2992 EmbeddedPointerUnmarshall(pStubMsg, ppMemory, pFormat, fMustAlloc);
2997 /***********************************************************************
2998 * NdrConformantVaryingStructBufferSize [RPCRT4.@]
3000 void WINAPI NdrConformantVaryingStructBufferSize(PMIDL_STUB_MESSAGE pStubMsg,
3001 unsigned char *pMemory,
3002 PFORMAT_STRING pFormat)
3004 const NDR_CVSTRUCT_FORMAT * pCVStructFormat = (NDR_CVSTRUCT_FORMAT*)pFormat;
3005 PFORMAT_STRING pCVArrayFormat;
3008 TRACE("(%p, %p, %p)\n", pStubMsg, pMemory, pFormat);
3010 pFormat += sizeof(NDR_CVSTRUCT_FORMAT);
3011 if (pCVStructFormat->type != RPC_FC_CVSTRUCT)
3013 ERR("invalid format type %x\n", pCVStructFormat->type);
3014 RpcRaiseException(RPC_S_INTERNAL_ERROR);
3018 pCVArrayFormat = (unsigned char*)&pCVStructFormat->offset_to_array_description +
3019 pCVStructFormat->offset_to_array_description;
3020 switch (*pCVArrayFormat)
3022 case RPC_FC_CVARRAY:
3023 esize = *(const WORD*)(pCVArrayFormat+2);
3025 pCVArrayFormat = ComputeConformance(pStubMsg, pMemory + pCVStructFormat->memory_size,
3026 pCVArrayFormat + 4, 0);
3027 pCVArrayFormat = ComputeVariance(pStubMsg, pMemory + pCVStructFormat->memory_size,
3028 pCVArrayFormat + 4, 0);
3030 case RPC_FC_C_CSTRING:
3031 TRACE("string=%s\n", debugstr_a((char*)pMemory + pCVStructFormat->memory_size));
3032 pStubMsg->ActualCount = strlen((char*)pMemory + pCVStructFormat->memory_size)+1;
3033 esize = sizeof(char);
3034 if (pCVArrayFormat[1] == RPC_FC_STRING_SIZED)
3035 pCVArrayFormat = ComputeConformance(pStubMsg, pMemory + pCVStructFormat->memory_size,
3036 pCVArrayFormat + 2, 0);
3038 pStubMsg->MaxCount = pStubMsg->ActualCount;
3040 case RPC_FC_C_WSTRING:
3041 TRACE("string=%s\n", debugstr_w((LPWSTR)pMemory + pCVStructFormat->memory_size));
3042 pStubMsg->ActualCount = strlenW((LPWSTR)pMemory + pCVStructFormat->memory_size)+1;
3043 esize = sizeof(WCHAR);
3044 if (pCVArrayFormat[1] == RPC_FC_STRING_SIZED)
3045 pCVArrayFormat = ComputeConformance(pStubMsg, pMemory + pCVStructFormat->memory_size,
3046 pCVArrayFormat + 2, 0);
3048 pStubMsg->MaxCount = pStubMsg->ActualCount;
3051 ERR("invalid array format type %x\n", *pCVArrayFormat);
3052 RpcRaiseException(RPC_S_INTERNAL_ERROR);
3056 SizeConformance(pStubMsg);
3058 ALIGN_LENGTH(pStubMsg->BufferLength, pCVStructFormat->alignment + 1);
3060 TRACE("memory_size = %d\n", pCVStructFormat->memory_size);
3062 pStubMsg->BufferLength += pCVStructFormat->memory_size;
3063 SizeVariance(pStubMsg);
3064 pStubMsg->BufferLength += esize * pStubMsg->MaxCount;
3066 EmbeddedPointerBufferSize(pStubMsg, pMemory, pFormat);
3069 /***********************************************************************
3070 * NdrConformantVaryingStructMemorySize [RPCRT4.@]
3072 unsigned long WINAPI NdrConformantVaryingStructMemorySize(PMIDL_STUB_MESSAGE pStubMsg,
3073 PFORMAT_STRING pFormat)
3075 const NDR_CVSTRUCT_FORMAT * pCVStructFormat = (NDR_CVSTRUCT_FORMAT*)pFormat;
3076 PFORMAT_STRING pCVArrayFormat;
3078 unsigned char cvarray_type;
3080 TRACE("(%p, %p)\n", pStubMsg, pFormat);
3082 pFormat += sizeof(NDR_CVSTRUCT_FORMAT);
3083 if (pCVStructFormat->type != RPC_FC_CVSTRUCT)
3085 ERR("invalid format type %x\n", pCVStructFormat->type);
3086 RpcRaiseException(RPC_S_INTERNAL_ERROR);
3090 pCVArrayFormat = (unsigned char*)&pCVStructFormat->offset_to_array_description +
3091 pCVStructFormat->offset_to_array_description;
3092 cvarray_type = *pCVArrayFormat;
3093 switch (cvarray_type)
3095 case RPC_FC_CVARRAY:
3096 esize = *(const WORD*)(pCVArrayFormat+2);
3097 pCVArrayFormat = ReadConformance(pStubMsg, pCVArrayFormat + 4);
3099 case RPC_FC_C_CSTRING:
3100 esize = sizeof(char);
3101 if (pCVArrayFormat[1] == RPC_FC_STRING_SIZED)
3102 pCVArrayFormat = ReadConformance(pStubMsg, pCVArrayFormat + 2);
3104 pCVArrayFormat = ReadConformance(pStubMsg, NULL);
3106 case RPC_FC_C_WSTRING:
3107 esize = sizeof(WCHAR);
3108 if (pCVArrayFormat[1] == RPC_FC_STRING_SIZED)
3109 pCVArrayFormat = ReadConformance(pStubMsg, pCVArrayFormat + 2);
3111 pCVArrayFormat = ReadConformance(pStubMsg, NULL);
3114 ERR("invalid array format type %x\n", *pCVArrayFormat);
3115 RpcRaiseException(RPC_S_INTERNAL_ERROR);
3119 ALIGN_POINTER(pStubMsg->Buffer, pCVStructFormat->alignment + 1);
3121 TRACE("memory_size = %d\n", pCVStructFormat->memory_size);
3123 pStubMsg->Buffer += pCVStructFormat->memory_size;
3124 pCVArrayFormat = ReadVariance(pStubMsg, pCVArrayFormat);
3125 pStubMsg->Buffer += pCVStructFormat->memory_size + pStubMsg->ActualCount * esize;
3127 pStubMsg->MemorySize += pCVStructFormat->memory_size + pStubMsg->MaxCount * esize;
3129 EmbeddedPointerMemorySize(pStubMsg, pFormat);
3131 return pCVStructFormat->memory_size + pStubMsg->MaxCount * esize;
3134 /***********************************************************************
3135 * NdrConformantVaryingStructFree [RPCRT4.@]
3137 void WINAPI NdrConformantVaryingStructFree(PMIDL_STUB_MESSAGE pStubMsg,
3138 unsigned char *pMemory,
3139 PFORMAT_STRING pFormat)
3141 const NDR_CVSTRUCT_FORMAT * pCVStructFormat = (NDR_CVSTRUCT_FORMAT*)pFormat;
3142 PFORMAT_STRING pCVArrayFormat;
3145 TRACE("(%p, %p, %p)\n", pStubMsg, pMemory, pFormat);
3147 pFormat += sizeof(NDR_CVSTRUCT_FORMAT);
3148 if (pCVStructFormat->type != RPC_FC_CVSTRUCT)
3150 ERR("invalid format type %x\n", pCVStructFormat->type);
3151 RpcRaiseException(RPC_S_INTERNAL_ERROR);
3155 pCVArrayFormat = (unsigned char*)&pCVStructFormat->offset_to_array_description +
3156 pCVStructFormat->offset_to_array_description;
3157 switch (*pCVArrayFormat)
3159 case RPC_FC_CVARRAY:
3160 esize = *(const WORD*)(pCVArrayFormat+2);
3162 pCVArrayFormat = ComputeConformance(pStubMsg, pMemory + pCVStructFormat->memory_size,
3163 pCVArrayFormat + 4, 0);
3164 pCVArrayFormat = ComputeVariance(pStubMsg, pMemory + pCVStructFormat->memory_size,
3167 case RPC_FC_C_CSTRING:
3168 TRACE("string=%s\n", debugstr_a((char*)pMemory + pCVStructFormat->memory_size));
3169 pStubMsg->ActualCount = strlen((char*)pMemory + pCVStructFormat->memory_size)+1;
3170 esize = sizeof(char);
3171 if (pCVArrayFormat[1] == RPC_FC_STRING_SIZED)
3172 pCVArrayFormat = ComputeConformance(pStubMsg, pMemory + pCVStructFormat->memory_size,
3173 pCVArrayFormat + 2, 0);
3175 pStubMsg->MaxCount = pStubMsg->ActualCount;
3177 case RPC_FC_C_WSTRING:
3178 TRACE("string=%s\n", debugstr_w((LPWSTR)pMemory + pCVStructFormat->memory_size));
3179 pStubMsg->ActualCount = strlenW((LPWSTR)pMemory + pCVStructFormat->memory_size)+1;
3180 esize = sizeof(WCHAR);
3181 if (pCVArrayFormat[1] == RPC_FC_STRING_SIZED)
3182 pCVArrayFormat = ComputeConformance(pStubMsg, pMemory + pCVStructFormat->memory_size,
3183 pCVArrayFormat + 2, 0);
3185 pStubMsg->MaxCount = pStubMsg->ActualCount;
3188 ERR("invalid array format type %x\n", *pCVArrayFormat);
3189 RpcRaiseException(RPC_S_INTERNAL_ERROR);
3193 TRACE("memory_size = %d\n", pCVStructFormat->memory_size);
3195 EmbeddedPointerFree(pStubMsg, pMemory, pFormat);
3201 unsigned char alignment;
3202 unsigned short total_size;
3203 } NDR_SMFARRAY_FORMAT;
3208 unsigned char alignment;
3209 unsigned long total_size;
3210 } NDR_LGFARRAY_FORMAT;
3212 /***********************************************************************
3213 * NdrFixedArrayMarshall [RPCRT4.@]
3215 unsigned char * WINAPI NdrFixedArrayMarshall(PMIDL_STUB_MESSAGE pStubMsg,
3216 unsigned char *pMemory,
3217 PFORMAT_STRING pFormat)
3219 const NDR_SMFARRAY_FORMAT *pSmFArrayFormat = (const NDR_SMFARRAY_FORMAT *)pFormat;
3220 unsigned long total_size;
3222 TRACE("(%p, %p, %p)\n", pStubMsg, pMemory, pFormat);
3224 if ((pSmFArrayFormat->type != RPC_FC_SMFARRAY) &&
3225 (pSmFArrayFormat->type != RPC_FC_LGFARRAY))
3227 ERR("invalid format type %x\n", pSmFArrayFormat->type);
3228 RpcRaiseException(RPC_S_INTERNAL_ERROR);
3232 ALIGN_POINTER(pStubMsg->Buffer, pSmFArrayFormat->alignment + 1);
3234 if (pSmFArrayFormat->type == RPC_FC_SMFARRAY)
3236 total_size = pSmFArrayFormat->total_size;
3237 pFormat = (unsigned char *)(pSmFArrayFormat + 1);
3241 const NDR_LGFARRAY_FORMAT *pLgFArrayFormat = (const NDR_LGFARRAY_FORMAT *)pFormat;
3242 total_size = pLgFArrayFormat->total_size;
3243 pFormat = (unsigned char *)(pLgFArrayFormat + 1);
3245 memcpy(pStubMsg->Buffer, pMemory, total_size);
3246 pStubMsg->Buffer += total_size;
3248 pFormat = EmbeddedPointerMarshall(pStubMsg, pMemory, pFormat);
3253 /***********************************************************************
3254 * NdrFixedArrayUnmarshall [RPCRT4.@]
3256 unsigned char * WINAPI NdrFixedArrayUnmarshall(PMIDL_STUB_MESSAGE pStubMsg,
3257 unsigned char **ppMemory,
3258 PFORMAT_STRING pFormat,
3259 unsigned char fMustAlloc)
3261 const NDR_SMFARRAY_FORMAT *pSmFArrayFormat = (const NDR_SMFARRAY_FORMAT *)pFormat;
3262 unsigned long total_size;
3264 TRACE("(%p, %p, %p, %d)\n", pStubMsg, ppMemory, pFormat, fMustAlloc);
3266 if ((pSmFArrayFormat->type != RPC_FC_SMFARRAY) &&
3267 (pSmFArrayFormat->type != RPC_FC_LGFARRAY))
3269 ERR("invalid format type %x\n", pSmFArrayFormat->type);
3270 RpcRaiseException(RPC_S_INTERNAL_ERROR);
3274 ALIGN_POINTER(pStubMsg->Buffer, pSmFArrayFormat->alignment + 1);
3276 if (pSmFArrayFormat->type == RPC_FC_SMFARRAY)
3278 total_size = pSmFArrayFormat->total_size;
3279 pFormat = (unsigned char *)(pSmFArrayFormat + 1);
3283 const NDR_LGFARRAY_FORMAT *pLgFArrayFormat = (const NDR_LGFARRAY_FORMAT *)pFormat;
3284 total_size = pLgFArrayFormat->total_size;
3285 pFormat = (unsigned char *)(pLgFArrayFormat + 1);
3288 if (fMustAlloc || !*ppMemory)
3289 *ppMemory = NdrAllocate(pStubMsg, total_size);
3290 memcpy(*ppMemory, pStubMsg->Buffer, total_size);
3291 pStubMsg->Buffer += total_size;
3293 pFormat = EmbeddedPointerUnmarshall(pStubMsg, ppMemory, pFormat, fMustAlloc);
3298 /***********************************************************************
3299 * NdrFixedArrayBufferSize [RPCRT4.@]
3301 void WINAPI NdrFixedArrayBufferSize(PMIDL_STUB_MESSAGE pStubMsg,
3302 unsigned char *pMemory,
3303 PFORMAT_STRING pFormat)
3305 const NDR_SMFARRAY_FORMAT *pSmFArrayFormat = (const NDR_SMFARRAY_FORMAT *)pFormat;
3306 unsigned long total_size;
3308 TRACE("(%p, %p, %p)\n", pStubMsg, pMemory, pFormat);
3310 if ((pSmFArrayFormat->type != RPC_FC_SMFARRAY) &&
3311 (pSmFArrayFormat->type != RPC_FC_LGFARRAY))
3313 ERR("invalid format type %x\n", pSmFArrayFormat->type);
3314 RpcRaiseException(RPC_S_INTERNAL_ERROR);
3318 ALIGN_LENGTH(pStubMsg->BufferLength, pSmFArrayFormat->alignment + 1);
3320 if (pSmFArrayFormat->type == RPC_FC_SMFARRAY)
3322 total_size = pSmFArrayFormat->total_size;
3323 pFormat = (unsigned char *)(pSmFArrayFormat + 1);
3327 const NDR_LGFARRAY_FORMAT *pLgFArrayFormat = (const NDR_LGFARRAY_FORMAT *)pFormat;
3328 total_size = pLgFArrayFormat->total_size;
3329 pFormat = (unsigned char *)(pLgFArrayFormat + 1);
3331 pStubMsg->BufferLength += total_size;
3333 EmbeddedPointerBufferSize(pStubMsg, pMemory, pFormat);
3336 /***********************************************************************
3337 * NdrFixedArrayMemorySize [RPCRT4.@]
3339 unsigned long WINAPI NdrFixedArrayMemorySize(PMIDL_STUB_MESSAGE pStubMsg,
3340 PFORMAT_STRING pFormat)
3342 const NDR_SMFARRAY_FORMAT *pSmFArrayFormat = (const NDR_SMFARRAY_FORMAT *)pFormat;
3343 unsigned long total_size;
3345 TRACE("(%p, %p)\n", pStubMsg, pFormat);
3347 if ((pSmFArrayFormat->type != RPC_FC_SMFARRAY) &&
3348 (pSmFArrayFormat->type != RPC_FC_LGFARRAY))
3350 ERR("invalid format type %x\n", pSmFArrayFormat->type);
3351 RpcRaiseException(RPC_S_INTERNAL_ERROR);
3355 ALIGN_POINTER(pStubMsg->Buffer, pSmFArrayFormat->alignment + 1);
3357 if (pSmFArrayFormat->type == RPC_FC_SMFARRAY)
3359 total_size = pSmFArrayFormat->total_size;
3360 pFormat = (unsigned char *)(pSmFArrayFormat + 1);
3364 const NDR_LGFARRAY_FORMAT *pLgFArrayFormat = (const NDR_LGFARRAY_FORMAT *)pFormat;
3365 total_size = pLgFArrayFormat->total_size;
3366 pFormat = (unsigned char *)(pLgFArrayFormat + 1);
3368 pStubMsg->Buffer += total_size;
3369 pStubMsg->MemorySize += total_size;
3371 EmbeddedPointerMemorySize(pStubMsg, pFormat);
3376 /***********************************************************************
3377 * NdrFixedArrayFree [RPCRT4.@]
3379 void WINAPI NdrFixedArrayFree(PMIDL_STUB_MESSAGE pStubMsg,
3380 unsigned char *pMemory,
3381 PFORMAT_STRING pFormat)
3383 const NDR_SMFARRAY_FORMAT *pSmFArrayFormat = (const NDR_SMFARRAY_FORMAT *)pFormat;
3385 TRACE("(%p, %p, %p)\n", pStubMsg, pMemory, pFormat);
3387 if ((pSmFArrayFormat->type != RPC_FC_SMFARRAY) &&
3388 (pSmFArrayFormat->type != RPC_FC_LGFARRAY))
3390 ERR("invalid format type %x\n", pSmFArrayFormat->type);
3391 RpcRaiseException(RPC_S_INTERNAL_ERROR);
3395 if (pSmFArrayFormat->type == RPC_FC_SMFARRAY)
3396 pFormat = (unsigned char *)(pSmFArrayFormat + 1);
3399 const NDR_LGFARRAY_FORMAT *pLgFArrayFormat = (const NDR_LGFARRAY_FORMAT *)pFormat;
3400 pFormat = (unsigned char *)(pLgFArrayFormat + 1);
3403 EmbeddedPointerFree(pStubMsg, pMemory, pFormat);
3406 /***********************************************************************
3407 * NdrVaryingArrayMarshall [RPCRT4.@]
3409 unsigned char * WINAPI NdrVaryingArrayMarshall(PMIDL_STUB_MESSAGE pStubMsg,
3410 unsigned char *pMemory,
3411 PFORMAT_STRING pFormat)
3417 /***********************************************************************
3418 * NdrVaryingArrayUnmarshall [RPCRT4.@]
3420 unsigned char * WINAPI NdrVaryingArrayUnmarshall(PMIDL_STUB_MESSAGE pStubMsg,
3421 unsigned char **ppMemory,
3422 PFORMAT_STRING pFormat,
3423 unsigned char fMustAlloc)
3429 /***********************************************************************
3430 * NdrVaryingArrayBufferSize [RPCRT4.@]
3432 void WINAPI NdrVaryingArrayBufferSize(PMIDL_STUB_MESSAGE pStubMsg,
3433 unsigned char *pMemory,
3434 PFORMAT_STRING pFormat)
3439 /***********************************************************************
3440 * NdrVaryingArrayMemorySize [RPCRT4.@]
3442 unsigned long WINAPI NdrVaryingArrayMemorySize(PMIDL_STUB_MESSAGE pStubMsg,
3443 PFORMAT_STRING pFormat)
3449 /***********************************************************************
3450 * NdrVaryingArrayFree [RPCRT4.@]
3452 void WINAPI NdrVaryingArrayFree(PMIDL_STUB_MESSAGE pStubMsg,
3453 unsigned char *pMemory,
3454 PFORMAT_STRING pFormat)
3459 /***********************************************************************
3460 * NdrEncapsulatedUnionMarshall [RPCRT4.@]
3462 unsigned char * WINAPI NdrEncapsulatedUnionMarshall(PMIDL_STUB_MESSAGE pStubMsg,
3463 unsigned char *pMemory,
3464 PFORMAT_STRING pFormat)
3470 /***********************************************************************
3471 * NdrEncapsulatedUnionUnmarshall [RPCRT4.@]
3473 unsigned char * WINAPI NdrEncapsulatedUnionUnmarshall(PMIDL_STUB_MESSAGE pStubMsg,
3474 unsigned char **ppMemory,
3475 PFORMAT_STRING pFormat,
3476 unsigned char fMustAlloc)
3482 /***********************************************************************
3483 * NdrEncapsulatedUnionBufferSize [RPCRT4.@]
3485 void WINAPI NdrEncapsulatedUnionBufferSize(PMIDL_STUB_MESSAGE pStubMsg,
3486 unsigned char *pMemory,
3487 PFORMAT_STRING pFormat)
3492 /***********************************************************************
3493 * NdrEncapsulatedUnionMemorySize [RPCRT4.@]
3495 unsigned long WINAPI NdrEncapsulatedUnionMemorySize(PMIDL_STUB_MESSAGE pStubMsg,
3496 PFORMAT_STRING pFormat)
3502 /***********************************************************************
3503 * NdrEncapsulatedUnionFree [RPCRT4.@]
3505 void WINAPI NdrEncapsulatedUnionFree(PMIDL_STUB_MESSAGE pStubMsg,
3506 unsigned char *pMemory,
3507 PFORMAT_STRING pFormat)
3512 static PFORMAT_STRING get_arm_offset_from_union_arm_selector(PMIDL_STUB_MESSAGE pStubMsg,
3513 unsigned long discriminant,
3514 PFORMAT_STRING pFormat)
3516 unsigned short num_arms, arm, type;
3518 num_arms = *(const SHORT*)pFormat & 0x0fff;
3520 for(arm = 0; arm < num_arms; arm++)
3522 if(discriminant == *(const ULONG*)pFormat)
3530 type = *(const unsigned short*)pFormat;
3531 TRACE("type %04x\n", type);
3532 if(arm == num_arms) /* default arm extras */
3536 ERR("no arm for 0x%lx and no default case\n", discriminant);
3537 RpcRaiseException(RPC_S_INVALID_TAG);
3542 TRACE("falling back to empty default case for 0x%lx\n", discriminant);
3549 static PFORMAT_STRING get_non_encapsulated_union_arm(PMIDL_STUB_MESSAGE pStubMsg,
3551 PFORMAT_STRING pFormat)
3553 pFormat += *(const SHORT*)pFormat;
3556 return get_arm_offset_from_union_arm_selector(pStubMsg, value, pFormat);
3559 /***********************************************************************
3560 * NdrNonEncapsulatedUnionMarshall [RPCRT4.@]
3562 unsigned char * WINAPI NdrNonEncapsulatedUnionMarshall(PMIDL_STUB_MESSAGE pStubMsg,
3563 unsigned char *pMemory,
3564 PFORMAT_STRING pFormat)
3566 unsigned short type;
3567 unsigned char switch_type;
3569 TRACE("(%p, %p, %p)\n", pStubMsg, pMemory, pFormat);
3572 switch_type = *pFormat;
3575 pFormat = ComputeConformance(pStubMsg, pMemory, pFormat, 0);
3576 TRACE("got switch value 0x%lx\n", pStubMsg->MaxCount);
3577 /* Marshall discriminant */
3578 NdrBaseTypeMarshall(pStubMsg, (unsigned char *)&pStubMsg->MaxCount, &switch_type);
3580 pFormat = get_non_encapsulated_union_arm(pStubMsg, pStubMsg->MaxCount, pFormat);
3584 type = *(const unsigned short*)pFormat;
3585 if((type & 0xff00) == 0x8000)
3587 unsigned char basetype = LOBYTE(type);
3588 return NdrBaseTypeMarshall(pStubMsg, pMemory, &basetype);
3592 PFORMAT_STRING desc = pFormat + *(const SHORT*)pFormat;
3593 NDR_MARSHALL m = NdrMarshaller[*desc & NDR_TABLE_MASK];
3596 unsigned char *saved_buffer = NULL;
3603 saved_buffer = pStubMsg->Buffer;
3604 pStubMsg->Buffer += 4; /* for pointer ID */
3605 PointerMarshall(pStubMsg, saved_buffer, *(unsigned char **)pMemory, desc);
3608 m(pStubMsg, pMemory, desc);
3611 else FIXME("no marshaller for embedded type %02x\n", *desc);
3616 static long unmarshall_discriminant(PMIDL_STUB_MESSAGE pStubMsg,
3617 PFORMAT_STRING *ppFormat)
3619 long discriminant = 0;
3627 discriminant = *(UCHAR *)pStubMsg->Buffer;
3628 pStubMsg->Buffer += sizeof(UCHAR);
3633 ALIGN_POINTER(pStubMsg->Buffer, sizeof(USHORT));
3634 discriminant = *(USHORT *)pStubMsg->Buffer;
3635 pStubMsg->Buffer += sizeof(USHORT);
3639 ALIGN_POINTER(pStubMsg->Buffer, sizeof(ULONG));
3640 discriminant = *(ULONG *)pStubMsg->Buffer;
3641 pStubMsg->Buffer += sizeof(ULONG);
3644 FIXME("Unhandled base type: 0x%02x\n", **ppFormat);
3648 if (pStubMsg->fHasNewCorrDesc)
3652 return discriminant;
3655 /**********************************************************************
3656 * NdrNonEncapsulatedUnionUnmarshall[RPCRT4.@]
3658 unsigned char * WINAPI NdrNonEncapsulatedUnionUnmarshall(PMIDL_STUB_MESSAGE pStubMsg,
3659 unsigned char **ppMemory,
3660 PFORMAT_STRING pFormat,
3661 unsigned char fMustAlloc)
3664 unsigned short type, size;
3666 TRACE("(%p, %p, %p, %d)\n", pStubMsg, ppMemory, pFormat, fMustAlloc);
3669 /* Unmarshall discriminant */
3670 discriminant = unmarshall_discriminant(pStubMsg, &pFormat);
3671 TRACE("unmarshalled discriminant %lx\n", discriminant);
3673 pFormat += *(const SHORT*)pFormat;
3675 size = *(const unsigned short*)pFormat;
3678 pFormat = get_arm_offset_from_union_arm_selector(pStubMsg, discriminant, pFormat);
3682 if(!*ppMemory || fMustAlloc)
3683 *ppMemory = NdrAllocate(pStubMsg, size);
3685 type = *(const unsigned short*)pFormat;
3686 if((type & 0xff00) == 0x8000)
3688 unsigned char basetype = LOBYTE(type);
3689 return NdrBaseTypeUnmarshall(pStubMsg, ppMemory, &basetype, fMustAlloc);
3693 PFORMAT_STRING desc = pFormat + *(const SHORT*)pFormat;
3694 NDR_UNMARSHALL m = NdrUnmarshaller[*desc & NDR_TABLE_MASK];
3697 unsigned char *saved_buffer = NULL;
3704 **(void***)ppMemory = NULL;
3705 ALIGN_POINTER(pStubMsg->Buffer, 4);
3706 saved_buffer = pStubMsg->Buffer;
3707 pStubMsg->Buffer += 4; /* for pointer ID */
3708 PointerUnmarshall(pStubMsg, saved_buffer, *(unsigned char ***)ppMemory, desc, fMustAlloc);
3711 m(pStubMsg, ppMemory, desc, fMustAlloc);
3714 else FIXME("no marshaller for embedded type %02x\n", *desc);
3719 /***********************************************************************
3720 * NdrNonEncapsulatedUnionBufferSize [RPCRT4.@]
3722 void WINAPI NdrNonEncapsulatedUnionBufferSize(PMIDL_STUB_MESSAGE pStubMsg,
3723 unsigned char *pMemory,
3724 PFORMAT_STRING pFormat)
3726 unsigned short type;
3727 unsigned char switch_type;
3729 TRACE("(%p, %p, %p)\n", pStubMsg, pMemory, pFormat);
3732 switch_type = *pFormat;
3735 pFormat = ComputeConformance(pStubMsg, pMemory, pFormat, 0);
3736 TRACE("got switch value 0x%lx\n", pStubMsg->MaxCount);
3737 /* Add discriminant size */
3738 NdrBaseTypeBufferSize(pStubMsg, (unsigned char *)&pStubMsg->MaxCount, &switch_type);
3740 pFormat = get_non_encapsulated_union_arm(pStubMsg, pStubMsg->MaxCount, pFormat);
3744 type = *(const unsigned short*)pFormat;
3745 if((type & 0xff00) == 0x8000)
3747 unsigned char basetype = LOBYTE(type);
3748 NdrBaseTypeBufferSize(pStubMsg, pMemory, &basetype);
3752 PFORMAT_STRING desc = pFormat + *(const SHORT*)pFormat;
3753 NDR_BUFFERSIZE m = NdrBufferSizer[*desc & NDR_TABLE_MASK];
3762 ALIGN_LENGTH(pStubMsg->BufferLength, 4);
3763 pStubMsg->BufferLength += 4; /* for pointer ID */
3764 PointerBufferSize(pStubMsg, *(unsigned char **)pMemory, desc);
3767 m(pStubMsg, pMemory, desc);
3770 else FIXME("no buffersizer for embedded type %02x\n", *desc);
3775 /***********************************************************************
3776 * NdrNonEncapsulatedUnionMemorySize [RPCRT4.@]
3778 unsigned long WINAPI NdrNonEncapsulatedUnionMemorySize(PMIDL_STUB_MESSAGE pStubMsg,
3779 PFORMAT_STRING pFormat)
3782 if (pStubMsg->fHasNewCorrDesc)
3787 pFormat += *(const SHORT*)pFormat;
3788 TRACE("size %d\n", *(const SHORT*)pFormat);
3789 return *(const SHORT*)pFormat;
3792 /***********************************************************************
3793 * NdrNonEncapsulatedUnionFree [RPCRT4.@]
3795 void WINAPI NdrNonEncapsulatedUnionFree(PMIDL_STUB_MESSAGE pStubMsg,
3796 unsigned char *pMemory,
3797 PFORMAT_STRING pFormat)
3802 /***********************************************************************
3803 * NdrByteCountPointerMarshall [RPCRT4.@]
3805 unsigned char * WINAPI NdrByteCountPointerMarshall(PMIDL_STUB_MESSAGE pStubMsg,
3806 unsigned char *pMemory,
3807 PFORMAT_STRING pFormat)
3813 /***********************************************************************
3814 * NdrByteCountPointerUnmarshall [RPCRT4.@]
3816 unsigned char * WINAPI NdrByteCountPointerUnmarshall(PMIDL_STUB_MESSAGE pStubMsg,
3817 unsigned char **ppMemory,
3818 PFORMAT_STRING pFormat,
3819 unsigned char fMustAlloc)
3825 /***********************************************************************
3826 * NdrByteCountPointerBufferSize [RPCRT4.@]
3828 void WINAPI NdrByteCountPointerBufferSize(PMIDL_STUB_MESSAGE pStubMsg,
3829 unsigned char *pMemory,
3830 PFORMAT_STRING pFormat)
3835 /***********************************************************************
3836 * NdrByteCountPointerMemorySize [RPCRT4.@]
3838 unsigned long WINAPI NdrByteCountPointerMemorySize(PMIDL_STUB_MESSAGE pStubMsg,
3839 PFORMAT_STRING pFormat)
3845 /***********************************************************************
3846 * NdrByteCountPointerFree [RPCRT4.@]
3848 void WINAPI NdrByteCountPointerFree(PMIDL_STUB_MESSAGE pStubMsg,
3849 unsigned char *pMemory,
3850 PFORMAT_STRING pFormat)
3855 /***********************************************************************
3856 * NdrXmitOrRepAsMarshall [RPCRT4.@]
3858 unsigned char * WINAPI NdrXmitOrRepAsMarshall(PMIDL_STUB_MESSAGE pStubMsg,
3859 unsigned char *pMemory,
3860 PFORMAT_STRING pFormat)
3866 /***********************************************************************
3867 * NdrXmitOrRepAsUnmarshall [RPCRT4.@]
3869 unsigned char * WINAPI NdrXmitOrRepAsUnmarshall(PMIDL_STUB_MESSAGE pStubMsg,
3870 unsigned char **ppMemory,
3871 PFORMAT_STRING pFormat,
3872 unsigned char fMustAlloc)
3878 /***********************************************************************
3879 * NdrXmitOrRepAsBufferSize [RPCRT4.@]
3881 void WINAPI NdrXmitOrRepAsBufferSize(PMIDL_STUB_MESSAGE pStubMsg,
3882 unsigned char *pMemory,
3883 PFORMAT_STRING pFormat)
3888 /***********************************************************************
3889 * NdrXmitOrRepAsMemorySize [RPCRT4.@]
3891 unsigned long WINAPI NdrXmitOrRepAsMemorySize(PMIDL_STUB_MESSAGE pStubMsg,
3892 PFORMAT_STRING pFormat)
3898 /***********************************************************************
3899 * NdrXmitOrRepAsFree [RPCRT4.@]
3901 void WINAPI NdrXmitOrRepAsFree(PMIDL_STUB_MESSAGE pStubMsg,
3902 unsigned char *pMemory,
3903 PFORMAT_STRING pFormat)
3908 /***********************************************************************
3909 * NdrBaseTypeMarshall [internal]
3911 static unsigned char *WINAPI NdrBaseTypeMarshall(
3912 PMIDL_STUB_MESSAGE pStubMsg,
3913 unsigned char *pMemory,
3914 PFORMAT_STRING pFormat)
3916 TRACE("pStubMsg %p, pMemory %p, type 0x%02x\n", pStubMsg, pMemory, *pFormat);
3924 *(UCHAR *)pStubMsg->Buffer = *(UCHAR *)pMemory;
3925 pStubMsg->Buffer += sizeof(UCHAR);
3926 TRACE("value: 0x%02x\n", *(UCHAR *)pMemory);
3931 ALIGN_POINTER(pStubMsg->Buffer, sizeof(USHORT));
3932 *(USHORT *)pStubMsg->Buffer = *(USHORT *)pMemory;
3933 pStubMsg->Buffer += sizeof(USHORT);
3934 TRACE("value: 0x%04x\n", *(USHORT *)pMemory);
3938 case RPC_FC_ERROR_STATUS_T:
3940 ALIGN_POINTER(pStubMsg->Buffer, sizeof(ULONG));
3941 *(ULONG *)pStubMsg->Buffer = *(ULONG *)pMemory;
3942 pStubMsg->Buffer += sizeof(ULONG);
3943 TRACE("value: 0x%08lx\n", *(ULONG *)pMemory);
3946 ALIGN_POINTER(pStubMsg->Buffer, sizeof(float));
3947 *(float *)pStubMsg->Buffer = *(float *)pMemory;
3948 pStubMsg->Buffer += sizeof(float);
3951 ALIGN_POINTER(pStubMsg->Buffer, sizeof(double));
3952 *(double *)pStubMsg->Buffer = *(double *)pMemory;
3953 pStubMsg->Buffer += sizeof(double);
3956 ALIGN_POINTER(pStubMsg->Buffer, sizeof(ULONGLONG));
3957 *(ULONGLONG *)pStubMsg->Buffer = *(ULONGLONG *)pMemory;
3958 pStubMsg->Buffer += sizeof(ULONGLONG);
3959 TRACE("value: %s\n", wine_dbgstr_longlong(*(ULONGLONG*)pMemory));
3962 /* only 16-bits on the wire, so do a sanity check */
3963 if (*(UINT *)pMemory > USHRT_MAX)
3964 RpcRaiseException(RPC_X_ENUM_VALUE_OUT_OF_RANGE);
3965 ALIGN_POINTER(pStubMsg->Buffer, sizeof(USHORT));
3966 *(USHORT *)pStubMsg->Buffer = *(UINT *)pMemory;
3967 pStubMsg->Buffer += sizeof(USHORT);
3968 TRACE("value: 0x%04x\n", *(UINT *)pMemory);
3971 FIXME("Unhandled base type: 0x%02x\n", *pFormat);
3974 STD_OVERFLOW_CHECK(pStubMsg);
3976 /* FIXME: what is the correct return value? */
3980 /***********************************************************************
3981 * NdrBaseTypeUnmarshall [internal]
3983 static unsigned char *WINAPI NdrBaseTypeUnmarshall(
3984 PMIDL_STUB_MESSAGE pStubMsg,
3985 unsigned char **ppMemory,
3986 PFORMAT_STRING pFormat,
3987 unsigned char fMustAlloc)
3989 TRACE("pStubMsg: %p, ppMemory: %p, type: 0x%02x, fMustAlloc: %s\n", pStubMsg, ppMemory, *pFormat, fMustAlloc ? "true" : "false");
3991 if (fMustAlloc || !*ppMemory)
3993 unsigned char *Buffer = pStubMsg->Buffer;
3994 *ppMemory = NdrAllocate(pStubMsg, NdrBaseTypeMemorySize(pStubMsg, pFormat));
3995 pStubMsg->Buffer = Buffer;
3998 TRACE("*ppMemory: %p\n", *ppMemory);
4006 **(UCHAR **)ppMemory = *(UCHAR *)pStubMsg->Buffer;
4007 pStubMsg->Buffer += sizeof(UCHAR);
4008 TRACE("value: 0x%02x\n", **(UCHAR **)ppMemory);
4013 ALIGN_POINTER(pStubMsg->Buffer, sizeof(USHORT));
4014 **(USHORT **)ppMemory = *(USHORT *)pStubMsg->Buffer;
4015 pStubMsg->Buffer += sizeof(USHORT);
4016 TRACE("value: 0x%04x\n", **(USHORT **)ppMemory);
4020 case RPC_FC_ERROR_STATUS_T:
4022 ALIGN_POINTER(pStubMsg->Buffer, sizeof(ULONG));
4023 **(ULONG **)ppMemory = *(ULONG *)pStubMsg->Buffer;
4024 pStubMsg->Buffer += sizeof(ULONG);
4025 TRACE("value: 0x%08lx\n", **(ULONG **)ppMemory);
4028 ALIGN_POINTER(pStubMsg->Buffer, sizeof(float));
4029 **(float **)ppMemory = *(float *)pStubMsg->Buffer;
4030 pStubMsg->Buffer += sizeof(float);
4031 TRACE("value: %f\n", **(float **)ppMemory);
4034 ALIGN_POINTER(pStubMsg->Buffer, sizeof(double));
4035 **(double **)ppMemory = *(double*)pStubMsg->Buffer;
4036 pStubMsg->Buffer += sizeof(double);
4037 TRACE("value: %f\n", **(double **)ppMemory);
4040 ALIGN_POINTER(pStubMsg->Buffer, sizeof(ULONGLONG));
4041 **(ULONGLONG **)ppMemory = *(ULONGLONG *)pStubMsg->Buffer;
4042 pStubMsg->Buffer += sizeof(ULONGLONG);
4043 TRACE("value: %s\n", wine_dbgstr_longlong(**(ULONGLONG **)ppMemory));
4046 ALIGN_POINTER(pStubMsg->Buffer, sizeof(USHORT));
4047 /* 16-bits on the wire, but int in memory */
4048 **(UINT **)ppMemory = *(USHORT *)pStubMsg->Buffer;
4049 pStubMsg->Buffer += sizeof(USHORT);
4050 TRACE("value: 0x%08x\n", **(UINT **)ppMemory);
4053 FIXME("Unhandled base type: 0x%02x\n", *pFormat);
4056 /* FIXME: what is the correct return value? */
4061 /***********************************************************************
4062 * NdrBaseTypeBufferSize [internal]
4064 static void WINAPI NdrBaseTypeBufferSize(
4065 PMIDL_STUB_MESSAGE pStubMsg,
4066 unsigned char *pMemory,
4067 PFORMAT_STRING pFormat)
4069 TRACE("pStubMsg %p, pMemory %p, type 0x%02x\n", pStubMsg, pMemory, *pFormat);
4077 pStubMsg->BufferLength += sizeof(UCHAR);
4083 ALIGN_LENGTH(pStubMsg->BufferLength, sizeof(USHORT));
4084 pStubMsg->BufferLength += sizeof(USHORT);
4089 ALIGN_LENGTH(pStubMsg->BufferLength, sizeof(ULONG));
4090 pStubMsg->BufferLength += sizeof(ULONG);
4093 ALIGN_LENGTH(pStubMsg->BufferLength, sizeof(float));
4094 pStubMsg->BufferLength += sizeof(float);
4097 ALIGN_LENGTH(pStubMsg->BufferLength, sizeof(double));
4098 pStubMsg->BufferLength += sizeof(double);
4101 ALIGN_LENGTH(pStubMsg->BufferLength, sizeof(ULONGLONG));
4102 pStubMsg->BufferLength += sizeof(ULONGLONG);
4104 case RPC_FC_ERROR_STATUS_T:
4105 ALIGN_LENGTH(pStubMsg->BufferLength, sizeof(error_status_t));
4106 pStubMsg->BufferLength += sizeof(error_status_t);
4109 FIXME("Unhandled base type: 0x%02x\n", *pFormat);
4113 /***********************************************************************
4114 * NdrBaseTypeMemorySize [internal]
4116 static unsigned long WINAPI NdrBaseTypeMemorySize(
4117 PMIDL_STUB_MESSAGE pStubMsg,
4118 PFORMAT_STRING pFormat)
4126 pStubMsg->Buffer += sizeof(UCHAR);
4127 pStubMsg->MemorySize += sizeof(UCHAR);
4128 return sizeof(UCHAR);
4132 pStubMsg->Buffer += sizeof(USHORT);
4133 pStubMsg->MemorySize += sizeof(USHORT);
4134 return sizeof(USHORT);
4137 pStubMsg->Buffer += sizeof(ULONG);
4138 pStubMsg->MemorySize += sizeof(ULONG);
4139 return sizeof(ULONG);
4141 pStubMsg->Buffer += sizeof(float);
4142 pStubMsg->MemorySize += sizeof(float);
4143 return sizeof(float);
4145 pStubMsg->Buffer += sizeof(double);
4146 pStubMsg->MemorySize += sizeof(double);
4147 return sizeof(double);
4149 pStubMsg->Buffer += sizeof(ULONGLONG);
4150 pStubMsg->MemorySize += sizeof(ULONGLONG);
4151 return sizeof(ULONGLONG);
4152 case RPC_FC_ERROR_STATUS_T:
4153 pStubMsg->Buffer += sizeof(error_status_t);
4154 pStubMsg->MemorySize += sizeof(error_status_t);
4155 return sizeof(error_status_t);
4158 pStubMsg->Buffer += sizeof(INT);
4159 pStubMsg->MemorySize += sizeof(INT);
4162 FIXME("Unhandled base type: 0x%02x\n", *pFormat);
4167 /***********************************************************************
4168 * NdrBaseTypeFree [internal]
4170 static void WINAPI NdrBaseTypeFree(PMIDL_STUB_MESSAGE pStubMsg,
4171 unsigned char *pMemory,
4172 PFORMAT_STRING pFormat)
4174 TRACE("pStubMsg %p pMemory %p type 0x%02x\n", pStubMsg, pMemory, *pFormat);
4179 /***********************************************************************
4180 * NdrClientContextMarshall
4182 void WINAPI NdrClientContextMarshall(PMIDL_STUB_MESSAGE pStubMsg,
4183 NDR_CCONTEXT ContextHandle,
4186 FIXME("(%p, %p, %d): stub\n", pStubMsg, ContextHandle, fCheck);
4189 /***********************************************************************
4190 * NdrClientContextUnmarshall
4192 void WINAPI NdrClientContextUnmarshall(PMIDL_STUB_MESSAGE pStubMsg,
4193 NDR_CCONTEXT * pContextHandle,
4194 RPC_BINDING_HANDLE BindHandle)
4196 FIXME("(%p, %p, %p): stub\n", pStubMsg, pContextHandle, BindHandle);
4199 void WINAPI NdrServerContextMarshall(PMIDL_STUB_MESSAGE pStubMsg,
4200 NDR_SCONTEXT ContextHandle,
4201 NDR_RUNDOWN RundownRoutine )
4203 FIXME("(%p, %p, %p): stub\n", pStubMsg, ContextHandle, RundownRoutine);
4206 NDR_SCONTEXT WINAPI NdrServerContextUnmarshall(PMIDL_STUB_MESSAGE pStubMsg)
4208 FIXME("(%p): stub\n", pStubMsg);
4212 void WINAPI NdrContextHandleSize(PMIDL_STUB_MESSAGE pStubMsg,
4213 unsigned char* pMemory,
4214 PFORMAT_STRING pFormat)
4216 FIXME("(%p, %p, %p): stub\n", pStubMsg, pMemory, pFormat);
4219 NDR_SCONTEXT WINAPI NdrContextHandleInitialize(PMIDL_STUB_MESSAGE pStubMsg,
4220 PFORMAT_STRING pFormat)
4222 FIXME("(%p, %p): stub\n", pStubMsg, pFormat);
4226 void WINAPI NdrServerContextNewMarshall(PMIDL_STUB_MESSAGE pStubMsg,
4227 NDR_SCONTEXT ContextHandle,
4228 NDR_RUNDOWN RundownRoutine,
4229 PFORMAT_STRING pFormat)
4231 FIXME("(%p, %p, %p, %p): stub\n", pStubMsg, ContextHandle, RundownRoutine, pFormat);
4234 NDR_SCONTEXT WINAPI NdrServerContextNewUnmarshall(PMIDL_STUB_MESSAGE pStubMsg,
4235 PFORMAT_STRING pFormat)
4237 FIXME("(%p, %p): stub\n", pStubMsg, pFormat);
4241 RPC_BINDING_HANDLE WINAPI NDRCContextBinding(NDR_CCONTEXT CContext)
4243 FIXME("(%p): stub\n", CContext);