4 * Copyright 2002 Greg Turner
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 * - figure out whether we *really* got this right
22 * - check for errors and throw exceptions
39 #include "wine/unicode.h"
40 #include "wine/rpcfc.h"
42 #include "wine/debug.h"
44 WINE_DEFAULT_DEBUG_CHANNEL(ole
);
47 # define LITTLE_ENDIAN_UINT32_WRITE(pchar, uint32) \
48 (*((UINT32 *)(pchar)) = (uint32))
50 # define LITTLE_ENDIAN_UINT32_READ(pchar) \
51 (*((UINT32 *)(pchar)))
53 /* these would work for i386 too, but less efficient */
54 # define LITTLE_ENDIAN_UINT32_WRITE(pchar, uint32) \
55 (*(pchar) = LOBYTE(LOWORD(uint32)), \
56 *((pchar)+1) = HIBYTE(LOWORD(uint32)), \
57 *((pchar)+2) = LOBYTE(HIWORD(uint32)), \
58 *((pchar)+3) = HIBYTE(HIWORD(uint32)), \
59 (uint32)) /* allow as r-value */
61 # define LITTLE_ENDIAN_UINT32_READ(pchar) \
63 MAKEWORD(*(pchar), *((pchar)+1)), \
64 MAKEWORD(*((pchar)+2), *((pchar)+3))))
67 #define BIG_ENDIAN_UINT32_WRITE(pchar, uint32) \
68 (*((pchar)+3) = LOBYTE(LOWORD(uint32)), \
69 *((pchar)+2) = HIBYTE(LOWORD(uint32)), \
70 *((pchar)+1) = LOBYTE(HIWORD(uint32)), \
71 *(pchar) = HIBYTE(HIWORD(uint32)), \
72 (uint32)) /* allow as r-value */
74 #define BIG_ENDIAN_UINT32_READ(pchar) \
76 MAKEWORD(*((pchar)+3), *((pchar)+2)), \
77 MAKEWORD(*((pchar)+1), *(pchar))))
79 #ifdef NDR_LOCAL_IS_BIG_ENDIAN
80 # define NDR_LOCAL_UINT32_WRITE(pchar, uint32) \
81 BIG_ENDIAN_UINT32_WRITE(pchar, uint32)
82 # define NDR_LOCAL_UINT32_READ(pchar) \
83 BIG_ENDIAN_UINT32_READ(pchar)
85 # define NDR_LOCAL_UINT32_WRITE(pchar, uint32) \
86 LITTLE_ENDIAN_UINT32_WRITE(pchar, uint32)
87 # define NDR_LOCAL_UINT32_READ(pchar) \
88 LITTLE_ENDIAN_UINT32_READ(pchar)
91 /* _Align must be the desired alignment,
92 * e.g. ALIGN_LENGTH(len, 4) to align on a dword boundary. */
93 #define ALIGNED_LENGTH(_Len, _Align) (((_Len)+(_Align)-1)&~((_Align)-1))
94 #define ALIGNED_POINTER(_Ptr, _Align) ((LPVOID)ALIGNED_LENGTH((ULONG_PTR)(_Ptr), _Align))
95 #define ALIGN_LENGTH(_Len, _Align) _Len = ALIGNED_LENGTH(_Len, _Align)
96 #define ALIGN_POINTER(_Ptr, _Align) _Ptr = ALIGNED_POINTER(_Ptr, _Align)
98 #define STD_OVERFLOW_CHECK(_Msg) do { \
99 TRACE("buffer=%d/%ld\n", _Msg->Buffer - (unsigned char *)_Msg->RpcMsg->Buffer, _Msg->BufferLength); \
100 if (_Msg->Buffer > (unsigned char *)_Msg->RpcMsg->Buffer + _Msg->BufferLength) \
101 ERR("buffer overflow %d bytes\n", _Msg->Buffer - ((unsigned char *)_Msg->RpcMsg->Buffer + _Msg->BufferLength)); \
104 #define NDR_TABLE_SIZE 128
105 #define NDR_TABLE_MASK 127
107 static unsigned char *WINAPI
NdrBaseTypeMarshall(PMIDL_STUB_MESSAGE
, unsigned char *, PFORMAT_STRING
);
108 static unsigned char *WINAPI
NdrBaseTypeUnmarshall(PMIDL_STUB_MESSAGE
, unsigned char **, PFORMAT_STRING
, unsigned char);
109 static void WINAPI
NdrBaseTypeBufferSize(PMIDL_STUB_MESSAGE
, unsigned char *, PFORMAT_STRING
);
110 static void WINAPI
NdrBaseTypeFree(PMIDL_STUB_MESSAGE
, unsigned char *, PFORMAT_STRING
);
111 static unsigned long WINAPI
NdrBaseTypeMemorySize(PMIDL_STUB_MESSAGE
, PFORMAT_STRING
);
113 const NDR_MARSHALL NdrMarshaller
[NDR_TABLE_SIZE
] = {
115 NdrBaseTypeMarshall
, NdrBaseTypeMarshall
, NdrBaseTypeMarshall
,
116 NdrBaseTypeMarshall
, NdrBaseTypeMarshall
, NdrBaseTypeMarshall
, NdrBaseTypeMarshall
,
117 NdrBaseTypeMarshall
, NdrBaseTypeMarshall
, NdrBaseTypeMarshall
, NdrBaseTypeMarshall
,
118 NdrBaseTypeMarshall
, NdrBaseTypeMarshall
, NdrBaseTypeMarshall
, NdrBaseTypeMarshall
,
122 NdrPointerMarshall
, NdrPointerMarshall
,
123 NdrPointerMarshall
, NdrPointerMarshall
,
125 NdrSimpleStructMarshall
, NdrSimpleStructMarshall
,
126 NdrConformantStructMarshall
, NdrConformantStructMarshall
,
127 NdrConformantVaryingStructMarshall
,
128 NdrComplexStructMarshall
,
130 NdrConformantArrayMarshall
,
131 NdrConformantVaryingArrayMarshall
,
132 NdrFixedArrayMarshall
, NdrFixedArrayMarshall
,
133 NdrVaryingArrayMarshall
, NdrVaryingArrayMarshall
,
134 NdrComplexArrayMarshall
,
136 NdrConformantStringMarshall
, 0, 0,
137 NdrConformantStringMarshall
,
138 NdrNonConformantStringMarshall
, 0, 0, 0,
140 NdrEncapsulatedUnionMarshall
,
141 NdrNonEncapsulatedUnionMarshall
,
142 NdrByteCountPointerMarshall
,
143 NdrXmitOrRepAsMarshall
, NdrXmitOrRepAsMarshall
,
145 NdrInterfacePointerMarshall
,
148 NdrUserMarshalMarshall
150 const NDR_UNMARSHALL NdrUnmarshaller
[NDR_TABLE_SIZE
] = {
152 NdrBaseTypeUnmarshall
, NdrBaseTypeUnmarshall
, NdrBaseTypeUnmarshall
,
153 NdrBaseTypeUnmarshall
, NdrBaseTypeUnmarshall
, NdrBaseTypeUnmarshall
, NdrBaseTypeUnmarshall
,
154 NdrBaseTypeUnmarshall
, NdrBaseTypeUnmarshall
, NdrBaseTypeUnmarshall
, NdrBaseTypeUnmarshall
,
155 NdrBaseTypeUnmarshall
, NdrBaseTypeUnmarshall
, NdrBaseTypeUnmarshall
, NdrBaseTypeUnmarshall
,
157 NdrBaseTypeUnmarshall
,
159 NdrPointerUnmarshall
, NdrPointerUnmarshall
,
160 NdrPointerUnmarshall
, NdrPointerUnmarshall
,
162 NdrSimpleStructUnmarshall
, NdrSimpleStructUnmarshall
,
163 NdrConformantStructUnmarshall
, NdrConformantStructUnmarshall
,
164 NdrConformantVaryingStructUnmarshall
,
165 NdrComplexStructUnmarshall
,
167 NdrConformantArrayUnmarshall
,
168 NdrConformantVaryingArrayUnmarshall
,
169 NdrFixedArrayUnmarshall
, NdrFixedArrayUnmarshall
,
170 NdrVaryingArrayUnmarshall
, NdrVaryingArrayUnmarshall
,
171 NdrComplexArrayUnmarshall
,
173 NdrConformantStringUnmarshall
, 0, 0,
174 NdrConformantStringUnmarshall
,
175 NdrNonConformantStringUnmarshall
, 0, 0, 0,
177 NdrEncapsulatedUnionUnmarshall
,
178 NdrNonEncapsulatedUnionUnmarshall
,
179 NdrByteCountPointerUnmarshall
,
180 NdrXmitOrRepAsUnmarshall
, NdrXmitOrRepAsUnmarshall
,
182 NdrInterfacePointerUnmarshall
,
185 NdrUserMarshalUnmarshall
187 const NDR_BUFFERSIZE NdrBufferSizer
[NDR_TABLE_SIZE
] = {
189 NdrBaseTypeBufferSize
, NdrBaseTypeBufferSize
, NdrBaseTypeBufferSize
,
190 NdrBaseTypeBufferSize
, NdrBaseTypeBufferSize
, NdrBaseTypeBufferSize
, NdrBaseTypeBufferSize
,
191 NdrBaseTypeBufferSize
, NdrBaseTypeBufferSize
, NdrBaseTypeBufferSize
, NdrBaseTypeBufferSize
,
192 NdrBaseTypeBufferSize
, NdrBaseTypeBufferSize
, NdrBaseTypeBufferSize
, NdrBaseTypeBufferSize
,
194 NdrBaseTypeBufferSize
,
196 NdrPointerBufferSize
, NdrPointerBufferSize
,
197 NdrPointerBufferSize
, NdrPointerBufferSize
,
199 NdrSimpleStructBufferSize
, NdrSimpleStructBufferSize
,
200 NdrConformantStructBufferSize
, NdrConformantStructBufferSize
,
201 NdrConformantVaryingStructBufferSize
,
202 NdrComplexStructBufferSize
,
204 NdrConformantArrayBufferSize
,
205 NdrConformantVaryingArrayBufferSize
,
206 NdrFixedArrayBufferSize
, NdrFixedArrayBufferSize
,
207 NdrVaryingArrayBufferSize
, NdrVaryingArrayBufferSize
,
208 NdrComplexArrayBufferSize
,
210 NdrConformantStringBufferSize
, 0, 0,
211 NdrConformantStringBufferSize
,
212 NdrNonConformantStringBufferSize
, 0, 0, 0,
214 NdrEncapsulatedUnionBufferSize
,
215 NdrNonEncapsulatedUnionBufferSize
,
216 NdrByteCountPointerBufferSize
,
217 NdrXmitOrRepAsBufferSize
, NdrXmitOrRepAsBufferSize
,
219 NdrInterfacePointerBufferSize
,
222 NdrUserMarshalBufferSize
224 const NDR_MEMORYSIZE NdrMemorySizer
[NDR_TABLE_SIZE
] = {
226 NdrBaseTypeMemorySize
, NdrBaseTypeMemorySize
, NdrBaseTypeMemorySize
,
227 NdrBaseTypeMemorySize
, NdrBaseTypeMemorySize
, NdrBaseTypeMemorySize
, NdrBaseTypeMemorySize
,
228 NdrBaseTypeMemorySize
, NdrBaseTypeMemorySize
, NdrBaseTypeMemorySize
, NdrBaseTypeMemorySize
,
229 NdrBaseTypeMemorySize
, NdrBaseTypeMemorySize
, NdrBaseTypeMemorySize
, NdrBaseTypeMemorySize
,
231 NdrBaseTypeMemorySize
,
233 NdrPointerMemorySize
, NdrPointerMemorySize
,
234 NdrPointerMemorySize
, NdrPointerMemorySize
,
236 NdrSimpleStructMemorySize
, NdrSimpleStructMemorySize
,
237 NdrConformantStructMemorySize
, NdrConformantStructMemorySize
,
238 NdrConformantVaryingStructMemorySize
,
239 NdrComplexStructMemorySize
,
241 NdrConformantArrayMemorySize
,
242 NdrConformantVaryingArrayMemorySize
,
243 NdrFixedArrayMemorySize
, NdrFixedArrayMemorySize
,
244 NdrVaryingArrayMemorySize
, NdrVaryingArrayMemorySize
,
245 NdrComplexArrayMemorySize
,
247 NdrConformantStringMemorySize
, 0, 0,
248 NdrConformantStringMemorySize
,
249 NdrNonConformantStringMemorySize
, 0, 0, 0,
251 NdrEncapsulatedUnionMemorySize
,
252 NdrNonEncapsulatedUnionMemorySize
,
253 NdrByteCountPointerMemorySize
,
254 NdrXmitOrRepAsMemorySize
, NdrXmitOrRepAsMemorySize
,
256 NdrInterfacePointerMemorySize
,
259 NdrUserMarshalMemorySize
261 const NDR_FREE NdrFreer
[NDR_TABLE_SIZE
] = {
263 NdrBaseTypeFree
, NdrBaseTypeFree
, NdrBaseTypeFree
,
264 NdrBaseTypeFree
, NdrBaseTypeFree
, NdrBaseTypeFree
, NdrBaseTypeFree
,
265 NdrBaseTypeFree
, NdrBaseTypeFree
, NdrBaseTypeFree
, NdrBaseTypeFree
,
266 NdrBaseTypeFree
, NdrBaseTypeFree
, NdrBaseTypeFree
, NdrBaseTypeFree
,
270 NdrPointerFree
, NdrPointerFree
,
271 NdrPointerFree
, NdrPointerFree
,
273 NdrSimpleStructFree
, NdrSimpleStructFree
,
274 NdrConformantStructFree
, NdrConformantStructFree
,
275 NdrConformantVaryingStructFree
,
276 NdrComplexStructFree
,
278 NdrConformantArrayFree
,
279 NdrConformantVaryingArrayFree
,
280 NdrFixedArrayFree
, NdrFixedArrayFree
,
281 NdrVaryingArrayFree
, NdrVaryingArrayFree
,
287 NdrEncapsulatedUnionFree
,
288 NdrNonEncapsulatedUnionFree
,
290 NdrXmitOrRepAsFree
, NdrXmitOrRepAsFree
,
292 NdrInterfacePointerFree
,
298 void * WINAPI
NdrAllocate(MIDL_STUB_MESSAGE
*pStubMsg
, size_t len
)
300 /* hmm, this is probably supposed to do more? */
301 return pStubMsg
->pfnAllocate(len
);
304 static void WINAPI
NdrFree(MIDL_STUB_MESSAGE
*pStubMsg
, unsigned char *Pointer
)
306 pStubMsg
->pfnFree(Pointer
);
309 static inline BOOL
IsConformanceOrVariancePresent(PFORMAT_STRING pFormat
)
311 return (*(const ULONG
*)pFormat
!= -1);
314 PFORMAT_STRING
ReadConformance(MIDL_STUB_MESSAGE
*pStubMsg
, PFORMAT_STRING pFormat
)
316 ALIGN_POINTER(pStubMsg
->Buffer
, 4);
317 pStubMsg
->MaxCount
= NDR_LOCAL_UINT32_READ(pStubMsg
->Buffer
);
318 pStubMsg
->Buffer
+= 4;
319 TRACE("unmarshalled conformance is %ld\n", pStubMsg
->MaxCount
);
320 if (pStubMsg
->fHasNewCorrDesc
)
326 static inline PFORMAT_STRING
ReadVariance(MIDL_STUB_MESSAGE
*pStubMsg
, PFORMAT_STRING pFormat
)
328 if (pFormat
&& !IsConformanceOrVariancePresent(pFormat
))
330 pStubMsg
->Offset
= 0;
331 pStubMsg
->ActualCount
= pStubMsg
->MaxCount
;
335 ALIGN_POINTER(pStubMsg
->Buffer
, 4);
336 pStubMsg
->Offset
= NDR_LOCAL_UINT32_READ(pStubMsg
->Buffer
);
337 pStubMsg
->Buffer
+= 4;
338 TRACE("offset is %ld\n", pStubMsg
->Offset
);
339 pStubMsg
->ActualCount
= NDR_LOCAL_UINT32_READ(pStubMsg
->Buffer
);
340 pStubMsg
->Buffer
+= 4;
341 TRACE("variance is %ld\n", pStubMsg
->ActualCount
);
344 if (pStubMsg
->fHasNewCorrDesc
)
350 /* writes the conformance value to the buffer */
351 static inline void WriteConformance(MIDL_STUB_MESSAGE
*pStubMsg
)
353 ALIGN_POINTER(pStubMsg
->Buffer
, 4);
354 NDR_LOCAL_UINT32_WRITE(pStubMsg
->Buffer
, pStubMsg
->MaxCount
);
355 pStubMsg
->Buffer
+= 4;
358 /* writes the variance values to the buffer */
359 static inline void WriteVariance(MIDL_STUB_MESSAGE
*pStubMsg
)
361 ALIGN_POINTER(pStubMsg
->Buffer
, 4);
362 NDR_LOCAL_UINT32_WRITE(pStubMsg
->Buffer
, pStubMsg
->Offset
);
363 pStubMsg
->Buffer
+= 4;
364 NDR_LOCAL_UINT32_WRITE(pStubMsg
->Buffer
, pStubMsg
->ActualCount
);
365 pStubMsg
->Buffer
+= 4;
368 /* requests buffer space for the conformance value */
369 static inline void SizeConformance(MIDL_STUB_MESSAGE
*pStubMsg
)
371 ALIGN_LENGTH(pStubMsg
->BufferLength
, 4);
372 pStubMsg
->BufferLength
+= 4;
375 /* requests buffer space for the variance values */
376 static inline void SizeVariance(MIDL_STUB_MESSAGE
*pStubMsg
)
378 ALIGN_LENGTH(pStubMsg
->BufferLength
, 4);
379 pStubMsg
->BufferLength
+= 8;
382 PFORMAT_STRING
ComputeConformanceOrVariance(
383 MIDL_STUB_MESSAGE
*pStubMsg
, unsigned char *pMemory
,
384 PFORMAT_STRING pFormat
, ULONG_PTR def
, ULONG
*pCount
)
386 BYTE dtype
= pFormat
[0] & 0xf;
387 short ofs
= *(short *)&pFormat
[2];
391 if (!IsConformanceOrVariancePresent(pFormat
)) {
392 /* null descriptor */
397 switch (pFormat
[0] & 0xf0) {
398 case RPC_FC_NORMAL_CONFORMANCE
:
399 TRACE("normal conformance, ofs=%d\n", ofs
);
402 case RPC_FC_POINTER_CONFORMANCE
:
403 TRACE("pointer conformance, ofs=%d\n", ofs
);
404 ptr
= pStubMsg
->Memory
;
406 case RPC_FC_TOP_LEVEL_CONFORMANCE
:
407 TRACE("toplevel conformance, ofs=%d\n", ofs
);
408 if (pStubMsg
->StackTop
) {
409 ptr
= pStubMsg
->StackTop
;
412 /* -Os mode, *pCount is already set */
416 case RPC_FC_CONSTANT_CONFORMANCE
:
417 data
= ofs
| ((DWORD
)pFormat
[1] << 16);
418 TRACE("constant conformance, val=%ld\n", data
);
421 case RPC_FC_TOP_LEVEL_MULTID_CONFORMANCE
:
422 FIXME("toplevel multidimensional conformance, ofs=%d\n", ofs
);
423 if (pStubMsg
->StackTop
) {
424 ptr
= pStubMsg
->StackTop
;
432 FIXME("unknown conformance type %x\n", pFormat
[0] & 0xf0);
435 switch (pFormat
[1]) {
436 case RPC_FC_DEREFERENCE
:
437 ptr
= *(LPVOID
*)((char *)ptr
+ ofs
);
439 case RPC_FC_CALLBACK
:
441 unsigned char *old_stack_top
= pStubMsg
->StackTop
;
442 pStubMsg
->StackTop
= ptr
;
444 /* ofs is index into StubDesc->apfnExprEval */
445 TRACE("callback conformance into apfnExprEval[%d]\n", ofs
);
446 pStubMsg
->StubDesc
->apfnExprEval
[ofs
](pStubMsg
);
448 pStubMsg
->StackTop
= old_stack_top
;
452 ptr
= (char *)ptr
+ ofs
;
465 data
= *(USHORT
*)ptr
;
476 FIXME("unknown conformance data type %x\n", dtype
);
479 TRACE("dereferenced data type %x at %p, got %ld\n", dtype
, ptr
, data
);
482 switch (pFormat
[1]) {
486 case RPC_FC_DEREFERENCE
:
487 /* already handled */
502 FIXME("unknown conformance op %d\n", pFormat
[1]);
507 TRACE("resulting conformance is %ld\n", *pCount
);
508 if (pStubMsg
->fHasNewCorrDesc
)
516 * NdrConformantString:
518 * What MS calls a ConformantString is, in DCE terminology,
519 * a Varying-Conformant String.
521 * maxlen: DWORD (max # of CHARTYPE characters, inclusive of '\0')
522 * offset: DWORD (actual string data begins at (offset) CHARTYPE's
523 * into unmarshalled string)
524 * length: DWORD (# of CHARTYPE characters, inclusive of '\0')
526 * data: CHARTYPE[maxlen]
528 * ], where CHARTYPE is the appropriate character type (specified externally)
532 /***********************************************************************
533 * NdrConformantStringMarshall [RPCRT4.@]
535 unsigned char *WINAPI
NdrConformantStringMarshall(MIDL_STUB_MESSAGE
*pStubMsg
,
536 unsigned char *pszMessage
, PFORMAT_STRING pFormat
)
540 TRACE("(pStubMsg == ^%p, pszMessage == ^%p, pFormat == ^%p)\n", pStubMsg
, pszMessage
, pFormat
);
542 if (*pFormat
== RPC_FC_C_CSTRING
) {
543 TRACE("string=%s\n", debugstr_a((char*)pszMessage
));
544 pStubMsg
->ActualCount
= strlen((char*)pszMessage
)+1;
547 else if (*pFormat
== RPC_FC_C_WSTRING
) {
548 TRACE("string=%s\n", debugstr_w((LPWSTR
)pszMessage
));
549 pStubMsg
->ActualCount
= strlenW((LPWSTR
)pszMessage
)+1;
553 ERR("Unhandled string type: %#x\n", *pFormat
);
554 /* FIXME: raise an exception. */
558 if (pFormat
[1] == RPC_FC_STRING_SIZED
)
559 pFormat
= ComputeConformance(pStubMsg
, pszMessage
, pFormat
+ 2, 0);
561 pStubMsg
->MaxCount
= pStubMsg
->ActualCount
;
562 pStubMsg
->Offset
= 0;
563 WriteConformance(pStubMsg
);
564 WriteVariance(pStubMsg
);
566 memcpy(pStubMsg
->Buffer
, pszMessage
, pStubMsg
->ActualCount
*esize
); /* the string itself */
567 pStubMsg
->Buffer
+= pStubMsg
->ActualCount
*esize
;
569 STD_OVERFLOW_CHECK(pStubMsg
);
572 return NULL
; /* is this always right? */
575 /***********************************************************************
576 * NdrConformantStringBufferSize [RPCRT4.@]
578 void WINAPI
NdrConformantStringBufferSize(PMIDL_STUB_MESSAGE pStubMsg
,
579 unsigned char* pMemory
, PFORMAT_STRING pFormat
)
581 TRACE("(pStubMsg == ^%p, pMemory == ^%p, pFormat == ^%p)\n", pStubMsg
, pMemory
, pFormat
);
583 SizeConformance(pStubMsg
);
584 SizeVariance(pStubMsg
);
586 if (*pFormat
== RPC_FC_C_CSTRING
) {
587 /* we need + 1 octet for '\0' */
588 TRACE("string=%s\n", debugstr_a((char*)pMemory
));
589 pStubMsg
->BufferLength
+= strlen((char*)pMemory
) + 1;
591 else if (*pFormat
== RPC_FC_C_WSTRING
) {
592 /* we need + 2 octets for L'\0' */
593 TRACE("string=%s\n", debugstr_w((LPWSTR
)pMemory
));
594 pStubMsg
->BufferLength
+= strlenW((LPWSTR
)pMemory
)*2 + 2;
597 ERR("Unhandled string type: %#x\n", *pFormat
);
598 /* FIXME: raise an exception */
602 /************************************************************************
603 * NdrConformantStringMemorySize [RPCRT4.@]
605 unsigned long WINAPI
NdrConformantStringMemorySize( PMIDL_STUB_MESSAGE pStubMsg
,
606 PFORMAT_STRING pFormat
)
608 unsigned long rslt
= 0;
610 TRACE("(pStubMsg == ^%p, pFormat == ^%p)\n", pStubMsg
, pFormat
);
612 assert(pStubMsg
&& pFormat
);
614 if (*pFormat
== RPC_FC_C_CSTRING
) {
615 rslt
= NDR_LOCAL_UINT32_READ(pStubMsg
->Buffer
); /* maxlen */
617 else if (*pFormat
== RPC_FC_C_WSTRING
) {
618 rslt
= NDR_LOCAL_UINT32_READ(pStubMsg
->Buffer
)*2; /* maxlen */
621 ERR("Unhandled string type: %#x\n", *pFormat
);
622 /* FIXME: raise an exception */
625 if (pFormat
[1] != RPC_FC_PAD
) {
626 FIXME("sized string format=%d\n", pFormat
[1]);
629 TRACE(" --> %lu\n", rslt
);
633 /************************************************************************
634 * NdrConformantStringUnmarshall [RPCRT4.@]
636 unsigned char *WINAPI
NdrConformantStringUnmarshall( PMIDL_STUB_MESSAGE pStubMsg
,
637 unsigned char** ppMemory
, PFORMAT_STRING pFormat
, unsigned char fMustAlloc
)
639 unsigned long len
, esize
;
641 TRACE("(pStubMsg == ^%p, *pMemory == ^%p, pFormat == ^%p, fMustAlloc == %u)\n",
642 pStubMsg
, *ppMemory
, pFormat
, fMustAlloc
);
644 assert(pFormat
&& ppMemory
&& pStubMsg
);
646 ReadConformance(pStubMsg
, NULL
);
647 ReadVariance(pStubMsg
, NULL
);
649 if (*pFormat
== RPC_FC_C_CSTRING
) esize
= 1;
650 else if (*pFormat
== RPC_FC_C_WSTRING
) esize
= 2;
652 ERR("Unhandled string type: %#x\n", *pFormat
);
653 /* FIXME: raise an exception */
657 len
= pStubMsg
->ActualCount
;
659 if (fMustAlloc
|| !*ppMemory
)
660 *ppMemory
= NdrAllocate(pStubMsg
, len
*esize
);
662 memcpy(*ppMemory
, pStubMsg
->Buffer
, len
*esize
);
664 pStubMsg
->Buffer
+= len
*esize
;
666 if (*pFormat
== RPC_FC_C_CSTRING
) {
667 TRACE("string=%s\n", debugstr_a((char*)*ppMemory
));
669 else if (*pFormat
== RPC_FC_C_WSTRING
) {
670 TRACE("string=%s\n", debugstr_w((LPWSTR
)*ppMemory
));
673 return NULL
; /* FIXME: is this always right? */
676 /***********************************************************************
677 * NdrNonConformantStringMarshall [RPCRT4.@]
679 unsigned char * WINAPI
NdrNonConformantStringMarshall(PMIDL_STUB_MESSAGE pStubMsg
,
680 unsigned char *pMemory
,
681 PFORMAT_STRING pFormat
)
687 /***********************************************************************
688 * NdrNonConformantStringUnmarshall [RPCRT4.@]
690 unsigned char * WINAPI
NdrNonConformantStringUnmarshall(PMIDL_STUB_MESSAGE pStubMsg
,
691 unsigned char **ppMemory
,
692 PFORMAT_STRING pFormat
,
693 unsigned char fMustAlloc
)
699 /***********************************************************************
700 * NdrNonConformantStringBufferSize [RPCRT4.@]
702 void WINAPI
NdrNonConformantStringBufferSize(PMIDL_STUB_MESSAGE pStubMsg
,
703 unsigned char *pMemory
,
704 PFORMAT_STRING pFormat
)
709 /***********************************************************************
710 * NdrNonConformantStringMemorySize [RPCRT4.@]
712 unsigned long WINAPI
NdrNonConformantStringMemorySize(PMIDL_STUB_MESSAGE pStubMsg
,
713 PFORMAT_STRING pFormat
)
719 static inline void dump_pointer_attr(unsigned char attr
)
721 if (attr
& RPC_FC_P_ALLOCALLNODES
)
722 TRACE(" RPC_FC_P_ALLOCALLNODES");
723 if (attr
& RPC_FC_P_DONTFREE
)
724 TRACE(" RPC_FC_P_DONTFREE");
725 if (attr
& RPC_FC_P_ONSTACK
)
726 TRACE(" RPC_FC_P_ONSTACK");
727 if (attr
& RPC_FC_P_SIMPLEPOINTER
)
728 TRACE(" RPC_FC_P_SIMPLEPOINTER");
729 if (attr
& RPC_FC_P_DEREF
)
730 TRACE(" RPC_FC_P_DEREF");
734 /***********************************************************************
737 void WINAPI
PointerMarshall(PMIDL_STUB_MESSAGE pStubMsg
,
738 unsigned char *Buffer
,
739 unsigned char *Pointer
,
740 PFORMAT_STRING pFormat
)
742 unsigned type
= pFormat
[0], attr
= pFormat
[1];
746 TRACE("(%p,%p,%p,%p)\n", pStubMsg
, Buffer
, Pointer
, pFormat
);
747 TRACE("type=0x%x, attr=", type
); dump_pointer_attr(attr
);
749 if (attr
& RPC_FC_P_SIMPLEPOINTER
) desc
= pFormat
;
750 else desc
= pFormat
+ *(const SHORT
*)pFormat
;
753 case RPC_FC_RP
: /* ref pointer (always non-null) */
754 #if 0 /* this causes problems for InstallShield so is disabled - we need more tests */
756 RpcRaiseException(RPC_X_NULL_REF_POINTER
);
759 case RPC_FC_UP
: /* unique pointer */
760 case RPC_FC_OP
: /* object pointer - same as unique here */
761 TRACE("writing %p to buffer\n", Pointer
);
762 NDR_LOCAL_UINT32_WRITE(Buffer
, (unsigned long)Pointer
);
766 FIXME("unhandled ptr type=%02x\n", type
);
767 RpcRaiseException(RPC_X_BAD_STUB_DATA
);
770 TRACE("calling marshaller for type 0x%x\n", (int)*desc
);
773 if (attr
& RPC_FC_P_DEREF
) {
774 Pointer
= *(unsigned char**)Pointer
;
775 TRACE("deref => %p\n", Pointer
);
777 m
= NdrMarshaller
[*desc
& NDR_TABLE_MASK
];
778 if (m
) m(pStubMsg
, Pointer
, desc
);
779 else FIXME("no marshaller for data type=%02x\n", *desc
);
782 STD_OVERFLOW_CHECK(pStubMsg
);
785 /***********************************************************************
788 void WINAPI
PointerUnmarshall(PMIDL_STUB_MESSAGE pStubMsg
,
789 unsigned char *Buffer
,
790 unsigned char **pPointer
,
791 PFORMAT_STRING pFormat
,
792 unsigned char fMustAlloc
)
794 unsigned type
= pFormat
[0], attr
= pFormat
[1];
797 DWORD pointer_id
= 0;
799 TRACE("(%p,%p,%p,%p,%d)\n", pStubMsg
, Buffer
, pPointer
, pFormat
, fMustAlloc
);
800 TRACE("type=0x%x, attr=", type
); dump_pointer_attr(attr
);
802 if (attr
& RPC_FC_P_SIMPLEPOINTER
) desc
= pFormat
;
803 else desc
= pFormat
+ *(const SHORT
*)pFormat
;
806 case RPC_FC_RP
: /* ref pointer (always non-null) */
809 case RPC_FC_UP
: /* unique pointer */
810 pointer_id
= NDR_LOCAL_UINT32_READ(Buffer
);
811 TRACE("pointer_id is 0x%08lx\n", pointer_id
);
813 case RPC_FC_OP
: /* object pointer - we must free data before overwriting it */
814 pointer_id
= NDR_LOCAL_UINT32_READ(Buffer
);
815 TRACE("pointer_id is 0x%08lx\n", pointer_id
);
817 FIXME("free object pointer %p\n", *pPointer
);
821 FIXME("unhandled ptr type=%02x\n", type
);
822 RpcRaiseException(RPC_X_BAD_STUB_DATA
);
826 if (attr
& RPC_FC_P_DEREF
) {
827 if (!*pPointer
|| fMustAlloc
)
828 *pPointer
= NdrAllocate(pStubMsg
, sizeof(void *));
829 pPointer
= *(unsigned char***)pPointer
;
830 TRACE("deref => %p\n", pPointer
);
832 m
= NdrUnmarshaller
[*desc
& NDR_TABLE_MASK
];
833 if (m
) m(pStubMsg
, pPointer
, desc
, fMustAlloc
);
834 else FIXME("no unmarshaller for data type=%02x\n", *desc
);
837 TRACE("pointer=%p\n", *pPointer
);
840 /***********************************************************************
843 void WINAPI
PointerBufferSize(PMIDL_STUB_MESSAGE pStubMsg
,
844 unsigned char *Pointer
,
845 PFORMAT_STRING pFormat
)
847 unsigned type
= pFormat
[0], attr
= pFormat
[1];
851 TRACE("(%p,%p,%p)\n", pStubMsg
, Pointer
, pFormat
);
852 TRACE("type=0x%x, attr=", type
); dump_pointer_attr(attr
);
854 if (attr
& RPC_FC_P_SIMPLEPOINTER
) desc
= pFormat
;
855 else desc
= pFormat
+ *(const SHORT
*)pFormat
;
858 case RPC_FC_RP
: /* ref pointer (always non-null) */
862 /* NULL pointer has no further representation */
868 FIXME("unhandled ptr type=%02x\n", type
);
869 RpcRaiseException(RPC_X_BAD_STUB_DATA
);
872 if (attr
& RPC_FC_P_DEREF
) {
873 Pointer
= *(unsigned char**)Pointer
;
874 TRACE("deref => %p\n", Pointer
);
877 m
= NdrBufferSizer
[*desc
& NDR_TABLE_MASK
];
878 if (m
) m(pStubMsg
, Pointer
, desc
);
879 else FIXME("no buffersizer for data type=%02x\n", *desc
);
882 /***********************************************************************
883 * PointerMemorySize [RPCRT4.@]
885 unsigned long WINAPI
PointerMemorySize(PMIDL_STUB_MESSAGE pStubMsg
,
886 unsigned char *Buffer
,
887 PFORMAT_STRING pFormat
)
889 unsigned type
= pFormat
[0], attr
= pFormat
[1];
893 FIXME("(%p,%p,%p): stub\n", pStubMsg
, Buffer
, pFormat
);
894 TRACE("type=0x%x, attr=", type
); dump_pointer_attr(attr
);
896 if (attr
& RPC_FC_P_SIMPLEPOINTER
) desc
= pFormat
;
897 else desc
= pFormat
+ *(const SHORT
*)pFormat
;
900 case RPC_FC_RP
: /* ref pointer (always non-null) */
903 FIXME("unhandled ptr type=%02x\n", type
);
904 RpcRaiseException(RPC_X_BAD_STUB_DATA
);
907 if (attr
& RPC_FC_P_DEREF
) {
911 m
= NdrMemorySizer
[*desc
& NDR_TABLE_MASK
];
912 if (m
) m(pStubMsg
, desc
);
913 else FIXME("no memorysizer for data type=%02x\n", *desc
);
918 /***********************************************************************
919 * PointerFree [RPCRT4.@]
921 void WINAPI
PointerFree(PMIDL_STUB_MESSAGE pStubMsg
,
922 unsigned char *Pointer
,
923 PFORMAT_STRING pFormat
)
925 unsigned type
= pFormat
[0], attr
= pFormat
[1];
929 TRACE("(%p,%p,%p)\n", pStubMsg
, Pointer
, pFormat
);
930 TRACE("type=0x%x, attr=", type
); dump_pointer_attr(attr
);
931 if (attr
& RPC_FC_P_DONTFREE
) return;
933 if (attr
& RPC_FC_P_SIMPLEPOINTER
) desc
= pFormat
;
934 else desc
= pFormat
+ *(const SHORT
*)pFormat
;
936 if (!Pointer
) return;
938 if (attr
& RPC_FC_P_DEREF
) {
939 Pointer
= *(unsigned char**)Pointer
;
940 TRACE("deref => %p\n", Pointer
);
943 m
= NdrFreer
[*desc
& NDR_TABLE_MASK
];
944 if (m
) m(pStubMsg
, Pointer
, desc
);
946 /* hmm... is this sensible?
947 * perhaps we should check if the memory comes from NdrAllocate,
948 * and deallocate only if so - checking if the pointer is between
949 * BufferStart and BufferEnd is probably no good since the buffer
950 * may be reallocated when the server wants to marshal the reply */
952 case RPC_FC_BOGUS_STRUCT
:
953 case RPC_FC_BOGUS_ARRAY
:
954 case RPC_FC_USER_MARSHAL
:
959 FIXME("unhandled data type=%02x\n", *desc
);
961 case RPC_FC_C_CSTRING
:
962 case RPC_FC_C_WSTRING
:
963 if (pStubMsg
->ReuseBuffer
) goto notfree
;
969 if (attr
& RPC_FC_P_ONSTACK
) {
970 TRACE("not freeing stack ptr %p\n", Pointer
);
973 TRACE("freeing %p\n", Pointer
);
974 NdrFree(pStubMsg
, Pointer
);
977 TRACE("not freeing %p\n", Pointer
);
980 /***********************************************************************
981 * EmbeddedPointerMarshall
983 unsigned char * WINAPI
EmbeddedPointerMarshall(PMIDL_STUB_MESSAGE pStubMsg
,
984 unsigned char *pMemory
,
985 PFORMAT_STRING pFormat
)
987 unsigned char *Mark
= pStubMsg
->BufferMark
;
988 unsigned long Offset
= pStubMsg
->Offset
;
989 unsigned ofs
, rep
, count
, stride
, xofs
;
992 TRACE("(%p,%p,%p)\n", pStubMsg
, pMemory
, pFormat
);
994 if (*pFormat
!= RPC_FC_PP
) return NULL
;
997 while (pFormat
[0] != RPC_FC_END
) {
998 switch (pFormat
[0]) {
1000 FIXME("unknown repeat type %d\n", pFormat
[0]);
1001 case RPC_FC_NO_REPEAT
:
1009 case RPC_FC_FIXED_REPEAT
:
1010 rep
= *(const WORD
*)&pFormat
[2];
1011 stride
= *(const WORD
*)&pFormat
[4];
1012 ofs
= *(const WORD
*)&pFormat
[6];
1013 count
= *(const WORD
*)&pFormat
[8];
1017 case RPC_FC_VARIABLE_REPEAT
:
1018 rep
= pStubMsg
->MaxCount
;
1019 stride
= *(const WORD
*)&pFormat
[2];
1020 ofs
= *(const WORD
*)&pFormat
[4];
1021 count
= *(const WORD
*)&pFormat
[6];
1022 xofs
= (pFormat
[1] == RPC_FC_VARIABLE_OFFSET
) ? Offset
* stride
: 0;
1026 for (i
= 0; i
< rep
; i
++) {
1027 PFORMAT_STRING info
= pFormat
;
1028 unsigned char *membase
= pMemory
+ (i
* stride
);
1029 unsigned char *bufbase
= Mark
+ (i
* stride
);
1031 /* ofs doesn't seem to matter in this context */
1032 for (u
=0; u
<count
; u
++,info
+=8) {
1033 unsigned char *memptr
= membase
+ *(const SHORT
*)&info
[0];
1034 unsigned char *bufptr
= bufbase
+ *(const SHORT
*)&info
[2];
1035 PointerMarshall(pStubMsg
, bufptr
, *(unsigned char**)memptr
, info
+4);
1038 pFormat
+= 8 * count
;
1041 STD_OVERFLOW_CHECK(pStubMsg
);
1046 /***********************************************************************
1047 * EmbeddedPointerUnmarshall
1049 unsigned char * WINAPI
EmbeddedPointerUnmarshall(PMIDL_STUB_MESSAGE pStubMsg
,
1050 unsigned char **ppMemory
,
1051 PFORMAT_STRING pFormat
,
1052 unsigned char fMustAlloc
)
1054 unsigned char *Mark
= pStubMsg
->BufferMark
;
1055 unsigned long Offset
= pStubMsg
->Offset
;
1056 unsigned ofs
, rep
, count
, stride
, xofs
;
1059 TRACE("(%p,%p,%p,%d)\n", pStubMsg
, ppMemory
, pFormat
, fMustAlloc
);
1061 if (*pFormat
!= RPC_FC_PP
) return NULL
;
1064 while (pFormat
[0] != RPC_FC_END
) {
1065 TRACE("pFormat[0] = 0x%x\n", pFormat
[0]);
1066 switch (pFormat
[0]) {
1068 FIXME("unknown repeat type %d\n", pFormat
[0]);
1069 case RPC_FC_NO_REPEAT
:
1077 case RPC_FC_FIXED_REPEAT
:
1078 rep
= *(const WORD
*)&pFormat
[2];
1079 stride
= *(const WORD
*)&pFormat
[4];
1080 ofs
= *(const WORD
*)&pFormat
[6];
1081 count
= *(const WORD
*)&pFormat
[8];
1085 case RPC_FC_VARIABLE_REPEAT
:
1086 rep
= pStubMsg
->MaxCount
;
1087 stride
= *(const WORD
*)&pFormat
[2];
1088 ofs
= *(const WORD
*)&pFormat
[4];
1089 count
= *(const WORD
*)&pFormat
[6];
1090 xofs
= (pFormat
[1] == RPC_FC_VARIABLE_OFFSET
) ? Offset
* stride
: 0;
1094 /* ofs doesn't seem to matter in this context */
1095 for (i
= 0; i
< rep
; i
++) {
1096 PFORMAT_STRING info
= pFormat
;
1097 unsigned char *membase
= *ppMemory
+ (i
* stride
);
1098 unsigned char *bufbase
= Mark
+ (i
* stride
);
1100 for (u
=0; u
<count
; u
++,info
+=8) {
1101 unsigned char *memptr
= membase
+ *(const SHORT
*)&info
[0];
1102 unsigned char *bufptr
= bufbase
+ *(const SHORT
*)&info
[2];
1103 *(void **)memptr
= NULL
;
1104 PointerUnmarshall(pStubMsg
, bufptr
, (unsigned char**)memptr
, info
+4, fMustAlloc
);
1107 pFormat
+= 8 * count
;
1113 /***********************************************************************
1114 * EmbeddedPointerBufferSize
1116 void WINAPI
EmbeddedPointerBufferSize(PMIDL_STUB_MESSAGE pStubMsg
,
1117 unsigned char *pMemory
,
1118 PFORMAT_STRING pFormat
)
1120 unsigned long Offset
= pStubMsg
->Offset
;
1121 unsigned ofs
, rep
, count
, stride
, xofs
;
1124 TRACE("(%p,%p,%p)\n", pStubMsg
, pMemory
, pFormat
);
1126 if (pStubMsg
->IgnoreEmbeddedPointers
) return;
1128 if (*pFormat
!= RPC_FC_PP
) return;
1131 while (pFormat
[0] != RPC_FC_END
) {
1132 switch (pFormat
[0]) {
1134 FIXME("unknown repeat type %d\n", pFormat
[0]);
1135 case RPC_FC_NO_REPEAT
:
1143 case RPC_FC_FIXED_REPEAT
:
1144 rep
= *(const WORD
*)&pFormat
[2];
1145 stride
= *(const WORD
*)&pFormat
[4];
1146 ofs
= *(const WORD
*)&pFormat
[6];
1147 count
= *(const WORD
*)&pFormat
[8];
1151 case RPC_FC_VARIABLE_REPEAT
:
1152 rep
= pStubMsg
->MaxCount
;
1153 stride
= *(const WORD
*)&pFormat
[2];
1154 ofs
= *(const WORD
*)&pFormat
[4];
1155 count
= *(const WORD
*)&pFormat
[6];
1156 xofs
= (pFormat
[1] == RPC_FC_VARIABLE_OFFSET
) ? Offset
* stride
: 0;
1160 /* ofs doesn't seem to matter in this context */
1161 for (i
= 0; i
< rep
; i
++) {
1162 PFORMAT_STRING info
= pFormat
;
1163 unsigned char *membase
= pMemory
+ (i
* stride
);
1165 for (u
=0; u
<count
; u
++,info
+=8) {
1166 unsigned char *memptr
= membase
+ *(const SHORT
*)&info
[0];
1167 PointerBufferSize(pStubMsg
, *(unsigned char**)memptr
, info
+4);
1170 pFormat
+= 8 * count
;
1174 /***********************************************************************
1175 * EmbeddedPointerMemorySize
1177 unsigned long WINAPI
EmbeddedPointerMemorySize(PMIDL_STUB_MESSAGE pStubMsg
,
1178 PFORMAT_STRING pFormat
)
1180 unsigned long Offset
= pStubMsg
->Offset
;
1181 unsigned char *Mark
= pStubMsg
->BufferMark
;
1182 unsigned ofs
, rep
, count
, stride
, xofs
;
1185 FIXME("(%p,%p): stub\n", pStubMsg
, pFormat
);
1187 if (*pFormat
!= RPC_FC_PP
) return 0;
1190 while (pFormat
[0] != RPC_FC_END
) {
1191 switch (pFormat
[0]) {
1193 FIXME("unknown repeat type %d\n", pFormat
[0]);
1194 case RPC_FC_NO_REPEAT
:
1202 case RPC_FC_FIXED_REPEAT
:
1203 rep
= *(const WORD
*)&pFormat
[2];
1204 stride
= *(const WORD
*)&pFormat
[4];
1205 ofs
= *(const WORD
*)&pFormat
[6];
1206 count
= *(const WORD
*)&pFormat
[8];
1210 case RPC_FC_VARIABLE_REPEAT
:
1211 rep
= pStubMsg
->MaxCount
;
1212 stride
= *(const WORD
*)&pFormat
[2];
1213 ofs
= *(const WORD
*)&pFormat
[4];
1214 count
= *(const WORD
*)&pFormat
[6];
1215 xofs
= (pFormat
[1] == RPC_FC_VARIABLE_OFFSET
) ? Offset
* stride
: 0;
1219 /* ofs doesn't seem to matter in this context */
1220 for (i
= 0; i
< rep
; i
++) {
1221 PFORMAT_STRING info
= pFormat
;
1222 unsigned char *bufbase
= Mark
+ (i
* stride
);
1224 for (u
=0; u
<count
; u
++,info
+=8) {
1225 unsigned char *bufptr
= bufbase
+ *(const SHORT
*)&info
[2];
1226 PointerMemorySize(pStubMsg
, bufptr
, info
+4);
1229 pFormat
+= 8 * count
;
1235 /***********************************************************************
1236 * EmbeddedPointerFree
1238 void WINAPI
EmbeddedPointerFree(PMIDL_STUB_MESSAGE pStubMsg
,
1239 unsigned char *pMemory
,
1240 PFORMAT_STRING pFormat
)
1242 unsigned long Offset
= pStubMsg
->Offset
;
1243 unsigned ofs
, rep
, count
, stride
, xofs
;
1246 TRACE("(%p,%p,%p)\n", pStubMsg
, pMemory
, pFormat
);
1247 if (*pFormat
!= RPC_FC_PP
) return;
1250 while (pFormat
[0] != RPC_FC_END
) {
1251 switch (pFormat
[0]) {
1253 FIXME("unknown repeat type %d\n", pFormat
[0]);
1254 case RPC_FC_NO_REPEAT
:
1262 case RPC_FC_FIXED_REPEAT
:
1263 rep
= *(const WORD
*)&pFormat
[2];
1264 stride
= *(const WORD
*)&pFormat
[4];
1265 ofs
= *(const WORD
*)&pFormat
[6];
1266 count
= *(const WORD
*)&pFormat
[8];
1270 case RPC_FC_VARIABLE_REPEAT
:
1271 rep
= pStubMsg
->MaxCount
;
1272 stride
= *(const WORD
*)&pFormat
[2];
1273 ofs
= *(const WORD
*)&pFormat
[4];
1274 count
= *(const WORD
*)&pFormat
[6];
1275 xofs
= (pFormat
[1] == RPC_FC_VARIABLE_OFFSET
) ? Offset
* stride
: 0;
1279 /* ofs doesn't seem to matter in this context */
1280 for (i
= 0; i
< rep
; i
++) {
1281 PFORMAT_STRING info
= pFormat
;
1282 unsigned char *membase
= pMemory
+ (i
* stride
);
1284 for (u
=0; u
<count
; u
++,info
+=8) {
1285 unsigned char *memptr
= membase
+ *(const SHORT
*)&info
[0];
1286 PointerFree(pStubMsg
, *(unsigned char**)memptr
, info
+4);
1289 pFormat
+= 8 * count
;
1293 /***********************************************************************
1294 * NdrPointerMarshall [RPCRT4.@]
1296 unsigned char * WINAPI
NdrPointerMarshall(PMIDL_STUB_MESSAGE pStubMsg
,
1297 unsigned char *pMemory
,
1298 PFORMAT_STRING pFormat
)
1300 unsigned char *Buffer
;
1302 TRACE("(%p,%p,%p)\n", pStubMsg
, pMemory
, pFormat
);
1304 /* incremement the buffer here instead of in PointerMarshall,
1305 * as that is used by embedded pointers which already handle the incrementing
1306 * the buffer, and shouldn't write any additional pointer data to the wire */
1307 if (*pFormat
!= RPC_FC_RP
)
1309 ALIGN_POINTER(pStubMsg
->Buffer
, 4);
1310 Buffer
= pStubMsg
->Buffer
;
1311 pStubMsg
->Buffer
+= 4;
1314 Buffer
= pStubMsg
->Buffer
;
1316 PointerMarshall(pStubMsg
, Buffer
, pMemory
, pFormat
);
1318 STD_OVERFLOW_CHECK(pStubMsg
);
1323 /***********************************************************************
1324 * NdrPointerUnmarshall [RPCRT4.@]
1326 unsigned char * WINAPI
NdrPointerUnmarshall(PMIDL_STUB_MESSAGE pStubMsg
,
1327 unsigned char **ppMemory
,
1328 PFORMAT_STRING pFormat
,
1329 unsigned char fMustAlloc
)
1331 unsigned char *Buffer
;
1333 TRACE("(%p,%p,%p,%d)\n", pStubMsg
, ppMemory
, pFormat
, fMustAlloc
);
1335 /* incremement the buffer here instead of in PointerUnmarshall,
1336 * as that is used by embedded pointers which already handle the incrementing
1337 * the buffer, and shouldn't read any additional pointer data from the
1339 if (*pFormat
!= RPC_FC_RP
)
1341 ALIGN_POINTER(pStubMsg
->Buffer
, 4);
1342 Buffer
= pStubMsg
->Buffer
;
1343 pStubMsg
->Buffer
+= 4;
1346 Buffer
= pStubMsg
->Buffer
;
1348 PointerUnmarshall(pStubMsg
, Buffer
, ppMemory
, pFormat
, fMustAlloc
);
1353 /***********************************************************************
1354 * NdrPointerBufferSize [RPCRT4.@]
1356 void WINAPI
NdrPointerBufferSize(PMIDL_STUB_MESSAGE pStubMsg
,
1357 unsigned char *pMemory
,
1358 PFORMAT_STRING pFormat
)
1360 TRACE("(%p,%p,%p)\n", pStubMsg
, pMemory
, pFormat
);
1362 /* incremement the buffer length here instead of in PointerBufferSize,
1363 * as that is used by embedded pointers which already handle the buffer
1364 * length, and shouldn't write anything more to the wire */
1365 if (*pFormat
!= RPC_FC_RP
)
1367 ALIGN_LENGTH(pStubMsg
->BufferLength
, 4);
1368 pStubMsg
->BufferLength
+= 4;
1371 PointerBufferSize(pStubMsg
, pMemory
, pFormat
);
1374 /***********************************************************************
1375 * NdrPointerMemorySize [RPCRT4.@]
1377 unsigned long WINAPI
NdrPointerMemorySize(PMIDL_STUB_MESSAGE pStubMsg
,
1378 PFORMAT_STRING pFormat
)
1380 /* unsigned size = *(LPWORD)(pFormat+2); */
1381 FIXME("(%p,%p): stub\n", pStubMsg
, pFormat
);
1382 PointerMemorySize(pStubMsg
, pStubMsg
->Buffer
, pFormat
);
1386 /***********************************************************************
1387 * NdrPointerFree [RPCRT4.@]
1389 void WINAPI
NdrPointerFree(PMIDL_STUB_MESSAGE pStubMsg
,
1390 unsigned char *pMemory
,
1391 PFORMAT_STRING pFormat
)
1393 TRACE("(%p,%p,%p)\n", pStubMsg
, pMemory
, pFormat
);
1394 PointerFree(pStubMsg
, pMemory
, pFormat
);
1397 /***********************************************************************
1398 * NdrSimpleStructMarshall [RPCRT4.@]
1400 unsigned char * WINAPI
NdrSimpleStructMarshall(PMIDL_STUB_MESSAGE pStubMsg
,
1401 unsigned char *pMemory
,
1402 PFORMAT_STRING pFormat
)
1404 unsigned size
= *(const WORD
*)(pFormat
+2);
1405 TRACE("(%p,%p,%p)\n", pStubMsg
, pMemory
, pFormat
);
1407 ALIGN_POINTER(pStubMsg
->Buffer
, pFormat
[1] + 1);
1409 memcpy(pStubMsg
->Buffer
, pMemory
, size
);
1410 pStubMsg
->BufferMark
= pStubMsg
->Buffer
;
1411 pStubMsg
->Buffer
+= size
;
1413 if (pFormat
[0] != RPC_FC_STRUCT
)
1414 EmbeddedPointerMarshall(pStubMsg
, pMemory
, pFormat
+4);
1416 STD_OVERFLOW_CHECK(pStubMsg
);
1421 /***********************************************************************
1422 * NdrSimpleStructUnmarshall [RPCRT4.@]
1424 unsigned char * WINAPI
NdrSimpleStructUnmarshall(PMIDL_STUB_MESSAGE pStubMsg
,
1425 unsigned char **ppMemory
,
1426 PFORMAT_STRING pFormat
,
1427 unsigned char fMustAlloc
)
1429 unsigned size
= *(const WORD
*)(pFormat
+2);
1430 TRACE("(%p,%p,%p,%d)\n", pStubMsg
, ppMemory
, pFormat
, fMustAlloc
);
1432 ALIGN_POINTER(pStubMsg
->Buffer
, pFormat
[1] + 1);
1435 *ppMemory
= NdrAllocate(pStubMsg
, size
);
1436 memcpy(*ppMemory
, pStubMsg
->Buffer
, size
);
1438 if (pStubMsg
->ReuseBuffer
&& !*ppMemory
)
1439 /* for servers, we may just point straight into the RPC buffer, I think
1440 * (I guess that's what MS does since MIDL code doesn't try to free) */
1441 *ppMemory
= pStubMsg
->Buffer
;
1443 /* for clients, memory should be provided by caller */
1444 memcpy(*ppMemory
, pStubMsg
->Buffer
, size
);
1447 pStubMsg
->BufferMark
= pStubMsg
->Buffer
;
1448 pStubMsg
->Buffer
+= size
;
1450 if (pFormat
[0] != RPC_FC_STRUCT
)
1451 EmbeddedPointerUnmarshall(pStubMsg
, ppMemory
, pFormat
+4, fMustAlloc
);
1457 /***********************************************************************
1458 * NdrSimpleStructUnmarshall [RPCRT4.@]
1460 void WINAPI
NdrSimpleTypeMarshall( PMIDL_STUB_MESSAGE pStubMsg
, unsigned char* pMemory
,
1461 unsigned char FormatChar
)
1467 /***********************************************************************
1468 * NdrSimpleStructUnmarshall [RPCRT4.@]
1470 void WINAPI
NdrSimpleTypeUnmarshall( PMIDL_STUB_MESSAGE pStubMsg
, unsigned char* pMemory
,
1471 unsigned char FormatChar
)
1477 /***********************************************************************
1478 * NdrSimpleStructBufferSize [RPCRT4.@]
1480 void WINAPI
NdrSimpleStructBufferSize(PMIDL_STUB_MESSAGE pStubMsg
,
1481 unsigned char *pMemory
,
1482 PFORMAT_STRING pFormat
)
1484 unsigned size
= *(const WORD
*)(pFormat
+2);
1485 TRACE("(%p,%p,%p)\n", pStubMsg
, pMemory
, pFormat
);
1487 ALIGN_LENGTH(pStubMsg
->BufferLength
, pFormat
[1] + 1);
1489 pStubMsg
->BufferLength
+= size
;
1490 if (pFormat
[0] != RPC_FC_STRUCT
)
1491 EmbeddedPointerBufferSize(pStubMsg
, pMemory
, pFormat
+4);
1494 /***********************************************************************
1495 * NdrSimpleStructMemorySize [RPCRT4.@]
1497 unsigned long WINAPI
NdrSimpleStructMemorySize(PMIDL_STUB_MESSAGE pStubMsg
,
1498 PFORMAT_STRING pFormat
)
1500 unsigned short size
= *(LPWORD
)(pFormat
+2);
1502 TRACE("(%p,%p)\n", pStubMsg
, pFormat
);
1504 ALIGN_POINTER(pStubMsg
->Buffer
, pFormat
[1] + 1);
1505 pStubMsg
->MemorySize
+= size
;
1506 pStubMsg
->Buffer
+= size
;
1508 if (pFormat
[0] != RPC_FC_STRUCT
)
1509 EmbeddedPointerMemorySize(pStubMsg
, pFormat
+4);
1513 /***********************************************************************
1514 * NdrSimpleStructFree [RPCRT4.@]
1516 void WINAPI
NdrSimpleStructFree(PMIDL_STUB_MESSAGE pStubMsg
,
1517 unsigned char *pMemory
,
1518 PFORMAT_STRING pFormat
)
1520 TRACE("(%p,%p,%p)\n", pStubMsg
, pMemory
, pFormat
);
1521 if (pFormat
[0] != RPC_FC_STRUCT
)
1522 EmbeddedPointerFree(pStubMsg
, pMemory
, pFormat
+4);
1526 static unsigned long EmbeddedComplexSize(PMIDL_STUB_MESSAGE pStubMsg
,
1527 PFORMAT_STRING pFormat
)
1531 case RPC_FC_PSTRUCT
:
1532 case RPC_FC_CSTRUCT
:
1533 case RPC_FC_BOGUS_STRUCT
:
1534 return *(const WORD
*)&pFormat
[2];
1535 case RPC_FC_USER_MARSHAL
:
1536 return *(const WORD
*)&pFormat
[4];
1537 case RPC_FC_NON_ENCAPSULATED_UNION
:
1539 if (pStubMsg
->fHasNewCorrDesc
)
1544 pFormat
+= *(const SHORT
*)pFormat
;
1545 return *(const SHORT
*)pFormat
;
1547 FIXME("unhandled embedded type %02x\n", *pFormat
);
1553 static unsigned long EmbeddedComplexMemorySize(PMIDL_STUB_MESSAGE pStubMsg
,
1554 PFORMAT_STRING pFormat
)
1556 NDR_MEMORYSIZE m
= NdrMemorySizer
[*pFormat
& NDR_TABLE_MASK
];
1560 FIXME("no memorysizer for data type=%02x\n", *pFormat
);
1564 return m(pStubMsg
, pFormat
);
1568 static unsigned char * ComplexMarshall(PMIDL_STUB_MESSAGE pStubMsg
,
1569 unsigned char *pMemory
,
1570 PFORMAT_STRING pFormat
,
1571 PFORMAT_STRING pPointer
)
1573 PFORMAT_STRING desc
;
1577 while (*pFormat
!= RPC_FC_END
) {
1581 TRACE("short=%d <= %p\n", *(WORD
*)pMemory
, pMemory
);
1582 memcpy(pStubMsg
->Buffer
, pMemory
, 2);
1583 pStubMsg
->Buffer
+= 2;
1589 TRACE("long=%ld <= %p\n", *(DWORD
*)pMemory
, pMemory
);
1590 memcpy(pStubMsg
->Buffer
, pMemory
, 4);
1591 pStubMsg
->Buffer
+= 4;
1594 case RPC_FC_POINTER
:
1595 TRACE("pointer=%p <= %p\n", *(unsigned char**)pMemory
, pMemory
);
1596 NdrPointerMarshall(pStubMsg
, *(unsigned char**)pMemory
, pPointer
);
1600 case RPC_FC_ALIGNM4
:
1601 ALIGN_POINTER(pMemory
, 4);
1603 case RPC_FC_ALIGNM8
:
1604 ALIGN_POINTER(pMemory
, 8);
1606 case RPC_FC_STRUCTPAD2
:
1609 case RPC_FC_EMBEDDED_COMPLEX
:
1610 pMemory
+= pFormat
[1];
1612 desc
= pFormat
+ *(const SHORT
*)pFormat
;
1613 size
= EmbeddedComplexSize(pStubMsg
, desc
);
1614 TRACE("embedded complex (size=%ld) <= %p\n", size
, pMemory
);
1615 m
= NdrMarshaller
[*desc
& NDR_TABLE_MASK
];
1616 if (m
) m(pStubMsg
, pMemory
, desc
);
1617 else FIXME("no marshaller for embedded type %02x\n", *desc
);
1624 FIXME("unhandled format %02x\n", *pFormat
);
1632 static unsigned char * ComplexUnmarshall(PMIDL_STUB_MESSAGE pStubMsg
,
1633 unsigned char *pMemory
,
1634 PFORMAT_STRING pFormat
,
1635 PFORMAT_STRING pPointer
,
1636 unsigned char fMustAlloc
)
1638 PFORMAT_STRING desc
;
1642 while (*pFormat
!= RPC_FC_END
) {
1646 memcpy(pMemory
, pStubMsg
->Buffer
, 2);
1647 TRACE("short=%d => %p\n", *(WORD
*)pMemory
, pMemory
);
1648 pStubMsg
->Buffer
+= 2;
1654 memcpy(pMemory
, pStubMsg
->Buffer
, 4);
1655 TRACE("long=%ld => %p\n", *(DWORD
*)pMemory
, pMemory
);
1656 pStubMsg
->Buffer
+= 4;
1659 case RPC_FC_POINTER
:
1660 *(unsigned char**)pMemory
= NULL
;
1661 TRACE("pointer => %p\n", pMemory
);
1662 NdrPointerUnmarshall(pStubMsg
, (unsigned char**)pMemory
, pPointer
, fMustAlloc
);
1666 case RPC_FC_ALIGNM4
:
1667 ALIGN_POINTER(pMemory
, 4);
1669 case RPC_FC_ALIGNM8
:
1670 ALIGN_POINTER(pMemory
, 8);
1672 case RPC_FC_STRUCTPAD2
:
1675 case RPC_FC_EMBEDDED_COMPLEX
:
1676 pMemory
+= pFormat
[1];
1678 desc
= pFormat
+ *(const SHORT
*)pFormat
;
1679 size
= EmbeddedComplexSize(pStubMsg
, desc
);
1680 TRACE("embedded complex (size=%ld) => %p\n", size
, pMemory
);
1681 m
= NdrUnmarshaller
[*desc
& NDR_TABLE_MASK
];
1682 memset(pMemory
, 0, size
); /* just in case */
1683 if (m
) m(pStubMsg
, &pMemory
, desc
, fMustAlloc
);
1684 else FIXME("no unmarshaller for embedded type %02x\n", *desc
);
1691 FIXME("unhandled format %d\n", *pFormat
);
1699 static unsigned char * ComplexBufferSize(PMIDL_STUB_MESSAGE pStubMsg
,
1700 unsigned char *pMemory
,
1701 PFORMAT_STRING pFormat
,
1702 PFORMAT_STRING pPointer
)
1704 PFORMAT_STRING desc
;
1708 while (*pFormat
!= RPC_FC_END
) {
1712 pStubMsg
->BufferLength
+= 2;
1718 pStubMsg
->BufferLength
+= 4;
1721 case RPC_FC_POINTER
:
1722 NdrPointerBufferSize(pStubMsg
, *(unsigned char**)pMemory
, pPointer
);
1726 case RPC_FC_ALIGNM4
:
1727 ALIGN_POINTER(pMemory
, 4);
1729 case RPC_FC_ALIGNM8
:
1730 ALIGN_POINTER(pMemory
, 8);
1732 case RPC_FC_STRUCTPAD2
:
1735 case RPC_FC_EMBEDDED_COMPLEX
:
1736 pMemory
+= pFormat
[1];
1738 desc
= pFormat
+ *(const SHORT
*)pFormat
;
1739 size
= EmbeddedComplexSize(pStubMsg
, desc
);
1740 m
= NdrBufferSizer
[*desc
& NDR_TABLE_MASK
];
1741 if (m
) m(pStubMsg
, pMemory
, desc
);
1742 else FIXME("no buffersizer for embedded type %02x\n", *desc
);
1749 FIXME("unhandled format %d\n", *pFormat
);
1757 static unsigned char * ComplexFree(PMIDL_STUB_MESSAGE pStubMsg
,
1758 unsigned char *pMemory
,
1759 PFORMAT_STRING pFormat
,
1760 PFORMAT_STRING pPointer
)
1762 PFORMAT_STRING desc
;
1766 while (*pFormat
!= RPC_FC_END
) {
1777 case RPC_FC_POINTER
:
1778 NdrPointerFree(pStubMsg
, *(unsigned char**)pMemory
, pPointer
);
1782 case RPC_FC_ALIGNM4
:
1783 ALIGN_POINTER(pMemory
, 4);
1785 case RPC_FC_ALIGNM8
:
1786 ALIGN_POINTER(pMemory
, 8);
1788 case RPC_FC_STRUCTPAD2
:
1791 case RPC_FC_EMBEDDED_COMPLEX
:
1792 pMemory
+= pFormat
[1];
1794 desc
= pFormat
+ *(const SHORT
*)pFormat
;
1795 size
= EmbeddedComplexSize(pStubMsg
, desc
);
1796 m
= NdrFreer
[*desc
& NDR_TABLE_MASK
];
1797 if (m
) m(pStubMsg
, pMemory
, desc
);
1798 else FIXME("no freer for embedded type %02x\n", *desc
);
1805 FIXME("unhandled format %d\n", *pFormat
);
1813 static unsigned long ComplexStructMemorySize(PMIDL_STUB_MESSAGE pStubMsg
,
1814 PFORMAT_STRING pFormat
)
1816 PFORMAT_STRING desc
;
1817 unsigned long size
= 0;
1819 while (*pFormat
!= RPC_FC_END
) {
1824 pStubMsg
->Buffer
+= 2;
1829 pStubMsg
->Buffer
+= 4;
1831 case RPC_FC_POINTER
:
1833 pStubMsg
->Buffer
+= 4;
1835 case RPC_FC_ALIGNM4
:
1836 ALIGN_LENGTH(size
, 4);
1837 ALIGN_POINTER(pStubMsg
->Buffer
, 4);
1839 case RPC_FC_ALIGNM8
:
1840 ALIGN_LENGTH(size
, 8);
1841 ALIGN_POINTER(pStubMsg
->Buffer
, 8);
1843 case RPC_FC_STRUCTPAD2
:
1845 pStubMsg
->Buffer
+= 2;
1847 case RPC_FC_EMBEDDED_COMPLEX
:
1850 desc
= pFormat
+ *(const SHORT
*)pFormat
;
1851 size
+= EmbeddedComplexMemorySize(pStubMsg
, desc
);
1857 FIXME("unhandled format %d\n", *pFormat
);
1865 /***********************************************************************
1866 * NdrComplexStructMarshall [RPCRT4.@]
1868 unsigned char * WINAPI
NdrComplexStructMarshall(PMIDL_STUB_MESSAGE pStubMsg
,
1869 unsigned char *pMemory
,
1870 PFORMAT_STRING pFormat
)
1872 PFORMAT_STRING conf_array
= NULL
;
1873 PFORMAT_STRING pointer_desc
= NULL
;
1874 unsigned char *OldMemory
= pStubMsg
->Memory
;
1876 TRACE("(%p,%p,%p)\n", pStubMsg
, pMemory
, pFormat
);
1878 ALIGN_POINTER(pStubMsg
->Buffer
, pFormat
[1] + 1);
1881 if (*(const WORD
*)pFormat
) conf_array
= pFormat
+ *(const WORD
*)pFormat
;
1883 if (*(const WORD
*)pFormat
) pointer_desc
= pFormat
+ *(const WORD
*)pFormat
;
1886 pStubMsg
->Memory
= pMemory
;
1888 ComplexMarshall(pStubMsg
, pMemory
, pFormat
, pointer_desc
);
1891 NdrConformantArrayMarshall(pStubMsg
, pMemory
, conf_array
);
1893 pStubMsg
->Memory
= OldMemory
;
1895 STD_OVERFLOW_CHECK(pStubMsg
);
1900 /***********************************************************************
1901 * NdrComplexStructUnmarshall [RPCRT4.@]
1903 unsigned char * WINAPI
NdrComplexStructUnmarshall(PMIDL_STUB_MESSAGE pStubMsg
,
1904 unsigned char **ppMemory
,
1905 PFORMAT_STRING pFormat
,
1906 unsigned char fMustAlloc
)
1908 unsigned size
= *(const WORD
*)(pFormat
+2);
1909 PFORMAT_STRING conf_array
= NULL
;
1910 PFORMAT_STRING pointer_desc
= NULL
;
1911 unsigned char *pMemory
;
1913 TRACE("(%p,%p,%p,%d)\n", pStubMsg
, ppMemory
, pFormat
, fMustAlloc
);
1915 ALIGN_POINTER(pStubMsg
->Buffer
, pFormat
[1] + 1);
1917 if (fMustAlloc
|| !*ppMemory
)
1919 *ppMemory
= NdrAllocate(pStubMsg
, size
);
1920 memset(*ppMemory
, 0, size
);
1924 if (*(const WORD
*)pFormat
) conf_array
= pFormat
+ *(const WORD
*)pFormat
;
1926 if (*(const WORD
*)pFormat
) pointer_desc
= pFormat
+ *(const WORD
*)pFormat
;
1929 pMemory
= ComplexUnmarshall(pStubMsg
, *ppMemory
, pFormat
, pointer_desc
, fMustAlloc
);
1932 NdrConformantArrayUnmarshall(pStubMsg
, &pMemory
, conf_array
, fMustAlloc
);
1937 /***********************************************************************
1938 * NdrComplexStructBufferSize [RPCRT4.@]
1940 void WINAPI
NdrComplexStructBufferSize(PMIDL_STUB_MESSAGE pStubMsg
,
1941 unsigned char *pMemory
,
1942 PFORMAT_STRING pFormat
)
1944 PFORMAT_STRING conf_array
= NULL
;
1945 PFORMAT_STRING pointer_desc
= NULL
;
1946 unsigned char *OldMemory
= pStubMsg
->Memory
;
1948 TRACE("(%p,%p,%p)\n", pStubMsg
, pMemory
, pFormat
);
1950 ALIGN_LENGTH(pStubMsg
->BufferLength
, pFormat
[1] + 1);
1953 if (*(const WORD
*)pFormat
) conf_array
= pFormat
+ *(const WORD
*)pFormat
;
1955 if (*(const WORD
*)pFormat
) pointer_desc
= pFormat
+ *(const WORD
*)pFormat
;
1958 pStubMsg
->Memory
= pMemory
;
1960 pMemory
= ComplexBufferSize(pStubMsg
, pMemory
, pFormat
, pointer_desc
);
1963 NdrConformantArrayBufferSize(pStubMsg
, pMemory
, conf_array
);
1965 pStubMsg
->Memory
= OldMemory
;
1968 /***********************************************************************
1969 * NdrComplexStructMemorySize [RPCRT4.@]
1971 unsigned long WINAPI
NdrComplexStructMemorySize(PMIDL_STUB_MESSAGE pStubMsg
,
1972 PFORMAT_STRING pFormat
)
1974 unsigned size
= *(const WORD
*)(pFormat
+2);
1975 PFORMAT_STRING conf_array
= NULL
;
1976 PFORMAT_STRING pointer_desc
= NULL
;
1978 TRACE("(%p,%p)\n", pStubMsg
, pFormat
);
1980 ALIGN_POINTER(pStubMsg
->Buffer
, pFormat
[1] + 1);
1983 if (*(const WORD
*)pFormat
) conf_array
= pFormat
+ *(const WORD
*)pFormat
;
1985 if (*(const WORD
*)pFormat
) pointer_desc
= pFormat
+ *(const WORD
*)pFormat
;
1988 ComplexStructMemorySize(pStubMsg
, pFormat
);
1991 NdrConformantArrayMemorySize(pStubMsg
, conf_array
);
1996 /***********************************************************************
1997 * NdrComplexStructFree [RPCRT4.@]
1999 void WINAPI
NdrComplexStructFree(PMIDL_STUB_MESSAGE pStubMsg
,
2000 unsigned char *pMemory
,
2001 PFORMAT_STRING pFormat
)
2003 PFORMAT_STRING conf_array
= NULL
;
2004 PFORMAT_STRING pointer_desc
= NULL
;
2005 unsigned char *OldMemory
= pStubMsg
->Memory
;
2007 TRACE("(%p,%p,%p)\n", pStubMsg
, pMemory
, pFormat
);
2010 if (*(const WORD
*)pFormat
) conf_array
= pFormat
+ *(const WORD
*)pFormat
;
2012 if (*(const WORD
*)pFormat
) pointer_desc
= pFormat
+ *(const WORD
*)pFormat
;
2015 pStubMsg
->Memory
= pMemory
;
2017 pMemory
= ComplexFree(pStubMsg
, pMemory
, pFormat
, pointer_desc
);
2020 NdrConformantArrayFree(pStubMsg
, pMemory
, conf_array
);
2022 pStubMsg
->Memory
= OldMemory
;
2025 /***********************************************************************
2026 * NdrConformantArrayMarshall [RPCRT4.@]
2028 unsigned char * WINAPI
NdrConformantArrayMarshall(PMIDL_STUB_MESSAGE pStubMsg
,
2029 unsigned char *pMemory
,
2030 PFORMAT_STRING pFormat
)
2032 DWORD size
= 0, esize
= *(const WORD
*)(pFormat
+2);
2033 unsigned char alignment
= pFormat
[1] + 1;
2035 TRACE("(%p,%p,%p)\n", pStubMsg
, pMemory
, pFormat
);
2036 if (pFormat
[0] != RPC_FC_CARRAY
) FIXME("format=%d\n", pFormat
[0]);
2038 pFormat
= ComputeConformance(pStubMsg
, pMemory
, pFormat
+4, 0);
2039 size
= pStubMsg
->MaxCount
;
2041 WriteConformance(pStubMsg
);
2043 ALIGN_POINTER(pStubMsg
->Buffer
, alignment
);
2045 memcpy(pStubMsg
->Buffer
, pMemory
, size
*esize
);
2046 pStubMsg
->BufferMark
= pStubMsg
->Buffer
;
2047 pStubMsg
->Buffer
+= size
*esize
;
2049 EmbeddedPointerMarshall(pStubMsg
, pMemory
, pFormat
);
2051 STD_OVERFLOW_CHECK(pStubMsg
);
2056 /***********************************************************************
2057 * NdrConformantArrayUnmarshall [RPCRT4.@]
2059 unsigned char * WINAPI
NdrConformantArrayUnmarshall(PMIDL_STUB_MESSAGE pStubMsg
,
2060 unsigned char **ppMemory
,
2061 PFORMAT_STRING pFormat
,
2062 unsigned char fMustAlloc
)
2064 DWORD size
= 0, esize
= *(const WORD
*)(pFormat
+2);
2065 unsigned char alignment
= pFormat
[1] + 1;
2067 TRACE("(%p,%p,%p,%d)\n", pStubMsg
, ppMemory
, pFormat
, fMustAlloc
);
2068 if (pFormat
[0] != RPC_FC_CARRAY
) FIXME("format=%d\n", pFormat
[0]);
2070 pFormat
= ReadConformance(pStubMsg
, pFormat
+4);
2071 size
= pStubMsg
->MaxCount
;
2073 if (fMustAlloc
|| !*ppMemory
)
2074 *ppMemory
= NdrAllocate(pStubMsg
, size
*esize
);
2076 ALIGN_POINTER(pStubMsg
->Buffer
, alignment
);
2078 memcpy(*ppMemory
, pStubMsg
->Buffer
, size
*esize
);
2080 pStubMsg
->BufferMark
= pStubMsg
->Buffer
;
2081 pStubMsg
->Buffer
+= size
*esize
;
2083 EmbeddedPointerUnmarshall(pStubMsg
, ppMemory
, pFormat
, fMustAlloc
);
2088 /***********************************************************************
2089 * NdrConformantArrayBufferSize [RPCRT4.@]
2091 void WINAPI
NdrConformantArrayBufferSize(PMIDL_STUB_MESSAGE pStubMsg
,
2092 unsigned char *pMemory
,
2093 PFORMAT_STRING pFormat
)
2095 DWORD size
= 0, esize
= *(const WORD
*)(pFormat
+2);
2096 unsigned char alignment
= pFormat
[1] + 1;
2098 TRACE("(%p,%p,%p)\n", pStubMsg
, pMemory
, pFormat
);
2099 if (pFormat
[0] != RPC_FC_CARRAY
) FIXME("format=%d\n", pFormat
[0]);
2101 pFormat
= ComputeConformance(pStubMsg
, pMemory
, pFormat
+4, 0);
2102 size
= pStubMsg
->MaxCount
;
2104 SizeConformance(pStubMsg
);
2106 ALIGN_LENGTH(pStubMsg
->BufferLength
, alignment
);
2108 /* conformance value plus array */
2109 pStubMsg
->BufferLength
+= size
*esize
;
2111 EmbeddedPointerBufferSize(pStubMsg
, pMemory
, pFormat
);
2114 /***********************************************************************
2115 * NdrConformantArrayMemorySize [RPCRT4.@]
2117 unsigned long WINAPI
NdrConformantArrayMemorySize(PMIDL_STUB_MESSAGE pStubMsg
,
2118 PFORMAT_STRING pFormat
)
2120 DWORD size
= 0, esize
= *(const WORD
*)(pFormat
+2);
2121 unsigned char *buffer
;
2123 TRACE("(%p,%p)\n", pStubMsg
, pFormat
);
2124 if (pFormat
[0] != RPC_FC_CARRAY
) FIXME("format=%d\n", pFormat
[0]);
2126 buffer
= pStubMsg
->Buffer
;
2127 pFormat
= ReadConformance(pStubMsg
, pFormat
+4);
2128 pStubMsg
->Buffer
= buffer
;
2129 size
= pStubMsg
->MaxCount
;
2134 /***********************************************************************
2135 * NdrConformantArrayFree [RPCRT4.@]
2137 void WINAPI
NdrConformantArrayFree(PMIDL_STUB_MESSAGE pStubMsg
,
2138 unsigned char *pMemory
,
2139 PFORMAT_STRING pFormat
)
2141 TRACE("(%p,%p,%p)\n", pStubMsg
, pMemory
, pFormat
);
2142 if (pFormat
[0] != RPC_FC_CARRAY
) FIXME("format=%d\n", pFormat
[0]);
2144 EmbeddedPointerFree(pStubMsg
, pMemory
, pFormat
);
2148 /***********************************************************************
2149 * NdrConformantVaryingArrayMarshall [RPCRT4.@]
2151 unsigned char* WINAPI
NdrConformantVaryingArrayMarshall( PMIDL_STUB_MESSAGE pStubMsg
,
2152 unsigned char* pMemory
,
2153 PFORMAT_STRING pFormat
)
2155 unsigned char alignment
= pFormat
[1] + 1;
2156 DWORD esize
= *(const WORD
*)(pFormat
+2);
2158 TRACE("(%p, %p, %p)\n", pStubMsg
, pMemory
, pFormat
);
2160 if (pFormat
[0] != RPC_FC_CVARRAY
)
2162 ERR("invalid format type %x\n", pFormat
[0]);
2163 RpcRaiseException(RPC_S_INTERNAL_ERROR
);
2167 pFormat
= ComputeConformance(pStubMsg
, pMemory
, pFormat
+4, 0);
2168 pFormat
= ComputeVariance(pStubMsg
, pMemory
, pFormat
, 0);
2170 WriteConformance(pStubMsg
);
2171 WriteVariance(pStubMsg
);
2173 ALIGN_POINTER(pStubMsg
->Buffer
, alignment
);
2175 memcpy(pStubMsg
->Buffer
, pMemory
+ pStubMsg
->Offset
, pStubMsg
->ActualCount
*esize
);
2176 pStubMsg
->BufferMark
= pStubMsg
->Buffer
;
2177 pStubMsg
->Buffer
+= pStubMsg
->ActualCount
*esize
;
2179 EmbeddedPointerMarshall(pStubMsg
, pMemory
, pFormat
);
2181 STD_OVERFLOW_CHECK(pStubMsg
);
2187 /***********************************************************************
2188 * NdrConformantVaryingArrayUnmarshall [RPCRT4.@]
2190 unsigned char* WINAPI
NdrConformantVaryingArrayUnmarshall( PMIDL_STUB_MESSAGE pStubMsg
,
2191 unsigned char** ppMemory
,
2192 PFORMAT_STRING pFormat
,
2193 unsigned char fMustAlloc
)
2195 unsigned char alignment
= pFormat
[1] + 1;
2196 DWORD esize
= *(const WORD
*)(pFormat
+2);
2198 TRACE("(%p, %p, %p, %d)\n", pStubMsg
, ppMemory
, pFormat
, fMustAlloc
);
2200 if (pFormat
[0] != RPC_FC_CVARRAY
)
2202 ERR("invalid format type %x\n", pFormat
[0]);
2203 RpcRaiseException(RPC_S_INTERNAL_ERROR
);
2207 pFormat
= ReadConformance(pStubMsg
, pFormat
);
2208 pFormat
= ReadVariance(pStubMsg
, pFormat
);
2210 ALIGN_POINTER(pStubMsg
->Buffer
, alignment
);
2212 if (!*ppMemory
|| fMustAlloc
)
2213 *ppMemory
= NdrAllocate(pStubMsg
, pStubMsg
->MaxCount
* esize
);
2214 memcpy(*ppMemory
+ pStubMsg
->Offset
, pStubMsg
->Buffer
, pStubMsg
->ActualCount
* esize
);
2215 pStubMsg
->Buffer
+= pStubMsg
->ActualCount
* esize
;
2217 EmbeddedPointerUnmarshall(pStubMsg
, ppMemory
, pFormat
, fMustAlloc
);
2223 /***********************************************************************
2224 * NdrConformantVaryingArrayFree [RPCRT4.@]
2226 void WINAPI
NdrConformantVaryingArrayFree( PMIDL_STUB_MESSAGE pStubMsg
,
2227 unsigned char* pMemory
,
2228 PFORMAT_STRING pFormat
)
2230 TRACE("(%p,%p,%p)\n", pStubMsg
, pMemory
, pFormat
);
2232 if (pFormat
[0] != RPC_FC_CVARRAY
)
2234 ERR("invalid format type %x\n", pFormat
[0]);
2235 RpcRaiseException(RPC_S_INTERNAL_ERROR
);
2239 pFormat
= ComputeConformance(pStubMsg
, pMemory
, pFormat
+4, 0);
2240 pFormat
= ComputeVariance(pStubMsg
, pMemory
, pFormat
, 0);
2242 EmbeddedPointerFree(pStubMsg
, pMemory
, pFormat
);
2246 /***********************************************************************
2247 * NdrConformantVaryingArrayBufferSize [RPCRT4.@]
2249 void WINAPI
NdrConformantVaryingArrayBufferSize( PMIDL_STUB_MESSAGE pStubMsg
,
2250 unsigned char* pMemory
, PFORMAT_STRING pFormat
)
2252 unsigned char alignment
= pFormat
[1] + 1;
2253 DWORD esize
= *(const WORD
*)(pFormat
+2);
2255 TRACE("(%p, %p, %p)\n", pStubMsg
, pMemory
, pFormat
);
2257 if (pFormat
[0] != RPC_FC_CVARRAY
)
2259 ERR("invalid format type %x\n", pFormat
[0]);
2260 RpcRaiseException(RPC_S_INTERNAL_ERROR
);
2265 pFormat
= ComputeConformance(pStubMsg
, pMemory
, pFormat
+4, 0);
2266 /* compute length */
2267 pFormat
= ComputeVariance(pStubMsg
, pMemory
, pFormat
, 0);
2269 SizeConformance(pStubMsg
);
2270 SizeVariance(pStubMsg
);
2272 ALIGN_LENGTH(pStubMsg
->BufferLength
, alignment
);
2274 pStubMsg
->BufferLength
+= pStubMsg
->ActualCount
*esize
;
2276 EmbeddedPointerBufferSize(pStubMsg
, pMemory
, pFormat
);
2280 /***********************************************************************
2281 * NdrConformantVaryingArrayMemorySize [RPCRT4.@]
2283 unsigned long WINAPI
NdrConformantVaryingArrayMemorySize( PMIDL_STUB_MESSAGE pStubMsg
,
2284 PFORMAT_STRING pFormat
)
2291 /***********************************************************************
2292 * NdrComplexArrayMarshall [RPCRT4.@]
2294 unsigned char * WINAPI
NdrComplexArrayMarshall(PMIDL_STUB_MESSAGE pStubMsg
,
2295 unsigned char *pMemory
,
2296 PFORMAT_STRING pFormat
)
2298 ULONG i
, count
, def
;
2299 BOOL variance_present
;
2300 unsigned char alignment
;
2302 TRACE("(%p,%p,%p)\n", pStubMsg
, pMemory
, pFormat
);
2304 if (pFormat
[0] != RPC_FC_BOGUS_ARRAY
)
2306 ERR("invalid format type %x\n", pFormat
[0]);
2307 RpcRaiseException(RPC_S_INTERNAL_ERROR
);
2311 alignment
= pFormat
[1] + 1;
2313 def
= *(const WORD
*)&pFormat
[2];
2316 pFormat
= ComputeConformance(pStubMsg
, pMemory
, pFormat
, def
);
2317 TRACE("conformance = %ld\n", pStubMsg
->MaxCount
);
2319 variance_present
= IsConformanceOrVariancePresent(pFormat
);
2320 pFormat
= ComputeVariance(pStubMsg
, pMemory
, pFormat
, pStubMsg
->MaxCount
);
2321 TRACE("variance = %ld\n", pStubMsg
->ActualCount
);
2323 WriteConformance(pStubMsg
);
2324 if (variance_present
)
2325 WriteVariance(pStubMsg
);
2327 ALIGN_POINTER(pStubMsg
->Buffer
, alignment
);
2329 count
= pStubMsg
->ActualCount
;
2330 for (i
= 0; i
< count
; i
++)
2331 pMemory
= ComplexMarshall(pStubMsg
, pMemory
, pFormat
, NULL
);
2333 STD_OVERFLOW_CHECK(pStubMsg
);
2338 /***********************************************************************
2339 * NdrComplexArrayUnmarshall [RPCRT4.@]
2341 unsigned char * WINAPI
NdrComplexArrayUnmarshall(PMIDL_STUB_MESSAGE pStubMsg
,
2342 unsigned char **ppMemory
,
2343 PFORMAT_STRING pFormat
,
2344 unsigned char fMustAlloc
)
2346 ULONG i
, count
, esize
;
2347 unsigned char alignment
;
2348 unsigned char *pMemory
;
2349 unsigned char *Buffer
;
2351 TRACE("(%p,%p,%p,%d)\n", pStubMsg
, ppMemory
, pFormat
, fMustAlloc
);
2353 if (pFormat
[0] != RPC_FC_BOGUS_ARRAY
)
2355 ERR("invalid format type %x\n", pFormat
[0]);
2356 RpcRaiseException(RPC_S_INTERNAL_ERROR
);
2360 alignment
= pFormat
[1] + 1;
2364 pFormat
= ReadConformance(pStubMsg
, pFormat
);
2365 pFormat
= ReadVariance(pStubMsg
, pFormat
);
2367 Buffer
= pStubMsg
->Buffer
;
2368 esize
= ComplexStructMemorySize(pStubMsg
, pFormat
);
2369 pStubMsg
->Buffer
= Buffer
;
2371 if (fMustAlloc
|| !*ppMemory
)
2373 *ppMemory
= NdrAllocate(pStubMsg
, pStubMsg
->MaxCount
* esize
);
2374 memset(*ppMemory
, 0, pStubMsg
->MaxCount
* esize
);
2377 ALIGN_POINTER(pStubMsg
->Buffer
, alignment
);
2379 pMemory
= *ppMemory
;
2380 count
= pStubMsg
->ActualCount
;
2381 for (i
= 0; i
< count
; i
++)
2382 pMemory
= ComplexUnmarshall(pStubMsg
, pMemory
, pFormat
, NULL
, fMustAlloc
);
2387 /***********************************************************************
2388 * NdrComplexArrayBufferSize [RPCRT4.@]
2390 void WINAPI
NdrComplexArrayBufferSize(PMIDL_STUB_MESSAGE pStubMsg
,
2391 unsigned char *pMemory
,
2392 PFORMAT_STRING pFormat
)
2394 ULONG i
, count
, def
;
2395 unsigned char alignment
;
2396 BOOL variance_present
;
2398 TRACE("(%p,%p,%p)\n", pStubMsg
, pMemory
, pFormat
);
2400 if (pFormat
[0] != RPC_FC_BOGUS_ARRAY
)
2402 ERR("invalid format type %x\n", pFormat
[0]);
2403 RpcRaiseException(RPC_S_INTERNAL_ERROR
);
2407 alignment
= pFormat
[1] + 1;
2409 def
= *(const WORD
*)&pFormat
[2];
2412 pFormat
= ComputeConformance(pStubMsg
, pMemory
, pFormat
, def
);
2413 TRACE("conformance = %ld\n", pStubMsg
->MaxCount
);
2414 SizeConformance(pStubMsg
);
2416 variance_present
= IsConformanceOrVariancePresent(pFormat
);
2417 pFormat
= ComputeVariance(pStubMsg
, pMemory
, pFormat
, pStubMsg
->MaxCount
);
2418 TRACE("variance = %ld\n", pStubMsg
->ActualCount
);
2420 if (variance_present
)
2421 SizeVariance(pStubMsg
);
2423 ALIGN_LENGTH(pStubMsg
->BufferLength
, alignment
);
2425 count
= pStubMsg
->ActualCount
;
2426 for (i
= 0; i
< count
; i
++)
2427 pMemory
= ComplexBufferSize(pStubMsg
, pMemory
, pFormat
, NULL
);
2430 /***********************************************************************
2431 * NdrComplexArrayMemorySize [RPCRT4.@]
2433 unsigned long WINAPI
NdrComplexArrayMemorySize(PMIDL_STUB_MESSAGE pStubMsg
,
2434 PFORMAT_STRING pFormat
)
2436 ULONG i
, count
, esize
;
2437 unsigned char alignment
;
2438 unsigned char *Buffer
;
2439 unsigned long SavedMemorySize
;
2440 unsigned long MemorySize
;
2442 TRACE("(%p,%p)\n", pStubMsg
, pFormat
);
2444 if (pFormat
[0] != RPC_FC_BOGUS_ARRAY
)
2446 ERR("invalid format type %x\n", pFormat
[0]);
2447 RpcRaiseException(RPC_S_INTERNAL_ERROR
);
2451 alignment
= pFormat
[1] + 1;
2455 pFormat
= ReadConformance(pStubMsg
, pFormat
);
2456 pFormat
= ReadVariance(pStubMsg
, pFormat
);
2458 ALIGN_POINTER(pStubMsg
->Buffer
, alignment
);
2460 SavedMemorySize
= pStubMsg
->MemorySize
;
2462 Buffer
= pStubMsg
->Buffer
;
2463 esize
= ComplexStructMemorySize(pStubMsg
, pFormat
);
2464 pStubMsg
->Buffer
= Buffer
;
2466 MemorySize
= esize
* pStubMsg
->MaxCount
;
2468 count
= pStubMsg
->ActualCount
;
2469 for (i
= 0; i
< count
; i
++)
2470 ComplexStructMemorySize(pStubMsg
, pFormat
);
2472 pStubMsg
->MemorySize
= SavedMemorySize
;
2474 pStubMsg
->MemorySize
+= MemorySize
;
2478 /***********************************************************************
2479 * NdrComplexArrayFree [RPCRT4.@]
2481 void WINAPI
NdrComplexArrayFree(PMIDL_STUB_MESSAGE pStubMsg
,
2482 unsigned char *pMemory
,
2483 PFORMAT_STRING pFormat
)
2485 ULONG i
, count
, def
;
2487 TRACE("(%p,%p,%p)\n", pStubMsg
, pMemory
, pFormat
);
2489 if (pFormat
[0] != RPC_FC_BOGUS_ARRAY
)
2491 ERR("invalid format type %x\n", pFormat
[0]);
2492 RpcRaiseException(RPC_S_INTERNAL_ERROR
);
2496 def
= *(const WORD
*)&pFormat
[2];
2499 pFormat
= ComputeConformance(pStubMsg
, pMemory
, pFormat
, def
);
2500 TRACE("conformance = %ld\n", pStubMsg
->MaxCount
);
2502 pFormat
= ComputeVariance(pStubMsg
, pMemory
, pFormat
, pStubMsg
->MaxCount
);
2503 TRACE("variance = %ld\n", pStubMsg
->ActualCount
);
2505 count
= pStubMsg
->ActualCount
;
2506 for (i
= 0; i
< count
; i
++)
2507 pMemory
= ComplexFree(pStubMsg
, pMemory
, pFormat
, NULL
);
2510 unsigned long UserMarshalFlags(PMIDL_STUB_MESSAGE pStubMsg
)
2512 return MAKELONG(pStubMsg
->dwDestContext
,
2513 pStubMsg
->RpcMsg
->DataRepresentation
);
2516 /***********************************************************************
2517 * NdrUserMarshalMarshall [RPCRT4.@]
2519 unsigned char * WINAPI
NdrUserMarshalMarshall(PMIDL_STUB_MESSAGE pStubMsg
,
2520 unsigned char *pMemory
,
2521 PFORMAT_STRING pFormat
)
2523 /* unsigned flags = pFormat[1]; */
2524 unsigned index
= *(const WORD
*)&pFormat
[2];
2525 unsigned long uflag
= UserMarshalFlags(pStubMsg
);
2526 TRACE("(%p,%p,%p)\n", pStubMsg
, pMemory
, pFormat
);
2527 TRACE("index=%d\n", index
);
2530 pStubMsg
->StubDesc
->aUserMarshalQuadruple
[index
].pfnMarshall(
2531 &uflag
, pStubMsg
->Buffer
, pMemory
);
2533 STD_OVERFLOW_CHECK(pStubMsg
);
2538 /***********************************************************************
2539 * NdrUserMarshalUnmarshall [RPCRT4.@]
2541 unsigned char * WINAPI
NdrUserMarshalUnmarshall(PMIDL_STUB_MESSAGE pStubMsg
,
2542 unsigned char **ppMemory
,
2543 PFORMAT_STRING pFormat
,
2544 unsigned char fMustAlloc
)
2546 /* unsigned flags = pFormat[1];*/
2547 unsigned index
= *(const WORD
*)&pFormat
[2];
2548 DWORD memsize
= *(const WORD
*)&pFormat
[4];
2549 unsigned long uflag
= UserMarshalFlags(pStubMsg
);
2550 TRACE("(%p,%p,%p,%d)\n", pStubMsg
, ppMemory
, pFormat
, fMustAlloc
);
2551 TRACE("index=%d\n", index
);
2553 if (fMustAlloc
|| !*ppMemory
)
2554 *ppMemory
= NdrAllocate(pStubMsg
, memsize
);
2557 pStubMsg
->StubDesc
->aUserMarshalQuadruple
[index
].pfnUnmarshall(
2558 &uflag
, pStubMsg
->Buffer
, *ppMemory
);
2563 /***********************************************************************
2564 * NdrUserMarshalBufferSize [RPCRT4.@]
2566 void WINAPI
NdrUserMarshalBufferSize(PMIDL_STUB_MESSAGE pStubMsg
,
2567 unsigned char *pMemory
,
2568 PFORMAT_STRING pFormat
)
2570 /* unsigned flags = pFormat[1];*/
2571 unsigned index
= *(const WORD
*)&pFormat
[2];
2572 DWORD bufsize
= *(const WORD
*)&pFormat
[6];
2573 unsigned long uflag
= UserMarshalFlags(pStubMsg
);
2574 TRACE("(%p,%p,%p)\n", pStubMsg
, pMemory
, pFormat
);
2575 TRACE("index=%d\n", index
);
2578 TRACE("size=%ld\n", bufsize
);
2579 pStubMsg
->BufferLength
+= bufsize
;
2583 pStubMsg
->BufferLength
=
2584 pStubMsg
->StubDesc
->aUserMarshalQuadruple
[index
].pfnBufferSize(
2585 &uflag
, pStubMsg
->BufferLength
, pMemory
);
2588 /***********************************************************************
2589 * NdrUserMarshalMemorySize [RPCRT4.@]
2591 unsigned long WINAPI
NdrUserMarshalMemorySize(PMIDL_STUB_MESSAGE pStubMsg
,
2592 PFORMAT_STRING pFormat
)
2594 unsigned index
= *(const WORD
*)&pFormat
[2];
2595 DWORD memsize
= *(const WORD
*)&pFormat
[4];
2596 DWORD bufsize
= *(const WORD
*)&pFormat
[6];
2598 TRACE("(%p,%p)\n", pStubMsg
, pFormat
);
2599 TRACE("index=%d\n", index
);
2601 pStubMsg
->MemorySize
+= memsize
;
2602 pStubMsg
->Buffer
+= bufsize
;
2604 return pStubMsg
->MemorySize
;
2607 /***********************************************************************
2608 * NdrUserMarshalFree [RPCRT4.@]
2610 void WINAPI
NdrUserMarshalFree(PMIDL_STUB_MESSAGE pStubMsg
,
2611 unsigned char *pMemory
,
2612 PFORMAT_STRING pFormat
)
2614 /* unsigned flags = pFormat[1]; */
2615 unsigned index
= *(const WORD
*)&pFormat
[2];
2616 unsigned long uflag
= UserMarshalFlags(pStubMsg
);
2617 TRACE("(%p,%p,%p)\n", pStubMsg
, pMemory
, pFormat
);
2618 TRACE("index=%d\n", index
);
2620 pStubMsg
->StubDesc
->aUserMarshalQuadruple
[index
].pfnFree(
2624 /***********************************************************************
2625 * NdrClearOutParameters [RPCRT4.@]
2627 void WINAPI
NdrClearOutParameters(PMIDL_STUB_MESSAGE pStubMsg
,
2628 PFORMAT_STRING pFormat
,
2631 FIXME("(%p,%p,%p): stub\n", pStubMsg
, pFormat
, ArgAddr
);
2634 /***********************************************************************
2635 * NdrConvert [RPCRT4.@]
2637 void WINAPI
NdrConvert( PMIDL_STUB_MESSAGE pStubMsg
, PFORMAT_STRING pFormat
)
2639 FIXME("(pStubMsg == ^%p, pFormat == ^%p): stub.\n", pStubMsg
, pFormat
);
2640 /* FIXME: since this stub doesn't do any converting, the proper behavior
2641 is to raise an exception */
2644 /***********************************************************************
2645 * NdrConvert2 [RPCRT4.@]
2647 void WINAPI
NdrConvert2( PMIDL_STUB_MESSAGE pStubMsg
, PFORMAT_STRING pFormat
, long NumberParams
)
2649 FIXME("(pStubMsg == ^%p, pFormat == ^%p, NumberParams == %ld): stub.\n",
2650 pStubMsg
, pFormat
, NumberParams
);
2651 /* FIXME: since this stub doesn't do any converting, the proper behavior
2652 is to raise an exception */
2655 typedef struct _NDR_CSTRUCT_FORMAT
2658 unsigned char alignment
;
2659 unsigned short memory_size
;
2660 short offset_to_array_description
;
2661 } NDR_CSTRUCT_FORMAT
, NDR_CVSTRUCT_FORMAT
;
2663 /***********************************************************************
2664 * NdrConformantStructMarshall [RPCRT4.@]
2666 unsigned char * WINAPI
NdrConformantStructMarshall(PMIDL_STUB_MESSAGE pStubMsg
,
2667 unsigned char *pMemory
,
2668 PFORMAT_STRING pFormat
)
2670 const NDR_CSTRUCT_FORMAT
* pCStructFormat
= (NDR_CSTRUCT_FORMAT
*)pFormat
;
2671 PFORMAT_STRING pCArrayFormat
;
2674 TRACE("(%p, %p, %p)\n", pStubMsg
, pMemory
, pFormat
);
2676 pFormat
+= sizeof(NDR_CSTRUCT_FORMAT
);
2677 if ((pCStructFormat
->type
!= RPC_FC_CPSTRUCT
) && (pCStructFormat
->type
!= RPC_FC_CSTRUCT
))
2679 ERR("invalid format type %x\n", pCStructFormat
->type
);
2680 RpcRaiseException(RPC_S_INTERNAL_ERROR
);
2684 pCArrayFormat
= (unsigned char*)&pCStructFormat
->offset_to_array_description
+
2685 pCStructFormat
->offset_to_array_description
;
2686 if (*pCArrayFormat
!= RPC_FC_CARRAY
)
2688 ERR("invalid array format type %x\n", pCStructFormat
->type
);
2689 RpcRaiseException(RPC_S_INTERNAL_ERROR
);
2692 esize
= *(const WORD
*)(pCArrayFormat
+2);
2694 ComputeConformance(pStubMsg
, pMemory
+ pCStructFormat
->memory_size
,
2695 pCArrayFormat
+ 4, 0);
2697 WriteConformance(pStubMsg
);
2699 ALIGN_POINTER(pStubMsg
->Buffer
, pCStructFormat
->alignment
+ 1);
2701 TRACE("memory_size = %d\n", pCStructFormat
->memory_size
);
2703 /* copy constant sized part of struct */
2704 pStubMsg
->BufferMark
= pStubMsg
->Buffer
;
2705 memcpy(pStubMsg
->Buffer
, pMemory
, pCStructFormat
->memory_size
+ pStubMsg
->MaxCount
* esize
);
2706 pStubMsg
->Buffer
+= pCStructFormat
->memory_size
+ pStubMsg
->MaxCount
* esize
;
2708 if (pCStructFormat
->type
== RPC_FC_CPSTRUCT
)
2709 EmbeddedPointerMarshall(pStubMsg
, pMemory
, pFormat
);
2711 STD_OVERFLOW_CHECK(pStubMsg
);
2716 /***********************************************************************
2717 * NdrConformantStructUnmarshall [RPCRT4.@]
2719 unsigned char * WINAPI
NdrConformantStructUnmarshall(PMIDL_STUB_MESSAGE pStubMsg
,
2720 unsigned char **ppMemory
,
2721 PFORMAT_STRING pFormat
,
2722 unsigned char fMustAlloc
)
2724 const NDR_CSTRUCT_FORMAT
* pCStructFormat
= (NDR_CSTRUCT_FORMAT
*)pFormat
;
2725 PFORMAT_STRING pCArrayFormat
;
2728 TRACE("(%p, %p, %p, %d)\n", pStubMsg
, ppMemory
, pFormat
, fMustAlloc
);
2730 pFormat
+= sizeof(NDR_CSTRUCT_FORMAT
);
2731 if ((pCStructFormat
->type
!= RPC_FC_CPSTRUCT
) && (pCStructFormat
->type
!= RPC_FC_CSTRUCT
))
2733 ERR("invalid format type %x\n", pCStructFormat
->type
);
2734 RpcRaiseException(RPC_S_INTERNAL_ERROR
);
2737 pCArrayFormat
= (unsigned char*)&pCStructFormat
->offset_to_array_description
+
2738 pCStructFormat
->offset_to_array_description
;
2739 if (*pCArrayFormat
!= RPC_FC_CARRAY
)
2741 ERR("invalid array format type %x\n", pCStructFormat
->type
);
2742 RpcRaiseException(RPC_S_INTERNAL_ERROR
);
2745 esize
= *(const WORD
*)(pCArrayFormat
+2);
2747 pCArrayFormat
= ReadConformance(pStubMsg
, pCArrayFormat
+ 4);
2749 ALIGN_POINTER(pStubMsg
->Buffer
, pCStructFormat
->alignment
+ 1);
2751 TRACE("memory_size = %d\n", pCStructFormat
->memory_size
);
2753 /* work out how much memory to allocate if we need to do so */
2754 if (!*ppMemory
|| fMustAlloc
)
2756 SIZE_T size
= pCStructFormat
->memory_size
+ pStubMsg
->MaxCount
* esize
;
2757 *ppMemory
= NdrAllocate(pStubMsg
, size
);
2760 /* now copy the data */
2761 pStubMsg
->BufferMark
= pStubMsg
->Buffer
;
2762 memcpy(*ppMemory
, pStubMsg
->Buffer
, pCStructFormat
->memory_size
+ pStubMsg
->MaxCount
* esize
);
2763 pStubMsg
->Buffer
+= pCStructFormat
->memory_size
+ pStubMsg
->MaxCount
* esize
;
2765 if (pCStructFormat
->type
== RPC_FC_CPSTRUCT
)
2766 EmbeddedPointerUnmarshall(pStubMsg
, ppMemory
, pFormat
, fMustAlloc
);
2771 /***********************************************************************
2772 * NdrConformantStructBufferSize [RPCRT4.@]
2774 void WINAPI
NdrConformantStructBufferSize(PMIDL_STUB_MESSAGE pStubMsg
,
2775 unsigned char *pMemory
,
2776 PFORMAT_STRING pFormat
)
2778 const NDR_CSTRUCT_FORMAT
* pCStructFormat
= (NDR_CSTRUCT_FORMAT
*)pFormat
;
2779 PFORMAT_STRING pCArrayFormat
;
2782 TRACE("(%p, %p, %p)\n", pStubMsg
, pMemory
, pFormat
);
2784 pFormat
+= sizeof(NDR_CSTRUCT_FORMAT
);
2785 if ((pCStructFormat
->type
!= RPC_FC_CPSTRUCT
) && (pCStructFormat
->type
!= RPC_FC_CSTRUCT
))
2787 ERR("invalid format type %x\n", pCStructFormat
->type
);
2788 RpcRaiseException(RPC_S_INTERNAL_ERROR
);
2791 pCArrayFormat
= (unsigned char*)&pCStructFormat
->offset_to_array_description
+
2792 pCStructFormat
->offset_to_array_description
;
2793 if (*pCArrayFormat
!= RPC_FC_CARRAY
)
2795 ERR("invalid array format type %x\n", pCStructFormat
->type
);
2796 RpcRaiseException(RPC_S_INTERNAL_ERROR
);
2799 esize
= *(const WORD
*)(pCArrayFormat
+2);
2801 pCArrayFormat
= ComputeConformance(pStubMsg
, pMemory
+ pCStructFormat
->memory_size
, pCArrayFormat
+4, 0);
2802 SizeConformance(pStubMsg
);
2804 ALIGN_LENGTH(pStubMsg
->BufferLength
, pCStructFormat
->alignment
+ 1);
2806 TRACE("memory_size = %d\n", pCStructFormat
->memory_size
);
2808 pStubMsg
->BufferLength
+= pCStructFormat
->memory_size
+ esize
* pStubMsg
->MaxCount
;
2810 if (pCStructFormat
->type
== RPC_FC_CPSTRUCT
)
2811 EmbeddedPointerBufferSize(pStubMsg
, pMemory
, pFormat
);
2814 /***********************************************************************
2815 * NdrConformantStructMemorySize [RPCRT4.@]
2817 unsigned long WINAPI
NdrConformantStructMemorySize(PMIDL_STUB_MESSAGE pStubMsg
,
2818 PFORMAT_STRING pFormat
)
2824 /***********************************************************************
2825 * NdrConformantStructFree [RPCRT4.@]
2827 void WINAPI
NdrConformantStructFree(PMIDL_STUB_MESSAGE pStubMsg
,
2828 unsigned char *pMemory
,
2829 PFORMAT_STRING pFormat
)
2834 /***********************************************************************
2835 * NdrConformantVaryingStructMarshall [RPCRT4.@]
2837 unsigned char * WINAPI
NdrConformantVaryingStructMarshall(PMIDL_STUB_MESSAGE pStubMsg
,
2838 unsigned char *pMemory
,
2839 PFORMAT_STRING pFormat
)
2841 const NDR_CVSTRUCT_FORMAT
* pCVStructFormat
= (NDR_CVSTRUCT_FORMAT
*)pFormat
;
2842 PFORMAT_STRING pCVArrayFormat
;
2845 TRACE("(%p, %p, %p)\n", pStubMsg
, pMemory
, pFormat
);
2847 pFormat
+= sizeof(NDR_CVSTRUCT_FORMAT
);
2848 if (pCVStructFormat
->type
!= RPC_FC_CVSTRUCT
)
2850 ERR("invalid format type %x\n", pCVStructFormat
->type
);
2851 RpcRaiseException(RPC_S_INTERNAL_ERROR
);
2855 pCVArrayFormat
= (unsigned char*)&pCVStructFormat
->offset_to_array_description
+
2856 pCVStructFormat
->offset_to_array_description
;
2857 switch (*pCVArrayFormat
)
2859 case RPC_FC_CVARRAY
:
2860 esize
= *(const WORD
*)(pCVArrayFormat
+2);
2862 pCVArrayFormat
= ComputeConformance(pStubMsg
, pMemory
+ pCVStructFormat
->memory_size
,
2863 pCVArrayFormat
+ 4, 0);
2864 pCVArrayFormat
= ComputeVariance(pStubMsg
, pMemory
+ pCVStructFormat
->memory_size
,
2867 case RPC_FC_C_CSTRING
:
2868 TRACE("string=%s\n", debugstr_a((char*)pMemory
+ pCVStructFormat
->memory_size
));
2869 pStubMsg
->ActualCount
= strlen((char*)pMemory
+ pCVStructFormat
->memory_size
)+1;
2870 esize
= sizeof(char);
2871 if (pCVArrayFormat
[1] == RPC_FC_STRING_SIZED
)
2872 pCVArrayFormat
= ComputeConformance(pStubMsg
, pMemory
+ pCVStructFormat
->memory_size
,
2873 pCVArrayFormat
+ 2, 0);
2875 pStubMsg
->MaxCount
= pStubMsg
->ActualCount
;
2877 case RPC_FC_C_WSTRING
:
2878 TRACE("string=%s\n", debugstr_w((LPWSTR
)pMemory
+ pCVStructFormat
->memory_size
));
2879 pStubMsg
->ActualCount
= strlenW((LPWSTR
)pMemory
+ pCVStructFormat
->memory_size
)+1;
2880 esize
= sizeof(WCHAR
);
2881 if (pCVArrayFormat
[1] == RPC_FC_STRING_SIZED
)
2882 pCVArrayFormat
= ComputeConformance(pStubMsg
, pMemory
+ pCVStructFormat
->memory_size
,
2883 pCVArrayFormat
+ 2, 0);
2885 pStubMsg
->MaxCount
= pStubMsg
->ActualCount
;
2888 ERR("invalid array format type %x\n", *pCVArrayFormat
);
2889 RpcRaiseException(RPC_S_INTERNAL_ERROR
);
2893 WriteConformance(pStubMsg
);
2895 ALIGN_POINTER(pStubMsg
->Buffer
, pCVStructFormat
->alignment
+ 1);
2897 TRACE("memory_size = %d\n", pCVStructFormat
->memory_size
);
2899 /* write constant sized part */
2900 pStubMsg
->BufferMark
= pStubMsg
->Buffer
;
2901 memcpy(pStubMsg
->Buffer
, pMemory
, pCVStructFormat
->memory_size
);
2902 pStubMsg
->Buffer
+= pCVStructFormat
->memory_size
;
2904 WriteVariance(pStubMsg
);
2906 /* write array part */
2907 memcpy(pStubMsg
->Buffer
, pMemory
+ pCVStructFormat
->memory_size
, pStubMsg
->ActualCount
* esize
);
2908 pStubMsg
->Buffer
+= pStubMsg
->ActualCount
* esize
;
2910 EmbeddedPointerMarshall(pStubMsg
, pMemory
, pFormat
);
2912 STD_OVERFLOW_CHECK(pStubMsg
);
2917 /***********************************************************************
2918 * NdrConformantVaryingStructUnmarshall [RPCRT4.@]
2920 unsigned char * WINAPI
NdrConformantVaryingStructUnmarshall(PMIDL_STUB_MESSAGE pStubMsg
,
2921 unsigned char **ppMemory
,
2922 PFORMAT_STRING pFormat
,
2923 unsigned char fMustAlloc
)
2925 const NDR_CVSTRUCT_FORMAT
* pCVStructFormat
= (NDR_CVSTRUCT_FORMAT
*)pFormat
;
2926 PFORMAT_STRING pCVArrayFormat
;
2928 unsigned char cvarray_type
;
2930 TRACE("(%p, %p, %p, %d)\n", pStubMsg
, ppMemory
, pFormat
, fMustAlloc
);
2932 pFormat
+= sizeof(NDR_CVSTRUCT_FORMAT
);
2933 if (pCVStructFormat
->type
!= RPC_FC_CVSTRUCT
)
2935 ERR("invalid format type %x\n", pCVStructFormat
->type
);
2936 RpcRaiseException(RPC_S_INTERNAL_ERROR
);
2940 pCVArrayFormat
= (unsigned char*)&pCVStructFormat
->offset_to_array_description
+
2941 pCVStructFormat
->offset_to_array_description
;
2942 cvarray_type
= *pCVArrayFormat
;
2943 switch (cvarray_type
)
2945 case RPC_FC_CVARRAY
:
2946 esize
= *(const WORD
*)(pCVArrayFormat
+2);
2947 pCVArrayFormat
= ReadConformance(pStubMsg
, pCVArrayFormat
+ 4);
2949 case RPC_FC_C_CSTRING
:
2950 esize
= sizeof(char);
2951 if (pCVArrayFormat
[1] == RPC_FC_STRING_SIZED
)
2952 pCVArrayFormat
= ReadConformance(pStubMsg
, pCVArrayFormat
+ 2);
2954 pCVArrayFormat
= ReadConformance(pStubMsg
, NULL
);
2956 case RPC_FC_C_WSTRING
:
2957 esize
= sizeof(WCHAR
);
2958 if (pCVArrayFormat
[1] == RPC_FC_STRING_SIZED
)
2959 pCVArrayFormat
= ReadConformance(pStubMsg
, pCVArrayFormat
+ 2);
2961 pCVArrayFormat
= ReadConformance(pStubMsg
, NULL
);
2964 ERR("invalid array format type %x\n", *pCVArrayFormat
);
2965 RpcRaiseException(RPC_S_INTERNAL_ERROR
);
2969 ALIGN_POINTER(pStubMsg
->Buffer
, pCVStructFormat
->alignment
+ 1);
2971 TRACE("memory_size = %d\n", pCVStructFormat
->memory_size
);
2973 /* work out how much memory to allocate if we need to do so */
2974 if (!*ppMemory
|| fMustAlloc
)
2976 SIZE_T size
= pCVStructFormat
->memory_size
+ pStubMsg
->MaxCount
* esize
;
2977 *ppMemory
= NdrAllocate(pStubMsg
, size
);
2980 /* copy the constant data */
2981 pStubMsg
->BufferMark
= pStubMsg
->Buffer
;
2982 memcpy(*ppMemory
, pStubMsg
->Buffer
, pCVStructFormat
->memory_size
);
2983 pStubMsg
->Buffer
+= pCVStructFormat
->memory_size
;
2985 pCVArrayFormat
= ReadVariance(pStubMsg
, pCVArrayFormat
);
2987 /* copy the array data */
2988 memcpy(*ppMemory
+ pCVStructFormat
->memory_size
, pStubMsg
->Buffer
,
2989 pStubMsg
->ActualCount
* esize
);
2990 pStubMsg
->Buffer
+= pStubMsg
->ActualCount
* esize
;
2992 if (cvarray_type
== RPC_FC_C_CSTRING
)
2993 TRACE("string=%s\n", debugstr_a((char *)(*ppMemory
+ pCVStructFormat
->memory_size
)));
2994 else if (cvarray_type
== RPC_FC_C_WSTRING
)
2995 TRACE("string=%s\n", debugstr_w((WCHAR
*)(*ppMemory
+ pCVStructFormat
->memory_size
)));
2997 EmbeddedPointerUnmarshall(pStubMsg
, ppMemory
, pFormat
, fMustAlloc
);
3002 /***********************************************************************
3003 * NdrConformantVaryingStructBufferSize [RPCRT4.@]
3005 void WINAPI
NdrConformantVaryingStructBufferSize(PMIDL_STUB_MESSAGE pStubMsg
,
3006 unsigned char *pMemory
,
3007 PFORMAT_STRING pFormat
)
3009 const NDR_CVSTRUCT_FORMAT
* pCVStructFormat
= (NDR_CVSTRUCT_FORMAT
*)pFormat
;
3010 PFORMAT_STRING pCVArrayFormat
;
3013 TRACE("(%p, %p, %p)\n", pStubMsg
, pMemory
, pFormat
);
3015 pFormat
+= sizeof(NDR_CVSTRUCT_FORMAT
);
3016 if (pCVStructFormat
->type
!= RPC_FC_CVSTRUCT
)
3018 ERR("invalid format type %x\n", pCVStructFormat
->type
);
3019 RpcRaiseException(RPC_S_INTERNAL_ERROR
);
3023 pCVArrayFormat
= (unsigned char*)&pCVStructFormat
->offset_to_array_description
+
3024 pCVStructFormat
->offset_to_array_description
;
3025 switch (*pCVArrayFormat
)
3027 case RPC_FC_CVARRAY
:
3028 esize
= *(const WORD
*)(pCVArrayFormat
+2);
3030 pCVArrayFormat
= ComputeConformance(pStubMsg
, pMemory
+ pCVStructFormat
->memory_size
,
3031 pCVArrayFormat
+ 4, 0);
3032 pCVArrayFormat
= ComputeVariance(pStubMsg
, pMemory
+ pCVStructFormat
->memory_size
,
3033 pCVArrayFormat
+ 4, 0);
3035 case RPC_FC_C_CSTRING
:
3036 TRACE("string=%s\n", debugstr_a((char*)pMemory
+ pCVStructFormat
->memory_size
));
3037 pStubMsg
->ActualCount
= strlen((char*)pMemory
+ pCVStructFormat
->memory_size
)+1;
3038 esize
= sizeof(char);
3039 if (pCVArrayFormat
[1] == RPC_FC_STRING_SIZED
)
3040 pCVArrayFormat
= ComputeConformance(pStubMsg
, pMemory
+ pCVStructFormat
->memory_size
,
3041 pCVArrayFormat
+ 2, 0);
3043 pStubMsg
->MaxCount
= pStubMsg
->ActualCount
;
3045 case RPC_FC_C_WSTRING
:
3046 TRACE("string=%s\n", debugstr_w((LPWSTR
)pMemory
+ pCVStructFormat
->memory_size
));
3047 pStubMsg
->ActualCount
= strlenW((LPWSTR
)pMemory
+ pCVStructFormat
->memory_size
)+1;
3048 esize
= sizeof(WCHAR
);
3049 if (pCVArrayFormat
[1] == RPC_FC_STRING_SIZED
)
3050 pCVArrayFormat
= ComputeConformance(pStubMsg
, pMemory
+ pCVStructFormat
->memory_size
,
3051 pCVArrayFormat
+ 2, 0);
3053 pStubMsg
->MaxCount
= pStubMsg
->ActualCount
;
3056 ERR("invalid array format type %x\n", *pCVArrayFormat
);
3057 RpcRaiseException(RPC_S_INTERNAL_ERROR
);
3061 SizeConformance(pStubMsg
);
3063 ALIGN_LENGTH(pStubMsg
->BufferLength
, pCVStructFormat
->alignment
+ 1);
3065 TRACE("memory_size = %d\n", pCVStructFormat
->memory_size
);
3067 pStubMsg
->BufferLength
+= pCVStructFormat
->memory_size
;
3068 SizeVariance(pStubMsg
);
3069 pStubMsg
->BufferLength
+= esize
* pStubMsg
->MaxCount
;
3071 EmbeddedPointerBufferSize(pStubMsg
, pMemory
, pFormat
);
3074 /***********************************************************************
3075 * NdrConformantVaryingStructMemorySize [RPCRT4.@]
3077 unsigned long WINAPI
NdrConformantVaryingStructMemorySize(PMIDL_STUB_MESSAGE pStubMsg
,
3078 PFORMAT_STRING pFormat
)
3080 const NDR_CVSTRUCT_FORMAT
* pCVStructFormat
= (NDR_CVSTRUCT_FORMAT
*)pFormat
;
3081 PFORMAT_STRING pCVArrayFormat
;
3083 unsigned char cvarray_type
;
3085 TRACE("(%p, %p)\n", pStubMsg
, pFormat
);
3087 pFormat
+= sizeof(NDR_CVSTRUCT_FORMAT
);
3088 if (pCVStructFormat
->type
!= RPC_FC_CVSTRUCT
)
3090 ERR("invalid format type %x\n", pCVStructFormat
->type
);
3091 RpcRaiseException(RPC_S_INTERNAL_ERROR
);
3095 pCVArrayFormat
= (unsigned char*)&pCVStructFormat
->offset_to_array_description
+
3096 pCVStructFormat
->offset_to_array_description
;
3097 cvarray_type
= *pCVArrayFormat
;
3098 switch (cvarray_type
)
3100 case RPC_FC_CVARRAY
:
3101 esize
= *(const WORD
*)(pCVArrayFormat
+2);
3102 pCVArrayFormat
= ReadConformance(pStubMsg
, pCVArrayFormat
+ 4);
3104 case RPC_FC_C_CSTRING
:
3105 esize
= sizeof(char);
3106 if (pCVArrayFormat
[1] == RPC_FC_STRING_SIZED
)
3107 pCVArrayFormat
= ReadConformance(pStubMsg
, pCVArrayFormat
+ 2);
3109 pCVArrayFormat
= ReadConformance(pStubMsg
, NULL
);
3111 case RPC_FC_C_WSTRING
:
3112 esize
= sizeof(WCHAR
);
3113 if (pCVArrayFormat
[1] == RPC_FC_STRING_SIZED
)
3114 pCVArrayFormat
= ReadConformance(pStubMsg
, pCVArrayFormat
+ 2);
3116 pCVArrayFormat
= ReadConformance(pStubMsg
, NULL
);
3119 ERR("invalid array format type %x\n", *pCVArrayFormat
);
3120 RpcRaiseException(RPC_S_INTERNAL_ERROR
);
3124 ALIGN_POINTER(pStubMsg
->Buffer
, pCVStructFormat
->alignment
+ 1);
3126 TRACE("memory_size = %d\n", pCVStructFormat
->memory_size
);
3128 pStubMsg
->Buffer
+= pCVStructFormat
->memory_size
;
3129 pCVArrayFormat
= ReadVariance(pStubMsg
, pCVArrayFormat
);
3130 pStubMsg
->Buffer
+= pCVStructFormat
->memory_size
+ pStubMsg
->ActualCount
* esize
;
3132 pStubMsg
->MemorySize
+= pCVStructFormat
->memory_size
+ pStubMsg
->MaxCount
* esize
;
3134 EmbeddedPointerMemorySize(pStubMsg
, pFormat
);
3136 return pCVStructFormat
->memory_size
+ pStubMsg
->MaxCount
* esize
;
3139 /***********************************************************************
3140 * NdrConformantVaryingStructFree [RPCRT4.@]
3142 void WINAPI
NdrConformantVaryingStructFree(PMIDL_STUB_MESSAGE pStubMsg
,
3143 unsigned char *pMemory
,
3144 PFORMAT_STRING pFormat
)
3146 const NDR_CVSTRUCT_FORMAT
* pCVStructFormat
= (NDR_CVSTRUCT_FORMAT
*)pFormat
;
3147 PFORMAT_STRING pCVArrayFormat
;
3150 TRACE("(%p, %p, %p)\n", pStubMsg
, pMemory
, pFormat
);
3152 pFormat
+= sizeof(NDR_CVSTRUCT_FORMAT
);
3153 if (pCVStructFormat
->type
!= RPC_FC_CVSTRUCT
)
3155 ERR("invalid format type %x\n", pCVStructFormat
->type
);
3156 RpcRaiseException(RPC_S_INTERNAL_ERROR
);
3160 pCVArrayFormat
= (unsigned char*)&pCVStructFormat
->offset_to_array_description
+
3161 pCVStructFormat
->offset_to_array_description
;
3162 switch (*pCVArrayFormat
)
3164 case RPC_FC_CVARRAY
:
3165 esize
= *(const WORD
*)(pCVArrayFormat
+2);
3167 pCVArrayFormat
= ComputeConformance(pStubMsg
, pMemory
+ pCVStructFormat
->memory_size
,
3168 pCVArrayFormat
+ 4, 0);
3169 pCVArrayFormat
= ComputeVariance(pStubMsg
, pMemory
+ pCVStructFormat
->memory_size
,
3172 case RPC_FC_C_CSTRING
:
3173 TRACE("string=%s\n", debugstr_a((char*)pMemory
+ pCVStructFormat
->memory_size
));
3174 pStubMsg
->ActualCount
= strlen((char*)pMemory
+ pCVStructFormat
->memory_size
)+1;
3175 esize
= sizeof(char);
3176 if (pCVArrayFormat
[1] == RPC_FC_STRING_SIZED
)
3177 pCVArrayFormat
= ComputeConformance(pStubMsg
, pMemory
+ pCVStructFormat
->memory_size
,
3178 pCVArrayFormat
+ 2, 0);
3180 pStubMsg
->MaxCount
= pStubMsg
->ActualCount
;
3182 case RPC_FC_C_WSTRING
:
3183 TRACE("string=%s\n", debugstr_w((LPWSTR
)pMemory
+ pCVStructFormat
->memory_size
));
3184 pStubMsg
->ActualCount
= strlenW((LPWSTR
)pMemory
+ pCVStructFormat
->memory_size
)+1;
3185 esize
= sizeof(WCHAR
);
3186 if (pCVArrayFormat
[1] == RPC_FC_STRING_SIZED
)
3187 pCVArrayFormat
= ComputeConformance(pStubMsg
, pMemory
+ pCVStructFormat
->memory_size
,
3188 pCVArrayFormat
+ 2, 0);
3190 pStubMsg
->MaxCount
= pStubMsg
->ActualCount
;
3193 ERR("invalid array format type %x\n", *pCVArrayFormat
);
3194 RpcRaiseException(RPC_S_INTERNAL_ERROR
);
3198 TRACE("memory_size = %d\n", pCVStructFormat
->memory_size
);
3200 EmbeddedPointerFree(pStubMsg
, pMemory
, pFormat
);
3206 unsigned char alignment
;
3207 unsigned short total_size
;
3208 } NDR_SMFARRAY_FORMAT
;
3213 unsigned char alignment
;
3214 unsigned long total_size
;
3215 } NDR_LGFARRAY_FORMAT
;
3217 /***********************************************************************
3218 * NdrFixedArrayMarshall [RPCRT4.@]
3220 unsigned char * WINAPI
NdrFixedArrayMarshall(PMIDL_STUB_MESSAGE pStubMsg
,
3221 unsigned char *pMemory
,
3222 PFORMAT_STRING pFormat
)
3224 const NDR_SMFARRAY_FORMAT
*pSmFArrayFormat
= (const NDR_SMFARRAY_FORMAT
*)pFormat
;
3225 unsigned long total_size
;
3227 TRACE("(%p, %p, %p)\n", pStubMsg
, pMemory
, pFormat
);
3229 if ((pSmFArrayFormat
->type
!= RPC_FC_SMFARRAY
) &&
3230 (pSmFArrayFormat
->type
!= RPC_FC_LGFARRAY
))
3232 ERR("invalid format type %x\n", pSmFArrayFormat
->type
);
3233 RpcRaiseException(RPC_S_INTERNAL_ERROR
);
3237 ALIGN_POINTER(pStubMsg
->Buffer
, pSmFArrayFormat
->alignment
+ 1);
3239 if (pSmFArrayFormat
->type
== RPC_FC_SMFARRAY
)
3241 total_size
= pSmFArrayFormat
->total_size
;
3242 pFormat
= (unsigned char *)(pSmFArrayFormat
+ 1);
3246 const NDR_LGFARRAY_FORMAT
*pLgFArrayFormat
= (const NDR_LGFARRAY_FORMAT
*)pFormat
;
3247 total_size
= pLgFArrayFormat
->total_size
;
3248 pFormat
= (unsigned char *)(pLgFArrayFormat
+ 1);
3250 memcpy(pStubMsg
->Buffer
, pMemory
, total_size
);
3251 pStubMsg
->Buffer
+= total_size
;
3253 pFormat
= EmbeddedPointerMarshall(pStubMsg
, pMemory
, pFormat
);
3258 /***********************************************************************
3259 * NdrFixedArrayUnmarshall [RPCRT4.@]
3261 unsigned char * WINAPI
NdrFixedArrayUnmarshall(PMIDL_STUB_MESSAGE pStubMsg
,
3262 unsigned char **ppMemory
,
3263 PFORMAT_STRING pFormat
,
3264 unsigned char fMustAlloc
)
3266 const NDR_SMFARRAY_FORMAT
*pSmFArrayFormat
= (const NDR_SMFARRAY_FORMAT
*)pFormat
;
3267 unsigned long total_size
;
3269 TRACE("(%p, %p, %p, %d)\n", pStubMsg
, ppMemory
, pFormat
, fMustAlloc
);
3271 if ((pSmFArrayFormat
->type
!= RPC_FC_SMFARRAY
) &&
3272 (pSmFArrayFormat
->type
!= RPC_FC_LGFARRAY
))
3274 ERR("invalid format type %x\n", pSmFArrayFormat
->type
);
3275 RpcRaiseException(RPC_S_INTERNAL_ERROR
);
3279 ALIGN_POINTER(pStubMsg
->Buffer
, pSmFArrayFormat
->alignment
+ 1);
3281 if (pSmFArrayFormat
->type
== RPC_FC_SMFARRAY
)
3283 total_size
= pSmFArrayFormat
->total_size
;
3284 pFormat
= (unsigned char *)(pSmFArrayFormat
+ 1);
3288 const NDR_LGFARRAY_FORMAT
*pLgFArrayFormat
= (const NDR_LGFARRAY_FORMAT
*)pFormat
;
3289 total_size
= pLgFArrayFormat
->total_size
;
3290 pFormat
= (unsigned char *)(pLgFArrayFormat
+ 1);
3293 if (fMustAlloc
|| !*ppMemory
)
3294 *ppMemory
= NdrAllocate(pStubMsg
, total_size
);
3295 memcpy(*ppMemory
, pStubMsg
->Buffer
, total_size
);
3296 pStubMsg
->Buffer
+= total_size
;
3298 pFormat
= EmbeddedPointerUnmarshall(pStubMsg
, ppMemory
, pFormat
, fMustAlloc
);
3303 /***********************************************************************
3304 * NdrFixedArrayBufferSize [RPCRT4.@]
3306 void WINAPI
NdrFixedArrayBufferSize(PMIDL_STUB_MESSAGE pStubMsg
,
3307 unsigned char *pMemory
,
3308 PFORMAT_STRING pFormat
)
3310 const NDR_SMFARRAY_FORMAT
*pSmFArrayFormat
= (const NDR_SMFARRAY_FORMAT
*)pFormat
;
3311 unsigned long total_size
;
3313 TRACE("(%p, %p, %p)\n", pStubMsg
, pMemory
, pFormat
);
3315 if ((pSmFArrayFormat
->type
!= RPC_FC_SMFARRAY
) &&
3316 (pSmFArrayFormat
->type
!= RPC_FC_LGFARRAY
))
3318 ERR("invalid format type %x\n", pSmFArrayFormat
->type
);
3319 RpcRaiseException(RPC_S_INTERNAL_ERROR
);
3323 ALIGN_LENGTH(pStubMsg
->BufferLength
, pSmFArrayFormat
->alignment
+ 1);
3325 if (pSmFArrayFormat
->type
== RPC_FC_SMFARRAY
)
3327 total_size
= pSmFArrayFormat
->total_size
;
3328 pFormat
= (unsigned char *)(pSmFArrayFormat
+ 1);
3332 const NDR_LGFARRAY_FORMAT
*pLgFArrayFormat
= (const NDR_LGFARRAY_FORMAT
*)pFormat
;
3333 total_size
= pLgFArrayFormat
->total_size
;
3334 pFormat
= (unsigned char *)(pLgFArrayFormat
+ 1);
3336 pStubMsg
->BufferLength
+= total_size
;
3338 EmbeddedPointerBufferSize(pStubMsg
, pMemory
, pFormat
);
3341 /***********************************************************************
3342 * NdrFixedArrayMemorySize [RPCRT4.@]
3344 unsigned long WINAPI
NdrFixedArrayMemorySize(PMIDL_STUB_MESSAGE pStubMsg
,
3345 PFORMAT_STRING pFormat
)
3347 const NDR_SMFARRAY_FORMAT
*pSmFArrayFormat
= (const NDR_SMFARRAY_FORMAT
*)pFormat
;
3348 unsigned long total_size
;
3350 TRACE("(%p, %p)\n", pStubMsg
, pFormat
);
3352 if ((pSmFArrayFormat
->type
!= RPC_FC_SMFARRAY
) &&
3353 (pSmFArrayFormat
->type
!= RPC_FC_LGFARRAY
))
3355 ERR("invalid format type %x\n", pSmFArrayFormat
->type
);
3356 RpcRaiseException(RPC_S_INTERNAL_ERROR
);
3360 ALIGN_POINTER(pStubMsg
->Buffer
, pSmFArrayFormat
->alignment
+ 1);
3362 if (pSmFArrayFormat
->type
== RPC_FC_SMFARRAY
)
3364 total_size
= pSmFArrayFormat
->total_size
;
3365 pFormat
= (unsigned char *)(pSmFArrayFormat
+ 1);
3369 const NDR_LGFARRAY_FORMAT
*pLgFArrayFormat
= (const NDR_LGFARRAY_FORMAT
*)pFormat
;
3370 total_size
= pLgFArrayFormat
->total_size
;
3371 pFormat
= (unsigned char *)(pLgFArrayFormat
+ 1);
3373 pStubMsg
->Buffer
+= total_size
;
3374 pStubMsg
->MemorySize
+= total_size
;
3376 EmbeddedPointerMemorySize(pStubMsg
, pFormat
);
3381 /***********************************************************************
3382 * NdrFixedArrayFree [RPCRT4.@]
3384 void WINAPI
NdrFixedArrayFree(PMIDL_STUB_MESSAGE pStubMsg
,
3385 unsigned char *pMemory
,
3386 PFORMAT_STRING pFormat
)
3388 const NDR_SMFARRAY_FORMAT
*pSmFArrayFormat
= (const NDR_SMFARRAY_FORMAT
*)pFormat
;
3390 TRACE("(%p, %p, %p)\n", pStubMsg
, pMemory
, pFormat
);
3392 if ((pSmFArrayFormat
->type
!= RPC_FC_SMFARRAY
) &&
3393 (pSmFArrayFormat
->type
!= RPC_FC_LGFARRAY
))
3395 ERR("invalid format type %x\n", pSmFArrayFormat
->type
);
3396 RpcRaiseException(RPC_S_INTERNAL_ERROR
);
3400 if (pSmFArrayFormat
->type
== RPC_FC_SMFARRAY
)
3401 pFormat
= (unsigned char *)(pSmFArrayFormat
+ 1);
3404 const NDR_LGFARRAY_FORMAT
*pLgFArrayFormat
= (const NDR_LGFARRAY_FORMAT
*)pFormat
;
3405 pFormat
= (unsigned char *)(pLgFArrayFormat
+ 1);
3408 EmbeddedPointerFree(pStubMsg
, pMemory
, pFormat
);
3411 /***********************************************************************
3412 * NdrVaryingArrayMarshall [RPCRT4.@]
3414 unsigned char * WINAPI
NdrVaryingArrayMarshall(PMIDL_STUB_MESSAGE pStubMsg
,
3415 unsigned char *pMemory
,
3416 PFORMAT_STRING pFormat
)
3422 /***********************************************************************
3423 * NdrVaryingArrayUnmarshall [RPCRT4.@]
3425 unsigned char * WINAPI
NdrVaryingArrayUnmarshall(PMIDL_STUB_MESSAGE pStubMsg
,
3426 unsigned char **ppMemory
,
3427 PFORMAT_STRING pFormat
,
3428 unsigned char fMustAlloc
)
3434 /***********************************************************************
3435 * NdrVaryingArrayBufferSize [RPCRT4.@]
3437 void WINAPI
NdrVaryingArrayBufferSize(PMIDL_STUB_MESSAGE pStubMsg
,
3438 unsigned char *pMemory
,
3439 PFORMAT_STRING pFormat
)
3444 /***********************************************************************
3445 * NdrVaryingArrayMemorySize [RPCRT4.@]
3447 unsigned long WINAPI
NdrVaryingArrayMemorySize(PMIDL_STUB_MESSAGE pStubMsg
,
3448 PFORMAT_STRING pFormat
)
3454 /***********************************************************************
3455 * NdrVaryingArrayFree [RPCRT4.@]
3457 void WINAPI
NdrVaryingArrayFree(PMIDL_STUB_MESSAGE pStubMsg
,
3458 unsigned char *pMemory
,
3459 PFORMAT_STRING pFormat
)
3464 /***********************************************************************
3465 * NdrEncapsulatedUnionMarshall [RPCRT4.@]
3467 unsigned char * WINAPI
NdrEncapsulatedUnionMarshall(PMIDL_STUB_MESSAGE pStubMsg
,
3468 unsigned char *pMemory
,
3469 PFORMAT_STRING pFormat
)
3475 /***********************************************************************
3476 * NdrEncapsulatedUnionUnmarshall [RPCRT4.@]
3478 unsigned char * WINAPI
NdrEncapsulatedUnionUnmarshall(PMIDL_STUB_MESSAGE pStubMsg
,
3479 unsigned char **ppMemory
,
3480 PFORMAT_STRING pFormat
,
3481 unsigned char fMustAlloc
)
3487 /***********************************************************************
3488 * NdrEncapsulatedUnionBufferSize [RPCRT4.@]
3490 void WINAPI
NdrEncapsulatedUnionBufferSize(PMIDL_STUB_MESSAGE pStubMsg
,
3491 unsigned char *pMemory
,
3492 PFORMAT_STRING pFormat
)
3497 /***********************************************************************
3498 * NdrEncapsulatedUnionMemorySize [RPCRT4.@]
3500 unsigned long WINAPI
NdrEncapsulatedUnionMemorySize(PMIDL_STUB_MESSAGE pStubMsg
,
3501 PFORMAT_STRING pFormat
)
3507 /***********************************************************************
3508 * NdrEncapsulatedUnionFree [RPCRT4.@]
3510 void WINAPI
NdrEncapsulatedUnionFree(PMIDL_STUB_MESSAGE pStubMsg
,
3511 unsigned char *pMemory
,
3512 PFORMAT_STRING pFormat
)
3517 static PFORMAT_STRING
get_arm_offset_from_union_arm_selector(PMIDL_STUB_MESSAGE pStubMsg
,
3518 unsigned long discriminant
,
3519 PFORMAT_STRING pFormat
)
3521 unsigned short num_arms
, arm
, type
;
3523 num_arms
= *(const SHORT
*)pFormat
& 0x0fff;
3525 for(arm
= 0; arm
< num_arms
; arm
++)
3527 if(discriminant
== *(const ULONG
*)pFormat
)
3535 type
= *(const unsigned short*)pFormat
;
3536 TRACE("type %04x\n", type
);
3537 if(arm
== num_arms
) /* default arm extras */
3541 ERR("no arm for 0x%lx and no default case\n", discriminant
);
3542 RpcRaiseException(RPC_S_INVALID_TAG
);
3547 TRACE("falling back to empty default case for 0x%lx\n", discriminant
);
3554 static PFORMAT_STRING
get_non_encapsulated_union_arm(PMIDL_STUB_MESSAGE pStubMsg
,
3556 PFORMAT_STRING pFormat
)
3558 pFormat
+= *(const SHORT
*)pFormat
;
3561 return get_arm_offset_from_union_arm_selector(pStubMsg
, value
, pFormat
);
3564 /***********************************************************************
3565 * NdrNonEncapsulatedUnionMarshall [RPCRT4.@]
3567 unsigned char * WINAPI
NdrNonEncapsulatedUnionMarshall(PMIDL_STUB_MESSAGE pStubMsg
,
3568 unsigned char *pMemory
,
3569 PFORMAT_STRING pFormat
)
3571 unsigned short type
;
3572 unsigned char switch_type
;
3574 TRACE("(%p, %p, %p)\n", pStubMsg
, pMemory
, pFormat
);
3577 switch_type
= *pFormat
;
3580 pFormat
= ComputeConformance(pStubMsg
, pMemory
, pFormat
, 0);
3581 TRACE("got switch value 0x%lx\n", pStubMsg
->MaxCount
);
3582 /* Marshall discriminant */
3583 NdrBaseTypeMarshall(pStubMsg
, (unsigned char *)&pStubMsg
->MaxCount
, &switch_type
);
3585 pFormat
= get_non_encapsulated_union_arm(pStubMsg
, pStubMsg
->MaxCount
, pFormat
);
3589 type
= *(const unsigned short*)pFormat
;
3590 if((type
& 0xff00) == 0x8000)
3592 unsigned char basetype
= LOBYTE(type
);
3593 return NdrBaseTypeMarshall(pStubMsg
, pMemory
, &basetype
);
3597 PFORMAT_STRING desc
= pFormat
+ *(const SHORT
*)pFormat
;
3598 NDR_MARSHALL m
= NdrMarshaller
[*desc
& NDR_TABLE_MASK
];
3601 unsigned char *saved_buffer
= NULL
;
3608 saved_buffer
= pStubMsg
->Buffer
;
3609 pStubMsg
->Buffer
+= 4; /* for pointer ID */
3610 PointerMarshall(pStubMsg
, saved_buffer
, *(unsigned char **)pMemory
, desc
);
3613 m(pStubMsg
, pMemory
, desc
);
3616 else FIXME("no marshaller for embedded type %02x\n", *desc
);
3621 static long unmarshall_discriminant(PMIDL_STUB_MESSAGE pStubMsg
,
3622 PFORMAT_STRING
*ppFormat
)
3624 long discriminant
= 0;
3632 discriminant
= *(UCHAR
*)pStubMsg
->Buffer
;
3633 pStubMsg
->Buffer
+= sizeof(UCHAR
);
3638 ALIGN_POINTER(pStubMsg
->Buffer
, sizeof(USHORT
));
3639 discriminant
= *(USHORT
*)pStubMsg
->Buffer
;
3640 pStubMsg
->Buffer
+= sizeof(USHORT
);
3644 ALIGN_POINTER(pStubMsg
->Buffer
, sizeof(ULONG
));
3645 discriminant
= *(ULONG
*)pStubMsg
->Buffer
;
3646 pStubMsg
->Buffer
+= sizeof(ULONG
);
3649 FIXME("Unhandled base type: 0x%02x\n", **ppFormat
);
3653 if (pStubMsg
->fHasNewCorrDesc
)
3657 return discriminant
;
3660 /**********************************************************************
3661 * NdrNonEncapsulatedUnionUnmarshall[RPCRT4.@]
3663 unsigned char * WINAPI
NdrNonEncapsulatedUnionUnmarshall(PMIDL_STUB_MESSAGE pStubMsg
,
3664 unsigned char **ppMemory
,
3665 PFORMAT_STRING pFormat
,
3666 unsigned char fMustAlloc
)
3669 unsigned short type
, size
;
3671 TRACE("(%p, %p, %p, %d)\n", pStubMsg
, ppMemory
, pFormat
, fMustAlloc
);
3674 /* Unmarshall discriminant */
3675 discriminant
= unmarshall_discriminant(pStubMsg
, &pFormat
);
3676 TRACE("unmarshalled discriminant %lx\n", discriminant
);
3678 pFormat
+= *(const SHORT
*)pFormat
;
3680 size
= *(const unsigned short*)pFormat
;
3683 pFormat
= get_arm_offset_from_union_arm_selector(pStubMsg
, discriminant
, pFormat
);
3687 if(!*ppMemory
|| fMustAlloc
)
3688 *ppMemory
= NdrAllocate(pStubMsg
, size
);
3690 type
= *(const unsigned short*)pFormat
;
3691 if((type
& 0xff00) == 0x8000)
3693 unsigned char basetype
= LOBYTE(type
);
3694 return NdrBaseTypeUnmarshall(pStubMsg
, ppMemory
, &basetype
, fMustAlloc
);
3698 PFORMAT_STRING desc
= pFormat
+ *(const SHORT
*)pFormat
;
3699 NDR_UNMARSHALL m
= NdrUnmarshaller
[*desc
& NDR_TABLE_MASK
];
3702 unsigned char *saved_buffer
= NULL
;
3709 **(void***)ppMemory
= NULL
;
3710 ALIGN_POINTER(pStubMsg
->Buffer
, 4);
3711 saved_buffer
= pStubMsg
->Buffer
;
3712 pStubMsg
->Buffer
+= 4; /* for pointer ID */
3713 PointerUnmarshall(pStubMsg
, saved_buffer
, *(unsigned char ***)ppMemory
, desc
, fMustAlloc
);
3716 m(pStubMsg
, ppMemory
, desc
, fMustAlloc
);
3719 else FIXME("no marshaller for embedded type %02x\n", *desc
);
3724 /***********************************************************************
3725 * NdrNonEncapsulatedUnionBufferSize [RPCRT4.@]
3727 void WINAPI
NdrNonEncapsulatedUnionBufferSize(PMIDL_STUB_MESSAGE pStubMsg
,
3728 unsigned char *pMemory
,
3729 PFORMAT_STRING pFormat
)
3731 unsigned short type
;
3732 unsigned char switch_type
;
3734 TRACE("(%p, %p, %p)\n", pStubMsg
, pMemory
, pFormat
);
3737 switch_type
= *pFormat
;
3740 pFormat
= ComputeConformance(pStubMsg
, pMemory
, pFormat
, 0);
3741 TRACE("got switch value 0x%lx\n", pStubMsg
->MaxCount
);
3742 /* Add discriminant size */
3743 NdrBaseTypeBufferSize(pStubMsg
, (unsigned char *)&pStubMsg
->MaxCount
, &switch_type
);
3745 pFormat
= get_non_encapsulated_union_arm(pStubMsg
, pStubMsg
->MaxCount
, pFormat
);
3749 type
= *(const unsigned short*)pFormat
;
3750 if((type
& 0xff00) == 0x8000)
3752 unsigned char basetype
= LOBYTE(type
);
3753 NdrBaseTypeBufferSize(pStubMsg
, pMemory
, &basetype
);
3757 PFORMAT_STRING desc
= pFormat
+ *(const SHORT
*)pFormat
;
3758 NDR_BUFFERSIZE m
= NdrBufferSizer
[*desc
& NDR_TABLE_MASK
];
3767 ALIGN_LENGTH(pStubMsg
->BufferLength
, 4);
3768 pStubMsg
->BufferLength
+= 4; /* for pointer ID */
3769 PointerBufferSize(pStubMsg
, *(unsigned char **)pMemory
, desc
);
3772 m(pStubMsg
, pMemory
, desc
);
3775 else FIXME("no buffersizer for embedded type %02x\n", *desc
);
3780 /***********************************************************************
3781 * NdrNonEncapsulatedUnionMemorySize [RPCRT4.@]
3783 unsigned long WINAPI
NdrNonEncapsulatedUnionMemorySize(PMIDL_STUB_MESSAGE pStubMsg
,
3784 PFORMAT_STRING pFormat
)
3787 if (pStubMsg
->fHasNewCorrDesc
)
3792 pFormat
+= *(const SHORT
*)pFormat
;
3793 TRACE("size %d\n", *(const SHORT
*)pFormat
);
3794 return *(const SHORT
*)pFormat
;
3797 /***********************************************************************
3798 * NdrNonEncapsulatedUnionFree [RPCRT4.@]
3800 void WINAPI
NdrNonEncapsulatedUnionFree(PMIDL_STUB_MESSAGE pStubMsg
,
3801 unsigned char *pMemory
,
3802 PFORMAT_STRING pFormat
)
3807 /***********************************************************************
3808 * NdrByteCountPointerMarshall [RPCRT4.@]
3810 unsigned char * WINAPI
NdrByteCountPointerMarshall(PMIDL_STUB_MESSAGE pStubMsg
,
3811 unsigned char *pMemory
,
3812 PFORMAT_STRING pFormat
)
3818 /***********************************************************************
3819 * NdrByteCountPointerUnmarshall [RPCRT4.@]
3821 unsigned char * WINAPI
NdrByteCountPointerUnmarshall(PMIDL_STUB_MESSAGE pStubMsg
,
3822 unsigned char **ppMemory
,
3823 PFORMAT_STRING pFormat
,
3824 unsigned char fMustAlloc
)
3830 /***********************************************************************
3831 * NdrByteCountPointerBufferSize [RPCRT4.@]
3833 void WINAPI
NdrByteCountPointerBufferSize(PMIDL_STUB_MESSAGE pStubMsg
,
3834 unsigned char *pMemory
,
3835 PFORMAT_STRING pFormat
)
3840 /***********************************************************************
3841 * NdrByteCountPointerMemorySize [RPCRT4.@]
3843 unsigned long WINAPI
NdrByteCountPointerMemorySize(PMIDL_STUB_MESSAGE pStubMsg
,
3844 PFORMAT_STRING pFormat
)
3850 /***********************************************************************
3851 * NdrByteCountPointerFree [RPCRT4.@]
3853 void WINAPI
NdrByteCountPointerFree(PMIDL_STUB_MESSAGE pStubMsg
,
3854 unsigned char *pMemory
,
3855 PFORMAT_STRING pFormat
)
3860 /***********************************************************************
3861 * NdrXmitOrRepAsMarshall [RPCRT4.@]
3863 unsigned char * WINAPI
NdrXmitOrRepAsMarshall(PMIDL_STUB_MESSAGE pStubMsg
,
3864 unsigned char *pMemory
,
3865 PFORMAT_STRING pFormat
)
3871 /***********************************************************************
3872 * NdrXmitOrRepAsUnmarshall [RPCRT4.@]
3874 unsigned char * WINAPI
NdrXmitOrRepAsUnmarshall(PMIDL_STUB_MESSAGE pStubMsg
,
3875 unsigned char **ppMemory
,
3876 PFORMAT_STRING pFormat
,
3877 unsigned char fMustAlloc
)
3883 /***********************************************************************
3884 * NdrXmitOrRepAsBufferSize [RPCRT4.@]
3886 void WINAPI
NdrXmitOrRepAsBufferSize(PMIDL_STUB_MESSAGE pStubMsg
,
3887 unsigned char *pMemory
,
3888 PFORMAT_STRING pFormat
)
3893 /***********************************************************************
3894 * NdrXmitOrRepAsMemorySize [RPCRT4.@]
3896 unsigned long WINAPI
NdrXmitOrRepAsMemorySize(PMIDL_STUB_MESSAGE pStubMsg
,
3897 PFORMAT_STRING pFormat
)
3903 /***********************************************************************
3904 * NdrXmitOrRepAsFree [RPCRT4.@]
3906 void WINAPI
NdrXmitOrRepAsFree(PMIDL_STUB_MESSAGE pStubMsg
,
3907 unsigned char *pMemory
,
3908 PFORMAT_STRING pFormat
)
3913 /***********************************************************************
3914 * NdrBaseTypeMarshall [internal]
3916 static unsigned char *WINAPI
NdrBaseTypeMarshall(
3917 PMIDL_STUB_MESSAGE pStubMsg
,
3918 unsigned char *pMemory
,
3919 PFORMAT_STRING pFormat
)
3921 TRACE("pStubMsg %p, pMemory %p, type 0x%02x\n", pStubMsg
, pMemory
, *pFormat
);
3929 *(UCHAR
*)pStubMsg
->Buffer
= *(UCHAR
*)pMemory
;
3930 pStubMsg
->Buffer
+= sizeof(UCHAR
);
3931 TRACE("value: 0x%02x\n", *(UCHAR
*)pMemory
);
3936 ALIGN_POINTER(pStubMsg
->Buffer
, sizeof(USHORT
));
3937 *(USHORT
*)pStubMsg
->Buffer
= *(USHORT
*)pMemory
;
3938 pStubMsg
->Buffer
+= sizeof(USHORT
);
3939 TRACE("value: 0x%04x\n", *(USHORT
*)pMemory
);
3943 case RPC_FC_ERROR_STATUS_T
:
3945 ALIGN_POINTER(pStubMsg
->Buffer
, sizeof(ULONG
));
3946 *(ULONG
*)pStubMsg
->Buffer
= *(ULONG
*)pMemory
;
3947 pStubMsg
->Buffer
+= sizeof(ULONG
);
3948 TRACE("value: 0x%08lx\n", *(ULONG
*)pMemory
);
3951 ALIGN_POINTER(pStubMsg
->Buffer
, sizeof(float));
3952 *(float *)pStubMsg
->Buffer
= *(float *)pMemory
;
3953 pStubMsg
->Buffer
+= sizeof(float);
3956 ALIGN_POINTER(pStubMsg
->Buffer
, sizeof(double));
3957 *(double *)pStubMsg
->Buffer
= *(double *)pMemory
;
3958 pStubMsg
->Buffer
+= sizeof(double);
3961 ALIGN_POINTER(pStubMsg
->Buffer
, sizeof(ULONGLONG
));
3962 *(ULONGLONG
*)pStubMsg
->Buffer
= *(ULONGLONG
*)pMemory
;
3963 pStubMsg
->Buffer
+= sizeof(ULONGLONG
);
3964 TRACE("value: %s\n", wine_dbgstr_longlong(*(ULONGLONG
*)pMemory
));
3967 /* only 16-bits on the wire, so do a sanity check */
3968 if (*(UINT
*)pMemory
> USHRT_MAX
)
3969 RpcRaiseException(RPC_X_ENUM_VALUE_OUT_OF_RANGE
);
3970 ALIGN_POINTER(pStubMsg
->Buffer
, sizeof(USHORT
));
3971 *(USHORT
*)pStubMsg
->Buffer
= *(UINT
*)pMemory
;
3972 pStubMsg
->Buffer
+= sizeof(USHORT
);
3973 TRACE("value: 0x%04x\n", *(UINT
*)pMemory
);
3976 FIXME("Unhandled base type: 0x%02x\n", *pFormat
);
3979 STD_OVERFLOW_CHECK(pStubMsg
);
3981 /* FIXME: what is the correct return value? */
3985 /***********************************************************************
3986 * NdrBaseTypeUnmarshall [internal]
3988 static unsigned char *WINAPI
NdrBaseTypeUnmarshall(
3989 PMIDL_STUB_MESSAGE pStubMsg
,
3990 unsigned char **ppMemory
,
3991 PFORMAT_STRING pFormat
,
3992 unsigned char fMustAlloc
)
3994 TRACE("pStubMsg: %p, ppMemory: %p, type: 0x%02x, fMustAlloc: %s\n", pStubMsg
, ppMemory
, *pFormat
, fMustAlloc
? "true" : "false");
3996 if (fMustAlloc
|| !*ppMemory
)
3998 unsigned char *Buffer
= pStubMsg
->Buffer
;
3999 unsigned long MemorySize
= pStubMsg
->MemorySize
;
4000 *ppMemory
= NdrAllocate(pStubMsg
, NdrBaseTypeMemorySize(pStubMsg
, pFormat
));
4001 pStubMsg
->MemorySize
= MemorySize
;
4002 pStubMsg
->Buffer
= Buffer
;
4005 TRACE("*ppMemory: %p\n", *ppMemory
);
4013 **(UCHAR
**)ppMemory
= *(UCHAR
*)pStubMsg
->Buffer
;
4014 pStubMsg
->Buffer
+= sizeof(UCHAR
);
4015 TRACE("value: 0x%02x\n", **(UCHAR
**)ppMemory
);
4020 ALIGN_POINTER(pStubMsg
->Buffer
, sizeof(USHORT
));
4021 **(USHORT
**)ppMemory
= *(USHORT
*)pStubMsg
->Buffer
;
4022 pStubMsg
->Buffer
+= sizeof(USHORT
);
4023 TRACE("value: 0x%04x\n", **(USHORT
**)ppMemory
);
4027 case RPC_FC_ERROR_STATUS_T
:
4029 ALIGN_POINTER(pStubMsg
->Buffer
, sizeof(ULONG
));
4030 **(ULONG
**)ppMemory
= *(ULONG
*)pStubMsg
->Buffer
;
4031 pStubMsg
->Buffer
+= sizeof(ULONG
);
4032 TRACE("value: 0x%08lx\n", **(ULONG
**)ppMemory
);
4035 ALIGN_POINTER(pStubMsg
->Buffer
, sizeof(float));
4036 **(float **)ppMemory
= *(float *)pStubMsg
->Buffer
;
4037 pStubMsg
->Buffer
+= sizeof(float);
4038 TRACE("value: %f\n", **(float **)ppMemory
);
4041 ALIGN_POINTER(pStubMsg
->Buffer
, sizeof(double));
4042 **(double **)ppMemory
= *(double*)pStubMsg
->Buffer
;
4043 pStubMsg
->Buffer
+= sizeof(double);
4044 TRACE("value: %f\n", **(double **)ppMemory
);
4047 ALIGN_POINTER(pStubMsg
->Buffer
, sizeof(ULONGLONG
));
4048 **(ULONGLONG
**)ppMemory
= *(ULONGLONG
*)pStubMsg
->Buffer
;
4049 pStubMsg
->Buffer
+= sizeof(ULONGLONG
);
4050 TRACE("value: %s\n", wine_dbgstr_longlong(**(ULONGLONG
**)ppMemory
));
4053 ALIGN_POINTER(pStubMsg
->Buffer
, sizeof(USHORT
));
4054 /* 16-bits on the wire, but int in memory */
4055 **(UINT
**)ppMemory
= *(USHORT
*)pStubMsg
->Buffer
;
4056 pStubMsg
->Buffer
+= sizeof(USHORT
);
4057 TRACE("value: 0x%08x\n", **(UINT
**)ppMemory
);
4060 FIXME("Unhandled base type: 0x%02x\n", *pFormat
);
4063 /* FIXME: what is the correct return value? */
4068 /***********************************************************************
4069 * NdrBaseTypeBufferSize [internal]
4071 static void WINAPI
NdrBaseTypeBufferSize(
4072 PMIDL_STUB_MESSAGE pStubMsg
,
4073 unsigned char *pMemory
,
4074 PFORMAT_STRING pFormat
)
4076 TRACE("pStubMsg %p, pMemory %p, type 0x%02x\n", pStubMsg
, pMemory
, *pFormat
);
4084 pStubMsg
->BufferLength
+= sizeof(UCHAR
);
4090 ALIGN_LENGTH(pStubMsg
->BufferLength
, sizeof(USHORT
));
4091 pStubMsg
->BufferLength
+= sizeof(USHORT
);
4096 ALIGN_LENGTH(pStubMsg
->BufferLength
, sizeof(ULONG
));
4097 pStubMsg
->BufferLength
+= sizeof(ULONG
);
4100 ALIGN_LENGTH(pStubMsg
->BufferLength
, sizeof(float));
4101 pStubMsg
->BufferLength
+= sizeof(float);
4104 ALIGN_LENGTH(pStubMsg
->BufferLength
, sizeof(double));
4105 pStubMsg
->BufferLength
+= sizeof(double);
4108 ALIGN_LENGTH(pStubMsg
->BufferLength
, sizeof(ULONGLONG
));
4109 pStubMsg
->BufferLength
+= sizeof(ULONGLONG
);
4111 case RPC_FC_ERROR_STATUS_T
:
4112 ALIGN_LENGTH(pStubMsg
->BufferLength
, sizeof(error_status_t
));
4113 pStubMsg
->BufferLength
+= sizeof(error_status_t
);
4116 FIXME("Unhandled base type: 0x%02x\n", *pFormat
);
4120 /***********************************************************************
4121 * NdrBaseTypeMemorySize [internal]
4123 static unsigned long WINAPI
NdrBaseTypeMemorySize(
4124 PMIDL_STUB_MESSAGE pStubMsg
,
4125 PFORMAT_STRING pFormat
)
4133 pStubMsg
->Buffer
+= sizeof(UCHAR
);
4134 pStubMsg
->MemorySize
+= sizeof(UCHAR
);
4135 return sizeof(UCHAR
);
4139 pStubMsg
->Buffer
+= sizeof(USHORT
);
4140 pStubMsg
->MemorySize
+= sizeof(USHORT
);
4141 return sizeof(USHORT
);
4144 pStubMsg
->Buffer
+= sizeof(ULONG
);
4145 pStubMsg
->MemorySize
+= sizeof(ULONG
);
4146 return sizeof(ULONG
);
4148 pStubMsg
->Buffer
+= sizeof(float);
4149 pStubMsg
->MemorySize
+= sizeof(float);
4150 return sizeof(float);
4152 pStubMsg
->Buffer
+= sizeof(double);
4153 pStubMsg
->MemorySize
+= sizeof(double);
4154 return sizeof(double);
4156 pStubMsg
->Buffer
+= sizeof(ULONGLONG
);
4157 pStubMsg
->MemorySize
+= sizeof(ULONGLONG
);
4158 return sizeof(ULONGLONG
);
4159 case RPC_FC_ERROR_STATUS_T
:
4160 pStubMsg
->Buffer
+= sizeof(error_status_t
);
4161 pStubMsg
->MemorySize
+= sizeof(error_status_t
);
4162 return sizeof(error_status_t
);
4165 pStubMsg
->Buffer
+= sizeof(INT
);
4166 pStubMsg
->MemorySize
+= sizeof(INT
);
4169 FIXME("Unhandled base type: 0x%02x\n", *pFormat
);
4174 /***********************************************************************
4175 * NdrBaseTypeFree [internal]
4177 static void WINAPI
NdrBaseTypeFree(PMIDL_STUB_MESSAGE pStubMsg
,
4178 unsigned char *pMemory
,
4179 PFORMAT_STRING pFormat
)
4181 TRACE("pStubMsg %p pMemory %p type 0x%02x\n", pStubMsg
, pMemory
, *pFormat
);
4186 /***********************************************************************
4187 * NdrClientContextMarshall
4189 void WINAPI
NdrClientContextMarshall(PMIDL_STUB_MESSAGE pStubMsg
,
4190 NDR_CCONTEXT ContextHandle
,
4193 FIXME("(%p, %p, %d): stub\n", pStubMsg
, ContextHandle
, fCheck
);
4196 /***********************************************************************
4197 * NdrClientContextUnmarshall
4199 void WINAPI
NdrClientContextUnmarshall(PMIDL_STUB_MESSAGE pStubMsg
,
4200 NDR_CCONTEXT
* pContextHandle
,
4201 RPC_BINDING_HANDLE BindHandle
)
4203 FIXME("(%p, %p, %p): stub\n", pStubMsg
, pContextHandle
, BindHandle
);
4206 void WINAPI
NdrServerContextMarshall(PMIDL_STUB_MESSAGE pStubMsg
,
4207 NDR_SCONTEXT ContextHandle
,
4208 NDR_RUNDOWN RundownRoutine
)
4210 FIXME("(%p, %p, %p): stub\n", pStubMsg
, ContextHandle
, RundownRoutine
);
4213 NDR_SCONTEXT WINAPI
NdrServerContextUnmarshall(PMIDL_STUB_MESSAGE pStubMsg
)
4215 FIXME("(%p): stub\n", pStubMsg
);
4219 void WINAPI
NdrContextHandleSize(PMIDL_STUB_MESSAGE pStubMsg
,
4220 unsigned char* pMemory
,
4221 PFORMAT_STRING pFormat
)
4223 FIXME("(%p, %p, %p): stub\n", pStubMsg
, pMemory
, pFormat
);
4226 NDR_SCONTEXT WINAPI
NdrContextHandleInitialize(PMIDL_STUB_MESSAGE pStubMsg
,
4227 PFORMAT_STRING pFormat
)
4229 FIXME("(%p, %p): stub\n", pStubMsg
, pFormat
);
4233 void WINAPI
NdrServerContextNewMarshall(PMIDL_STUB_MESSAGE pStubMsg
,
4234 NDR_SCONTEXT ContextHandle
,
4235 NDR_RUNDOWN RundownRoutine
,
4236 PFORMAT_STRING pFormat
)
4238 FIXME("(%p, %p, %p, %p): stub\n", pStubMsg
, ContextHandle
, RundownRoutine
, pFormat
);
4241 NDR_SCONTEXT WINAPI
NdrServerContextNewUnmarshall(PMIDL_STUB_MESSAGE pStubMsg
,
4242 PFORMAT_STRING pFormat
)
4244 FIXME("(%p, %p): stub\n", pStubMsg
, pFormat
);
4248 RPC_BINDING_HANDLE WINAPI
NDRCContextBinding(NDR_CCONTEXT CContext
)
4250 FIXME("(%p): stub\n", CContext
);