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);
46 #define BUFFER_PARANOIA 20
49 # define LITTLE_ENDIAN_UINT32_WRITE(pchar, uint32) \
50 (*((UINT32 *)(pchar)) = (uint32))
52 # define LITTLE_ENDIAN_UINT32_READ(pchar) \
53 (*((UINT32 *)(pchar)))
55 /* these would work for i386 too, but less efficient */
56 # define LITTLE_ENDIAN_UINT32_WRITE(pchar, uint32) \
57 (*(pchar) = LOBYTE(LOWORD(uint32)), \
58 *((pchar)+1) = HIBYTE(LOWORD(uint32)), \
59 *((pchar)+2) = LOBYTE(HIWORD(uint32)), \
60 *((pchar)+3) = HIBYTE(HIWORD(uint32)), \
61 (uint32)) /* allow as r-value */
63 # define LITTLE_ENDIAN_UINT32_READ(pchar) \
65 MAKEWORD(*(pchar), *((pchar)+1)), \
66 MAKEWORD(*((pchar)+2), *((pchar)+3))))
69 #define BIG_ENDIAN_UINT32_WRITE(pchar, uint32) \
70 (*((pchar)+3) = LOBYTE(LOWORD(uint32)), \
71 *((pchar)+2) = HIBYTE(LOWORD(uint32)), \
72 *((pchar)+1) = LOBYTE(HIWORD(uint32)), \
73 *(pchar) = HIBYTE(HIWORD(uint32)), \
74 (uint32)) /* allow as r-value */
76 #define BIG_ENDIAN_UINT32_READ(pchar) \
78 MAKEWORD(*((pchar)+3), *((pchar)+2)), \
79 MAKEWORD(*((pchar)+1), *(pchar))))
81 #ifdef NDR_LOCAL_IS_BIG_ENDIAN
82 # define NDR_LOCAL_UINT32_WRITE(pchar, uint32) \
83 BIG_ENDIAN_UINT32_WRITE(pchar, uint32)
84 # define NDR_LOCAL_UINT32_READ(pchar) \
85 BIG_ENDIAN_UINT32_READ(pchar)
87 # define NDR_LOCAL_UINT32_WRITE(pchar, uint32) \
88 LITTLE_ENDIAN_UINT32_WRITE(pchar, uint32)
89 # define NDR_LOCAL_UINT32_READ(pchar) \
90 LITTLE_ENDIAN_UINT32_READ(pchar)
93 /* _Align must be the desired alignment,
94 * e.g. ALIGN_LENGTH(len, 4) to align on a dword boundary. */
95 #define ALIGNED_LENGTH(_Len, _Align) (((_Len)+(_Align)-1)&~((_Align)-1))
96 #define ALIGNED_POINTER(_Ptr, _Align) ((LPVOID)ALIGNED_LENGTH((ULONG_PTR)(_Ptr), _Align))
97 #define ALIGN_LENGTH(_Len, _Align) _Len = ALIGNED_LENGTH(_Len, _Align)
98 #define ALIGN_POINTER(_Ptr, _Align) _Ptr = ALIGNED_POINTER(_Ptr, _Align)
100 #define STD_OVERFLOW_CHECK(_Msg) do { \
101 TRACE("buffer=%d/%ld\n", _Msg->Buffer - (unsigned char *)_Msg->RpcMsg->Buffer, _Msg->BufferLength); \
102 if (_Msg->Buffer > (unsigned char *)_Msg->RpcMsg->Buffer + _Msg->BufferLength) \
103 ERR("buffer overflow %d bytes\n", _Msg->Buffer - ((unsigned char *)_Msg->RpcMsg->Buffer + _Msg->BufferLength)); \
106 #define NDR_TABLE_SIZE 128
107 #define NDR_TABLE_MASK 127
109 static unsigned char *WINAPI NdrBaseTypeMarshall(PMIDL_STUB_MESSAGE, unsigned char *, PFORMAT_STRING);
110 static unsigned char *WINAPI NdrBaseTypeUnmarshall(PMIDL_STUB_MESSAGE, unsigned char **, PFORMAT_STRING, unsigned char);
111 static void WINAPI NdrBaseTypeBufferSize(PMIDL_STUB_MESSAGE, unsigned char *, PFORMAT_STRING);
112 static void WINAPI NdrBaseTypeFree(PMIDL_STUB_MESSAGE, unsigned char *, PFORMAT_STRING);
113 static unsigned long WINAPI NdrBaseTypeMemorySize(PMIDL_STUB_MESSAGE, PFORMAT_STRING);
115 const NDR_MARSHALL NdrMarshaller[NDR_TABLE_SIZE] = {
117 NdrBaseTypeMarshall, NdrBaseTypeMarshall, NdrBaseTypeMarshall,
118 NdrBaseTypeMarshall, NdrBaseTypeMarshall, NdrBaseTypeMarshall, NdrBaseTypeMarshall,
119 NdrBaseTypeMarshall, NdrBaseTypeMarshall, NdrBaseTypeMarshall, NdrBaseTypeMarshall,
120 NdrBaseTypeMarshall, NdrBaseTypeMarshall, NdrBaseTypeMarshall, NdrBaseTypeMarshall,
124 NdrPointerMarshall, NdrPointerMarshall,
125 NdrPointerMarshall, NdrPointerMarshall,
127 NdrSimpleStructMarshall, NdrSimpleStructMarshall,
128 NdrConformantStructMarshall, NdrConformantStructMarshall,
129 NdrConformantVaryingStructMarshall,
130 NdrComplexStructMarshall,
132 NdrConformantArrayMarshall,
133 NdrConformantVaryingArrayMarshall,
134 NdrFixedArrayMarshall, NdrFixedArrayMarshall,
135 NdrVaryingArrayMarshall, NdrVaryingArrayMarshall,
136 NdrComplexArrayMarshall,
138 NdrConformantStringMarshall, 0, 0,
139 NdrConformantStringMarshall,
140 NdrNonConformantStringMarshall, 0, 0, 0,
142 NdrEncapsulatedUnionMarshall,
143 NdrNonEncapsulatedUnionMarshall,
145 NdrXmitOrRepAsMarshall, NdrXmitOrRepAsMarshall,
147 NdrInterfacePointerMarshall,
150 NdrUserMarshalMarshall
152 const NDR_UNMARSHALL NdrUnmarshaller[NDR_TABLE_SIZE] = {
154 NdrBaseTypeUnmarshall, NdrBaseTypeUnmarshall, NdrBaseTypeUnmarshall,
155 NdrBaseTypeUnmarshall, NdrBaseTypeUnmarshall, NdrBaseTypeUnmarshall, NdrBaseTypeUnmarshall,
156 NdrBaseTypeUnmarshall, NdrBaseTypeUnmarshall, NdrBaseTypeUnmarshall, NdrBaseTypeUnmarshall,
157 NdrBaseTypeUnmarshall, NdrBaseTypeUnmarshall, NdrBaseTypeUnmarshall, NdrBaseTypeUnmarshall,
159 NdrBaseTypeUnmarshall,
161 NdrPointerUnmarshall, NdrPointerUnmarshall,
162 NdrPointerUnmarshall, NdrPointerUnmarshall,
164 NdrSimpleStructUnmarshall, NdrSimpleStructUnmarshall,
165 NdrConformantStructUnmarshall, NdrConformantStructUnmarshall,
166 NdrConformantVaryingStructUnmarshall,
167 NdrComplexStructUnmarshall,
169 NdrConformantArrayUnmarshall,
170 NdrConformantVaryingArrayUnmarshall,
171 NdrFixedArrayUnmarshall, NdrFixedArrayUnmarshall,
172 NdrVaryingArrayUnmarshall, NdrVaryingArrayUnmarshall,
173 NdrComplexArrayUnmarshall,
175 NdrConformantStringUnmarshall, 0, 0,
176 NdrConformantStringUnmarshall,
177 NdrNonConformantStringUnmarshall, 0, 0, 0,
179 NdrEncapsulatedUnionUnmarshall,
180 NdrNonEncapsulatedUnionUnmarshall,
182 NdrXmitOrRepAsUnmarshall, NdrXmitOrRepAsUnmarshall,
184 NdrInterfacePointerUnmarshall,
187 NdrUserMarshalUnmarshall
189 const NDR_BUFFERSIZE NdrBufferSizer[NDR_TABLE_SIZE] = {
191 NdrBaseTypeBufferSize, NdrBaseTypeBufferSize, NdrBaseTypeBufferSize,
192 NdrBaseTypeBufferSize, NdrBaseTypeBufferSize, NdrBaseTypeBufferSize, NdrBaseTypeBufferSize,
193 NdrBaseTypeBufferSize, NdrBaseTypeBufferSize, NdrBaseTypeBufferSize, NdrBaseTypeBufferSize,
194 NdrBaseTypeBufferSize, NdrBaseTypeBufferSize, NdrBaseTypeBufferSize, NdrBaseTypeBufferSize,
196 NdrBaseTypeBufferSize,
198 NdrPointerBufferSize, NdrPointerBufferSize,
199 NdrPointerBufferSize, NdrPointerBufferSize,
201 NdrSimpleStructBufferSize, NdrSimpleStructBufferSize,
202 NdrConformantStructBufferSize, NdrConformantStructBufferSize,
203 NdrConformantVaryingStructBufferSize,
204 NdrComplexStructBufferSize,
206 NdrConformantArrayBufferSize,
207 NdrConformantVaryingArrayBufferSize,
208 NdrFixedArrayBufferSize, NdrFixedArrayBufferSize,
209 NdrVaryingArrayBufferSize, NdrVaryingArrayBufferSize,
210 NdrComplexArrayBufferSize,
212 NdrConformantStringBufferSize, 0, 0,
213 NdrConformantStringBufferSize,
214 NdrNonConformantStringBufferSize, 0, 0, 0,
216 NdrEncapsulatedUnionBufferSize,
217 NdrNonEncapsulatedUnionBufferSize,
219 NdrXmitOrRepAsBufferSize, NdrXmitOrRepAsBufferSize,
221 NdrInterfacePointerBufferSize,
224 NdrUserMarshalBufferSize
226 const NDR_MEMORYSIZE NdrMemorySizer[NDR_TABLE_SIZE] = {
228 NdrBaseTypeMemorySize, NdrBaseTypeMemorySize, NdrBaseTypeMemorySize,
229 NdrBaseTypeMemorySize, NdrBaseTypeMemorySize, NdrBaseTypeMemorySize, NdrBaseTypeMemorySize,
230 NdrBaseTypeMemorySize, NdrBaseTypeMemorySize, NdrBaseTypeMemorySize, NdrBaseTypeMemorySize,
231 NdrBaseTypeMemorySize, NdrBaseTypeMemorySize, NdrBaseTypeMemorySize, NdrBaseTypeMemorySize,
233 NdrBaseTypeMemorySize,
235 NdrPointerMemorySize, NdrPointerMemorySize,
236 NdrPointerMemorySize, NdrPointerMemorySize,
238 NdrSimpleStructMemorySize, NdrSimpleStructMemorySize,
240 NdrComplexStructMemorySize,
242 NdrConformantArrayMemorySize, 0, 0, 0, 0, 0,
243 NdrComplexArrayMemorySize,
245 NdrConformantStringMemorySize, 0, 0,
246 NdrConformantStringMemorySize,
247 NdrNonConformantStringMemorySize, 0, 0, 0,
251 NdrInterfacePointerMemorySize,
254 NdrUserMarshalMemorySize
256 const NDR_FREE NdrFreer[NDR_TABLE_SIZE] = {
258 NdrBaseTypeFree, NdrBaseTypeFree, NdrBaseTypeFree,
259 NdrBaseTypeFree, NdrBaseTypeFree, NdrBaseTypeFree, NdrBaseTypeFree,
260 NdrBaseTypeFree, NdrBaseTypeFree, NdrBaseTypeFree, NdrBaseTypeFree,
261 NdrBaseTypeFree, NdrBaseTypeFree, NdrBaseTypeFree, NdrBaseTypeFree,
265 NdrPointerFree, NdrPointerFree,
266 NdrPointerFree, NdrPointerFree,
268 NdrSimpleStructFree, NdrSimpleStructFree,
269 NdrConformantStructFree, NdrConformantStructFree,
270 NdrConformantVaryingStructFree,
271 NdrComplexStructFree,
273 NdrConformantArrayFree,
274 NdrConformantVaryingArrayFree,
275 NdrFixedArrayFree, NdrFixedArrayFree,
276 NdrVaryingArrayFree, NdrVaryingArrayFree,
282 NdrEncapsulatedUnionFree,
283 NdrNonEncapsulatedUnionFree,
285 NdrXmitOrRepAsFree, NdrXmitOrRepAsFree,
287 NdrInterfacePointerFree,
293 void * WINAPI NdrAllocate(MIDL_STUB_MESSAGE *pStubMsg, size_t len)
295 /* hmm, this is probably supposed to do more? */
296 return pStubMsg->pfnAllocate(len);
299 static void WINAPI NdrFree(MIDL_STUB_MESSAGE *pStubMsg, unsigned char *Pointer)
301 pStubMsg->pfnFree(Pointer);
304 static inline BOOL IsConformanceOrVariancePresent(PFORMAT_STRING pFormat)
306 return (*(const ULONG *)pFormat != -1);
309 PFORMAT_STRING ReadConformance(MIDL_STUB_MESSAGE *pStubMsg, PFORMAT_STRING pFormat)
311 ALIGN_POINTER(pStubMsg->Buffer, 4);
312 pStubMsg->MaxCount = NDR_LOCAL_UINT32_READ(pStubMsg->Buffer);
313 pStubMsg->Buffer += 4;
314 TRACE("unmarshalled conformance is %ld\n", pStubMsg->MaxCount);
315 if (pStubMsg->fHasNewCorrDesc)
321 static inline PFORMAT_STRING ReadVariance(MIDL_STUB_MESSAGE *pStubMsg, PFORMAT_STRING pFormat)
323 if (pFormat && !IsConformanceOrVariancePresent(pFormat))
325 pStubMsg->Offset = 0;
326 pStubMsg->ActualCount = pStubMsg->MaxCount;
330 ALIGN_POINTER(pStubMsg->Buffer, 4);
331 pStubMsg->Offset = NDR_LOCAL_UINT32_READ(pStubMsg->Buffer);
332 pStubMsg->Buffer += 4;
333 TRACE("offset is %ld\n", pStubMsg->Offset);
334 pStubMsg->ActualCount = NDR_LOCAL_UINT32_READ(pStubMsg->Buffer);
335 pStubMsg->Buffer += 4;
336 TRACE("variance is %ld\n", pStubMsg->ActualCount);
339 if (pStubMsg->fHasNewCorrDesc)
345 /* writes the conformance value to the buffer */
346 static inline void WriteConformance(MIDL_STUB_MESSAGE *pStubMsg)
348 ALIGN_POINTER(pStubMsg->Buffer, 4);
349 NDR_LOCAL_UINT32_WRITE(pStubMsg->Buffer, pStubMsg->MaxCount);
350 pStubMsg->Buffer += 4;
353 /* writes the variance values to the buffer */
354 static inline void WriteVariance(MIDL_STUB_MESSAGE *pStubMsg)
356 ALIGN_POINTER(pStubMsg->Buffer, 4);
357 NDR_LOCAL_UINT32_WRITE(pStubMsg->Buffer, pStubMsg->Offset);
358 pStubMsg->Buffer += 4;
359 NDR_LOCAL_UINT32_WRITE(pStubMsg->Buffer, pStubMsg->ActualCount);
360 pStubMsg->Buffer += 4;
363 /* requests buffer space for the conformance value */
364 static inline void SizeConformance(MIDL_STUB_MESSAGE *pStubMsg)
366 ALIGN_LENGTH(pStubMsg->BufferLength, 4);
367 pStubMsg->BufferLength += 4;
370 /* requests buffer space for the variance values */
371 static inline void SizeVariance(MIDL_STUB_MESSAGE *pStubMsg)
373 ALIGN_LENGTH(pStubMsg->BufferLength, 4);
374 pStubMsg->BufferLength += 8;
377 PFORMAT_STRING ComputeConformanceOrVariance(
378 MIDL_STUB_MESSAGE *pStubMsg, unsigned char *pMemory,
379 PFORMAT_STRING pFormat, ULONG_PTR def, ULONG *pCount)
381 BYTE dtype = pFormat[0] & 0xf;
382 short ofs = *(short *)&pFormat[2];
386 if (!IsConformanceOrVariancePresent(pFormat)) {
387 /* null descriptor */
392 switch (pFormat[0] & 0xf0) {
393 case RPC_FC_NORMAL_CONFORMANCE:
394 TRACE("normal conformance, ofs=%d\n", ofs);
397 case RPC_FC_POINTER_CONFORMANCE:
398 TRACE("pointer conformance, ofs=%d\n", ofs);
399 ptr = pStubMsg->Memory;
401 case RPC_FC_TOP_LEVEL_CONFORMANCE:
402 TRACE("toplevel conformance, ofs=%d\n", ofs);
403 if (pStubMsg->StackTop) {
404 ptr = pStubMsg->StackTop;
407 /* -Os mode, *pCount is already set */
411 case RPC_FC_CONSTANT_CONFORMANCE:
412 data = ofs | ((DWORD)pFormat[1] << 16);
413 TRACE("constant conformance, val=%ld\n", data);
416 case RPC_FC_TOP_LEVEL_MULTID_CONFORMANCE:
417 FIXME("toplevel multidimensional conformance, ofs=%d\n", ofs);
418 if (pStubMsg->StackTop) {
419 ptr = pStubMsg->StackTop;
427 FIXME("unknown conformance type %x\n", pFormat[0] & 0xf0);
430 switch (pFormat[1]) {
431 case RPC_FC_DEREFERENCE:
432 ptr = *(LPVOID*)((char *)ptr + ofs);
434 case RPC_FC_CALLBACK:
436 unsigned char *old_stack_top = pStubMsg->StackTop;
437 pStubMsg->StackTop = ptr;
439 /* ofs is index into StubDesc->apfnExprEval */
440 TRACE("callback conformance into apfnExprEval[%d]\n", ofs);
441 pStubMsg->StubDesc->apfnExprEval[ofs](pStubMsg);
443 pStubMsg->StackTop = old_stack_top;
447 ptr = (char *)ptr + ofs;
460 data = *(USHORT*)ptr;
471 FIXME("unknown conformance data type %x\n", dtype);
474 TRACE("dereferenced data type %x at %p, got %ld\n", dtype, ptr, data);
477 switch (pFormat[1]) {
481 case RPC_FC_DEREFERENCE:
482 /* already handled */
497 FIXME("unknown conformance op %d\n", pFormat[1]);
502 TRACE("resulting conformance is %ld\n", *pCount);
503 if (pStubMsg->fHasNewCorrDesc)
511 * NdrConformantString:
513 * What MS calls a ConformantString is, in DCE terminology,
514 * a Varying-Conformant String.
516 * maxlen: DWORD (max # of CHARTYPE characters, inclusive of '\0')
517 * offset: DWORD (actual string data begins at (offset) CHARTYPE's
518 * into unmarshalled string)
519 * length: DWORD (# of CHARTYPE characters, inclusive of '\0')
521 * data: CHARTYPE[maxlen]
523 * ], where CHARTYPE is the appropriate character type (specified externally)
527 /***********************************************************************
528 * NdrConformantStringMarshall [RPCRT4.@]
530 unsigned char *WINAPI NdrConformantStringMarshall(MIDL_STUB_MESSAGE *pStubMsg,
531 unsigned char *pszMessage, PFORMAT_STRING pFormat)
533 unsigned long len, esize;
535 TRACE("(pStubMsg == ^%p, pszMessage == ^%p, pFormat == ^%p)\n", pStubMsg, pszMessage, pFormat);
538 if (*pFormat == RPC_FC_C_CSTRING) {
539 TRACE("string=%s\n", debugstr_a((char*)pszMessage));
540 len = strlen((char*)pszMessage)+1;
543 else if (*pFormat == RPC_FC_C_WSTRING) {
544 TRACE("string=%s\n", debugstr_w((LPWSTR)pszMessage));
545 len = strlenW((LPWSTR)pszMessage)+1;
549 ERR("Unhandled string type: %#x\n", *pFormat);
550 /* FIXME: raise an exception. */
554 if (pFormat[1] != RPC_FC_PAD) {
555 FIXME("sized string format=%d\n", pFormat[1]);
558 assert( (pStubMsg->BufferLength >= (len*esize + 13)) && (pStubMsg->Buffer != NULL) );
560 pStubMsg->MaxCount = pStubMsg->ActualCount = len;
561 pStubMsg->Offset = 0;
562 WriteConformance(pStubMsg);
563 WriteVariance(pStubMsg);
565 memcpy(pStubMsg->Buffer, pszMessage, len*esize); /* the string itself */
566 pStubMsg->Buffer += len*esize;
568 STD_OVERFLOW_CHECK(pStubMsg);
571 return NULL; /* is this always right? */
574 /***********************************************************************
575 * NdrConformantStringBufferSize [RPCRT4.@]
577 void WINAPI NdrConformantStringBufferSize(PMIDL_STUB_MESSAGE pStubMsg,
578 unsigned char* pMemory, PFORMAT_STRING pFormat)
580 TRACE("(pStubMsg == ^%p, pMemory == ^%p, pFormat == ^%p)\n", pStubMsg, pMemory, pFormat);
582 SizeConformance(pStubMsg);
583 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 + BUFFER_PARANOIA;
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 + BUFFER_PARANOIA;
597 ERR("Unhandled string type: %#x\n", *pFormat);
598 /* FIXME: raise an exception */
601 if (pFormat[1] != RPC_FC_PAD) {
602 FIXME("sized string format=%d\n", pFormat[1]);
606 /************************************************************************
607 * NdrConformantStringMemorySize [RPCRT4.@]
609 unsigned long WINAPI NdrConformantStringMemorySize( PMIDL_STUB_MESSAGE pStubMsg,
610 PFORMAT_STRING pFormat )
612 unsigned long rslt = 0;
614 TRACE("(pStubMsg == ^%p, pFormat == ^%p)\n", pStubMsg, pFormat);
616 assert(pStubMsg && pFormat);
618 if (*pFormat == RPC_FC_C_CSTRING) {
619 rslt = NDR_LOCAL_UINT32_READ(pStubMsg->Buffer); /* maxlen */
621 else if (*pFormat == RPC_FC_C_WSTRING) {
622 rslt = NDR_LOCAL_UINT32_READ(pStubMsg->Buffer)*2; /* maxlen */
625 ERR("Unhandled string type: %#x\n", *pFormat);
626 /* FIXME: raise an exception */
629 if (pFormat[1] != RPC_FC_PAD) {
630 FIXME("sized string format=%d\n", pFormat[1]);
633 TRACE(" --> %lu\n", rslt);
637 /************************************************************************
638 * NdrConformantStringUnmarshall [RPCRT4.@]
640 unsigned char *WINAPI NdrConformantStringUnmarshall( PMIDL_STUB_MESSAGE pStubMsg,
641 unsigned char** ppMemory, PFORMAT_STRING pFormat, unsigned char fMustAlloc )
643 unsigned long len, esize;
645 TRACE("(pStubMsg == ^%p, *pMemory == ^%p, pFormat == ^%p, fMustAlloc == %u)\n",
646 pStubMsg, *ppMemory, pFormat, fMustAlloc);
648 assert(pFormat && ppMemory && pStubMsg);
650 ReadConformance(pStubMsg, NULL);
651 ReadVariance(pStubMsg, NULL);
653 if (*pFormat == RPC_FC_C_CSTRING) esize = 1;
654 else if (*pFormat == RPC_FC_C_WSTRING) esize = 2;
656 ERR("Unhandled string type: %#x\n", *pFormat);
657 /* FIXME: raise an exception */
661 if (pFormat[1] != RPC_FC_PAD) {
662 FIXME("sized string format=%d\n", pFormat[1]);
665 len = pStubMsg->ActualCount;
667 if (fMustAlloc || !*ppMemory)
668 *ppMemory = NdrAllocate(pStubMsg, len*esize + BUFFER_PARANOIA);
670 memcpy(*ppMemory, pStubMsg->Buffer, len*esize);
672 pStubMsg->Buffer += len*esize;
674 if (*pFormat == RPC_FC_C_CSTRING) {
675 TRACE("string=%s\n", debugstr_a((char*)*ppMemory));
677 else if (*pFormat == RPC_FC_C_WSTRING) {
678 TRACE("string=%s\n", debugstr_w((LPWSTR)*ppMemory));
681 return NULL; /* FIXME: is this always right? */
684 /***********************************************************************
685 * NdrNonConformantStringMarshall [RPCRT4.@]
687 unsigned char * WINAPI NdrNonConformantStringMarshall(PMIDL_STUB_MESSAGE pStubMsg,
688 unsigned char *pMemory,
689 PFORMAT_STRING pFormat)
695 /***********************************************************************
696 * NdrNonConformantStringUnmarshall [RPCRT4.@]
698 unsigned char * WINAPI NdrNonConformantStringUnmarshall(PMIDL_STUB_MESSAGE pStubMsg,
699 unsigned char **ppMemory,
700 PFORMAT_STRING pFormat,
701 unsigned char fMustAlloc)
707 /***********************************************************************
708 * NdrNonConformantStringBufferSize [RPCRT4.@]
710 void WINAPI NdrNonConformantStringBufferSize(PMIDL_STUB_MESSAGE pStubMsg,
711 unsigned char *pMemory,
712 PFORMAT_STRING pFormat)
717 /***********************************************************************
718 * NdrNonConformantStringMemorySize [RPCRT4.@]
720 unsigned long WINAPI NdrNonConformantStringMemorySize(PMIDL_STUB_MESSAGE pStubMsg,
721 PFORMAT_STRING pFormat)
727 static inline void dump_pointer_attr(unsigned char attr)
729 if (attr & RPC_FC_P_ALLOCALLNODES)
730 TRACE(" RPC_FC_P_ALLOCALLNODES");
731 if (attr & RPC_FC_P_DONTFREE)
732 TRACE(" RPC_FC_P_DONTFREE");
733 if (attr & RPC_FC_P_ONSTACK)
734 TRACE(" RPC_FC_P_ONSTACK");
735 if (attr & RPC_FC_P_SIMPLEPOINTER)
736 TRACE(" RPC_FC_P_SIMPLEPOINTER");
737 if (attr & RPC_FC_P_DEREF)
738 TRACE(" RPC_FC_P_DEREF");
742 /***********************************************************************
745 void WINAPI PointerMarshall(PMIDL_STUB_MESSAGE pStubMsg,
746 unsigned char *Buffer,
747 unsigned char *Pointer,
748 PFORMAT_STRING pFormat)
750 unsigned type = pFormat[0], attr = pFormat[1];
754 TRACE("(%p,%p,%p,%p)\n", pStubMsg, Buffer, Pointer, pFormat);
755 TRACE("type=0x%x, attr=", type); dump_pointer_attr(attr);
757 if (attr & RPC_FC_P_SIMPLEPOINTER) desc = pFormat;
758 else desc = pFormat + *(const SHORT*)pFormat;
761 case RPC_FC_RP: /* ref pointer (always non-null) */
762 #if 0 /* this causes problems for InstallShield so is disabled - we need more tests */
764 RpcRaiseException(RPC_X_NULL_REF_POINTER);
767 case RPC_FC_UP: /* unique pointer */
768 case RPC_FC_OP: /* object pointer - same as unique here */
769 TRACE("writing %p to buffer\n", Pointer);
770 NDR_LOCAL_UINT32_WRITE(Buffer, (unsigned long)Pointer);
774 FIXME("unhandled ptr type=%02x\n", type);
775 RpcRaiseException(RPC_X_BAD_STUB_DATA);
778 TRACE("calling marshaller for type 0x%x\n", (int)*desc);
781 if (attr & RPC_FC_P_DEREF) {
782 Pointer = *(unsigned char**)Pointer;
783 TRACE("deref => %p\n", Pointer);
785 m = NdrMarshaller[*desc & NDR_TABLE_MASK];
786 if (m) m(pStubMsg, Pointer, desc);
787 else FIXME("no marshaller for data type=%02x\n", *desc);
790 STD_OVERFLOW_CHECK(pStubMsg);
793 /***********************************************************************
796 void WINAPI PointerUnmarshall(PMIDL_STUB_MESSAGE pStubMsg,
797 unsigned char *Buffer,
798 unsigned char **pPointer,
799 PFORMAT_STRING pFormat,
800 unsigned char fMustAlloc)
802 unsigned type = pFormat[0], attr = pFormat[1];
805 DWORD pointer_id = 0;
807 TRACE("(%p,%p,%p,%p,%d)\n", pStubMsg, Buffer, pPointer, pFormat, fMustAlloc);
808 TRACE("type=0x%x, attr=", type); dump_pointer_attr(attr);
810 if (attr & RPC_FC_P_SIMPLEPOINTER) desc = pFormat;
811 else desc = pFormat + *(const SHORT*)pFormat;
814 case RPC_FC_RP: /* ref pointer (always non-null) */
817 case RPC_FC_UP: /* unique pointer */
818 pointer_id = NDR_LOCAL_UINT32_READ(Buffer);
819 TRACE("pointer_id is 0x%08lx\n", pointer_id);
821 case RPC_FC_OP: /* object pointer - we must free data before overwriting it */
822 pointer_id = NDR_LOCAL_UINT32_READ(Buffer);
823 TRACE("pointer_id is 0x%08lx\n", pointer_id);
825 FIXME("free object pointer %p\n", *pPointer);
829 FIXME("unhandled ptr type=%02x\n", type);
830 RpcRaiseException(RPC_X_BAD_STUB_DATA);
834 if (attr & RPC_FC_P_DEREF) {
835 if (!*pPointer || fMustAlloc)
836 *pPointer = NdrAllocate(pStubMsg, sizeof(void *));
837 pPointer = *(unsigned char***)pPointer;
838 TRACE("deref => %p\n", pPointer);
840 m = NdrUnmarshaller[*desc & NDR_TABLE_MASK];
841 if (m) m(pStubMsg, pPointer, desc, fMustAlloc);
842 else FIXME("no unmarshaller for data type=%02x\n", *desc);
845 TRACE("pointer=%p\n", *pPointer);
848 /***********************************************************************
851 void WINAPI PointerBufferSize(PMIDL_STUB_MESSAGE pStubMsg,
852 unsigned char *Pointer,
853 PFORMAT_STRING pFormat)
855 unsigned type = pFormat[0], attr = pFormat[1];
859 TRACE("(%p,%p,%p)\n", pStubMsg, Pointer, pFormat);
860 TRACE("type=0x%x, attr=", type); dump_pointer_attr(attr);
862 if (attr & RPC_FC_P_SIMPLEPOINTER) desc = pFormat;
863 else desc = pFormat + *(const SHORT*)pFormat;
866 case RPC_FC_RP: /* ref pointer (always non-null) */
870 /* NULL pointer has no further representation */
876 FIXME("unhandled ptr type=%02x\n", type);
877 RpcRaiseException(RPC_X_BAD_STUB_DATA);
880 if (attr & RPC_FC_P_DEREF) {
881 Pointer = *(unsigned char**)Pointer;
882 TRACE("deref => %p\n", Pointer);
885 m = NdrBufferSizer[*desc & NDR_TABLE_MASK];
886 if (m) m(pStubMsg, Pointer, desc);
887 else FIXME("no buffersizer for data type=%02x\n", *desc);
890 /***********************************************************************
891 * PointerMemorySize [RPCRT4.@]
893 unsigned long WINAPI PointerMemorySize(PMIDL_STUB_MESSAGE pStubMsg,
894 unsigned char *Buffer,
895 PFORMAT_STRING pFormat)
897 unsigned type = pFormat[0], attr = pFormat[1];
901 FIXME("(%p,%p,%p): stub\n", pStubMsg, Buffer, pFormat);
902 TRACE("type=0x%x, attr=", type); dump_pointer_attr(attr);
904 if (attr & RPC_FC_P_SIMPLEPOINTER) desc = pFormat;
905 else desc = pFormat + *(const SHORT*)pFormat;
908 case RPC_FC_RP: /* ref pointer (always non-null) */
911 FIXME("unhandled ptr type=%02x\n", type);
912 RpcRaiseException(RPC_X_BAD_STUB_DATA);
915 if (attr & RPC_FC_P_DEREF) {
919 m = NdrMemorySizer[*desc & NDR_TABLE_MASK];
920 if (m) m(pStubMsg, desc);
921 else FIXME("no memorysizer for data type=%02x\n", *desc);
926 /***********************************************************************
927 * PointerFree [RPCRT4.@]
929 void WINAPI PointerFree(PMIDL_STUB_MESSAGE pStubMsg,
930 unsigned char *Pointer,
931 PFORMAT_STRING pFormat)
933 unsigned type = pFormat[0], attr = pFormat[1];
937 TRACE("(%p,%p,%p)\n", pStubMsg, Pointer, pFormat);
938 TRACE("type=0x%x, attr=", type); dump_pointer_attr(attr);
939 if (attr & RPC_FC_P_DONTFREE) return;
941 if (attr & RPC_FC_P_SIMPLEPOINTER) desc = pFormat;
942 else desc = pFormat + *(const SHORT*)pFormat;
944 if (!Pointer) return;
946 if (attr & RPC_FC_P_DEREF) {
947 Pointer = *(unsigned char**)Pointer;
948 TRACE("deref => %p\n", Pointer);
951 m = NdrFreer[*desc & NDR_TABLE_MASK];
952 if (m) m(pStubMsg, Pointer, desc);
954 /* hmm... is this sensible?
955 * perhaps we should check if the memory comes from NdrAllocate,
956 * and deallocate only if so - checking if the pointer is between
957 * BufferStart and BufferEnd is probably no good since the buffer
958 * may be reallocated when the server wants to marshal the reply */
960 case RPC_FC_BOGUS_STRUCT:
961 case RPC_FC_BOGUS_ARRAY:
962 case RPC_FC_USER_MARSHAL:
967 FIXME("unhandled data type=%02x\n", *desc);
969 case RPC_FC_C_CSTRING:
970 case RPC_FC_C_WSTRING:
971 if (pStubMsg->ReuseBuffer) goto notfree;
977 if (attr & RPC_FC_P_ONSTACK) {
978 TRACE("not freeing stack ptr %p\n", Pointer);
981 TRACE("freeing %p\n", Pointer);
982 NdrFree(pStubMsg, Pointer);
985 TRACE("not freeing %p\n", Pointer);
988 /***********************************************************************
989 * EmbeddedPointerMarshall
991 unsigned char * WINAPI EmbeddedPointerMarshall(PMIDL_STUB_MESSAGE pStubMsg,
992 unsigned char *pMemory,
993 PFORMAT_STRING pFormat)
995 unsigned char *Mark = pStubMsg->BufferMark;
996 unsigned long Offset = pStubMsg->Offset;
997 unsigned ofs, rep, count, stride, xofs;
1000 TRACE("(%p,%p,%p)\n", pStubMsg, pMemory, pFormat);
1002 if (*pFormat != RPC_FC_PP) return NULL;
1005 while (pFormat[0] != RPC_FC_END) {
1006 switch (pFormat[0]) {
1008 FIXME("unknown repeat type %d\n", pFormat[0]);
1009 case RPC_FC_NO_REPEAT:
1017 case RPC_FC_FIXED_REPEAT:
1018 rep = *(const WORD*)&pFormat[2];
1019 stride = *(const WORD*)&pFormat[4];
1020 ofs = *(const WORD*)&pFormat[6];
1021 count = *(const WORD*)&pFormat[8];
1025 case RPC_FC_VARIABLE_REPEAT:
1026 rep = pStubMsg->MaxCount;
1027 stride = *(const WORD*)&pFormat[2];
1028 ofs = *(const WORD*)&pFormat[4];
1029 count = *(const WORD*)&pFormat[6];
1030 xofs = (pFormat[1] == RPC_FC_VARIABLE_OFFSET) ? Offset * stride : 0;
1034 for (i = 0; i < rep; i++) {
1035 PFORMAT_STRING info = pFormat;
1036 unsigned char *membase = pMemory + (i * stride);
1037 unsigned char *bufbase = Mark + (i * stride);
1039 /* ofs doesn't seem to matter in this context */
1040 for (u=0; u<count; u++,info+=8) {
1041 unsigned char *memptr = membase + *(const SHORT*)&info[0];
1042 unsigned char *bufptr = bufbase + *(const SHORT*)&info[2];
1043 PointerMarshall(pStubMsg, bufptr, *(unsigned char**)memptr, info+4);
1046 pFormat += 8 * count;
1049 STD_OVERFLOW_CHECK(pStubMsg);
1054 /***********************************************************************
1055 * EmbeddedPointerUnmarshall
1057 unsigned char * WINAPI EmbeddedPointerUnmarshall(PMIDL_STUB_MESSAGE pStubMsg,
1058 unsigned char **ppMemory,
1059 PFORMAT_STRING pFormat,
1060 unsigned char fMustAlloc)
1062 unsigned char *Mark = pStubMsg->BufferMark;
1063 unsigned long Offset = pStubMsg->Offset;
1064 unsigned ofs, rep, count, stride, xofs;
1067 TRACE("(%p,%p,%p,%d)\n", pStubMsg, ppMemory, pFormat, fMustAlloc);
1069 if (*pFormat != RPC_FC_PP) return NULL;
1072 while (pFormat[0] != RPC_FC_END) {
1073 TRACE("pFormat[0] = 0x%x\n", pFormat[0]);
1074 switch (pFormat[0]) {
1076 FIXME("unknown repeat type %d\n", pFormat[0]);
1077 case RPC_FC_NO_REPEAT:
1085 case RPC_FC_FIXED_REPEAT:
1086 rep = *(const WORD*)&pFormat[2];
1087 stride = *(const WORD*)&pFormat[4];
1088 ofs = *(const WORD*)&pFormat[6];
1089 count = *(const WORD*)&pFormat[8];
1093 case RPC_FC_VARIABLE_REPEAT:
1094 rep = pStubMsg->MaxCount;
1095 stride = *(const WORD*)&pFormat[2];
1096 ofs = *(const WORD*)&pFormat[4];
1097 count = *(const WORD*)&pFormat[6];
1098 xofs = (pFormat[1] == RPC_FC_VARIABLE_OFFSET) ? Offset * stride : 0;
1102 /* ofs doesn't seem to matter in this context */
1103 for (i = 0; i < rep; i++) {
1104 PFORMAT_STRING info = pFormat;
1105 unsigned char *membase = *ppMemory + (i * stride);
1106 unsigned char *bufbase = Mark + (i * stride);
1108 for (u=0; u<count; u++,info+=8) {
1109 unsigned char *memptr = membase + *(const SHORT*)&info[0];
1110 unsigned char *bufptr = bufbase + *(const SHORT*)&info[2];
1111 *(void **)memptr = NULL;
1112 PointerUnmarshall(pStubMsg, bufptr, (unsigned char**)memptr, info+4, fMustAlloc);
1115 pFormat += 8 * count;
1121 /***********************************************************************
1122 * EmbeddedPointerBufferSize
1124 void WINAPI EmbeddedPointerBufferSize(PMIDL_STUB_MESSAGE pStubMsg,
1125 unsigned char *pMemory,
1126 PFORMAT_STRING pFormat)
1128 unsigned long Offset = pStubMsg->Offset;
1129 unsigned ofs, rep, count, stride, xofs;
1132 TRACE("(%p,%p,%p)\n", pStubMsg, pMemory, pFormat);
1134 if (pStubMsg->IgnoreEmbeddedPointers) return;
1136 if (*pFormat != RPC_FC_PP) return;
1139 while (pFormat[0] != RPC_FC_END) {
1140 switch (pFormat[0]) {
1142 FIXME("unknown repeat type %d\n", pFormat[0]);
1143 case RPC_FC_NO_REPEAT:
1151 case RPC_FC_FIXED_REPEAT:
1152 rep = *(const WORD*)&pFormat[2];
1153 stride = *(const WORD*)&pFormat[4];
1154 ofs = *(const WORD*)&pFormat[6];
1155 count = *(const WORD*)&pFormat[8];
1159 case RPC_FC_VARIABLE_REPEAT:
1160 rep = pStubMsg->MaxCount;
1161 stride = *(const WORD*)&pFormat[2];
1162 ofs = *(const WORD*)&pFormat[4];
1163 count = *(const WORD*)&pFormat[6];
1164 xofs = (pFormat[1] == RPC_FC_VARIABLE_OFFSET) ? Offset * stride : 0;
1168 /* ofs doesn't seem to matter in this context */
1169 for (i = 0; i < rep; i++) {
1170 PFORMAT_STRING info = pFormat;
1171 unsigned char *membase = pMemory + (i * stride);
1173 for (u=0; u<count; u++,info+=8) {
1174 unsigned char *memptr = membase + *(const SHORT*)&info[0];
1175 PointerBufferSize(pStubMsg, *(unsigned char**)memptr, info+4);
1178 pFormat += 8 * count;
1182 /***********************************************************************
1183 * EmbeddedPointerMemorySize
1185 unsigned long WINAPI EmbeddedPointerMemorySize(PMIDL_STUB_MESSAGE pStubMsg,
1186 PFORMAT_STRING pFormat)
1188 unsigned long Offset = pStubMsg->Offset;
1189 unsigned char *Mark = pStubMsg->BufferMark;
1190 unsigned ofs, rep, count, stride, xofs;
1193 FIXME("(%p,%p): stub\n", pStubMsg, pFormat);
1195 if (*pFormat != RPC_FC_PP) return 0;
1198 while (pFormat[0] != RPC_FC_END) {
1199 switch (pFormat[0]) {
1201 FIXME("unknown repeat type %d\n", pFormat[0]);
1202 case RPC_FC_NO_REPEAT:
1210 case RPC_FC_FIXED_REPEAT:
1211 rep = *(const WORD*)&pFormat[2];
1212 stride = *(const WORD*)&pFormat[4];
1213 ofs = *(const WORD*)&pFormat[6];
1214 count = *(const WORD*)&pFormat[8];
1218 case RPC_FC_VARIABLE_REPEAT:
1219 rep = pStubMsg->MaxCount;
1220 stride = *(const WORD*)&pFormat[2];
1221 ofs = *(const WORD*)&pFormat[4];
1222 count = *(const WORD*)&pFormat[6];
1223 xofs = (pFormat[1] == RPC_FC_VARIABLE_OFFSET) ? Offset * stride : 0;
1227 /* ofs doesn't seem to matter in this context */
1228 for (i = 0; i < rep; i++) {
1229 PFORMAT_STRING info = pFormat;
1230 unsigned char *bufbase = Mark + (i * stride);
1232 for (u=0; u<count; u++,info+=8) {
1233 unsigned char *bufptr = bufbase + *(const SHORT*)&info[2];
1234 PointerMemorySize(pStubMsg, bufptr, info+4);
1237 pFormat += 8 * count;
1243 /***********************************************************************
1244 * EmbeddedPointerFree
1246 void WINAPI EmbeddedPointerFree(PMIDL_STUB_MESSAGE pStubMsg,
1247 unsigned char *pMemory,
1248 PFORMAT_STRING pFormat)
1250 unsigned long Offset = pStubMsg->Offset;
1251 unsigned ofs, rep, count, stride, xofs;
1254 TRACE("(%p,%p,%p)\n", pStubMsg, pMemory, pFormat);
1255 if (*pFormat != RPC_FC_PP) return;
1258 while (pFormat[0] != RPC_FC_END) {
1259 switch (pFormat[0]) {
1261 FIXME("unknown repeat type %d\n", pFormat[0]);
1262 case RPC_FC_NO_REPEAT:
1270 case RPC_FC_FIXED_REPEAT:
1271 rep = *(const WORD*)&pFormat[2];
1272 stride = *(const WORD*)&pFormat[4];
1273 ofs = *(const WORD*)&pFormat[6];
1274 count = *(const WORD*)&pFormat[8];
1278 case RPC_FC_VARIABLE_REPEAT:
1279 rep = pStubMsg->MaxCount;
1280 stride = *(const WORD*)&pFormat[2];
1281 ofs = *(const WORD*)&pFormat[4];
1282 count = *(const WORD*)&pFormat[6];
1283 xofs = (pFormat[1] == RPC_FC_VARIABLE_OFFSET) ? Offset * stride : 0;
1287 /* ofs doesn't seem to matter in this context */
1288 for (i = 0; i < rep; i++) {
1289 PFORMAT_STRING info = pFormat;
1290 unsigned char *membase = pMemory + (i * stride);
1292 for (u=0; u<count; u++,info+=8) {
1293 unsigned char *memptr = membase + *(const SHORT*)&info[0];
1294 PointerFree(pStubMsg, *(unsigned char**)memptr, info+4);
1297 pFormat += 8 * count;
1301 /***********************************************************************
1302 * NdrPointerMarshall [RPCRT4.@]
1304 unsigned char * WINAPI NdrPointerMarshall(PMIDL_STUB_MESSAGE pStubMsg,
1305 unsigned char *pMemory,
1306 PFORMAT_STRING pFormat)
1308 unsigned char *Buffer;
1310 TRACE("(%p,%p,%p)\n", pStubMsg, pMemory, pFormat);
1312 /* incremement the buffer here instead of in PointerMarshall,
1313 * as that is used by embedded pointers which already handle the incrementing
1314 * the buffer, and shouldn't write any additional pointer data to the wire */
1315 if (*pFormat != RPC_FC_RP)
1317 ALIGN_POINTER(pStubMsg->Buffer, 4);
1318 Buffer = pStubMsg->Buffer;
1319 pStubMsg->Buffer += 4;
1322 Buffer = pStubMsg->Buffer;
1324 PointerMarshall(pStubMsg, Buffer, pMemory, pFormat);
1326 STD_OVERFLOW_CHECK(pStubMsg);
1331 /***********************************************************************
1332 * NdrPointerUnmarshall [RPCRT4.@]
1334 unsigned char * WINAPI NdrPointerUnmarshall(PMIDL_STUB_MESSAGE pStubMsg,
1335 unsigned char **ppMemory,
1336 PFORMAT_STRING pFormat,
1337 unsigned char fMustAlloc)
1339 unsigned char *Buffer;
1341 TRACE("(%p,%p,%p,%d)\n", pStubMsg, ppMemory, pFormat, fMustAlloc);
1343 /* incremement the buffer here instead of in PointerUnmarshall,
1344 * as that is used by embedded pointers which already handle the incrementing
1345 * the buffer, and shouldn't read any additional pointer data from the
1347 if (*pFormat != RPC_FC_RP)
1349 ALIGN_POINTER(pStubMsg->Buffer, 4);
1350 Buffer = pStubMsg->Buffer;
1351 pStubMsg->Buffer += 4;
1354 Buffer = pStubMsg->Buffer;
1356 PointerUnmarshall(pStubMsg, Buffer, ppMemory, pFormat, fMustAlloc);
1361 /***********************************************************************
1362 * NdrPointerBufferSize [RPCRT4.@]
1364 void WINAPI NdrPointerBufferSize(PMIDL_STUB_MESSAGE pStubMsg,
1365 unsigned char *pMemory,
1366 PFORMAT_STRING pFormat)
1368 TRACE("(%p,%p,%p)\n", pStubMsg, pMemory, pFormat);
1370 /* incremement the buffer length here instead of in PointerBufferSize,
1371 * as that is used by embedded pointers which already handle the buffer
1372 * length, and shouldn't write anything more to the wire */
1373 if (*pFormat != RPC_FC_RP)
1375 ALIGN_LENGTH(pStubMsg->BufferLength, 4);
1376 pStubMsg->BufferLength += 4;
1379 PointerBufferSize(pStubMsg, pMemory, pFormat);
1382 /***********************************************************************
1383 * NdrPointerMemorySize [RPCRT4.@]
1385 unsigned long WINAPI NdrPointerMemorySize(PMIDL_STUB_MESSAGE pStubMsg,
1386 PFORMAT_STRING pFormat)
1388 /* unsigned size = *(LPWORD)(pFormat+2); */
1389 FIXME("(%p,%p): stub\n", pStubMsg, pFormat);
1390 PointerMemorySize(pStubMsg, pStubMsg->Buffer, pFormat);
1394 /***********************************************************************
1395 * NdrPointerFree [RPCRT4.@]
1397 void WINAPI NdrPointerFree(PMIDL_STUB_MESSAGE pStubMsg,
1398 unsigned char *pMemory,
1399 PFORMAT_STRING pFormat)
1401 TRACE("(%p,%p,%p)\n", pStubMsg, pMemory, pFormat);
1402 PointerFree(pStubMsg, pMemory, pFormat);
1405 /***********************************************************************
1406 * NdrSimpleStructMarshall [RPCRT4.@]
1408 unsigned char * WINAPI NdrSimpleStructMarshall(PMIDL_STUB_MESSAGE pStubMsg,
1409 unsigned char *pMemory,
1410 PFORMAT_STRING pFormat)
1412 unsigned size = *(const WORD*)(pFormat+2);
1413 TRACE("(%p,%p,%p)\n", pStubMsg, pMemory, pFormat);
1415 ALIGN_POINTER(pStubMsg->Buffer, pFormat[1] + 1);
1417 memcpy(pStubMsg->Buffer, pMemory, size);
1418 pStubMsg->BufferMark = pStubMsg->Buffer;
1419 pStubMsg->Buffer += size;
1421 if (pFormat[0] != RPC_FC_STRUCT)
1422 EmbeddedPointerMarshall(pStubMsg, pMemory, pFormat+4);
1424 STD_OVERFLOW_CHECK(pStubMsg);
1429 /***********************************************************************
1430 * NdrSimpleStructUnmarshall [RPCRT4.@]
1432 unsigned char * WINAPI NdrSimpleStructUnmarshall(PMIDL_STUB_MESSAGE pStubMsg,
1433 unsigned char **ppMemory,
1434 PFORMAT_STRING pFormat,
1435 unsigned char fMustAlloc)
1437 unsigned size = *(const WORD*)(pFormat+2);
1438 TRACE("(%p,%p,%p,%d)\n", pStubMsg, ppMemory, pFormat, fMustAlloc);
1440 ALIGN_POINTER(pStubMsg->Buffer, pFormat[1] + 1);
1443 *ppMemory = NdrAllocate(pStubMsg, size);
1444 memcpy(*ppMemory, pStubMsg->Buffer, size);
1446 if (pStubMsg->ReuseBuffer && !*ppMemory)
1447 /* for servers, we may just point straight into the RPC buffer, I think
1448 * (I guess that's what MS does since MIDL code doesn't try to free) */
1449 *ppMemory = pStubMsg->Buffer;
1451 /* for clients, memory should be provided by caller */
1452 memcpy(*ppMemory, pStubMsg->Buffer, size);
1455 pStubMsg->BufferMark = pStubMsg->Buffer;
1456 pStubMsg->Buffer += size;
1458 if (pFormat[0] != RPC_FC_STRUCT)
1459 EmbeddedPointerUnmarshall(pStubMsg, ppMemory, pFormat+4, fMustAlloc);
1465 /***********************************************************************
1466 * NdrSimpleStructUnmarshall [RPCRT4.@]
1468 void WINAPI NdrSimpleTypeMarshall( PMIDL_STUB_MESSAGE pStubMsg, unsigned char* pMemory,
1469 unsigned char FormatChar )
1475 /***********************************************************************
1476 * NdrSimpleStructUnmarshall [RPCRT4.@]
1478 void WINAPI NdrSimpleTypeUnmarshall( PMIDL_STUB_MESSAGE pStubMsg, unsigned char* pMemory,
1479 unsigned char FormatChar )
1485 /***********************************************************************
1486 * NdrSimpleStructBufferSize [RPCRT4.@]
1488 void WINAPI NdrSimpleStructBufferSize(PMIDL_STUB_MESSAGE pStubMsg,
1489 unsigned char *pMemory,
1490 PFORMAT_STRING pFormat)
1492 unsigned size = *(const WORD*)(pFormat+2);
1493 TRACE("(%p,%p,%p)\n", pStubMsg, pMemory, pFormat);
1495 ALIGN_LENGTH(pStubMsg->BufferLength, pFormat[1] + 1);
1497 pStubMsg->BufferLength += size;
1498 if (pFormat[0] != RPC_FC_STRUCT)
1499 EmbeddedPointerBufferSize(pStubMsg, pMemory, pFormat+4);
1502 /***********************************************************************
1503 * NdrSimpleStructMemorySize [RPCRT4.@]
1505 unsigned long WINAPI NdrSimpleStructMemorySize(PMIDL_STUB_MESSAGE pStubMsg,
1506 PFORMAT_STRING pFormat)
1508 unsigned short size = *(LPWORD)(pFormat+2);
1510 TRACE("(%p,%p)\n", pStubMsg, pFormat);
1512 ALIGN_POINTER(pStubMsg->Buffer, pFormat[1] + 1);
1513 pStubMsg->MemorySize += size;
1514 pStubMsg->Buffer += size;
1516 if (pFormat[0] != RPC_FC_STRUCT)
1517 EmbeddedPointerMemorySize(pStubMsg, pFormat+4);
1521 /***********************************************************************
1522 * NdrSimpleStructFree [RPCRT4.@]
1524 void WINAPI NdrSimpleStructFree(PMIDL_STUB_MESSAGE pStubMsg,
1525 unsigned char *pMemory,
1526 PFORMAT_STRING pFormat)
1528 TRACE("(%p,%p,%p)\n", pStubMsg, pMemory, pFormat);
1529 if (pFormat[0] != RPC_FC_STRUCT)
1530 EmbeddedPointerFree(pStubMsg, pMemory, pFormat+4);
1534 unsigned long WINAPI EmbeddedComplexSize(PMIDL_STUB_MESSAGE pStubMsg,
1535 PFORMAT_STRING pFormat)
1539 case RPC_FC_PSTRUCT:
1540 case RPC_FC_CSTRUCT:
1541 case RPC_FC_BOGUS_STRUCT:
1542 return *(const WORD*)&pFormat[2];
1543 case RPC_FC_USER_MARSHAL:
1544 return *(const WORD*)&pFormat[4];
1545 case RPC_FC_NON_ENCAPSULATED_UNION:
1547 if (pStubMsg->fHasNewCorrDesc)
1552 pFormat += *(const SHORT*)pFormat;
1553 return *(const SHORT*)pFormat;
1555 FIXME("unhandled embedded type %02x\n", *pFormat);
1561 unsigned long WINAPI EmbeddedComplexMemorySize(PMIDL_STUB_MESSAGE pStubMsg,
1562 PFORMAT_STRING pFormat)
1564 NDR_MEMORYSIZE m = NdrMemorySizer[*pFormat & NDR_TABLE_MASK];
1568 FIXME("no memorysizer for data type=%02x\n", *pFormat);
1572 return m(pStubMsg, pFormat);
1576 unsigned char * WINAPI ComplexMarshall(PMIDL_STUB_MESSAGE pStubMsg,
1577 unsigned char *pMemory,
1578 PFORMAT_STRING pFormat,
1579 PFORMAT_STRING pPointer)
1581 PFORMAT_STRING desc;
1585 while (*pFormat != RPC_FC_END) {
1589 TRACE("short=%d <= %p\n", *(WORD*)pMemory, pMemory);
1590 memcpy(pStubMsg->Buffer, pMemory, 2);
1591 pStubMsg->Buffer += 2;
1597 TRACE("long=%ld <= %p\n", *(DWORD*)pMemory, pMemory);
1598 memcpy(pStubMsg->Buffer, pMemory, 4);
1599 pStubMsg->Buffer += 4;
1602 case RPC_FC_POINTER:
1603 TRACE("pointer=%p <= %p\n", *(unsigned char**)pMemory, pMemory);
1604 NdrPointerMarshall(pStubMsg, *(unsigned char**)pMemory, pPointer);
1608 case RPC_FC_ALIGNM4:
1609 ALIGN_POINTER(pMemory, 4);
1611 case RPC_FC_ALIGNM8:
1612 ALIGN_POINTER(pMemory, 8);
1614 case RPC_FC_STRUCTPAD2:
1617 case RPC_FC_EMBEDDED_COMPLEX:
1618 pMemory += pFormat[1];
1620 desc = pFormat + *(const SHORT*)pFormat;
1621 size = EmbeddedComplexSize(pStubMsg, desc);
1622 TRACE("embedded complex (size=%ld) <= %p\n", size, pMemory);
1623 m = NdrMarshaller[*desc & NDR_TABLE_MASK];
1624 if (m) m(pStubMsg, pMemory, desc);
1625 else FIXME("no marshaller for embedded type %02x\n", *desc);
1632 FIXME("unhandled format %02x\n", *pFormat);
1640 unsigned char * WINAPI ComplexUnmarshall(PMIDL_STUB_MESSAGE pStubMsg,
1641 unsigned char *pMemory,
1642 PFORMAT_STRING pFormat,
1643 PFORMAT_STRING pPointer,
1644 unsigned char fMustAlloc)
1646 PFORMAT_STRING desc;
1650 while (*pFormat != RPC_FC_END) {
1654 memcpy(pMemory, pStubMsg->Buffer, 2);
1655 TRACE("short=%d => %p\n", *(WORD*)pMemory, pMemory);
1656 pStubMsg->Buffer += 2;
1662 memcpy(pMemory, pStubMsg->Buffer, 4);
1663 TRACE("long=%ld => %p\n", *(DWORD*)pMemory, pMemory);
1664 pStubMsg->Buffer += 4;
1667 case RPC_FC_POINTER:
1668 *(unsigned char**)pMemory = NULL;
1669 TRACE("pointer => %p\n", pMemory);
1670 NdrPointerUnmarshall(pStubMsg, (unsigned char**)pMemory, pPointer, fMustAlloc);
1674 case RPC_FC_ALIGNM4:
1675 ALIGN_POINTER(pMemory, 4);
1677 case RPC_FC_ALIGNM8:
1678 ALIGN_POINTER(pMemory, 8);
1680 case RPC_FC_STRUCTPAD2:
1683 case RPC_FC_EMBEDDED_COMPLEX:
1684 pMemory += pFormat[1];
1686 desc = pFormat + *(const SHORT*)pFormat;
1687 size = EmbeddedComplexSize(pStubMsg, desc);
1688 TRACE("embedded complex (size=%ld) => %p\n", size, pMemory);
1689 m = NdrUnmarshaller[*desc & NDR_TABLE_MASK];
1690 memset(pMemory, 0, size); /* just in case */
1691 if (m) m(pStubMsg, &pMemory, desc, fMustAlloc);
1692 else FIXME("no unmarshaller for embedded type %02x\n", *desc);
1699 FIXME("unhandled format %d\n", *pFormat);
1707 unsigned char * WINAPI ComplexBufferSize(PMIDL_STUB_MESSAGE pStubMsg,
1708 unsigned char *pMemory,
1709 PFORMAT_STRING pFormat,
1710 PFORMAT_STRING pPointer)
1712 PFORMAT_STRING desc;
1716 while (*pFormat != RPC_FC_END) {
1720 pStubMsg->BufferLength += 2;
1726 pStubMsg->BufferLength += 4;
1729 case RPC_FC_POINTER:
1730 NdrPointerBufferSize(pStubMsg, *(unsigned char**)pMemory, pPointer);
1734 case RPC_FC_ALIGNM4:
1735 ALIGN_POINTER(pMemory, 4);
1737 case RPC_FC_ALIGNM8:
1738 ALIGN_POINTER(pMemory, 8);
1740 case RPC_FC_STRUCTPAD2:
1743 case RPC_FC_EMBEDDED_COMPLEX:
1744 pMemory += pFormat[1];
1746 desc = pFormat + *(const SHORT*)pFormat;
1747 size = EmbeddedComplexSize(pStubMsg, desc);
1748 m = NdrBufferSizer[*desc & NDR_TABLE_MASK];
1749 if (m) m(pStubMsg, pMemory, desc);
1750 else FIXME("no buffersizer for embedded type %02x\n", *desc);
1757 FIXME("unhandled format %d\n", *pFormat);
1765 unsigned char * WINAPI ComplexFree(PMIDL_STUB_MESSAGE pStubMsg,
1766 unsigned char *pMemory,
1767 PFORMAT_STRING pFormat,
1768 PFORMAT_STRING pPointer)
1770 PFORMAT_STRING desc;
1774 while (*pFormat != RPC_FC_END) {
1785 case RPC_FC_POINTER:
1786 NdrPointerFree(pStubMsg, *(unsigned char**)pMemory, pPointer);
1790 case RPC_FC_ALIGNM4:
1791 ALIGN_POINTER(pMemory, 4);
1793 case RPC_FC_ALIGNM8:
1794 ALIGN_POINTER(pMemory, 8);
1796 case RPC_FC_STRUCTPAD2:
1799 case RPC_FC_EMBEDDED_COMPLEX:
1800 pMemory += pFormat[1];
1802 desc = pFormat + *(const SHORT*)pFormat;
1803 size = EmbeddedComplexSize(pStubMsg, desc);
1804 m = NdrFreer[*desc & NDR_TABLE_MASK];
1805 if (m) m(pStubMsg, pMemory, desc);
1806 else FIXME("no freer for embedded type %02x\n", *desc);
1813 FIXME("unhandled format %d\n", *pFormat);
1821 unsigned long WINAPI ComplexStructMemorySize(PMIDL_STUB_MESSAGE pStubMsg,
1822 PFORMAT_STRING pFormat)
1824 PFORMAT_STRING desc;
1825 unsigned long size = 0;
1827 while (*pFormat != RPC_FC_END) {
1832 pStubMsg->Buffer += 2;
1837 pStubMsg->Buffer += 4;
1839 case RPC_FC_POINTER:
1841 pStubMsg->Buffer += 4;
1843 case RPC_FC_ALIGNM4:
1844 ALIGN_LENGTH(size, 4);
1845 ALIGN_POINTER(pStubMsg->Buffer, 4);
1847 case RPC_FC_ALIGNM8:
1848 ALIGN_LENGTH(size, 8);
1849 ALIGN_POINTER(pStubMsg->Buffer, 8);
1851 case RPC_FC_STRUCTPAD2:
1853 pStubMsg->Buffer += 2;
1855 case RPC_FC_EMBEDDED_COMPLEX:
1858 desc = pFormat + *(const SHORT*)pFormat;
1859 size += EmbeddedComplexMemorySize(pStubMsg, desc);
1865 FIXME("unhandled format %d\n", *pFormat);
1873 /***********************************************************************
1874 * NdrComplexStructMarshall [RPCRT4.@]
1876 unsigned char * WINAPI NdrComplexStructMarshall(PMIDL_STUB_MESSAGE pStubMsg,
1877 unsigned char *pMemory,
1878 PFORMAT_STRING pFormat)
1880 PFORMAT_STRING conf_array = NULL;
1881 PFORMAT_STRING pointer_desc = NULL;
1882 unsigned char *OldMemory = pStubMsg->Memory;
1884 TRACE("(%p,%p,%p)\n", pStubMsg, pMemory, pFormat);
1886 ALIGN_POINTER(pStubMsg->Buffer, pFormat[1] + 1);
1889 if (*(const WORD*)pFormat) conf_array = pFormat + *(const WORD*)pFormat;
1891 if (*(const WORD*)pFormat) pointer_desc = pFormat + *(const WORD*)pFormat;
1894 pStubMsg->Memory = pMemory;
1896 ComplexMarshall(pStubMsg, pMemory, pFormat, pointer_desc);
1899 NdrConformantArrayMarshall(pStubMsg, pMemory, conf_array);
1901 pStubMsg->Memory = OldMemory;
1903 STD_OVERFLOW_CHECK(pStubMsg);
1908 /***********************************************************************
1909 * NdrComplexStructUnmarshall [RPCRT4.@]
1911 unsigned char * WINAPI NdrComplexStructUnmarshall(PMIDL_STUB_MESSAGE pStubMsg,
1912 unsigned char **ppMemory,
1913 PFORMAT_STRING pFormat,
1914 unsigned char fMustAlloc)
1916 unsigned size = *(const WORD*)(pFormat+2);
1917 PFORMAT_STRING conf_array = NULL;
1918 PFORMAT_STRING pointer_desc = NULL;
1919 unsigned char *pMemory;
1921 TRACE("(%p,%p,%p,%d)\n", pStubMsg, ppMemory, pFormat, fMustAlloc);
1923 ALIGN_POINTER(pStubMsg->Buffer, pFormat[1] + 1);
1925 if (fMustAlloc || !*ppMemory)
1927 *ppMemory = NdrAllocate(pStubMsg, size);
1928 memset(*ppMemory, 0, size);
1932 if (*(const WORD*)pFormat) conf_array = pFormat + *(const WORD*)pFormat;
1934 if (*(const WORD*)pFormat) pointer_desc = pFormat + *(const WORD*)pFormat;
1937 pMemory = ComplexUnmarshall(pStubMsg, *ppMemory, pFormat, pointer_desc, fMustAlloc);
1940 NdrConformantArrayUnmarshall(pStubMsg, &pMemory, conf_array, fMustAlloc);
1945 /***********************************************************************
1946 * NdrComplexStructBufferSize [RPCRT4.@]
1948 void WINAPI NdrComplexStructBufferSize(PMIDL_STUB_MESSAGE pStubMsg,
1949 unsigned char *pMemory,
1950 PFORMAT_STRING pFormat)
1952 PFORMAT_STRING conf_array = NULL;
1953 PFORMAT_STRING pointer_desc = NULL;
1954 unsigned char *OldMemory = pStubMsg->Memory;
1956 TRACE("(%p,%p,%p)\n", pStubMsg, pMemory, pFormat);
1958 ALIGN_LENGTH(pStubMsg->BufferLength, pFormat[1] + 1);
1961 if (*(const WORD*)pFormat) conf_array = pFormat + *(const WORD*)pFormat;
1963 if (*(const WORD*)pFormat) pointer_desc = pFormat + *(const WORD*)pFormat;
1966 pStubMsg->Memory = pMemory;
1968 pMemory = ComplexBufferSize(pStubMsg, pMemory, pFormat, pointer_desc);
1971 NdrConformantArrayBufferSize(pStubMsg, pMemory, conf_array);
1973 pStubMsg->Memory = OldMemory;
1976 /***********************************************************************
1977 * NdrComplexStructMemorySize [RPCRT4.@]
1979 unsigned long WINAPI NdrComplexStructMemorySize(PMIDL_STUB_MESSAGE pStubMsg,
1980 PFORMAT_STRING pFormat)
1982 unsigned size = *(const WORD*)(pFormat+2);
1983 PFORMAT_STRING conf_array = NULL;
1984 PFORMAT_STRING pointer_desc = NULL;
1986 TRACE("(%p,%p)\n", pStubMsg, pFormat);
1988 ALIGN_POINTER(pStubMsg->Buffer, pFormat[1] + 1);
1991 if (*(const WORD*)pFormat) conf_array = pFormat + *(const WORD*)pFormat;
1993 if (*(const WORD*)pFormat) pointer_desc = pFormat + *(const WORD*)pFormat;
1996 ComplexStructMemorySize(pStubMsg, pFormat);
1999 NdrConformantArrayMemorySize(pStubMsg, conf_array);
2004 /***********************************************************************
2005 * NdrComplexStructFree [RPCRT4.@]
2007 void WINAPI NdrComplexStructFree(PMIDL_STUB_MESSAGE pStubMsg,
2008 unsigned char *pMemory,
2009 PFORMAT_STRING pFormat)
2011 PFORMAT_STRING conf_array = NULL;
2012 PFORMAT_STRING pointer_desc = NULL;
2013 unsigned char *OldMemory = pStubMsg->Memory;
2015 TRACE("(%p,%p,%p)\n", pStubMsg, pMemory, pFormat);
2018 if (*(const WORD*)pFormat) conf_array = pFormat + *(const WORD*)pFormat;
2020 if (*(const WORD*)pFormat) pointer_desc = pFormat + *(const WORD*)pFormat;
2023 pStubMsg->Memory = pMemory;
2025 pMemory = ComplexFree(pStubMsg, pMemory, pFormat, pointer_desc);
2028 NdrConformantArrayFree(pStubMsg, pMemory, conf_array);
2030 pStubMsg->Memory = OldMemory;
2033 /***********************************************************************
2034 * NdrConformantArrayMarshall [RPCRT4.@]
2036 unsigned char * WINAPI NdrConformantArrayMarshall(PMIDL_STUB_MESSAGE pStubMsg,
2037 unsigned char *pMemory,
2038 PFORMAT_STRING pFormat)
2040 DWORD size = 0, esize = *(const WORD*)(pFormat+2);
2041 unsigned char alignment = pFormat[1] + 1;
2043 TRACE("(%p,%p,%p)\n", pStubMsg, pMemory, pFormat);
2044 if (pFormat[0] != RPC_FC_CARRAY) FIXME("format=%d\n", pFormat[0]);
2046 pFormat = ComputeConformance(pStubMsg, pMemory, pFormat+4, 0);
2047 size = pStubMsg->MaxCount;
2049 WriteConformance(pStubMsg);
2051 ALIGN_POINTER(pStubMsg->Buffer, alignment);
2053 memcpy(pStubMsg->Buffer, pMemory, size*esize);
2054 pStubMsg->BufferMark = pStubMsg->Buffer;
2055 pStubMsg->Buffer += size*esize;
2057 EmbeddedPointerMarshall(pStubMsg, pMemory, pFormat);
2059 STD_OVERFLOW_CHECK(pStubMsg);
2064 /***********************************************************************
2065 * NdrConformantArrayUnmarshall [RPCRT4.@]
2067 unsigned char * WINAPI NdrConformantArrayUnmarshall(PMIDL_STUB_MESSAGE pStubMsg,
2068 unsigned char **ppMemory,
2069 PFORMAT_STRING pFormat,
2070 unsigned char fMustAlloc)
2072 DWORD size = 0, esize = *(const WORD*)(pFormat+2);
2073 unsigned char alignment = pFormat[1] + 1;
2075 TRACE("(%p,%p,%p,%d)\n", pStubMsg, ppMemory, pFormat, fMustAlloc);
2076 if (pFormat[0] != RPC_FC_CARRAY) FIXME("format=%d\n", pFormat[0]);
2078 pFormat = ReadConformance(pStubMsg, pFormat+4);
2079 size = pStubMsg->MaxCount;
2081 if (fMustAlloc || !*ppMemory)
2082 *ppMemory = NdrAllocate(pStubMsg, size*esize);
2084 ALIGN_POINTER(pStubMsg->Buffer, alignment);
2086 memcpy(*ppMemory, pStubMsg->Buffer, size*esize);
2088 pStubMsg->BufferMark = pStubMsg->Buffer;
2089 pStubMsg->Buffer += size*esize;
2091 EmbeddedPointerUnmarshall(pStubMsg, ppMemory, pFormat, fMustAlloc);
2096 /***********************************************************************
2097 * NdrConformantArrayBufferSize [RPCRT4.@]
2099 void WINAPI NdrConformantArrayBufferSize(PMIDL_STUB_MESSAGE pStubMsg,
2100 unsigned char *pMemory,
2101 PFORMAT_STRING pFormat)
2103 DWORD size = 0, esize = *(const WORD*)(pFormat+2);
2104 unsigned char alignment = pFormat[1] + 1;
2106 TRACE("(%p,%p,%p)\n", pStubMsg, pMemory, pFormat);
2107 if (pFormat[0] != RPC_FC_CARRAY) FIXME("format=%d\n", pFormat[0]);
2109 pFormat = ComputeConformance(pStubMsg, pMemory, pFormat+4, 0);
2110 size = pStubMsg->MaxCount;
2112 SizeConformance(pStubMsg);
2114 ALIGN_LENGTH(pStubMsg->BufferLength, alignment);
2116 /* conformance value plus array */
2117 pStubMsg->BufferLength += size*esize;
2119 EmbeddedPointerBufferSize(pStubMsg, pMemory, pFormat);
2122 /***********************************************************************
2123 * NdrConformantArrayMemorySize [RPCRT4.@]
2125 unsigned long WINAPI NdrConformantArrayMemorySize(PMIDL_STUB_MESSAGE pStubMsg,
2126 PFORMAT_STRING pFormat)
2128 DWORD size = 0, esize = *(const WORD*)(pFormat+2);
2129 unsigned char *buffer;
2131 TRACE("(%p,%p)\n", pStubMsg, pFormat);
2132 if (pFormat[0] != RPC_FC_CARRAY) FIXME("format=%d\n", pFormat[0]);
2134 buffer = pStubMsg->Buffer;
2135 pFormat = ReadConformance(pStubMsg, pFormat+4);
2136 pStubMsg->Buffer = buffer;
2137 size = pStubMsg->MaxCount;
2142 /***********************************************************************
2143 * NdrConformantArrayFree [RPCRT4.@]
2145 void WINAPI NdrConformantArrayFree(PMIDL_STUB_MESSAGE pStubMsg,
2146 unsigned char *pMemory,
2147 PFORMAT_STRING pFormat)
2149 TRACE("(%p,%p,%p)\n", pStubMsg, pMemory, pFormat);
2150 if (pFormat[0] != RPC_FC_CARRAY) FIXME("format=%d\n", pFormat[0]);
2152 EmbeddedPointerFree(pStubMsg, pMemory, pFormat);
2156 /***********************************************************************
2157 * NdrConformantVaryingArrayMarshall [RPCRT4.@]
2159 unsigned char* WINAPI NdrConformantVaryingArrayMarshall( PMIDL_STUB_MESSAGE pStubMsg,
2160 unsigned char* pMemory,
2161 PFORMAT_STRING pFormat )
2163 unsigned char alignment = pFormat[1] + 1;
2164 DWORD esize = *(const WORD*)(pFormat+2);
2166 TRACE("(%p, %p, %p)\n", pStubMsg, pMemory, pFormat);
2168 if (pFormat[0] != RPC_FC_CVARRAY)
2170 ERR("invalid format type %x\n", pFormat[0]);
2171 RpcRaiseException(RPC_S_INTERNAL_ERROR);
2175 pFormat = ComputeConformance(pStubMsg, pMemory, pFormat+4, 0);
2176 pFormat = ComputeVariance(pStubMsg, pMemory, pFormat, 0);
2178 WriteConformance(pStubMsg);
2179 WriteVariance(pStubMsg);
2181 ALIGN_POINTER(pStubMsg->Buffer, alignment);
2183 memcpy(pStubMsg->Buffer, pMemory + pStubMsg->Offset, pStubMsg->ActualCount*esize);
2184 pStubMsg->BufferMark = pStubMsg->Buffer;
2185 pStubMsg->Buffer += pStubMsg->ActualCount*esize;
2187 EmbeddedPointerMarshall(pStubMsg, pMemory, pFormat);
2189 STD_OVERFLOW_CHECK(pStubMsg);
2195 /***********************************************************************
2196 * NdrConformantVaryingArrayUnmarshall [RPCRT4.@]
2198 unsigned char* WINAPI NdrConformantVaryingArrayUnmarshall( PMIDL_STUB_MESSAGE pStubMsg,
2199 unsigned char** ppMemory,
2200 PFORMAT_STRING pFormat,
2201 unsigned char fMustAlloc )
2203 unsigned char alignment = pFormat[1] + 1;
2204 DWORD esize = *(const WORD*)(pFormat+2);
2206 TRACE("(%p, %p, %p, %d)\n", pStubMsg, ppMemory, pFormat, fMustAlloc);
2208 if (pFormat[0] != RPC_FC_CVARRAY)
2210 ERR("invalid format type %x\n", pFormat[0]);
2211 RpcRaiseException(RPC_S_INTERNAL_ERROR);
2215 pFormat = ReadConformance(pStubMsg, pFormat);
2216 pFormat = ReadVariance(pStubMsg, pFormat);
2218 ALIGN_POINTER(pStubMsg->Buffer, alignment);
2220 if (!*ppMemory || fMustAlloc)
2221 *ppMemory = NdrAllocate(pStubMsg, pStubMsg->MaxCount * esize);
2222 memcpy(*ppMemory + pStubMsg->Offset, pStubMsg->Buffer, pStubMsg->ActualCount * esize);
2223 pStubMsg->Buffer += pStubMsg->ActualCount * esize;
2225 EmbeddedPointerUnmarshall(pStubMsg, ppMemory, pFormat, fMustAlloc);
2231 /***********************************************************************
2232 * NdrConformantVaryingArrayFree [RPCRT4.@]
2234 void WINAPI NdrConformantVaryingArrayFree( PMIDL_STUB_MESSAGE pStubMsg,
2235 unsigned char* pMemory,
2236 PFORMAT_STRING pFormat )
2238 TRACE("(%p,%p,%p)\n", pStubMsg, pMemory, pFormat);
2240 if (pFormat[0] != RPC_FC_CVARRAY)
2242 ERR("invalid format type %x\n", pFormat[0]);
2243 RpcRaiseException(RPC_S_INTERNAL_ERROR);
2247 pFormat = ComputeConformance(pStubMsg, pMemory, pFormat+4, 0);
2248 pFormat = ComputeVariance(pStubMsg, pMemory, pFormat, 0);
2250 EmbeddedPointerFree(pStubMsg, pMemory, pFormat);
2254 /***********************************************************************
2255 * NdrConformantVaryingArrayBufferSize [RPCRT4.@]
2257 void WINAPI NdrConformantVaryingArrayBufferSize( PMIDL_STUB_MESSAGE pStubMsg,
2258 unsigned char* pMemory, PFORMAT_STRING pFormat )
2260 unsigned char alignment = pFormat[1] + 1;
2261 DWORD esize = *(const WORD*)(pFormat+2);
2263 TRACE("(%p, %p, %p)\n", pStubMsg, pMemory, pFormat);
2265 if (pFormat[0] != RPC_FC_CVARRAY)
2267 ERR("invalid format type %x\n", pFormat[0]);
2268 RpcRaiseException(RPC_S_INTERNAL_ERROR);
2273 pFormat = ComputeConformance(pStubMsg, pMemory, pFormat+4, 0);
2274 /* compute length */
2275 pFormat = ComputeVariance(pStubMsg, pMemory, pFormat, 0);
2277 SizeConformance(pStubMsg);
2278 SizeVariance(pStubMsg);
2280 ALIGN_LENGTH(pStubMsg->BufferLength, alignment);
2282 pStubMsg->BufferLength += pStubMsg->ActualCount*esize;
2284 EmbeddedPointerBufferSize(pStubMsg, pMemory, pFormat);
2288 /***********************************************************************
2289 * NdrConformantVaryingArrayMemorySize [RPCRT4.@]
2291 unsigned long WINAPI NdrConformantVaryingArrayMemorySize( PMIDL_STUB_MESSAGE pStubMsg,
2292 PFORMAT_STRING pFormat )
2299 /***********************************************************************
2300 * NdrComplexArrayMarshall [RPCRT4.@]
2302 unsigned char * WINAPI NdrComplexArrayMarshall(PMIDL_STUB_MESSAGE pStubMsg,
2303 unsigned char *pMemory,
2304 PFORMAT_STRING pFormat)
2306 ULONG i, count, def;
2307 BOOL variance_present;
2308 unsigned char alignment;
2310 TRACE("(%p,%p,%p)\n", pStubMsg, pMemory, pFormat);
2312 if (pFormat[0] != RPC_FC_BOGUS_ARRAY)
2314 ERR("invalid format type %x\n", pFormat[0]);
2315 RpcRaiseException(RPC_S_INTERNAL_ERROR);
2319 alignment = pFormat[1] + 1;
2321 def = *(const WORD*)&pFormat[2];
2324 pFormat = ComputeConformance(pStubMsg, pMemory, pFormat, def);
2325 TRACE("conformance = %ld\n", pStubMsg->MaxCount);
2327 variance_present = IsConformanceOrVariancePresent(pFormat);
2328 pFormat = ComputeVariance(pStubMsg, pMemory, pFormat, pStubMsg->MaxCount);
2329 TRACE("variance = %ld\n", pStubMsg->ActualCount);
2331 WriteConformance(pStubMsg);
2332 if (variance_present)
2333 WriteVariance(pStubMsg);
2335 ALIGN_POINTER(pStubMsg->Buffer, alignment);
2337 count = pStubMsg->ActualCount;
2338 for (i = 0; i < count; i++)
2339 pMemory = ComplexMarshall(pStubMsg, pMemory, pFormat, NULL);
2341 STD_OVERFLOW_CHECK(pStubMsg);
2346 /***********************************************************************
2347 * NdrComplexArrayUnmarshall [RPCRT4.@]
2349 unsigned char * WINAPI NdrComplexArrayUnmarshall(PMIDL_STUB_MESSAGE pStubMsg,
2350 unsigned char **ppMemory,
2351 PFORMAT_STRING pFormat,
2352 unsigned char fMustAlloc)
2354 ULONG i, count, esize;
2355 unsigned char alignment;
2356 unsigned char *pMemory;
2357 unsigned char *Buffer;
2359 TRACE("(%p,%p,%p,%d)\n", pStubMsg, ppMemory, pFormat, fMustAlloc);
2361 if (pFormat[0] != RPC_FC_BOGUS_ARRAY)
2363 ERR("invalid format type %x\n", pFormat[0]);
2364 RpcRaiseException(RPC_S_INTERNAL_ERROR);
2368 alignment = pFormat[1] + 1;
2372 pFormat = ReadConformance(pStubMsg, pFormat);
2373 pFormat = ReadVariance(pStubMsg, pFormat);
2375 Buffer = pStubMsg->Buffer;
2376 esize = ComplexStructMemorySize(pStubMsg, pFormat);
2377 pStubMsg->Buffer = Buffer;
2379 if (fMustAlloc || !*ppMemory)
2381 *ppMemory = NdrAllocate(pStubMsg, pStubMsg->MaxCount * esize);
2382 memset(*ppMemory, 0, pStubMsg->MaxCount * esize);
2385 ALIGN_POINTER(pStubMsg->Buffer, alignment);
2387 pMemory = *ppMemory;
2388 count = pStubMsg->ActualCount;
2389 for (i = 0; i < count; i++)
2390 pMemory = ComplexUnmarshall(pStubMsg, pMemory, pFormat, NULL, fMustAlloc);
2395 /***********************************************************************
2396 * NdrComplexArrayBufferSize [RPCRT4.@]
2398 void WINAPI NdrComplexArrayBufferSize(PMIDL_STUB_MESSAGE pStubMsg,
2399 unsigned char *pMemory,
2400 PFORMAT_STRING pFormat)
2402 ULONG i, count, def;
2403 unsigned char alignment;
2404 BOOL variance_present;
2406 TRACE("(%p,%p,%p)\n", pStubMsg, pMemory, pFormat);
2408 if (pFormat[0] != RPC_FC_BOGUS_ARRAY)
2410 ERR("invalid format type %x\n", pFormat[0]);
2411 RpcRaiseException(RPC_S_INTERNAL_ERROR);
2415 alignment = pFormat[1] + 1;
2417 def = *(const WORD*)&pFormat[2];
2420 pFormat = ComputeConformance(pStubMsg, pMemory, pFormat, def);
2421 TRACE("conformance = %ld\n", pStubMsg->MaxCount);
2422 SizeConformance(pStubMsg);
2424 variance_present = IsConformanceOrVariancePresent(pFormat);
2425 pFormat = ComputeVariance(pStubMsg, pMemory, pFormat, pStubMsg->MaxCount);
2426 TRACE("variance = %ld\n", pStubMsg->ActualCount);
2428 if (variance_present)
2429 SizeVariance(pStubMsg);
2431 ALIGN_LENGTH(pStubMsg->BufferLength, alignment);
2433 count = pStubMsg->ActualCount;
2434 for (i = 0; i < count; i++)
2435 pMemory = ComplexBufferSize(pStubMsg, pMemory, pFormat, NULL);
2438 /***********************************************************************
2439 * NdrComplexArrayMemorySize [RPCRT4.@]
2441 unsigned long WINAPI NdrComplexArrayMemorySize(PMIDL_STUB_MESSAGE pStubMsg,
2442 PFORMAT_STRING pFormat)
2444 ULONG i, count, esize;
2445 unsigned char alignment;
2446 unsigned char *Buffer;
2447 unsigned long SavedMemorySize;
2448 unsigned long MemorySize;
2450 TRACE("(%p,%p)\n", pStubMsg, pFormat);
2452 if (pFormat[0] != RPC_FC_BOGUS_ARRAY)
2454 ERR("invalid format type %x\n", pFormat[0]);
2455 RpcRaiseException(RPC_S_INTERNAL_ERROR);
2459 alignment = pFormat[1] + 1;
2463 pFormat = ReadConformance(pStubMsg, pFormat);
2464 pFormat = ReadVariance(pStubMsg, pFormat);
2466 ALIGN_POINTER(pStubMsg->Buffer, alignment);
2468 SavedMemorySize = pStubMsg->MemorySize;
2470 Buffer = pStubMsg->Buffer;
2471 esize = ComplexStructMemorySize(pStubMsg, pFormat);
2472 pStubMsg->Buffer = Buffer;
2474 MemorySize = esize * pStubMsg->MaxCount;
2476 count = pStubMsg->ActualCount;
2477 for (i = 0; i < count; i++)
2478 ComplexStructMemorySize(pStubMsg, pFormat);
2480 pStubMsg->MemorySize = SavedMemorySize;
2482 pStubMsg->MemorySize += MemorySize;
2486 /***********************************************************************
2487 * NdrComplexArrayFree [RPCRT4.@]
2489 void WINAPI NdrComplexArrayFree(PMIDL_STUB_MESSAGE pStubMsg,
2490 unsigned char *pMemory,
2491 PFORMAT_STRING pFormat)
2493 ULONG i, count, def;
2495 TRACE("(%p,%p,%p)\n", pStubMsg, pMemory, pFormat);
2497 if (pFormat[0] != RPC_FC_BOGUS_ARRAY)
2499 ERR("invalid format type %x\n", pFormat[0]);
2500 RpcRaiseException(RPC_S_INTERNAL_ERROR);
2504 def = *(const WORD*)&pFormat[2];
2507 pFormat = ComputeConformance(pStubMsg, pMemory, pFormat, def);
2508 TRACE("conformance = %ld\n", pStubMsg->MaxCount);
2510 pFormat = ComputeVariance(pStubMsg, pMemory, pFormat, pStubMsg->MaxCount);
2511 TRACE("variance = %ld\n", pStubMsg->ActualCount);
2513 count = pStubMsg->ActualCount;
2514 for (i = 0; i < count; i++)
2515 pMemory = ComplexFree(pStubMsg, pMemory, pFormat, NULL);
2518 unsigned long UserMarshalFlags(PMIDL_STUB_MESSAGE pStubMsg)
2520 return MAKELONG(pStubMsg->dwDestContext,
2521 pStubMsg->RpcMsg->DataRepresentation);
2524 /***********************************************************************
2525 * NdrUserMarshalMarshall [RPCRT4.@]
2527 unsigned char * WINAPI NdrUserMarshalMarshall(PMIDL_STUB_MESSAGE pStubMsg,
2528 unsigned char *pMemory,
2529 PFORMAT_STRING pFormat)
2531 /* unsigned flags = pFormat[1]; */
2532 unsigned index = *(const WORD*)&pFormat[2];
2533 unsigned long uflag = UserMarshalFlags(pStubMsg);
2534 TRACE("(%p,%p,%p)\n", pStubMsg, pMemory, pFormat);
2535 TRACE("index=%d\n", index);
2538 pStubMsg->StubDesc->aUserMarshalQuadruple[index].pfnMarshall(
2539 &uflag, pStubMsg->Buffer, pMemory);
2541 STD_OVERFLOW_CHECK(pStubMsg);
2546 /***********************************************************************
2547 * NdrUserMarshalUnmarshall [RPCRT4.@]
2549 unsigned char * WINAPI NdrUserMarshalUnmarshall(PMIDL_STUB_MESSAGE pStubMsg,
2550 unsigned char **ppMemory,
2551 PFORMAT_STRING pFormat,
2552 unsigned char fMustAlloc)
2554 /* unsigned flags = pFormat[1];*/
2555 unsigned index = *(const WORD*)&pFormat[2];
2556 DWORD memsize = *(const WORD*)&pFormat[4];
2557 unsigned long uflag = UserMarshalFlags(pStubMsg);
2558 TRACE("(%p,%p,%p,%d)\n", pStubMsg, ppMemory, pFormat, fMustAlloc);
2559 TRACE("index=%d\n", index);
2561 if (fMustAlloc || !*ppMemory)
2562 *ppMemory = NdrAllocate(pStubMsg, memsize);
2565 pStubMsg->StubDesc->aUserMarshalQuadruple[index].pfnUnmarshall(
2566 &uflag, pStubMsg->Buffer, *ppMemory);
2571 /***********************************************************************
2572 * NdrUserMarshalBufferSize [RPCRT4.@]
2574 void WINAPI NdrUserMarshalBufferSize(PMIDL_STUB_MESSAGE pStubMsg,
2575 unsigned char *pMemory,
2576 PFORMAT_STRING pFormat)
2578 /* unsigned flags = pFormat[1];*/
2579 unsigned index = *(const WORD*)&pFormat[2];
2580 DWORD bufsize = *(const WORD*)&pFormat[6];
2581 unsigned long uflag = UserMarshalFlags(pStubMsg);
2582 TRACE("(%p,%p,%p)\n", pStubMsg, pMemory, pFormat);
2583 TRACE("index=%d\n", index);
2586 TRACE("size=%ld\n", bufsize);
2587 pStubMsg->BufferLength += bufsize;
2591 pStubMsg->BufferLength =
2592 pStubMsg->StubDesc->aUserMarshalQuadruple[index].pfnBufferSize(
2593 &uflag, pStubMsg->BufferLength, pMemory);
2596 /***********************************************************************
2597 * NdrUserMarshalMemorySize [RPCRT4.@]
2599 unsigned long WINAPI NdrUserMarshalMemorySize(PMIDL_STUB_MESSAGE pStubMsg,
2600 PFORMAT_STRING pFormat)
2602 unsigned index = *(const WORD*)&pFormat[2];
2603 /* DWORD memsize = *(const WORD*)&pFormat[4]; */
2604 FIXME("(%p,%p): stub\n", pStubMsg, pFormat);
2605 TRACE("index=%d\n", index);
2610 /***********************************************************************
2611 * NdrUserMarshalFree [RPCRT4.@]
2613 void WINAPI NdrUserMarshalFree(PMIDL_STUB_MESSAGE pStubMsg,
2614 unsigned char *pMemory,
2615 PFORMAT_STRING pFormat)
2617 /* unsigned flags = pFormat[1]; */
2618 unsigned index = *(const WORD*)&pFormat[2];
2619 unsigned long uflag = UserMarshalFlags(pStubMsg);
2620 TRACE("(%p,%p,%p)\n", pStubMsg, pMemory, pFormat);
2621 TRACE("index=%d\n", index);
2623 pStubMsg->StubDesc->aUserMarshalQuadruple[index].pfnFree(
2627 /***********************************************************************
2628 * NdrClearOutParameters [RPCRT4.@]
2630 void WINAPI NdrClearOutParameters(PMIDL_STUB_MESSAGE pStubMsg,
2631 PFORMAT_STRING pFormat,
2634 FIXME("(%p,%p,%p): stub\n", pStubMsg, pFormat, ArgAddr);
2637 /***********************************************************************
2638 * NdrConvert [RPCRT4.@]
2640 void WINAPI NdrConvert( PMIDL_STUB_MESSAGE pStubMsg, PFORMAT_STRING pFormat )
2642 FIXME("(pStubMsg == ^%p, pFormat == ^%p): stub.\n", pStubMsg, pFormat);
2643 /* FIXME: since this stub doesn't do any converting, the proper behavior
2644 is to raise an exception */
2647 /***********************************************************************
2648 * NdrConvert2 [RPCRT4.@]
2650 void WINAPI NdrConvert2( PMIDL_STUB_MESSAGE pStubMsg, PFORMAT_STRING pFormat, long NumberParams )
2652 FIXME("(pStubMsg == ^%p, pFormat == ^%p, NumberParams == %ld): stub.\n",
2653 pStubMsg, pFormat, NumberParams);
2654 /* FIXME: since this stub doesn't do any converting, the proper behavior
2655 is to raise an exception */
2658 typedef struct _NDR_CSTRUCT_FORMAT
2661 unsigned char alignment;
2662 unsigned short memory_size;
2663 short offset_to_array_description;
2664 } NDR_CSTRUCT_FORMAT;
2666 /***********************************************************************
2667 * NdrConformantStructMarshall [RPCRT4.@]
2669 unsigned char * WINAPI NdrConformantStructMarshall(PMIDL_STUB_MESSAGE pStubMsg,
2670 unsigned char *pMemory,
2671 PFORMAT_STRING pFormat)
2673 const NDR_CSTRUCT_FORMAT * pCStructFormat = (NDR_CSTRUCT_FORMAT*)pFormat;
2674 PFORMAT_STRING pCArrayFormat;
2677 TRACE("(%p, %p, %p)\n", pStubMsg, pMemory, pFormat);
2679 pFormat += sizeof(NDR_CSTRUCT_FORMAT);
2680 if ((pCStructFormat->type != RPC_FC_CPSTRUCT) && (pCStructFormat->type != RPC_FC_CSTRUCT))
2682 ERR("invalid format type %x\n", pCStructFormat->type);
2683 RpcRaiseException(RPC_S_INTERNAL_ERROR);
2687 pCArrayFormat = (unsigned char*)&pCStructFormat->offset_to_array_description +
2688 pCStructFormat->offset_to_array_description;
2689 if (*pCArrayFormat != RPC_FC_CARRAY)
2691 ERR("invalid array format type %x\n", pCStructFormat->type);
2692 RpcRaiseException(RPC_S_INTERNAL_ERROR);
2695 esize = *(const WORD*)(pCArrayFormat+2);
2697 ComputeConformance(pStubMsg, pMemory + pCStructFormat->memory_size,
2698 pCArrayFormat + 4, 0);
2700 WriteConformance(pStubMsg);
2702 ALIGN_POINTER(pStubMsg->Buffer, pCStructFormat->alignment + 1);
2704 TRACE("memory_size = %d\n", pCStructFormat->memory_size);
2706 /* copy constant sized part of struct */
2707 pStubMsg->BufferMark = pStubMsg->Buffer;
2708 memcpy(pStubMsg->Buffer, pMemory, pCStructFormat->memory_size + pStubMsg->MaxCount * esize);
2709 pStubMsg->Buffer += pCStructFormat->memory_size + pStubMsg->MaxCount * esize;
2711 if (pCStructFormat->type == RPC_FC_CPSTRUCT)
2712 EmbeddedPointerMarshall(pStubMsg, pMemory, pFormat);
2714 STD_OVERFLOW_CHECK(pStubMsg);
2719 /***********************************************************************
2720 * NdrConformantStructUnmarshall [RPCRT4.@]
2722 unsigned char * WINAPI NdrConformantStructUnmarshall(PMIDL_STUB_MESSAGE pStubMsg,
2723 unsigned char **ppMemory,
2724 PFORMAT_STRING pFormat,
2725 unsigned char fMustAlloc)
2727 const NDR_CSTRUCT_FORMAT * pCStructFormat = (NDR_CSTRUCT_FORMAT*)pFormat;
2728 PFORMAT_STRING pCArrayFormat;
2731 TRACE("(%p, %p, %p, %d)\n", pStubMsg, ppMemory, pFormat, fMustAlloc);
2733 pFormat += sizeof(NDR_CSTRUCT_FORMAT);
2734 if ((pCStructFormat->type != RPC_FC_CPSTRUCT) && (pCStructFormat->type != RPC_FC_CSTRUCT))
2736 ERR("invalid format type %x\n", pCStructFormat->type);
2737 RpcRaiseException(RPC_S_INTERNAL_ERROR);
2740 pCArrayFormat = (unsigned char*)&pCStructFormat->offset_to_array_description +
2741 pCStructFormat->offset_to_array_description;
2742 if (*pCArrayFormat != RPC_FC_CARRAY)
2744 ERR("invalid array format type %x\n", pCStructFormat->type);
2745 RpcRaiseException(RPC_S_INTERNAL_ERROR);
2748 esize = *(const WORD*)(pCArrayFormat+2);
2750 pCArrayFormat = ReadConformance(pStubMsg, pCArrayFormat + 4);
2752 ALIGN_POINTER(pStubMsg->Buffer, pCStructFormat->alignment + 1);
2754 TRACE("memory_size = %d\n", pCStructFormat->memory_size);
2756 /* work out how much memory to allocate if we need to do so */
2757 if (!*ppMemory || fMustAlloc)
2759 SIZE_T size = pCStructFormat->memory_size + pStubMsg->MaxCount * esize;
2760 *ppMemory = NdrAllocate(pStubMsg, size);
2763 /* now copy the data */
2764 pStubMsg->BufferMark = pStubMsg->Buffer;
2765 memcpy(*ppMemory, pStubMsg->Buffer, pCStructFormat->memory_size + pStubMsg->MaxCount * esize);
2766 pStubMsg->Buffer += pCStructFormat->memory_size + pStubMsg->MaxCount * esize;
2768 if (pCStructFormat->type == RPC_FC_CPSTRUCT)
2769 EmbeddedPointerUnmarshall(pStubMsg, ppMemory, pFormat, fMustAlloc);
2774 /***********************************************************************
2775 * NdrConformantStructBufferSize [RPCRT4.@]
2777 void WINAPI NdrConformantStructBufferSize(PMIDL_STUB_MESSAGE pStubMsg,
2778 unsigned char *pMemory,
2779 PFORMAT_STRING pFormat)
2781 const NDR_CSTRUCT_FORMAT * pCStructFormat = (NDR_CSTRUCT_FORMAT*)pFormat;
2782 PFORMAT_STRING pCArrayFormat;
2785 TRACE("(%p, %p, %p)\n", pStubMsg, pMemory, pFormat);
2787 pFormat += sizeof(NDR_CSTRUCT_FORMAT);
2788 if ((pCStructFormat->type != RPC_FC_CPSTRUCT) && (pCStructFormat->type != RPC_FC_CSTRUCT))
2790 ERR("invalid format type %x\n", pCStructFormat->type);
2791 RpcRaiseException(RPC_S_INTERNAL_ERROR);
2794 pCArrayFormat = (unsigned char*)&pCStructFormat->offset_to_array_description +
2795 pCStructFormat->offset_to_array_description;
2796 if (*pCArrayFormat != RPC_FC_CARRAY)
2798 ERR("invalid array format type %x\n", pCStructFormat->type);
2799 RpcRaiseException(RPC_S_INTERNAL_ERROR);
2802 esize = *(const WORD*)(pCArrayFormat+2);
2804 pCArrayFormat = ComputeConformance(pStubMsg, pMemory + pCStructFormat->memory_size, pCArrayFormat+4, 0);
2805 SizeConformance(pStubMsg);
2807 ALIGN_LENGTH(pStubMsg->BufferLength, pCStructFormat->alignment + 1);
2809 TRACE("memory_size = %d\n", pCStructFormat->memory_size);
2811 pStubMsg->BufferLength += pCStructFormat->memory_size + esize * pStubMsg->MaxCount;
2813 if (pCStructFormat->type == RPC_FC_CPSTRUCT)
2814 EmbeddedPointerBufferSize(pStubMsg, pMemory, pFormat);
2817 /***********************************************************************
2818 * NdrConformantStructMemorySize [RPCRT4.@]
2820 unsigned long WINAPI NdrConformantStructMemorySize(PMIDL_STUB_MESSAGE pStubMsg,
2821 PFORMAT_STRING pFormat)
2827 /***********************************************************************
2828 * NdrConformantStructFree [RPCRT4.@]
2830 void WINAPI NdrConformantStructFree(PMIDL_STUB_MESSAGE pStubMsg,
2831 unsigned char *pMemory,
2832 PFORMAT_STRING pFormat)
2837 /***********************************************************************
2838 * NdrConformantVaryingStructMarshall [RPCRT4.@]
2840 unsigned char * WINAPI NdrConformantVaryingStructMarshall(PMIDL_STUB_MESSAGE pStubMsg,
2841 unsigned char *pMemory,
2842 PFORMAT_STRING pFormat)
2848 /***********************************************************************
2849 * NdrConformantVaryingStructUnmarshall [RPCRT4.@]
2851 unsigned char * WINAPI NdrConformantVaryingStructUnmarshall(PMIDL_STUB_MESSAGE pStubMsg,
2852 unsigned char **ppMemory,
2853 PFORMAT_STRING pFormat,
2854 unsigned char fMustAlloc)
2860 /***********************************************************************
2861 * NdrConformantVaryingStructBufferSize [RPCRT4.@]
2863 void WINAPI NdrConformantVaryingStructBufferSize(PMIDL_STUB_MESSAGE pStubMsg,
2864 unsigned char *pMemory,
2865 PFORMAT_STRING pFormat)
2870 /***********************************************************************
2871 * NdrConformantVaryingStructMemorySize [RPCRT4.@]
2873 unsigned long WINAPI NdrConformantVaryingStructMemorySize(PMIDL_STUB_MESSAGE pStubMsg,
2874 PFORMAT_STRING pFormat)
2880 /***********************************************************************
2881 * NdrConformantVaryingStructFree [RPCRT4.@]
2883 void WINAPI NdrConformantVaryingStructFree(PMIDL_STUB_MESSAGE pStubMsg,
2884 unsigned char *pMemory,
2885 PFORMAT_STRING pFormat)
2890 /***********************************************************************
2891 * NdrFixedArrayMarshall [RPCRT4.@]
2893 unsigned char * WINAPI NdrFixedArrayMarshall(PMIDL_STUB_MESSAGE pStubMsg,
2894 unsigned char *pMemory,
2895 PFORMAT_STRING pFormat)
2901 /***********************************************************************
2902 * NdrFixedArrayUnmarshall [RPCRT4.@]
2904 unsigned char * WINAPI NdrFixedArrayUnmarshall(PMIDL_STUB_MESSAGE pStubMsg,
2905 unsigned char **ppMemory,
2906 PFORMAT_STRING pFormat,
2907 unsigned char fMustAlloc)
2913 /***********************************************************************
2914 * NdrFixedArrayBufferSize [RPCRT4.@]
2916 void WINAPI NdrFixedArrayBufferSize(PMIDL_STUB_MESSAGE pStubMsg,
2917 unsigned char *pMemory,
2918 PFORMAT_STRING pFormat)
2923 /***********************************************************************
2924 * NdrFixedArrayMemorySize [RPCRT4.@]
2926 unsigned long WINAPI NdrFixedArrayMemorySize(PMIDL_STUB_MESSAGE pStubMsg,
2927 PFORMAT_STRING pFormat)
2933 /***********************************************************************
2934 * NdrFixedArrayFree [RPCRT4.@]
2936 void WINAPI NdrFixedArrayFree(PMIDL_STUB_MESSAGE pStubMsg,
2937 unsigned char *pMemory,
2938 PFORMAT_STRING pFormat)
2943 /***********************************************************************
2944 * NdrVaryingArrayMarshall [RPCRT4.@]
2946 unsigned char * WINAPI NdrVaryingArrayMarshall(PMIDL_STUB_MESSAGE pStubMsg,
2947 unsigned char *pMemory,
2948 PFORMAT_STRING pFormat)
2954 /***********************************************************************
2955 * NdrVaryingArrayUnmarshall [RPCRT4.@]
2957 unsigned char * WINAPI NdrVaryingArrayUnmarshall(PMIDL_STUB_MESSAGE pStubMsg,
2958 unsigned char **ppMemory,
2959 PFORMAT_STRING pFormat,
2960 unsigned char fMustAlloc)
2966 /***********************************************************************
2967 * NdrVaryingArrayBufferSize [RPCRT4.@]
2969 void WINAPI NdrVaryingArrayBufferSize(PMIDL_STUB_MESSAGE pStubMsg,
2970 unsigned char *pMemory,
2971 PFORMAT_STRING pFormat)
2976 /***********************************************************************
2977 * NdrVaryingArrayMemorySize [RPCRT4.@]
2979 unsigned long WINAPI NdrVaryingArrayMemorySize(PMIDL_STUB_MESSAGE pStubMsg,
2980 PFORMAT_STRING pFormat)
2986 /***********************************************************************
2987 * NdrVaryingArrayFree [RPCRT4.@]
2989 void WINAPI NdrVaryingArrayFree(PMIDL_STUB_MESSAGE pStubMsg,
2990 unsigned char *pMemory,
2991 PFORMAT_STRING pFormat)
2996 /***********************************************************************
2997 * NdrEncapsulatedUnionMarshall [RPCRT4.@]
2999 unsigned char * WINAPI NdrEncapsulatedUnionMarshall(PMIDL_STUB_MESSAGE pStubMsg,
3000 unsigned char *pMemory,
3001 PFORMAT_STRING pFormat)
3007 /***********************************************************************
3008 * NdrEncapsulatedUnionUnmarshall [RPCRT4.@]
3010 unsigned char * WINAPI NdrEncapsulatedUnionUnmarshall(PMIDL_STUB_MESSAGE pStubMsg,
3011 unsigned char **ppMemory,
3012 PFORMAT_STRING pFormat,
3013 unsigned char fMustAlloc)
3019 /***********************************************************************
3020 * NdrEncapsulatedUnionBufferSize [RPCRT4.@]
3022 void WINAPI NdrEncapsulatedUnionBufferSize(PMIDL_STUB_MESSAGE pStubMsg,
3023 unsigned char *pMemory,
3024 PFORMAT_STRING pFormat)
3029 /***********************************************************************
3030 * NdrEncapsulatedUnionMemorySize [RPCRT4.@]
3032 unsigned long WINAPI NdrEncapsulatedUnionMemorySize(PMIDL_STUB_MESSAGE pStubMsg,
3033 PFORMAT_STRING pFormat)
3039 /***********************************************************************
3040 * NdrEncapsulatedUnionFree [RPCRT4.@]
3042 void WINAPI NdrEncapsulatedUnionFree(PMIDL_STUB_MESSAGE pStubMsg,
3043 unsigned char *pMemory,
3044 PFORMAT_STRING pFormat)
3049 static PFORMAT_STRING get_arm_offset_from_union_arm_selector(PMIDL_STUB_MESSAGE pStubMsg,
3050 unsigned long discriminant,
3051 PFORMAT_STRING pFormat)
3053 unsigned short num_arms, arm, type;
3055 num_arms = *(const SHORT*)pFormat & 0x0fff;
3057 for(arm = 0; arm < num_arms; arm++)
3059 if(discriminant == *(const ULONG*)pFormat)
3067 type = *(const unsigned short*)pFormat;
3068 TRACE("type %04x\n", type);
3069 if(arm == num_arms) /* default arm extras */
3073 FIXME("should raise an exception here\n");
3078 /* Don't marshall any type. FIXME is this correct? */
3085 static PFORMAT_STRING get_non_encapsulated_union_arm(PMIDL_STUB_MESSAGE pStubMsg,
3086 unsigned char *pMemory,
3087 PFORMAT_STRING pFormat)
3091 pFormat = ComputeConformanceOrVariance(pStubMsg, pMemory, pFormat,
3093 TRACE("got switch value %lx\n", value);
3094 pFormat += *(const SHORT*)pFormat;
3097 return get_arm_offset_from_union_arm_selector(pStubMsg, value, pFormat);
3100 static unsigned char *get_conformance_address(PMIDL_STUB_MESSAGE pStubMsg,
3101 unsigned char *pMemory,
3102 PFORMAT_STRING pFormat)
3104 short ofs = *(short *)&pFormat[2];
3107 switch (pFormat[0] & 0xf0)
3109 case RPC_FC_NORMAL_CONFORMANCE:
3113 FIXME("Conformance type %x\n", pFormat[0]);
3119 FIXME("Conformance op %x\n", pFormat[1]);
3123 return (unsigned char *)ptr + ofs;
3126 /***********************************************************************
3127 * NdrNonEncapsulatedUnionMarshall [RPCRT4.@]
3129 unsigned char * WINAPI NdrNonEncapsulatedUnionMarshall(PMIDL_STUB_MESSAGE pStubMsg,
3130 unsigned char *pMemory,
3131 PFORMAT_STRING pFormat)
3133 unsigned char *discriminant;
3134 unsigned short type;
3136 TRACE("(%p, %p, %p)\n", pStubMsg, pMemory, pFormat);
3139 /* Marshall discriminant */
3140 discriminant = get_conformance_address(pStubMsg, pMemory, pFormat + 1);
3141 NdrBaseTypeMarshall(pStubMsg, discriminant, pFormat);
3144 pFormat = get_non_encapsulated_union_arm(pStubMsg, pMemory, pFormat);
3148 type = *(const unsigned short*)pFormat;
3149 if((type & 0xff00) == 0x8000)
3151 unsigned char basetype = LOBYTE(type);
3152 return NdrBaseTypeMarshall(pStubMsg, pMemory, &basetype);
3156 PFORMAT_STRING desc = pFormat + *(const SHORT*)pFormat;
3157 NDR_MARSHALL m = NdrMarshaller[*desc & NDR_TABLE_MASK];
3160 unsigned char *saved_buffer = NULL;
3167 saved_buffer = pStubMsg->Buffer;
3168 pStubMsg->Buffer += 4; /* for pointer ID */
3169 PointerMarshall(pStubMsg, saved_buffer, *(unsigned char **)pMemory, desc);
3172 m(pStubMsg, pMemory, desc);
3175 else FIXME("no marshaller for embedded type %02x\n", *desc);
3180 static long unmarshall_discriminant(PMIDL_STUB_MESSAGE pStubMsg,
3181 PFORMAT_STRING *ppFormat)
3183 long discriminant = 0;
3191 discriminant = *(UCHAR *)pStubMsg->Buffer;
3192 pStubMsg->Buffer += sizeof(UCHAR);
3197 ALIGN_POINTER(pStubMsg->Buffer, sizeof(USHORT));
3198 discriminant = *(USHORT *)pStubMsg->Buffer;
3199 pStubMsg->Buffer += sizeof(USHORT);
3203 ALIGN_POINTER(pStubMsg->Buffer, sizeof(ULONG));
3204 discriminant = *(ULONG *)pStubMsg->Buffer;
3205 pStubMsg->Buffer += sizeof(ULONG);
3208 FIXME("Unhandled base type: 0x%02x\n", **ppFormat);
3212 if (pStubMsg->fHasNewCorrDesc)
3216 return discriminant;
3219 /**********************************************************************
3220 * NdrNonEncapsulatedUnionUnmarshall[RPCRT4.@]
3222 unsigned char * WINAPI NdrNonEncapsulatedUnionUnmarshall(PMIDL_STUB_MESSAGE pStubMsg,
3223 unsigned char **ppMemory,
3224 PFORMAT_STRING pFormat,
3225 unsigned char fMustAlloc)
3228 unsigned short type, size;
3230 TRACE("(%p, %p, %p, %d)\n", pStubMsg, ppMemory, pFormat, fMustAlloc);
3233 /* Unmarshall discriminant */
3234 discriminant = unmarshall_discriminant(pStubMsg, &pFormat);
3235 TRACE("unmarshalled discriminant %lx\n", discriminant);
3237 pFormat += *(const SHORT*)pFormat;
3239 size = *(const unsigned short*)pFormat;
3242 pFormat = get_arm_offset_from_union_arm_selector(pStubMsg, discriminant, pFormat);
3246 if(!*ppMemory || fMustAlloc)
3247 *ppMemory = NdrAllocate(pStubMsg, size);
3249 type = *(const unsigned short*)pFormat;
3250 if((type & 0xff00) == 0x8000)
3252 unsigned char basetype = LOBYTE(type);
3253 return NdrBaseTypeUnmarshall(pStubMsg, ppMemory, &basetype, fMustAlloc);
3257 PFORMAT_STRING desc = pFormat + *(const SHORT*)pFormat;
3258 NDR_UNMARSHALL m = NdrUnmarshaller[*desc & NDR_TABLE_MASK];
3261 unsigned char *saved_buffer = NULL;
3268 **(void***)ppMemory = NULL;
3269 ALIGN_POINTER(pStubMsg->Buffer, 4);
3270 saved_buffer = pStubMsg->Buffer;
3271 pStubMsg->Buffer += 4; /* for pointer ID */
3272 PointerUnmarshall(pStubMsg, saved_buffer, *(unsigned char ***)ppMemory, desc, fMustAlloc);
3275 m(pStubMsg, ppMemory, desc, fMustAlloc);
3278 else FIXME("no marshaller for embedded type %02x\n", *desc);
3283 /***********************************************************************
3284 * NdrNonEncapsulatedUnionBufferSize [RPCRT4.@]
3286 void WINAPI NdrNonEncapsulatedUnionBufferSize(PMIDL_STUB_MESSAGE pStubMsg,
3287 unsigned char *pMemory,
3288 PFORMAT_STRING pFormat)
3290 unsigned short type;
3291 TRACE("(%p, %p, %p)\n", pStubMsg, pMemory, pFormat);
3294 /* Add discriminant size */
3295 NdrBaseTypeBufferSize(pStubMsg, pMemory, pFormat);
3298 pFormat = get_non_encapsulated_union_arm(pStubMsg, pMemory, pFormat);
3302 type = *(const unsigned short*)pFormat;
3303 if((type & 0xff00) == 0x8000)
3305 unsigned char basetype = LOBYTE(type);
3306 NdrBaseTypeBufferSize(pStubMsg, pMemory, &basetype);
3310 PFORMAT_STRING desc = pFormat + *(const SHORT*)pFormat;
3311 NDR_BUFFERSIZE m = NdrBufferSizer[*desc & NDR_TABLE_MASK];
3320 ALIGN_LENGTH(pStubMsg->BufferLength, 4);
3321 pStubMsg->BufferLength += 4; /* for pointer ID */
3322 PointerBufferSize(pStubMsg, *(unsigned char **)pMemory, desc);
3325 m(pStubMsg, pMemory, desc);
3328 else FIXME("no buffersizer for embedded type %02x\n", *desc);
3333 /***********************************************************************
3334 * NdrNonEncapsulatedUnionMemorySize [RPCRT4.@]
3336 unsigned long WINAPI NdrNonEncapsulatedUnionMemorySize(PMIDL_STUB_MESSAGE pStubMsg,
3337 PFORMAT_STRING pFormat)
3340 if (pStubMsg->fHasNewCorrDesc)
3345 pFormat += *(const SHORT*)pFormat;
3346 TRACE("size %d\n", *(const SHORT*)pFormat);
3347 return *(const SHORT*)pFormat;
3350 /***********************************************************************
3351 * NdrNonEncapsulatedUnionFree [RPCRT4.@]
3353 void WINAPI NdrNonEncapsulatedUnionFree(PMIDL_STUB_MESSAGE pStubMsg,
3354 unsigned char *pMemory,
3355 PFORMAT_STRING pFormat)
3360 /***********************************************************************
3361 * NdrByteCountPointerMarshall [RPCRT4.@]
3363 unsigned char * WINAPI NdrByteCountPointerMarshall(PMIDL_STUB_MESSAGE pStubMsg,
3364 unsigned char *pMemory,
3365 PFORMAT_STRING pFormat)
3371 /***********************************************************************
3372 * NdrByteCountPointerUnmarshall [RPCRT4.@]
3374 unsigned char * WINAPI NdrByteCountPointerUnmarshall(PMIDL_STUB_MESSAGE pStubMsg,
3375 unsigned char **ppMemory,
3376 PFORMAT_STRING pFormat,
3377 unsigned char fMustAlloc)
3383 /***********************************************************************
3384 * NdrByteCountPointerBufferSize [RPCRT4.@]
3386 void WINAPI NdrByteCountPointerBufferSize(PMIDL_STUB_MESSAGE pStubMsg,
3387 unsigned char *pMemory,
3388 PFORMAT_STRING pFormat)
3393 /***********************************************************************
3394 * NdrByteCountPointerMemorySize [RPCRT4.@]
3396 unsigned long WINAPI NdrByteCountPointerMemorySize(PMIDL_STUB_MESSAGE pStubMsg,
3397 PFORMAT_STRING pFormat)
3403 /***********************************************************************
3404 * NdrByteCountPointerFree [RPCRT4.@]
3406 void WINAPI NdrByteCountPointerFree(PMIDL_STUB_MESSAGE pStubMsg,
3407 unsigned char *pMemory,
3408 PFORMAT_STRING pFormat)
3413 /***********************************************************************
3414 * NdrXmitOrRepAsMarshall [RPCRT4.@]
3416 unsigned char * WINAPI NdrXmitOrRepAsMarshall(PMIDL_STUB_MESSAGE pStubMsg,
3417 unsigned char *pMemory,
3418 PFORMAT_STRING pFormat)
3424 /***********************************************************************
3425 * NdrXmitOrRepAsUnmarshall [RPCRT4.@]
3427 unsigned char * WINAPI NdrXmitOrRepAsUnmarshall(PMIDL_STUB_MESSAGE pStubMsg,
3428 unsigned char **ppMemory,
3429 PFORMAT_STRING pFormat,
3430 unsigned char fMustAlloc)
3436 /***********************************************************************
3437 * NdrXmitOrRepAsBufferSize [RPCRT4.@]
3439 void WINAPI NdrXmitOrRepAsBufferSize(PMIDL_STUB_MESSAGE pStubMsg,
3440 unsigned char *pMemory,
3441 PFORMAT_STRING pFormat)
3446 /***********************************************************************
3447 * NdrXmitOrRepAsMemorySize [RPCRT4.@]
3449 unsigned long WINAPI NdrXmitOrRepAsMemorySize(PMIDL_STUB_MESSAGE pStubMsg,
3450 PFORMAT_STRING pFormat)
3456 /***********************************************************************
3457 * NdrXmitOrRepAsFree [RPCRT4.@]
3459 void WINAPI NdrXmitOrRepAsFree(PMIDL_STUB_MESSAGE pStubMsg,
3460 unsigned char *pMemory,
3461 PFORMAT_STRING pFormat)
3466 /***********************************************************************
3467 * NdrBaseTypeMarshall [internal]
3469 static unsigned char *WINAPI NdrBaseTypeMarshall(
3470 PMIDL_STUB_MESSAGE pStubMsg,
3471 unsigned char *pMemory,
3472 PFORMAT_STRING pFormat)
3474 TRACE("pStubMsg %p, pMemory %p, type 0x%02x\n", pStubMsg, pMemory, *pFormat);
3482 *(UCHAR *)pStubMsg->Buffer = *(UCHAR *)pMemory;
3483 pStubMsg->Buffer += sizeof(UCHAR);
3484 TRACE("value: 0x%02x\n", *(UCHAR *)pMemory);
3489 ALIGN_POINTER(pStubMsg->Buffer, sizeof(USHORT));
3490 *(USHORT *)pStubMsg->Buffer = *(USHORT *)pMemory;
3491 pStubMsg->Buffer += sizeof(USHORT);
3492 TRACE("value: 0x%04x\n", *(USHORT *)pMemory);
3496 case RPC_FC_ERROR_STATUS_T:
3498 ALIGN_POINTER(pStubMsg->Buffer, sizeof(ULONG));
3499 *(ULONG *)pStubMsg->Buffer = *(ULONG *)pMemory;
3500 pStubMsg->Buffer += sizeof(ULONG);
3501 TRACE("value: 0x%08lx\n", *(ULONG *)pMemory);
3504 ALIGN_POINTER(pStubMsg->Buffer, sizeof(float));
3505 *(float *)pStubMsg->Buffer = *(float *)pMemory;
3506 pStubMsg->Buffer += sizeof(float);
3509 ALIGN_POINTER(pStubMsg->Buffer, sizeof(double));
3510 *(double *)pStubMsg->Buffer = *(double *)pMemory;
3511 pStubMsg->Buffer += sizeof(double);
3514 ALIGN_POINTER(pStubMsg->Buffer, sizeof(ULONGLONG));
3515 *(ULONGLONG *)pStubMsg->Buffer = *(ULONGLONG *)pMemory;
3516 pStubMsg->Buffer += sizeof(ULONGLONG);
3517 TRACE("value: %s\n", wine_dbgstr_longlong(*(ULONGLONG*)pMemory));
3520 /* only 16-bits on the wire, so do a sanity check */
3521 if (*(UINT *)pMemory > USHRT_MAX)
3522 RpcRaiseException(RPC_X_ENUM_VALUE_OUT_OF_RANGE);
3523 ALIGN_POINTER(pStubMsg->Buffer, sizeof(USHORT));
3524 *(USHORT *)pStubMsg->Buffer = *(UINT *)pMemory;
3525 pStubMsg->Buffer += sizeof(USHORT);
3526 TRACE("value: 0x%04x\n", *(UINT *)pMemory);
3529 FIXME("Unhandled base type: 0x%02x\n", *pFormat);
3532 STD_OVERFLOW_CHECK(pStubMsg);
3534 /* FIXME: what is the correct return value? */
3538 /***********************************************************************
3539 * NdrBaseTypeUnmarshall [internal]
3541 static unsigned char *WINAPI NdrBaseTypeUnmarshall(
3542 PMIDL_STUB_MESSAGE pStubMsg,
3543 unsigned char **ppMemory,
3544 PFORMAT_STRING pFormat,
3545 unsigned char fMustAlloc)
3547 TRACE("pStubMsg: %p, ppMemory: %p, type: 0x%02x, fMustAlloc: %s\n", pStubMsg, ppMemory, *pFormat, fMustAlloc ? "true" : "false");
3549 if (fMustAlloc || !*ppMemory)
3551 unsigned char *Buffer = pStubMsg->Buffer;
3552 *ppMemory = NdrAllocate(pStubMsg, NdrBaseTypeMemorySize(pStubMsg, pFormat));
3553 pStubMsg->Buffer = Buffer;
3556 TRACE("*ppMemory: %p\n", *ppMemory);
3564 **(UCHAR **)ppMemory = *(UCHAR *)pStubMsg->Buffer;
3565 pStubMsg->Buffer += sizeof(UCHAR);
3566 TRACE("value: 0x%02x\n", **(UCHAR **)ppMemory);
3571 ALIGN_POINTER(pStubMsg->Buffer, sizeof(USHORT));
3572 **(USHORT **)ppMemory = *(USHORT *)pStubMsg->Buffer;
3573 pStubMsg->Buffer += sizeof(USHORT);
3574 TRACE("value: 0x%04x\n", **(USHORT **)ppMemory);
3578 case RPC_FC_ERROR_STATUS_T:
3580 ALIGN_POINTER(pStubMsg->Buffer, sizeof(ULONG));
3581 **(ULONG **)ppMemory = *(ULONG *)pStubMsg->Buffer;
3582 pStubMsg->Buffer += sizeof(ULONG);
3583 TRACE("value: 0x%08lx\n", **(ULONG **)ppMemory);
3586 ALIGN_POINTER(pStubMsg->Buffer, sizeof(float));
3587 **(float **)ppMemory = *(float *)pStubMsg->Buffer;
3588 pStubMsg->Buffer += sizeof(float);
3589 TRACE("value: %f\n", **(float **)ppMemory);
3592 ALIGN_POINTER(pStubMsg->Buffer, sizeof(double));
3593 **(double **)ppMemory = *(double*)pStubMsg->Buffer;
3594 pStubMsg->Buffer += sizeof(double);
3595 TRACE("value: %f\n", **(double **)ppMemory);
3598 ALIGN_POINTER(pStubMsg->Buffer, sizeof(ULONGLONG));
3599 **(ULONGLONG **)ppMemory = *(ULONGLONG *)pStubMsg->Buffer;
3600 pStubMsg->Buffer += sizeof(ULONGLONG);
3601 TRACE("value: %s\n", wine_dbgstr_longlong(**(ULONGLONG **)ppMemory));
3604 ALIGN_POINTER(pStubMsg->Buffer, sizeof(USHORT));
3605 /* 16-bits on the wire, but int in memory */
3606 **(UINT **)ppMemory = *(USHORT *)pStubMsg->Buffer;
3607 pStubMsg->Buffer += sizeof(USHORT);
3608 TRACE("value: 0x%08x\n", **(UINT **)ppMemory);
3611 FIXME("Unhandled base type: 0x%02x\n", *pFormat);
3614 /* FIXME: what is the correct return value? */
3619 /***********************************************************************
3620 * NdrBaseTypeBufferSize [internal]
3622 static void WINAPI NdrBaseTypeBufferSize(
3623 PMIDL_STUB_MESSAGE pStubMsg,
3624 unsigned char *pMemory,
3625 PFORMAT_STRING pFormat)
3627 TRACE("pStubMsg %p, pMemory %p, type 0x%02x\n", pStubMsg, pMemory, *pFormat);
3635 pStubMsg->BufferLength += sizeof(UCHAR);
3641 ALIGN_LENGTH(pStubMsg->BufferLength, sizeof(USHORT));
3642 pStubMsg->BufferLength += sizeof(USHORT);
3647 ALIGN_LENGTH(pStubMsg->BufferLength, sizeof(ULONG));
3648 pStubMsg->BufferLength += sizeof(ULONG);
3651 ALIGN_LENGTH(pStubMsg->BufferLength, sizeof(float));
3652 pStubMsg->BufferLength += sizeof(float);
3655 ALIGN_LENGTH(pStubMsg->BufferLength, sizeof(double));
3656 pStubMsg->BufferLength += sizeof(double);
3659 ALIGN_LENGTH(pStubMsg->BufferLength, sizeof(ULONGLONG));
3660 pStubMsg->BufferLength += sizeof(ULONGLONG);
3662 case RPC_FC_ERROR_STATUS_T:
3663 ALIGN_LENGTH(pStubMsg->BufferLength, sizeof(error_status_t));
3664 pStubMsg->BufferLength += sizeof(error_status_t);
3667 FIXME("Unhandled base type: 0x%02x\n", *pFormat);
3671 /***********************************************************************
3672 * NdrBaseTypeMemorySize [internal]
3674 static unsigned long WINAPI NdrBaseTypeMemorySize(
3675 PMIDL_STUB_MESSAGE pStubMsg,
3676 PFORMAT_STRING pFormat)
3684 pStubMsg->Buffer += sizeof(UCHAR);
3685 pStubMsg->MemorySize += sizeof(UCHAR);
3686 return sizeof(UCHAR);
3690 pStubMsg->Buffer += sizeof(USHORT);
3691 pStubMsg->MemorySize += sizeof(USHORT);
3692 return sizeof(USHORT);
3695 pStubMsg->Buffer += sizeof(ULONG);
3696 pStubMsg->MemorySize += sizeof(ULONG);
3697 return sizeof(ULONG);
3699 pStubMsg->Buffer += sizeof(float);
3700 pStubMsg->MemorySize += sizeof(float);
3701 return sizeof(float);
3703 pStubMsg->Buffer += sizeof(double);
3704 pStubMsg->MemorySize += sizeof(double);
3705 return sizeof(double);
3707 pStubMsg->Buffer += sizeof(ULONGLONG);
3708 pStubMsg->MemorySize += sizeof(ULONGLONG);
3709 return sizeof(ULONGLONG);
3710 case RPC_FC_ERROR_STATUS_T:
3711 pStubMsg->Buffer += sizeof(error_status_t);
3712 pStubMsg->MemorySize += sizeof(error_status_t);
3713 return sizeof(error_status_t);
3716 pStubMsg->Buffer += sizeof(INT);
3717 pStubMsg->MemorySize += sizeof(INT);
3720 FIXME("Unhandled base type: 0x%02x\n", *pFormat);
3725 /***********************************************************************
3726 * NdrBaseTypeFree [internal]
3728 static void WINAPI NdrBaseTypeFree(PMIDL_STUB_MESSAGE pStubMsg,
3729 unsigned char *pMemory,
3730 PFORMAT_STRING pFormat)
3732 TRACE("pStubMsg %p pMemory %p type 0x%02x\n", pStubMsg, pMemory, *pFormat);
3737 /***********************************************************************
3738 * NdrClientContextMarshall
3740 void WINAPI NdrClientContextMarshall(PMIDL_STUB_MESSAGE pStubMsg,
3741 NDR_CCONTEXT ContextHandle,
3744 FIXME("(%p, %p, %d): stub\n", pStubMsg, ContextHandle, fCheck);
3747 /***********************************************************************
3748 * NdrClientContextUnmarshall
3750 void WINAPI NdrClientContextUnmarshall(PMIDL_STUB_MESSAGE pStubMsg,
3751 NDR_CCONTEXT * pContextHandle,
3752 RPC_BINDING_HANDLE BindHandle)
3754 FIXME("(%p, %p, %p): stub\n", pStubMsg, pContextHandle, BindHandle);
3757 void WINAPI NdrServerContextMarshall(PMIDL_STUB_MESSAGE pStubMsg,
3758 NDR_SCONTEXT ContextHandle,
3759 NDR_RUNDOWN RundownRoutine )
3761 FIXME("(%p, %p, %p): stub\n", pStubMsg, ContextHandle, RundownRoutine);
3764 NDR_SCONTEXT WINAPI NdrServerContextUnmarshall(PMIDL_STUB_MESSAGE pStubMsg)
3766 FIXME("(%p): stub\n", pStubMsg);
3770 void WINAPI NdrContextHandleSize(PMIDL_STUB_MESSAGE pStubMsg,
3771 unsigned char* pMemory,
3772 PFORMAT_STRING pFormat)
3774 FIXME("(%p, %p, %p): stub\n", pStubMsg, pMemory, pFormat);
3777 NDR_SCONTEXT WINAPI NdrContextHandleInitialize(PMIDL_STUB_MESSAGE pStubMsg,
3778 PFORMAT_STRING pFormat)
3780 FIXME("(%p, %p): stub\n", pStubMsg, pFormat);
3784 void WINAPI NdrServerContextNewMarshall(PMIDL_STUB_MESSAGE pStubMsg,
3785 NDR_SCONTEXT ContextHandle,
3786 NDR_RUNDOWN RundownRoutine,
3787 PFORMAT_STRING pFormat)
3789 FIXME("(%p, %p, %p, %p): stub\n", pStubMsg, ContextHandle, RundownRoutine, pFormat);
3792 NDR_SCONTEXT WINAPI NdrServerContextNewUnmarshall(PMIDL_STUB_MESSAGE pStubMsg,
3793 PFORMAT_STRING pFormat)
3795 FIXME("(%p, %p): stub\n", pStubMsg, pFormat);
3799 RPC_BINDING_HANDLE WINAPI NDRCContextBinding(NDR_CCONTEXT CContext)
3801 FIXME("(%p): stub\n", CContext);