rpcrt4: Implement NdrUserMarshalMemorySize.
[wine/multimedia.git] / dlls / rpcrt4 / ndr_marshall.c
blob3ba3194c5b95b71c0463e7f5712a84b1ccee9f8e
1 /*
2 * NDR data marshalling
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
20 * TODO:
21 * - figure out whether we *really* got this right
22 * - check for errors and throw exceptions
25 #include <stdarg.h>
26 #include <stdio.h>
27 #include <string.h>
28 #include <assert.h>
29 #include <limits.h>
31 #include "windef.h"
32 #include "winbase.h"
33 #include "winerror.h"
34 #include "winreg.h"
36 #include "ndr_misc.h"
37 #include "rpcndr.h"
39 #include "wine/unicode.h"
40 #include "wine/rpcfc.h"
42 #include "wine/debug.h"
44 WINE_DEFAULT_DEBUG_CHANNEL(ole);
46 #if defined(__i386__)
47 # define LITTLE_ENDIAN_UINT32_WRITE(pchar, uint32) \
48 (*((UINT32 *)(pchar)) = (uint32))
50 # define LITTLE_ENDIAN_UINT32_READ(pchar) \
51 (*((UINT32 *)(pchar)))
52 #else
53 /* these would work for i386 too, but less efficient */
54 # define LITTLE_ENDIAN_UINT32_WRITE(pchar, uint32) \
55 (*(pchar) = LOBYTE(LOWORD(uint32)), \
56 *((pchar)+1) = HIBYTE(LOWORD(uint32)), \
57 *((pchar)+2) = LOBYTE(HIWORD(uint32)), \
58 *((pchar)+3) = HIBYTE(HIWORD(uint32)), \
59 (uint32)) /* allow as r-value */
61 # define LITTLE_ENDIAN_UINT32_READ(pchar) \
62 (MAKELONG( \
63 MAKEWORD(*(pchar), *((pchar)+1)), \
64 MAKEWORD(*((pchar)+2), *((pchar)+3))))
65 #endif
67 #define BIG_ENDIAN_UINT32_WRITE(pchar, uint32) \
68 (*((pchar)+3) = LOBYTE(LOWORD(uint32)), \
69 *((pchar)+2) = HIBYTE(LOWORD(uint32)), \
70 *((pchar)+1) = LOBYTE(HIWORD(uint32)), \
71 *(pchar) = HIBYTE(HIWORD(uint32)), \
72 (uint32)) /* allow as r-value */
74 #define BIG_ENDIAN_UINT32_READ(pchar) \
75 (MAKELONG( \
76 MAKEWORD(*((pchar)+3), *((pchar)+2)), \
77 MAKEWORD(*((pchar)+1), *(pchar))))
79 #ifdef NDR_LOCAL_IS_BIG_ENDIAN
80 # define NDR_LOCAL_UINT32_WRITE(pchar, uint32) \
81 BIG_ENDIAN_UINT32_WRITE(pchar, uint32)
82 # define NDR_LOCAL_UINT32_READ(pchar) \
83 BIG_ENDIAN_UINT32_READ(pchar)
84 #else
85 # define NDR_LOCAL_UINT32_WRITE(pchar, uint32) \
86 LITTLE_ENDIAN_UINT32_WRITE(pchar, uint32)
87 # define NDR_LOCAL_UINT32_READ(pchar) \
88 LITTLE_ENDIAN_UINT32_READ(pchar)
89 #endif
91 /* _Align must be the desired alignment,
92 * e.g. ALIGN_LENGTH(len, 4) to align on a dword boundary. */
93 #define ALIGNED_LENGTH(_Len, _Align) (((_Len)+(_Align)-1)&~((_Align)-1))
94 #define ALIGNED_POINTER(_Ptr, _Align) ((LPVOID)ALIGNED_LENGTH((ULONG_PTR)(_Ptr), _Align))
95 #define ALIGN_LENGTH(_Len, _Align) _Len = ALIGNED_LENGTH(_Len, _Align)
96 #define ALIGN_POINTER(_Ptr, _Align) _Ptr = ALIGNED_POINTER(_Ptr, _Align)
98 #define STD_OVERFLOW_CHECK(_Msg) do { \
99 TRACE("buffer=%d/%ld\n", _Msg->Buffer - (unsigned char *)_Msg->RpcMsg->Buffer, _Msg->BufferLength); \
100 if (_Msg->Buffer > (unsigned char *)_Msg->RpcMsg->Buffer + _Msg->BufferLength) \
101 ERR("buffer overflow %d bytes\n", _Msg->Buffer - ((unsigned char *)_Msg->RpcMsg->Buffer + _Msg->BufferLength)); \
102 } while (0)
104 #define NDR_TABLE_SIZE 128
105 #define NDR_TABLE_MASK 127
107 static unsigned char *WINAPI NdrBaseTypeMarshall(PMIDL_STUB_MESSAGE, unsigned char *, PFORMAT_STRING);
108 static unsigned char *WINAPI NdrBaseTypeUnmarshall(PMIDL_STUB_MESSAGE, unsigned char **, PFORMAT_STRING, unsigned char);
109 static void WINAPI NdrBaseTypeBufferSize(PMIDL_STUB_MESSAGE, unsigned char *, PFORMAT_STRING);
110 static void WINAPI NdrBaseTypeFree(PMIDL_STUB_MESSAGE, unsigned char *, PFORMAT_STRING);
111 static unsigned long WINAPI NdrBaseTypeMemorySize(PMIDL_STUB_MESSAGE, PFORMAT_STRING);
113 const NDR_MARSHALL NdrMarshaller[NDR_TABLE_SIZE] = {
115 NdrBaseTypeMarshall, NdrBaseTypeMarshall, NdrBaseTypeMarshall,
116 NdrBaseTypeMarshall, NdrBaseTypeMarshall, NdrBaseTypeMarshall, NdrBaseTypeMarshall,
117 NdrBaseTypeMarshall, NdrBaseTypeMarshall, NdrBaseTypeMarshall, NdrBaseTypeMarshall,
118 NdrBaseTypeMarshall, NdrBaseTypeMarshall, NdrBaseTypeMarshall, NdrBaseTypeMarshall,
119 /* 0x10 */
120 NdrBaseTypeMarshall,
121 /* 0x11 */
122 NdrPointerMarshall, NdrPointerMarshall,
123 NdrPointerMarshall, NdrPointerMarshall,
124 /* 0x15 */
125 NdrSimpleStructMarshall, NdrSimpleStructMarshall,
126 NdrConformantStructMarshall, NdrConformantStructMarshall,
127 NdrConformantVaryingStructMarshall,
128 NdrComplexStructMarshall,
129 /* 0x1b */
130 NdrConformantArrayMarshall,
131 NdrConformantVaryingArrayMarshall,
132 NdrFixedArrayMarshall, NdrFixedArrayMarshall,
133 NdrVaryingArrayMarshall, NdrVaryingArrayMarshall,
134 NdrComplexArrayMarshall,
135 /* 0x22 */
136 NdrConformantStringMarshall, 0, 0,
137 NdrConformantStringMarshall,
138 NdrNonConformantStringMarshall, 0, 0, 0,
139 /* 0x2a */
140 NdrEncapsulatedUnionMarshall,
141 NdrNonEncapsulatedUnionMarshall,
142 NdrByteCountPointerMarshall,
143 NdrXmitOrRepAsMarshall, NdrXmitOrRepAsMarshall,
144 /* 0x2f */
145 NdrInterfacePointerMarshall,
146 /* 0xb0 */
147 0, 0, 0, 0,
148 NdrUserMarshalMarshall
150 const NDR_UNMARSHALL NdrUnmarshaller[NDR_TABLE_SIZE] = {
152 NdrBaseTypeUnmarshall, NdrBaseTypeUnmarshall, NdrBaseTypeUnmarshall,
153 NdrBaseTypeUnmarshall, NdrBaseTypeUnmarshall, NdrBaseTypeUnmarshall, NdrBaseTypeUnmarshall,
154 NdrBaseTypeUnmarshall, NdrBaseTypeUnmarshall, NdrBaseTypeUnmarshall, NdrBaseTypeUnmarshall,
155 NdrBaseTypeUnmarshall, NdrBaseTypeUnmarshall, NdrBaseTypeUnmarshall, NdrBaseTypeUnmarshall,
156 /* 0x10 */
157 NdrBaseTypeUnmarshall,
158 /* 0x11 */
159 NdrPointerUnmarshall, NdrPointerUnmarshall,
160 NdrPointerUnmarshall, NdrPointerUnmarshall,
161 /* 0x15 */
162 NdrSimpleStructUnmarshall, NdrSimpleStructUnmarshall,
163 NdrConformantStructUnmarshall, NdrConformantStructUnmarshall,
164 NdrConformantVaryingStructUnmarshall,
165 NdrComplexStructUnmarshall,
166 /* 0x1b */
167 NdrConformantArrayUnmarshall,
168 NdrConformantVaryingArrayUnmarshall,
169 NdrFixedArrayUnmarshall, NdrFixedArrayUnmarshall,
170 NdrVaryingArrayUnmarshall, NdrVaryingArrayUnmarshall,
171 NdrComplexArrayUnmarshall,
172 /* 0x22 */
173 NdrConformantStringUnmarshall, 0, 0,
174 NdrConformantStringUnmarshall,
175 NdrNonConformantStringUnmarshall, 0, 0, 0,
176 /* 0x2a */
177 NdrEncapsulatedUnionUnmarshall,
178 NdrNonEncapsulatedUnionUnmarshall,
179 NdrByteCountPointerUnmarshall,
180 NdrXmitOrRepAsUnmarshall, NdrXmitOrRepAsUnmarshall,
181 /* 0x2f */
182 NdrInterfacePointerUnmarshall,
183 /* 0xb0 */
184 0, 0, 0, 0,
185 NdrUserMarshalUnmarshall
187 const NDR_BUFFERSIZE NdrBufferSizer[NDR_TABLE_SIZE] = {
189 NdrBaseTypeBufferSize, NdrBaseTypeBufferSize, NdrBaseTypeBufferSize,
190 NdrBaseTypeBufferSize, NdrBaseTypeBufferSize, NdrBaseTypeBufferSize, NdrBaseTypeBufferSize,
191 NdrBaseTypeBufferSize, NdrBaseTypeBufferSize, NdrBaseTypeBufferSize, NdrBaseTypeBufferSize,
192 NdrBaseTypeBufferSize, NdrBaseTypeBufferSize, NdrBaseTypeBufferSize, NdrBaseTypeBufferSize,
193 /* 0x10 */
194 NdrBaseTypeBufferSize,
195 /* 0x11 */
196 NdrPointerBufferSize, NdrPointerBufferSize,
197 NdrPointerBufferSize, NdrPointerBufferSize,
198 /* 0x15 */
199 NdrSimpleStructBufferSize, NdrSimpleStructBufferSize,
200 NdrConformantStructBufferSize, NdrConformantStructBufferSize,
201 NdrConformantVaryingStructBufferSize,
202 NdrComplexStructBufferSize,
203 /* 0x1b */
204 NdrConformantArrayBufferSize,
205 NdrConformantVaryingArrayBufferSize,
206 NdrFixedArrayBufferSize, NdrFixedArrayBufferSize,
207 NdrVaryingArrayBufferSize, NdrVaryingArrayBufferSize,
208 NdrComplexArrayBufferSize,
209 /* 0x22 */
210 NdrConformantStringBufferSize, 0, 0,
211 NdrConformantStringBufferSize,
212 NdrNonConformantStringBufferSize, 0, 0, 0,
213 /* 0x2a */
214 NdrEncapsulatedUnionBufferSize,
215 NdrNonEncapsulatedUnionBufferSize,
216 NdrByteCountPointerBufferSize,
217 NdrXmitOrRepAsBufferSize, NdrXmitOrRepAsBufferSize,
218 /* 0x2f */
219 NdrInterfacePointerBufferSize,
220 /* 0xb0 */
221 0, 0, 0, 0,
222 NdrUserMarshalBufferSize
224 const NDR_MEMORYSIZE NdrMemorySizer[NDR_TABLE_SIZE] = {
226 NdrBaseTypeMemorySize, NdrBaseTypeMemorySize, NdrBaseTypeMemorySize,
227 NdrBaseTypeMemorySize, NdrBaseTypeMemorySize, NdrBaseTypeMemorySize, NdrBaseTypeMemorySize,
228 NdrBaseTypeMemorySize, NdrBaseTypeMemorySize, NdrBaseTypeMemorySize, NdrBaseTypeMemorySize,
229 NdrBaseTypeMemorySize, NdrBaseTypeMemorySize, NdrBaseTypeMemorySize, NdrBaseTypeMemorySize,
230 /* 0x10 */
231 NdrBaseTypeMemorySize,
232 /* 0x11 */
233 NdrPointerMemorySize, NdrPointerMemorySize,
234 NdrPointerMemorySize, NdrPointerMemorySize,
235 /* 0x15 */
236 NdrSimpleStructMemorySize, NdrSimpleStructMemorySize,
237 NdrConformantStructMemorySize, NdrConformantStructMemorySize,
238 NdrConformantVaryingStructMemorySize,
239 NdrComplexStructMemorySize,
240 /* 0x1b */
241 NdrConformantArrayMemorySize,
242 NdrConformantVaryingArrayMemorySize,
243 NdrFixedArrayMemorySize, NdrFixedArrayMemorySize,
244 NdrVaryingArrayMemorySize, NdrVaryingArrayMemorySize,
245 NdrComplexArrayMemorySize,
246 /* 0x22 */
247 NdrConformantStringMemorySize, 0, 0,
248 NdrConformantStringMemorySize,
249 NdrNonConformantStringMemorySize, 0, 0, 0,
250 /* 0x2a */
251 NdrEncapsulatedUnionMemorySize,
252 NdrNonEncapsulatedUnionMemorySize,
253 NdrByteCountPointerMemorySize,
254 NdrXmitOrRepAsMemorySize, NdrXmitOrRepAsMemorySize,
255 /* 0x2f */
256 NdrInterfacePointerMemorySize,
257 /* 0xb0 */
258 0, 0, 0, 0,
259 NdrUserMarshalMemorySize
261 const NDR_FREE NdrFreer[NDR_TABLE_SIZE] = {
263 NdrBaseTypeFree, NdrBaseTypeFree, NdrBaseTypeFree,
264 NdrBaseTypeFree, NdrBaseTypeFree, NdrBaseTypeFree, NdrBaseTypeFree,
265 NdrBaseTypeFree, NdrBaseTypeFree, NdrBaseTypeFree, NdrBaseTypeFree,
266 NdrBaseTypeFree, NdrBaseTypeFree, NdrBaseTypeFree, NdrBaseTypeFree,
267 /* 0x10 */
268 NdrBaseTypeFree,
269 /* 0x11 */
270 NdrPointerFree, NdrPointerFree,
271 NdrPointerFree, NdrPointerFree,
272 /* 0x15 */
273 NdrSimpleStructFree, NdrSimpleStructFree,
274 NdrConformantStructFree, NdrConformantStructFree,
275 NdrConformantVaryingStructFree,
276 NdrComplexStructFree,
277 /* 0x1b */
278 NdrConformantArrayFree,
279 NdrConformantVaryingArrayFree,
280 NdrFixedArrayFree, NdrFixedArrayFree,
281 NdrVaryingArrayFree, NdrVaryingArrayFree,
282 NdrComplexArrayFree,
283 /* 0x22 */
284 0, 0, 0,
285 0, 0, 0, 0, 0,
286 /* 0x2a */
287 NdrEncapsulatedUnionFree,
288 NdrNonEncapsulatedUnionFree,
290 NdrXmitOrRepAsFree, NdrXmitOrRepAsFree,
291 /* 0x2f */
292 NdrInterfacePointerFree,
293 /* 0xb0 */
294 0, 0, 0, 0,
295 NdrUserMarshalFree
298 void * WINAPI NdrAllocate(MIDL_STUB_MESSAGE *pStubMsg, size_t len)
300 /* hmm, this is probably supposed to do more? */
301 return pStubMsg->pfnAllocate(len);
304 static void WINAPI NdrFree(MIDL_STUB_MESSAGE *pStubMsg, unsigned char *Pointer)
306 pStubMsg->pfnFree(Pointer);
309 static inline BOOL IsConformanceOrVariancePresent(PFORMAT_STRING pFormat)
311 return (*(const ULONG *)pFormat != -1);
314 PFORMAT_STRING ReadConformance(MIDL_STUB_MESSAGE *pStubMsg, PFORMAT_STRING pFormat)
316 ALIGN_POINTER(pStubMsg->Buffer, 4);
317 pStubMsg->MaxCount = NDR_LOCAL_UINT32_READ(pStubMsg->Buffer);
318 pStubMsg->Buffer += 4;
319 TRACE("unmarshalled conformance is %ld\n", pStubMsg->MaxCount);
320 if (pStubMsg->fHasNewCorrDesc)
321 return pFormat+6;
322 else
323 return pFormat+4;
326 static inline PFORMAT_STRING ReadVariance(MIDL_STUB_MESSAGE *pStubMsg, PFORMAT_STRING pFormat)
328 if (pFormat && !IsConformanceOrVariancePresent(pFormat))
330 pStubMsg->Offset = 0;
331 pStubMsg->ActualCount = pStubMsg->MaxCount;
332 goto done;
335 ALIGN_POINTER(pStubMsg->Buffer, 4);
336 pStubMsg->Offset = NDR_LOCAL_UINT32_READ(pStubMsg->Buffer);
337 pStubMsg->Buffer += 4;
338 TRACE("offset is %ld\n", pStubMsg->Offset);
339 pStubMsg->ActualCount = NDR_LOCAL_UINT32_READ(pStubMsg->Buffer);
340 pStubMsg->Buffer += 4;
341 TRACE("variance is %ld\n", pStubMsg->ActualCount);
343 done:
344 if (pStubMsg->fHasNewCorrDesc)
345 return pFormat+6;
346 else
347 return pFormat+4;
350 /* writes the conformance value to the buffer */
351 static inline void WriteConformance(MIDL_STUB_MESSAGE *pStubMsg)
353 ALIGN_POINTER(pStubMsg->Buffer, 4);
354 NDR_LOCAL_UINT32_WRITE(pStubMsg->Buffer, pStubMsg->MaxCount);
355 pStubMsg->Buffer += 4;
358 /* writes the variance values to the buffer */
359 static inline void WriteVariance(MIDL_STUB_MESSAGE *pStubMsg)
361 ALIGN_POINTER(pStubMsg->Buffer, 4);
362 NDR_LOCAL_UINT32_WRITE(pStubMsg->Buffer, pStubMsg->Offset);
363 pStubMsg->Buffer += 4;
364 NDR_LOCAL_UINT32_WRITE(pStubMsg->Buffer, pStubMsg->ActualCount);
365 pStubMsg->Buffer += 4;
368 /* requests buffer space for the conformance value */
369 static inline void SizeConformance(MIDL_STUB_MESSAGE *pStubMsg)
371 ALIGN_LENGTH(pStubMsg->BufferLength, 4);
372 pStubMsg->BufferLength += 4;
375 /* requests buffer space for the variance values */
376 static inline void SizeVariance(MIDL_STUB_MESSAGE *pStubMsg)
378 ALIGN_LENGTH(pStubMsg->BufferLength, 4);
379 pStubMsg->BufferLength += 8;
382 PFORMAT_STRING ComputeConformanceOrVariance(
383 MIDL_STUB_MESSAGE *pStubMsg, unsigned char *pMemory,
384 PFORMAT_STRING pFormat, ULONG_PTR def, ULONG *pCount)
386 BYTE dtype = pFormat[0] & 0xf;
387 short ofs = *(short *)&pFormat[2];
388 LPVOID ptr = NULL;
389 DWORD data = 0;
391 if (!IsConformanceOrVariancePresent(pFormat)) {
392 /* null descriptor */
393 *pCount = def;
394 goto finish_conf;
397 switch (pFormat[0] & 0xf0) {
398 case RPC_FC_NORMAL_CONFORMANCE:
399 TRACE("normal conformance, ofs=%d\n", ofs);
400 ptr = pMemory;
401 break;
402 case RPC_FC_POINTER_CONFORMANCE:
403 TRACE("pointer conformance, ofs=%d\n", ofs);
404 ptr = pStubMsg->Memory;
405 break;
406 case RPC_FC_TOP_LEVEL_CONFORMANCE:
407 TRACE("toplevel conformance, ofs=%d\n", ofs);
408 if (pStubMsg->StackTop) {
409 ptr = pStubMsg->StackTop;
411 else {
412 /* -Os mode, *pCount is already set */
413 goto finish_conf;
415 break;
416 case RPC_FC_CONSTANT_CONFORMANCE:
417 data = ofs | ((DWORD)pFormat[1] << 16);
418 TRACE("constant conformance, val=%ld\n", data);
419 *pCount = data;
420 goto finish_conf;
421 case RPC_FC_TOP_LEVEL_MULTID_CONFORMANCE:
422 FIXME("toplevel multidimensional conformance, ofs=%d\n", ofs);
423 if (pStubMsg->StackTop) {
424 ptr = pStubMsg->StackTop;
426 else {
427 /* ? */
428 goto done_conf_grab;
430 break;
431 default:
432 FIXME("unknown conformance type %x\n", pFormat[0] & 0xf0);
435 switch (pFormat[1]) {
436 case RPC_FC_DEREFERENCE:
437 ptr = *(LPVOID*)((char *)ptr + ofs);
438 break;
439 case RPC_FC_CALLBACK:
441 unsigned char *old_stack_top = pStubMsg->StackTop;
442 pStubMsg->StackTop = ptr;
444 /* ofs is index into StubDesc->apfnExprEval */
445 TRACE("callback conformance into apfnExprEval[%d]\n", ofs);
446 pStubMsg->StubDesc->apfnExprEval[ofs](pStubMsg);
448 pStubMsg->StackTop = old_stack_top;
449 goto finish_conf;
451 default:
452 ptr = (char *)ptr + ofs;
453 break;
456 switch (dtype) {
457 case RPC_FC_LONG:
458 case RPC_FC_ULONG:
459 data = *(DWORD*)ptr;
460 break;
461 case RPC_FC_SHORT:
462 data = *(SHORT*)ptr;
463 break;
464 case RPC_FC_USHORT:
465 data = *(USHORT*)ptr;
466 break;
467 case RPC_FC_CHAR:
468 case RPC_FC_SMALL:
469 data = *(CHAR*)ptr;
470 break;
471 case RPC_FC_BYTE:
472 case RPC_FC_USMALL:
473 data = *(UCHAR*)ptr;
474 break;
475 default:
476 FIXME("unknown conformance data type %x\n", dtype);
477 goto done_conf_grab;
479 TRACE("dereferenced data type %x at %p, got %ld\n", dtype, ptr, data);
481 done_conf_grab:
482 switch (pFormat[1]) {
483 case 0: /* no op */
484 *pCount = data;
485 break;
486 case RPC_FC_DEREFERENCE:
487 /* already handled */
488 break;
489 case RPC_FC_ADD_1:
490 *pCount = data + 1;
491 break;
492 case RPC_FC_SUB_1:
493 *pCount = data - 1;
494 break;
495 case RPC_FC_MULT_2:
496 *pCount = data * 2;
497 break;
498 case RPC_FC_DIV_2:
499 *pCount = data / 2;
500 break;
501 default:
502 FIXME("unknown conformance op %d\n", pFormat[1]);
503 goto finish_conf;
506 finish_conf:
507 TRACE("resulting conformance is %ld\n", *pCount);
508 if (pStubMsg->fHasNewCorrDesc)
509 return pFormat+6;
510 else
511 return pFormat+4;
516 * NdrConformantString:
518 * What MS calls a ConformantString is, in DCE terminology,
519 * a Varying-Conformant String.
521 * maxlen: DWORD (max # of CHARTYPE characters, inclusive of '\0')
522 * offset: DWORD (actual string data begins at (offset) CHARTYPE's
523 * into unmarshalled string)
524 * length: DWORD (# of CHARTYPE characters, inclusive of '\0')
525 * [
526 * data: CHARTYPE[maxlen]
527 * ]
528 * ], where CHARTYPE is the appropriate character type (specified externally)
532 /***********************************************************************
533 * NdrConformantStringMarshall [RPCRT4.@]
535 unsigned char *WINAPI NdrConformantStringMarshall(MIDL_STUB_MESSAGE *pStubMsg,
536 unsigned char *pszMessage, PFORMAT_STRING pFormat)
538 unsigned long esize;
540 TRACE("(pStubMsg == ^%p, pszMessage == ^%p, pFormat == ^%p)\n", pStubMsg, pszMessage, pFormat);
542 if (*pFormat == RPC_FC_C_CSTRING) {
543 TRACE("string=%s\n", debugstr_a((char*)pszMessage));
544 pStubMsg->ActualCount = strlen((char*)pszMessage)+1;
545 esize = 1;
547 else if (*pFormat == RPC_FC_C_WSTRING) {
548 TRACE("string=%s\n", debugstr_w((LPWSTR)pszMessage));
549 pStubMsg->ActualCount = strlenW((LPWSTR)pszMessage)+1;
550 esize = 2;
552 else {
553 ERR("Unhandled string type: %#x\n", *pFormat);
554 /* FIXME: raise an exception. */
555 return NULL;
558 if (pFormat[1] == RPC_FC_STRING_SIZED)
559 pFormat = ComputeConformance(pStubMsg, pszMessage, pFormat + 2, 0);
560 else
561 pStubMsg->MaxCount = pStubMsg->ActualCount;
562 pStubMsg->Offset = 0;
563 WriteConformance(pStubMsg);
564 WriteVariance(pStubMsg);
566 memcpy(pStubMsg->Buffer, pszMessage, pStubMsg->ActualCount*esize); /* the string itself */
567 pStubMsg->Buffer += pStubMsg->ActualCount*esize;
569 STD_OVERFLOW_CHECK(pStubMsg);
571 /* success */
572 return NULL; /* is this always right? */
575 /***********************************************************************
576 * NdrConformantStringBufferSize [RPCRT4.@]
578 void WINAPI NdrConformantStringBufferSize(PMIDL_STUB_MESSAGE pStubMsg,
579 unsigned char* pMemory, PFORMAT_STRING pFormat)
581 TRACE("(pStubMsg == ^%p, pMemory == ^%p, pFormat == ^%p)\n", pStubMsg, pMemory, pFormat);
583 SizeConformance(pStubMsg);
584 SizeVariance(pStubMsg);
586 if (*pFormat == RPC_FC_C_CSTRING) {
587 /* we need + 1 octet for '\0' */
588 TRACE("string=%s\n", debugstr_a((char*)pMemory));
589 pStubMsg->BufferLength += strlen((char*)pMemory) + 1;
591 else if (*pFormat == RPC_FC_C_WSTRING) {
592 /* we need + 2 octets for L'\0' */
593 TRACE("string=%s\n", debugstr_w((LPWSTR)pMemory));
594 pStubMsg->BufferLength += strlenW((LPWSTR)pMemory)*2 + 2;
596 else {
597 ERR("Unhandled string type: %#x\n", *pFormat);
598 /* FIXME: raise an exception */
602 /************************************************************************
603 * NdrConformantStringMemorySize [RPCRT4.@]
605 unsigned long WINAPI NdrConformantStringMemorySize( PMIDL_STUB_MESSAGE pStubMsg,
606 PFORMAT_STRING pFormat )
608 unsigned long rslt = 0;
610 TRACE("(pStubMsg == ^%p, pFormat == ^%p)\n", pStubMsg, pFormat);
612 assert(pStubMsg && pFormat);
614 if (*pFormat == RPC_FC_C_CSTRING) {
615 rslt = NDR_LOCAL_UINT32_READ(pStubMsg->Buffer); /* maxlen */
617 else if (*pFormat == RPC_FC_C_WSTRING) {
618 rslt = NDR_LOCAL_UINT32_READ(pStubMsg->Buffer)*2; /* maxlen */
620 else {
621 ERR("Unhandled string type: %#x\n", *pFormat);
622 /* FIXME: raise an exception */
625 if (pFormat[1] != RPC_FC_PAD) {
626 FIXME("sized string format=%d\n", pFormat[1]);
629 TRACE(" --> %lu\n", rslt);
630 return rslt;
633 /************************************************************************
634 * NdrConformantStringUnmarshall [RPCRT4.@]
636 unsigned char *WINAPI NdrConformantStringUnmarshall( PMIDL_STUB_MESSAGE pStubMsg,
637 unsigned char** ppMemory, PFORMAT_STRING pFormat, unsigned char fMustAlloc )
639 unsigned long len, esize;
641 TRACE("(pStubMsg == ^%p, *pMemory == ^%p, pFormat == ^%p, fMustAlloc == %u)\n",
642 pStubMsg, *ppMemory, pFormat, fMustAlloc);
644 assert(pFormat && ppMemory && pStubMsg);
646 ReadConformance(pStubMsg, NULL);
647 ReadVariance(pStubMsg, NULL);
649 if (*pFormat == RPC_FC_C_CSTRING) esize = 1;
650 else if (*pFormat == RPC_FC_C_WSTRING) esize = 2;
651 else {
652 ERR("Unhandled string type: %#x\n", *pFormat);
653 /* FIXME: raise an exception */
654 esize = 0;
657 len = pStubMsg->ActualCount;
659 if (fMustAlloc || !*ppMemory)
660 *ppMemory = NdrAllocate(pStubMsg, len*esize);
662 memcpy(*ppMemory, pStubMsg->Buffer, len*esize);
664 pStubMsg->Buffer += len*esize;
666 if (*pFormat == RPC_FC_C_CSTRING) {
667 TRACE("string=%s\n", debugstr_a((char*)*ppMemory));
669 else if (*pFormat == RPC_FC_C_WSTRING) {
670 TRACE("string=%s\n", debugstr_w((LPWSTR)*ppMemory));
673 return NULL; /* FIXME: is this always right? */
676 /***********************************************************************
677 * NdrNonConformantStringMarshall [RPCRT4.@]
679 unsigned char * WINAPI NdrNonConformantStringMarshall(PMIDL_STUB_MESSAGE pStubMsg,
680 unsigned char *pMemory,
681 PFORMAT_STRING pFormat)
683 FIXME("stub\n");
684 return NULL;
687 /***********************************************************************
688 * NdrNonConformantStringUnmarshall [RPCRT4.@]
690 unsigned char * WINAPI NdrNonConformantStringUnmarshall(PMIDL_STUB_MESSAGE pStubMsg,
691 unsigned char **ppMemory,
692 PFORMAT_STRING pFormat,
693 unsigned char fMustAlloc)
695 FIXME("stub\n");
696 return NULL;
699 /***********************************************************************
700 * NdrNonConformantStringBufferSize [RPCRT4.@]
702 void WINAPI NdrNonConformantStringBufferSize(PMIDL_STUB_MESSAGE pStubMsg,
703 unsigned char *pMemory,
704 PFORMAT_STRING pFormat)
706 FIXME("stub\n");
709 /***********************************************************************
710 * NdrNonConformantStringMemorySize [RPCRT4.@]
712 unsigned long WINAPI NdrNonConformantStringMemorySize(PMIDL_STUB_MESSAGE pStubMsg,
713 PFORMAT_STRING pFormat)
715 FIXME("stub\n");
716 return 0;
719 static inline void dump_pointer_attr(unsigned char attr)
721 if (attr & RPC_FC_P_ALLOCALLNODES)
722 TRACE(" RPC_FC_P_ALLOCALLNODES");
723 if (attr & RPC_FC_P_DONTFREE)
724 TRACE(" RPC_FC_P_DONTFREE");
725 if (attr & RPC_FC_P_ONSTACK)
726 TRACE(" RPC_FC_P_ONSTACK");
727 if (attr & RPC_FC_P_SIMPLEPOINTER)
728 TRACE(" RPC_FC_P_SIMPLEPOINTER");
729 if (attr & RPC_FC_P_DEREF)
730 TRACE(" RPC_FC_P_DEREF");
731 TRACE("\n");
734 /***********************************************************************
735 * PointerMarshall
737 void WINAPI PointerMarshall(PMIDL_STUB_MESSAGE pStubMsg,
738 unsigned char *Buffer,
739 unsigned char *Pointer,
740 PFORMAT_STRING pFormat)
742 unsigned type = pFormat[0], attr = pFormat[1];
743 PFORMAT_STRING desc;
744 NDR_MARSHALL m;
746 TRACE("(%p,%p,%p,%p)\n", pStubMsg, Buffer, Pointer, pFormat);
747 TRACE("type=0x%x, attr=", type); dump_pointer_attr(attr);
748 pFormat += 2;
749 if (attr & RPC_FC_P_SIMPLEPOINTER) desc = pFormat;
750 else desc = pFormat + *(const SHORT*)pFormat;
752 switch (type) {
753 case RPC_FC_RP: /* ref pointer (always non-null) */
754 #if 0 /* this causes problems for InstallShield so is disabled - we need more tests */
755 if (!Pointer)
756 RpcRaiseException(RPC_X_NULL_REF_POINTER);
757 #endif
758 break;
759 case RPC_FC_UP: /* unique pointer */
760 case RPC_FC_OP: /* object pointer - same as unique here */
761 TRACE("writing %p to buffer\n", Pointer);
762 NDR_LOCAL_UINT32_WRITE(Buffer, (unsigned long)Pointer);
763 break;
764 case RPC_FC_FP:
765 default:
766 FIXME("unhandled ptr type=%02x\n", type);
767 RpcRaiseException(RPC_X_BAD_STUB_DATA);
770 TRACE("calling marshaller for type 0x%x\n", (int)*desc);
772 if (Pointer) {
773 if (attr & RPC_FC_P_DEREF) {
774 Pointer = *(unsigned char**)Pointer;
775 TRACE("deref => %p\n", Pointer);
777 m = NdrMarshaller[*desc & NDR_TABLE_MASK];
778 if (m) m(pStubMsg, Pointer, desc);
779 else FIXME("no marshaller for data type=%02x\n", *desc);
782 STD_OVERFLOW_CHECK(pStubMsg);
785 /***********************************************************************
786 * PointerUnmarshall
788 void WINAPI PointerUnmarshall(PMIDL_STUB_MESSAGE pStubMsg,
789 unsigned char *Buffer,
790 unsigned char **pPointer,
791 PFORMAT_STRING pFormat,
792 unsigned char fMustAlloc)
794 unsigned type = pFormat[0], attr = pFormat[1];
795 PFORMAT_STRING desc;
796 NDR_UNMARSHALL m;
797 DWORD pointer_id = 0;
799 TRACE("(%p,%p,%p,%p,%d)\n", pStubMsg, Buffer, pPointer, pFormat, fMustAlloc);
800 TRACE("type=0x%x, attr=", type); dump_pointer_attr(attr);
801 pFormat += 2;
802 if (attr & RPC_FC_P_SIMPLEPOINTER) desc = pFormat;
803 else desc = pFormat + *(const SHORT*)pFormat;
805 switch (type) {
806 case RPC_FC_RP: /* ref pointer (always non-null) */
807 pointer_id = ~0UL;
808 break;
809 case RPC_FC_UP: /* unique pointer */
810 pointer_id = NDR_LOCAL_UINT32_READ(Buffer);
811 TRACE("pointer_id is 0x%08lx\n", pointer_id);
812 break;
813 case RPC_FC_OP: /* object pointer - we must free data before overwriting it */
814 pointer_id = NDR_LOCAL_UINT32_READ(Buffer);
815 TRACE("pointer_id is 0x%08lx\n", pointer_id);
816 if (*pPointer)
817 FIXME("free object pointer %p\n", *pPointer);
818 break;
819 case RPC_FC_FP:
820 default:
821 FIXME("unhandled ptr type=%02x\n", type);
822 RpcRaiseException(RPC_X_BAD_STUB_DATA);
825 if (pointer_id) {
826 if (attr & RPC_FC_P_DEREF) {
827 if (!*pPointer || fMustAlloc)
828 *pPointer = NdrAllocate(pStubMsg, sizeof(void *));
829 pPointer = *(unsigned char***)pPointer;
830 TRACE("deref => %p\n", pPointer);
832 m = NdrUnmarshaller[*desc & NDR_TABLE_MASK];
833 if (m) m(pStubMsg, pPointer, desc, fMustAlloc);
834 else FIXME("no unmarshaller for data type=%02x\n", *desc);
837 TRACE("pointer=%p\n", *pPointer);
840 /***********************************************************************
841 * PointerBufferSize
843 void WINAPI PointerBufferSize(PMIDL_STUB_MESSAGE pStubMsg,
844 unsigned char *Pointer,
845 PFORMAT_STRING pFormat)
847 unsigned type = pFormat[0], attr = pFormat[1];
848 PFORMAT_STRING desc;
849 NDR_BUFFERSIZE m;
851 TRACE("(%p,%p,%p)\n", pStubMsg, Pointer, pFormat);
852 TRACE("type=0x%x, attr=", type); dump_pointer_attr(attr);
853 pFormat += 2;
854 if (attr & RPC_FC_P_SIMPLEPOINTER) desc = pFormat;
855 else desc = pFormat + *(const SHORT*)pFormat;
857 switch (type) {
858 case RPC_FC_RP: /* ref pointer (always non-null) */
859 break;
860 case RPC_FC_OP:
861 case RPC_FC_UP:
862 /* NULL pointer has no further representation */
863 if (!Pointer)
864 return;
865 break;
866 case RPC_FC_FP:
867 default:
868 FIXME("unhandled ptr type=%02x\n", type);
869 RpcRaiseException(RPC_X_BAD_STUB_DATA);
872 if (attr & RPC_FC_P_DEREF) {
873 Pointer = *(unsigned char**)Pointer;
874 TRACE("deref => %p\n", Pointer);
877 m = NdrBufferSizer[*desc & NDR_TABLE_MASK];
878 if (m) m(pStubMsg, Pointer, desc);
879 else FIXME("no buffersizer for data type=%02x\n", *desc);
882 /***********************************************************************
883 * PointerMemorySize [RPCRT4.@]
885 unsigned long WINAPI PointerMemorySize(PMIDL_STUB_MESSAGE pStubMsg,
886 unsigned char *Buffer,
887 PFORMAT_STRING pFormat)
889 unsigned type = pFormat[0], attr = pFormat[1];
890 PFORMAT_STRING desc;
891 NDR_MEMORYSIZE m;
893 FIXME("(%p,%p,%p): stub\n", pStubMsg, Buffer, pFormat);
894 TRACE("type=0x%x, attr=", type); dump_pointer_attr(attr);
895 pFormat += 2;
896 if (attr & RPC_FC_P_SIMPLEPOINTER) desc = pFormat;
897 else desc = pFormat + *(const SHORT*)pFormat;
899 switch (type) {
900 case RPC_FC_RP: /* ref pointer (always non-null) */
901 break;
902 default:
903 FIXME("unhandled ptr type=%02x\n", type);
904 RpcRaiseException(RPC_X_BAD_STUB_DATA);
907 if (attr & RPC_FC_P_DEREF) {
908 TRACE("deref\n");
911 m = NdrMemorySizer[*desc & NDR_TABLE_MASK];
912 if (m) m(pStubMsg, desc);
913 else FIXME("no memorysizer for data type=%02x\n", *desc);
915 return 0;
918 /***********************************************************************
919 * PointerFree [RPCRT4.@]
921 void WINAPI PointerFree(PMIDL_STUB_MESSAGE pStubMsg,
922 unsigned char *Pointer,
923 PFORMAT_STRING pFormat)
925 unsigned type = pFormat[0], attr = pFormat[1];
926 PFORMAT_STRING desc;
927 NDR_FREE m;
929 TRACE("(%p,%p,%p)\n", pStubMsg, Pointer, pFormat);
930 TRACE("type=0x%x, attr=", type); dump_pointer_attr(attr);
931 if (attr & RPC_FC_P_DONTFREE) return;
932 pFormat += 2;
933 if (attr & RPC_FC_P_SIMPLEPOINTER) desc = pFormat;
934 else desc = pFormat + *(const SHORT*)pFormat;
936 if (!Pointer) return;
938 if (attr & RPC_FC_P_DEREF) {
939 Pointer = *(unsigned char**)Pointer;
940 TRACE("deref => %p\n", Pointer);
943 m = NdrFreer[*desc & NDR_TABLE_MASK];
944 if (m) m(pStubMsg, Pointer, desc);
946 /* hmm... is this sensible?
947 * perhaps we should check if the memory comes from NdrAllocate,
948 * and deallocate only if so - checking if the pointer is between
949 * BufferStart and BufferEnd is probably no good since the buffer
950 * may be reallocated when the server wants to marshal the reply */
951 switch (*desc) {
952 case RPC_FC_BOGUS_STRUCT:
953 case RPC_FC_BOGUS_ARRAY:
954 case RPC_FC_USER_MARSHAL:
955 case RPC_FC_CARRAY:
956 case RPC_FC_CVARRAY:
957 break;
958 default:
959 FIXME("unhandled data type=%02x\n", *desc);
960 break;
961 case RPC_FC_C_CSTRING:
962 case RPC_FC_C_WSTRING:
963 if (pStubMsg->ReuseBuffer) goto notfree;
964 break;
965 case RPC_FC_IP:
966 goto notfree;
969 if (attr & RPC_FC_P_ONSTACK) {
970 TRACE("not freeing stack ptr %p\n", Pointer);
971 return;
973 TRACE("freeing %p\n", Pointer);
974 NdrFree(pStubMsg, Pointer);
975 return;
976 notfree:
977 TRACE("not freeing %p\n", Pointer);
980 /***********************************************************************
981 * EmbeddedPointerMarshall
983 unsigned char * WINAPI EmbeddedPointerMarshall(PMIDL_STUB_MESSAGE pStubMsg,
984 unsigned char *pMemory,
985 PFORMAT_STRING pFormat)
987 unsigned char *Mark = pStubMsg->BufferMark;
988 unsigned long Offset = pStubMsg->Offset;
989 unsigned ofs, rep, count, stride, xofs;
990 unsigned i;
992 TRACE("(%p,%p,%p)\n", pStubMsg, pMemory, pFormat);
994 if (*pFormat != RPC_FC_PP) return NULL;
995 pFormat += 2;
997 while (pFormat[0] != RPC_FC_END) {
998 switch (pFormat[0]) {
999 default:
1000 FIXME("unknown repeat type %d\n", pFormat[0]);
1001 case RPC_FC_NO_REPEAT:
1002 rep = 1;
1003 stride = 0;
1004 ofs = 0;
1005 count = 1;
1006 xofs = 0;
1007 pFormat += 2;
1008 break;
1009 case RPC_FC_FIXED_REPEAT:
1010 rep = *(const WORD*)&pFormat[2];
1011 stride = *(const WORD*)&pFormat[4];
1012 ofs = *(const WORD*)&pFormat[6];
1013 count = *(const WORD*)&pFormat[8];
1014 xofs = 0;
1015 pFormat += 10;
1016 break;
1017 case RPC_FC_VARIABLE_REPEAT:
1018 rep = pStubMsg->MaxCount;
1019 stride = *(const WORD*)&pFormat[2];
1020 ofs = *(const WORD*)&pFormat[4];
1021 count = *(const WORD*)&pFormat[6];
1022 xofs = (pFormat[1] == RPC_FC_VARIABLE_OFFSET) ? Offset * stride : 0;
1023 pFormat += 8;
1024 break;
1026 for (i = 0; i < rep; i++) {
1027 PFORMAT_STRING info = pFormat;
1028 unsigned char *membase = pMemory + (i * stride);
1029 unsigned char *bufbase = Mark + (i * stride);
1030 unsigned u;
1031 /* ofs doesn't seem to matter in this context */
1032 for (u=0; u<count; u++,info+=8) {
1033 unsigned char *memptr = membase + *(const SHORT*)&info[0];
1034 unsigned char *bufptr = bufbase + *(const SHORT*)&info[2];
1035 PointerMarshall(pStubMsg, bufptr, *(unsigned char**)memptr, info+4);
1038 pFormat += 8 * count;
1041 STD_OVERFLOW_CHECK(pStubMsg);
1043 return NULL;
1046 /***********************************************************************
1047 * EmbeddedPointerUnmarshall
1049 unsigned char * WINAPI EmbeddedPointerUnmarshall(PMIDL_STUB_MESSAGE pStubMsg,
1050 unsigned char **ppMemory,
1051 PFORMAT_STRING pFormat,
1052 unsigned char fMustAlloc)
1054 unsigned char *Mark = pStubMsg->BufferMark;
1055 unsigned long Offset = pStubMsg->Offset;
1056 unsigned ofs, rep, count, stride, xofs;
1057 unsigned i;
1059 TRACE("(%p,%p,%p,%d)\n", pStubMsg, ppMemory, pFormat, fMustAlloc);
1061 if (*pFormat != RPC_FC_PP) return NULL;
1062 pFormat += 2;
1064 while (pFormat[0] != RPC_FC_END) {
1065 TRACE("pFormat[0] = 0x%x\n", pFormat[0]);
1066 switch (pFormat[0]) {
1067 default:
1068 FIXME("unknown repeat type %d\n", pFormat[0]);
1069 case RPC_FC_NO_REPEAT:
1070 rep = 1;
1071 stride = 0;
1072 ofs = 0;
1073 count = 1;
1074 xofs = 0;
1075 pFormat += 2;
1076 break;
1077 case RPC_FC_FIXED_REPEAT:
1078 rep = *(const WORD*)&pFormat[2];
1079 stride = *(const WORD*)&pFormat[4];
1080 ofs = *(const WORD*)&pFormat[6];
1081 count = *(const WORD*)&pFormat[8];
1082 xofs = 0;
1083 pFormat += 10;
1084 break;
1085 case RPC_FC_VARIABLE_REPEAT:
1086 rep = pStubMsg->MaxCount;
1087 stride = *(const WORD*)&pFormat[2];
1088 ofs = *(const WORD*)&pFormat[4];
1089 count = *(const WORD*)&pFormat[6];
1090 xofs = (pFormat[1] == RPC_FC_VARIABLE_OFFSET) ? Offset * stride : 0;
1091 pFormat += 8;
1092 break;
1094 /* ofs doesn't seem to matter in this context */
1095 for (i = 0; i < rep; i++) {
1096 PFORMAT_STRING info = pFormat;
1097 unsigned char *membase = *ppMemory + (i * stride);
1098 unsigned char *bufbase = Mark + (i * stride);
1099 unsigned u;
1100 for (u=0; u<count; u++,info+=8) {
1101 unsigned char *memptr = membase + *(const SHORT*)&info[0];
1102 unsigned char *bufptr = bufbase + *(const SHORT*)&info[2];
1103 *(void **)memptr = NULL;
1104 PointerUnmarshall(pStubMsg, bufptr, (unsigned char**)memptr, info+4, fMustAlloc);
1107 pFormat += 8 * count;
1110 return NULL;
1113 /***********************************************************************
1114 * EmbeddedPointerBufferSize
1116 void WINAPI EmbeddedPointerBufferSize(PMIDL_STUB_MESSAGE pStubMsg,
1117 unsigned char *pMemory,
1118 PFORMAT_STRING pFormat)
1120 unsigned long Offset = pStubMsg->Offset;
1121 unsigned ofs, rep, count, stride, xofs;
1122 unsigned i;
1124 TRACE("(%p,%p,%p)\n", pStubMsg, pMemory, pFormat);
1126 if (pStubMsg->IgnoreEmbeddedPointers) return;
1128 if (*pFormat != RPC_FC_PP) return;
1129 pFormat += 2;
1131 while (pFormat[0] != RPC_FC_END) {
1132 switch (pFormat[0]) {
1133 default:
1134 FIXME("unknown repeat type %d\n", pFormat[0]);
1135 case RPC_FC_NO_REPEAT:
1136 rep = 1;
1137 stride = 0;
1138 ofs = 0;
1139 count = 1;
1140 xofs = 0;
1141 pFormat += 2;
1142 break;
1143 case RPC_FC_FIXED_REPEAT:
1144 rep = *(const WORD*)&pFormat[2];
1145 stride = *(const WORD*)&pFormat[4];
1146 ofs = *(const WORD*)&pFormat[6];
1147 count = *(const WORD*)&pFormat[8];
1148 xofs = 0;
1149 pFormat += 10;
1150 break;
1151 case RPC_FC_VARIABLE_REPEAT:
1152 rep = pStubMsg->MaxCount;
1153 stride = *(const WORD*)&pFormat[2];
1154 ofs = *(const WORD*)&pFormat[4];
1155 count = *(const WORD*)&pFormat[6];
1156 xofs = (pFormat[1] == RPC_FC_VARIABLE_OFFSET) ? Offset * stride : 0;
1157 pFormat += 8;
1158 break;
1160 /* ofs doesn't seem to matter in this context */
1161 for (i = 0; i < rep; i++) {
1162 PFORMAT_STRING info = pFormat;
1163 unsigned char *membase = pMemory + (i * stride);
1164 unsigned u;
1165 for (u=0; u<count; u++,info+=8) {
1166 unsigned char *memptr = membase + *(const SHORT*)&info[0];
1167 PointerBufferSize(pStubMsg, *(unsigned char**)memptr, info+4);
1170 pFormat += 8 * count;
1174 /***********************************************************************
1175 * EmbeddedPointerMemorySize
1177 unsigned long WINAPI EmbeddedPointerMemorySize(PMIDL_STUB_MESSAGE pStubMsg,
1178 PFORMAT_STRING pFormat)
1180 unsigned long Offset = pStubMsg->Offset;
1181 unsigned char *Mark = pStubMsg->BufferMark;
1182 unsigned ofs, rep, count, stride, xofs;
1183 unsigned i;
1185 FIXME("(%p,%p): stub\n", pStubMsg, pFormat);
1187 if (*pFormat != RPC_FC_PP) return 0;
1188 pFormat += 2;
1190 while (pFormat[0] != RPC_FC_END) {
1191 switch (pFormat[0]) {
1192 default:
1193 FIXME("unknown repeat type %d\n", pFormat[0]);
1194 case RPC_FC_NO_REPEAT:
1195 rep = 1;
1196 stride = 0;
1197 ofs = 0;
1198 count = 1;
1199 xofs = 0;
1200 pFormat += 2;
1201 break;
1202 case RPC_FC_FIXED_REPEAT:
1203 rep = *(const WORD*)&pFormat[2];
1204 stride = *(const WORD*)&pFormat[4];
1205 ofs = *(const WORD*)&pFormat[6];
1206 count = *(const WORD*)&pFormat[8];
1207 xofs = 0;
1208 pFormat += 10;
1209 break;
1210 case RPC_FC_VARIABLE_REPEAT:
1211 rep = pStubMsg->MaxCount;
1212 stride = *(const WORD*)&pFormat[2];
1213 ofs = *(const WORD*)&pFormat[4];
1214 count = *(const WORD*)&pFormat[6];
1215 xofs = (pFormat[1] == RPC_FC_VARIABLE_OFFSET) ? Offset * stride : 0;
1216 pFormat += 8;
1217 break;
1219 /* ofs doesn't seem to matter in this context */
1220 for (i = 0; i < rep; i++) {
1221 PFORMAT_STRING info = pFormat;
1222 unsigned char *bufbase = Mark + (i * stride);
1223 unsigned u;
1224 for (u=0; u<count; u++,info+=8) {
1225 unsigned char *bufptr = bufbase + *(const SHORT*)&info[2];
1226 PointerMemorySize(pStubMsg, bufptr, info+4);
1229 pFormat += 8 * count;
1232 return 0;
1235 /***********************************************************************
1236 * EmbeddedPointerFree
1238 void WINAPI EmbeddedPointerFree(PMIDL_STUB_MESSAGE pStubMsg,
1239 unsigned char *pMemory,
1240 PFORMAT_STRING pFormat)
1242 unsigned long Offset = pStubMsg->Offset;
1243 unsigned ofs, rep, count, stride, xofs;
1244 unsigned i;
1246 TRACE("(%p,%p,%p)\n", pStubMsg, pMemory, pFormat);
1247 if (*pFormat != RPC_FC_PP) return;
1248 pFormat += 2;
1250 while (pFormat[0] != RPC_FC_END) {
1251 switch (pFormat[0]) {
1252 default:
1253 FIXME("unknown repeat type %d\n", pFormat[0]);
1254 case RPC_FC_NO_REPEAT:
1255 rep = 1;
1256 stride = 0;
1257 ofs = 0;
1258 count = 1;
1259 xofs = 0;
1260 pFormat += 2;
1261 break;
1262 case RPC_FC_FIXED_REPEAT:
1263 rep = *(const WORD*)&pFormat[2];
1264 stride = *(const WORD*)&pFormat[4];
1265 ofs = *(const WORD*)&pFormat[6];
1266 count = *(const WORD*)&pFormat[8];
1267 xofs = 0;
1268 pFormat += 10;
1269 break;
1270 case RPC_FC_VARIABLE_REPEAT:
1271 rep = pStubMsg->MaxCount;
1272 stride = *(const WORD*)&pFormat[2];
1273 ofs = *(const WORD*)&pFormat[4];
1274 count = *(const WORD*)&pFormat[6];
1275 xofs = (pFormat[1] == RPC_FC_VARIABLE_OFFSET) ? Offset * stride : 0;
1276 pFormat += 8;
1277 break;
1279 /* ofs doesn't seem to matter in this context */
1280 for (i = 0; i < rep; i++) {
1281 PFORMAT_STRING info = pFormat;
1282 unsigned char *membase = pMemory + (i * stride);
1283 unsigned u;
1284 for (u=0; u<count; u++,info+=8) {
1285 unsigned char *memptr = membase + *(const SHORT*)&info[0];
1286 PointerFree(pStubMsg, *(unsigned char**)memptr, info+4);
1289 pFormat += 8 * count;
1293 /***********************************************************************
1294 * NdrPointerMarshall [RPCRT4.@]
1296 unsigned char * WINAPI NdrPointerMarshall(PMIDL_STUB_MESSAGE pStubMsg,
1297 unsigned char *pMemory,
1298 PFORMAT_STRING pFormat)
1300 unsigned char *Buffer;
1302 TRACE("(%p,%p,%p)\n", pStubMsg, pMemory, pFormat);
1304 /* incremement the buffer here instead of in PointerMarshall,
1305 * as that is used by embedded pointers which already handle the incrementing
1306 * the buffer, and shouldn't write any additional pointer data to the wire */
1307 if (*pFormat != RPC_FC_RP)
1309 ALIGN_POINTER(pStubMsg->Buffer, 4);
1310 Buffer = pStubMsg->Buffer;
1311 pStubMsg->Buffer += 4;
1313 else
1314 Buffer = pStubMsg->Buffer;
1316 PointerMarshall(pStubMsg, Buffer, pMemory, pFormat);
1318 STD_OVERFLOW_CHECK(pStubMsg);
1320 return NULL;
1323 /***********************************************************************
1324 * NdrPointerUnmarshall [RPCRT4.@]
1326 unsigned char * WINAPI NdrPointerUnmarshall(PMIDL_STUB_MESSAGE pStubMsg,
1327 unsigned char **ppMemory,
1328 PFORMAT_STRING pFormat,
1329 unsigned char fMustAlloc)
1331 unsigned char *Buffer;
1333 TRACE("(%p,%p,%p,%d)\n", pStubMsg, ppMemory, pFormat, fMustAlloc);
1335 /* incremement the buffer here instead of in PointerUnmarshall,
1336 * as that is used by embedded pointers which already handle the incrementing
1337 * the buffer, and shouldn't read any additional pointer data from the
1338 * buffer */
1339 if (*pFormat != RPC_FC_RP)
1341 ALIGN_POINTER(pStubMsg->Buffer, 4);
1342 Buffer = pStubMsg->Buffer;
1343 pStubMsg->Buffer += 4;
1345 else
1346 Buffer = pStubMsg->Buffer;
1348 PointerUnmarshall(pStubMsg, Buffer, ppMemory, pFormat, fMustAlloc);
1350 return NULL;
1353 /***********************************************************************
1354 * NdrPointerBufferSize [RPCRT4.@]
1356 void WINAPI NdrPointerBufferSize(PMIDL_STUB_MESSAGE pStubMsg,
1357 unsigned char *pMemory,
1358 PFORMAT_STRING pFormat)
1360 TRACE("(%p,%p,%p)\n", pStubMsg, pMemory, pFormat);
1362 /* incremement the buffer length here instead of in PointerBufferSize,
1363 * as that is used by embedded pointers which already handle the buffer
1364 * length, and shouldn't write anything more to the wire */
1365 if (*pFormat != RPC_FC_RP)
1367 ALIGN_LENGTH(pStubMsg->BufferLength, 4);
1368 pStubMsg->BufferLength += 4;
1371 PointerBufferSize(pStubMsg, pMemory, pFormat);
1374 /***********************************************************************
1375 * NdrPointerMemorySize [RPCRT4.@]
1377 unsigned long WINAPI NdrPointerMemorySize(PMIDL_STUB_MESSAGE pStubMsg,
1378 PFORMAT_STRING pFormat)
1380 /* unsigned size = *(LPWORD)(pFormat+2); */
1381 FIXME("(%p,%p): stub\n", pStubMsg, pFormat);
1382 PointerMemorySize(pStubMsg, pStubMsg->Buffer, pFormat);
1383 return 0;
1386 /***********************************************************************
1387 * NdrPointerFree [RPCRT4.@]
1389 void WINAPI NdrPointerFree(PMIDL_STUB_MESSAGE pStubMsg,
1390 unsigned char *pMemory,
1391 PFORMAT_STRING pFormat)
1393 TRACE("(%p,%p,%p)\n", pStubMsg, pMemory, pFormat);
1394 PointerFree(pStubMsg, pMemory, pFormat);
1397 /***********************************************************************
1398 * NdrSimpleStructMarshall [RPCRT4.@]
1400 unsigned char * WINAPI NdrSimpleStructMarshall(PMIDL_STUB_MESSAGE pStubMsg,
1401 unsigned char *pMemory,
1402 PFORMAT_STRING pFormat)
1404 unsigned size = *(const WORD*)(pFormat+2);
1405 TRACE("(%p,%p,%p)\n", pStubMsg, pMemory, pFormat);
1407 ALIGN_POINTER(pStubMsg->Buffer, pFormat[1] + 1);
1409 memcpy(pStubMsg->Buffer, pMemory, size);
1410 pStubMsg->BufferMark = pStubMsg->Buffer;
1411 pStubMsg->Buffer += size;
1413 if (pFormat[0] != RPC_FC_STRUCT)
1414 EmbeddedPointerMarshall(pStubMsg, pMemory, pFormat+4);
1416 STD_OVERFLOW_CHECK(pStubMsg);
1418 return NULL;
1421 /***********************************************************************
1422 * NdrSimpleStructUnmarshall [RPCRT4.@]
1424 unsigned char * WINAPI NdrSimpleStructUnmarshall(PMIDL_STUB_MESSAGE pStubMsg,
1425 unsigned char **ppMemory,
1426 PFORMAT_STRING pFormat,
1427 unsigned char fMustAlloc)
1429 unsigned size = *(const WORD*)(pFormat+2);
1430 TRACE("(%p,%p,%p,%d)\n", pStubMsg, ppMemory, pFormat, fMustAlloc);
1432 ALIGN_POINTER(pStubMsg->Buffer, pFormat[1] + 1);
1434 if (fMustAlloc) {
1435 *ppMemory = NdrAllocate(pStubMsg, size);
1436 memcpy(*ppMemory, pStubMsg->Buffer, size);
1437 } else {
1438 if (pStubMsg->ReuseBuffer && !*ppMemory)
1439 /* for servers, we may just point straight into the RPC buffer, I think
1440 * (I guess that's what MS does since MIDL code doesn't try to free) */
1441 *ppMemory = pStubMsg->Buffer;
1442 else
1443 /* for clients, memory should be provided by caller */
1444 memcpy(*ppMemory, pStubMsg->Buffer, size);
1447 pStubMsg->BufferMark = pStubMsg->Buffer;
1448 pStubMsg->Buffer += size;
1450 if (pFormat[0] != RPC_FC_STRUCT)
1451 EmbeddedPointerUnmarshall(pStubMsg, ppMemory, pFormat+4, fMustAlloc);
1453 return NULL;
1457 /***********************************************************************
1458 * NdrSimpleStructUnmarshall [RPCRT4.@]
1460 void WINAPI NdrSimpleTypeMarshall( PMIDL_STUB_MESSAGE pStubMsg, unsigned char* pMemory,
1461 unsigned char FormatChar )
1463 FIXME("stub\n");
1467 /***********************************************************************
1468 * NdrSimpleStructUnmarshall [RPCRT4.@]
1470 void WINAPI NdrSimpleTypeUnmarshall( PMIDL_STUB_MESSAGE pStubMsg, unsigned char* pMemory,
1471 unsigned char FormatChar )
1473 FIXME("stub\n");
1477 /***********************************************************************
1478 * NdrSimpleStructBufferSize [RPCRT4.@]
1480 void WINAPI NdrSimpleStructBufferSize(PMIDL_STUB_MESSAGE pStubMsg,
1481 unsigned char *pMemory,
1482 PFORMAT_STRING pFormat)
1484 unsigned size = *(const WORD*)(pFormat+2);
1485 TRACE("(%p,%p,%p)\n", pStubMsg, pMemory, pFormat);
1487 ALIGN_LENGTH(pStubMsg->BufferLength, pFormat[1] + 1);
1489 pStubMsg->BufferLength += size;
1490 if (pFormat[0] != RPC_FC_STRUCT)
1491 EmbeddedPointerBufferSize(pStubMsg, pMemory, pFormat+4);
1494 /***********************************************************************
1495 * NdrSimpleStructMemorySize [RPCRT4.@]
1497 unsigned long WINAPI NdrSimpleStructMemorySize(PMIDL_STUB_MESSAGE pStubMsg,
1498 PFORMAT_STRING pFormat)
1500 unsigned short size = *(LPWORD)(pFormat+2);
1502 TRACE("(%p,%p)\n", pStubMsg, pFormat);
1504 ALIGN_POINTER(pStubMsg->Buffer, pFormat[1] + 1);
1505 pStubMsg->MemorySize += size;
1506 pStubMsg->Buffer += size;
1508 if (pFormat[0] != RPC_FC_STRUCT)
1509 EmbeddedPointerMemorySize(pStubMsg, pFormat+4);
1510 return size;
1513 /***********************************************************************
1514 * NdrSimpleStructFree [RPCRT4.@]
1516 void WINAPI NdrSimpleStructFree(PMIDL_STUB_MESSAGE pStubMsg,
1517 unsigned char *pMemory,
1518 PFORMAT_STRING pFormat)
1520 TRACE("(%p,%p,%p)\n", pStubMsg, pMemory, pFormat);
1521 if (pFormat[0] != RPC_FC_STRUCT)
1522 EmbeddedPointerFree(pStubMsg, pMemory, pFormat+4);
1526 static unsigned long EmbeddedComplexSize(PMIDL_STUB_MESSAGE pStubMsg,
1527 PFORMAT_STRING pFormat)
1529 switch (*pFormat) {
1530 case RPC_FC_STRUCT:
1531 case RPC_FC_PSTRUCT:
1532 case RPC_FC_CSTRUCT:
1533 case RPC_FC_BOGUS_STRUCT:
1534 return *(const WORD*)&pFormat[2];
1535 case RPC_FC_USER_MARSHAL:
1536 return *(const WORD*)&pFormat[4];
1537 case RPC_FC_NON_ENCAPSULATED_UNION:
1538 pFormat += 2;
1539 if (pStubMsg->fHasNewCorrDesc)
1540 pFormat += 6;
1541 else
1542 pFormat += 4;
1544 pFormat += *(const SHORT*)pFormat;
1545 return *(const SHORT*)pFormat;
1546 default:
1547 FIXME("unhandled embedded type %02x\n", *pFormat);
1549 return 0;
1553 static unsigned long EmbeddedComplexMemorySize(PMIDL_STUB_MESSAGE pStubMsg,
1554 PFORMAT_STRING pFormat)
1556 NDR_MEMORYSIZE m = NdrMemorySizer[*pFormat & NDR_TABLE_MASK];
1558 if (!m)
1560 FIXME("no memorysizer for data type=%02x\n", *pFormat);
1561 return 0;
1564 return m(pStubMsg, pFormat);
1568 static unsigned char * ComplexMarshall(PMIDL_STUB_MESSAGE pStubMsg,
1569 unsigned char *pMemory,
1570 PFORMAT_STRING pFormat,
1571 PFORMAT_STRING pPointer)
1573 PFORMAT_STRING desc;
1574 NDR_MARSHALL m;
1575 unsigned long size;
1577 while (*pFormat != RPC_FC_END) {
1578 switch (*pFormat) {
1579 case RPC_FC_SHORT:
1580 case RPC_FC_USHORT:
1581 TRACE("short=%d <= %p\n", *(WORD*)pMemory, pMemory);
1582 memcpy(pStubMsg->Buffer, pMemory, 2);
1583 pStubMsg->Buffer += 2;
1584 pMemory += 2;
1585 break;
1586 case RPC_FC_LONG:
1587 case RPC_FC_ULONG:
1588 case RPC_FC_ENUM32:
1589 TRACE("long=%ld <= %p\n", *(DWORD*)pMemory, pMemory);
1590 memcpy(pStubMsg->Buffer, pMemory, 4);
1591 pStubMsg->Buffer += 4;
1592 pMemory += 4;
1593 break;
1594 case RPC_FC_POINTER:
1595 TRACE("pointer=%p <= %p\n", *(unsigned char**)pMemory, pMemory);
1596 NdrPointerMarshall(pStubMsg, *(unsigned char**)pMemory, pPointer);
1597 pPointer += 4;
1598 pMemory += 4;
1599 break;
1600 case RPC_FC_ALIGNM4:
1601 ALIGN_POINTER(pMemory, 4);
1602 break;
1603 case RPC_FC_ALIGNM8:
1604 ALIGN_POINTER(pMemory, 8);
1605 break;
1606 case RPC_FC_STRUCTPAD2:
1607 pMemory += 2;
1608 break;
1609 case RPC_FC_EMBEDDED_COMPLEX:
1610 pMemory += pFormat[1];
1611 pFormat += 2;
1612 desc = pFormat + *(const SHORT*)pFormat;
1613 size = EmbeddedComplexSize(pStubMsg, desc);
1614 TRACE("embedded complex (size=%ld) <= %p\n", size, pMemory);
1615 m = NdrMarshaller[*desc & NDR_TABLE_MASK];
1616 if (m) m(pStubMsg, pMemory, desc);
1617 else FIXME("no marshaller for embedded type %02x\n", *desc);
1618 pMemory += size;
1619 pFormat += 2;
1620 continue;
1621 case RPC_FC_PAD:
1622 break;
1623 default:
1624 FIXME("unhandled format %02x\n", *pFormat);
1626 pFormat++;
1629 return pMemory;
1632 static unsigned char * ComplexUnmarshall(PMIDL_STUB_MESSAGE pStubMsg,
1633 unsigned char *pMemory,
1634 PFORMAT_STRING pFormat,
1635 PFORMAT_STRING pPointer,
1636 unsigned char fMustAlloc)
1638 PFORMAT_STRING desc;
1639 NDR_UNMARSHALL m;
1640 unsigned long size;
1642 while (*pFormat != RPC_FC_END) {
1643 switch (*pFormat) {
1644 case RPC_FC_SHORT:
1645 case RPC_FC_USHORT:
1646 memcpy(pMemory, pStubMsg->Buffer, 2);
1647 TRACE("short=%d => %p\n", *(WORD*)pMemory, pMemory);
1648 pStubMsg->Buffer += 2;
1649 pMemory += 2;
1650 break;
1651 case RPC_FC_LONG:
1652 case RPC_FC_ULONG:
1653 case RPC_FC_ENUM32:
1654 memcpy(pMemory, pStubMsg->Buffer, 4);
1655 TRACE("long=%ld => %p\n", *(DWORD*)pMemory, pMemory);
1656 pStubMsg->Buffer += 4;
1657 pMemory += 4;
1658 break;
1659 case RPC_FC_POINTER:
1660 *(unsigned char**)pMemory = NULL;
1661 TRACE("pointer => %p\n", pMemory);
1662 NdrPointerUnmarshall(pStubMsg, (unsigned char**)pMemory, pPointer, fMustAlloc);
1663 pPointer += 4;
1664 pMemory += 4;
1665 break;
1666 case RPC_FC_ALIGNM4:
1667 ALIGN_POINTER(pMemory, 4);
1668 break;
1669 case RPC_FC_ALIGNM8:
1670 ALIGN_POINTER(pMemory, 8);
1671 break;
1672 case RPC_FC_STRUCTPAD2:
1673 pMemory += 2;
1674 break;
1675 case RPC_FC_EMBEDDED_COMPLEX:
1676 pMemory += pFormat[1];
1677 pFormat += 2;
1678 desc = pFormat + *(const SHORT*)pFormat;
1679 size = EmbeddedComplexSize(pStubMsg, desc);
1680 TRACE("embedded complex (size=%ld) => %p\n", size, pMemory);
1681 m = NdrUnmarshaller[*desc & NDR_TABLE_MASK];
1682 memset(pMemory, 0, size); /* just in case */
1683 if (m) m(pStubMsg, &pMemory, desc, fMustAlloc);
1684 else FIXME("no unmarshaller for embedded type %02x\n", *desc);
1685 pMemory += size;
1686 pFormat += 2;
1687 continue;
1688 case RPC_FC_PAD:
1689 break;
1690 default:
1691 FIXME("unhandled format %d\n", *pFormat);
1693 pFormat++;
1696 return pMemory;
1699 static unsigned char * ComplexBufferSize(PMIDL_STUB_MESSAGE pStubMsg,
1700 unsigned char *pMemory,
1701 PFORMAT_STRING pFormat,
1702 PFORMAT_STRING pPointer)
1704 PFORMAT_STRING desc;
1705 NDR_BUFFERSIZE m;
1706 unsigned long size;
1708 while (*pFormat != RPC_FC_END) {
1709 switch (*pFormat) {
1710 case RPC_FC_SHORT:
1711 case RPC_FC_USHORT:
1712 pStubMsg->BufferLength += 2;
1713 pMemory += 2;
1714 break;
1715 case RPC_FC_LONG:
1716 case RPC_FC_ULONG:
1717 case RPC_FC_ENUM32:
1718 pStubMsg->BufferLength += 4;
1719 pMemory += 4;
1720 break;
1721 case RPC_FC_POINTER:
1722 NdrPointerBufferSize(pStubMsg, *(unsigned char**)pMemory, pPointer);
1723 pPointer += 4;
1724 pMemory += 4;
1725 break;
1726 case RPC_FC_ALIGNM4:
1727 ALIGN_POINTER(pMemory, 4);
1728 break;
1729 case RPC_FC_ALIGNM8:
1730 ALIGN_POINTER(pMemory, 8);
1731 break;
1732 case RPC_FC_STRUCTPAD2:
1733 pMemory += 2;
1734 break;
1735 case RPC_FC_EMBEDDED_COMPLEX:
1736 pMemory += pFormat[1];
1737 pFormat += 2;
1738 desc = pFormat + *(const SHORT*)pFormat;
1739 size = EmbeddedComplexSize(pStubMsg, desc);
1740 m = NdrBufferSizer[*desc & NDR_TABLE_MASK];
1741 if (m) m(pStubMsg, pMemory, desc);
1742 else FIXME("no buffersizer for embedded type %02x\n", *desc);
1743 pMemory += size;
1744 pFormat += 2;
1745 continue;
1746 case RPC_FC_PAD:
1747 break;
1748 default:
1749 FIXME("unhandled format %d\n", *pFormat);
1751 pFormat++;
1754 return pMemory;
1757 static unsigned char * ComplexFree(PMIDL_STUB_MESSAGE pStubMsg,
1758 unsigned char *pMemory,
1759 PFORMAT_STRING pFormat,
1760 PFORMAT_STRING pPointer)
1762 PFORMAT_STRING desc;
1763 NDR_FREE m;
1764 unsigned long size;
1766 while (*pFormat != RPC_FC_END) {
1767 switch (*pFormat) {
1768 case RPC_FC_SHORT:
1769 case RPC_FC_USHORT:
1770 pMemory += 2;
1771 break;
1772 case RPC_FC_LONG:
1773 case RPC_FC_ULONG:
1774 case RPC_FC_ENUM32:
1775 pMemory += 4;
1776 break;
1777 case RPC_FC_POINTER:
1778 NdrPointerFree(pStubMsg, *(unsigned char**)pMemory, pPointer);
1779 pPointer += 4;
1780 pMemory += 4;
1781 break;
1782 case RPC_FC_ALIGNM4:
1783 ALIGN_POINTER(pMemory, 4);
1784 break;
1785 case RPC_FC_ALIGNM8:
1786 ALIGN_POINTER(pMemory, 8);
1787 break;
1788 case RPC_FC_STRUCTPAD2:
1789 pMemory += 2;
1790 break;
1791 case RPC_FC_EMBEDDED_COMPLEX:
1792 pMemory += pFormat[1];
1793 pFormat += 2;
1794 desc = pFormat + *(const SHORT*)pFormat;
1795 size = EmbeddedComplexSize(pStubMsg, desc);
1796 m = NdrFreer[*desc & NDR_TABLE_MASK];
1797 if (m) m(pStubMsg, pMemory, desc);
1798 else FIXME("no freer for embedded type %02x\n", *desc);
1799 pMemory += size;
1800 pFormat += 2;
1801 continue;
1802 case RPC_FC_PAD:
1803 break;
1804 default:
1805 FIXME("unhandled format %d\n", *pFormat);
1807 pFormat++;
1810 return pMemory;
1813 static unsigned long ComplexStructMemorySize(PMIDL_STUB_MESSAGE pStubMsg,
1814 PFORMAT_STRING pFormat)
1816 PFORMAT_STRING desc;
1817 unsigned long size = 0;
1819 while (*pFormat != RPC_FC_END) {
1820 switch (*pFormat) {
1821 case RPC_FC_SHORT:
1822 case RPC_FC_USHORT:
1823 size += 2;
1824 pStubMsg->Buffer += 2;
1825 break;
1826 case RPC_FC_LONG:
1827 case RPC_FC_ULONG:
1828 size += 4;
1829 pStubMsg->Buffer += 4;
1830 break;
1831 case RPC_FC_POINTER:
1832 size += 4;
1833 pStubMsg->Buffer += 4;
1834 break;
1835 case RPC_FC_ALIGNM4:
1836 ALIGN_LENGTH(size, 4);
1837 ALIGN_POINTER(pStubMsg->Buffer, 4);
1838 break;
1839 case RPC_FC_ALIGNM8:
1840 ALIGN_LENGTH(size, 8);
1841 ALIGN_POINTER(pStubMsg->Buffer, 8);
1842 break;
1843 case RPC_FC_STRUCTPAD2:
1844 size += 2;
1845 pStubMsg->Buffer += 2;
1846 break;
1847 case RPC_FC_EMBEDDED_COMPLEX:
1848 size += pFormat[1];
1849 pFormat += 2;
1850 desc = pFormat + *(const SHORT*)pFormat;
1851 size += EmbeddedComplexMemorySize(pStubMsg, desc);
1852 pFormat += 2;
1853 continue;
1854 case RPC_FC_PAD:
1855 break;
1856 default:
1857 FIXME("unhandled format %d\n", *pFormat);
1859 pFormat++;
1862 return size;
1865 /***********************************************************************
1866 * NdrComplexStructMarshall [RPCRT4.@]
1868 unsigned char * WINAPI NdrComplexStructMarshall(PMIDL_STUB_MESSAGE pStubMsg,
1869 unsigned char *pMemory,
1870 PFORMAT_STRING pFormat)
1872 PFORMAT_STRING conf_array = NULL;
1873 PFORMAT_STRING pointer_desc = NULL;
1874 unsigned char *OldMemory = pStubMsg->Memory;
1876 TRACE("(%p,%p,%p)\n", pStubMsg, pMemory, pFormat);
1878 ALIGN_POINTER(pStubMsg->Buffer, pFormat[1] + 1);
1880 pFormat += 4;
1881 if (*(const WORD*)pFormat) conf_array = pFormat + *(const WORD*)pFormat;
1882 pFormat += 2;
1883 if (*(const WORD*)pFormat) pointer_desc = pFormat + *(const WORD*)pFormat;
1884 pFormat += 2;
1886 pStubMsg->Memory = pMemory;
1888 ComplexMarshall(pStubMsg, pMemory, pFormat, pointer_desc);
1890 if (conf_array)
1891 NdrConformantArrayMarshall(pStubMsg, pMemory, conf_array);
1893 pStubMsg->Memory = OldMemory;
1895 STD_OVERFLOW_CHECK(pStubMsg);
1897 return NULL;
1900 /***********************************************************************
1901 * NdrComplexStructUnmarshall [RPCRT4.@]
1903 unsigned char * WINAPI NdrComplexStructUnmarshall(PMIDL_STUB_MESSAGE pStubMsg,
1904 unsigned char **ppMemory,
1905 PFORMAT_STRING pFormat,
1906 unsigned char fMustAlloc)
1908 unsigned size = *(const WORD*)(pFormat+2);
1909 PFORMAT_STRING conf_array = NULL;
1910 PFORMAT_STRING pointer_desc = NULL;
1911 unsigned char *pMemory;
1913 TRACE("(%p,%p,%p,%d)\n", pStubMsg, ppMemory, pFormat, fMustAlloc);
1915 ALIGN_POINTER(pStubMsg->Buffer, pFormat[1] + 1);
1917 if (fMustAlloc || !*ppMemory)
1919 *ppMemory = NdrAllocate(pStubMsg, size);
1920 memset(*ppMemory, 0, size);
1923 pFormat += 4;
1924 if (*(const WORD*)pFormat) conf_array = pFormat + *(const WORD*)pFormat;
1925 pFormat += 2;
1926 if (*(const WORD*)pFormat) pointer_desc = pFormat + *(const WORD*)pFormat;
1927 pFormat += 2;
1929 pMemory = ComplexUnmarshall(pStubMsg, *ppMemory, pFormat, pointer_desc, fMustAlloc);
1931 if (conf_array)
1932 NdrConformantArrayUnmarshall(pStubMsg, &pMemory, conf_array, fMustAlloc);
1934 return NULL;
1937 /***********************************************************************
1938 * NdrComplexStructBufferSize [RPCRT4.@]
1940 void WINAPI NdrComplexStructBufferSize(PMIDL_STUB_MESSAGE pStubMsg,
1941 unsigned char *pMemory,
1942 PFORMAT_STRING pFormat)
1944 PFORMAT_STRING conf_array = NULL;
1945 PFORMAT_STRING pointer_desc = NULL;
1946 unsigned char *OldMemory = pStubMsg->Memory;
1948 TRACE("(%p,%p,%p)\n", pStubMsg, pMemory, pFormat);
1950 ALIGN_LENGTH(pStubMsg->BufferLength, pFormat[1] + 1);
1952 pFormat += 4;
1953 if (*(const WORD*)pFormat) conf_array = pFormat + *(const WORD*)pFormat;
1954 pFormat += 2;
1955 if (*(const WORD*)pFormat) pointer_desc = pFormat + *(const WORD*)pFormat;
1956 pFormat += 2;
1958 pStubMsg->Memory = pMemory;
1960 pMemory = ComplexBufferSize(pStubMsg, pMemory, pFormat, pointer_desc);
1962 if (conf_array)
1963 NdrConformantArrayBufferSize(pStubMsg, pMemory, conf_array);
1965 pStubMsg->Memory = OldMemory;
1968 /***********************************************************************
1969 * NdrComplexStructMemorySize [RPCRT4.@]
1971 unsigned long WINAPI NdrComplexStructMemorySize(PMIDL_STUB_MESSAGE pStubMsg,
1972 PFORMAT_STRING pFormat)
1974 unsigned size = *(const WORD*)(pFormat+2);
1975 PFORMAT_STRING conf_array = NULL;
1976 PFORMAT_STRING pointer_desc = NULL;
1978 TRACE("(%p,%p)\n", pStubMsg, pFormat);
1980 ALIGN_POINTER(pStubMsg->Buffer, pFormat[1] + 1);
1982 pFormat += 4;
1983 if (*(const WORD*)pFormat) conf_array = pFormat + *(const WORD*)pFormat;
1984 pFormat += 2;
1985 if (*(const WORD*)pFormat) pointer_desc = pFormat + *(const WORD*)pFormat;
1986 pFormat += 2;
1988 ComplexStructMemorySize(pStubMsg, pFormat);
1990 if (conf_array)
1991 NdrConformantArrayMemorySize(pStubMsg, conf_array);
1993 return size;
1996 /***********************************************************************
1997 * NdrComplexStructFree [RPCRT4.@]
1999 void WINAPI NdrComplexStructFree(PMIDL_STUB_MESSAGE pStubMsg,
2000 unsigned char *pMemory,
2001 PFORMAT_STRING pFormat)
2003 PFORMAT_STRING conf_array = NULL;
2004 PFORMAT_STRING pointer_desc = NULL;
2005 unsigned char *OldMemory = pStubMsg->Memory;
2007 TRACE("(%p,%p,%p)\n", pStubMsg, pMemory, pFormat);
2009 pFormat += 4;
2010 if (*(const WORD*)pFormat) conf_array = pFormat + *(const WORD*)pFormat;
2011 pFormat += 2;
2012 if (*(const WORD*)pFormat) pointer_desc = pFormat + *(const WORD*)pFormat;
2013 pFormat += 2;
2015 pStubMsg->Memory = pMemory;
2017 pMemory = ComplexFree(pStubMsg, pMemory, pFormat, pointer_desc);
2019 if (conf_array)
2020 NdrConformantArrayFree(pStubMsg, pMemory, conf_array);
2022 pStubMsg->Memory = OldMemory;
2025 /***********************************************************************
2026 * NdrConformantArrayMarshall [RPCRT4.@]
2028 unsigned char * WINAPI NdrConformantArrayMarshall(PMIDL_STUB_MESSAGE pStubMsg,
2029 unsigned char *pMemory,
2030 PFORMAT_STRING pFormat)
2032 DWORD size = 0, esize = *(const WORD*)(pFormat+2);
2033 unsigned char alignment = pFormat[1] + 1;
2035 TRACE("(%p,%p,%p)\n", pStubMsg, pMemory, pFormat);
2036 if (pFormat[0] != RPC_FC_CARRAY) FIXME("format=%d\n", pFormat[0]);
2038 pFormat = ComputeConformance(pStubMsg, pMemory, pFormat+4, 0);
2039 size = pStubMsg->MaxCount;
2041 WriteConformance(pStubMsg);
2043 ALIGN_POINTER(pStubMsg->Buffer, alignment);
2045 memcpy(pStubMsg->Buffer, pMemory, size*esize);
2046 pStubMsg->BufferMark = pStubMsg->Buffer;
2047 pStubMsg->Buffer += size*esize;
2049 EmbeddedPointerMarshall(pStubMsg, pMemory, pFormat);
2051 STD_OVERFLOW_CHECK(pStubMsg);
2053 return NULL;
2056 /***********************************************************************
2057 * NdrConformantArrayUnmarshall [RPCRT4.@]
2059 unsigned char * WINAPI NdrConformantArrayUnmarshall(PMIDL_STUB_MESSAGE pStubMsg,
2060 unsigned char **ppMemory,
2061 PFORMAT_STRING pFormat,
2062 unsigned char fMustAlloc)
2064 DWORD size = 0, esize = *(const WORD*)(pFormat+2);
2065 unsigned char alignment = pFormat[1] + 1;
2067 TRACE("(%p,%p,%p,%d)\n", pStubMsg, ppMemory, pFormat, fMustAlloc);
2068 if (pFormat[0] != RPC_FC_CARRAY) FIXME("format=%d\n", pFormat[0]);
2070 pFormat = ReadConformance(pStubMsg, pFormat+4);
2071 size = pStubMsg->MaxCount;
2073 if (fMustAlloc || !*ppMemory)
2074 *ppMemory = NdrAllocate(pStubMsg, size*esize);
2076 ALIGN_POINTER(pStubMsg->Buffer, alignment);
2078 memcpy(*ppMemory, pStubMsg->Buffer, size*esize);
2080 pStubMsg->BufferMark = pStubMsg->Buffer;
2081 pStubMsg->Buffer += size*esize;
2083 EmbeddedPointerUnmarshall(pStubMsg, ppMemory, pFormat, fMustAlloc);
2085 return NULL;
2088 /***********************************************************************
2089 * NdrConformantArrayBufferSize [RPCRT4.@]
2091 void WINAPI NdrConformantArrayBufferSize(PMIDL_STUB_MESSAGE pStubMsg,
2092 unsigned char *pMemory,
2093 PFORMAT_STRING pFormat)
2095 DWORD size = 0, esize = *(const WORD*)(pFormat+2);
2096 unsigned char alignment = pFormat[1] + 1;
2098 TRACE("(%p,%p,%p)\n", pStubMsg, pMemory, pFormat);
2099 if (pFormat[0] != RPC_FC_CARRAY) FIXME("format=%d\n", pFormat[0]);
2101 pFormat = ComputeConformance(pStubMsg, pMemory, pFormat+4, 0);
2102 size = pStubMsg->MaxCount;
2104 SizeConformance(pStubMsg);
2106 ALIGN_LENGTH(pStubMsg->BufferLength, alignment);
2108 /* conformance value plus array */
2109 pStubMsg->BufferLength += size*esize;
2111 EmbeddedPointerBufferSize(pStubMsg, pMemory, pFormat);
2114 /***********************************************************************
2115 * NdrConformantArrayMemorySize [RPCRT4.@]
2117 unsigned long WINAPI NdrConformantArrayMemorySize(PMIDL_STUB_MESSAGE pStubMsg,
2118 PFORMAT_STRING pFormat)
2120 DWORD size = 0, esize = *(const WORD*)(pFormat+2);
2121 unsigned char *buffer;
2123 TRACE("(%p,%p)\n", pStubMsg, pFormat);
2124 if (pFormat[0] != RPC_FC_CARRAY) FIXME("format=%d\n", pFormat[0]);
2126 buffer = pStubMsg->Buffer;
2127 pFormat = ReadConformance(pStubMsg, pFormat+4);
2128 pStubMsg->Buffer = buffer;
2129 size = pStubMsg->MaxCount;
2131 return size*esize;
2134 /***********************************************************************
2135 * NdrConformantArrayFree [RPCRT4.@]
2137 void WINAPI NdrConformantArrayFree(PMIDL_STUB_MESSAGE pStubMsg,
2138 unsigned char *pMemory,
2139 PFORMAT_STRING pFormat)
2141 TRACE("(%p,%p,%p)\n", pStubMsg, pMemory, pFormat);
2142 if (pFormat[0] != RPC_FC_CARRAY) FIXME("format=%d\n", pFormat[0]);
2144 EmbeddedPointerFree(pStubMsg, pMemory, pFormat);
2148 /***********************************************************************
2149 * NdrConformantVaryingArrayMarshall [RPCRT4.@]
2151 unsigned char* WINAPI NdrConformantVaryingArrayMarshall( PMIDL_STUB_MESSAGE pStubMsg,
2152 unsigned char* pMemory,
2153 PFORMAT_STRING pFormat )
2155 unsigned char alignment = pFormat[1] + 1;
2156 DWORD esize = *(const WORD*)(pFormat+2);
2158 TRACE("(%p, %p, %p)\n", pStubMsg, pMemory, pFormat);
2160 if (pFormat[0] != RPC_FC_CVARRAY)
2162 ERR("invalid format type %x\n", pFormat[0]);
2163 RpcRaiseException(RPC_S_INTERNAL_ERROR);
2164 return NULL;
2167 pFormat = ComputeConformance(pStubMsg, pMemory, pFormat+4, 0);
2168 pFormat = ComputeVariance(pStubMsg, pMemory, pFormat, 0);
2170 WriteConformance(pStubMsg);
2171 WriteVariance(pStubMsg);
2173 ALIGN_POINTER(pStubMsg->Buffer, alignment);
2175 memcpy(pStubMsg->Buffer, pMemory + pStubMsg->Offset, pStubMsg->ActualCount*esize);
2176 pStubMsg->BufferMark = pStubMsg->Buffer;
2177 pStubMsg->Buffer += pStubMsg->ActualCount*esize;
2179 EmbeddedPointerMarshall(pStubMsg, pMemory, pFormat);
2181 STD_OVERFLOW_CHECK(pStubMsg);
2183 return NULL;
2187 /***********************************************************************
2188 * NdrConformantVaryingArrayUnmarshall [RPCRT4.@]
2190 unsigned char* WINAPI NdrConformantVaryingArrayUnmarshall( PMIDL_STUB_MESSAGE pStubMsg,
2191 unsigned char** ppMemory,
2192 PFORMAT_STRING pFormat,
2193 unsigned char fMustAlloc )
2195 unsigned char alignment = pFormat[1] + 1;
2196 DWORD esize = *(const WORD*)(pFormat+2);
2198 TRACE("(%p, %p, %p, %d)\n", pStubMsg, ppMemory, pFormat, fMustAlloc);
2200 if (pFormat[0] != RPC_FC_CVARRAY)
2202 ERR("invalid format type %x\n", pFormat[0]);
2203 RpcRaiseException(RPC_S_INTERNAL_ERROR);
2204 return NULL;
2207 pFormat = ReadConformance(pStubMsg, pFormat);
2208 pFormat = ReadVariance(pStubMsg, pFormat);
2210 ALIGN_POINTER(pStubMsg->Buffer, alignment);
2212 if (!*ppMemory || fMustAlloc)
2213 *ppMemory = NdrAllocate(pStubMsg, pStubMsg->MaxCount * esize);
2214 memcpy(*ppMemory + pStubMsg->Offset, pStubMsg->Buffer, pStubMsg->ActualCount * esize);
2215 pStubMsg->Buffer += pStubMsg->ActualCount * esize;
2217 EmbeddedPointerUnmarshall(pStubMsg, ppMemory, pFormat, fMustAlloc);
2219 return NULL;
2223 /***********************************************************************
2224 * NdrConformantVaryingArrayFree [RPCRT4.@]
2226 void WINAPI NdrConformantVaryingArrayFree( PMIDL_STUB_MESSAGE pStubMsg,
2227 unsigned char* pMemory,
2228 PFORMAT_STRING pFormat )
2230 TRACE("(%p,%p,%p)\n", pStubMsg, pMemory, pFormat);
2232 if (pFormat[0] != RPC_FC_CVARRAY)
2234 ERR("invalid format type %x\n", pFormat[0]);
2235 RpcRaiseException(RPC_S_INTERNAL_ERROR);
2236 return;
2239 pFormat = ComputeConformance(pStubMsg, pMemory, pFormat+4, 0);
2240 pFormat = ComputeVariance(pStubMsg, pMemory, pFormat, 0);
2242 EmbeddedPointerFree(pStubMsg, pMemory, pFormat);
2246 /***********************************************************************
2247 * NdrConformantVaryingArrayBufferSize [RPCRT4.@]
2249 void WINAPI NdrConformantVaryingArrayBufferSize( PMIDL_STUB_MESSAGE pStubMsg,
2250 unsigned char* pMemory, PFORMAT_STRING pFormat )
2252 unsigned char alignment = pFormat[1] + 1;
2253 DWORD esize = *(const WORD*)(pFormat+2);
2255 TRACE("(%p, %p, %p)\n", pStubMsg, pMemory, pFormat);
2257 if (pFormat[0] != RPC_FC_CVARRAY)
2259 ERR("invalid format type %x\n", pFormat[0]);
2260 RpcRaiseException(RPC_S_INTERNAL_ERROR);
2261 return;
2264 /* compute size */
2265 pFormat = ComputeConformance(pStubMsg, pMemory, pFormat+4, 0);
2266 /* compute length */
2267 pFormat = ComputeVariance(pStubMsg, pMemory, pFormat, 0);
2269 SizeConformance(pStubMsg);
2270 SizeVariance(pStubMsg);
2272 ALIGN_LENGTH(pStubMsg->BufferLength, alignment);
2274 pStubMsg->BufferLength += pStubMsg->ActualCount*esize;
2276 EmbeddedPointerBufferSize(pStubMsg, pMemory, pFormat);
2280 /***********************************************************************
2281 * NdrConformantVaryingArrayMemorySize [RPCRT4.@]
2283 unsigned long WINAPI NdrConformantVaryingArrayMemorySize( PMIDL_STUB_MESSAGE pStubMsg,
2284 PFORMAT_STRING pFormat )
2286 FIXME( "stub\n" );
2287 return 0;
2291 /***********************************************************************
2292 * NdrComplexArrayMarshall [RPCRT4.@]
2294 unsigned char * WINAPI NdrComplexArrayMarshall(PMIDL_STUB_MESSAGE pStubMsg,
2295 unsigned char *pMemory,
2296 PFORMAT_STRING pFormat)
2298 ULONG i, count, def;
2299 BOOL variance_present;
2300 unsigned char alignment;
2302 TRACE("(%p,%p,%p)\n", pStubMsg, pMemory, pFormat);
2304 if (pFormat[0] != RPC_FC_BOGUS_ARRAY)
2306 ERR("invalid format type %x\n", pFormat[0]);
2307 RpcRaiseException(RPC_S_INTERNAL_ERROR);
2308 return NULL;
2311 alignment = pFormat[1] + 1;
2313 def = *(const WORD*)&pFormat[2];
2314 pFormat += 4;
2316 pFormat = ComputeConformance(pStubMsg, pMemory, pFormat, def);
2317 TRACE("conformance = %ld\n", pStubMsg->MaxCount);
2319 variance_present = IsConformanceOrVariancePresent(pFormat);
2320 pFormat = ComputeVariance(pStubMsg, pMemory, pFormat, pStubMsg->MaxCount);
2321 TRACE("variance = %ld\n", pStubMsg->ActualCount);
2323 WriteConformance(pStubMsg);
2324 if (variance_present)
2325 WriteVariance(pStubMsg);
2327 ALIGN_POINTER(pStubMsg->Buffer, alignment);
2329 count = pStubMsg->ActualCount;
2330 for (i = 0; i < count; i++)
2331 pMemory = ComplexMarshall(pStubMsg, pMemory, pFormat, NULL);
2333 STD_OVERFLOW_CHECK(pStubMsg);
2335 return NULL;
2338 /***********************************************************************
2339 * NdrComplexArrayUnmarshall [RPCRT4.@]
2341 unsigned char * WINAPI NdrComplexArrayUnmarshall(PMIDL_STUB_MESSAGE pStubMsg,
2342 unsigned char **ppMemory,
2343 PFORMAT_STRING pFormat,
2344 unsigned char fMustAlloc)
2346 ULONG i, count, esize;
2347 unsigned char alignment;
2348 unsigned char *pMemory;
2349 unsigned char *Buffer;
2351 TRACE("(%p,%p,%p,%d)\n", pStubMsg, ppMemory, pFormat, fMustAlloc);
2353 if (pFormat[0] != RPC_FC_BOGUS_ARRAY)
2355 ERR("invalid format type %x\n", pFormat[0]);
2356 RpcRaiseException(RPC_S_INTERNAL_ERROR);
2357 return NULL;
2360 alignment = pFormat[1] + 1;
2362 pFormat += 4;
2364 pFormat = ReadConformance(pStubMsg, pFormat);
2365 pFormat = ReadVariance(pStubMsg, pFormat);
2367 Buffer = pStubMsg->Buffer;
2368 esize = ComplexStructMemorySize(pStubMsg, pFormat);
2369 pStubMsg->Buffer = Buffer;
2371 if (fMustAlloc || !*ppMemory)
2373 *ppMemory = NdrAllocate(pStubMsg, pStubMsg->MaxCount * esize);
2374 memset(*ppMemory, 0, pStubMsg->MaxCount * esize);
2377 ALIGN_POINTER(pStubMsg->Buffer, alignment);
2379 pMemory = *ppMemory;
2380 count = pStubMsg->ActualCount;
2381 for (i = 0; i < count; i++)
2382 pMemory = ComplexUnmarshall(pStubMsg, pMemory, pFormat, NULL, fMustAlloc);
2384 return NULL;
2387 /***********************************************************************
2388 * NdrComplexArrayBufferSize [RPCRT4.@]
2390 void WINAPI NdrComplexArrayBufferSize(PMIDL_STUB_MESSAGE pStubMsg,
2391 unsigned char *pMemory,
2392 PFORMAT_STRING pFormat)
2394 ULONG i, count, def;
2395 unsigned char alignment;
2396 BOOL variance_present;
2398 TRACE("(%p,%p,%p)\n", pStubMsg, pMemory, pFormat);
2400 if (pFormat[0] != RPC_FC_BOGUS_ARRAY)
2402 ERR("invalid format type %x\n", pFormat[0]);
2403 RpcRaiseException(RPC_S_INTERNAL_ERROR);
2404 return;
2407 alignment = pFormat[1] + 1;
2409 def = *(const WORD*)&pFormat[2];
2410 pFormat += 4;
2412 pFormat = ComputeConformance(pStubMsg, pMemory, pFormat, def);
2413 TRACE("conformance = %ld\n", pStubMsg->MaxCount);
2414 SizeConformance(pStubMsg);
2416 variance_present = IsConformanceOrVariancePresent(pFormat);
2417 pFormat = ComputeVariance(pStubMsg, pMemory, pFormat, pStubMsg->MaxCount);
2418 TRACE("variance = %ld\n", pStubMsg->ActualCount);
2420 if (variance_present)
2421 SizeVariance(pStubMsg);
2423 ALIGN_LENGTH(pStubMsg->BufferLength, alignment);
2425 count = pStubMsg->ActualCount;
2426 for (i = 0; i < count; i++)
2427 pMemory = ComplexBufferSize(pStubMsg, pMemory, pFormat, NULL);
2430 /***********************************************************************
2431 * NdrComplexArrayMemorySize [RPCRT4.@]
2433 unsigned long WINAPI NdrComplexArrayMemorySize(PMIDL_STUB_MESSAGE pStubMsg,
2434 PFORMAT_STRING pFormat)
2436 ULONG i, count, esize;
2437 unsigned char alignment;
2438 unsigned char *Buffer;
2439 unsigned long SavedMemorySize;
2440 unsigned long MemorySize;
2442 TRACE("(%p,%p)\n", pStubMsg, pFormat);
2444 if (pFormat[0] != RPC_FC_BOGUS_ARRAY)
2446 ERR("invalid format type %x\n", pFormat[0]);
2447 RpcRaiseException(RPC_S_INTERNAL_ERROR);
2448 return 0;
2451 alignment = pFormat[1] + 1;
2453 pFormat += 4;
2455 pFormat = ReadConformance(pStubMsg, pFormat);
2456 pFormat = ReadVariance(pStubMsg, pFormat);
2458 ALIGN_POINTER(pStubMsg->Buffer, alignment);
2460 SavedMemorySize = pStubMsg->MemorySize;
2462 Buffer = pStubMsg->Buffer;
2463 esize = ComplexStructMemorySize(pStubMsg, pFormat);
2464 pStubMsg->Buffer = Buffer;
2466 MemorySize = esize * pStubMsg->MaxCount;
2468 count = pStubMsg->ActualCount;
2469 for (i = 0; i < count; i++)
2470 ComplexStructMemorySize(pStubMsg, pFormat);
2472 pStubMsg->MemorySize = SavedMemorySize;
2474 pStubMsg->MemorySize += MemorySize;
2475 return MemorySize;
2478 /***********************************************************************
2479 * NdrComplexArrayFree [RPCRT4.@]
2481 void WINAPI NdrComplexArrayFree(PMIDL_STUB_MESSAGE pStubMsg,
2482 unsigned char *pMemory,
2483 PFORMAT_STRING pFormat)
2485 ULONG i, count, def;
2487 TRACE("(%p,%p,%p)\n", pStubMsg, pMemory, pFormat);
2489 if (pFormat[0] != RPC_FC_BOGUS_ARRAY)
2491 ERR("invalid format type %x\n", pFormat[0]);
2492 RpcRaiseException(RPC_S_INTERNAL_ERROR);
2493 return;
2496 def = *(const WORD*)&pFormat[2];
2497 pFormat += 4;
2499 pFormat = ComputeConformance(pStubMsg, pMemory, pFormat, def);
2500 TRACE("conformance = %ld\n", pStubMsg->MaxCount);
2502 pFormat = ComputeVariance(pStubMsg, pMemory, pFormat, pStubMsg->MaxCount);
2503 TRACE("variance = %ld\n", pStubMsg->ActualCount);
2505 count = pStubMsg->ActualCount;
2506 for (i = 0; i < count; i++)
2507 pMemory = ComplexFree(pStubMsg, pMemory, pFormat, NULL);
2510 unsigned long UserMarshalFlags(PMIDL_STUB_MESSAGE pStubMsg)
2512 return MAKELONG(pStubMsg->dwDestContext,
2513 pStubMsg->RpcMsg->DataRepresentation);
2516 /***********************************************************************
2517 * NdrUserMarshalMarshall [RPCRT4.@]
2519 unsigned char * WINAPI NdrUserMarshalMarshall(PMIDL_STUB_MESSAGE pStubMsg,
2520 unsigned char *pMemory,
2521 PFORMAT_STRING pFormat)
2523 /* unsigned flags = pFormat[1]; */
2524 unsigned index = *(const WORD*)&pFormat[2];
2525 unsigned long uflag = UserMarshalFlags(pStubMsg);
2526 TRACE("(%p,%p,%p)\n", pStubMsg, pMemory, pFormat);
2527 TRACE("index=%d\n", index);
2529 pStubMsg->Buffer =
2530 pStubMsg->StubDesc->aUserMarshalQuadruple[index].pfnMarshall(
2531 &uflag, pStubMsg->Buffer, pMemory);
2533 STD_OVERFLOW_CHECK(pStubMsg);
2535 return NULL;
2538 /***********************************************************************
2539 * NdrUserMarshalUnmarshall [RPCRT4.@]
2541 unsigned char * WINAPI NdrUserMarshalUnmarshall(PMIDL_STUB_MESSAGE pStubMsg,
2542 unsigned char **ppMemory,
2543 PFORMAT_STRING pFormat,
2544 unsigned char fMustAlloc)
2546 /* unsigned flags = pFormat[1];*/
2547 unsigned index = *(const WORD*)&pFormat[2];
2548 DWORD memsize = *(const WORD*)&pFormat[4];
2549 unsigned long uflag = UserMarshalFlags(pStubMsg);
2550 TRACE("(%p,%p,%p,%d)\n", pStubMsg, ppMemory, pFormat, fMustAlloc);
2551 TRACE("index=%d\n", index);
2553 if (fMustAlloc || !*ppMemory)
2554 *ppMemory = NdrAllocate(pStubMsg, memsize);
2556 pStubMsg->Buffer =
2557 pStubMsg->StubDesc->aUserMarshalQuadruple[index].pfnUnmarshall(
2558 &uflag, pStubMsg->Buffer, *ppMemory);
2560 return NULL;
2563 /***********************************************************************
2564 * NdrUserMarshalBufferSize [RPCRT4.@]
2566 void WINAPI NdrUserMarshalBufferSize(PMIDL_STUB_MESSAGE pStubMsg,
2567 unsigned char *pMemory,
2568 PFORMAT_STRING pFormat)
2570 /* unsigned flags = pFormat[1];*/
2571 unsigned index = *(const WORD*)&pFormat[2];
2572 DWORD bufsize = *(const WORD*)&pFormat[6];
2573 unsigned long uflag = UserMarshalFlags(pStubMsg);
2574 TRACE("(%p,%p,%p)\n", pStubMsg, pMemory, pFormat);
2575 TRACE("index=%d\n", index);
2577 if (bufsize) {
2578 TRACE("size=%ld\n", bufsize);
2579 pStubMsg->BufferLength += bufsize;
2580 return;
2583 pStubMsg->BufferLength =
2584 pStubMsg->StubDesc->aUserMarshalQuadruple[index].pfnBufferSize(
2585 &uflag, pStubMsg->BufferLength, pMemory);
2588 /***********************************************************************
2589 * NdrUserMarshalMemorySize [RPCRT4.@]
2591 unsigned long WINAPI NdrUserMarshalMemorySize(PMIDL_STUB_MESSAGE pStubMsg,
2592 PFORMAT_STRING pFormat)
2594 unsigned index = *(const WORD*)&pFormat[2];
2595 DWORD memsize = *(const WORD*)&pFormat[4];
2596 DWORD bufsize = *(const WORD*)&pFormat[6];
2598 TRACE("(%p,%p)\n", pStubMsg, pFormat);
2599 TRACE("index=%d\n", index);
2601 pStubMsg->MemorySize += memsize;
2602 pStubMsg->Buffer += bufsize;
2604 return pStubMsg->MemorySize;
2607 /***********************************************************************
2608 * NdrUserMarshalFree [RPCRT4.@]
2610 void WINAPI NdrUserMarshalFree(PMIDL_STUB_MESSAGE pStubMsg,
2611 unsigned char *pMemory,
2612 PFORMAT_STRING pFormat)
2614 /* unsigned flags = pFormat[1]; */
2615 unsigned index = *(const WORD*)&pFormat[2];
2616 unsigned long uflag = UserMarshalFlags(pStubMsg);
2617 TRACE("(%p,%p,%p)\n", pStubMsg, pMemory, pFormat);
2618 TRACE("index=%d\n", index);
2620 pStubMsg->StubDesc->aUserMarshalQuadruple[index].pfnFree(
2621 &uflag, pMemory);
2624 /***********************************************************************
2625 * NdrClearOutParameters [RPCRT4.@]
2627 void WINAPI NdrClearOutParameters(PMIDL_STUB_MESSAGE pStubMsg,
2628 PFORMAT_STRING pFormat,
2629 void *ArgAddr)
2631 FIXME("(%p,%p,%p): stub\n", pStubMsg, pFormat, ArgAddr);
2634 /***********************************************************************
2635 * NdrConvert [RPCRT4.@]
2637 void WINAPI NdrConvert( PMIDL_STUB_MESSAGE pStubMsg, PFORMAT_STRING pFormat )
2639 FIXME("(pStubMsg == ^%p, pFormat == ^%p): stub.\n", pStubMsg, pFormat);
2640 /* FIXME: since this stub doesn't do any converting, the proper behavior
2641 is to raise an exception */
2644 /***********************************************************************
2645 * NdrConvert2 [RPCRT4.@]
2647 void WINAPI NdrConvert2( PMIDL_STUB_MESSAGE pStubMsg, PFORMAT_STRING pFormat, long NumberParams )
2649 FIXME("(pStubMsg == ^%p, pFormat == ^%p, NumberParams == %ld): stub.\n",
2650 pStubMsg, pFormat, NumberParams);
2651 /* FIXME: since this stub doesn't do any converting, the proper behavior
2652 is to raise an exception */
2655 typedef struct _NDR_CSTRUCT_FORMAT
2657 unsigned char type;
2658 unsigned char alignment;
2659 unsigned short memory_size;
2660 short offset_to_array_description;
2661 } NDR_CSTRUCT_FORMAT, NDR_CVSTRUCT_FORMAT;
2663 /***********************************************************************
2664 * NdrConformantStructMarshall [RPCRT4.@]
2666 unsigned char * WINAPI NdrConformantStructMarshall(PMIDL_STUB_MESSAGE pStubMsg,
2667 unsigned char *pMemory,
2668 PFORMAT_STRING pFormat)
2670 const NDR_CSTRUCT_FORMAT * pCStructFormat = (NDR_CSTRUCT_FORMAT*)pFormat;
2671 PFORMAT_STRING pCArrayFormat;
2672 ULONG esize;
2674 TRACE("(%p, %p, %p)\n", pStubMsg, pMemory, pFormat);
2676 pFormat += sizeof(NDR_CSTRUCT_FORMAT);
2677 if ((pCStructFormat->type != RPC_FC_CPSTRUCT) && (pCStructFormat->type != RPC_FC_CSTRUCT))
2679 ERR("invalid format type %x\n", pCStructFormat->type);
2680 RpcRaiseException(RPC_S_INTERNAL_ERROR);
2681 return NULL;
2684 pCArrayFormat = (unsigned char*)&pCStructFormat->offset_to_array_description +
2685 pCStructFormat->offset_to_array_description;
2686 if (*pCArrayFormat != RPC_FC_CARRAY)
2688 ERR("invalid array format type %x\n", pCStructFormat->type);
2689 RpcRaiseException(RPC_S_INTERNAL_ERROR);
2690 return NULL;
2692 esize = *(const WORD*)(pCArrayFormat+2);
2694 ComputeConformance(pStubMsg, pMemory + pCStructFormat->memory_size,
2695 pCArrayFormat + 4, 0);
2697 WriteConformance(pStubMsg);
2699 ALIGN_POINTER(pStubMsg->Buffer, pCStructFormat->alignment + 1);
2701 TRACE("memory_size = %d\n", pCStructFormat->memory_size);
2703 /* copy constant sized part of struct */
2704 pStubMsg->BufferMark = pStubMsg->Buffer;
2705 memcpy(pStubMsg->Buffer, pMemory, pCStructFormat->memory_size + pStubMsg->MaxCount * esize);
2706 pStubMsg->Buffer += pCStructFormat->memory_size + pStubMsg->MaxCount * esize;
2708 if (pCStructFormat->type == RPC_FC_CPSTRUCT)
2709 EmbeddedPointerMarshall(pStubMsg, pMemory, pFormat);
2711 STD_OVERFLOW_CHECK(pStubMsg);
2713 return NULL;
2716 /***********************************************************************
2717 * NdrConformantStructUnmarshall [RPCRT4.@]
2719 unsigned char * WINAPI NdrConformantStructUnmarshall(PMIDL_STUB_MESSAGE pStubMsg,
2720 unsigned char **ppMemory,
2721 PFORMAT_STRING pFormat,
2722 unsigned char fMustAlloc)
2724 const NDR_CSTRUCT_FORMAT * pCStructFormat = (NDR_CSTRUCT_FORMAT*)pFormat;
2725 PFORMAT_STRING pCArrayFormat;
2726 ULONG esize;
2728 TRACE("(%p, %p, %p, %d)\n", pStubMsg, ppMemory, pFormat, fMustAlloc);
2730 pFormat += sizeof(NDR_CSTRUCT_FORMAT);
2731 if ((pCStructFormat->type != RPC_FC_CPSTRUCT) && (pCStructFormat->type != RPC_FC_CSTRUCT))
2733 ERR("invalid format type %x\n", pCStructFormat->type);
2734 RpcRaiseException(RPC_S_INTERNAL_ERROR);
2735 return NULL;
2737 pCArrayFormat = (unsigned char*)&pCStructFormat->offset_to_array_description +
2738 pCStructFormat->offset_to_array_description;
2739 if (*pCArrayFormat != RPC_FC_CARRAY)
2741 ERR("invalid array format type %x\n", pCStructFormat->type);
2742 RpcRaiseException(RPC_S_INTERNAL_ERROR);
2743 return NULL;
2745 esize = *(const WORD*)(pCArrayFormat+2);
2747 pCArrayFormat = ReadConformance(pStubMsg, pCArrayFormat + 4);
2749 ALIGN_POINTER(pStubMsg->Buffer, pCStructFormat->alignment + 1);
2751 TRACE("memory_size = %d\n", pCStructFormat->memory_size);
2753 /* work out how much memory to allocate if we need to do so */
2754 if (!*ppMemory || fMustAlloc)
2756 SIZE_T size = pCStructFormat->memory_size + pStubMsg->MaxCount * esize;
2757 *ppMemory = NdrAllocate(pStubMsg, size);
2760 /* now copy the data */
2761 pStubMsg->BufferMark = pStubMsg->Buffer;
2762 memcpy(*ppMemory, pStubMsg->Buffer, pCStructFormat->memory_size + pStubMsg->MaxCount * esize);
2763 pStubMsg->Buffer += pCStructFormat->memory_size + pStubMsg->MaxCount * esize;
2765 if (pCStructFormat->type == RPC_FC_CPSTRUCT)
2766 EmbeddedPointerUnmarshall(pStubMsg, ppMemory, pFormat, fMustAlloc);
2768 return NULL;
2771 /***********************************************************************
2772 * NdrConformantStructBufferSize [RPCRT4.@]
2774 void WINAPI NdrConformantStructBufferSize(PMIDL_STUB_MESSAGE pStubMsg,
2775 unsigned char *pMemory,
2776 PFORMAT_STRING pFormat)
2778 const NDR_CSTRUCT_FORMAT * pCStructFormat = (NDR_CSTRUCT_FORMAT*)pFormat;
2779 PFORMAT_STRING pCArrayFormat;
2780 ULONG esize;
2782 TRACE("(%p, %p, %p)\n", pStubMsg, pMemory, pFormat);
2784 pFormat += sizeof(NDR_CSTRUCT_FORMAT);
2785 if ((pCStructFormat->type != RPC_FC_CPSTRUCT) && (pCStructFormat->type != RPC_FC_CSTRUCT))
2787 ERR("invalid format type %x\n", pCStructFormat->type);
2788 RpcRaiseException(RPC_S_INTERNAL_ERROR);
2789 return;
2791 pCArrayFormat = (unsigned char*)&pCStructFormat->offset_to_array_description +
2792 pCStructFormat->offset_to_array_description;
2793 if (*pCArrayFormat != RPC_FC_CARRAY)
2795 ERR("invalid array format type %x\n", pCStructFormat->type);
2796 RpcRaiseException(RPC_S_INTERNAL_ERROR);
2797 return;
2799 esize = *(const WORD*)(pCArrayFormat+2);
2801 pCArrayFormat = ComputeConformance(pStubMsg, pMemory + pCStructFormat->memory_size, pCArrayFormat+4, 0);
2802 SizeConformance(pStubMsg);
2804 ALIGN_LENGTH(pStubMsg->BufferLength, pCStructFormat->alignment + 1);
2806 TRACE("memory_size = %d\n", pCStructFormat->memory_size);
2808 pStubMsg->BufferLength += pCStructFormat->memory_size + esize * pStubMsg->MaxCount;
2810 if (pCStructFormat->type == RPC_FC_CPSTRUCT)
2811 EmbeddedPointerBufferSize(pStubMsg, pMemory, pFormat);
2814 /***********************************************************************
2815 * NdrConformantStructMemorySize [RPCRT4.@]
2817 unsigned long WINAPI NdrConformantStructMemorySize(PMIDL_STUB_MESSAGE pStubMsg,
2818 PFORMAT_STRING pFormat)
2820 FIXME("stub\n");
2821 return 0;
2824 /***********************************************************************
2825 * NdrConformantStructFree [RPCRT4.@]
2827 void WINAPI NdrConformantStructFree(PMIDL_STUB_MESSAGE pStubMsg,
2828 unsigned char *pMemory,
2829 PFORMAT_STRING pFormat)
2831 FIXME("stub\n");
2834 /***********************************************************************
2835 * NdrConformantVaryingStructMarshall [RPCRT4.@]
2837 unsigned char * WINAPI NdrConformantVaryingStructMarshall(PMIDL_STUB_MESSAGE pStubMsg,
2838 unsigned char *pMemory,
2839 PFORMAT_STRING pFormat)
2841 const NDR_CVSTRUCT_FORMAT * pCVStructFormat = (NDR_CVSTRUCT_FORMAT*)pFormat;
2842 PFORMAT_STRING pCVArrayFormat;
2843 ULONG esize;
2845 TRACE("(%p, %p, %p)\n", pStubMsg, pMemory, pFormat);
2847 pFormat += sizeof(NDR_CVSTRUCT_FORMAT);
2848 if (pCVStructFormat->type != RPC_FC_CVSTRUCT)
2850 ERR("invalid format type %x\n", pCVStructFormat->type);
2851 RpcRaiseException(RPC_S_INTERNAL_ERROR);
2852 return NULL;
2855 pCVArrayFormat = (unsigned char*)&pCVStructFormat->offset_to_array_description +
2856 pCVStructFormat->offset_to_array_description;
2857 switch (*pCVArrayFormat)
2859 case RPC_FC_CVARRAY:
2860 esize = *(const WORD*)(pCVArrayFormat+2);
2862 pCVArrayFormat = ComputeConformance(pStubMsg, pMemory + pCVStructFormat->memory_size,
2863 pCVArrayFormat + 4, 0);
2864 pCVArrayFormat = ComputeVariance(pStubMsg, pMemory + pCVStructFormat->memory_size,
2865 pCVArrayFormat, 0);
2866 break;
2867 case RPC_FC_C_CSTRING:
2868 TRACE("string=%s\n", debugstr_a((char*)pMemory + pCVStructFormat->memory_size));
2869 pStubMsg->ActualCount = strlen((char*)pMemory + pCVStructFormat->memory_size)+1;
2870 esize = sizeof(char);
2871 if (pCVArrayFormat[1] == RPC_FC_STRING_SIZED)
2872 pCVArrayFormat = ComputeConformance(pStubMsg, pMemory + pCVStructFormat->memory_size,
2873 pCVArrayFormat + 2, 0);
2874 else
2875 pStubMsg->MaxCount = pStubMsg->ActualCount;
2876 break;
2877 case RPC_FC_C_WSTRING:
2878 TRACE("string=%s\n", debugstr_w((LPWSTR)pMemory + pCVStructFormat->memory_size));
2879 pStubMsg->ActualCount = strlenW((LPWSTR)pMemory + pCVStructFormat->memory_size)+1;
2880 esize = sizeof(WCHAR);
2881 if (pCVArrayFormat[1] == RPC_FC_STRING_SIZED)
2882 pCVArrayFormat = ComputeConformance(pStubMsg, pMemory + pCVStructFormat->memory_size,
2883 pCVArrayFormat + 2, 0);
2884 else
2885 pStubMsg->MaxCount = pStubMsg->ActualCount;
2886 break;
2887 default:
2888 ERR("invalid array format type %x\n", *pCVArrayFormat);
2889 RpcRaiseException(RPC_S_INTERNAL_ERROR);
2890 return NULL;
2893 WriteConformance(pStubMsg);
2895 ALIGN_POINTER(pStubMsg->Buffer, pCVStructFormat->alignment + 1);
2897 TRACE("memory_size = %d\n", pCVStructFormat->memory_size);
2899 /* write constant sized part */
2900 pStubMsg->BufferMark = pStubMsg->Buffer;
2901 memcpy(pStubMsg->Buffer, pMemory, pCVStructFormat->memory_size);
2902 pStubMsg->Buffer += pCVStructFormat->memory_size;
2904 WriteVariance(pStubMsg);
2906 /* write array part */
2907 memcpy(pStubMsg->Buffer, pMemory + pCVStructFormat->memory_size, pStubMsg->ActualCount * esize);
2908 pStubMsg->Buffer += pStubMsg->ActualCount * esize;
2910 EmbeddedPointerMarshall(pStubMsg, pMemory, pFormat);
2912 STD_OVERFLOW_CHECK(pStubMsg);
2914 return NULL;
2917 /***********************************************************************
2918 * NdrConformantVaryingStructUnmarshall [RPCRT4.@]
2920 unsigned char * WINAPI NdrConformantVaryingStructUnmarshall(PMIDL_STUB_MESSAGE pStubMsg,
2921 unsigned char **ppMemory,
2922 PFORMAT_STRING pFormat,
2923 unsigned char fMustAlloc)
2925 const NDR_CVSTRUCT_FORMAT * pCVStructFormat = (NDR_CVSTRUCT_FORMAT*)pFormat;
2926 PFORMAT_STRING pCVArrayFormat;
2927 ULONG esize;
2928 unsigned char cvarray_type;
2930 TRACE("(%p, %p, %p, %d)\n", pStubMsg, ppMemory, pFormat, fMustAlloc);
2932 pFormat += sizeof(NDR_CVSTRUCT_FORMAT);
2933 if (pCVStructFormat->type != RPC_FC_CVSTRUCT)
2935 ERR("invalid format type %x\n", pCVStructFormat->type);
2936 RpcRaiseException(RPC_S_INTERNAL_ERROR);
2937 return NULL;
2940 pCVArrayFormat = (unsigned char*)&pCVStructFormat->offset_to_array_description +
2941 pCVStructFormat->offset_to_array_description;
2942 cvarray_type = *pCVArrayFormat;
2943 switch (cvarray_type)
2945 case RPC_FC_CVARRAY:
2946 esize = *(const WORD*)(pCVArrayFormat+2);
2947 pCVArrayFormat = ReadConformance(pStubMsg, pCVArrayFormat + 4);
2948 break;
2949 case RPC_FC_C_CSTRING:
2950 esize = sizeof(char);
2951 if (pCVArrayFormat[1] == RPC_FC_STRING_SIZED)
2952 pCVArrayFormat = ReadConformance(pStubMsg, pCVArrayFormat + 2);
2953 else
2954 pCVArrayFormat = ReadConformance(pStubMsg, NULL);
2955 break;
2956 case RPC_FC_C_WSTRING:
2957 esize = sizeof(WCHAR);
2958 if (pCVArrayFormat[1] == RPC_FC_STRING_SIZED)
2959 pCVArrayFormat = ReadConformance(pStubMsg, pCVArrayFormat + 2);
2960 else
2961 pCVArrayFormat = ReadConformance(pStubMsg, NULL);
2962 break;
2963 default:
2964 ERR("invalid array format type %x\n", *pCVArrayFormat);
2965 RpcRaiseException(RPC_S_INTERNAL_ERROR);
2966 return NULL;
2969 ALIGN_POINTER(pStubMsg->Buffer, pCVStructFormat->alignment + 1);
2971 TRACE("memory_size = %d\n", pCVStructFormat->memory_size);
2973 /* work out how much memory to allocate if we need to do so */
2974 if (!*ppMemory || fMustAlloc)
2976 SIZE_T size = pCVStructFormat->memory_size + pStubMsg->MaxCount * esize;
2977 *ppMemory = NdrAllocate(pStubMsg, size);
2980 /* copy the constant data */
2981 pStubMsg->BufferMark = pStubMsg->Buffer;
2982 memcpy(*ppMemory, pStubMsg->Buffer, pCVStructFormat->memory_size);
2983 pStubMsg->Buffer += pCVStructFormat->memory_size;
2985 pCVArrayFormat = ReadVariance(pStubMsg, pCVArrayFormat);
2987 /* copy the array data */
2988 memcpy(*ppMemory + pCVStructFormat->memory_size, pStubMsg->Buffer,
2989 pStubMsg->ActualCount * esize);
2990 pStubMsg->Buffer += pStubMsg->ActualCount * esize;
2992 if (cvarray_type == RPC_FC_C_CSTRING)
2993 TRACE("string=%s\n", debugstr_a((char *)(*ppMemory + pCVStructFormat->memory_size)));
2994 else if (cvarray_type == RPC_FC_C_WSTRING)
2995 TRACE("string=%s\n", debugstr_w((WCHAR *)(*ppMemory + pCVStructFormat->memory_size)));
2997 EmbeddedPointerUnmarshall(pStubMsg, ppMemory, pFormat, fMustAlloc);
2999 return NULL;
3002 /***********************************************************************
3003 * NdrConformantVaryingStructBufferSize [RPCRT4.@]
3005 void WINAPI NdrConformantVaryingStructBufferSize(PMIDL_STUB_MESSAGE pStubMsg,
3006 unsigned char *pMemory,
3007 PFORMAT_STRING pFormat)
3009 const NDR_CVSTRUCT_FORMAT * pCVStructFormat = (NDR_CVSTRUCT_FORMAT*)pFormat;
3010 PFORMAT_STRING pCVArrayFormat;
3011 ULONG esize;
3013 TRACE("(%p, %p, %p)\n", pStubMsg, pMemory, pFormat);
3015 pFormat += sizeof(NDR_CVSTRUCT_FORMAT);
3016 if (pCVStructFormat->type != RPC_FC_CVSTRUCT)
3018 ERR("invalid format type %x\n", pCVStructFormat->type);
3019 RpcRaiseException(RPC_S_INTERNAL_ERROR);
3020 return;
3023 pCVArrayFormat = (unsigned char*)&pCVStructFormat->offset_to_array_description +
3024 pCVStructFormat->offset_to_array_description;
3025 switch (*pCVArrayFormat)
3027 case RPC_FC_CVARRAY:
3028 esize = *(const WORD*)(pCVArrayFormat+2);
3030 pCVArrayFormat = ComputeConformance(pStubMsg, pMemory + pCVStructFormat->memory_size,
3031 pCVArrayFormat + 4, 0);
3032 pCVArrayFormat = ComputeVariance(pStubMsg, pMemory + pCVStructFormat->memory_size,
3033 pCVArrayFormat + 4, 0);
3034 break;
3035 case RPC_FC_C_CSTRING:
3036 TRACE("string=%s\n", debugstr_a((char*)pMemory + pCVStructFormat->memory_size));
3037 pStubMsg->ActualCount = strlen((char*)pMemory + pCVStructFormat->memory_size)+1;
3038 esize = sizeof(char);
3039 if (pCVArrayFormat[1] == RPC_FC_STRING_SIZED)
3040 pCVArrayFormat = ComputeConformance(pStubMsg, pMemory + pCVStructFormat->memory_size,
3041 pCVArrayFormat + 2, 0);
3042 else
3043 pStubMsg->MaxCount = pStubMsg->ActualCount;
3044 break;
3045 case RPC_FC_C_WSTRING:
3046 TRACE("string=%s\n", debugstr_w((LPWSTR)pMemory + pCVStructFormat->memory_size));
3047 pStubMsg->ActualCount = strlenW((LPWSTR)pMemory + pCVStructFormat->memory_size)+1;
3048 esize = sizeof(WCHAR);
3049 if (pCVArrayFormat[1] == RPC_FC_STRING_SIZED)
3050 pCVArrayFormat = ComputeConformance(pStubMsg, pMemory + pCVStructFormat->memory_size,
3051 pCVArrayFormat + 2, 0);
3052 else
3053 pStubMsg->MaxCount = pStubMsg->ActualCount;
3054 break;
3055 default:
3056 ERR("invalid array format type %x\n", *pCVArrayFormat);
3057 RpcRaiseException(RPC_S_INTERNAL_ERROR);
3058 return;
3061 SizeConformance(pStubMsg);
3063 ALIGN_LENGTH(pStubMsg->BufferLength, pCVStructFormat->alignment + 1);
3065 TRACE("memory_size = %d\n", pCVStructFormat->memory_size);
3067 pStubMsg->BufferLength += pCVStructFormat->memory_size;
3068 SizeVariance(pStubMsg);
3069 pStubMsg->BufferLength += esize * pStubMsg->MaxCount;
3071 EmbeddedPointerBufferSize(pStubMsg, pMemory, pFormat);
3074 /***********************************************************************
3075 * NdrConformantVaryingStructMemorySize [RPCRT4.@]
3077 unsigned long WINAPI NdrConformantVaryingStructMemorySize(PMIDL_STUB_MESSAGE pStubMsg,
3078 PFORMAT_STRING pFormat)
3080 const NDR_CVSTRUCT_FORMAT * pCVStructFormat = (NDR_CVSTRUCT_FORMAT*)pFormat;
3081 PFORMAT_STRING pCVArrayFormat;
3082 ULONG esize;
3083 unsigned char cvarray_type;
3085 TRACE("(%p, %p)\n", pStubMsg, pFormat);
3087 pFormat += sizeof(NDR_CVSTRUCT_FORMAT);
3088 if (pCVStructFormat->type != RPC_FC_CVSTRUCT)
3090 ERR("invalid format type %x\n", pCVStructFormat->type);
3091 RpcRaiseException(RPC_S_INTERNAL_ERROR);
3092 return 0;
3095 pCVArrayFormat = (unsigned char*)&pCVStructFormat->offset_to_array_description +
3096 pCVStructFormat->offset_to_array_description;
3097 cvarray_type = *pCVArrayFormat;
3098 switch (cvarray_type)
3100 case RPC_FC_CVARRAY:
3101 esize = *(const WORD*)(pCVArrayFormat+2);
3102 pCVArrayFormat = ReadConformance(pStubMsg, pCVArrayFormat + 4);
3103 break;
3104 case RPC_FC_C_CSTRING:
3105 esize = sizeof(char);
3106 if (pCVArrayFormat[1] == RPC_FC_STRING_SIZED)
3107 pCVArrayFormat = ReadConformance(pStubMsg, pCVArrayFormat + 2);
3108 else
3109 pCVArrayFormat = ReadConformance(pStubMsg, NULL);
3110 break;
3111 case RPC_FC_C_WSTRING:
3112 esize = sizeof(WCHAR);
3113 if (pCVArrayFormat[1] == RPC_FC_STRING_SIZED)
3114 pCVArrayFormat = ReadConformance(pStubMsg, pCVArrayFormat + 2);
3115 else
3116 pCVArrayFormat = ReadConformance(pStubMsg, NULL);
3117 break;
3118 default:
3119 ERR("invalid array format type %x\n", *pCVArrayFormat);
3120 RpcRaiseException(RPC_S_INTERNAL_ERROR);
3121 return 0;
3124 ALIGN_POINTER(pStubMsg->Buffer, pCVStructFormat->alignment + 1);
3126 TRACE("memory_size = %d\n", pCVStructFormat->memory_size);
3128 pStubMsg->Buffer += pCVStructFormat->memory_size;
3129 pCVArrayFormat = ReadVariance(pStubMsg, pCVArrayFormat);
3130 pStubMsg->Buffer += pCVStructFormat->memory_size + pStubMsg->ActualCount * esize;
3132 pStubMsg->MemorySize += pCVStructFormat->memory_size + pStubMsg->MaxCount * esize;
3134 EmbeddedPointerMemorySize(pStubMsg, pFormat);
3136 return pCVStructFormat->memory_size + pStubMsg->MaxCount * esize;
3139 /***********************************************************************
3140 * NdrConformantVaryingStructFree [RPCRT4.@]
3142 void WINAPI NdrConformantVaryingStructFree(PMIDL_STUB_MESSAGE pStubMsg,
3143 unsigned char *pMemory,
3144 PFORMAT_STRING pFormat)
3146 const NDR_CVSTRUCT_FORMAT * pCVStructFormat = (NDR_CVSTRUCT_FORMAT*)pFormat;
3147 PFORMAT_STRING pCVArrayFormat;
3148 ULONG esize;
3150 TRACE("(%p, %p, %p)\n", pStubMsg, pMemory, pFormat);
3152 pFormat += sizeof(NDR_CVSTRUCT_FORMAT);
3153 if (pCVStructFormat->type != RPC_FC_CVSTRUCT)
3155 ERR("invalid format type %x\n", pCVStructFormat->type);
3156 RpcRaiseException(RPC_S_INTERNAL_ERROR);
3157 return;
3160 pCVArrayFormat = (unsigned char*)&pCVStructFormat->offset_to_array_description +
3161 pCVStructFormat->offset_to_array_description;
3162 switch (*pCVArrayFormat)
3164 case RPC_FC_CVARRAY:
3165 esize = *(const WORD*)(pCVArrayFormat+2);
3167 pCVArrayFormat = ComputeConformance(pStubMsg, pMemory + pCVStructFormat->memory_size,
3168 pCVArrayFormat + 4, 0);
3169 pCVArrayFormat = ComputeVariance(pStubMsg, pMemory + pCVStructFormat->memory_size,
3170 pCVArrayFormat, 0);
3171 break;
3172 case RPC_FC_C_CSTRING:
3173 TRACE("string=%s\n", debugstr_a((char*)pMemory + pCVStructFormat->memory_size));
3174 pStubMsg->ActualCount = strlen((char*)pMemory + pCVStructFormat->memory_size)+1;
3175 esize = sizeof(char);
3176 if (pCVArrayFormat[1] == RPC_FC_STRING_SIZED)
3177 pCVArrayFormat = ComputeConformance(pStubMsg, pMemory + pCVStructFormat->memory_size,
3178 pCVArrayFormat + 2, 0);
3179 else
3180 pStubMsg->MaxCount = pStubMsg->ActualCount;
3181 break;
3182 case RPC_FC_C_WSTRING:
3183 TRACE("string=%s\n", debugstr_w((LPWSTR)pMemory + pCVStructFormat->memory_size));
3184 pStubMsg->ActualCount = strlenW((LPWSTR)pMemory + pCVStructFormat->memory_size)+1;
3185 esize = sizeof(WCHAR);
3186 if (pCVArrayFormat[1] == RPC_FC_STRING_SIZED)
3187 pCVArrayFormat = ComputeConformance(pStubMsg, pMemory + pCVStructFormat->memory_size,
3188 pCVArrayFormat + 2, 0);
3189 else
3190 pStubMsg->MaxCount = pStubMsg->ActualCount;
3191 break;
3192 default:
3193 ERR("invalid array format type %x\n", *pCVArrayFormat);
3194 RpcRaiseException(RPC_S_INTERNAL_ERROR);
3195 return;
3198 TRACE("memory_size = %d\n", pCVStructFormat->memory_size);
3200 EmbeddedPointerFree(pStubMsg, pMemory, pFormat);
3203 typedef struct
3205 unsigned char type;
3206 unsigned char alignment;
3207 unsigned short total_size;
3208 } NDR_SMFARRAY_FORMAT;
3210 typedef struct
3212 unsigned char type;
3213 unsigned char alignment;
3214 unsigned long total_size;
3215 } NDR_LGFARRAY_FORMAT;
3217 /***********************************************************************
3218 * NdrFixedArrayMarshall [RPCRT4.@]
3220 unsigned char * WINAPI NdrFixedArrayMarshall(PMIDL_STUB_MESSAGE pStubMsg,
3221 unsigned char *pMemory,
3222 PFORMAT_STRING pFormat)
3224 const NDR_SMFARRAY_FORMAT *pSmFArrayFormat = (const NDR_SMFARRAY_FORMAT *)pFormat;
3225 unsigned long total_size;
3227 TRACE("(%p, %p, %p)\n", pStubMsg, pMemory, pFormat);
3229 if ((pSmFArrayFormat->type != RPC_FC_SMFARRAY) &&
3230 (pSmFArrayFormat->type != RPC_FC_LGFARRAY))
3232 ERR("invalid format type %x\n", pSmFArrayFormat->type);
3233 RpcRaiseException(RPC_S_INTERNAL_ERROR);
3234 return NULL;
3237 ALIGN_POINTER(pStubMsg->Buffer, pSmFArrayFormat->alignment + 1);
3239 if (pSmFArrayFormat->type == RPC_FC_SMFARRAY)
3241 total_size = pSmFArrayFormat->total_size;
3242 pFormat = (unsigned char *)(pSmFArrayFormat + 1);
3244 else
3246 const NDR_LGFARRAY_FORMAT *pLgFArrayFormat = (const NDR_LGFARRAY_FORMAT *)pFormat;
3247 total_size = pLgFArrayFormat->total_size;
3248 pFormat = (unsigned char *)(pLgFArrayFormat + 1);
3250 memcpy(pStubMsg->Buffer, pMemory, total_size);
3251 pStubMsg->Buffer += total_size;
3253 pFormat = EmbeddedPointerMarshall(pStubMsg, pMemory, pFormat);
3255 return NULL;
3258 /***********************************************************************
3259 * NdrFixedArrayUnmarshall [RPCRT4.@]
3261 unsigned char * WINAPI NdrFixedArrayUnmarshall(PMIDL_STUB_MESSAGE pStubMsg,
3262 unsigned char **ppMemory,
3263 PFORMAT_STRING pFormat,
3264 unsigned char fMustAlloc)
3266 const NDR_SMFARRAY_FORMAT *pSmFArrayFormat = (const NDR_SMFARRAY_FORMAT *)pFormat;
3267 unsigned long total_size;
3269 TRACE("(%p, %p, %p, %d)\n", pStubMsg, ppMemory, pFormat, fMustAlloc);
3271 if ((pSmFArrayFormat->type != RPC_FC_SMFARRAY) &&
3272 (pSmFArrayFormat->type != RPC_FC_LGFARRAY))
3274 ERR("invalid format type %x\n", pSmFArrayFormat->type);
3275 RpcRaiseException(RPC_S_INTERNAL_ERROR);
3276 return NULL;
3279 ALIGN_POINTER(pStubMsg->Buffer, pSmFArrayFormat->alignment + 1);
3281 if (pSmFArrayFormat->type == RPC_FC_SMFARRAY)
3283 total_size = pSmFArrayFormat->total_size;
3284 pFormat = (unsigned char *)(pSmFArrayFormat + 1);
3286 else
3288 const NDR_LGFARRAY_FORMAT *pLgFArrayFormat = (const NDR_LGFARRAY_FORMAT *)pFormat;
3289 total_size = pLgFArrayFormat->total_size;
3290 pFormat = (unsigned char *)(pLgFArrayFormat + 1);
3293 if (fMustAlloc || !*ppMemory)
3294 *ppMemory = NdrAllocate(pStubMsg, total_size);
3295 memcpy(*ppMemory, pStubMsg->Buffer, total_size);
3296 pStubMsg->Buffer += total_size;
3298 pFormat = EmbeddedPointerUnmarshall(pStubMsg, ppMemory, pFormat, fMustAlloc);
3300 return NULL;
3303 /***********************************************************************
3304 * NdrFixedArrayBufferSize [RPCRT4.@]
3306 void WINAPI NdrFixedArrayBufferSize(PMIDL_STUB_MESSAGE pStubMsg,
3307 unsigned char *pMemory,
3308 PFORMAT_STRING pFormat)
3310 const NDR_SMFARRAY_FORMAT *pSmFArrayFormat = (const NDR_SMFARRAY_FORMAT *)pFormat;
3311 unsigned long total_size;
3313 TRACE("(%p, %p, %p)\n", pStubMsg, pMemory, pFormat);
3315 if ((pSmFArrayFormat->type != RPC_FC_SMFARRAY) &&
3316 (pSmFArrayFormat->type != RPC_FC_LGFARRAY))
3318 ERR("invalid format type %x\n", pSmFArrayFormat->type);
3319 RpcRaiseException(RPC_S_INTERNAL_ERROR);
3320 return;
3323 ALIGN_LENGTH(pStubMsg->BufferLength, pSmFArrayFormat->alignment + 1);
3325 if (pSmFArrayFormat->type == RPC_FC_SMFARRAY)
3327 total_size = pSmFArrayFormat->total_size;
3328 pFormat = (unsigned char *)(pSmFArrayFormat + 1);
3330 else
3332 const NDR_LGFARRAY_FORMAT *pLgFArrayFormat = (const NDR_LGFARRAY_FORMAT *)pFormat;
3333 total_size = pLgFArrayFormat->total_size;
3334 pFormat = (unsigned char *)(pLgFArrayFormat + 1);
3336 pStubMsg->BufferLength += total_size;
3338 EmbeddedPointerBufferSize(pStubMsg, pMemory, pFormat);
3341 /***********************************************************************
3342 * NdrFixedArrayMemorySize [RPCRT4.@]
3344 unsigned long WINAPI NdrFixedArrayMemorySize(PMIDL_STUB_MESSAGE pStubMsg,
3345 PFORMAT_STRING pFormat)
3347 const NDR_SMFARRAY_FORMAT *pSmFArrayFormat = (const NDR_SMFARRAY_FORMAT *)pFormat;
3348 unsigned long total_size;
3350 TRACE("(%p, %p)\n", pStubMsg, pFormat);
3352 if ((pSmFArrayFormat->type != RPC_FC_SMFARRAY) &&
3353 (pSmFArrayFormat->type != RPC_FC_LGFARRAY))
3355 ERR("invalid format type %x\n", pSmFArrayFormat->type);
3356 RpcRaiseException(RPC_S_INTERNAL_ERROR);
3357 return 0;
3360 ALIGN_POINTER(pStubMsg->Buffer, pSmFArrayFormat->alignment + 1);
3362 if (pSmFArrayFormat->type == RPC_FC_SMFARRAY)
3364 total_size = pSmFArrayFormat->total_size;
3365 pFormat = (unsigned char *)(pSmFArrayFormat + 1);
3367 else
3369 const NDR_LGFARRAY_FORMAT *pLgFArrayFormat = (const NDR_LGFARRAY_FORMAT *)pFormat;
3370 total_size = pLgFArrayFormat->total_size;
3371 pFormat = (unsigned char *)(pLgFArrayFormat + 1);
3373 pStubMsg->Buffer += total_size;
3374 pStubMsg->MemorySize += total_size;
3376 EmbeddedPointerMemorySize(pStubMsg, pFormat);
3378 return total_size;
3381 /***********************************************************************
3382 * NdrFixedArrayFree [RPCRT4.@]
3384 void WINAPI NdrFixedArrayFree(PMIDL_STUB_MESSAGE pStubMsg,
3385 unsigned char *pMemory,
3386 PFORMAT_STRING pFormat)
3388 const NDR_SMFARRAY_FORMAT *pSmFArrayFormat = (const NDR_SMFARRAY_FORMAT *)pFormat;
3390 TRACE("(%p, %p, %p)\n", pStubMsg, pMemory, pFormat);
3392 if ((pSmFArrayFormat->type != RPC_FC_SMFARRAY) &&
3393 (pSmFArrayFormat->type != RPC_FC_LGFARRAY))
3395 ERR("invalid format type %x\n", pSmFArrayFormat->type);
3396 RpcRaiseException(RPC_S_INTERNAL_ERROR);
3397 return;
3400 if (pSmFArrayFormat->type == RPC_FC_SMFARRAY)
3401 pFormat = (unsigned char *)(pSmFArrayFormat + 1);
3402 else
3404 const NDR_LGFARRAY_FORMAT *pLgFArrayFormat = (const NDR_LGFARRAY_FORMAT *)pFormat;
3405 pFormat = (unsigned char *)(pLgFArrayFormat + 1);
3408 EmbeddedPointerFree(pStubMsg, pMemory, pFormat);
3411 /***********************************************************************
3412 * NdrVaryingArrayMarshall [RPCRT4.@]
3414 unsigned char * WINAPI NdrVaryingArrayMarshall(PMIDL_STUB_MESSAGE pStubMsg,
3415 unsigned char *pMemory,
3416 PFORMAT_STRING pFormat)
3418 FIXME("stub\n");
3419 return NULL;
3422 /***********************************************************************
3423 * NdrVaryingArrayUnmarshall [RPCRT4.@]
3425 unsigned char * WINAPI NdrVaryingArrayUnmarshall(PMIDL_STUB_MESSAGE pStubMsg,
3426 unsigned char **ppMemory,
3427 PFORMAT_STRING pFormat,
3428 unsigned char fMustAlloc)
3430 FIXME("stub\n");
3431 return NULL;
3434 /***********************************************************************
3435 * NdrVaryingArrayBufferSize [RPCRT4.@]
3437 void WINAPI NdrVaryingArrayBufferSize(PMIDL_STUB_MESSAGE pStubMsg,
3438 unsigned char *pMemory,
3439 PFORMAT_STRING pFormat)
3441 FIXME("stub\n");
3444 /***********************************************************************
3445 * NdrVaryingArrayMemorySize [RPCRT4.@]
3447 unsigned long WINAPI NdrVaryingArrayMemorySize(PMIDL_STUB_MESSAGE pStubMsg,
3448 PFORMAT_STRING pFormat)
3450 FIXME("stub\n");
3451 return 0;
3454 /***********************************************************************
3455 * NdrVaryingArrayFree [RPCRT4.@]
3457 void WINAPI NdrVaryingArrayFree(PMIDL_STUB_MESSAGE pStubMsg,
3458 unsigned char *pMemory,
3459 PFORMAT_STRING pFormat)
3461 FIXME("stub\n");
3464 /***********************************************************************
3465 * NdrEncapsulatedUnionMarshall [RPCRT4.@]
3467 unsigned char * WINAPI NdrEncapsulatedUnionMarshall(PMIDL_STUB_MESSAGE pStubMsg,
3468 unsigned char *pMemory,
3469 PFORMAT_STRING pFormat)
3471 FIXME("stub\n");
3472 return NULL;
3475 /***********************************************************************
3476 * NdrEncapsulatedUnionUnmarshall [RPCRT4.@]
3478 unsigned char * WINAPI NdrEncapsulatedUnionUnmarshall(PMIDL_STUB_MESSAGE pStubMsg,
3479 unsigned char **ppMemory,
3480 PFORMAT_STRING pFormat,
3481 unsigned char fMustAlloc)
3483 FIXME("stub\n");
3484 return NULL;
3487 /***********************************************************************
3488 * NdrEncapsulatedUnionBufferSize [RPCRT4.@]
3490 void WINAPI NdrEncapsulatedUnionBufferSize(PMIDL_STUB_MESSAGE pStubMsg,
3491 unsigned char *pMemory,
3492 PFORMAT_STRING pFormat)
3494 FIXME("stub\n");
3497 /***********************************************************************
3498 * NdrEncapsulatedUnionMemorySize [RPCRT4.@]
3500 unsigned long WINAPI NdrEncapsulatedUnionMemorySize(PMIDL_STUB_MESSAGE pStubMsg,
3501 PFORMAT_STRING pFormat)
3503 FIXME("stub\n");
3504 return 0;
3507 /***********************************************************************
3508 * NdrEncapsulatedUnionFree [RPCRT4.@]
3510 void WINAPI NdrEncapsulatedUnionFree(PMIDL_STUB_MESSAGE pStubMsg,
3511 unsigned char *pMemory,
3512 PFORMAT_STRING pFormat)
3514 FIXME("stub\n");
3517 static PFORMAT_STRING get_arm_offset_from_union_arm_selector(PMIDL_STUB_MESSAGE pStubMsg,
3518 unsigned long discriminant,
3519 PFORMAT_STRING pFormat)
3521 unsigned short num_arms, arm, type;
3523 num_arms = *(const SHORT*)pFormat & 0x0fff;
3524 pFormat += 2;
3525 for(arm = 0; arm < num_arms; arm++)
3527 if(discriminant == *(const ULONG*)pFormat)
3529 pFormat += 4;
3530 break;
3532 pFormat += 6;
3535 type = *(const unsigned short*)pFormat;
3536 TRACE("type %04x\n", type);
3537 if(arm == num_arms) /* default arm extras */
3539 if(type == 0xffff)
3541 ERR("no arm for 0x%lx and no default case\n", discriminant);
3542 RpcRaiseException(RPC_S_INVALID_TAG);
3543 return NULL;
3545 if(type == 0)
3547 TRACE("falling back to empty default case for 0x%lx\n", discriminant);
3548 return NULL;
3551 return pFormat;
3554 static PFORMAT_STRING get_non_encapsulated_union_arm(PMIDL_STUB_MESSAGE pStubMsg,
3555 ULONG value,
3556 PFORMAT_STRING pFormat)
3558 pFormat += *(const SHORT*)pFormat;
3559 pFormat += 2;
3561 return get_arm_offset_from_union_arm_selector(pStubMsg, value, pFormat);
3564 /***********************************************************************
3565 * NdrNonEncapsulatedUnionMarshall [RPCRT4.@]
3567 unsigned char * WINAPI NdrNonEncapsulatedUnionMarshall(PMIDL_STUB_MESSAGE pStubMsg,
3568 unsigned char *pMemory,
3569 PFORMAT_STRING pFormat)
3571 unsigned short type;
3572 unsigned char switch_type;
3574 TRACE("(%p, %p, %p)\n", pStubMsg, pMemory, pFormat);
3575 pFormat++;
3577 switch_type = *pFormat;
3578 pFormat++;
3580 pFormat = ComputeConformance(pStubMsg, pMemory, pFormat, 0);
3581 TRACE("got switch value 0x%lx\n", pStubMsg->MaxCount);
3582 /* Marshall discriminant */
3583 NdrBaseTypeMarshall(pStubMsg, (unsigned char *)&pStubMsg->MaxCount, &switch_type);
3585 pFormat = get_non_encapsulated_union_arm(pStubMsg, pStubMsg->MaxCount, pFormat);
3586 if(!pFormat)
3587 return NULL;
3589 type = *(const unsigned short*)pFormat;
3590 if((type & 0xff00) == 0x8000)
3592 unsigned char basetype = LOBYTE(type);
3593 return NdrBaseTypeMarshall(pStubMsg, pMemory, &basetype);
3595 else
3597 PFORMAT_STRING desc = pFormat + *(const SHORT*)pFormat;
3598 NDR_MARSHALL m = NdrMarshaller[*desc & NDR_TABLE_MASK];
3599 if (m)
3601 unsigned char *saved_buffer = NULL;
3602 switch(*desc)
3604 case RPC_FC_RP:
3605 case RPC_FC_UP:
3606 case RPC_FC_OP:
3607 case RPC_FC_FP:
3608 saved_buffer = pStubMsg->Buffer;
3609 pStubMsg->Buffer += 4; /* for pointer ID */
3610 PointerMarshall(pStubMsg, saved_buffer, *(unsigned char **)pMemory, desc);
3611 break;
3612 default:
3613 m(pStubMsg, pMemory, desc);
3616 else FIXME("no marshaller for embedded type %02x\n", *desc);
3618 return NULL;
3621 static long unmarshall_discriminant(PMIDL_STUB_MESSAGE pStubMsg,
3622 PFORMAT_STRING *ppFormat)
3624 long discriminant = 0;
3626 switch(**ppFormat)
3628 case RPC_FC_BYTE:
3629 case RPC_FC_CHAR:
3630 case RPC_FC_SMALL:
3631 case RPC_FC_USMALL:
3632 discriminant = *(UCHAR *)pStubMsg->Buffer;
3633 pStubMsg->Buffer += sizeof(UCHAR);
3634 break;
3635 case RPC_FC_WCHAR:
3636 case RPC_FC_SHORT:
3637 case RPC_FC_USHORT:
3638 ALIGN_POINTER(pStubMsg->Buffer, sizeof(USHORT));
3639 discriminant = *(USHORT *)pStubMsg->Buffer;
3640 pStubMsg->Buffer += sizeof(USHORT);
3641 break;
3642 case RPC_FC_LONG:
3643 case RPC_FC_ULONG:
3644 ALIGN_POINTER(pStubMsg->Buffer, sizeof(ULONG));
3645 discriminant = *(ULONG *)pStubMsg->Buffer;
3646 pStubMsg->Buffer += sizeof(ULONG);
3647 break;
3648 default:
3649 FIXME("Unhandled base type: 0x%02x\n", **ppFormat);
3651 (*ppFormat)++;
3653 if (pStubMsg->fHasNewCorrDesc)
3654 *ppFormat += 6;
3655 else
3656 *ppFormat += 4;
3657 return discriminant;
3660 /**********************************************************************
3661 * NdrNonEncapsulatedUnionUnmarshall[RPCRT4.@]
3663 unsigned char * WINAPI NdrNonEncapsulatedUnionUnmarshall(PMIDL_STUB_MESSAGE pStubMsg,
3664 unsigned char **ppMemory,
3665 PFORMAT_STRING pFormat,
3666 unsigned char fMustAlloc)
3668 long discriminant;
3669 unsigned short type, size;
3671 TRACE("(%p, %p, %p, %d)\n", pStubMsg, ppMemory, pFormat, fMustAlloc);
3672 pFormat++;
3674 /* Unmarshall discriminant */
3675 discriminant = unmarshall_discriminant(pStubMsg, &pFormat);
3676 TRACE("unmarshalled discriminant %lx\n", discriminant);
3678 pFormat += *(const SHORT*)pFormat;
3680 size = *(const unsigned short*)pFormat;
3681 pFormat += 2;
3683 pFormat = get_arm_offset_from_union_arm_selector(pStubMsg, discriminant, pFormat);
3684 if(!pFormat)
3685 return NULL;
3687 if(!*ppMemory || fMustAlloc)
3688 *ppMemory = NdrAllocate(pStubMsg, size);
3690 type = *(const unsigned short*)pFormat;
3691 if((type & 0xff00) == 0x8000)
3693 unsigned char basetype = LOBYTE(type);
3694 return NdrBaseTypeUnmarshall(pStubMsg, ppMemory, &basetype, fMustAlloc);
3696 else
3698 PFORMAT_STRING desc = pFormat + *(const SHORT*)pFormat;
3699 NDR_UNMARSHALL m = NdrUnmarshaller[*desc & NDR_TABLE_MASK];
3700 if (m)
3702 unsigned char *saved_buffer = NULL;
3703 switch(*desc)
3705 case RPC_FC_RP:
3706 case RPC_FC_UP:
3707 case RPC_FC_OP:
3708 case RPC_FC_FP:
3709 **(void***)ppMemory = NULL;
3710 ALIGN_POINTER(pStubMsg->Buffer, 4);
3711 saved_buffer = pStubMsg->Buffer;
3712 pStubMsg->Buffer += 4; /* for pointer ID */
3713 PointerUnmarshall(pStubMsg, saved_buffer, *(unsigned char ***)ppMemory, desc, fMustAlloc);
3714 break;
3715 default:
3716 m(pStubMsg, ppMemory, desc, fMustAlloc);
3719 else FIXME("no marshaller for embedded type %02x\n", *desc);
3721 return NULL;
3724 /***********************************************************************
3725 * NdrNonEncapsulatedUnionBufferSize [RPCRT4.@]
3727 void WINAPI NdrNonEncapsulatedUnionBufferSize(PMIDL_STUB_MESSAGE pStubMsg,
3728 unsigned char *pMemory,
3729 PFORMAT_STRING pFormat)
3731 unsigned short type;
3732 unsigned char switch_type;
3734 TRACE("(%p, %p, %p)\n", pStubMsg, pMemory, pFormat);
3735 pFormat++;
3737 switch_type = *pFormat;
3738 pFormat++;
3740 pFormat = ComputeConformance(pStubMsg, pMemory, pFormat, 0);
3741 TRACE("got switch value 0x%lx\n", pStubMsg->MaxCount);
3742 /* Add discriminant size */
3743 NdrBaseTypeBufferSize(pStubMsg, (unsigned char *)&pStubMsg->MaxCount, &switch_type);
3745 pFormat = get_non_encapsulated_union_arm(pStubMsg, pStubMsg->MaxCount, pFormat);
3746 if(!pFormat)
3747 return;
3749 type = *(const unsigned short*)pFormat;
3750 if((type & 0xff00) == 0x8000)
3752 unsigned char basetype = LOBYTE(type);
3753 NdrBaseTypeBufferSize(pStubMsg, pMemory, &basetype);
3755 else
3757 PFORMAT_STRING desc = pFormat + *(const SHORT*)pFormat;
3758 NDR_BUFFERSIZE m = NdrBufferSizer[*desc & NDR_TABLE_MASK];
3759 if (m)
3761 switch(*desc)
3763 case RPC_FC_RP:
3764 case RPC_FC_UP:
3765 case RPC_FC_OP:
3766 case RPC_FC_FP:
3767 ALIGN_LENGTH(pStubMsg->BufferLength, 4);
3768 pStubMsg->BufferLength += 4; /* for pointer ID */
3769 PointerBufferSize(pStubMsg, *(unsigned char **)pMemory, desc);
3770 break;
3771 default:
3772 m(pStubMsg, pMemory, desc);
3775 else FIXME("no buffersizer for embedded type %02x\n", *desc);
3777 return;
3780 /***********************************************************************
3781 * NdrNonEncapsulatedUnionMemorySize [RPCRT4.@]
3783 unsigned long WINAPI NdrNonEncapsulatedUnionMemorySize(PMIDL_STUB_MESSAGE pStubMsg,
3784 PFORMAT_STRING pFormat)
3786 pFormat += 2;
3787 if (pStubMsg->fHasNewCorrDesc)
3788 pFormat += 6;
3789 else
3790 pFormat += 4;
3792 pFormat += *(const SHORT*)pFormat;
3793 TRACE("size %d\n", *(const SHORT*)pFormat);
3794 return *(const SHORT*)pFormat;
3797 /***********************************************************************
3798 * NdrNonEncapsulatedUnionFree [RPCRT4.@]
3800 void WINAPI NdrNonEncapsulatedUnionFree(PMIDL_STUB_MESSAGE pStubMsg,
3801 unsigned char *pMemory,
3802 PFORMAT_STRING pFormat)
3804 FIXME("stub\n");
3807 /***********************************************************************
3808 * NdrByteCountPointerMarshall [RPCRT4.@]
3810 unsigned char * WINAPI NdrByteCountPointerMarshall(PMIDL_STUB_MESSAGE pStubMsg,
3811 unsigned char *pMemory,
3812 PFORMAT_STRING pFormat)
3814 FIXME("stub\n");
3815 return NULL;
3818 /***********************************************************************
3819 * NdrByteCountPointerUnmarshall [RPCRT4.@]
3821 unsigned char * WINAPI NdrByteCountPointerUnmarshall(PMIDL_STUB_MESSAGE pStubMsg,
3822 unsigned char **ppMemory,
3823 PFORMAT_STRING pFormat,
3824 unsigned char fMustAlloc)
3826 FIXME("stub\n");
3827 return NULL;
3830 /***********************************************************************
3831 * NdrByteCountPointerBufferSize [RPCRT4.@]
3833 void WINAPI NdrByteCountPointerBufferSize(PMIDL_STUB_MESSAGE pStubMsg,
3834 unsigned char *pMemory,
3835 PFORMAT_STRING pFormat)
3837 FIXME("stub\n");
3840 /***********************************************************************
3841 * NdrByteCountPointerMemorySize [RPCRT4.@]
3843 unsigned long WINAPI NdrByteCountPointerMemorySize(PMIDL_STUB_MESSAGE pStubMsg,
3844 PFORMAT_STRING pFormat)
3846 FIXME("stub\n");
3847 return 0;
3850 /***********************************************************************
3851 * NdrByteCountPointerFree [RPCRT4.@]
3853 void WINAPI NdrByteCountPointerFree(PMIDL_STUB_MESSAGE pStubMsg,
3854 unsigned char *pMemory,
3855 PFORMAT_STRING pFormat)
3857 FIXME("stub\n");
3860 /***********************************************************************
3861 * NdrXmitOrRepAsMarshall [RPCRT4.@]
3863 unsigned char * WINAPI NdrXmitOrRepAsMarshall(PMIDL_STUB_MESSAGE pStubMsg,
3864 unsigned char *pMemory,
3865 PFORMAT_STRING pFormat)
3867 FIXME("stub\n");
3868 return NULL;
3871 /***********************************************************************
3872 * NdrXmitOrRepAsUnmarshall [RPCRT4.@]
3874 unsigned char * WINAPI NdrXmitOrRepAsUnmarshall(PMIDL_STUB_MESSAGE pStubMsg,
3875 unsigned char **ppMemory,
3876 PFORMAT_STRING pFormat,
3877 unsigned char fMustAlloc)
3879 FIXME("stub\n");
3880 return NULL;
3883 /***********************************************************************
3884 * NdrXmitOrRepAsBufferSize [RPCRT4.@]
3886 void WINAPI NdrXmitOrRepAsBufferSize(PMIDL_STUB_MESSAGE pStubMsg,
3887 unsigned char *pMemory,
3888 PFORMAT_STRING pFormat)
3890 FIXME("stub\n");
3893 /***********************************************************************
3894 * NdrXmitOrRepAsMemorySize [RPCRT4.@]
3896 unsigned long WINAPI NdrXmitOrRepAsMemorySize(PMIDL_STUB_MESSAGE pStubMsg,
3897 PFORMAT_STRING pFormat)
3899 FIXME("stub\n");
3900 return 0;
3903 /***********************************************************************
3904 * NdrXmitOrRepAsFree [RPCRT4.@]
3906 void WINAPI NdrXmitOrRepAsFree(PMIDL_STUB_MESSAGE pStubMsg,
3907 unsigned char *pMemory,
3908 PFORMAT_STRING pFormat)
3910 FIXME("stub\n");
3913 /***********************************************************************
3914 * NdrBaseTypeMarshall [internal]
3916 static unsigned char *WINAPI NdrBaseTypeMarshall(
3917 PMIDL_STUB_MESSAGE pStubMsg,
3918 unsigned char *pMemory,
3919 PFORMAT_STRING pFormat)
3921 TRACE("pStubMsg %p, pMemory %p, type 0x%02x\n", pStubMsg, pMemory, *pFormat);
3923 switch(*pFormat)
3925 case RPC_FC_BYTE:
3926 case RPC_FC_CHAR:
3927 case RPC_FC_SMALL:
3928 case RPC_FC_USMALL:
3929 *(UCHAR *)pStubMsg->Buffer = *(UCHAR *)pMemory;
3930 pStubMsg->Buffer += sizeof(UCHAR);
3931 TRACE("value: 0x%02x\n", *(UCHAR *)pMemory);
3932 break;
3933 case RPC_FC_WCHAR:
3934 case RPC_FC_SHORT:
3935 case RPC_FC_USHORT:
3936 ALIGN_POINTER(pStubMsg->Buffer, sizeof(USHORT));
3937 *(USHORT *)pStubMsg->Buffer = *(USHORT *)pMemory;
3938 pStubMsg->Buffer += sizeof(USHORT);
3939 TRACE("value: 0x%04x\n", *(USHORT *)pMemory);
3940 break;
3941 case RPC_FC_LONG:
3942 case RPC_FC_ULONG:
3943 case RPC_FC_ERROR_STATUS_T:
3944 case RPC_FC_ENUM32:
3945 ALIGN_POINTER(pStubMsg->Buffer, sizeof(ULONG));
3946 *(ULONG *)pStubMsg->Buffer = *(ULONG *)pMemory;
3947 pStubMsg->Buffer += sizeof(ULONG);
3948 TRACE("value: 0x%08lx\n", *(ULONG *)pMemory);
3949 break;
3950 case RPC_FC_FLOAT:
3951 ALIGN_POINTER(pStubMsg->Buffer, sizeof(float));
3952 *(float *)pStubMsg->Buffer = *(float *)pMemory;
3953 pStubMsg->Buffer += sizeof(float);
3954 break;
3955 case RPC_FC_DOUBLE:
3956 ALIGN_POINTER(pStubMsg->Buffer, sizeof(double));
3957 *(double *)pStubMsg->Buffer = *(double *)pMemory;
3958 pStubMsg->Buffer += sizeof(double);
3959 break;
3960 case RPC_FC_HYPER:
3961 ALIGN_POINTER(pStubMsg->Buffer, sizeof(ULONGLONG));
3962 *(ULONGLONG *)pStubMsg->Buffer = *(ULONGLONG *)pMemory;
3963 pStubMsg->Buffer += sizeof(ULONGLONG);
3964 TRACE("value: %s\n", wine_dbgstr_longlong(*(ULONGLONG*)pMemory));
3965 break;
3966 case RPC_FC_ENUM16:
3967 /* only 16-bits on the wire, so do a sanity check */
3968 if (*(UINT *)pMemory > USHRT_MAX)
3969 RpcRaiseException(RPC_X_ENUM_VALUE_OUT_OF_RANGE);
3970 ALIGN_POINTER(pStubMsg->Buffer, sizeof(USHORT));
3971 *(USHORT *)pStubMsg->Buffer = *(UINT *)pMemory;
3972 pStubMsg->Buffer += sizeof(USHORT);
3973 TRACE("value: 0x%04x\n", *(UINT *)pMemory);
3974 break;
3975 default:
3976 FIXME("Unhandled base type: 0x%02x\n", *pFormat);
3979 STD_OVERFLOW_CHECK(pStubMsg);
3981 /* FIXME: what is the correct return value? */
3982 return NULL;
3985 /***********************************************************************
3986 * NdrBaseTypeUnmarshall [internal]
3988 static unsigned char *WINAPI NdrBaseTypeUnmarshall(
3989 PMIDL_STUB_MESSAGE pStubMsg,
3990 unsigned char **ppMemory,
3991 PFORMAT_STRING pFormat,
3992 unsigned char fMustAlloc)
3994 TRACE("pStubMsg: %p, ppMemory: %p, type: 0x%02x, fMustAlloc: %s\n", pStubMsg, ppMemory, *pFormat, fMustAlloc ? "true" : "false");
3996 if (fMustAlloc || !*ppMemory)
3998 unsigned char *Buffer = pStubMsg->Buffer;
3999 unsigned long MemorySize = pStubMsg->MemorySize;
4000 *ppMemory = NdrAllocate(pStubMsg, NdrBaseTypeMemorySize(pStubMsg, pFormat));
4001 pStubMsg->MemorySize = MemorySize;
4002 pStubMsg->Buffer = Buffer;
4005 TRACE("*ppMemory: %p\n", *ppMemory);
4007 switch(*pFormat)
4009 case RPC_FC_BYTE:
4010 case RPC_FC_CHAR:
4011 case RPC_FC_SMALL:
4012 case RPC_FC_USMALL:
4013 **(UCHAR **)ppMemory = *(UCHAR *)pStubMsg->Buffer;
4014 pStubMsg->Buffer += sizeof(UCHAR);
4015 TRACE("value: 0x%02x\n", **(UCHAR **)ppMemory);
4016 break;
4017 case RPC_FC_WCHAR:
4018 case RPC_FC_SHORT:
4019 case RPC_FC_USHORT:
4020 ALIGN_POINTER(pStubMsg->Buffer, sizeof(USHORT));
4021 **(USHORT **)ppMemory = *(USHORT *)pStubMsg->Buffer;
4022 pStubMsg->Buffer += sizeof(USHORT);
4023 TRACE("value: 0x%04x\n", **(USHORT **)ppMemory);
4024 break;
4025 case RPC_FC_LONG:
4026 case RPC_FC_ULONG:
4027 case RPC_FC_ERROR_STATUS_T:
4028 case RPC_FC_ENUM32:
4029 ALIGN_POINTER(pStubMsg->Buffer, sizeof(ULONG));
4030 **(ULONG **)ppMemory = *(ULONG *)pStubMsg->Buffer;
4031 pStubMsg->Buffer += sizeof(ULONG);
4032 TRACE("value: 0x%08lx\n", **(ULONG **)ppMemory);
4033 break;
4034 case RPC_FC_FLOAT:
4035 ALIGN_POINTER(pStubMsg->Buffer, sizeof(float));
4036 **(float **)ppMemory = *(float *)pStubMsg->Buffer;
4037 pStubMsg->Buffer += sizeof(float);
4038 TRACE("value: %f\n", **(float **)ppMemory);
4039 break;
4040 case RPC_FC_DOUBLE:
4041 ALIGN_POINTER(pStubMsg->Buffer, sizeof(double));
4042 **(double **)ppMemory = *(double*)pStubMsg->Buffer;
4043 pStubMsg->Buffer += sizeof(double);
4044 TRACE("value: %f\n", **(double **)ppMemory);
4045 break;
4046 case RPC_FC_HYPER:
4047 ALIGN_POINTER(pStubMsg->Buffer, sizeof(ULONGLONG));
4048 **(ULONGLONG **)ppMemory = *(ULONGLONG *)pStubMsg->Buffer;
4049 pStubMsg->Buffer += sizeof(ULONGLONG);
4050 TRACE("value: %s\n", wine_dbgstr_longlong(**(ULONGLONG **)ppMemory));
4051 break;
4052 case RPC_FC_ENUM16:
4053 ALIGN_POINTER(pStubMsg->Buffer, sizeof(USHORT));
4054 /* 16-bits on the wire, but int in memory */
4055 **(UINT **)ppMemory = *(USHORT *)pStubMsg->Buffer;
4056 pStubMsg->Buffer += sizeof(USHORT);
4057 TRACE("value: 0x%08x\n", **(UINT **)ppMemory);
4058 break;
4059 default:
4060 FIXME("Unhandled base type: 0x%02x\n", *pFormat);
4063 /* FIXME: what is the correct return value? */
4065 return NULL;
4068 /***********************************************************************
4069 * NdrBaseTypeBufferSize [internal]
4071 static void WINAPI NdrBaseTypeBufferSize(
4072 PMIDL_STUB_MESSAGE pStubMsg,
4073 unsigned char *pMemory,
4074 PFORMAT_STRING pFormat)
4076 TRACE("pStubMsg %p, pMemory %p, type 0x%02x\n", pStubMsg, pMemory, *pFormat);
4078 switch(*pFormat)
4080 case RPC_FC_BYTE:
4081 case RPC_FC_CHAR:
4082 case RPC_FC_SMALL:
4083 case RPC_FC_USMALL:
4084 pStubMsg->BufferLength += sizeof(UCHAR);
4085 break;
4086 case RPC_FC_WCHAR:
4087 case RPC_FC_SHORT:
4088 case RPC_FC_USHORT:
4089 case RPC_FC_ENUM16:
4090 ALIGN_LENGTH(pStubMsg->BufferLength, sizeof(USHORT));
4091 pStubMsg->BufferLength += sizeof(USHORT);
4092 break;
4093 case RPC_FC_LONG:
4094 case RPC_FC_ULONG:
4095 case RPC_FC_ENUM32:
4096 ALIGN_LENGTH(pStubMsg->BufferLength, sizeof(ULONG));
4097 pStubMsg->BufferLength += sizeof(ULONG);
4098 break;
4099 case RPC_FC_FLOAT:
4100 ALIGN_LENGTH(pStubMsg->BufferLength, sizeof(float));
4101 pStubMsg->BufferLength += sizeof(float);
4102 break;
4103 case RPC_FC_DOUBLE:
4104 ALIGN_LENGTH(pStubMsg->BufferLength, sizeof(double));
4105 pStubMsg->BufferLength += sizeof(double);
4106 break;
4107 case RPC_FC_HYPER:
4108 ALIGN_LENGTH(pStubMsg->BufferLength, sizeof(ULONGLONG));
4109 pStubMsg->BufferLength += sizeof(ULONGLONG);
4110 break;
4111 case RPC_FC_ERROR_STATUS_T:
4112 ALIGN_LENGTH(pStubMsg->BufferLength, sizeof(error_status_t));
4113 pStubMsg->BufferLength += sizeof(error_status_t);
4114 break;
4115 default:
4116 FIXME("Unhandled base type: 0x%02x\n", *pFormat);
4120 /***********************************************************************
4121 * NdrBaseTypeMemorySize [internal]
4123 static unsigned long WINAPI NdrBaseTypeMemorySize(
4124 PMIDL_STUB_MESSAGE pStubMsg,
4125 PFORMAT_STRING pFormat)
4127 switch(*pFormat)
4129 case RPC_FC_BYTE:
4130 case RPC_FC_CHAR:
4131 case RPC_FC_SMALL:
4132 case RPC_FC_USMALL:
4133 pStubMsg->Buffer += sizeof(UCHAR);
4134 pStubMsg->MemorySize += sizeof(UCHAR);
4135 return sizeof(UCHAR);
4136 case RPC_FC_WCHAR:
4137 case RPC_FC_SHORT:
4138 case RPC_FC_USHORT:
4139 pStubMsg->Buffer += sizeof(USHORT);
4140 pStubMsg->MemorySize += sizeof(USHORT);
4141 return sizeof(USHORT);
4142 case RPC_FC_LONG:
4143 case RPC_FC_ULONG:
4144 pStubMsg->Buffer += sizeof(ULONG);
4145 pStubMsg->MemorySize += sizeof(ULONG);
4146 return sizeof(ULONG);
4147 case RPC_FC_FLOAT:
4148 pStubMsg->Buffer += sizeof(float);
4149 pStubMsg->MemorySize += sizeof(float);
4150 return sizeof(float);
4151 case RPC_FC_DOUBLE:
4152 pStubMsg->Buffer += sizeof(double);
4153 pStubMsg->MemorySize += sizeof(double);
4154 return sizeof(double);
4155 case RPC_FC_HYPER:
4156 pStubMsg->Buffer += sizeof(ULONGLONG);
4157 pStubMsg->MemorySize += sizeof(ULONGLONG);
4158 return sizeof(ULONGLONG);
4159 case RPC_FC_ERROR_STATUS_T:
4160 pStubMsg->Buffer += sizeof(error_status_t);
4161 pStubMsg->MemorySize += sizeof(error_status_t);
4162 return sizeof(error_status_t);
4163 case RPC_FC_ENUM16:
4164 case RPC_FC_ENUM32:
4165 pStubMsg->Buffer += sizeof(INT);
4166 pStubMsg->MemorySize += sizeof(INT);
4167 return sizeof(INT);
4168 default:
4169 FIXME("Unhandled base type: 0x%02x\n", *pFormat);
4170 return 0;
4174 /***********************************************************************
4175 * NdrBaseTypeFree [internal]
4177 static void WINAPI NdrBaseTypeFree(PMIDL_STUB_MESSAGE pStubMsg,
4178 unsigned char *pMemory,
4179 PFORMAT_STRING pFormat)
4181 TRACE("pStubMsg %p pMemory %p type 0x%02x\n", pStubMsg, pMemory, *pFormat);
4183 /* nothing to do */
4186 /***********************************************************************
4187 * NdrClientContextMarshall
4189 void WINAPI NdrClientContextMarshall(PMIDL_STUB_MESSAGE pStubMsg,
4190 NDR_CCONTEXT ContextHandle,
4191 int fCheck)
4193 FIXME("(%p, %p, %d): stub\n", pStubMsg, ContextHandle, fCheck);
4196 /***********************************************************************
4197 * NdrClientContextUnmarshall
4199 void WINAPI NdrClientContextUnmarshall(PMIDL_STUB_MESSAGE pStubMsg,
4200 NDR_CCONTEXT * pContextHandle,
4201 RPC_BINDING_HANDLE BindHandle)
4203 FIXME("(%p, %p, %p): stub\n", pStubMsg, pContextHandle, BindHandle);
4206 void WINAPI NdrServerContextMarshall(PMIDL_STUB_MESSAGE pStubMsg,
4207 NDR_SCONTEXT ContextHandle,
4208 NDR_RUNDOWN RundownRoutine )
4210 FIXME("(%p, %p, %p): stub\n", pStubMsg, ContextHandle, RundownRoutine);
4213 NDR_SCONTEXT WINAPI NdrServerContextUnmarshall(PMIDL_STUB_MESSAGE pStubMsg)
4215 FIXME("(%p): stub\n", pStubMsg);
4216 return NULL;
4219 void WINAPI NdrContextHandleSize(PMIDL_STUB_MESSAGE pStubMsg,
4220 unsigned char* pMemory,
4221 PFORMAT_STRING pFormat)
4223 FIXME("(%p, %p, %p): stub\n", pStubMsg, pMemory, pFormat);
4226 NDR_SCONTEXT WINAPI NdrContextHandleInitialize(PMIDL_STUB_MESSAGE pStubMsg,
4227 PFORMAT_STRING pFormat)
4229 FIXME("(%p, %p): stub\n", pStubMsg, pFormat);
4230 return NULL;
4233 void WINAPI NdrServerContextNewMarshall(PMIDL_STUB_MESSAGE pStubMsg,
4234 NDR_SCONTEXT ContextHandle,
4235 NDR_RUNDOWN RundownRoutine,
4236 PFORMAT_STRING pFormat)
4238 FIXME("(%p, %p, %p, %p): stub\n", pStubMsg, ContextHandle, RundownRoutine, pFormat);
4241 NDR_SCONTEXT WINAPI NdrServerContextNewUnmarshall(PMIDL_STUB_MESSAGE pStubMsg,
4242 PFORMAT_STRING pFormat)
4244 FIXME("(%p, %p): stub\n", pStubMsg, pFormat);
4245 return NULL;
4248 RPC_BINDING_HANDLE WINAPI NDRCContextBinding(NDR_CCONTEXT CContext)
4250 FIXME("(%p): stub\n", CContext);
4251 return NULL;