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 - (unsigned char *)_Msg->RpcMsg->Buffer, _Msg->BufferLength); \
101 if (_Msg->Buffer > (unsigned char *)_Msg->RpcMsg->Buffer + _Msg->BufferLength) \
102 ERR("buffer overflow %d bytes\n", _Msg->Buffer - ((unsigned char *)_Msg->RpcMsg->Buffer + _Msg->BufferLength)); \
105 #define NDR_TABLE_SIZE 128
106 #define NDR_TABLE_MASK 127
108 static unsigned char *WINAPI
NdrBaseTypeMarshall(PMIDL_STUB_MESSAGE
, unsigned char *, PFORMAT_STRING
);
109 static unsigned char *WINAPI
NdrBaseTypeUnmarshall(PMIDL_STUB_MESSAGE
, unsigned char **, PFORMAT_STRING
, unsigned char);
110 static void WINAPI
NdrBaseTypeBufferSize(PMIDL_STUB_MESSAGE
, unsigned char *, PFORMAT_STRING
);
111 static void WINAPI
NdrBaseTypeFree(PMIDL_STUB_MESSAGE
, unsigned char *, PFORMAT_STRING
);
112 static unsigned long WINAPI
NdrBaseTypeMemorySize(PMIDL_STUB_MESSAGE
, PFORMAT_STRING
);
114 NDR_MARSHALL NdrMarshaller
[NDR_TABLE_SIZE
] = {
116 NdrBaseTypeMarshall
, NdrBaseTypeMarshall
, NdrBaseTypeMarshall
,
117 NdrBaseTypeMarshall
, NdrBaseTypeMarshall
, NdrBaseTypeMarshall
, NdrBaseTypeMarshall
,
118 NdrBaseTypeMarshall
, NdrBaseTypeMarshall
, NdrBaseTypeMarshall
, NdrBaseTypeMarshall
,
119 NdrBaseTypeMarshall
, NdrBaseTypeMarshall
, NdrBaseTypeMarshall
, NdrBaseTypeMarshall
,
123 NdrPointerMarshall
, NdrPointerMarshall
,
124 NdrPointerMarshall
, NdrPointerMarshall
,
126 NdrSimpleStructMarshall
, NdrSimpleStructMarshall
,
127 NdrConformantStructMarshall
, NdrConformantStructMarshall
,
128 NdrConformantVaryingStructMarshall
,
129 NdrComplexStructMarshall
,
131 NdrConformantArrayMarshall
,
132 NdrConformantVaryingArrayMarshall
,
133 NdrFixedArrayMarshall
, NdrFixedArrayMarshall
,
134 NdrVaryingArrayMarshall
, NdrVaryingArrayMarshall
,
135 NdrComplexArrayMarshall
,
137 NdrConformantStringMarshall
, 0, 0,
138 NdrConformantStringMarshall
,
139 NdrNonConformantStringMarshall
, 0, 0, 0,
141 NdrEncapsulatedUnionMarshall
,
142 NdrNonEncapsulatedUnionMarshall
,
144 NdrXmitOrRepAsMarshall
, NdrXmitOrRepAsMarshall
,
146 NdrInterfacePointerMarshall
,
149 NdrUserMarshalMarshall
151 NDR_UNMARSHALL NdrUnmarshaller
[NDR_TABLE_SIZE
] = {
153 NdrBaseTypeUnmarshall
, NdrBaseTypeUnmarshall
, NdrBaseTypeUnmarshall
,
154 NdrBaseTypeUnmarshall
, NdrBaseTypeUnmarshall
, NdrBaseTypeUnmarshall
, NdrBaseTypeUnmarshall
,
155 NdrBaseTypeUnmarshall
, NdrBaseTypeUnmarshall
, NdrBaseTypeUnmarshall
, NdrBaseTypeUnmarshall
,
156 NdrBaseTypeUnmarshall
, NdrBaseTypeUnmarshall
, NdrBaseTypeUnmarshall
, NdrBaseTypeUnmarshall
,
158 NdrBaseTypeUnmarshall
,
160 NdrPointerUnmarshall
, NdrPointerUnmarshall
,
161 NdrPointerUnmarshall
, NdrPointerUnmarshall
,
163 NdrSimpleStructUnmarshall
, NdrSimpleStructUnmarshall
,
164 NdrConformantStructUnmarshall
, NdrConformantStructUnmarshall
,
165 NdrConformantVaryingStructUnmarshall
,
166 NdrComplexStructUnmarshall
,
168 NdrConformantArrayUnmarshall
,
169 NdrConformantVaryingArrayUnmarshall
,
170 NdrFixedArrayUnmarshall
, NdrFixedArrayUnmarshall
,
171 NdrVaryingArrayUnmarshall
, NdrVaryingArrayUnmarshall
,
172 NdrComplexArrayUnmarshall
,
174 NdrConformantStringUnmarshall
, 0, 0,
175 NdrConformantStringUnmarshall
,
176 NdrNonConformantStringUnmarshall
, 0, 0, 0,
178 NdrEncapsulatedUnionUnmarshall
,
179 NdrNonEncapsulatedUnionUnmarshall
,
181 NdrXmitOrRepAsUnmarshall
, NdrXmitOrRepAsUnmarshall
,
183 NdrInterfacePointerUnmarshall
,
186 NdrUserMarshalUnmarshall
188 NDR_BUFFERSIZE NdrBufferSizer
[NDR_TABLE_SIZE
] = {
190 NdrBaseTypeBufferSize
, NdrBaseTypeBufferSize
, NdrBaseTypeBufferSize
,
191 NdrBaseTypeBufferSize
, NdrBaseTypeBufferSize
, NdrBaseTypeBufferSize
, NdrBaseTypeBufferSize
,
192 NdrBaseTypeBufferSize
, NdrBaseTypeBufferSize
, NdrBaseTypeBufferSize
, NdrBaseTypeBufferSize
,
193 NdrBaseTypeBufferSize
, NdrBaseTypeBufferSize
, NdrBaseTypeBufferSize
, NdrBaseTypeBufferSize
,
195 NdrBaseTypeBufferSize
,
197 NdrPointerBufferSize
, NdrPointerBufferSize
,
198 NdrPointerBufferSize
, NdrPointerBufferSize
,
200 NdrSimpleStructBufferSize
, NdrSimpleStructBufferSize
,
201 NdrConformantStructBufferSize
, NdrConformantStructBufferSize
,
202 NdrConformantVaryingStructBufferSize
,
203 NdrComplexStructBufferSize
,
205 NdrConformantArrayBufferSize
,
206 NdrConformantVaryingArrayBufferSize
,
207 NdrFixedArrayBufferSize
, NdrFixedArrayBufferSize
,
208 NdrVaryingArrayBufferSize
, NdrVaryingArrayBufferSize
,
209 NdrComplexArrayBufferSize
,
211 NdrConformantStringBufferSize
, 0, 0,
212 NdrConformantStringBufferSize
,
213 NdrNonConformantStringBufferSize
, 0, 0, 0,
215 NdrEncapsulatedUnionBufferSize
,
216 NdrNonEncapsulatedUnionBufferSize
,
218 NdrXmitOrRepAsBufferSize
, NdrXmitOrRepAsBufferSize
,
220 NdrInterfacePointerBufferSize
,
223 NdrUserMarshalBufferSize
225 NDR_MEMORYSIZE NdrMemorySizer
[NDR_TABLE_SIZE
] = {
227 NdrBaseTypeMemorySize
, NdrBaseTypeMemorySize
, NdrBaseTypeMemorySize
,
228 NdrBaseTypeMemorySize
, NdrBaseTypeMemorySize
, NdrBaseTypeMemorySize
, NdrBaseTypeMemorySize
,
229 NdrBaseTypeMemorySize
, NdrBaseTypeMemorySize
, NdrBaseTypeMemorySize
, NdrBaseTypeMemorySize
,
230 NdrBaseTypeMemorySize
, NdrBaseTypeMemorySize
, NdrBaseTypeMemorySize
, NdrBaseTypeMemorySize
,
232 NdrBaseTypeMemorySize
,
234 NdrPointerMemorySize
, NdrPointerMemorySize
,
235 NdrPointerMemorySize
, NdrPointerMemorySize
,
237 NdrSimpleStructMemorySize
, NdrSimpleStructMemorySize
,
239 NdrComplexStructMemorySize
,
241 NdrConformantArrayMemorySize
, 0, 0, 0, 0, 0,
242 NdrComplexArrayMemorySize
,
244 NdrConformantStringMemorySize
, 0, 0,
245 NdrConformantStringMemorySize
,
246 NdrNonConformantStringMemorySize
, 0, 0, 0,
250 NdrInterfacePointerMemorySize
,
253 NdrUserMarshalMemorySize
255 NDR_FREE NdrFreer
[NDR_TABLE_SIZE
] = {
257 NdrBaseTypeFree
, NdrBaseTypeFree
, NdrBaseTypeFree
,
258 NdrBaseTypeFree
, NdrBaseTypeFree
, NdrBaseTypeFree
, NdrBaseTypeFree
,
259 NdrBaseTypeFree
, NdrBaseTypeFree
, NdrBaseTypeFree
, NdrBaseTypeFree
,
260 NdrBaseTypeFree
, NdrBaseTypeFree
, NdrBaseTypeFree
, NdrBaseTypeFree
,
264 NdrPointerFree
, NdrPointerFree
,
265 NdrPointerFree
, NdrPointerFree
,
267 NdrSimpleStructFree
, NdrSimpleStructFree
,
268 NdrConformantStructFree
, NdrConformantStructFree
,
269 NdrConformantVaryingStructFree
,
270 NdrComplexStructFree
,
272 NdrConformantArrayFree
,
273 NdrConformantVaryingArrayFree
,
274 NdrFixedArrayFree
, NdrFixedArrayFree
,
275 NdrVaryingArrayFree
, NdrVaryingArrayFree
,
281 NdrEncapsulatedUnionFree
,
282 NdrNonEncapsulatedUnionFree
,
284 NdrXmitOrRepAsFree
, NdrXmitOrRepAsFree
,
286 NdrInterfacePointerFree
,
292 void * WINAPI
NdrAllocate(MIDL_STUB_MESSAGE
*pStubMsg
, size_t len
)
294 /* hmm, this is probably supposed to do more? */
295 return pStubMsg
->pfnAllocate(len
);
298 static void WINAPI
NdrFree(MIDL_STUB_MESSAGE
*pStubMsg
, unsigned char *Pointer
)
300 pStubMsg
->pfnFree(Pointer
);
303 PFORMAT_STRING
ReadConformance(MIDL_STUB_MESSAGE
*pStubMsg
, PFORMAT_STRING pFormat
)
305 pStubMsg
->MaxCount
= NDR_LOCAL_UINT32_READ(pStubMsg
->Buffer
);
306 pStubMsg
->Buffer
+= 4;
307 TRACE("unmarshalled conformance is %ld\n", pStubMsg
->MaxCount
);
311 static inline PFORMAT_STRING
ReadVariance(MIDL_STUB_MESSAGE
*pStubMsg
, PFORMAT_STRING pFormat
)
313 pStubMsg
->ActualCount
= NDR_LOCAL_UINT32_READ(pStubMsg
->Buffer
);
314 pStubMsg
->Buffer
+= 4;
315 TRACE("unmarshalled variance is %ld\n", pStubMsg
->ActualCount
);
319 PFORMAT_STRING
ComputeConformanceOrVariance(
320 MIDL_STUB_MESSAGE
*pStubMsg
, unsigned char *pMemory
,
321 PFORMAT_STRING pFormat
, ULONG_PTR def
, ULONG
*pCount
)
323 BYTE dtype
= pFormat
[0] & 0xf;
324 short ofs
= *(short *)&pFormat
[2];
328 /* FIXME: is this correct? */
329 if (pFormat
[0] == 0xff) {
330 /* null descriptor */
335 switch (pFormat
[0] & 0xf0) {
336 case RPC_FC_NORMAL_CONFORMANCE
:
337 TRACE("normal conformance, ofs=%d\n", ofs
);
340 case RPC_FC_POINTER_CONFORMANCE
:
341 TRACE("pointer conformance, ofs=%d\n", ofs
);
342 ptr
= pStubMsg
->Memory
+ ofs
;
344 case RPC_FC_TOP_LEVEL_CONFORMANCE
:
345 TRACE("toplevel conformance, ofs=%d\n", ofs
);
346 if (pStubMsg
->StackTop
) {
347 ptr
= pStubMsg
->StackTop
+ ofs
;
350 /* -Os mode, *pCount is already set */
354 case RPC_FC_CONSTANT_CONFORMANCE
:
355 data
= ofs
| ((DWORD
)pFormat
[1] << 16);
356 TRACE("constant conformance, val=%ld\n", data
);
359 case RPC_FC_TOP_LEVEL_MULTID_CONFORMANCE
:
360 FIXME("toplevel multidimensional conformance, ofs=%d\n", ofs
);
361 if (pStubMsg
->StackTop
) {
362 ptr
= pStubMsg
->StackTop
+ ofs
;
370 FIXME("unknown conformance type %x\n", pFormat
[0] & 0xf0);
373 switch (pFormat
[1]) {
374 case RPC_FC_DEREFERENCE
:
377 case RPC_FC_CALLBACK
:
378 /* ofs is index into StubDesc->apfnExprEval */
379 FIXME("handle callback\n");
394 data
= *(USHORT
*)ptr
;
403 FIXME("unknown conformance data type %x\n", dtype
);
406 TRACE("dereferenced data type %x at %p, got %ld\n", dtype
, ptr
, data
);
409 switch (pFormat
[1]) {
413 case RPC_FC_DEREFERENCE
:
414 /* already handled */
417 FIXME("unknown conformance op %d\n", pFormat
[1]);
422 TRACE("resulting conformance is %ld\n", *pCount
);
428 * NdrConformantString:
430 * What MS calls a ConformantString is, in DCE terminology,
431 * a Varying-Conformant String.
433 * maxlen: DWORD (max # of CHARTYPE characters, inclusive of '\0')
434 * offset: DWORD (actual string data begins at (offset) CHARTYPE's
435 * into unmarshalled string)
436 * length: DWORD (# of CHARTYPE characters, inclusive of '\0')
438 * data: CHARTYPE[maxlen]
440 * ], where CHARTYPE is the appropriate character type (specified externally)
444 /***********************************************************************
445 * NdrConformantStringMarshall [RPCRT4.@]
447 unsigned char *WINAPI
NdrConformantStringMarshall(MIDL_STUB_MESSAGE
*pStubMsg
,
448 unsigned char *pszMessage
, PFORMAT_STRING pFormat
)
450 unsigned long len
, esize
;
453 TRACE("(pStubMsg == ^%p, pszMessage == ^%p, pFormat == ^%p)\n", pStubMsg
, pszMessage
, pFormat
);
456 if (pszMessage
== NULL
) {
457 TRACE("string=%s\n", debugstr_a(pszMessage
));
461 else if (*pFormat
== RPC_FC_C_CSTRING
) {
462 TRACE("string=%s\n", debugstr_a(pszMessage
));
463 len
= strlen(pszMessage
)+1;
466 else if (*pFormat
== RPC_FC_C_WSTRING
) {
467 TRACE("string=%s\n", debugstr_w((LPWSTR
)pszMessage
));
468 len
= strlenW((LPWSTR
)pszMessage
)+1;
472 ERR("Unhandled string type: %#x\n", *pFormat
);
473 /* FIXME: raise an exception. */
477 if (pFormat
[1] != RPC_FC_PAD
) {
478 FIXME("sized string format=%d\n", pFormat
[1]);
481 assert( (pStubMsg
->BufferLength
>= (len
*esize
+ 13)) && (pStubMsg
->Buffer
!= NULL
) );
483 c
= pStubMsg
->Buffer
;
485 NDR_LOCAL_UINT32_WRITE(c
, len
); /* max length: strlen + 1 (for '\0') */
486 c
+= 8; /* offset: 0 */
487 NDR_LOCAL_UINT32_WRITE(c
, len
); /* actual length: (same) */
490 memcpy(c
, pszMessage
, len
*esize
); /* the string itself */
493 pStubMsg
->Buffer
= c
;
495 STD_OVERFLOW_CHECK(pStubMsg
);
498 return NULL
; /* is this always right? */
501 /***********************************************************************
502 * NdrConformantStringBufferSize [RPCRT4.@]
504 void WINAPI
NdrConformantStringBufferSize(PMIDL_STUB_MESSAGE pStubMsg
,
505 unsigned char* pMemory
, PFORMAT_STRING pFormat
)
507 TRACE("(pStubMsg == ^%p, pMemory == ^%p, pFormat == ^%p)\n", pStubMsg
, pMemory
, pFormat
);
510 if (pMemory
== NULL
) {
511 /* we need 12 octets for the [maxlen, offset, len] DWORDS */
512 TRACE("string=NULL\n");
513 pStubMsg
->BufferLength
+= 12 + BUFFER_PARANOIA
;
515 else if (*pFormat
== RPC_FC_C_CSTRING
) {
516 /* we need 12 octets for the [maxlen, offset, len] DWORDS, + 1 octet for '\0' */
517 TRACE("string=%s\n", debugstr_a((char*)pMemory
));
518 pStubMsg
->BufferLength
+= strlen((char*)pMemory
) + 13 + BUFFER_PARANOIA
;
520 else if (*pFormat
== RPC_FC_C_WSTRING
) {
521 /* we need 12 octets for the [maxlen, offset, len] DWORDS, + 2 octets for L'\0' */
522 TRACE("string=%s\n", debugstr_w((LPWSTR
)pMemory
));
523 pStubMsg
->BufferLength
+= strlenW((LPWSTR
)pMemory
)*2 + 14 + BUFFER_PARANOIA
;
526 ERR("Unhandled string type: %#x\n", *pFormat
);
527 /* FIXME: raise an exception */
530 if (pFormat
[1] != RPC_FC_PAD
) {
531 FIXME("sized string format=%d\n", pFormat
[1]);
535 /************************************************************************
536 * NdrConformantStringMemorySize [RPCRT4.@]
538 unsigned long WINAPI
NdrConformantStringMemorySize( PMIDL_STUB_MESSAGE pStubMsg
,
539 PFORMAT_STRING pFormat
)
541 unsigned long rslt
= 0;
543 TRACE("(pStubMsg == ^%p, pFormat == ^%p)\n", pStubMsg
, pFormat
);
545 assert(pStubMsg
&& pFormat
);
547 if (*pFormat
== RPC_FC_C_CSTRING
) {
548 rslt
= NDR_LOCAL_UINT32_READ(pStubMsg
->Buffer
); /* maxlen */
550 else if (*pFormat
== RPC_FC_C_WSTRING
) {
551 rslt
= NDR_LOCAL_UINT32_READ(pStubMsg
->Buffer
)*2; /* maxlen */
554 ERR("Unhandled string type: %#x\n", *pFormat
);
555 /* FIXME: raise an exception */
558 if (pFormat
[1] != RPC_FC_PAD
) {
559 FIXME("sized string format=%d\n", pFormat
[1]);
562 TRACE(" --> %lu\n", rslt
);
566 /************************************************************************
567 * NdrConformantStringUnmarshall [RPCRT4.@]
569 unsigned char *WINAPI
NdrConformantStringUnmarshall( PMIDL_STUB_MESSAGE pStubMsg
,
570 unsigned char** ppMemory
, PFORMAT_STRING pFormat
, unsigned char fMustAlloc
)
572 unsigned long len
, esize
, ofs
;
574 TRACE("(pStubMsg == ^%p, *pMemory == ^%p, pFormat == ^%p, fMustAlloc == %u)\n",
575 pStubMsg
, *ppMemory
, pFormat
, fMustAlloc
);
577 assert(pFormat
&& ppMemory
&& pStubMsg
);
579 pStubMsg
->Buffer
+= 4;
580 ofs
= NDR_LOCAL_UINT32_READ(pStubMsg
->Buffer
);
581 pStubMsg
->Buffer
+= 4;
582 len
= NDR_LOCAL_UINT32_READ(pStubMsg
->Buffer
);
583 pStubMsg
->Buffer
+= 4;
585 if (*pFormat
== RPC_FC_C_CSTRING
) esize
= 1;
586 else if (*pFormat
== RPC_FC_C_WSTRING
) esize
= 2;
588 ERR("Unhandled string type: %#x\n", *pFormat
);
589 /* FIXME: raise an exception */
593 if (pFormat
[1] != RPC_FC_PAD
) {
594 FIXME("sized string format=%d\n", pFormat
[1]);
597 if (fMustAlloc
|| !*ppMemory
)
598 *ppMemory
= NdrAllocate(pStubMsg
, len
*esize
+ BUFFER_PARANOIA
);
600 memcpy(*ppMemory
, pStubMsg
->Buffer
, len
*esize
);
602 pStubMsg
->Buffer
+= len
*esize
;
604 if (*pFormat
== RPC_FC_C_CSTRING
) {
605 TRACE("string=%s\n", debugstr_a((char*)*ppMemory
));
607 else if (*pFormat
== RPC_FC_C_WSTRING
) {
608 TRACE("string=%s\n", debugstr_w((LPWSTR
)*ppMemory
));
611 return NULL
; /* FIXME: is this always right? */
614 /***********************************************************************
615 * NdrNonConformantStringMarshall [RPCRT4.@]
617 unsigned char * WINAPI
NdrNonConformantStringMarshall(PMIDL_STUB_MESSAGE pStubMsg
,
618 unsigned char *pMemory
,
619 PFORMAT_STRING pFormat
)
625 /***********************************************************************
626 * NdrNonConformantStringUnmarshall [RPCRT4.@]
628 unsigned char * WINAPI
NdrNonConformantStringUnmarshall(PMIDL_STUB_MESSAGE pStubMsg
,
629 unsigned char **ppMemory
,
630 PFORMAT_STRING pFormat
,
631 unsigned char fMustAlloc
)
637 /***********************************************************************
638 * NdrNonConformantStringBufferSize [RPCRT4.@]
640 void WINAPI
NdrNonConformantStringBufferSize(PMIDL_STUB_MESSAGE pStubMsg
,
641 unsigned char *pMemory
,
642 PFORMAT_STRING pFormat
)
647 /***********************************************************************
648 * NdrNonConformantStringMemorySize [RPCRT4.@]
650 unsigned long WINAPI
NdrNonConformantStringMemorySize(PMIDL_STUB_MESSAGE pStubMsg
,
651 PFORMAT_STRING pFormat
)
657 static inline void dump_pointer_attr(unsigned char attr
)
659 if (attr
& RPC_FC_P_ALLOCALLNODES
)
660 TRACE(" RPC_FC_P_ALLOCALLNODES");
661 if (attr
& RPC_FC_P_DONTFREE
)
662 TRACE(" RPC_FC_P_DONTFREE");
663 if (attr
& RPC_FC_P_ONSTACK
)
664 TRACE(" RPC_FC_P_ONSTACK");
665 if (attr
& RPC_FC_P_SIMPLEPOINTER
)
666 TRACE(" RPC_FC_P_SIMPLEPOINTER");
667 if (attr
& RPC_FC_P_DEREF
)
668 TRACE(" RPC_FC_P_DEREF");
672 /***********************************************************************
675 void WINAPI
PointerMarshall(PMIDL_STUB_MESSAGE pStubMsg
,
676 unsigned char *Buffer
,
677 unsigned char *Pointer
,
678 PFORMAT_STRING pFormat
)
680 unsigned type
= pFormat
[0], attr
= pFormat
[1];
684 TRACE("(%p,%p,%p,%p)\n", pStubMsg
, Buffer
, Pointer
, pFormat
);
685 TRACE("type=0x%x, attr=", type
); dump_pointer_attr(attr
);
687 if (attr
& RPC_FC_P_SIMPLEPOINTER
) desc
= pFormat
;
688 else desc
= pFormat
+ *(const SHORT
*)pFormat
;
689 if (attr
& RPC_FC_P_DEREF
) {
690 Pointer
= *(unsigned char**)Pointer
;
691 TRACE("deref => %p\n", Pointer
);
695 case RPC_FC_RP
: /* ref pointer (always non-null) */
696 #if 0 /* this causes problems for InstallShield so is disabled - we need more tests */
698 RpcRaiseException(RPC_X_NULL_REF_POINTER
);
701 case RPC_FC_UP
: /* unique pointer */
702 case RPC_FC_OP
: /* object pointer - same as unique here */
703 TRACE("writing %p to buffer\n", Pointer
);
704 NDR_LOCAL_UINT32_WRITE(pStubMsg
->Buffer
, (unsigned long)Pointer
);
705 pStubMsg
->Buffer
+= 4;
709 FIXME("unhandled ptr type=%02x\n", type
);
710 RpcRaiseException(RPC_X_BAD_STUB_DATA
);
713 TRACE("calling marshaller for type 0x%x\n", (int)*desc
);
716 m
= NdrMarshaller
[*desc
& NDR_TABLE_MASK
];
717 if (m
) m(pStubMsg
, Pointer
, desc
);
718 else FIXME("no marshaller for data type=%02x\n", *desc
);
721 STD_OVERFLOW_CHECK(pStubMsg
);
724 /***********************************************************************
727 void WINAPI
PointerUnmarshall(PMIDL_STUB_MESSAGE pStubMsg
,
728 unsigned char *Buffer
,
729 unsigned char **pPointer
,
730 PFORMAT_STRING pFormat
,
731 unsigned char fMustAlloc
)
733 unsigned type
= pFormat
[0], attr
= pFormat
[1];
736 DWORD pointer_id
= 0;
738 TRACE("(%p,%p,%p,%p,%d)\n", pStubMsg
, Buffer
, pPointer
, pFormat
, fMustAlloc
);
739 TRACE("type=0x%x, attr=", type
); dump_pointer_attr(attr
);
741 if (attr
& RPC_FC_P_SIMPLEPOINTER
) desc
= pFormat
;
742 else desc
= pFormat
+ *(const SHORT
*)pFormat
;
743 if (attr
& RPC_FC_P_DEREF
) {
744 pPointer
= *(unsigned char***)pPointer
;
745 TRACE("deref => %p\n", pPointer
);
749 case RPC_FC_RP
: /* ref pointer (always non-null) */
752 case RPC_FC_UP
: /* unique pointer */
753 pointer_id
= NDR_LOCAL_UINT32_READ(pStubMsg
->Buffer
);
754 pStubMsg
->Buffer
+= 4;
756 case RPC_FC_OP
: /* object pointer - we must free data before overwriting it */
757 pointer_id
= NDR_LOCAL_UINT32_READ(pStubMsg
->Buffer
);
758 pStubMsg
->Buffer
+= 4;
760 FIXME("free object pointer %p\n", *pPointer
);
764 FIXME("unhandled ptr type=%02x\n", type
);
765 RpcRaiseException(RPC_X_BAD_STUB_DATA
);
769 m
= NdrUnmarshaller
[*desc
& NDR_TABLE_MASK
];
770 if (m
) m(pStubMsg
, pPointer
, desc
, fMustAlloc
);
771 else FIXME("no unmarshaller for data type=%02x\n", *desc
);
774 TRACE("pointer=%p\n", *pPointer
);
777 /***********************************************************************
780 void WINAPI
PointerBufferSize(PMIDL_STUB_MESSAGE pStubMsg
,
781 unsigned char *Pointer
,
782 PFORMAT_STRING pFormat
)
784 unsigned type
= pFormat
[0], attr
= pFormat
[1];
788 TRACE("(%p,%p,%p)\n", pStubMsg
, Pointer
, pFormat
);
789 TRACE("type=%d, attr=%d\n", type
, attr
);
791 if (attr
& RPC_FC_P_SIMPLEPOINTER
) desc
= pFormat
;
792 else desc
= pFormat
+ *(const SHORT
*)pFormat
;
793 if (attr
& RPC_FC_P_DEREF
) {
794 Pointer
= *(unsigned char**)Pointer
;
795 TRACE("deref => %p\n", Pointer
);
799 case RPC_FC_RP
: /* ref pointer (always non-null) */
803 pStubMsg
->BufferLength
+= 4;
804 /* NULL pointer has no further representation */
810 FIXME("unhandled ptr type=%02x\n", type
);
811 RpcRaiseException(RPC_X_BAD_STUB_DATA
);
814 m
= NdrBufferSizer
[*desc
& NDR_TABLE_MASK
];
815 if (m
) m(pStubMsg
, Pointer
, desc
);
816 else FIXME("no buffersizer for data type=%02x\n", *desc
);
819 /***********************************************************************
820 * PointerMemorySize [RPCRT4.@]
822 unsigned long WINAPI
PointerMemorySize(PMIDL_STUB_MESSAGE pStubMsg
,
823 unsigned char *Buffer
,
824 PFORMAT_STRING pFormat
)
826 unsigned type
= pFormat
[0], attr
= pFormat
[1];
830 FIXME("(%p,%p,%p): stub\n", pStubMsg
, Buffer
, pFormat
);
831 TRACE("type=%d, attr=", type
); dump_pointer_attr(attr
);
833 if (attr
& RPC_FC_P_SIMPLEPOINTER
) desc
= pFormat
;
834 else desc
= pFormat
+ *(const SHORT
*)pFormat
;
835 if (attr
& RPC_FC_P_DEREF
) {
840 case RPC_FC_RP
: /* ref pointer (always non-null) */
843 FIXME("unhandled ptr type=%02x\n", type
);
844 RpcRaiseException(RPC_X_BAD_STUB_DATA
);
847 m
= NdrMemorySizer
[*desc
& NDR_TABLE_MASK
];
848 if (m
) m(pStubMsg
, desc
);
849 else FIXME("no memorysizer for data type=%02x\n", *desc
);
854 /***********************************************************************
855 * PointerFree [RPCRT4.@]
857 void WINAPI
PointerFree(PMIDL_STUB_MESSAGE pStubMsg
,
858 unsigned char *Pointer
,
859 PFORMAT_STRING pFormat
)
861 unsigned type
= pFormat
[0], attr
= pFormat
[1];
865 TRACE("(%p,%p,%p)\n", pStubMsg
, Pointer
, pFormat
);
866 TRACE("type=%d, attr=", type
); dump_pointer_attr(attr
);
867 if (attr
& RPC_FC_P_DONTFREE
) return;
869 if (attr
& RPC_FC_P_SIMPLEPOINTER
) desc
= pFormat
;
870 else desc
= pFormat
+ *(const SHORT
*)pFormat
;
871 if (attr
& RPC_FC_P_DEREF
) {
872 Pointer
= *(unsigned char**)Pointer
;
873 TRACE("deref => %p\n", Pointer
);
876 if (!Pointer
) return;
878 m
= NdrFreer
[*desc
& NDR_TABLE_MASK
];
879 if (m
) m(pStubMsg
, Pointer
, desc
);
881 /* hmm... is this sensible?
882 * perhaps we should check if the memory comes from NdrAllocate,
883 * and deallocate only if so - checking if the pointer is between
884 * BufferStart and BufferEnd is probably no good since the buffer
885 * may be reallocated when the server wants to marshal the reply */
887 case RPC_FC_BOGUS_STRUCT
:
888 case RPC_FC_BOGUS_ARRAY
:
889 case RPC_FC_USER_MARSHAL
:
892 FIXME("unhandled data type=%02x\n", *desc
);
894 case RPC_FC_C_CSTRING
:
895 case RPC_FC_C_WSTRING
:
896 if (pStubMsg
->ReuseBuffer
) goto notfree
;
902 if (attr
& RPC_FC_P_ONSTACK
) {
903 TRACE("not freeing stack ptr %p\n", Pointer
);
906 TRACE("freeing %p\n", Pointer
);
907 NdrFree(pStubMsg
, Pointer
);
910 TRACE("not freeing %p\n", Pointer
);
913 /***********************************************************************
914 * EmbeddedPointerMarshall
916 unsigned char * WINAPI
EmbeddedPointerMarshall(PMIDL_STUB_MESSAGE pStubMsg
,
917 unsigned char *pMemory
,
918 PFORMAT_STRING pFormat
)
920 unsigned char *Mark
= pStubMsg
->BufferMark
;
921 unsigned long Offset
= pStubMsg
->Offset
;
922 unsigned ofs
, rep
, count
, stride
, xofs
;
924 TRACE("(%p,%p,%p)\n", pStubMsg
, pMemory
, pFormat
);
926 if (*pFormat
!= RPC_FC_PP
) return NULL
;
929 while (pFormat
[0] != RPC_FC_END
) {
930 switch (pFormat
[0]) {
932 FIXME("unknown repeat type %d\n", pFormat
[0]);
933 case RPC_FC_NO_REPEAT
:
941 case RPC_FC_FIXED_REPEAT
:
942 rep
= *(const WORD
*)&pFormat
[2];
943 stride
= *(const WORD
*)&pFormat
[4];
944 ofs
= *(const WORD
*)&pFormat
[6];
945 count
= *(const WORD
*)&pFormat
[8];
949 case RPC_FC_VARIABLE_REPEAT
:
950 rep
= pStubMsg
->MaxCount
;
951 stride
= *(const WORD
*)&pFormat
[2];
952 ofs
= *(const WORD
*)&pFormat
[4];
953 count
= *(const WORD
*)&pFormat
[6];
954 xofs
= (pFormat
[1] == RPC_FC_VARIABLE_OFFSET
) ? Offset
* stride
: 0;
958 /* ofs doesn't seem to matter in this context */
960 PFORMAT_STRING info
= pFormat
;
961 unsigned char *membase
= pMemory
+ xofs
;
963 for (u
=0; u
<count
; u
++,info
+=8) {
964 unsigned char *memptr
= membase
+ *(const SHORT
*)&info
[0];
965 unsigned char *bufptr
= Mark
+ *(const SHORT
*)&info
[2];
966 PointerMarshall(pStubMsg
, bufptr
, *(unsigned char**)memptr
, info
+4);
970 pFormat
+= 8 * count
;
973 STD_OVERFLOW_CHECK(pStubMsg
);
978 /***********************************************************************
979 * EmbeddedPointerUnmarshall
981 unsigned char * WINAPI
EmbeddedPointerUnmarshall(PMIDL_STUB_MESSAGE pStubMsg
,
982 unsigned char **ppMemory
,
983 PFORMAT_STRING pFormat
,
984 unsigned char fMustAlloc
)
986 unsigned char *Mark
= pStubMsg
->BufferMark
;
987 unsigned long Offset
= pStubMsg
->Offset
;
988 unsigned ofs
, rep
, count
, stride
, xofs
;
990 TRACE("(%p,%p,%p,%d)\n", pStubMsg
, ppMemory
, pFormat
, fMustAlloc
);
992 if (*pFormat
!= RPC_FC_PP
) return NULL
;
995 while (pFormat
[0] != RPC_FC_END
) {
996 switch (pFormat
[0]) {
998 FIXME("unknown repeat type %d\n", pFormat
[0]);
999 case RPC_FC_NO_REPEAT
:
1007 case RPC_FC_FIXED_REPEAT
:
1008 rep
= *(const WORD
*)&pFormat
[2];
1009 stride
= *(const WORD
*)&pFormat
[4];
1010 ofs
= *(const WORD
*)&pFormat
[6];
1011 count
= *(const WORD
*)&pFormat
[8];
1015 case RPC_FC_VARIABLE_REPEAT
:
1016 rep
= pStubMsg
->MaxCount
;
1017 stride
= *(const WORD
*)&pFormat
[2];
1018 ofs
= *(const WORD
*)&pFormat
[4];
1019 count
= *(const WORD
*)&pFormat
[6];
1020 xofs
= (pFormat
[1] == RPC_FC_VARIABLE_OFFSET
) ? Offset
* stride
: 0;
1024 /* ofs doesn't seem to matter in this context */
1026 PFORMAT_STRING info
= pFormat
;
1027 unsigned char *membase
= *ppMemory
+ xofs
;
1029 for (u
=0; u
<count
; u
++,info
+=8) {
1030 unsigned char *memptr
= membase
+ *(const SHORT
*)&info
[0];
1031 unsigned char *bufptr
= Mark
+ *(const SHORT
*)&info
[2];
1032 PointerUnmarshall(pStubMsg
, bufptr
, (unsigned char**)memptr
, info
+4, fMustAlloc
);
1036 pFormat
+= 8 * count
;
1042 /***********************************************************************
1043 * EmbeddedPointerBufferSize
1045 void WINAPI
EmbeddedPointerBufferSize(PMIDL_STUB_MESSAGE pStubMsg
,
1046 unsigned char *pMemory
,
1047 PFORMAT_STRING pFormat
)
1049 unsigned long Offset
= pStubMsg
->Offset
;
1050 unsigned ofs
, rep
, count
, stride
, xofs
;
1052 TRACE("(%p,%p,%p)\n", pStubMsg
, pMemory
, pFormat
);
1053 if (*pFormat
!= RPC_FC_PP
) return;
1056 while (pFormat
[0] != RPC_FC_END
) {
1057 switch (pFormat
[0]) {
1059 FIXME("unknown repeat type %d\n", pFormat
[0]);
1060 case RPC_FC_NO_REPEAT
:
1068 case RPC_FC_FIXED_REPEAT
:
1069 rep
= *(const WORD
*)&pFormat
[2];
1070 stride
= *(const WORD
*)&pFormat
[4];
1071 ofs
= *(const WORD
*)&pFormat
[6];
1072 count
= *(const WORD
*)&pFormat
[8];
1076 case RPC_FC_VARIABLE_REPEAT
:
1077 rep
= pStubMsg
->MaxCount
;
1078 stride
= *(const WORD
*)&pFormat
[2];
1079 ofs
= *(const WORD
*)&pFormat
[4];
1080 count
= *(const WORD
*)&pFormat
[6];
1081 xofs
= (pFormat
[1] == RPC_FC_VARIABLE_OFFSET
) ? Offset
* stride
: 0;
1085 /* ofs doesn't seem to matter in this context */
1087 PFORMAT_STRING info
= pFormat
;
1088 unsigned char *membase
= pMemory
+ xofs
;
1090 for (u
=0; u
<count
; u
++,info
+=8) {
1091 unsigned char *memptr
= membase
+ *(const SHORT
*)&info
[0];
1092 PointerBufferSize(pStubMsg
, *(unsigned char**)memptr
, info
+4);
1096 pFormat
+= 8 * count
;
1100 /***********************************************************************
1101 * EmbeddedPointerMemorySize
1103 unsigned long WINAPI
EmbeddedPointerMemorySize(PMIDL_STUB_MESSAGE pStubMsg
,
1104 PFORMAT_STRING pFormat
)
1106 unsigned long Offset
= pStubMsg
->Offset
;
1107 unsigned char *Mark
= pStubMsg
->BufferMark
;
1108 unsigned ofs
, rep
, count
, stride
, xofs
;
1110 FIXME("(%p,%p): stub\n", pStubMsg
, pFormat
);
1111 if (*pFormat
!= RPC_FC_PP
) return 0;
1114 while (pFormat
[0] != RPC_FC_END
) {
1115 switch (pFormat
[0]) {
1117 FIXME("unknown repeat type %d\n", pFormat
[0]);
1118 case RPC_FC_NO_REPEAT
:
1126 case RPC_FC_FIXED_REPEAT
:
1127 rep
= *(const WORD
*)&pFormat
[2];
1128 stride
= *(const WORD
*)&pFormat
[4];
1129 ofs
= *(const WORD
*)&pFormat
[6];
1130 count
= *(const WORD
*)&pFormat
[8];
1134 case RPC_FC_VARIABLE_REPEAT
:
1135 rep
= pStubMsg
->MaxCount
;
1136 stride
= *(const WORD
*)&pFormat
[2];
1137 ofs
= *(const WORD
*)&pFormat
[4];
1138 count
= *(const WORD
*)&pFormat
[6];
1139 xofs
= (pFormat
[1] == RPC_FC_VARIABLE_OFFSET
) ? Offset
* stride
: 0;
1143 /* ofs doesn't seem to matter in this context */
1145 PFORMAT_STRING info
= pFormat
;
1147 for (u
=0; u
<count
; u
++,info
+=8) {
1148 unsigned char *bufptr
= Mark
+ *(const SHORT
*)&info
[2];
1149 PointerMemorySize(pStubMsg
, bufptr
, info
+4);
1153 pFormat
+= 8 * count
;
1159 /***********************************************************************
1160 * EmbeddedPointerFree
1162 void WINAPI
EmbeddedPointerFree(PMIDL_STUB_MESSAGE pStubMsg
,
1163 unsigned char *pMemory
,
1164 PFORMAT_STRING pFormat
)
1166 unsigned long Offset
= pStubMsg
->Offset
;
1167 unsigned ofs
, rep
, count
, stride
, xofs
;
1169 TRACE("(%p,%p,%p)\n", pStubMsg
, pMemory
, pFormat
);
1170 if (*pFormat
!= RPC_FC_PP
) return;
1173 while (pFormat
[0] != RPC_FC_END
) {
1174 switch (pFormat
[0]) {
1176 FIXME("unknown repeat type %d\n", pFormat
[0]);
1177 case RPC_FC_NO_REPEAT
:
1185 case RPC_FC_FIXED_REPEAT
:
1186 rep
= *(const WORD
*)&pFormat
[2];
1187 stride
= *(const WORD
*)&pFormat
[4];
1188 ofs
= *(const WORD
*)&pFormat
[6];
1189 count
= *(const WORD
*)&pFormat
[8];
1193 case RPC_FC_VARIABLE_REPEAT
:
1194 rep
= pStubMsg
->MaxCount
;
1195 stride
= *(const WORD
*)&pFormat
[2];
1196 ofs
= *(const WORD
*)&pFormat
[4];
1197 count
= *(const WORD
*)&pFormat
[6];
1198 xofs
= (pFormat
[1] == RPC_FC_VARIABLE_OFFSET
) ? Offset
* stride
: 0;
1202 /* ofs doesn't seem to matter in this context */
1204 PFORMAT_STRING info
= pFormat
;
1205 unsigned char *membase
= pMemory
+ xofs
;
1207 for (u
=0; u
<count
; u
++,info
+=8) {
1208 unsigned char *memptr
= membase
+ *(const SHORT
*)&info
[0];
1209 PointerFree(pStubMsg
, *(unsigned char**)memptr
, info
+4);
1213 pFormat
+= 8 * count
;
1217 /***********************************************************************
1218 * NdrPointerMarshall [RPCRT4.@]
1220 unsigned char * WINAPI
NdrPointerMarshall(PMIDL_STUB_MESSAGE pStubMsg
,
1221 unsigned char *pMemory
,
1222 PFORMAT_STRING pFormat
)
1224 TRACE("(%p,%p,%p)\n", pStubMsg
, pMemory
, pFormat
);
1226 pStubMsg
->BufferMark
= pStubMsg
->Buffer
;
1227 PointerMarshall(pStubMsg
, pStubMsg
->Buffer
, pMemory
, pFormat
);
1229 STD_OVERFLOW_CHECK(pStubMsg
);
1234 /***********************************************************************
1235 * NdrPointerUnmarshall [RPCRT4.@]
1237 unsigned char * WINAPI
NdrPointerUnmarshall(PMIDL_STUB_MESSAGE pStubMsg
,
1238 unsigned char **ppMemory
,
1239 PFORMAT_STRING pFormat
,
1240 unsigned char fMustAlloc
)
1242 TRACE("(%p,%p,%p,%d)\n", pStubMsg
, ppMemory
, pFormat
, fMustAlloc
);
1244 pStubMsg
->BufferMark
= pStubMsg
->Buffer
;
1245 PointerUnmarshall(pStubMsg
, pStubMsg
->Buffer
, ppMemory
, pFormat
, fMustAlloc
);
1250 /***********************************************************************
1251 * NdrPointerBufferSize [RPCRT4.@]
1253 void WINAPI
NdrPointerBufferSize(PMIDL_STUB_MESSAGE pStubMsg
,
1254 unsigned char *pMemory
,
1255 PFORMAT_STRING pFormat
)
1257 TRACE("(%p,%p,%p)\n", pStubMsg
, pMemory
, pFormat
);
1258 PointerBufferSize(pStubMsg
, pMemory
, pFormat
);
1261 /***********************************************************************
1262 * NdrPointerMemorySize [RPCRT4.@]
1264 unsigned long WINAPI
NdrPointerMemorySize(PMIDL_STUB_MESSAGE pStubMsg
,
1265 PFORMAT_STRING pFormat
)
1267 /* unsigned size = *(LPWORD)(pFormat+2); */
1268 FIXME("(%p,%p): stub\n", pStubMsg
, pFormat
);
1269 PointerMemorySize(pStubMsg
, pStubMsg
->Buffer
, pFormat
);
1273 /***********************************************************************
1274 * NdrPointerFree [RPCRT4.@]
1276 void WINAPI
NdrPointerFree(PMIDL_STUB_MESSAGE pStubMsg
,
1277 unsigned char *pMemory
,
1278 PFORMAT_STRING pFormat
)
1280 TRACE("(%p,%p,%p)\n", pStubMsg
, pMemory
, pFormat
);
1281 PointerFree(pStubMsg
, pMemory
, pFormat
);
1284 /***********************************************************************
1285 * NdrSimpleStructMarshall [RPCRT4.@]
1287 unsigned char * WINAPI
NdrSimpleStructMarshall(PMIDL_STUB_MESSAGE pStubMsg
,
1288 unsigned char *pMemory
,
1289 PFORMAT_STRING pFormat
)
1291 unsigned size
= *(const WORD
*)(pFormat
+2);
1292 TRACE("(%p,%p,%p)\n", pStubMsg
, pMemory
, pFormat
);
1294 memcpy(pStubMsg
->Buffer
, pMemory
, size
);
1295 pStubMsg
->BufferMark
= pStubMsg
->Buffer
;
1296 pStubMsg
->Buffer
+= size
;
1298 if (pFormat
[0] != RPC_FC_STRUCT
)
1299 EmbeddedPointerMarshall(pStubMsg
, pMemory
, pFormat
+4);
1302 * This test does not work when NdrSimpleStructMarshall is called
1303 * by an rpc-server to marshall data to return to the client because
1304 * BufferStart and BufferEnd are bogus. MIDL does not update them
1305 * when a new buffer is allocated in order to return data to the caller.
1308 STD_OVERFLOW_CHECK(pStubMsg
);
1314 /***********************************************************************
1315 * NdrSimpleStructUnmarshall [RPCRT4.@]
1317 unsigned char * WINAPI
NdrSimpleStructUnmarshall(PMIDL_STUB_MESSAGE pStubMsg
,
1318 unsigned char **ppMemory
,
1319 PFORMAT_STRING pFormat
,
1320 unsigned char fMustAlloc
)
1322 unsigned size
= *(const WORD
*)(pFormat
+2);
1323 TRACE("(%p,%p,%p,%d)\n", pStubMsg
, ppMemory
, pFormat
, fMustAlloc
);
1326 *ppMemory
= NdrAllocate(pStubMsg
, size
);
1327 memcpy(*ppMemory
, pStubMsg
->Buffer
, size
);
1329 if (pStubMsg
->ReuseBuffer
&& !*ppMemory
)
1330 /* for servers, we may just point straight into the RPC buffer, I think
1331 * (I guess that's what MS does since MIDL code doesn't try to free) */
1332 *ppMemory
= pStubMsg
->Buffer
;
1334 /* for clients, memory should be provided by caller */
1335 memcpy(*ppMemory
, pStubMsg
->Buffer
, size
);
1338 pStubMsg
->BufferMark
= pStubMsg
->Buffer
;
1339 pStubMsg
->Buffer
+= size
;
1341 if (pFormat
[0] != RPC_FC_STRUCT
)
1342 EmbeddedPointerUnmarshall(pStubMsg
, ppMemory
, pFormat
+4, fMustAlloc
);
1348 /***********************************************************************
1349 * NdrSimpleTypeUnmarshall [RPCRT4.@]
1351 void WINAPI
NdrSimpleTypeMarshall(PMIDL_STUB_MESSAGE pStubMsg
,
1352 unsigned char *pMemory
,
1353 unsigned char FormatChar
)
1359 /***********************************************************************
1360 * NdrSimpleTypeUnmarshall [RPCRT4.@]
1362 void WINAPI
NdrSimpleTypeUnmarshall(PMIDL_STUB_MESSAGE pStubMsg
,
1363 unsigned char *pMemory
,
1364 unsigned char FormatChar
)
1370 /***********************************************************************
1371 * NdrSimpleStructBufferSize [RPCRT4.@]
1373 void WINAPI
NdrSimpleStructBufferSize(PMIDL_STUB_MESSAGE pStubMsg
,
1374 unsigned char *pMemory
,
1375 PFORMAT_STRING pFormat
)
1377 unsigned size
= *(const WORD
*)(pFormat
+2);
1378 TRACE("(%p,%p,%p)\n", pStubMsg
, pMemory
, pFormat
);
1379 pStubMsg
->BufferLength
+= size
;
1380 if (pFormat
[0] != RPC_FC_STRUCT
)
1381 EmbeddedPointerBufferSize(pStubMsg
, pMemory
, pFormat
+4);
1384 /***********************************************************************
1385 * NdrSimpleStructMemorySize [RPCRT4.@]
1387 unsigned long WINAPI
NdrSimpleStructMemorySize(PMIDL_STUB_MESSAGE pStubMsg
,
1388 PFORMAT_STRING pFormat
)
1390 /* unsigned size = *(LPWORD)(pFormat+2); */
1391 FIXME("(%p,%p): stub\n", pStubMsg
, pFormat
);
1392 if (pFormat
[0] != RPC_FC_STRUCT
)
1393 EmbeddedPointerMemorySize(pStubMsg
, pFormat
+4);
1397 /***********************************************************************
1398 * NdrSimpleStructFree [RPCRT4.@]
1400 void WINAPI
NdrSimpleStructFree(PMIDL_STUB_MESSAGE pStubMsg
,
1401 unsigned char *pMemory
,
1402 PFORMAT_STRING pFormat
)
1404 TRACE("(%p,%p,%p)\n", pStubMsg
, pMemory
, pFormat
);
1405 if (pFormat
[0] != RPC_FC_STRUCT
)
1406 EmbeddedPointerFree(pStubMsg
, pMemory
, pFormat
+4);
1410 unsigned long WINAPI
EmbeddedComplexSize(PMIDL_STUB_MESSAGE pStubMsg
,
1411 PFORMAT_STRING pFormat
)
1415 case RPC_FC_PSTRUCT
:
1416 case RPC_FC_CSTRUCT
:
1417 case RPC_FC_BOGUS_STRUCT
:
1418 return *(const WORD
*)&pFormat
[2];
1419 case RPC_FC_USER_MARSHAL
:
1420 return *(const WORD
*)&pFormat
[4];
1422 FIXME("unhandled embedded type %02x\n", *pFormat
);
1428 unsigned char * WINAPI
ComplexMarshall(PMIDL_STUB_MESSAGE pStubMsg
,
1429 unsigned char *pMemory
,
1430 PFORMAT_STRING pFormat
,
1431 PFORMAT_STRING pPointer
)
1433 PFORMAT_STRING desc
;
1437 while (*pFormat
!= RPC_FC_END
) {
1441 TRACE("short=%d <= %p\n", *(WORD
*)pMemory
, pMemory
);
1442 memcpy(pStubMsg
->Buffer
, pMemory
, 2);
1443 pStubMsg
->Buffer
+= 2;
1449 TRACE("long=%ld <= %p\n", *(DWORD
*)pMemory
, pMemory
);
1450 memcpy(pStubMsg
->Buffer
, pMemory
, 4);
1451 pStubMsg
->Buffer
+= 4;
1454 case RPC_FC_POINTER
:
1455 TRACE("pointer=%p <= %p\n", *(unsigned char**)pMemory
, pMemory
);
1456 NdrPointerMarshall(pStubMsg
, *(unsigned char**)pMemory
, pPointer
);
1460 case RPC_FC_ALIGNM4
:
1461 ALIGN_POINTER(pMemory
, 3);
1463 case RPC_FC_ALIGNM8
:
1464 ALIGN_POINTER(pMemory
, 7);
1466 case RPC_FC_STRUCTPAD2
:
1469 case RPC_FC_EMBEDDED_COMPLEX
:
1470 pMemory
+= pFormat
[1];
1472 desc
= pFormat
+ *(const SHORT
*)pFormat
;
1473 size
= EmbeddedComplexSize(pStubMsg
, desc
);
1474 TRACE("embedded complex (size=%ld) <= %p\n", size
, pMemory
);
1475 m
= NdrMarshaller
[*desc
& NDR_TABLE_MASK
];
1476 if (m
) m(pStubMsg
, pMemory
, desc
);
1477 else FIXME("no marshaller for embedded type %02x\n", *desc
);
1484 FIXME("unhandled format %02x\n", *pFormat
);
1492 unsigned char * WINAPI
ComplexUnmarshall(PMIDL_STUB_MESSAGE pStubMsg
,
1493 unsigned char *pMemory
,
1494 PFORMAT_STRING pFormat
,
1495 PFORMAT_STRING pPointer
,
1496 unsigned char fMustAlloc
)
1498 PFORMAT_STRING desc
;
1502 while (*pFormat
!= RPC_FC_END
) {
1506 memcpy(pMemory
, pStubMsg
->Buffer
, 2);
1507 TRACE("short=%d => %p\n", *(WORD
*)pMemory
, pMemory
);
1508 pStubMsg
->Buffer
+= 2;
1514 memcpy(pMemory
, pStubMsg
->Buffer
, 4);
1515 TRACE("long=%ld => %p\n", *(DWORD
*)pMemory
, pMemory
);
1516 pStubMsg
->Buffer
+= 4;
1519 case RPC_FC_POINTER
:
1520 *(unsigned char**)pMemory
= NULL
;
1521 TRACE("pointer => %p\n", pMemory
);
1522 NdrPointerUnmarshall(pStubMsg
, (unsigned char**)pMemory
, pPointer
, fMustAlloc
);
1526 case RPC_FC_ALIGNM4
:
1527 ALIGN_POINTER(pMemory
, 3);
1529 case RPC_FC_ALIGNM8
:
1530 ALIGN_POINTER(pMemory
, 7);
1532 case RPC_FC_STRUCTPAD2
:
1535 case RPC_FC_EMBEDDED_COMPLEX
:
1536 pMemory
+= pFormat
[1];
1538 desc
= pFormat
+ *(const SHORT
*)pFormat
;
1539 size
= EmbeddedComplexSize(pStubMsg
, desc
);
1540 TRACE("embedded complex (size=%ld) => %p\n", size
, pMemory
);
1541 m
= NdrUnmarshaller
[*desc
& NDR_TABLE_MASK
];
1542 memset(pMemory
, 0, size
); /* just in case */
1543 if (m
) m(pStubMsg
, &pMemory
, desc
, fMustAlloc
);
1544 else FIXME("no unmarshaller for embedded type %02x\n", *desc
);
1551 FIXME("unhandled format %d\n", *pFormat
);
1559 unsigned char * WINAPI
ComplexBufferSize(PMIDL_STUB_MESSAGE pStubMsg
,
1560 unsigned char *pMemory
,
1561 PFORMAT_STRING pFormat
,
1562 PFORMAT_STRING pPointer
)
1564 PFORMAT_STRING desc
;
1568 while (*pFormat
!= RPC_FC_END
) {
1572 pStubMsg
->BufferLength
+= 2;
1578 pStubMsg
->BufferLength
+= 4;
1581 case RPC_FC_POINTER
:
1582 NdrPointerBufferSize(pStubMsg
, *(unsigned char**)pMemory
, pPointer
);
1586 case RPC_FC_ALIGNM4
:
1587 ALIGN_POINTER(pMemory
, 3);
1589 case RPC_FC_ALIGNM8
:
1590 ALIGN_POINTER(pMemory
, 7);
1592 case RPC_FC_STRUCTPAD2
:
1595 case RPC_FC_EMBEDDED_COMPLEX
:
1596 pMemory
+= pFormat
[1];
1598 desc
= pFormat
+ *(const SHORT
*)pFormat
;
1599 size
= EmbeddedComplexSize(pStubMsg
, desc
);
1600 m
= NdrBufferSizer
[*desc
& NDR_TABLE_MASK
];
1601 if (m
) m(pStubMsg
, pMemory
, desc
);
1602 else FIXME("no buffersizer for embedded type %02x\n", *desc
);
1609 FIXME("unhandled format %d\n", *pFormat
);
1617 unsigned char * WINAPI
ComplexFree(PMIDL_STUB_MESSAGE pStubMsg
,
1618 unsigned char *pMemory
,
1619 PFORMAT_STRING pFormat
,
1620 PFORMAT_STRING pPointer
)
1622 PFORMAT_STRING desc
;
1626 while (*pFormat
!= RPC_FC_END
) {
1637 case RPC_FC_POINTER
:
1638 NdrPointerFree(pStubMsg
, *(unsigned char**)pMemory
, pPointer
);
1642 case RPC_FC_ALIGNM4
:
1643 ALIGN_POINTER(pMemory
, 3);
1645 case RPC_FC_ALIGNM8
:
1646 ALIGN_POINTER(pMemory
, 7);
1648 case RPC_FC_STRUCTPAD2
:
1651 case RPC_FC_EMBEDDED_COMPLEX
:
1652 pMemory
+= pFormat
[1];
1654 desc
= pFormat
+ *(const SHORT
*)pFormat
;
1655 size
= EmbeddedComplexSize(pStubMsg
, desc
);
1656 m
= NdrFreer
[*desc
& NDR_TABLE_MASK
];
1657 if (m
) m(pStubMsg
, pMemory
, desc
);
1658 else FIXME("no freer for embedded type %02x\n", *desc
);
1665 FIXME("unhandled format %d\n", *pFormat
);
1673 unsigned long WINAPI
ComplexStructSize(PMIDL_STUB_MESSAGE pStubMsg
,
1674 PFORMAT_STRING pFormat
)
1676 PFORMAT_STRING desc
;
1677 unsigned long size
= 0;
1679 while (*pFormat
!= RPC_FC_END
) {
1689 case RPC_FC_POINTER
:
1692 case RPC_FC_ALIGNM4
:
1693 ALIGN_LENGTH(size
, 3);
1695 case RPC_FC_ALIGNM8
:
1696 ALIGN_LENGTH(size
, 7);
1698 case RPC_FC_STRUCTPAD2
:
1701 case RPC_FC_EMBEDDED_COMPLEX
:
1704 desc
= pFormat
+ *(const SHORT
*)pFormat
;
1705 size
+= EmbeddedComplexSize(pStubMsg
, desc
);
1711 FIXME("unhandled format %d\n", *pFormat
);
1719 /***********************************************************************
1720 * NdrComplexStructMarshall [RPCRT4.@]
1722 unsigned char * WINAPI
NdrComplexStructMarshall(PMIDL_STUB_MESSAGE pStubMsg
,
1723 unsigned char *pMemory
,
1724 PFORMAT_STRING pFormat
)
1726 PFORMAT_STRING conf_array
= NULL
;
1727 PFORMAT_STRING pointer_desc
= NULL
;
1728 unsigned char *OldMemory
= pStubMsg
->Memory
;
1730 TRACE("(%p,%p,%p)\n", pStubMsg
, pMemory
, pFormat
);
1733 if (*(const WORD
*)pFormat
) conf_array
= pFormat
+ *(const WORD
*)pFormat
;
1735 if (*(const WORD
*)pFormat
) pointer_desc
= pFormat
+ *(const WORD
*)pFormat
;
1738 pStubMsg
->Memory
= pMemory
;
1740 ComplexMarshall(pStubMsg
, pMemory
, pFormat
, pointer_desc
);
1743 NdrConformantArrayMarshall(pStubMsg
, pMemory
, conf_array
);
1745 pStubMsg
->Memory
= OldMemory
;
1747 STD_OVERFLOW_CHECK(pStubMsg
);
1752 /***********************************************************************
1753 * NdrComplexStructUnmarshall [RPCRT4.@]
1755 unsigned char * WINAPI
NdrComplexStructUnmarshall(PMIDL_STUB_MESSAGE pStubMsg
,
1756 unsigned char **ppMemory
,
1757 PFORMAT_STRING pFormat
,
1758 unsigned char fMustAlloc
)
1760 unsigned size
= *(const WORD
*)(pFormat
+2);
1761 PFORMAT_STRING conf_array
= NULL
;
1762 PFORMAT_STRING pointer_desc
= NULL
;
1763 unsigned char *pMemory
;
1765 TRACE("(%p,%p,%p,%d)\n", pStubMsg
, ppMemory
, pFormat
, fMustAlloc
);
1767 if (fMustAlloc
|| !*ppMemory
)
1768 *ppMemory
= NdrAllocate(pStubMsg
, size
);
1771 if (*(const WORD
*)pFormat
) conf_array
= pFormat
+ *(const WORD
*)pFormat
;
1773 if (*(const WORD
*)pFormat
) pointer_desc
= pFormat
+ *(const WORD
*)pFormat
;
1776 pMemory
= ComplexUnmarshall(pStubMsg
, *ppMemory
, pFormat
, pointer_desc
, fMustAlloc
);
1779 NdrConformantArrayUnmarshall(pStubMsg
, &pMemory
, conf_array
, fMustAlloc
);
1784 /***********************************************************************
1785 * NdrComplexStructBufferSize [RPCRT4.@]
1787 void WINAPI
NdrComplexStructBufferSize(PMIDL_STUB_MESSAGE pStubMsg
,
1788 unsigned char *pMemory
,
1789 PFORMAT_STRING pFormat
)
1791 PFORMAT_STRING conf_array
= NULL
;
1792 PFORMAT_STRING pointer_desc
= NULL
;
1793 unsigned char *OldMemory
= pStubMsg
->Memory
;
1795 TRACE("(%p,%p,%p)\n", pStubMsg
, pMemory
, pFormat
);
1798 if (*(const WORD
*)pFormat
) conf_array
= pFormat
+ *(const WORD
*)pFormat
;
1800 if (*(const WORD
*)pFormat
) pointer_desc
= pFormat
+ *(const WORD
*)pFormat
;
1803 pStubMsg
->Memory
= pMemory
;
1805 pMemory
= ComplexBufferSize(pStubMsg
, pMemory
, pFormat
, pointer_desc
);
1808 NdrConformantArrayBufferSize(pStubMsg
, pMemory
, conf_array
);
1810 pStubMsg
->Memory
= OldMemory
;
1813 /***********************************************************************
1814 * NdrComplexStructMemorySize [RPCRT4.@]
1816 unsigned long WINAPI
NdrComplexStructMemorySize(PMIDL_STUB_MESSAGE pStubMsg
,
1817 PFORMAT_STRING pFormat
)
1819 /* unsigned size = *(LPWORD)(pFormat+2); */
1820 PFORMAT_STRING conf_array
= NULL
;
1821 PFORMAT_STRING pointer_desc
= NULL
;
1823 FIXME("(%p,%p): stub\n", pStubMsg
, pFormat
);
1826 if (*(const WORD
*)pFormat
) conf_array
= pFormat
+ *(const WORD
*)pFormat
;
1828 if (*(const WORD
*)pFormat
) pointer_desc
= pFormat
+ *(const WORD
*)pFormat
;
1834 /***********************************************************************
1835 * NdrComplexStructFree [RPCRT4.@]
1837 void WINAPI
NdrComplexStructFree(PMIDL_STUB_MESSAGE pStubMsg
,
1838 unsigned char *pMemory
,
1839 PFORMAT_STRING pFormat
)
1841 PFORMAT_STRING conf_array
= NULL
;
1842 PFORMAT_STRING pointer_desc
= NULL
;
1843 unsigned char *OldMemory
= pStubMsg
->Memory
;
1845 TRACE("(%p,%p,%p)\n", pStubMsg
, pMemory
, pFormat
);
1848 if (*(const WORD
*)pFormat
) conf_array
= pFormat
+ *(const WORD
*)pFormat
;
1850 if (*(const WORD
*)pFormat
) pointer_desc
= pFormat
+ *(const WORD
*)pFormat
;
1853 pStubMsg
->Memory
= pMemory
;
1855 pMemory
= ComplexFree(pStubMsg
, pMemory
, pFormat
, pointer_desc
);
1858 NdrConformantArrayFree(pStubMsg
, pMemory
, conf_array
);
1860 pStubMsg
->Memory
= OldMemory
;
1863 /***********************************************************************
1864 * NdrConformantArrayMarshall [RPCRT4.@]
1866 unsigned char * WINAPI
NdrConformantArrayMarshall(PMIDL_STUB_MESSAGE pStubMsg
,
1867 unsigned char *pMemory
,
1868 PFORMAT_STRING pFormat
)
1870 DWORD size
= 0, esize
= *(const WORD
*)(pFormat
+2);
1871 TRACE("(%p,%p,%p)\n", pStubMsg
, pMemory
, pFormat
);
1872 if (pFormat
[0] != RPC_FC_CARRAY
) FIXME("format=%d\n", pFormat
[0]);
1874 pFormat
= ComputeConformance(pStubMsg
, pMemory
, pFormat
+4, 0);
1875 size
= pStubMsg
->MaxCount
;
1877 NDR_LOCAL_UINT32_WRITE(pStubMsg
->Buffer
, size
);
1878 pStubMsg
->Buffer
+= 4;
1880 memcpy(pStubMsg
->Buffer
, pMemory
, size
*esize
);
1881 pStubMsg
->BufferMark
= pStubMsg
->Buffer
;
1882 pStubMsg
->Buffer
+= size
*esize
;
1884 EmbeddedPointerMarshall(pStubMsg
, pMemory
, pFormat
);
1886 STD_OVERFLOW_CHECK(pStubMsg
);
1891 /***********************************************************************
1892 * NdrConformantArrayUnmarshall [RPCRT4.@]
1894 unsigned char * WINAPI
NdrConformantArrayUnmarshall(PMIDL_STUB_MESSAGE pStubMsg
,
1895 unsigned char **ppMemory
,
1896 PFORMAT_STRING pFormat
,
1897 unsigned char fMustAlloc
)
1899 DWORD size
= 0, esize
= *(const WORD
*)(pFormat
+2);
1900 TRACE("(%p,%p,%p,%d)\n", pStubMsg
, ppMemory
, pFormat
, fMustAlloc
);
1901 if (pFormat
[0] != RPC_FC_CARRAY
) FIXME("format=%d\n", pFormat
[0]);
1903 pFormat
= ReadConformance(pStubMsg
, pFormat
+4);
1904 size
= pStubMsg
->MaxCount
;
1906 if (fMustAlloc
|| !*ppMemory
)
1907 *ppMemory
= NdrAllocate(pStubMsg
, size
*esize
);
1909 memcpy(*ppMemory
, pStubMsg
->Buffer
, size
*esize
);
1911 pStubMsg
->BufferMark
= pStubMsg
->Buffer
;
1912 pStubMsg
->Buffer
+= size
*esize
;
1914 EmbeddedPointerUnmarshall(pStubMsg
, ppMemory
, pFormat
, fMustAlloc
);
1919 /***********************************************************************
1920 * NdrConformantArrayBufferSize [RPCRT4.@]
1922 void WINAPI
NdrConformantArrayBufferSize(PMIDL_STUB_MESSAGE pStubMsg
,
1923 unsigned char *pMemory
,
1924 PFORMAT_STRING pFormat
)
1926 DWORD size
= 0, esize
= *(const WORD
*)(pFormat
+2);
1927 TRACE("(%p,%p,%p)\n", pStubMsg
, pMemory
, pFormat
);
1928 if (pFormat
[0] != RPC_FC_CARRAY
) FIXME("format=%d\n", pFormat
[0]);
1930 pFormat
= ComputeConformance(pStubMsg
, pMemory
, pFormat
+4, 0);
1931 size
= pStubMsg
->MaxCount
;
1933 /* conformance value plus array */
1934 pStubMsg
->BufferLength
+= sizeof(DWORD
) + size
*esize
;
1936 EmbeddedPointerBufferSize(pStubMsg
, pMemory
, pFormat
);
1939 /***********************************************************************
1940 * NdrConformantArrayMemorySize [RPCRT4.@]
1942 unsigned long WINAPI
NdrConformantArrayMemorySize(PMIDL_STUB_MESSAGE pStubMsg
,
1943 PFORMAT_STRING pFormat
)
1945 DWORD size
= 0, esize
= *(const WORD
*)(pFormat
+2);
1946 unsigned char *buffer
;
1948 TRACE("(%p,%p)\n", pStubMsg
, pFormat
);
1949 if (pFormat
[0] != RPC_FC_CARRAY
) FIXME("format=%d\n", pFormat
[0]);
1951 buffer
= pStubMsg
->Buffer
;
1952 pFormat
= ReadConformance(pStubMsg
, pFormat
+4);
1953 pStubMsg
->Buffer
= buffer
;
1954 size
= pStubMsg
->MaxCount
;
1959 /***********************************************************************
1960 * NdrConformantArrayFree [RPCRT4.@]
1962 void WINAPI
NdrConformantArrayFree(PMIDL_STUB_MESSAGE pStubMsg
,
1963 unsigned char *pMemory
,
1964 PFORMAT_STRING pFormat
)
1966 TRACE("(%p,%p,%p)\n", pStubMsg
, pMemory
, pFormat
);
1967 if (pFormat
[0] != RPC_FC_CARRAY
) FIXME("format=%d\n", pFormat
[0]);
1969 EmbeddedPointerFree(pStubMsg
, pMemory
, pFormat
);
1973 /***********************************************************************
1974 * NdrConformantVaryingArrayMarshall [RPCRT4.@]
1976 unsigned char* WINAPI
NdrConformantVaryingArrayMarshall( PMIDL_STUB_MESSAGE pStubMsg
,
1977 unsigned char* pMemory
,
1978 PFORMAT_STRING pFormat
)
1980 DWORD esize
= *(const WORD
*)(pFormat
+2);
1982 TRACE("(%p, %p, %p)\n", pStubMsg
, pMemory
, pFormat
);
1984 if (pFormat
[0] != RPC_FC_CVARRAY
)
1986 ERR("invalid format type %x\n", pFormat
[0]);
1987 RpcRaiseException(RPC_S_INTERNAL_ERROR
);
1991 pFormat
= ComputeConformance(pStubMsg
, pMemory
, pFormat
+4, 0);
1992 pFormat
= ComputeVariance(pStubMsg
, pMemory
, pFormat
, 0);
1994 NDR_LOCAL_UINT32_WRITE(pStubMsg
->Buffer
, pStubMsg
->MaxCount
);
1995 pStubMsg
->Buffer
+= 4;
1996 NDR_LOCAL_UINT32_WRITE(pStubMsg
->Buffer
, pStubMsg
->Offset
);
1997 pStubMsg
->Buffer
+= 4;
1998 NDR_LOCAL_UINT32_WRITE(pStubMsg
->Buffer
, pStubMsg
->ActualCount
);
1999 pStubMsg
->Buffer
+= 4;
2001 memcpy(pStubMsg
->Buffer
, pMemory
+ pStubMsg
->Offset
, pStubMsg
->ActualCount
*esize
);
2002 pStubMsg
->BufferMark
= pStubMsg
->Buffer
;
2003 pStubMsg
->Buffer
+= pStubMsg
->ActualCount
*esize
;
2005 EmbeddedPointerMarshall(pStubMsg
, pMemory
, pFormat
);
2007 STD_OVERFLOW_CHECK(pStubMsg
);
2013 /***********************************************************************
2014 * NdrConformantVaryingArrayUnmarshall [RPCRT4.@]
2016 unsigned char* WINAPI
NdrConformantVaryingArrayUnmarshall( PMIDL_STUB_MESSAGE pStubMsg
,
2017 unsigned char** ppMemory
,
2018 PFORMAT_STRING pFormat
,
2019 unsigned char fMustAlloc
)
2022 DWORD esize
= *(const WORD
*)(pFormat
+2);
2024 TRACE("(%p, %p, %p, %d)\n", pStubMsg
, ppMemory
, pFormat
, fMustAlloc
);
2026 if (pFormat
[0] != RPC_FC_CVARRAY
)
2028 ERR("invalid format type %x\n", pFormat
[0]);
2029 RpcRaiseException(RPC_S_INTERNAL_ERROR
);
2032 pFormat
= ReadConformance(pStubMsg
, pFormat
);
2033 offset
= NDR_LOCAL_UINT32_READ(pStubMsg
->Buffer
);
2034 pStubMsg
->Buffer
+= 4;
2035 pFormat
= ReadVariance(pStubMsg
, pFormat
);
2037 if (!*ppMemory
|| fMustAlloc
)
2038 *ppMemory
= NdrAllocate(pStubMsg
, pStubMsg
->MaxCount
* esize
);
2039 memcpy(*ppMemory
+ offset
, pStubMsg
->Buffer
, pStubMsg
->ActualCount
* esize
);
2040 pStubMsg
->Buffer
+= pStubMsg
->ActualCount
* esize
;
2042 EmbeddedPointerUnmarshall(pStubMsg
, ppMemory
, pFormat
, fMustAlloc
);
2048 /***********************************************************************
2049 * NdrConformantVaryingArrayFree [RPCRT4.@]
2051 void WINAPI
NdrConformantVaryingArrayFree( PMIDL_STUB_MESSAGE pStubMsg
,
2052 unsigned char* pMemory
,
2053 PFORMAT_STRING pFormat
)
2059 /***********************************************************************
2060 * NdrConformantVaryingArrayBufferSize [RPCRT4.@]
2062 void WINAPI
NdrConformantVaryingArrayBufferSize( PMIDL_STUB_MESSAGE pStubMsg
,
2063 unsigned char* pMemory
, PFORMAT_STRING pFormat
)
2065 DWORD esize
= *(const WORD
*)(pFormat
+2);
2067 TRACE("(%p, %p, %p)\n", pStubMsg
, pMemory
, pFormat
);
2069 if (pFormat
[0] != RPC_FC_CVARRAY
)
2071 ERR("invalid format type %x\n", pFormat
[0]);
2072 RpcRaiseException(RPC_S_INTERNAL_ERROR
);
2077 pFormat
= ComputeConformance(pStubMsg
, pMemory
, pFormat
+4, 0);
2078 /* compute length */
2079 pFormat
= ComputeVariance(pStubMsg
, pMemory
, pFormat
, 0);
2081 /* conformance + offset + variance + array */
2082 pStubMsg
->BufferLength
+= 3*sizeof(DWORD
) + pStubMsg
->ActualCount
*esize
;
2084 EmbeddedPointerBufferSize(pStubMsg
, pMemory
, pFormat
);
2088 /***********************************************************************
2089 * NdrConformantVaryingArrayMemorySize [RPCRT4.@]
2091 unsigned long WINAPI
NdrConformantVaryingArrayMemorySize( PMIDL_STUB_MESSAGE pStubMsg
,
2092 PFORMAT_STRING pFormat
)
2099 /***********************************************************************
2100 * NdrComplexArrayMarshall [RPCRT4.@]
2102 unsigned char * WINAPI
NdrComplexArrayMarshall(PMIDL_STUB_MESSAGE pStubMsg
,
2103 unsigned char *pMemory
,
2104 PFORMAT_STRING pFormat
)
2106 DWORD size
= 0, count
, def
;
2107 TRACE("(%p,%p,%p)\n", pStubMsg
, pMemory
, pFormat
);
2109 def
= *(const WORD
*)&pFormat
[2];
2112 pFormat
= ComputeConformance(pStubMsg
, pMemory
, pFormat
, def
);
2113 size
= pStubMsg
->MaxCount
;
2114 TRACE("conformance=%ld\n", size
);
2116 if (*(const DWORD
*)pFormat
!= 0xffffffff)
2117 FIXME("compute variance\n");
2120 NDR_LOCAL_UINT32_WRITE(pStubMsg
->Buffer
, size
);
2121 pStubMsg
->Buffer
+= 4;
2123 for (count
=0; count
<size
; count
++)
2124 pMemory
= ComplexMarshall(pStubMsg
, pMemory
, pFormat
, NULL
);
2126 STD_OVERFLOW_CHECK(pStubMsg
);
2131 /***********************************************************************
2132 * NdrComplexArrayUnmarshall [RPCRT4.@]
2134 unsigned char * WINAPI
NdrComplexArrayUnmarshall(PMIDL_STUB_MESSAGE pStubMsg
,
2135 unsigned char **ppMemory
,
2136 PFORMAT_STRING pFormat
,
2137 unsigned char fMustAlloc
)
2139 DWORD size
= 0, count
, esize
;
2140 unsigned char *pMemory
;
2141 TRACE("(%p,%p,%p,%d)\n", pStubMsg
, ppMemory
, pFormat
, fMustAlloc
);
2145 pFormat
= ReadConformance(pStubMsg
, pFormat
);
2146 size
= pStubMsg
->MaxCount
;
2147 TRACE("conformance=%ld\n", size
);
2151 esize
= ComplexStructSize(pStubMsg
, pFormat
);
2153 if (fMustAlloc
|| !*ppMemory
)
2154 *ppMemory
= NdrAllocate(pStubMsg
, size
*esize
);
2156 pMemory
= *ppMemory
;
2157 for (count
=0; count
<size
; count
++)
2158 pMemory
= ComplexUnmarshall(pStubMsg
, pMemory
, pFormat
, NULL
, fMustAlloc
);
2163 /***********************************************************************
2164 * NdrComplexArrayBufferSize [RPCRT4.@]
2166 void WINAPI
NdrComplexArrayBufferSize(PMIDL_STUB_MESSAGE pStubMsg
,
2167 unsigned char *pMemory
,
2168 PFORMAT_STRING pFormat
)
2170 DWORD size
= 0, count
, def
;
2171 TRACE("(%p,%p,%p)\n", pStubMsg
, pMemory
, pFormat
);
2173 def
= *(const WORD
*)&pFormat
[2];
2176 pFormat
= ComputeConformance(pStubMsg
, pMemory
, pFormat
, def
);
2177 size
= pStubMsg
->MaxCount
;
2178 TRACE("conformance=%ld\n", size
);
2180 if (*(const DWORD
*)pFormat
!= 0xffffffff)
2181 FIXME("compute variance\n");
2184 for (count
=0; count
<size
; count
++)
2185 pMemory
= ComplexBufferSize(pStubMsg
, pMemory
, pFormat
, NULL
);
2188 /***********************************************************************
2189 * NdrComplexArrayMemorySize [RPCRT4.@]
2191 unsigned long WINAPI
NdrComplexArrayMemorySize(PMIDL_STUB_MESSAGE pStubMsg
,
2192 PFORMAT_STRING pFormat
)
2195 FIXME("(%p,%p): stub\n", pStubMsg
, pFormat
);
2199 pFormat
= ReadConformance(pStubMsg
, pFormat
);
2200 size
= pStubMsg
->MaxCount
;
2201 TRACE("conformance=%ld\n", size
);
2208 /***********************************************************************
2209 * NdrComplexArrayFree [RPCRT4.@]
2211 void WINAPI
NdrComplexArrayFree(PMIDL_STUB_MESSAGE pStubMsg
,
2212 unsigned char *pMemory
,
2213 PFORMAT_STRING pFormat
)
2215 DWORD size
= 0, count
, def
;
2216 TRACE("(%p,%p,%p)\n", pStubMsg
, pMemory
, pFormat
);
2218 def
= *(const WORD
*)&pFormat
[2];
2221 pFormat
= ComputeConformance(pStubMsg
, pMemory
, pFormat
, def
);
2222 size
= pStubMsg
->MaxCount
;
2223 TRACE("conformance=%ld\n", size
);
2225 if (*(const DWORD
*)pFormat
!= 0xffffffff)
2226 FIXME("compute variance\n");
2229 for (count
=0; count
<size
; count
++)
2230 pMemory
= ComplexFree(pStubMsg
, pMemory
, pFormat
, NULL
);
2233 unsigned long UserMarshalFlags(PMIDL_STUB_MESSAGE pStubMsg
)
2235 return MAKELONG(pStubMsg
->dwDestContext
,
2236 pStubMsg
->RpcMsg
->DataRepresentation
);
2239 /***********************************************************************
2240 * NdrUserMarshalMarshall [RPCRT4.@]
2242 unsigned char * WINAPI
NdrUserMarshalMarshall(PMIDL_STUB_MESSAGE pStubMsg
,
2243 unsigned char *pMemory
,
2244 PFORMAT_STRING pFormat
)
2246 /* unsigned flags = pFormat[1]; */
2247 unsigned index
= *(const WORD
*)&pFormat
[2];
2248 unsigned long uflag
= UserMarshalFlags(pStubMsg
);
2249 TRACE("(%p,%p,%p)\n", pStubMsg
, pMemory
, pFormat
);
2250 TRACE("index=%d\n", index
);
2253 pStubMsg
->StubDesc
->aUserMarshalQuadruple
[index
].pfnMarshall(
2254 &uflag
, pStubMsg
->Buffer
, pMemory
);
2256 STD_OVERFLOW_CHECK(pStubMsg
);
2261 /***********************************************************************
2262 * NdrUserMarshalUnmarshall [RPCRT4.@]
2264 unsigned char * WINAPI
NdrUserMarshalUnmarshall(PMIDL_STUB_MESSAGE pStubMsg
,
2265 unsigned char **ppMemory
,
2266 PFORMAT_STRING pFormat
,
2267 unsigned char fMustAlloc
)
2269 /* unsigned flags = pFormat[1];*/
2270 unsigned index
= *(const WORD
*)&pFormat
[2];
2271 DWORD memsize
= *(const WORD
*)&pFormat
[4];
2272 unsigned long uflag
= UserMarshalFlags(pStubMsg
);
2273 TRACE("(%p,%p,%p,%d)\n", pStubMsg
, ppMemory
, pFormat
, fMustAlloc
);
2274 TRACE("index=%d\n", index
);
2276 if (fMustAlloc
|| !*ppMemory
)
2277 *ppMemory
= NdrAllocate(pStubMsg
, memsize
);
2280 pStubMsg
->StubDesc
->aUserMarshalQuadruple
[index
].pfnUnmarshall(
2281 &uflag
, pStubMsg
->Buffer
, *ppMemory
);
2286 /***********************************************************************
2287 * NdrUserMarshalBufferSize [RPCRT4.@]
2289 void WINAPI
NdrUserMarshalBufferSize(PMIDL_STUB_MESSAGE pStubMsg
,
2290 unsigned char *pMemory
,
2291 PFORMAT_STRING pFormat
)
2293 /* unsigned flags = pFormat[1];*/
2294 unsigned index
= *(const WORD
*)&pFormat
[2];
2295 DWORD bufsize
= *(const WORD
*)&pFormat
[6];
2296 unsigned long uflag
= UserMarshalFlags(pStubMsg
);
2297 TRACE("(%p,%p,%p)\n", pStubMsg
, pMemory
, pFormat
);
2298 TRACE("index=%d\n", index
);
2301 TRACE("size=%ld\n", bufsize
);
2302 pStubMsg
->BufferLength
+= bufsize
;
2306 pStubMsg
->BufferLength
=
2307 pStubMsg
->StubDesc
->aUserMarshalQuadruple
[index
].pfnBufferSize(
2308 &uflag
, pStubMsg
->BufferLength
, pMemory
);
2311 /***********************************************************************
2312 * NdrUserMarshalMemorySize [RPCRT4.@]
2314 unsigned long WINAPI
NdrUserMarshalMemorySize(PMIDL_STUB_MESSAGE pStubMsg
,
2315 PFORMAT_STRING pFormat
)
2317 unsigned index
= *(const WORD
*)&pFormat
[2];
2318 /* DWORD memsize = *(const WORD*)&pFormat[4]; */
2319 FIXME("(%p,%p): stub\n", pStubMsg
, pFormat
);
2320 TRACE("index=%d\n", index
);
2325 /***********************************************************************
2326 * NdrUserMarshalFree [RPCRT4.@]
2328 void WINAPI
NdrUserMarshalFree(PMIDL_STUB_MESSAGE pStubMsg
,
2329 unsigned char *pMemory
,
2330 PFORMAT_STRING pFormat
)
2332 /* unsigned flags = pFormat[1]; */
2333 unsigned index
= *(const WORD
*)&pFormat
[2];
2334 unsigned long uflag
= UserMarshalFlags(pStubMsg
);
2335 TRACE("(%p,%p,%p)\n", pStubMsg
, pMemory
, pFormat
);
2336 TRACE("index=%d\n", index
);
2338 pStubMsg
->StubDesc
->aUserMarshalQuadruple
[index
].pfnFree(
2342 /***********************************************************************
2343 * NdrClearOutParameters [RPCRT4.@]
2345 void WINAPI
NdrClearOutParameters(PMIDL_STUB_MESSAGE pStubMsg
,
2346 PFORMAT_STRING pFormat
,
2349 FIXME("(%p,%p,%p): stub\n", pStubMsg
, pFormat
, ArgAddr
);
2352 /***********************************************************************
2353 * NdrConvert [RPCRT4.@]
2355 void WINAPI
NdrConvert( PMIDL_STUB_MESSAGE pStubMsg
, PFORMAT_STRING pFormat
)
2357 FIXME("(pStubMsg == ^%p, pFormat == ^%p): stub.\n", pStubMsg
, pFormat
);
2358 /* FIXME: since this stub doesn't do any converting, the proper behavior
2359 is to raise an exception */
2362 /***********************************************************************
2363 * NdrConvert2 [RPCRT4.@]
2365 void WINAPI
NdrConvert2( PMIDL_STUB_MESSAGE pStubMsg
, PFORMAT_STRING pFormat
, long NumberParams
)
2367 FIXME("(pStubMsg == ^%p, pFormat == ^%p, NumberParams == %ld): stub.\n",
2368 pStubMsg
, pFormat
, NumberParams
);
2369 /* FIXME: since this stub doesn't do any converting, the proper behavior
2370 is to raise an exception */
2373 typedef struct _NDR_CSTRUCT_FORMAT
2376 unsigned char alignment
;
2377 unsigned short memory_size
;
2378 short offset_to_array_description
;
2379 } NDR_CSTRUCT_FORMAT
;
2381 /***********************************************************************
2382 * NdrConformantStructMarshall [RPCRT4.@]
2384 unsigned char * WINAPI
NdrConformantStructMarshall(PMIDL_STUB_MESSAGE pStubMsg
,
2385 unsigned char *pMemory
,
2386 PFORMAT_STRING pFormat
)
2388 const NDR_CSTRUCT_FORMAT
* pCStructFormat
= (NDR_CSTRUCT_FORMAT
*)pFormat
;
2389 pFormat
+= sizeof(NDR_CSTRUCT_FORMAT
);
2391 TRACE("(%p, %p, %p)\n", pStubMsg
, pMemory
, pFormat
);
2393 if ((pCStructFormat
->type
!= RPC_FC_CPSTRUCT
) && (pCStructFormat
->type
!= RPC_FC_CSTRUCT
))
2395 ERR("invalid format type %x\n", pCStructFormat
->type
);
2396 RpcRaiseException(RPC_S_INTERNAL_ERROR
);
2400 TRACE("memory_size = %d\n", pCStructFormat
->memory_size
);
2402 /* copy constant sized part of struct */
2403 memcpy(pStubMsg
->Buffer
, pMemory
, pCStructFormat
->memory_size
);
2404 pStubMsg
->Buffer
+= pCStructFormat
->memory_size
;
2406 if (pCStructFormat
->offset_to_array_description
)
2408 PFORMAT_STRING pArrayFormat
= (unsigned char*)&pCStructFormat
->offset_to_array_description
+
2409 pCStructFormat
->offset_to_array_description
;
2410 NdrConformantArrayMarshall(pStubMsg
, pMemory
+ pCStructFormat
->memory_size
, pArrayFormat
);
2412 if (pCStructFormat
->type
== RPC_FC_CPSTRUCT
)
2413 EmbeddedPointerMarshall(pStubMsg
, pMemory
, pFormat
);
2417 /***********************************************************************
2418 * NdrConformantStructUnmarshall [RPCRT4.@]
2420 unsigned char * WINAPI
NdrConformantStructUnmarshall(PMIDL_STUB_MESSAGE pStubMsg
,
2421 unsigned char **ppMemory
,
2422 PFORMAT_STRING pFormat
,
2423 unsigned char fMustAlloc
)
2425 const NDR_CSTRUCT_FORMAT
* pCStructFormat
= (NDR_CSTRUCT_FORMAT
*)pFormat
;
2426 pFormat
+= sizeof(NDR_CSTRUCT_FORMAT
);
2428 TRACE("(%p, %p, %p, %d)\n", pStubMsg
, ppMemory
, pFormat
, fMustAlloc
);
2430 if ((pCStructFormat
->type
!= RPC_FC_CPSTRUCT
) && (pCStructFormat
->type
!= RPC_FC_CSTRUCT
))
2432 ERR("invalid format type %x\n", pCStructFormat
->type
);
2433 RpcRaiseException(RPC_S_INTERNAL_ERROR
);
2437 TRACE("memory_size = %d\n", pCStructFormat
->memory_size
);
2439 /* work out how much memory to allocate if we need to do so */
2440 if (!*ppMemory
|| fMustAlloc
)
2442 SIZE_T size
= pCStructFormat
->memory_size
;
2444 if (pCStructFormat
->offset_to_array_description
)
2446 unsigned char *buffer
;
2447 PFORMAT_STRING pArrayFormat
= (unsigned char*)&pCStructFormat
->offset_to_array_description
+
2448 pCStructFormat
->offset_to_array_description
;
2449 buffer
= pStubMsg
->Buffer
;
2450 pStubMsg
->Buffer
+= pCStructFormat
->memory_size
;
2451 size
+= NdrConformantArrayMemorySize(pStubMsg
, pArrayFormat
);
2452 pStubMsg
->Buffer
= buffer
;
2454 *ppMemory
= NdrAllocate(pStubMsg
, size
);
2457 /* now copy the data */
2458 memcpy(*ppMemory
, pStubMsg
->Buffer
, pCStructFormat
->memory_size
);
2459 pStubMsg
->Buffer
+= pCStructFormat
->memory_size
;
2460 if (pCStructFormat
->offset_to_array_description
)
2462 PFORMAT_STRING pArrayFormat
= (unsigned char*)&pCStructFormat
->offset_to_array_description
+
2463 pCStructFormat
->offset_to_array_description
;
2464 unsigned char *pMemoryArray
= *ppMemory
+ pCStructFormat
->memory_size
;
2465 /* note that we pass fMustAlloc as 0 as we have already allocated the
2467 NdrConformantArrayUnmarshall(pStubMsg
, &pMemoryArray
, pArrayFormat
, 0);
2469 if (pCStructFormat
->type
== RPC_FC_CPSTRUCT
)
2470 EmbeddedPointerUnmarshall(pStubMsg
, ppMemory
, pFormat
, fMustAlloc
);
2474 /***********************************************************************
2475 * NdrConformantStructBufferSize [RPCRT4.@]
2477 void WINAPI
NdrConformantStructBufferSize(PMIDL_STUB_MESSAGE pStubMsg
,
2478 unsigned char *pMemory
,
2479 PFORMAT_STRING pFormat
)
2481 const NDR_CSTRUCT_FORMAT
* pCStructFormat
= (NDR_CSTRUCT_FORMAT
*)pFormat
;
2482 pFormat
+= sizeof(NDR_CSTRUCT_FORMAT
);
2483 TRACE("(%p, %p, %p)\n", pStubMsg
, pMemory
, pFormat
);
2485 if ((pCStructFormat
->type
!= RPC_FC_CPSTRUCT
) && (pCStructFormat
->type
!= RPC_FC_CSTRUCT
))
2487 ERR("invalid format type %x\n", pCStructFormat
->type
);
2488 RpcRaiseException(RPC_S_INTERNAL_ERROR
);
2492 TRACE("memory_size = %d\n", pCStructFormat
->memory_size
);
2494 /* add constant sized part of struct to buffer size */
2495 pStubMsg
->BufferLength
+= pCStructFormat
->memory_size
;
2497 if (pCStructFormat
->offset_to_array_description
)
2499 PFORMAT_STRING pArrayFormat
= (unsigned char*)&pCStructFormat
->offset_to_array_description
+
2500 pCStructFormat
->offset_to_array_description
;
2501 NdrConformantArrayBufferSize(pStubMsg
, pMemory
+ pCStructFormat
->memory_size
, pArrayFormat
);
2503 if (pCStructFormat
->type
== RPC_FC_CPSTRUCT
)
2504 EmbeddedPointerBufferSize(pStubMsg
, pMemory
, pFormat
);
2507 /***********************************************************************
2508 * NdrConformantStructMemorySize [RPCRT4.@]
2510 unsigned long WINAPI
NdrConformantStructMemorySize(PMIDL_STUB_MESSAGE pStubMsg
,
2511 PFORMAT_STRING pFormat
)
2517 /***********************************************************************
2518 * NdrConformantStructFree [RPCRT4.@]
2520 void WINAPI
NdrConformantStructFree(PMIDL_STUB_MESSAGE pStubMsg
,
2521 unsigned char *pMemory
,
2522 PFORMAT_STRING pFormat
)
2527 /***********************************************************************
2528 * NdrConformantVaryingStructMarshall [RPCRT4.@]
2530 unsigned char * WINAPI
NdrConformantVaryingStructMarshall(PMIDL_STUB_MESSAGE pStubMsg
,
2531 unsigned char *pMemory
,
2532 PFORMAT_STRING pFormat
)
2538 /***********************************************************************
2539 * NdrConformantVaryingStructUnmarshall [RPCRT4.@]
2541 unsigned char * WINAPI
NdrConformantVaryingStructUnmarshall(PMIDL_STUB_MESSAGE pStubMsg
,
2542 unsigned char **ppMemory
,
2543 PFORMAT_STRING pFormat
,
2544 unsigned char fMustAlloc
)
2550 /***********************************************************************
2551 * NdrConformantVaryingStructBufferSize [RPCRT4.@]
2553 void WINAPI
NdrConformantVaryingStructBufferSize(PMIDL_STUB_MESSAGE pStubMsg
,
2554 unsigned char *pMemory
,
2555 PFORMAT_STRING pFormat
)
2560 /***********************************************************************
2561 * NdrConformantVaryingStructMemorySize [RPCRT4.@]
2563 unsigned long WINAPI
NdrConformantVaryingStructMemorySize(PMIDL_STUB_MESSAGE pStubMsg
,
2564 PFORMAT_STRING pFormat
)
2570 /***********************************************************************
2571 * NdrConformantVaryingStructFree [RPCRT4.@]
2573 void WINAPI
NdrConformantVaryingStructFree(PMIDL_STUB_MESSAGE pStubMsg
,
2574 unsigned char *pMemory
,
2575 PFORMAT_STRING pFormat
)
2580 /***********************************************************************
2581 * NdrFixedArrayMarshall [RPCRT4.@]
2583 unsigned char * WINAPI
NdrFixedArrayMarshall(PMIDL_STUB_MESSAGE pStubMsg
,
2584 unsigned char *pMemory
,
2585 PFORMAT_STRING pFormat
)
2591 /***********************************************************************
2592 * NdrFixedArrayUnmarshall [RPCRT4.@]
2594 unsigned char * WINAPI
NdrFixedArrayUnmarshall(PMIDL_STUB_MESSAGE pStubMsg
,
2595 unsigned char **ppMemory
,
2596 PFORMAT_STRING pFormat
,
2597 unsigned char fMustAlloc
)
2603 /***********************************************************************
2604 * NdrFixedArrayBufferSize [RPCRT4.@]
2606 void WINAPI
NdrFixedArrayBufferSize(PMIDL_STUB_MESSAGE pStubMsg
,
2607 unsigned char *pMemory
,
2608 PFORMAT_STRING pFormat
)
2613 /***********************************************************************
2614 * NdrFixedArrayMemorySize [RPCRT4.@]
2616 unsigned long WINAPI
NdrFixedArrayMemorySize(PMIDL_STUB_MESSAGE pStubMsg
,
2617 PFORMAT_STRING pFormat
)
2623 /***********************************************************************
2624 * NdrFixedArrayFree [RPCRT4.@]
2626 void WINAPI
NdrFixedArrayFree(PMIDL_STUB_MESSAGE pStubMsg
,
2627 unsigned char *pMemory
,
2628 PFORMAT_STRING pFormat
)
2633 /***********************************************************************
2634 * NdrVaryingArrayMarshall [RPCRT4.@]
2636 unsigned char * WINAPI
NdrVaryingArrayMarshall(PMIDL_STUB_MESSAGE pStubMsg
,
2637 unsigned char *pMemory
,
2638 PFORMAT_STRING pFormat
)
2644 /***********************************************************************
2645 * NdrVaryingArrayUnmarshall [RPCRT4.@]
2647 unsigned char * WINAPI
NdrVaryingArrayUnmarshall(PMIDL_STUB_MESSAGE pStubMsg
,
2648 unsigned char **ppMemory
,
2649 PFORMAT_STRING pFormat
,
2650 unsigned char fMustAlloc
)
2656 /***********************************************************************
2657 * NdrVaryingArrayBufferSize [RPCRT4.@]
2659 void WINAPI
NdrVaryingArrayBufferSize(PMIDL_STUB_MESSAGE pStubMsg
,
2660 unsigned char *pMemory
,
2661 PFORMAT_STRING pFormat
)
2666 /***********************************************************************
2667 * NdrVaryingArrayMemorySize [RPCRT4.@]
2669 unsigned long WINAPI
NdrVaryingArrayMemorySize(PMIDL_STUB_MESSAGE pStubMsg
,
2670 PFORMAT_STRING pFormat
)
2676 /***********************************************************************
2677 * NdrVaryingArrayFree [RPCRT4.@]
2679 void WINAPI
NdrVaryingArrayFree(PMIDL_STUB_MESSAGE pStubMsg
,
2680 unsigned char *pMemory
,
2681 PFORMAT_STRING pFormat
)
2686 /***********************************************************************
2687 * NdrEncapsulatedUnionMarshall [RPCRT4.@]
2689 unsigned char * WINAPI
NdrEncapsulatedUnionMarshall(PMIDL_STUB_MESSAGE pStubMsg
,
2690 unsigned char *pMemory
,
2691 PFORMAT_STRING pFormat
)
2697 /***********************************************************************
2698 * NdrEncapsulatedUnionUnmarshall [RPCRT4.@]
2700 unsigned char * WINAPI
NdrEncapsulatedUnionUnmarshall(PMIDL_STUB_MESSAGE pStubMsg
,
2701 unsigned char **ppMemory
,
2702 PFORMAT_STRING pFormat
,
2703 unsigned char fMustAlloc
)
2709 /***********************************************************************
2710 * NdrEncapsulatedUnionBufferSize [RPCRT4.@]
2712 void WINAPI
NdrEncapsulatedUnionBufferSize(PMIDL_STUB_MESSAGE pStubMsg
,
2713 unsigned char *pMemory
,
2714 PFORMAT_STRING pFormat
)
2719 /***********************************************************************
2720 * NdrEncapsulatedUnionMemorySize [RPCRT4.@]
2722 unsigned long WINAPI
NdrEncapsulatedUnionMemorySize(PMIDL_STUB_MESSAGE pStubMsg
,
2723 PFORMAT_STRING pFormat
)
2729 /***********************************************************************
2730 * NdrEncapsulatedUnionFree [RPCRT4.@]
2732 void WINAPI
NdrEncapsulatedUnionFree(PMIDL_STUB_MESSAGE pStubMsg
,
2733 unsigned char *pMemory
,
2734 PFORMAT_STRING pFormat
)
2739 /***********************************************************************
2740 * NdrNonEncapsulatedUnionMarshall [RPCRT4.@]
2742 unsigned char * WINAPI
NdrNonEncapsulatedUnionMarshall(PMIDL_STUB_MESSAGE pStubMsg
,
2743 unsigned char *pMemory
,
2744 PFORMAT_STRING pFormat
)
2750 /***********************************************************************
2751 * NdrNonEncapsulatedUnionUnmarshall [RPCRT4.@]
2753 unsigned char * WINAPI
NdrNonEncapsulatedUnionUnmarshall(PMIDL_STUB_MESSAGE pStubMsg
,
2754 unsigned char **ppMemory
,
2755 PFORMAT_STRING pFormat
,
2756 unsigned char fMustAlloc
)
2762 /***********************************************************************
2763 * NdrNonEncapsulatedUnionBufferSize [RPCRT4.@]
2765 void WINAPI
NdrNonEncapsulatedUnionBufferSize(PMIDL_STUB_MESSAGE pStubMsg
,
2766 unsigned char *pMemory
,
2767 PFORMAT_STRING pFormat
)
2772 /***********************************************************************
2773 * NdrNonEncapsulatedUnionMemorySize [RPCRT4.@]
2775 unsigned long WINAPI
NdrNonEncapsulatedUnionMemorySize(PMIDL_STUB_MESSAGE pStubMsg
,
2776 PFORMAT_STRING pFormat
)
2782 /***********************************************************************
2783 * NdrNonEncapsulatedUnionFree [RPCRT4.@]
2785 void WINAPI
NdrNonEncapsulatedUnionFree(PMIDL_STUB_MESSAGE pStubMsg
,
2786 unsigned char *pMemory
,
2787 PFORMAT_STRING pFormat
)
2792 /***********************************************************************
2793 * NdrByteCountPointerMarshall [RPCRT4.@]
2795 unsigned char * WINAPI
NdrByteCountPointerMarshall(PMIDL_STUB_MESSAGE pStubMsg
,
2796 unsigned char *pMemory
,
2797 PFORMAT_STRING pFormat
)
2803 /***********************************************************************
2804 * NdrByteCountPointerUnmarshall [RPCRT4.@]
2806 unsigned char * WINAPI
NdrByteCountPointerUnmarshall(PMIDL_STUB_MESSAGE pStubMsg
,
2807 unsigned char **ppMemory
,
2808 PFORMAT_STRING pFormat
,
2809 unsigned char fMustAlloc
)
2815 /***********************************************************************
2816 * NdrByteCountPointerBufferSize [RPCRT4.@]
2818 void WINAPI
NdrByteCountPointerBufferSize(PMIDL_STUB_MESSAGE pStubMsg
,
2819 unsigned char *pMemory
,
2820 PFORMAT_STRING pFormat
)
2825 /***********************************************************************
2826 * NdrByteCountPointerMemorySize [RPCRT4.@]
2828 unsigned long WINAPI
NdrByteCountPointerMemorySize(PMIDL_STUB_MESSAGE pStubMsg
,
2829 PFORMAT_STRING pFormat
)
2835 /***********************************************************************
2836 * NdrByteCountPointerFree [RPCRT4.@]
2838 void WINAPI
NdrByteCountPointerFree(PMIDL_STUB_MESSAGE pStubMsg
,
2839 unsigned char *pMemory
,
2840 PFORMAT_STRING pFormat
)
2845 /***********************************************************************
2846 * NdrXmitOrRepAsMarshall [RPCRT4.@]
2848 unsigned char * WINAPI
NdrXmitOrRepAsMarshall(PMIDL_STUB_MESSAGE pStubMsg
,
2849 unsigned char *pMemory
,
2850 PFORMAT_STRING pFormat
)
2856 /***********************************************************************
2857 * NdrXmitOrRepAsUnmarshall [RPCRT4.@]
2859 unsigned char * WINAPI
NdrXmitOrRepAsUnmarshall(PMIDL_STUB_MESSAGE pStubMsg
,
2860 unsigned char **ppMemory
,
2861 PFORMAT_STRING pFormat
,
2862 unsigned char fMustAlloc
)
2868 /***********************************************************************
2869 * NdrXmitOrRepAsBufferSize [RPCRT4.@]
2871 void WINAPI
NdrXmitOrRepAsBufferSize(PMIDL_STUB_MESSAGE pStubMsg
,
2872 unsigned char *pMemory
,
2873 PFORMAT_STRING pFormat
)
2878 /***********************************************************************
2879 * NdrXmitOrRepAsMemorySize [RPCRT4.@]
2881 unsigned long WINAPI
NdrXmitOrRepAsMemorySize(PMIDL_STUB_MESSAGE pStubMsg
,
2882 PFORMAT_STRING pFormat
)
2888 /***********************************************************************
2889 * NdrXmitOrRepAsFree [RPCRT4.@]
2891 void WINAPI
NdrXmitOrRepAsFree(PMIDL_STUB_MESSAGE pStubMsg
,
2892 unsigned char *pMemory
,
2893 PFORMAT_STRING pFormat
)
2898 /***********************************************************************
2899 * NdrBaseTypeMarshall [internal]
2901 static unsigned char *WINAPI
NdrBaseTypeMarshall(
2902 PMIDL_STUB_MESSAGE pStubMsg
,
2903 unsigned char *pMemory
,
2904 PFORMAT_STRING pFormat
)
2906 TRACE("pStubMsg %p, pMemory %p, type 0x%02x\n", pStubMsg
, pMemory
, *pFormat
);
2914 *(UCHAR
*)pStubMsg
->Buffer
= *(UCHAR
*)pMemory
;
2915 pStubMsg
->Buffer
+= sizeof(UCHAR
);
2916 TRACE("value: 0x%02x\n", *(UCHAR
*)pMemory
);
2921 ALIGN_POINTER(pStubMsg
->Buffer
, sizeof(USHORT
) - 1);
2922 *(USHORT
*)pStubMsg
->Buffer
= *(USHORT
*)pMemory
;
2923 pStubMsg
->Buffer
+= sizeof(USHORT
);
2924 TRACE("value: 0x%04x\n", *(USHORT
*)pMemory
);
2928 case RPC_FC_ERROR_STATUS_T
:
2929 ALIGN_POINTER(pStubMsg
->Buffer
, sizeof(ULONG
) - 1);
2930 *(ULONG
*)pStubMsg
->Buffer
= *(ULONG
*)pMemory
;
2931 pStubMsg
->Buffer
+= sizeof(ULONG
);
2932 TRACE("value: 0x%08lx\n", *(ULONG
*)pMemory
);
2935 ALIGN_POINTER(pStubMsg
->Buffer
, sizeof(float) - 1);
2936 *(float *)pStubMsg
->Buffer
= *(float *)pMemory
;
2937 pStubMsg
->Buffer
+= sizeof(float);
2940 ALIGN_POINTER(pStubMsg
->Buffer
, sizeof(double) - 1);
2941 *(double *)pStubMsg
->Buffer
= *(double *)pMemory
;
2942 pStubMsg
->Buffer
+= sizeof(double);
2945 ALIGN_POINTER(pStubMsg
->Buffer
, sizeof(ULONGLONG
) - 1);
2946 *(ULONGLONG
*)pStubMsg
->Buffer
= *(ULONGLONG
*)pMemory
;
2947 pStubMsg
->Buffer
+= sizeof(ULONGLONG
);
2948 TRACE("value: %s\n", wine_dbgstr_longlong(*(ULONGLONG
*)pMemory
));
2953 FIXME("Unhandled base type: 0x%02x\n", *pFormat
);
2956 STD_OVERFLOW_CHECK(pStubMsg
);
2958 /* FIXME: what is the correct return value? */
2962 /***********************************************************************
2963 * NdrBaseTypeUnmarshall [internal]
2965 static unsigned char *WINAPI
NdrBaseTypeUnmarshall(
2966 PMIDL_STUB_MESSAGE pStubMsg
,
2967 unsigned char **ppMemory
,
2968 PFORMAT_STRING pFormat
,
2969 unsigned char fMustAlloc
)
2971 TRACE("pStubMsg: %p, ppMemory: %p, type: 0x%02x, fMustAlloc: %s\n", pStubMsg
, ppMemory
, *pFormat
, fMustAlloc
? "true" : "false");
2973 if (fMustAlloc
|| !*ppMemory
)
2974 *ppMemory
= NdrAllocate(pStubMsg
, NdrBaseTypeMemorySize(pStubMsg
, pFormat
));
2976 TRACE("*ppMemory: %p\n", *ppMemory
);
2984 **(UCHAR
**)ppMemory
= *(UCHAR
*)pStubMsg
->Buffer
;
2985 pStubMsg
->Buffer
+= sizeof(UCHAR
);
2986 TRACE("value: 0x%02x\n", **(UCHAR
**)ppMemory
);
2991 ALIGN_POINTER(pStubMsg
->Buffer
, sizeof(USHORT
) - 1);
2992 **(USHORT
**)ppMemory
= *(USHORT
*)pStubMsg
->Buffer
;
2993 pStubMsg
->Buffer
+= sizeof(USHORT
);
2994 TRACE("value: 0x%04x\n", **(USHORT
**)ppMemory
);
2998 case RPC_FC_ERROR_STATUS_T
:
2999 ALIGN_POINTER(pStubMsg
->Buffer
, sizeof(ULONG
) - 1);
3000 **(ULONG
**)ppMemory
= *(ULONG
*)pStubMsg
->Buffer
;
3001 pStubMsg
->Buffer
+= sizeof(ULONG
);
3002 TRACE("value: 0x%08lx\n", **(ULONG
**)ppMemory
);
3005 ALIGN_POINTER(pStubMsg
->Buffer
, sizeof(float) - 1);
3006 **(float **)ppMemory
= *(float *)pStubMsg
->Buffer
;
3007 pStubMsg
->Buffer
+= sizeof(float);
3008 TRACE("value: %f\n", **(float **)ppMemory
);
3011 ALIGN_POINTER(pStubMsg
->Buffer
, sizeof(double) - 1);
3012 **(double **)ppMemory
= *(double*)pStubMsg
->Buffer
;
3013 pStubMsg
->Buffer
+= sizeof(double);
3014 TRACE("value: %f\n", **(double **)ppMemory
);
3017 ALIGN_POINTER(pStubMsg
->Buffer
, sizeof(ULONGLONG
) - 1);
3018 **(ULONGLONG
**)ppMemory
= *(ULONGLONG
*)pStubMsg
->Buffer
;
3019 pStubMsg
->Buffer
+= sizeof(ULONGLONG
);
3020 TRACE("value: %s\n", wine_dbgstr_longlong(**(ULONGLONG
**)ppMemory
));
3025 FIXME("Unhandled base type: 0x%02x\n", *pFormat
);
3028 /* FIXME: what is the correct return value? */
3033 /***********************************************************************
3034 * NdrBaseTypeBufferSize [internal]
3036 static void WINAPI
NdrBaseTypeBufferSize(
3037 PMIDL_STUB_MESSAGE pStubMsg
,
3038 unsigned char *pMemory
,
3039 PFORMAT_STRING pFormat
)
3041 TRACE("pStubMsg %p, pMemory %p, type 0x%02x\n", pStubMsg
, pMemory
, *pFormat
);
3049 pStubMsg
->BufferLength
+= sizeof(UCHAR
);
3054 ALIGN_LENGTH(pStubMsg
->BufferLength
, sizeof(USHORT
) - 1);
3055 pStubMsg
->BufferLength
+= sizeof(USHORT
);
3059 ALIGN_LENGTH(pStubMsg
->BufferLength
, sizeof(ULONG
) - 1);
3060 pStubMsg
->BufferLength
+= sizeof(ULONG
);
3063 ALIGN_LENGTH(pStubMsg
->BufferLength
, sizeof(float) - 1);
3064 pStubMsg
->BufferLength
+= sizeof(float);
3067 ALIGN_LENGTH(pStubMsg
->BufferLength
, sizeof(double) - 1);
3068 pStubMsg
->BufferLength
+= sizeof(double);
3071 ALIGN_LENGTH(pStubMsg
->BufferLength
, sizeof(ULONGLONG
) - 1);
3072 pStubMsg
->BufferLength
+= sizeof(ULONGLONG
);
3074 case RPC_FC_ERROR_STATUS_T
:
3075 ALIGN_LENGTH(pStubMsg
->BufferLength
, sizeof(error_status_t
) - 1);
3076 pStubMsg
->BufferLength
+= sizeof(error_status_t
);
3081 FIXME("Unhandled base type: 0x%02x\n", *pFormat
);
3085 /***********************************************************************
3086 * NdrBaseTypeMemorySize [internal]
3088 static unsigned long WINAPI
NdrBaseTypeMemorySize(
3089 PMIDL_STUB_MESSAGE pStubMsg
,
3090 PFORMAT_STRING pFormat
)
3098 return sizeof(UCHAR
);
3102 return sizeof(USHORT
);
3105 return sizeof(ULONG
);
3107 return sizeof(float);
3109 return sizeof(double);
3111 return sizeof(ULONGLONG
);
3112 case RPC_FC_ERROR_STATUS_T
:
3113 return sizeof(error_status_t
);
3117 FIXME("Unhandled base type: 0x%02x\n", *pFormat
);
3122 /***********************************************************************
3123 * NdrBaseTypeFree [internal]
3125 static void WINAPI
NdrBaseTypeFree(PMIDL_STUB_MESSAGE pStubMsg
,
3126 unsigned char *pMemory
,
3127 PFORMAT_STRING pFormat
)
3129 TRACE("pStubMsg %p pMemory %p type 0x%02x\n", pStubMsg
, pMemory
, *pFormat
);
3134 /***********************************************************************
3135 * NdrClientContextMarshall
3137 void WINAPI
NdrClientContextMarshall(PMIDL_STUB_MESSAGE pStubMsg
,
3138 NDR_CCONTEXT ContextHandle
,
3141 FIXME("(%p, %p, %d): stub\n", pStubMsg
, ContextHandle
, fCheck
);
3144 /***********************************************************************
3145 * NdrClientContextUnmarshall
3147 void WINAPI
NdrClientContextUnmarshall(PMIDL_STUB_MESSAGE pStubMsg
,
3148 NDR_CCONTEXT
* pContextHandle
,
3149 RPC_BINDING_HANDLE BindHandle
)
3151 FIXME("(%p, %p, %p): stub\n", pStubMsg
, pContextHandle
, BindHandle
);
3154 void WINAPI
NdrServerContextMarshall(PMIDL_STUB_MESSAGE pStubMsg
,
3155 NDR_SCONTEXT ContextHandle
,
3156 NDR_RUNDOWN RundownRoutine
)
3158 FIXME("(%p, %p, %p): stub\n", pStubMsg
, ContextHandle
, RundownRoutine
);
3161 NDR_SCONTEXT WINAPI
NdrServerContextUnmarshall(PMIDL_STUB_MESSAGE pStubMsg
)
3163 FIXME("(%p): stub\n", pStubMsg
);
3167 void WINAPI
NdrContextHandleSize(PMIDL_STUB_MESSAGE pStubMsg
,
3168 unsigned char* pMemory
,
3169 PFORMAT_STRING pFormat
)
3171 FIXME("(%p, %p, %p): stub\n", pStubMsg
, pMemory
, pFormat
);
3174 NDR_SCONTEXT WINAPI
NdrContextHandleInitialize(PMIDL_STUB_MESSAGE pStubMsg
,
3175 PFORMAT_STRING pFormat
)
3177 FIXME("(%p, %p): stub\n", pStubMsg
, pFormat
);
3181 void WINAPI
NdrServerContextNewMarshall(PMIDL_STUB_MESSAGE pStubMsg
,
3182 NDR_SCONTEXT ContextHandle
,
3183 NDR_RUNDOWN RundownRoutine
,
3184 PFORMAT_STRING pFormat
)
3186 FIXME("(%p, %p, %p, %p): stub\n", pStubMsg
, ContextHandle
, RundownRoutine
, pFormat
);
3189 NDR_SCONTEXT WINAPI
NdrServerContextNewUnmarshall(PMIDL_STUB_MESSAGE pStubMsg
,
3190 PFORMAT_STRING pFormat
)
3192 FIXME("(%p, %p): stub\n", pStubMsg
, pFormat
);
3196 RPC_BINDING_HANDLE WINAPI
NDRCContextBinding(NDR_CCONTEXT CContext
)
3198 FIXME("(%p): stub\n", CContext
);