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
38 #include "wine/unicode.h"
39 #include "wine/rpcfc.h"
41 #include "wine/debug.h"
43 WINE_DEFAULT_DEBUG_CHANNEL(ole
);
45 #define BUFFER_PARANOIA 20
48 # define LITTLE_ENDIAN_UINT32_WRITE(pchar, uint32) \
49 (*((UINT32 *)(pchar)) = (uint32))
51 # define LITTLE_ENDIAN_UINT32_READ(pchar) \
52 (*((UINT32 *)(pchar)))
54 /* these would work for i386 too, but less efficient */
55 # define LITTLE_ENDIAN_UINT32_WRITE(pchar, uint32) \
56 (*(pchar) = LOBYTE(LOWORD(uint32)), \
57 *((pchar)+1) = HIBYTE(LOWORD(uint32)), \
58 *((pchar)+2) = LOBYTE(HIWORD(uint32)), \
59 *((pchar)+3) = HIBYTE(HIWORD(uint32)), \
60 (uint32)) /* allow as r-value */
62 # define LITTLE_ENDIAN_UINT32_READ(pchar) \
64 MAKEWORD(*(pchar), *((pchar)+1)), \
65 MAKEWORD(*((pchar)+2), *((pchar)+3))))
68 #define BIG_ENDIAN_UINT32_WRITE(pchar, uint32) \
69 (*((pchar)+3) = LOBYTE(LOWORD(uint32)), \
70 *((pchar)+2) = HIBYTE(LOWORD(uint32)), \
71 *((pchar)+1) = LOBYTE(HIWORD(uint32)), \
72 *(pchar) = HIBYTE(HIWORD(uint32)), \
73 (uint32)) /* allow as r-value */
75 #define BIG_ENDIAN_UINT32_READ(pchar) \
77 MAKEWORD(*((pchar)+3), *((pchar)+2)), \
78 MAKEWORD(*((pchar)+1), *(pchar))))
80 #ifdef NDR_LOCAL_IS_BIG_ENDIAN
81 # define NDR_LOCAL_UINT32_WRITE(pchar, uint32) \
82 BIG_ENDIAN_UINT32_WRITE(pchar, uint32)
83 # define NDR_LOCAL_UINT32_READ(pchar) \
84 BIG_ENDIAN_UINT32_READ(pchar)
86 # define NDR_LOCAL_UINT32_WRITE(pchar, uint32) \
87 LITTLE_ENDIAN_UINT32_WRITE(pchar, uint32)
88 # define NDR_LOCAL_UINT32_READ(pchar) \
89 LITTLE_ENDIAN_UINT32_READ(pchar)
92 /* _Align must be the desired alignment minus 1,
93 * e.g. ALIGN_LENGTH(len, 3) to align on a dword boundary. */
94 #define ALIGNED_LENGTH(_Len, _Align) (((_Len)+(_Align))&~(_Align))
95 #define ALIGNED_POINTER(_Ptr, _Align) ((LPVOID)ALIGNED_LENGTH((ULONG_PTR)(_Ptr), _Align))
96 #define ALIGN_LENGTH(_Len, _Align) _Len = ALIGNED_LENGTH(_Len, _Align)
97 #define ALIGN_POINTER(_Ptr, _Align) _Ptr = ALIGNED_POINTER(_Ptr, _Align)
99 #define STD_OVERFLOW_CHECK(_Msg) do { \
100 TRACE("buffer=%d/%ld\n", _Msg->Buffer - _Msg->BufferStart, _Msg->BufferLength); \
101 if (_Msg->Buffer > _Msg->BufferEnd) ERR("buffer overflow %d bytes\n", _Msg->Buffer - _Msg->BufferEnd); \
104 #define NDR_TABLE_SIZE 128
105 #define NDR_TABLE_MASK 127
107 NDR_MARSHALL NdrMarshaller
[NDR_TABLE_SIZE
] = {
108 0, 0, 0, 0, 0, 0, 0, 0,
109 0, 0, 0, 0, 0, 0, 0, 0,
113 NdrPointerMarshall
, NdrPointerMarshall
,
114 NdrPointerMarshall
, NdrPointerMarshall
,
116 NdrSimpleStructMarshall
, NdrSimpleStructMarshall
,
117 NdrConformantStructMarshall
, NdrConformantStructMarshall
,
118 NdrConformantVaryingStructMarshall
,
119 NdrComplexStructMarshall
,
121 NdrConformantArrayMarshall
,
122 NdrConformantVaryingArrayMarshall
,
123 NdrFixedArrayMarshall
, NdrFixedArrayMarshall
,
124 NdrVaryingArrayMarshall
, NdrVaryingArrayMarshall
,
125 NdrComplexArrayMarshall
,
127 NdrConformantStringMarshall
, 0, 0,
128 NdrConformantStringMarshall
,
129 NdrNonConformantStringMarshall
, 0, 0, 0,
131 NdrEncapsulatedUnionMarshall
,
132 NdrNonEncapsulatedUnionMarshall
,
134 NdrXmitOrRepAsMarshall
, NdrXmitOrRepAsMarshall
,
136 NdrInterfacePointerMarshall
,
139 NdrUserMarshalMarshall
141 NDR_UNMARSHALL NdrUnmarshaller
[NDR_TABLE_SIZE
] = {
142 0, 0, 0, 0, 0, 0, 0, 0,
143 0, 0, 0, 0, 0, 0, 0, 0,
147 NdrPointerUnmarshall
, NdrPointerUnmarshall
,
148 NdrPointerUnmarshall
, NdrPointerUnmarshall
,
150 NdrSimpleStructUnmarshall
, NdrSimpleStructUnmarshall
,
151 NdrConformantStructUnmarshall
, NdrConformantStructUnmarshall
,
152 NdrConformantVaryingStructUnmarshall
,
153 NdrComplexStructUnmarshall
,
155 NdrConformantArrayUnmarshall
,
156 NdrConformantVaryingArrayUnmarshall
,
157 NdrFixedArrayUnmarshall
, NdrFixedArrayUnmarshall
,
158 NdrVaryingArrayUnmarshall
, NdrVaryingArrayUnmarshall
,
159 NdrComplexArrayUnmarshall
,
161 NdrConformantStringUnmarshall
, 0, 0,
162 NdrConformantStringUnmarshall
,
163 NdrNonConformantStringUnmarshall
, 0, 0, 0,
165 NdrEncapsulatedUnionUnmarshall
,
166 NdrNonEncapsulatedUnionUnmarshall
,
168 NdrXmitOrRepAsUnmarshall
, NdrXmitOrRepAsUnmarshall
,
170 NdrInterfacePointerUnmarshall
,
173 NdrUserMarshalUnmarshall
175 NDR_BUFFERSIZE NdrBufferSizer
[NDR_TABLE_SIZE
] = {
176 0, 0, 0, 0, 0, 0, 0, 0,
177 0, 0, 0, 0, 0, 0, 0, 0,
181 NdrPointerBufferSize
, NdrPointerBufferSize
,
182 NdrPointerBufferSize
, NdrPointerBufferSize
,
184 NdrSimpleStructBufferSize
, NdrSimpleStructBufferSize
,
185 NdrConformantStructBufferSize
, NdrConformantStructBufferSize
,
186 NdrConformantVaryingStructBufferSize
,
187 NdrComplexStructBufferSize
,
189 NdrConformantArrayBufferSize
,
190 NdrConformantVaryingArrayBufferSize
,
191 NdrFixedArrayBufferSize
, NdrFixedArrayBufferSize
,
192 NdrVaryingArrayBufferSize
, NdrVaryingArrayBufferSize
,
193 NdrComplexArrayBufferSize
,
195 NdrConformantStringBufferSize
, 0, 0,
196 NdrConformantStringBufferSize
,
197 NdrNonConformantStringBufferSize
, 0, 0, 0,
199 NdrEncapsulatedUnionBufferSize
,
200 NdrNonEncapsulatedUnionBufferSize
,
202 NdrXmitOrRepAsBufferSize
, NdrXmitOrRepAsBufferSize
,
204 NdrInterfacePointerBufferSize
,
207 NdrUserMarshalBufferSize
209 NDR_MEMORYSIZE NdrMemorySizer
[NDR_TABLE_SIZE
] = {
210 0, 0, 0, 0, 0, 0, 0, 0,
211 0, 0, 0, 0, 0, 0, 0, 0,
215 NdrPointerMemorySize
, NdrPointerMemorySize
,
216 NdrPointerMemorySize
, NdrPointerMemorySize
,
218 NdrSimpleStructMemorySize
, NdrSimpleStructMemorySize
,
220 NdrComplexStructMemorySize
,
222 NdrConformantArrayMemorySize
, 0, 0, 0, 0, 0,
223 NdrComplexArrayMemorySize
,
225 NdrConformantStringMemorySize
, 0, 0,
226 NdrConformantStringMemorySize
,
227 NdrNonConformantStringMemorySize
, 0, 0, 0,
231 NdrInterfacePointerMemorySize
,
234 NdrUserMarshalMemorySize
236 NDR_FREE NdrFreer
[NDR_TABLE_SIZE
] = {
237 0, 0, 0, 0, 0, 0, 0, 0,
238 0, 0, 0, 0, 0, 0, 0, 0,
242 NdrPointerFree
, NdrPointerFree
,
243 NdrPointerFree
, NdrPointerFree
,
245 NdrSimpleStructFree
, NdrSimpleStructFree
,
246 NdrConformantStructFree
, NdrConformantStructFree
,
247 NdrConformantVaryingStructFree
,
248 NdrComplexStructFree
,
250 NdrConformantArrayFree
,
251 NdrConformantVaryingArrayFree
,
252 NdrFixedArrayFree
, NdrFixedArrayFree
,
253 NdrVaryingArrayFree
, NdrVaryingArrayFree
,
259 NdrEncapsulatedUnionFree
,
260 NdrNonEncapsulatedUnionFree
,
262 NdrXmitOrRepAsFree
, NdrXmitOrRepAsFree
,
264 NdrInterfacePointerFree
,
270 void * WINAPI
NdrAllocate(MIDL_STUB_MESSAGE
*pStubMsg
, size_t len
)
272 /* hmm, this is probably supposed to do more? */
273 return pStubMsg
->pfnAllocate(len
);
276 static void WINAPI
NdrFree(MIDL_STUB_MESSAGE
*pStubMsg
, unsigned char *Pointer
)
278 pStubMsg
->pfnFree(Pointer
);
281 PFORMAT_STRING
ReadConformance(MIDL_STUB_MESSAGE
*pStubMsg
, PFORMAT_STRING pFormat
)
283 pStubMsg
->MaxCount
= NDR_LOCAL_UINT32_READ(pStubMsg
->Buffer
);
284 pStubMsg
->Buffer
+= 4;
285 TRACE("unmarshalled conformance is %ld\n", pStubMsg
->MaxCount
);
289 PFORMAT_STRING
ComputeConformance(MIDL_STUB_MESSAGE
*pStubMsg
, unsigned char *pMemory
,
290 PFORMAT_STRING pFormat
, ULONG_PTR def
)
292 BYTE dtype
= pFormat
[0] & 0xf;
293 DWORD ofs
= (DWORD
)pFormat
[2] | ((DWORD
)pFormat
[3] << 8);
297 if (pFormat
[0] == 0xff) {
298 /* null descriptor */
299 pStubMsg
->MaxCount
= def
;
303 switch (pFormat
[0] & 0xf0) {
304 case RPC_FC_NORMAL_CONFORMANCE
:
305 TRACE("normal conformance, ofs=%ld\n", ofs
);
308 case RPC_FC_POINTER_CONFORMANCE
:
309 TRACE("pointer conformance, ofs=%ld\n", ofs
);
310 ptr
= pStubMsg
->Memory
+ ofs
;
312 case RPC_FC_TOP_LEVEL_CONFORMANCE
:
313 TRACE("toplevel conformance, ofs=%ld\n", ofs
);
314 if (pStubMsg
->StackTop
) {
315 ptr
= pStubMsg
->StackTop
+ ofs
;
318 /* -Os mode, MaxCount is already set */
322 case RPC_FC_CONSTANT_CONFORMANCE
:
323 data
= ofs
| ((DWORD
)pFormat
[1] << 16);
324 TRACE("constant conformance, val=%ld\n", data
);
325 pStubMsg
->MaxCount
= data
;
327 case RPC_FC_TOP_LEVEL_MULTID_CONFORMANCE
:
328 FIXME("toplevel multidimensional conformance, ofs=%ld\n", ofs
);
329 if (pStubMsg
->StackTop
) {
330 ptr
= pStubMsg
->StackTop
+ ofs
;
338 FIXME("unknown conformance type %x\n", pFormat
[0] & 0xf0);
341 switch (pFormat
[1]) {
342 case RPC_FC_DEREFERENCE
:
345 case RPC_FC_CALLBACK
:
346 /* ofs is index into StubDesc->apfnExprEval */
347 FIXME("handle callback\n");
362 data
= *(USHORT
*)ptr
;
371 FIXME("unknown conformance data type %x\n", dtype
);
374 TRACE("dereferenced data type %x at %p, got %ld\n", dtype
, ptr
, data
);
377 switch (pFormat
[1]) {
379 pStubMsg
->MaxCount
= data
;
381 case RPC_FC_DEREFERENCE
:
382 /* already handled */
385 FIXME("unknown conformance op %d\n", pFormat
[1]);
390 TRACE("resulting conformance is %ld\n", pStubMsg
->MaxCount
);
396 * NdrConformantString:
398 * What MS calls a ConformantString is, in DCE terminology,
399 * a Varying-Conformant String.
401 * maxlen: DWORD (max # of CHARTYPE characters, inclusive of '\0')
402 * offset: DWORD (actual string data begins at (offset) CHARTYPE's
403 * into unmarshalled string)
404 * length: DWORD (# of CHARTYPE characters, inclusive of '\0')
406 * data: CHARTYPE[maxlen]
408 * ], where CHARTYPE is the appropriate character type (specified externally)
412 /***********************************************************************
413 * NdrConformantStringMarshall [RPCRT4.@]
415 unsigned char *WINAPI
NdrConformantStringMarshall(MIDL_STUB_MESSAGE
*pStubMsg
,
416 unsigned char *pszMessage
, PFORMAT_STRING pFormat
)
418 unsigned long len
, esize
;
421 TRACE("(pStubMsg == ^%p, pszMessage == ^%p, pFormat == ^%p)\n", pStubMsg
, pszMessage
, pFormat
);
424 if (pszMessage
== NULL
) {
425 TRACE("string=%s\n", debugstr_a(pszMessage
));
429 else if (*pFormat
== RPC_FC_C_CSTRING
) {
430 TRACE("string=%s\n", debugstr_a(pszMessage
));
431 len
= strlen(pszMessage
)+1;
434 else if (*pFormat
== RPC_FC_C_WSTRING
) {
435 TRACE("string=%s\n", debugstr_w((LPWSTR
)pszMessage
));
436 len
= strlenW((LPWSTR
)pszMessage
)+1;
440 ERR("Unhandled string type: %#x\n", *pFormat
);
441 /* FIXME: raise an exception. */
445 if (pFormat
[1] != RPC_FC_PAD
) {
446 FIXME("sized string format=%d\n", pFormat
[1]);
449 assert( (pStubMsg
->BufferLength
>= (len
*esize
+ 13)) && (pStubMsg
->Buffer
!= NULL
) );
451 c
= pStubMsg
->Buffer
;
453 NDR_LOCAL_UINT32_WRITE(c
, len
); /* max length: strlen + 1 (for '\0') */
454 c
+= 8; /* offset: 0 */
455 NDR_LOCAL_UINT32_WRITE(c
, len
); /* actual length: (same) */
458 memcpy(c
, pszMessage
, len
*esize
); /* the string itself */
461 pStubMsg
->Buffer
= c
;
463 STD_OVERFLOW_CHECK(pStubMsg
);
466 return NULL
; /* is this always right? */
469 /***********************************************************************
470 * NdrConformantStringBufferSize [RPCRT4.@]
472 void WINAPI
NdrConformantStringBufferSize(PMIDL_STUB_MESSAGE pStubMsg
,
473 unsigned char* pMemory
, PFORMAT_STRING pFormat
)
475 TRACE("(pStubMsg == ^%p, pMemory == ^%p, pFormat == ^%p)\n", pStubMsg
, pMemory
, pFormat
);
478 if (pMemory
== NULL
) {
479 /* we need 12 octets for the [maxlen, offset, len] DWORDS */
480 TRACE("string=NULL\n");
481 pStubMsg
->BufferLength
+= 12 + BUFFER_PARANOIA
;
483 else if (*pFormat
== RPC_FC_C_CSTRING
) {
484 /* we need 12 octets for the [maxlen, offset, len] DWORDS, + 1 octet for '\0' */
485 TRACE("string=%s\n", debugstr_a((char*)pMemory
));
486 pStubMsg
->BufferLength
+= strlen((char*)pMemory
) + 13 + BUFFER_PARANOIA
;
488 else if (*pFormat
== RPC_FC_C_WSTRING
) {
489 /* we need 12 octets for the [maxlen, offset, len] DWORDS, + 2 octets for L'\0' */
490 TRACE("string=%s\n", debugstr_w((LPWSTR
)pMemory
));
491 pStubMsg
->BufferLength
+= strlenW((LPWSTR
)pMemory
)*2 + 14 + BUFFER_PARANOIA
;
494 ERR("Unhandled string type: %#x\n", *pFormat
);
495 /* FIXME: raise an exception */
498 if (pFormat
[1] != RPC_FC_PAD
) {
499 FIXME("sized string format=%d\n", pFormat
[1]);
503 /************************************************************************
504 * NdrConformantStringMemorySize [RPCRT4.@]
506 unsigned long WINAPI
NdrConformantStringMemorySize( PMIDL_STUB_MESSAGE pStubMsg
,
507 PFORMAT_STRING pFormat
)
509 unsigned long rslt
= 0;
511 TRACE("(pStubMsg == ^%p, pFormat == ^%p)\n", pStubMsg
, pFormat
);
513 assert(pStubMsg
&& pFormat
);
515 if (*pFormat
== RPC_FC_C_CSTRING
) {
516 rslt
= NDR_LOCAL_UINT32_READ(pStubMsg
->Buffer
); /* maxlen */
518 else if (*pFormat
== RPC_FC_C_WSTRING
) {
519 rslt
= NDR_LOCAL_UINT32_READ(pStubMsg
->Buffer
)*2; /* maxlen */
522 ERR("Unhandled string type: %#x\n", *pFormat
);
523 /* FIXME: raise an exception */
526 if (pFormat
[1] != RPC_FC_PAD
) {
527 FIXME("sized string format=%d\n", pFormat
[1]);
530 TRACE(" --> %lu\n", rslt
);
534 /************************************************************************
535 * NdrConformantStringUnmarshall [RPCRT4.@]
537 unsigned char *WINAPI
NdrConformantStringUnmarshall( PMIDL_STUB_MESSAGE pStubMsg
,
538 unsigned char** ppMemory
, PFORMAT_STRING pFormat
, unsigned char fMustAlloc
)
540 unsigned long len
, esize
, ofs
;
543 TRACE("(pStubMsg == ^%p, *pMemory == ^%p, pFormat == ^%p, fMustAlloc == %u)\n",
544 pStubMsg
, *ppMemory
, pFormat
, fMustAlloc
);
546 assert(pFormat
&& ppMemory
&& pStubMsg
);
548 pStubMsg
->Buffer
+= 4;
549 ofs
= NDR_LOCAL_UINT32_READ(pStubMsg
->Buffer
);
550 pStubMsg
->Buffer
+= 4;
551 len
= NDR_LOCAL_UINT32_READ(pStubMsg
->Buffer
);
552 pStubMsg
->Buffer
+= 4;
554 if (*pFormat
== RPC_FC_C_CSTRING
) esize
= 1;
555 else if (*pFormat
== RPC_FC_C_WSTRING
) esize
= 2;
557 ERR("Unhandled string type: %#x\n", *pFormat
);
558 /* FIXME: raise an exception */
562 if (pFormat
[1] != RPC_FC_PAD
) {
563 FIXME("sized string format=%d\n", pFormat
[1]);
567 *ppMemory
= NdrAllocate(pStubMsg
, len
*esize
+ BUFFER_PARANOIA
);
569 if (pStubMsg
->ReuseBuffer
&& !*ppMemory
)
570 /* for servers, we may just point straight into the RPC buffer, I think
571 * (I guess that's what MS does since MIDL code doesn't try to free) */
572 *ppMemory
= pStubMsg
->Buffer
- ofs
*esize
;
573 /* for clients, memory should be provided by caller */
581 pMem
= *ppMemory
+ ofs
*esize
;
583 if (pMem
!= pStubMsg
->Buffer
)
584 memcpy(pMem
, pStubMsg
->Buffer
, len
*esize
);
586 pStubMsg
->Buffer
+= len
*esize
;
588 if (*pFormat
== RPC_FC_C_CSTRING
) {
589 TRACE("string=%s\n", debugstr_a((char*)pMem
));
591 else if (*pFormat
== RPC_FC_C_WSTRING
) {
592 TRACE("string=%s\n", debugstr_w((LPWSTR
)pMem
));
595 return NULL
; /* FIXME: is this always right? */
598 /***********************************************************************
599 * NdrNonConformantStringMarshall [RPCRT4.@]
601 unsigned char * WINAPI
NdrNonConformantStringMarshall(PMIDL_STUB_MESSAGE pStubMsg
,
602 unsigned char *pMemory
,
603 PFORMAT_STRING pFormat
)
609 /***********************************************************************
610 * NdrNonConformantStringUnmarshall [RPCRT4.@]
612 unsigned char * WINAPI
NdrNonConformantStringUnmarshall(PMIDL_STUB_MESSAGE pStubMsg
,
613 unsigned char **ppMemory
,
614 PFORMAT_STRING pFormat
,
615 unsigned char fMustAlloc
)
621 /***********************************************************************
622 * NdrNonConformantStringBufferSize [RPCRT4.@]
624 void WINAPI
NdrNonConformantStringBufferSize(PMIDL_STUB_MESSAGE pStubMsg
,
625 unsigned char *pMemory
,
626 PFORMAT_STRING pFormat
)
631 /***********************************************************************
632 * NdrNonConformantStringMemorySize [RPCRT4.@]
634 unsigned long WINAPI
NdrNonConformantStringMemorySize(PMIDL_STUB_MESSAGE pStubMsg
,
635 PFORMAT_STRING pFormat
)
641 static inline void dump_pointer_attr(unsigned char attr
)
643 if (attr
& RPC_FC_P_ALLOCALLNODES
)
644 TRACE(" RPC_FC_P_ALLOCALLNODES");
645 if (attr
& RPC_FC_P_DONTFREE
)
646 TRACE(" RPC_FC_P_DONTFREE");
647 if (attr
& RPC_FC_P_ONSTACK
)
648 TRACE(" RPC_FC_P_ONSTACK");
649 if (attr
& RPC_FC_P_SIMPLEPOINTER
)
650 TRACE(" RPC_FC_P_SIMPLEPOINTER");
651 if (attr
& RPC_FC_P_DEREF
)
652 TRACE(" RPC_FC_P_DEREF");
656 /***********************************************************************
659 void WINAPI
PointerMarshall(PMIDL_STUB_MESSAGE pStubMsg
,
660 unsigned char *Buffer
,
661 unsigned char *Pointer
,
662 PFORMAT_STRING pFormat
)
664 unsigned type
= pFormat
[0], attr
= pFormat
[1];
668 TRACE("(%p,%p,%p,%p)\n", pStubMsg
, Buffer
, Pointer
, pFormat
);
669 TRACE("type=0x%x, attr=", type
); dump_pointer_attr(attr
);
671 if (attr
& RPC_FC_P_SIMPLEPOINTER
) desc
= pFormat
;
672 else desc
= pFormat
+ *(const SHORT
*)pFormat
;
673 if (attr
& RPC_FC_P_DEREF
) {
674 Pointer
= *(unsigned char**)Pointer
;
675 TRACE("deref => %p\n", Pointer
);
679 case RPC_FC_RP
: /* ref pointer (always non-null) */
680 #if 0 /* this causes problems for InstallShield so is disabled - we need more tests */
682 RpcRaiseException(RPC_X_NULL_REF_POINTER
);
685 case RPC_FC_UP
: /* unique pointer */
686 case RPC_FC_OP
: /* object pointer - same as unique here */
687 TRACE("writing %p to buffer\n", Pointer
);
688 NDR_LOCAL_UINT32_WRITE(pStubMsg
->Buffer
, (unsigned long)Pointer
);
689 pStubMsg
->Buffer
+= 4;
693 FIXME("unhandled ptr type=%02x\n", type
);
694 RpcRaiseException(RPC_X_BAD_STUB_DATA
);
697 TRACE("calling marshaller for type 0x%x\n", (int)*desc
);
700 m
= NdrMarshaller
[*desc
& NDR_TABLE_MASK
];
701 if (m
) m(pStubMsg
, Pointer
, desc
);
702 else FIXME("no marshaller for data type=%02x\n", *desc
);
705 STD_OVERFLOW_CHECK(pStubMsg
);
708 /***********************************************************************
711 void WINAPI
PointerUnmarshall(PMIDL_STUB_MESSAGE pStubMsg
,
712 unsigned char *Buffer
,
713 unsigned char **pPointer
,
714 PFORMAT_STRING pFormat
,
715 unsigned char fMustAlloc
)
717 unsigned type
= pFormat
[0], attr
= pFormat
[1];
720 DWORD pointer_id
= 0;
722 TRACE("(%p,%p,%p,%p,%d)\n", pStubMsg
, Buffer
, pPointer
, pFormat
, fMustAlloc
);
723 TRACE("type=0x%x, attr=", type
); dump_pointer_attr(attr
);
725 if (attr
& RPC_FC_P_SIMPLEPOINTER
) desc
= pFormat
;
726 else desc
= pFormat
+ *(const SHORT
*)pFormat
;
727 if (attr
& RPC_FC_P_DEREF
) {
728 pPointer
= *(unsigned char***)pPointer
;
729 TRACE("deref => %p\n", pPointer
);
733 case RPC_FC_RP
: /* ref pointer (always non-null) */
736 case RPC_FC_UP
: /* unique pointer */
737 pointer_id
= NDR_LOCAL_UINT32_READ(pStubMsg
->Buffer
);
738 pStubMsg
->Buffer
+= 4;
740 case RPC_FC_OP
: /* object pointer - we must free data before overwriting it */
741 pointer_id
= NDR_LOCAL_UINT32_READ(pStubMsg
->Buffer
);
742 pStubMsg
->Buffer
+= 4;
744 FIXME("free object pointer %p\n", *pPointer
);
748 FIXME("unhandled ptr type=%02x\n", type
);
749 RpcRaiseException(RPC_X_BAD_STUB_DATA
);
755 m
= NdrUnmarshaller
[*desc
& NDR_TABLE_MASK
];
756 if (m
) m(pStubMsg
, pPointer
, desc
, fMustAlloc
);
757 else FIXME("no unmarshaller for data type=%02x\n", *desc
);
760 TRACE("pointer=%p\n", *pPointer
);
763 /***********************************************************************
766 void WINAPI
PointerBufferSize(PMIDL_STUB_MESSAGE pStubMsg
,
767 unsigned char *Pointer
,
768 PFORMAT_STRING pFormat
)
770 unsigned type
= pFormat
[0], attr
= pFormat
[1];
774 TRACE("(%p,%p,%p)\n", pStubMsg
, Pointer
, pFormat
);
775 TRACE("type=%d, attr=%d\n", type
, attr
);
777 if (attr
& RPC_FC_P_SIMPLEPOINTER
) desc
= pFormat
;
778 else desc
= pFormat
+ *(const SHORT
*)pFormat
;
779 if (attr
& RPC_FC_P_DEREF
) {
780 Pointer
= *(unsigned char**)Pointer
;
781 TRACE("deref => %p\n", Pointer
);
785 case RPC_FC_RP
: /* ref pointer (always non-null) */
789 pStubMsg
->BufferLength
+= 4;
790 /* NULL pointer has no further representation */
796 FIXME("unhandled ptr type=%02x\n", type
);
797 RpcRaiseException(RPC_X_BAD_STUB_DATA
);
800 m
= NdrBufferSizer
[*desc
& NDR_TABLE_MASK
];
801 if (m
) m(pStubMsg
, Pointer
, desc
);
802 else FIXME("no buffersizer for data type=%02x\n", *desc
);
805 /***********************************************************************
806 * PointerMemorySize [RPCRT4.@]
808 unsigned long WINAPI
PointerMemorySize(PMIDL_STUB_MESSAGE pStubMsg
,
809 unsigned char *Buffer
,
810 PFORMAT_STRING pFormat
)
812 unsigned type
= pFormat
[0], attr
= pFormat
[1];
816 FIXME("(%p,%p,%p): stub\n", pStubMsg
, Buffer
, pFormat
);
817 TRACE("type=%d, attr=", type
); dump_pointer_attr(attr
);
819 if (attr
& RPC_FC_P_SIMPLEPOINTER
) desc
= pFormat
;
820 else desc
= pFormat
+ *(const SHORT
*)pFormat
;
821 if (attr
& RPC_FC_P_DEREF
) {
826 case RPC_FC_RP
: /* ref pointer (always non-null) */
829 FIXME("unhandled ptr type=%02x\n", type
);
830 RpcRaiseException(RPC_X_BAD_STUB_DATA
);
833 m
= NdrMemorySizer
[*desc
& NDR_TABLE_MASK
];
834 if (m
) m(pStubMsg
, desc
);
835 else FIXME("no memorysizer for data type=%02x\n", *desc
);
840 /***********************************************************************
841 * PointerFree [RPCRT4.@]
843 void WINAPI
PointerFree(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=%d, attr=", type
); dump_pointer_attr(attr
);
853 if (attr
& RPC_FC_P_DONTFREE
) return;
855 if (attr
& RPC_FC_P_SIMPLEPOINTER
) desc
= pFormat
;
856 else desc
= pFormat
+ *(const SHORT
*)pFormat
;
857 if (attr
& RPC_FC_P_DEREF
) {
858 Pointer
= *(unsigned char**)Pointer
;
859 TRACE("deref => %p\n", Pointer
);
862 if (!Pointer
) return;
864 m
= NdrFreer
[*desc
& NDR_TABLE_MASK
];
865 if (m
) m(pStubMsg
, Pointer
, desc
);
867 /* hmm... is this sensible?
868 * perhaps we should check if the memory comes from NdrAllocate,
869 * and deallocate only if so - checking if the pointer is between
870 * BufferStart and BufferEnd is probably no good since the buffer
871 * may be reallocated when the server wants to marshal the reply */
873 case RPC_FC_BOGUS_STRUCT
:
874 case RPC_FC_BOGUS_ARRAY
:
875 case RPC_FC_USER_MARSHAL
:
878 FIXME("unhandled data type=%02x\n", *desc
);
880 case RPC_FC_C_CSTRING
:
881 case RPC_FC_C_WSTRING
:
882 if (pStubMsg
->ReuseBuffer
) goto notfree
;
888 if (attr
& RPC_FC_P_ONSTACK
) {
889 TRACE("not freeing stack ptr %p\n", Pointer
);
892 TRACE("freeing %p\n", Pointer
);
893 NdrFree(pStubMsg
, Pointer
);
896 TRACE("not freeing %p\n", Pointer
);
899 /***********************************************************************
900 * EmbeddedPointerMarshall
902 unsigned char * WINAPI
EmbeddedPointerMarshall(PMIDL_STUB_MESSAGE pStubMsg
,
903 unsigned char *pMemory
,
904 PFORMAT_STRING pFormat
)
906 unsigned char *Mark
= pStubMsg
->BufferMark
;
907 unsigned long Offset
= pStubMsg
->Offset
;
908 unsigned ofs
, rep
, count
, stride
, xofs
;
910 TRACE("(%p,%p,%p)\n", pStubMsg
, pMemory
, pFormat
);
912 if (*pFormat
!= RPC_FC_PP
) return NULL
;
915 while (pFormat
[0] != RPC_FC_END
) {
916 switch (pFormat
[0]) {
918 FIXME("unknown repeat type %d\n", pFormat
[0]);
919 case RPC_FC_NO_REPEAT
:
927 case RPC_FC_FIXED_REPEAT
:
928 rep
= *(const WORD
*)&pFormat
[2];
929 stride
= *(const WORD
*)&pFormat
[4];
930 ofs
= *(const WORD
*)&pFormat
[6];
931 count
= *(const WORD
*)&pFormat
[8];
935 case RPC_FC_VARIABLE_REPEAT
:
936 rep
= pStubMsg
->MaxCount
;
937 stride
= *(const WORD
*)&pFormat
[2];
938 ofs
= *(const WORD
*)&pFormat
[4];
939 count
= *(const WORD
*)&pFormat
[6];
940 xofs
= (pFormat
[1] == RPC_FC_VARIABLE_OFFSET
) ? Offset
* stride
: 0;
944 /* ofs doesn't seem to matter in this context */
946 PFORMAT_STRING info
= pFormat
;
947 unsigned char *membase
= pMemory
+ xofs
;
949 for (u
=0; u
<count
; u
++,info
+=8) {
950 unsigned char *memptr
= membase
+ *(const SHORT
*)&info
[0];
951 unsigned char *bufptr
= Mark
+ *(const SHORT
*)&info
[2];
952 PointerMarshall(pStubMsg
, bufptr
, *(unsigned char**)memptr
, info
+4);
956 pFormat
+= 8 * count
;
959 STD_OVERFLOW_CHECK(pStubMsg
);
964 /***********************************************************************
965 * EmbeddedPointerUnmarshall
967 unsigned char * WINAPI
EmbeddedPointerUnmarshall(PMIDL_STUB_MESSAGE pStubMsg
,
968 unsigned char **ppMemory
,
969 PFORMAT_STRING pFormat
,
970 unsigned char fMustAlloc
)
972 unsigned char *Mark
= pStubMsg
->BufferMark
;
973 unsigned long Offset
= pStubMsg
->Offset
;
974 unsigned ofs
, rep
, count
, stride
, xofs
;
976 TRACE("(%p,%p,%p,%d)\n", pStubMsg
, ppMemory
, pFormat
, fMustAlloc
);
978 if (*pFormat
!= RPC_FC_PP
) return NULL
;
981 while (pFormat
[0] != RPC_FC_END
) {
982 switch (pFormat
[0]) {
984 FIXME("unknown repeat type %d\n", pFormat
[0]);
985 case RPC_FC_NO_REPEAT
:
993 case RPC_FC_FIXED_REPEAT
:
994 rep
= *(const WORD
*)&pFormat
[2];
995 stride
= *(const WORD
*)&pFormat
[4];
996 ofs
= *(const WORD
*)&pFormat
[6];
997 count
= *(const WORD
*)&pFormat
[8];
1001 case RPC_FC_VARIABLE_REPEAT
:
1002 rep
= pStubMsg
->MaxCount
;
1003 stride
= *(const WORD
*)&pFormat
[2];
1004 ofs
= *(const WORD
*)&pFormat
[4];
1005 count
= *(const WORD
*)&pFormat
[6];
1006 xofs
= (pFormat
[1] == RPC_FC_VARIABLE_OFFSET
) ? Offset
* stride
: 0;
1010 /* ofs doesn't seem to matter in this context */
1012 PFORMAT_STRING info
= pFormat
;
1013 unsigned char *membase
= *ppMemory
+ xofs
;
1015 for (u
=0; u
<count
; u
++,info
+=8) {
1016 unsigned char *memptr
= membase
+ *(const SHORT
*)&info
[0];
1017 unsigned char *bufptr
= Mark
+ *(const SHORT
*)&info
[2];
1018 PointerUnmarshall(pStubMsg
, bufptr
, (unsigned char**)memptr
, info
+4, fMustAlloc
);
1022 pFormat
+= 8 * count
;
1028 /***********************************************************************
1029 * EmbeddedPointerBufferSize
1031 void WINAPI
EmbeddedPointerBufferSize(PMIDL_STUB_MESSAGE pStubMsg
,
1032 unsigned char *pMemory
,
1033 PFORMAT_STRING pFormat
)
1035 unsigned long Offset
= pStubMsg
->Offset
;
1036 unsigned ofs
, rep
, count
, stride
, xofs
;
1038 TRACE("(%p,%p,%p)\n", pStubMsg
, pMemory
, pFormat
);
1039 if (*pFormat
!= RPC_FC_PP
) return;
1042 while (pFormat
[0] != RPC_FC_END
) {
1043 switch (pFormat
[0]) {
1045 FIXME("unknown repeat type %d\n", pFormat
[0]);
1046 case RPC_FC_NO_REPEAT
:
1054 case RPC_FC_FIXED_REPEAT
:
1055 rep
= *(const WORD
*)&pFormat
[2];
1056 stride
= *(const WORD
*)&pFormat
[4];
1057 ofs
= *(const WORD
*)&pFormat
[6];
1058 count
= *(const WORD
*)&pFormat
[8];
1062 case RPC_FC_VARIABLE_REPEAT
:
1063 rep
= pStubMsg
->MaxCount
;
1064 stride
= *(const WORD
*)&pFormat
[2];
1065 ofs
= *(const WORD
*)&pFormat
[4];
1066 count
= *(const WORD
*)&pFormat
[6];
1067 xofs
= (pFormat
[1] == RPC_FC_VARIABLE_OFFSET
) ? Offset
* stride
: 0;
1071 /* ofs doesn't seem to matter in this context */
1073 PFORMAT_STRING info
= pFormat
;
1074 unsigned char *membase
= pMemory
+ xofs
;
1076 for (u
=0; u
<count
; u
++,info
+=8) {
1077 unsigned char *memptr
= membase
+ *(const SHORT
*)&info
[0];
1078 PointerBufferSize(pStubMsg
, *(unsigned char**)memptr
, info
+4);
1082 pFormat
+= 8 * count
;
1086 /***********************************************************************
1087 * EmbeddedPointerMemorySize
1089 unsigned long WINAPI
EmbeddedPointerMemorySize(PMIDL_STUB_MESSAGE pStubMsg
,
1090 PFORMAT_STRING pFormat
)
1092 unsigned long Offset
= pStubMsg
->Offset
;
1093 unsigned char *Mark
= pStubMsg
->BufferMark
;
1094 unsigned ofs
, rep
, count
, stride
, xofs
;
1096 FIXME("(%p,%p): stub\n", pStubMsg
, pFormat
);
1097 if (*pFormat
!= RPC_FC_PP
) return 0;
1100 while (pFormat
[0] != RPC_FC_END
) {
1101 switch (pFormat
[0]) {
1103 FIXME("unknown repeat type %d\n", pFormat
[0]);
1104 case RPC_FC_NO_REPEAT
:
1112 case RPC_FC_FIXED_REPEAT
:
1113 rep
= *(const WORD
*)&pFormat
[2];
1114 stride
= *(const WORD
*)&pFormat
[4];
1115 ofs
= *(const WORD
*)&pFormat
[6];
1116 count
= *(const WORD
*)&pFormat
[8];
1120 case RPC_FC_VARIABLE_REPEAT
:
1121 rep
= pStubMsg
->MaxCount
;
1122 stride
= *(const WORD
*)&pFormat
[2];
1123 ofs
= *(const WORD
*)&pFormat
[4];
1124 count
= *(const WORD
*)&pFormat
[6];
1125 xofs
= (pFormat
[1] == RPC_FC_VARIABLE_OFFSET
) ? Offset
* stride
: 0;
1129 /* ofs doesn't seem to matter in this context */
1131 PFORMAT_STRING info
= pFormat
;
1133 for (u
=0; u
<count
; u
++,info
+=8) {
1134 unsigned char *bufptr
= Mark
+ *(const SHORT
*)&info
[2];
1135 PointerMemorySize(pStubMsg
, bufptr
, info
+4);
1139 pFormat
+= 8 * count
;
1145 /***********************************************************************
1146 * EmbeddedPointerFree
1148 void WINAPI
EmbeddedPointerFree(PMIDL_STUB_MESSAGE pStubMsg
,
1149 unsigned char *pMemory
,
1150 PFORMAT_STRING pFormat
)
1152 unsigned long Offset
= pStubMsg
->Offset
;
1153 unsigned ofs
, rep
, count
, stride
, xofs
;
1155 TRACE("(%p,%p,%p)\n", pStubMsg
, pMemory
, pFormat
);
1156 if (*pFormat
!= RPC_FC_PP
) return;
1159 while (pFormat
[0] != RPC_FC_END
) {
1160 switch (pFormat
[0]) {
1162 FIXME("unknown repeat type %d\n", pFormat
[0]);
1163 case RPC_FC_NO_REPEAT
:
1171 case RPC_FC_FIXED_REPEAT
:
1172 rep
= *(const WORD
*)&pFormat
[2];
1173 stride
= *(const WORD
*)&pFormat
[4];
1174 ofs
= *(const WORD
*)&pFormat
[6];
1175 count
= *(const WORD
*)&pFormat
[8];
1179 case RPC_FC_VARIABLE_REPEAT
:
1180 rep
= pStubMsg
->MaxCount
;
1181 stride
= *(const WORD
*)&pFormat
[2];
1182 ofs
= *(const WORD
*)&pFormat
[4];
1183 count
= *(const WORD
*)&pFormat
[6];
1184 xofs
= (pFormat
[1] == RPC_FC_VARIABLE_OFFSET
) ? Offset
* stride
: 0;
1188 /* ofs doesn't seem to matter in this context */
1190 PFORMAT_STRING info
= pFormat
;
1191 unsigned char *membase
= pMemory
+ xofs
;
1193 for (u
=0; u
<count
; u
++,info
+=8) {
1194 unsigned char *memptr
= membase
+ *(const SHORT
*)&info
[0];
1195 PointerFree(pStubMsg
, *(unsigned char**)memptr
, info
+4);
1199 pFormat
+= 8 * count
;
1203 /***********************************************************************
1204 * NdrPointerMarshall [RPCRT4.@]
1206 unsigned char * WINAPI
NdrPointerMarshall(PMIDL_STUB_MESSAGE pStubMsg
,
1207 unsigned char *pMemory
,
1208 PFORMAT_STRING pFormat
)
1210 TRACE("(%p,%p,%p)\n", pStubMsg
, pMemory
, pFormat
);
1212 pStubMsg
->BufferMark
= pStubMsg
->Buffer
;
1213 PointerMarshall(pStubMsg
, pStubMsg
->Buffer
, pMemory
, pFormat
);
1215 STD_OVERFLOW_CHECK(pStubMsg
);
1220 /***********************************************************************
1221 * NdrPointerUnmarshall [RPCRT4.@]
1223 unsigned char * WINAPI
NdrPointerUnmarshall(PMIDL_STUB_MESSAGE pStubMsg
,
1224 unsigned char **ppMemory
,
1225 PFORMAT_STRING pFormat
,
1226 unsigned char fMustAlloc
)
1228 TRACE("(%p,%p,%p,%d)\n", pStubMsg
, ppMemory
, pFormat
, fMustAlloc
);
1230 pStubMsg
->BufferMark
= pStubMsg
->Buffer
;
1231 PointerUnmarshall(pStubMsg
, pStubMsg
->Buffer
, ppMemory
, pFormat
, fMustAlloc
);
1236 /***********************************************************************
1237 * NdrPointerBufferSize [RPCRT4.@]
1239 void WINAPI
NdrPointerBufferSize(PMIDL_STUB_MESSAGE pStubMsg
,
1240 unsigned char *pMemory
,
1241 PFORMAT_STRING pFormat
)
1243 TRACE("(%p,%p,%p)\n", pStubMsg
, pMemory
, pFormat
);
1244 PointerBufferSize(pStubMsg
, pMemory
, pFormat
);
1247 /***********************************************************************
1248 * NdrPointerMemorySize [RPCRT4.@]
1250 unsigned long WINAPI
NdrPointerMemorySize(PMIDL_STUB_MESSAGE pStubMsg
,
1251 PFORMAT_STRING pFormat
)
1253 /* unsigned size = *(LPWORD)(pFormat+2); */
1254 FIXME("(%p,%p): stub\n", pStubMsg
, pFormat
);
1255 PointerMemorySize(pStubMsg
, pStubMsg
->Buffer
, pFormat
);
1259 /***********************************************************************
1260 * NdrPointerFree [RPCRT4.@]
1262 void WINAPI
NdrPointerFree(PMIDL_STUB_MESSAGE pStubMsg
,
1263 unsigned char *pMemory
,
1264 PFORMAT_STRING pFormat
)
1266 TRACE("(%p,%p,%p)\n", pStubMsg
, pMemory
, pFormat
);
1267 PointerFree(pStubMsg
, pMemory
, pFormat
);
1270 /***********************************************************************
1271 * NdrSimpleStructMarshall [RPCRT4.@]
1273 unsigned char * WINAPI
NdrSimpleStructMarshall(PMIDL_STUB_MESSAGE pStubMsg
,
1274 unsigned char *pMemory
,
1275 PFORMAT_STRING pFormat
)
1277 unsigned size
= *(const WORD
*)(pFormat
+2);
1278 TRACE("(%p,%p,%p)\n", pStubMsg
, pMemory
, pFormat
);
1280 memcpy(pStubMsg
->Buffer
, pMemory
, size
);
1281 pStubMsg
->BufferMark
= pStubMsg
->Buffer
;
1282 pStubMsg
->Buffer
+= size
;
1284 if (pFormat
[0] != RPC_FC_STRUCT
)
1285 EmbeddedPointerMarshall(pStubMsg
, pMemory
, pFormat
+4);
1288 * This test does not work when NdrSimpleStructMarshall is called
1289 * by an rpc-server to marshall data to return to the client because
1290 * BufferStart and BufferEnd are bogus. MIDL does not update them
1291 * when a new buffer is allocated in order to return data to the caller.
1294 STD_OVERFLOW_CHECK(pStubMsg
);
1300 /***********************************************************************
1301 * NdrSimpleStructUnmarshall [RPCRT4.@]
1303 unsigned char * WINAPI
NdrSimpleStructUnmarshall(PMIDL_STUB_MESSAGE pStubMsg
,
1304 unsigned char **ppMemory
,
1305 PFORMAT_STRING pFormat
,
1306 unsigned char fMustAlloc
)
1308 unsigned size
= *(const WORD
*)(pFormat
+2);
1309 TRACE("(%p,%p,%p,%d)\n", pStubMsg
, ppMemory
, pFormat
, fMustAlloc
);
1312 *ppMemory
= NdrAllocate(pStubMsg
, size
);
1313 memcpy(*ppMemory
, pStubMsg
->Buffer
, size
);
1315 if (pStubMsg
->ReuseBuffer
&& !*ppMemory
)
1316 /* for servers, we may just point straight into the RPC buffer, I think
1317 * (I guess that's what MS does since MIDL code doesn't try to free) */
1318 *ppMemory
= pStubMsg
->Buffer
;
1320 /* for clients, memory should be provided by caller */
1321 memcpy(*ppMemory
, pStubMsg
->Buffer
, size
);
1324 pStubMsg
->BufferMark
= pStubMsg
->Buffer
;
1325 pStubMsg
->Buffer
+= size
;
1327 if (pFormat
[0] != RPC_FC_STRUCT
)
1328 EmbeddedPointerUnmarshall(pStubMsg
, ppMemory
, pFormat
+4, fMustAlloc
);
1334 /***********************************************************************
1335 * NdrSimpleTypeUnmarshall [RPCRT4.@]
1337 void WINAPI
NdrSimpleTypeMarshall(PMIDL_STUB_MESSAGE pStubMsg
,
1338 unsigned char *pMemory
,
1339 unsigned char FormatChar
)
1345 /***********************************************************************
1346 * NdrSimpleTypeUnmarshall [RPCRT4.@]
1348 void WINAPI
NdrSimpleTypeUnmarshall(PMIDL_STUB_MESSAGE pStubMsg
,
1349 unsigned char *pMemory
,
1350 unsigned char FormatChar
)
1356 /***********************************************************************
1357 * NdrSimpleStructBufferSize [RPCRT4.@]
1359 void WINAPI
NdrSimpleStructBufferSize(PMIDL_STUB_MESSAGE pStubMsg
,
1360 unsigned char *pMemory
,
1361 PFORMAT_STRING pFormat
)
1363 unsigned size
= *(const WORD
*)(pFormat
+2);
1364 TRACE("(%p,%p,%p)\n", pStubMsg
, pMemory
, pFormat
);
1365 pStubMsg
->BufferLength
+= size
;
1366 if (pFormat
[0] != RPC_FC_STRUCT
)
1367 EmbeddedPointerBufferSize(pStubMsg
, pMemory
, pFormat
+4);
1370 /***********************************************************************
1371 * NdrSimpleStructMemorySize [RPCRT4.@]
1373 unsigned long WINAPI
NdrSimpleStructMemorySize(PMIDL_STUB_MESSAGE pStubMsg
,
1374 PFORMAT_STRING pFormat
)
1376 /* unsigned size = *(LPWORD)(pFormat+2); */
1377 FIXME("(%p,%p): stub\n", pStubMsg
, pFormat
);
1378 if (pFormat
[0] != RPC_FC_STRUCT
)
1379 EmbeddedPointerMemorySize(pStubMsg
, pFormat
+4);
1383 /***********************************************************************
1384 * NdrSimpleStructFree [RPCRT4.@]
1386 void WINAPI
NdrSimpleStructFree(PMIDL_STUB_MESSAGE pStubMsg
,
1387 unsigned char *pMemory
,
1388 PFORMAT_STRING pFormat
)
1390 TRACE("(%p,%p,%p)\n", pStubMsg
, pMemory
, pFormat
);
1391 if (pFormat
[0] != RPC_FC_STRUCT
)
1392 EmbeddedPointerFree(pStubMsg
, pMemory
, pFormat
+4);
1396 unsigned long WINAPI
EmbeddedComplexSize(PMIDL_STUB_MESSAGE pStubMsg
,
1397 PFORMAT_STRING pFormat
)
1401 case RPC_FC_PSTRUCT
:
1402 case RPC_FC_CSTRUCT
:
1403 case RPC_FC_BOGUS_STRUCT
:
1404 return *(const WORD
*)&pFormat
[2];
1405 case RPC_FC_USER_MARSHAL
:
1406 return *(const WORD
*)&pFormat
[4];
1408 FIXME("unhandled embedded type %02x\n", *pFormat
);
1414 unsigned char * WINAPI
ComplexMarshall(PMIDL_STUB_MESSAGE pStubMsg
,
1415 unsigned char *pMemory
,
1416 PFORMAT_STRING pFormat
,
1417 PFORMAT_STRING pPointer
)
1419 PFORMAT_STRING desc
;
1423 while (*pFormat
!= RPC_FC_END
) {
1427 TRACE("short=%d <= %p\n", *(WORD
*)pMemory
, pMemory
);
1428 memcpy(pStubMsg
->Buffer
, pMemory
, 2);
1429 pStubMsg
->Buffer
+= 2;
1434 TRACE("long=%ld <= %p\n", *(DWORD
*)pMemory
, pMemory
);
1435 memcpy(pStubMsg
->Buffer
, pMemory
, 4);
1436 pStubMsg
->Buffer
+= 4;
1439 case RPC_FC_POINTER
:
1440 TRACE("pointer=%p <= %p\n", *(unsigned char**)pMemory
, pMemory
);
1441 NdrPointerMarshall(pStubMsg
, *(unsigned char**)pMemory
, pPointer
);
1445 case RPC_FC_ALIGNM4
:
1446 ALIGN_POINTER(pMemory
, 3);
1448 case RPC_FC_ALIGNM8
:
1449 ALIGN_POINTER(pMemory
, 7);
1451 case RPC_FC_EMBEDDED_COMPLEX
:
1452 pMemory
+= pFormat
[1];
1454 desc
= pFormat
+ *(const SHORT
*)pFormat
;
1455 size
= EmbeddedComplexSize(pStubMsg
, desc
);
1456 TRACE("embedded complex (size=%ld) <= %p\n", size
, pMemory
);
1457 m
= NdrMarshaller
[*desc
& NDR_TABLE_MASK
];
1458 if (m
) m(pStubMsg
, pMemory
, desc
);
1459 else FIXME("no marshaller for embedded type %02x\n", *desc
);
1466 FIXME("unhandled format %02x\n", *pFormat
);
1474 unsigned char * WINAPI
ComplexUnmarshall(PMIDL_STUB_MESSAGE pStubMsg
,
1475 unsigned char *pMemory
,
1476 PFORMAT_STRING pFormat
,
1477 PFORMAT_STRING pPointer
,
1478 unsigned char fMustAlloc
)
1480 PFORMAT_STRING desc
;
1484 while (*pFormat
!= RPC_FC_END
) {
1488 memcpy(pMemory
, pStubMsg
->Buffer
, 2);
1489 TRACE("short=%d => %p\n", *(WORD
*)pMemory
, pMemory
);
1490 pStubMsg
->Buffer
+= 2;
1495 memcpy(pMemory
, pStubMsg
->Buffer
, 4);
1496 TRACE("long=%ld => %p\n", *(DWORD
*)pMemory
, pMemory
);
1497 pStubMsg
->Buffer
+= 4;
1500 case RPC_FC_POINTER
:
1501 *(unsigned char**)pMemory
= NULL
;
1502 TRACE("pointer => %p\n", pMemory
);
1503 NdrPointerUnmarshall(pStubMsg
, (unsigned char**)pMemory
, pPointer
, fMustAlloc
);
1507 case RPC_FC_ALIGNM4
:
1508 ALIGN_POINTER(pMemory
, 3);
1510 case RPC_FC_ALIGNM8
:
1511 ALIGN_POINTER(pMemory
, 7);
1513 case RPC_FC_EMBEDDED_COMPLEX
:
1514 pMemory
+= pFormat
[1];
1516 desc
= pFormat
+ *(const SHORT
*)pFormat
;
1517 size
= EmbeddedComplexSize(pStubMsg
, desc
);
1518 TRACE("embedded complex (size=%ld) => %p\n", size
, pMemory
);
1519 m
= NdrUnmarshaller
[*desc
& NDR_TABLE_MASK
];
1520 memset(pMemory
, 0, size
); /* just in case */
1521 if (m
) m(pStubMsg
, &pMemory
, desc
, fMustAlloc
);
1522 else FIXME("no unmarshaller for embedded type %02x\n", *desc
);
1529 FIXME("unhandled format %d\n", *pFormat
);
1537 unsigned char * WINAPI
ComplexBufferSize(PMIDL_STUB_MESSAGE pStubMsg
,
1538 unsigned char *pMemory
,
1539 PFORMAT_STRING pFormat
,
1540 PFORMAT_STRING pPointer
)
1542 PFORMAT_STRING desc
;
1546 while (*pFormat
!= RPC_FC_END
) {
1550 pStubMsg
->BufferLength
+= 2;
1555 pStubMsg
->BufferLength
+= 4;
1558 case RPC_FC_POINTER
:
1559 NdrPointerBufferSize(pStubMsg
, *(unsigned char**)pMemory
, pPointer
);
1563 case RPC_FC_ALIGNM4
:
1564 ALIGN_POINTER(pMemory
, 3);
1566 case RPC_FC_ALIGNM8
:
1567 ALIGN_POINTER(pMemory
, 7);
1569 case RPC_FC_EMBEDDED_COMPLEX
:
1570 pMemory
+= pFormat
[1];
1572 desc
= pFormat
+ *(const SHORT
*)pFormat
;
1573 size
= EmbeddedComplexSize(pStubMsg
, desc
);
1574 m
= NdrBufferSizer
[*desc
& NDR_TABLE_MASK
];
1575 if (m
) m(pStubMsg
, pMemory
, desc
);
1576 else FIXME("no buffersizer for embedded type %02x\n", *desc
);
1583 FIXME("unhandled format %d\n", *pFormat
);
1591 unsigned char * WINAPI
ComplexFree(PMIDL_STUB_MESSAGE pStubMsg
,
1592 unsigned char *pMemory
,
1593 PFORMAT_STRING pFormat
,
1594 PFORMAT_STRING pPointer
)
1596 PFORMAT_STRING desc
;
1600 while (*pFormat
!= RPC_FC_END
) {
1610 case RPC_FC_POINTER
:
1611 NdrPointerFree(pStubMsg
, *(unsigned char**)pMemory
, pPointer
);
1615 case RPC_FC_ALIGNM4
:
1616 ALIGN_POINTER(pMemory
, 3);
1618 case RPC_FC_ALIGNM8
:
1619 ALIGN_POINTER(pMemory
, 7);
1621 case RPC_FC_EMBEDDED_COMPLEX
:
1622 pMemory
+= pFormat
[1];
1624 desc
= pFormat
+ *(const SHORT
*)pFormat
;
1625 size
= EmbeddedComplexSize(pStubMsg
, desc
);
1626 m
= NdrFreer
[*desc
& NDR_TABLE_MASK
];
1627 if (m
) m(pStubMsg
, pMemory
, desc
);
1628 else FIXME("no freer for embedded type %02x\n", *desc
);
1635 FIXME("unhandled format %d\n", *pFormat
);
1643 unsigned long WINAPI
ComplexStructSize(PMIDL_STUB_MESSAGE pStubMsg
,
1644 PFORMAT_STRING pFormat
)
1646 PFORMAT_STRING desc
;
1647 unsigned long size
= 0;
1649 while (*pFormat
!= RPC_FC_END
) {
1659 case RPC_FC_POINTER
:
1662 case RPC_FC_ALIGNM4
:
1663 ALIGN_LENGTH(size
, 3);
1665 case RPC_FC_ALIGNM8
:
1666 ALIGN_LENGTH(size
, 7);
1668 case RPC_FC_EMBEDDED_COMPLEX
:
1671 desc
= pFormat
+ *(const SHORT
*)pFormat
;
1672 size
+= EmbeddedComplexSize(pStubMsg
, desc
);
1678 FIXME("unhandled format %d\n", *pFormat
);
1686 /***********************************************************************
1687 * NdrComplexStructMarshall [RPCRT4.@]
1689 unsigned char * WINAPI
NdrComplexStructMarshall(PMIDL_STUB_MESSAGE pStubMsg
,
1690 unsigned char *pMemory
,
1691 PFORMAT_STRING pFormat
)
1693 PFORMAT_STRING conf_array
= NULL
;
1694 PFORMAT_STRING pointer_desc
= NULL
;
1695 unsigned char *OldMemory
= pStubMsg
->Memory
;
1697 TRACE("(%p,%p,%p)\n", pStubMsg
, pMemory
, pFormat
);
1700 if (*(const WORD
*)pFormat
) conf_array
= pFormat
+ *(const WORD
*)pFormat
;
1702 if (*(const WORD
*)pFormat
) pointer_desc
= pFormat
+ *(const WORD
*)pFormat
;
1705 pStubMsg
->Memory
= pMemory
;
1707 ComplexMarshall(pStubMsg
, pMemory
, pFormat
, pointer_desc
);
1710 NdrConformantArrayMarshall(pStubMsg
, pMemory
, conf_array
);
1712 pStubMsg
->Memory
= OldMemory
;
1714 STD_OVERFLOW_CHECK(pStubMsg
);
1719 /***********************************************************************
1720 * NdrComplexStructUnmarshall [RPCRT4.@]
1722 unsigned char * WINAPI
NdrComplexStructUnmarshall(PMIDL_STUB_MESSAGE pStubMsg
,
1723 unsigned char **ppMemory
,
1724 PFORMAT_STRING pFormat
,
1725 unsigned char fMustAlloc
)
1727 unsigned size
= *(const WORD
*)(pFormat
+2);
1728 PFORMAT_STRING conf_array
= NULL
;
1729 PFORMAT_STRING pointer_desc
= NULL
;
1730 unsigned char *pMemory
;
1732 TRACE("(%p,%p,%p,%d)\n", pStubMsg
, ppMemory
, pFormat
, fMustAlloc
);
1734 if (fMustAlloc
|| !*ppMemory
)
1735 *ppMemory
= NdrAllocate(pStubMsg
, size
);
1738 if (*(const WORD
*)pFormat
) conf_array
= pFormat
+ *(const WORD
*)pFormat
;
1740 if (*(const WORD
*)pFormat
) pointer_desc
= pFormat
+ *(const WORD
*)pFormat
;
1743 pMemory
= ComplexUnmarshall(pStubMsg
, *ppMemory
, pFormat
, pointer_desc
, fMustAlloc
);
1746 NdrConformantArrayUnmarshall(pStubMsg
, &pMemory
, conf_array
, fMustAlloc
);
1751 /***********************************************************************
1752 * NdrComplexStructBufferSize [RPCRT4.@]
1754 void WINAPI
NdrComplexStructBufferSize(PMIDL_STUB_MESSAGE pStubMsg
,
1755 unsigned char *pMemory
,
1756 PFORMAT_STRING pFormat
)
1758 PFORMAT_STRING conf_array
= NULL
;
1759 PFORMAT_STRING pointer_desc
= NULL
;
1760 unsigned char *OldMemory
= pStubMsg
->Memory
;
1762 TRACE("(%p,%p,%p)\n", pStubMsg
, pMemory
, pFormat
);
1765 if (*(const WORD
*)pFormat
) conf_array
= pFormat
+ *(const WORD
*)pFormat
;
1767 if (*(const WORD
*)pFormat
) pointer_desc
= pFormat
+ *(const WORD
*)pFormat
;
1770 pStubMsg
->Memory
= pMemory
;
1772 pMemory
= ComplexBufferSize(pStubMsg
, pMemory
, pFormat
, pointer_desc
);
1775 NdrConformantArrayBufferSize(pStubMsg
, pMemory
, conf_array
);
1777 pStubMsg
->Memory
= OldMemory
;
1780 /***********************************************************************
1781 * NdrComplexStructMemorySize [RPCRT4.@]
1783 unsigned long WINAPI
NdrComplexStructMemorySize(PMIDL_STUB_MESSAGE pStubMsg
,
1784 PFORMAT_STRING pFormat
)
1786 /* unsigned size = *(LPWORD)(pFormat+2); */
1787 PFORMAT_STRING conf_array
= NULL
;
1788 PFORMAT_STRING pointer_desc
= NULL
;
1790 FIXME("(%p,%p): stub\n", pStubMsg
, pFormat
);
1793 if (*(const WORD
*)pFormat
) conf_array
= pFormat
+ *(const WORD
*)pFormat
;
1795 if (*(const WORD
*)pFormat
) pointer_desc
= pFormat
+ *(const WORD
*)pFormat
;
1801 /***********************************************************************
1802 * NdrComplexStructFree [RPCRT4.@]
1804 void WINAPI
NdrComplexStructFree(PMIDL_STUB_MESSAGE pStubMsg
,
1805 unsigned char *pMemory
,
1806 PFORMAT_STRING pFormat
)
1808 PFORMAT_STRING conf_array
= NULL
;
1809 PFORMAT_STRING pointer_desc
= NULL
;
1810 unsigned char *OldMemory
= pStubMsg
->Memory
;
1812 TRACE("(%p,%p,%p)\n", pStubMsg
, pMemory
, pFormat
);
1815 if (*(const WORD
*)pFormat
) conf_array
= pFormat
+ *(const WORD
*)pFormat
;
1817 if (*(const WORD
*)pFormat
) pointer_desc
= pFormat
+ *(const WORD
*)pFormat
;
1820 pStubMsg
->Memory
= pMemory
;
1822 pMemory
= ComplexFree(pStubMsg
, pMemory
, pFormat
, pointer_desc
);
1825 NdrConformantArrayFree(pStubMsg
, pMemory
, conf_array
);
1827 pStubMsg
->Memory
= OldMemory
;
1830 /***********************************************************************
1831 * NdrConformantArrayMarshall [RPCRT4.@]
1833 unsigned char * WINAPI
NdrConformantArrayMarshall(PMIDL_STUB_MESSAGE pStubMsg
,
1834 unsigned char *pMemory
,
1835 PFORMAT_STRING pFormat
)
1837 DWORD size
= 0, esize
= *(const WORD
*)(pFormat
+2);
1838 TRACE("(%p,%p,%p)\n", pStubMsg
, pMemory
, pFormat
);
1839 if (pFormat
[0] != RPC_FC_CARRAY
) FIXME("format=%d\n", pFormat
[0]);
1841 pFormat
= ComputeConformance(pStubMsg
, pMemory
, pFormat
+4, 0);
1842 size
= pStubMsg
->MaxCount
;
1844 NDR_LOCAL_UINT32_WRITE(pStubMsg
->Buffer
, size
);
1845 pStubMsg
->Buffer
+= 4;
1847 memcpy(pStubMsg
->Buffer
, pMemory
, size
*esize
);
1848 pStubMsg
->BufferMark
= pStubMsg
->Buffer
;
1849 pStubMsg
->Buffer
+= size
*esize
;
1851 EmbeddedPointerMarshall(pStubMsg
, pMemory
, pFormat
);
1853 STD_OVERFLOW_CHECK(pStubMsg
);
1858 /***********************************************************************
1859 * NdrConformantArrayUnmarshall [RPCRT4.@]
1861 unsigned char * WINAPI
NdrConformantArrayUnmarshall(PMIDL_STUB_MESSAGE pStubMsg
,
1862 unsigned char **ppMemory
,
1863 PFORMAT_STRING pFormat
,
1864 unsigned char fMustAlloc
)
1866 DWORD size
= 0, esize
= *(const WORD
*)(pFormat
+2);
1867 TRACE("(%p,%p,%p,%d)\n", pStubMsg
, ppMemory
, pFormat
, fMustAlloc
);
1868 if (pFormat
[0] != RPC_FC_CARRAY
) FIXME("format=%d\n", pFormat
[0]);
1870 pFormat
= ReadConformance(pStubMsg
, pFormat
+4);
1871 size
= pStubMsg
->MaxCount
;
1873 if (fMustAlloc
|| !*ppMemory
)
1874 *ppMemory
= NdrAllocate(pStubMsg
, size
*esize
);
1876 memcpy(*ppMemory
, pStubMsg
->Buffer
, size
*esize
);
1878 pStubMsg
->BufferMark
= pStubMsg
->Buffer
;
1879 pStubMsg
->Buffer
+= size
*esize
;
1881 EmbeddedPointerUnmarshall(pStubMsg
, ppMemory
, pFormat
, fMustAlloc
);
1886 /***********************************************************************
1887 * NdrConformantArrayBufferSize [RPCRT4.@]
1889 void WINAPI
NdrConformantArrayBufferSize(PMIDL_STUB_MESSAGE pStubMsg
,
1890 unsigned char *pMemory
,
1891 PFORMAT_STRING pFormat
)
1893 DWORD size
= 0, esize
= *(const WORD
*)(pFormat
+2);
1894 TRACE("(%p,%p,%p)\n", pStubMsg
, pMemory
, pFormat
);
1895 if (pFormat
[0] != RPC_FC_CARRAY
) FIXME("format=%d\n", pFormat
[0]);
1897 pFormat
= ComputeConformance(pStubMsg
, pMemory
, pFormat
+4, 0);
1898 size
= pStubMsg
->MaxCount
;
1900 pStubMsg
->BufferLength
+= size
*esize
;
1902 EmbeddedPointerBufferSize(pStubMsg
, pMemory
, pFormat
);
1905 /***********************************************************************
1906 * NdrConformantArrayMemorySize [RPCRT4.@]
1908 unsigned long WINAPI
NdrConformantArrayMemorySize(PMIDL_STUB_MESSAGE pStubMsg
,
1909 PFORMAT_STRING pFormat
)
1912 FIXME("(%p,%p): stub\n", pStubMsg
, pFormat
);
1913 if (pFormat
[0] != RPC_FC_CARRAY
) FIXME("format=%d\n", pFormat
[0]);
1915 pFormat
= ReadConformance(pStubMsg
, pFormat
+4);
1916 size
= pStubMsg
->MaxCount
;
1918 EmbeddedPointerMemorySize(pStubMsg
, pFormat
);
1923 /***********************************************************************
1924 * NdrConformantArrayFree [RPCRT4.@]
1926 void WINAPI
NdrConformantArrayFree(PMIDL_STUB_MESSAGE pStubMsg
,
1927 unsigned char *pMemory
,
1928 PFORMAT_STRING pFormat
)
1930 TRACE("(%p,%p,%p)\n", pStubMsg
, pMemory
, pFormat
);
1931 if (pFormat
[0] != RPC_FC_CARRAY
) FIXME("format=%d\n", pFormat
[0]);
1933 EmbeddedPointerFree(pStubMsg
, pMemory
, pFormat
);
1937 /***********************************************************************
1938 * NdrConformantVaryingArrayMarshall [RPCRT4.@]
1940 unsigned char* WINAPI
NdrConformantVaryingArrayMarshall( PMIDL_STUB_MESSAGE pStubMsg
,
1941 unsigned char* pMemory
,
1942 PFORMAT_STRING pFormat
)
1949 /***********************************************************************
1950 * NdrConformantVaryingArrayUnmarshall [RPCRT4.@]
1952 unsigned char* WINAPI
NdrConformantVaryingArrayUnmarshall( PMIDL_STUB_MESSAGE pStubMsg
,
1953 unsigned char** ppMemory
,
1954 PFORMAT_STRING pFormat
,
1955 unsigned char fMustAlloc
)
1962 /***********************************************************************
1963 * NdrConformantVaryingArrayFree [RPCRT4.@]
1965 void WINAPI
NdrConformantVaryingArrayFree( PMIDL_STUB_MESSAGE pStubMsg
,
1966 unsigned char* pMemory
,
1967 PFORMAT_STRING pFormat
)
1973 /***********************************************************************
1974 * NdrConformantVaryingArrayBufferSize [RPCRT4.@]
1976 void WINAPI
NdrConformantVaryingArrayBufferSize( PMIDL_STUB_MESSAGE pStubMsg
,
1977 unsigned char* pMemory
, PFORMAT_STRING pFormat
)
1983 /***********************************************************************
1984 * NdrConformantVaryingArrayMemorySize [RPCRT4.@]
1986 unsigned long WINAPI
NdrConformantVaryingArrayMemorySize( PMIDL_STUB_MESSAGE pStubMsg
,
1987 PFORMAT_STRING pFormat
)
1994 /***********************************************************************
1995 * NdrComplexArrayMarshall [RPCRT4.@]
1997 unsigned char * WINAPI
NdrComplexArrayMarshall(PMIDL_STUB_MESSAGE pStubMsg
,
1998 unsigned char *pMemory
,
1999 PFORMAT_STRING pFormat
)
2001 DWORD size
= 0, count
, def
;
2002 TRACE("(%p,%p,%p)\n", pStubMsg
, pMemory
, pFormat
);
2004 def
= *(const WORD
*)&pFormat
[2];
2007 pFormat
= ComputeConformance(pStubMsg
, pMemory
, pFormat
, def
);
2008 size
= pStubMsg
->MaxCount
;
2009 TRACE("conformance=%ld\n", size
);
2011 if (*(const DWORD
*)pFormat
!= 0xffffffff)
2012 FIXME("compute variance\n");
2015 NDR_LOCAL_UINT32_WRITE(pStubMsg
->Buffer
, size
);
2016 pStubMsg
->Buffer
+= 4;
2018 for (count
=0; count
<size
; count
++)
2019 pMemory
= ComplexMarshall(pStubMsg
, pMemory
, pFormat
, NULL
);
2021 STD_OVERFLOW_CHECK(pStubMsg
);
2026 /***********************************************************************
2027 * NdrComplexArrayUnmarshall [RPCRT4.@]
2029 unsigned char * WINAPI
NdrComplexArrayUnmarshall(PMIDL_STUB_MESSAGE pStubMsg
,
2030 unsigned char **ppMemory
,
2031 PFORMAT_STRING pFormat
,
2032 unsigned char fMustAlloc
)
2034 DWORD size
= 0, count
, esize
;
2035 unsigned char *pMemory
;
2036 TRACE("(%p,%p,%p,%d)\n", pStubMsg
, ppMemory
, pFormat
, fMustAlloc
);
2040 pFormat
= ReadConformance(pStubMsg
, pFormat
);
2041 size
= pStubMsg
->MaxCount
;
2042 TRACE("conformance=%ld\n", size
);
2046 esize
= ComplexStructSize(pStubMsg
, pFormat
);
2048 if (fMustAlloc
|| !*ppMemory
)
2049 *ppMemory
= NdrAllocate(pStubMsg
, size
*esize
);
2051 pMemory
= *ppMemory
;
2052 for (count
=0; count
<size
; count
++)
2053 pMemory
= ComplexUnmarshall(pStubMsg
, pMemory
, pFormat
, NULL
, fMustAlloc
);
2058 /***********************************************************************
2059 * NdrComplexArrayBufferSize [RPCRT4.@]
2061 void WINAPI
NdrComplexArrayBufferSize(PMIDL_STUB_MESSAGE pStubMsg
,
2062 unsigned char *pMemory
,
2063 PFORMAT_STRING pFormat
)
2065 DWORD size
= 0, count
, def
;
2066 TRACE("(%p,%p,%p)\n", pStubMsg
, pMemory
, pFormat
);
2068 def
= *(const WORD
*)&pFormat
[2];
2071 pFormat
= ComputeConformance(pStubMsg
, pMemory
, pFormat
, def
);
2072 size
= pStubMsg
->MaxCount
;
2073 TRACE("conformance=%ld\n", size
);
2075 if (*(const DWORD
*)pFormat
!= 0xffffffff)
2076 FIXME("compute variance\n");
2079 for (count
=0; count
<size
; count
++)
2080 pMemory
= ComplexBufferSize(pStubMsg
, pMemory
, pFormat
, NULL
);
2083 /***********************************************************************
2084 * NdrComplexArrayMemorySize [RPCRT4.@]
2086 unsigned long WINAPI
NdrComplexArrayMemorySize(PMIDL_STUB_MESSAGE pStubMsg
,
2087 PFORMAT_STRING pFormat
)
2090 FIXME("(%p,%p): stub\n", pStubMsg
, pFormat
);
2094 pFormat
= ReadConformance(pStubMsg
, pFormat
);
2095 size
= pStubMsg
->MaxCount
;
2096 TRACE("conformance=%ld\n", size
);
2103 /***********************************************************************
2104 * NdrComplexArrayFree [RPCRT4.@]
2106 void WINAPI
NdrComplexArrayFree(PMIDL_STUB_MESSAGE pStubMsg
,
2107 unsigned char *pMemory
,
2108 PFORMAT_STRING pFormat
)
2110 DWORD size
= 0, count
, def
;
2111 TRACE("(%p,%p,%p)\n", pStubMsg
, pMemory
, pFormat
);
2113 def
= *(const WORD
*)&pFormat
[2];
2116 pFormat
= ComputeConformance(pStubMsg
, pMemory
, pFormat
, def
);
2117 size
= pStubMsg
->MaxCount
;
2118 TRACE("conformance=%ld\n", size
);
2120 if (*(const DWORD
*)pFormat
!= 0xffffffff)
2121 FIXME("compute variance\n");
2124 for (count
=0; count
<size
; count
++)
2125 pMemory
= ComplexFree(pStubMsg
, pMemory
, pFormat
, NULL
);
2128 unsigned long UserMarshalFlags(PMIDL_STUB_MESSAGE pStubMsg
)
2130 return MAKELONG(pStubMsg
->dwDestContext
,
2131 pStubMsg
->RpcMsg
->DataRepresentation
);
2134 /***********************************************************************
2135 * NdrUserMarshalMarshall [RPCRT4.@]
2137 unsigned char * WINAPI
NdrUserMarshalMarshall(PMIDL_STUB_MESSAGE pStubMsg
,
2138 unsigned char *pMemory
,
2139 PFORMAT_STRING pFormat
)
2141 /* unsigned flags = pFormat[1]; */
2142 unsigned index
= *(const WORD
*)&pFormat
[2];
2143 unsigned long uflag
= UserMarshalFlags(pStubMsg
);
2144 TRACE("(%p,%p,%p)\n", pStubMsg
, pMemory
, pFormat
);
2145 TRACE("index=%d\n", index
);
2148 pStubMsg
->StubDesc
->aUserMarshalQuadruple
[index
].pfnMarshall(
2149 &uflag
, pStubMsg
->Buffer
, pMemory
);
2151 STD_OVERFLOW_CHECK(pStubMsg
);
2156 /***********************************************************************
2157 * NdrUserMarshalUnmarshall [RPCRT4.@]
2159 unsigned char * WINAPI
NdrUserMarshalUnmarshall(PMIDL_STUB_MESSAGE pStubMsg
,
2160 unsigned char **ppMemory
,
2161 PFORMAT_STRING pFormat
,
2162 unsigned char fMustAlloc
)
2164 /* unsigned flags = pFormat[1];*/
2165 unsigned index
= *(const WORD
*)&pFormat
[2];
2166 DWORD memsize
= *(const WORD
*)&pFormat
[4];
2167 unsigned long uflag
= UserMarshalFlags(pStubMsg
);
2168 TRACE("(%p,%p,%p,%d)\n", pStubMsg
, ppMemory
, pFormat
, fMustAlloc
);
2169 TRACE("index=%d\n", index
);
2171 if (fMustAlloc
|| !*ppMemory
)
2172 *ppMemory
= NdrAllocate(pStubMsg
, memsize
);
2175 pStubMsg
->StubDesc
->aUserMarshalQuadruple
[index
].pfnUnmarshall(
2176 &uflag
, pStubMsg
->Buffer
, *ppMemory
);
2181 /***********************************************************************
2182 * NdrUserMarshalBufferSize [RPCRT4.@]
2184 void WINAPI
NdrUserMarshalBufferSize(PMIDL_STUB_MESSAGE pStubMsg
,
2185 unsigned char *pMemory
,
2186 PFORMAT_STRING pFormat
)
2188 /* unsigned flags = pFormat[1];*/
2189 unsigned index
= *(const WORD
*)&pFormat
[2];
2190 DWORD bufsize
= *(const WORD
*)&pFormat
[6];
2191 unsigned long uflag
= UserMarshalFlags(pStubMsg
);
2192 TRACE("(%p,%p,%p)\n", pStubMsg
, pMemory
, pFormat
);
2193 TRACE("index=%d\n", index
);
2196 TRACE("size=%ld\n", bufsize
);
2197 pStubMsg
->BufferLength
+= bufsize
;
2201 pStubMsg
->BufferLength
=
2202 pStubMsg
->StubDesc
->aUserMarshalQuadruple
[index
].pfnBufferSize(
2203 &uflag
, pStubMsg
->BufferLength
, pMemory
);
2206 /***********************************************************************
2207 * NdrUserMarshalMemorySize [RPCRT4.@]
2209 unsigned long WINAPI
NdrUserMarshalMemorySize(PMIDL_STUB_MESSAGE pStubMsg
,
2210 PFORMAT_STRING pFormat
)
2212 unsigned index
= *(const WORD
*)&pFormat
[2];
2213 /* DWORD memsize = *(const WORD*)&pFormat[4]; */
2214 FIXME("(%p,%p): stub\n", pStubMsg
, pFormat
);
2215 TRACE("index=%d\n", index
);
2220 /***********************************************************************
2221 * NdrUserMarshalFree [RPCRT4.@]
2223 void WINAPI
NdrUserMarshalFree(PMIDL_STUB_MESSAGE pStubMsg
,
2224 unsigned char *pMemory
,
2225 PFORMAT_STRING pFormat
)
2227 /* unsigned flags = pFormat[1]; */
2228 unsigned index
= *(const WORD
*)&pFormat
[2];
2229 unsigned long uflag
= UserMarshalFlags(pStubMsg
);
2230 TRACE("(%p,%p,%p)\n", pStubMsg
, pMemory
, pFormat
);
2231 TRACE("index=%d\n", index
);
2233 pStubMsg
->StubDesc
->aUserMarshalQuadruple
[index
].pfnFree(
2237 /***********************************************************************
2238 * NdrClearOutParameters [RPCRT4.@]
2240 void WINAPI
NdrClearOutParameters(PMIDL_STUB_MESSAGE pStubMsg
,
2241 PFORMAT_STRING pFormat
,
2244 FIXME("(%p,%p,%p): stub\n", pStubMsg
, pFormat
, ArgAddr
);
2247 /***********************************************************************
2248 * NdrConvert [RPCRT4.@]
2250 void WINAPI
NdrConvert( PMIDL_STUB_MESSAGE pStubMsg
, PFORMAT_STRING pFormat
)
2252 FIXME("(pStubMsg == ^%p, pFormat == ^%p): stub.\n", pStubMsg
, pFormat
);
2253 /* FIXME: since this stub doesn't do any converting, the proper behavior
2254 is to raise an exception */
2257 /***********************************************************************
2258 * NdrConvert2 [RPCRT4.@]
2260 void WINAPI
NdrConvert2( PMIDL_STUB_MESSAGE pStubMsg
, PFORMAT_STRING pFormat
, long NumberParams
)
2262 FIXME("(pStubMsg == ^%p, pFormat == ^%p, NumberParams == %ld): stub.\n",
2263 pStubMsg
, pFormat
, NumberParams
);
2264 /* FIXME: since this stub doesn't do any converting, the proper behavior
2265 is to raise an exception */
2268 /***********************************************************************
2269 * NdrConformantStructMarshall [RPCRT4.@]
2271 unsigned char * WINAPI
NdrConformantStructMarshall(PMIDL_STUB_MESSAGE pStubMsg
,
2272 unsigned char *pMemory
,
2273 PFORMAT_STRING pFormat
)
2279 /***********************************************************************
2280 * NdrConformantStructUnmarshall [RPCRT4.@]
2282 unsigned char * WINAPI
NdrConformantStructUnmarshall(PMIDL_STUB_MESSAGE pStubMsg
,
2283 unsigned char **ppMemory
,
2284 PFORMAT_STRING pFormat
,
2285 unsigned char fMustAlloc
)
2291 /***********************************************************************
2292 * NdrConformantStructBufferSize [RPCRT4.@]
2294 void WINAPI
NdrConformantStructBufferSize(PMIDL_STUB_MESSAGE pStubMsg
,
2295 unsigned char *pMemory
,
2296 PFORMAT_STRING pFormat
)
2301 /***********************************************************************
2302 * NdrConformantStructMemorySize [RPCRT4.@]
2304 unsigned long WINAPI
NdrConformantStructMemorySize(PMIDL_STUB_MESSAGE pStubMsg
,
2305 PFORMAT_STRING pFormat
)
2311 /***********************************************************************
2312 * NdrConformantStructFree [RPCRT4.@]
2314 void WINAPI
NdrConformantStructFree(PMIDL_STUB_MESSAGE pStubMsg
,
2315 unsigned char *pMemory
,
2316 PFORMAT_STRING pFormat
)
2321 /***********************************************************************
2322 * NdrConformantVaryingStructMarshall [RPCRT4.@]
2324 unsigned char * WINAPI
NdrConformantVaryingStructMarshall(PMIDL_STUB_MESSAGE pStubMsg
,
2325 unsigned char *pMemory
,
2326 PFORMAT_STRING pFormat
)
2332 /***********************************************************************
2333 * NdrConformantVaryingStructUnmarshall [RPCRT4.@]
2335 unsigned char * WINAPI
NdrConformantVaryingStructUnmarshall(PMIDL_STUB_MESSAGE pStubMsg
,
2336 unsigned char **ppMemory
,
2337 PFORMAT_STRING pFormat
,
2338 unsigned char fMustAlloc
)
2344 /***********************************************************************
2345 * NdrConformantVaryingStructBufferSize [RPCRT4.@]
2347 void WINAPI
NdrConformantVaryingStructBufferSize(PMIDL_STUB_MESSAGE pStubMsg
,
2348 unsigned char *pMemory
,
2349 PFORMAT_STRING pFormat
)
2354 /***********************************************************************
2355 * NdrConformantVaryingStructMemorySize [RPCRT4.@]
2357 unsigned long WINAPI
NdrConformantVaryingStructMemorySize(PMIDL_STUB_MESSAGE pStubMsg
,
2358 PFORMAT_STRING pFormat
)
2364 /***********************************************************************
2365 * NdrConformantVaryingStructFree [RPCRT4.@]
2367 void WINAPI
NdrConformantVaryingStructFree(PMIDL_STUB_MESSAGE pStubMsg
,
2368 unsigned char *pMemory
,
2369 PFORMAT_STRING pFormat
)
2374 /***********************************************************************
2375 * NdrFixedArrayMarshall [RPCRT4.@]
2377 unsigned char * WINAPI
NdrFixedArrayMarshall(PMIDL_STUB_MESSAGE pStubMsg
,
2378 unsigned char *pMemory
,
2379 PFORMAT_STRING pFormat
)
2385 /***********************************************************************
2386 * NdrFixedArrayUnmarshall [RPCRT4.@]
2388 unsigned char * WINAPI
NdrFixedArrayUnmarshall(PMIDL_STUB_MESSAGE pStubMsg
,
2389 unsigned char **ppMemory
,
2390 PFORMAT_STRING pFormat
,
2391 unsigned char fMustAlloc
)
2397 /***********************************************************************
2398 * NdrFixedArrayBufferSize [RPCRT4.@]
2400 void WINAPI
NdrFixedArrayBufferSize(PMIDL_STUB_MESSAGE pStubMsg
,
2401 unsigned char *pMemory
,
2402 PFORMAT_STRING pFormat
)
2407 /***********************************************************************
2408 * NdrFixedArrayMemorySize [RPCRT4.@]
2410 unsigned long WINAPI
NdrFixedArrayMemorySize(PMIDL_STUB_MESSAGE pStubMsg
,
2411 PFORMAT_STRING pFormat
)
2417 /***********************************************************************
2418 * NdrFixedArrayFree [RPCRT4.@]
2420 void WINAPI
NdrFixedArrayFree(PMIDL_STUB_MESSAGE pStubMsg
,
2421 unsigned char *pMemory
,
2422 PFORMAT_STRING pFormat
)
2427 /***********************************************************************
2428 * NdrVaryingArrayMarshall [RPCRT4.@]
2430 unsigned char * WINAPI
NdrVaryingArrayMarshall(PMIDL_STUB_MESSAGE pStubMsg
,
2431 unsigned char *pMemory
,
2432 PFORMAT_STRING pFormat
)
2438 /***********************************************************************
2439 * NdrVaryingArrayUnmarshall [RPCRT4.@]
2441 unsigned char * WINAPI
NdrVaryingArrayUnmarshall(PMIDL_STUB_MESSAGE pStubMsg
,
2442 unsigned char **ppMemory
,
2443 PFORMAT_STRING pFormat
,
2444 unsigned char fMustAlloc
)
2450 /***********************************************************************
2451 * NdrVaryingArrayBufferSize [RPCRT4.@]
2453 void WINAPI
NdrVaryingArrayBufferSize(PMIDL_STUB_MESSAGE pStubMsg
,
2454 unsigned char *pMemory
,
2455 PFORMAT_STRING pFormat
)
2460 /***********************************************************************
2461 * NdrVaryingArrayMemorySize [RPCRT4.@]
2463 unsigned long WINAPI
NdrVaryingArrayMemorySize(PMIDL_STUB_MESSAGE pStubMsg
,
2464 PFORMAT_STRING pFormat
)
2470 /***********************************************************************
2471 * NdrVaryingArrayFree [RPCRT4.@]
2473 void WINAPI
NdrVaryingArrayFree(PMIDL_STUB_MESSAGE pStubMsg
,
2474 unsigned char *pMemory
,
2475 PFORMAT_STRING pFormat
)
2480 /***********************************************************************
2481 * NdrEncapsulatedUnionMarshall [RPCRT4.@]
2483 unsigned char * WINAPI
NdrEncapsulatedUnionMarshall(PMIDL_STUB_MESSAGE pStubMsg
,
2484 unsigned char *pMemory
,
2485 PFORMAT_STRING pFormat
)
2491 /***********************************************************************
2492 * NdrEncapsulatedUnionUnmarshall [RPCRT4.@]
2494 unsigned char * WINAPI
NdrEncapsulatedUnionUnmarshall(PMIDL_STUB_MESSAGE pStubMsg
,
2495 unsigned char **ppMemory
,
2496 PFORMAT_STRING pFormat
,
2497 unsigned char fMustAlloc
)
2503 /***********************************************************************
2504 * NdrEncapsulatedUnionBufferSize [RPCRT4.@]
2506 void WINAPI
NdrEncapsulatedUnionBufferSize(PMIDL_STUB_MESSAGE pStubMsg
,
2507 unsigned char *pMemory
,
2508 PFORMAT_STRING pFormat
)
2513 /***********************************************************************
2514 * NdrEncapsulatedUnionMemorySize [RPCRT4.@]
2516 unsigned long WINAPI
NdrEncapsulatedUnionMemorySize(PMIDL_STUB_MESSAGE pStubMsg
,
2517 PFORMAT_STRING pFormat
)
2523 /***********************************************************************
2524 * NdrEncapsulatedUnionFree [RPCRT4.@]
2526 void WINAPI
NdrEncapsulatedUnionFree(PMIDL_STUB_MESSAGE pStubMsg
,
2527 unsigned char *pMemory
,
2528 PFORMAT_STRING pFormat
)
2533 /***********************************************************************
2534 * NdrNonEncapsulatedUnionMarshall [RPCRT4.@]
2536 unsigned char * WINAPI
NdrNonEncapsulatedUnionMarshall(PMIDL_STUB_MESSAGE pStubMsg
,
2537 unsigned char *pMemory
,
2538 PFORMAT_STRING pFormat
)
2544 /***********************************************************************
2545 * NdrNonEncapsulatedUnionUnmarshall [RPCRT4.@]
2547 unsigned char * WINAPI
NdrNonEncapsulatedUnionUnmarshall(PMIDL_STUB_MESSAGE pStubMsg
,
2548 unsigned char **ppMemory
,
2549 PFORMAT_STRING pFormat
,
2550 unsigned char fMustAlloc
)
2556 /***********************************************************************
2557 * NdrNonEncapsulatedUnionBufferSize [RPCRT4.@]
2559 void WINAPI
NdrNonEncapsulatedUnionBufferSize(PMIDL_STUB_MESSAGE pStubMsg
,
2560 unsigned char *pMemory
,
2561 PFORMAT_STRING pFormat
)
2566 /***********************************************************************
2567 * NdrNonEncapsulatedUnionMemorySize [RPCRT4.@]
2569 unsigned long WINAPI
NdrNonEncapsulatedUnionMemorySize(PMIDL_STUB_MESSAGE pStubMsg
,
2570 PFORMAT_STRING pFormat
)
2576 /***********************************************************************
2577 * NdrNonEncapsulatedUnionFree [RPCRT4.@]
2579 void WINAPI
NdrNonEncapsulatedUnionFree(PMIDL_STUB_MESSAGE pStubMsg
,
2580 unsigned char *pMemory
,
2581 PFORMAT_STRING pFormat
)
2586 /***********************************************************************
2587 * NdrByteCountPointerMarshall [RPCRT4.@]
2589 unsigned char * WINAPI
NdrByteCountPointerMarshall(PMIDL_STUB_MESSAGE pStubMsg
,
2590 unsigned char *pMemory
,
2591 PFORMAT_STRING pFormat
)
2597 /***********************************************************************
2598 * NdrByteCountPointerUnmarshall [RPCRT4.@]
2600 unsigned char * WINAPI
NdrByteCountPointerUnmarshall(PMIDL_STUB_MESSAGE pStubMsg
,
2601 unsigned char **ppMemory
,
2602 PFORMAT_STRING pFormat
,
2603 unsigned char fMustAlloc
)
2609 /***********************************************************************
2610 * NdrByteCountPointerBufferSize [RPCRT4.@]
2612 void WINAPI
NdrByteCountPointerBufferSize(PMIDL_STUB_MESSAGE pStubMsg
,
2613 unsigned char *pMemory
,
2614 PFORMAT_STRING pFormat
)
2619 /***********************************************************************
2620 * NdrByteCountPointerMemorySize [RPCRT4.@]
2622 unsigned long WINAPI
NdrByteCountPointerMemorySize(PMIDL_STUB_MESSAGE pStubMsg
,
2623 PFORMAT_STRING pFormat
)
2629 /***********************************************************************
2630 * NdrByteCountPointerFree [RPCRT4.@]
2632 void WINAPI
NdrByteCountPointerFree(PMIDL_STUB_MESSAGE pStubMsg
,
2633 unsigned char *pMemory
,
2634 PFORMAT_STRING pFormat
)
2639 /***********************************************************************
2640 * NdrXmitOrRepAsMarshall [RPCRT4.@]
2642 unsigned char * WINAPI
NdrXmitOrRepAsMarshall(PMIDL_STUB_MESSAGE pStubMsg
,
2643 unsigned char *pMemory
,
2644 PFORMAT_STRING pFormat
)
2650 /***********************************************************************
2651 * NdrXmitOrRepAsUnmarshall [RPCRT4.@]
2653 unsigned char * WINAPI
NdrXmitOrRepAsUnmarshall(PMIDL_STUB_MESSAGE pStubMsg
,
2654 unsigned char **ppMemory
,
2655 PFORMAT_STRING pFormat
,
2656 unsigned char fMustAlloc
)
2662 /***********************************************************************
2663 * NdrXmitOrRepAsBufferSize [RPCRT4.@]
2665 void WINAPI
NdrXmitOrRepAsBufferSize(PMIDL_STUB_MESSAGE pStubMsg
,
2666 unsigned char *pMemory
,
2667 PFORMAT_STRING pFormat
)
2672 /***********************************************************************
2673 * NdrXmitOrRepAsMemorySize [RPCRT4.@]
2675 unsigned long WINAPI
NdrXmitOrRepAsMemorySize(PMIDL_STUB_MESSAGE pStubMsg
,
2676 PFORMAT_STRING pFormat
)
2682 /***********************************************************************
2683 * NdrXmitOrRepAsFree [RPCRT4.@]
2685 void WINAPI
NdrXmitOrRepAsFree(PMIDL_STUB_MESSAGE pStubMsg
,
2686 unsigned char *pMemory
,
2687 PFORMAT_STRING pFormat
)
2692 /***********************************************************************
2693 * NdrClientContextMarshall
2695 void WINAPI
NdrClientContextMarshall(PMIDL_STUB_MESSAGE pStubMsg
,
2696 NDR_CCONTEXT ContextHandle
,
2699 FIXME("(%p, %p, %d): stub\n", pStubMsg
, ContextHandle
, fCheck
);
2702 /***********************************************************************
2703 * NdrClientContextUnmarshall
2705 void WINAPI
NdrClientContextUnmarshall(PMIDL_STUB_MESSAGE pStubMsg
,
2706 NDR_CCONTEXT
* pContextHandle
,
2707 RPC_BINDING_HANDLE BindHandle
)
2709 FIXME("(%p, %p, %p): stub\n", pStubMsg
, pContextHandle
, BindHandle
);
2712 void WINAPI
NdrServerContextMarshall(PMIDL_STUB_MESSAGE pStubMsg
,
2713 NDR_SCONTEXT ContextHandle
,
2714 NDR_RUNDOWN RundownRoutine
)
2716 FIXME("(%p, %p, %p): stub\n", pStubMsg
, ContextHandle
, RundownRoutine
);
2719 NDR_SCONTEXT WINAPI
NdrServerContextUnmarshall(PMIDL_STUB_MESSAGE pStubMsg
)
2721 FIXME("(%p): stub\n", pStubMsg
);
2725 void WINAPI
NdrContextHandleSize(PMIDL_STUB_MESSAGE pStubMsg
,
2726 unsigned char* pMemory
,
2727 PFORMAT_STRING pFormat
)
2729 FIXME("(%p, %p, %p): stub\n", pStubMsg
, pMemory
, pFormat
);
2732 NDR_SCONTEXT WINAPI
NdrContextHandleInitialize(PMIDL_STUB_MESSAGE pStubMsg
,
2733 PFORMAT_STRING pFormat
)
2735 FIXME("(%p, %p): stub\n", pStubMsg
, pFormat
);
2739 void WINAPI
NdrServerContextNewMarshall(PMIDL_STUB_MESSAGE pStubMsg
,
2740 NDR_SCONTEXT ContextHandle
,
2741 NDR_RUNDOWN RundownRoutine
,
2742 PFORMAT_STRING pFormat
)
2744 FIXME("(%p, %p, %p, %p): stub\n", pStubMsg
, ContextHandle
, RundownRoutine
, pFormat
);
2747 NDR_SCONTEXT WINAPI
NdrServerContextNewUnmarshall(PMIDL_STUB_MESSAGE pStubMsg
,
2748 PFORMAT_STRING pFormat
)
2750 FIXME("(%p, %p): stub\n", pStubMsg
, pFormat
);
2754 RPC_BINDING_HANDLE WINAPI
NDRCContextBinding(NDR_CCONTEXT CContext
)
2756 FIXME("(%p): stub\n", CContext
);