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 minus 1,
94 * e.g. ALIGN_LENGTH(len, 3) to align on a dword boundary. */
95 #define ALIGNED_LENGTH(_Len, _Align) (((_Len)+(_Align))&~(_Align))
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;
712 if (attr & RPC_FC_P_DEREF) {
713 Pointer = *(unsigned char**)Pointer;
714 TRACE("deref => %p\n", Pointer);
718 case RPC_FC_RP: /* ref pointer (always non-null) */
719 #if 0 /* this causes problems for InstallShield so is disabled - we need more tests */
721 RpcRaiseException(RPC_X_NULL_REF_POINTER);
724 case RPC_FC_UP: /* unique pointer */
725 case RPC_FC_OP: /* object pointer - same as unique here */
726 TRACE("writing %p to buffer\n", Pointer);
727 NDR_LOCAL_UINT32_WRITE(pStubMsg->Buffer, (unsigned long)Pointer);
728 pStubMsg->Buffer += 4;
732 FIXME("unhandled ptr type=%02x\n", type);
733 RpcRaiseException(RPC_X_BAD_STUB_DATA);
736 TRACE("calling marshaller for type 0x%x\n", (int)*desc);
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;
766 if (attr & RPC_FC_P_DEREF) {
767 pPointer = *(unsigned char***)pPointer;
768 TRACE("deref => %p\n", pPointer);
772 case RPC_FC_RP: /* ref pointer (always non-null) */
775 case RPC_FC_UP: /* unique pointer */
776 pointer_id = NDR_LOCAL_UINT32_READ(pStubMsg->Buffer);
777 pStubMsg->Buffer += 4;
779 case RPC_FC_OP: /* object pointer - we must free data before overwriting it */
780 pointer_id = NDR_LOCAL_UINT32_READ(pStubMsg->Buffer);
781 pStubMsg->Buffer += 4;
783 FIXME("free object pointer %p\n", *pPointer);
787 FIXME("unhandled ptr type=%02x\n", type);
788 RpcRaiseException(RPC_X_BAD_STUB_DATA);
792 m = NdrUnmarshaller[*desc & NDR_TABLE_MASK];
793 if (m) m(pStubMsg, pPointer, desc, fMustAlloc);
794 else FIXME("no unmarshaller for data type=%02x\n", *desc);
797 TRACE("pointer=%p\n", *pPointer);
800 /***********************************************************************
803 void WINAPI PointerBufferSize(PMIDL_STUB_MESSAGE pStubMsg,
804 unsigned char *Pointer,
805 PFORMAT_STRING pFormat)
807 unsigned type = pFormat[0], attr = pFormat[1];
811 TRACE("(%p,%p,%p)\n", pStubMsg, Pointer, pFormat);
812 TRACE("type=0x%x, attr=", type); dump_pointer_attr(attr);
814 if (attr & RPC_FC_P_SIMPLEPOINTER) desc = pFormat;
815 else desc = pFormat + *(const SHORT*)pFormat;
816 if (attr & RPC_FC_P_DEREF) {
817 Pointer = *(unsigned char**)Pointer;
818 TRACE("deref => %p\n", Pointer);
822 case RPC_FC_RP: /* ref pointer (always non-null) */
826 pStubMsg->BufferLength += 4;
827 /* NULL pointer has no further representation */
833 FIXME("unhandled ptr type=%02x\n", type);
834 RpcRaiseException(RPC_X_BAD_STUB_DATA);
837 m = NdrBufferSizer[*desc & NDR_TABLE_MASK];
838 if (m) m(pStubMsg, Pointer, desc);
839 else FIXME("no buffersizer for data type=%02x\n", *desc);
842 /***********************************************************************
843 * PointerMemorySize [RPCRT4.@]
845 unsigned long WINAPI PointerMemorySize(PMIDL_STUB_MESSAGE pStubMsg,
846 unsigned char *Buffer,
847 PFORMAT_STRING pFormat)
849 unsigned type = pFormat[0], attr = pFormat[1];
853 FIXME("(%p,%p,%p): stub\n", pStubMsg, Buffer, pFormat);
854 TRACE("type=0x%x, attr=", type); dump_pointer_attr(attr);
856 if (attr & RPC_FC_P_SIMPLEPOINTER) desc = pFormat;
857 else desc = pFormat + *(const SHORT*)pFormat;
858 if (attr & RPC_FC_P_DEREF) {
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 m = NdrMemorySizer[*desc & NDR_TABLE_MASK];
871 if (m) m(pStubMsg, desc);
872 else FIXME("no memorysizer for data type=%02x\n", *desc);
877 /***********************************************************************
878 * PointerFree [RPCRT4.@]
880 void WINAPI PointerFree(PMIDL_STUB_MESSAGE pStubMsg,
881 unsigned char *Pointer,
882 PFORMAT_STRING pFormat)
884 unsigned type = pFormat[0], attr = pFormat[1];
888 TRACE("(%p,%p,%p)\n", pStubMsg, Pointer, pFormat);
889 TRACE("type=0x%x, attr=", type); dump_pointer_attr(attr);
890 if (attr & RPC_FC_P_DONTFREE) return;
892 if (attr & RPC_FC_P_SIMPLEPOINTER) desc = pFormat;
893 else desc = pFormat + *(const SHORT*)pFormat;
894 if (attr & RPC_FC_P_DEREF) {
895 Pointer = *(unsigned char**)Pointer;
896 TRACE("deref => %p\n", Pointer);
899 if (!Pointer) return;
901 m = NdrFreer[*desc & NDR_TABLE_MASK];
902 if (m) m(pStubMsg, Pointer, desc);
904 /* hmm... is this sensible?
905 * perhaps we should check if the memory comes from NdrAllocate,
906 * and deallocate only if so - checking if the pointer is between
907 * BufferStart and BufferEnd is probably no good since the buffer
908 * may be reallocated when the server wants to marshal the reply */
910 case RPC_FC_BOGUS_STRUCT:
911 case RPC_FC_BOGUS_ARRAY:
912 case RPC_FC_USER_MARSHAL:
917 FIXME("unhandled data type=%02x\n", *desc);
919 case RPC_FC_C_CSTRING:
920 case RPC_FC_C_WSTRING:
921 if (pStubMsg->ReuseBuffer) goto notfree;
927 if (attr & RPC_FC_P_ONSTACK) {
928 TRACE("not freeing stack ptr %p\n", Pointer);
931 TRACE("freeing %p\n", Pointer);
932 NdrFree(pStubMsg, Pointer);
935 TRACE("not freeing %p\n", Pointer);
938 /***********************************************************************
939 * EmbeddedPointerMarshall
941 unsigned char * WINAPI EmbeddedPointerMarshall(PMIDL_STUB_MESSAGE pStubMsg,
942 unsigned char *pMemory,
943 PFORMAT_STRING pFormat)
945 unsigned char *Mark = pStubMsg->BufferMark;
946 unsigned long Offset = pStubMsg->Offset;
947 unsigned ofs, rep, count, stride, xofs;
949 TRACE("(%p,%p,%p)\n", pStubMsg, pMemory, pFormat);
951 if (*pFormat != RPC_FC_PP) return NULL;
954 while (pFormat[0] != RPC_FC_END) {
955 switch (pFormat[0]) {
957 FIXME("unknown repeat type %d\n", pFormat[0]);
958 case RPC_FC_NO_REPEAT:
966 case RPC_FC_FIXED_REPEAT:
967 rep = *(const WORD*)&pFormat[2];
968 stride = *(const WORD*)&pFormat[4];
969 ofs = *(const WORD*)&pFormat[6];
970 count = *(const WORD*)&pFormat[8];
974 case RPC_FC_VARIABLE_REPEAT:
975 rep = pStubMsg->MaxCount;
976 stride = *(const WORD*)&pFormat[2];
977 ofs = *(const WORD*)&pFormat[4];
978 count = *(const WORD*)&pFormat[6];
979 xofs = (pFormat[1] == RPC_FC_VARIABLE_OFFSET) ? Offset * stride : 0;
983 /* ofs doesn't seem to matter in this context */
985 PFORMAT_STRING info = pFormat;
986 unsigned char *membase = pMemory + xofs;
988 for (u=0; u<count; u++,info+=8) {
989 unsigned char *memptr = membase + *(const SHORT*)&info[0];
990 unsigned char *bufptr = Mark + *(const SHORT*)&info[2];
991 PointerMarshall(pStubMsg, bufptr, *(unsigned char**)memptr, info+4);
995 pFormat += 8 * count;
998 STD_OVERFLOW_CHECK(pStubMsg);
1003 /***********************************************************************
1004 * EmbeddedPointerUnmarshall
1006 unsigned char * WINAPI EmbeddedPointerUnmarshall(PMIDL_STUB_MESSAGE pStubMsg,
1007 unsigned char **ppMemory,
1008 PFORMAT_STRING pFormat,
1009 unsigned char fMustAlloc)
1011 unsigned char *Mark = pStubMsg->BufferMark;
1012 unsigned long Offset = pStubMsg->Offset;
1013 unsigned ofs, rep, count, stride, xofs;
1015 TRACE("(%p,%p,%p,%d)\n", pStubMsg, ppMemory, pFormat, fMustAlloc);
1017 if (*pFormat != RPC_FC_PP) return NULL;
1020 while (pFormat[0] != RPC_FC_END) {
1021 switch (pFormat[0]) {
1023 FIXME("unknown repeat type %d\n", pFormat[0]);
1024 case RPC_FC_NO_REPEAT:
1032 case RPC_FC_FIXED_REPEAT:
1033 rep = *(const WORD*)&pFormat[2];
1034 stride = *(const WORD*)&pFormat[4];
1035 ofs = *(const WORD*)&pFormat[6];
1036 count = *(const WORD*)&pFormat[8];
1040 case RPC_FC_VARIABLE_REPEAT:
1041 rep = pStubMsg->MaxCount;
1042 stride = *(const WORD*)&pFormat[2];
1043 ofs = *(const WORD*)&pFormat[4];
1044 count = *(const WORD*)&pFormat[6];
1045 xofs = (pFormat[1] == RPC_FC_VARIABLE_OFFSET) ? Offset * stride : 0;
1049 /* ofs doesn't seem to matter in this context */
1051 PFORMAT_STRING info = pFormat;
1052 unsigned char *membase = *ppMemory + xofs;
1054 for (u=0; u<count; u++,info+=8) {
1055 unsigned char *memptr = membase + *(const SHORT*)&info[0];
1056 unsigned char *bufptr = Mark + *(const SHORT*)&info[2];
1057 PointerUnmarshall(pStubMsg, bufptr, (unsigned char**)memptr, info+4, fMustAlloc);
1061 pFormat += 8 * count;
1067 /***********************************************************************
1068 * EmbeddedPointerBufferSize
1070 void WINAPI EmbeddedPointerBufferSize(PMIDL_STUB_MESSAGE pStubMsg,
1071 unsigned char *pMemory,
1072 PFORMAT_STRING pFormat)
1074 unsigned long Offset = pStubMsg->Offset;
1075 unsigned ofs, rep, count, stride, xofs;
1077 TRACE("(%p,%p,%p)\n", pStubMsg, pMemory, pFormat);
1078 if (*pFormat != RPC_FC_PP) return;
1081 while (pFormat[0] != RPC_FC_END) {
1082 switch (pFormat[0]) {
1084 FIXME("unknown repeat type %d\n", pFormat[0]);
1085 case RPC_FC_NO_REPEAT:
1093 case RPC_FC_FIXED_REPEAT:
1094 rep = *(const WORD*)&pFormat[2];
1095 stride = *(const WORD*)&pFormat[4];
1096 ofs = *(const WORD*)&pFormat[6];
1097 count = *(const WORD*)&pFormat[8];
1101 case RPC_FC_VARIABLE_REPEAT:
1102 rep = pStubMsg->MaxCount;
1103 stride = *(const WORD*)&pFormat[2];
1104 ofs = *(const WORD*)&pFormat[4];
1105 count = *(const WORD*)&pFormat[6];
1106 xofs = (pFormat[1] == RPC_FC_VARIABLE_OFFSET) ? Offset * stride : 0;
1110 /* ofs doesn't seem to matter in this context */
1112 PFORMAT_STRING info = pFormat;
1113 unsigned char *membase = pMemory + xofs;
1115 for (u=0; u<count; u++,info+=8) {
1116 unsigned char *memptr = membase + *(const SHORT*)&info[0];
1117 PointerBufferSize(pStubMsg, *(unsigned char**)memptr, info+4);
1121 pFormat += 8 * count;
1125 /***********************************************************************
1126 * EmbeddedPointerMemorySize
1128 unsigned long WINAPI EmbeddedPointerMemorySize(PMIDL_STUB_MESSAGE pStubMsg,
1129 PFORMAT_STRING pFormat)
1131 unsigned long Offset = pStubMsg->Offset;
1132 unsigned char *Mark = pStubMsg->BufferMark;
1133 unsigned ofs, rep, count, stride, xofs;
1135 FIXME("(%p,%p): stub\n", pStubMsg, pFormat);
1136 if (*pFormat != RPC_FC_PP) return 0;
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 */
1170 PFORMAT_STRING info = pFormat;
1172 for (u=0; u<count; u++,info+=8) {
1173 unsigned char *bufptr = Mark + *(const SHORT*)&info[2];
1174 PointerMemorySize(pStubMsg, bufptr, info+4);
1178 pFormat += 8 * count;
1184 /***********************************************************************
1185 * EmbeddedPointerFree
1187 void WINAPI EmbeddedPointerFree(PMIDL_STUB_MESSAGE pStubMsg,
1188 unsigned char *pMemory,
1189 PFORMAT_STRING pFormat)
1191 unsigned long Offset = pStubMsg->Offset;
1192 unsigned ofs, rep, count, stride, xofs;
1194 TRACE("(%p,%p,%p)\n", pStubMsg, pMemory, pFormat);
1195 if (*pFormat != RPC_FC_PP) return;
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 */
1229 PFORMAT_STRING info = pFormat;
1230 unsigned char *membase = pMemory + xofs;
1232 for (u=0; u<count; u++,info+=8) {
1233 unsigned char *memptr = membase + *(const SHORT*)&info[0];
1234 PointerFree(pStubMsg, *(unsigned char**)memptr, info+4);
1238 pFormat += 8 * count;
1242 /***********************************************************************
1243 * NdrPointerMarshall [RPCRT4.@]
1245 unsigned char * WINAPI NdrPointerMarshall(PMIDL_STUB_MESSAGE pStubMsg,
1246 unsigned char *pMemory,
1247 PFORMAT_STRING pFormat)
1249 TRACE("(%p,%p,%p)\n", pStubMsg, pMemory, pFormat);
1251 pStubMsg->BufferMark = pStubMsg->Buffer;
1252 PointerMarshall(pStubMsg, pStubMsg->Buffer, pMemory, pFormat);
1254 STD_OVERFLOW_CHECK(pStubMsg);
1259 /***********************************************************************
1260 * NdrPointerUnmarshall [RPCRT4.@]
1262 unsigned char * WINAPI NdrPointerUnmarshall(PMIDL_STUB_MESSAGE pStubMsg,
1263 unsigned char **ppMemory,
1264 PFORMAT_STRING pFormat,
1265 unsigned char fMustAlloc)
1267 TRACE("(%p,%p,%p,%d)\n", pStubMsg, ppMemory, pFormat, fMustAlloc);
1269 pStubMsg->BufferMark = pStubMsg->Buffer;
1270 PointerUnmarshall(pStubMsg, pStubMsg->Buffer, ppMemory, pFormat, fMustAlloc);
1275 /***********************************************************************
1276 * NdrPointerBufferSize [RPCRT4.@]
1278 void WINAPI NdrPointerBufferSize(PMIDL_STUB_MESSAGE pStubMsg,
1279 unsigned char *pMemory,
1280 PFORMAT_STRING pFormat)
1282 TRACE("(%p,%p,%p)\n", pStubMsg, pMemory, pFormat);
1283 PointerBufferSize(pStubMsg, pMemory, pFormat);
1286 /***********************************************************************
1287 * NdrPointerMemorySize [RPCRT4.@]
1289 unsigned long WINAPI NdrPointerMemorySize(PMIDL_STUB_MESSAGE pStubMsg,
1290 PFORMAT_STRING pFormat)
1292 /* unsigned size = *(LPWORD)(pFormat+2); */
1293 FIXME("(%p,%p): stub\n", pStubMsg, pFormat);
1294 PointerMemorySize(pStubMsg, pStubMsg->Buffer, pFormat);
1298 /***********************************************************************
1299 * NdrPointerFree [RPCRT4.@]
1301 void WINAPI NdrPointerFree(PMIDL_STUB_MESSAGE pStubMsg,
1302 unsigned char *pMemory,
1303 PFORMAT_STRING pFormat)
1305 TRACE("(%p,%p,%p)\n", pStubMsg, pMemory, pFormat);
1306 PointerFree(pStubMsg, pMemory, pFormat);
1309 /***********************************************************************
1310 * NdrSimpleStructMarshall [RPCRT4.@]
1312 unsigned char * WINAPI NdrSimpleStructMarshall(PMIDL_STUB_MESSAGE pStubMsg,
1313 unsigned char *pMemory,
1314 PFORMAT_STRING pFormat)
1316 unsigned size = *(const WORD*)(pFormat+2);
1317 TRACE("(%p,%p,%p)\n", pStubMsg, pMemory, pFormat);
1319 memcpy(pStubMsg->Buffer, pMemory, size);
1320 pStubMsg->BufferMark = pStubMsg->Buffer;
1321 pStubMsg->Buffer += size;
1323 if (pFormat[0] != RPC_FC_STRUCT)
1324 EmbeddedPointerMarshall(pStubMsg, pMemory, pFormat+4);
1326 STD_OVERFLOW_CHECK(pStubMsg);
1331 /***********************************************************************
1332 * NdrSimpleStructUnmarshall [RPCRT4.@]
1334 unsigned char * WINAPI NdrSimpleStructUnmarshall(PMIDL_STUB_MESSAGE pStubMsg,
1335 unsigned char **ppMemory,
1336 PFORMAT_STRING pFormat,
1337 unsigned char fMustAlloc)
1339 unsigned size = *(const WORD*)(pFormat+2);
1340 TRACE("(%p,%p,%p,%d)\n", pStubMsg, ppMemory, pFormat, fMustAlloc);
1343 *ppMemory = NdrAllocate(pStubMsg, size);
1344 memcpy(*ppMemory, pStubMsg->Buffer, size);
1346 if (pStubMsg->ReuseBuffer && !*ppMemory)
1347 /* for servers, we may just point straight into the RPC buffer, I think
1348 * (I guess that's what MS does since MIDL code doesn't try to free) */
1349 *ppMemory = pStubMsg->Buffer;
1351 /* for clients, memory should be provided by caller */
1352 memcpy(*ppMemory, pStubMsg->Buffer, size);
1355 pStubMsg->BufferMark = pStubMsg->Buffer;
1356 pStubMsg->Buffer += size;
1358 if (pFormat[0] != RPC_FC_STRUCT)
1359 EmbeddedPointerUnmarshall(pStubMsg, ppMemory, pFormat+4, fMustAlloc);
1365 /***********************************************************************
1366 * NdrSimpleStructUnmarshall [RPCRT4.@]
1368 void WINAPI NdrSimpleTypeMarshall( PMIDL_STUB_MESSAGE pStubMsg, unsigned char* pMemory,
1369 unsigned char FormatChar )
1375 /***********************************************************************
1376 * NdrSimpleStructUnmarshall [RPCRT4.@]
1378 void WINAPI NdrSimpleTypeUnmarshall( PMIDL_STUB_MESSAGE pStubMsg, unsigned char* pMemory,
1379 unsigned char FormatChar )
1385 /***********************************************************************
1386 * NdrSimpleStructBufferSize [RPCRT4.@]
1388 void WINAPI NdrSimpleStructBufferSize(PMIDL_STUB_MESSAGE pStubMsg,
1389 unsigned char *pMemory,
1390 PFORMAT_STRING pFormat)
1392 unsigned size = *(const WORD*)(pFormat+2);
1393 TRACE("(%p,%p,%p)\n", pStubMsg, pMemory, pFormat);
1394 pStubMsg->BufferLength += size;
1395 if (pFormat[0] != RPC_FC_STRUCT)
1396 EmbeddedPointerBufferSize(pStubMsg, pMemory, pFormat+4);
1399 /***********************************************************************
1400 * NdrSimpleStructMemorySize [RPCRT4.@]
1402 unsigned long WINAPI NdrSimpleStructMemorySize(PMIDL_STUB_MESSAGE pStubMsg,
1403 PFORMAT_STRING pFormat)
1405 /* unsigned size = *(LPWORD)(pFormat+2); */
1406 FIXME("(%p,%p): stub\n", pStubMsg, pFormat);
1407 if (pFormat[0] != RPC_FC_STRUCT)
1408 EmbeddedPointerMemorySize(pStubMsg, pFormat+4);
1412 /***********************************************************************
1413 * NdrSimpleStructFree [RPCRT4.@]
1415 void WINAPI NdrSimpleStructFree(PMIDL_STUB_MESSAGE pStubMsg,
1416 unsigned char *pMemory,
1417 PFORMAT_STRING pFormat)
1419 TRACE("(%p,%p,%p)\n", pStubMsg, pMemory, pFormat);
1420 if (pFormat[0] != RPC_FC_STRUCT)
1421 EmbeddedPointerFree(pStubMsg, pMemory, pFormat+4);
1425 static long NonEncapsulatedUnionSize(PMIDL_STUB_MESSAGE pStubMsg,
1426 PFORMAT_STRING pFormat)
1429 if (pStubMsg->fHasNewCorrDesc)
1434 pFormat += *(const SHORT*)pFormat;
1435 TRACE("size %d\n", *(const SHORT*)pFormat);
1436 return *(const SHORT*)pFormat;
1439 unsigned long WINAPI EmbeddedComplexSize(PMIDL_STUB_MESSAGE pStubMsg,
1440 PFORMAT_STRING pFormat)
1444 case RPC_FC_PSTRUCT:
1445 case RPC_FC_CSTRUCT:
1446 case RPC_FC_BOGUS_STRUCT:
1447 return *(const WORD*)&pFormat[2];
1448 case RPC_FC_USER_MARSHAL:
1449 return *(const WORD*)&pFormat[4];
1450 case RPC_FC_NON_ENCAPSULATED_UNION:
1451 return NonEncapsulatedUnionSize(pStubMsg, pFormat);
1453 FIXME("unhandled embedded type %02x\n", *pFormat);
1459 unsigned char * WINAPI ComplexMarshall(PMIDL_STUB_MESSAGE pStubMsg,
1460 unsigned char *pMemory,
1461 PFORMAT_STRING pFormat,
1462 PFORMAT_STRING pPointer)
1464 PFORMAT_STRING desc;
1468 while (*pFormat != RPC_FC_END) {
1472 TRACE("short=%d <= %p\n", *(WORD*)pMemory, pMemory);
1473 memcpy(pStubMsg->Buffer, pMemory, 2);
1474 pStubMsg->Buffer += 2;
1480 TRACE("long=%ld <= %p\n", *(DWORD*)pMemory, pMemory);
1481 memcpy(pStubMsg->Buffer, pMemory, 4);
1482 pStubMsg->Buffer += 4;
1485 case RPC_FC_POINTER:
1486 TRACE("pointer=%p <= %p\n", *(unsigned char**)pMemory, pMemory);
1487 NdrPointerMarshall(pStubMsg, *(unsigned char**)pMemory, pPointer);
1491 case RPC_FC_ALIGNM4:
1492 ALIGN_POINTER(pMemory, 3);
1494 case RPC_FC_ALIGNM8:
1495 ALIGN_POINTER(pMemory, 7);
1497 case RPC_FC_STRUCTPAD2:
1500 case RPC_FC_EMBEDDED_COMPLEX:
1501 pMemory += pFormat[1];
1503 desc = pFormat + *(const SHORT*)pFormat;
1504 size = EmbeddedComplexSize(pStubMsg, desc);
1505 TRACE("embedded complex (size=%ld) <= %p\n", size, pMemory);
1506 m = NdrMarshaller[*desc & NDR_TABLE_MASK];
1507 if (m) m(pStubMsg, pMemory, desc);
1508 else FIXME("no marshaller for embedded type %02x\n", *desc);
1515 FIXME("unhandled format %02x\n", *pFormat);
1523 unsigned char * WINAPI ComplexUnmarshall(PMIDL_STUB_MESSAGE pStubMsg,
1524 unsigned char *pMemory,
1525 PFORMAT_STRING pFormat,
1526 PFORMAT_STRING pPointer,
1527 unsigned char fMustAlloc)
1529 PFORMAT_STRING desc;
1533 while (*pFormat != RPC_FC_END) {
1537 memcpy(pMemory, pStubMsg->Buffer, 2);
1538 TRACE("short=%d => %p\n", *(WORD*)pMemory, pMemory);
1539 pStubMsg->Buffer += 2;
1545 memcpy(pMemory, pStubMsg->Buffer, 4);
1546 TRACE("long=%ld => %p\n", *(DWORD*)pMemory, pMemory);
1547 pStubMsg->Buffer += 4;
1550 case RPC_FC_POINTER:
1551 *(unsigned char**)pMemory = NULL;
1552 TRACE("pointer => %p\n", pMemory);
1553 NdrPointerUnmarshall(pStubMsg, (unsigned char**)pMemory, pPointer, fMustAlloc);
1557 case RPC_FC_ALIGNM4:
1558 ALIGN_POINTER(pMemory, 3);
1560 case RPC_FC_ALIGNM8:
1561 ALIGN_POINTER(pMemory, 7);
1563 case RPC_FC_STRUCTPAD2:
1566 case RPC_FC_EMBEDDED_COMPLEX:
1567 pMemory += pFormat[1];
1569 desc = pFormat + *(const SHORT*)pFormat;
1570 size = EmbeddedComplexSize(pStubMsg, desc);
1571 TRACE("embedded complex (size=%ld) => %p\n", size, pMemory);
1572 m = NdrUnmarshaller[*desc & NDR_TABLE_MASK];
1573 memset(pMemory, 0, size); /* just in case */
1574 if (m) m(pStubMsg, &pMemory, desc, fMustAlloc);
1575 else FIXME("no unmarshaller for embedded type %02x\n", *desc);
1582 FIXME("unhandled format %d\n", *pFormat);
1590 unsigned char * WINAPI ComplexBufferSize(PMIDL_STUB_MESSAGE pStubMsg,
1591 unsigned char *pMemory,
1592 PFORMAT_STRING pFormat,
1593 PFORMAT_STRING pPointer)
1595 PFORMAT_STRING desc;
1599 while (*pFormat != RPC_FC_END) {
1603 pStubMsg->BufferLength += 2;
1609 pStubMsg->BufferLength += 4;
1612 case RPC_FC_POINTER:
1613 NdrPointerBufferSize(pStubMsg, *(unsigned char**)pMemory, pPointer);
1617 case RPC_FC_ALIGNM4:
1618 ALIGN_POINTER(pMemory, 3);
1620 case RPC_FC_ALIGNM8:
1621 ALIGN_POINTER(pMemory, 7);
1623 case RPC_FC_STRUCTPAD2:
1626 case RPC_FC_EMBEDDED_COMPLEX:
1627 pMemory += pFormat[1];
1629 desc = pFormat + *(const SHORT*)pFormat;
1630 size = EmbeddedComplexSize(pStubMsg, desc);
1631 m = NdrBufferSizer[*desc & NDR_TABLE_MASK];
1632 if (m) m(pStubMsg, pMemory, desc);
1633 else FIXME("no buffersizer for embedded type %02x\n", *desc);
1640 FIXME("unhandled format %d\n", *pFormat);
1648 unsigned char * WINAPI ComplexFree(PMIDL_STUB_MESSAGE pStubMsg,
1649 unsigned char *pMemory,
1650 PFORMAT_STRING pFormat,
1651 PFORMAT_STRING pPointer)
1653 PFORMAT_STRING desc;
1657 while (*pFormat != RPC_FC_END) {
1668 case RPC_FC_POINTER:
1669 NdrPointerFree(pStubMsg, *(unsigned char**)pMemory, pPointer);
1673 case RPC_FC_ALIGNM4:
1674 ALIGN_POINTER(pMemory, 3);
1676 case RPC_FC_ALIGNM8:
1677 ALIGN_POINTER(pMemory, 7);
1679 case RPC_FC_STRUCTPAD2:
1682 case RPC_FC_EMBEDDED_COMPLEX:
1683 pMemory += pFormat[1];
1685 desc = pFormat + *(const SHORT*)pFormat;
1686 size = EmbeddedComplexSize(pStubMsg, desc);
1687 m = NdrFreer[*desc & NDR_TABLE_MASK];
1688 if (m) m(pStubMsg, pMemory, desc);
1689 else FIXME("no freer for embedded type %02x\n", *desc);
1696 FIXME("unhandled format %d\n", *pFormat);
1704 unsigned long WINAPI ComplexStructSize(PMIDL_STUB_MESSAGE pStubMsg,
1705 PFORMAT_STRING pFormat)
1707 PFORMAT_STRING desc;
1708 unsigned long size = 0;
1710 while (*pFormat != RPC_FC_END) {
1720 case RPC_FC_POINTER:
1723 case RPC_FC_ALIGNM4:
1724 ALIGN_LENGTH(size, 3);
1726 case RPC_FC_ALIGNM8:
1727 ALIGN_LENGTH(size, 7);
1729 case RPC_FC_STRUCTPAD2:
1732 case RPC_FC_EMBEDDED_COMPLEX:
1735 desc = pFormat + *(const SHORT*)pFormat;
1736 size += EmbeddedComplexSize(pStubMsg, desc);
1742 FIXME("unhandled format %d\n", *pFormat);
1750 /***********************************************************************
1751 * NdrComplexStructMarshall [RPCRT4.@]
1753 unsigned char * WINAPI NdrComplexStructMarshall(PMIDL_STUB_MESSAGE pStubMsg,
1754 unsigned char *pMemory,
1755 PFORMAT_STRING pFormat)
1757 PFORMAT_STRING conf_array = NULL;
1758 PFORMAT_STRING pointer_desc = NULL;
1759 unsigned char *OldMemory = pStubMsg->Memory;
1761 TRACE("(%p,%p,%p)\n", pStubMsg, pMemory, pFormat);
1764 if (*(const WORD*)pFormat) conf_array = pFormat + *(const WORD*)pFormat;
1766 if (*(const WORD*)pFormat) pointer_desc = pFormat + *(const WORD*)pFormat;
1769 pStubMsg->Memory = pMemory;
1771 ComplexMarshall(pStubMsg, pMemory, pFormat, pointer_desc);
1774 NdrConformantArrayMarshall(pStubMsg, pMemory, conf_array);
1776 pStubMsg->Memory = OldMemory;
1778 STD_OVERFLOW_CHECK(pStubMsg);
1783 /***********************************************************************
1784 * NdrComplexStructUnmarshall [RPCRT4.@]
1786 unsigned char * WINAPI NdrComplexStructUnmarshall(PMIDL_STUB_MESSAGE pStubMsg,
1787 unsigned char **ppMemory,
1788 PFORMAT_STRING pFormat,
1789 unsigned char fMustAlloc)
1791 unsigned size = *(const WORD*)(pFormat+2);
1792 PFORMAT_STRING conf_array = NULL;
1793 PFORMAT_STRING pointer_desc = NULL;
1794 unsigned char *pMemory;
1796 TRACE("(%p,%p,%p,%d)\n", pStubMsg, ppMemory, pFormat, fMustAlloc);
1798 if (fMustAlloc || !*ppMemory)
1800 *ppMemory = NdrAllocate(pStubMsg, size);
1801 memset(*ppMemory, 0, size);
1805 if (*(const WORD*)pFormat) conf_array = pFormat + *(const WORD*)pFormat;
1807 if (*(const WORD*)pFormat) pointer_desc = pFormat + *(const WORD*)pFormat;
1810 pMemory = ComplexUnmarshall(pStubMsg, *ppMemory, pFormat, pointer_desc, fMustAlloc);
1813 NdrConformantArrayUnmarshall(pStubMsg, &pMemory, conf_array, fMustAlloc);
1818 /***********************************************************************
1819 * NdrComplexStructBufferSize [RPCRT4.@]
1821 void WINAPI NdrComplexStructBufferSize(PMIDL_STUB_MESSAGE pStubMsg,
1822 unsigned char *pMemory,
1823 PFORMAT_STRING pFormat)
1825 PFORMAT_STRING conf_array = NULL;
1826 PFORMAT_STRING pointer_desc = NULL;
1827 unsigned char *OldMemory = pStubMsg->Memory;
1829 TRACE("(%p,%p,%p)\n", pStubMsg, pMemory, pFormat);
1832 if (*(const WORD*)pFormat) conf_array = pFormat + *(const WORD*)pFormat;
1834 if (*(const WORD*)pFormat) pointer_desc = pFormat + *(const WORD*)pFormat;
1837 pStubMsg->Memory = pMemory;
1839 pMemory = ComplexBufferSize(pStubMsg, pMemory, pFormat, pointer_desc);
1842 NdrConformantArrayBufferSize(pStubMsg, pMemory, conf_array);
1844 pStubMsg->Memory = OldMemory;
1847 /***********************************************************************
1848 * NdrComplexStructMemorySize [RPCRT4.@]
1850 unsigned long WINAPI NdrComplexStructMemorySize(PMIDL_STUB_MESSAGE pStubMsg,
1851 PFORMAT_STRING pFormat)
1853 /* unsigned size = *(LPWORD)(pFormat+2); */
1854 PFORMAT_STRING conf_array = NULL;
1855 PFORMAT_STRING pointer_desc = NULL;
1857 FIXME("(%p,%p): stub\n", pStubMsg, pFormat);
1860 if (*(const WORD*)pFormat) conf_array = pFormat + *(const WORD*)pFormat;
1862 if (*(const WORD*)pFormat) pointer_desc = pFormat + *(const WORD*)pFormat;
1868 /***********************************************************************
1869 * NdrComplexStructFree [RPCRT4.@]
1871 void WINAPI NdrComplexStructFree(PMIDL_STUB_MESSAGE pStubMsg,
1872 unsigned char *pMemory,
1873 PFORMAT_STRING pFormat)
1875 PFORMAT_STRING conf_array = NULL;
1876 PFORMAT_STRING pointer_desc = NULL;
1877 unsigned char *OldMemory = pStubMsg->Memory;
1879 TRACE("(%p,%p,%p)\n", pStubMsg, pMemory, pFormat);
1882 if (*(const WORD*)pFormat) conf_array = pFormat + *(const WORD*)pFormat;
1884 if (*(const WORD*)pFormat) pointer_desc = pFormat + *(const WORD*)pFormat;
1887 pStubMsg->Memory = pMemory;
1889 pMemory = ComplexFree(pStubMsg, pMemory, pFormat, pointer_desc);
1892 NdrConformantArrayFree(pStubMsg, pMemory, conf_array);
1894 pStubMsg->Memory = OldMemory;
1897 /***********************************************************************
1898 * NdrConformantArrayMarshall [RPCRT4.@]
1900 unsigned char * WINAPI NdrConformantArrayMarshall(PMIDL_STUB_MESSAGE pStubMsg,
1901 unsigned char *pMemory,
1902 PFORMAT_STRING pFormat)
1904 DWORD size = 0, esize = *(const WORD*)(pFormat+2);
1905 TRACE("(%p,%p,%p)\n", pStubMsg, pMemory, pFormat);
1906 if (pFormat[0] != RPC_FC_CARRAY) FIXME("format=%d\n", pFormat[0]);
1908 pFormat = ComputeConformance(pStubMsg, pMemory, pFormat+4, 0);
1909 size = pStubMsg->MaxCount;
1911 NDR_LOCAL_UINT32_WRITE(pStubMsg->Buffer, size);
1912 pStubMsg->Buffer += 4;
1914 memcpy(pStubMsg->Buffer, pMemory, size*esize);
1915 pStubMsg->BufferMark = pStubMsg->Buffer;
1916 pStubMsg->Buffer += size*esize;
1918 EmbeddedPointerMarshall(pStubMsg, pMemory, pFormat);
1920 STD_OVERFLOW_CHECK(pStubMsg);
1925 /***********************************************************************
1926 * NdrConformantArrayUnmarshall [RPCRT4.@]
1928 unsigned char * WINAPI NdrConformantArrayUnmarshall(PMIDL_STUB_MESSAGE pStubMsg,
1929 unsigned char **ppMemory,
1930 PFORMAT_STRING pFormat,
1931 unsigned char fMustAlloc)
1933 DWORD size = 0, esize = *(const WORD*)(pFormat+2);
1934 TRACE("(%p,%p,%p,%d)\n", pStubMsg, ppMemory, pFormat, fMustAlloc);
1935 if (pFormat[0] != RPC_FC_CARRAY) FIXME("format=%d\n", pFormat[0]);
1937 pFormat = ReadConformance(pStubMsg, pFormat+4);
1938 size = pStubMsg->MaxCount;
1940 if (fMustAlloc || !*ppMemory)
1941 *ppMemory = NdrAllocate(pStubMsg, size*esize);
1943 memcpy(*ppMemory, pStubMsg->Buffer, size*esize);
1945 pStubMsg->BufferMark = pStubMsg->Buffer;
1946 pStubMsg->Buffer += size*esize;
1948 EmbeddedPointerUnmarshall(pStubMsg, ppMemory, pFormat, fMustAlloc);
1953 /***********************************************************************
1954 * NdrConformantArrayBufferSize [RPCRT4.@]
1956 void WINAPI NdrConformantArrayBufferSize(PMIDL_STUB_MESSAGE pStubMsg,
1957 unsigned char *pMemory,
1958 PFORMAT_STRING pFormat)
1960 DWORD size = 0, esize = *(const WORD*)(pFormat+2);
1961 TRACE("(%p,%p,%p)\n", pStubMsg, pMemory, pFormat);
1962 if (pFormat[0] != RPC_FC_CARRAY) FIXME("format=%d\n", pFormat[0]);
1964 pFormat = ComputeConformance(pStubMsg, pMemory, pFormat+4, 0);
1965 size = pStubMsg->MaxCount;
1967 /* conformance value plus array */
1968 pStubMsg->BufferLength += sizeof(DWORD) + size*esize;
1970 EmbeddedPointerBufferSize(pStubMsg, pMemory, pFormat);
1973 /***********************************************************************
1974 * NdrConformantArrayMemorySize [RPCRT4.@]
1976 unsigned long WINAPI NdrConformantArrayMemorySize(PMIDL_STUB_MESSAGE pStubMsg,
1977 PFORMAT_STRING pFormat)
1979 DWORD size = 0, esize = *(const WORD*)(pFormat+2);
1980 unsigned char *buffer;
1982 TRACE("(%p,%p)\n", pStubMsg, pFormat);
1983 if (pFormat[0] != RPC_FC_CARRAY) FIXME("format=%d\n", pFormat[0]);
1985 buffer = pStubMsg->Buffer;
1986 pFormat = ReadConformance(pStubMsg, pFormat+4);
1987 pStubMsg->Buffer = buffer;
1988 size = pStubMsg->MaxCount;
1993 /***********************************************************************
1994 * NdrConformantArrayFree [RPCRT4.@]
1996 void WINAPI NdrConformantArrayFree(PMIDL_STUB_MESSAGE pStubMsg,
1997 unsigned char *pMemory,
1998 PFORMAT_STRING pFormat)
2000 TRACE("(%p,%p,%p)\n", pStubMsg, pMemory, pFormat);
2001 if (pFormat[0] != RPC_FC_CARRAY) FIXME("format=%d\n", pFormat[0]);
2003 EmbeddedPointerFree(pStubMsg, pMemory, pFormat);
2007 /***********************************************************************
2008 * NdrConformantVaryingArrayMarshall [RPCRT4.@]
2010 unsigned char* WINAPI NdrConformantVaryingArrayMarshall( PMIDL_STUB_MESSAGE pStubMsg,
2011 unsigned char* pMemory,
2012 PFORMAT_STRING pFormat )
2014 DWORD esize = *(const WORD*)(pFormat+2);
2016 TRACE("(%p, %p, %p)\n", pStubMsg, pMemory, pFormat);
2018 if (pFormat[0] != RPC_FC_CVARRAY)
2020 ERR("invalid format type %x\n", pFormat[0]);
2021 RpcRaiseException(RPC_S_INTERNAL_ERROR);
2025 pFormat = ComputeConformance(pStubMsg, pMemory, pFormat+4, 0);
2026 pFormat = ComputeVariance(pStubMsg, pMemory, pFormat, 0);
2028 NDR_LOCAL_UINT32_WRITE(pStubMsg->Buffer, pStubMsg->MaxCount);
2029 pStubMsg->Buffer += 4;
2030 NDR_LOCAL_UINT32_WRITE(pStubMsg->Buffer, pStubMsg->Offset);
2031 pStubMsg->Buffer += 4;
2032 NDR_LOCAL_UINT32_WRITE(pStubMsg->Buffer, pStubMsg->ActualCount);
2033 pStubMsg->Buffer += 4;
2035 memcpy(pStubMsg->Buffer, pMemory + pStubMsg->Offset, pStubMsg->ActualCount*esize);
2036 pStubMsg->BufferMark = pStubMsg->Buffer;
2037 pStubMsg->Buffer += pStubMsg->ActualCount*esize;
2039 EmbeddedPointerMarshall(pStubMsg, pMemory, pFormat);
2041 STD_OVERFLOW_CHECK(pStubMsg);
2047 /***********************************************************************
2048 * NdrConformantVaryingArrayUnmarshall [RPCRT4.@]
2050 unsigned char* WINAPI NdrConformantVaryingArrayUnmarshall( PMIDL_STUB_MESSAGE pStubMsg,
2051 unsigned char** ppMemory,
2052 PFORMAT_STRING pFormat,
2053 unsigned char fMustAlloc )
2055 DWORD esize = *(const WORD*)(pFormat+2);
2057 TRACE("(%p, %p, %p, %d)\n", pStubMsg, ppMemory, pFormat, fMustAlloc);
2059 if (pFormat[0] != RPC_FC_CVARRAY)
2061 ERR("invalid format type %x\n", pFormat[0]);
2062 RpcRaiseException(RPC_S_INTERNAL_ERROR);
2065 pFormat = ReadConformance(pStubMsg, pFormat);
2066 pFormat = ReadVariance(pStubMsg, pFormat);
2068 if (!*ppMemory || fMustAlloc)
2069 *ppMemory = NdrAllocate(pStubMsg, pStubMsg->MaxCount * esize);
2070 memcpy(*ppMemory + pStubMsg->Offset, pStubMsg->Buffer, pStubMsg->ActualCount * esize);
2071 pStubMsg->Buffer += pStubMsg->ActualCount * esize;
2073 EmbeddedPointerUnmarshall(pStubMsg, ppMemory, pFormat, fMustAlloc);
2079 /***********************************************************************
2080 * NdrConformantVaryingArrayFree [RPCRT4.@]
2082 void WINAPI NdrConformantVaryingArrayFree( PMIDL_STUB_MESSAGE pStubMsg,
2083 unsigned char* pMemory,
2084 PFORMAT_STRING pFormat )
2090 /***********************************************************************
2091 * NdrConformantVaryingArrayBufferSize [RPCRT4.@]
2093 void WINAPI NdrConformantVaryingArrayBufferSize( PMIDL_STUB_MESSAGE pStubMsg,
2094 unsigned char* pMemory, PFORMAT_STRING pFormat )
2096 DWORD esize = *(const WORD*)(pFormat+2);
2098 TRACE("(%p, %p, %p)\n", pStubMsg, pMemory, pFormat);
2100 if (pFormat[0] != RPC_FC_CVARRAY)
2102 ERR("invalid format type %x\n", pFormat[0]);
2103 RpcRaiseException(RPC_S_INTERNAL_ERROR);
2108 pFormat = ComputeConformance(pStubMsg, pMemory, pFormat+4, 0);
2109 /* compute length */
2110 pFormat = ComputeVariance(pStubMsg, pMemory, pFormat, 0);
2112 /* conformance + offset + variance + array */
2113 pStubMsg->BufferLength += 3*sizeof(DWORD) + pStubMsg->ActualCount*esize;
2115 EmbeddedPointerBufferSize(pStubMsg, pMemory, pFormat);
2119 /***********************************************************************
2120 * NdrConformantVaryingArrayMemorySize [RPCRT4.@]
2122 unsigned long WINAPI NdrConformantVaryingArrayMemorySize( PMIDL_STUB_MESSAGE pStubMsg,
2123 PFORMAT_STRING pFormat )
2130 /***********************************************************************
2131 * NdrComplexArrayMarshall [RPCRT4.@]
2133 unsigned char * WINAPI NdrComplexArrayMarshall(PMIDL_STUB_MESSAGE pStubMsg,
2134 unsigned char *pMemory,
2135 PFORMAT_STRING pFormat)
2138 BOOL variance_present;
2140 TRACE("(%p,%p,%p)\n", pStubMsg, pMemory, pFormat);
2142 if (pFormat[0] != RPC_FC_BOGUS_ARRAY)
2144 ERR("invalid format type %x\n", pFormat[0]);
2145 RpcRaiseException(RPC_S_INTERNAL_ERROR);
2149 def = *(const WORD*)&pFormat[2];
2152 pFormat = ComputeConformance(pStubMsg, pMemory, pFormat, def);
2153 TRACE("conformance = %ld\n", pStubMsg->MaxCount);
2155 variance_present = IsConformanceOrVariancePresent(pFormat);
2156 pFormat = ComputeVariance(pStubMsg, pMemory, pFormat, pStubMsg->MaxCount);
2157 TRACE("variance = %ld\n", pStubMsg->ActualCount);
2159 NDR_LOCAL_UINT32_WRITE(pStubMsg->Buffer, pStubMsg->MaxCount);
2160 pStubMsg->Buffer += 4;
2161 if (variance_present)
2163 NDR_LOCAL_UINT32_WRITE(pStubMsg->Buffer, pStubMsg->Offset);
2164 pStubMsg->Buffer += 4;
2165 NDR_LOCAL_UINT32_WRITE(pStubMsg->Buffer, pStubMsg->ActualCount);
2166 pStubMsg->Buffer += 4;
2169 for (count = 0; count < pStubMsg->ActualCount; count++)
2170 pMemory = ComplexMarshall(pStubMsg, pMemory, pFormat, NULL);
2172 STD_OVERFLOW_CHECK(pStubMsg);
2177 /***********************************************************************
2178 * NdrComplexArrayUnmarshall [RPCRT4.@]
2180 unsigned char * WINAPI NdrComplexArrayUnmarshall(PMIDL_STUB_MESSAGE pStubMsg,
2181 unsigned char **ppMemory,
2182 PFORMAT_STRING pFormat,
2183 unsigned char fMustAlloc)
2186 unsigned char *pMemory;
2188 TRACE("(%p,%p,%p,%d)\n", pStubMsg, ppMemory, pFormat, fMustAlloc);
2190 if (pFormat[0] != RPC_FC_BOGUS_ARRAY)
2192 ERR("invalid format type %x\n", pFormat[0]);
2193 RpcRaiseException(RPC_S_INTERNAL_ERROR);
2199 pFormat = ReadConformance(pStubMsg, pFormat);
2200 pFormat = ReadVariance(pStubMsg, pFormat);
2202 esize = ComplexStructSize(pStubMsg, pFormat);
2204 if (fMustAlloc || !*ppMemory)
2206 *ppMemory = NdrAllocate(pStubMsg, pStubMsg->MaxCount * esize);
2207 memset(*ppMemory, 0, pStubMsg->MaxCount * esize);
2210 pMemory = *ppMemory;
2211 for (count = 0; count < pStubMsg->ActualCount; count++)
2212 pMemory = ComplexUnmarshall(pStubMsg, pMemory, pFormat, NULL, fMustAlloc);
2217 /***********************************************************************
2218 * NdrComplexArrayBufferSize [RPCRT4.@]
2220 void WINAPI NdrComplexArrayBufferSize(PMIDL_STUB_MESSAGE pStubMsg,
2221 unsigned char *pMemory,
2222 PFORMAT_STRING pFormat)
2225 BOOL variance_present;
2227 TRACE("(%p,%p,%p)\n", pStubMsg, pMemory, pFormat);
2229 if (pFormat[0] != RPC_FC_BOGUS_ARRAY)
2231 ERR("invalid format type %x\n", pFormat[0]);
2232 RpcRaiseException(RPC_S_INTERNAL_ERROR);
2236 def = *(const WORD*)&pFormat[2];
2239 pFormat = ComputeConformance(pStubMsg, pMemory, pFormat, def);
2240 TRACE("conformance = %ld\n", pStubMsg->MaxCount);
2241 pStubMsg->BufferLength += sizeof(ULONG);
2243 variance_present = IsConformanceOrVariancePresent(pFormat);
2244 pFormat = ComputeVariance(pStubMsg, pMemory, pFormat, pStubMsg->MaxCount);
2245 TRACE("variance = %ld\n", pStubMsg->ActualCount);
2247 if (variance_present)
2248 pStubMsg->BufferLength += 2*sizeof(ULONG);
2250 for (count=0; count < pStubMsg->ActualCount; count++)
2251 pMemory = ComplexBufferSize(pStubMsg, pMemory, pFormat, NULL);
2254 /***********************************************************************
2255 * NdrComplexArrayMemorySize [RPCRT4.@]
2257 unsigned long WINAPI NdrComplexArrayMemorySize(PMIDL_STUB_MESSAGE pStubMsg,
2258 PFORMAT_STRING pFormat)
2261 FIXME("(%p,%p): stub\n", pStubMsg, pFormat);
2263 if (pFormat[0] != RPC_FC_BOGUS_ARRAY)
2265 ERR("invalid format type %x\n", pFormat[0]);
2266 RpcRaiseException(RPC_S_INTERNAL_ERROR);
2272 pFormat = ReadConformance(pStubMsg, pFormat);
2273 size = pStubMsg->MaxCount;
2274 TRACE("conformance=%ld\n", size);
2281 /***********************************************************************
2282 * NdrComplexArrayFree [RPCRT4.@]
2284 void WINAPI NdrComplexArrayFree(PMIDL_STUB_MESSAGE pStubMsg,
2285 unsigned char *pMemory,
2286 PFORMAT_STRING pFormat)
2290 TRACE("(%p,%p,%p)\n", pStubMsg, pMemory, pFormat);
2292 if (pFormat[0] != RPC_FC_BOGUS_ARRAY)
2294 ERR("invalid format type %x\n", pFormat[0]);
2295 RpcRaiseException(RPC_S_INTERNAL_ERROR);
2299 def = *(const WORD*)&pFormat[2];
2302 pFormat = ComputeConformance(pStubMsg, pMemory, pFormat, def);
2303 TRACE("conformance = %ld\n", pStubMsg->MaxCount);
2305 pFormat = ComputeVariance(pStubMsg, pMemory, pFormat, pStubMsg->MaxCount);
2306 TRACE("variance = %ld\n", pStubMsg->ActualCount);
2308 for (count=0; count < pStubMsg->ActualCount; count++)
2309 pMemory = ComplexFree(pStubMsg, pMemory, pFormat, NULL);
2312 unsigned long UserMarshalFlags(PMIDL_STUB_MESSAGE pStubMsg)
2314 return MAKELONG(pStubMsg->dwDestContext,
2315 pStubMsg->RpcMsg->DataRepresentation);
2318 /***********************************************************************
2319 * NdrUserMarshalMarshall [RPCRT4.@]
2321 unsigned char * WINAPI NdrUserMarshalMarshall(PMIDL_STUB_MESSAGE pStubMsg,
2322 unsigned char *pMemory,
2323 PFORMAT_STRING pFormat)
2325 /* unsigned flags = pFormat[1]; */
2326 unsigned index = *(const WORD*)&pFormat[2];
2327 unsigned long uflag = UserMarshalFlags(pStubMsg);
2328 TRACE("(%p,%p,%p)\n", pStubMsg, pMemory, pFormat);
2329 TRACE("index=%d\n", index);
2332 pStubMsg->StubDesc->aUserMarshalQuadruple[index].pfnMarshall(
2333 &uflag, pStubMsg->Buffer, pMemory);
2335 STD_OVERFLOW_CHECK(pStubMsg);
2340 /***********************************************************************
2341 * NdrUserMarshalUnmarshall [RPCRT4.@]
2343 unsigned char * WINAPI NdrUserMarshalUnmarshall(PMIDL_STUB_MESSAGE pStubMsg,
2344 unsigned char **ppMemory,
2345 PFORMAT_STRING pFormat,
2346 unsigned char fMustAlloc)
2348 /* unsigned flags = pFormat[1];*/
2349 unsigned index = *(const WORD*)&pFormat[2];
2350 DWORD memsize = *(const WORD*)&pFormat[4];
2351 unsigned long uflag = UserMarshalFlags(pStubMsg);
2352 TRACE("(%p,%p,%p,%d)\n", pStubMsg, ppMemory, pFormat, fMustAlloc);
2353 TRACE("index=%d\n", index);
2355 if (fMustAlloc || !*ppMemory)
2356 *ppMemory = NdrAllocate(pStubMsg, memsize);
2359 pStubMsg->StubDesc->aUserMarshalQuadruple[index].pfnUnmarshall(
2360 &uflag, pStubMsg->Buffer, *ppMemory);
2365 /***********************************************************************
2366 * NdrUserMarshalBufferSize [RPCRT4.@]
2368 void WINAPI NdrUserMarshalBufferSize(PMIDL_STUB_MESSAGE pStubMsg,
2369 unsigned char *pMemory,
2370 PFORMAT_STRING pFormat)
2372 /* unsigned flags = pFormat[1];*/
2373 unsigned index = *(const WORD*)&pFormat[2];
2374 DWORD bufsize = *(const WORD*)&pFormat[6];
2375 unsigned long uflag = UserMarshalFlags(pStubMsg);
2376 TRACE("(%p,%p,%p)\n", pStubMsg, pMemory, pFormat);
2377 TRACE("index=%d\n", index);
2380 TRACE("size=%ld\n", bufsize);
2381 pStubMsg->BufferLength += bufsize;
2385 pStubMsg->BufferLength =
2386 pStubMsg->StubDesc->aUserMarshalQuadruple[index].pfnBufferSize(
2387 &uflag, pStubMsg->BufferLength, pMemory);
2390 /***********************************************************************
2391 * NdrUserMarshalMemorySize [RPCRT4.@]
2393 unsigned long WINAPI NdrUserMarshalMemorySize(PMIDL_STUB_MESSAGE pStubMsg,
2394 PFORMAT_STRING pFormat)
2396 unsigned index = *(const WORD*)&pFormat[2];
2397 /* DWORD memsize = *(const WORD*)&pFormat[4]; */
2398 FIXME("(%p,%p): stub\n", pStubMsg, pFormat);
2399 TRACE("index=%d\n", index);
2404 /***********************************************************************
2405 * NdrUserMarshalFree [RPCRT4.@]
2407 void WINAPI NdrUserMarshalFree(PMIDL_STUB_MESSAGE pStubMsg,
2408 unsigned char *pMemory,
2409 PFORMAT_STRING pFormat)
2411 /* unsigned flags = pFormat[1]; */
2412 unsigned index = *(const WORD*)&pFormat[2];
2413 unsigned long uflag = UserMarshalFlags(pStubMsg);
2414 TRACE("(%p,%p,%p)\n", pStubMsg, pMemory, pFormat);
2415 TRACE("index=%d\n", index);
2417 pStubMsg->StubDesc->aUserMarshalQuadruple[index].pfnFree(
2421 /***********************************************************************
2422 * NdrClearOutParameters [RPCRT4.@]
2424 void WINAPI NdrClearOutParameters(PMIDL_STUB_MESSAGE pStubMsg,
2425 PFORMAT_STRING pFormat,
2428 FIXME("(%p,%p,%p): stub\n", pStubMsg, pFormat, ArgAddr);
2431 /***********************************************************************
2432 * NdrConvert [RPCRT4.@]
2434 void WINAPI NdrConvert( PMIDL_STUB_MESSAGE pStubMsg, PFORMAT_STRING pFormat )
2436 FIXME("(pStubMsg == ^%p, pFormat == ^%p): stub.\n", pStubMsg, pFormat);
2437 /* FIXME: since this stub doesn't do any converting, the proper behavior
2438 is to raise an exception */
2441 /***********************************************************************
2442 * NdrConvert2 [RPCRT4.@]
2444 void WINAPI NdrConvert2( PMIDL_STUB_MESSAGE pStubMsg, PFORMAT_STRING pFormat, long NumberParams )
2446 FIXME("(pStubMsg == ^%p, pFormat == ^%p, NumberParams == %ld): stub.\n",
2447 pStubMsg, pFormat, NumberParams);
2448 /* FIXME: since this stub doesn't do any converting, the proper behavior
2449 is to raise an exception */
2452 typedef struct _NDR_CSTRUCT_FORMAT
2455 unsigned char alignment;
2456 unsigned short memory_size;
2457 short offset_to_array_description;
2458 } NDR_CSTRUCT_FORMAT;
2460 /***********************************************************************
2461 * NdrConformantStructMarshall [RPCRT4.@]
2463 unsigned char * WINAPI NdrConformantStructMarshall(PMIDL_STUB_MESSAGE pStubMsg,
2464 unsigned char *pMemory,
2465 PFORMAT_STRING pFormat)
2467 const NDR_CSTRUCT_FORMAT * pCStructFormat = (NDR_CSTRUCT_FORMAT*)pFormat;
2468 pFormat += sizeof(NDR_CSTRUCT_FORMAT);
2470 TRACE("(%p, %p, %p)\n", pStubMsg, pMemory, pFormat);
2472 if ((pCStructFormat->type != RPC_FC_CPSTRUCT) && (pCStructFormat->type != RPC_FC_CSTRUCT))
2474 ERR("invalid format type %x\n", pCStructFormat->type);
2475 RpcRaiseException(RPC_S_INTERNAL_ERROR);
2479 TRACE("memory_size = %d\n", pCStructFormat->memory_size);
2481 /* copy constant sized part of struct */
2482 memcpy(pStubMsg->Buffer, pMemory, pCStructFormat->memory_size);
2483 pStubMsg->Buffer += pCStructFormat->memory_size;
2485 if (pCStructFormat->offset_to_array_description)
2487 PFORMAT_STRING pArrayFormat = (unsigned char*)&pCStructFormat->offset_to_array_description +
2488 pCStructFormat->offset_to_array_description;
2489 NdrConformantArrayMarshall(pStubMsg, pMemory + pCStructFormat->memory_size, pArrayFormat);
2491 if (pCStructFormat->type == RPC_FC_CPSTRUCT)
2492 EmbeddedPointerMarshall(pStubMsg, pMemory, pFormat);
2496 /***********************************************************************
2497 * NdrConformantStructUnmarshall [RPCRT4.@]
2499 unsigned char * WINAPI NdrConformantStructUnmarshall(PMIDL_STUB_MESSAGE pStubMsg,
2500 unsigned char **ppMemory,
2501 PFORMAT_STRING pFormat,
2502 unsigned char fMustAlloc)
2504 const NDR_CSTRUCT_FORMAT * pCStructFormat = (NDR_CSTRUCT_FORMAT*)pFormat;
2505 pFormat += sizeof(NDR_CSTRUCT_FORMAT);
2507 TRACE("(%p, %p, %p, %d)\n", pStubMsg, ppMemory, pFormat, fMustAlloc);
2509 if ((pCStructFormat->type != RPC_FC_CPSTRUCT) && (pCStructFormat->type != RPC_FC_CSTRUCT))
2511 ERR("invalid format type %x\n", pCStructFormat->type);
2512 RpcRaiseException(RPC_S_INTERNAL_ERROR);
2516 TRACE("memory_size = %d\n", pCStructFormat->memory_size);
2518 /* work out how much memory to allocate if we need to do so */
2519 if (!*ppMemory || fMustAlloc)
2521 SIZE_T size = pCStructFormat->memory_size;
2523 if (pCStructFormat->offset_to_array_description)
2525 unsigned char *buffer;
2526 PFORMAT_STRING pArrayFormat = (unsigned char*)&pCStructFormat->offset_to_array_description +
2527 pCStructFormat->offset_to_array_description;
2528 buffer = pStubMsg->Buffer;
2529 pStubMsg->Buffer += pCStructFormat->memory_size;
2530 size += NdrConformantArrayMemorySize(pStubMsg, pArrayFormat);
2531 pStubMsg->Buffer = buffer;
2533 *ppMemory = NdrAllocate(pStubMsg, size);
2536 /* now copy the data */
2537 memcpy(*ppMemory, pStubMsg->Buffer, pCStructFormat->memory_size);
2538 pStubMsg->Buffer += pCStructFormat->memory_size;
2539 if (pCStructFormat->offset_to_array_description)
2541 PFORMAT_STRING pArrayFormat = (unsigned char*)&pCStructFormat->offset_to_array_description +
2542 pCStructFormat->offset_to_array_description;
2543 unsigned char *pMemoryArray = *ppMemory + pCStructFormat->memory_size;
2544 /* note that we pass fMustAlloc as 0 as we have already allocated the
2546 NdrConformantArrayUnmarshall(pStubMsg, &pMemoryArray, pArrayFormat, 0);
2548 if (pCStructFormat->type == RPC_FC_CPSTRUCT)
2549 EmbeddedPointerUnmarshall(pStubMsg, ppMemory, pFormat, fMustAlloc);
2553 /***********************************************************************
2554 * NdrConformantStructBufferSize [RPCRT4.@]
2556 void WINAPI NdrConformantStructBufferSize(PMIDL_STUB_MESSAGE pStubMsg,
2557 unsigned char *pMemory,
2558 PFORMAT_STRING pFormat)
2560 const NDR_CSTRUCT_FORMAT * pCStructFormat = (NDR_CSTRUCT_FORMAT*)pFormat;
2561 pFormat += sizeof(NDR_CSTRUCT_FORMAT);
2562 TRACE("(%p, %p, %p)\n", pStubMsg, pMemory, pFormat);
2564 if ((pCStructFormat->type != RPC_FC_CPSTRUCT) && (pCStructFormat->type != RPC_FC_CSTRUCT))
2566 ERR("invalid format type %x\n", pCStructFormat->type);
2567 RpcRaiseException(RPC_S_INTERNAL_ERROR);
2571 TRACE("memory_size = %d\n", pCStructFormat->memory_size);
2573 /* add constant sized part of struct to buffer size */
2574 pStubMsg->BufferLength += pCStructFormat->memory_size;
2576 if (pCStructFormat->offset_to_array_description)
2578 PFORMAT_STRING pArrayFormat = (unsigned char*)&pCStructFormat->offset_to_array_description +
2579 pCStructFormat->offset_to_array_description;
2580 NdrConformantArrayBufferSize(pStubMsg, pMemory + pCStructFormat->memory_size, pArrayFormat);
2582 if (pCStructFormat->type == RPC_FC_CPSTRUCT)
2583 EmbeddedPointerBufferSize(pStubMsg, pMemory, pFormat);
2586 /***********************************************************************
2587 * NdrConformantStructMemorySize [RPCRT4.@]
2589 unsigned long WINAPI NdrConformantStructMemorySize(PMIDL_STUB_MESSAGE pStubMsg,
2590 PFORMAT_STRING pFormat)
2596 /***********************************************************************
2597 * NdrConformantStructFree [RPCRT4.@]
2599 void WINAPI NdrConformantStructFree(PMIDL_STUB_MESSAGE pStubMsg,
2600 unsigned char *pMemory,
2601 PFORMAT_STRING pFormat)
2606 /***********************************************************************
2607 * NdrConformantVaryingStructMarshall [RPCRT4.@]
2609 unsigned char * WINAPI NdrConformantVaryingStructMarshall(PMIDL_STUB_MESSAGE pStubMsg,
2610 unsigned char *pMemory,
2611 PFORMAT_STRING pFormat)
2617 /***********************************************************************
2618 * NdrConformantVaryingStructUnmarshall [RPCRT4.@]
2620 unsigned char * WINAPI NdrConformantVaryingStructUnmarshall(PMIDL_STUB_MESSAGE pStubMsg,
2621 unsigned char **ppMemory,
2622 PFORMAT_STRING pFormat,
2623 unsigned char fMustAlloc)
2629 /***********************************************************************
2630 * NdrConformantVaryingStructBufferSize [RPCRT4.@]
2632 void WINAPI NdrConformantVaryingStructBufferSize(PMIDL_STUB_MESSAGE pStubMsg,
2633 unsigned char *pMemory,
2634 PFORMAT_STRING pFormat)
2639 /***********************************************************************
2640 * NdrConformantVaryingStructMemorySize [RPCRT4.@]
2642 unsigned long WINAPI NdrConformantVaryingStructMemorySize(PMIDL_STUB_MESSAGE pStubMsg,
2643 PFORMAT_STRING pFormat)
2649 /***********************************************************************
2650 * NdrConformantVaryingStructFree [RPCRT4.@]
2652 void WINAPI NdrConformantVaryingStructFree(PMIDL_STUB_MESSAGE pStubMsg,
2653 unsigned char *pMemory,
2654 PFORMAT_STRING pFormat)
2659 /***********************************************************************
2660 * NdrFixedArrayMarshall [RPCRT4.@]
2662 unsigned char * WINAPI NdrFixedArrayMarshall(PMIDL_STUB_MESSAGE pStubMsg,
2663 unsigned char *pMemory,
2664 PFORMAT_STRING pFormat)
2670 /***********************************************************************
2671 * NdrFixedArrayUnmarshall [RPCRT4.@]
2673 unsigned char * WINAPI NdrFixedArrayUnmarshall(PMIDL_STUB_MESSAGE pStubMsg,
2674 unsigned char **ppMemory,
2675 PFORMAT_STRING pFormat,
2676 unsigned char fMustAlloc)
2682 /***********************************************************************
2683 * NdrFixedArrayBufferSize [RPCRT4.@]
2685 void WINAPI NdrFixedArrayBufferSize(PMIDL_STUB_MESSAGE pStubMsg,
2686 unsigned char *pMemory,
2687 PFORMAT_STRING pFormat)
2692 /***********************************************************************
2693 * NdrFixedArrayMemorySize [RPCRT4.@]
2695 unsigned long WINAPI NdrFixedArrayMemorySize(PMIDL_STUB_MESSAGE pStubMsg,
2696 PFORMAT_STRING pFormat)
2702 /***********************************************************************
2703 * NdrFixedArrayFree [RPCRT4.@]
2705 void WINAPI NdrFixedArrayFree(PMIDL_STUB_MESSAGE pStubMsg,
2706 unsigned char *pMemory,
2707 PFORMAT_STRING pFormat)
2712 /***********************************************************************
2713 * NdrVaryingArrayMarshall [RPCRT4.@]
2715 unsigned char * WINAPI NdrVaryingArrayMarshall(PMIDL_STUB_MESSAGE pStubMsg,
2716 unsigned char *pMemory,
2717 PFORMAT_STRING pFormat)
2723 /***********************************************************************
2724 * NdrVaryingArrayUnmarshall [RPCRT4.@]
2726 unsigned char * WINAPI NdrVaryingArrayUnmarshall(PMIDL_STUB_MESSAGE pStubMsg,
2727 unsigned char **ppMemory,
2728 PFORMAT_STRING pFormat,
2729 unsigned char fMustAlloc)
2735 /***********************************************************************
2736 * NdrVaryingArrayBufferSize [RPCRT4.@]
2738 void WINAPI NdrVaryingArrayBufferSize(PMIDL_STUB_MESSAGE pStubMsg,
2739 unsigned char *pMemory,
2740 PFORMAT_STRING pFormat)
2745 /***********************************************************************
2746 * NdrVaryingArrayMemorySize [RPCRT4.@]
2748 unsigned long WINAPI NdrVaryingArrayMemorySize(PMIDL_STUB_MESSAGE pStubMsg,
2749 PFORMAT_STRING pFormat)
2755 /***********************************************************************
2756 * NdrVaryingArrayFree [RPCRT4.@]
2758 void WINAPI NdrVaryingArrayFree(PMIDL_STUB_MESSAGE pStubMsg,
2759 unsigned char *pMemory,
2760 PFORMAT_STRING pFormat)
2765 /***********************************************************************
2766 * NdrEncapsulatedUnionMarshall [RPCRT4.@]
2768 unsigned char * WINAPI NdrEncapsulatedUnionMarshall(PMIDL_STUB_MESSAGE pStubMsg,
2769 unsigned char *pMemory,
2770 PFORMAT_STRING pFormat)
2776 /***********************************************************************
2777 * NdrEncapsulatedUnionUnmarshall [RPCRT4.@]
2779 unsigned char * WINAPI NdrEncapsulatedUnionUnmarshall(PMIDL_STUB_MESSAGE pStubMsg,
2780 unsigned char **ppMemory,
2781 PFORMAT_STRING pFormat,
2782 unsigned char fMustAlloc)
2788 /***********************************************************************
2789 * NdrEncapsulatedUnionBufferSize [RPCRT4.@]
2791 void WINAPI NdrEncapsulatedUnionBufferSize(PMIDL_STUB_MESSAGE pStubMsg,
2792 unsigned char *pMemory,
2793 PFORMAT_STRING pFormat)
2798 /***********************************************************************
2799 * NdrEncapsulatedUnionMemorySize [RPCRT4.@]
2801 unsigned long WINAPI NdrEncapsulatedUnionMemorySize(PMIDL_STUB_MESSAGE pStubMsg,
2802 PFORMAT_STRING pFormat)
2808 /***********************************************************************
2809 * NdrEncapsulatedUnionFree [RPCRT4.@]
2811 void WINAPI NdrEncapsulatedUnionFree(PMIDL_STUB_MESSAGE pStubMsg,
2812 unsigned char *pMemory,
2813 PFORMAT_STRING pFormat)
2818 static PFORMAT_STRING get_arm_offset_from_union_arm_selector(PMIDL_STUB_MESSAGE pStubMsg,
2819 unsigned long discriminant,
2820 PFORMAT_STRING pFormat)
2822 unsigned short num_arms, arm, type;
2824 num_arms = *(const SHORT*)pFormat & 0x0fff;
2826 for(arm = 0; arm < num_arms; arm++)
2828 if(discriminant == *(const ULONG*)pFormat)
2836 type = *(const unsigned short*)pFormat;
2837 TRACE("type %04x\n", type);
2838 if(arm == num_arms) /* default arm extras */
2842 FIXME("should raise an exception here\n");
2847 /* Don't marshall any type. FIXME is this correct? */
2854 static PFORMAT_STRING get_non_encapsulated_union_arm(PMIDL_STUB_MESSAGE pStubMsg,
2855 unsigned char *pMemory,
2856 PFORMAT_STRING pFormat)
2860 pFormat = ComputeConformanceOrVariance(pStubMsg, pMemory, pFormat,
2862 TRACE("got switch value %lx\n", value);
2863 pFormat += *(const SHORT*)pFormat;
2866 return get_arm_offset_from_union_arm_selector(pStubMsg, value, pFormat);
2869 static unsigned char *get_conformance_address(PMIDL_STUB_MESSAGE pStubMsg,
2870 unsigned char *pMemory,
2871 PFORMAT_STRING pFormat)
2873 short ofs = *(short *)&pFormat[2];
2876 switch (pFormat[0] & 0xf0)
2878 case RPC_FC_NORMAL_CONFORMANCE:
2882 FIXME("Conformance type %x\n", pFormat[0]);
2888 FIXME("Conformance op %x\n", pFormat[1]);
2892 return (unsigned char *)ptr + ofs;
2895 /***********************************************************************
2896 * NdrNonEncapsulatedUnionMarshall [RPCRT4.@]
2898 unsigned char * WINAPI NdrNonEncapsulatedUnionMarshall(PMIDL_STUB_MESSAGE pStubMsg,
2899 unsigned char *pMemory,
2900 PFORMAT_STRING pFormat)
2902 unsigned char *discriminant;
2903 unsigned short type;
2905 TRACE("(%p, %p, %p)\n", pStubMsg, pMemory, pFormat);
2908 /* Marshall discriminant */
2909 discriminant = get_conformance_address(pStubMsg, pMemory, pFormat + 1);
2910 NdrBaseTypeMarshall(pStubMsg, discriminant, pFormat);
2913 pFormat = get_non_encapsulated_union_arm(pStubMsg, pMemory, pFormat);
2917 type = *(const unsigned short*)pFormat;
2921 return NdrBaseTypeMarshall(pStubMsg, pMemory, pFormat);
2925 PFORMAT_STRING desc = pFormat + *(const SHORT*)pFormat;
2926 NDR_MARSHALL m = NdrMarshaller[*desc & NDR_TABLE_MASK];
2935 pMemory = *(void**)pMemory;
2938 m(pStubMsg, pMemory, desc);
2940 else FIXME("no marshaller for embedded type %02x\n", *desc);
2945 static long unmarshall_discriminant(PMIDL_STUB_MESSAGE pStubMsg,
2946 PFORMAT_STRING *ppFormat)
2948 long discriminant = 0;
2956 discriminant = *(UCHAR *)pStubMsg->Buffer;
2957 pStubMsg->Buffer += sizeof(UCHAR);
2962 ALIGN_POINTER(pStubMsg->Buffer, sizeof(USHORT) - 1);
2963 discriminant = *(USHORT *)pStubMsg->Buffer;
2964 pStubMsg->Buffer += sizeof(USHORT);
2968 ALIGN_POINTER(pStubMsg->Buffer, sizeof(ULONG) - 1);
2969 discriminant = *(ULONG *)pStubMsg->Buffer;
2970 pStubMsg->Buffer += sizeof(ULONG);
2973 FIXME("Unhandled base type: 0x%02x\n", **ppFormat);
2977 if (pStubMsg->fHasNewCorrDesc)
2981 return discriminant;
2984 /**********************************************************************
2985 * NdrNonEncapsulatedUnionUnmarshall[RPCRT4.@]
2987 unsigned char * WINAPI NdrNonEncapsulatedUnionUnmarshall(PMIDL_STUB_MESSAGE pStubMsg,
2988 unsigned char **ppMemory,
2989 PFORMAT_STRING pFormat,
2990 unsigned char fMustAlloc)
2993 unsigned short type, size;
2995 TRACE("(%p, %p, %p, %d)\n", pStubMsg, ppMemory, pFormat, fMustAlloc);
2998 /* Unmarshall discriminant */
2999 discriminant = unmarshall_discriminant(pStubMsg, &pFormat);
3000 TRACE("unmarshalled discriminant %lx\n", discriminant);
3002 pFormat += *(const SHORT*)pFormat;
3004 size = *(const unsigned short*)pFormat;
3007 pFormat = get_arm_offset_from_union_arm_selector(pStubMsg, discriminant, pFormat);
3011 if(!*ppMemory || fMustAlloc)
3012 *ppMemory = NdrAllocate(pStubMsg, size);
3014 type = *(const unsigned short*)pFormat;
3018 return NdrBaseTypeUnmarshall(pStubMsg, ppMemory, pFormat, fMustAlloc);
3022 PFORMAT_STRING desc = pFormat + *(const SHORT*)pFormat;
3023 NDR_UNMARSHALL m = NdrUnmarshaller[*desc & NDR_TABLE_MASK];
3032 **(void***)ppMemory = NULL;
3035 return m(pStubMsg, (unsigned char **)*ppMemory, desc, fMustAlloc);
3037 else FIXME("no marshaller for embedded type %02x\n", *desc);
3042 /***********************************************************************
3043 * NdrNonEncapsulatedUnionBufferSize [RPCRT4.@]
3045 void WINAPI NdrNonEncapsulatedUnionBufferSize(PMIDL_STUB_MESSAGE pStubMsg,
3046 unsigned char *pMemory,
3047 PFORMAT_STRING pFormat)
3049 unsigned short type;
3050 TRACE("(%p, %p, %p)\n", pStubMsg, pMemory, pFormat);
3053 /* Add discriminant size */
3054 NdrBaseTypeBufferSize(pStubMsg, pMemory, pFormat);
3057 pFormat = get_non_encapsulated_union_arm(pStubMsg, pMemory, pFormat);
3061 type = *(const unsigned short*)pFormat;
3065 NdrBaseTypeBufferSize(pStubMsg, pMemory, pFormat);
3069 PFORMAT_STRING desc = pFormat + *(const SHORT*)pFormat;
3070 NDR_BUFFERSIZE m = NdrBufferSizer[*desc & NDR_TABLE_MASK];
3079 pMemory = *(void**)pMemory;
3082 m(pStubMsg, pMemory, desc);
3084 else FIXME("no buffersizer for embedded type %02x\n", *desc);
3089 /***********************************************************************
3090 * NdrNonEncapsulatedUnionMemorySize [RPCRT4.@]
3092 unsigned long WINAPI NdrNonEncapsulatedUnionMemorySize(PMIDL_STUB_MESSAGE pStubMsg,
3093 PFORMAT_STRING pFormat)
3099 /***********************************************************************
3100 * NdrNonEncapsulatedUnionFree [RPCRT4.@]
3102 void WINAPI NdrNonEncapsulatedUnionFree(PMIDL_STUB_MESSAGE pStubMsg,
3103 unsigned char *pMemory,
3104 PFORMAT_STRING pFormat)
3109 /***********************************************************************
3110 * NdrByteCountPointerMarshall [RPCRT4.@]
3112 unsigned char * WINAPI NdrByteCountPointerMarshall(PMIDL_STUB_MESSAGE pStubMsg,
3113 unsigned char *pMemory,
3114 PFORMAT_STRING pFormat)
3120 /***********************************************************************
3121 * NdrByteCountPointerUnmarshall [RPCRT4.@]
3123 unsigned char * WINAPI NdrByteCountPointerUnmarshall(PMIDL_STUB_MESSAGE pStubMsg,
3124 unsigned char **ppMemory,
3125 PFORMAT_STRING pFormat,
3126 unsigned char fMustAlloc)
3132 /***********************************************************************
3133 * NdrByteCountPointerBufferSize [RPCRT4.@]
3135 void WINAPI NdrByteCountPointerBufferSize(PMIDL_STUB_MESSAGE pStubMsg,
3136 unsigned char *pMemory,
3137 PFORMAT_STRING pFormat)
3142 /***********************************************************************
3143 * NdrByteCountPointerMemorySize [RPCRT4.@]
3145 unsigned long WINAPI NdrByteCountPointerMemorySize(PMIDL_STUB_MESSAGE pStubMsg,
3146 PFORMAT_STRING pFormat)
3152 /***********************************************************************
3153 * NdrByteCountPointerFree [RPCRT4.@]
3155 void WINAPI NdrByteCountPointerFree(PMIDL_STUB_MESSAGE pStubMsg,
3156 unsigned char *pMemory,
3157 PFORMAT_STRING pFormat)
3162 /***********************************************************************
3163 * NdrXmitOrRepAsMarshall [RPCRT4.@]
3165 unsigned char * WINAPI NdrXmitOrRepAsMarshall(PMIDL_STUB_MESSAGE pStubMsg,
3166 unsigned char *pMemory,
3167 PFORMAT_STRING pFormat)
3173 /***********************************************************************
3174 * NdrXmitOrRepAsUnmarshall [RPCRT4.@]
3176 unsigned char * WINAPI NdrXmitOrRepAsUnmarshall(PMIDL_STUB_MESSAGE pStubMsg,
3177 unsigned char **ppMemory,
3178 PFORMAT_STRING pFormat,
3179 unsigned char fMustAlloc)
3185 /***********************************************************************
3186 * NdrXmitOrRepAsBufferSize [RPCRT4.@]
3188 void WINAPI NdrXmitOrRepAsBufferSize(PMIDL_STUB_MESSAGE pStubMsg,
3189 unsigned char *pMemory,
3190 PFORMAT_STRING pFormat)
3195 /***********************************************************************
3196 * NdrXmitOrRepAsMemorySize [RPCRT4.@]
3198 unsigned long WINAPI NdrXmitOrRepAsMemorySize(PMIDL_STUB_MESSAGE pStubMsg,
3199 PFORMAT_STRING pFormat)
3205 /***********************************************************************
3206 * NdrXmitOrRepAsFree [RPCRT4.@]
3208 void WINAPI NdrXmitOrRepAsFree(PMIDL_STUB_MESSAGE pStubMsg,
3209 unsigned char *pMemory,
3210 PFORMAT_STRING pFormat)
3215 /***********************************************************************
3216 * NdrBaseTypeMarshall [internal]
3218 static unsigned char *WINAPI NdrBaseTypeMarshall(
3219 PMIDL_STUB_MESSAGE pStubMsg,
3220 unsigned char *pMemory,
3221 PFORMAT_STRING pFormat)
3223 TRACE("pStubMsg %p, pMemory %p, type 0x%02x\n", pStubMsg, pMemory, *pFormat);
3231 *(UCHAR *)pStubMsg->Buffer = *(UCHAR *)pMemory;
3232 pStubMsg->Buffer += sizeof(UCHAR);
3233 TRACE("value: 0x%02x\n", *(UCHAR *)pMemory);
3238 ALIGN_POINTER(pStubMsg->Buffer, sizeof(USHORT) - 1);
3239 *(USHORT *)pStubMsg->Buffer = *(USHORT *)pMemory;
3240 pStubMsg->Buffer += sizeof(USHORT);
3241 TRACE("value: 0x%04x\n", *(USHORT *)pMemory);
3245 case RPC_FC_ERROR_STATUS_T:
3247 ALIGN_POINTER(pStubMsg->Buffer, sizeof(ULONG) - 1);
3248 *(ULONG *)pStubMsg->Buffer = *(ULONG *)pMemory;
3249 pStubMsg->Buffer += sizeof(ULONG);
3250 TRACE("value: 0x%08lx\n", *(ULONG *)pMemory);
3253 ALIGN_POINTER(pStubMsg->Buffer, sizeof(float) - 1);
3254 *(float *)pStubMsg->Buffer = *(float *)pMemory;
3255 pStubMsg->Buffer += sizeof(float);
3258 ALIGN_POINTER(pStubMsg->Buffer, sizeof(double) - 1);
3259 *(double *)pStubMsg->Buffer = *(double *)pMemory;
3260 pStubMsg->Buffer += sizeof(double);
3263 ALIGN_POINTER(pStubMsg->Buffer, sizeof(ULONGLONG) - 1);
3264 *(ULONGLONG *)pStubMsg->Buffer = *(ULONGLONG *)pMemory;
3265 pStubMsg->Buffer += sizeof(ULONGLONG);
3266 TRACE("value: %s\n", wine_dbgstr_longlong(*(ULONGLONG*)pMemory));
3269 /* only 16-bits on the wire, so do a sanity check */
3270 if (*(UINT *)pMemory > USHRT_MAX)
3271 RpcRaiseException(RPC_X_ENUM_VALUE_OUT_OF_RANGE);
3272 ALIGN_POINTER(pStubMsg->Buffer, sizeof(USHORT) - 1);
3273 *(USHORT *)pStubMsg->Buffer = *(UINT *)pMemory;
3274 pStubMsg->Buffer += sizeof(USHORT);
3275 TRACE("value: 0x%04x\n", *(UINT *)pMemory);
3278 FIXME("Unhandled base type: 0x%02x\n", *pFormat);
3281 STD_OVERFLOW_CHECK(pStubMsg);
3283 /* FIXME: what is the correct return value? */
3287 /***********************************************************************
3288 * NdrBaseTypeUnmarshall [internal]
3290 static unsigned char *WINAPI NdrBaseTypeUnmarshall(
3291 PMIDL_STUB_MESSAGE pStubMsg,
3292 unsigned char **ppMemory,
3293 PFORMAT_STRING pFormat,
3294 unsigned char fMustAlloc)
3296 TRACE("pStubMsg: %p, ppMemory: %p, type: 0x%02x, fMustAlloc: %s\n", pStubMsg, ppMemory, *pFormat, fMustAlloc ? "true" : "false");
3298 if (fMustAlloc || !*ppMemory)
3299 *ppMemory = NdrAllocate(pStubMsg, NdrBaseTypeMemorySize(pStubMsg, pFormat));
3301 TRACE("*ppMemory: %p\n", *ppMemory);
3309 **(UCHAR **)ppMemory = *(UCHAR *)pStubMsg->Buffer;
3310 pStubMsg->Buffer += sizeof(UCHAR);
3311 TRACE("value: 0x%02x\n", **(UCHAR **)ppMemory);
3316 ALIGN_POINTER(pStubMsg->Buffer, sizeof(USHORT) - 1);
3317 **(USHORT **)ppMemory = *(USHORT *)pStubMsg->Buffer;
3318 pStubMsg->Buffer += sizeof(USHORT);
3319 TRACE("value: 0x%04x\n", **(USHORT **)ppMemory);
3323 case RPC_FC_ERROR_STATUS_T:
3325 ALIGN_POINTER(pStubMsg->Buffer, sizeof(ULONG) - 1);
3326 **(ULONG **)ppMemory = *(ULONG *)pStubMsg->Buffer;
3327 pStubMsg->Buffer += sizeof(ULONG);
3328 TRACE("value: 0x%08lx\n", **(ULONG **)ppMemory);
3331 ALIGN_POINTER(pStubMsg->Buffer, sizeof(float) - 1);
3332 **(float **)ppMemory = *(float *)pStubMsg->Buffer;
3333 pStubMsg->Buffer += sizeof(float);
3334 TRACE("value: %f\n", **(float **)ppMemory);
3337 ALIGN_POINTER(pStubMsg->Buffer, sizeof(double) - 1);
3338 **(double **)ppMemory = *(double*)pStubMsg->Buffer;
3339 pStubMsg->Buffer += sizeof(double);
3340 TRACE("value: %f\n", **(double **)ppMemory);
3343 ALIGN_POINTER(pStubMsg->Buffer, sizeof(ULONGLONG) - 1);
3344 **(ULONGLONG **)ppMemory = *(ULONGLONG *)pStubMsg->Buffer;
3345 pStubMsg->Buffer += sizeof(ULONGLONG);
3346 TRACE("value: %s\n", wine_dbgstr_longlong(**(ULONGLONG **)ppMemory));
3349 ALIGN_POINTER(pStubMsg->Buffer, sizeof(USHORT) - 1);
3350 /* 16-bits on the wire, but int in memory */
3351 **(UINT **)ppMemory = *(USHORT *)pStubMsg->Buffer;
3352 pStubMsg->Buffer += sizeof(USHORT);
3353 TRACE("value: 0x%08x\n", **(UINT **)ppMemory);
3356 FIXME("Unhandled base type: 0x%02x\n", *pFormat);
3359 /* FIXME: what is the correct return value? */
3364 /***********************************************************************
3365 * NdrBaseTypeBufferSize [internal]
3367 static void WINAPI NdrBaseTypeBufferSize(
3368 PMIDL_STUB_MESSAGE pStubMsg,
3369 unsigned char *pMemory,
3370 PFORMAT_STRING pFormat)
3372 TRACE("pStubMsg %p, pMemory %p, type 0x%02x\n", pStubMsg, pMemory, *pFormat);
3380 pStubMsg->BufferLength += sizeof(UCHAR);
3386 ALIGN_LENGTH(pStubMsg->BufferLength, sizeof(USHORT) - 1);
3387 pStubMsg->BufferLength += sizeof(USHORT);
3392 ALIGN_LENGTH(pStubMsg->BufferLength, sizeof(ULONG) - 1);
3393 pStubMsg->BufferLength += sizeof(ULONG);
3396 ALIGN_LENGTH(pStubMsg->BufferLength, sizeof(float) - 1);
3397 pStubMsg->BufferLength += sizeof(float);
3400 ALIGN_LENGTH(pStubMsg->BufferLength, sizeof(double) - 1);
3401 pStubMsg->BufferLength += sizeof(double);
3404 ALIGN_LENGTH(pStubMsg->BufferLength, sizeof(ULONGLONG) - 1);
3405 pStubMsg->BufferLength += sizeof(ULONGLONG);
3407 case RPC_FC_ERROR_STATUS_T:
3408 ALIGN_LENGTH(pStubMsg->BufferLength, sizeof(error_status_t) - 1);
3409 pStubMsg->BufferLength += sizeof(error_status_t);
3412 FIXME("Unhandled base type: 0x%02x\n", *pFormat);
3416 /***********************************************************************
3417 * NdrBaseTypeMemorySize [internal]
3419 static unsigned long WINAPI NdrBaseTypeMemorySize(
3420 PMIDL_STUB_MESSAGE pStubMsg,
3421 PFORMAT_STRING pFormat)
3429 return sizeof(UCHAR);
3433 return sizeof(USHORT);
3436 return sizeof(ULONG);
3438 return sizeof(float);
3440 return sizeof(double);
3442 return sizeof(ULONGLONG);
3443 case RPC_FC_ERROR_STATUS_T:
3444 return sizeof(error_status_t);
3449 FIXME("Unhandled base type: 0x%02x\n", *pFormat);
3454 /***********************************************************************
3455 * NdrBaseTypeFree [internal]
3457 static void WINAPI NdrBaseTypeFree(PMIDL_STUB_MESSAGE pStubMsg,
3458 unsigned char *pMemory,
3459 PFORMAT_STRING pFormat)
3461 TRACE("pStubMsg %p pMemory %p type 0x%02x\n", pStubMsg, pMemory, *pFormat);
3466 /***********************************************************************
3467 * NdrClientContextMarshall
3469 void WINAPI NdrClientContextMarshall(PMIDL_STUB_MESSAGE pStubMsg,
3470 NDR_CCONTEXT ContextHandle,
3473 FIXME("(%p, %p, %d): stub\n", pStubMsg, ContextHandle, fCheck);
3476 /***********************************************************************
3477 * NdrClientContextUnmarshall
3479 void WINAPI NdrClientContextUnmarshall(PMIDL_STUB_MESSAGE pStubMsg,
3480 NDR_CCONTEXT * pContextHandle,
3481 RPC_BINDING_HANDLE BindHandle)
3483 FIXME("(%p, %p, %p): stub\n", pStubMsg, pContextHandle, BindHandle);
3486 void WINAPI NdrServerContextMarshall(PMIDL_STUB_MESSAGE pStubMsg,
3487 NDR_SCONTEXT ContextHandle,
3488 NDR_RUNDOWN RundownRoutine )
3490 FIXME("(%p, %p, %p): stub\n", pStubMsg, ContextHandle, RundownRoutine);
3493 NDR_SCONTEXT WINAPI NdrServerContextUnmarshall(PMIDL_STUB_MESSAGE pStubMsg)
3495 FIXME("(%p): stub\n", pStubMsg);
3499 void WINAPI NdrContextHandleSize(PMIDL_STUB_MESSAGE pStubMsg,
3500 unsigned char* pMemory,
3501 PFORMAT_STRING pFormat)
3503 FIXME("(%p, %p, %p): stub\n", pStubMsg, pMemory, pFormat);
3506 NDR_SCONTEXT WINAPI NdrContextHandleInitialize(PMIDL_STUB_MESSAGE pStubMsg,
3507 PFORMAT_STRING pFormat)
3509 FIXME("(%p, %p): stub\n", pStubMsg, pFormat);
3513 void WINAPI NdrServerContextNewMarshall(PMIDL_STUB_MESSAGE pStubMsg,
3514 NDR_SCONTEXT ContextHandle,
3515 NDR_RUNDOWN RundownRoutine,
3516 PFORMAT_STRING pFormat)
3518 FIXME("(%p, %p, %p, %p): stub\n", pStubMsg, ContextHandle, RundownRoutine, pFormat);
3521 NDR_SCONTEXT WINAPI NdrServerContextNewUnmarshall(PMIDL_STUB_MESSAGE pStubMsg,
3522 PFORMAT_STRING pFormat)
3524 FIXME("(%p, %p): stub\n", pStubMsg, pFormat);
3528 RPC_BINDING_HANDLE WINAPI NDRCContextBinding(NDR_CCONTEXT CContext)
3530 FIXME("(%p): stub\n", CContext);