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
:
379 unsigned char *old_stack_top
= pStubMsg
->StackTop
;
380 pStubMsg
->StackTop
= ptr
;
382 /* ofs is index into StubDesc->apfnExprEval */
383 TRACE("callback conformance into apfnExprEval[%d]\n", ofs
);
384 pStubMsg
->StubDesc
->apfnExprEval
[ofs
](pStubMsg
);
386 pStubMsg
->StackTop
= old_stack_top
;
402 data
= *(USHORT
*)ptr
;
411 FIXME("unknown conformance data type %x\n", dtype
);
414 TRACE("dereferenced data type %x at %p, got %ld\n", dtype
, ptr
, data
);
417 switch (pFormat
[1]) {
421 case RPC_FC_DEREFERENCE
:
422 /* already handled */
425 FIXME("unknown conformance op %d\n", pFormat
[1]);
430 TRACE("resulting conformance is %ld\n", *pCount
);
436 * NdrConformantString:
438 * What MS calls a ConformantString is, in DCE terminology,
439 * a Varying-Conformant String.
441 * maxlen: DWORD (max # of CHARTYPE characters, inclusive of '\0')
442 * offset: DWORD (actual string data begins at (offset) CHARTYPE's
443 * into unmarshalled string)
444 * length: DWORD (# of CHARTYPE characters, inclusive of '\0')
446 * data: CHARTYPE[maxlen]
448 * ], where CHARTYPE is the appropriate character type (specified externally)
452 /***********************************************************************
453 * NdrConformantStringMarshall [RPCRT4.@]
455 unsigned char *WINAPI
NdrConformantStringMarshall(MIDL_STUB_MESSAGE
*pStubMsg
,
456 unsigned char *pszMessage
, PFORMAT_STRING pFormat
)
458 unsigned long len
, esize
;
461 TRACE("(pStubMsg == ^%p, pszMessage == ^%p, pFormat == ^%p)\n", pStubMsg
, pszMessage
, pFormat
);
464 if (pszMessage
== NULL
) {
465 TRACE("string=%s\n", debugstr_a(pszMessage
));
469 else if (*pFormat
== RPC_FC_C_CSTRING
) {
470 TRACE("string=%s\n", debugstr_a(pszMessage
));
471 len
= strlen(pszMessage
)+1;
474 else if (*pFormat
== RPC_FC_C_WSTRING
) {
475 TRACE("string=%s\n", debugstr_w((LPWSTR
)pszMessage
));
476 len
= strlenW((LPWSTR
)pszMessage
)+1;
480 ERR("Unhandled string type: %#x\n", *pFormat
);
481 /* FIXME: raise an exception. */
485 if (pFormat
[1] != RPC_FC_PAD
) {
486 FIXME("sized string format=%d\n", pFormat
[1]);
489 assert( (pStubMsg
->BufferLength
>= (len
*esize
+ 13)) && (pStubMsg
->Buffer
!= NULL
) );
491 c
= pStubMsg
->Buffer
;
493 NDR_LOCAL_UINT32_WRITE(c
, len
); /* max length: strlen + 1 (for '\0') */
494 c
+= 8; /* offset: 0 */
495 NDR_LOCAL_UINT32_WRITE(c
, len
); /* actual length: (same) */
498 memcpy(c
, pszMessage
, len
*esize
); /* the string itself */
501 pStubMsg
->Buffer
= c
;
503 STD_OVERFLOW_CHECK(pStubMsg
);
506 return NULL
; /* is this always right? */
509 /***********************************************************************
510 * NdrConformantStringBufferSize [RPCRT4.@]
512 void WINAPI
NdrConformantStringBufferSize(PMIDL_STUB_MESSAGE pStubMsg
,
513 unsigned char* pMemory
, PFORMAT_STRING pFormat
)
515 TRACE("(pStubMsg == ^%p, pMemory == ^%p, pFormat == ^%p)\n", pStubMsg
, pMemory
, pFormat
);
518 if (pMemory
== NULL
) {
519 /* we need 12 octets for the [maxlen, offset, len] DWORDS */
520 TRACE("string=NULL\n");
521 pStubMsg
->BufferLength
+= 12 + BUFFER_PARANOIA
;
523 else if (*pFormat
== RPC_FC_C_CSTRING
) {
524 /* we need 12 octets for the [maxlen, offset, len] DWORDS, + 1 octet for '\0' */
525 TRACE("string=%s\n", debugstr_a((char*)pMemory
));
526 pStubMsg
->BufferLength
+= strlen((char*)pMemory
) + 13 + BUFFER_PARANOIA
;
528 else if (*pFormat
== RPC_FC_C_WSTRING
) {
529 /* we need 12 octets for the [maxlen, offset, len] DWORDS, + 2 octets for L'\0' */
530 TRACE("string=%s\n", debugstr_w((LPWSTR
)pMemory
));
531 pStubMsg
->BufferLength
+= strlenW((LPWSTR
)pMemory
)*2 + 14 + BUFFER_PARANOIA
;
534 ERR("Unhandled string type: %#x\n", *pFormat
);
535 /* FIXME: raise an exception */
538 if (pFormat
[1] != RPC_FC_PAD
) {
539 FIXME("sized string format=%d\n", pFormat
[1]);
543 /************************************************************************
544 * NdrConformantStringMemorySize [RPCRT4.@]
546 unsigned long WINAPI
NdrConformantStringMemorySize( PMIDL_STUB_MESSAGE pStubMsg
,
547 PFORMAT_STRING pFormat
)
549 unsigned long rslt
= 0;
551 TRACE("(pStubMsg == ^%p, pFormat == ^%p)\n", pStubMsg
, pFormat
);
553 assert(pStubMsg
&& pFormat
);
555 if (*pFormat
== RPC_FC_C_CSTRING
) {
556 rslt
= NDR_LOCAL_UINT32_READ(pStubMsg
->Buffer
); /* maxlen */
558 else if (*pFormat
== RPC_FC_C_WSTRING
) {
559 rslt
= NDR_LOCAL_UINT32_READ(pStubMsg
->Buffer
)*2; /* maxlen */
562 ERR("Unhandled string type: %#x\n", *pFormat
);
563 /* FIXME: raise an exception */
566 if (pFormat
[1] != RPC_FC_PAD
) {
567 FIXME("sized string format=%d\n", pFormat
[1]);
570 TRACE(" --> %lu\n", rslt
);
574 /************************************************************************
575 * NdrConformantStringUnmarshall [RPCRT4.@]
577 unsigned char *WINAPI
NdrConformantStringUnmarshall( PMIDL_STUB_MESSAGE pStubMsg
,
578 unsigned char** ppMemory
, PFORMAT_STRING pFormat
, unsigned char fMustAlloc
)
580 unsigned long len
, esize
, ofs
;
582 TRACE("(pStubMsg == ^%p, *pMemory == ^%p, pFormat == ^%p, fMustAlloc == %u)\n",
583 pStubMsg
, *ppMemory
, pFormat
, fMustAlloc
);
585 assert(pFormat
&& ppMemory
&& pStubMsg
);
587 pStubMsg
->Buffer
+= 4;
588 ofs
= NDR_LOCAL_UINT32_READ(pStubMsg
->Buffer
);
589 pStubMsg
->Buffer
+= 4;
590 len
= NDR_LOCAL_UINT32_READ(pStubMsg
->Buffer
);
591 pStubMsg
->Buffer
+= 4;
593 if (*pFormat
== RPC_FC_C_CSTRING
) esize
= 1;
594 else if (*pFormat
== RPC_FC_C_WSTRING
) esize
= 2;
596 ERR("Unhandled string type: %#x\n", *pFormat
);
597 /* FIXME: raise an exception */
601 if (pFormat
[1] != RPC_FC_PAD
) {
602 FIXME("sized string format=%d\n", pFormat
[1]);
605 if (fMustAlloc
|| !*ppMemory
)
606 *ppMemory
= NdrAllocate(pStubMsg
, len
*esize
+ BUFFER_PARANOIA
);
608 memcpy(*ppMemory
, pStubMsg
->Buffer
, len
*esize
);
610 pStubMsg
->Buffer
+= len
*esize
;
612 if (*pFormat
== RPC_FC_C_CSTRING
) {
613 TRACE("string=%s\n", debugstr_a((char*)*ppMemory
));
615 else if (*pFormat
== RPC_FC_C_WSTRING
) {
616 TRACE("string=%s\n", debugstr_w((LPWSTR
)*ppMemory
));
619 return NULL
; /* FIXME: is this always right? */
622 /***********************************************************************
623 * NdrNonConformantStringMarshall [RPCRT4.@]
625 unsigned char * WINAPI
NdrNonConformantStringMarshall(PMIDL_STUB_MESSAGE pStubMsg
,
626 unsigned char *pMemory
,
627 PFORMAT_STRING pFormat
)
633 /***********************************************************************
634 * NdrNonConformantStringUnmarshall [RPCRT4.@]
636 unsigned char * WINAPI
NdrNonConformantStringUnmarshall(PMIDL_STUB_MESSAGE pStubMsg
,
637 unsigned char **ppMemory
,
638 PFORMAT_STRING pFormat
,
639 unsigned char fMustAlloc
)
645 /***********************************************************************
646 * NdrNonConformantStringBufferSize [RPCRT4.@]
648 void WINAPI
NdrNonConformantStringBufferSize(PMIDL_STUB_MESSAGE pStubMsg
,
649 unsigned char *pMemory
,
650 PFORMAT_STRING pFormat
)
655 /***********************************************************************
656 * NdrNonConformantStringMemorySize [RPCRT4.@]
658 unsigned long WINAPI
NdrNonConformantStringMemorySize(PMIDL_STUB_MESSAGE pStubMsg
,
659 PFORMAT_STRING pFormat
)
665 static inline void dump_pointer_attr(unsigned char attr
)
667 if (attr
& RPC_FC_P_ALLOCALLNODES
)
668 TRACE(" RPC_FC_P_ALLOCALLNODES");
669 if (attr
& RPC_FC_P_DONTFREE
)
670 TRACE(" RPC_FC_P_DONTFREE");
671 if (attr
& RPC_FC_P_ONSTACK
)
672 TRACE(" RPC_FC_P_ONSTACK");
673 if (attr
& RPC_FC_P_SIMPLEPOINTER
)
674 TRACE(" RPC_FC_P_SIMPLEPOINTER");
675 if (attr
& RPC_FC_P_DEREF
)
676 TRACE(" RPC_FC_P_DEREF");
680 /***********************************************************************
683 void WINAPI
PointerMarshall(PMIDL_STUB_MESSAGE pStubMsg
,
684 unsigned char *Buffer
,
685 unsigned char *Pointer
,
686 PFORMAT_STRING pFormat
)
688 unsigned type
= pFormat
[0], attr
= pFormat
[1];
692 TRACE("(%p,%p,%p,%p)\n", pStubMsg
, Buffer
, Pointer
, pFormat
);
693 TRACE("type=0x%x, attr=", type
); dump_pointer_attr(attr
);
695 if (attr
& RPC_FC_P_SIMPLEPOINTER
) desc
= pFormat
;
696 else desc
= pFormat
+ *(const SHORT
*)pFormat
;
697 if (attr
& RPC_FC_P_DEREF
) {
698 Pointer
= *(unsigned char**)Pointer
;
699 TRACE("deref => %p\n", Pointer
);
703 case RPC_FC_RP
: /* ref pointer (always non-null) */
704 #if 0 /* this causes problems for InstallShield so is disabled - we need more tests */
706 RpcRaiseException(RPC_X_NULL_REF_POINTER
);
709 case RPC_FC_UP
: /* unique pointer */
710 case RPC_FC_OP
: /* object pointer - same as unique here */
711 TRACE("writing %p to buffer\n", Pointer
);
712 NDR_LOCAL_UINT32_WRITE(pStubMsg
->Buffer
, (unsigned long)Pointer
);
713 pStubMsg
->Buffer
+= 4;
717 FIXME("unhandled ptr type=%02x\n", type
);
718 RpcRaiseException(RPC_X_BAD_STUB_DATA
);
721 TRACE("calling marshaller for type 0x%x\n", (int)*desc
);
724 m
= NdrMarshaller
[*desc
& NDR_TABLE_MASK
];
725 if (m
) m(pStubMsg
, Pointer
, desc
);
726 else FIXME("no marshaller for data type=%02x\n", *desc
);
729 STD_OVERFLOW_CHECK(pStubMsg
);
732 /***********************************************************************
735 void WINAPI
PointerUnmarshall(PMIDL_STUB_MESSAGE pStubMsg
,
736 unsigned char *Buffer
,
737 unsigned char **pPointer
,
738 PFORMAT_STRING pFormat
,
739 unsigned char fMustAlloc
)
741 unsigned type
= pFormat
[0], attr
= pFormat
[1];
744 DWORD pointer_id
= 0;
746 TRACE("(%p,%p,%p,%p,%d)\n", pStubMsg
, Buffer
, pPointer
, pFormat
, fMustAlloc
);
747 TRACE("type=0x%x, attr=", type
); dump_pointer_attr(attr
);
749 if (attr
& RPC_FC_P_SIMPLEPOINTER
) desc
= pFormat
;
750 else desc
= pFormat
+ *(const SHORT
*)pFormat
;
751 if (attr
& RPC_FC_P_DEREF
) {
752 pPointer
= *(unsigned char***)pPointer
;
753 TRACE("deref => %p\n", pPointer
);
757 case RPC_FC_RP
: /* ref pointer (always non-null) */
760 case RPC_FC_UP
: /* unique pointer */
761 pointer_id
= NDR_LOCAL_UINT32_READ(pStubMsg
->Buffer
);
762 pStubMsg
->Buffer
+= 4;
764 case RPC_FC_OP
: /* object pointer - we must free data before overwriting it */
765 pointer_id
= NDR_LOCAL_UINT32_READ(pStubMsg
->Buffer
);
766 pStubMsg
->Buffer
+= 4;
768 FIXME("free object pointer %p\n", *pPointer
);
772 FIXME("unhandled ptr type=%02x\n", type
);
773 RpcRaiseException(RPC_X_BAD_STUB_DATA
);
777 m
= NdrUnmarshaller
[*desc
& NDR_TABLE_MASK
];
778 if (m
) m(pStubMsg
, pPointer
, desc
, fMustAlloc
);
779 else FIXME("no unmarshaller for data type=%02x\n", *desc
);
782 TRACE("pointer=%p\n", *pPointer
);
785 /***********************************************************************
788 void WINAPI
PointerBufferSize(PMIDL_STUB_MESSAGE pStubMsg
,
789 unsigned char *Pointer
,
790 PFORMAT_STRING pFormat
)
792 unsigned type
= pFormat
[0], attr
= pFormat
[1];
796 TRACE("(%p,%p,%p)\n", pStubMsg
, Pointer
, pFormat
);
797 TRACE("type=%d, attr=%d\n", type
, attr
);
799 if (attr
& RPC_FC_P_SIMPLEPOINTER
) desc
= pFormat
;
800 else desc
= pFormat
+ *(const SHORT
*)pFormat
;
801 if (attr
& RPC_FC_P_DEREF
) {
802 Pointer
= *(unsigned char**)Pointer
;
803 TRACE("deref => %p\n", Pointer
);
807 case RPC_FC_RP
: /* ref pointer (always non-null) */
811 pStubMsg
->BufferLength
+= 4;
812 /* NULL pointer has no further representation */
818 FIXME("unhandled ptr type=%02x\n", type
);
819 RpcRaiseException(RPC_X_BAD_STUB_DATA
);
822 m
= NdrBufferSizer
[*desc
& NDR_TABLE_MASK
];
823 if (m
) m(pStubMsg
, Pointer
, desc
);
824 else FIXME("no buffersizer for data type=%02x\n", *desc
);
827 /***********************************************************************
828 * PointerMemorySize [RPCRT4.@]
830 unsigned long WINAPI
PointerMemorySize(PMIDL_STUB_MESSAGE pStubMsg
,
831 unsigned char *Buffer
,
832 PFORMAT_STRING pFormat
)
834 unsigned type
= pFormat
[0], attr
= pFormat
[1];
838 FIXME("(%p,%p,%p): stub\n", pStubMsg
, Buffer
, pFormat
);
839 TRACE("type=%d, attr=", type
); dump_pointer_attr(attr
);
841 if (attr
& RPC_FC_P_SIMPLEPOINTER
) desc
= pFormat
;
842 else desc
= pFormat
+ *(const SHORT
*)pFormat
;
843 if (attr
& RPC_FC_P_DEREF
) {
848 case RPC_FC_RP
: /* ref pointer (always non-null) */
851 FIXME("unhandled ptr type=%02x\n", type
);
852 RpcRaiseException(RPC_X_BAD_STUB_DATA
);
855 m
= NdrMemorySizer
[*desc
& NDR_TABLE_MASK
];
856 if (m
) m(pStubMsg
, desc
);
857 else FIXME("no memorysizer for data type=%02x\n", *desc
);
862 /***********************************************************************
863 * PointerFree [RPCRT4.@]
865 void WINAPI
PointerFree(PMIDL_STUB_MESSAGE pStubMsg
,
866 unsigned char *Pointer
,
867 PFORMAT_STRING pFormat
)
869 unsigned type
= pFormat
[0], attr
= pFormat
[1];
873 TRACE("(%p,%p,%p)\n", pStubMsg
, Pointer
, pFormat
);
874 TRACE("type=%d, attr=", type
); dump_pointer_attr(attr
);
875 if (attr
& RPC_FC_P_DONTFREE
) return;
877 if (attr
& RPC_FC_P_SIMPLEPOINTER
) desc
= pFormat
;
878 else desc
= pFormat
+ *(const SHORT
*)pFormat
;
879 if (attr
& RPC_FC_P_DEREF
) {
880 Pointer
= *(unsigned char**)Pointer
;
881 TRACE("deref => %p\n", Pointer
);
884 if (!Pointer
) return;
886 m
= NdrFreer
[*desc
& NDR_TABLE_MASK
];
887 if (m
) m(pStubMsg
, Pointer
, desc
);
889 /* hmm... is this sensible?
890 * perhaps we should check if the memory comes from NdrAllocate,
891 * and deallocate only if so - checking if the pointer is between
892 * BufferStart and BufferEnd is probably no good since the buffer
893 * may be reallocated when the server wants to marshal the reply */
895 case RPC_FC_BOGUS_STRUCT
:
896 case RPC_FC_BOGUS_ARRAY
:
897 case RPC_FC_USER_MARSHAL
:
900 FIXME("unhandled data type=%02x\n", *desc
);
902 case RPC_FC_C_CSTRING
:
903 case RPC_FC_C_WSTRING
:
904 if (pStubMsg
->ReuseBuffer
) goto notfree
;
910 if (attr
& RPC_FC_P_ONSTACK
) {
911 TRACE("not freeing stack ptr %p\n", Pointer
);
914 TRACE("freeing %p\n", Pointer
);
915 NdrFree(pStubMsg
, Pointer
);
918 TRACE("not freeing %p\n", Pointer
);
921 /***********************************************************************
922 * EmbeddedPointerMarshall
924 unsigned char * WINAPI
EmbeddedPointerMarshall(PMIDL_STUB_MESSAGE pStubMsg
,
925 unsigned char *pMemory
,
926 PFORMAT_STRING pFormat
)
928 unsigned char *Mark
= pStubMsg
->BufferMark
;
929 unsigned long Offset
= pStubMsg
->Offset
;
930 unsigned ofs
, rep
, count
, stride
, xofs
;
932 TRACE("(%p,%p,%p)\n", pStubMsg
, pMemory
, pFormat
);
934 if (*pFormat
!= RPC_FC_PP
) return NULL
;
937 while (pFormat
[0] != RPC_FC_END
) {
938 switch (pFormat
[0]) {
940 FIXME("unknown repeat type %d\n", pFormat
[0]);
941 case RPC_FC_NO_REPEAT
:
949 case RPC_FC_FIXED_REPEAT
:
950 rep
= *(const WORD
*)&pFormat
[2];
951 stride
= *(const WORD
*)&pFormat
[4];
952 ofs
= *(const WORD
*)&pFormat
[6];
953 count
= *(const WORD
*)&pFormat
[8];
957 case RPC_FC_VARIABLE_REPEAT
:
958 rep
= pStubMsg
->MaxCount
;
959 stride
= *(const WORD
*)&pFormat
[2];
960 ofs
= *(const WORD
*)&pFormat
[4];
961 count
= *(const WORD
*)&pFormat
[6];
962 xofs
= (pFormat
[1] == RPC_FC_VARIABLE_OFFSET
) ? Offset
* stride
: 0;
966 /* ofs doesn't seem to matter in this context */
968 PFORMAT_STRING info
= pFormat
;
969 unsigned char *membase
= pMemory
+ xofs
;
971 for (u
=0; u
<count
; u
++,info
+=8) {
972 unsigned char *memptr
= membase
+ *(const SHORT
*)&info
[0];
973 unsigned char *bufptr
= Mark
+ *(const SHORT
*)&info
[2];
974 PointerMarshall(pStubMsg
, bufptr
, *(unsigned char**)memptr
, info
+4);
978 pFormat
+= 8 * count
;
981 STD_OVERFLOW_CHECK(pStubMsg
);
986 /***********************************************************************
987 * EmbeddedPointerUnmarshall
989 unsigned char * WINAPI
EmbeddedPointerUnmarshall(PMIDL_STUB_MESSAGE pStubMsg
,
990 unsigned char **ppMemory
,
991 PFORMAT_STRING pFormat
,
992 unsigned char fMustAlloc
)
994 unsigned char *Mark
= pStubMsg
->BufferMark
;
995 unsigned long Offset
= pStubMsg
->Offset
;
996 unsigned ofs
, rep
, count
, stride
, xofs
;
998 TRACE("(%p,%p,%p,%d)\n", pStubMsg
, ppMemory
, pFormat
, fMustAlloc
);
1000 if (*pFormat
!= RPC_FC_PP
) return NULL
;
1003 while (pFormat
[0] != RPC_FC_END
) {
1004 switch (pFormat
[0]) {
1006 FIXME("unknown repeat type %d\n", pFormat
[0]);
1007 case RPC_FC_NO_REPEAT
:
1015 case RPC_FC_FIXED_REPEAT
:
1016 rep
= *(const WORD
*)&pFormat
[2];
1017 stride
= *(const WORD
*)&pFormat
[4];
1018 ofs
= *(const WORD
*)&pFormat
[6];
1019 count
= *(const WORD
*)&pFormat
[8];
1023 case RPC_FC_VARIABLE_REPEAT
:
1024 rep
= pStubMsg
->MaxCount
;
1025 stride
= *(const WORD
*)&pFormat
[2];
1026 ofs
= *(const WORD
*)&pFormat
[4];
1027 count
= *(const WORD
*)&pFormat
[6];
1028 xofs
= (pFormat
[1] == RPC_FC_VARIABLE_OFFSET
) ? Offset
* stride
: 0;
1032 /* ofs doesn't seem to matter in this context */
1034 PFORMAT_STRING info
= pFormat
;
1035 unsigned char *membase
= *ppMemory
+ xofs
;
1037 for (u
=0; u
<count
; u
++,info
+=8) {
1038 unsigned char *memptr
= membase
+ *(const SHORT
*)&info
[0];
1039 unsigned char *bufptr
= Mark
+ *(const SHORT
*)&info
[2];
1040 PointerUnmarshall(pStubMsg
, bufptr
, (unsigned char**)memptr
, info
+4, fMustAlloc
);
1044 pFormat
+= 8 * count
;
1050 /***********************************************************************
1051 * EmbeddedPointerBufferSize
1053 void WINAPI
EmbeddedPointerBufferSize(PMIDL_STUB_MESSAGE pStubMsg
,
1054 unsigned char *pMemory
,
1055 PFORMAT_STRING pFormat
)
1057 unsigned long Offset
= pStubMsg
->Offset
;
1058 unsigned ofs
, rep
, count
, stride
, xofs
;
1060 TRACE("(%p,%p,%p)\n", pStubMsg
, pMemory
, pFormat
);
1061 if (*pFormat
!= RPC_FC_PP
) return;
1064 while (pFormat
[0] != RPC_FC_END
) {
1065 switch (pFormat
[0]) {
1067 FIXME("unknown repeat type %d\n", pFormat
[0]);
1068 case RPC_FC_NO_REPEAT
:
1076 case RPC_FC_FIXED_REPEAT
:
1077 rep
= *(const WORD
*)&pFormat
[2];
1078 stride
= *(const WORD
*)&pFormat
[4];
1079 ofs
= *(const WORD
*)&pFormat
[6];
1080 count
= *(const WORD
*)&pFormat
[8];
1084 case RPC_FC_VARIABLE_REPEAT
:
1085 rep
= pStubMsg
->MaxCount
;
1086 stride
= *(const WORD
*)&pFormat
[2];
1087 ofs
= *(const WORD
*)&pFormat
[4];
1088 count
= *(const WORD
*)&pFormat
[6];
1089 xofs
= (pFormat
[1] == RPC_FC_VARIABLE_OFFSET
) ? Offset
* stride
: 0;
1093 /* ofs doesn't seem to matter in this context */
1095 PFORMAT_STRING info
= pFormat
;
1096 unsigned char *membase
= pMemory
+ xofs
;
1098 for (u
=0; u
<count
; u
++,info
+=8) {
1099 unsigned char *memptr
= membase
+ *(const SHORT
*)&info
[0];
1100 PointerBufferSize(pStubMsg
, *(unsigned char**)memptr
, info
+4);
1104 pFormat
+= 8 * count
;
1108 /***********************************************************************
1109 * EmbeddedPointerMemorySize
1111 unsigned long WINAPI
EmbeddedPointerMemorySize(PMIDL_STUB_MESSAGE pStubMsg
,
1112 PFORMAT_STRING pFormat
)
1114 unsigned long Offset
= pStubMsg
->Offset
;
1115 unsigned char *Mark
= pStubMsg
->BufferMark
;
1116 unsigned ofs
, rep
, count
, stride
, xofs
;
1118 FIXME("(%p,%p): stub\n", pStubMsg
, pFormat
);
1119 if (*pFormat
!= RPC_FC_PP
) return 0;
1122 while (pFormat
[0] != RPC_FC_END
) {
1123 switch (pFormat
[0]) {
1125 FIXME("unknown repeat type %d\n", pFormat
[0]);
1126 case RPC_FC_NO_REPEAT
:
1134 case RPC_FC_FIXED_REPEAT
:
1135 rep
= *(const WORD
*)&pFormat
[2];
1136 stride
= *(const WORD
*)&pFormat
[4];
1137 ofs
= *(const WORD
*)&pFormat
[6];
1138 count
= *(const WORD
*)&pFormat
[8];
1142 case RPC_FC_VARIABLE_REPEAT
:
1143 rep
= pStubMsg
->MaxCount
;
1144 stride
= *(const WORD
*)&pFormat
[2];
1145 ofs
= *(const WORD
*)&pFormat
[4];
1146 count
= *(const WORD
*)&pFormat
[6];
1147 xofs
= (pFormat
[1] == RPC_FC_VARIABLE_OFFSET
) ? Offset
* stride
: 0;
1151 /* ofs doesn't seem to matter in this context */
1153 PFORMAT_STRING info
= pFormat
;
1155 for (u
=0; u
<count
; u
++,info
+=8) {
1156 unsigned char *bufptr
= Mark
+ *(const SHORT
*)&info
[2];
1157 PointerMemorySize(pStubMsg
, bufptr
, info
+4);
1161 pFormat
+= 8 * count
;
1167 /***********************************************************************
1168 * EmbeddedPointerFree
1170 void WINAPI
EmbeddedPointerFree(PMIDL_STUB_MESSAGE pStubMsg
,
1171 unsigned char *pMemory
,
1172 PFORMAT_STRING pFormat
)
1174 unsigned long Offset
= pStubMsg
->Offset
;
1175 unsigned ofs
, rep
, count
, stride
, xofs
;
1177 TRACE("(%p,%p,%p)\n", pStubMsg
, pMemory
, pFormat
);
1178 if (*pFormat
!= RPC_FC_PP
) return;
1181 while (pFormat
[0] != RPC_FC_END
) {
1182 switch (pFormat
[0]) {
1184 FIXME("unknown repeat type %d\n", pFormat
[0]);
1185 case RPC_FC_NO_REPEAT
:
1193 case RPC_FC_FIXED_REPEAT
:
1194 rep
= *(const WORD
*)&pFormat
[2];
1195 stride
= *(const WORD
*)&pFormat
[4];
1196 ofs
= *(const WORD
*)&pFormat
[6];
1197 count
= *(const WORD
*)&pFormat
[8];
1201 case RPC_FC_VARIABLE_REPEAT
:
1202 rep
= pStubMsg
->MaxCount
;
1203 stride
= *(const WORD
*)&pFormat
[2];
1204 ofs
= *(const WORD
*)&pFormat
[4];
1205 count
= *(const WORD
*)&pFormat
[6];
1206 xofs
= (pFormat
[1] == RPC_FC_VARIABLE_OFFSET
) ? Offset
* stride
: 0;
1210 /* ofs doesn't seem to matter in this context */
1212 PFORMAT_STRING info
= pFormat
;
1213 unsigned char *membase
= pMemory
+ xofs
;
1215 for (u
=0; u
<count
; u
++,info
+=8) {
1216 unsigned char *memptr
= membase
+ *(const SHORT
*)&info
[0];
1217 PointerFree(pStubMsg
, *(unsigned char**)memptr
, info
+4);
1221 pFormat
+= 8 * count
;
1225 /***********************************************************************
1226 * NdrPointerMarshall [RPCRT4.@]
1228 unsigned char * WINAPI
NdrPointerMarshall(PMIDL_STUB_MESSAGE pStubMsg
,
1229 unsigned char *pMemory
,
1230 PFORMAT_STRING pFormat
)
1232 TRACE("(%p,%p,%p)\n", pStubMsg
, pMemory
, pFormat
);
1234 pStubMsg
->BufferMark
= pStubMsg
->Buffer
;
1235 PointerMarshall(pStubMsg
, pStubMsg
->Buffer
, pMemory
, pFormat
);
1237 STD_OVERFLOW_CHECK(pStubMsg
);
1242 /***********************************************************************
1243 * NdrPointerUnmarshall [RPCRT4.@]
1245 unsigned char * WINAPI
NdrPointerUnmarshall(PMIDL_STUB_MESSAGE pStubMsg
,
1246 unsigned char **ppMemory
,
1247 PFORMAT_STRING pFormat
,
1248 unsigned char fMustAlloc
)
1250 TRACE("(%p,%p,%p,%d)\n", pStubMsg
, ppMemory
, pFormat
, fMustAlloc
);
1252 pStubMsg
->BufferMark
= pStubMsg
->Buffer
;
1253 PointerUnmarshall(pStubMsg
, pStubMsg
->Buffer
, ppMemory
, pFormat
, fMustAlloc
);
1258 /***********************************************************************
1259 * NdrPointerBufferSize [RPCRT4.@]
1261 void WINAPI
NdrPointerBufferSize(PMIDL_STUB_MESSAGE pStubMsg
,
1262 unsigned char *pMemory
,
1263 PFORMAT_STRING pFormat
)
1265 TRACE("(%p,%p,%p)\n", pStubMsg
, pMemory
, pFormat
);
1266 PointerBufferSize(pStubMsg
, pMemory
, pFormat
);
1269 /***********************************************************************
1270 * NdrPointerMemorySize [RPCRT4.@]
1272 unsigned long WINAPI
NdrPointerMemorySize(PMIDL_STUB_MESSAGE pStubMsg
,
1273 PFORMAT_STRING pFormat
)
1275 /* unsigned size = *(LPWORD)(pFormat+2); */
1276 FIXME("(%p,%p): stub\n", pStubMsg
, pFormat
);
1277 PointerMemorySize(pStubMsg
, pStubMsg
->Buffer
, pFormat
);
1281 /***********************************************************************
1282 * NdrPointerFree [RPCRT4.@]
1284 void WINAPI
NdrPointerFree(PMIDL_STUB_MESSAGE pStubMsg
,
1285 unsigned char *pMemory
,
1286 PFORMAT_STRING pFormat
)
1288 TRACE("(%p,%p,%p)\n", pStubMsg
, pMemory
, pFormat
);
1289 PointerFree(pStubMsg
, pMemory
, pFormat
);
1292 /***********************************************************************
1293 * NdrSimpleStructMarshall [RPCRT4.@]
1295 unsigned char * WINAPI
NdrSimpleStructMarshall(PMIDL_STUB_MESSAGE pStubMsg
,
1296 unsigned char *pMemory
,
1297 PFORMAT_STRING pFormat
)
1299 unsigned size
= *(const WORD
*)(pFormat
+2);
1300 TRACE("(%p,%p,%p)\n", pStubMsg
, pMemory
, pFormat
);
1302 memcpy(pStubMsg
->Buffer
, pMemory
, size
);
1303 pStubMsg
->BufferMark
= pStubMsg
->Buffer
;
1304 pStubMsg
->Buffer
+= size
;
1306 if (pFormat
[0] != RPC_FC_STRUCT
)
1307 EmbeddedPointerMarshall(pStubMsg
, pMemory
, pFormat
+4);
1310 * This test does not work when NdrSimpleStructMarshall is called
1311 * by an rpc-server to marshall data to return to the client because
1312 * BufferStart and BufferEnd are bogus. MIDL does not update them
1313 * when a new buffer is allocated in order to return data to the caller.
1316 STD_OVERFLOW_CHECK(pStubMsg
);
1322 /***********************************************************************
1323 * NdrSimpleStructUnmarshall [RPCRT4.@]
1325 unsigned char * WINAPI
NdrSimpleStructUnmarshall(PMIDL_STUB_MESSAGE pStubMsg
,
1326 unsigned char **ppMemory
,
1327 PFORMAT_STRING pFormat
,
1328 unsigned char fMustAlloc
)
1330 unsigned size
= *(const WORD
*)(pFormat
+2);
1331 TRACE("(%p,%p,%p,%d)\n", pStubMsg
, ppMemory
, pFormat
, fMustAlloc
);
1334 *ppMemory
= NdrAllocate(pStubMsg
, size
);
1335 memcpy(*ppMemory
, pStubMsg
->Buffer
, size
);
1337 if (pStubMsg
->ReuseBuffer
&& !*ppMemory
)
1338 /* for servers, we may just point straight into the RPC buffer, I think
1339 * (I guess that's what MS does since MIDL code doesn't try to free) */
1340 *ppMemory
= pStubMsg
->Buffer
;
1342 /* for clients, memory should be provided by caller */
1343 memcpy(*ppMemory
, pStubMsg
->Buffer
, size
);
1346 pStubMsg
->BufferMark
= pStubMsg
->Buffer
;
1347 pStubMsg
->Buffer
+= size
;
1349 if (pFormat
[0] != RPC_FC_STRUCT
)
1350 EmbeddedPointerUnmarshall(pStubMsg
, ppMemory
, pFormat
+4, fMustAlloc
);
1356 /***********************************************************************
1357 * NdrSimpleTypeUnmarshall [RPCRT4.@]
1359 void WINAPI
NdrSimpleTypeMarshall(PMIDL_STUB_MESSAGE pStubMsg
,
1360 unsigned char *pMemory
,
1361 unsigned char FormatChar
)
1367 /***********************************************************************
1368 * NdrSimpleTypeUnmarshall [RPCRT4.@]
1370 void WINAPI
NdrSimpleTypeUnmarshall(PMIDL_STUB_MESSAGE pStubMsg
,
1371 unsigned char *pMemory
,
1372 unsigned char FormatChar
)
1378 /***********************************************************************
1379 * NdrSimpleStructBufferSize [RPCRT4.@]
1381 void WINAPI
NdrSimpleStructBufferSize(PMIDL_STUB_MESSAGE pStubMsg
,
1382 unsigned char *pMemory
,
1383 PFORMAT_STRING pFormat
)
1385 unsigned size
= *(const WORD
*)(pFormat
+2);
1386 TRACE("(%p,%p,%p)\n", pStubMsg
, pMemory
, pFormat
);
1387 pStubMsg
->BufferLength
+= size
;
1388 if (pFormat
[0] != RPC_FC_STRUCT
)
1389 EmbeddedPointerBufferSize(pStubMsg
, pMemory
, pFormat
+4);
1392 /***********************************************************************
1393 * NdrSimpleStructMemorySize [RPCRT4.@]
1395 unsigned long WINAPI
NdrSimpleStructMemorySize(PMIDL_STUB_MESSAGE pStubMsg
,
1396 PFORMAT_STRING pFormat
)
1398 /* unsigned size = *(LPWORD)(pFormat+2); */
1399 FIXME("(%p,%p): stub\n", pStubMsg
, pFormat
);
1400 if (pFormat
[0] != RPC_FC_STRUCT
)
1401 EmbeddedPointerMemorySize(pStubMsg
, pFormat
+4);
1405 /***********************************************************************
1406 * NdrSimpleStructFree [RPCRT4.@]
1408 void WINAPI
NdrSimpleStructFree(PMIDL_STUB_MESSAGE pStubMsg
,
1409 unsigned char *pMemory
,
1410 PFORMAT_STRING pFormat
)
1412 TRACE("(%p,%p,%p)\n", pStubMsg
, pMemory
, pFormat
);
1413 if (pFormat
[0] != RPC_FC_STRUCT
)
1414 EmbeddedPointerFree(pStubMsg
, pMemory
, pFormat
+4);
1418 unsigned long WINAPI
EmbeddedComplexSize(PMIDL_STUB_MESSAGE pStubMsg
,
1419 PFORMAT_STRING pFormat
)
1423 case RPC_FC_PSTRUCT
:
1424 case RPC_FC_CSTRUCT
:
1425 case RPC_FC_BOGUS_STRUCT
:
1426 return *(const WORD
*)&pFormat
[2];
1427 case RPC_FC_USER_MARSHAL
:
1428 return *(const WORD
*)&pFormat
[4];
1430 FIXME("unhandled embedded type %02x\n", *pFormat
);
1436 unsigned char * WINAPI
ComplexMarshall(PMIDL_STUB_MESSAGE pStubMsg
,
1437 unsigned char *pMemory
,
1438 PFORMAT_STRING pFormat
,
1439 PFORMAT_STRING pPointer
)
1441 PFORMAT_STRING desc
;
1445 while (*pFormat
!= RPC_FC_END
) {
1449 TRACE("short=%d <= %p\n", *(WORD
*)pMemory
, pMemory
);
1450 memcpy(pStubMsg
->Buffer
, pMemory
, 2);
1451 pStubMsg
->Buffer
+= 2;
1457 TRACE("long=%ld <= %p\n", *(DWORD
*)pMemory
, pMemory
);
1458 memcpy(pStubMsg
->Buffer
, pMemory
, 4);
1459 pStubMsg
->Buffer
+= 4;
1462 case RPC_FC_POINTER
:
1463 TRACE("pointer=%p <= %p\n", *(unsigned char**)pMemory
, pMemory
);
1464 NdrPointerMarshall(pStubMsg
, *(unsigned char**)pMemory
, pPointer
);
1468 case RPC_FC_ALIGNM4
:
1469 ALIGN_POINTER(pMemory
, 3);
1471 case RPC_FC_ALIGNM8
:
1472 ALIGN_POINTER(pMemory
, 7);
1474 case RPC_FC_STRUCTPAD2
:
1477 case RPC_FC_EMBEDDED_COMPLEX
:
1478 pMemory
+= pFormat
[1];
1480 desc
= pFormat
+ *(const SHORT
*)pFormat
;
1481 size
= EmbeddedComplexSize(pStubMsg
, desc
);
1482 TRACE("embedded complex (size=%ld) <= %p\n", size
, pMemory
);
1483 m
= NdrMarshaller
[*desc
& NDR_TABLE_MASK
];
1484 if (m
) m(pStubMsg
, pMemory
, desc
);
1485 else FIXME("no marshaller for embedded type %02x\n", *desc
);
1492 FIXME("unhandled format %02x\n", *pFormat
);
1500 unsigned char * WINAPI
ComplexUnmarshall(PMIDL_STUB_MESSAGE pStubMsg
,
1501 unsigned char *pMemory
,
1502 PFORMAT_STRING pFormat
,
1503 PFORMAT_STRING pPointer
,
1504 unsigned char fMustAlloc
)
1506 PFORMAT_STRING desc
;
1510 while (*pFormat
!= RPC_FC_END
) {
1514 memcpy(pMemory
, pStubMsg
->Buffer
, 2);
1515 TRACE("short=%d => %p\n", *(WORD
*)pMemory
, pMemory
);
1516 pStubMsg
->Buffer
+= 2;
1522 memcpy(pMemory
, pStubMsg
->Buffer
, 4);
1523 TRACE("long=%ld => %p\n", *(DWORD
*)pMemory
, pMemory
);
1524 pStubMsg
->Buffer
+= 4;
1527 case RPC_FC_POINTER
:
1528 *(unsigned char**)pMemory
= NULL
;
1529 TRACE("pointer => %p\n", pMemory
);
1530 NdrPointerUnmarshall(pStubMsg
, (unsigned char**)pMemory
, pPointer
, fMustAlloc
);
1534 case RPC_FC_ALIGNM4
:
1535 ALIGN_POINTER(pMemory
, 3);
1537 case RPC_FC_ALIGNM8
:
1538 ALIGN_POINTER(pMemory
, 7);
1540 case RPC_FC_STRUCTPAD2
:
1543 case RPC_FC_EMBEDDED_COMPLEX
:
1544 pMemory
+= pFormat
[1];
1546 desc
= pFormat
+ *(const SHORT
*)pFormat
;
1547 size
= EmbeddedComplexSize(pStubMsg
, desc
);
1548 TRACE("embedded complex (size=%ld) => %p\n", size
, pMemory
);
1549 m
= NdrUnmarshaller
[*desc
& NDR_TABLE_MASK
];
1550 memset(pMemory
, 0, size
); /* just in case */
1551 if (m
) m(pStubMsg
, &pMemory
, desc
, fMustAlloc
);
1552 else FIXME("no unmarshaller for embedded type %02x\n", *desc
);
1559 FIXME("unhandled format %d\n", *pFormat
);
1567 unsigned char * WINAPI
ComplexBufferSize(PMIDL_STUB_MESSAGE pStubMsg
,
1568 unsigned char *pMemory
,
1569 PFORMAT_STRING pFormat
,
1570 PFORMAT_STRING pPointer
)
1572 PFORMAT_STRING desc
;
1576 while (*pFormat
!= RPC_FC_END
) {
1580 pStubMsg
->BufferLength
+= 2;
1586 pStubMsg
->BufferLength
+= 4;
1589 case RPC_FC_POINTER
:
1590 NdrPointerBufferSize(pStubMsg
, *(unsigned char**)pMemory
, pPointer
);
1594 case RPC_FC_ALIGNM4
:
1595 ALIGN_POINTER(pMemory
, 3);
1597 case RPC_FC_ALIGNM8
:
1598 ALIGN_POINTER(pMemory
, 7);
1600 case RPC_FC_STRUCTPAD2
:
1603 case RPC_FC_EMBEDDED_COMPLEX
:
1604 pMemory
+= pFormat
[1];
1606 desc
= pFormat
+ *(const SHORT
*)pFormat
;
1607 size
= EmbeddedComplexSize(pStubMsg
, desc
);
1608 m
= NdrBufferSizer
[*desc
& NDR_TABLE_MASK
];
1609 if (m
) m(pStubMsg
, pMemory
, desc
);
1610 else FIXME("no buffersizer for embedded type %02x\n", *desc
);
1617 FIXME("unhandled format %d\n", *pFormat
);
1625 unsigned char * WINAPI
ComplexFree(PMIDL_STUB_MESSAGE pStubMsg
,
1626 unsigned char *pMemory
,
1627 PFORMAT_STRING pFormat
,
1628 PFORMAT_STRING pPointer
)
1630 PFORMAT_STRING desc
;
1634 while (*pFormat
!= RPC_FC_END
) {
1645 case RPC_FC_POINTER
:
1646 NdrPointerFree(pStubMsg
, *(unsigned char**)pMemory
, pPointer
);
1650 case RPC_FC_ALIGNM4
:
1651 ALIGN_POINTER(pMemory
, 3);
1653 case RPC_FC_ALIGNM8
:
1654 ALIGN_POINTER(pMemory
, 7);
1656 case RPC_FC_STRUCTPAD2
:
1659 case RPC_FC_EMBEDDED_COMPLEX
:
1660 pMemory
+= pFormat
[1];
1662 desc
= pFormat
+ *(const SHORT
*)pFormat
;
1663 size
= EmbeddedComplexSize(pStubMsg
, desc
);
1664 m
= NdrFreer
[*desc
& NDR_TABLE_MASK
];
1665 if (m
) m(pStubMsg
, pMemory
, desc
);
1666 else FIXME("no freer for embedded type %02x\n", *desc
);
1673 FIXME("unhandled format %d\n", *pFormat
);
1681 unsigned long WINAPI
ComplexStructSize(PMIDL_STUB_MESSAGE pStubMsg
,
1682 PFORMAT_STRING pFormat
)
1684 PFORMAT_STRING desc
;
1685 unsigned long size
= 0;
1687 while (*pFormat
!= RPC_FC_END
) {
1697 case RPC_FC_POINTER
:
1700 case RPC_FC_ALIGNM4
:
1701 ALIGN_LENGTH(size
, 3);
1703 case RPC_FC_ALIGNM8
:
1704 ALIGN_LENGTH(size
, 7);
1706 case RPC_FC_STRUCTPAD2
:
1709 case RPC_FC_EMBEDDED_COMPLEX
:
1712 desc
= pFormat
+ *(const SHORT
*)pFormat
;
1713 size
+= EmbeddedComplexSize(pStubMsg
, desc
);
1719 FIXME("unhandled format %d\n", *pFormat
);
1727 /***********************************************************************
1728 * NdrComplexStructMarshall [RPCRT4.@]
1730 unsigned char * WINAPI
NdrComplexStructMarshall(PMIDL_STUB_MESSAGE pStubMsg
,
1731 unsigned char *pMemory
,
1732 PFORMAT_STRING pFormat
)
1734 PFORMAT_STRING conf_array
= NULL
;
1735 PFORMAT_STRING pointer_desc
= NULL
;
1736 unsigned char *OldMemory
= pStubMsg
->Memory
;
1738 TRACE("(%p,%p,%p)\n", pStubMsg
, pMemory
, pFormat
);
1741 if (*(const WORD
*)pFormat
) conf_array
= pFormat
+ *(const WORD
*)pFormat
;
1743 if (*(const WORD
*)pFormat
) pointer_desc
= pFormat
+ *(const WORD
*)pFormat
;
1746 pStubMsg
->Memory
= pMemory
;
1748 ComplexMarshall(pStubMsg
, pMemory
, pFormat
, pointer_desc
);
1751 NdrConformantArrayMarshall(pStubMsg
, pMemory
, conf_array
);
1753 pStubMsg
->Memory
= OldMemory
;
1755 STD_OVERFLOW_CHECK(pStubMsg
);
1760 /***********************************************************************
1761 * NdrComplexStructUnmarshall [RPCRT4.@]
1763 unsigned char * WINAPI
NdrComplexStructUnmarshall(PMIDL_STUB_MESSAGE pStubMsg
,
1764 unsigned char **ppMemory
,
1765 PFORMAT_STRING pFormat
,
1766 unsigned char fMustAlloc
)
1768 unsigned size
= *(const WORD
*)(pFormat
+2);
1769 PFORMAT_STRING conf_array
= NULL
;
1770 PFORMAT_STRING pointer_desc
= NULL
;
1771 unsigned char *pMemory
;
1773 TRACE("(%p,%p,%p,%d)\n", pStubMsg
, ppMemory
, pFormat
, fMustAlloc
);
1775 if (fMustAlloc
|| !*ppMemory
)
1776 *ppMemory
= NdrAllocate(pStubMsg
, size
);
1779 if (*(const WORD
*)pFormat
) conf_array
= pFormat
+ *(const WORD
*)pFormat
;
1781 if (*(const WORD
*)pFormat
) pointer_desc
= pFormat
+ *(const WORD
*)pFormat
;
1784 pMemory
= ComplexUnmarshall(pStubMsg
, *ppMemory
, pFormat
, pointer_desc
, fMustAlloc
);
1787 NdrConformantArrayUnmarshall(pStubMsg
, &pMemory
, conf_array
, fMustAlloc
);
1792 /***********************************************************************
1793 * NdrComplexStructBufferSize [RPCRT4.@]
1795 void WINAPI
NdrComplexStructBufferSize(PMIDL_STUB_MESSAGE pStubMsg
,
1796 unsigned char *pMemory
,
1797 PFORMAT_STRING pFormat
)
1799 PFORMAT_STRING conf_array
= NULL
;
1800 PFORMAT_STRING pointer_desc
= NULL
;
1801 unsigned char *OldMemory
= pStubMsg
->Memory
;
1803 TRACE("(%p,%p,%p)\n", pStubMsg
, pMemory
, pFormat
);
1806 if (*(const WORD
*)pFormat
) conf_array
= pFormat
+ *(const WORD
*)pFormat
;
1808 if (*(const WORD
*)pFormat
) pointer_desc
= pFormat
+ *(const WORD
*)pFormat
;
1811 pStubMsg
->Memory
= pMemory
;
1813 pMemory
= ComplexBufferSize(pStubMsg
, pMemory
, pFormat
, pointer_desc
);
1816 NdrConformantArrayBufferSize(pStubMsg
, pMemory
, conf_array
);
1818 pStubMsg
->Memory
= OldMemory
;
1821 /***********************************************************************
1822 * NdrComplexStructMemorySize [RPCRT4.@]
1824 unsigned long WINAPI
NdrComplexStructMemorySize(PMIDL_STUB_MESSAGE pStubMsg
,
1825 PFORMAT_STRING pFormat
)
1827 /* unsigned size = *(LPWORD)(pFormat+2); */
1828 PFORMAT_STRING conf_array
= NULL
;
1829 PFORMAT_STRING pointer_desc
= NULL
;
1831 FIXME("(%p,%p): stub\n", pStubMsg
, pFormat
);
1834 if (*(const WORD
*)pFormat
) conf_array
= pFormat
+ *(const WORD
*)pFormat
;
1836 if (*(const WORD
*)pFormat
) pointer_desc
= pFormat
+ *(const WORD
*)pFormat
;
1842 /***********************************************************************
1843 * NdrComplexStructFree [RPCRT4.@]
1845 void WINAPI
NdrComplexStructFree(PMIDL_STUB_MESSAGE pStubMsg
,
1846 unsigned char *pMemory
,
1847 PFORMAT_STRING pFormat
)
1849 PFORMAT_STRING conf_array
= NULL
;
1850 PFORMAT_STRING pointer_desc
= NULL
;
1851 unsigned char *OldMemory
= pStubMsg
->Memory
;
1853 TRACE("(%p,%p,%p)\n", pStubMsg
, pMemory
, pFormat
);
1856 if (*(const WORD
*)pFormat
) conf_array
= pFormat
+ *(const WORD
*)pFormat
;
1858 if (*(const WORD
*)pFormat
) pointer_desc
= pFormat
+ *(const WORD
*)pFormat
;
1861 pStubMsg
->Memory
= pMemory
;
1863 pMemory
= ComplexFree(pStubMsg
, pMemory
, pFormat
, pointer_desc
);
1866 NdrConformantArrayFree(pStubMsg
, pMemory
, conf_array
);
1868 pStubMsg
->Memory
= OldMemory
;
1871 /***********************************************************************
1872 * NdrConformantArrayMarshall [RPCRT4.@]
1874 unsigned char * WINAPI
NdrConformantArrayMarshall(PMIDL_STUB_MESSAGE pStubMsg
,
1875 unsigned char *pMemory
,
1876 PFORMAT_STRING pFormat
)
1878 DWORD size
= 0, esize
= *(const WORD
*)(pFormat
+2);
1879 TRACE("(%p,%p,%p)\n", pStubMsg
, pMemory
, pFormat
);
1880 if (pFormat
[0] != RPC_FC_CARRAY
) FIXME("format=%d\n", pFormat
[0]);
1882 pFormat
= ComputeConformance(pStubMsg
, pMemory
, pFormat
+4, 0);
1883 size
= pStubMsg
->MaxCount
;
1885 NDR_LOCAL_UINT32_WRITE(pStubMsg
->Buffer
, size
);
1886 pStubMsg
->Buffer
+= 4;
1888 memcpy(pStubMsg
->Buffer
, pMemory
, size
*esize
);
1889 pStubMsg
->BufferMark
= pStubMsg
->Buffer
;
1890 pStubMsg
->Buffer
+= size
*esize
;
1892 EmbeddedPointerMarshall(pStubMsg
, pMemory
, pFormat
);
1894 STD_OVERFLOW_CHECK(pStubMsg
);
1899 /***********************************************************************
1900 * NdrConformantArrayUnmarshall [RPCRT4.@]
1902 unsigned char * WINAPI
NdrConformantArrayUnmarshall(PMIDL_STUB_MESSAGE pStubMsg
,
1903 unsigned char **ppMemory
,
1904 PFORMAT_STRING pFormat
,
1905 unsigned char fMustAlloc
)
1907 DWORD size
= 0, esize
= *(const WORD
*)(pFormat
+2);
1908 TRACE("(%p,%p,%p,%d)\n", pStubMsg
, ppMemory
, pFormat
, fMustAlloc
);
1909 if (pFormat
[0] != RPC_FC_CARRAY
) FIXME("format=%d\n", pFormat
[0]);
1911 pFormat
= ReadConformance(pStubMsg
, pFormat
+4);
1912 size
= pStubMsg
->MaxCount
;
1914 if (fMustAlloc
|| !*ppMemory
)
1915 *ppMemory
= NdrAllocate(pStubMsg
, size
*esize
);
1917 memcpy(*ppMemory
, pStubMsg
->Buffer
, size
*esize
);
1919 pStubMsg
->BufferMark
= pStubMsg
->Buffer
;
1920 pStubMsg
->Buffer
+= size
*esize
;
1922 EmbeddedPointerUnmarshall(pStubMsg
, ppMemory
, pFormat
, fMustAlloc
);
1927 /***********************************************************************
1928 * NdrConformantArrayBufferSize [RPCRT4.@]
1930 void WINAPI
NdrConformantArrayBufferSize(PMIDL_STUB_MESSAGE pStubMsg
,
1931 unsigned char *pMemory
,
1932 PFORMAT_STRING pFormat
)
1934 DWORD size
= 0, esize
= *(const WORD
*)(pFormat
+2);
1935 TRACE("(%p,%p,%p)\n", pStubMsg
, pMemory
, pFormat
);
1936 if (pFormat
[0] != RPC_FC_CARRAY
) FIXME("format=%d\n", pFormat
[0]);
1938 pFormat
= ComputeConformance(pStubMsg
, pMemory
, pFormat
+4, 0);
1939 size
= pStubMsg
->MaxCount
;
1941 /* conformance value plus array */
1942 pStubMsg
->BufferLength
+= sizeof(DWORD
) + size
*esize
;
1944 EmbeddedPointerBufferSize(pStubMsg
, pMemory
, pFormat
);
1947 /***********************************************************************
1948 * NdrConformantArrayMemorySize [RPCRT4.@]
1950 unsigned long WINAPI
NdrConformantArrayMemorySize(PMIDL_STUB_MESSAGE pStubMsg
,
1951 PFORMAT_STRING pFormat
)
1953 DWORD size
= 0, esize
= *(const WORD
*)(pFormat
+2);
1954 unsigned char *buffer
;
1956 TRACE("(%p,%p)\n", pStubMsg
, pFormat
);
1957 if (pFormat
[0] != RPC_FC_CARRAY
) FIXME("format=%d\n", pFormat
[0]);
1959 buffer
= pStubMsg
->Buffer
;
1960 pFormat
= ReadConformance(pStubMsg
, pFormat
+4);
1961 pStubMsg
->Buffer
= buffer
;
1962 size
= pStubMsg
->MaxCount
;
1967 /***********************************************************************
1968 * NdrConformantArrayFree [RPCRT4.@]
1970 void WINAPI
NdrConformantArrayFree(PMIDL_STUB_MESSAGE pStubMsg
,
1971 unsigned char *pMemory
,
1972 PFORMAT_STRING pFormat
)
1974 TRACE("(%p,%p,%p)\n", pStubMsg
, pMemory
, pFormat
);
1975 if (pFormat
[0] != RPC_FC_CARRAY
) FIXME("format=%d\n", pFormat
[0]);
1977 EmbeddedPointerFree(pStubMsg
, pMemory
, pFormat
);
1981 /***********************************************************************
1982 * NdrConformantVaryingArrayMarshall [RPCRT4.@]
1984 unsigned char* WINAPI
NdrConformantVaryingArrayMarshall( PMIDL_STUB_MESSAGE pStubMsg
,
1985 unsigned char* pMemory
,
1986 PFORMAT_STRING pFormat
)
1988 DWORD esize
= *(const WORD
*)(pFormat
+2);
1990 TRACE("(%p, %p, %p)\n", pStubMsg
, pMemory
, pFormat
);
1992 if (pFormat
[0] != RPC_FC_CVARRAY
)
1994 ERR("invalid format type %x\n", pFormat
[0]);
1995 RpcRaiseException(RPC_S_INTERNAL_ERROR
);
1999 pFormat
= ComputeConformance(pStubMsg
, pMemory
, pFormat
+4, 0);
2000 pFormat
= ComputeVariance(pStubMsg
, pMemory
, pFormat
, 0);
2002 NDR_LOCAL_UINT32_WRITE(pStubMsg
->Buffer
, pStubMsg
->MaxCount
);
2003 pStubMsg
->Buffer
+= 4;
2004 NDR_LOCAL_UINT32_WRITE(pStubMsg
->Buffer
, pStubMsg
->Offset
);
2005 pStubMsg
->Buffer
+= 4;
2006 NDR_LOCAL_UINT32_WRITE(pStubMsg
->Buffer
, pStubMsg
->ActualCount
);
2007 pStubMsg
->Buffer
+= 4;
2009 memcpy(pStubMsg
->Buffer
, pMemory
+ pStubMsg
->Offset
, pStubMsg
->ActualCount
*esize
);
2010 pStubMsg
->BufferMark
= pStubMsg
->Buffer
;
2011 pStubMsg
->Buffer
+= pStubMsg
->ActualCount
*esize
;
2013 EmbeddedPointerMarshall(pStubMsg
, pMemory
, pFormat
);
2015 STD_OVERFLOW_CHECK(pStubMsg
);
2021 /***********************************************************************
2022 * NdrConformantVaryingArrayUnmarshall [RPCRT4.@]
2024 unsigned char* WINAPI
NdrConformantVaryingArrayUnmarshall( PMIDL_STUB_MESSAGE pStubMsg
,
2025 unsigned char** ppMemory
,
2026 PFORMAT_STRING pFormat
,
2027 unsigned char fMustAlloc
)
2030 DWORD esize
= *(const WORD
*)(pFormat
+2);
2032 TRACE("(%p, %p, %p, %d)\n", pStubMsg
, ppMemory
, pFormat
, fMustAlloc
);
2034 if (pFormat
[0] != RPC_FC_CVARRAY
)
2036 ERR("invalid format type %x\n", pFormat
[0]);
2037 RpcRaiseException(RPC_S_INTERNAL_ERROR
);
2040 pFormat
= ReadConformance(pStubMsg
, pFormat
);
2041 offset
= NDR_LOCAL_UINT32_READ(pStubMsg
->Buffer
);
2042 pStubMsg
->Buffer
+= 4;
2043 pFormat
= ReadVariance(pStubMsg
, pFormat
);
2045 if (!*ppMemory
|| fMustAlloc
)
2046 *ppMemory
= NdrAllocate(pStubMsg
, pStubMsg
->MaxCount
* esize
);
2047 memcpy(*ppMemory
+ offset
, pStubMsg
->Buffer
, pStubMsg
->ActualCount
* esize
);
2048 pStubMsg
->Buffer
+= pStubMsg
->ActualCount
* esize
;
2050 EmbeddedPointerUnmarshall(pStubMsg
, ppMemory
, pFormat
, fMustAlloc
);
2056 /***********************************************************************
2057 * NdrConformantVaryingArrayFree [RPCRT4.@]
2059 void WINAPI
NdrConformantVaryingArrayFree( PMIDL_STUB_MESSAGE pStubMsg
,
2060 unsigned char* pMemory
,
2061 PFORMAT_STRING pFormat
)
2067 /***********************************************************************
2068 * NdrConformantVaryingArrayBufferSize [RPCRT4.@]
2070 void WINAPI
NdrConformantVaryingArrayBufferSize( PMIDL_STUB_MESSAGE pStubMsg
,
2071 unsigned char* pMemory
, PFORMAT_STRING pFormat
)
2073 DWORD esize
= *(const WORD
*)(pFormat
+2);
2075 TRACE("(%p, %p, %p)\n", pStubMsg
, pMemory
, pFormat
);
2077 if (pFormat
[0] != RPC_FC_CVARRAY
)
2079 ERR("invalid format type %x\n", pFormat
[0]);
2080 RpcRaiseException(RPC_S_INTERNAL_ERROR
);
2085 pFormat
= ComputeConformance(pStubMsg
, pMemory
, pFormat
+4, 0);
2086 /* compute length */
2087 pFormat
= ComputeVariance(pStubMsg
, pMemory
, pFormat
, 0);
2089 /* conformance + offset + variance + array */
2090 pStubMsg
->BufferLength
+= 3*sizeof(DWORD
) + pStubMsg
->ActualCount
*esize
;
2092 EmbeddedPointerBufferSize(pStubMsg
, pMemory
, pFormat
);
2096 /***********************************************************************
2097 * NdrConformantVaryingArrayMemorySize [RPCRT4.@]
2099 unsigned long WINAPI
NdrConformantVaryingArrayMemorySize( PMIDL_STUB_MESSAGE pStubMsg
,
2100 PFORMAT_STRING pFormat
)
2107 /***********************************************************************
2108 * NdrComplexArrayMarshall [RPCRT4.@]
2110 unsigned char * WINAPI
NdrComplexArrayMarshall(PMIDL_STUB_MESSAGE pStubMsg
,
2111 unsigned char *pMemory
,
2112 PFORMAT_STRING pFormat
)
2114 DWORD size
= 0, count
, def
;
2115 TRACE("(%p,%p,%p)\n", pStubMsg
, pMemory
, pFormat
);
2117 def
= *(const WORD
*)&pFormat
[2];
2120 pFormat
= ComputeConformance(pStubMsg
, pMemory
, pFormat
, def
);
2121 size
= pStubMsg
->MaxCount
;
2122 TRACE("conformance=%ld\n", size
);
2124 if (*(const DWORD
*)pFormat
!= 0xffffffff)
2125 FIXME("compute variance\n");
2128 NDR_LOCAL_UINT32_WRITE(pStubMsg
->Buffer
, size
);
2129 pStubMsg
->Buffer
+= 4;
2131 for (count
=0; count
<size
; count
++)
2132 pMemory
= ComplexMarshall(pStubMsg
, pMemory
, pFormat
, NULL
);
2134 STD_OVERFLOW_CHECK(pStubMsg
);
2139 /***********************************************************************
2140 * NdrComplexArrayUnmarshall [RPCRT4.@]
2142 unsigned char * WINAPI
NdrComplexArrayUnmarshall(PMIDL_STUB_MESSAGE pStubMsg
,
2143 unsigned char **ppMemory
,
2144 PFORMAT_STRING pFormat
,
2145 unsigned char fMustAlloc
)
2147 DWORD size
= 0, count
, esize
;
2148 unsigned char *pMemory
;
2149 TRACE("(%p,%p,%p,%d)\n", pStubMsg
, ppMemory
, pFormat
, fMustAlloc
);
2153 pFormat
= ReadConformance(pStubMsg
, pFormat
);
2154 size
= pStubMsg
->MaxCount
;
2155 TRACE("conformance=%ld\n", size
);
2159 esize
= ComplexStructSize(pStubMsg
, pFormat
);
2161 if (fMustAlloc
|| !*ppMemory
)
2162 *ppMemory
= NdrAllocate(pStubMsg
, size
*esize
);
2164 pMemory
= *ppMemory
;
2165 for (count
=0; count
<size
; count
++)
2166 pMemory
= ComplexUnmarshall(pStubMsg
, pMemory
, pFormat
, NULL
, fMustAlloc
);
2171 /***********************************************************************
2172 * NdrComplexArrayBufferSize [RPCRT4.@]
2174 void WINAPI
NdrComplexArrayBufferSize(PMIDL_STUB_MESSAGE pStubMsg
,
2175 unsigned char *pMemory
,
2176 PFORMAT_STRING pFormat
)
2178 DWORD size
= 0, count
, def
;
2179 TRACE("(%p,%p,%p)\n", pStubMsg
, pMemory
, pFormat
);
2181 def
= *(const WORD
*)&pFormat
[2];
2184 pFormat
= ComputeConformance(pStubMsg
, pMemory
, pFormat
, def
);
2185 size
= pStubMsg
->MaxCount
;
2186 TRACE("conformance=%ld\n", size
);
2188 if (*(const DWORD
*)pFormat
!= 0xffffffff)
2189 FIXME("compute variance\n");
2192 for (count
=0; count
<size
; count
++)
2193 pMemory
= ComplexBufferSize(pStubMsg
, pMemory
, pFormat
, NULL
);
2196 /***********************************************************************
2197 * NdrComplexArrayMemorySize [RPCRT4.@]
2199 unsigned long WINAPI
NdrComplexArrayMemorySize(PMIDL_STUB_MESSAGE pStubMsg
,
2200 PFORMAT_STRING pFormat
)
2203 FIXME("(%p,%p): stub\n", pStubMsg
, pFormat
);
2207 pFormat
= ReadConformance(pStubMsg
, pFormat
);
2208 size
= pStubMsg
->MaxCount
;
2209 TRACE("conformance=%ld\n", size
);
2216 /***********************************************************************
2217 * NdrComplexArrayFree [RPCRT4.@]
2219 void WINAPI
NdrComplexArrayFree(PMIDL_STUB_MESSAGE pStubMsg
,
2220 unsigned char *pMemory
,
2221 PFORMAT_STRING pFormat
)
2223 DWORD size
= 0, count
, def
;
2224 TRACE("(%p,%p,%p)\n", pStubMsg
, pMemory
, pFormat
);
2226 def
= *(const WORD
*)&pFormat
[2];
2229 pFormat
= ComputeConformance(pStubMsg
, pMemory
, pFormat
, def
);
2230 size
= pStubMsg
->MaxCount
;
2231 TRACE("conformance=%ld\n", size
);
2233 if (*(const DWORD
*)pFormat
!= 0xffffffff)
2234 FIXME("compute variance\n");
2237 for (count
=0; count
<size
; count
++)
2238 pMemory
= ComplexFree(pStubMsg
, pMemory
, pFormat
, NULL
);
2241 unsigned long UserMarshalFlags(PMIDL_STUB_MESSAGE pStubMsg
)
2243 return MAKELONG(pStubMsg
->dwDestContext
,
2244 pStubMsg
->RpcMsg
->DataRepresentation
);
2247 /***********************************************************************
2248 * NdrUserMarshalMarshall [RPCRT4.@]
2250 unsigned char * WINAPI
NdrUserMarshalMarshall(PMIDL_STUB_MESSAGE pStubMsg
,
2251 unsigned char *pMemory
,
2252 PFORMAT_STRING pFormat
)
2254 /* unsigned flags = pFormat[1]; */
2255 unsigned index
= *(const WORD
*)&pFormat
[2];
2256 unsigned long uflag
= UserMarshalFlags(pStubMsg
);
2257 TRACE("(%p,%p,%p)\n", pStubMsg
, pMemory
, pFormat
);
2258 TRACE("index=%d\n", index
);
2261 pStubMsg
->StubDesc
->aUserMarshalQuadruple
[index
].pfnMarshall(
2262 &uflag
, pStubMsg
->Buffer
, pMemory
);
2264 STD_OVERFLOW_CHECK(pStubMsg
);
2269 /***********************************************************************
2270 * NdrUserMarshalUnmarshall [RPCRT4.@]
2272 unsigned char * WINAPI
NdrUserMarshalUnmarshall(PMIDL_STUB_MESSAGE pStubMsg
,
2273 unsigned char **ppMemory
,
2274 PFORMAT_STRING pFormat
,
2275 unsigned char fMustAlloc
)
2277 /* unsigned flags = pFormat[1];*/
2278 unsigned index
= *(const WORD
*)&pFormat
[2];
2279 DWORD memsize
= *(const WORD
*)&pFormat
[4];
2280 unsigned long uflag
= UserMarshalFlags(pStubMsg
);
2281 TRACE("(%p,%p,%p,%d)\n", pStubMsg
, ppMemory
, pFormat
, fMustAlloc
);
2282 TRACE("index=%d\n", index
);
2284 if (fMustAlloc
|| !*ppMemory
)
2285 *ppMemory
= NdrAllocate(pStubMsg
, memsize
);
2288 pStubMsg
->StubDesc
->aUserMarshalQuadruple
[index
].pfnUnmarshall(
2289 &uflag
, pStubMsg
->Buffer
, *ppMemory
);
2294 /***********************************************************************
2295 * NdrUserMarshalBufferSize [RPCRT4.@]
2297 void WINAPI
NdrUserMarshalBufferSize(PMIDL_STUB_MESSAGE pStubMsg
,
2298 unsigned char *pMemory
,
2299 PFORMAT_STRING pFormat
)
2301 /* unsigned flags = pFormat[1];*/
2302 unsigned index
= *(const WORD
*)&pFormat
[2];
2303 DWORD bufsize
= *(const WORD
*)&pFormat
[6];
2304 unsigned long uflag
= UserMarshalFlags(pStubMsg
);
2305 TRACE("(%p,%p,%p)\n", pStubMsg
, pMemory
, pFormat
);
2306 TRACE("index=%d\n", index
);
2309 TRACE("size=%ld\n", bufsize
);
2310 pStubMsg
->BufferLength
+= bufsize
;
2314 pStubMsg
->BufferLength
=
2315 pStubMsg
->StubDesc
->aUserMarshalQuadruple
[index
].pfnBufferSize(
2316 &uflag
, pStubMsg
->BufferLength
, pMemory
);
2319 /***********************************************************************
2320 * NdrUserMarshalMemorySize [RPCRT4.@]
2322 unsigned long WINAPI
NdrUserMarshalMemorySize(PMIDL_STUB_MESSAGE pStubMsg
,
2323 PFORMAT_STRING pFormat
)
2325 unsigned index
= *(const WORD
*)&pFormat
[2];
2326 /* DWORD memsize = *(const WORD*)&pFormat[4]; */
2327 FIXME("(%p,%p): stub\n", pStubMsg
, pFormat
);
2328 TRACE("index=%d\n", index
);
2333 /***********************************************************************
2334 * NdrUserMarshalFree [RPCRT4.@]
2336 void WINAPI
NdrUserMarshalFree(PMIDL_STUB_MESSAGE pStubMsg
,
2337 unsigned char *pMemory
,
2338 PFORMAT_STRING pFormat
)
2340 /* unsigned flags = pFormat[1]; */
2341 unsigned index
= *(const WORD
*)&pFormat
[2];
2342 unsigned long uflag
= UserMarshalFlags(pStubMsg
);
2343 TRACE("(%p,%p,%p)\n", pStubMsg
, pMemory
, pFormat
);
2344 TRACE("index=%d\n", index
);
2346 pStubMsg
->StubDesc
->aUserMarshalQuadruple
[index
].pfnFree(
2350 /***********************************************************************
2351 * NdrClearOutParameters [RPCRT4.@]
2353 void WINAPI
NdrClearOutParameters(PMIDL_STUB_MESSAGE pStubMsg
,
2354 PFORMAT_STRING pFormat
,
2357 FIXME("(%p,%p,%p): stub\n", pStubMsg
, pFormat
, ArgAddr
);
2360 /***********************************************************************
2361 * NdrConvert [RPCRT4.@]
2363 void WINAPI
NdrConvert( PMIDL_STUB_MESSAGE pStubMsg
, PFORMAT_STRING pFormat
)
2365 FIXME("(pStubMsg == ^%p, pFormat == ^%p): stub.\n", pStubMsg
, pFormat
);
2366 /* FIXME: since this stub doesn't do any converting, the proper behavior
2367 is to raise an exception */
2370 /***********************************************************************
2371 * NdrConvert2 [RPCRT4.@]
2373 void WINAPI
NdrConvert2( PMIDL_STUB_MESSAGE pStubMsg
, PFORMAT_STRING pFormat
, long NumberParams
)
2375 FIXME("(pStubMsg == ^%p, pFormat == ^%p, NumberParams == %ld): stub.\n",
2376 pStubMsg
, pFormat
, NumberParams
);
2377 /* FIXME: since this stub doesn't do any converting, the proper behavior
2378 is to raise an exception */
2381 typedef struct _NDR_CSTRUCT_FORMAT
2384 unsigned char alignment
;
2385 unsigned short memory_size
;
2386 short offset_to_array_description
;
2387 } NDR_CSTRUCT_FORMAT
;
2389 /***********************************************************************
2390 * NdrConformantStructMarshall [RPCRT4.@]
2392 unsigned char * WINAPI
NdrConformantStructMarshall(PMIDL_STUB_MESSAGE pStubMsg
,
2393 unsigned char *pMemory
,
2394 PFORMAT_STRING pFormat
)
2396 const NDR_CSTRUCT_FORMAT
* pCStructFormat
= (NDR_CSTRUCT_FORMAT
*)pFormat
;
2397 pFormat
+= sizeof(NDR_CSTRUCT_FORMAT
);
2399 TRACE("(%p, %p, %p)\n", pStubMsg
, pMemory
, pFormat
);
2401 if ((pCStructFormat
->type
!= RPC_FC_CPSTRUCT
) && (pCStructFormat
->type
!= RPC_FC_CSTRUCT
))
2403 ERR("invalid format type %x\n", pCStructFormat
->type
);
2404 RpcRaiseException(RPC_S_INTERNAL_ERROR
);
2408 TRACE("memory_size = %d\n", pCStructFormat
->memory_size
);
2410 /* copy constant sized part of struct */
2411 memcpy(pStubMsg
->Buffer
, pMemory
, pCStructFormat
->memory_size
);
2412 pStubMsg
->Buffer
+= pCStructFormat
->memory_size
;
2414 if (pCStructFormat
->offset_to_array_description
)
2416 PFORMAT_STRING pArrayFormat
= (unsigned char*)&pCStructFormat
->offset_to_array_description
+
2417 pCStructFormat
->offset_to_array_description
;
2418 NdrConformantArrayMarshall(pStubMsg
, pMemory
+ pCStructFormat
->memory_size
, pArrayFormat
);
2420 if (pCStructFormat
->type
== RPC_FC_CPSTRUCT
)
2421 EmbeddedPointerMarshall(pStubMsg
, pMemory
, pFormat
);
2425 /***********************************************************************
2426 * NdrConformantStructUnmarshall [RPCRT4.@]
2428 unsigned char * WINAPI
NdrConformantStructUnmarshall(PMIDL_STUB_MESSAGE pStubMsg
,
2429 unsigned char **ppMemory
,
2430 PFORMAT_STRING pFormat
,
2431 unsigned char fMustAlloc
)
2433 const NDR_CSTRUCT_FORMAT
* pCStructFormat
= (NDR_CSTRUCT_FORMAT
*)pFormat
;
2434 pFormat
+= sizeof(NDR_CSTRUCT_FORMAT
);
2436 TRACE("(%p, %p, %p, %d)\n", pStubMsg
, ppMemory
, pFormat
, fMustAlloc
);
2438 if ((pCStructFormat
->type
!= RPC_FC_CPSTRUCT
) && (pCStructFormat
->type
!= RPC_FC_CSTRUCT
))
2440 ERR("invalid format type %x\n", pCStructFormat
->type
);
2441 RpcRaiseException(RPC_S_INTERNAL_ERROR
);
2445 TRACE("memory_size = %d\n", pCStructFormat
->memory_size
);
2447 /* work out how much memory to allocate if we need to do so */
2448 if (!*ppMemory
|| fMustAlloc
)
2450 SIZE_T size
= pCStructFormat
->memory_size
;
2452 if (pCStructFormat
->offset_to_array_description
)
2454 unsigned char *buffer
;
2455 PFORMAT_STRING pArrayFormat
= (unsigned char*)&pCStructFormat
->offset_to_array_description
+
2456 pCStructFormat
->offset_to_array_description
;
2457 buffer
= pStubMsg
->Buffer
;
2458 pStubMsg
->Buffer
+= pCStructFormat
->memory_size
;
2459 size
+= NdrConformantArrayMemorySize(pStubMsg
, pArrayFormat
);
2460 pStubMsg
->Buffer
= buffer
;
2462 *ppMemory
= NdrAllocate(pStubMsg
, size
);
2465 /* now copy the data */
2466 memcpy(*ppMemory
, pStubMsg
->Buffer
, pCStructFormat
->memory_size
);
2467 pStubMsg
->Buffer
+= pCStructFormat
->memory_size
;
2468 if (pCStructFormat
->offset_to_array_description
)
2470 PFORMAT_STRING pArrayFormat
= (unsigned char*)&pCStructFormat
->offset_to_array_description
+
2471 pCStructFormat
->offset_to_array_description
;
2472 unsigned char *pMemoryArray
= *ppMemory
+ pCStructFormat
->memory_size
;
2473 /* note that we pass fMustAlloc as 0 as we have already allocated the
2475 NdrConformantArrayUnmarshall(pStubMsg
, &pMemoryArray
, pArrayFormat
, 0);
2477 if (pCStructFormat
->type
== RPC_FC_CPSTRUCT
)
2478 EmbeddedPointerUnmarshall(pStubMsg
, ppMemory
, pFormat
, fMustAlloc
);
2482 /***********************************************************************
2483 * NdrConformantStructBufferSize [RPCRT4.@]
2485 void WINAPI
NdrConformantStructBufferSize(PMIDL_STUB_MESSAGE pStubMsg
,
2486 unsigned char *pMemory
,
2487 PFORMAT_STRING pFormat
)
2489 const NDR_CSTRUCT_FORMAT
* pCStructFormat
= (NDR_CSTRUCT_FORMAT
*)pFormat
;
2490 pFormat
+= sizeof(NDR_CSTRUCT_FORMAT
);
2491 TRACE("(%p, %p, %p)\n", pStubMsg
, pMemory
, pFormat
);
2493 if ((pCStructFormat
->type
!= RPC_FC_CPSTRUCT
) && (pCStructFormat
->type
!= RPC_FC_CSTRUCT
))
2495 ERR("invalid format type %x\n", pCStructFormat
->type
);
2496 RpcRaiseException(RPC_S_INTERNAL_ERROR
);
2500 TRACE("memory_size = %d\n", pCStructFormat
->memory_size
);
2502 /* add constant sized part of struct to buffer size */
2503 pStubMsg
->BufferLength
+= pCStructFormat
->memory_size
;
2505 if (pCStructFormat
->offset_to_array_description
)
2507 PFORMAT_STRING pArrayFormat
= (unsigned char*)&pCStructFormat
->offset_to_array_description
+
2508 pCStructFormat
->offset_to_array_description
;
2509 NdrConformantArrayBufferSize(pStubMsg
, pMemory
+ pCStructFormat
->memory_size
, pArrayFormat
);
2511 if (pCStructFormat
->type
== RPC_FC_CPSTRUCT
)
2512 EmbeddedPointerBufferSize(pStubMsg
, pMemory
, pFormat
);
2515 /***********************************************************************
2516 * NdrConformantStructMemorySize [RPCRT4.@]
2518 unsigned long WINAPI
NdrConformantStructMemorySize(PMIDL_STUB_MESSAGE pStubMsg
,
2519 PFORMAT_STRING pFormat
)
2525 /***********************************************************************
2526 * NdrConformantStructFree [RPCRT4.@]
2528 void WINAPI
NdrConformantStructFree(PMIDL_STUB_MESSAGE pStubMsg
,
2529 unsigned char *pMemory
,
2530 PFORMAT_STRING pFormat
)
2535 /***********************************************************************
2536 * NdrConformantVaryingStructMarshall [RPCRT4.@]
2538 unsigned char * WINAPI
NdrConformantVaryingStructMarshall(PMIDL_STUB_MESSAGE pStubMsg
,
2539 unsigned char *pMemory
,
2540 PFORMAT_STRING pFormat
)
2546 /***********************************************************************
2547 * NdrConformantVaryingStructUnmarshall [RPCRT4.@]
2549 unsigned char * WINAPI
NdrConformantVaryingStructUnmarshall(PMIDL_STUB_MESSAGE pStubMsg
,
2550 unsigned char **ppMemory
,
2551 PFORMAT_STRING pFormat
,
2552 unsigned char fMustAlloc
)
2558 /***********************************************************************
2559 * NdrConformantVaryingStructBufferSize [RPCRT4.@]
2561 void WINAPI
NdrConformantVaryingStructBufferSize(PMIDL_STUB_MESSAGE pStubMsg
,
2562 unsigned char *pMemory
,
2563 PFORMAT_STRING pFormat
)
2568 /***********************************************************************
2569 * NdrConformantVaryingStructMemorySize [RPCRT4.@]
2571 unsigned long WINAPI
NdrConformantVaryingStructMemorySize(PMIDL_STUB_MESSAGE pStubMsg
,
2572 PFORMAT_STRING pFormat
)
2578 /***********************************************************************
2579 * NdrConformantVaryingStructFree [RPCRT4.@]
2581 void WINAPI
NdrConformantVaryingStructFree(PMIDL_STUB_MESSAGE pStubMsg
,
2582 unsigned char *pMemory
,
2583 PFORMAT_STRING pFormat
)
2588 /***********************************************************************
2589 * NdrFixedArrayMarshall [RPCRT4.@]
2591 unsigned char * WINAPI
NdrFixedArrayMarshall(PMIDL_STUB_MESSAGE pStubMsg
,
2592 unsigned char *pMemory
,
2593 PFORMAT_STRING pFormat
)
2599 /***********************************************************************
2600 * NdrFixedArrayUnmarshall [RPCRT4.@]
2602 unsigned char * WINAPI
NdrFixedArrayUnmarshall(PMIDL_STUB_MESSAGE pStubMsg
,
2603 unsigned char **ppMemory
,
2604 PFORMAT_STRING pFormat
,
2605 unsigned char fMustAlloc
)
2611 /***********************************************************************
2612 * NdrFixedArrayBufferSize [RPCRT4.@]
2614 void WINAPI
NdrFixedArrayBufferSize(PMIDL_STUB_MESSAGE pStubMsg
,
2615 unsigned char *pMemory
,
2616 PFORMAT_STRING pFormat
)
2621 /***********************************************************************
2622 * NdrFixedArrayMemorySize [RPCRT4.@]
2624 unsigned long WINAPI
NdrFixedArrayMemorySize(PMIDL_STUB_MESSAGE pStubMsg
,
2625 PFORMAT_STRING pFormat
)
2631 /***********************************************************************
2632 * NdrFixedArrayFree [RPCRT4.@]
2634 void WINAPI
NdrFixedArrayFree(PMIDL_STUB_MESSAGE pStubMsg
,
2635 unsigned char *pMemory
,
2636 PFORMAT_STRING pFormat
)
2641 /***********************************************************************
2642 * NdrVaryingArrayMarshall [RPCRT4.@]
2644 unsigned char * WINAPI
NdrVaryingArrayMarshall(PMIDL_STUB_MESSAGE pStubMsg
,
2645 unsigned char *pMemory
,
2646 PFORMAT_STRING pFormat
)
2652 /***********************************************************************
2653 * NdrVaryingArrayUnmarshall [RPCRT4.@]
2655 unsigned char * WINAPI
NdrVaryingArrayUnmarshall(PMIDL_STUB_MESSAGE pStubMsg
,
2656 unsigned char **ppMemory
,
2657 PFORMAT_STRING pFormat
,
2658 unsigned char fMustAlloc
)
2664 /***********************************************************************
2665 * NdrVaryingArrayBufferSize [RPCRT4.@]
2667 void WINAPI
NdrVaryingArrayBufferSize(PMIDL_STUB_MESSAGE pStubMsg
,
2668 unsigned char *pMemory
,
2669 PFORMAT_STRING pFormat
)
2674 /***********************************************************************
2675 * NdrVaryingArrayMemorySize [RPCRT4.@]
2677 unsigned long WINAPI
NdrVaryingArrayMemorySize(PMIDL_STUB_MESSAGE pStubMsg
,
2678 PFORMAT_STRING pFormat
)
2684 /***********************************************************************
2685 * NdrVaryingArrayFree [RPCRT4.@]
2687 void WINAPI
NdrVaryingArrayFree(PMIDL_STUB_MESSAGE pStubMsg
,
2688 unsigned char *pMemory
,
2689 PFORMAT_STRING pFormat
)
2694 /***********************************************************************
2695 * NdrEncapsulatedUnionMarshall [RPCRT4.@]
2697 unsigned char * WINAPI
NdrEncapsulatedUnionMarshall(PMIDL_STUB_MESSAGE pStubMsg
,
2698 unsigned char *pMemory
,
2699 PFORMAT_STRING pFormat
)
2705 /***********************************************************************
2706 * NdrEncapsulatedUnionUnmarshall [RPCRT4.@]
2708 unsigned char * WINAPI
NdrEncapsulatedUnionUnmarshall(PMIDL_STUB_MESSAGE pStubMsg
,
2709 unsigned char **ppMemory
,
2710 PFORMAT_STRING pFormat
,
2711 unsigned char fMustAlloc
)
2717 /***********************************************************************
2718 * NdrEncapsulatedUnionBufferSize [RPCRT4.@]
2720 void WINAPI
NdrEncapsulatedUnionBufferSize(PMIDL_STUB_MESSAGE pStubMsg
,
2721 unsigned char *pMemory
,
2722 PFORMAT_STRING pFormat
)
2727 /***********************************************************************
2728 * NdrEncapsulatedUnionMemorySize [RPCRT4.@]
2730 unsigned long WINAPI
NdrEncapsulatedUnionMemorySize(PMIDL_STUB_MESSAGE pStubMsg
,
2731 PFORMAT_STRING pFormat
)
2737 /***********************************************************************
2738 * NdrEncapsulatedUnionFree [RPCRT4.@]
2740 void WINAPI
NdrEncapsulatedUnionFree(PMIDL_STUB_MESSAGE pStubMsg
,
2741 unsigned char *pMemory
,
2742 PFORMAT_STRING pFormat
)
2747 /***********************************************************************
2748 * NdrNonEncapsulatedUnionMarshall [RPCRT4.@]
2750 unsigned char * WINAPI
NdrNonEncapsulatedUnionMarshall(PMIDL_STUB_MESSAGE pStubMsg
,
2751 unsigned char *pMemory
,
2752 PFORMAT_STRING pFormat
)
2758 /***********************************************************************
2759 * NdrNonEncapsulatedUnionUnmarshall [RPCRT4.@]
2761 unsigned char * WINAPI
NdrNonEncapsulatedUnionUnmarshall(PMIDL_STUB_MESSAGE pStubMsg
,
2762 unsigned char **ppMemory
,
2763 PFORMAT_STRING pFormat
,
2764 unsigned char fMustAlloc
)
2770 /***********************************************************************
2771 * NdrNonEncapsulatedUnionBufferSize [RPCRT4.@]
2773 void WINAPI
NdrNonEncapsulatedUnionBufferSize(PMIDL_STUB_MESSAGE pStubMsg
,
2774 unsigned char *pMemory
,
2775 PFORMAT_STRING pFormat
)
2780 /***********************************************************************
2781 * NdrNonEncapsulatedUnionMemorySize [RPCRT4.@]
2783 unsigned long WINAPI
NdrNonEncapsulatedUnionMemorySize(PMIDL_STUB_MESSAGE pStubMsg
,
2784 PFORMAT_STRING pFormat
)
2790 /***********************************************************************
2791 * NdrNonEncapsulatedUnionFree [RPCRT4.@]
2793 void WINAPI
NdrNonEncapsulatedUnionFree(PMIDL_STUB_MESSAGE pStubMsg
,
2794 unsigned char *pMemory
,
2795 PFORMAT_STRING pFormat
)
2800 /***********************************************************************
2801 * NdrByteCountPointerMarshall [RPCRT4.@]
2803 unsigned char * WINAPI
NdrByteCountPointerMarshall(PMIDL_STUB_MESSAGE pStubMsg
,
2804 unsigned char *pMemory
,
2805 PFORMAT_STRING pFormat
)
2811 /***********************************************************************
2812 * NdrByteCountPointerUnmarshall [RPCRT4.@]
2814 unsigned char * WINAPI
NdrByteCountPointerUnmarshall(PMIDL_STUB_MESSAGE pStubMsg
,
2815 unsigned char **ppMemory
,
2816 PFORMAT_STRING pFormat
,
2817 unsigned char fMustAlloc
)
2823 /***********************************************************************
2824 * NdrByteCountPointerBufferSize [RPCRT4.@]
2826 void WINAPI
NdrByteCountPointerBufferSize(PMIDL_STUB_MESSAGE pStubMsg
,
2827 unsigned char *pMemory
,
2828 PFORMAT_STRING pFormat
)
2833 /***********************************************************************
2834 * NdrByteCountPointerMemorySize [RPCRT4.@]
2836 unsigned long WINAPI
NdrByteCountPointerMemorySize(PMIDL_STUB_MESSAGE pStubMsg
,
2837 PFORMAT_STRING pFormat
)
2843 /***********************************************************************
2844 * NdrByteCountPointerFree [RPCRT4.@]
2846 void WINAPI
NdrByteCountPointerFree(PMIDL_STUB_MESSAGE pStubMsg
,
2847 unsigned char *pMemory
,
2848 PFORMAT_STRING pFormat
)
2853 /***********************************************************************
2854 * NdrXmitOrRepAsMarshall [RPCRT4.@]
2856 unsigned char * WINAPI
NdrXmitOrRepAsMarshall(PMIDL_STUB_MESSAGE pStubMsg
,
2857 unsigned char *pMemory
,
2858 PFORMAT_STRING pFormat
)
2864 /***********************************************************************
2865 * NdrXmitOrRepAsUnmarshall [RPCRT4.@]
2867 unsigned char * WINAPI
NdrXmitOrRepAsUnmarshall(PMIDL_STUB_MESSAGE pStubMsg
,
2868 unsigned char **ppMemory
,
2869 PFORMAT_STRING pFormat
,
2870 unsigned char fMustAlloc
)
2876 /***********************************************************************
2877 * NdrXmitOrRepAsBufferSize [RPCRT4.@]
2879 void WINAPI
NdrXmitOrRepAsBufferSize(PMIDL_STUB_MESSAGE pStubMsg
,
2880 unsigned char *pMemory
,
2881 PFORMAT_STRING pFormat
)
2886 /***********************************************************************
2887 * NdrXmitOrRepAsMemorySize [RPCRT4.@]
2889 unsigned long WINAPI
NdrXmitOrRepAsMemorySize(PMIDL_STUB_MESSAGE pStubMsg
,
2890 PFORMAT_STRING pFormat
)
2896 /***********************************************************************
2897 * NdrXmitOrRepAsFree [RPCRT4.@]
2899 void WINAPI
NdrXmitOrRepAsFree(PMIDL_STUB_MESSAGE pStubMsg
,
2900 unsigned char *pMemory
,
2901 PFORMAT_STRING pFormat
)
2906 /***********************************************************************
2907 * NdrBaseTypeMarshall [internal]
2909 static unsigned char *WINAPI
NdrBaseTypeMarshall(
2910 PMIDL_STUB_MESSAGE pStubMsg
,
2911 unsigned char *pMemory
,
2912 PFORMAT_STRING pFormat
)
2914 TRACE("pStubMsg %p, pMemory %p, type 0x%02x\n", pStubMsg
, pMemory
, *pFormat
);
2922 *(UCHAR
*)pStubMsg
->Buffer
= *(UCHAR
*)pMemory
;
2923 pStubMsg
->Buffer
+= sizeof(UCHAR
);
2924 TRACE("value: 0x%02x\n", *(UCHAR
*)pMemory
);
2929 ALIGN_POINTER(pStubMsg
->Buffer
, sizeof(USHORT
) - 1);
2930 *(USHORT
*)pStubMsg
->Buffer
= *(USHORT
*)pMemory
;
2931 pStubMsg
->Buffer
+= sizeof(USHORT
);
2932 TRACE("value: 0x%04x\n", *(USHORT
*)pMemory
);
2936 case RPC_FC_ERROR_STATUS_T
:
2937 ALIGN_POINTER(pStubMsg
->Buffer
, sizeof(ULONG
) - 1);
2938 *(ULONG
*)pStubMsg
->Buffer
= *(ULONG
*)pMemory
;
2939 pStubMsg
->Buffer
+= sizeof(ULONG
);
2940 TRACE("value: 0x%08lx\n", *(ULONG
*)pMemory
);
2943 ALIGN_POINTER(pStubMsg
->Buffer
, sizeof(float) - 1);
2944 *(float *)pStubMsg
->Buffer
= *(float *)pMemory
;
2945 pStubMsg
->Buffer
+= sizeof(float);
2948 ALIGN_POINTER(pStubMsg
->Buffer
, sizeof(double) - 1);
2949 *(double *)pStubMsg
->Buffer
= *(double *)pMemory
;
2950 pStubMsg
->Buffer
+= sizeof(double);
2953 ALIGN_POINTER(pStubMsg
->Buffer
, sizeof(ULONGLONG
) - 1);
2954 *(ULONGLONG
*)pStubMsg
->Buffer
= *(ULONGLONG
*)pMemory
;
2955 pStubMsg
->Buffer
+= sizeof(ULONGLONG
);
2956 TRACE("value: %s\n", wine_dbgstr_longlong(*(ULONGLONG
*)pMemory
));
2961 FIXME("Unhandled base type: 0x%02x\n", *pFormat
);
2964 STD_OVERFLOW_CHECK(pStubMsg
);
2966 /* FIXME: what is the correct return value? */
2970 /***********************************************************************
2971 * NdrBaseTypeUnmarshall [internal]
2973 static unsigned char *WINAPI
NdrBaseTypeUnmarshall(
2974 PMIDL_STUB_MESSAGE pStubMsg
,
2975 unsigned char **ppMemory
,
2976 PFORMAT_STRING pFormat
,
2977 unsigned char fMustAlloc
)
2979 TRACE("pStubMsg: %p, ppMemory: %p, type: 0x%02x, fMustAlloc: %s\n", pStubMsg
, ppMemory
, *pFormat
, fMustAlloc
? "true" : "false");
2981 if (fMustAlloc
|| !*ppMemory
)
2982 *ppMemory
= NdrAllocate(pStubMsg
, NdrBaseTypeMemorySize(pStubMsg
, pFormat
));
2984 TRACE("*ppMemory: %p\n", *ppMemory
);
2992 **(UCHAR
**)ppMemory
= *(UCHAR
*)pStubMsg
->Buffer
;
2993 pStubMsg
->Buffer
+= sizeof(UCHAR
);
2994 TRACE("value: 0x%02x\n", **(UCHAR
**)ppMemory
);
2999 ALIGN_POINTER(pStubMsg
->Buffer
, sizeof(USHORT
) - 1);
3000 **(USHORT
**)ppMemory
= *(USHORT
*)pStubMsg
->Buffer
;
3001 pStubMsg
->Buffer
+= sizeof(USHORT
);
3002 TRACE("value: 0x%04x\n", **(USHORT
**)ppMemory
);
3006 case RPC_FC_ERROR_STATUS_T
:
3007 ALIGN_POINTER(pStubMsg
->Buffer
, sizeof(ULONG
) - 1);
3008 **(ULONG
**)ppMemory
= *(ULONG
*)pStubMsg
->Buffer
;
3009 pStubMsg
->Buffer
+= sizeof(ULONG
);
3010 TRACE("value: 0x%08lx\n", **(ULONG
**)ppMemory
);
3013 ALIGN_POINTER(pStubMsg
->Buffer
, sizeof(float) - 1);
3014 **(float **)ppMemory
= *(float *)pStubMsg
->Buffer
;
3015 pStubMsg
->Buffer
+= sizeof(float);
3016 TRACE("value: %f\n", **(float **)ppMemory
);
3019 ALIGN_POINTER(pStubMsg
->Buffer
, sizeof(double) - 1);
3020 **(double **)ppMemory
= *(double*)pStubMsg
->Buffer
;
3021 pStubMsg
->Buffer
+= sizeof(double);
3022 TRACE("value: %f\n", **(double **)ppMemory
);
3025 ALIGN_POINTER(pStubMsg
->Buffer
, sizeof(ULONGLONG
) - 1);
3026 **(ULONGLONG
**)ppMemory
= *(ULONGLONG
*)pStubMsg
->Buffer
;
3027 pStubMsg
->Buffer
+= sizeof(ULONGLONG
);
3028 TRACE("value: %s\n", wine_dbgstr_longlong(**(ULONGLONG
**)ppMemory
));
3033 FIXME("Unhandled base type: 0x%02x\n", *pFormat
);
3036 /* FIXME: what is the correct return value? */
3041 /***********************************************************************
3042 * NdrBaseTypeBufferSize [internal]
3044 static void WINAPI
NdrBaseTypeBufferSize(
3045 PMIDL_STUB_MESSAGE pStubMsg
,
3046 unsigned char *pMemory
,
3047 PFORMAT_STRING pFormat
)
3049 TRACE("pStubMsg %p, pMemory %p, type 0x%02x\n", pStubMsg
, pMemory
, *pFormat
);
3057 pStubMsg
->BufferLength
+= sizeof(UCHAR
);
3062 ALIGN_LENGTH(pStubMsg
->BufferLength
, sizeof(USHORT
) - 1);
3063 pStubMsg
->BufferLength
+= sizeof(USHORT
);
3067 ALIGN_LENGTH(pStubMsg
->BufferLength
, sizeof(ULONG
) - 1);
3068 pStubMsg
->BufferLength
+= sizeof(ULONG
);
3071 ALIGN_LENGTH(pStubMsg
->BufferLength
, sizeof(float) - 1);
3072 pStubMsg
->BufferLength
+= sizeof(float);
3075 ALIGN_LENGTH(pStubMsg
->BufferLength
, sizeof(double) - 1);
3076 pStubMsg
->BufferLength
+= sizeof(double);
3079 ALIGN_LENGTH(pStubMsg
->BufferLength
, sizeof(ULONGLONG
) - 1);
3080 pStubMsg
->BufferLength
+= sizeof(ULONGLONG
);
3082 case RPC_FC_ERROR_STATUS_T
:
3083 ALIGN_LENGTH(pStubMsg
->BufferLength
, sizeof(error_status_t
) - 1);
3084 pStubMsg
->BufferLength
+= sizeof(error_status_t
);
3089 FIXME("Unhandled base type: 0x%02x\n", *pFormat
);
3093 /***********************************************************************
3094 * NdrBaseTypeMemorySize [internal]
3096 static unsigned long WINAPI
NdrBaseTypeMemorySize(
3097 PMIDL_STUB_MESSAGE pStubMsg
,
3098 PFORMAT_STRING pFormat
)
3106 return sizeof(UCHAR
);
3110 return sizeof(USHORT
);
3113 return sizeof(ULONG
);
3115 return sizeof(float);
3117 return sizeof(double);
3119 return sizeof(ULONGLONG
);
3120 case RPC_FC_ERROR_STATUS_T
:
3121 return sizeof(error_status_t
);
3125 FIXME("Unhandled base type: 0x%02x\n", *pFormat
);
3130 /***********************************************************************
3131 * NdrBaseTypeFree [internal]
3133 static void WINAPI
NdrBaseTypeFree(PMIDL_STUB_MESSAGE pStubMsg
,
3134 unsigned char *pMemory
,
3135 PFORMAT_STRING pFormat
)
3137 TRACE("pStubMsg %p pMemory %p type 0x%02x\n", pStubMsg
, pMemory
, *pFormat
);
3142 /***********************************************************************
3143 * NdrClientContextMarshall
3145 void WINAPI
NdrClientContextMarshall(PMIDL_STUB_MESSAGE pStubMsg
,
3146 NDR_CCONTEXT ContextHandle
,
3149 FIXME("(%p, %p, %d): stub\n", pStubMsg
, ContextHandle
, fCheck
);
3152 /***********************************************************************
3153 * NdrClientContextUnmarshall
3155 void WINAPI
NdrClientContextUnmarshall(PMIDL_STUB_MESSAGE pStubMsg
,
3156 NDR_CCONTEXT
* pContextHandle
,
3157 RPC_BINDING_HANDLE BindHandle
)
3159 FIXME("(%p, %p, %p): stub\n", pStubMsg
, pContextHandle
, BindHandle
);
3162 void WINAPI
NdrServerContextMarshall(PMIDL_STUB_MESSAGE pStubMsg
,
3163 NDR_SCONTEXT ContextHandle
,
3164 NDR_RUNDOWN RundownRoutine
)
3166 FIXME("(%p, %p, %p): stub\n", pStubMsg
, ContextHandle
, RundownRoutine
);
3169 NDR_SCONTEXT WINAPI
NdrServerContextUnmarshall(PMIDL_STUB_MESSAGE pStubMsg
)
3171 FIXME("(%p): stub\n", pStubMsg
);
3175 void WINAPI
NdrContextHandleSize(PMIDL_STUB_MESSAGE pStubMsg
,
3176 unsigned char* pMemory
,
3177 PFORMAT_STRING pFormat
)
3179 FIXME("(%p, %p, %p): stub\n", pStubMsg
, pMemory
, pFormat
);
3182 NDR_SCONTEXT WINAPI
NdrContextHandleInitialize(PMIDL_STUB_MESSAGE pStubMsg
,
3183 PFORMAT_STRING pFormat
)
3185 FIXME("(%p, %p): stub\n", pStubMsg
, pFormat
);
3189 void WINAPI
NdrServerContextNewMarshall(PMIDL_STUB_MESSAGE pStubMsg
,
3190 NDR_SCONTEXT ContextHandle
,
3191 NDR_RUNDOWN RundownRoutine
,
3192 PFORMAT_STRING pFormat
)
3194 FIXME("(%p, %p, %p, %p): stub\n", pStubMsg
, ContextHandle
, RundownRoutine
, pFormat
);
3197 NDR_SCONTEXT WINAPI
NdrServerContextNewUnmarshall(PMIDL_STUB_MESSAGE pStubMsg
,
3198 PFORMAT_STRING pFormat
)
3200 FIXME("(%p, %p): stub\n", pStubMsg
, pFormat
);
3204 RPC_BINDING_HANDLE WINAPI
NDRCContextBinding(NDR_CCONTEXT CContext
)
3206 FIXME("(%p): stub\n", CContext
);