4 * Copyright 2002 Greg Turner
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 * - figure out whether we *really* got this right
22 * - check for errors and throw exceptions
39 #include "wine/unicode.h"
40 #include "wine/rpcfc.h"
42 #include "wine/debug.h"
44 WINE_DEFAULT_DEBUG_CHANNEL(ole
);
46 #define BUFFER_PARANOIA 20
49 # define LITTLE_ENDIAN_UINT32_WRITE(pchar, uint32) \
50 (*((UINT32 *)(pchar)) = (uint32))
52 # define LITTLE_ENDIAN_UINT32_READ(pchar) \
53 (*((UINT32 *)(pchar)))
55 /* these would work for i386 too, but less efficient */
56 # define LITTLE_ENDIAN_UINT32_WRITE(pchar, uint32) \
57 (*(pchar) = LOBYTE(LOWORD(uint32)), \
58 *((pchar)+1) = HIBYTE(LOWORD(uint32)), \
59 *((pchar)+2) = LOBYTE(HIWORD(uint32)), \
60 *((pchar)+3) = HIBYTE(HIWORD(uint32)), \
61 (uint32)) /* allow as r-value */
63 # define LITTLE_ENDIAN_UINT32_READ(pchar) \
65 MAKEWORD(*(pchar), *((pchar)+1)), \
66 MAKEWORD(*((pchar)+2), *((pchar)+3))))
69 #define BIG_ENDIAN_UINT32_WRITE(pchar, uint32) \
70 (*((pchar)+3) = LOBYTE(LOWORD(uint32)), \
71 *((pchar)+2) = HIBYTE(LOWORD(uint32)), \
72 *((pchar)+1) = LOBYTE(HIWORD(uint32)), \
73 *(pchar) = HIBYTE(HIWORD(uint32)), \
74 (uint32)) /* allow as r-value */
76 #define BIG_ENDIAN_UINT32_READ(pchar) \
78 MAKEWORD(*((pchar)+3), *((pchar)+2)), \
79 MAKEWORD(*((pchar)+1), *(pchar))))
81 #ifdef NDR_LOCAL_IS_BIG_ENDIAN
82 # define NDR_LOCAL_UINT32_WRITE(pchar, uint32) \
83 BIG_ENDIAN_UINT32_WRITE(pchar, uint32)
84 # define NDR_LOCAL_UINT32_READ(pchar) \
85 BIG_ENDIAN_UINT32_READ(pchar)
87 # define NDR_LOCAL_UINT32_WRITE(pchar, uint32) \
88 LITTLE_ENDIAN_UINT32_WRITE(pchar, uint32)
89 # define NDR_LOCAL_UINT32_READ(pchar) \
90 LITTLE_ENDIAN_UINT32_READ(pchar)
93 /* _Align must be the desired alignment minus 1,
94 * e.g. ALIGN_LENGTH(len, 3) to align on a dword boundary. */
95 #define ALIGNED_LENGTH(_Len, _Align) (((_Len)+(_Align))&~(_Align))
96 #define ALIGNED_POINTER(_Ptr, _Align) ((LPVOID)ALIGNED_LENGTH((ULONG_PTR)(_Ptr), _Align))
97 #define ALIGN_LENGTH(_Len, _Align) _Len = ALIGNED_LENGTH(_Len, _Align)
98 #define ALIGN_POINTER(_Ptr, _Align) _Ptr = ALIGNED_POINTER(_Ptr, _Align)
100 #define STD_OVERFLOW_CHECK(_Msg) do { \
101 TRACE("buffer=%d/%ld\n", _Msg->Buffer - (unsigned char *)_Msg->RpcMsg->Buffer, _Msg->BufferLength); \
102 if (_Msg->Buffer > (unsigned char *)_Msg->RpcMsg->Buffer + _Msg->BufferLength) \
103 ERR("buffer overflow %d bytes\n", _Msg->Buffer - ((unsigned char *)_Msg->RpcMsg->Buffer + _Msg->BufferLength)); \
106 #define NDR_TABLE_SIZE 128
107 #define NDR_TABLE_MASK 127
109 static unsigned char *WINAPI
NdrBaseTypeMarshall(PMIDL_STUB_MESSAGE
, unsigned char *, PFORMAT_STRING
);
110 static unsigned char *WINAPI
NdrBaseTypeUnmarshall(PMIDL_STUB_MESSAGE
, unsigned char **, PFORMAT_STRING
, unsigned char);
111 static void WINAPI
NdrBaseTypeBufferSize(PMIDL_STUB_MESSAGE
, unsigned char *, PFORMAT_STRING
);
112 static void WINAPI
NdrBaseTypeFree(PMIDL_STUB_MESSAGE
, unsigned char *, PFORMAT_STRING
);
113 static unsigned long WINAPI
NdrBaseTypeMemorySize(PMIDL_STUB_MESSAGE
, PFORMAT_STRING
);
115 const NDR_MARSHALL NdrMarshaller
[NDR_TABLE_SIZE
] = {
117 NdrBaseTypeMarshall
, NdrBaseTypeMarshall
, NdrBaseTypeMarshall
,
118 NdrBaseTypeMarshall
, NdrBaseTypeMarshall
, NdrBaseTypeMarshall
, NdrBaseTypeMarshall
,
119 NdrBaseTypeMarshall
, NdrBaseTypeMarshall
, NdrBaseTypeMarshall
, NdrBaseTypeMarshall
,
120 NdrBaseTypeMarshall
, NdrBaseTypeMarshall
, NdrBaseTypeMarshall
, NdrBaseTypeMarshall
,
124 NdrPointerMarshall
, NdrPointerMarshall
,
125 NdrPointerMarshall
, NdrPointerMarshall
,
127 NdrSimpleStructMarshall
, NdrSimpleStructMarshall
,
128 NdrConformantStructMarshall
, NdrConformantStructMarshall
,
129 NdrConformantVaryingStructMarshall
,
130 NdrComplexStructMarshall
,
132 NdrConformantArrayMarshall
,
133 NdrConformantVaryingArrayMarshall
,
134 NdrFixedArrayMarshall
, NdrFixedArrayMarshall
,
135 NdrVaryingArrayMarshall
, NdrVaryingArrayMarshall
,
136 NdrComplexArrayMarshall
,
138 NdrConformantStringMarshall
, 0, 0,
139 NdrConformantStringMarshall
,
140 NdrNonConformantStringMarshall
, 0, 0, 0,
142 NdrEncapsulatedUnionMarshall
,
143 NdrNonEncapsulatedUnionMarshall
,
145 NdrXmitOrRepAsMarshall
, NdrXmitOrRepAsMarshall
,
147 NdrInterfacePointerMarshall
,
150 NdrUserMarshalMarshall
152 const NDR_UNMARSHALL NdrUnmarshaller
[NDR_TABLE_SIZE
] = {
154 NdrBaseTypeUnmarshall
, NdrBaseTypeUnmarshall
, NdrBaseTypeUnmarshall
,
155 NdrBaseTypeUnmarshall
, NdrBaseTypeUnmarshall
, NdrBaseTypeUnmarshall
, NdrBaseTypeUnmarshall
,
156 NdrBaseTypeUnmarshall
, NdrBaseTypeUnmarshall
, NdrBaseTypeUnmarshall
, NdrBaseTypeUnmarshall
,
157 NdrBaseTypeUnmarshall
, NdrBaseTypeUnmarshall
, NdrBaseTypeUnmarshall
, NdrBaseTypeUnmarshall
,
159 NdrBaseTypeUnmarshall
,
161 NdrPointerUnmarshall
, NdrPointerUnmarshall
,
162 NdrPointerUnmarshall
, NdrPointerUnmarshall
,
164 NdrSimpleStructUnmarshall
, NdrSimpleStructUnmarshall
,
165 NdrConformantStructUnmarshall
, NdrConformantStructUnmarshall
,
166 NdrConformantVaryingStructUnmarshall
,
167 NdrComplexStructUnmarshall
,
169 NdrConformantArrayUnmarshall
,
170 NdrConformantVaryingArrayUnmarshall
,
171 NdrFixedArrayUnmarshall
, NdrFixedArrayUnmarshall
,
172 NdrVaryingArrayUnmarshall
, NdrVaryingArrayUnmarshall
,
173 NdrComplexArrayUnmarshall
,
175 NdrConformantStringUnmarshall
, 0, 0,
176 NdrConformantStringUnmarshall
,
177 NdrNonConformantStringUnmarshall
, 0, 0, 0,
179 NdrEncapsulatedUnionUnmarshall
,
180 NdrNonEncapsulatedUnionUnmarshall
,
182 NdrXmitOrRepAsUnmarshall
, NdrXmitOrRepAsUnmarshall
,
184 NdrInterfacePointerUnmarshall
,
187 NdrUserMarshalUnmarshall
189 const NDR_BUFFERSIZE NdrBufferSizer
[NDR_TABLE_SIZE
] = {
191 NdrBaseTypeBufferSize
, NdrBaseTypeBufferSize
, NdrBaseTypeBufferSize
,
192 NdrBaseTypeBufferSize
, NdrBaseTypeBufferSize
, NdrBaseTypeBufferSize
, NdrBaseTypeBufferSize
,
193 NdrBaseTypeBufferSize
, NdrBaseTypeBufferSize
, NdrBaseTypeBufferSize
, NdrBaseTypeBufferSize
,
194 NdrBaseTypeBufferSize
, NdrBaseTypeBufferSize
, NdrBaseTypeBufferSize
, NdrBaseTypeBufferSize
,
196 NdrBaseTypeBufferSize
,
198 NdrPointerBufferSize
, NdrPointerBufferSize
,
199 NdrPointerBufferSize
, NdrPointerBufferSize
,
201 NdrSimpleStructBufferSize
, NdrSimpleStructBufferSize
,
202 NdrConformantStructBufferSize
, NdrConformantStructBufferSize
,
203 NdrConformantVaryingStructBufferSize
,
204 NdrComplexStructBufferSize
,
206 NdrConformantArrayBufferSize
,
207 NdrConformantVaryingArrayBufferSize
,
208 NdrFixedArrayBufferSize
, NdrFixedArrayBufferSize
,
209 NdrVaryingArrayBufferSize
, NdrVaryingArrayBufferSize
,
210 NdrComplexArrayBufferSize
,
212 NdrConformantStringBufferSize
, 0, 0,
213 NdrConformantStringBufferSize
,
214 NdrNonConformantStringBufferSize
, 0, 0, 0,
216 NdrEncapsulatedUnionBufferSize
,
217 NdrNonEncapsulatedUnionBufferSize
,
219 NdrXmitOrRepAsBufferSize
, NdrXmitOrRepAsBufferSize
,
221 NdrInterfacePointerBufferSize
,
224 NdrUserMarshalBufferSize
226 const NDR_MEMORYSIZE NdrMemorySizer
[NDR_TABLE_SIZE
] = {
228 NdrBaseTypeMemorySize
, NdrBaseTypeMemorySize
, NdrBaseTypeMemorySize
,
229 NdrBaseTypeMemorySize
, NdrBaseTypeMemorySize
, NdrBaseTypeMemorySize
, NdrBaseTypeMemorySize
,
230 NdrBaseTypeMemorySize
, NdrBaseTypeMemorySize
, NdrBaseTypeMemorySize
, NdrBaseTypeMemorySize
,
231 NdrBaseTypeMemorySize
, NdrBaseTypeMemorySize
, NdrBaseTypeMemorySize
, NdrBaseTypeMemorySize
,
233 NdrBaseTypeMemorySize
,
235 NdrPointerMemorySize
, NdrPointerMemorySize
,
236 NdrPointerMemorySize
, NdrPointerMemorySize
,
238 NdrSimpleStructMemorySize
, NdrSimpleStructMemorySize
,
240 NdrComplexStructMemorySize
,
242 NdrConformantArrayMemorySize
, 0, 0, 0, 0, 0,
243 NdrComplexArrayMemorySize
,
245 NdrConformantStringMemorySize
, 0, 0,
246 NdrConformantStringMemorySize
,
247 NdrNonConformantStringMemorySize
, 0, 0, 0,
251 NdrInterfacePointerMemorySize
,
254 NdrUserMarshalMemorySize
256 const NDR_FREE NdrFreer
[NDR_TABLE_SIZE
] = {
258 NdrBaseTypeFree
, NdrBaseTypeFree
, NdrBaseTypeFree
,
259 NdrBaseTypeFree
, NdrBaseTypeFree
, NdrBaseTypeFree
, NdrBaseTypeFree
,
260 NdrBaseTypeFree
, NdrBaseTypeFree
, NdrBaseTypeFree
, NdrBaseTypeFree
,
261 NdrBaseTypeFree
, NdrBaseTypeFree
, NdrBaseTypeFree
, NdrBaseTypeFree
,
265 NdrPointerFree
, NdrPointerFree
,
266 NdrPointerFree
, NdrPointerFree
,
268 NdrSimpleStructFree
, NdrSimpleStructFree
,
269 NdrConformantStructFree
, NdrConformantStructFree
,
270 NdrConformantVaryingStructFree
,
271 NdrComplexStructFree
,
273 NdrConformantArrayFree
,
274 NdrConformantVaryingArrayFree
,
275 NdrFixedArrayFree
, NdrFixedArrayFree
,
276 NdrVaryingArrayFree
, NdrVaryingArrayFree
,
282 NdrEncapsulatedUnionFree
,
283 NdrNonEncapsulatedUnionFree
,
285 NdrXmitOrRepAsFree
, NdrXmitOrRepAsFree
,
287 NdrInterfacePointerFree
,
293 void * WINAPI
NdrAllocate(MIDL_STUB_MESSAGE
*pStubMsg
, size_t len
)
295 /* hmm, this is probably supposed to do more? */
296 return pStubMsg
->pfnAllocate(len
);
299 static void WINAPI
NdrFree(MIDL_STUB_MESSAGE
*pStubMsg
, unsigned char *Pointer
)
301 pStubMsg
->pfnFree(Pointer
);
304 static inline BOOL
IsConformanceOrVariancePresent(PFORMAT_STRING pFormat
)
306 return (*(const ULONG
*)pFormat
!= -1);
309 PFORMAT_STRING
ReadConformance(MIDL_STUB_MESSAGE
*pStubMsg
, PFORMAT_STRING pFormat
)
311 pStubMsg
->MaxCount
= NDR_LOCAL_UINT32_READ(pStubMsg
->Buffer
);
312 pStubMsg
->Buffer
+= 4;
313 TRACE("unmarshalled conformance is %ld\n", pStubMsg
->MaxCount
);
314 if (pStubMsg
->fHasNewCorrDesc
)
320 static inline PFORMAT_STRING
ReadVariance(MIDL_STUB_MESSAGE
*pStubMsg
, PFORMAT_STRING pFormat
)
322 if (!IsConformanceOrVariancePresent(pFormat
))
324 pStubMsg
->Offset
= 0;
325 pStubMsg
->ActualCount
= pStubMsg
->MaxCount
;
329 pStubMsg
->Offset
= NDR_LOCAL_UINT32_READ(pStubMsg
->Buffer
);
330 pStubMsg
->Buffer
+= 4;
331 TRACE("offset is %ld\n", pStubMsg
->Offset
);
332 pStubMsg
->ActualCount
= NDR_LOCAL_UINT32_READ(pStubMsg
->Buffer
);
333 pStubMsg
->Buffer
+= 4;
334 TRACE("variance is %ld\n", pStubMsg
->ActualCount
);
337 if (pStubMsg
->fHasNewCorrDesc
)
343 PFORMAT_STRING
ComputeConformanceOrVariance(
344 MIDL_STUB_MESSAGE
*pStubMsg
, unsigned char *pMemory
,
345 PFORMAT_STRING pFormat
, ULONG_PTR def
, ULONG
*pCount
)
347 BYTE dtype
= pFormat
[0] & 0xf;
348 short ofs
= *(short *)&pFormat
[2];
352 if (!IsConformanceOrVariancePresent(pFormat
)) {
353 /* null descriptor */
358 switch (pFormat
[0] & 0xf0) {
359 case RPC_FC_NORMAL_CONFORMANCE
:
360 TRACE("normal conformance, ofs=%d\n", ofs
);
363 case RPC_FC_POINTER_CONFORMANCE
:
364 TRACE("pointer conformance, ofs=%d\n", ofs
);
365 ptr
= pStubMsg
->Memory
+ ofs
;
367 case RPC_FC_TOP_LEVEL_CONFORMANCE
:
368 TRACE("toplevel conformance, ofs=%d\n", ofs
);
369 if (pStubMsg
->StackTop
) {
370 ptr
= pStubMsg
->StackTop
+ ofs
;
373 /* -Os mode, *pCount is already set */
377 case RPC_FC_CONSTANT_CONFORMANCE
:
378 data
= ofs
| ((DWORD
)pFormat
[1] << 16);
379 TRACE("constant conformance, val=%ld\n", data
);
382 case RPC_FC_TOP_LEVEL_MULTID_CONFORMANCE
:
383 FIXME("toplevel multidimensional conformance, ofs=%d\n", ofs
);
384 if (pStubMsg
->StackTop
) {
385 ptr
= pStubMsg
->StackTop
+ ofs
;
393 FIXME("unknown conformance type %x\n", pFormat
[0] & 0xf0);
396 switch (pFormat
[1]) {
397 case RPC_FC_DEREFERENCE
:
400 case RPC_FC_CALLBACK
:
402 unsigned char *old_stack_top
= pStubMsg
->StackTop
;
403 pStubMsg
->StackTop
= ptr
;
405 /* ofs is index into StubDesc->apfnExprEval */
406 TRACE("callback conformance into apfnExprEval[%d]\n", ofs
);
407 pStubMsg
->StubDesc
->apfnExprEval
[ofs
](pStubMsg
);
409 pStubMsg
->StackTop
= old_stack_top
;
425 data
= *(USHORT
*)ptr
;
434 FIXME("unknown conformance data type %x\n", dtype
);
437 TRACE("dereferenced data type %x at %p, got %ld\n", dtype
, ptr
, data
);
440 switch (pFormat
[1]) {
444 case RPC_FC_DEREFERENCE
:
445 /* already handled */
448 FIXME("unknown conformance op %d\n", pFormat
[1]);
453 TRACE("resulting conformance is %ld\n", *pCount
);
454 if (pStubMsg
->fHasNewCorrDesc
)
462 * NdrConformantString:
464 * What MS calls a ConformantString is, in DCE terminology,
465 * a Varying-Conformant String.
467 * maxlen: DWORD (max # of CHARTYPE characters, inclusive of '\0')
468 * offset: DWORD (actual string data begins at (offset) CHARTYPE's
469 * into unmarshalled string)
470 * length: DWORD (# of CHARTYPE characters, inclusive of '\0')
472 * data: CHARTYPE[maxlen]
474 * ], where CHARTYPE is the appropriate character type (specified externally)
478 /***********************************************************************
479 * NdrConformantStringMarshall [RPCRT4.@]
481 unsigned char *WINAPI
NdrConformantStringMarshall(MIDL_STUB_MESSAGE
*pStubMsg
,
482 unsigned char *pszMessage
, PFORMAT_STRING pFormat
)
484 unsigned long len
, esize
;
487 TRACE("(pStubMsg == ^%p, pszMessage == ^%p, pFormat == ^%p)\n", pStubMsg
, pszMessage
, pFormat
);
490 if (*pFormat
== RPC_FC_C_CSTRING
) {
491 TRACE("string=%s\n", debugstr_a((char*)pszMessage
));
492 len
= strlen((char*)pszMessage
)+1;
495 else if (*pFormat
== RPC_FC_C_WSTRING
) {
496 TRACE("string=%s\n", debugstr_w((LPWSTR
)pszMessage
));
497 len
= strlenW((LPWSTR
)pszMessage
)+1;
501 ERR("Unhandled string type: %#x\n", *pFormat
);
502 /* FIXME: raise an exception. */
506 if (pFormat
[1] != RPC_FC_PAD
) {
507 FIXME("sized string format=%d\n", pFormat
[1]);
510 assert( (pStubMsg
->BufferLength
>= (len
*esize
+ 13)) && (pStubMsg
->Buffer
!= NULL
) );
512 c
= pStubMsg
->Buffer
;
514 NDR_LOCAL_UINT32_WRITE(c
, len
); /* max length: strlen + 1 (for '\0') */
515 c
+= 8; /* offset: 0 */
516 NDR_LOCAL_UINT32_WRITE(c
, len
); /* actual length: (same) */
518 memcpy(c
, pszMessage
, len
*esize
); /* the string itself */
520 pStubMsg
->Buffer
= c
;
522 STD_OVERFLOW_CHECK(pStubMsg
);
525 return NULL
; /* is this always right? */
528 /***********************************************************************
529 * NdrConformantStringBufferSize [RPCRT4.@]
531 void WINAPI
NdrConformantStringBufferSize(PMIDL_STUB_MESSAGE pStubMsg
,
532 unsigned char* pMemory
, PFORMAT_STRING pFormat
)
534 TRACE("(pStubMsg == ^%p, pMemory == ^%p, pFormat == ^%p)\n", pStubMsg
, pMemory
, pFormat
);
537 if (*pFormat
== RPC_FC_C_CSTRING
) {
538 /* we need 12 octets for the [maxlen, offset, len] DWORDS, + 1 octet for '\0' */
539 TRACE("string=%s\n", debugstr_a((char*)pMemory
));
540 pStubMsg
->BufferLength
+= strlen((char*)pMemory
) + 13 + BUFFER_PARANOIA
;
542 else if (*pFormat
== RPC_FC_C_WSTRING
) {
543 /* we need 12 octets for the [maxlen, offset, len] DWORDS, + 2 octets for L'\0' */
544 TRACE("string=%s\n", debugstr_w((LPWSTR
)pMemory
));
545 pStubMsg
->BufferLength
+= strlenW((LPWSTR
)pMemory
)*2 + 14 + BUFFER_PARANOIA
;
548 ERR("Unhandled string type: %#x\n", *pFormat
);
549 /* FIXME: raise an exception */
552 if (pFormat
[1] != RPC_FC_PAD
) {
553 FIXME("sized string format=%d\n", pFormat
[1]);
557 /************************************************************************
558 * NdrConformantStringMemorySize [RPCRT4.@]
560 unsigned long WINAPI
NdrConformantStringMemorySize( PMIDL_STUB_MESSAGE pStubMsg
,
561 PFORMAT_STRING pFormat
)
563 unsigned long rslt
= 0;
565 TRACE("(pStubMsg == ^%p, pFormat == ^%p)\n", pStubMsg
, pFormat
);
567 assert(pStubMsg
&& pFormat
);
569 if (*pFormat
== RPC_FC_C_CSTRING
) {
570 rslt
= NDR_LOCAL_UINT32_READ(pStubMsg
->Buffer
); /* maxlen */
572 else if (*pFormat
== RPC_FC_C_WSTRING
) {
573 rslt
= NDR_LOCAL_UINT32_READ(pStubMsg
->Buffer
)*2; /* maxlen */
576 ERR("Unhandled string type: %#x\n", *pFormat
);
577 /* FIXME: raise an exception */
580 if (pFormat
[1] != RPC_FC_PAD
) {
581 FIXME("sized string format=%d\n", pFormat
[1]);
584 TRACE(" --> %lu\n", rslt
);
588 /************************************************************************
589 * NdrConformantStringUnmarshall [RPCRT4.@]
591 unsigned char *WINAPI
NdrConformantStringUnmarshall( PMIDL_STUB_MESSAGE pStubMsg
,
592 unsigned char** ppMemory
, PFORMAT_STRING pFormat
, unsigned char fMustAlloc
)
594 unsigned long len
, esize
, ofs
;
596 TRACE("(pStubMsg == ^%p, *pMemory == ^%p, pFormat == ^%p, fMustAlloc == %u)\n",
597 pStubMsg
, *ppMemory
, pFormat
, fMustAlloc
);
599 assert(pFormat
&& ppMemory
&& pStubMsg
);
601 pStubMsg
->Buffer
+= 4;
602 ofs
= NDR_LOCAL_UINT32_READ(pStubMsg
->Buffer
);
603 pStubMsg
->Buffer
+= 4;
604 len
= NDR_LOCAL_UINT32_READ(pStubMsg
->Buffer
);
605 pStubMsg
->Buffer
+= 4;
607 if (*pFormat
== RPC_FC_C_CSTRING
) esize
= 1;
608 else if (*pFormat
== RPC_FC_C_WSTRING
) esize
= 2;
610 ERR("Unhandled string type: %#x\n", *pFormat
);
611 /* FIXME: raise an exception */
615 if (pFormat
[1] != RPC_FC_PAD
) {
616 FIXME("sized string format=%d\n", pFormat
[1]);
619 if (fMustAlloc
|| !*ppMemory
)
620 *ppMemory
= NdrAllocate(pStubMsg
, len
*esize
+ BUFFER_PARANOIA
);
622 memcpy(*ppMemory
, pStubMsg
->Buffer
, len
*esize
);
624 pStubMsg
->Buffer
+= len
*esize
;
626 if (*pFormat
== RPC_FC_C_CSTRING
) {
627 TRACE("string=%s\n", debugstr_a((char*)*ppMemory
));
629 else if (*pFormat
== RPC_FC_C_WSTRING
) {
630 TRACE("string=%s\n", debugstr_w((LPWSTR
)*ppMemory
));
633 return NULL
; /* FIXME: is this always right? */
636 /***********************************************************************
637 * NdrNonConformantStringMarshall [RPCRT4.@]
639 unsigned char * WINAPI
NdrNonConformantStringMarshall(PMIDL_STUB_MESSAGE pStubMsg
,
640 unsigned char *pMemory
,
641 PFORMAT_STRING pFormat
)
647 /***********************************************************************
648 * NdrNonConformantStringUnmarshall [RPCRT4.@]
650 unsigned char * WINAPI
NdrNonConformantStringUnmarshall(PMIDL_STUB_MESSAGE pStubMsg
,
651 unsigned char **ppMemory
,
652 PFORMAT_STRING pFormat
,
653 unsigned char fMustAlloc
)
659 /***********************************************************************
660 * NdrNonConformantStringBufferSize [RPCRT4.@]
662 void WINAPI
NdrNonConformantStringBufferSize(PMIDL_STUB_MESSAGE pStubMsg
,
663 unsigned char *pMemory
,
664 PFORMAT_STRING pFormat
)
669 /***********************************************************************
670 * NdrNonConformantStringMemorySize [RPCRT4.@]
672 unsigned long WINAPI
NdrNonConformantStringMemorySize(PMIDL_STUB_MESSAGE pStubMsg
,
673 PFORMAT_STRING pFormat
)
679 static inline void dump_pointer_attr(unsigned char attr
)
681 if (attr
& RPC_FC_P_ALLOCALLNODES
)
682 TRACE(" RPC_FC_P_ALLOCALLNODES");
683 if (attr
& RPC_FC_P_DONTFREE
)
684 TRACE(" RPC_FC_P_DONTFREE");
685 if (attr
& RPC_FC_P_ONSTACK
)
686 TRACE(" RPC_FC_P_ONSTACK");
687 if (attr
& RPC_FC_P_SIMPLEPOINTER
)
688 TRACE(" RPC_FC_P_SIMPLEPOINTER");
689 if (attr
& RPC_FC_P_DEREF
)
690 TRACE(" RPC_FC_P_DEREF");
694 /***********************************************************************
697 void WINAPI
PointerMarshall(PMIDL_STUB_MESSAGE pStubMsg
,
698 unsigned char *Buffer
,
699 unsigned char *Pointer
,
700 PFORMAT_STRING pFormat
)
702 unsigned type
= pFormat
[0], attr
= pFormat
[1];
706 TRACE("(%p,%p,%p,%p)\n", pStubMsg
, Buffer
, Pointer
, pFormat
);
707 TRACE("type=0x%x, attr=", type
); dump_pointer_attr(attr
);
709 if (attr
& RPC_FC_P_SIMPLEPOINTER
) desc
= pFormat
;
710 else desc
= pFormat
+ *(const SHORT
*)pFormat
;
711 if (attr
& RPC_FC_P_DEREF
) {
712 Pointer
= *(unsigned char**)Pointer
;
713 TRACE("deref => %p\n", Pointer
);
717 case RPC_FC_RP
: /* ref pointer (always non-null) */
718 #if 0 /* this causes problems for InstallShield so is disabled - we need more tests */
720 RpcRaiseException(RPC_X_NULL_REF_POINTER
);
723 case RPC_FC_UP
: /* unique pointer */
724 case RPC_FC_OP
: /* object pointer - same as unique here */
725 TRACE("writing %p to buffer\n", Pointer
);
726 NDR_LOCAL_UINT32_WRITE(pStubMsg
->Buffer
, (unsigned long)Pointer
);
727 pStubMsg
->Buffer
+= 4;
731 FIXME("unhandled ptr type=%02x\n", type
);
732 RpcRaiseException(RPC_X_BAD_STUB_DATA
);
735 TRACE("calling marshaller for type 0x%x\n", (int)*desc
);
738 m
= NdrMarshaller
[*desc
& NDR_TABLE_MASK
];
739 if (m
) m(pStubMsg
, Pointer
, desc
);
740 else FIXME("no marshaller for data type=%02x\n", *desc
);
743 STD_OVERFLOW_CHECK(pStubMsg
);
746 /***********************************************************************
749 void WINAPI
PointerUnmarshall(PMIDL_STUB_MESSAGE pStubMsg
,
750 unsigned char *Buffer
,
751 unsigned char **pPointer
,
752 PFORMAT_STRING pFormat
,
753 unsigned char fMustAlloc
)
755 unsigned type
= pFormat
[0], attr
= pFormat
[1];
758 DWORD pointer_id
= 0;
760 TRACE("(%p,%p,%p,%p,%d)\n", pStubMsg
, Buffer
, pPointer
, pFormat
, fMustAlloc
);
761 TRACE("type=0x%x, attr=", type
); dump_pointer_attr(attr
);
763 if (attr
& RPC_FC_P_SIMPLEPOINTER
) desc
= pFormat
;
764 else desc
= pFormat
+ *(const SHORT
*)pFormat
;
765 if (attr
& RPC_FC_P_DEREF
) {
766 pPointer
= *(unsigned char***)pPointer
;
767 TRACE("deref => %p\n", pPointer
);
771 case RPC_FC_RP
: /* ref pointer (always non-null) */
774 case RPC_FC_UP
: /* unique pointer */
775 pointer_id
= NDR_LOCAL_UINT32_READ(pStubMsg
->Buffer
);
776 pStubMsg
->Buffer
+= 4;
778 case RPC_FC_OP
: /* object pointer - we must free data before overwriting it */
779 pointer_id
= NDR_LOCAL_UINT32_READ(pStubMsg
->Buffer
);
780 pStubMsg
->Buffer
+= 4;
782 FIXME("free object pointer %p\n", *pPointer
);
786 FIXME("unhandled ptr type=%02x\n", type
);
787 RpcRaiseException(RPC_X_BAD_STUB_DATA
);
791 m
= NdrUnmarshaller
[*desc
& NDR_TABLE_MASK
];
792 if (m
) m(pStubMsg
, pPointer
, desc
, fMustAlloc
);
793 else FIXME("no unmarshaller for data type=%02x\n", *desc
);
796 TRACE("pointer=%p\n", *pPointer
);
799 /***********************************************************************
802 void WINAPI
PointerBufferSize(PMIDL_STUB_MESSAGE pStubMsg
,
803 unsigned char *Pointer
,
804 PFORMAT_STRING pFormat
)
806 unsigned type
= pFormat
[0], attr
= pFormat
[1];
810 TRACE("(%p,%p,%p)\n", pStubMsg
, Pointer
, pFormat
);
811 TRACE("type=%d, attr=%d\n", type
, attr
);
813 if (attr
& RPC_FC_P_SIMPLEPOINTER
) desc
= pFormat
;
814 else desc
= pFormat
+ *(const SHORT
*)pFormat
;
815 if (attr
& RPC_FC_P_DEREF
) {
816 Pointer
= *(unsigned char**)Pointer
;
817 TRACE("deref => %p\n", Pointer
);
821 case RPC_FC_RP
: /* ref pointer (always non-null) */
825 pStubMsg
->BufferLength
+= 4;
826 /* NULL pointer has no further representation */
832 FIXME("unhandled ptr type=%02x\n", type
);
833 RpcRaiseException(RPC_X_BAD_STUB_DATA
);
836 m
= NdrBufferSizer
[*desc
& NDR_TABLE_MASK
];
837 if (m
) m(pStubMsg
, Pointer
, desc
);
838 else FIXME("no buffersizer for data type=%02x\n", *desc
);
841 /***********************************************************************
842 * PointerMemorySize [RPCRT4.@]
844 unsigned long WINAPI
PointerMemorySize(PMIDL_STUB_MESSAGE pStubMsg
,
845 unsigned char *Buffer
,
846 PFORMAT_STRING pFormat
)
848 unsigned type
= pFormat
[0], attr
= pFormat
[1];
852 FIXME("(%p,%p,%p): stub\n", pStubMsg
, Buffer
, pFormat
);
853 TRACE("type=%d, attr=", type
); dump_pointer_attr(attr
);
855 if (attr
& RPC_FC_P_SIMPLEPOINTER
) desc
= pFormat
;
856 else desc
= pFormat
+ *(const SHORT
*)pFormat
;
857 if (attr
& RPC_FC_P_DEREF
) {
862 case RPC_FC_RP
: /* ref pointer (always non-null) */
865 FIXME("unhandled ptr type=%02x\n", type
);
866 RpcRaiseException(RPC_X_BAD_STUB_DATA
);
869 m
= NdrMemorySizer
[*desc
& NDR_TABLE_MASK
];
870 if (m
) m(pStubMsg
, desc
);
871 else FIXME("no memorysizer for data type=%02x\n", *desc
);
876 /***********************************************************************
877 * PointerFree [RPCRT4.@]
879 void WINAPI
PointerFree(PMIDL_STUB_MESSAGE pStubMsg
,
880 unsigned char *Pointer
,
881 PFORMAT_STRING pFormat
)
883 unsigned type
= pFormat
[0], attr
= pFormat
[1];
887 TRACE("(%p,%p,%p)\n", pStubMsg
, Pointer
, pFormat
);
888 TRACE("type=%d, attr=", type
); dump_pointer_attr(attr
);
889 if (attr
& RPC_FC_P_DONTFREE
) return;
891 if (attr
& RPC_FC_P_SIMPLEPOINTER
) desc
= pFormat
;
892 else desc
= pFormat
+ *(const SHORT
*)pFormat
;
893 if (attr
& RPC_FC_P_DEREF
) {
894 Pointer
= *(unsigned char**)Pointer
;
895 TRACE("deref => %p\n", Pointer
);
898 if (!Pointer
) return;
900 m
= NdrFreer
[*desc
& NDR_TABLE_MASK
];
901 if (m
) m(pStubMsg
, Pointer
, desc
);
903 /* hmm... is this sensible?
904 * perhaps we should check if the memory comes from NdrAllocate,
905 * and deallocate only if so - checking if the pointer is between
906 * BufferStart and BufferEnd is probably no good since the buffer
907 * may be reallocated when the server wants to marshal the reply */
909 case RPC_FC_BOGUS_STRUCT
:
910 case RPC_FC_BOGUS_ARRAY
:
911 case RPC_FC_USER_MARSHAL
:
914 FIXME("unhandled data type=%02x\n", *desc
);
916 case RPC_FC_C_CSTRING
:
917 case RPC_FC_C_WSTRING
:
918 if (pStubMsg
->ReuseBuffer
) goto notfree
;
924 if (attr
& RPC_FC_P_ONSTACK
) {
925 TRACE("not freeing stack ptr %p\n", Pointer
);
928 TRACE("freeing %p\n", Pointer
);
929 NdrFree(pStubMsg
, Pointer
);
932 TRACE("not freeing %p\n", Pointer
);
935 /***********************************************************************
936 * EmbeddedPointerMarshall
938 unsigned char * WINAPI
EmbeddedPointerMarshall(PMIDL_STUB_MESSAGE pStubMsg
,
939 unsigned char *pMemory
,
940 PFORMAT_STRING pFormat
)
942 unsigned char *Mark
= pStubMsg
->BufferMark
;
943 unsigned long Offset
= pStubMsg
->Offset
;
944 unsigned ofs
, rep
, count
, stride
, xofs
;
946 TRACE("(%p,%p,%p)\n", pStubMsg
, pMemory
, pFormat
);
948 if (*pFormat
!= RPC_FC_PP
) return NULL
;
951 while (pFormat
[0] != RPC_FC_END
) {
952 switch (pFormat
[0]) {
954 FIXME("unknown repeat type %d\n", pFormat
[0]);
955 case RPC_FC_NO_REPEAT
:
963 case RPC_FC_FIXED_REPEAT
:
964 rep
= *(const WORD
*)&pFormat
[2];
965 stride
= *(const WORD
*)&pFormat
[4];
966 ofs
= *(const WORD
*)&pFormat
[6];
967 count
= *(const WORD
*)&pFormat
[8];
971 case RPC_FC_VARIABLE_REPEAT
:
972 rep
= pStubMsg
->MaxCount
;
973 stride
= *(const WORD
*)&pFormat
[2];
974 ofs
= *(const WORD
*)&pFormat
[4];
975 count
= *(const WORD
*)&pFormat
[6];
976 xofs
= (pFormat
[1] == RPC_FC_VARIABLE_OFFSET
) ? Offset
* stride
: 0;
980 /* ofs doesn't seem to matter in this context */
982 PFORMAT_STRING info
= pFormat
;
983 unsigned char *membase
= pMemory
+ xofs
;
985 for (u
=0; u
<count
; u
++,info
+=8) {
986 unsigned char *memptr
= membase
+ *(const SHORT
*)&info
[0];
987 unsigned char *bufptr
= Mark
+ *(const SHORT
*)&info
[2];
988 PointerMarshall(pStubMsg
, bufptr
, *(unsigned char**)memptr
, info
+4);
992 pFormat
+= 8 * count
;
995 STD_OVERFLOW_CHECK(pStubMsg
);
1000 /***********************************************************************
1001 * EmbeddedPointerUnmarshall
1003 unsigned char * WINAPI
EmbeddedPointerUnmarshall(PMIDL_STUB_MESSAGE pStubMsg
,
1004 unsigned char **ppMemory
,
1005 PFORMAT_STRING pFormat
,
1006 unsigned char fMustAlloc
)
1008 unsigned char *Mark
= pStubMsg
->BufferMark
;
1009 unsigned long Offset
= pStubMsg
->Offset
;
1010 unsigned ofs
, rep
, count
, stride
, xofs
;
1012 TRACE("(%p,%p,%p,%d)\n", pStubMsg
, ppMemory
, pFormat
, fMustAlloc
);
1014 if (*pFormat
!= RPC_FC_PP
) return NULL
;
1017 while (pFormat
[0] != RPC_FC_END
) {
1018 switch (pFormat
[0]) {
1020 FIXME("unknown repeat type %d\n", pFormat
[0]);
1021 case RPC_FC_NO_REPEAT
:
1029 case RPC_FC_FIXED_REPEAT
:
1030 rep
= *(const WORD
*)&pFormat
[2];
1031 stride
= *(const WORD
*)&pFormat
[4];
1032 ofs
= *(const WORD
*)&pFormat
[6];
1033 count
= *(const WORD
*)&pFormat
[8];
1037 case RPC_FC_VARIABLE_REPEAT
:
1038 rep
= pStubMsg
->MaxCount
;
1039 stride
= *(const WORD
*)&pFormat
[2];
1040 ofs
= *(const WORD
*)&pFormat
[4];
1041 count
= *(const WORD
*)&pFormat
[6];
1042 xofs
= (pFormat
[1] == RPC_FC_VARIABLE_OFFSET
) ? Offset
* stride
: 0;
1046 /* ofs doesn't seem to matter in this context */
1048 PFORMAT_STRING info
= pFormat
;
1049 unsigned char *membase
= *ppMemory
+ xofs
;
1051 for (u
=0; u
<count
; u
++,info
+=8) {
1052 unsigned char *memptr
= membase
+ *(const SHORT
*)&info
[0];
1053 unsigned char *bufptr
= Mark
+ *(const SHORT
*)&info
[2];
1054 PointerUnmarshall(pStubMsg
, bufptr
, (unsigned char**)memptr
, info
+4, fMustAlloc
);
1058 pFormat
+= 8 * count
;
1064 /***********************************************************************
1065 * EmbeddedPointerBufferSize
1067 void WINAPI
EmbeddedPointerBufferSize(PMIDL_STUB_MESSAGE pStubMsg
,
1068 unsigned char *pMemory
,
1069 PFORMAT_STRING pFormat
)
1071 unsigned long Offset
= pStubMsg
->Offset
;
1072 unsigned ofs
, rep
, count
, stride
, xofs
;
1074 TRACE("(%p,%p,%p)\n", pStubMsg
, pMemory
, pFormat
);
1075 if (*pFormat
!= RPC_FC_PP
) return;
1078 while (pFormat
[0] != RPC_FC_END
) {
1079 switch (pFormat
[0]) {
1081 FIXME("unknown repeat type %d\n", pFormat
[0]);
1082 case RPC_FC_NO_REPEAT
:
1090 case RPC_FC_FIXED_REPEAT
:
1091 rep
= *(const WORD
*)&pFormat
[2];
1092 stride
= *(const WORD
*)&pFormat
[4];
1093 ofs
= *(const WORD
*)&pFormat
[6];
1094 count
= *(const WORD
*)&pFormat
[8];
1098 case RPC_FC_VARIABLE_REPEAT
:
1099 rep
= pStubMsg
->MaxCount
;
1100 stride
= *(const WORD
*)&pFormat
[2];
1101 ofs
= *(const WORD
*)&pFormat
[4];
1102 count
= *(const WORD
*)&pFormat
[6];
1103 xofs
= (pFormat
[1] == RPC_FC_VARIABLE_OFFSET
) ? Offset
* stride
: 0;
1107 /* ofs doesn't seem to matter in this context */
1109 PFORMAT_STRING info
= pFormat
;
1110 unsigned char *membase
= pMemory
+ xofs
;
1112 for (u
=0; u
<count
; u
++,info
+=8) {
1113 unsigned char *memptr
= membase
+ *(const SHORT
*)&info
[0];
1114 PointerBufferSize(pStubMsg
, *(unsigned char**)memptr
, info
+4);
1118 pFormat
+= 8 * count
;
1122 /***********************************************************************
1123 * EmbeddedPointerMemorySize
1125 unsigned long WINAPI
EmbeddedPointerMemorySize(PMIDL_STUB_MESSAGE pStubMsg
,
1126 PFORMAT_STRING pFormat
)
1128 unsigned long Offset
= pStubMsg
->Offset
;
1129 unsigned char *Mark
= pStubMsg
->BufferMark
;
1130 unsigned ofs
, rep
, count
, stride
, xofs
;
1132 FIXME("(%p,%p): stub\n", pStubMsg
, pFormat
);
1133 if (*pFormat
!= RPC_FC_PP
) return 0;
1136 while (pFormat
[0] != RPC_FC_END
) {
1137 switch (pFormat
[0]) {
1139 FIXME("unknown repeat type %d\n", pFormat
[0]);
1140 case RPC_FC_NO_REPEAT
:
1148 case RPC_FC_FIXED_REPEAT
:
1149 rep
= *(const WORD
*)&pFormat
[2];
1150 stride
= *(const WORD
*)&pFormat
[4];
1151 ofs
= *(const WORD
*)&pFormat
[6];
1152 count
= *(const WORD
*)&pFormat
[8];
1156 case RPC_FC_VARIABLE_REPEAT
:
1157 rep
= pStubMsg
->MaxCount
;
1158 stride
= *(const WORD
*)&pFormat
[2];
1159 ofs
= *(const WORD
*)&pFormat
[4];
1160 count
= *(const WORD
*)&pFormat
[6];
1161 xofs
= (pFormat
[1] == RPC_FC_VARIABLE_OFFSET
) ? Offset
* stride
: 0;
1165 /* ofs doesn't seem to matter in this context */
1167 PFORMAT_STRING info
= pFormat
;
1169 for (u
=0; u
<count
; u
++,info
+=8) {
1170 unsigned char *bufptr
= Mark
+ *(const SHORT
*)&info
[2];
1171 PointerMemorySize(pStubMsg
, bufptr
, info
+4);
1175 pFormat
+= 8 * count
;
1181 /***********************************************************************
1182 * EmbeddedPointerFree
1184 void WINAPI
EmbeddedPointerFree(PMIDL_STUB_MESSAGE pStubMsg
,
1185 unsigned char *pMemory
,
1186 PFORMAT_STRING pFormat
)
1188 unsigned long Offset
= pStubMsg
->Offset
;
1189 unsigned ofs
, rep
, count
, stride
, xofs
;
1191 TRACE("(%p,%p,%p)\n", pStubMsg
, pMemory
, pFormat
);
1192 if (*pFormat
!= RPC_FC_PP
) return;
1195 while (pFormat
[0] != RPC_FC_END
) {
1196 switch (pFormat
[0]) {
1198 FIXME("unknown repeat type %d\n", pFormat
[0]);
1199 case RPC_FC_NO_REPEAT
:
1207 case RPC_FC_FIXED_REPEAT
:
1208 rep
= *(const WORD
*)&pFormat
[2];
1209 stride
= *(const WORD
*)&pFormat
[4];
1210 ofs
= *(const WORD
*)&pFormat
[6];
1211 count
= *(const WORD
*)&pFormat
[8];
1215 case RPC_FC_VARIABLE_REPEAT
:
1216 rep
= pStubMsg
->MaxCount
;
1217 stride
= *(const WORD
*)&pFormat
[2];
1218 ofs
= *(const WORD
*)&pFormat
[4];
1219 count
= *(const WORD
*)&pFormat
[6];
1220 xofs
= (pFormat
[1] == RPC_FC_VARIABLE_OFFSET
) ? Offset
* stride
: 0;
1224 /* ofs doesn't seem to matter in this context */
1226 PFORMAT_STRING info
= pFormat
;
1227 unsigned char *membase
= pMemory
+ xofs
;
1229 for (u
=0; u
<count
; u
++,info
+=8) {
1230 unsigned char *memptr
= membase
+ *(const SHORT
*)&info
[0];
1231 PointerFree(pStubMsg
, *(unsigned char**)memptr
, info
+4);
1235 pFormat
+= 8 * count
;
1239 /***********************************************************************
1240 * NdrPointerMarshall [RPCRT4.@]
1242 unsigned char * WINAPI
NdrPointerMarshall(PMIDL_STUB_MESSAGE pStubMsg
,
1243 unsigned char *pMemory
,
1244 PFORMAT_STRING pFormat
)
1246 TRACE("(%p,%p,%p)\n", pStubMsg
, pMemory
, pFormat
);
1248 pStubMsg
->BufferMark
= pStubMsg
->Buffer
;
1249 PointerMarshall(pStubMsg
, pStubMsg
->Buffer
, pMemory
, pFormat
);
1251 STD_OVERFLOW_CHECK(pStubMsg
);
1256 /***********************************************************************
1257 * NdrPointerUnmarshall [RPCRT4.@]
1259 unsigned char * WINAPI
NdrPointerUnmarshall(PMIDL_STUB_MESSAGE pStubMsg
,
1260 unsigned char **ppMemory
,
1261 PFORMAT_STRING pFormat
,
1262 unsigned char fMustAlloc
)
1264 TRACE("(%p,%p,%p,%d)\n", pStubMsg
, ppMemory
, pFormat
, fMustAlloc
);
1266 pStubMsg
->BufferMark
= pStubMsg
->Buffer
;
1267 PointerUnmarshall(pStubMsg
, pStubMsg
->Buffer
, ppMemory
, pFormat
, fMustAlloc
);
1272 /***********************************************************************
1273 * NdrPointerBufferSize [RPCRT4.@]
1275 void WINAPI
NdrPointerBufferSize(PMIDL_STUB_MESSAGE pStubMsg
,
1276 unsigned char *pMemory
,
1277 PFORMAT_STRING pFormat
)
1279 TRACE("(%p,%p,%p)\n", pStubMsg
, pMemory
, pFormat
);
1280 PointerBufferSize(pStubMsg
, pMemory
, pFormat
);
1283 /***********************************************************************
1284 * NdrPointerMemorySize [RPCRT4.@]
1286 unsigned long WINAPI
NdrPointerMemorySize(PMIDL_STUB_MESSAGE pStubMsg
,
1287 PFORMAT_STRING pFormat
)
1289 /* unsigned size = *(LPWORD)(pFormat+2); */
1290 FIXME("(%p,%p): stub\n", pStubMsg
, pFormat
);
1291 PointerMemorySize(pStubMsg
, pStubMsg
->Buffer
, pFormat
);
1295 /***********************************************************************
1296 * NdrPointerFree [RPCRT4.@]
1298 void WINAPI
NdrPointerFree(PMIDL_STUB_MESSAGE pStubMsg
,
1299 unsigned char *pMemory
,
1300 PFORMAT_STRING pFormat
)
1302 TRACE("(%p,%p,%p)\n", pStubMsg
, pMemory
, pFormat
);
1303 PointerFree(pStubMsg
, pMemory
, pFormat
);
1306 /***********************************************************************
1307 * NdrSimpleStructMarshall [RPCRT4.@]
1309 unsigned char * WINAPI
NdrSimpleStructMarshall(PMIDL_STUB_MESSAGE pStubMsg
,
1310 unsigned char *pMemory
,
1311 PFORMAT_STRING pFormat
)
1313 unsigned size
= *(const WORD
*)(pFormat
+2);
1314 TRACE("(%p,%p,%p)\n", pStubMsg
, pMemory
, pFormat
);
1316 memcpy(pStubMsg
->Buffer
, pMemory
, size
);
1317 pStubMsg
->BufferMark
= pStubMsg
->Buffer
;
1318 pStubMsg
->Buffer
+= size
;
1320 if (pFormat
[0] != RPC_FC_STRUCT
)
1321 EmbeddedPointerMarshall(pStubMsg
, pMemory
, pFormat
+4);
1323 STD_OVERFLOW_CHECK(pStubMsg
);
1328 /***********************************************************************
1329 * NdrSimpleStructUnmarshall [RPCRT4.@]
1331 unsigned char * WINAPI
NdrSimpleStructUnmarshall(PMIDL_STUB_MESSAGE pStubMsg
,
1332 unsigned char **ppMemory
,
1333 PFORMAT_STRING pFormat
,
1334 unsigned char fMustAlloc
)
1336 unsigned size
= *(const WORD
*)(pFormat
+2);
1337 TRACE("(%p,%p,%p,%d)\n", pStubMsg
, ppMemory
, pFormat
, fMustAlloc
);
1340 *ppMemory
= NdrAllocate(pStubMsg
, size
);
1341 memcpy(*ppMemory
, pStubMsg
->Buffer
, size
);
1343 if (pStubMsg
->ReuseBuffer
&& !*ppMemory
)
1344 /* for servers, we may just point straight into the RPC buffer, I think
1345 * (I guess that's what MS does since MIDL code doesn't try to free) */
1346 *ppMemory
= pStubMsg
->Buffer
;
1348 /* for clients, memory should be provided by caller */
1349 memcpy(*ppMemory
, pStubMsg
->Buffer
, size
);
1352 pStubMsg
->BufferMark
= pStubMsg
->Buffer
;
1353 pStubMsg
->Buffer
+= size
;
1355 if (pFormat
[0] != RPC_FC_STRUCT
)
1356 EmbeddedPointerUnmarshall(pStubMsg
, ppMemory
, pFormat
+4, fMustAlloc
);
1362 /***********************************************************************
1363 * NdrSimpleStructUnmarshall [RPCRT4.@]
1365 void WINAPI
NdrSimpleTypeMarshall( PMIDL_STUB_MESSAGE pStubMsg
, unsigned char* pMemory
,
1366 unsigned char FormatChar
)
1372 /***********************************************************************
1373 * NdrSimpleStructUnmarshall [RPCRT4.@]
1375 void WINAPI
NdrSimpleTypeUnmarshall( PMIDL_STUB_MESSAGE pStubMsg
, unsigned char* pMemory
,
1376 unsigned char FormatChar
)
1382 /***********************************************************************
1383 * NdrSimpleStructBufferSize [RPCRT4.@]
1385 void WINAPI
NdrSimpleStructBufferSize(PMIDL_STUB_MESSAGE pStubMsg
,
1386 unsigned char *pMemory
,
1387 PFORMAT_STRING pFormat
)
1389 unsigned size
= *(const WORD
*)(pFormat
+2);
1390 TRACE("(%p,%p,%p)\n", pStubMsg
, pMemory
, pFormat
);
1391 pStubMsg
->BufferLength
+= size
;
1392 if (pFormat
[0] != RPC_FC_STRUCT
)
1393 EmbeddedPointerBufferSize(pStubMsg
, pMemory
, pFormat
+4);
1396 /***********************************************************************
1397 * NdrSimpleStructMemorySize [RPCRT4.@]
1399 unsigned long WINAPI
NdrSimpleStructMemorySize(PMIDL_STUB_MESSAGE pStubMsg
,
1400 PFORMAT_STRING pFormat
)
1402 /* unsigned size = *(LPWORD)(pFormat+2); */
1403 FIXME("(%p,%p): stub\n", pStubMsg
, pFormat
);
1404 if (pFormat
[0] != RPC_FC_STRUCT
)
1405 EmbeddedPointerMemorySize(pStubMsg
, pFormat
+4);
1409 /***********************************************************************
1410 * NdrSimpleStructFree [RPCRT4.@]
1412 void WINAPI
NdrSimpleStructFree(PMIDL_STUB_MESSAGE pStubMsg
,
1413 unsigned char *pMemory
,
1414 PFORMAT_STRING pFormat
)
1416 TRACE("(%p,%p,%p)\n", pStubMsg
, pMemory
, pFormat
);
1417 if (pFormat
[0] != RPC_FC_STRUCT
)
1418 EmbeddedPointerFree(pStubMsg
, pMemory
, pFormat
+4);
1422 unsigned long WINAPI
EmbeddedComplexSize(PMIDL_STUB_MESSAGE pStubMsg
,
1423 PFORMAT_STRING pFormat
)
1427 case RPC_FC_PSTRUCT
:
1428 case RPC_FC_CSTRUCT
:
1429 case RPC_FC_BOGUS_STRUCT
:
1430 return *(const WORD
*)&pFormat
[2];
1431 case RPC_FC_USER_MARSHAL
:
1432 return *(const WORD
*)&pFormat
[4];
1434 FIXME("unhandled embedded type %02x\n", *pFormat
);
1440 unsigned char * WINAPI
ComplexMarshall(PMIDL_STUB_MESSAGE pStubMsg
,
1441 unsigned char *pMemory
,
1442 PFORMAT_STRING pFormat
,
1443 PFORMAT_STRING pPointer
)
1445 PFORMAT_STRING desc
;
1449 while (*pFormat
!= RPC_FC_END
) {
1453 TRACE("short=%d <= %p\n", *(WORD
*)pMemory
, pMemory
);
1454 memcpy(pStubMsg
->Buffer
, pMemory
, 2);
1455 pStubMsg
->Buffer
+= 2;
1461 TRACE("long=%ld <= %p\n", *(DWORD
*)pMemory
, pMemory
);
1462 memcpy(pStubMsg
->Buffer
, pMemory
, 4);
1463 pStubMsg
->Buffer
+= 4;
1466 case RPC_FC_POINTER
:
1467 TRACE("pointer=%p <= %p\n", *(unsigned char**)pMemory
, pMemory
);
1468 NdrPointerMarshall(pStubMsg
, *(unsigned char**)pMemory
, pPointer
);
1472 case RPC_FC_ALIGNM4
:
1473 ALIGN_POINTER(pMemory
, 3);
1475 case RPC_FC_ALIGNM8
:
1476 ALIGN_POINTER(pMemory
, 7);
1478 case RPC_FC_STRUCTPAD2
:
1481 case RPC_FC_EMBEDDED_COMPLEX
:
1482 pMemory
+= pFormat
[1];
1484 desc
= pFormat
+ *(const SHORT
*)pFormat
;
1485 size
= EmbeddedComplexSize(pStubMsg
, desc
);
1486 TRACE("embedded complex (size=%ld) <= %p\n", size
, pMemory
);
1487 m
= NdrMarshaller
[*desc
& NDR_TABLE_MASK
];
1488 if (m
) m(pStubMsg
, pMemory
, desc
);
1489 else FIXME("no marshaller for embedded type %02x\n", *desc
);
1496 FIXME("unhandled format %02x\n", *pFormat
);
1504 unsigned char * WINAPI
ComplexUnmarshall(PMIDL_STUB_MESSAGE pStubMsg
,
1505 unsigned char *pMemory
,
1506 PFORMAT_STRING pFormat
,
1507 PFORMAT_STRING pPointer
,
1508 unsigned char fMustAlloc
)
1510 PFORMAT_STRING desc
;
1514 while (*pFormat
!= RPC_FC_END
) {
1518 memcpy(pMemory
, pStubMsg
->Buffer
, 2);
1519 TRACE("short=%d => %p\n", *(WORD
*)pMemory
, pMemory
);
1520 pStubMsg
->Buffer
+= 2;
1526 memcpy(pMemory
, pStubMsg
->Buffer
, 4);
1527 TRACE("long=%ld => %p\n", *(DWORD
*)pMemory
, pMemory
);
1528 pStubMsg
->Buffer
+= 4;
1531 case RPC_FC_POINTER
:
1532 *(unsigned char**)pMemory
= NULL
;
1533 TRACE("pointer => %p\n", pMemory
);
1534 NdrPointerUnmarshall(pStubMsg
, (unsigned char**)pMemory
, pPointer
, fMustAlloc
);
1538 case RPC_FC_ALIGNM4
:
1539 ALIGN_POINTER(pMemory
, 3);
1541 case RPC_FC_ALIGNM8
:
1542 ALIGN_POINTER(pMemory
, 7);
1544 case RPC_FC_STRUCTPAD2
:
1547 case RPC_FC_EMBEDDED_COMPLEX
:
1548 pMemory
+= pFormat
[1];
1550 desc
= pFormat
+ *(const SHORT
*)pFormat
;
1551 size
= EmbeddedComplexSize(pStubMsg
, desc
);
1552 TRACE("embedded complex (size=%ld) => %p\n", size
, pMemory
);
1553 m
= NdrUnmarshaller
[*desc
& NDR_TABLE_MASK
];
1554 memset(pMemory
, 0, size
); /* just in case */
1555 if (m
) m(pStubMsg
, &pMemory
, desc
, fMustAlloc
);
1556 else FIXME("no unmarshaller for embedded type %02x\n", *desc
);
1563 FIXME("unhandled format %d\n", *pFormat
);
1571 unsigned char * WINAPI
ComplexBufferSize(PMIDL_STUB_MESSAGE pStubMsg
,
1572 unsigned char *pMemory
,
1573 PFORMAT_STRING pFormat
,
1574 PFORMAT_STRING pPointer
)
1576 PFORMAT_STRING desc
;
1580 while (*pFormat
!= RPC_FC_END
) {
1584 pStubMsg
->BufferLength
+= 2;
1590 pStubMsg
->BufferLength
+= 4;
1593 case RPC_FC_POINTER
:
1594 NdrPointerBufferSize(pStubMsg
, *(unsigned char**)pMemory
, pPointer
);
1598 case RPC_FC_ALIGNM4
:
1599 ALIGN_POINTER(pMemory
, 3);
1601 case RPC_FC_ALIGNM8
:
1602 ALIGN_POINTER(pMemory
, 7);
1604 case RPC_FC_STRUCTPAD2
:
1607 case RPC_FC_EMBEDDED_COMPLEX
:
1608 pMemory
+= pFormat
[1];
1610 desc
= pFormat
+ *(const SHORT
*)pFormat
;
1611 size
= EmbeddedComplexSize(pStubMsg
, desc
);
1612 m
= NdrBufferSizer
[*desc
& NDR_TABLE_MASK
];
1613 if (m
) m(pStubMsg
, pMemory
, desc
);
1614 else FIXME("no buffersizer for embedded type %02x\n", *desc
);
1621 FIXME("unhandled format %d\n", *pFormat
);
1629 unsigned char * WINAPI
ComplexFree(PMIDL_STUB_MESSAGE pStubMsg
,
1630 unsigned char *pMemory
,
1631 PFORMAT_STRING pFormat
,
1632 PFORMAT_STRING pPointer
)
1634 PFORMAT_STRING desc
;
1638 while (*pFormat
!= RPC_FC_END
) {
1649 case RPC_FC_POINTER
:
1650 NdrPointerFree(pStubMsg
, *(unsigned char**)pMemory
, pPointer
);
1654 case RPC_FC_ALIGNM4
:
1655 ALIGN_POINTER(pMemory
, 3);
1657 case RPC_FC_ALIGNM8
:
1658 ALIGN_POINTER(pMemory
, 7);
1660 case RPC_FC_STRUCTPAD2
:
1663 case RPC_FC_EMBEDDED_COMPLEX
:
1664 pMemory
+= pFormat
[1];
1666 desc
= pFormat
+ *(const SHORT
*)pFormat
;
1667 size
= EmbeddedComplexSize(pStubMsg
, desc
);
1668 m
= NdrFreer
[*desc
& NDR_TABLE_MASK
];
1669 if (m
) m(pStubMsg
, pMemory
, desc
);
1670 else FIXME("no freer for embedded type %02x\n", *desc
);
1677 FIXME("unhandled format %d\n", *pFormat
);
1685 unsigned long WINAPI
ComplexStructSize(PMIDL_STUB_MESSAGE pStubMsg
,
1686 PFORMAT_STRING pFormat
)
1688 PFORMAT_STRING desc
;
1689 unsigned long size
= 0;
1691 while (*pFormat
!= RPC_FC_END
) {
1701 case RPC_FC_POINTER
:
1704 case RPC_FC_ALIGNM4
:
1705 ALIGN_LENGTH(size
, 3);
1707 case RPC_FC_ALIGNM8
:
1708 ALIGN_LENGTH(size
, 7);
1710 case RPC_FC_STRUCTPAD2
:
1713 case RPC_FC_EMBEDDED_COMPLEX
:
1716 desc
= pFormat
+ *(const SHORT
*)pFormat
;
1717 size
+= EmbeddedComplexSize(pStubMsg
, desc
);
1723 FIXME("unhandled format %d\n", *pFormat
);
1731 /***********************************************************************
1732 * NdrComplexStructMarshall [RPCRT4.@]
1734 unsigned char * WINAPI
NdrComplexStructMarshall(PMIDL_STUB_MESSAGE pStubMsg
,
1735 unsigned char *pMemory
,
1736 PFORMAT_STRING pFormat
)
1738 PFORMAT_STRING conf_array
= NULL
;
1739 PFORMAT_STRING pointer_desc
= NULL
;
1740 unsigned char *OldMemory
= pStubMsg
->Memory
;
1742 TRACE("(%p,%p,%p)\n", pStubMsg
, pMemory
, pFormat
);
1745 if (*(const WORD
*)pFormat
) conf_array
= pFormat
+ *(const WORD
*)pFormat
;
1747 if (*(const WORD
*)pFormat
) pointer_desc
= pFormat
+ *(const WORD
*)pFormat
;
1750 pStubMsg
->Memory
= pMemory
;
1752 ComplexMarshall(pStubMsg
, pMemory
, pFormat
, pointer_desc
);
1755 NdrConformantArrayMarshall(pStubMsg
, pMemory
, conf_array
);
1757 pStubMsg
->Memory
= OldMemory
;
1759 STD_OVERFLOW_CHECK(pStubMsg
);
1764 /***********************************************************************
1765 * NdrComplexStructUnmarshall [RPCRT4.@]
1767 unsigned char * WINAPI
NdrComplexStructUnmarshall(PMIDL_STUB_MESSAGE pStubMsg
,
1768 unsigned char **ppMemory
,
1769 PFORMAT_STRING pFormat
,
1770 unsigned char fMustAlloc
)
1772 unsigned size
= *(const WORD
*)(pFormat
+2);
1773 PFORMAT_STRING conf_array
= NULL
;
1774 PFORMAT_STRING pointer_desc
= NULL
;
1775 unsigned char *pMemory
;
1777 TRACE("(%p,%p,%p,%d)\n", pStubMsg
, ppMemory
, pFormat
, fMustAlloc
);
1779 if (fMustAlloc
|| !*ppMemory
)
1781 *ppMemory
= NdrAllocate(pStubMsg
, size
);
1782 memset(*ppMemory
, 0, size
);
1786 if (*(const WORD
*)pFormat
) conf_array
= pFormat
+ *(const WORD
*)pFormat
;
1788 if (*(const WORD
*)pFormat
) pointer_desc
= pFormat
+ *(const WORD
*)pFormat
;
1791 pMemory
= ComplexUnmarshall(pStubMsg
, *ppMemory
, pFormat
, pointer_desc
, fMustAlloc
);
1794 NdrConformantArrayUnmarshall(pStubMsg
, &pMemory
, conf_array
, fMustAlloc
);
1799 /***********************************************************************
1800 * NdrComplexStructBufferSize [RPCRT4.@]
1802 void WINAPI
NdrComplexStructBufferSize(PMIDL_STUB_MESSAGE pStubMsg
,
1803 unsigned char *pMemory
,
1804 PFORMAT_STRING pFormat
)
1806 PFORMAT_STRING conf_array
= NULL
;
1807 PFORMAT_STRING pointer_desc
= NULL
;
1808 unsigned char *OldMemory
= pStubMsg
->Memory
;
1810 TRACE("(%p,%p,%p)\n", pStubMsg
, pMemory
, pFormat
);
1813 if (*(const WORD
*)pFormat
) conf_array
= pFormat
+ *(const WORD
*)pFormat
;
1815 if (*(const WORD
*)pFormat
) pointer_desc
= pFormat
+ *(const WORD
*)pFormat
;
1818 pStubMsg
->Memory
= pMemory
;
1820 pMemory
= ComplexBufferSize(pStubMsg
, pMemory
, pFormat
, pointer_desc
);
1823 NdrConformantArrayBufferSize(pStubMsg
, pMemory
, conf_array
);
1825 pStubMsg
->Memory
= OldMemory
;
1828 /***********************************************************************
1829 * NdrComplexStructMemorySize [RPCRT4.@]
1831 unsigned long WINAPI
NdrComplexStructMemorySize(PMIDL_STUB_MESSAGE pStubMsg
,
1832 PFORMAT_STRING pFormat
)
1834 /* unsigned size = *(LPWORD)(pFormat+2); */
1835 PFORMAT_STRING conf_array
= NULL
;
1836 PFORMAT_STRING pointer_desc
= NULL
;
1838 FIXME("(%p,%p): stub\n", pStubMsg
, pFormat
);
1841 if (*(const WORD
*)pFormat
) conf_array
= pFormat
+ *(const WORD
*)pFormat
;
1843 if (*(const WORD
*)pFormat
) pointer_desc
= pFormat
+ *(const WORD
*)pFormat
;
1849 /***********************************************************************
1850 * NdrComplexStructFree [RPCRT4.@]
1852 void WINAPI
NdrComplexStructFree(PMIDL_STUB_MESSAGE pStubMsg
,
1853 unsigned char *pMemory
,
1854 PFORMAT_STRING pFormat
)
1856 PFORMAT_STRING conf_array
= NULL
;
1857 PFORMAT_STRING pointer_desc
= NULL
;
1858 unsigned char *OldMemory
= pStubMsg
->Memory
;
1860 TRACE("(%p,%p,%p)\n", pStubMsg
, pMemory
, pFormat
);
1863 if (*(const WORD
*)pFormat
) conf_array
= pFormat
+ *(const WORD
*)pFormat
;
1865 if (*(const WORD
*)pFormat
) pointer_desc
= pFormat
+ *(const WORD
*)pFormat
;
1868 pStubMsg
->Memory
= pMemory
;
1870 pMemory
= ComplexFree(pStubMsg
, pMemory
, pFormat
, pointer_desc
);
1873 NdrConformantArrayFree(pStubMsg
, pMemory
, conf_array
);
1875 pStubMsg
->Memory
= OldMemory
;
1878 /***********************************************************************
1879 * NdrConformantArrayMarshall [RPCRT4.@]
1881 unsigned char * WINAPI
NdrConformantArrayMarshall(PMIDL_STUB_MESSAGE pStubMsg
,
1882 unsigned char *pMemory
,
1883 PFORMAT_STRING pFormat
)
1885 DWORD size
= 0, esize
= *(const WORD
*)(pFormat
+2);
1886 TRACE("(%p,%p,%p)\n", pStubMsg
, pMemory
, pFormat
);
1887 if (pFormat
[0] != RPC_FC_CARRAY
) FIXME("format=%d\n", pFormat
[0]);
1889 pFormat
= ComputeConformance(pStubMsg
, pMemory
, pFormat
+4, 0);
1890 size
= pStubMsg
->MaxCount
;
1892 NDR_LOCAL_UINT32_WRITE(pStubMsg
->Buffer
, size
);
1893 pStubMsg
->Buffer
+= 4;
1895 memcpy(pStubMsg
->Buffer
, pMemory
, size
*esize
);
1896 pStubMsg
->BufferMark
= pStubMsg
->Buffer
;
1897 pStubMsg
->Buffer
+= size
*esize
;
1899 EmbeddedPointerMarshall(pStubMsg
, pMemory
, pFormat
);
1901 STD_OVERFLOW_CHECK(pStubMsg
);
1906 /***********************************************************************
1907 * NdrConformantArrayUnmarshall [RPCRT4.@]
1909 unsigned char * WINAPI
NdrConformantArrayUnmarshall(PMIDL_STUB_MESSAGE pStubMsg
,
1910 unsigned char **ppMemory
,
1911 PFORMAT_STRING pFormat
,
1912 unsigned char fMustAlloc
)
1914 DWORD size
= 0, esize
= *(const WORD
*)(pFormat
+2);
1915 TRACE("(%p,%p,%p,%d)\n", pStubMsg
, ppMemory
, pFormat
, fMustAlloc
);
1916 if (pFormat
[0] != RPC_FC_CARRAY
) FIXME("format=%d\n", pFormat
[0]);
1918 pFormat
= ReadConformance(pStubMsg
, pFormat
+4);
1919 size
= pStubMsg
->MaxCount
;
1921 if (fMustAlloc
|| !*ppMemory
)
1922 *ppMemory
= NdrAllocate(pStubMsg
, size
*esize
);
1924 memcpy(*ppMemory
, pStubMsg
->Buffer
, size
*esize
);
1926 pStubMsg
->BufferMark
= pStubMsg
->Buffer
;
1927 pStubMsg
->Buffer
+= size
*esize
;
1929 EmbeddedPointerUnmarshall(pStubMsg
, ppMemory
, pFormat
, fMustAlloc
);
1934 /***********************************************************************
1935 * NdrConformantArrayBufferSize [RPCRT4.@]
1937 void WINAPI
NdrConformantArrayBufferSize(PMIDL_STUB_MESSAGE pStubMsg
,
1938 unsigned char *pMemory
,
1939 PFORMAT_STRING pFormat
)
1941 DWORD size
= 0, esize
= *(const WORD
*)(pFormat
+2);
1942 TRACE("(%p,%p,%p)\n", pStubMsg
, pMemory
, pFormat
);
1943 if (pFormat
[0] != RPC_FC_CARRAY
) FIXME("format=%d\n", pFormat
[0]);
1945 pFormat
= ComputeConformance(pStubMsg
, pMemory
, pFormat
+4, 0);
1946 size
= pStubMsg
->MaxCount
;
1948 /* conformance value plus array */
1949 pStubMsg
->BufferLength
+= sizeof(DWORD
) + size
*esize
;
1951 EmbeddedPointerBufferSize(pStubMsg
, pMemory
, pFormat
);
1954 /***********************************************************************
1955 * NdrConformantArrayMemorySize [RPCRT4.@]
1957 unsigned long WINAPI
NdrConformantArrayMemorySize(PMIDL_STUB_MESSAGE pStubMsg
,
1958 PFORMAT_STRING pFormat
)
1960 DWORD size
= 0, esize
= *(const WORD
*)(pFormat
+2);
1961 unsigned char *buffer
;
1963 TRACE("(%p,%p)\n", pStubMsg
, pFormat
);
1964 if (pFormat
[0] != RPC_FC_CARRAY
) FIXME("format=%d\n", pFormat
[0]);
1966 buffer
= pStubMsg
->Buffer
;
1967 pFormat
= ReadConformance(pStubMsg
, pFormat
+4);
1968 pStubMsg
->Buffer
= buffer
;
1969 size
= pStubMsg
->MaxCount
;
1974 /***********************************************************************
1975 * NdrConformantArrayFree [RPCRT4.@]
1977 void WINAPI
NdrConformantArrayFree(PMIDL_STUB_MESSAGE pStubMsg
,
1978 unsigned char *pMemory
,
1979 PFORMAT_STRING pFormat
)
1981 TRACE("(%p,%p,%p)\n", pStubMsg
, pMemory
, pFormat
);
1982 if (pFormat
[0] != RPC_FC_CARRAY
) FIXME("format=%d\n", pFormat
[0]);
1984 EmbeddedPointerFree(pStubMsg
, pMemory
, pFormat
);
1988 /***********************************************************************
1989 * NdrConformantVaryingArrayMarshall [RPCRT4.@]
1991 unsigned char* WINAPI
NdrConformantVaryingArrayMarshall( PMIDL_STUB_MESSAGE pStubMsg
,
1992 unsigned char* pMemory
,
1993 PFORMAT_STRING pFormat
)
1995 DWORD esize
= *(const WORD
*)(pFormat
+2);
1997 TRACE("(%p, %p, %p)\n", pStubMsg
, pMemory
, pFormat
);
1999 if (pFormat
[0] != RPC_FC_CVARRAY
)
2001 ERR("invalid format type %x\n", pFormat
[0]);
2002 RpcRaiseException(RPC_S_INTERNAL_ERROR
);
2006 pFormat
= ComputeConformance(pStubMsg
, pMemory
, pFormat
+4, 0);
2007 pFormat
= ComputeVariance(pStubMsg
, pMemory
, pFormat
, 0);
2009 NDR_LOCAL_UINT32_WRITE(pStubMsg
->Buffer
, pStubMsg
->MaxCount
);
2010 pStubMsg
->Buffer
+= 4;
2011 NDR_LOCAL_UINT32_WRITE(pStubMsg
->Buffer
, pStubMsg
->Offset
);
2012 pStubMsg
->Buffer
+= 4;
2013 NDR_LOCAL_UINT32_WRITE(pStubMsg
->Buffer
, pStubMsg
->ActualCount
);
2014 pStubMsg
->Buffer
+= 4;
2016 memcpy(pStubMsg
->Buffer
, pMemory
+ pStubMsg
->Offset
, pStubMsg
->ActualCount
*esize
);
2017 pStubMsg
->BufferMark
= pStubMsg
->Buffer
;
2018 pStubMsg
->Buffer
+= pStubMsg
->ActualCount
*esize
;
2020 EmbeddedPointerMarshall(pStubMsg
, pMemory
, pFormat
);
2022 STD_OVERFLOW_CHECK(pStubMsg
);
2028 /***********************************************************************
2029 * NdrConformantVaryingArrayUnmarshall [RPCRT4.@]
2031 unsigned char* WINAPI
NdrConformantVaryingArrayUnmarshall( PMIDL_STUB_MESSAGE pStubMsg
,
2032 unsigned char** ppMemory
,
2033 PFORMAT_STRING pFormat
,
2034 unsigned char fMustAlloc
)
2036 DWORD esize
= *(const WORD
*)(pFormat
+2);
2038 TRACE("(%p, %p, %p, %d)\n", pStubMsg
, ppMemory
, pFormat
, fMustAlloc
);
2040 if (pFormat
[0] != RPC_FC_CVARRAY
)
2042 ERR("invalid format type %x\n", pFormat
[0]);
2043 RpcRaiseException(RPC_S_INTERNAL_ERROR
);
2046 pFormat
= ReadConformance(pStubMsg
, pFormat
);
2047 pFormat
= ReadVariance(pStubMsg
, pFormat
);
2049 if (!*ppMemory
|| fMustAlloc
)
2050 *ppMemory
= NdrAllocate(pStubMsg
, pStubMsg
->MaxCount
* esize
);
2051 memcpy(*ppMemory
+ pStubMsg
->Offset
, pStubMsg
->Buffer
, pStubMsg
->ActualCount
* esize
);
2052 pStubMsg
->Buffer
+= pStubMsg
->ActualCount
* esize
;
2054 EmbeddedPointerUnmarshall(pStubMsg
, ppMemory
, pFormat
, fMustAlloc
);
2060 /***********************************************************************
2061 * NdrConformantVaryingArrayFree [RPCRT4.@]
2063 void WINAPI
NdrConformantVaryingArrayFree( PMIDL_STUB_MESSAGE pStubMsg
,
2064 unsigned char* pMemory
,
2065 PFORMAT_STRING pFormat
)
2071 /***********************************************************************
2072 * NdrConformantVaryingArrayBufferSize [RPCRT4.@]
2074 void WINAPI
NdrConformantVaryingArrayBufferSize( PMIDL_STUB_MESSAGE pStubMsg
,
2075 unsigned char* pMemory
, PFORMAT_STRING pFormat
)
2077 DWORD esize
= *(const WORD
*)(pFormat
+2);
2079 TRACE("(%p, %p, %p)\n", pStubMsg
, pMemory
, pFormat
);
2081 if (pFormat
[0] != RPC_FC_CVARRAY
)
2083 ERR("invalid format type %x\n", pFormat
[0]);
2084 RpcRaiseException(RPC_S_INTERNAL_ERROR
);
2089 pFormat
= ComputeConformance(pStubMsg
, pMemory
, pFormat
+4, 0);
2090 /* compute length */
2091 pFormat
= ComputeVariance(pStubMsg
, pMemory
, pFormat
, 0);
2093 /* conformance + offset + variance + array */
2094 pStubMsg
->BufferLength
+= 3*sizeof(DWORD
) + pStubMsg
->ActualCount
*esize
;
2096 EmbeddedPointerBufferSize(pStubMsg
, pMemory
, pFormat
);
2100 /***********************************************************************
2101 * NdrConformantVaryingArrayMemorySize [RPCRT4.@]
2103 unsigned long WINAPI
NdrConformantVaryingArrayMemorySize( PMIDL_STUB_MESSAGE pStubMsg
,
2104 PFORMAT_STRING pFormat
)
2111 /***********************************************************************
2112 * NdrComplexArrayMarshall [RPCRT4.@]
2114 unsigned char * WINAPI
NdrComplexArrayMarshall(PMIDL_STUB_MESSAGE pStubMsg
,
2115 unsigned char *pMemory
,
2116 PFORMAT_STRING pFormat
)
2119 BOOL variance_present
;
2121 TRACE("(%p,%p,%p)\n", pStubMsg
, pMemory
, pFormat
);
2123 if (pFormat
[0] != RPC_FC_BOGUS_ARRAY
)
2125 ERR("invalid format type %x\n", pFormat
[0]);
2126 RpcRaiseException(RPC_S_INTERNAL_ERROR
);
2130 def
= *(const WORD
*)&pFormat
[2];
2133 pFormat
= ComputeConformance(pStubMsg
, pMemory
, pFormat
, def
);
2134 TRACE("conformance = %ld\n", pStubMsg
->MaxCount
);
2136 variance_present
= IsConformanceOrVariancePresent(pFormat
);
2137 pFormat
= ComputeVariance(pStubMsg
, pMemory
, pFormat
, pStubMsg
->MaxCount
);
2138 TRACE("variance = %ld\n", pStubMsg
->ActualCount
);
2140 NDR_LOCAL_UINT32_WRITE(pStubMsg
->Buffer
, pStubMsg
->MaxCount
);
2141 pStubMsg
->Buffer
+= 4;
2142 if (variance_present
)
2144 NDR_LOCAL_UINT32_WRITE(pStubMsg
->Buffer
, pStubMsg
->Offset
);
2145 pStubMsg
->Buffer
+= 4;
2146 NDR_LOCAL_UINT32_WRITE(pStubMsg
->Buffer
, pStubMsg
->ActualCount
);
2147 pStubMsg
->Buffer
+= 4;
2150 for (count
= 0; count
< pStubMsg
->ActualCount
; count
++)
2151 pMemory
= ComplexMarshall(pStubMsg
, pMemory
, pFormat
, NULL
);
2153 STD_OVERFLOW_CHECK(pStubMsg
);
2158 /***********************************************************************
2159 * NdrComplexArrayUnmarshall [RPCRT4.@]
2161 unsigned char * WINAPI
NdrComplexArrayUnmarshall(PMIDL_STUB_MESSAGE pStubMsg
,
2162 unsigned char **ppMemory
,
2163 PFORMAT_STRING pFormat
,
2164 unsigned char fMustAlloc
)
2167 unsigned char *pMemory
;
2169 TRACE("(%p,%p,%p,%d)\n", pStubMsg
, ppMemory
, pFormat
, fMustAlloc
);
2171 if (pFormat
[0] != RPC_FC_BOGUS_ARRAY
)
2173 ERR("invalid format type %x\n", pFormat
[0]);
2174 RpcRaiseException(RPC_S_INTERNAL_ERROR
);
2180 pFormat
= ReadConformance(pStubMsg
, pFormat
);
2181 pFormat
= ReadVariance(pStubMsg
, pFormat
);
2183 esize
= ComplexStructSize(pStubMsg
, pFormat
);
2185 if (fMustAlloc
|| !*ppMemory
)
2187 *ppMemory
= NdrAllocate(pStubMsg
, pStubMsg
->MaxCount
* esize
);
2188 memset(*ppMemory
, 0, pStubMsg
->MaxCount
* esize
);
2191 pMemory
= *ppMemory
;
2192 for (count
= 0; count
< pStubMsg
->ActualCount
; count
++)
2193 pMemory
= ComplexUnmarshall(pStubMsg
, pMemory
, pFormat
, NULL
, fMustAlloc
);
2198 /***********************************************************************
2199 * NdrComplexArrayBufferSize [RPCRT4.@]
2201 void WINAPI
NdrComplexArrayBufferSize(PMIDL_STUB_MESSAGE pStubMsg
,
2202 unsigned char *pMemory
,
2203 PFORMAT_STRING pFormat
)
2206 BOOL variance_present
;
2208 TRACE("(%p,%p,%p)\n", pStubMsg
, pMemory
, pFormat
);
2210 if (pFormat
[0] != RPC_FC_BOGUS_ARRAY
)
2212 ERR("invalid format type %x\n", pFormat
[0]);
2213 RpcRaiseException(RPC_S_INTERNAL_ERROR
);
2217 def
= *(const WORD
*)&pFormat
[2];
2220 pFormat
= ComputeConformance(pStubMsg
, pMemory
, pFormat
, def
);
2221 TRACE("conformance = %ld\n", pStubMsg
->MaxCount
);
2222 pStubMsg
->BufferLength
+= sizeof(ULONG
);
2224 variance_present
= IsConformanceOrVariancePresent(pFormat
);
2225 pFormat
= ComputeVariance(pStubMsg
, pMemory
, pFormat
, pStubMsg
->MaxCount
);
2226 TRACE("variance = %ld\n", pStubMsg
->ActualCount
);
2228 if (variance_present
)
2229 pStubMsg
->BufferLength
+= 2*sizeof(ULONG
);
2231 for (count
=0; count
< pStubMsg
->ActualCount
; count
++)
2232 pMemory
= ComplexBufferSize(pStubMsg
, pMemory
, pFormat
, NULL
);
2235 /***********************************************************************
2236 * NdrComplexArrayMemorySize [RPCRT4.@]
2238 unsigned long WINAPI
NdrComplexArrayMemorySize(PMIDL_STUB_MESSAGE pStubMsg
,
2239 PFORMAT_STRING pFormat
)
2242 FIXME("(%p,%p): stub\n", pStubMsg
, pFormat
);
2244 if (pFormat
[0] != RPC_FC_BOGUS_ARRAY
)
2246 ERR("invalid format type %x\n", pFormat
[0]);
2247 RpcRaiseException(RPC_S_INTERNAL_ERROR
);
2253 pFormat
= ReadConformance(pStubMsg
, pFormat
);
2254 size
= pStubMsg
->MaxCount
;
2255 TRACE("conformance=%ld\n", size
);
2262 /***********************************************************************
2263 * NdrComplexArrayFree [RPCRT4.@]
2265 void WINAPI
NdrComplexArrayFree(PMIDL_STUB_MESSAGE pStubMsg
,
2266 unsigned char *pMemory
,
2267 PFORMAT_STRING pFormat
)
2271 TRACE("(%p,%p,%p)\n", pStubMsg
, pMemory
, pFormat
);
2273 if (pFormat
[0] != RPC_FC_BOGUS_ARRAY
)
2275 ERR("invalid format type %x\n", pFormat
[0]);
2276 RpcRaiseException(RPC_S_INTERNAL_ERROR
);
2280 def
= *(const WORD
*)&pFormat
[2];
2283 pFormat
= ComputeConformance(pStubMsg
, pMemory
, pFormat
, def
);
2284 TRACE("conformance = %ld\n", pStubMsg
->MaxCount
);
2286 pFormat
= ComputeVariance(pStubMsg
, pMemory
, pFormat
, pStubMsg
->MaxCount
);
2287 TRACE("variance = %ld\n", pStubMsg
->ActualCount
);
2289 for (count
=0; count
< pStubMsg
->ActualCount
; count
++)
2290 pMemory
= ComplexFree(pStubMsg
, pMemory
, pFormat
, NULL
);
2293 unsigned long UserMarshalFlags(PMIDL_STUB_MESSAGE pStubMsg
)
2295 return MAKELONG(pStubMsg
->dwDestContext
,
2296 pStubMsg
->RpcMsg
->DataRepresentation
);
2299 /***********************************************************************
2300 * NdrUserMarshalMarshall [RPCRT4.@]
2302 unsigned char * WINAPI
NdrUserMarshalMarshall(PMIDL_STUB_MESSAGE pStubMsg
,
2303 unsigned char *pMemory
,
2304 PFORMAT_STRING pFormat
)
2306 /* unsigned flags = pFormat[1]; */
2307 unsigned index
= *(const WORD
*)&pFormat
[2];
2308 unsigned long uflag
= UserMarshalFlags(pStubMsg
);
2309 TRACE("(%p,%p,%p)\n", pStubMsg
, pMemory
, pFormat
);
2310 TRACE("index=%d\n", index
);
2313 pStubMsg
->StubDesc
->aUserMarshalQuadruple
[index
].pfnMarshall(
2314 &uflag
, pStubMsg
->Buffer
, pMemory
);
2316 STD_OVERFLOW_CHECK(pStubMsg
);
2321 /***********************************************************************
2322 * NdrUserMarshalUnmarshall [RPCRT4.@]
2324 unsigned char * WINAPI
NdrUserMarshalUnmarshall(PMIDL_STUB_MESSAGE pStubMsg
,
2325 unsigned char **ppMemory
,
2326 PFORMAT_STRING pFormat
,
2327 unsigned char fMustAlloc
)
2329 /* unsigned flags = pFormat[1];*/
2330 unsigned index
= *(const WORD
*)&pFormat
[2];
2331 DWORD memsize
= *(const WORD
*)&pFormat
[4];
2332 unsigned long uflag
= UserMarshalFlags(pStubMsg
);
2333 TRACE("(%p,%p,%p,%d)\n", pStubMsg
, ppMemory
, pFormat
, fMustAlloc
);
2334 TRACE("index=%d\n", index
);
2336 if (fMustAlloc
|| !*ppMemory
)
2337 *ppMemory
= NdrAllocate(pStubMsg
, memsize
);
2340 pStubMsg
->StubDesc
->aUserMarshalQuadruple
[index
].pfnUnmarshall(
2341 &uflag
, pStubMsg
->Buffer
, *ppMemory
);
2346 /***********************************************************************
2347 * NdrUserMarshalBufferSize [RPCRT4.@]
2349 void WINAPI
NdrUserMarshalBufferSize(PMIDL_STUB_MESSAGE pStubMsg
,
2350 unsigned char *pMemory
,
2351 PFORMAT_STRING pFormat
)
2353 /* unsigned flags = pFormat[1];*/
2354 unsigned index
= *(const WORD
*)&pFormat
[2];
2355 DWORD bufsize
= *(const WORD
*)&pFormat
[6];
2356 unsigned long uflag
= UserMarshalFlags(pStubMsg
);
2357 TRACE("(%p,%p,%p)\n", pStubMsg
, pMemory
, pFormat
);
2358 TRACE("index=%d\n", index
);
2361 TRACE("size=%ld\n", bufsize
);
2362 pStubMsg
->BufferLength
+= bufsize
;
2366 pStubMsg
->BufferLength
=
2367 pStubMsg
->StubDesc
->aUserMarshalQuadruple
[index
].pfnBufferSize(
2368 &uflag
, pStubMsg
->BufferLength
, pMemory
);
2371 /***********************************************************************
2372 * NdrUserMarshalMemorySize [RPCRT4.@]
2374 unsigned long WINAPI
NdrUserMarshalMemorySize(PMIDL_STUB_MESSAGE pStubMsg
,
2375 PFORMAT_STRING pFormat
)
2377 unsigned index
= *(const WORD
*)&pFormat
[2];
2378 /* DWORD memsize = *(const WORD*)&pFormat[4]; */
2379 FIXME("(%p,%p): stub\n", pStubMsg
, pFormat
);
2380 TRACE("index=%d\n", index
);
2385 /***********************************************************************
2386 * NdrUserMarshalFree [RPCRT4.@]
2388 void WINAPI
NdrUserMarshalFree(PMIDL_STUB_MESSAGE pStubMsg
,
2389 unsigned char *pMemory
,
2390 PFORMAT_STRING pFormat
)
2392 /* unsigned flags = pFormat[1]; */
2393 unsigned index
= *(const WORD
*)&pFormat
[2];
2394 unsigned long uflag
= UserMarshalFlags(pStubMsg
);
2395 TRACE("(%p,%p,%p)\n", pStubMsg
, pMemory
, pFormat
);
2396 TRACE("index=%d\n", index
);
2398 pStubMsg
->StubDesc
->aUserMarshalQuadruple
[index
].pfnFree(
2402 /***********************************************************************
2403 * NdrClearOutParameters [RPCRT4.@]
2405 void WINAPI
NdrClearOutParameters(PMIDL_STUB_MESSAGE pStubMsg
,
2406 PFORMAT_STRING pFormat
,
2409 FIXME("(%p,%p,%p): stub\n", pStubMsg
, pFormat
, ArgAddr
);
2412 /***********************************************************************
2413 * NdrConvert [RPCRT4.@]
2415 void WINAPI
NdrConvert( PMIDL_STUB_MESSAGE pStubMsg
, PFORMAT_STRING pFormat
)
2417 FIXME("(pStubMsg == ^%p, pFormat == ^%p): stub.\n", pStubMsg
, pFormat
);
2418 /* FIXME: since this stub doesn't do any converting, the proper behavior
2419 is to raise an exception */
2422 /***********************************************************************
2423 * NdrConvert2 [RPCRT4.@]
2425 void WINAPI
NdrConvert2( PMIDL_STUB_MESSAGE pStubMsg
, PFORMAT_STRING pFormat
, long NumberParams
)
2427 FIXME("(pStubMsg == ^%p, pFormat == ^%p, NumberParams == %ld): stub.\n",
2428 pStubMsg
, pFormat
, NumberParams
);
2429 /* FIXME: since this stub doesn't do any converting, the proper behavior
2430 is to raise an exception */
2433 typedef struct _NDR_CSTRUCT_FORMAT
2436 unsigned char alignment
;
2437 unsigned short memory_size
;
2438 short offset_to_array_description
;
2439 } NDR_CSTRUCT_FORMAT
;
2441 /***********************************************************************
2442 * NdrConformantStructMarshall [RPCRT4.@]
2444 unsigned char * WINAPI
NdrConformantStructMarshall(PMIDL_STUB_MESSAGE pStubMsg
,
2445 unsigned char *pMemory
,
2446 PFORMAT_STRING pFormat
)
2448 const NDR_CSTRUCT_FORMAT
* pCStructFormat
= (NDR_CSTRUCT_FORMAT
*)pFormat
;
2449 pFormat
+= sizeof(NDR_CSTRUCT_FORMAT
);
2451 TRACE("(%p, %p, %p)\n", pStubMsg
, pMemory
, pFormat
);
2453 if ((pCStructFormat
->type
!= RPC_FC_CPSTRUCT
) && (pCStructFormat
->type
!= RPC_FC_CSTRUCT
))
2455 ERR("invalid format type %x\n", pCStructFormat
->type
);
2456 RpcRaiseException(RPC_S_INTERNAL_ERROR
);
2460 TRACE("memory_size = %d\n", pCStructFormat
->memory_size
);
2462 /* copy constant sized part of struct */
2463 memcpy(pStubMsg
->Buffer
, pMemory
, pCStructFormat
->memory_size
);
2464 pStubMsg
->Buffer
+= pCStructFormat
->memory_size
;
2466 if (pCStructFormat
->offset_to_array_description
)
2468 PFORMAT_STRING pArrayFormat
= (unsigned char*)&pCStructFormat
->offset_to_array_description
+
2469 pCStructFormat
->offset_to_array_description
;
2470 NdrConformantArrayMarshall(pStubMsg
, pMemory
+ pCStructFormat
->memory_size
, pArrayFormat
);
2472 if (pCStructFormat
->type
== RPC_FC_CPSTRUCT
)
2473 EmbeddedPointerMarshall(pStubMsg
, pMemory
, pFormat
);
2477 /***********************************************************************
2478 * NdrConformantStructUnmarshall [RPCRT4.@]
2480 unsigned char * WINAPI
NdrConformantStructUnmarshall(PMIDL_STUB_MESSAGE pStubMsg
,
2481 unsigned char **ppMemory
,
2482 PFORMAT_STRING pFormat
,
2483 unsigned char fMustAlloc
)
2485 const NDR_CSTRUCT_FORMAT
* pCStructFormat
= (NDR_CSTRUCT_FORMAT
*)pFormat
;
2486 pFormat
+= sizeof(NDR_CSTRUCT_FORMAT
);
2488 TRACE("(%p, %p, %p, %d)\n", pStubMsg
, ppMemory
, pFormat
, fMustAlloc
);
2490 if ((pCStructFormat
->type
!= RPC_FC_CPSTRUCT
) && (pCStructFormat
->type
!= RPC_FC_CSTRUCT
))
2492 ERR("invalid format type %x\n", pCStructFormat
->type
);
2493 RpcRaiseException(RPC_S_INTERNAL_ERROR
);
2497 TRACE("memory_size = %d\n", pCStructFormat
->memory_size
);
2499 /* work out how much memory to allocate if we need to do so */
2500 if (!*ppMemory
|| fMustAlloc
)
2502 SIZE_T size
= pCStructFormat
->memory_size
;
2504 if (pCStructFormat
->offset_to_array_description
)
2506 unsigned char *buffer
;
2507 PFORMAT_STRING pArrayFormat
= (unsigned char*)&pCStructFormat
->offset_to_array_description
+
2508 pCStructFormat
->offset_to_array_description
;
2509 buffer
= pStubMsg
->Buffer
;
2510 pStubMsg
->Buffer
+= pCStructFormat
->memory_size
;
2511 size
+= NdrConformantArrayMemorySize(pStubMsg
, pArrayFormat
);
2512 pStubMsg
->Buffer
= buffer
;
2514 *ppMemory
= NdrAllocate(pStubMsg
, size
);
2517 /* now copy the data */
2518 memcpy(*ppMemory
, pStubMsg
->Buffer
, pCStructFormat
->memory_size
);
2519 pStubMsg
->Buffer
+= pCStructFormat
->memory_size
;
2520 if (pCStructFormat
->offset_to_array_description
)
2522 PFORMAT_STRING pArrayFormat
= (unsigned char*)&pCStructFormat
->offset_to_array_description
+
2523 pCStructFormat
->offset_to_array_description
;
2524 unsigned char *pMemoryArray
= *ppMemory
+ pCStructFormat
->memory_size
;
2525 /* note that we pass fMustAlloc as 0 as we have already allocated the
2527 NdrConformantArrayUnmarshall(pStubMsg
, &pMemoryArray
, pArrayFormat
, 0);
2529 if (pCStructFormat
->type
== RPC_FC_CPSTRUCT
)
2530 EmbeddedPointerUnmarshall(pStubMsg
, ppMemory
, pFormat
, fMustAlloc
);
2534 /***********************************************************************
2535 * NdrConformantStructBufferSize [RPCRT4.@]
2537 void WINAPI
NdrConformantStructBufferSize(PMIDL_STUB_MESSAGE pStubMsg
,
2538 unsigned char *pMemory
,
2539 PFORMAT_STRING pFormat
)
2541 const NDR_CSTRUCT_FORMAT
* pCStructFormat
= (NDR_CSTRUCT_FORMAT
*)pFormat
;
2542 pFormat
+= sizeof(NDR_CSTRUCT_FORMAT
);
2543 TRACE("(%p, %p, %p)\n", pStubMsg
, pMemory
, pFormat
);
2545 if ((pCStructFormat
->type
!= RPC_FC_CPSTRUCT
) && (pCStructFormat
->type
!= RPC_FC_CSTRUCT
))
2547 ERR("invalid format type %x\n", pCStructFormat
->type
);
2548 RpcRaiseException(RPC_S_INTERNAL_ERROR
);
2552 TRACE("memory_size = %d\n", pCStructFormat
->memory_size
);
2554 /* add constant sized part of struct to buffer size */
2555 pStubMsg
->BufferLength
+= pCStructFormat
->memory_size
;
2557 if (pCStructFormat
->offset_to_array_description
)
2559 PFORMAT_STRING pArrayFormat
= (unsigned char*)&pCStructFormat
->offset_to_array_description
+
2560 pCStructFormat
->offset_to_array_description
;
2561 NdrConformantArrayBufferSize(pStubMsg
, pMemory
+ pCStructFormat
->memory_size
, pArrayFormat
);
2563 if (pCStructFormat
->type
== RPC_FC_CPSTRUCT
)
2564 EmbeddedPointerBufferSize(pStubMsg
, pMemory
, pFormat
);
2567 /***********************************************************************
2568 * NdrConformantStructMemorySize [RPCRT4.@]
2570 unsigned long WINAPI
NdrConformantStructMemorySize(PMIDL_STUB_MESSAGE pStubMsg
,
2571 PFORMAT_STRING pFormat
)
2577 /***********************************************************************
2578 * NdrConformantStructFree [RPCRT4.@]
2580 void WINAPI
NdrConformantStructFree(PMIDL_STUB_MESSAGE pStubMsg
,
2581 unsigned char *pMemory
,
2582 PFORMAT_STRING pFormat
)
2587 /***********************************************************************
2588 * NdrConformantVaryingStructMarshall [RPCRT4.@]
2590 unsigned char * WINAPI
NdrConformantVaryingStructMarshall(PMIDL_STUB_MESSAGE pStubMsg
,
2591 unsigned char *pMemory
,
2592 PFORMAT_STRING pFormat
)
2598 /***********************************************************************
2599 * NdrConformantVaryingStructUnmarshall [RPCRT4.@]
2601 unsigned char * WINAPI
NdrConformantVaryingStructUnmarshall(PMIDL_STUB_MESSAGE pStubMsg
,
2602 unsigned char **ppMemory
,
2603 PFORMAT_STRING pFormat
,
2604 unsigned char fMustAlloc
)
2610 /***********************************************************************
2611 * NdrConformantVaryingStructBufferSize [RPCRT4.@]
2613 void WINAPI
NdrConformantVaryingStructBufferSize(PMIDL_STUB_MESSAGE pStubMsg
,
2614 unsigned char *pMemory
,
2615 PFORMAT_STRING pFormat
)
2620 /***********************************************************************
2621 * NdrConformantVaryingStructMemorySize [RPCRT4.@]
2623 unsigned long WINAPI
NdrConformantVaryingStructMemorySize(PMIDL_STUB_MESSAGE pStubMsg
,
2624 PFORMAT_STRING pFormat
)
2630 /***********************************************************************
2631 * NdrConformantVaryingStructFree [RPCRT4.@]
2633 void WINAPI
NdrConformantVaryingStructFree(PMIDL_STUB_MESSAGE pStubMsg
,
2634 unsigned char *pMemory
,
2635 PFORMAT_STRING pFormat
)
2640 /***********************************************************************
2641 * NdrFixedArrayMarshall [RPCRT4.@]
2643 unsigned char * WINAPI
NdrFixedArrayMarshall(PMIDL_STUB_MESSAGE pStubMsg
,
2644 unsigned char *pMemory
,
2645 PFORMAT_STRING pFormat
)
2651 /***********************************************************************
2652 * NdrFixedArrayUnmarshall [RPCRT4.@]
2654 unsigned char * WINAPI
NdrFixedArrayUnmarshall(PMIDL_STUB_MESSAGE pStubMsg
,
2655 unsigned char **ppMemory
,
2656 PFORMAT_STRING pFormat
,
2657 unsigned char fMustAlloc
)
2663 /***********************************************************************
2664 * NdrFixedArrayBufferSize [RPCRT4.@]
2666 void WINAPI
NdrFixedArrayBufferSize(PMIDL_STUB_MESSAGE pStubMsg
,
2667 unsigned char *pMemory
,
2668 PFORMAT_STRING pFormat
)
2673 /***********************************************************************
2674 * NdrFixedArrayMemorySize [RPCRT4.@]
2676 unsigned long WINAPI
NdrFixedArrayMemorySize(PMIDL_STUB_MESSAGE pStubMsg
,
2677 PFORMAT_STRING pFormat
)
2683 /***********************************************************************
2684 * NdrFixedArrayFree [RPCRT4.@]
2686 void WINAPI
NdrFixedArrayFree(PMIDL_STUB_MESSAGE pStubMsg
,
2687 unsigned char *pMemory
,
2688 PFORMAT_STRING pFormat
)
2693 /***********************************************************************
2694 * NdrVaryingArrayMarshall [RPCRT4.@]
2696 unsigned char * WINAPI
NdrVaryingArrayMarshall(PMIDL_STUB_MESSAGE pStubMsg
,
2697 unsigned char *pMemory
,
2698 PFORMAT_STRING pFormat
)
2704 /***********************************************************************
2705 * NdrVaryingArrayUnmarshall [RPCRT4.@]
2707 unsigned char * WINAPI
NdrVaryingArrayUnmarshall(PMIDL_STUB_MESSAGE pStubMsg
,
2708 unsigned char **ppMemory
,
2709 PFORMAT_STRING pFormat
,
2710 unsigned char fMustAlloc
)
2716 /***********************************************************************
2717 * NdrVaryingArrayBufferSize [RPCRT4.@]
2719 void WINAPI
NdrVaryingArrayBufferSize(PMIDL_STUB_MESSAGE pStubMsg
,
2720 unsigned char *pMemory
,
2721 PFORMAT_STRING pFormat
)
2726 /***********************************************************************
2727 * NdrVaryingArrayMemorySize [RPCRT4.@]
2729 unsigned long WINAPI
NdrVaryingArrayMemorySize(PMIDL_STUB_MESSAGE pStubMsg
,
2730 PFORMAT_STRING pFormat
)
2736 /***********************************************************************
2737 * NdrVaryingArrayFree [RPCRT4.@]
2739 void WINAPI
NdrVaryingArrayFree(PMIDL_STUB_MESSAGE pStubMsg
,
2740 unsigned char *pMemory
,
2741 PFORMAT_STRING pFormat
)
2746 /***********************************************************************
2747 * NdrEncapsulatedUnionMarshall [RPCRT4.@]
2749 unsigned char * WINAPI
NdrEncapsulatedUnionMarshall(PMIDL_STUB_MESSAGE pStubMsg
,
2750 unsigned char *pMemory
,
2751 PFORMAT_STRING pFormat
)
2757 /***********************************************************************
2758 * NdrEncapsulatedUnionUnmarshall [RPCRT4.@]
2760 unsigned char * WINAPI
NdrEncapsulatedUnionUnmarshall(PMIDL_STUB_MESSAGE pStubMsg
,
2761 unsigned char **ppMemory
,
2762 PFORMAT_STRING pFormat
,
2763 unsigned char fMustAlloc
)
2769 /***********************************************************************
2770 * NdrEncapsulatedUnionBufferSize [RPCRT4.@]
2772 void WINAPI
NdrEncapsulatedUnionBufferSize(PMIDL_STUB_MESSAGE pStubMsg
,
2773 unsigned char *pMemory
,
2774 PFORMAT_STRING pFormat
)
2779 /***********************************************************************
2780 * NdrEncapsulatedUnionMemorySize [RPCRT4.@]
2782 unsigned long WINAPI
NdrEncapsulatedUnionMemorySize(PMIDL_STUB_MESSAGE pStubMsg
,
2783 PFORMAT_STRING pFormat
)
2789 /***********************************************************************
2790 * NdrEncapsulatedUnionFree [RPCRT4.@]
2792 void WINAPI
NdrEncapsulatedUnionFree(PMIDL_STUB_MESSAGE pStubMsg
,
2793 unsigned char *pMemory
,
2794 PFORMAT_STRING pFormat
)
2799 /***********************************************************************
2800 * NdrNonEncapsulatedUnionMarshall [RPCRT4.@]
2802 unsigned char * WINAPI
NdrNonEncapsulatedUnionMarshall(PMIDL_STUB_MESSAGE pStubMsg
,
2803 unsigned char *pMemory
,
2804 PFORMAT_STRING pFormat
)
2810 /***********************************************************************
2811 * NdrNonEncapsulatedUnionUnmarshall [RPCRT4.@]
2813 unsigned char * WINAPI
NdrNonEncapsulatedUnionUnmarshall(PMIDL_STUB_MESSAGE pStubMsg
,
2814 unsigned char **ppMemory
,
2815 PFORMAT_STRING pFormat
,
2816 unsigned char fMustAlloc
)
2822 /***********************************************************************
2823 * NdrNonEncapsulatedUnionBufferSize [RPCRT4.@]
2825 void WINAPI
NdrNonEncapsulatedUnionBufferSize(PMIDL_STUB_MESSAGE pStubMsg
,
2826 unsigned char *pMemory
,
2827 PFORMAT_STRING pFormat
)
2832 /***********************************************************************
2833 * NdrNonEncapsulatedUnionMemorySize [RPCRT4.@]
2835 unsigned long WINAPI
NdrNonEncapsulatedUnionMemorySize(PMIDL_STUB_MESSAGE pStubMsg
,
2836 PFORMAT_STRING pFormat
)
2842 /***********************************************************************
2843 * NdrNonEncapsulatedUnionFree [RPCRT4.@]
2845 void WINAPI
NdrNonEncapsulatedUnionFree(PMIDL_STUB_MESSAGE pStubMsg
,
2846 unsigned char *pMemory
,
2847 PFORMAT_STRING pFormat
)
2852 /***********************************************************************
2853 * NdrByteCountPointerMarshall [RPCRT4.@]
2855 unsigned char * WINAPI
NdrByteCountPointerMarshall(PMIDL_STUB_MESSAGE pStubMsg
,
2856 unsigned char *pMemory
,
2857 PFORMAT_STRING pFormat
)
2863 /***********************************************************************
2864 * NdrByteCountPointerUnmarshall [RPCRT4.@]
2866 unsigned char * WINAPI
NdrByteCountPointerUnmarshall(PMIDL_STUB_MESSAGE pStubMsg
,
2867 unsigned char **ppMemory
,
2868 PFORMAT_STRING pFormat
,
2869 unsigned char fMustAlloc
)
2875 /***********************************************************************
2876 * NdrByteCountPointerBufferSize [RPCRT4.@]
2878 void WINAPI
NdrByteCountPointerBufferSize(PMIDL_STUB_MESSAGE pStubMsg
,
2879 unsigned char *pMemory
,
2880 PFORMAT_STRING pFormat
)
2885 /***********************************************************************
2886 * NdrByteCountPointerMemorySize [RPCRT4.@]
2888 unsigned long WINAPI
NdrByteCountPointerMemorySize(PMIDL_STUB_MESSAGE pStubMsg
,
2889 PFORMAT_STRING pFormat
)
2895 /***********************************************************************
2896 * NdrByteCountPointerFree [RPCRT4.@]
2898 void WINAPI
NdrByteCountPointerFree(PMIDL_STUB_MESSAGE pStubMsg
,
2899 unsigned char *pMemory
,
2900 PFORMAT_STRING pFormat
)
2905 /***********************************************************************
2906 * NdrXmitOrRepAsMarshall [RPCRT4.@]
2908 unsigned char * WINAPI
NdrXmitOrRepAsMarshall(PMIDL_STUB_MESSAGE pStubMsg
,
2909 unsigned char *pMemory
,
2910 PFORMAT_STRING pFormat
)
2916 /***********************************************************************
2917 * NdrXmitOrRepAsUnmarshall [RPCRT4.@]
2919 unsigned char * WINAPI
NdrXmitOrRepAsUnmarshall(PMIDL_STUB_MESSAGE pStubMsg
,
2920 unsigned char **ppMemory
,
2921 PFORMAT_STRING pFormat
,
2922 unsigned char fMustAlloc
)
2928 /***********************************************************************
2929 * NdrXmitOrRepAsBufferSize [RPCRT4.@]
2931 void WINAPI
NdrXmitOrRepAsBufferSize(PMIDL_STUB_MESSAGE pStubMsg
,
2932 unsigned char *pMemory
,
2933 PFORMAT_STRING pFormat
)
2938 /***********************************************************************
2939 * NdrXmitOrRepAsMemorySize [RPCRT4.@]
2941 unsigned long WINAPI
NdrXmitOrRepAsMemorySize(PMIDL_STUB_MESSAGE pStubMsg
,
2942 PFORMAT_STRING pFormat
)
2948 /***********************************************************************
2949 * NdrXmitOrRepAsFree [RPCRT4.@]
2951 void WINAPI
NdrXmitOrRepAsFree(PMIDL_STUB_MESSAGE pStubMsg
,
2952 unsigned char *pMemory
,
2953 PFORMAT_STRING pFormat
)
2958 /***********************************************************************
2959 * NdrBaseTypeMarshall [internal]
2961 static unsigned char *WINAPI
NdrBaseTypeMarshall(
2962 PMIDL_STUB_MESSAGE pStubMsg
,
2963 unsigned char *pMemory
,
2964 PFORMAT_STRING pFormat
)
2966 TRACE("pStubMsg %p, pMemory %p, type 0x%02x\n", pStubMsg
, pMemory
, *pFormat
);
2974 *(UCHAR
*)pStubMsg
->Buffer
= *(UCHAR
*)pMemory
;
2975 pStubMsg
->Buffer
+= sizeof(UCHAR
);
2976 TRACE("value: 0x%02x\n", *(UCHAR
*)pMemory
);
2981 ALIGN_POINTER(pStubMsg
->Buffer
, sizeof(USHORT
) - 1);
2982 *(USHORT
*)pStubMsg
->Buffer
= *(USHORT
*)pMemory
;
2983 pStubMsg
->Buffer
+= sizeof(USHORT
);
2984 TRACE("value: 0x%04x\n", *(USHORT
*)pMemory
);
2988 case RPC_FC_ERROR_STATUS_T
:
2990 ALIGN_POINTER(pStubMsg
->Buffer
, sizeof(ULONG
) - 1);
2991 *(ULONG
*)pStubMsg
->Buffer
= *(ULONG
*)pMemory
;
2992 pStubMsg
->Buffer
+= sizeof(ULONG
);
2993 TRACE("value: 0x%08lx\n", *(ULONG
*)pMemory
);
2996 ALIGN_POINTER(pStubMsg
->Buffer
, sizeof(float) - 1);
2997 *(float *)pStubMsg
->Buffer
= *(float *)pMemory
;
2998 pStubMsg
->Buffer
+= sizeof(float);
3001 ALIGN_POINTER(pStubMsg
->Buffer
, sizeof(double) - 1);
3002 *(double *)pStubMsg
->Buffer
= *(double *)pMemory
;
3003 pStubMsg
->Buffer
+= sizeof(double);
3006 ALIGN_POINTER(pStubMsg
->Buffer
, sizeof(ULONGLONG
) - 1);
3007 *(ULONGLONG
*)pStubMsg
->Buffer
= *(ULONGLONG
*)pMemory
;
3008 pStubMsg
->Buffer
+= sizeof(ULONGLONG
);
3009 TRACE("value: %s\n", wine_dbgstr_longlong(*(ULONGLONG
*)pMemory
));
3012 /* only 16-bits on the wire, so do a sanity check */
3013 if (*(UINT
*)pMemory
> USHRT_MAX
)
3014 RpcRaiseException(RPC_X_ENUM_VALUE_OUT_OF_RANGE
);
3015 ALIGN_POINTER(pStubMsg
->Buffer
, sizeof(USHORT
) - 1);
3016 *(USHORT
*)pStubMsg
->Buffer
= *(UINT
*)pMemory
;
3017 pStubMsg
->Buffer
+= sizeof(USHORT
);
3018 TRACE("value: 0x%04x\n", *(UINT
*)pMemory
);
3021 FIXME("Unhandled base type: 0x%02x\n", *pFormat
);
3024 STD_OVERFLOW_CHECK(pStubMsg
);
3026 /* FIXME: what is the correct return value? */
3030 /***********************************************************************
3031 * NdrBaseTypeUnmarshall [internal]
3033 static unsigned char *WINAPI
NdrBaseTypeUnmarshall(
3034 PMIDL_STUB_MESSAGE pStubMsg
,
3035 unsigned char **ppMemory
,
3036 PFORMAT_STRING pFormat
,
3037 unsigned char fMustAlloc
)
3039 TRACE("pStubMsg: %p, ppMemory: %p, type: 0x%02x, fMustAlloc: %s\n", pStubMsg
, ppMemory
, *pFormat
, fMustAlloc
? "true" : "false");
3041 if (fMustAlloc
|| !*ppMemory
)
3042 *ppMemory
= NdrAllocate(pStubMsg
, NdrBaseTypeMemorySize(pStubMsg
, pFormat
));
3044 TRACE("*ppMemory: %p\n", *ppMemory
);
3052 **(UCHAR
**)ppMemory
= *(UCHAR
*)pStubMsg
->Buffer
;
3053 pStubMsg
->Buffer
+= sizeof(UCHAR
);
3054 TRACE("value: 0x%02x\n", **(UCHAR
**)ppMemory
);
3059 ALIGN_POINTER(pStubMsg
->Buffer
, sizeof(USHORT
) - 1);
3060 **(USHORT
**)ppMemory
= *(USHORT
*)pStubMsg
->Buffer
;
3061 pStubMsg
->Buffer
+= sizeof(USHORT
);
3062 TRACE("value: 0x%04x\n", **(USHORT
**)ppMemory
);
3066 case RPC_FC_ERROR_STATUS_T
:
3068 ALIGN_POINTER(pStubMsg
->Buffer
, sizeof(ULONG
) - 1);
3069 **(ULONG
**)ppMemory
= *(ULONG
*)pStubMsg
->Buffer
;
3070 pStubMsg
->Buffer
+= sizeof(ULONG
);
3071 TRACE("value: 0x%08lx\n", **(ULONG
**)ppMemory
);
3074 ALIGN_POINTER(pStubMsg
->Buffer
, sizeof(float) - 1);
3075 **(float **)ppMemory
= *(float *)pStubMsg
->Buffer
;
3076 pStubMsg
->Buffer
+= sizeof(float);
3077 TRACE("value: %f\n", **(float **)ppMemory
);
3080 ALIGN_POINTER(pStubMsg
->Buffer
, sizeof(double) - 1);
3081 **(double **)ppMemory
= *(double*)pStubMsg
->Buffer
;
3082 pStubMsg
->Buffer
+= sizeof(double);
3083 TRACE("value: %f\n", **(double **)ppMemory
);
3086 ALIGN_POINTER(pStubMsg
->Buffer
, sizeof(ULONGLONG
) - 1);
3087 **(ULONGLONG
**)ppMemory
= *(ULONGLONG
*)pStubMsg
->Buffer
;
3088 pStubMsg
->Buffer
+= sizeof(ULONGLONG
);
3089 TRACE("value: %s\n", wine_dbgstr_longlong(**(ULONGLONG
**)ppMemory
));
3092 ALIGN_POINTER(pStubMsg
->Buffer
, sizeof(USHORT
) - 1);
3093 /* 16-bits on the wire, but int in memory */
3094 **(UINT
**)ppMemory
= *(USHORT
*)pStubMsg
->Buffer
;
3095 pStubMsg
->Buffer
+= sizeof(USHORT
);
3096 TRACE("value: 0x%08x\n", **(UINT
**)ppMemory
);
3099 FIXME("Unhandled base type: 0x%02x\n", *pFormat
);
3102 /* FIXME: what is the correct return value? */
3107 /***********************************************************************
3108 * NdrBaseTypeBufferSize [internal]
3110 static void WINAPI
NdrBaseTypeBufferSize(
3111 PMIDL_STUB_MESSAGE pStubMsg
,
3112 unsigned char *pMemory
,
3113 PFORMAT_STRING pFormat
)
3115 TRACE("pStubMsg %p, pMemory %p, type 0x%02x\n", pStubMsg
, pMemory
, *pFormat
);
3123 pStubMsg
->BufferLength
+= sizeof(UCHAR
);
3129 ALIGN_LENGTH(pStubMsg
->BufferLength
, sizeof(USHORT
) - 1);
3130 pStubMsg
->BufferLength
+= sizeof(USHORT
);
3135 ALIGN_LENGTH(pStubMsg
->BufferLength
, sizeof(ULONG
) - 1);
3136 pStubMsg
->BufferLength
+= sizeof(ULONG
);
3139 ALIGN_LENGTH(pStubMsg
->BufferLength
, sizeof(float) - 1);
3140 pStubMsg
->BufferLength
+= sizeof(float);
3143 ALIGN_LENGTH(pStubMsg
->BufferLength
, sizeof(double) - 1);
3144 pStubMsg
->BufferLength
+= sizeof(double);
3147 ALIGN_LENGTH(pStubMsg
->BufferLength
, sizeof(ULONGLONG
) - 1);
3148 pStubMsg
->BufferLength
+= sizeof(ULONGLONG
);
3150 case RPC_FC_ERROR_STATUS_T
:
3151 ALIGN_LENGTH(pStubMsg
->BufferLength
, sizeof(error_status_t
) - 1);
3152 pStubMsg
->BufferLength
+= sizeof(error_status_t
);
3155 FIXME("Unhandled base type: 0x%02x\n", *pFormat
);
3159 /***********************************************************************
3160 * NdrBaseTypeMemorySize [internal]
3162 static unsigned long WINAPI
NdrBaseTypeMemorySize(
3163 PMIDL_STUB_MESSAGE pStubMsg
,
3164 PFORMAT_STRING pFormat
)
3172 return sizeof(UCHAR
);
3176 return sizeof(USHORT
);
3179 return sizeof(ULONG
);
3181 return sizeof(float);
3183 return sizeof(double);
3185 return sizeof(ULONGLONG
);
3186 case RPC_FC_ERROR_STATUS_T
:
3187 return sizeof(error_status_t
);
3192 FIXME("Unhandled base type: 0x%02x\n", *pFormat
);
3197 /***********************************************************************
3198 * NdrBaseTypeFree [internal]
3200 static void WINAPI
NdrBaseTypeFree(PMIDL_STUB_MESSAGE pStubMsg
,
3201 unsigned char *pMemory
,
3202 PFORMAT_STRING pFormat
)
3204 TRACE("pStubMsg %p pMemory %p type 0x%02x\n", pStubMsg
, pMemory
, *pFormat
);
3209 /***********************************************************************
3210 * NdrClientContextMarshall
3212 void WINAPI
NdrClientContextMarshall(PMIDL_STUB_MESSAGE pStubMsg
,
3213 NDR_CCONTEXT ContextHandle
,
3216 FIXME("(%p, %p, %d): stub\n", pStubMsg
, ContextHandle
, fCheck
);
3219 /***********************************************************************
3220 * NdrClientContextUnmarshall
3222 void WINAPI
NdrClientContextUnmarshall(PMIDL_STUB_MESSAGE pStubMsg
,
3223 NDR_CCONTEXT
* pContextHandle
,
3224 RPC_BINDING_HANDLE BindHandle
)
3226 FIXME("(%p, %p, %p): stub\n", pStubMsg
, pContextHandle
, BindHandle
);
3229 void WINAPI
NdrServerContextMarshall(PMIDL_STUB_MESSAGE pStubMsg
,
3230 NDR_SCONTEXT ContextHandle
,
3231 NDR_RUNDOWN RundownRoutine
)
3233 FIXME("(%p, %p, %p): stub\n", pStubMsg
, ContextHandle
, RundownRoutine
);
3236 NDR_SCONTEXT WINAPI
NdrServerContextUnmarshall(PMIDL_STUB_MESSAGE pStubMsg
)
3238 FIXME("(%p): stub\n", pStubMsg
);
3242 void WINAPI
NdrContextHandleSize(PMIDL_STUB_MESSAGE pStubMsg
,
3243 unsigned char* pMemory
,
3244 PFORMAT_STRING pFormat
)
3246 FIXME("(%p, %p, %p): stub\n", pStubMsg
, pMemory
, pFormat
);
3249 NDR_SCONTEXT WINAPI
NdrContextHandleInitialize(PMIDL_STUB_MESSAGE pStubMsg
,
3250 PFORMAT_STRING pFormat
)
3252 FIXME("(%p, %p): stub\n", pStubMsg
, pFormat
);
3256 void WINAPI
NdrServerContextNewMarshall(PMIDL_STUB_MESSAGE pStubMsg
,
3257 NDR_SCONTEXT ContextHandle
,
3258 NDR_RUNDOWN RundownRoutine
,
3259 PFORMAT_STRING pFormat
)
3261 FIXME("(%p, %p, %p, %p): stub\n", pStubMsg
, ContextHandle
, RundownRoutine
, pFormat
);
3264 NDR_SCONTEXT WINAPI
NdrServerContextNewUnmarshall(PMIDL_STUB_MESSAGE pStubMsg
,
3265 PFORMAT_STRING pFormat
)
3267 FIXME("(%p, %p): stub\n", pStubMsg
, pFormat
);
3271 RPC_BINDING_HANDLE WINAPI
NDRCContextBinding(NDR_CCONTEXT CContext
)
3273 FIXME("(%p): stub\n", CContext
);