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 return sizeof(void *);
1549 FIXME("unhandled embedded type %02x\n", *pFormat);
1555 static unsigned long EmbeddedComplexMemorySize(PMIDL_STUB_MESSAGE pStubMsg,
1556 PFORMAT_STRING pFormat)
1558 NDR_MEMORYSIZE m = NdrMemorySizer[*pFormat & NDR_TABLE_MASK];
1562 FIXME("no memorysizer for data type=%02x\n", *pFormat);
1566 return m(pStubMsg, pFormat);
1570 static unsigned char * ComplexMarshall(PMIDL_STUB_MESSAGE pStubMsg,
1571 unsigned char *pMemory,
1572 PFORMAT_STRING pFormat,
1573 PFORMAT_STRING pPointer)
1575 PFORMAT_STRING desc;
1579 while (*pFormat != RPC_FC_END) {
1583 TRACE("short=%d <= %p\n", *(WORD*)pMemory, pMemory);
1584 memcpy(pStubMsg->Buffer, pMemory, 2);
1585 pStubMsg->Buffer += 2;
1591 TRACE("long=%ld <= %p\n", *(DWORD*)pMemory, pMemory);
1592 memcpy(pStubMsg->Buffer, pMemory, 4);
1593 pStubMsg->Buffer += 4;
1596 case RPC_FC_POINTER:
1597 TRACE("pointer=%p <= %p\n", *(unsigned char**)pMemory, pMemory);
1598 NdrPointerMarshall(pStubMsg, *(unsigned char**)pMemory, pPointer);
1602 case RPC_FC_ALIGNM4:
1603 ALIGN_POINTER(pMemory, 4);
1605 case RPC_FC_ALIGNM8:
1606 ALIGN_POINTER(pMemory, 8);
1608 case RPC_FC_STRUCTPAD2:
1611 case RPC_FC_EMBEDDED_COMPLEX:
1612 pMemory += pFormat[1];
1614 desc = pFormat + *(const SHORT*)pFormat;
1615 size = EmbeddedComplexSize(pStubMsg, desc);
1616 TRACE("embedded complex (size=%ld) <= %p\n", size, pMemory);
1617 m = NdrMarshaller[*desc & NDR_TABLE_MASK];
1618 if (m) m(pStubMsg, pMemory, desc);
1619 else FIXME("no marshaller for embedded type %02x\n", *desc);
1626 FIXME("unhandled format %02x\n", *pFormat);
1634 static unsigned char * ComplexUnmarshall(PMIDL_STUB_MESSAGE pStubMsg,
1635 unsigned char *pMemory,
1636 PFORMAT_STRING pFormat,
1637 PFORMAT_STRING pPointer,
1638 unsigned char fMustAlloc)
1640 PFORMAT_STRING desc;
1644 while (*pFormat != RPC_FC_END) {
1648 memcpy(pMemory, pStubMsg->Buffer, 2);
1649 TRACE("short=%d => %p\n", *(WORD*)pMemory, pMemory);
1650 pStubMsg->Buffer += 2;
1656 memcpy(pMemory, pStubMsg->Buffer, 4);
1657 TRACE("long=%ld => %p\n", *(DWORD*)pMemory, pMemory);
1658 pStubMsg->Buffer += 4;
1661 case RPC_FC_POINTER:
1662 *(unsigned char**)pMemory = NULL;
1663 TRACE("pointer => %p\n", pMemory);
1664 NdrPointerUnmarshall(pStubMsg, (unsigned char**)pMemory, pPointer, fMustAlloc);
1668 case RPC_FC_ALIGNM4:
1669 ALIGN_POINTER(pMemory, 4);
1671 case RPC_FC_ALIGNM8:
1672 ALIGN_POINTER(pMemory, 8);
1674 case RPC_FC_STRUCTPAD2:
1677 case RPC_FC_EMBEDDED_COMPLEX:
1678 pMemory += pFormat[1];
1680 desc = pFormat + *(const SHORT*)pFormat;
1681 size = EmbeddedComplexSize(pStubMsg, desc);
1682 TRACE("embedded complex (size=%ld) => %p\n", size, pMemory);
1683 m = NdrUnmarshaller[*desc & NDR_TABLE_MASK];
1684 memset(pMemory, 0, size); /* just in case */
1685 if (m) m(pStubMsg, &pMemory, desc, fMustAlloc);
1686 else FIXME("no unmarshaller for embedded type %02x\n", *desc);
1693 FIXME("unhandled format %d\n", *pFormat);
1701 static unsigned char * ComplexBufferSize(PMIDL_STUB_MESSAGE pStubMsg,
1702 unsigned char *pMemory,
1703 PFORMAT_STRING pFormat,
1704 PFORMAT_STRING pPointer)
1706 PFORMAT_STRING desc;
1710 while (*pFormat != RPC_FC_END) {
1714 pStubMsg->BufferLength += 2;
1720 pStubMsg->BufferLength += 4;
1723 case RPC_FC_POINTER:
1724 NdrPointerBufferSize(pStubMsg, *(unsigned char**)pMemory, pPointer);
1728 case RPC_FC_ALIGNM4:
1729 ALIGN_POINTER(pMemory, 4);
1731 case RPC_FC_ALIGNM8:
1732 ALIGN_POINTER(pMemory, 8);
1734 case RPC_FC_STRUCTPAD2:
1737 case RPC_FC_EMBEDDED_COMPLEX:
1738 pMemory += pFormat[1];
1740 desc = pFormat + *(const SHORT*)pFormat;
1741 size = EmbeddedComplexSize(pStubMsg, desc);
1742 m = NdrBufferSizer[*desc & NDR_TABLE_MASK];
1743 if (m) m(pStubMsg, pMemory, desc);
1744 else FIXME("no buffersizer for embedded type %02x\n", *desc);
1751 FIXME("unhandled format %d\n", *pFormat);
1759 static unsigned char * ComplexFree(PMIDL_STUB_MESSAGE pStubMsg,
1760 unsigned char *pMemory,
1761 PFORMAT_STRING pFormat,
1762 PFORMAT_STRING pPointer)
1764 PFORMAT_STRING desc;
1768 while (*pFormat != RPC_FC_END) {
1779 case RPC_FC_POINTER:
1780 NdrPointerFree(pStubMsg, *(unsigned char**)pMemory, pPointer);
1784 case RPC_FC_ALIGNM4:
1785 ALIGN_POINTER(pMemory, 4);
1787 case RPC_FC_ALIGNM8:
1788 ALIGN_POINTER(pMemory, 8);
1790 case RPC_FC_STRUCTPAD2:
1793 case RPC_FC_EMBEDDED_COMPLEX:
1794 pMemory += pFormat[1];
1796 desc = pFormat + *(const SHORT*)pFormat;
1797 size = EmbeddedComplexSize(pStubMsg, desc);
1798 m = NdrFreer[*desc & NDR_TABLE_MASK];
1799 if (m) m(pStubMsg, pMemory, desc);
1800 else FIXME("no freer for embedded type %02x\n", *desc);
1807 FIXME("unhandled format %d\n", *pFormat);
1815 static unsigned long ComplexStructMemorySize(PMIDL_STUB_MESSAGE pStubMsg,
1816 PFORMAT_STRING pFormat)
1818 PFORMAT_STRING desc;
1819 unsigned long size = 0;
1821 while (*pFormat != RPC_FC_END) {
1826 pStubMsg->Buffer += 2;
1831 pStubMsg->Buffer += 4;
1833 case RPC_FC_POINTER:
1835 pStubMsg->Buffer += 4;
1837 case RPC_FC_ALIGNM4:
1838 ALIGN_LENGTH(size, 4);
1839 ALIGN_POINTER(pStubMsg->Buffer, 4);
1841 case RPC_FC_ALIGNM8:
1842 ALIGN_LENGTH(size, 8);
1843 ALIGN_POINTER(pStubMsg->Buffer, 8);
1845 case RPC_FC_STRUCTPAD2:
1847 pStubMsg->Buffer += 2;
1849 case RPC_FC_EMBEDDED_COMPLEX:
1852 desc = pFormat + *(const SHORT*)pFormat;
1853 size += EmbeddedComplexMemorySize(pStubMsg, desc);
1859 FIXME("unhandled format %d\n", *pFormat);
1867 /***********************************************************************
1868 * NdrComplexStructMarshall [RPCRT4.@]
1870 unsigned char * WINAPI NdrComplexStructMarshall(PMIDL_STUB_MESSAGE pStubMsg,
1871 unsigned char *pMemory,
1872 PFORMAT_STRING pFormat)
1874 PFORMAT_STRING conf_array = NULL;
1875 PFORMAT_STRING pointer_desc = NULL;
1876 unsigned char *OldMemory = pStubMsg->Memory;
1878 TRACE("(%p,%p,%p)\n", pStubMsg, pMemory, pFormat);
1880 ALIGN_POINTER(pStubMsg->Buffer, pFormat[1] + 1);
1883 if (*(const WORD*)pFormat) conf_array = pFormat + *(const WORD*)pFormat;
1885 if (*(const WORD*)pFormat) pointer_desc = pFormat + *(const WORD*)pFormat;
1888 pStubMsg->Memory = pMemory;
1890 ComplexMarshall(pStubMsg, pMemory, pFormat, pointer_desc);
1893 NdrConformantArrayMarshall(pStubMsg, pMemory, conf_array);
1895 pStubMsg->Memory = OldMemory;
1897 STD_OVERFLOW_CHECK(pStubMsg);
1902 /***********************************************************************
1903 * NdrComplexStructUnmarshall [RPCRT4.@]
1905 unsigned char * WINAPI NdrComplexStructUnmarshall(PMIDL_STUB_MESSAGE pStubMsg,
1906 unsigned char **ppMemory,
1907 PFORMAT_STRING pFormat,
1908 unsigned char fMustAlloc)
1910 unsigned size = *(const WORD*)(pFormat+2);
1911 PFORMAT_STRING conf_array = NULL;
1912 PFORMAT_STRING pointer_desc = NULL;
1913 unsigned char *pMemory;
1915 TRACE("(%p,%p,%p,%d)\n", pStubMsg, ppMemory, pFormat, fMustAlloc);
1917 ALIGN_POINTER(pStubMsg->Buffer, pFormat[1] + 1);
1919 if (fMustAlloc || !*ppMemory)
1921 *ppMemory = NdrAllocate(pStubMsg, size);
1922 memset(*ppMemory, 0, size);
1926 if (*(const WORD*)pFormat) conf_array = pFormat + *(const WORD*)pFormat;
1928 if (*(const WORD*)pFormat) pointer_desc = pFormat + *(const WORD*)pFormat;
1931 pMemory = ComplexUnmarshall(pStubMsg, *ppMemory, pFormat, pointer_desc, fMustAlloc);
1934 NdrConformantArrayUnmarshall(pStubMsg, &pMemory, conf_array, fMustAlloc);
1939 /***********************************************************************
1940 * NdrComplexStructBufferSize [RPCRT4.@]
1942 void WINAPI NdrComplexStructBufferSize(PMIDL_STUB_MESSAGE pStubMsg,
1943 unsigned char *pMemory,
1944 PFORMAT_STRING pFormat)
1946 PFORMAT_STRING conf_array = NULL;
1947 PFORMAT_STRING pointer_desc = NULL;
1948 unsigned char *OldMemory = pStubMsg->Memory;
1950 TRACE("(%p,%p,%p)\n", pStubMsg, pMemory, pFormat);
1952 ALIGN_LENGTH(pStubMsg->BufferLength, pFormat[1] + 1);
1955 if (*(const WORD*)pFormat) conf_array = pFormat + *(const WORD*)pFormat;
1957 if (*(const WORD*)pFormat) pointer_desc = pFormat + *(const WORD*)pFormat;
1960 pStubMsg->Memory = pMemory;
1962 pMemory = ComplexBufferSize(pStubMsg, pMemory, pFormat, pointer_desc);
1965 NdrConformantArrayBufferSize(pStubMsg, pMemory, conf_array);
1967 pStubMsg->Memory = OldMemory;
1970 /***********************************************************************
1971 * NdrComplexStructMemorySize [RPCRT4.@]
1973 unsigned long WINAPI NdrComplexStructMemorySize(PMIDL_STUB_MESSAGE pStubMsg,
1974 PFORMAT_STRING pFormat)
1976 unsigned size = *(const WORD*)(pFormat+2);
1977 PFORMAT_STRING conf_array = NULL;
1978 PFORMAT_STRING pointer_desc = NULL;
1980 TRACE("(%p,%p)\n", pStubMsg, pFormat);
1982 ALIGN_POINTER(pStubMsg->Buffer, pFormat[1] + 1);
1985 if (*(const WORD*)pFormat) conf_array = pFormat + *(const WORD*)pFormat;
1987 if (*(const WORD*)pFormat) pointer_desc = pFormat + *(const WORD*)pFormat;
1990 ComplexStructMemorySize(pStubMsg, pFormat);
1993 NdrConformantArrayMemorySize(pStubMsg, conf_array);
1998 /***********************************************************************
1999 * NdrComplexStructFree [RPCRT4.@]
2001 void WINAPI NdrComplexStructFree(PMIDL_STUB_MESSAGE pStubMsg,
2002 unsigned char *pMemory,
2003 PFORMAT_STRING pFormat)
2005 PFORMAT_STRING conf_array = NULL;
2006 PFORMAT_STRING pointer_desc = NULL;
2007 unsigned char *OldMemory = pStubMsg->Memory;
2009 TRACE("(%p,%p,%p)\n", pStubMsg, pMemory, pFormat);
2012 if (*(const WORD*)pFormat) conf_array = pFormat + *(const WORD*)pFormat;
2014 if (*(const WORD*)pFormat) pointer_desc = pFormat + *(const WORD*)pFormat;
2017 pStubMsg->Memory = pMemory;
2019 pMemory = ComplexFree(pStubMsg, pMemory, pFormat, pointer_desc);
2022 NdrConformantArrayFree(pStubMsg, pMemory, conf_array);
2024 pStubMsg->Memory = OldMemory;
2027 /***********************************************************************
2028 * NdrConformantArrayMarshall [RPCRT4.@]
2030 unsigned char * WINAPI NdrConformantArrayMarshall(PMIDL_STUB_MESSAGE pStubMsg,
2031 unsigned char *pMemory,
2032 PFORMAT_STRING pFormat)
2034 DWORD size = 0, esize = *(const WORD*)(pFormat+2);
2035 unsigned char alignment = pFormat[1] + 1;
2037 TRACE("(%p,%p,%p)\n", pStubMsg, pMemory, pFormat);
2038 if (pFormat[0] != RPC_FC_CARRAY) FIXME("format=%d\n", pFormat[0]);
2040 pFormat = ComputeConformance(pStubMsg, pMemory, pFormat+4, 0);
2041 size = pStubMsg->MaxCount;
2043 WriteConformance(pStubMsg);
2045 ALIGN_POINTER(pStubMsg->Buffer, alignment);
2047 memcpy(pStubMsg->Buffer, pMemory, size*esize);
2048 pStubMsg->BufferMark = pStubMsg->Buffer;
2049 pStubMsg->Buffer += size*esize;
2051 EmbeddedPointerMarshall(pStubMsg, pMemory, pFormat);
2053 STD_OVERFLOW_CHECK(pStubMsg);
2058 /***********************************************************************
2059 * NdrConformantArrayUnmarshall [RPCRT4.@]
2061 unsigned char * WINAPI NdrConformantArrayUnmarshall(PMIDL_STUB_MESSAGE pStubMsg,
2062 unsigned char **ppMemory,
2063 PFORMAT_STRING pFormat,
2064 unsigned char fMustAlloc)
2066 DWORD size = 0, esize = *(const WORD*)(pFormat+2);
2067 unsigned char alignment = pFormat[1] + 1;
2069 TRACE("(%p,%p,%p,%d)\n", pStubMsg, ppMemory, pFormat, fMustAlloc);
2070 if (pFormat[0] != RPC_FC_CARRAY) FIXME("format=%d\n", pFormat[0]);
2072 pFormat = ReadConformance(pStubMsg, pFormat+4);
2073 size = pStubMsg->MaxCount;
2075 if (fMustAlloc || !*ppMemory)
2076 *ppMemory = NdrAllocate(pStubMsg, size*esize);
2078 ALIGN_POINTER(pStubMsg->Buffer, alignment);
2080 memcpy(*ppMemory, pStubMsg->Buffer, size*esize);
2082 pStubMsg->BufferMark = pStubMsg->Buffer;
2083 pStubMsg->Buffer += size*esize;
2085 EmbeddedPointerUnmarshall(pStubMsg, ppMemory, pFormat, fMustAlloc);
2090 /***********************************************************************
2091 * NdrConformantArrayBufferSize [RPCRT4.@]
2093 void WINAPI NdrConformantArrayBufferSize(PMIDL_STUB_MESSAGE pStubMsg,
2094 unsigned char *pMemory,
2095 PFORMAT_STRING pFormat)
2097 DWORD size = 0, esize = *(const WORD*)(pFormat+2);
2098 unsigned char alignment = pFormat[1] + 1;
2100 TRACE("(%p,%p,%p)\n", pStubMsg, pMemory, pFormat);
2101 if (pFormat[0] != RPC_FC_CARRAY) FIXME("format=%d\n", pFormat[0]);
2103 pFormat = ComputeConformance(pStubMsg, pMemory, pFormat+4, 0);
2104 size = pStubMsg->MaxCount;
2106 SizeConformance(pStubMsg);
2108 ALIGN_LENGTH(pStubMsg->BufferLength, alignment);
2110 /* conformance value plus array */
2111 pStubMsg->BufferLength += size*esize;
2113 EmbeddedPointerBufferSize(pStubMsg, pMemory, pFormat);
2116 /***********************************************************************
2117 * NdrConformantArrayMemorySize [RPCRT4.@]
2119 unsigned long WINAPI NdrConformantArrayMemorySize(PMIDL_STUB_MESSAGE pStubMsg,
2120 PFORMAT_STRING pFormat)
2122 DWORD size = 0, esize = *(const WORD*)(pFormat+2);
2123 unsigned char alignment = pFormat[1] + 1;
2125 TRACE("(%p,%p)\n", pStubMsg, pFormat);
2126 if (pFormat[0] != RPC_FC_CARRAY) FIXME("format=%d\n", pFormat[0]);
2128 pFormat = ReadConformance(pStubMsg, pFormat+4);
2129 size = pStubMsg->MaxCount;
2130 pStubMsg->MemorySize += size*esize;
2132 ALIGN_POINTER(pStubMsg->Buffer, alignment);
2133 pStubMsg->BufferMark = pStubMsg->Buffer;
2134 pStubMsg->Buffer += size*esize;
2136 EmbeddedPointerMemorySize(pStubMsg, pFormat);
2138 return pStubMsg->MemorySize;
2141 /***********************************************************************
2142 * NdrConformantArrayFree [RPCRT4.@]
2144 void WINAPI NdrConformantArrayFree(PMIDL_STUB_MESSAGE pStubMsg,
2145 unsigned char *pMemory,
2146 PFORMAT_STRING pFormat)
2148 TRACE("(%p,%p,%p)\n", pStubMsg, pMemory, pFormat);
2149 if (pFormat[0] != RPC_FC_CARRAY) FIXME("format=%d\n", pFormat[0]);
2151 EmbeddedPointerFree(pStubMsg, pMemory, pFormat);
2155 /***********************************************************************
2156 * NdrConformantVaryingArrayMarshall [RPCRT4.@]
2158 unsigned char* WINAPI NdrConformantVaryingArrayMarshall( PMIDL_STUB_MESSAGE pStubMsg,
2159 unsigned char* pMemory,
2160 PFORMAT_STRING pFormat )
2162 unsigned char alignment = pFormat[1] + 1;
2163 DWORD esize = *(const WORD*)(pFormat+2);
2165 TRACE("(%p, %p, %p)\n", pStubMsg, pMemory, pFormat);
2167 if (pFormat[0] != RPC_FC_CVARRAY)
2169 ERR("invalid format type %x\n", pFormat[0]);
2170 RpcRaiseException(RPC_S_INTERNAL_ERROR);
2174 pFormat = ComputeConformance(pStubMsg, pMemory, pFormat+4, 0);
2175 pFormat = ComputeVariance(pStubMsg, pMemory, pFormat, 0);
2177 WriteConformance(pStubMsg);
2178 WriteVariance(pStubMsg);
2180 ALIGN_POINTER(pStubMsg->Buffer, alignment);
2182 memcpy(pStubMsg->Buffer, pMemory + pStubMsg->Offset, pStubMsg->ActualCount*esize);
2183 pStubMsg->BufferMark = pStubMsg->Buffer;
2184 pStubMsg->Buffer += pStubMsg->ActualCount*esize;
2186 EmbeddedPointerMarshall(pStubMsg, pMemory, pFormat);
2188 STD_OVERFLOW_CHECK(pStubMsg);
2194 /***********************************************************************
2195 * NdrConformantVaryingArrayUnmarshall [RPCRT4.@]
2197 unsigned char* WINAPI NdrConformantVaryingArrayUnmarshall( PMIDL_STUB_MESSAGE pStubMsg,
2198 unsigned char** ppMemory,
2199 PFORMAT_STRING pFormat,
2200 unsigned char fMustAlloc )
2202 unsigned char alignment = pFormat[1] + 1;
2203 DWORD esize = *(const WORD*)(pFormat+2);
2205 TRACE("(%p, %p, %p, %d)\n", pStubMsg, ppMemory, pFormat, fMustAlloc);
2207 if (pFormat[0] != RPC_FC_CVARRAY)
2209 ERR("invalid format type %x\n", pFormat[0]);
2210 RpcRaiseException(RPC_S_INTERNAL_ERROR);
2214 pFormat = ReadConformance(pStubMsg, pFormat);
2215 pFormat = ReadVariance(pStubMsg, pFormat);
2217 ALIGN_POINTER(pStubMsg->Buffer, alignment);
2219 if (!*ppMemory || fMustAlloc)
2220 *ppMemory = NdrAllocate(pStubMsg, pStubMsg->MaxCount * esize);
2221 memcpy(*ppMemory + pStubMsg->Offset, pStubMsg->Buffer, pStubMsg->ActualCount * esize);
2222 pStubMsg->Buffer += pStubMsg->ActualCount * esize;
2224 EmbeddedPointerUnmarshall(pStubMsg, ppMemory, pFormat, fMustAlloc);
2230 /***********************************************************************
2231 * NdrConformantVaryingArrayFree [RPCRT4.@]
2233 void WINAPI NdrConformantVaryingArrayFree( PMIDL_STUB_MESSAGE pStubMsg,
2234 unsigned char* pMemory,
2235 PFORMAT_STRING pFormat )
2237 TRACE("(%p,%p,%p)\n", pStubMsg, pMemory, pFormat);
2239 if (pFormat[0] != RPC_FC_CVARRAY)
2241 ERR("invalid format type %x\n", pFormat[0]);
2242 RpcRaiseException(RPC_S_INTERNAL_ERROR);
2246 pFormat = ComputeConformance(pStubMsg, pMemory, pFormat+4, 0);
2247 pFormat = ComputeVariance(pStubMsg, pMemory, pFormat, 0);
2249 EmbeddedPointerFree(pStubMsg, pMemory, pFormat);
2253 /***********************************************************************
2254 * NdrConformantVaryingArrayBufferSize [RPCRT4.@]
2256 void WINAPI NdrConformantVaryingArrayBufferSize( PMIDL_STUB_MESSAGE pStubMsg,
2257 unsigned char* pMemory, PFORMAT_STRING pFormat )
2259 unsigned char alignment = pFormat[1] + 1;
2260 DWORD esize = *(const WORD*)(pFormat+2);
2262 TRACE("(%p, %p, %p)\n", pStubMsg, pMemory, pFormat);
2264 if (pFormat[0] != RPC_FC_CVARRAY)
2266 ERR("invalid format type %x\n", pFormat[0]);
2267 RpcRaiseException(RPC_S_INTERNAL_ERROR);
2272 pFormat = ComputeConformance(pStubMsg, pMemory, pFormat+4, 0);
2273 /* compute length */
2274 pFormat = ComputeVariance(pStubMsg, pMemory, pFormat, 0);
2276 SizeConformance(pStubMsg);
2277 SizeVariance(pStubMsg);
2279 ALIGN_LENGTH(pStubMsg->BufferLength, alignment);
2281 pStubMsg->BufferLength += pStubMsg->ActualCount*esize;
2283 EmbeddedPointerBufferSize(pStubMsg, pMemory, pFormat);
2287 /***********************************************************************
2288 * NdrConformantVaryingArrayMemorySize [RPCRT4.@]
2290 unsigned long WINAPI NdrConformantVaryingArrayMemorySize( PMIDL_STUB_MESSAGE pStubMsg,
2291 PFORMAT_STRING pFormat )
2298 /***********************************************************************
2299 * NdrComplexArrayMarshall [RPCRT4.@]
2301 unsigned char * WINAPI NdrComplexArrayMarshall(PMIDL_STUB_MESSAGE pStubMsg,
2302 unsigned char *pMemory,
2303 PFORMAT_STRING pFormat)
2305 ULONG i, count, def;
2306 BOOL variance_present;
2307 unsigned char alignment;
2309 TRACE("(%p,%p,%p)\n", pStubMsg, pMemory, pFormat);
2311 if (pFormat[0] != RPC_FC_BOGUS_ARRAY)
2313 ERR("invalid format type %x\n", pFormat[0]);
2314 RpcRaiseException(RPC_S_INTERNAL_ERROR);
2318 alignment = pFormat[1] + 1;
2320 def = *(const WORD*)&pFormat[2];
2323 pFormat = ComputeConformance(pStubMsg, pMemory, pFormat, def);
2324 TRACE("conformance = %ld\n", pStubMsg->MaxCount);
2326 variance_present = IsConformanceOrVariancePresent(pFormat);
2327 pFormat = ComputeVariance(pStubMsg, pMemory, pFormat, pStubMsg->MaxCount);
2328 TRACE("variance = %ld\n", pStubMsg->ActualCount);
2330 WriteConformance(pStubMsg);
2331 if (variance_present)
2332 WriteVariance(pStubMsg);
2334 ALIGN_POINTER(pStubMsg->Buffer, alignment);
2336 count = pStubMsg->ActualCount;
2337 for (i = 0; i < count; i++)
2338 pMemory = ComplexMarshall(pStubMsg, pMemory, pFormat, NULL);
2340 STD_OVERFLOW_CHECK(pStubMsg);
2345 /***********************************************************************
2346 * NdrComplexArrayUnmarshall [RPCRT4.@]
2348 unsigned char * WINAPI NdrComplexArrayUnmarshall(PMIDL_STUB_MESSAGE pStubMsg,
2349 unsigned char **ppMemory,
2350 PFORMAT_STRING pFormat,
2351 unsigned char fMustAlloc)
2353 ULONG i, count, esize;
2354 unsigned char alignment;
2355 unsigned char *pMemory;
2356 unsigned char *Buffer;
2358 TRACE("(%p,%p,%p,%d)\n", pStubMsg, ppMemory, pFormat, fMustAlloc);
2360 if (pFormat[0] != RPC_FC_BOGUS_ARRAY)
2362 ERR("invalid format type %x\n", pFormat[0]);
2363 RpcRaiseException(RPC_S_INTERNAL_ERROR);
2367 alignment = pFormat[1] + 1;
2371 pFormat = ReadConformance(pStubMsg, pFormat);
2372 pFormat = ReadVariance(pStubMsg, pFormat);
2374 Buffer = pStubMsg->Buffer;
2375 esize = ComplexStructMemorySize(pStubMsg, pFormat);
2376 pStubMsg->Buffer = Buffer;
2378 if (fMustAlloc || !*ppMemory)
2380 *ppMemory = NdrAllocate(pStubMsg, pStubMsg->MaxCount * esize);
2381 memset(*ppMemory, 0, pStubMsg->MaxCount * esize);
2384 ALIGN_POINTER(pStubMsg->Buffer, alignment);
2386 pMemory = *ppMemory;
2387 count = pStubMsg->ActualCount;
2388 for (i = 0; i < count; i++)
2389 pMemory = ComplexUnmarshall(pStubMsg, pMemory, pFormat, NULL, fMustAlloc);
2394 /***********************************************************************
2395 * NdrComplexArrayBufferSize [RPCRT4.@]
2397 void WINAPI NdrComplexArrayBufferSize(PMIDL_STUB_MESSAGE pStubMsg,
2398 unsigned char *pMemory,
2399 PFORMAT_STRING pFormat)
2401 ULONG i, count, def;
2402 unsigned char alignment;
2403 BOOL variance_present;
2405 TRACE("(%p,%p,%p)\n", pStubMsg, pMemory, pFormat);
2407 if (pFormat[0] != RPC_FC_BOGUS_ARRAY)
2409 ERR("invalid format type %x\n", pFormat[0]);
2410 RpcRaiseException(RPC_S_INTERNAL_ERROR);
2414 alignment = pFormat[1] + 1;
2416 def = *(const WORD*)&pFormat[2];
2419 pFormat = ComputeConformance(pStubMsg, pMemory, pFormat, def);
2420 TRACE("conformance = %ld\n", pStubMsg->MaxCount);
2421 SizeConformance(pStubMsg);
2423 variance_present = IsConformanceOrVariancePresent(pFormat);
2424 pFormat = ComputeVariance(pStubMsg, pMemory, pFormat, pStubMsg->MaxCount);
2425 TRACE("variance = %ld\n", pStubMsg->ActualCount);
2427 if (variance_present)
2428 SizeVariance(pStubMsg);
2430 ALIGN_LENGTH(pStubMsg->BufferLength, alignment);
2432 count = pStubMsg->ActualCount;
2433 for (i = 0; i < count; i++)
2434 pMemory = ComplexBufferSize(pStubMsg, pMemory, pFormat, NULL);
2437 /***********************************************************************
2438 * NdrComplexArrayMemorySize [RPCRT4.@]
2440 unsigned long WINAPI NdrComplexArrayMemorySize(PMIDL_STUB_MESSAGE pStubMsg,
2441 PFORMAT_STRING pFormat)
2443 ULONG i, count, esize;
2444 unsigned char alignment;
2445 unsigned char *Buffer;
2446 unsigned long SavedMemorySize;
2447 unsigned long MemorySize;
2449 TRACE("(%p,%p)\n", pStubMsg, pFormat);
2451 if (pFormat[0] != RPC_FC_BOGUS_ARRAY)
2453 ERR("invalid format type %x\n", pFormat[0]);
2454 RpcRaiseException(RPC_S_INTERNAL_ERROR);
2458 alignment = pFormat[1] + 1;
2462 pFormat = ReadConformance(pStubMsg, pFormat);
2463 pFormat = ReadVariance(pStubMsg, pFormat);
2465 ALIGN_POINTER(pStubMsg->Buffer, alignment);
2467 SavedMemorySize = pStubMsg->MemorySize;
2469 Buffer = pStubMsg->Buffer;
2470 esize = ComplexStructMemorySize(pStubMsg, pFormat);
2471 pStubMsg->Buffer = Buffer;
2473 MemorySize = esize * pStubMsg->MaxCount;
2475 count = pStubMsg->ActualCount;
2476 for (i = 0; i < count; i++)
2477 ComplexStructMemorySize(pStubMsg, pFormat);
2479 pStubMsg->MemorySize = SavedMemorySize;
2481 pStubMsg->MemorySize += MemorySize;
2485 /***********************************************************************
2486 * NdrComplexArrayFree [RPCRT4.@]
2488 void WINAPI NdrComplexArrayFree(PMIDL_STUB_MESSAGE pStubMsg,
2489 unsigned char *pMemory,
2490 PFORMAT_STRING pFormat)
2492 ULONG i, count, def;
2494 TRACE("(%p,%p,%p)\n", pStubMsg, pMemory, pFormat);
2496 if (pFormat[0] != RPC_FC_BOGUS_ARRAY)
2498 ERR("invalid format type %x\n", pFormat[0]);
2499 RpcRaiseException(RPC_S_INTERNAL_ERROR);
2503 def = *(const WORD*)&pFormat[2];
2506 pFormat = ComputeConformance(pStubMsg, pMemory, pFormat, def);
2507 TRACE("conformance = %ld\n", pStubMsg->MaxCount);
2509 pFormat = ComputeVariance(pStubMsg, pMemory, pFormat, pStubMsg->MaxCount);
2510 TRACE("variance = %ld\n", pStubMsg->ActualCount);
2512 count = pStubMsg->ActualCount;
2513 for (i = 0; i < count; i++)
2514 pMemory = ComplexFree(pStubMsg, pMemory, pFormat, NULL);
2517 unsigned long UserMarshalFlags(PMIDL_STUB_MESSAGE pStubMsg)
2519 return MAKELONG(pStubMsg->dwDestContext,
2520 pStubMsg->RpcMsg->DataRepresentation);
2523 #define USER_MARSHAL_PTR_PREFIX \
2524 ( (DWORD)'U' | ( (DWORD)'s' << 8 ) | \
2525 ( (DWORD)'e' << 16 ) | ( (DWORD)'r' << 24 ) )
2527 /***********************************************************************
2528 * NdrUserMarshalMarshall [RPCRT4.@]
2530 unsigned char * WINAPI NdrUserMarshalMarshall(PMIDL_STUB_MESSAGE pStubMsg,
2531 unsigned char *pMemory,
2532 PFORMAT_STRING pFormat)
2534 unsigned flags = pFormat[1];
2535 unsigned index = *(const WORD*)&pFormat[2];
2536 unsigned long uflag = UserMarshalFlags(pStubMsg);
2537 TRACE("(%p,%p,%p)\n", pStubMsg, pMemory, pFormat);
2538 TRACE("index=%d\n", index);
2540 if (flags & USER_MARSHAL_POINTER)
2542 ALIGN_POINTER(pStubMsg->Buffer, 4);
2543 NDR_LOCAL_UINT32_WRITE(pStubMsg->Buffer, USER_MARSHAL_PTR_PREFIX);
2544 pStubMsg->Buffer += 4;
2545 ALIGN_POINTER(pStubMsg->Buffer, 8);
2548 ALIGN_POINTER(pStubMsg->Buffer, (flags & 0xf) + 1);
2551 pStubMsg->StubDesc->aUserMarshalQuadruple[index].pfnMarshall(
2552 &uflag, pStubMsg->Buffer, pMemory);
2554 STD_OVERFLOW_CHECK(pStubMsg);
2559 /***********************************************************************
2560 * NdrUserMarshalUnmarshall [RPCRT4.@]
2562 unsigned char * WINAPI NdrUserMarshalUnmarshall(PMIDL_STUB_MESSAGE pStubMsg,
2563 unsigned char **ppMemory,
2564 PFORMAT_STRING pFormat,
2565 unsigned char fMustAlloc)
2567 unsigned flags = pFormat[1];
2568 unsigned index = *(const WORD*)&pFormat[2];
2569 DWORD memsize = *(const WORD*)&pFormat[4];
2570 unsigned long uflag = UserMarshalFlags(pStubMsg);
2571 TRACE("(%p,%p,%p,%d)\n", pStubMsg, ppMemory, pFormat, fMustAlloc);
2572 TRACE("index=%d\n", index);
2574 if (flags & USER_MARSHAL_POINTER)
2576 ALIGN_POINTER(pStubMsg->Buffer, 4);
2577 /* skip pointer prefix */
2578 pStubMsg->Buffer += 4;
2579 ALIGN_POINTER(pStubMsg->Buffer, 8);
2582 ALIGN_POINTER(pStubMsg->Buffer, (flags & 0xf) + 1);
2584 if (fMustAlloc || !*ppMemory)
2585 *ppMemory = NdrAllocate(pStubMsg, memsize);
2588 pStubMsg->StubDesc->aUserMarshalQuadruple[index].pfnUnmarshall(
2589 &uflag, pStubMsg->Buffer, *ppMemory);
2594 /***********************************************************************
2595 * NdrUserMarshalBufferSize [RPCRT4.@]
2597 void WINAPI NdrUserMarshalBufferSize(PMIDL_STUB_MESSAGE pStubMsg,
2598 unsigned char *pMemory,
2599 PFORMAT_STRING pFormat)
2601 unsigned flags = pFormat[1];
2602 unsigned index = *(const WORD*)&pFormat[2];
2603 DWORD bufsize = *(const WORD*)&pFormat[6];
2604 unsigned long uflag = UserMarshalFlags(pStubMsg);
2605 TRACE("(%p,%p,%p)\n", pStubMsg, pMemory, pFormat);
2606 TRACE("index=%d\n", index);
2608 if (flags & USER_MARSHAL_POINTER)
2610 ALIGN_LENGTH(pStubMsg->BufferLength, 4);
2611 /* skip pointer prefix */
2612 pStubMsg->BufferLength += 4;
2613 ALIGN_LENGTH(pStubMsg->BufferLength, 8);
2616 ALIGN_LENGTH(pStubMsg->BufferLength, (flags & 0xf) + 1);
2619 TRACE("size=%ld\n", bufsize);
2620 pStubMsg->BufferLength += bufsize;
2624 pStubMsg->BufferLength =
2625 pStubMsg->StubDesc->aUserMarshalQuadruple[index].pfnBufferSize(
2626 &uflag, pStubMsg->BufferLength, pMemory);
2629 /***********************************************************************
2630 * NdrUserMarshalMemorySize [RPCRT4.@]
2632 unsigned long WINAPI NdrUserMarshalMemorySize(PMIDL_STUB_MESSAGE pStubMsg,
2633 PFORMAT_STRING pFormat)
2635 unsigned flags = pFormat[1];
2636 unsigned index = *(const WORD*)&pFormat[2];
2637 DWORD memsize = *(const WORD*)&pFormat[4];
2638 DWORD bufsize = *(const WORD*)&pFormat[6];
2640 TRACE("(%p,%p)\n", pStubMsg, pFormat);
2641 TRACE("index=%d\n", index);
2643 pStubMsg->MemorySize += memsize;
2645 if (flags & USER_MARSHAL_POINTER)
2647 ALIGN_POINTER(pStubMsg->Buffer, 4);
2648 /* skip pointer prefix */
2649 pStubMsg->Buffer += 4;
2650 ALIGN_POINTER(pStubMsg->Buffer, 8);
2653 ALIGN_POINTER(pStubMsg->Buffer, (flags & 0xf) + 1);
2655 pStubMsg->Buffer += bufsize;
2657 return pStubMsg->MemorySize;
2660 /***********************************************************************
2661 * NdrUserMarshalFree [RPCRT4.@]
2663 void WINAPI NdrUserMarshalFree(PMIDL_STUB_MESSAGE pStubMsg,
2664 unsigned char *pMemory,
2665 PFORMAT_STRING pFormat)
2667 /* unsigned flags = pFormat[1]; */
2668 unsigned index = *(const WORD*)&pFormat[2];
2669 unsigned long uflag = UserMarshalFlags(pStubMsg);
2670 TRACE("(%p,%p,%p)\n", pStubMsg, pMemory, pFormat);
2671 TRACE("index=%d\n", index);
2673 pStubMsg->StubDesc->aUserMarshalQuadruple[index].pfnFree(
2677 /***********************************************************************
2678 * NdrClearOutParameters [RPCRT4.@]
2680 void WINAPI NdrClearOutParameters(PMIDL_STUB_MESSAGE pStubMsg,
2681 PFORMAT_STRING pFormat,
2684 FIXME("(%p,%p,%p): stub\n", pStubMsg, pFormat, ArgAddr);
2687 /***********************************************************************
2688 * NdrConvert [RPCRT4.@]
2690 void WINAPI NdrConvert( PMIDL_STUB_MESSAGE pStubMsg, PFORMAT_STRING pFormat )
2692 FIXME("(pStubMsg == ^%p, pFormat == ^%p): stub.\n", pStubMsg, pFormat);
2693 /* FIXME: since this stub doesn't do any converting, the proper behavior
2694 is to raise an exception */
2697 /***********************************************************************
2698 * NdrConvert2 [RPCRT4.@]
2700 void WINAPI NdrConvert2( PMIDL_STUB_MESSAGE pStubMsg, PFORMAT_STRING pFormat, long NumberParams )
2702 FIXME("(pStubMsg == ^%p, pFormat == ^%p, NumberParams == %ld): stub.\n",
2703 pStubMsg, pFormat, NumberParams);
2704 /* FIXME: since this stub doesn't do any converting, the proper behavior
2705 is to raise an exception */
2708 typedef struct _NDR_CSTRUCT_FORMAT
2711 unsigned char alignment;
2712 unsigned short memory_size;
2713 short offset_to_array_description;
2714 } NDR_CSTRUCT_FORMAT, NDR_CVSTRUCT_FORMAT;
2716 /***********************************************************************
2717 * NdrConformantStructMarshall [RPCRT4.@]
2719 unsigned char * WINAPI NdrConformantStructMarshall(PMIDL_STUB_MESSAGE pStubMsg,
2720 unsigned char *pMemory,
2721 PFORMAT_STRING pFormat)
2723 const NDR_CSTRUCT_FORMAT * pCStructFormat = (NDR_CSTRUCT_FORMAT*)pFormat;
2724 PFORMAT_STRING pCArrayFormat;
2727 TRACE("(%p, %p, %p)\n", pStubMsg, pMemory, pFormat);
2729 pFormat += sizeof(NDR_CSTRUCT_FORMAT);
2730 if ((pCStructFormat->type != RPC_FC_CPSTRUCT) && (pCStructFormat->type != RPC_FC_CSTRUCT))
2732 ERR("invalid format type %x\n", pCStructFormat->type);
2733 RpcRaiseException(RPC_S_INTERNAL_ERROR);
2737 pCArrayFormat = (unsigned char*)&pCStructFormat->offset_to_array_description +
2738 pCStructFormat->offset_to_array_description;
2739 if (*pCArrayFormat != RPC_FC_CARRAY)
2741 ERR("invalid array format type %x\n", pCStructFormat->type);
2742 RpcRaiseException(RPC_S_INTERNAL_ERROR);
2745 esize = *(const WORD*)(pCArrayFormat+2);
2747 ComputeConformance(pStubMsg, pMemory + pCStructFormat->memory_size,
2748 pCArrayFormat + 4, 0);
2750 WriteConformance(pStubMsg);
2752 ALIGN_POINTER(pStubMsg->Buffer, pCStructFormat->alignment + 1);
2754 TRACE("memory_size = %d\n", pCStructFormat->memory_size);
2756 /* copy constant sized part of struct */
2757 pStubMsg->BufferMark = pStubMsg->Buffer;
2758 memcpy(pStubMsg->Buffer, pMemory, pCStructFormat->memory_size + pStubMsg->MaxCount * esize);
2759 pStubMsg->Buffer += pCStructFormat->memory_size + pStubMsg->MaxCount * esize;
2761 if (pCStructFormat->type == RPC_FC_CPSTRUCT)
2762 EmbeddedPointerMarshall(pStubMsg, pMemory, pFormat);
2764 STD_OVERFLOW_CHECK(pStubMsg);
2769 /***********************************************************************
2770 * NdrConformantStructUnmarshall [RPCRT4.@]
2772 unsigned char * WINAPI NdrConformantStructUnmarshall(PMIDL_STUB_MESSAGE pStubMsg,
2773 unsigned char **ppMemory,
2774 PFORMAT_STRING pFormat,
2775 unsigned char fMustAlloc)
2777 const NDR_CSTRUCT_FORMAT * pCStructFormat = (NDR_CSTRUCT_FORMAT*)pFormat;
2778 PFORMAT_STRING pCArrayFormat;
2781 TRACE("(%p, %p, %p, %d)\n", pStubMsg, ppMemory, pFormat, fMustAlloc);
2783 pFormat += sizeof(NDR_CSTRUCT_FORMAT);
2784 if ((pCStructFormat->type != RPC_FC_CPSTRUCT) && (pCStructFormat->type != RPC_FC_CSTRUCT))
2786 ERR("invalid format type %x\n", pCStructFormat->type);
2787 RpcRaiseException(RPC_S_INTERNAL_ERROR);
2790 pCArrayFormat = (unsigned char*)&pCStructFormat->offset_to_array_description +
2791 pCStructFormat->offset_to_array_description;
2792 if (*pCArrayFormat != RPC_FC_CARRAY)
2794 ERR("invalid array format type %x\n", pCStructFormat->type);
2795 RpcRaiseException(RPC_S_INTERNAL_ERROR);
2798 esize = *(const WORD*)(pCArrayFormat+2);
2800 pCArrayFormat = ReadConformance(pStubMsg, pCArrayFormat + 4);
2802 ALIGN_POINTER(pStubMsg->Buffer, pCStructFormat->alignment + 1);
2804 TRACE("memory_size = %d\n", pCStructFormat->memory_size);
2806 /* work out how much memory to allocate if we need to do so */
2807 if (!*ppMemory || fMustAlloc)
2809 SIZE_T size = pCStructFormat->memory_size + pStubMsg->MaxCount * esize;
2810 *ppMemory = NdrAllocate(pStubMsg, size);
2813 /* now copy the data */
2814 pStubMsg->BufferMark = pStubMsg->Buffer;
2815 memcpy(*ppMemory, pStubMsg->Buffer, pCStructFormat->memory_size + pStubMsg->MaxCount * esize);
2816 pStubMsg->Buffer += pCStructFormat->memory_size + pStubMsg->MaxCount * esize;
2818 if (pCStructFormat->type == RPC_FC_CPSTRUCT)
2819 EmbeddedPointerUnmarshall(pStubMsg, ppMemory, pFormat, fMustAlloc);
2824 /***********************************************************************
2825 * NdrConformantStructBufferSize [RPCRT4.@]
2827 void WINAPI NdrConformantStructBufferSize(PMIDL_STUB_MESSAGE pStubMsg,
2828 unsigned char *pMemory,
2829 PFORMAT_STRING pFormat)
2831 const NDR_CSTRUCT_FORMAT * pCStructFormat = (NDR_CSTRUCT_FORMAT*)pFormat;
2832 PFORMAT_STRING pCArrayFormat;
2835 TRACE("(%p, %p, %p)\n", pStubMsg, pMemory, pFormat);
2837 pFormat += sizeof(NDR_CSTRUCT_FORMAT);
2838 if ((pCStructFormat->type != RPC_FC_CPSTRUCT) && (pCStructFormat->type != RPC_FC_CSTRUCT))
2840 ERR("invalid format type %x\n", pCStructFormat->type);
2841 RpcRaiseException(RPC_S_INTERNAL_ERROR);
2844 pCArrayFormat = (unsigned char*)&pCStructFormat->offset_to_array_description +
2845 pCStructFormat->offset_to_array_description;
2846 if (*pCArrayFormat != RPC_FC_CARRAY)
2848 ERR("invalid array format type %x\n", pCStructFormat->type);
2849 RpcRaiseException(RPC_S_INTERNAL_ERROR);
2852 esize = *(const WORD*)(pCArrayFormat+2);
2854 pCArrayFormat = ComputeConformance(pStubMsg, pMemory + pCStructFormat->memory_size, pCArrayFormat+4, 0);
2855 SizeConformance(pStubMsg);
2857 ALIGN_LENGTH(pStubMsg->BufferLength, pCStructFormat->alignment + 1);
2859 TRACE("memory_size = %d\n", pCStructFormat->memory_size);
2861 pStubMsg->BufferLength += pCStructFormat->memory_size + esize * pStubMsg->MaxCount;
2863 if (pCStructFormat->type == RPC_FC_CPSTRUCT)
2864 EmbeddedPointerBufferSize(pStubMsg, pMemory, pFormat);
2867 /***********************************************************************
2868 * NdrConformantStructMemorySize [RPCRT4.@]
2870 unsigned long WINAPI NdrConformantStructMemorySize(PMIDL_STUB_MESSAGE pStubMsg,
2871 PFORMAT_STRING pFormat)
2877 /***********************************************************************
2878 * NdrConformantStructFree [RPCRT4.@]
2880 void WINAPI NdrConformantStructFree(PMIDL_STUB_MESSAGE pStubMsg,
2881 unsigned char *pMemory,
2882 PFORMAT_STRING pFormat)
2887 /***********************************************************************
2888 * NdrConformantVaryingStructMarshall [RPCRT4.@]
2890 unsigned char * WINAPI NdrConformantVaryingStructMarshall(PMIDL_STUB_MESSAGE pStubMsg,
2891 unsigned char *pMemory,
2892 PFORMAT_STRING pFormat)
2894 const NDR_CVSTRUCT_FORMAT * pCVStructFormat = (NDR_CVSTRUCT_FORMAT*)pFormat;
2895 PFORMAT_STRING pCVArrayFormat;
2898 TRACE("(%p, %p, %p)\n", pStubMsg, pMemory, pFormat);
2900 pFormat += sizeof(NDR_CVSTRUCT_FORMAT);
2901 if (pCVStructFormat->type != RPC_FC_CVSTRUCT)
2903 ERR("invalid format type %x\n", pCVStructFormat->type);
2904 RpcRaiseException(RPC_S_INTERNAL_ERROR);
2908 pCVArrayFormat = (unsigned char*)&pCVStructFormat->offset_to_array_description +
2909 pCVStructFormat->offset_to_array_description;
2910 switch (*pCVArrayFormat)
2912 case RPC_FC_CVARRAY:
2913 esize = *(const WORD*)(pCVArrayFormat+2);
2915 pCVArrayFormat = ComputeConformance(pStubMsg, pMemory + pCVStructFormat->memory_size,
2916 pCVArrayFormat + 4, 0);
2917 pCVArrayFormat = ComputeVariance(pStubMsg, pMemory + pCVStructFormat->memory_size,
2920 case RPC_FC_C_CSTRING:
2921 TRACE("string=%s\n", debugstr_a((char*)pMemory + pCVStructFormat->memory_size));
2922 pStubMsg->ActualCount = strlen((char*)pMemory + pCVStructFormat->memory_size)+1;
2923 esize = sizeof(char);
2924 if (pCVArrayFormat[1] == RPC_FC_STRING_SIZED)
2925 pCVArrayFormat = ComputeConformance(pStubMsg, pMemory + pCVStructFormat->memory_size,
2926 pCVArrayFormat + 2, 0);
2928 pStubMsg->MaxCount = pStubMsg->ActualCount;
2930 case RPC_FC_C_WSTRING:
2931 TRACE("string=%s\n", debugstr_w((LPWSTR)pMemory + pCVStructFormat->memory_size));
2932 pStubMsg->ActualCount = strlenW((LPWSTR)pMemory + pCVStructFormat->memory_size)+1;
2933 esize = sizeof(WCHAR);
2934 if (pCVArrayFormat[1] == RPC_FC_STRING_SIZED)
2935 pCVArrayFormat = ComputeConformance(pStubMsg, pMemory + pCVStructFormat->memory_size,
2936 pCVArrayFormat + 2, 0);
2938 pStubMsg->MaxCount = pStubMsg->ActualCount;
2941 ERR("invalid array format type %x\n", *pCVArrayFormat);
2942 RpcRaiseException(RPC_S_INTERNAL_ERROR);
2946 WriteConformance(pStubMsg);
2948 ALIGN_POINTER(pStubMsg->Buffer, pCVStructFormat->alignment + 1);
2950 TRACE("memory_size = %d\n", pCVStructFormat->memory_size);
2952 /* write constant sized part */
2953 pStubMsg->BufferMark = pStubMsg->Buffer;
2954 memcpy(pStubMsg->Buffer, pMemory, pCVStructFormat->memory_size);
2955 pStubMsg->Buffer += pCVStructFormat->memory_size;
2957 WriteVariance(pStubMsg);
2959 /* write array part */
2960 memcpy(pStubMsg->Buffer, pMemory + pCVStructFormat->memory_size, pStubMsg->ActualCount * esize);
2961 pStubMsg->Buffer += pStubMsg->ActualCount * esize;
2963 EmbeddedPointerMarshall(pStubMsg, pMemory, pFormat);
2965 STD_OVERFLOW_CHECK(pStubMsg);
2970 /***********************************************************************
2971 * NdrConformantVaryingStructUnmarshall [RPCRT4.@]
2973 unsigned char * WINAPI NdrConformantVaryingStructUnmarshall(PMIDL_STUB_MESSAGE pStubMsg,
2974 unsigned char **ppMemory,
2975 PFORMAT_STRING pFormat,
2976 unsigned char fMustAlloc)
2978 const NDR_CVSTRUCT_FORMAT * pCVStructFormat = (NDR_CVSTRUCT_FORMAT*)pFormat;
2979 PFORMAT_STRING pCVArrayFormat;
2981 unsigned char cvarray_type;
2983 TRACE("(%p, %p, %p, %d)\n", pStubMsg, ppMemory, pFormat, fMustAlloc);
2985 pFormat += sizeof(NDR_CVSTRUCT_FORMAT);
2986 if (pCVStructFormat->type != RPC_FC_CVSTRUCT)
2988 ERR("invalid format type %x\n", pCVStructFormat->type);
2989 RpcRaiseException(RPC_S_INTERNAL_ERROR);
2993 pCVArrayFormat = (unsigned char*)&pCVStructFormat->offset_to_array_description +
2994 pCVStructFormat->offset_to_array_description;
2995 cvarray_type = *pCVArrayFormat;
2996 switch (cvarray_type)
2998 case RPC_FC_CVARRAY:
2999 esize = *(const WORD*)(pCVArrayFormat+2);
3000 pCVArrayFormat = ReadConformance(pStubMsg, pCVArrayFormat + 4);
3002 case RPC_FC_C_CSTRING:
3003 esize = sizeof(char);
3004 if (pCVArrayFormat[1] == RPC_FC_STRING_SIZED)
3005 pCVArrayFormat = ReadConformance(pStubMsg, pCVArrayFormat + 2);
3007 pCVArrayFormat = ReadConformance(pStubMsg, NULL);
3009 case RPC_FC_C_WSTRING:
3010 esize = sizeof(WCHAR);
3011 if (pCVArrayFormat[1] == RPC_FC_STRING_SIZED)
3012 pCVArrayFormat = ReadConformance(pStubMsg, pCVArrayFormat + 2);
3014 pCVArrayFormat = ReadConformance(pStubMsg, NULL);
3017 ERR("invalid array format type %x\n", *pCVArrayFormat);
3018 RpcRaiseException(RPC_S_INTERNAL_ERROR);
3022 ALIGN_POINTER(pStubMsg->Buffer, pCVStructFormat->alignment + 1);
3024 TRACE("memory_size = %d\n", pCVStructFormat->memory_size);
3026 /* work out how much memory to allocate if we need to do so */
3027 if (!*ppMemory || fMustAlloc)
3029 SIZE_T size = pCVStructFormat->memory_size + pStubMsg->MaxCount * esize;
3030 *ppMemory = NdrAllocate(pStubMsg, size);
3033 /* copy the constant data */
3034 pStubMsg->BufferMark = pStubMsg->Buffer;
3035 memcpy(*ppMemory, pStubMsg->Buffer, pCVStructFormat->memory_size);
3036 pStubMsg->Buffer += pCVStructFormat->memory_size;
3038 pCVArrayFormat = ReadVariance(pStubMsg, pCVArrayFormat);
3040 /* copy the array data */
3041 memcpy(*ppMemory + pCVStructFormat->memory_size, pStubMsg->Buffer,
3042 pStubMsg->ActualCount * esize);
3043 pStubMsg->Buffer += pStubMsg->ActualCount * esize;
3045 if (cvarray_type == RPC_FC_C_CSTRING)
3046 TRACE("string=%s\n", debugstr_a((char *)(*ppMemory + pCVStructFormat->memory_size)));
3047 else if (cvarray_type == RPC_FC_C_WSTRING)
3048 TRACE("string=%s\n", debugstr_w((WCHAR *)(*ppMemory + pCVStructFormat->memory_size)));
3050 EmbeddedPointerUnmarshall(pStubMsg, ppMemory, pFormat, fMustAlloc);
3055 /***********************************************************************
3056 * NdrConformantVaryingStructBufferSize [RPCRT4.@]
3058 void WINAPI NdrConformantVaryingStructBufferSize(PMIDL_STUB_MESSAGE pStubMsg,
3059 unsigned char *pMemory,
3060 PFORMAT_STRING pFormat)
3062 const NDR_CVSTRUCT_FORMAT * pCVStructFormat = (NDR_CVSTRUCT_FORMAT*)pFormat;
3063 PFORMAT_STRING pCVArrayFormat;
3066 TRACE("(%p, %p, %p)\n", pStubMsg, pMemory, pFormat);
3068 pFormat += sizeof(NDR_CVSTRUCT_FORMAT);
3069 if (pCVStructFormat->type != RPC_FC_CVSTRUCT)
3071 ERR("invalid format type %x\n", pCVStructFormat->type);
3072 RpcRaiseException(RPC_S_INTERNAL_ERROR);
3076 pCVArrayFormat = (unsigned char*)&pCVStructFormat->offset_to_array_description +
3077 pCVStructFormat->offset_to_array_description;
3078 switch (*pCVArrayFormat)
3080 case RPC_FC_CVARRAY:
3081 esize = *(const WORD*)(pCVArrayFormat+2);
3083 pCVArrayFormat = ComputeConformance(pStubMsg, pMemory + pCVStructFormat->memory_size,
3084 pCVArrayFormat + 4, 0);
3085 pCVArrayFormat = ComputeVariance(pStubMsg, pMemory + pCVStructFormat->memory_size,
3086 pCVArrayFormat + 4, 0);
3088 case RPC_FC_C_CSTRING:
3089 TRACE("string=%s\n", debugstr_a((char*)pMemory + pCVStructFormat->memory_size));
3090 pStubMsg->ActualCount = strlen((char*)pMemory + pCVStructFormat->memory_size)+1;
3091 esize = sizeof(char);
3092 if (pCVArrayFormat[1] == RPC_FC_STRING_SIZED)
3093 pCVArrayFormat = ComputeConformance(pStubMsg, pMemory + pCVStructFormat->memory_size,
3094 pCVArrayFormat + 2, 0);
3096 pStubMsg->MaxCount = pStubMsg->ActualCount;
3098 case RPC_FC_C_WSTRING:
3099 TRACE("string=%s\n", debugstr_w((LPWSTR)pMemory + pCVStructFormat->memory_size));
3100 pStubMsg->ActualCount = strlenW((LPWSTR)pMemory + pCVStructFormat->memory_size)+1;
3101 esize = sizeof(WCHAR);
3102 if (pCVArrayFormat[1] == RPC_FC_STRING_SIZED)
3103 pCVArrayFormat = ComputeConformance(pStubMsg, pMemory + pCVStructFormat->memory_size,
3104 pCVArrayFormat + 2, 0);
3106 pStubMsg->MaxCount = pStubMsg->ActualCount;
3109 ERR("invalid array format type %x\n", *pCVArrayFormat);
3110 RpcRaiseException(RPC_S_INTERNAL_ERROR);
3114 SizeConformance(pStubMsg);
3116 ALIGN_LENGTH(pStubMsg->BufferLength, pCVStructFormat->alignment + 1);
3118 TRACE("memory_size = %d\n", pCVStructFormat->memory_size);
3120 pStubMsg->BufferLength += pCVStructFormat->memory_size;
3121 SizeVariance(pStubMsg);
3122 pStubMsg->BufferLength += esize * pStubMsg->MaxCount;
3124 EmbeddedPointerBufferSize(pStubMsg, pMemory, pFormat);
3127 /***********************************************************************
3128 * NdrConformantVaryingStructMemorySize [RPCRT4.@]
3130 unsigned long WINAPI NdrConformantVaryingStructMemorySize(PMIDL_STUB_MESSAGE pStubMsg,
3131 PFORMAT_STRING pFormat)
3133 const NDR_CVSTRUCT_FORMAT * pCVStructFormat = (NDR_CVSTRUCT_FORMAT*)pFormat;
3134 PFORMAT_STRING pCVArrayFormat;
3136 unsigned char cvarray_type;
3138 TRACE("(%p, %p)\n", pStubMsg, pFormat);
3140 pFormat += sizeof(NDR_CVSTRUCT_FORMAT);
3141 if (pCVStructFormat->type != RPC_FC_CVSTRUCT)
3143 ERR("invalid format type %x\n", pCVStructFormat->type);
3144 RpcRaiseException(RPC_S_INTERNAL_ERROR);
3148 pCVArrayFormat = (unsigned char*)&pCVStructFormat->offset_to_array_description +
3149 pCVStructFormat->offset_to_array_description;
3150 cvarray_type = *pCVArrayFormat;
3151 switch (cvarray_type)
3153 case RPC_FC_CVARRAY:
3154 esize = *(const WORD*)(pCVArrayFormat+2);
3155 pCVArrayFormat = ReadConformance(pStubMsg, pCVArrayFormat + 4);
3157 case RPC_FC_C_CSTRING:
3158 esize = sizeof(char);
3159 if (pCVArrayFormat[1] == RPC_FC_STRING_SIZED)
3160 pCVArrayFormat = ReadConformance(pStubMsg, pCVArrayFormat + 2);
3162 pCVArrayFormat = ReadConformance(pStubMsg, NULL);
3164 case RPC_FC_C_WSTRING:
3165 esize = sizeof(WCHAR);
3166 if (pCVArrayFormat[1] == RPC_FC_STRING_SIZED)
3167 pCVArrayFormat = ReadConformance(pStubMsg, pCVArrayFormat + 2);
3169 pCVArrayFormat = ReadConformance(pStubMsg, NULL);
3172 ERR("invalid array format type %x\n", *pCVArrayFormat);
3173 RpcRaiseException(RPC_S_INTERNAL_ERROR);
3177 ALIGN_POINTER(pStubMsg->Buffer, pCVStructFormat->alignment + 1);
3179 TRACE("memory_size = %d\n", pCVStructFormat->memory_size);
3181 pStubMsg->Buffer += pCVStructFormat->memory_size;
3182 pCVArrayFormat = ReadVariance(pStubMsg, pCVArrayFormat);
3183 pStubMsg->Buffer += pCVStructFormat->memory_size + pStubMsg->ActualCount * esize;
3185 pStubMsg->MemorySize += pCVStructFormat->memory_size + pStubMsg->MaxCount * esize;
3187 EmbeddedPointerMemorySize(pStubMsg, pFormat);
3189 return pCVStructFormat->memory_size + pStubMsg->MaxCount * esize;
3192 /***********************************************************************
3193 * NdrConformantVaryingStructFree [RPCRT4.@]
3195 void WINAPI NdrConformantVaryingStructFree(PMIDL_STUB_MESSAGE pStubMsg,
3196 unsigned char *pMemory,
3197 PFORMAT_STRING pFormat)
3199 const NDR_CVSTRUCT_FORMAT * pCVStructFormat = (NDR_CVSTRUCT_FORMAT*)pFormat;
3200 PFORMAT_STRING pCVArrayFormat;
3203 TRACE("(%p, %p, %p)\n", pStubMsg, pMemory, pFormat);
3205 pFormat += sizeof(NDR_CVSTRUCT_FORMAT);
3206 if (pCVStructFormat->type != RPC_FC_CVSTRUCT)
3208 ERR("invalid format type %x\n", pCVStructFormat->type);
3209 RpcRaiseException(RPC_S_INTERNAL_ERROR);
3213 pCVArrayFormat = (unsigned char*)&pCVStructFormat->offset_to_array_description +
3214 pCVStructFormat->offset_to_array_description;
3215 switch (*pCVArrayFormat)
3217 case RPC_FC_CVARRAY:
3218 esize = *(const WORD*)(pCVArrayFormat+2);
3220 pCVArrayFormat = ComputeConformance(pStubMsg, pMemory + pCVStructFormat->memory_size,
3221 pCVArrayFormat + 4, 0);
3222 pCVArrayFormat = ComputeVariance(pStubMsg, pMemory + pCVStructFormat->memory_size,
3225 case RPC_FC_C_CSTRING:
3226 TRACE("string=%s\n", debugstr_a((char*)pMemory + pCVStructFormat->memory_size));
3227 pStubMsg->ActualCount = strlen((char*)pMemory + pCVStructFormat->memory_size)+1;
3228 esize = sizeof(char);
3229 if (pCVArrayFormat[1] == RPC_FC_STRING_SIZED)
3230 pCVArrayFormat = ComputeConformance(pStubMsg, pMemory + pCVStructFormat->memory_size,
3231 pCVArrayFormat + 2, 0);
3233 pStubMsg->MaxCount = pStubMsg->ActualCount;
3235 case RPC_FC_C_WSTRING:
3236 TRACE("string=%s\n", debugstr_w((LPWSTR)pMemory + pCVStructFormat->memory_size));
3237 pStubMsg->ActualCount = strlenW((LPWSTR)pMemory + pCVStructFormat->memory_size)+1;
3238 esize = sizeof(WCHAR);
3239 if (pCVArrayFormat[1] == RPC_FC_STRING_SIZED)
3240 pCVArrayFormat = ComputeConformance(pStubMsg, pMemory + pCVStructFormat->memory_size,
3241 pCVArrayFormat + 2, 0);
3243 pStubMsg->MaxCount = pStubMsg->ActualCount;
3246 ERR("invalid array format type %x\n", *pCVArrayFormat);
3247 RpcRaiseException(RPC_S_INTERNAL_ERROR);
3251 TRACE("memory_size = %d\n", pCVStructFormat->memory_size);
3253 EmbeddedPointerFree(pStubMsg, pMemory, pFormat);
3259 unsigned char alignment;
3260 unsigned short total_size;
3261 } NDR_SMFARRAY_FORMAT;
3266 unsigned char alignment;
3267 unsigned long total_size;
3268 } NDR_LGFARRAY_FORMAT;
3270 /***********************************************************************
3271 * NdrFixedArrayMarshall [RPCRT4.@]
3273 unsigned char * WINAPI NdrFixedArrayMarshall(PMIDL_STUB_MESSAGE pStubMsg,
3274 unsigned char *pMemory,
3275 PFORMAT_STRING pFormat)
3277 const NDR_SMFARRAY_FORMAT *pSmFArrayFormat = (const NDR_SMFARRAY_FORMAT *)pFormat;
3278 unsigned long total_size;
3280 TRACE("(%p, %p, %p)\n", pStubMsg, pMemory, pFormat);
3282 if ((pSmFArrayFormat->type != RPC_FC_SMFARRAY) &&
3283 (pSmFArrayFormat->type != RPC_FC_LGFARRAY))
3285 ERR("invalid format type %x\n", pSmFArrayFormat->type);
3286 RpcRaiseException(RPC_S_INTERNAL_ERROR);
3290 ALIGN_POINTER(pStubMsg->Buffer, pSmFArrayFormat->alignment + 1);
3292 if (pSmFArrayFormat->type == RPC_FC_SMFARRAY)
3294 total_size = pSmFArrayFormat->total_size;
3295 pFormat = (unsigned char *)(pSmFArrayFormat + 1);
3299 const NDR_LGFARRAY_FORMAT *pLgFArrayFormat = (const NDR_LGFARRAY_FORMAT *)pFormat;
3300 total_size = pLgFArrayFormat->total_size;
3301 pFormat = (unsigned char *)(pLgFArrayFormat + 1);
3303 memcpy(pStubMsg->Buffer, pMemory, total_size);
3304 pStubMsg->Buffer += total_size;
3306 pFormat = EmbeddedPointerMarshall(pStubMsg, pMemory, pFormat);
3311 /***********************************************************************
3312 * NdrFixedArrayUnmarshall [RPCRT4.@]
3314 unsigned char * WINAPI NdrFixedArrayUnmarshall(PMIDL_STUB_MESSAGE pStubMsg,
3315 unsigned char **ppMemory,
3316 PFORMAT_STRING pFormat,
3317 unsigned char fMustAlloc)
3319 const NDR_SMFARRAY_FORMAT *pSmFArrayFormat = (const NDR_SMFARRAY_FORMAT *)pFormat;
3320 unsigned long total_size;
3322 TRACE("(%p, %p, %p, %d)\n", pStubMsg, ppMemory, pFormat, fMustAlloc);
3324 if ((pSmFArrayFormat->type != RPC_FC_SMFARRAY) &&
3325 (pSmFArrayFormat->type != RPC_FC_LGFARRAY))
3327 ERR("invalid format type %x\n", pSmFArrayFormat->type);
3328 RpcRaiseException(RPC_S_INTERNAL_ERROR);
3332 ALIGN_POINTER(pStubMsg->Buffer, pSmFArrayFormat->alignment + 1);
3334 if (pSmFArrayFormat->type == RPC_FC_SMFARRAY)
3336 total_size = pSmFArrayFormat->total_size;
3337 pFormat = (unsigned char *)(pSmFArrayFormat + 1);
3341 const NDR_LGFARRAY_FORMAT *pLgFArrayFormat = (const NDR_LGFARRAY_FORMAT *)pFormat;
3342 total_size = pLgFArrayFormat->total_size;
3343 pFormat = (unsigned char *)(pLgFArrayFormat + 1);
3346 if (fMustAlloc || !*ppMemory)
3347 *ppMemory = NdrAllocate(pStubMsg, total_size);
3348 memcpy(*ppMemory, pStubMsg->Buffer, total_size);
3349 pStubMsg->Buffer += total_size;
3351 pFormat = EmbeddedPointerUnmarshall(pStubMsg, ppMemory, pFormat, fMustAlloc);
3356 /***********************************************************************
3357 * NdrFixedArrayBufferSize [RPCRT4.@]
3359 void WINAPI NdrFixedArrayBufferSize(PMIDL_STUB_MESSAGE pStubMsg,
3360 unsigned char *pMemory,
3361 PFORMAT_STRING pFormat)
3363 const NDR_SMFARRAY_FORMAT *pSmFArrayFormat = (const NDR_SMFARRAY_FORMAT *)pFormat;
3364 unsigned long total_size;
3366 TRACE("(%p, %p, %p)\n", pStubMsg, pMemory, pFormat);
3368 if ((pSmFArrayFormat->type != RPC_FC_SMFARRAY) &&
3369 (pSmFArrayFormat->type != RPC_FC_LGFARRAY))
3371 ERR("invalid format type %x\n", pSmFArrayFormat->type);
3372 RpcRaiseException(RPC_S_INTERNAL_ERROR);
3376 ALIGN_LENGTH(pStubMsg->BufferLength, pSmFArrayFormat->alignment + 1);
3378 if (pSmFArrayFormat->type == RPC_FC_SMFARRAY)
3380 total_size = pSmFArrayFormat->total_size;
3381 pFormat = (unsigned char *)(pSmFArrayFormat + 1);
3385 const NDR_LGFARRAY_FORMAT *pLgFArrayFormat = (const NDR_LGFARRAY_FORMAT *)pFormat;
3386 total_size = pLgFArrayFormat->total_size;
3387 pFormat = (unsigned char *)(pLgFArrayFormat + 1);
3389 pStubMsg->BufferLength += total_size;
3391 EmbeddedPointerBufferSize(pStubMsg, pMemory, pFormat);
3394 /***********************************************************************
3395 * NdrFixedArrayMemorySize [RPCRT4.@]
3397 unsigned long WINAPI NdrFixedArrayMemorySize(PMIDL_STUB_MESSAGE pStubMsg,
3398 PFORMAT_STRING pFormat)
3400 const NDR_SMFARRAY_FORMAT *pSmFArrayFormat = (const NDR_SMFARRAY_FORMAT *)pFormat;
3401 unsigned long total_size;
3403 TRACE("(%p, %p)\n", pStubMsg, pFormat);
3405 if ((pSmFArrayFormat->type != RPC_FC_SMFARRAY) &&
3406 (pSmFArrayFormat->type != RPC_FC_LGFARRAY))
3408 ERR("invalid format type %x\n", pSmFArrayFormat->type);
3409 RpcRaiseException(RPC_S_INTERNAL_ERROR);
3413 ALIGN_POINTER(pStubMsg->Buffer, pSmFArrayFormat->alignment + 1);
3415 if (pSmFArrayFormat->type == RPC_FC_SMFARRAY)
3417 total_size = pSmFArrayFormat->total_size;
3418 pFormat = (unsigned char *)(pSmFArrayFormat + 1);
3422 const NDR_LGFARRAY_FORMAT *pLgFArrayFormat = (const NDR_LGFARRAY_FORMAT *)pFormat;
3423 total_size = pLgFArrayFormat->total_size;
3424 pFormat = (unsigned char *)(pLgFArrayFormat + 1);
3426 pStubMsg->Buffer += total_size;
3427 pStubMsg->MemorySize += total_size;
3429 EmbeddedPointerMemorySize(pStubMsg, pFormat);
3434 /***********************************************************************
3435 * NdrFixedArrayFree [RPCRT4.@]
3437 void WINAPI NdrFixedArrayFree(PMIDL_STUB_MESSAGE pStubMsg,
3438 unsigned char *pMemory,
3439 PFORMAT_STRING pFormat)
3441 const NDR_SMFARRAY_FORMAT *pSmFArrayFormat = (const NDR_SMFARRAY_FORMAT *)pFormat;
3443 TRACE("(%p, %p, %p)\n", pStubMsg, pMemory, pFormat);
3445 if ((pSmFArrayFormat->type != RPC_FC_SMFARRAY) &&
3446 (pSmFArrayFormat->type != RPC_FC_LGFARRAY))
3448 ERR("invalid format type %x\n", pSmFArrayFormat->type);
3449 RpcRaiseException(RPC_S_INTERNAL_ERROR);
3453 if (pSmFArrayFormat->type == RPC_FC_SMFARRAY)
3454 pFormat = (unsigned char *)(pSmFArrayFormat + 1);
3457 const NDR_LGFARRAY_FORMAT *pLgFArrayFormat = (const NDR_LGFARRAY_FORMAT *)pFormat;
3458 pFormat = (unsigned char *)(pLgFArrayFormat + 1);
3461 EmbeddedPointerFree(pStubMsg, pMemory, pFormat);
3464 /***********************************************************************
3465 * NdrVaryingArrayMarshall [RPCRT4.@]
3467 unsigned char * WINAPI NdrVaryingArrayMarshall(PMIDL_STUB_MESSAGE pStubMsg,
3468 unsigned char *pMemory,
3469 PFORMAT_STRING pFormat)
3475 /***********************************************************************
3476 * NdrVaryingArrayUnmarshall [RPCRT4.@]
3478 unsigned char * WINAPI NdrVaryingArrayUnmarshall(PMIDL_STUB_MESSAGE pStubMsg,
3479 unsigned char **ppMemory,
3480 PFORMAT_STRING pFormat,
3481 unsigned char fMustAlloc)
3487 /***********************************************************************
3488 * NdrVaryingArrayBufferSize [RPCRT4.@]
3490 void WINAPI NdrVaryingArrayBufferSize(PMIDL_STUB_MESSAGE pStubMsg,
3491 unsigned char *pMemory,
3492 PFORMAT_STRING pFormat)
3497 /***********************************************************************
3498 * NdrVaryingArrayMemorySize [RPCRT4.@]
3500 unsigned long WINAPI NdrVaryingArrayMemorySize(PMIDL_STUB_MESSAGE pStubMsg,
3501 PFORMAT_STRING pFormat)
3507 /***********************************************************************
3508 * NdrVaryingArrayFree [RPCRT4.@]
3510 void WINAPI NdrVaryingArrayFree(PMIDL_STUB_MESSAGE pStubMsg,
3511 unsigned char *pMemory,
3512 PFORMAT_STRING pFormat)
3517 /***********************************************************************
3518 * NdrEncapsulatedUnionMarshall [RPCRT4.@]
3520 unsigned char * WINAPI NdrEncapsulatedUnionMarshall(PMIDL_STUB_MESSAGE pStubMsg,
3521 unsigned char *pMemory,
3522 PFORMAT_STRING pFormat)
3528 /***********************************************************************
3529 * NdrEncapsulatedUnionUnmarshall [RPCRT4.@]
3531 unsigned char * WINAPI NdrEncapsulatedUnionUnmarshall(PMIDL_STUB_MESSAGE pStubMsg,
3532 unsigned char **ppMemory,
3533 PFORMAT_STRING pFormat,
3534 unsigned char fMustAlloc)
3540 /***********************************************************************
3541 * NdrEncapsulatedUnionBufferSize [RPCRT4.@]
3543 void WINAPI NdrEncapsulatedUnionBufferSize(PMIDL_STUB_MESSAGE pStubMsg,
3544 unsigned char *pMemory,
3545 PFORMAT_STRING pFormat)
3550 /***********************************************************************
3551 * NdrEncapsulatedUnionMemorySize [RPCRT4.@]
3553 unsigned long WINAPI NdrEncapsulatedUnionMemorySize(PMIDL_STUB_MESSAGE pStubMsg,
3554 PFORMAT_STRING pFormat)
3560 /***********************************************************************
3561 * NdrEncapsulatedUnionFree [RPCRT4.@]
3563 void WINAPI NdrEncapsulatedUnionFree(PMIDL_STUB_MESSAGE pStubMsg,
3564 unsigned char *pMemory,
3565 PFORMAT_STRING pFormat)
3570 static PFORMAT_STRING get_arm_offset_from_union_arm_selector(PMIDL_STUB_MESSAGE pStubMsg,
3571 unsigned long discriminant,
3572 PFORMAT_STRING pFormat)
3574 unsigned short num_arms, arm, type;
3576 num_arms = *(const SHORT*)pFormat & 0x0fff;
3578 for(arm = 0; arm < num_arms; arm++)
3580 if(discriminant == *(const ULONG*)pFormat)
3588 type = *(const unsigned short*)pFormat;
3589 TRACE("type %04x\n", type);
3590 if(arm == num_arms) /* default arm extras */
3594 ERR("no arm for 0x%lx and no default case\n", discriminant);
3595 RpcRaiseException(RPC_S_INVALID_TAG);
3600 TRACE("falling back to empty default case for 0x%lx\n", discriminant);
3607 static PFORMAT_STRING get_non_encapsulated_union_arm(PMIDL_STUB_MESSAGE pStubMsg,
3609 PFORMAT_STRING pFormat)
3611 pFormat += *(const SHORT*)pFormat;
3614 return get_arm_offset_from_union_arm_selector(pStubMsg, value, pFormat);
3617 /***********************************************************************
3618 * NdrNonEncapsulatedUnionMarshall [RPCRT4.@]
3620 unsigned char * WINAPI NdrNonEncapsulatedUnionMarshall(PMIDL_STUB_MESSAGE pStubMsg,
3621 unsigned char *pMemory,
3622 PFORMAT_STRING pFormat)
3624 unsigned short type;
3625 unsigned char switch_type;
3627 TRACE("(%p, %p, %p)\n", pStubMsg, pMemory, pFormat);
3630 switch_type = *pFormat;
3633 pFormat = ComputeConformance(pStubMsg, pMemory, pFormat, 0);
3634 TRACE("got switch value 0x%lx\n", pStubMsg->MaxCount);
3635 /* Marshall discriminant */
3636 NdrBaseTypeMarshall(pStubMsg, (unsigned char *)&pStubMsg->MaxCount, &switch_type);
3638 pFormat = get_non_encapsulated_union_arm(pStubMsg, pStubMsg->MaxCount, pFormat);
3642 type = *(const unsigned short*)pFormat;
3643 if((type & 0xff00) == 0x8000)
3645 unsigned char basetype = LOBYTE(type);
3646 return NdrBaseTypeMarshall(pStubMsg, pMemory, &basetype);
3650 PFORMAT_STRING desc = pFormat + *(const SHORT*)pFormat;
3651 NDR_MARSHALL m = NdrMarshaller[*desc & NDR_TABLE_MASK];
3654 unsigned char *saved_buffer = NULL;
3661 saved_buffer = pStubMsg->Buffer;
3662 pStubMsg->Buffer += 4; /* for pointer ID */
3663 PointerMarshall(pStubMsg, saved_buffer, *(unsigned char **)pMemory, desc);
3666 m(pStubMsg, pMemory, desc);
3669 else FIXME("no marshaller for embedded type %02x\n", *desc);
3674 static long unmarshall_discriminant(PMIDL_STUB_MESSAGE pStubMsg,
3675 PFORMAT_STRING *ppFormat)
3677 long discriminant = 0;
3685 discriminant = *(UCHAR *)pStubMsg->Buffer;
3686 pStubMsg->Buffer += sizeof(UCHAR);
3691 ALIGN_POINTER(pStubMsg->Buffer, sizeof(USHORT));
3692 discriminant = *(USHORT *)pStubMsg->Buffer;
3693 pStubMsg->Buffer += sizeof(USHORT);
3697 ALIGN_POINTER(pStubMsg->Buffer, sizeof(ULONG));
3698 discriminant = *(ULONG *)pStubMsg->Buffer;
3699 pStubMsg->Buffer += sizeof(ULONG);
3702 FIXME("Unhandled base type: 0x%02x\n", **ppFormat);
3706 if (pStubMsg->fHasNewCorrDesc)
3710 return discriminant;
3713 /**********************************************************************
3714 * NdrNonEncapsulatedUnionUnmarshall[RPCRT4.@]
3716 unsigned char * WINAPI NdrNonEncapsulatedUnionUnmarshall(PMIDL_STUB_MESSAGE pStubMsg,
3717 unsigned char **ppMemory,
3718 PFORMAT_STRING pFormat,
3719 unsigned char fMustAlloc)
3722 unsigned short type, size;
3724 TRACE("(%p, %p, %p, %d)\n", pStubMsg, ppMemory, pFormat, fMustAlloc);
3727 /* Unmarshall discriminant */
3728 discriminant = unmarshall_discriminant(pStubMsg, &pFormat);
3729 TRACE("unmarshalled discriminant %lx\n", discriminant);
3731 pFormat += *(const SHORT*)pFormat;
3733 size = *(const unsigned short*)pFormat;
3736 pFormat = get_arm_offset_from_union_arm_selector(pStubMsg, discriminant, pFormat);
3740 if(!*ppMemory || fMustAlloc)
3741 *ppMemory = NdrAllocate(pStubMsg, size);
3743 type = *(const unsigned short*)pFormat;
3744 if((type & 0xff00) == 0x8000)
3746 unsigned char basetype = LOBYTE(type);
3747 return NdrBaseTypeUnmarshall(pStubMsg, ppMemory, &basetype, fMustAlloc);
3751 PFORMAT_STRING desc = pFormat + *(const SHORT*)pFormat;
3752 NDR_UNMARSHALL m = NdrUnmarshaller[*desc & NDR_TABLE_MASK];
3755 unsigned char *saved_buffer = NULL;
3762 **(void***)ppMemory = NULL;
3763 ALIGN_POINTER(pStubMsg->Buffer, 4);
3764 saved_buffer = pStubMsg->Buffer;
3765 pStubMsg->Buffer += 4; /* for pointer ID */
3766 PointerUnmarshall(pStubMsg, saved_buffer, *(unsigned char ***)ppMemory, desc, fMustAlloc);
3769 m(pStubMsg, ppMemory, desc, fMustAlloc);
3772 else FIXME("no marshaller for embedded type %02x\n", *desc);
3777 /***********************************************************************
3778 * NdrNonEncapsulatedUnionBufferSize [RPCRT4.@]
3780 void WINAPI NdrNonEncapsulatedUnionBufferSize(PMIDL_STUB_MESSAGE pStubMsg,
3781 unsigned char *pMemory,
3782 PFORMAT_STRING pFormat)
3784 unsigned short type;
3785 unsigned char switch_type;
3787 TRACE("(%p, %p, %p)\n", pStubMsg, pMemory, pFormat);
3790 switch_type = *pFormat;
3793 pFormat = ComputeConformance(pStubMsg, pMemory, pFormat, 0);
3794 TRACE("got switch value 0x%lx\n", pStubMsg->MaxCount);
3795 /* Add discriminant size */
3796 NdrBaseTypeBufferSize(pStubMsg, (unsigned char *)&pStubMsg->MaxCount, &switch_type);
3798 pFormat = get_non_encapsulated_union_arm(pStubMsg, pStubMsg->MaxCount, pFormat);
3802 type = *(const unsigned short*)pFormat;
3803 if((type & 0xff00) == 0x8000)
3805 unsigned char basetype = LOBYTE(type);
3806 NdrBaseTypeBufferSize(pStubMsg, pMemory, &basetype);
3810 PFORMAT_STRING desc = pFormat + *(const SHORT*)pFormat;
3811 NDR_BUFFERSIZE m = NdrBufferSizer[*desc & NDR_TABLE_MASK];
3820 ALIGN_LENGTH(pStubMsg->BufferLength, 4);
3821 pStubMsg->BufferLength += 4; /* for pointer ID */
3822 PointerBufferSize(pStubMsg, *(unsigned char **)pMemory, desc);
3825 m(pStubMsg, pMemory, desc);
3828 else FIXME("no buffersizer for embedded type %02x\n", *desc);
3833 /***********************************************************************
3834 * NdrNonEncapsulatedUnionMemorySize [RPCRT4.@]
3836 unsigned long WINAPI NdrNonEncapsulatedUnionMemorySize(PMIDL_STUB_MESSAGE pStubMsg,
3837 PFORMAT_STRING pFormat)
3839 unsigned long discriminant;
3840 unsigned short type, size;
3843 /* Unmarshall discriminant */
3844 discriminant = unmarshall_discriminant(pStubMsg, &pFormat);
3845 TRACE("unmarshalled discriminant 0x%lx\n", discriminant);
3847 pFormat += *(const SHORT*)pFormat;
3849 size = *(const unsigned short*)pFormat;
3852 pFormat = get_arm_offset_from_union_arm_selector(pStubMsg, discriminant, pFormat);
3856 pStubMsg->Memory += size;
3858 type = *(const unsigned short*)pFormat;
3859 if((type & 0xff00) == 0x8000)
3861 return NdrBaseTypeMemorySize(pStubMsg, pFormat);
3865 PFORMAT_STRING desc = pFormat + *(const SHORT*)pFormat;
3866 NDR_MEMORYSIZE m = NdrMemorySizer[*desc & NDR_TABLE_MASK];
3867 unsigned char *saved_buffer;
3876 ALIGN_POINTER(pStubMsg->Buffer, 4);
3877 saved_buffer = pStubMsg->Buffer;
3878 pStubMsg->Buffer += 4;
3879 ALIGN_LENGTH(pStubMsg->MemorySize, 4);
3880 pStubMsg->MemorySize += 4;
3881 PointerMemorySize(pStubMsg, saved_buffer, pFormat);
3884 return m(pStubMsg, desc);
3887 else FIXME("no marshaller for embedded type %02x\n", *desc);
3890 TRACE("size %d\n", size);
3894 /***********************************************************************
3895 * NdrNonEncapsulatedUnionFree [RPCRT4.@]
3897 void WINAPI NdrNonEncapsulatedUnionFree(PMIDL_STUB_MESSAGE pStubMsg,
3898 unsigned char *pMemory,
3899 PFORMAT_STRING pFormat)
3904 /***********************************************************************
3905 * NdrByteCountPointerMarshall [RPCRT4.@]
3907 unsigned char * WINAPI NdrByteCountPointerMarshall(PMIDL_STUB_MESSAGE pStubMsg,
3908 unsigned char *pMemory,
3909 PFORMAT_STRING pFormat)
3915 /***********************************************************************
3916 * NdrByteCountPointerUnmarshall [RPCRT4.@]
3918 unsigned char * WINAPI NdrByteCountPointerUnmarshall(PMIDL_STUB_MESSAGE pStubMsg,
3919 unsigned char **ppMemory,
3920 PFORMAT_STRING pFormat,
3921 unsigned char fMustAlloc)
3927 /***********************************************************************
3928 * NdrByteCountPointerBufferSize [RPCRT4.@]
3930 void WINAPI NdrByteCountPointerBufferSize(PMIDL_STUB_MESSAGE pStubMsg,
3931 unsigned char *pMemory,
3932 PFORMAT_STRING pFormat)
3937 /***********************************************************************
3938 * NdrByteCountPointerMemorySize [RPCRT4.@]
3940 unsigned long WINAPI NdrByteCountPointerMemorySize(PMIDL_STUB_MESSAGE pStubMsg,
3941 PFORMAT_STRING pFormat)
3947 /***********************************************************************
3948 * NdrByteCountPointerFree [RPCRT4.@]
3950 void WINAPI NdrByteCountPointerFree(PMIDL_STUB_MESSAGE pStubMsg,
3951 unsigned char *pMemory,
3952 PFORMAT_STRING pFormat)
3957 /***********************************************************************
3958 * NdrXmitOrRepAsMarshall [RPCRT4.@]
3960 unsigned char * WINAPI NdrXmitOrRepAsMarshall(PMIDL_STUB_MESSAGE pStubMsg,
3961 unsigned char *pMemory,
3962 PFORMAT_STRING pFormat)
3968 /***********************************************************************
3969 * NdrXmitOrRepAsUnmarshall [RPCRT4.@]
3971 unsigned char * WINAPI NdrXmitOrRepAsUnmarshall(PMIDL_STUB_MESSAGE pStubMsg,
3972 unsigned char **ppMemory,
3973 PFORMAT_STRING pFormat,
3974 unsigned char fMustAlloc)
3980 /***********************************************************************
3981 * NdrXmitOrRepAsBufferSize [RPCRT4.@]
3983 void WINAPI NdrXmitOrRepAsBufferSize(PMIDL_STUB_MESSAGE pStubMsg,
3984 unsigned char *pMemory,
3985 PFORMAT_STRING pFormat)
3990 /***********************************************************************
3991 * NdrXmitOrRepAsMemorySize [RPCRT4.@]
3993 unsigned long WINAPI NdrXmitOrRepAsMemorySize(PMIDL_STUB_MESSAGE pStubMsg,
3994 PFORMAT_STRING pFormat)
4000 /***********************************************************************
4001 * NdrXmitOrRepAsFree [RPCRT4.@]
4003 void WINAPI NdrXmitOrRepAsFree(PMIDL_STUB_MESSAGE pStubMsg,
4004 unsigned char *pMemory,
4005 PFORMAT_STRING pFormat)
4010 /***********************************************************************
4011 * NdrBaseTypeMarshall [internal]
4013 static unsigned char *WINAPI NdrBaseTypeMarshall(
4014 PMIDL_STUB_MESSAGE pStubMsg,
4015 unsigned char *pMemory,
4016 PFORMAT_STRING pFormat)
4018 TRACE("pStubMsg %p, pMemory %p, type 0x%02x\n", pStubMsg, pMemory, *pFormat);
4026 *(UCHAR *)pStubMsg->Buffer = *(UCHAR *)pMemory;
4027 pStubMsg->Buffer += sizeof(UCHAR);
4028 TRACE("value: 0x%02x\n", *(UCHAR *)pMemory);
4033 ALIGN_POINTER(pStubMsg->Buffer, sizeof(USHORT));
4034 *(USHORT *)pStubMsg->Buffer = *(USHORT *)pMemory;
4035 pStubMsg->Buffer += sizeof(USHORT);
4036 TRACE("value: 0x%04x\n", *(USHORT *)pMemory);
4040 case RPC_FC_ERROR_STATUS_T:
4042 ALIGN_POINTER(pStubMsg->Buffer, sizeof(ULONG));
4043 *(ULONG *)pStubMsg->Buffer = *(ULONG *)pMemory;
4044 pStubMsg->Buffer += sizeof(ULONG);
4045 TRACE("value: 0x%08lx\n", *(ULONG *)pMemory);
4048 ALIGN_POINTER(pStubMsg->Buffer, sizeof(float));
4049 *(float *)pStubMsg->Buffer = *(float *)pMemory;
4050 pStubMsg->Buffer += sizeof(float);
4053 ALIGN_POINTER(pStubMsg->Buffer, sizeof(double));
4054 *(double *)pStubMsg->Buffer = *(double *)pMemory;
4055 pStubMsg->Buffer += sizeof(double);
4058 ALIGN_POINTER(pStubMsg->Buffer, sizeof(ULONGLONG));
4059 *(ULONGLONG *)pStubMsg->Buffer = *(ULONGLONG *)pMemory;
4060 pStubMsg->Buffer += sizeof(ULONGLONG);
4061 TRACE("value: %s\n", wine_dbgstr_longlong(*(ULONGLONG*)pMemory));
4064 /* only 16-bits on the wire, so do a sanity check */
4065 if (*(UINT *)pMemory > USHRT_MAX)
4066 RpcRaiseException(RPC_X_ENUM_VALUE_OUT_OF_RANGE);
4067 ALIGN_POINTER(pStubMsg->Buffer, sizeof(USHORT));
4068 *(USHORT *)pStubMsg->Buffer = *(UINT *)pMemory;
4069 pStubMsg->Buffer += sizeof(USHORT);
4070 TRACE("value: 0x%04x\n", *(UINT *)pMemory);
4073 FIXME("Unhandled base type: 0x%02x\n", *pFormat);
4076 STD_OVERFLOW_CHECK(pStubMsg);
4078 /* FIXME: what is the correct return value? */
4082 /***********************************************************************
4083 * NdrBaseTypeUnmarshall [internal]
4085 static unsigned char *WINAPI NdrBaseTypeUnmarshall(
4086 PMIDL_STUB_MESSAGE pStubMsg,
4087 unsigned char **ppMemory,
4088 PFORMAT_STRING pFormat,
4089 unsigned char fMustAlloc)
4091 TRACE("pStubMsg: %p, ppMemory: %p, type: 0x%02x, fMustAlloc: %s\n", pStubMsg, ppMemory, *pFormat, fMustAlloc ? "true" : "false");
4093 if (fMustAlloc || !*ppMemory)
4095 unsigned char *Buffer = pStubMsg->Buffer;
4096 unsigned long MemorySize = pStubMsg->MemorySize;
4097 *ppMemory = NdrAllocate(pStubMsg, NdrBaseTypeMemorySize(pStubMsg, pFormat));
4098 pStubMsg->MemorySize = MemorySize;
4099 pStubMsg->Buffer = Buffer;
4102 TRACE("*ppMemory: %p\n", *ppMemory);
4110 **(UCHAR **)ppMemory = *(UCHAR *)pStubMsg->Buffer;
4111 pStubMsg->Buffer += sizeof(UCHAR);
4112 TRACE("value: 0x%02x\n", **(UCHAR **)ppMemory);
4117 ALIGN_POINTER(pStubMsg->Buffer, sizeof(USHORT));
4118 **(USHORT **)ppMemory = *(USHORT *)pStubMsg->Buffer;
4119 pStubMsg->Buffer += sizeof(USHORT);
4120 TRACE("value: 0x%04x\n", **(USHORT **)ppMemory);
4124 case RPC_FC_ERROR_STATUS_T:
4126 ALIGN_POINTER(pStubMsg->Buffer, sizeof(ULONG));
4127 **(ULONG **)ppMemory = *(ULONG *)pStubMsg->Buffer;
4128 pStubMsg->Buffer += sizeof(ULONG);
4129 TRACE("value: 0x%08lx\n", **(ULONG **)ppMemory);
4132 ALIGN_POINTER(pStubMsg->Buffer, sizeof(float));
4133 **(float **)ppMemory = *(float *)pStubMsg->Buffer;
4134 pStubMsg->Buffer += sizeof(float);
4135 TRACE("value: %f\n", **(float **)ppMemory);
4138 ALIGN_POINTER(pStubMsg->Buffer, sizeof(double));
4139 **(double **)ppMemory = *(double*)pStubMsg->Buffer;
4140 pStubMsg->Buffer += sizeof(double);
4141 TRACE("value: %f\n", **(double **)ppMemory);
4144 ALIGN_POINTER(pStubMsg->Buffer, sizeof(ULONGLONG));
4145 **(ULONGLONG **)ppMemory = *(ULONGLONG *)pStubMsg->Buffer;
4146 pStubMsg->Buffer += sizeof(ULONGLONG);
4147 TRACE("value: %s\n", wine_dbgstr_longlong(**(ULONGLONG **)ppMemory));
4150 ALIGN_POINTER(pStubMsg->Buffer, sizeof(USHORT));
4151 /* 16-bits on the wire, but int in memory */
4152 **(UINT **)ppMemory = *(USHORT *)pStubMsg->Buffer;
4153 pStubMsg->Buffer += sizeof(USHORT);
4154 TRACE("value: 0x%08x\n", **(UINT **)ppMemory);
4157 FIXME("Unhandled base type: 0x%02x\n", *pFormat);
4160 /* FIXME: what is the correct return value? */
4165 /***********************************************************************
4166 * NdrBaseTypeBufferSize [internal]
4168 static void WINAPI NdrBaseTypeBufferSize(
4169 PMIDL_STUB_MESSAGE pStubMsg,
4170 unsigned char *pMemory,
4171 PFORMAT_STRING pFormat)
4173 TRACE("pStubMsg %p, pMemory %p, type 0x%02x\n", pStubMsg, pMemory, *pFormat);
4181 pStubMsg->BufferLength += sizeof(UCHAR);
4187 ALIGN_LENGTH(pStubMsg->BufferLength, sizeof(USHORT));
4188 pStubMsg->BufferLength += sizeof(USHORT);
4193 ALIGN_LENGTH(pStubMsg->BufferLength, sizeof(ULONG));
4194 pStubMsg->BufferLength += sizeof(ULONG);
4197 ALIGN_LENGTH(pStubMsg->BufferLength, sizeof(float));
4198 pStubMsg->BufferLength += sizeof(float);
4201 ALIGN_LENGTH(pStubMsg->BufferLength, sizeof(double));
4202 pStubMsg->BufferLength += sizeof(double);
4205 ALIGN_LENGTH(pStubMsg->BufferLength, sizeof(ULONGLONG));
4206 pStubMsg->BufferLength += sizeof(ULONGLONG);
4208 case RPC_FC_ERROR_STATUS_T:
4209 ALIGN_LENGTH(pStubMsg->BufferLength, sizeof(error_status_t));
4210 pStubMsg->BufferLength += sizeof(error_status_t);
4213 FIXME("Unhandled base type: 0x%02x\n", *pFormat);
4217 /***********************************************************************
4218 * NdrBaseTypeMemorySize [internal]
4220 static unsigned long WINAPI NdrBaseTypeMemorySize(
4221 PMIDL_STUB_MESSAGE pStubMsg,
4222 PFORMAT_STRING pFormat)
4230 pStubMsg->Buffer += sizeof(UCHAR);
4231 pStubMsg->MemorySize += sizeof(UCHAR);
4232 return sizeof(UCHAR);
4236 pStubMsg->Buffer += sizeof(USHORT);
4237 pStubMsg->MemorySize += sizeof(USHORT);
4238 return sizeof(USHORT);
4241 pStubMsg->Buffer += sizeof(ULONG);
4242 pStubMsg->MemorySize += sizeof(ULONG);
4243 return sizeof(ULONG);
4245 pStubMsg->Buffer += sizeof(float);
4246 pStubMsg->MemorySize += sizeof(float);
4247 return sizeof(float);
4249 pStubMsg->Buffer += sizeof(double);
4250 pStubMsg->MemorySize += sizeof(double);
4251 return sizeof(double);
4253 pStubMsg->Buffer += sizeof(ULONGLONG);
4254 pStubMsg->MemorySize += sizeof(ULONGLONG);
4255 return sizeof(ULONGLONG);
4256 case RPC_FC_ERROR_STATUS_T:
4257 pStubMsg->Buffer += sizeof(error_status_t);
4258 pStubMsg->MemorySize += sizeof(error_status_t);
4259 return sizeof(error_status_t);
4262 pStubMsg->Buffer += sizeof(INT);
4263 pStubMsg->MemorySize += sizeof(INT);
4266 FIXME("Unhandled base type: 0x%02x\n", *pFormat);
4271 /***********************************************************************
4272 * NdrBaseTypeFree [internal]
4274 static void WINAPI NdrBaseTypeFree(PMIDL_STUB_MESSAGE pStubMsg,
4275 unsigned char *pMemory,
4276 PFORMAT_STRING pFormat)
4278 TRACE("pStubMsg %p pMemory %p type 0x%02x\n", pStubMsg, pMemory, *pFormat);
4283 /***********************************************************************
4284 * NdrClientContextMarshall
4286 void WINAPI NdrClientContextMarshall(PMIDL_STUB_MESSAGE pStubMsg,
4287 NDR_CCONTEXT ContextHandle,
4290 FIXME("(%p, %p, %d): stub\n", pStubMsg, ContextHandle, fCheck);
4293 /***********************************************************************
4294 * NdrClientContextUnmarshall
4296 void WINAPI NdrClientContextUnmarshall(PMIDL_STUB_MESSAGE pStubMsg,
4297 NDR_CCONTEXT * pContextHandle,
4298 RPC_BINDING_HANDLE BindHandle)
4300 FIXME("(%p, %p, %p): stub\n", pStubMsg, pContextHandle, BindHandle);
4303 void WINAPI NdrServerContextMarshall(PMIDL_STUB_MESSAGE pStubMsg,
4304 NDR_SCONTEXT ContextHandle,
4305 NDR_RUNDOWN RundownRoutine )
4307 FIXME("(%p, %p, %p): stub\n", pStubMsg, ContextHandle, RundownRoutine);
4310 NDR_SCONTEXT WINAPI NdrServerContextUnmarshall(PMIDL_STUB_MESSAGE pStubMsg)
4312 FIXME("(%p): stub\n", pStubMsg);
4316 void WINAPI NdrContextHandleSize(PMIDL_STUB_MESSAGE pStubMsg,
4317 unsigned char* pMemory,
4318 PFORMAT_STRING pFormat)
4320 FIXME("(%p, %p, %p): stub\n", pStubMsg, pMemory, pFormat);
4323 NDR_SCONTEXT WINAPI NdrContextHandleInitialize(PMIDL_STUB_MESSAGE pStubMsg,
4324 PFORMAT_STRING pFormat)
4326 FIXME("(%p, %p): stub\n", pStubMsg, pFormat);
4330 void WINAPI NdrServerContextNewMarshall(PMIDL_STUB_MESSAGE pStubMsg,
4331 NDR_SCONTEXT ContextHandle,
4332 NDR_RUNDOWN RundownRoutine,
4333 PFORMAT_STRING pFormat)
4335 FIXME("(%p, %p, %p, %p): stub\n", pStubMsg, ContextHandle, RundownRoutine, pFormat);
4338 NDR_SCONTEXT WINAPI NdrServerContextNewUnmarshall(PMIDL_STUB_MESSAGE pStubMsg,
4339 PFORMAT_STRING pFormat)
4341 FIXME("(%p, %p): stub\n", pStubMsg, pFormat);
4345 RPC_BINDING_HANDLE WINAPI NDRCContextBinding(NDR_CCONTEXT CContext)
4347 FIXME("(%p): stub\n", CContext);