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 pStubMsg->MaxCount = NDR_LOCAL_UINT32_READ(pStubMsg->Buffer);
312 pStubMsg->Buffer += 4;
313 TRACE("unmarshalled conformance is %ld\n", pStubMsg->MaxCount);
314 if (pStubMsg->fHasNewCorrDesc)
320 static inline PFORMAT_STRING ReadVariance(MIDL_STUB_MESSAGE *pStubMsg, PFORMAT_STRING pFormat)
322 if (!IsConformanceOrVariancePresent(pFormat))
324 pStubMsg->Offset = 0;
325 pStubMsg->ActualCount = pStubMsg->MaxCount;
329 pStubMsg->Offset = NDR_LOCAL_UINT32_READ(pStubMsg->Buffer);
330 pStubMsg->Buffer += 4;
331 TRACE("offset is %ld\n", pStubMsg->Offset);
332 pStubMsg->ActualCount = NDR_LOCAL_UINT32_READ(pStubMsg->Buffer);
333 pStubMsg->Buffer += 4;
334 TRACE("variance is %ld\n", pStubMsg->ActualCount);
337 if (pStubMsg->fHasNewCorrDesc)
343 PFORMAT_STRING ComputeConformanceOrVariance(
344 MIDL_STUB_MESSAGE *pStubMsg, unsigned char *pMemory,
345 PFORMAT_STRING pFormat, ULONG_PTR def, ULONG *pCount)
347 BYTE dtype = pFormat[0] & 0xf;
348 short ofs = *(short *)&pFormat[2];
352 if (!IsConformanceOrVariancePresent(pFormat)) {
353 /* null descriptor */
358 switch (pFormat[0] & 0xf0) {
359 case RPC_FC_NORMAL_CONFORMANCE:
360 TRACE("normal conformance, ofs=%d\n", ofs);
363 case RPC_FC_POINTER_CONFORMANCE:
364 TRACE("pointer conformance, ofs=%d\n", ofs);
365 ptr = pStubMsg->Memory;
367 case RPC_FC_TOP_LEVEL_CONFORMANCE:
368 TRACE("toplevel conformance, ofs=%d\n", ofs);
369 if (pStubMsg->StackTop) {
370 ptr = pStubMsg->StackTop;
373 /* -Os mode, *pCount is already set */
377 case RPC_FC_CONSTANT_CONFORMANCE:
378 data = ofs | ((DWORD)pFormat[1] << 16);
379 TRACE("constant conformance, val=%ld\n", data);
382 case RPC_FC_TOP_LEVEL_MULTID_CONFORMANCE:
383 FIXME("toplevel multidimensional conformance, ofs=%d\n", ofs);
384 if (pStubMsg->StackTop) {
385 ptr = pStubMsg->StackTop;
393 FIXME("unknown conformance type %x\n", pFormat[0] & 0xf0);
396 switch (pFormat[1]) {
397 case RPC_FC_DEREFERENCE:
398 ptr = *(LPVOID*)((char *)ptr + ofs);
400 case RPC_FC_CALLBACK:
402 unsigned char *old_stack_top = pStubMsg->StackTop;
403 pStubMsg->StackTop = ptr;
405 /* ofs is index into StubDesc->apfnExprEval */
406 TRACE("callback conformance into apfnExprEval[%d]\n", ofs);
407 pStubMsg->StubDesc->apfnExprEval[ofs](pStubMsg);
409 pStubMsg->StackTop = old_stack_top;
413 ptr = (char *)ptr + ofs;
426 data = *(USHORT*)ptr;
435 FIXME("unknown conformance data type %x\n", dtype);
438 TRACE("dereferenced data type %x at %p, got %ld\n", dtype, ptr, data);
441 switch (pFormat[1]) {
445 case RPC_FC_DEREFERENCE:
446 /* already handled */
449 FIXME("unknown conformance op %d\n", pFormat[1]);
454 TRACE("resulting conformance is %ld\n", *pCount);
455 if (pStubMsg->fHasNewCorrDesc)
463 * NdrConformantString:
465 * What MS calls a ConformantString is, in DCE terminology,
466 * a Varying-Conformant String.
468 * maxlen: DWORD (max # of CHARTYPE characters, inclusive of '\0')
469 * offset: DWORD (actual string data begins at (offset) CHARTYPE's
470 * into unmarshalled string)
471 * length: DWORD (# of CHARTYPE characters, inclusive of '\0')
473 * data: CHARTYPE[maxlen]
475 * ], where CHARTYPE is the appropriate character type (specified externally)
479 /***********************************************************************
480 * NdrConformantStringMarshall [RPCRT4.@]
482 unsigned char *WINAPI NdrConformantStringMarshall(MIDL_STUB_MESSAGE *pStubMsg,
483 unsigned char *pszMessage, PFORMAT_STRING pFormat)
485 unsigned long len, esize;
488 TRACE("(pStubMsg == ^%p, pszMessage == ^%p, pFormat == ^%p)\n", pStubMsg, pszMessage, pFormat);
491 if (*pFormat == RPC_FC_C_CSTRING) {
492 TRACE("string=%s\n", debugstr_a((char*)pszMessage));
493 len = strlen((char*)pszMessage)+1;
496 else if (*pFormat == RPC_FC_C_WSTRING) {
497 TRACE("string=%s\n", debugstr_w((LPWSTR)pszMessage));
498 len = strlenW((LPWSTR)pszMessage)+1;
502 ERR("Unhandled string type: %#x\n", *pFormat);
503 /* FIXME: raise an exception. */
507 if (pFormat[1] != RPC_FC_PAD) {
508 FIXME("sized string format=%d\n", pFormat[1]);
511 assert( (pStubMsg->BufferLength >= (len*esize + 13)) && (pStubMsg->Buffer != NULL) );
513 c = pStubMsg->Buffer;
515 NDR_LOCAL_UINT32_WRITE(c, len); /* max length: strlen + 1 (for '\0') */
516 c += 8; /* offset: 0 */
517 NDR_LOCAL_UINT32_WRITE(c, len); /* actual length: (same) */
519 memcpy(c, pszMessage, len*esize); /* the string itself */
521 pStubMsg->Buffer = c;
523 STD_OVERFLOW_CHECK(pStubMsg);
526 return NULL; /* is this always right? */
529 /***********************************************************************
530 * NdrConformantStringBufferSize [RPCRT4.@]
532 void WINAPI NdrConformantStringBufferSize(PMIDL_STUB_MESSAGE pStubMsg,
533 unsigned char* pMemory, PFORMAT_STRING pFormat)
535 TRACE("(pStubMsg == ^%p, pMemory == ^%p, pFormat == ^%p)\n", pStubMsg, pMemory, pFormat);
538 if (*pFormat == RPC_FC_C_CSTRING) {
539 /* we need 12 octets for the [maxlen, offset, len] DWORDS, + 1 octet for '\0' */
540 TRACE("string=%s\n", debugstr_a((char*)pMemory));
541 pStubMsg->BufferLength += strlen((char*)pMemory) + 13 + BUFFER_PARANOIA;
543 else if (*pFormat == RPC_FC_C_WSTRING) {
544 /* we need 12 octets for the [maxlen, offset, len] DWORDS, + 2 octets for L'\0' */
545 TRACE("string=%s\n", debugstr_w((LPWSTR)pMemory));
546 pStubMsg->BufferLength += strlenW((LPWSTR)pMemory)*2 + 14 + BUFFER_PARANOIA;
549 ERR("Unhandled string type: %#x\n", *pFormat);
550 /* FIXME: raise an exception */
553 if (pFormat[1] != RPC_FC_PAD) {
554 FIXME("sized string format=%d\n", pFormat[1]);
558 /************************************************************************
559 * NdrConformantStringMemorySize [RPCRT4.@]
561 unsigned long WINAPI NdrConformantStringMemorySize( PMIDL_STUB_MESSAGE pStubMsg,
562 PFORMAT_STRING pFormat )
564 unsigned long rslt = 0;
566 TRACE("(pStubMsg == ^%p, pFormat == ^%p)\n", pStubMsg, pFormat);
568 assert(pStubMsg && pFormat);
570 if (*pFormat == RPC_FC_C_CSTRING) {
571 rslt = NDR_LOCAL_UINT32_READ(pStubMsg->Buffer); /* maxlen */
573 else if (*pFormat == RPC_FC_C_WSTRING) {
574 rslt = NDR_LOCAL_UINT32_READ(pStubMsg->Buffer)*2; /* maxlen */
577 ERR("Unhandled string type: %#x\n", *pFormat);
578 /* FIXME: raise an exception */
581 if (pFormat[1] != RPC_FC_PAD) {
582 FIXME("sized string format=%d\n", pFormat[1]);
585 TRACE(" --> %lu\n", rslt);
589 /************************************************************************
590 * NdrConformantStringUnmarshall [RPCRT4.@]
592 unsigned char *WINAPI NdrConformantStringUnmarshall( PMIDL_STUB_MESSAGE pStubMsg,
593 unsigned char** ppMemory, PFORMAT_STRING pFormat, unsigned char fMustAlloc )
595 unsigned long len, esize, ofs;
597 TRACE("(pStubMsg == ^%p, *pMemory == ^%p, pFormat == ^%p, fMustAlloc == %u)\n",
598 pStubMsg, *ppMemory, pFormat, fMustAlloc);
600 assert(pFormat && ppMemory && pStubMsg);
602 pStubMsg->Buffer += 4;
603 ofs = NDR_LOCAL_UINT32_READ(pStubMsg->Buffer);
604 pStubMsg->Buffer += 4;
605 len = NDR_LOCAL_UINT32_READ(pStubMsg->Buffer);
606 pStubMsg->Buffer += 4;
608 if (*pFormat == RPC_FC_C_CSTRING) esize = 1;
609 else if (*pFormat == RPC_FC_C_WSTRING) esize = 2;
611 ERR("Unhandled string type: %#x\n", *pFormat);
612 /* FIXME: raise an exception */
616 if (pFormat[1] != RPC_FC_PAD) {
617 FIXME("sized string format=%d\n", pFormat[1]);
620 if (fMustAlloc || !*ppMemory)
621 *ppMemory = NdrAllocate(pStubMsg, len*esize + BUFFER_PARANOIA);
623 memcpy(*ppMemory, pStubMsg->Buffer, len*esize);
625 pStubMsg->Buffer += len*esize;
627 if (*pFormat == RPC_FC_C_CSTRING) {
628 TRACE("string=%s\n", debugstr_a((char*)*ppMemory));
630 else if (*pFormat == RPC_FC_C_WSTRING) {
631 TRACE("string=%s\n", debugstr_w((LPWSTR)*ppMemory));
634 return NULL; /* FIXME: is this always right? */
637 /***********************************************************************
638 * NdrNonConformantStringMarshall [RPCRT4.@]
640 unsigned char * WINAPI NdrNonConformantStringMarshall(PMIDL_STUB_MESSAGE pStubMsg,
641 unsigned char *pMemory,
642 PFORMAT_STRING pFormat)
648 /***********************************************************************
649 * NdrNonConformantStringUnmarshall [RPCRT4.@]
651 unsigned char * WINAPI NdrNonConformantStringUnmarshall(PMIDL_STUB_MESSAGE pStubMsg,
652 unsigned char **ppMemory,
653 PFORMAT_STRING pFormat,
654 unsigned char fMustAlloc)
660 /***********************************************************************
661 * NdrNonConformantStringBufferSize [RPCRT4.@]
663 void WINAPI NdrNonConformantStringBufferSize(PMIDL_STUB_MESSAGE pStubMsg,
664 unsigned char *pMemory,
665 PFORMAT_STRING pFormat)
670 /***********************************************************************
671 * NdrNonConformantStringMemorySize [RPCRT4.@]
673 unsigned long WINAPI NdrNonConformantStringMemorySize(PMIDL_STUB_MESSAGE pStubMsg,
674 PFORMAT_STRING pFormat)
680 static inline void dump_pointer_attr(unsigned char attr)
682 if (attr & RPC_FC_P_ALLOCALLNODES)
683 TRACE(" RPC_FC_P_ALLOCALLNODES");
684 if (attr & RPC_FC_P_DONTFREE)
685 TRACE(" RPC_FC_P_DONTFREE");
686 if (attr & RPC_FC_P_ONSTACK)
687 TRACE(" RPC_FC_P_ONSTACK");
688 if (attr & RPC_FC_P_SIMPLEPOINTER)
689 TRACE(" RPC_FC_P_SIMPLEPOINTER");
690 if (attr & RPC_FC_P_DEREF)
691 TRACE(" RPC_FC_P_DEREF");
695 /***********************************************************************
698 void WINAPI PointerMarshall(PMIDL_STUB_MESSAGE pStubMsg,
699 unsigned char *Buffer,
700 unsigned char *Pointer,
701 PFORMAT_STRING pFormat)
703 unsigned type = pFormat[0], attr = pFormat[1];
707 TRACE("(%p,%p,%p,%p)\n", pStubMsg, Buffer, Pointer, pFormat);
708 TRACE("type=0x%x, attr=", type); dump_pointer_attr(attr);
710 if (attr & RPC_FC_P_SIMPLEPOINTER) desc = pFormat;
711 else desc = pFormat + *(const SHORT*)pFormat;
714 case RPC_FC_RP: /* ref pointer (always non-null) */
715 #if 0 /* this causes problems for InstallShield so is disabled - we need more tests */
717 RpcRaiseException(RPC_X_NULL_REF_POINTER);
720 case RPC_FC_UP: /* unique pointer */
721 case RPC_FC_OP: /* object pointer - same as unique here */
722 TRACE("writing %p to buffer\n", Pointer);
723 NDR_LOCAL_UINT32_WRITE(pStubMsg->Buffer, (unsigned long)Pointer);
724 pStubMsg->Buffer += 4;
728 FIXME("unhandled ptr type=%02x\n", type);
729 RpcRaiseException(RPC_X_BAD_STUB_DATA);
732 TRACE("calling marshaller for type 0x%x\n", (int)*desc);
735 if (attr & RPC_FC_P_DEREF) {
736 Pointer = *(unsigned char**)Pointer;
737 TRACE("deref => %p\n", Pointer);
739 m = NdrMarshaller[*desc & NDR_TABLE_MASK];
740 if (m) m(pStubMsg, Pointer, desc);
741 else FIXME("no marshaller for data type=%02x\n", *desc);
744 STD_OVERFLOW_CHECK(pStubMsg);
747 /***********************************************************************
750 void WINAPI PointerUnmarshall(PMIDL_STUB_MESSAGE pStubMsg,
751 unsigned char *Buffer,
752 unsigned char **pPointer,
753 PFORMAT_STRING pFormat,
754 unsigned char fMustAlloc)
756 unsigned type = pFormat[0], attr = pFormat[1];
759 DWORD pointer_id = 0;
761 TRACE("(%p,%p,%p,%p,%d)\n", pStubMsg, Buffer, pPointer, pFormat, fMustAlloc);
762 TRACE("type=0x%x, attr=", type); dump_pointer_attr(attr);
764 if (attr & RPC_FC_P_SIMPLEPOINTER) desc = pFormat;
765 else desc = pFormat + *(const SHORT*)pFormat;
768 case RPC_FC_RP: /* ref pointer (always non-null) */
771 case RPC_FC_UP: /* unique pointer */
772 pointer_id = NDR_LOCAL_UINT32_READ(pStubMsg->Buffer);
773 pStubMsg->Buffer += 4;
775 case RPC_FC_OP: /* object pointer - we must free data before overwriting it */
776 pointer_id = NDR_LOCAL_UINT32_READ(pStubMsg->Buffer);
777 pStubMsg->Buffer += 4;
779 FIXME("free object pointer %p\n", *pPointer);
783 FIXME("unhandled ptr type=%02x\n", type);
784 RpcRaiseException(RPC_X_BAD_STUB_DATA);
788 if (attr & RPC_FC_P_DEREF) {
789 if (!*pPointer || fMustAlloc)
790 *pPointer = NdrAllocate(pStubMsg, sizeof(void *));
791 pPointer = *(unsigned char***)pPointer;
792 TRACE("deref => %p\n", pPointer);
794 m = NdrUnmarshaller[*desc & NDR_TABLE_MASK];
795 if (m) m(pStubMsg, pPointer, desc, fMustAlloc);
796 else FIXME("no unmarshaller for data type=%02x\n", *desc);
799 TRACE("pointer=%p\n", *pPointer);
802 /***********************************************************************
805 void WINAPI PointerBufferSize(PMIDL_STUB_MESSAGE pStubMsg,
806 unsigned char *Pointer,
807 PFORMAT_STRING pFormat)
809 unsigned type = pFormat[0], attr = pFormat[1];
813 TRACE("(%p,%p,%p)\n", pStubMsg, Pointer, pFormat);
814 TRACE("type=0x%x, attr=", type); dump_pointer_attr(attr);
816 if (attr & RPC_FC_P_SIMPLEPOINTER) desc = pFormat;
817 else desc = pFormat + *(const SHORT*)pFormat;
820 case RPC_FC_RP: /* ref pointer (always non-null) */
824 pStubMsg->BufferLength += 4;
825 /* NULL pointer has no further representation */
831 FIXME("unhandled ptr type=%02x\n", type);
832 RpcRaiseException(RPC_X_BAD_STUB_DATA);
835 if (attr & RPC_FC_P_DEREF) {
836 Pointer = *(unsigned char**)Pointer;
837 TRACE("deref => %p\n", Pointer);
840 m = NdrBufferSizer[*desc & NDR_TABLE_MASK];
841 if (m) m(pStubMsg, Pointer, desc);
842 else FIXME("no buffersizer for data type=%02x\n", *desc);
845 /***********************************************************************
846 * PointerMemorySize [RPCRT4.@]
848 unsigned long WINAPI PointerMemorySize(PMIDL_STUB_MESSAGE pStubMsg,
849 unsigned char *Buffer,
850 PFORMAT_STRING pFormat)
852 unsigned type = pFormat[0], attr = pFormat[1];
856 FIXME("(%p,%p,%p): stub\n", pStubMsg, Buffer, pFormat);
857 TRACE("type=0x%x, attr=", type); dump_pointer_attr(attr);
859 if (attr & RPC_FC_P_SIMPLEPOINTER) desc = pFormat;
860 else desc = pFormat + *(const SHORT*)pFormat;
863 case RPC_FC_RP: /* ref pointer (always non-null) */
866 FIXME("unhandled ptr type=%02x\n", type);
867 RpcRaiseException(RPC_X_BAD_STUB_DATA);
870 if (attr & RPC_FC_P_DEREF) {
874 m = NdrMemorySizer[*desc & NDR_TABLE_MASK];
875 if (m) m(pStubMsg, desc);
876 else FIXME("no memorysizer for data type=%02x\n", *desc);
881 /***********************************************************************
882 * PointerFree [RPCRT4.@]
884 void WINAPI PointerFree(PMIDL_STUB_MESSAGE pStubMsg,
885 unsigned char *Pointer,
886 PFORMAT_STRING pFormat)
888 unsigned type = pFormat[0], attr = pFormat[1];
892 TRACE("(%p,%p,%p)\n", pStubMsg, Pointer, pFormat);
893 TRACE("type=0x%x, attr=", type); dump_pointer_attr(attr);
894 if (attr & RPC_FC_P_DONTFREE) return;
896 if (attr & RPC_FC_P_SIMPLEPOINTER) desc = pFormat;
897 else desc = pFormat + *(const SHORT*)pFormat;
899 if (!Pointer) return;
901 if (attr & RPC_FC_P_DEREF) {
902 Pointer = *(unsigned char**)Pointer;
903 TRACE("deref => %p\n", Pointer);
906 m = NdrFreer[*desc & NDR_TABLE_MASK];
907 if (m) m(pStubMsg, Pointer, desc);
909 /* hmm... is this sensible?
910 * perhaps we should check if the memory comes from NdrAllocate,
911 * and deallocate only if so - checking if the pointer is between
912 * BufferStart and BufferEnd is probably no good since the buffer
913 * may be reallocated when the server wants to marshal the reply */
915 case RPC_FC_BOGUS_STRUCT:
916 case RPC_FC_BOGUS_ARRAY:
917 case RPC_FC_USER_MARSHAL:
922 FIXME("unhandled data type=%02x\n", *desc);
924 case RPC_FC_C_CSTRING:
925 case RPC_FC_C_WSTRING:
926 if (pStubMsg->ReuseBuffer) goto notfree;
932 if (attr & RPC_FC_P_ONSTACK) {
933 TRACE("not freeing stack ptr %p\n", Pointer);
936 TRACE("freeing %p\n", Pointer);
937 NdrFree(pStubMsg, Pointer);
940 TRACE("not freeing %p\n", Pointer);
943 /***********************************************************************
944 * EmbeddedPointerMarshall
946 unsigned char * WINAPI EmbeddedPointerMarshall(PMIDL_STUB_MESSAGE pStubMsg,
947 unsigned char *pMemory,
948 PFORMAT_STRING pFormat)
950 unsigned char *Mark = pStubMsg->BufferMark;
951 unsigned long Offset = pStubMsg->Offset;
952 unsigned ofs, rep, count, stride, xofs;
954 TRACE("(%p,%p,%p)\n", pStubMsg, pMemory, pFormat);
956 if (*pFormat != RPC_FC_PP) return NULL;
959 while (pFormat[0] != RPC_FC_END) {
960 switch (pFormat[0]) {
962 FIXME("unknown repeat type %d\n", pFormat[0]);
963 case RPC_FC_NO_REPEAT:
971 case RPC_FC_FIXED_REPEAT:
972 rep = *(const WORD*)&pFormat[2];
973 stride = *(const WORD*)&pFormat[4];
974 ofs = *(const WORD*)&pFormat[6];
975 count = *(const WORD*)&pFormat[8];
979 case RPC_FC_VARIABLE_REPEAT:
980 rep = pStubMsg->MaxCount;
981 stride = *(const WORD*)&pFormat[2];
982 ofs = *(const WORD*)&pFormat[4];
983 count = *(const WORD*)&pFormat[6];
984 xofs = (pFormat[1] == RPC_FC_VARIABLE_OFFSET) ? Offset * stride : 0;
988 /* ofs doesn't seem to matter in this context */
990 PFORMAT_STRING info = pFormat;
991 unsigned char *membase = pMemory + xofs;
993 for (u=0; u<count; u++,info+=8) {
994 unsigned char *memptr = membase + *(const SHORT*)&info[0];
995 unsigned char *bufptr = Mark + *(const SHORT*)&info[2];
996 PointerMarshall(pStubMsg, bufptr, *(unsigned char**)memptr, info+4);
1000 pFormat += 8 * count;
1003 STD_OVERFLOW_CHECK(pStubMsg);
1008 /***********************************************************************
1009 * EmbeddedPointerUnmarshall
1011 unsigned char * WINAPI EmbeddedPointerUnmarshall(PMIDL_STUB_MESSAGE pStubMsg,
1012 unsigned char **ppMemory,
1013 PFORMAT_STRING pFormat,
1014 unsigned char fMustAlloc)
1016 unsigned char *Mark = pStubMsg->BufferMark;
1017 unsigned long Offset = pStubMsg->Offset;
1018 unsigned ofs, rep, count, stride, xofs;
1020 TRACE("(%p,%p,%p,%d)\n", pStubMsg, ppMemory, pFormat, fMustAlloc);
1022 if (*pFormat != RPC_FC_PP) return NULL;
1025 while (pFormat[0] != RPC_FC_END) {
1026 switch (pFormat[0]) {
1028 FIXME("unknown repeat type %d\n", pFormat[0]);
1029 case RPC_FC_NO_REPEAT:
1037 case RPC_FC_FIXED_REPEAT:
1038 rep = *(const WORD*)&pFormat[2];
1039 stride = *(const WORD*)&pFormat[4];
1040 ofs = *(const WORD*)&pFormat[6];
1041 count = *(const WORD*)&pFormat[8];
1045 case RPC_FC_VARIABLE_REPEAT:
1046 rep = pStubMsg->MaxCount;
1047 stride = *(const WORD*)&pFormat[2];
1048 ofs = *(const WORD*)&pFormat[4];
1049 count = *(const WORD*)&pFormat[6];
1050 xofs = (pFormat[1] == RPC_FC_VARIABLE_OFFSET) ? Offset * stride : 0;
1054 /* ofs doesn't seem to matter in this context */
1056 PFORMAT_STRING info = pFormat;
1057 unsigned char *membase = *ppMemory + xofs;
1059 for (u=0; u<count; u++,info+=8) {
1060 unsigned char *memptr = membase + *(const SHORT*)&info[0];
1061 unsigned char *bufptr = Mark + *(const SHORT*)&info[2];
1062 PointerUnmarshall(pStubMsg, bufptr, (unsigned char**)memptr, info+4, fMustAlloc);
1066 pFormat += 8 * count;
1072 /***********************************************************************
1073 * EmbeddedPointerBufferSize
1075 void WINAPI EmbeddedPointerBufferSize(PMIDL_STUB_MESSAGE pStubMsg,
1076 unsigned char *pMemory,
1077 PFORMAT_STRING pFormat)
1079 unsigned long Offset = pStubMsg->Offset;
1080 unsigned ofs, rep, count, stride, xofs;
1082 TRACE("(%p,%p,%p)\n", pStubMsg, pMemory, pFormat);
1083 if (*pFormat != RPC_FC_PP) return;
1086 while (pFormat[0] != RPC_FC_END) {
1087 switch (pFormat[0]) {
1089 FIXME("unknown repeat type %d\n", pFormat[0]);
1090 case RPC_FC_NO_REPEAT:
1098 case RPC_FC_FIXED_REPEAT:
1099 rep = *(const WORD*)&pFormat[2];
1100 stride = *(const WORD*)&pFormat[4];
1101 ofs = *(const WORD*)&pFormat[6];
1102 count = *(const WORD*)&pFormat[8];
1106 case RPC_FC_VARIABLE_REPEAT:
1107 rep = pStubMsg->MaxCount;
1108 stride = *(const WORD*)&pFormat[2];
1109 ofs = *(const WORD*)&pFormat[4];
1110 count = *(const WORD*)&pFormat[6];
1111 xofs = (pFormat[1] == RPC_FC_VARIABLE_OFFSET) ? Offset * stride : 0;
1115 /* ofs doesn't seem to matter in this context */
1117 PFORMAT_STRING info = pFormat;
1118 unsigned char *membase = pMemory + xofs;
1120 for (u=0; u<count; u++,info+=8) {
1121 unsigned char *memptr = membase + *(const SHORT*)&info[0];
1122 PointerBufferSize(pStubMsg, *(unsigned char**)memptr, info+4);
1126 pFormat += 8 * count;
1130 /***********************************************************************
1131 * EmbeddedPointerMemorySize
1133 unsigned long WINAPI EmbeddedPointerMemorySize(PMIDL_STUB_MESSAGE pStubMsg,
1134 PFORMAT_STRING pFormat)
1136 unsigned long Offset = pStubMsg->Offset;
1137 unsigned char *Mark = pStubMsg->BufferMark;
1138 unsigned ofs, rep, count, stride, xofs;
1140 FIXME("(%p,%p): stub\n", pStubMsg, pFormat);
1141 if (*pFormat != RPC_FC_PP) return 0;
1144 while (pFormat[0] != RPC_FC_END) {
1145 switch (pFormat[0]) {
1147 FIXME("unknown repeat type %d\n", pFormat[0]);
1148 case RPC_FC_NO_REPEAT:
1156 case RPC_FC_FIXED_REPEAT:
1157 rep = *(const WORD*)&pFormat[2];
1158 stride = *(const WORD*)&pFormat[4];
1159 ofs = *(const WORD*)&pFormat[6];
1160 count = *(const WORD*)&pFormat[8];
1164 case RPC_FC_VARIABLE_REPEAT:
1165 rep = pStubMsg->MaxCount;
1166 stride = *(const WORD*)&pFormat[2];
1167 ofs = *(const WORD*)&pFormat[4];
1168 count = *(const WORD*)&pFormat[6];
1169 xofs = (pFormat[1] == RPC_FC_VARIABLE_OFFSET) ? Offset * stride : 0;
1173 /* ofs doesn't seem to matter in this context */
1175 PFORMAT_STRING info = pFormat;
1177 for (u=0; u<count; u++,info+=8) {
1178 unsigned char *bufptr = Mark + *(const SHORT*)&info[2];
1179 PointerMemorySize(pStubMsg, bufptr, info+4);
1183 pFormat += 8 * count;
1189 /***********************************************************************
1190 * EmbeddedPointerFree
1192 void WINAPI EmbeddedPointerFree(PMIDL_STUB_MESSAGE pStubMsg,
1193 unsigned char *pMemory,
1194 PFORMAT_STRING pFormat)
1196 unsigned long Offset = pStubMsg->Offset;
1197 unsigned ofs, rep, count, stride, xofs;
1199 TRACE("(%p,%p,%p)\n", pStubMsg, pMemory, pFormat);
1200 if (*pFormat != RPC_FC_PP) return;
1203 while (pFormat[0] != RPC_FC_END) {
1204 switch (pFormat[0]) {
1206 FIXME("unknown repeat type %d\n", pFormat[0]);
1207 case RPC_FC_NO_REPEAT:
1215 case RPC_FC_FIXED_REPEAT:
1216 rep = *(const WORD*)&pFormat[2];
1217 stride = *(const WORD*)&pFormat[4];
1218 ofs = *(const WORD*)&pFormat[6];
1219 count = *(const WORD*)&pFormat[8];
1223 case RPC_FC_VARIABLE_REPEAT:
1224 rep = pStubMsg->MaxCount;
1225 stride = *(const WORD*)&pFormat[2];
1226 ofs = *(const WORD*)&pFormat[4];
1227 count = *(const WORD*)&pFormat[6];
1228 xofs = (pFormat[1] == RPC_FC_VARIABLE_OFFSET) ? Offset * stride : 0;
1232 /* ofs doesn't seem to matter in this context */
1234 PFORMAT_STRING info = pFormat;
1235 unsigned char *membase = pMemory + xofs;
1237 for (u=0; u<count; u++,info+=8) {
1238 unsigned char *memptr = membase + *(const SHORT*)&info[0];
1239 PointerFree(pStubMsg, *(unsigned char**)memptr, info+4);
1243 pFormat += 8 * count;
1247 /***********************************************************************
1248 * NdrPointerMarshall [RPCRT4.@]
1250 unsigned char * WINAPI NdrPointerMarshall(PMIDL_STUB_MESSAGE pStubMsg,
1251 unsigned char *pMemory,
1252 PFORMAT_STRING pFormat)
1254 TRACE("(%p,%p,%p)\n", pStubMsg, pMemory, pFormat);
1256 pStubMsg->BufferMark = pStubMsg->Buffer;
1257 PointerMarshall(pStubMsg, pStubMsg->Buffer, pMemory, pFormat);
1259 STD_OVERFLOW_CHECK(pStubMsg);
1264 /***********************************************************************
1265 * NdrPointerUnmarshall [RPCRT4.@]
1267 unsigned char * WINAPI NdrPointerUnmarshall(PMIDL_STUB_MESSAGE pStubMsg,
1268 unsigned char **ppMemory,
1269 PFORMAT_STRING pFormat,
1270 unsigned char fMustAlloc)
1272 TRACE("(%p,%p,%p,%d)\n", pStubMsg, ppMemory, pFormat, fMustAlloc);
1274 pStubMsg->BufferMark = pStubMsg->Buffer;
1275 PointerUnmarshall(pStubMsg, pStubMsg->Buffer, ppMemory, pFormat, fMustAlloc);
1280 /***********************************************************************
1281 * NdrPointerBufferSize [RPCRT4.@]
1283 void WINAPI NdrPointerBufferSize(PMIDL_STUB_MESSAGE pStubMsg,
1284 unsigned char *pMemory,
1285 PFORMAT_STRING pFormat)
1287 TRACE("(%p,%p,%p)\n", pStubMsg, pMemory, pFormat);
1288 PointerBufferSize(pStubMsg, pMemory, pFormat);
1291 /***********************************************************************
1292 * NdrPointerMemorySize [RPCRT4.@]
1294 unsigned long WINAPI NdrPointerMemorySize(PMIDL_STUB_MESSAGE pStubMsg,
1295 PFORMAT_STRING pFormat)
1297 /* unsigned size = *(LPWORD)(pFormat+2); */
1298 FIXME("(%p,%p): stub\n", pStubMsg, pFormat);
1299 PointerMemorySize(pStubMsg, pStubMsg->Buffer, pFormat);
1303 /***********************************************************************
1304 * NdrPointerFree [RPCRT4.@]
1306 void WINAPI NdrPointerFree(PMIDL_STUB_MESSAGE pStubMsg,
1307 unsigned char *pMemory,
1308 PFORMAT_STRING pFormat)
1310 TRACE("(%p,%p,%p)\n", pStubMsg, pMemory, pFormat);
1311 PointerFree(pStubMsg, pMemory, pFormat);
1314 /***********************************************************************
1315 * NdrSimpleStructMarshall [RPCRT4.@]
1317 unsigned char * WINAPI NdrSimpleStructMarshall(PMIDL_STUB_MESSAGE pStubMsg,
1318 unsigned char *pMemory,
1319 PFORMAT_STRING pFormat)
1321 unsigned size = *(const WORD*)(pFormat+2);
1322 TRACE("(%p,%p,%p)\n", pStubMsg, pMemory, pFormat);
1324 memcpy(pStubMsg->Buffer, pMemory, size);
1325 pStubMsg->BufferMark = pStubMsg->Buffer;
1326 pStubMsg->Buffer += size;
1328 if (pFormat[0] != RPC_FC_STRUCT)
1329 EmbeddedPointerMarshall(pStubMsg, pMemory, pFormat+4);
1331 STD_OVERFLOW_CHECK(pStubMsg);
1336 /***********************************************************************
1337 * NdrSimpleStructUnmarshall [RPCRT4.@]
1339 unsigned char * WINAPI NdrSimpleStructUnmarshall(PMIDL_STUB_MESSAGE pStubMsg,
1340 unsigned char **ppMemory,
1341 PFORMAT_STRING pFormat,
1342 unsigned char fMustAlloc)
1344 unsigned size = *(const WORD*)(pFormat+2);
1345 TRACE("(%p,%p,%p,%d)\n", pStubMsg, ppMemory, pFormat, fMustAlloc);
1348 *ppMemory = NdrAllocate(pStubMsg, size);
1349 memcpy(*ppMemory, pStubMsg->Buffer, size);
1351 if (pStubMsg->ReuseBuffer && !*ppMemory)
1352 /* for servers, we may just point straight into the RPC buffer, I think
1353 * (I guess that's what MS does since MIDL code doesn't try to free) */
1354 *ppMemory = pStubMsg->Buffer;
1356 /* for clients, memory should be provided by caller */
1357 memcpy(*ppMemory, pStubMsg->Buffer, size);
1360 pStubMsg->BufferMark = pStubMsg->Buffer;
1361 pStubMsg->Buffer += size;
1363 if (pFormat[0] != RPC_FC_STRUCT)
1364 EmbeddedPointerUnmarshall(pStubMsg, ppMemory, pFormat+4, fMustAlloc);
1370 /***********************************************************************
1371 * NdrSimpleStructUnmarshall [RPCRT4.@]
1373 void WINAPI NdrSimpleTypeMarshall( PMIDL_STUB_MESSAGE pStubMsg, unsigned char* pMemory,
1374 unsigned char FormatChar )
1380 /***********************************************************************
1381 * NdrSimpleStructUnmarshall [RPCRT4.@]
1383 void WINAPI NdrSimpleTypeUnmarshall( PMIDL_STUB_MESSAGE pStubMsg, unsigned char* pMemory,
1384 unsigned char FormatChar )
1390 /***********************************************************************
1391 * NdrSimpleStructBufferSize [RPCRT4.@]
1393 void WINAPI NdrSimpleStructBufferSize(PMIDL_STUB_MESSAGE pStubMsg,
1394 unsigned char *pMemory,
1395 PFORMAT_STRING pFormat)
1397 unsigned size = *(const WORD*)(pFormat+2);
1398 TRACE("(%p,%p,%p)\n", pStubMsg, pMemory, pFormat);
1399 pStubMsg->BufferLength += size;
1400 if (pFormat[0] != RPC_FC_STRUCT)
1401 EmbeddedPointerBufferSize(pStubMsg, pMemory, pFormat+4);
1404 /***********************************************************************
1405 * NdrSimpleStructMemorySize [RPCRT4.@]
1407 unsigned long WINAPI NdrSimpleStructMemorySize(PMIDL_STUB_MESSAGE pStubMsg,
1408 PFORMAT_STRING pFormat)
1410 /* unsigned size = *(LPWORD)(pFormat+2); */
1411 FIXME("(%p,%p): stub\n", pStubMsg, pFormat);
1412 if (pFormat[0] != RPC_FC_STRUCT)
1413 EmbeddedPointerMemorySize(pStubMsg, pFormat+4);
1417 /***********************************************************************
1418 * NdrSimpleStructFree [RPCRT4.@]
1420 void WINAPI NdrSimpleStructFree(PMIDL_STUB_MESSAGE pStubMsg,
1421 unsigned char *pMemory,
1422 PFORMAT_STRING pFormat)
1424 TRACE("(%p,%p,%p)\n", pStubMsg, pMemory, pFormat);
1425 if (pFormat[0] != RPC_FC_STRUCT)
1426 EmbeddedPointerFree(pStubMsg, pMemory, pFormat+4);
1430 static long NonEncapsulatedUnionSize(PMIDL_STUB_MESSAGE pStubMsg,
1431 PFORMAT_STRING pFormat)
1434 if (pStubMsg->fHasNewCorrDesc)
1439 pFormat += *(const SHORT*)pFormat;
1440 TRACE("size %d\n", *(const SHORT*)pFormat);
1441 return *(const SHORT*)pFormat;
1444 unsigned long WINAPI EmbeddedComplexSize(PMIDL_STUB_MESSAGE pStubMsg,
1445 PFORMAT_STRING pFormat)
1449 case RPC_FC_PSTRUCT:
1450 case RPC_FC_CSTRUCT:
1451 case RPC_FC_BOGUS_STRUCT:
1452 return *(const WORD*)&pFormat[2];
1453 case RPC_FC_USER_MARSHAL:
1454 return *(const WORD*)&pFormat[4];
1455 case RPC_FC_NON_ENCAPSULATED_UNION:
1456 return NonEncapsulatedUnionSize(pStubMsg, pFormat);
1458 FIXME("unhandled embedded type %02x\n", *pFormat);
1464 unsigned char * WINAPI ComplexMarshall(PMIDL_STUB_MESSAGE pStubMsg,
1465 unsigned char *pMemory,
1466 PFORMAT_STRING pFormat,
1467 PFORMAT_STRING pPointer)
1469 PFORMAT_STRING desc;
1473 while (*pFormat != RPC_FC_END) {
1477 TRACE("short=%d <= %p\n", *(WORD*)pMemory, pMemory);
1478 memcpy(pStubMsg->Buffer, pMemory, 2);
1479 pStubMsg->Buffer += 2;
1485 TRACE("long=%ld <= %p\n", *(DWORD*)pMemory, pMemory);
1486 memcpy(pStubMsg->Buffer, pMemory, 4);
1487 pStubMsg->Buffer += 4;
1490 case RPC_FC_POINTER:
1491 TRACE("pointer=%p <= %p\n", *(unsigned char**)pMemory, pMemory);
1492 NdrPointerMarshall(pStubMsg, *(unsigned char**)pMemory, pPointer);
1496 case RPC_FC_ALIGNM4:
1497 ALIGN_POINTER(pMemory, 4);
1499 case RPC_FC_ALIGNM8:
1500 ALIGN_POINTER(pMemory, 8);
1502 case RPC_FC_STRUCTPAD2:
1505 case RPC_FC_EMBEDDED_COMPLEX:
1506 pMemory += pFormat[1];
1508 desc = pFormat + *(const SHORT*)pFormat;
1509 size = EmbeddedComplexSize(pStubMsg, desc);
1510 TRACE("embedded complex (size=%ld) <= %p\n", size, pMemory);
1511 m = NdrMarshaller[*desc & NDR_TABLE_MASK];
1512 if (m) m(pStubMsg, pMemory, desc);
1513 else FIXME("no marshaller for embedded type %02x\n", *desc);
1520 FIXME("unhandled format %02x\n", *pFormat);
1528 unsigned char * WINAPI ComplexUnmarshall(PMIDL_STUB_MESSAGE pStubMsg,
1529 unsigned char *pMemory,
1530 PFORMAT_STRING pFormat,
1531 PFORMAT_STRING pPointer,
1532 unsigned char fMustAlloc)
1534 PFORMAT_STRING desc;
1538 while (*pFormat != RPC_FC_END) {
1542 memcpy(pMemory, pStubMsg->Buffer, 2);
1543 TRACE("short=%d => %p\n", *(WORD*)pMemory, pMemory);
1544 pStubMsg->Buffer += 2;
1550 memcpy(pMemory, pStubMsg->Buffer, 4);
1551 TRACE("long=%ld => %p\n", *(DWORD*)pMemory, pMemory);
1552 pStubMsg->Buffer += 4;
1555 case RPC_FC_POINTER:
1556 *(unsigned char**)pMemory = NULL;
1557 TRACE("pointer => %p\n", pMemory);
1558 NdrPointerUnmarshall(pStubMsg, (unsigned char**)pMemory, pPointer, fMustAlloc);
1562 case RPC_FC_ALIGNM4:
1563 ALIGN_POINTER(pMemory, 4);
1565 case RPC_FC_ALIGNM8:
1566 ALIGN_POINTER(pMemory, 8);
1568 case RPC_FC_STRUCTPAD2:
1571 case RPC_FC_EMBEDDED_COMPLEX:
1572 pMemory += pFormat[1];
1574 desc = pFormat + *(const SHORT*)pFormat;
1575 size = EmbeddedComplexSize(pStubMsg, desc);
1576 TRACE("embedded complex (size=%ld) => %p\n", size, pMemory);
1577 m = NdrUnmarshaller[*desc & NDR_TABLE_MASK];
1578 memset(pMemory, 0, size); /* just in case */
1579 if (m) m(pStubMsg, &pMemory, desc, fMustAlloc);
1580 else FIXME("no unmarshaller for embedded type %02x\n", *desc);
1587 FIXME("unhandled format %d\n", *pFormat);
1595 unsigned char * WINAPI ComplexBufferSize(PMIDL_STUB_MESSAGE pStubMsg,
1596 unsigned char *pMemory,
1597 PFORMAT_STRING pFormat,
1598 PFORMAT_STRING pPointer)
1600 PFORMAT_STRING desc;
1604 while (*pFormat != RPC_FC_END) {
1608 pStubMsg->BufferLength += 2;
1614 pStubMsg->BufferLength += 4;
1617 case RPC_FC_POINTER:
1618 NdrPointerBufferSize(pStubMsg, *(unsigned char**)pMemory, pPointer);
1622 case RPC_FC_ALIGNM4:
1623 ALIGN_POINTER(pMemory, 4);
1625 case RPC_FC_ALIGNM8:
1626 ALIGN_POINTER(pMemory, 8);
1628 case RPC_FC_STRUCTPAD2:
1631 case RPC_FC_EMBEDDED_COMPLEX:
1632 pMemory += pFormat[1];
1634 desc = pFormat + *(const SHORT*)pFormat;
1635 size = EmbeddedComplexSize(pStubMsg, desc);
1636 m = NdrBufferSizer[*desc & NDR_TABLE_MASK];
1637 if (m) m(pStubMsg, pMemory, desc);
1638 else FIXME("no buffersizer for embedded type %02x\n", *desc);
1645 FIXME("unhandled format %d\n", *pFormat);
1653 unsigned char * WINAPI ComplexFree(PMIDL_STUB_MESSAGE pStubMsg,
1654 unsigned char *pMemory,
1655 PFORMAT_STRING pFormat,
1656 PFORMAT_STRING pPointer)
1658 PFORMAT_STRING desc;
1662 while (*pFormat != RPC_FC_END) {
1673 case RPC_FC_POINTER:
1674 NdrPointerFree(pStubMsg, *(unsigned char**)pMemory, pPointer);
1678 case RPC_FC_ALIGNM4:
1679 ALIGN_POINTER(pMemory, 4);
1681 case RPC_FC_ALIGNM8:
1682 ALIGN_POINTER(pMemory, 8);
1684 case RPC_FC_STRUCTPAD2:
1687 case RPC_FC_EMBEDDED_COMPLEX:
1688 pMemory += pFormat[1];
1690 desc = pFormat + *(const SHORT*)pFormat;
1691 size = EmbeddedComplexSize(pStubMsg, desc);
1692 m = NdrFreer[*desc & NDR_TABLE_MASK];
1693 if (m) m(pStubMsg, pMemory, desc);
1694 else FIXME("no freer for embedded type %02x\n", *desc);
1701 FIXME("unhandled format %d\n", *pFormat);
1709 unsigned long WINAPI ComplexStructSize(PMIDL_STUB_MESSAGE pStubMsg,
1710 PFORMAT_STRING pFormat)
1712 PFORMAT_STRING desc;
1713 unsigned long size = 0;
1715 while (*pFormat != RPC_FC_END) {
1725 case RPC_FC_POINTER:
1728 case RPC_FC_ALIGNM4:
1729 ALIGN_LENGTH(size, 4);
1731 case RPC_FC_ALIGNM8:
1732 ALIGN_LENGTH(size, 8);
1734 case RPC_FC_STRUCTPAD2:
1737 case RPC_FC_EMBEDDED_COMPLEX:
1740 desc = pFormat + *(const SHORT*)pFormat;
1741 size += EmbeddedComplexSize(pStubMsg, desc);
1747 FIXME("unhandled format %d\n", *pFormat);
1755 /***********************************************************************
1756 * NdrComplexStructMarshall [RPCRT4.@]
1758 unsigned char * WINAPI NdrComplexStructMarshall(PMIDL_STUB_MESSAGE pStubMsg,
1759 unsigned char *pMemory,
1760 PFORMAT_STRING pFormat)
1762 PFORMAT_STRING conf_array = NULL;
1763 PFORMAT_STRING pointer_desc = NULL;
1764 unsigned char *OldMemory = pStubMsg->Memory;
1766 TRACE("(%p,%p,%p)\n", pStubMsg, pMemory, pFormat);
1769 if (*(const WORD*)pFormat) conf_array = pFormat + *(const WORD*)pFormat;
1771 if (*(const WORD*)pFormat) pointer_desc = pFormat + *(const WORD*)pFormat;
1774 pStubMsg->Memory = pMemory;
1776 ComplexMarshall(pStubMsg, pMemory, pFormat, pointer_desc);
1779 NdrConformantArrayMarshall(pStubMsg, pMemory, conf_array);
1781 pStubMsg->Memory = OldMemory;
1783 STD_OVERFLOW_CHECK(pStubMsg);
1788 /***********************************************************************
1789 * NdrComplexStructUnmarshall [RPCRT4.@]
1791 unsigned char * WINAPI NdrComplexStructUnmarshall(PMIDL_STUB_MESSAGE pStubMsg,
1792 unsigned char **ppMemory,
1793 PFORMAT_STRING pFormat,
1794 unsigned char fMustAlloc)
1796 unsigned size = *(const WORD*)(pFormat+2);
1797 PFORMAT_STRING conf_array = NULL;
1798 PFORMAT_STRING pointer_desc = NULL;
1799 unsigned char *pMemory;
1801 TRACE("(%p,%p,%p,%d)\n", pStubMsg, ppMemory, pFormat, fMustAlloc);
1803 if (fMustAlloc || !*ppMemory)
1805 *ppMemory = NdrAllocate(pStubMsg, size);
1806 memset(*ppMemory, 0, size);
1810 if (*(const WORD*)pFormat) conf_array = pFormat + *(const WORD*)pFormat;
1812 if (*(const WORD*)pFormat) pointer_desc = pFormat + *(const WORD*)pFormat;
1815 pMemory = ComplexUnmarshall(pStubMsg, *ppMemory, pFormat, pointer_desc, fMustAlloc);
1818 NdrConformantArrayUnmarshall(pStubMsg, &pMemory, conf_array, fMustAlloc);
1823 /***********************************************************************
1824 * NdrComplexStructBufferSize [RPCRT4.@]
1826 void WINAPI NdrComplexStructBufferSize(PMIDL_STUB_MESSAGE pStubMsg,
1827 unsigned char *pMemory,
1828 PFORMAT_STRING pFormat)
1830 PFORMAT_STRING conf_array = NULL;
1831 PFORMAT_STRING pointer_desc = NULL;
1832 unsigned char *OldMemory = pStubMsg->Memory;
1834 TRACE("(%p,%p,%p)\n", pStubMsg, pMemory, pFormat);
1837 if (*(const WORD*)pFormat) conf_array = pFormat + *(const WORD*)pFormat;
1839 if (*(const WORD*)pFormat) pointer_desc = pFormat + *(const WORD*)pFormat;
1842 pStubMsg->Memory = pMemory;
1844 pMemory = ComplexBufferSize(pStubMsg, pMemory, pFormat, pointer_desc);
1847 NdrConformantArrayBufferSize(pStubMsg, pMemory, conf_array);
1849 pStubMsg->Memory = OldMemory;
1852 /***********************************************************************
1853 * NdrComplexStructMemorySize [RPCRT4.@]
1855 unsigned long WINAPI NdrComplexStructMemorySize(PMIDL_STUB_MESSAGE pStubMsg,
1856 PFORMAT_STRING pFormat)
1858 /* unsigned size = *(LPWORD)(pFormat+2); */
1859 PFORMAT_STRING conf_array = NULL;
1860 PFORMAT_STRING pointer_desc = NULL;
1862 FIXME("(%p,%p): stub\n", pStubMsg, pFormat);
1865 if (*(const WORD*)pFormat) conf_array = pFormat + *(const WORD*)pFormat;
1867 if (*(const WORD*)pFormat) pointer_desc = pFormat + *(const WORD*)pFormat;
1873 /***********************************************************************
1874 * NdrComplexStructFree [RPCRT4.@]
1876 void WINAPI NdrComplexStructFree(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);
1887 if (*(const WORD*)pFormat) conf_array = pFormat + *(const WORD*)pFormat;
1889 if (*(const WORD*)pFormat) pointer_desc = pFormat + *(const WORD*)pFormat;
1892 pStubMsg->Memory = pMemory;
1894 pMemory = ComplexFree(pStubMsg, pMemory, pFormat, pointer_desc);
1897 NdrConformantArrayFree(pStubMsg, pMemory, conf_array);
1899 pStubMsg->Memory = OldMemory;
1902 /***********************************************************************
1903 * NdrConformantArrayMarshall [RPCRT4.@]
1905 unsigned char * WINAPI NdrConformantArrayMarshall(PMIDL_STUB_MESSAGE pStubMsg,
1906 unsigned char *pMemory,
1907 PFORMAT_STRING pFormat)
1909 DWORD size = 0, esize = *(const WORD*)(pFormat+2);
1910 TRACE("(%p,%p,%p)\n", pStubMsg, pMemory, pFormat);
1911 if (pFormat[0] != RPC_FC_CARRAY) FIXME("format=%d\n", pFormat[0]);
1913 pFormat = ComputeConformance(pStubMsg, pMemory, pFormat+4, 0);
1914 size = pStubMsg->MaxCount;
1916 NDR_LOCAL_UINT32_WRITE(pStubMsg->Buffer, size);
1917 pStubMsg->Buffer += 4;
1919 memcpy(pStubMsg->Buffer, pMemory, size*esize);
1920 pStubMsg->BufferMark = pStubMsg->Buffer;
1921 pStubMsg->Buffer += size*esize;
1923 EmbeddedPointerMarshall(pStubMsg, pMemory, pFormat);
1925 STD_OVERFLOW_CHECK(pStubMsg);
1930 /***********************************************************************
1931 * NdrConformantArrayUnmarshall [RPCRT4.@]
1933 unsigned char * WINAPI NdrConformantArrayUnmarshall(PMIDL_STUB_MESSAGE pStubMsg,
1934 unsigned char **ppMemory,
1935 PFORMAT_STRING pFormat,
1936 unsigned char fMustAlloc)
1938 DWORD size = 0, esize = *(const WORD*)(pFormat+2);
1939 TRACE("(%p,%p,%p,%d)\n", pStubMsg, ppMemory, pFormat, fMustAlloc);
1940 if (pFormat[0] != RPC_FC_CARRAY) FIXME("format=%d\n", pFormat[0]);
1942 pFormat = ReadConformance(pStubMsg, pFormat+4);
1943 size = pStubMsg->MaxCount;
1945 if (fMustAlloc || !*ppMemory)
1946 *ppMemory = NdrAllocate(pStubMsg, size*esize);
1948 memcpy(*ppMemory, pStubMsg->Buffer, size*esize);
1950 pStubMsg->BufferMark = pStubMsg->Buffer;
1951 pStubMsg->Buffer += size*esize;
1953 EmbeddedPointerUnmarshall(pStubMsg, ppMemory, pFormat, fMustAlloc);
1958 /***********************************************************************
1959 * NdrConformantArrayBufferSize [RPCRT4.@]
1961 void WINAPI NdrConformantArrayBufferSize(PMIDL_STUB_MESSAGE pStubMsg,
1962 unsigned char *pMemory,
1963 PFORMAT_STRING pFormat)
1965 DWORD size = 0, esize = *(const WORD*)(pFormat+2);
1966 TRACE("(%p,%p,%p)\n", pStubMsg, pMemory, pFormat);
1967 if (pFormat[0] != RPC_FC_CARRAY) FIXME("format=%d\n", pFormat[0]);
1969 pFormat = ComputeConformance(pStubMsg, pMemory, pFormat+4, 0);
1970 size = pStubMsg->MaxCount;
1972 /* conformance value plus array */
1973 pStubMsg->BufferLength += sizeof(DWORD) + size*esize;
1975 EmbeddedPointerBufferSize(pStubMsg, pMemory, pFormat);
1978 /***********************************************************************
1979 * NdrConformantArrayMemorySize [RPCRT4.@]
1981 unsigned long WINAPI NdrConformantArrayMemorySize(PMIDL_STUB_MESSAGE pStubMsg,
1982 PFORMAT_STRING pFormat)
1984 DWORD size = 0, esize = *(const WORD*)(pFormat+2);
1985 unsigned char *buffer;
1987 TRACE("(%p,%p)\n", pStubMsg, pFormat);
1988 if (pFormat[0] != RPC_FC_CARRAY) FIXME("format=%d\n", pFormat[0]);
1990 buffer = pStubMsg->Buffer;
1991 pFormat = ReadConformance(pStubMsg, pFormat+4);
1992 pStubMsg->Buffer = buffer;
1993 size = pStubMsg->MaxCount;
1998 /***********************************************************************
1999 * NdrConformantArrayFree [RPCRT4.@]
2001 void WINAPI NdrConformantArrayFree(PMIDL_STUB_MESSAGE pStubMsg,
2002 unsigned char *pMemory,
2003 PFORMAT_STRING pFormat)
2005 TRACE("(%p,%p,%p)\n", pStubMsg, pMemory, pFormat);
2006 if (pFormat[0] != RPC_FC_CARRAY) FIXME("format=%d\n", pFormat[0]);
2008 EmbeddedPointerFree(pStubMsg, pMemory, pFormat);
2012 /***********************************************************************
2013 * NdrConformantVaryingArrayMarshall [RPCRT4.@]
2015 unsigned char* WINAPI NdrConformantVaryingArrayMarshall( PMIDL_STUB_MESSAGE pStubMsg,
2016 unsigned char* pMemory,
2017 PFORMAT_STRING pFormat )
2019 DWORD esize = *(const WORD*)(pFormat+2);
2021 TRACE("(%p, %p, %p)\n", pStubMsg, pMemory, pFormat);
2023 if (pFormat[0] != RPC_FC_CVARRAY)
2025 ERR("invalid format type %x\n", pFormat[0]);
2026 RpcRaiseException(RPC_S_INTERNAL_ERROR);
2030 pFormat = ComputeConformance(pStubMsg, pMemory, pFormat+4, 0);
2031 pFormat = ComputeVariance(pStubMsg, pMemory, pFormat, 0);
2033 NDR_LOCAL_UINT32_WRITE(pStubMsg->Buffer, pStubMsg->MaxCount);
2034 pStubMsg->Buffer += 4;
2035 NDR_LOCAL_UINT32_WRITE(pStubMsg->Buffer, pStubMsg->Offset);
2036 pStubMsg->Buffer += 4;
2037 NDR_LOCAL_UINT32_WRITE(pStubMsg->Buffer, pStubMsg->ActualCount);
2038 pStubMsg->Buffer += 4;
2040 memcpy(pStubMsg->Buffer, pMemory + pStubMsg->Offset, pStubMsg->ActualCount*esize);
2041 pStubMsg->BufferMark = pStubMsg->Buffer;
2042 pStubMsg->Buffer += pStubMsg->ActualCount*esize;
2044 EmbeddedPointerMarshall(pStubMsg, pMemory, pFormat);
2046 STD_OVERFLOW_CHECK(pStubMsg);
2052 /***********************************************************************
2053 * NdrConformantVaryingArrayUnmarshall [RPCRT4.@]
2055 unsigned char* WINAPI NdrConformantVaryingArrayUnmarshall( PMIDL_STUB_MESSAGE pStubMsg,
2056 unsigned char** ppMemory,
2057 PFORMAT_STRING pFormat,
2058 unsigned char fMustAlloc )
2060 DWORD esize = *(const WORD*)(pFormat+2);
2062 TRACE("(%p, %p, %p, %d)\n", pStubMsg, ppMemory, pFormat, fMustAlloc);
2064 if (pFormat[0] != RPC_FC_CVARRAY)
2066 ERR("invalid format type %x\n", pFormat[0]);
2067 RpcRaiseException(RPC_S_INTERNAL_ERROR);
2070 pFormat = ReadConformance(pStubMsg, pFormat);
2071 pFormat = ReadVariance(pStubMsg, pFormat);
2073 if (!*ppMemory || fMustAlloc)
2074 *ppMemory = NdrAllocate(pStubMsg, pStubMsg->MaxCount * esize);
2075 memcpy(*ppMemory + pStubMsg->Offset, pStubMsg->Buffer, pStubMsg->ActualCount * esize);
2076 pStubMsg->Buffer += pStubMsg->ActualCount * esize;
2078 EmbeddedPointerUnmarshall(pStubMsg, ppMemory, pFormat, fMustAlloc);
2084 /***********************************************************************
2085 * NdrConformantVaryingArrayFree [RPCRT4.@]
2087 void WINAPI NdrConformantVaryingArrayFree( PMIDL_STUB_MESSAGE pStubMsg,
2088 unsigned char* pMemory,
2089 PFORMAT_STRING pFormat )
2091 TRACE("(%p,%p,%p)\n", pStubMsg, pMemory, pFormat);
2093 if (pFormat[0] != RPC_FC_CVARRAY)
2095 ERR("invalid format type %x\n", pFormat[0]);
2096 RpcRaiseException(RPC_S_INTERNAL_ERROR);
2100 pFormat = ComputeConformance(pStubMsg, pMemory, pFormat+4, 0);
2101 pFormat = ComputeVariance(pStubMsg, pMemory, pFormat, 0);
2103 EmbeddedPointerFree(pStubMsg, pMemory, pFormat);
2107 /***********************************************************************
2108 * NdrConformantVaryingArrayBufferSize [RPCRT4.@]
2110 void WINAPI NdrConformantVaryingArrayBufferSize( PMIDL_STUB_MESSAGE pStubMsg,
2111 unsigned char* pMemory, PFORMAT_STRING pFormat )
2113 DWORD esize = *(const WORD*)(pFormat+2);
2115 TRACE("(%p, %p, %p)\n", pStubMsg, pMemory, pFormat);
2117 if (pFormat[0] != RPC_FC_CVARRAY)
2119 ERR("invalid format type %x\n", pFormat[0]);
2120 RpcRaiseException(RPC_S_INTERNAL_ERROR);
2125 pFormat = ComputeConformance(pStubMsg, pMemory, pFormat+4, 0);
2126 /* compute length */
2127 pFormat = ComputeVariance(pStubMsg, pMemory, pFormat, 0);
2129 /* conformance + offset + variance + array */
2130 pStubMsg->BufferLength += 3*sizeof(DWORD) + pStubMsg->ActualCount*esize;
2132 EmbeddedPointerBufferSize(pStubMsg, pMemory, pFormat);
2136 /***********************************************************************
2137 * NdrConformantVaryingArrayMemorySize [RPCRT4.@]
2139 unsigned long WINAPI NdrConformantVaryingArrayMemorySize( PMIDL_STUB_MESSAGE pStubMsg,
2140 PFORMAT_STRING pFormat )
2147 /***********************************************************************
2148 * NdrComplexArrayMarshall [RPCRT4.@]
2150 unsigned char * WINAPI NdrComplexArrayMarshall(PMIDL_STUB_MESSAGE pStubMsg,
2151 unsigned char *pMemory,
2152 PFORMAT_STRING pFormat)
2155 BOOL variance_present;
2157 TRACE("(%p,%p,%p)\n", pStubMsg, pMemory, pFormat);
2159 if (pFormat[0] != RPC_FC_BOGUS_ARRAY)
2161 ERR("invalid format type %x\n", pFormat[0]);
2162 RpcRaiseException(RPC_S_INTERNAL_ERROR);
2166 def = *(const WORD*)&pFormat[2];
2169 pFormat = ComputeConformance(pStubMsg, pMemory, pFormat, def);
2170 TRACE("conformance = %ld\n", pStubMsg->MaxCount);
2172 variance_present = IsConformanceOrVariancePresent(pFormat);
2173 pFormat = ComputeVariance(pStubMsg, pMemory, pFormat, pStubMsg->MaxCount);
2174 TRACE("variance = %ld\n", pStubMsg->ActualCount);
2176 NDR_LOCAL_UINT32_WRITE(pStubMsg->Buffer, pStubMsg->MaxCount);
2177 pStubMsg->Buffer += 4;
2178 if (variance_present)
2180 NDR_LOCAL_UINT32_WRITE(pStubMsg->Buffer, pStubMsg->Offset);
2181 pStubMsg->Buffer += 4;
2182 NDR_LOCAL_UINT32_WRITE(pStubMsg->Buffer, pStubMsg->ActualCount);
2183 pStubMsg->Buffer += 4;
2186 for (count = 0; count < pStubMsg->ActualCount; count++)
2187 pMemory = ComplexMarshall(pStubMsg, pMemory, pFormat, NULL);
2189 STD_OVERFLOW_CHECK(pStubMsg);
2194 /***********************************************************************
2195 * NdrComplexArrayUnmarshall [RPCRT4.@]
2197 unsigned char * WINAPI NdrComplexArrayUnmarshall(PMIDL_STUB_MESSAGE pStubMsg,
2198 unsigned char **ppMemory,
2199 PFORMAT_STRING pFormat,
2200 unsigned char fMustAlloc)
2203 unsigned char *pMemory;
2205 TRACE("(%p,%p,%p,%d)\n", pStubMsg, ppMemory, pFormat, fMustAlloc);
2207 if (pFormat[0] != RPC_FC_BOGUS_ARRAY)
2209 ERR("invalid format type %x\n", pFormat[0]);
2210 RpcRaiseException(RPC_S_INTERNAL_ERROR);
2216 pFormat = ReadConformance(pStubMsg, pFormat);
2217 pFormat = ReadVariance(pStubMsg, pFormat);
2219 esize = ComplexStructSize(pStubMsg, pFormat);
2221 if (fMustAlloc || !*ppMemory)
2223 *ppMemory = NdrAllocate(pStubMsg, pStubMsg->MaxCount * esize);
2224 memset(*ppMemory, 0, pStubMsg->MaxCount * esize);
2227 pMemory = *ppMemory;
2228 for (count = 0; count < pStubMsg->ActualCount; count++)
2229 pMemory = ComplexUnmarshall(pStubMsg, pMemory, pFormat, NULL, fMustAlloc);
2234 /***********************************************************************
2235 * NdrComplexArrayBufferSize [RPCRT4.@]
2237 void WINAPI NdrComplexArrayBufferSize(PMIDL_STUB_MESSAGE pStubMsg,
2238 unsigned char *pMemory,
2239 PFORMAT_STRING pFormat)
2242 BOOL variance_present;
2244 TRACE("(%p,%p,%p)\n", pStubMsg, pMemory, pFormat);
2246 if (pFormat[0] != RPC_FC_BOGUS_ARRAY)
2248 ERR("invalid format type %x\n", pFormat[0]);
2249 RpcRaiseException(RPC_S_INTERNAL_ERROR);
2253 def = *(const WORD*)&pFormat[2];
2256 pFormat = ComputeConformance(pStubMsg, pMemory, pFormat, def);
2257 TRACE("conformance = %ld\n", pStubMsg->MaxCount);
2258 pStubMsg->BufferLength += sizeof(ULONG);
2260 variance_present = IsConformanceOrVariancePresent(pFormat);
2261 pFormat = ComputeVariance(pStubMsg, pMemory, pFormat, pStubMsg->MaxCount);
2262 TRACE("variance = %ld\n", pStubMsg->ActualCount);
2264 if (variance_present)
2265 pStubMsg->BufferLength += 2*sizeof(ULONG);
2267 for (count=0; count < pStubMsg->ActualCount; count++)
2268 pMemory = ComplexBufferSize(pStubMsg, pMemory, pFormat, NULL);
2271 /***********************************************************************
2272 * NdrComplexArrayMemorySize [RPCRT4.@]
2274 unsigned long WINAPI NdrComplexArrayMemorySize(PMIDL_STUB_MESSAGE pStubMsg,
2275 PFORMAT_STRING pFormat)
2278 FIXME("(%p,%p): stub\n", pStubMsg, pFormat);
2280 if (pFormat[0] != RPC_FC_BOGUS_ARRAY)
2282 ERR("invalid format type %x\n", pFormat[0]);
2283 RpcRaiseException(RPC_S_INTERNAL_ERROR);
2289 pFormat = ReadConformance(pStubMsg, pFormat);
2290 size = pStubMsg->MaxCount;
2291 TRACE("conformance=%ld\n", size);
2298 /***********************************************************************
2299 * NdrComplexArrayFree [RPCRT4.@]
2301 void WINAPI NdrComplexArrayFree(PMIDL_STUB_MESSAGE pStubMsg,
2302 unsigned char *pMemory,
2303 PFORMAT_STRING pFormat)
2307 TRACE("(%p,%p,%p)\n", pStubMsg, pMemory, pFormat);
2309 if (pFormat[0] != RPC_FC_BOGUS_ARRAY)
2311 ERR("invalid format type %x\n", pFormat[0]);
2312 RpcRaiseException(RPC_S_INTERNAL_ERROR);
2316 def = *(const WORD*)&pFormat[2];
2319 pFormat = ComputeConformance(pStubMsg, pMemory, pFormat, def);
2320 TRACE("conformance = %ld\n", pStubMsg->MaxCount);
2322 pFormat = ComputeVariance(pStubMsg, pMemory, pFormat, pStubMsg->MaxCount);
2323 TRACE("variance = %ld\n", pStubMsg->ActualCount);
2325 for (count=0; count < pStubMsg->ActualCount; count++)
2326 pMemory = ComplexFree(pStubMsg, pMemory, pFormat, NULL);
2329 unsigned long UserMarshalFlags(PMIDL_STUB_MESSAGE pStubMsg)
2331 return MAKELONG(pStubMsg->dwDestContext,
2332 pStubMsg->RpcMsg->DataRepresentation);
2335 /***********************************************************************
2336 * NdrUserMarshalMarshall [RPCRT4.@]
2338 unsigned char * WINAPI NdrUserMarshalMarshall(PMIDL_STUB_MESSAGE pStubMsg,
2339 unsigned char *pMemory,
2340 PFORMAT_STRING pFormat)
2342 /* unsigned flags = pFormat[1]; */
2343 unsigned index = *(const WORD*)&pFormat[2];
2344 unsigned long uflag = UserMarshalFlags(pStubMsg);
2345 TRACE("(%p,%p,%p)\n", pStubMsg, pMemory, pFormat);
2346 TRACE("index=%d\n", index);
2349 pStubMsg->StubDesc->aUserMarshalQuadruple[index].pfnMarshall(
2350 &uflag, pStubMsg->Buffer, pMemory);
2352 STD_OVERFLOW_CHECK(pStubMsg);
2357 /***********************************************************************
2358 * NdrUserMarshalUnmarshall [RPCRT4.@]
2360 unsigned char * WINAPI NdrUserMarshalUnmarshall(PMIDL_STUB_MESSAGE pStubMsg,
2361 unsigned char **ppMemory,
2362 PFORMAT_STRING pFormat,
2363 unsigned char fMustAlloc)
2365 /* unsigned flags = pFormat[1];*/
2366 unsigned index = *(const WORD*)&pFormat[2];
2367 DWORD memsize = *(const WORD*)&pFormat[4];
2368 unsigned long uflag = UserMarshalFlags(pStubMsg);
2369 TRACE("(%p,%p,%p,%d)\n", pStubMsg, ppMemory, pFormat, fMustAlloc);
2370 TRACE("index=%d\n", index);
2372 if (fMustAlloc || !*ppMemory)
2373 *ppMemory = NdrAllocate(pStubMsg, memsize);
2376 pStubMsg->StubDesc->aUserMarshalQuadruple[index].pfnUnmarshall(
2377 &uflag, pStubMsg->Buffer, *ppMemory);
2382 /***********************************************************************
2383 * NdrUserMarshalBufferSize [RPCRT4.@]
2385 void WINAPI NdrUserMarshalBufferSize(PMIDL_STUB_MESSAGE pStubMsg,
2386 unsigned char *pMemory,
2387 PFORMAT_STRING pFormat)
2389 /* unsigned flags = pFormat[1];*/
2390 unsigned index = *(const WORD*)&pFormat[2];
2391 DWORD bufsize = *(const WORD*)&pFormat[6];
2392 unsigned long uflag = UserMarshalFlags(pStubMsg);
2393 TRACE("(%p,%p,%p)\n", pStubMsg, pMemory, pFormat);
2394 TRACE("index=%d\n", index);
2397 TRACE("size=%ld\n", bufsize);
2398 pStubMsg->BufferLength += bufsize;
2402 pStubMsg->BufferLength =
2403 pStubMsg->StubDesc->aUserMarshalQuadruple[index].pfnBufferSize(
2404 &uflag, pStubMsg->BufferLength, pMemory);
2407 /***********************************************************************
2408 * NdrUserMarshalMemorySize [RPCRT4.@]
2410 unsigned long WINAPI NdrUserMarshalMemorySize(PMIDL_STUB_MESSAGE pStubMsg,
2411 PFORMAT_STRING pFormat)
2413 unsigned index = *(const WORD*)&pFormat[2];
2414 /* DWORD memsize = *(const WORD*)&pFormat[4]; */
2415 FIXME("(%p,%p): stub\n", pStubMsg, pFormat);
2416 TRACE("index=%d\n", index);
2421 /***********************************************************************
2422 * NdrUserMarshalFree [RPCRT4.@]
2424 void WINAPI NdrUserMarshalFree(PMIDL_STUB_MESSAGE pStubMsg,
2425 unsigned char *pMemory,
2426 PFORMAT_STRING pFormat)
2428 /* unsigned flags = pFormat[1]; */
2429 unsigned index = *(const WORD*)&pFormat[2];
2430 unsigned long uflag = UserMarshalFlags(pStubMsg);
2431 TRACE("(%p,%p,%p)\n", pStubMsg, pMemory, pFormat);
2432 TRACE("index=%d\n", index);
2434 pStubMsg->StubDesc->aUserMarshalQuadruple[index].pfnFree(
2438 /***********************************************************************
2439 * NdrClearOutParameters [RPCRT4.@]
2441 void WINAPI NdrClearOutParameters(PMIDL_STUB_MESSAGE pStubMsg,
2442 PFORMAT_STRING pFormat,
2445 FIXME("(%p,%p,%p): stub\n", pStubMsg, pFormat, ArgAddr);
2448 /***********************************************************************
2449 * NdrConvert [RPCRT4.@]
2451 void WINAPI NdrConvert( PMIDL_STUB_MESSAGE pStubMsg, PFORMAT_STRING pFormat )
2453 FIXME("(pStubMsg == ^%p, pFormat == ^%p): stub.\n", pStubMsg, pFormat);
2454 /* FIXME: since this stub doesn't do any converting, the proper behavior
2455 is to raise an exception */
2458 /***********************************************************************
2459 * NdrConvert2 [RPCRT4.@]
2461 void WINAPI NdrConvert2( PMIDL_STUB_MESSAGE pStubMsg, PFORMAT_STRING pFormat, long NumberParams )
2463 FIXME("(pStubMsg == ^%p, pFormat == ^%p, NumberParams == %ld): stub.\n",
2464 pStubMsg, pFormat, NumberParams);
2465 /* FIXME: since this stub doesn't do any converting, the proper behavior
2466 is to raise an exception */
2469 typedef struct _NDR_CSTRUCT_FORMAT
2472 unsigned char alignment;
2473 unsigned short memory_size;
2474 short offset_to_array_description;
2475 } NDR_CSTRUCT_FORMAT;
2477 /***********************************************************************
2478 * NdrConformantStructMarshall [RPCRT4.@]
2480 unsigned char * WINAPI NdrConformantStructMarshall(PMIDL_STUB_MESSAGE pStubMsg,
2481 unsigned char *pMemory,
2482 PFORMAT_STRING pFormat)
2484 const NDR_CSTRUCT_FORMAT * pCStructFormat = (NDR_CSTRUCT_FORMAT*)pFormat;
2485 pFormat += sizeof(NDR_CSTRUCT_FORMAT);
2487 TRACE("(%p, %p, %p)\n", pStubMsg, pMemory, pFormat);
2489 if ((pCStructFormat->type != RPC_FC_CPSTRUCT) && (pCStructFormat->type != RPC_FC_CSTRUCT))
2491 ERR("invalid format type %x\n", pCStructFormat->type);
2492 RpcRaiseException(RPC_S_INTERNAL_ERROR);
2496 TRACE("memory_size = %d\n", pCStructFormat->memory_size);
2498 /* copy constant sized part of struct */
2499 memcpy(pStubMsg->Buffer, pMemory, pCStructFormat->memory_size);
2500 pStubMsg->Buffer += pCStructFormat->memory_size;
2502 if (pCStructFormat->offset_to_array_description)
2504 PFORMAT_STRING pArrayFormat = (unsigned char*)&pCStructFormat->offset_to_array_description +
2505 pCStructFormat->offset_to_array_description;
2506 NdrConformantArrayMarshall(pStubMsg, pMemory + pCStructFormat->memory_size, pArrayFormat);
2508 if (pCStructFormat->type == RPC_FC_CPSTRUCT)
2509 EmbeddedPointerMarshall(pStubMsg, pMemory, pFormat);
2513 /***********************************************************************
2514 * NdrConformantStructUnmarshall [RPCRT4.@]
2516 unsigned char * WINAPI NdrConformantStructUnmarshall(PMIDL_STUB_MESSAGE pStubMsg,
2517 unsigned char **ppMemory,
2518 PFORMAT_STRING pFormat,
2519 unsigned char fMustAlloc)
2521 const NDR_CSTRUCT_FORMAT * pCStructFormat = (NDR_CSTRUCT_FORMAT*)pFormat;
2522 pFormat += sizeof(NDR_CSTRUCT_FORMAT);
2524 TRACE("(%p, %p, %p, %d)\n", pStubMsg, ppMemory, pFormat, fMustAlloc);
2526 if ((pCStructFormat->type != RPC_FC_CPSTRUCT) && (pCStructFormat->type != RPC_FC_CSTRUCT))
2528 ERR("invalid format type %x\n", pCStructFormat->type);
2529 RpcRaiseException(RPC_S_INTERNAL_ERROR);
2533 TRACE("memory_size = %d\n", pCStructFormat->memory_size);
2535 /* work out how much memory to allocate if we need to do so */
2536 if (!*ppMemory || fMustAlloc)
2538 SIZE_T size = pCStructFormat->memory_size;
2540 if (pCStructFormat->offset_to_array_description)
2542 unsigned char *buffer;
2543 PFORMAT_STRING pArrayFormat = (unsigned char*)&pCStructFormat->offset_to_array_description +
2544 pCStructFormat->offset_to_array_description;
2545 buffer = pStubMsg->Buffer;
2546 pStubMsg->Buffer += pCStructFormat->memory_size;
2547 size += NdrConformantArrayMemorySize(pStubMsg, pArrayFormat);
2548 pStubMsg->Buffer = buffer;
2550 *ppMemory = NdrAllocate(pStubMsg, size);
2553 /* now copy the data */
2554 memcpy(*ppMemory, pStubMsg->Buffer, pCStructFormat->memory_size);
2555 pStubMsg->Buffer += pCStructFormat->memory_size;
2556 if (pCStructFormat->offset_to_array_description)
2558 PFORMAT_STRING pArrayFormat = (unsigned char*)&pCStructFormat->offset_to_array_description +
2559 pCStructFormat->offset_to_array_description;
2560 unsigned char *pMemoryArray = *ppMemory + pCStructFormat->memory_size;
2561 /* note that we pass fMustAlloc as 0 as we have already allocated the
2563 NdrConformantArrayUnmarshall(pStubMsg, &pMemoryArray, pArrayFormat, 0);
2565 if (pCStructFormat->type == RPC_FC_CPSTRUCT)
2566 EmbeddedPointerUnmarshall(pStubMsg, ppMemory, pFormat, fMustAlloc);
2570 /***********************************************************************
2571 * NdrConformantStructBufferSize [RPCRT4.@]
2573 void WINAPI NdrConformantStructBufferSize(PMIDL_STUB_MESSAGE pStubMsg,
2574 unsigned char *pMemory,
2575 PFORMAT_STRING pFormat)
2577 const NDR_CSTRUCT_FORMAT * pCStructFormat = (NDR_CSTRUCT_FORMAT*)pFormat;
2578 pFormat += sizeof(NDR_CSTRUCT_FORMAT);
2579 TRACE("(%p, %p, %p)\n", pStubMsg, pMemory, pFormat);
2581 if ((pCStructFormat->type != RPC_FC_CPSTRUCT) && (pCStructFormat->type != RPC_FC_CSTRUCT))
2583 ERR("invalid format type %x\n", pCStructFormat->type);
2584 RpcRaiseException(RPC_S_INTERNAL_ERROR);
2588 TRACE("memory_size = %d\n", pCStructFormat->memory_size);
2590 /* add constant sized part of struct to buffer size */
2591 pStubMsg->BufferLength += pCStructFormat->memory_size;
2593 if (pCStructFormat->offset_to_array_description)
2595 PFORMAT_STRING pArrayFormat = (unsigned char*)&pCStructFormat->offset_to_array_description +
2596 pCStructFormat->offset_to_array_description;
2597 NdrConformantArrayBufferSize(pStubMsg, pMemory + pCStructFormat->memory_size, pArrayFormat);
2599 if (pCStructFormat->type == RPC_FC_CPSTRUCT)
2600 EmbeddedPointerBufferSize(pStubMsg, pMemory, pFormat);
2603 /***********************************************************************
2604 * NdrConformantStructMemorySize [RPCRT4.@]
2606 unsigned long WINAPI NdrConformantStructMemorySize(PMIDL_STUB_MESSAGE pStubMsg,
2607 PFORMAT_STRING pFormat)
2613 /***********************************************************************
2614 * NdrConformantStructFree [RPCRT4.@]
2616 void WINAPI NdrConformantStructFree(PMIDL_STUB_MESSAGE pStubMsg,
2617 unsigned char *pMemory,
2618 PFORMAT_STRING pFormat)
2623 /***********************************************************************
2624 * NdrConformantVaryingStructMarshall [RPCRT4.@]
2626 unsigned char * WINAPI NdrConformantVaryingStructMarshall(PMIDL_STUB_MESSAGE pStubMsg,
2627 unsigned char *pMemory,
2628 PFORMAT_STRING pFormat)
2634 /***********************************************************************
2635 * NdrConformantVaryingStructUnmarshall [RPCRT4.@]
2637 unsigned char * WINAPI NdrConformantVaryingStructUnmarshall(PMIDL_STUB_MESSAGE pStubMsg,
2638 unsigned char **ppMemory,
2639 PFORMAT_STRING pFormat,
2640 unsigned char fMustAlloc)
2646 /***********************************************************************
2647 * NdrConformantVaryingStructBufferSize [RPCRT4.@]
2649 void WINAPI NdrConformantVaryingStructBufferSize(PMIDL_STUB_MESSAGE pStubMsg,
2650 unsigned char *pMemory,
2651 PFORMAT_STRING pFormat)
2656 /***********************************************************************
2657 * NdrConformantVaryingStructMemorySize [RPCRT4.@]
2659 unsigned long WINAPI NdrConformantVaryingStructMemorySize(PMIDL_STUB_MESSAGE pStubMsg,
2660 PFORMAT_STRING pFormat)
2666 /***********************************************************************
2667 * NdrConformantVaryingStructFree [RPCRT4.@]
2669 void WINAPI NdrConformantVaryingStructFree(PMIDL_STUB_MESSAGE pStubMsg,
2670 unsigned char *pMemory,
2671 PFORMAT_STRING pFormat)
2676 /***********************************************************************
2677 * NdrFixedArrayMarshall [RPCRT4.@]
2679 unsigned char * WINAPI NdrFixedArrayMarshall(PMIDL_STUB_MESSAGE pStubMsg,
2680 unsigned char *pMemory,
2681 PFORMAT_STRING pFormat)
2687 /***********************************************************************
2688 * NdrFixedArrayUnmarshall [RPCRT4.@]
2690 unsigned char * WINAPI NdrFixedArrayUnmarshall(PMIDL_STUB_MESSAGE pStubMsg,
2691 unsigned char **ppMemory,
2692 PFORMAT_STRING pFormat,
2693 unsigned char fMustAlloc)
2699 /***********************************************************************
2700 * NdrFixedArrayBufferSize [RPCRT4.@]
2702 void WINAPI NdrFixedArrayBufferSize(PMIDL_STUB_MESSAGE pStubMsg,
2703 unsigned char *pMemory,
2704 PFORMAT_STRING pFormat)
2709 /***********************************************************************
2710 * NdrFixedArrayMemorySize [RPCRT4.@]
2712 unsigned long WINAPI NdrFixedArrayMemorySize(PMIDL_STUB_MESSAGE pStubMsg,
2713 PFORMAT_STRING pFormat)
2719 /***********************************************************************
2720 * NdrFixedArrayFree [RPCRT4.@]
2722 void WINAPI NdrFixedArrayFree(PMIDL_STUB_MESSAGE pStubMsg,
2723 unsigned char *pMemory,
2724 PFORMAT_STRING pFormat)
2729 /***********************************************************************
2730 * NdrVaryingArrayMarshall [RPCRT4.@]
2732 unsigned char * WINAPI NdrVaryingArrayMarshall(PMIDL_STUB_MESSAGE pStubMsg,
2733 unsigned char *pMemory,
2734 PFORMAT_STRING pFormat)
2740 /***********************************************************************
2741 * NdrVaryingArrayUnmarshall [RPCRT4.@]
2743 unsigned char * WINAPI NdrVaryingArrayUnmarshall(PMIDL_STUB_MESSAGE pStubMsg,
2744 unsigned char **ppMemory,
2745 PFORMAT_STRING pFormat,
2746 unsigned char fMustAlloc)
2752 /***********************************************************************
2753 * NdrVaryingArrayBufferSize [RPCRT4.@]
2755 void WINAPI NdrVaryingArrayBufferSize(PMIDL_STUB_MESSAGE pStubMsg,
2756 unsigned char *pMemory,
2757 PFORMAT_STRING pFormat)
2762 /***********************************************************************
2763 * NdrVaryingArrayMemorySize [RPCRT4.@]
2765 unsigned long WINAPI NdrVaryingArrayMemorySize(PMIDL_STUB_MESSAGE pStubMsg,
2766 PFORMAT_STRING pFormat)
2772 /***********************************************************************
2773 * NdrVaryingArrayFree [RPCRT4.@]
2775 void WINAPI NdrVaryingArrayFree(PMIDL_STUB_MESSAGE pStubMsg,
2776 unsigned char *pMemory,
2777 PFORMAT_STRING pFormat)
2782 /***********************************************************************
2783 * NdrEncapsulatedUnionMarshall [RPCRT4.@]
2785 unsigned char * WINAPI NdrEncapsulatedUnionMarshall(PMIDL_STUB_MESSAGE pStubMsg,
2786 unsigned char *pMemory,
2787 PFORMAT_STRING pFormat)
2793 /***********************************************************************
2794 * NdrEncapsulatedUnionUnmarshall [RPCRT4.@]
2796 unsigned char * WINAPI NdrEncapsulatedUnionUnmarshall(PMIDL_STUB_MESSAGE pStubMsg,
2797 unsigned char **ppMemory,
2798 PFORMAT_STRING pFormat,
2799 unsigned char fMustAlloc)
2805 /***********************************************************************
2806 * NdrEncapsulatedUnionBufferSize [RPCRT4.@]
2808 void WINAPI NdrEncapsulatedUnionBufferSize(PMIDL_STUB_MESSAGE pStubMsg,
2809 unsigned char *pMemory,
2810 PFORMAT_STRING pFormat)
2815 /***********************************************************************
2816 * NdrEncapsulatedUnionMemorySize [RPCRT4.@]
2818 unsigned long WINAPI NdrEncapsulatedUnionMemorySize(PMIDL_STUB_MESSAGE pStubMsg,
2819 PFORMAT_STRING pFormat)
2825 /***********************************************************************
2826 * NdrEncapsulatedUnionFree [RPCRT4.@]
2828 void WINAPI NdrEncapsulatedUnionFree(PMIDL_STUB_MESSAGE pStubMsg,
2829 unsigned char *pMemory,
2830 PFORMAT_STRING pFormat)
2835 static PFORMAT_STRING get_arm_offset_from_union_arm_selector(PMIDL_STUB_MESSAGE pStubMsg,
2836 unsigned long discriminant,
2837 PFORMAT_STRING pFormat)
2839 unsigned short num_arms, arm, type;
2841 num_arms = *(const SHORT*)pFormat & 0x0fff;
2843 for(arm = 0; arm < num_arms; arm++)
2845 if(discriminant == *(const ULONG*)pFormat)
2853 type = *(const unsigned short*)pFormat;
2854 TRACE("type %04x\n", type);
2855 if(arm == num_arms) /* default arm extras */
2859 FIXME("should raise an exception here\n");
2864 /* Don't marshall any type. FIXME is this correct? */
2871 static PFORMAT_STRING get_non_encapsulated_union_arm(PMIDL_STUB_MESSAGE pStubMsg,
2872 unsigned char *pMemory,
2873 PFORMAT_STRING pFormat)
2877 pFormat = ComputeConformanceOrVariance(pStubMsg, pMemory, pFormat,
2879 TRACE("got switch value %lx\n", value);
2880 pFormat += *(const SHORT*)pFormat;
2883 return get_arm_offset_from_union_arm_selector(pStubMsg, value, pFormat);
2886 static unsigned char *get_conformance_address(PMIDL_STUB_MESSAGE pStubMsg,
2887 unsigned char *pMemory,
2888 PFORMAT_STRING pFormat)
2890 short ofs = *(short *)&pFormat[2];
2893 switch (pFormat[0] & 0xf0)
2895 case RPC_FC_NORMAL_CONFORMANCE:
2899 FIXME("Conformance type %x\n", pFormat[0]);
2905 FIXME("Conformance op %x\n", pFormat[1]);
2909 return (unsigned char *)ptr + ofs;
2912 /***********************************************************************
2913 * NdrNonEncapsulatedUnionMarshall [RPCRT4.@]
2915 unsigned char * WINAPI NdrNonEncapsulatedUnionMarshall(PMIDL_STUB_MESSAGE pStubMsg,
2916 unsigned char *pMemory,
2917 PFORMAT_STRING pFormat)
2919 unsigned char *discriminant;
2920 unsigned short type;
2922 TRACE("(%p, %p, %p)\n", pStubMsg, pMemory, pFormat);
2925 /* Marshall discriminant */
2926 discriminant = get_conformance_address(pStubMsg, pMemory, pFormat + 1);
2927 NdrBaseTypeMarshall(pStubMsg, discriminant, pFormat);
2930 pFormat = get_non_encapsulated_union_arm(pStubMsg, pMemory, pFormat);
2934 type = *(const unsigned short*)pFormat;
2938 return NdrBaseTypeMarshall(pStubMsg, pMemory, pFormat);
2942 PFORMAT_STRING desc = pFormat + *(const SHORT*)pFormat;
2943 NDR_MARSHALL m = NdrMarshaller[*desc & NDR_TABLE_MASK];
2952 pMemory = *(void**)pMemory;
2955 m(pStubMsg, pMemory, desc);
2957 else FIXME("no marshaller for embedded type %02x\n", *desc);
2962 static long unmarshall_discriminant(PMIDL_STUB_MESSAGE pStubMsg,
2963 PFORMAT_STRING *ppFormat)
2965 long discriminant = 0;
2973 discriminant = *(UCHAR *)pStubMsg->Buffer;
2974 pStubMsg->Buffer += sizeof(UCHAR);
2979 ALIGN_POINTER(pStubMsg->Buffer, sizeof(USHORT));
2980 discriminant = *(USHORT *)pStubMsg->Buffer;
2981 pStubMsg->Buffer += sizeof(USHORT);
2985 ALIGN_POINTER(pStubMsg->Buffer, sizeof(ULONG));
2986 discriminant = *(ULONG *)pStubMsg->Buffer;
2987 pStubMsg->Buffer += sizeof(ULONG);
2990 FIXME("Unhandled base type: 0x%02x\n", **ppFormat);
2994 if (pStubMsg->fHasNewCorrDesc)
2998 return discriminant;
3001 /**********************************************************************
3002 * NdrNonEncapsulatedUnionUnmarshall[RPCRT4.@]
3004 unsigned char * WINAPI NdrNonEncapsulatedUnionUnmarshall(PMIDL_STUB_MESSAGE pStubMsg,
3005 unsigned char **ppMemory,
3006 PFORMAT_STRING pFormat,
3007 unsigned char fMustAlloc)
3010 unsigned short type, size;
3012 TRACE("(%p, %p, %p, %d)\n", pStubMsg, ppMemory, pFormat, fMustAlloc);
3015 /* Unmarshall discriminant */
3016 discriminant = unmarshall_discriminant(pStubMsg, &pFormat);
3017 TRACE("unmarshalled discriminant %lx\n", discriminant);
3019 pFormat += *(const SHORT*)pFormat;
3021 size = *(const unsigned short*)pFormat;
3024 pFormat = get_arm_offset_from_union_arm_selector(pStubMsg, discriminant, pFormat);
3028 if(!*ppMemory || fMustAlloc)
3029 *ppMemory = NdrAllocate(pStubMsg, size);
3031 type = *(const unsigned short*)pFormat;
3035 return NdrBaseTypeUnmarshall(pStubMsg, ppMemory, pFormat, fMustAlloc);
3039 PFORMAT_STRING desc = pFormat + *(const SHORT*)pFormat;
3040 NDR_UNMARSHALL m = NdrUnmarshaller[*desc & NDR_TABLE_MASK];
3049 **(void***)ppMemory = NULL;
3052 return m(pStubMsg, (unsigned char **)*ppMemory, desc, fMustAlloc);
3054 else FIXME("no marshaller for embedded type %02x\n", *desc);
3059 /***********************************************************************
3060 * NdrNonEncapsulatedUnionBufferSize [RPCRT4.@]
3062 void WINAPI NdrNonEncapsulatedUnionBufferSize(PMIDL_STUB_MESSAGE pStubMsg,
3063 unsigned char *pMemory,
3064 PFORMAT_STRING pFormat)
3066 unsigned short type;
3067 TRACE("(%p, %p, %p)\n", pStubMsg, pMemory, pFormat);
3070 /* Add discriminant size */
3071 NdrBaseTypeBufferSize(pStubMsg, pMemory, pFormat);
3074 pFormat = get_non_encapsulated_union_arm(pStubMsg, pMemory, pFormat);
3078 type = *(const unsigned short*)pFormat;
3082 NdrBaseTypeBufferSize(pStubMsg, pMemory, pFormat);
3086 PFORMAT_STRING desc = pFormat + *(const SHORT*)pFormat;
3087 NDR_BUFFERSIZE m = NdrBufferSizer[*desc & NDR_TABLE_MASK];
3096 pMemory = *(void**)pMemory;
3099 m(pStubMsg, pMemory, desc);
3101 else FIXME("no buffersizer for embedded type %02x\n", *desc);
3106 /***********************************************************************
3107 * NdrNonEncapsulatedUnionMemorySize [RPCRT4.@]
3109 unsigned long WINAPI NdrNonEncapsulatedUnionMemorySize(PMIDL_STUB_MESSAGE pStubMsg,
3110 PFORMAT_STRING pFormat)
3116 /***********************************************************************
3117 * NdrNonEncapsulatedUnionFree [RPCRT4.@]
3119 void WINAPI NdrNonEncapsulatedUnionFree(PMIDL_STUB_MESSAGE pStubMsg,
3120 unsigned char *pMemory,
3121 PFORMAT_STRING pFormat)
3126 /***********************************************************************
3127 * NdrByteCountPointerMarshall [RPCRT4.@]
3129 unsigned char * WINAPI NdrByteCountPointerMarshall(PMIDL_STUB_MESSAGE pStubMsg,
3130 unsigned char *pMemory,
3131 PFORMAT_STRING pFormat)
3137 /***********************************************************************
3138 * NdrByteCountPointerUnmarshall [RPCRT4.@]
3140 unsigned char * WINAPI NdrByteCountPointerUnmarshall(PMIDL_STUB_MESSAGE pStubMsg,
3141 unsigned char **ppMemory,
3142 PFORMAT_STRING pFormat,
3143 unsigned char fMustAlloc)
3149 /***********************************************************************
3150 * NdrByteCountPointerBufferSize [RPCRT4.@]
3152 void WINAPI NdrByteCountPointerBufferSize(PMIDL_STUB_MESSAGE pStubMsg,
3153 unsigned char *pMemory,
3154 PFORMAT_STRING pFormat)
3159 /***********************************************************************
3160 * NdrByteCountPointerMemorySize [RPCRT4.@]
3162 unsigned long WINAPI NdrByteCountPointerMemorySize(PMIDL_STUB_MESSAGE pStubMsg,
3163 PFORMAT_STRING pFormat)
3169 /***********************************************************************
3170 * NdrByteCountPointerFree [RPCRT4.@]
3172 void WINAPI NdrByteCountPointerFree(PMIDL_STUB_MESSAGE pStubMsg,
3173 unsigned char *pMemory,
3174 PFORMAT_STRING pFormat)
3179 /***********************************************************************
3180 * NdrXmitOrRepAsMarshall [RPCRT4.@]
3182 unsigned char * WINAPI NdrXmitOrRepAsMarshall(PMIDL_STUB_MESSAGE pStubMsg,
3183 unsigned char *pMemory,
3184 PFORMAT_STRING pFormat)
3190 /***********************************************************************
3191 * NdrXmitOrRepAsUnmarshall [RPCRT4.@]
3193 unsigned char * WINAPI NdrXmitOrRepAsUnmarshall(PMIDL_STUB_MESSAGE pStubMsg,
3194 unsigned char **ppMemory,
3195 PFORMAT_STRING pFormat,
3196 unsigned char fMustAlloc)
3202 /***********************************************************************
3203 * NdrXmitOrRepAsBufferSize [RPCRT4.@]
3205 void WINAPI NdrXmitOrRepAsBufferSize(PMIDL_STUB_MESSAGE pStubMsg,
3206 unsigned char *pMemory,
3207 PFORMAT_STRING pFormat)
3212 /***********************************************************************
3213 * NdrXmitOrRepAsMemorySize [RPCRT4.@]
3215 unsigned long WINAPI NdrXmitOrRepAsMemorySize(PMIDL_STUB_MESSAGE pStubMsg,
3216 PFORMAT_STRING pFormat)
3222 /***********************************************************************
3223 * NdrXmitOrRepAsFree [RPCRT4.@]
3225 void WINAPI NdrXmitOrRepAsFree(PMIDL_STUB_MESSAGE pStubMsg,
3226 unsigned char *pMemory,
3227 PFORMAT_STRING pFormat)
3232 /***********************************************************************
3233 * NdrBaseTypeMarshall [internal]
3235 static unsigned char *WINAPI NdrBaseTypeMarshall(
3236 PMIDL_STUB_MESSAGE pStubMsg,
3237 unsigned char *pMemory,
3238 PFORMAT_STRING pFormat)
3240 TRACE("pStubMsg %p, pMemory %p, type 0x%02x\n", pStubMsg, pMemory, *pFormat);
3248 *(UCHAR *)pStubMsg->Buffer = *(UCHAR *)pMemory;
3249 pStubMsg->Buffer += sizeof(UCHAR);
3250 TRACE("value: 0x%02x\n", *(UCHAR *)pMemory);
3255 ALIGN_POINTER(pStubMsg->Buffer, sizeof(USHORT));
3256 *(USHORT *)pStubMsg->Buffer = *(USHORT *)pMemory;
3257 pStubMsg->Buffer += sizeof(USHORT);
3258 TRACE("value: 0x%04x\n", *(USHORT *)pMemory);
3262 case RPC_FC_ERROR_STATUS_T:
3264 ALIGN_POINTER(pStubMsg->Buffer, sizeof(ULONG));
3265 *(ULONG *)pStubMsg->Buffer = *(ULONG *)pMemory;
3266 pStubMsg->Buffer += sizeof(ULONG);
3267 TRACE("value: 0x%08lx\n", *(ULONG *)pMemory);
3270 ALIGN_POINTER(pStubMsg->Buffer, sizeof(float));
3271 *(float *)pStubMsg->Buffer = *(float *)pMemory;
3272 pStubMsg->Buffer += sizeof(float);
3275 ALIGN_POINTER(pStubMsg->Buffer, sizeof(double));
3276 *(double *)pStubMsg->Buffer = *(double *)pMemory;
3277 pStubMsg->Buffer += sizeof(double);
3280 ALIGN_POINTER(pStubMsg->Buffer, sizeof(ULONGLONG));
3281 *(ULONGLONG *)pStubMsg->Buffer = *(ULONGLONG *)pMemory;
3282 pStubMsg->Buffer += sizeof(ULONGLONG);
3283 TRACE("value: %s\n", wine_dbgstr_longlong(*(ULONGLONG*)pMemory));
3286 /* only 16-bits on the wire, so do a sanity check */
3287 if (*(UINT *)pMemory > USHRT_MAX)
3288 RpcRaiseException(RPC_X_ENUM_VALUE_OUT_OF_RANGE);
3289 ALIGN_POINTER(pStubMsg->Buffer, sizeof(USHORT));
3290 *(USHORT *)pStubMsg->Buffer = *(UINT *)pMemory;
3291 pStubMsg->Buffer += sizeof(USHORT);
3292 TRACE("value: 0x%04x\n", *(UINT *)pMemory);
3295 FIXME("Unhandled base type: 0x%02x\n", *pFormat);
3298 STD_OVERFLOW_CHECK(pStubMsg);
3300 /* FIXME: what is the correct return value? */
3304 /***********************************************************************
3305 * NdrBaseTypeUnmarshall [internal]
3307 static unsigned char *WINAPI NdrBaseTypeUnmarshall(
3308 PMIDL_STUB_MESSAGE pStubMsg,
3309 unsigned char **ppMemory,
3310 PFORMAT_STRING pFormat,
3311 unsigned char fMustAlloc)
3313 TRACE("pStubMsg: %p, ppMemory: %p, type: 0x%02x, fMustAlloc: %s\n", pStubMsg, ppMemory, *pFormat, fMustAlloc ? "true" : "false");
3315 if (fMustAlloc || !*ppMemory)
3316 *ppMemory = NdrAllocate(pStubMsg, NdrBaseTypeMemorySize(pStubMsg, pFormat));
3318 TRACE("*ppMemory: %p\n", *ppMemory);
3326 **(UCHAR **)ppMemory = *(UCHAR *)pStubMsg->Buffer;
3327 pStubMsg->Buffer += sizeof(UCHAR);
3328 TRACE("value: 0x%02x\n", **(UCHAR **)ppMemory);
3333 ALIGN_POINTER(pStubMsg->Buffer, sizeof(USHORT));
3334 **(USHORT **)ppMemory = *(USHORT *)pStubMsg->Buffer;
3335 pStubMsg->Buffer += sizeof(USHORT);
3336 TRACE("value: 0x%04x\n", **(USHORT **)ppMemory);
3340 case RPC_FC_ERROR_STATUS_T:
3342 ALIGN_POINTER(pStubMsg->Buffer, sizeof(ULONG));
3343 **(ULONG **)ppMemory = *(ULONG *)pStubMsg->Buffer;
3344 pStubMsg->Buffer += sizeof(ULONG);
3345 TRACE("value: 0x%08lx\n", **(ULONG **)ppMemory);
3348 ALIGN_POINTER(pStubMsg->Buffer, sizeof(float));
3349 **(float **)ppMemory = *(float *)pStubMsg->Buffer;
3350 pStubMsg->Buffer += sizeof(float);
3351 TRACE("value: %f\n", **(float **)ppMemory);
3354 ALIGN_POINTER(pStubMsg->Buffer, sizeof(double));
3355 **(double **)ppMemory = *(double*)pStubMsg->Buffer;
3356 pStubMsg->Buffer += sizeof(double);
3357 TRACE("value: %f\n", **(double **)ppMemory);
3360 ALIGN_POINTER(pStubMsg->Buffer, sizeof(ULONGLONG));
3361 **(ULONGLONG **)ppMemory = *(ULONGLONG *)pStubMsg->Buffer;
3362 pStubMsg->Buffer += sizeof(ULONGLONG);
3363 TRACE("value: %s\n", wine_dbgstr_longlong(**(ULONGLONG **)ppMemory));
3366 ALIGN_POINTER(pStubMsg->Buffer, sizeof(USHORT));
3367 /* 16-bits on the wire, but int in memory */
3368 **(UINT **)ppMemory = *(USHORT *)pStubMsg->Buffer;
3369 pStubMsg->Buffer += sizeof(USHORT);
3370 TRACE("value: 0x%08x\n", **(UINT **)ppMemory);
3373 FIXME("Unhandled base type: 0x%02x\n", *pFormat);
3376 /* FIXME: what is the correct return value? */
3381 /***********************************************************************
3382 * NdrBaseTypeBufferSize [internal]
3384 static void WINAPI NdrBaseTypeBufferSize(
3385 PMIDL_STUB_MESSAGE pStubMsg,
3386 unsigned char *pMemory,
3387 PFORMAT_STRING pFormat)
3389 TRACE("pStubMsg %p, pMemory %p, type 0x%02x\n", pStubMsg, pMemory, *pFormat);
3397 pStubMsg->BufferLength += sizeof(UCHAR);
3403 ALIGN_LENGTH(pStubMsg->BufferLength, sizeof(USHORT));
3404 pStubMsg->BufferLength += sizeof(USHORT);
3409 ALIGN_LENGTH(pStubMsg->BufferLength, sizeof(ULONG));
3410 pStubMsg->BufferLength += sizeof(ULONG);
3413 ALIGN_LENGTH(pStubMsg->BufferLength, sizeof(float));
3414 pStubMsg->BufferLength += sizeof(float);
3417 ALIGN_LENGTH(pStubMsg->BufferLength, sizeof(double));
3418 pStubMsg->BufferLength += sizeof(double);
3421 ALIGN_LENGTH(pStubMsg->BufferLength, sizeof(ULONGLONG));
3422 pStubMsg->BufferLength += sizeof(ULONGLONG);
3424 case RPC_FC_ERROR_STATUS_T:
3425 ALIGN_LENGTH(pStubMsg->BufferLength, sizeof(error_status_t));
3426 pStubMsg->BufferLength += sizeof(error_status_t);
3429 FIXME("Unhandled base type: 0x%02x\n", *pFormat);
3433 /***********************************************************************
3434 * NdrBaseTypeMemorySize [internal]
3436 static unsigned long WINAPI NdrBaseTypeMemorySize(
3437 PMIDL_STUB_MESSAGE pStubMsg,
3438 PFORMAT_STRING pFormat)
3446 return sizeof(UCHAR);
3450 return sizeof(USHORT);
3453 return sizeof(ULONG);
3455 return sizeof(float);
3457 return sizeof(double);
3459 return sizeof(ULONGLONG);
3460 case RPC_FC_ERROR_STATUS_T:
3461 return sizeof(error_status_t);
3466 FIXME("Unhandled base type: 0x%02x\n", *pFormat);
3471 /***********************************************************************
3472 * NdrBaseTypeFree [internal]
3474 static void WINAPI NdrBaseTypeFree(PMIDL_STUB_MESSAGE pStubMsg,
3475 unsigned char *pMemory,
3476 PFORMAT_STRING pFormat)
3478 TRACE("pStubMsg %p pMemory %p type 0x%02x\n", pStubMsg, pMemory, *pFormat);
3483 /***********************************************************************
3484 * NdrClientContextMarshall
3486 void WINAPI NdrClientContextMarshall(PMIDL_STUB_MESSAGE pStubMsg,
3487 NDR_CCONTEXT ContextHandle,
3490 FIXME("(%p, %p, %d): stub\n", pStubMsg, ContextHandle, fCheck);
3493 /***********************************************************************
3494 * NdrClientContextUnmarshall
3496 void WINAPI NdrClientContextUnmarshall(PMIDL_STUB_MESSAGE pStubMsg,
3497 NDR_CCONTEXT * pContextHandle,
3498 RPC_BINDING_HANDLE BindHandle)
3500 FIXME("(%p, %p, %p): stub\n", pStubMsg, pContextHandle, BindHandle);
3503 void WINAPI NdrServerContextMarshall(PMIDL_STUB_MESSAGE pStubMsg,
3504 NDR_SCONTEXT ContextHandle,
3505 NDR_RUNDOWN RundownRoutine )
3507 FIXME("(%p, %p, %p): stub\n", pStubMsg, ContextHandle, RundownRoutine);
3510 NDR_SCONTEXT WINAPI NdrServerContextUnmarshall(PMIDL_STUB_MESSAGE pStubMsg)
3512 FIXME("(%p): stub\n", pStubMsg);
3516 void WINAPI NdrContextHandleSize(PMIDL_STUB_MESSAGE pStubMsg,
3517 unsigned char* pMemory,
3518 PFORMAT_STRING pFormat)
3520 FIXME("(%p, %p, %p): stub\n", pStubMsg, pMemory, pFormat);
3523 NDR_SCONTEXT WINAPI NdrContextHandleInitialize(PMIDL_STUB_MESSAGE pStubMsg,
3524 PFORMAT_STRING pFormat)
3526 FIXME("(%p, %p): stub\n", pStubMsg, pFormat);
3530 void WINAPI NdrServerContextNewMarshall(PMIDL_STUB_MESSAGE pStubMsg,
3531 NDR_SCONTEXT ContextHandle,
3532 NDR_RUNDOWN RundownRoutine,
3533 PFORMAT_STRING pFormat)
3535 FIXME("(%p, %p, %p, %p): stub\n", pStubMsg, ContextHandle, RundownRoutine, pFormat);
3538 NDR_SCONTEXT WINAPI NdrServerContextNewUnmarshall(PMIDL_STUB_MESSAGE pStubMsg,
3539 PFORMAT_STRING pFormat)
3541 FIXME("(%p, %p): stub\n", pStubMsg, pFormat);
3545 RPC_BINDING_HANDLE WINAPI NDRCContextBinding(NDR_CCONTEXT CContext)
3547 FIXME("(%p): stub\n", CContext);