ntdll: Add wrappers for the remaining math functions.
[wine/testsucceed.git] / dlls / rpcrt4 / ndr_marshall.c
blobb8904999ca264248f5cbacbe7924acd0fa246b57
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 #define BUFFER_PARANOIA 20
48 #if defined(__i386__)
49 # define LITTLE_ENDIAN_UINT32_WRITE(pchar, uint32) \
50 (*((UINT32 *)(pchar)) = (uint32))
52 # define LITTLE_ENDIAN_UINT32_READ(pchar) \
53 (*((UINT32 *)(pchar)))
54 #else
55 /* these would work for i386 too, but less efficient */
56 # define LITTLE_ENDIAN_UINT32_WRITE(pchar, uint32) \
57 (*(pchar) = LOBYTE(LOWORD(uint32)), \
58 *((pchar)+1) = HIBYTE(LOWORD(uint32)), \
59 *((pchar)+2) = LOBYTE(HIWORD(uint32)), \
60 *((pchar)+3) = HIBYTE(HIWORD(uint32)), \
61 (uint32)) /* allow as r-value */
63 # define LITTLE_ENDIAN_UINT32_READ(pchar) \
64 (MAKELONG( \
65 MAKEWORD(*(pchar), *((pchar)+1)), \
66 MAKEWORD(*((pchar)+2), *((pchar)+3))))
67 #endif
69 #define BIG_ENDIAN_UINT32_WRITE(pchar, uint32) \
70 (*((pchar)+3) = LOBYTE(LOWORD(uint32)), \
71 *((pchar)+2) = HIBYTE(LOWORD(uint32)), \
72 *((pchar)+1) = LOBYTE(HIWORD(uint32)), \
73 *(pchar) = HIBYTE(HIWORD(uint32)), \
74 (uint32)) /* allow as r-value */
76 #define BIG_ENDIAN_UINT32_READ(pchar) \
77 (MAKELONG( \
78 MAKEWORD(*((pchar)+3), *((pchar)+2)), \
79 MAKEWORD(*((pchar)+1), *(pchar))))
81 #ifdef NDR_LOCAL_IS_BIG_ENDIAN
82 # define NDR_LOCAL_UINT32_WRITE(pchar, uint32) \
83 BIG_ENDIAN_UINT32_WRITE(pchar, uint32)
84 # define NDR_LOCAL_UINT32_READ(pchar) \
85 BIG_ENDIAN_UINT32_READ(pchar)
86 #else
87 # define NDR_LOCAL_UINT32_WRITE(pchar, uint32) \
88 LITTLE_ENDIAN_UINT32_WRITE(pchar, uint32)
89 # define NDR_LOCAL_UINT32_READ(pchar) \
90 LITTLE_ENDIAN_UINT32_READ(pchar)
91 #endif
93 /* _Align must be the desired alignment minus 1,
94 * e.g. ALIGN_LENGTH(len, 3) to align on a dword boundary. */
95 #define ALIGNED_LENGTH(_Len, _Align) (((_Len)+(_Align))&~(_Align))
96 #define ALIGNED_POINTER(_Ptr, _Align) ((LPVOID)ALIGNED_LENGTH((ULONG_PTR)(_Ptr), _Align))
97 #define ALIGN_LENGTH(_Len, _Align) _Len = ALIGNED_LENGTH(_Len, _Align)
98 #define ALIGN_POINTER(_Ptr, _Align) _Ptr = ALIGNED_POINTER(_Ptr, _Align)
100 #define STD_OVERFLOW_CHECK(_Msg) do { \
101 TRACE("buffer=%d/%ld\n", _Msg->Buffer - (unsigned char *)_Msg->RpcMsg->Buffer, _Msg->BufferLength); \
102 if (_Msg->Buffer > (unsigned char *)_Msg->RpcMsg->Buffer + _Msg->BufferLength) \
103 ERR("buffer overflow %d bytes\n", _Msg->Buffer - ((unsigned char *)_Msg->RpcMsg->Buffer + _Msg->BufferLength)); \
104 } while (0)
106 #define NDR_TABLE_SIZE 128
107 #define NDR_TABLE_MASK 127
109 static unsigned char *WINAPI NdrBaseTypeMarshall(PMIDL_STUB_MESSAGE, unsigned char *, PFORMAT_STRING);
110 static unsigned char *WINAPI NdrBaseTypeUnmarshall(PMIDL_STUB_MESSAGE, unsigned char **, PFORMAT_STRING, unsigned char);
111 static void WINAPI NdrBaseTypeBufferSize(PMIDL_STUB_MESSAGE, unsigned char *, PFORMAT_STRING);
112 static void WINAPI NdrBaseTypeFree(PMIDL_STUB_MESSAGE, unsigned char *, PFORMAT_STRING);
113 static unsigned long WINAPI NdrBaseTypeMemorySize(PMIDL_STUB_MESSAGE, PFORMAT_STRING);
115 const NDR_MARSHALL NdrMarshaller[NDR_TABLE_SIZE] = {
117 NdrBaseTypeMarshall, NdrBaseTypeMarshall, NdrBaseTypeMarshall,
118 NdrBaseTypeMarshall, NdrBaseTypeMarshall, NdrBaseTypeMarshall, NdrBaseTypeMarshall,
119 NdrBaseTypeMarshall, NdrBaseTypeMarshall, NdrBaseTypeMarshall, NdrBaseTypeMarshall,
120 NdrBaseTypeMarshall, NdrBaseTypeMarshall, NdrBaseTypeMarshall, NdrBaseTypeMarshall,
121 /* 0x10 */
122 NdrBaseTypeMarshall,
123 /* 0x11 */
124 NdrPointerMarshall, NdrPointerMarshall,
125 NdrPointerMarshall, NdrPointerMarshall,
126 /* 0x15 */
127 NdrSimpleStructMarshall, NdrSimpleStructMarshall,
128 NdrConformantStructMarshall, NdrConformantStructMarshall,
129 NdrConformantVaryingStructMarshall,
130 NdrComplexStructMarshall,
131 /* 0x1b */
132 NdrConformantArrayMarshall,
133 NdrConformantVaryingArrayMarshall,
134 NdrFixedArrayMarshall, NdrFixedArrayMarshall,
135 NdrVaryingArrayMarshall, NdrVaryingArrayMarshall,
136 NdrComplexArrayMarshall,
137 /* 0x22 */
138 NdrConformantStringMarshall, 0, 0,
139 NdrConformantStringMarshall,
140 NdrNonConformantStringMarshall, 0, 0, 0,
141 /* 0x2a */
142 NdrEncapsulatedUnionMarshall,
143 NdrNonEncapsulatedUnionMarshall,
145 NdrXmitOrRepAsMarshall, NdrXmitOrRepAsMarshall,
146 /* 0x2f */
147 NdrInterfacePointerMarshall,
148 /* 0xb0 */
149 0, 0, 0, 0,
150 NdrUserMarshalMarshall
152 const NDR_UNMARSHALL NdrUnmarshaller[NDR_TABLE_SIZE] = {
154 NdrBaseTypeUnmarshall, NdrBaseTypeUnmarshall, NdrBaseTypeUnmarshall,
155 NdrBaseTypeUnmarshall, NdrBaseTypeUnmarshall, NdrBaseTypeUnmarshall, NdrBaseTypeUnmarshall,
156 NdrBaseTypeUnmarshall, NdrBaseTypeUnmarshall, NdrBaseTypeUnmarshall, NdrBaseTypeUnmarshall,
157 NdrBaseTypeUnmarshall, NdrBaseTypeUnmarshall, NdrBaseTypeUnmarshall, NdrBaseTypeUnmarshall,
158 /* 0x10 */
159 NdrBaseTypeUnmarshall,
160 /* 0x11 */
161 NdrPointerUnmarshall, NdrPointerUnmarshall,
162 NdrPointerUnmarshall, NdrPointerUnmarshall,
163 /* 0x15 */
164 NdrSimpleStructUnmarshall, NdrSimpleStructUnmarshall,
165 NdrConformantStructUnmarshall, NdrConformantStructUnmarshall,
166 NdrConformantVaryingStructUnmarshall,
167 NdrComplexStructUnmarshall,
168 /* 0x1b */
169 NdrConformantArrayUnmarshall,
170 NdrConformantVaryingArrayUnmarshall,
171 NdrFixedArrayUnmarshall, NdrFixedArrayUnmarshall,
172 NdrVaryingArrayUnmarshall, NdrVaryingArrayUnmarshall,
173 NdrComplexArrayUnmarshall,
174 /* 0x22 */
175 NdrConformantStringUnmarshall, 0, 0,
176 NdrConformantStringUnmarshall,
177 NdrNonConformantStringUnmarshall, 0, 0, 0,
178 /* 0x2a */
179 NdrEncapsulatedUnionUnmarshall,
180 NdrNonEncapsulatedUnionUnmarshall,
182 NdrXmitOrRepAsUnmarshall, NdrXmitOrRepAsUnmarshall,
183 /* 0x2f */
184 NdrInterfacePointerUnmarshall,
185 /* 0xb0 */
186 0, 0, 0, 0,
187 NdrUserMarshalUnmarshall
189 const NDR_BUFFERSIZE NdrBufferSizer[NDR_TABLE_SIZE] = {
191 NdrBaseTypeBufferSize, NdrBaseTypeBufferSize, NdrBaseTypeBufferSize,
192 NdrBaseTypeBufferSize, NdrBaseTypeBufferSize, NdrBaseTypeBufferSize, NdrBaseTypeBufferSize,
193 NdrBaseTypeBufferSize, NdrBaseTypeBufferSize, NdrBaseTypeBufferSize, NdrBaseTypeBufferSize,
194 NdrBaseTypeBufferSize, NdrBaseTypeBufferSize, NdrBaseTypeBufferSize, NdrBaseTypeBufferSize,
195 /* 0x10 */
196 NdrBaseTypeBufferSize,
197 /* 0x11 */
198 NdrPointerBufferSize, NdrPointerBufferSize,
199 NdrPointerBufferSize, NdrPointerBufferSize,
200 /* 0x15 */
201 NdrSimpleStructBufferSize, NdrSimpleStructBufferSize,
202 NdrConformantStructBufferSize, NdrConformantStructBufferSize,
203 NdrConformantVaryingStructBufferSize,
204 NdrComplexStructBufferSize,
205 /* 0x1b */
206 NdrConformantArrayBufferSize,
207 NdrConformantVaryingArrayBufferSize,
208 NdrFixedArrayBufferSize, NdrFixedArrayBufferSize,
209 NdrVaryingArrayBufferSize, NdrVaryingArrayBufferSize,
210 NdrComplexArrayBufferSize,
211 /* 0x22 */
212 NdrConformantStringBufferSize, 0, 0,
213 NdrConformantStringBufferSize,
214 NdrNonConformantStringBufferSize, 0, 0, 0,
215 /* 0x2a */
216 NdrEncapsulatedUnionBufferSize,
217 NdrNonEncapsulatedUnionBufferSize,
219 NdrXmitOrRepAsBufferSize, NdrXmitOrRepAsBufferSize,
220 /* 0x2f */
221 NdrInterfacePointerBufferSize,
222 /* 0xb0 */
223 0, 0, 0, 0,
224 NdrUserMarshalBufferSize
226 const NDR_MEMORYSIZE NdrMemorySizer[NDR_TABLE_SIZE] = {
228 NdrBaseTypeMemorySize, NdrBaseTypeMemorySize, NdrBaseTypeMemorySize,
229 NdrBaseTypeMemorySize, NdrBaseTypeMemorySize, NdrBaseTypeMemorySize, NdrBaseTypeMemorySize,
230 NdrBaseTypeMemorySize, NdrBaseTypeMemorySize, NdrBaseTypeMemorySize, NdrBaseTypeMemorySize,
231 NdrBaseTypeMemorySize, NdrBaseTypeMemorySize, NdrBaseTypeMemorySize, NdrBaseTypeMemorySize,
232 /* 0x10 */
233 NdrBaseTypeMemorySize,
234 /* 0x11 */
235 NdrPointerMemorySize, NdrPointerMemorySize,
236 NdrPointerMemorySize, NdrPointerMemorySize,
237 /* 0x15 */
238 NdrSimpleStructMemorySize, NdrSimpleStructMemorySize,
239 0, 0, 0,
240 NdrComplexStructMemorySize,
241 /* 0x1b */
242 NdrConformantArrayMemorySize, 0, 0, 0, 0, 0,
243 NdrComplexArrayMemorySize,
244 /* 0x22 */
245 NdrConformantStringMemorySize, 0, 0,
246 NdrConformantStringMemorySize,
247 NdrNonConformantStringMemorySize, 0, 0, 0,
248 /* 0x2a */
249 0, 0, 0, 0, 0,
250 /* 0x2f */
251 NdrInterfacePointerMemorySize,
252 /* 0xb0 */
253 0, 0, 0, 0,
254 NdrUserMarshalMemorySize
256 const NDR_FREE NdrFreer[NDR_TABLE_SIZE] = {
258 NdrBaseTypeFree, NdrBaseTypeFree, NdrBaseTypeFree,
259 NdrBaseTypeFree, NdrBaseTypeFree, NdrBaseTypeFree, NdrBaseTypeFree,
260 NdrBaseTypeFree, NdrBaseTypeFree, NdrBaseTypeFree, NdrBaseTypeFree,
261 NdrBaseTypeFree, NdrBaseTypeFree, NdrBaseTypeFree, NdrBaseTypeFree,
262 /* 0x10 */
263 NdrBaseTypeFree,
264 /* 0x11 */
265 NdrPointerFree, NdrPointerFree,
266 NdrPointerFree, NdrPointerFree,
267 /* 0x15 */
268 NdrSimpleStructFree, NdrSimpleStructFree,
269 NdrConformantStructFree, NdrConformantStructFree,
270 NdrConformantVaryingStructFree,
271 NdrComplexStructFree,
272 /* 0x1b */
273 NdrConformantArrayFree,
274 NdrConformantVaryingArrayFree,
275 NdrFixedArrayFree, NdrFixedArrayFree,
276 NdrVaryingArrayFree, NdrVaryingArrayFree,
277 NdrComplexArrayFree,
278 /* 0x22 */
279 0, 0, 0,
280 0, 0, 0, 0, 0,
281 /* 0x2a */
282 NdrEncapsulatedUnionFree,
283 NdrNonEncapsulatedUnionFree,
285 NdrXmitOrRepAsFree, NdrXmitOrRepAsFree,
286 /* 0x2f */
287 NdrInterfacePointerFree,
288 /* 0xb0 */
289 0, 0, 0, 0,
290 NdrUserMarshalFree
293 void * WINAPI NdrAllocate(MIDL_STUB_MESSAGE *pStubMsg, size_t len)
295 /* hmm, this is probably supposed to do more? */
296 return pStubMsg->pfnAllocate(len);
299 static void WINAPI NdrFree(MIDL_STUB_MESSAGE *pStubMsg, unsigned char *Pointer)
301 pStubMsg->pfnFree(Pointer);
304 static inline BOOL IsConformanceOrVariancePresent(PFORMAT_STRING pFormat)
306 return (*(const ULONG *)pFormat != -1);
309 PFORMAT_STRING ReadConformance(MIDL_STUB_MESSAGE *pStubMsg, PFORMAT_STRING pFormat)
311 pStubMsg->MaxCount = NDR_LOCAL_UINT32_READ(pStubMsg->Buffer);
312 pStubMsg->Buffer += 4;
313 TRACE("unmarshalled conformance is %ld\n", pStubMsg->MaxCount);
314 if (pStubMsg->fHasNewCorrDesc)
315 return pFormat+6;
316 else
317 return pFormat+4;
320 static inline PFORMAT_STRING ReadVariance(MIDL_STUB_MESSAGE *pStubMsg, PFORMAT_STRING pFormat)
322 if (!IsConformanceOrVariancePresent(pFormat))
324 pStubMsg->Offset = 0;
325 pStubMsg->ActualCount = pStubMsg->MaxCount;
326 goto done;
329 pStubMsg->Offset = NDR_LOCAL_UINT32_READ(pStubMsg->Buffer);
330 pStubMsg->Buffer += 4;
331 TRACE("offset is %ld\n", pStubMsg->Offset);
332 pStubMsg->ActualCount = NDR_LOCAL_UINT32_READ(pStubMsg->Buffer);
333 pStubMsg->Buffer += 4;
334 TRACE("variance is %ld\n", pStubMsg->ActualCount);
336 done:
337 if (pStubMsg->fHasNewCorrDesc)
338 return pFormat+6;
339 else
340 return pFormat+4;
343 PFORMAT_STRING ComputeConformanceOrVariance(
344 MIDL_STUB_MESSAGE *pStubMsg, unsigned char *pMemory,
345 PFORMAT_STRING pFormat, ULONG_PTR def, ULONG *pCount)
347 BYTE dtype = pFormat[0] & 0xf;
348 short ofs = *(short *)&pFormat[2];
349 LPVOID ptr = NULL;
350 DWORD data = 0;
352 if (!IsConformanceOrVariancePresent(pFormat)) {
353 /* null descriptor */
354 *pCount = def;
355 goto finish_conf;
358 switch (pFormat[0] & 0xf0) {
359 case RPC_FC_NORMAL_CONFORMANCE:
360 TRACE("normal conformance, ofs=%d\n", ofs);
361 ptr = pMemory + ofs;
362 break;
363 case RPC_FC_POINTER_CONFORMANCE:
364 TRACE("pointer conformance, ofs=%d\n", ofs);
365 ptr = pStubMsg->Memory + ofs;
366 break;
367 case RPC_FC_TOP_LEVEL_CONFORMANCE:
368 TRACE("toplevel conformance, ofs=%d\n", ofs);
369 if (pStubMsg->StackTop) {
370 ptr = pStubMsg->StackTop + ofs;
372 else {
373 /* -Os mode, *pCount is already set */
374 goto finish_conf;
376 break;
377 case RPC_FC_CONSTANT_CONFORMANCE:
378 data = ofs | ((DWORD)pFormat[1] << 16);
379 TRACE("constant conformance, val=%ld\n", data);
380 *pCount = data;
381 goto finish_conf;
382 case RPC_FC_TOP_LEVEL_MULTID_CONFORMANCE:
383 FIXME("toplevel multidimensional conformance, ofs=%d\n", ofs);
384 if (pStubMsg->StackTop) {
385 ptr = pStubMsg->StackTop + ofs;
387 else {
388 /* ? */
389 goto done_conf_grab;
391 break;
392 default:
393 FIXME("unknown conformance type %x\n", pFormat[0] & 0xf0);
396 switch (pFormat[1]) {
397 case RPC_FC_DEREFERENCE:
398 ptr = *(LPVOID*)ptr;
399 break;
400 case RPC_FC_CALLBACK:
402 unsigned char *old_stack_top = pStubMsg->StackTop;
403 pStubMsg->StackTop = ptr;
405 /* ofs is index into StubDesc->apfnExprEval */
406 TRACE("callback conformance into apfnExprEval[%d]\n", ofs);
407 pStubMsg->StubDesc->apfnExprEval[ofs](pStubMsg);
409 pStubMsg->StackTop = old_stack_top;
410 goto finish_conf;
412 default:
413 break;
416 switch (dtype) {
417 case RPC_FC_LONG:
418 case RPC_FC_ULONG:
419 data = *(DWORD*)ptr;
420 break;
421 case RPC_FC_SHORT:
422 data = *(SHORT*)ptr;
423 break;
424 case RPC_FC_USHORT:
425 data = *(USHORT*)ptr;
426 break;
427 case RPC_FC_SMALL:
428 data = *(CHAR*)ptr;
429 break;
430 case RPC_FC_USMALL:
431 data = *(UCHAR*)ptr;
432 break;
433 default:
434 FIXME("unknown conformance data type %x\n", dtype);
435 goto done_conf_grab;
437 TRACE("dereferenced data type %x at %p, got %ld\n", dtype, ptr, data);
439 done_conf_grab:
440 switch (pFormat[1]) {
441 case 0: /* no op */
442 *pCount = data;
443 break;
444 case RPC_FC_DEREFERENCE:
445 /* already handled */
446 break;
447 default:
448 FIXME("unknown conformance op %d\n", pFormat[1]);
449 goto finish_conf;
452 finish_conf:
453 TRACE("resulting conformance is %ld\n", *pCount);
454 if (pStubMsg->fHasNewCorrDesc)
455 return pFormat+6;
456 else
457 return pFormat+4;
462 * NdrConformantString:
464 * What MS calls a ConformantString is, in DCE terminology,
465 * a Varying-Conformant String.
467 * maxlen: DWORD (max # of CHARTYPE characters, inclusive of '\0')
468 * offset: DWORD (actual string data begins at (offset) CHARTYPE's
469 * into unmarshalled string)
470 * length: DWORD (# of CHARTYPE characters, inclusive of '\0')
471 * [
472 * data: CHARTYPE[maxlen]
473 * ]
474 * ], where CHARTYPE is the appropriate character type (specified externally)
478 /***********************************************************************
479 * NdrConformantStringMarshall [RPCRT4.@]
481 unsigned char *WINAPI NdrConformantStringMarshall(MIDL_STUB_MESSAGE *pStubMsg,
482 unsigned char *pszMessage, PFORMAT_STRING pFormat)
484 unsigned long len, esize;
485 unsigned char *c;
487 TRACE("(pStubMsg == ^%p, pszMessage == ^%p, pFormat == ^%p)\n", pStubMsg, pszMessage, pFormat);
489 assert(pFormat);
490 if (*pFormat == RPC_FC_C_CSTRING) {
491 TRACE("string=%s\n", debugstr_a((char*)pszMessage));
492 len = strlen((char*)pszMessage)+1;
493 esize = 1;
495 else if (*pFormat == RPC_FC_C_WSTRING) {
496 TRACE("string=%s\n", debugstr_w((LPWSTR)pszMessage));
497 len = strlenW((LPWSTR)pszMessage)+1;
498 esize = 2;
500 else {
501 ERR("Unhandled string type: %#x\n", *pFormat);
502 /* FIXME: raise an exception. */
503 return NULL;
506 if (pFormat[1] != RPC_FC_PAD) {
507 FIXME("sized string format=%d\n", pFormat[1]);
510 assert( (pStubMsg->BufferLength >= (len*esize + 13)) && (pStubMsg->Buffer != NULL) );
512 c = pStubMsg->Buffer;
513 memset(c, 0, 12);
514 NDR_LOCAL_UINT32_WRITE(c, len); /* max length: strlen + 1 (for '\0') */
515 c += 8; /* offset: 0 */
516 NDR_LOCAL_UINT32_WRITE(c, len); /* actual length: (same) */
517 c += 4;
518 memcpy(c, pszMessage, len*esize); /* the string itself */
519 c += len*esize;
520 pStubMsg->Buffer = c;
522 STD_OVERFLOW_CHECK(pStubMsg);
524 /* success */
525 return NULL; /* is this always right? */
528 /***********************************************************************
529 * NdrConformantStringBufferSize [RPCRT4.@]
531 void WINAPI NdrConformantStringBufferSize(PMIDL_STUB_MESSAGE pStubMsg,
532 unsigned char* pMemory, PFORMAT_STRING pFormat)
534 TRACE("(pStubMsg == ^%p, pMemory == ^%p, pFormat == ^%p)\n", pStubMsg, pMemory, pFormat);
536 assert(pFormat);
537 if (*pFormat == RPC_FC_C_CSTRING) {
538 /* we need 12 octets for the [maxlen, offset, len] DWORDS, + 1 octet for '\0' */
539 TRACE("string=%s\n", debugstr_a((char*)pMemory));
540 pStubMsg->BufferLength += strlen((char*)pMemory) + 13 + BUFFER_PARANOIA;
542 else if (*pFormat == RPC_FC_C_WSTRING) {
543 /* we need 12 octets for the [maxlen, offset, len] DWORDS, + 2 octets for L'\0' */
544 TRACE("string=%s\n", debugstr_w((LPWSTR)pMemory));
545 pStubMsg->BufferLength += strlenW((LPWSTR)pMemory)*2 + 14 + BUFFER_PARANOIA;
547 else {
548 ERR("Unhandled string type: %#x\n", *pFormat);
549 /* FIXME: raise an exception */
552 if (pFormat[1] != RPC_FC_PAD) {
553 FIXME("sized string format=%d\n", pFormat[1]);
557 /************************************************************************
558 * NdrConformantStringMemorySize [RPCRT4.@]
560 unsigned long WINAPI NdrConformantStringMemorySize( PMIDL_STUB_MESSAGE pStubMsg,
561 PFORMAT_STRING pFormat )
563 unsigned long rslt = 0;
565 TRACE("(pStubMsg == ^%p, pFormat == ^%p)\n", pStubMsg, pFormat);
567 assert(pStubMsg && pFormat);
569 if (*pFormat == RPC_FC_C_CSTRING) {
570 rslt = NDR_LOCAL_UINT32_READ(pStubMsg->Buffer); /* maxlen */
572 else if (*pFormat == RPC_FC_C_WSTRING) {
573 rslt = NDR_LOCAL_UINT32_READ(pStubMsg->Buffer)*2; /* maxlen */
575 else {
576 ERR("Unhandled string type: %#x\n", *pFormat);
577 /* FIXME: raise an exception */
580 if (pFormat[1] != RPC_FC_PAD) {
581 FIXME("sized string format=%d\n", pFormat[1]);
584 TRACE(" --> %lu\n", rslt);
585 return rslt;
588 /************************************************************************
589 * NdrConformantStringUnmarshall [RPCRT4.@]
591 unsigned char *WINAPI NdrConformantStringUnmarshall( PMIDL_STUB_MESSAGE pStubMsg,
592 unsigned char** ppMemory, PFORMAT_STRING pFormat, unsigned char fMustAlloc )
594 unsigned long len, esize, ofs;
596 TRACE("(pStubMsg == ^%p, *pMemory == ^%p, pFormat == ^%p, fMustAlloc == %u)\n",
597 pStubMsg, *ppMemory, pFormat, fMustAlloc);
599 assert(pFormat && ppMemory && pStubMsg);
601 pStubMsg->Buffer += 4;
602 ofs = NDR_LOCAL_UINT32_READ(pStubMsg->Buffer);
603 pStubMsg->Buffer += 4;
604 len = NDR_LOCAL_UINT32_READ(pStubMsg->Buffer);
605 pStubMsg->Buffer += 4;
607 if (*pFormat == RPC_FC_C_CSTRING) esize = 1;
608 else if (*pFormat == RPC_FC_C_WSTRING) esize = 2;
609 else {
610 ERR("Unhandled string type: %#x\n", *pFormat);
611 /* FIXME: raise an exception */
612 esize = 0;
615 if (pFormat[1] != RPC_FC_PAD) {
616 FIXME("sized string format=%d\n", pFormat[1]);
619 if (fMustAlloc || !*ppMemory)
620 *ppMemory = NdrAllocate(pStubMsg, len*esize + BUFFER_PARANOIA);
622 memcpy(*ppMemory, pStubMsg->Buffer, len*esize);
624 pStubMsg->Buffer += len*esize;
626 if (*pFormat == RPC_FC_C_CSTRING) {
627 TRACE("string=%s\n", debugstr_a((char*)*ppMemory));
629 else if (*pFormat == RPC_FC_C_WSTRING) {
630 TRACE("string=%s\n", debugstr_w((LPWSTR)*ppMemory));
633 return NULL; /* FIXME: is this always right? */
636 /***********************************************************************
637 * NdrNonConformantStringMarshall [RPCRT4.@]
639 unsigned char * WINAPI NdrNonConformantStringMarshall(PMIDL_STUB_MESSAGE pStubMsg,
640 unsigned char *pMemory,
641 PFORMAT_STRING pFormat)
643 FIXME("stub\n");
644 return NULL;
647 /***********************************************************************
648 * NdrNonConformantStringUnmarshall [RPCRT4.@]
650 unsigned char * WINAPI NdrNonConformantStringUnmarshall(PMIDL_STUB_MESSAGE pStubMsg,
651 unsigned char **ppMemory,
652 PFORMAT_STRING pFormat,
653 unsigned char fMustAlloc)
655 FIXME("stub\n");
656 return NULL;
659 /***********************************************************************
660 * NdrNonConformantStringBufferSize [RPCRT4.@]
662 void WINAPI NdrNonConformantStringBufferSize(PMIDL_STUB_MESSAGE pStubMsg,
663 unsigned char *pMemory,
664 PFORMAT_STRING pFormat)
666 FIXME("stub\n");
669 /***********************************************************************
670 * NdrNonConformantStringMemorySize [RPCRT4.@]
672 unsigned long WINAPI NdrNonConformantStringMemorySize(PMIDL_STUB_MESSAGE pStubMsg,
673 PFORMAT_STRING pFormat)
675 FIXME("stub\n");
676 return 0;
679 static inline void dump_pointer_attr(unsigned char attr)
681 if (attr & RPC_FC_P_ALLOCALLNODES)
682 TRACE(" RPC_FC_P_ALLOCALLNODES");
683 if (attr & RPC_FC_P_DONTFREE)
684 TRACE(" RPC_FC_P_DONTFREE");
685 if (attr & RPC_FC_P_ONSTACK)
686 TRACE(" RPC_FC_P_ONSTACK");
687 if (attr & RPC_FC_P_SIMPLEPOINTER)
688 TRACE(" RPC_FC_P_SIMPLEPOINTER");
689 if (attr & RPC_FC_P_DEREF)
690 TRACE(" RPC_FC_P_DEREF");
691 TRACE("\n");
694 /***********************************************************************
695 * PointerMarshall
697 void WINAPI PointerMarshall(PMIDL_STUB_MESSAGE pStubMsg,
698 unsigned char *Buffer,
699 unsigned char *Pointer,
700 PFORMAT_STRING pFormat)
702 unsigned type = pFormat[0], attr = pFormat[1];
703 PFORMAT_STRING desc;
704 NDR_MARSHALL m;
706 TRACE("(%p,%p,%p,%p)\n", pStubMsg, Buffer, Pointer, pFormat);
707 TRACE("type=0x%x, attr=", type); dump_pointer_attr(attr);
708 pFormat += 2;
709 if (attr & RPC_FC_P_SIMPLEPOINTER) desc = pFormat;
710 else desc = pFormat + *(const SHORT*)pFormat;
711 if (attr & RPC_FC_P_DEREF) {
712 Pointer = *(unsigned char**)Pointer;
713 TRACE("deref => %p\n", Pointer);
716 switch (type) {
717 case RPC_FC_RP: /* ref pointer (always non-null) */
718 #if 0 /* this causes problems for InstallShield so is disabled - we need more tests */
719 if (!Pointer)
720 RpcRaiseException(RPC_X_NULL_REF_POINTER);
721 #endif
722 break;
723 case RPC_FC_UP: /* unique pointer */
724 case RPC_FC_OP: /* object pointer - same as unique here */
725 TRACE("writing %p to buffer\n", Pointer);
726 NDR_LOCAL_UINT32_WRITE(pStubMsg->Buffer, (unsigned long)Pointer);
727 pStubMsg->Buffer += 4;
728 break;
729 case RPC_FC_FP:
730 default:
731 FIXME("unhandled ptr type=%02x\n", type);
732 RpcRaiseException(RPC_X_BAD_STUB_DATA);
735 TRACE("calling marshaller for type 0x%x\n", (int)*desc);
737 if (Pointer) {
738 m = NdrMarshaller[*desc & NDR_TABLE_MASK];
739 if (m) m(pStubMsg, Pointer, desc);
740 else FIXME("no marshaller for data type=%02x\n", *desc);
743 STD_OVERFLOW_CHECK(pStubMsg);
746 /***********************************************************************
747 * PointerUnmarshall
749 void WINAPI PointerUnmarshall(PMIDL_STUB_MESSAGE pStubMsg,
750 unsigned char *Buffer,
751 unsigned char **pPointer,
752 PFORMAT_STRING pFormat,
753 unsigned char fMustAlloc)
755 unsigned type = pFormat[0], attr = pFormat[1];
756 PFORMAT_STRING desc;
757 NDR_UNMARSHALL m;
758 DWORD pointer_id = 0;
760 TRACE("(%p,%p,%p,%p,%d)\n", pStubMsg, Buffer, pPointer, pFormat, fMustAlloc);
761 TRACE("type=0x%x, attr=", type); dump_pointer_attr(attr);
762 pFormat += 2;
763 if (attr & RPC_FC_P_SIMPLEPOINTER) desc = pFormat;
764 else desc = pFormat + *(const SHORT*)pFormat;
765 if (attr & RPC_FC_P_DEREF) {
766 pPointer = *(unsigned char***)pPointer;
767 TRACE("deref => %p\n", pPointer);
770 switch (type) {
771 case RPC_FC_RP: /* ref pointer (always non-null) */
772 pointer_id = ~0UL;
773 break;
774 case RPC_FC_UP: /* unique pointer */
775 pointer_id = NDR_LOCAL_UINT32_READ(pStubMsg->Buffer);
776 pStubMsg->Buffer += 4;
777 break;
778 case RPC_FC_OP: /* object pointer - we must free data before overwriting it */
779 pointer_id = NDR_LOCAL_UINT32_READ(pStubMsg->Buffer);
780 pStubMsg->Buffer += 4;
781 if (*pPointer)
782 FIXME("free object pointer %p\n", *pPointer);
783 break;
784 case RPC_FC_FP:
785 default:
786 FIXME("unhandled ptr type=%02x\n", type);
787 RpcRaiseException(RPC_X_BAD_STUB_DATA);
790 if (pointer_id) {
791 m = NdrUnmarshaller[*desc & NDR_TABLE_MASK];
792 if (m) m(pStubMsg, pPointer, desc, fMustAlloc);
793 else FIXME("no unmarshaller for data type=%02x\n", *desc);
796 TRACE("pointer=%p\n", *pPointer);
799 /***********************************************************************
800 * PointerBufferSize
802 void WINAPI PointerBufferSize(PMIDL_STUB_MESSAGE pStubMsg,
803 unsigned char *Pointer,
804 PFORMAT_STRING pFormat)
806 unsigned type = pFormat[0], attr = pFormat[1];
807 PFORMAT_STRING desc;
808 NDR_BUFFERSIZE m;
810 TRACE("(%p,%p,%p)\n", pStubMsg, Pointer, pFormat);
811 TRACE("type=%d, attr=%d\n", type, attr);
812 pFormat += 2;
813 if (attr & RPC_FC_P_SIMPLEPOINTER) desc = pFormat;
814 else desc = pFormat + *(const SHORT*)pFormat;
815 if (attr & RPC_FC_P_DEREF) {
816 Pointer = *(unsigned char**)Pointer;
817 TRACE("deref => %p\n", Pointer);
820 switch (type) {
821 case RPC_FC_RP: /* ref pointer (always non-null) */
822 break;
823 case RPC_FC_OP:
824 case RPC_FC_UP:
825 pStubMsg->BufferLength += 4;
826 /* NULL pointer has no further representation */
827 if (!Pointer)
828 return;
829 break;
830 case RPC_FC_FP:
831 default:
832 FIXME("unhandled ptr type=%02x\n", type);
833 RpcRaiseException(RPC_X_BAD_STUB_DATA);
836 m = NdrBufferSizer[*desc & NDR_TABLE_MASK];
837 if (m) m(pStubMsg, Pointer, desc);
838 else FIXME("no buffersizer for data type=%02x\n", *desc);
841 /***********************************************************************
842 * PointerMemorySize [RPCRT4.@]
844 unsigned long WINAPI PointerMemorySize(PMIDL_STUB_MESSAGE pStubMsg,
845 unsigned char *Buffer,
846 PFORMAT_STRING pFormat)
848 unsigned type = pFormat[0], attr = pFormat[1];
849 PFORMAT_STRING desc;
850 NDR_MEMORYSIZE m;
852 FIXME("(%p,%p,%p): stub\n", pStubMsg, Buffer, pFormat);
853 TRACE("type=%d, attr=", type); dump_pointer_attr(attr);
854 pFormat += 2;
855 if (attr & RPC_FC_P_SIMPLEPOINTER) desc = pFormat;
856 else desc = pFormat + *(const SHORT*)pFormat;
857 if (attr & RPC_FC_P_DEREF) {
858 TRACE("deref\n");
861 switch (type) {
862 case RPC_FC_RP: /* ref pointer (always non-null) */
863 break;
864 default:
865 FIXME("unhandled ptr type=%02x\n", type);
866 RpcRaiseException(RPC_X_BAD_STUB_DATA);
869 m = NdrMemorySizer[*desc & NDR_TABLE_MASK];
870 if (m) m(pStubMsg, desc);
871 else FIXME("no memorysizer for data type=%02x\n", *desc);
873 return 0;
876 /***********************************************************************
877 * PointerFree [RPCRT4.@]
879 void WINAPI PointerFree(PMIDL_STUB_MESSAGE pStubMsg,
880 unsigned char *Pointer,
881 PFORMAT_STRING pFormat)
883 unsigned type = pFormat[0], attr = pFormat[1];
884 PFORMAT_STRING desc;
885 NDR_FREE m;
887 TRACE("(%p,%p,%p)\n", pStubMsg, Pointer, pFormat);
888 TRACE("type=%d, attr=", type); dump_pointer_attr(attr);
889 if (attr & RPC_FC_P_DONTFREE) return;
890 pFormat += 2;
891 if (attr & RPC_FC_P_SIMPLEPOINTER) desc = pFormat;
892 else desc = pFormat + *(const SHORT*)pFormat;
893 if (attr & RPC_FC_P_DEREF) {
894 Pointer = *(unsigned char**)Pointer;
895 TRACE("deref => %p\n", Pointer);
898 if (!Pointer) return;
900 m = NdrFreer[*desc & NDR_TABLE_MASK];
901 if (m) m(pStubMsg, Pointer, desc);
903 /* hmm... is this sensible?
904 * perhaps we should check if the memory comes from NdrAllocate,
905 * and deallocate only if so - checking if the pointer is between
906 * BufferStart and BufferEnd is probably no good since the buffer
907 * may be reallocated when the server wants to marshal the reply */
908 switch (*desc) {
909 case RPC_FC_BOGUS_STRUCT:
910 case RPC_FC_BOGUS_ARRAY:
911 case RPC_FC_USER_MARSHAL:
912 break;
913 default:
914 FIXME("unhandled data type=%02x\n", *desc);
915 case RPC_FC_CARRAY:
916 case RPC_FC_C_CSTRING:
917 case RPC_FC_C_WSTRING:
918 if (pStubMsg->ReuseBuffer) goto notfree;
919 break;
920 case RPC_FC_IP:
921 goto notfree;
924 if (attr & RPC_FC_P_ONSTACK) {
925 TRACE("not freeing stack ptr %p\n", Pointer);
926 return;
928 TRACE("freeing %p\n", Pointer);
929 NdrFree(pStubMsg, Pointer);
930 return;
931 notfree:
932 TRACE("not freeing %p\n", Pointer);
935 /***********************************************************************
936 * EmbeddedPointerMarshall
938 unsigned char * WINAPI EmbeddedPointerMarshall(PMIDL_STUB_MESSAGE pStubMsg,
939 unsigned char *pMemory,
940 PFORMAT_STRING pFormat)
942 unsigned char *Mark = pStubMsg->BufferMark;
943 unsigned long Offset = pStubMsg->Offset;
944 unsigned ofs, rep, count, stride, xofs;
946 TRACE("(%p,%p,%p)\n", pStubMsg, pMemory, pFormat);
948 if (*pFormat != RPC_FC_PP) return NULL;
949 pFormat += 2;
951 while (pFormat[0] != RPC_FC_END) {
952 switch (pFormat[0]) {
953 default:
954 FIXME("unknown repeat type %d\n", pFormat[0]);
955 case RPC_FC_NO_REPEAT:
956 rep = 1;
957 stride = 0;
958 ofs = 0;
959 count = 1;
960 xofs = 0;
961 pFormat += 2;
962 break;
963 case RPC_FC_FIXED_REPEAT:
964 rep = *(const WORD*)&pFormat[2];
965 stride = *(const WORD*)&pFormat[4];
966 ofs = *(const WORD*)&pFormat[6];
967 count = *(const WORD*)&pFormat[8];
968 xofs = 0;
969 pFormat += 10;
970 break;
971 case RPC_FC_VARIABLE_REPEAT:
972 rep = pStubMsg->MaxCount;
973 stride = *(const WORD*)&pFormat[2];
974 ofs = *(const WORD*)&pFormat[4];
975 count = *(const WORD*)&pFormat[6];
976 xofs = (pFormat[1] == RPC_FC_VARIABLE_OFFSET) ? Offset * stride : 0;
977 pFormat += 8;
978 break;
980 /* ofs doesn't seem to matter in this context */
981 while (rep) {
982 PFORMAT_STRING info = pFormat;
983 unsigned char *membase = pMemory + xofs;
984 unsigned u;
985 for (u=0; u<count; u++,info+=8) {
986 unsigned char *memptr = membase + *(const SHORT*)&info[0];
987 unsigned char *bufptr = Mark + *(const SHORT*)&info[2];
988 PointerMarshall(pStubMsg, bufptr, *(unsigned char**)memptr, info+4);
990 rep--;
992 pFormat += 8 * count;
995 STD_OVERFLOW_CHECK(pStubMsg);
997 return NULL;
1000 /***********************************************************************
1001 * EmbeddedPointerUnmarshall
1003 unsigned char * WINAPI EmbeddedPointerUnmarshall(PMIDL_STUB_MESSAGE pStubMsg,
1004 unsigned char **ppMemory,
1005 PFORMAT_STRING pFormat,
1006 unsigned char fMustAlloc)
1008 unsigned char *Mark = pStubMsg->BufferMark;
1009 unsigned long Offset = pStubMsg->Offset;
1010 unsigned ofs, rep, count, stride, xofs;
1012 TRACE("(%p,%p,%p,%d)\n", pStubMsg, ppMemory, pFormat, fMustAlloc);
1014 if (*pFormat != RPC_FC_PP) return NULL;
1015 pFormat += 2;
1017 while (pFormat[0] != RPC_FC_END) {
1018 switch (pFormat[0]) {
1019 default:
1020 FIXME("unknown repeat type %d\n", pFormat[0]);
1021 case RPC_FC_NO_REPEAT:
1022 rep = 1;
1023 stride = 0;
1024 ofs = 0;
1025 count = 1;
1026 xofs = 0;
1027 pFormat += 2;
1028 break;
1029 case RPC_FC_FIXED_REPEAT:
1030 rep = *(const WORD*)&pFormat[2];
1031 stride = *(const WORD*)&pFormat[4];
1032 ofs = *(const WORD*)&pFormat[6];
1033 count = *(const WORD*)&pFormat[8];
1034 xofs = 0;
1035 pFormat += 10;
1036 break;
1037 case RPC_FC_VARIABLE_REPEAT:
1038 rep = pStubMsg->MaxCount;
1039 stride = *(const WORD*)&pFormat[2];
1040 ofs = *(const WORD*)&pFormat[4];
1041 count = *(const WORD*)&pFormat[6];
1042 xofs = (pFormat[1] == RPC_FC_VARIABLE_OFFSET) ? Offset * stride : 0;
1043 pFormat += 8;
1044 break;
1046 /* ofs doesn't seem to matter in this context */
1047 while (rep) {
1048 PFORMAT_STRING info = pFormat;
1049 unsigned char *membase = *ppMemory + xofs;
1050 unsigned u;
1051 for (u=0; u<count; u++,info+=8) {
1052 unsigned char *memptr = membase + *(const SHORT*)&info[0];
1053 unsigned char *bufptr = Mark + *(const SHORT*)&info[2];
1054 PointerUnmarshall(pStubMsg, bufptr, (unsigned char**)memptr, info+4, fMustAlloc);
1056 rep--;
1058 pFormat += 8 * count;
1061 return NULL;
1064 /***********************************************************************
1065 * EmbeddedPointerBufferSize
1067 void WINAPI EmbeddedPointerBufferSize(PMIDL_STUB_MESSAGE pStubMsg,
1068 unsigned char *pMemory,
1069 PFORMAT_STRING pFormat)
1071 unsigned long Offset = pStubMsg->Offset;
1072 unsigned ofs, rep, count, stride, xofs;
1074 TRACE("(%p,%p,%p)\n", pStubMsg, pMemory, pFormat);
1075 if (*pFormat != RPC_FC_PP) return;
1076 pFormat += 2;
1078 while (pFormat[0] != RPC_FC_END) {
1079 switch (pFormat[0]) {
1080 default:
1081 FIXME("unknown repeat type %d\n", pFormat[0]);
1082 case RPC_FC_NO_REPEAT:
1083 rep = 1;
1084 stride = 0;
1085 ofs = 0;
1086 count = 1;
1087 xofs = 0;
1088 pFormat += 2;
1089 break;
1090 case RPC_FC_FIXED_REPEAT:
1091 rep = *(const WORD*)&pFormat[2];
1092 stride = *(const WORD*)&pFormat[4];
1093 ofs = *(const WORD*)&pFormat[6];
1094 count = *(const WORD*)&pFormat[8];
1095 xofs = 0;
1096 pFormat += 10;
1097 break;
1098 case RPC_FC_VARIABLE_REPEAT:
1099 rep = pStubMsg->MaxCount;
1100 stride = *(const WORD*)&pFormat[2];
1101 ofs = *(const WORD*)&pFormat[4];
1102 count = *(const WORD*)&pFormat[6];
1103 xofs = (pFormat[1] == RPC_FC_VARIABLE_OFFSET) ? Offset * stride : 0;
1104 pFormat += 8;
1105 break;
1107 /* ofs doesn't seem to matter in this context */
1108 while (rep) {
1109 PFORMAT_STRING info = pFormat;
1110 unsigned char *membase = pMemory + xofs;
1111 unsigned u;
1112 for (u=0; u<count; u++,info+=8) {
1113 unsigned char *memptr = membase + *(const SHORT*)&info[0];
1114 PointerBufferSize(pStubMsg, *(unsigned char**)memptr, info+4);
1116 rep--;
1118 pFormat += 8 * count;
1122 /***********************************************************************
1123 * EmbeddedPointerMemorySize
1125 unsigned long WINAPI EmbeddedPointerMemorySize(PMIDL_STUB_MESSAGE pStubMsg,
1126 PFORMAT_STRING pFormat)
1128 unsigned long Offset = pStubMsg->Offset;
1129 unsigned char *Mark = pStubMsg->BufferMark;
1130 unsigned ofs, rep, count, stride, xofs;
1132 FIXME("(%p,%p): stub\n", pStubMsg, pFormat);
1133 if (*pFormat != RPC_FC_PP) return 0;
1134 pFormat += 2;
1136 while (pFormat[0] != RPC_FC_END) {
1137 switch (pFormat[0]) {
1138 default:
1139 FIXME("unknown repeat type %d\n", pFormat[0]);
1140 case RPC_FC_NO_REPEAT:
1141 rep = 1;
1142 stride = 0;
1143 ofs = 0;
1144 count = 1;
1145 xofs = 0;
1146 pFormat += 2;
1147 break;
1148 case RPC_FC_FIXED_REPEAT:
1149 rep = *(const WORD*)&pFormat[2];
1150 stride = *(const WORD*)&pFormat[4];
1151 ofs = *(const WORD*)&pFormat[6];
1152 count = *(const WORD*)&pFormat[8];
1153 xofs = 0;
1154 pFormat += 10;
1155 break;
1156 case RPC_FC_VARIABLE_REPEAT:
1157 rep = pStubMsg->MaxCount;
1158 stride = *(const WORD*)&pFormat[2];
1159 ofs = *(const WORD*)&pFormat[4];
1160 count = *(const WORD*)&pFormat[6];
1161 xofs = (pFormat[1] == RPC_FC_VARIABLE_OFFSET) ? Offset * stride : 0;
1162 pFormat += 8;
1163 break;
1165 /* ofs doesn't seem to matter in this context */
1166 while (rep) {
1167 PFORMAT_STRING info = pFormat;
1168 unsigned u;
1169 for (u=0; u<count; u++,info+=8) {
1170 unsigned char *bufptr = Mark + *(const SHORT*)&info[2];
1171 PointerMemorySize(pStubMsg, bufptr, info+4);
1173 rep--;
1175 pFormat += 8 * count;
1178 return 0;
1181 /***********************************************************************
1182 * EmbeddedPointerFree
1184 void WINAPI EmbeddedPointerFree(PMIDL_STUB_MESSAGE pStubMsg,
1185 unsigned char *pMemory,
1186 PFORMAT_STRING pFormat)
1188 unsigned long Offset = pStubMsg->Offset;
1189 unsigned ofs, rep, count, stride, xofs;
1191 TRACE("(%p,%p,%p)\n", pStubMsg, pMemory, pFormat);
1192 if (*pFormat != RPC_FC_PP) return;
1193 pFormat += 2;
1195 while (pFormat[0] != RPC_FC_END) {
1196 switch (pFormat[0]) {
1197 default:
1198 FIXME("unknown repeat type %d\n", pFormat[0]);
1199 case RPC_FC_NO_REPEAT:
1200 rep = 1;
1201 stride = 0;
1202 ofs = 0;
1203 count = 1;
1204 xofs = 0;
1205 pFormat += 2;
1206 break;
1207 case RPC_FC_FIXED_REPEAT:
1208 rep = *(const WORD*)&pFormat[2];
1209 stride = *(const WORD*)&pFormat[4];
1210 ofs = *(const WORD*)&pFormat[6];
1211 count = *(const WORD*)&pFormat[8];
1212 xofs = 0;
1213 pFormat += 10;
1214 break;
1215 case RPC_FC_VARIABLE_REPEAT:
1216 rep = pStubMsg->MaxCount;
1217 stride = *(const WORD*)&pFormat[2];
1218 ofs = *(const WORD*)&pFormat[4];
1219 count = *(const WORD*)&pFormat[6];
1220 xofs = (pFormat[1] == RPC_FC_VARIABLE_OFFSET) ? Offset * stride : 0;
1221 pFormat += 8;
1222 break;
1224 /* ofs doesn't seem to matter in this context */
1225 while (rep) {
1226 PFORMAT_STRING info = pFormat;
1227 unsigned char *membase = pMemory + xofs;
1228 unsigned u;
1229 for (u=0; u<count; u++,info+=8) {
1230 unsigned char *memptr = membase + *(const SHORT*)&info[0];
1231 PointerFree(pStubMsg, *(unsigned char**)memptr, info+4);
1233 rep--;
1235 pFormat += 8 * count;
1239 /***********************************************************************
1240 * NdrPointerMarshall [RPCRT4.@]
1242 unsigned char * WINAPI NdrPointerMarshall(PMIDL_STUB_MESSAGE pStubMsg,
1243 unsigned char *pMemory,
1244 PFORMAT_STRING pFormat)
1246 TRACE("(%p,%p,%p)\n", pStubMsg, pMemory, pFormat);
1248 pStubMsg->BufferMark = pStubMsg->Buffer;
1249 PointerMarshall(pStubMsg, pStubMsg->Buffer, pMemory, pFormat);
1251 STD_OVERFLOW_CHECK(pStubMsg);
1253 return NULL;
1256 /***********************************************************************
1257 * NdrPointerUnmarshall [RPCRT4.@]
1259 unsigned char * WINAPI NdrPointerUnmarshall(PMIDL_STUB_MESSAGE pStubMsg,
1260 unsigned char **ppMemory,
1261 PFORMAT_STRING pFormat,
1262 unsigned char fMustAlloc)
1264 TRACE("(%p,%p,%p,%d)\n", pStubMsg, ppMemory, pFormat, fMustAlloc);
1266 pStubMsg->BufferMark = pStubMsg->Buffer;
1267 PointerUnmarshall(pStubMsg, pStubMsg->Buffer, ppMemory, pFormat, fMustAlloc);
1269 return NULL;
1272 /***********************************************************************
1273 * NdrPointerBufferSize [RPCRT4.@]
1275 void WINAPI NdrPointerBufferSize(PMIDL_STUB_MESSAGE pStubMsg,
1276 unsigned char *pMemory,
1277 PFORMAT_STRING pFormat)
1279 TRACE("(%p,%p,%p)\n", pStubMsg, pMemory, pFormat);
1280 PointerBufferSize(pStubMsg, pMemory, pFormat);
1283 /***********************************************************************
1284 * NdrPointerMemorySize [RPCRT4.@]
1286 unsigned long WINAPI NdrPointerMemorySize(PMIDL_STUB_MESSAGE pStubMsg,
1287 PFORMAT_STRING pFormat)
1289 /* unsigned size = *(LPWORD)(pFormat+2); */
1290 FIXME("(%p,%p): stub\n", pStubMsg, pFormat);
1291 PointerMemorySize(pStubMsg, pStubMsg->Buffer, pFormat);
1292 return 0;
1295 /***********************************************************************
1296 * NdrPointerFree [RPCRT4.@]
1298 void WINAPI NdrPointerFree(PMIDL_STUB_MESSAGE pStubMsg,
1299 unsigned char *pMemory,
1300 PFORMAT_STRING pFormat)
1302 TRACE("(%p,%p,%p)\n", pStubMsg, pMemory, pFormat);
1303 PointerFree(pStubMsg, pMemory, pFormat);
1306 /***********************************************************************
1307 * NdrSimpleStructMarshall [RPCRT4.@]
1309 unsigned char * WINAPI NdrSimpleStructMarshall(PMIDL_STUB_MESSAGE pStubMsg,
1310 unsigned char *pMemory,
1311 PFORMAT_STRING pFormat)
1313 unsigned size = *(const WORD*)(pFormat+2);
1314 TRACE("(%p,%p,%p)\n", pStubMsg, pMemory, pFormat);
1316 memcpy(pStubMsg->Buffer, pMemory, size);
1317 pStubMsg->BufferMark = pStubMsg->Buffer;
1318 pStubMsg->Buffer += size;
1320 if (pFormat[0] != RPC_FC_STRUCT)
1321 EmbeddedPointerMarshall(pStubMsg, pMemory, pFormat+4);
1323 STD_OVERFLOW_CHECK(pStubMsg);
1325 return NULL;
1328 /***********************************************************************
1329 * NdrSimpleStructUnmarshall [RPCRT4.@]
1331 unsigned char * WINAPI NdrSimpleStructUnmarshall(PMIDL_STUB_MESSAGE pStubMsg,
1332 unsigned char **ppMemory,
1333 PFORMAT_STRING pFormat,
1334 unsigned char fMustAlloc)
1336 unsigned size = *(const WORD*)(pFormat+2);
1337 TRACE("(%p,%p,%p,%d)\n", pStubMsg, ppMemory, pFormat, fMustAlloc);
1339 if (fMustAlloc) {
1340 *ppMemory = NdrAllocate(pStubMsg, size);
1341 memcpy(*ppMemory, pStubMsg->Buffer, size);
1342 } else {
1343 if (pStubMsg->ReuseBuffer && !*ppMemory)
1344 /* for servers, we may just point straight into the RPC buffer, I think
1345 * (I guess that's what MS does since MIDL code doesn't try to free) */
1346 *ppMemory = pStubMsg->Buffer;
1347 else
1348 /* for clients, memory should be provided by caller */
1349 memcpy(*ppMemory, pStubMsg->Buffer, size);
1352 pStubMsg->BufferMark = pStubMsg->Buffer;
1353 pStubMsg->Buffer += size;
1355 if (pFormat[0] != RPC_FC_STRUCT)
1356 EmbeddedPointerUnmarshall(pStubMsg, ppMemory, pFormat+4, fMustAlloc);
1358 return NULL;
1362 /***********************************************************************
1363 * NdrSimpleStructUnmarshall [RPCRT4.@]
1365 void WINAPI NdrSimpleTypeMarshall( PMIDL_STUB_MESSAGE pStubMsg, unsigned char* pMemory,
1366 unsigned char FormatChar )
1368 FIXME("stub\n");
1372 /***********************************************************************
1373 * NdrSimpleStructUnmarshall [RPCRT4.@]
1375 void WINAPI NdrSimpleTypeUnmarshall( PMIDL_STUB_MESSAGE pStubMsg, unsigned char* pMemory,
1376 unsigned char FormatChar )
1378 FIXME("stub\n");
1382 /***********************************************************************
1383 * NdrSimpleStructBufferSize [RPCRT4.@]
1385 void WINAPI NdrSimpleStructBufferSize(PMIDL_STUB_MESSAGE pStubMsg,
1386 unsigned char *pMemory,
1387 PFORMAT_STRING pFormat)
1389 unsigned size = *(const WORD*)(pFormat+2);
1390 TRACE("(%p,%p,%p)\n", pStubMsg, pMemory, pFormat);
1391 pStubMsg->BufferLength += size;
1392 if (pFormat[0] != RPC_FC_STRUCT)
1393 EmbeddedPointerBufferSize(pStubMsg, pMemory, pFormat+4);
1396 /***********************************************************************
1397 * NdrSimpleStructMemorySize [RPCRT4.@]
1399 unsigned long WINAPI NdrSimpleStructMemorySize(PMIDL_STUB_MESSAGE pStubMsg,
1400 PFORMAT_STRING pFormat)
1402 /* unsigned size = *(LPWORD)(pFormat+2); */
1403 FIXME("(%p,%p): stub\n", pStubMsg, pFormat);
1404 if (pFormat[0] != RPC_FC_STRUCT)
1405 EmbeddedPointerMemorySize(pStubMsg, pFormat+4);
1406 return 0;
1409 /***********************************************************************
1410 * NdrSimpleStructFree [RPCRT4.@]
1412 void WINAPI NdrSimpleStructFree(PMIDL_STUB_MESSAGE pStubMsg,
1413 unsigned char *pMemory,
1414 PFORMAT_STRING pFormat)
1416 TRACE("(%p,%p,%p)\n", pStubMsg, pMemory, pFormat);
1417 if (pFormat[0] != RPC_FC_STRUCT)
1418 EmbeddedPointerFree(pStubMsg, pMemory, pFormat+4);
1422 unsigned long WINAPI EmbeddedComplexSize(PMIDL_STUB_MESSAGE pStubMsg,
1423 PFORMAT_STRING pFormat)
1425 switch (*pFormat) {
1426 case RPC_FC_STRUCT:
1427 case RPC_FC_PSTRUCT:
1428 case RPC_FC_CSTRUCT:
1429 case RPC_FC_BOGUS_STRUCT:
1430 return *(const WORD*)&pFormat[2];
1431 case RPC_FC_USER_MARSHAL:
1432 return *(const WORD*)&pFormat[4];
1433 default:
1434 FIXME("unhandled embedded type %02x\n", *pFormat);
1436 return 0;
1440 unsigned char * WINAPI ComplexMarshall(PMIDL_STUB_MESSAGE pStubMsg,
1441 unsigned char *pMemory,
1442 PFORMAT_STRING pFormat,
1443 PFORMAT_STRING pPointer)
1445 PFORMAT_STRING desc;
1446 NDR_MARSHALL m;
1447 unsigned long size;
1449 while (*pFormat != RPC_FC_END) {
1450 switch (*pFormat) {
1451 case RPC_FC_SHORT:
1452 case RPC_FC_USHORT:
1453 TRACE("short=%d <= %p\n", *(WORD*)pMemory, pMemory);
1454 memcpy(pStubMsg->Buffer, pMemory, 2);
1455 pStubMsg->Buffer += 2;
1456 pMemory += 2;
1457 break;
1458 case RPC_FC_LONG:
1459 case RPC_FC_ULONG:
1460 case RPC_FC_ENUM32:
1461 TRACE("long=%ld <= %p\n", *(DWORD*)pMemory, pMemory);
1462 memcpy(pStubMsg->Buffer, pMemory, 4);
1463 pStubMsg->Buffer += 4;
1464 pMemory += 4;
1465 break;
1466 case RPC_FC_POINTER:
1467 TRACE("pointer=%p <= %p\n", *(unsigned char**)pMemory, pMemory);
1468 NdrPointerMarshall(pStubMsg, *(unsigned char**)pMemory, pPointer);
1469 pPointer += 4;
1470 pMemory += 4;
1471 break;
1472 case RPC_FC_ALIGNM4:
1473 ALIGN_POINTER(pMemory, 3);
1474 break;
1475 case RPC_FC_ALIGNM8:
1476 ALIGN_POINTER(pMemory, 7);
1477 break;
1478 case RPC_FC_STRUCTPAD2:
1479 pMemory += 2;
1480 break;
1481 case RPC_FC_EMBEDDED_COMPLEX:
1482 pMemory += pFormat[1];
1483 pFormat += 2;
1484 desc = pFormat + *(const SHORT*)pFormat;
1485 size = EmbeddedComplexSize(pStubMsg, desc);
1486 TRACE("embedded complex (size=%ld) <= %p\n", size, pMemory);
1487 m = NdrMarshaller[*desc & NDR_TABLE_MASK];
1488 if (m) m(pStubMsg, pMemory, desc);
1489 else FIXME("no marshaller for embedded type %02x\n", *desc);
1490 pMemory += size;
1491 pFormat += 2;
1492 continue;
1493 case RPC_FC_PAD:
1494 break;
1495 default:
1496 FIXME("unhandled format %02x\n", *pFormat);
1498 pFormat++;
1501 return pMemory;
1504 unsigned char * WINAPI ComplexUnmarshall(PMIDL_STUB_MESSAGE pStubMsg,
1505 unsigned char *pMemory,
1506 PFORMAT_STRING pFormat,
1507 PFORMAT_STRING pPointer,
1508 unsigned char fMustAlloc)
1510 PFORMAT_STRING desc;
1511 NDR_UNMARSHALL m;
1512 unsigned long size;
1514 while (*pFormat != RPC_FC_END) {
1515 switch (*pFormat) {
1516 case RPC_FC_SHORT:
1517 case RPC_FC_USHORT:
1518 memcpy(pMemory, pStubMsg->Buffer, 2);
1519 TRACE("short=%d => %p\n", *(WORD*)pMemory, pMemory);
1520 pStubMsg->Buffer += 2;
1521 pMemory += 2;
1522 break;
1523 case RPC_FC_LONG:
1524 case RPC_FC_ULONG:
1525 case RPC_FC_ENUM32:
1526 memcpy(pMemory, pStubMsg->Buffer, 4);
1527 TRACE("long=%ld => %p\n", *(DWORD*)pMemory, pMemory);
1528 pStubMsg->Buffer += 4;
1529 pMemory += 4;
1530 break;
1531 case RPC_FC_POINTER:
1532 *(unsigned char**)pMemory = NULL;
1533 TRACE("pointer => %p\n", pMemory);
1534 NdrPointerUnmarshall(pStubMsg, (unsigned char**)pMemory, pPointer, fMustAlloc);
1535 pPointer += 4;
1536 pMemory += 4;
1537 break;
1538 case RPC_FC_ALIGNM4:
1539 ALIGN_POINTER(pMemory, 3);
1540 break;
1541 case RPC_FC_ALIGNM8:
1542 ALIGN_POINTER(pMemory, 7);
1543 break;
1544 case RPC_FC_STRUCTPAD2:
1545 pMemory += 2;
1546 break;
1547 case RPC_FC_EMBEDDED_COMPLEX:
1548 pMemory += pFormat[1];
1549 pFormat += 2;
1550 desc = pFormat + *(const SHORT*)pFormat;
1551 size = EmbeddedComplexSize(pStubMsg, desc);
1552 TRACE("embedded complex (size=%ld) => %p\n", size, pMemory);
1553 m = NdrUnmarshaller[*desc & NDR_TABLE_MASK];
1554 memset(pMemory, 0, size); /* just in case */
1555 if (m) m(pStubMsg, &pMemory, desc, fMustAlloc);
1556 else FIXME("no unmarshaller for embedded type %02x\n", *desc);
1557 pMemory += size;
1558 pFormat += 2;
1559 continue;
1560 case RPC_FC_PAD:
1561 break;
1562 default:
1563 FIXME("unhandled format %d\n", *pFormat);
1565 pFormat++;
1568 return pMemory;
1571 unsigned char * WINAPI ComplexBufferSize(PMIDL_STUB_MESSAGE pStubMsg,
1572 unsigned char *pMemory,
1573 PFORMAT_STRING pFormat,
1574 PFORMAT_STRING pPointer)
1576 PFORMAT_STRING desc;
1577 NDR_BUFFERSIZE m;
1578 unsigned long size;
1580 while (*pFormat != RPC_FC_END) {
1581 switch (*pFormat) {
1582 case RPC_FC_SHORT:
1583 case RPC_FC_USHORT:
1584 pStubMsg->BufferLength += 2;
1585 pMemory += 2;
1586 break;
1587 case RPC_FC_LONG:
1588 case RPC_FC_ULONG:
1589 case RPC_FC_ENUM32:
1590 pStubMsg->BufferLength += 4;
1591 pMemory += 4;
1592 break;
1593 case RPC_FC_POINTER:
1594 NdrPointerBufferSize(pStubMsg, *(unsigned char**)pMemory, pPointer);
1595 pPointer += 4;
1596 pMemory += 4;
1597 break;
1598 case RPC_FC_ALIGNM4:
1599 ALIGN_POINTER(pMemory, 3);
1600 break;
1601 case RPC_FC_ALIGNM8:
1602 ALIGN_POINTER(pMemory, 7);
1603 break;
1604 case RPC_FC_STRUCTPAD2:
1605 pMemory += 2;
1606 break;
1607 case RPC_FC_EMBEDDED_COMPLEX:
1608 pMemory += pFormat[1];
1609 pFormat += 2;
1610 desc = pFormat + *(const SHORT*)pFormat;
1611 size = EmbeddedComplexSize(pStubMsg, desc);
1612 m = NdrBufferSizer[*desc & NDR_TABLE_MASK];
1613 if (m) m(pStubMsg, pMemory, desc);
1614 else FIXME("no buffersizer for embedded type %02x\n", *desc);
1615 pMemory += size;
1616 pFormat += 2;
1617 continue;
1618 case RPC_FC_PAD:
1619 break;
1620 default:
1621 FIXME("unhandled format %d\n", *pFormat);
1623 pFormat++;
1626 return pMemory;
1629 unsigned char * WINAPI ComplexFree(PMIDL_STUB_MESSAGE pStubMsg,
1630 unsigned char *pMemory,
1631 PFORMAT_STRING pFormat,
1632 PFORMAT_STRING pPointer)
1634 PFORMAT_STRING desc;
1635 NDR_FREE m;
1636 unsigned long size;
1638 while (*pFormat != RPC_FC_END) {
1639 switch (*pFormat) {
1640 case RPC_FC_SHORT:
1641 case RPC_FC_USHORT:
1642 pMemory += 2;
1643 break;
1644 case RPC_FC_LONG:
1645 case RPC_FC_ULONG:
1646 case RPC_FC_ENUM32:
1647 pMemory += 4;
1648 break;
1649 case RPC_FC_POINTER:
1650 NdrPointerFree(pStubMsg, *(unsigned char**)pMemory, pPointer);
1651 pPointer += 4;
1652 pMemory += 4;
1653 break;
1654 case RPC_FC_ALIGNM4:
1655 ALIGN_POINTER(pMemory, 3);
1656 break;
1657 case RPC_FC_ALIGNM8:
1658 ALIGN_POINTER(pMemory, 7);
1659 break;
1660 case RPC_FC_STRUCTPAD2:
1661 pMemory += 2;
1662 break;
1663 case RPC_FC_EMBEDDED_COMPLEX:
1664 pMemory += pFormat[1];
1665 pFormat += 2;
1666 desc = pFormat + *(const SHORT*)pFormat;
1667 size = EmbeddedComplexSize(pStubMsg, desc);
1668 m = NdrFreer[*desc & NDR_TABLE_MASK];
1669 if (m) m(pStubMsg, pMemory, desc);
1670 else FIXME("no freer for embedded type %02x\n", *desc);
1671 pMemory += size;
1672 pFormat += 2;
1673 continue;
1674 case RPC_FC_PAD:
1675 break;
1676 default:
1677 FIXME("unhandled format %d\n", *pFormat);
1679 pFormat++;
1682 return pMemory;
1685 unsigned long WINAPI ComplexStructSize(PMIDL_STUB_MESSAGE pStubMsg,
1686 PFORMAT_STRING pFormat)
1688 PFORMAT_STRING desc;
1689 unsigned long size = 0;
1691 while (*pFormat != RPC_FC_END) {
1692 switch (*pFormat) {
1693 case RPC_FC_SHORT:
1694 case RPC_FC_USHORT:
1695 size += 2;
1696 break;
1697 case RPC_FC_LONG:
1698 case RPC_FC_ULONG:
1699 size += 4;
1700 break;
1701 case RPC_FC_POINTER:
1702 size += 4;
1703 break;
1704 case RPC_FC_ALIGNM4:
1705 ALIGN_LENGTH(size, 3);
1706 break;
1707 case RPC_FC_ALIGNM8:
1708 ALIGN_LENGTH(size, 7);
1709 break;
1710 case RPC_FC_STRUCTPAD2:
1711 size += 2;
1712 break;
1713 case RPC_FC_EMBEDDED_COMPLEX:
1714 size += pFormat[1];
1715 pFormat += 2;
1716 desc = pFormat + *(const SHORT*)pFormat;
1717 size += EmbeddedComplexSize(pStubMsg, desc);
1718 pFormat += 2;
1719 continue;
1720 case RPC_FC_PAD:
1721 break;
1722 default:
1723 FIXME("unhandled format %d\n", *pFormat);
1725 pFormat++;
1728 return size;
1731 /***********************************************************************
1732 * NdrComplexStructMarshall [RPCRT4.@]
1734 unsigned char * WINAPI NdrComplexStructMarshall(PMIDL_STUB_MESSAGE pStubMsg,
1735 unsigned char *pMemory,
1736 PFORMAT_STRING pFormat)
1738 PFORMAT_STRING conf_array = NULL;
1739 PFORMAT_STRING pointer_desc = NULL;
1740 unsigned char *OldMemory = pStubMsg->Memory;
1742 TRACE("(%p,%p,%p)\n", pStubMsg, pMemory, pFormat);
1744 pFormat += 4;
1745 if (*(const WORD*)pFormat) conf_array = pFormat + *(const WORD*)pFormat;
1746 pFormat += 2;
1747 if (*(const WORD*)pFormat) pointer_desc = pFormat + *(const WORD*)pFormat;
1748 pFormat += 2;
1750 pStubMsg->Memory = pMemory;
1752 ComplexMarshall(pStubMsg, pMemory, pFormat, pointer_desc);
1754 if (conf_array)
1755 NdrConformantArrayMarshall(pStubMsg, pMemory, conf_array);
1757 pStubMsg->Memory = OldMemory;
1759 STD_OVERFLOW_CHECK(pStubMsg);
1761 return NULL;
1764 /***********************************************************************
1765 * NdrComplexStructUnmarshall [RPCRT4.@]
1767 unsigned char * WINAPI NdrComplexStructUnmarshall(PMIDL_STUB_MESSAGE pStubMsg,
1768 unsigned char **ppMemory,
1769 PFORMAT_STRING pFormat,
1770 unsigned char fMustAlloc)
1772 unsigned size = *(const WORD*)(pFormat+2);
1773 PFORMAT_STRING conf_array = NULL;
1774 PFORMAT_STRING pointer_desc = NULL;
1775 unsigned char *pMemory;
1777 TRACE("(%p,%p,%p,%d)\n", pStubMsg, ppMemory, pFormat, fMustAlloc);
1779 if (fMustAlloc || !*ppMemory)
1781 *ppMemory = NdrAllocate(pStubMsg, size);
1782 memset(*ppMemory, 0, size);
1785 pFormat += 4;
1786 if (*(const WORD*)pFormat) conf_array = pFormat + *(const WORD*)pFormat;
1787 pFormat += 2;
1788 if (*(const WORD*)pFormat) pointer_desc = pFormat + *(const WORD*)pFormat;
1789 pFormat += 2;
1791 pMemory = ComplexUnmarshall(pStubMsg, *ppMemory, pFormat, pointer_desc, fMustAlloc);
1793 if (conf_array)
1794 NdrConformantArrayUnmarshall(pStubMsg, &pMemory, conf_array, fMustAlloc);
1796 return NULL;
1799 /***********************************************************************
1800 * NdrComplexStructBufferSize [RPCRT4.@]
1802 void WINAPI NdrComplexStructBufferSize(PMIDL_STUB_MESSAGE pStubMsg,
1803 unsigned char *pMemory,
1804 PFORMAT_STRING pFormat)
1806 PFORMAT_STRING conf_array = NULL;
1807 PFORMAT_STRING pointer_desc = NULL;
1808 unsigned char *OldMemory = pStubMsg->Memory;
1810 TRACE("(%p,%p,%p)\n", pStubMsg, pMemory, pFormat);
1812 pFormat += 4;
1813 if (*(const WORD*)pFormat) conf_array = pFormat + *(const WORD*)pFormat;
1814 pFormat += 2;
1815 if (*(const WORD*)pFormat) pointer_desc = pFormat + *(const WORD*)pFormat;
1816 pFormat += 2;
1818 pStubMsg->Memory = pMemory;
1820 pMemory = ComplexBufferSize(pStubMsg, pMemory, pFormat, pointer_desc);
1822 if (conf_array)
1823 NdrConformantArrayBufferSize(pStubMsg, pMemory, conf_array);
1825 pStubMsg->Memory = OldMemory;
1828 /***********************************************************************
1829 * NdrComplexStructMemorySize [RPCRT4.@]
1831 unsigned long WINAPI NdrComplexStructMemorySize(PMIDL_STUB_MESSAGE pStubMsg,
1832 PFORMAT_STRING pFormat)
1834 /* unsigned size = *(LPWORD)(pFormat+2); */
1835 PFORMAT_STRING conf_array = NULL;
1836 PFORMAT_STRING pointer_desc = NULL;
1838 FIXME("(%p,%p): stub\n", pStubMsg, pFormat);
1840 pFormat += 4;
1841 if (*(const WORD*)pFormat) conf_array = pFormat + *(const WORD*)pFormat;
1842 pFormat += 2;
1843 if (*(const WORD*)pFormat) pointer_desc = pFormat + *(const WORD*)pFormat;
1844 pFormat += 2;
1846 return 0;
1849 /***********************************************************************
1850 * NdrComplexStructFree [RPCRT4.@]
1852 void WINAPI NdrComplexStructFree(PMIDL_STUB_MESSAGE pStubMsg,
1853 unsigned char *pMemory,
1854 PFORMAT_STRING pFormat)
1856 PFORMAT_STRING conf_array = NULL;
1857 PFORMAT_STRING pointer_desc = NULL;
1858 unsigned char *OldMemory = pStubMsg->Memory;
1860 TRACE("(%p,%p,%p)\n", pStubMsg, pMemory, pFormat);
1862 pFormat += 4;
1863 if (*(const WORD*)pFormat) conf_array = pFormat + *(const WORD*)pFormat;
1864 pFormat += 2;
1865 if (*(const WORD*)pFormat) pointer_desc = pFormat + *(const WORD*)pFormat;
1866 pFormat += 2;
1868 pStubMsg->Memory = pMemory;
1870 pMemory = ComplexFree(pStubMsg, pMemory, pFormat, pointer_desc);
1872 if (conf_array)
1873 NdrConformantArrayFree(pStubMsg, pMemory, conf_array);
1875 pStubMsg->Memory = OldMemory;
1878 /***********************************************************************
1879 * NdrConformantArrayMarshall [RPCRT4.@]
1881 unsigned char * WINAPI NdrConformantArrayMarshall(PMIDL_STUB_MESSAGE pStubMsg,
1882 unsigned char *pMemory,
1883 PFORMAT_STRING pFormat)
1885 DWORD size = 0, esize = *(const WORD*)(pFormat+2);
1886 TRACE("(%p,%p,%p)\n", pStubMsg, pMemory, pFormat);
1887 if (pFormat[0] != RPC_FC_CARRAY) FIXME("format=%d\n", pFormat[0]);
1889 pFormat = ComputeConformance(pStubMsg, pMemory, pFormat+4, 0);
1890 size = pStubMsg->MaxCount;
1892 NDR_LOCAL_UINT32_WRITE(pStubMsg->Buffer, size);
1893 pStubMsg->Buffer += 4;
1895 memcpy(pStubMsg->Buffer, pMemory, size*esize);
1896 pStubMsg->BufferMark = pStubMsg->Buffer;
1897 pStubMsg->Buffer += size*esize;
1899 EmbeddedPointerMarshall(pStubMsg, pMemory, pFormat);
1901 STD_OVERFLOW_CHECK(pStubMsg);
1903 return NULL;
1906 /***********************************************************************
1907 * NdrConformantArrayUnmarshall [RPCRT4.@]
1909 unsigned char * WINAPI NdrConformantArrayUnmarshall(PMIDL_STUB_MESSAGE pStubMsg,
1910 unsigned char **ppMemory,
1911 PFORMAT_STRING pFormat,
1912 unsigned char fMustAlloc)
1914 DWORD size = 0, esize = *(const WORD*)(pFormat+2);
1915 TRACE("(%p,%p,%p,%d)\n", pStubMsg, ppMemory, pFormat, fMustAlloc);
1916 if (pFormat[0] != RPC_FC_CARRAY) FIXME("format=%d\n", pFormat[0]);
1918 pFormat = ReadConformance(pStubMsg, pFormat+4);
1919 size = pStubMsg->MaxCount;
1921 if (fMustAlloc || !*ppMemory)
1922 *ppMemory = NdrAllocate(pStubMsg, size*esize);
1924 memcpy(*ppMemory, pStubMsg->Buffer, size*esize);
1926 pStubMsg->BufferMark = pStubMsg->Buffer;
1927 pStubMsg->Buffer += size*esize;
1929 EmbeddedPointerUnmarshall(pStubMsg, ppMemory, pFormat, fMustAlloc);
1931 return NULL;
1934 /***********************************************************************
1935 * NdrConformantArrayBufferSize [RPCRT4.@]
1937 void WINAPI NdrConformantArrayBufferSize(PMIDL_STUB_MESSAGE pStubMsg,
1938 unsigned char *pMemory,
1939 PFORMAT_STRING pFormat)
1941 DWORD size = 0, esize = *(const WORD*)(pFormat+2);
1942 TRACE("(%p,%p,%p)\n", pStubMsg, pMemory, pFormat);
1943 if (pFormat[0] != RPC_FC_CARRAY) FIXME("format=%d\n", pFormat[0]);
1945 pFormat = ComputeConformance(pStubMsg, pMemory, pFormat+4, 0);
1946 size = pStubMsg->MaxCount;
1948 /* conformance value plus array */
1949 pStubMsg->BufferLength += sizeof(DWORD) + size*esize;
1951 EmbeddedPointerBufferSize(pStubMsg, pMemory, pFormat);
1954 /***********************************************************************
1955 * NdrConformantArrayMemorySize [RPCRT4.@]
1957 unsigned long WINAPI NdrConformantArrayMemorySize(PMIDL_STUB_MESSAGE pStubMsg,
1958 PFORMAT_STRING pFormat)
1960 DWORD size = 0, esize = *(const WORD*)(pFormat+2);
1961 unsigned char *buffer;
1963 TRACE("(%p,%p)\n", pStubMsg, pFormat);
1964 if (pFormat[0] != RPC_FC_CARRAY) FIXME("format=%d\n", pFormat[0]);
1966 buffer = pStubMsg->Buffer;
1967 pFormat = ReadConformance(pStubMsg, pFormat+4);
1968 pStubMsg->Buffer = buffer;
1969 size = pStubMsg->MaxCount;
1971 return size*esize;
1974 /***********************************************************************
1975 * NdrConformantArrayFree [RPCRT4.@]
1977 void WINAPI NdrConformantArrayFree(PMIDL_STUB_MESSAGE pStubMsg,
1978 unsigned char *pMemory,
1979 PFORMAT_STRING pFormat)
1981 TRACE("(%p,%p,%p)\n", pStubMsg, pMemory, pFormat);
1982 if (pFormat[0] != RPC_FC_CARRAY) FIXME("format=%d\n", pFormat[0]);
1984 EmbeddedPointerFree(pStubMsg, pMemory, pFormat);
1988 /***********************************************************************
1989 * NdrConformantVaryingArrayMarshall [RPCRT4.@]
1991 unsigned char* WINAPI NdrConformantVaryingArrayMarshall( PMIDL_STUB_MESSAGE pStubMsg,
1992 unsigned char* pMemory,
1993 PFORMAT_STRING pFormat )
1995 DWORD esize = *(const WORD*)(pFormat+2);
1997 TRACE("(%p, %p, %p)\n", pStubMsg, pMemory, pFormat);
1999 if (pFormat[0] != RPC_FC_CVARRAY)
2001 ERR("invalid format type %x\n", pFormat[0]);
2002 RpcRaiseException(RPC_S_INTERNAL_ERROR);
2003 return NULL;
2006 pFormat = ComputeConformance(pStubMsg, pMemory, pFormat+4, 0);
2007 pFormat = ComputeVariance(pStubMsg, pMemory, pFormat, 0);
2009 NDR_LOCAL_UINT32_WRITE(pStubMsg->Buffer, pStubMsg->MaxCount);
2010 pStubMsg->Buffer += 4;
2011 NDR_LOCAL_UINT32_WRITE(pStubMsg->Buffer, pStubMsg->Offset);
2012 pStubMsg->Buffer += 4;
2013 NDR_LOCAL_UINT32_WRITE(pStubMsg->Buffer, pStubMsg->ActualCount);
2014 pStubMsg->Buffer += 4;
2016 memcpy(pStubMsg->Buffer, pMemory + pStubMsg->Offset, pStubMsg->ActualCount*esize);
2017 pStubMsg->BufferMark = pStubMsg->Buffer;
2018 pStubMsg->Buffer += pStubMsg->ActualCount*esize;
2020 EmbeddedPointerMarshall(pStubMsg, pMemory, pFormat);
2022 STD_OVERFLOW_CHECK(pStubMsg);
2024 return NULL;
2028 /***********************************************************************
2029 * NdrConformantVaryingArrayUnmarshall [RPCRT4.@]
2031 unsigned char* WINAPI NdrConformantVaryingArrayUnmarshall( PMIDL_STUB_MESSAGE pStubMsg,
2032 unsigned char** ppMemory,
2033 PFORMAT_STRING pFormat,
2034 unsigned char fMustAlloc )
2036 DWORD esize = *(const WORD*)(pFormat+2);
2038 TRACE("(%p, %p, %p, %d)\n", pStubMsg, ppMemory, pFormat, fMustAlloc);
2040 if (pFormat[0] != RPC_FC_CVARRAY)
2042 ERR("invalid format type %x\n", pFormat[0]);
2043 RpcRaiseException(RPC_S_INTERNAL_ERROR);
2044 return NULL;
2046 pFormat = ReadConformance(pStubMsg, pFormat);
2047 pFormat = ReadVariance(pStubMsg, pFormat);
2049 if (!*ppMemory || fMustAlloc)
2050 *ppMemory = NdrAllocate(pStubMsg, pStubMsg->MaxCount * esize);
2051 memcpy(*ppMemory + pStubMsg->Offset, pStubMsg->Buffer, pStubMsg->ActualCount * esize);
2052 pStubMsg->Buffer += pStubMsg->ActualCount * esize;
2054 EmbeddedPointerUnmarshall(pStubMsg, ppMemory, pFormat, fMustAlloc);
2056 return NULL;
2060 /***********************************************************************
2061 * NdrConformantVaryingArrayFree [RPCRT4.@]
2063 void WINAPI NdrConformantVaryingArrayFree( PMIDL_STUB_MESSAGE pStubMsg,
2064 unsigned char* pMemory,
2065 PFORMAT_STRING pFormat )
2067 FIXME( "stub\n" );
2071 /***********************************************************************
2072 * NdrConformantVaryingArrayBufferSize [RPCRT4.@]
2074 void WINAPI NdrConformantVaryingArrayBufferSize( PMIDL_STUB_MESSAGE pStubMsg,
2075 unsigned char* pMemory, PFORMAT_STRING pFormat )
2077 DWORD esize = *(const WORD*)(pFormat+2);
2079 TRACE("(%p, %p, %p)\n", pStubMsg, pMemory, pFormat);
2081 if (pFormat[0] != RPC_FC_CVARRAY)
2083 ERR("invalid format type %x\n", pFormat[0]);
2084 RpcRaiseException(RPC_S_INTERNAL_ERROR);
2085 return;
2088 /* compute size */
2089 pFormat = ComputeConformance(pStubMsg, pMemory, pFormat+4, 0);
2090 /* compute length */
2091 pFormat = ComputeVariance(pStubMsg, pMemory, pFormat, 0);
2093 /* conformance + offset + variance + array */
2094 pStubMsg->BufferLength += 3*sizeof(DWORD) + pStubMsg->ActualCount*esize;
2096 EmbeddedPointerBufferSize(pStubMsg, pMemory, pFormat);
2100 /***********************************************************************
2101 * NdrConformantVaryingArrayMemorySize [RPCRT4.@]
2103 unsigned long WINAPI NdrConformantVaryingArrayMemorySize( PMIDL_STUB_MESSAGE pStubMsg,
2104 PFORMAT_STRING pFormat )
2106 FIXME( "stub\n" );
2107 return 0;
2111 /***********************************************************************
2112 * NdrComplexArrayMarshall [RPCRT4.@]
2114 unsigned char * WINAPI NdrComplexArrayMarshall(PMIDL_STUB_MESSAGE pStubMsg,
2115 unsigned char *pMemory,
2116 PFORMAT_STRING pFormat)
2118 ULONG count, def;
2119 BOOL variance_present;
2121 TRACE("(%p,%p,%p)\n", pStubMsg, pMemory, pFormat);
2123 if (pFormat[0] != RPC_FC_BOGUS_ARRAY)
2125 ERR("invalid format type %x\n", pFormat[0]);
2126 RpcRaiseException(RPC_S_INTERNAL_ERROR);
2127 return NULL;
2130 def = *(const WORD*)&pFormat[2];
2131 pFormat += 4;
2133 pFormat = ComputeConformance(pStubMsg, pMemory, pFormat, def);
2134 TRACE("conformance = %ld\n", pStubMsg->MaxCount);
2136 variance_present = IsConformanceOrVariancePresent(pFormat);
2137 pFormat = ComputeVariance(pStubMsg, pMemory, pFormat, pStubMsg->MaxCount);
2138 TRACE("variance = %ld\n", pStubMsg->ActualCount);
2140 NDR_LOCAL_UINT32_WRITE(pStubMsg->Buffer, pStubMsg->MaxCount);
2141 pStubMsg->Buffer += 4;
2142 if (variance_present)
2144 NDR_LOCAL_UINT32_WRITE(pStubMsg->Buffer, pStubMsg->Offset);
2145 pStubMsg->Buffer += 4;
2146 NDR_LOCAL_UINT32_WRITE(pStubMsg->Buffer, pStubMsg->ActualCount);
2147 pStubMsg->Buffer += 4;
2150 for (count = 0; count < pStubMsg->ActualCount; count++)
2151 pMemory = ComplexMarshall(pStubMsg, pMemory, pFormat, NULL);
2153 STD_OVERFLOW_CHECK(pStubMsg);
2155 return NULL;
2158 /***********************************************************************
2159 * NdrComplexArrayUnmarshall [RPCRT4.@]
2161 unsigned char * WINAPI NdrComplexArrayUnmarshall(PMIDL_STUB_MESSAGE pStubMsg,
2162 unsigned char **ppMemory,
2163 PFORMAT_STRING pFormat,
2164 unsigned char fMustAlloc)
2166 ULONG count, esize;
2167 unsigned char *pMemory;
2169 TRACE("(%p,%p,%p,%d)\n", pStubMsg, ppMemory, pFormat, fMustAlloc);
2171 if (pFormat[0] != RPC_FC_BOGUS_ARRAY)
2173 ERR("invalid format type %x\n", pFormat[0]);
2174 RpcRaiseException(RPC_S_INTERNAL_ERROR);
2175 return NULL;
2178 pFormat += 4;
2180 pFormat = ReadConformance(pStubMsg, pFormat);
2181 pFormat = ReadVariance(pStubMsg, pFormat);
2183 esize = ComplexStructSize(pStubMsg, pFormat);
2185 if (fMustAlloc || !*ppMemory)
2187 *ppMemory = NdrAllocate(pStubMsg, pStubMsg->MaxCount * esize);
2188 memset(*ppMemory, 0, pStubMsg->MaxCount * esize);
2191 pMemory = *ppMemory;
2192 for (count = 0; count < pStubMsg->ActualCount; count++)
2193 pMemory = ComplexUnmarshall(pStubMsg, pMemory, pFormat, NULL, fMustAlloc);
2195 return NULL;
2198 /***********************************************************************
2199 * NdrComplexArrayBufferSize [RPCRT4.@]
2201 void WINAPI NdrComplexArrayBufferSize(PMIDL_STUB_MESSAGE pStubMsg,
2202 unsigned char *pMemory,
2203 PFORMAT_STRING pFormat)
2205 ULONG count, def;
2206 BOOL variance_present;
2208 TRACE("(%p,%p,%p)\n", pStubMsg, pMemory, pFormat);
2210 if (pFormat[0] != RPC_FC_BOGUS_ARRAY)
2212 ERR("invalid format type %x\n", pFormat[0]);
2213 RpcRaiseException(RPC_S_INTERNAL_ERROR);
2214 return;
2217 def = *(const WORD*)&pFormat[2];
2218 pFormat += 4;
2220 pFormat = ComputeConformance(pStubMsg, pMemory, pFormat, def);
2221 TRACE("conformance = %ld\n", pStubMsg->MaxCount);
2222 pStubMsg->BufferLength += sizeof(ULONG);
2224 variance_present = IsConformanceOrVariancePresent(pFormat);
2225 pFormat = ComputeVariance(pStubMsg, pMemory, pFormat, pStubMsg->MaxCount);
2226 TRACE("variance = %ld\n", pStubMsg->ActualCount);
2228 if (variance_present)
2229 pStubMsg->BufferLength += 2*sizeof(ULONG);
2231 for (count=0; count < pStubMsg->ActualCount; count++)
2232 pMemory = ComplexBufferSize(pStubMsg, pMemory, pFormat, NULL);
2235 /***********************************************************************
2236 * NdrComplexArrayMemorySize [RPCRT4.@]
2238 unsigned long WINAPI NdrComplexArrayMemorySize(PMIDL_STUB_MESSAGE pStubMsg,
2239 PFORMAT_STRING pFormat)
2241 DWORD size = 0;
2242 FIXME("(%p,%p): stub\n", pStubMsg, pFormat);
2244 if (pFormat[0] != RPC_FC_BOGUS_ARRAY)
2246 ERR("invalid format type %x\n", pFormat[0]);
2247 RpcRaiseException(RPC_S_INTERNAL_ERROR);
2248 return 0;
2251 pFormat += 4;
2253 pFormat = ReadConformance(pStubMsg, pFormat);
2254 size = pStubMsg->MaxCount;
2255 TRACE("conformance=%ld\n", size);
2257 pFormat += 4;
2259 return 0;
2262 /***********************************************************************
2263 * NdrComplexArrayFree [RPCRT4.@]
2265 void WINAPI NdrComplexArrayFree(PMIDL_STUB_MESSAGE pStubMsg,
2266 unsigned char *pMemory,
2267 PFORMAT_STRING pFormat)
2269 ULONG count, def;
2271 TRACE("(%p,%p,%p)\n", pStubMsg, pMemory, pFormat);
2273 if (pFormat[0] != RPC_FC_BOGUS_ARRAY)
2275 ERR("invalid format type %x\n", pFormat[0]);
2276 RpcRaiseException(RPC_S_INTERNAL_ERROR);
2277 return;
2280 def = *(const WORD*)&pFormat[2];
2281 pFormat += 4;
2283 pFormat = ComputeConformance(pStubMsg, pMemory, pFormat, def);
2284 TRACE("conformance = %ld\n", pStubMsg->MaxCount);
2286 pFormat = ComputeVariance(pStubMsg, pMemory, pFormat, pStubMsg->MaxCount);
2287 TRACE("variance = %ld\n", pStubMsg->ActualCount);
2289 for (count=0; count < pStubMsg->ActualCount; count++)
2290 pMemory = ComplexFree(pStubMsg, pMemory, pFormat, NULL);
2293 unsigned long UserMarshalFlags(PMIDL_STUB_MESSAGE pStubMsg)
2295 return MAKELONG(pStubMsg->dwDestContext,
2296 pStubMsg->RpcMsg->DataRepresentation);
2299 /***********************************************************************
2300 * NdrUserMarshalMarshall [RPCRT4.@]
2302 unsigned char * WINAPI NdrUserMarshalMarshall(PMIDL_STUB_MESSAGE pStubMsg,
2303 unsigned char *pMemory,
2304 PFORMAT_STRING pFormat)
2306 /* unsigned flags = pFormat[1]; */
2307 unsigned index = *(const WORD*)&pFormat[2];
2308 unsigned long uflag = UserMarshalFlags(pStubMsg);
2309 TRACE("(%p,%p,%p)\n", pStubMsg, pMemory, pFormat);
2310 TRACE("index=%d\n", index);
2312 pStubMsg->Buffer =
2313 pStubMsg->StubDesc->aUserMarshalQuadruple[index].pfnMarshall(
2314 &uflag, pStubMsg->Buffer, pMemory);
2316 STD_OVERFLOW_CHECK(pStubMsg);
2318 return NULL;
2321 /***********************************************************************
2322 * NdrUserMarshalUnmarshall [RPCRT4.@]
2324 unsigned char * WINAPI NdrUserMarshalUnmarshall(PMIDL_STUB_MESSAGE pStubMsg,
2325 unsigned char **ppMemory,
2326 PFORMAT_STRING pFormat,
2327 unsigned char fMustAlloc)
2329 /* unsigned flags = pFormat[1];*/
2330 unsigned index = *(const WORD*)&pFormat[2];
2331 DWORD memsize = *(const WORD*)&pFormat[4];
2332 unsigned long uflag = UserMarshalFlags(pStubMsg);
2333 TRACE("(%p,%p,%p,%d)\n", pStubMsg, ppMemory, pFormat, fMustAlloc);
2334 TRACE("index=%d\n", index);
2336 if (fMustAlloc || !*ppMemory)
2337 *ppMemory = NdrAllocate(pStubMsg, memsize);
2339 pStubMsg->Buffer =
2340 pStubMsg->StubDesc->aUserMarshalQuadruple[index].pfnUnmarshall(
2341 &uflag, pStubMsg->Buffer, *ppMemory);
2343 return NULL;
2346 /***********************************************************************
2347 * NdrUserMarshalBufferSize [RPCRT4.@]
2349 void WINAPI NdrUserMarshalBufferSize(PMIDL_STUB_MESSAGE pStubMsg,
2350 unsigned char *pMemory,
2351 PFORMAT_STRING pFormat)
2353 /* unsigned flags = pFormat[1];*/
2354 unsigned index = *(const WORD*)&pFormat[2];
2355 DWORD bufsize = *(const WORD*)&pFormat[6];
2356 unsigned long uflag = UserMarshalFlags(pStubMsg);
2357 TRACE("(%p,%p,%p)\n", pStubMsg, pMemory, pFormat);
2358 TRACE("index=%d\n", index);
2360 if (bufsize) {
2361 TRACE("size=%ld\n", bufsize);
2362 pStubMsg->BufferLength += bufsize;
2363 return;
2366 pStubMsg->BufferLength =
2367 pStubMsg->StubDesc->aUserMarshalQuadruple[index].pfnBufferSize(
2368 &uflag, pStubMsg->BufferLength, pMemory);
2371 /***********************************************************************
2372 * NdrUserMarshalMemorySize [RPCRT4.@]
2374 unsigned long WINAPI NdrUserMarshalMemorySize(PMIDL_STUB_MESSAGE pStubMsg,
2375 PFORMAT_STRING pFormat)
2377 unsigned index = *(const WORD*)&pFormat[2];
2378 /* DWORD memsize = *(const WORD*)&pFormat[4]; */
2379 FIXME("(%p,%p): stub\n", pStubMsg, pFormat);
2380 TRACE("index=%d\n", index);
2382 return 0;
2385 /***********************************************************************
2386 * NdrUserMarshalFree [RPCRT4.@]
2388 void WINAPI NdrUserMarshalFree(PMIDL_STUB_MESSAGE pStubMsg,
2389 unsigned char *pMemory,
2390 PFORMAT_STRING pFormat)
2392 /* unsigned flags = pFormat[1]; */
2393 unsigned index = *(const WORD*)&pFormat[2];
2394 unsigned long uflag = UserMarshalFlags(pStubMsg);
2395 TRACE("(%p,%p,%p)\n", pStubMsg, pMemory, pFormat);
2396 TRACE("index=%d\n", index);
2398 pStubMsg->StubDesc->aUserMarshalQuadruple[index].pfnFree(
2399 &uflag, pMemory);
2402 /***********************************************************************
2403 * NdrClearOutParameters [RPCRT4.@]
2405 void WINAPI NdrClearOutParameters(PMIDL_STUB_MESSAGE pStubMsg,
2406 PFORMAT_STRING pFormat,
2407 void *ArgAddr)
2409 FIXME("(%p,%p,%p): stub\n", pStubMsg, pFormat, ArgAddr);
2412 /***********************************************************************
2413 * NdrConvert [RPCRT4.@]
2415 void WINAPI NdrConvert( PMIDL_STUB_MESSAGE pStubMsg, PFORMAT_STRING pFormat )
2417 FIXME("(pStubMsg == ^%p, pFormat == ^%p): stub.\n", pStubMsg, pFormat);
2418 /* FIXME: since this stub doesn't do any converting, the proper behavior
2419 is to raise an exception */
2422 /***********************************************************************
2423 * NdrConvert2 [RPCRT4.@]
2425 void WINAPI NdrConvert2( PMIDL_STUB_MESSAGE pStubMsg, PFORMAT_STRING pFormat, long NumberParams )
2427 FIXME("(pStubMsg == ^%p, pFormat == ^%p, NumberParams == %ld): stub.\n",
2428 pStubMsg, pFormat, NumberParams);
2429 /* FIXME: since this stub doesn't do any converting, the proper behavior
2430 is to raise an exception */
2433 typedef struct _NDR_CSTRUCT_FORMAT
2435 unsigned char type;
2436 unsigned char alignment;
2437 unsigned short memory_size;
2438 short offset_to_array_description;
2439 } NDR_CSTRUCT_FORMAT;
2441 /***********************************************************************
2442 * NdrConformantStructMarshall [RPCRT4.@]
2444 unsigned char * WINAPI NdrConformantStructMarshall(PMIDL_STUB_MESSAGE pStubMsg,
2445 unsigned char *pMemory,
2446 PFORMAT_STRING pFormat)
2448 const NDR_CSTRUCT_FORMAT * pCStructFormat = (NDR_CSTRUCT_FORMAT*)pFormat;
2449 pFormat += sizeof(NDR_CSTRUCT_FORMAT);
2451 TRACE("(%p, %p, %p)\n", pStubMsg, pMemory, pFormat);
2453 if ((pCStructFormat->type != RPC_FC_CPSTRUCT) && (pCStructFormat->type != RPC_FC_CSTRUCT))
2455 ERR("invalid format type %x\n", pCStructFormat->type);
2456 RpcRaiseException(RPC_S_INTERNAL_ERROR);
2457 return NULL;
2460 TRACE("memory_size = %d\n", pCStructFormat->memory_size);
2462 /* copy constant sized part of struct */
2463 memcpy(pStubMsg->Buffer, pMemory, pCStructFormat->memory_size);
2464 pStubMsg->Buffer += pCStructFormat->memory_size;
2466 if (pCStructFormat->offset_to_array_description)
2468 PFORMAT_STRING pArrayFormat = (unsigned char*)&pCStructFormat->offset_to_array_description +
2469 pCStructFormat->offset_to_array_description;
2470 NdrConformantArrayMarshall(pStubMsg, pMemory + pCStructFormat->memory_size, pArrayFormat);
2472 if (pCStructFormat->type == RPC_FC_CPSTRUCT)
2473 EmbeddedPointerMarshall(pStubMsg, pMemory, pFormat);
2474 return NULL;
2477 /***********************************************************************
2478 * NdrConformantStructUnmarshall [RPCRT4.@]
2480 unsigned char * WINAPI NdrConformantStructUnmarshall(PMIDL_STUB_MESSAGE pStubMsg,
2481 unsigned char **ppMemory,
2482 PFORMAT_STRING pFormat,
2483 unsigned char fMustAlloc)
2485 const NDR_CSTRUCT_FORMAT * pCStructFormat = (NDR_CSTRUCT_FORMAT*)pFormat;
2486 pFormat += sizeof(NDR_CSTRUCT_FORMAT);
2488 TRACE("(%p, %p, %p, %d)\n", pStubMsg, ppMemory, pFormat, fMustAlloc);
2490 if ((pCStructFormat->type != RPC_FC_CPSTRUCT) && (pCStructFormat->type != RPC_FC_CSTRUCT))
2492 ERR("invalid format type %x\n", pCStructFormat->type);
2493 RpcRaiseException(RPC_S_INTERNAL_ERROR);
2494 return NULL;
2497 TRACE("memory_size = %d\n", pCStructFormat->memory_size);
2499 /* work out how much memory to allocate if we need to do so */
2500 if (!*ppMemory || fMustAlloc)
2502 SIZE_T size = pCStructFormat->memory_size;
2504 if (pCStructFormat->offset_to_array_description)
2506 unsigned char *buffer;
2507 PFORMAT_STRING pArrayFormat = (unsigned char*)&pCStructFormat->offset_to_array_description +
2508 pCStructFormat->offset_to_array_description;
2509 buffer = pStubMsg->Buffer;
2510 pStubMsg->Buffer += pCStructFormat->memory_size;
2511 size += NdrConformantArrayMemorySize(pStubMsg, pArrayFormat);
2512 pStubMsg->Buffer = buffer;
2514 *ppMemory = NdrAllocate(pStubMsg, size);
2517 /* now copy the data */
2518 memcpy(*ppMemory, pStubMsg->Buffer, pCStructFormat->memory_size);
2519 pStubMsg->Buffer += pCStructFormat->memory_size;
2520 if (pCStructFormat->offset_to_array_description)
2522 PFORMAT_STRING pArrayFormat = (unsigned char*)&pCStructFormat->offset_to_array_description +
2523 pCStructFormat->offset_to_array_description;
2524 unsigned char *pMemoryArray = *ppMemory + pCStructFormat->memory_size;
2525 /* note that we pass fMustAlloc as 0 as we have already allocated the
2526 * memory */
2527 NdrConformantArrayUnmarshall(pStubMsg, &pMemoryArray, pArrayFormat, 0);
2529 if (pCStructFormat->type == RPC_FC_CPSTRUCT)
2530 EmbeddedPointerUnmarshall(pStubMsg, ppMemory, pFormat, fMustAlloc);
2531 return NULL;
2534 /***********************************************************************
2535 * NdrConformantStructBufferSize [RPCRT4.@]
2537 void WINAPI NdrConformantStructBufferSize(PMIDL_STUB_MESSAGE pStubMsg,
2538 unsigned char *pMemory,
2539 PFORMAT_STRING pFormat)
2541 const NDR_CSTRUCT_FORMAT * pCStructFormat = (NDR_CSTRUCT_FORMAT*)pFormat;
2542 pFormat += sizeof(NDR_CSTRUCT_FORMAT);
2543 TRACE("(%p, %p, %p)\n", pStubMsg, pMemory, pFormat);
2545 if ((pCStructFormat->type != RPC_FC_CPSTRUCT) && (pCStructFormat->type != RPC_FC_CSTRUCT))
2547 ERR("invalid format type %x\n", pCStructFormat->type);
2548 RpcRaiseException(RPC_S_INTERNAL_ERROR);
2549 return;
2552 TRACE("memory_size = %d\n", pCStructFormat->memory_size);
2554 /* add constant sized part of struct to buffer size */
2555 pStubMsg->BufferLength += pCStructFormat->memory_size;
2557 if (pCStructFormat->offset_to_array_description)
2559 PFORMAT_STRING pArrayFormat = (unsigned char*)&pCStructFormat->offset_to_array_description +
2560 pCStructFormat->offset_to_array_description;
2561 NdrConformantArrayBufferSize(pStubMsg, pMemory + pCStructFormat->memory_size, pArrayFormat);
2563 if (pCStructFormat->type == RPC_FC_CPSTRUCT)
2564 EmbeddedPointerBufferSize(pStubMsg, pMemory, pFormat);
2567 /***********************************************************************
2568 * NdrConformantStructMemorySize [RPCRT4.@]
2570 unsigned long WINAPI NdrConformantStructMemorySize(PMIDL_STUB_MESSAGE pStubMsg,
2571 PFORMAT_STRING pFormat)
2573 FIXME("stub\n");
2574 return 0;
2577 /***********************************************************************
2578 * NdrConformantStructFree [RPCRT4.@]
2580 void WINAPI NdrConformantStructFree(PMIDL_STUB_MESSAGE pStubMsg,
2581 unsigned char *pMemory,
2582 PFORMAT_STRING pFormat)
2584 FIXME("stub\n");
2587 /***********************************************************************
2588 * NdrConformantVaryingStructMarshall [RPCRT4.@]
2590 unsigned char * WINAPI NdrConformantVaryingStructMarshall(PMIDL_STUB_MESSAGE pStubMsg,
2591 unsigned char *pMemory,
2592 PFORMAT_STRING pFormat)
2594 FIXME("stub\n");
2595 return NULL;
2598 /***********************************************************************
2599 * NdrConformantVaryingStructUnmarshall [RPCRT4.@]
2601 unsigned char * WINAPI NdrConformantVaryingStructUnmarshall(PMIDL_STUB_MESSAGE pStubMsg,
2602 unsigned char **ppMemory,
2603 PFORMAT_STRING pFormat,
2604 unsigned char fMustAlloc)
2606 FIXME("stub\n");
2607 return NULL;
2610 /***********************************************************************
2611 * NdrConformantVaryingStructBufferSize [RPCRT4.@]
2613 void WINAPI NdrConformantVaryingStructBufferSize(PMIDL_STUB_MESSAGE pStubMsg,
2614 unsigned char *pMemory,
2615 PFORMAT_STRING pFormat)
2617 FIXME("stub\n");
2620 /***********************************************************************
2621 * NdrConformantVaryingStructMemorySize [RPCRT4.@]
2623 unsigned long WINAPI NdrConformantVaryingStructMemorySize(PMIDL_STUB_MESSAGE pStubMsg,
2624 PFORMAT_STRING pFormat)
2626 FIXME("stub\n");
2627 return 0;
2630 /***********************************************************************
2631 * NdrConformantVaryingStructFree [RPCRT4.@]
2633 void WINAPI NdrConformantVaryingStructFree(PMIDL_STUB_MESSAGE pStubMsg,
2634 unsigned char *pMemory,
2635 PFORMAT_STRING pFormat)
2637 FIXME("stub\n");
2640 /***********************************************************************
2641 * NdrFixedArrayMarshall [RPCRT4.@]
2643 unsigned char * WINAPI NdrFixedArrayMarshall(PMIDL_STUB_MESSAGE pStubMsg,
2644 unsigned char *pMemory,
2645 PFORMAT_STRING pFormat)
2647 FIXME("stub\n");
2648 return NULL;
2651 /***********************************************************************
2652 * NdrFixedArrayUnmarshall [RPCRT4.@]
2654 unsigned char * WINAPI NdrFixedArrayUnmarshall(PMIDL_STUB_MESSAGE pStubMsg,
2655 unsigned char **ppMemory,
2656 PFORMAT_STRING pFormat,
2657 unsigned char fMustAlloc)
2659 FIXME("stub\n");
2660 return NULL;
2663 /***********************************************************************
2664 * NdrFixedArrayBufferSize [RPCRT4.@]
2666 void WINAPI NdrFixedArrayBufferSize(PMIDL_STUB_MESSAGE pStubMsg,
2667 unsigned char *pMemory,
2668 PFORMAT_STRING pFormat)
2670 FIXME("stub\n");
2673 /***********************************************************************
2674 * NdrFixedArrayMemorySize [RPCRT4.@]
2676 unsigned long WINAPI NdrFixedArrayMemorySize(PMIDL_STUB_MESSAGE pStubMsg,
2677 PFORMAT_STRING pFormat)
2679 FIXME("stub\n");
2680 return 0;
2683 /***********************************************************************
2684 * NdrFixedArrayFree [RPCRT4.@]
2686 void WINAPI NdrFixedArrayFree(PMIDL_STUB_MESSAGE pStubMsg,
2687 unsigned char *pMemory,
2688 PFORMAT_STRING pFormat)
2690 FIXME("stub\n");
2693 /***********************************************************************
2694 * NdrVaryingArrayMarshall [RPCRT4.@]
2696 unsigned char * WINAPI NdrVaryingArrayMarshall(PMIDL_STUB_MESSAGE pStubMsg,
2697 unsigned char *pMemory,
2698 PFORMAT_STRING pFormat)
2700 FIXME("stub\n");
2701 return NULL;
2704 /***********************************************************************
2705 * NdrVaryingArrayUnmarshall [RPCRT4.@]
2707 unsigned char * WINAPI NdrVaryingArrayUnmarshall(PMIDL_STUB_MESSAGE pStubMsg,
2708 unsigned char **ppMemory,
2709 PFORMAT_STRING pFormat,
2710 unsigned char fMustAlloc)
2712 FIXME("stub\n");
2713 return NULL;
2716 /***********************************************************************
2717 * NdrVaryingArrayBufferSize [RPCRT4.@]
2719 void WINAPI NdrVaryingArrayBufferSize(PMIDL_STUB_MESSAGE pStubMsg,
2720 unsigned char *pMemory,
2721 PFORMAT_STRING pFormat)
2723 FIXME("stub\n");
2726 /***********************************************************************
2727 * NdrVaryingArrayMemorySize [RPCRT4.@]
2729 unsigned long WINAPI NdrVaryingArrayMemorySize(PMIDL_STUB_MESSAGE pStubMsg,
2730 PFORMAT_STRING pFormat)
2732 FIXME("stub\n");
2733 return 0;
2736 /***********************************************************************
2737 * NdrVaryingArrayFree [RPCRT4.@]
2739 void WINAPI NdrVaryingArrayFree(PMIDL_STUB_MESSAGE pStubMsg,
2740 unsigned char *pMemory,
2741 PFORMAT_STRING pFormat)
2743 FIXME("stub\n");
2746 /***********************************************************************
2747 * NdrEncapsulatedUnionMarshall [RPCRT4.@]
2749 unsigned char * WINAPI NdrEncapsulatedUnionMarshall(PMIDL_STUB_MESSAGE pStubMsg,
2750 unsigned char *pMemory,
2751 PFORMAT_STRING pFormat)
2753 FIXME("stub\n");
2754 return NULL;
2757 /***********************************************************************
2758 * NdrEncapsulatedUnionUnmarshall [RPCRT4.@]
2760 unsigned char * WINAPI NdrEncapsulatedUnionUnmarshall(PMIDL_STUB_MESSAGE pStubMsg,
2761 unsigned char **ppMemory,
2762 PFORMAT_STRING pFormat,
2763 unsigned char fMustAlloc)
2765 FIXME("stub\n");
2766 return NULL;
2769 /***********************************************************************
2770 * NdrEncapsulatedUnionBufferSize [RPCRT4.@]
2772 void WINAPI NdrEncapsulatedUnionBufferSize(PMIDL_STUB_MESSAGE pStubMsg,
2773 unsigned char *pMemory,
2774 PFORMAT_STRING pFormat)
2776 FIXME("stub\n");
2779 /***********************************************************************
2780 * NdrEncapsulatedUnionMemorySize [RPCRT4.@]
2782 unsigned long WINAPI NdrEncapsulatedUnionMemorySize(PMIDL_STUB_MESSAGE pStubMsg,
2783 PFORMAT_STRING pFormat)
2785 FIXME("stub\n");
2786 return 0;
2789 /***********************************************************************
2790 * NdrEncapsulatedUnionFree [RPCRT4.@]
2792 void WINAPI NdrEncapsulatedUnionFree(PMIDL_STUB_MESSAGE pStubMsg,
2793 unsigned char *pMemory,
2794 PFORMAT_STRING pFormat)
2796 FIXME("stub\n");
2799 /***********************************************************************
2800 * NdrNonEncapsulatedUnionMarshall [RPCRT4.@]
2802 unsigned char * WINAPI NdrNonEncapsulatedUnionMarshall(PMIDL_STUB_MESSAGE pStubMsg,
2803 unsigned char *pMemory,
2804 PFORMAT_STRING pFormat)
2806 FIXME("stub\n");
2807 return NULL;
2810 /***********************************************************************
2811 * NdrNonEncapsulatedUnionUnmarshall [RPCRT4.@]
2813 unsigned char * WINAPI NdrNonEncapsulatedUnionUnmarshall(PMIDL_STUB_MESSAGE pStubMsg,
2814 unsigned char **ppMemory,
2815 PFORMAT_STRING pFormat,
2816 unsigned char fMustAlloc)
2818 FIXME("stub\n");
2819 return NULL;
2822 /***********************************************************************
2823 * NdrNonEncapsulatedUnionBufferSize [RPCRT4.@]
2825 void WINAPI NdrNonEncapsulatedUnionBufferSize(PMIDL_STUB_MESSAGE pStubMsg,
2826 unsigned char *pMemory,
2827 PFORMAT_STRING pFormat)
2829 FIXME("stub\n");
2832 /***********************************************************************
2833 * NdrNonEncapsulatedUnionMemorySize [RPCRT4.@]
2835 unsigned long WINAPI NdrNonEncapsulatedUnionMemorySize(PMIDL_STUB_MESSAGE pStubMsg,
2836 PFORMAT_STRING pFormat)
2838 FIXME("stub\n");
2839 return 0;
2842 /***********************************************************************
2843 * NdrNonEncapsulatedUnionFree [RPCRT4.@]
2845 void WINAPI NdrNonEncapsulatedUnionFree(PMIDL_STUB_MESSAGE pStubMsg,
2846 unsigned char *pMemory,
2847 PFORMAT_STRING pFormat)
2849 FIXME("stub\n");
2852 /***********************************************************************
2853 * NdrByteCountPointerMarshall [RPCRT4.@]
2855 unsigned char * WINAPI NdrByteCountPointerMarshall(PMIDL_STUB_MESSAGE pStubMsg,
2856 unsigned char *pMemory,
2857 PFORMAT_STRING pFormat)
2859 FIXME("stub\n");
2860 return NULL;
2863 /***********************************************************************
2864 * NdrByteCountPointerUnmarshall [RPCRT4.@]
2866 unsigned char * WINAPI NdrByteCountPointerUnmarshall(PMIDL_STUB_MESSAGE pStubMsg,
2867 unsigned char **ppMemory,
2868 PFORMAT_STRING pFormat,
2869 unsigned char fMustAlloc)
2871 FIXME("stub\n");
2872 return NULL;
2875 /***********************************************************************
2876 * NdrByteCountPointerBufferSize [RPCRT4.@]
2878 void WINAPI NdrByteCountPointerBufferSize(PMIDL_STUB_MESSAGE pStubMsg,
2879 unsigned char *pMemory,
2880 PFORMAT_STRING pFormat)
2882 FIXME("stub\n");
2885 /***********************************************************************
2886 * NdrByteCountPointerMemorySize [RPCRT4.@]
2888 unsigned long WINAPI NdrByteCountPointerMemorySize(PMIDL_STUB_MESSAGE pStubMsg,
2889 PFORMAT_STRING pFormat)
2891 FIXME("stub\n");
2892 return 0;
2895 /***********************************************************************
2896 * NdrByteCountPointerFree [RPCRT4.@]
2898 void WINAPI NdrByteCountPointerFree(PMIDL_STUB_MESSAGE pStubMsg,
2899 unsigned char *pMemory,
2900 PFORMAT_STRING pFormat)
2902 FIXME("stub\n");
2905 /***********************************************************************
2906 * NdrXmitOrRepAsMarshall [RPCRT4.@]
2908 unsigned char * WINAPI NdrXmitOrRepAsMarshall(PMIDL_STUB_MESSAGE pStubMsg,
2909 unsigned char *pMemory,
2910 PFORMAT_STRING pFormat)
2912 FIXME("stub\n");
2913 return NULL;
2916 /***********************************************************************
2917 * NdrXmitOrRepAsUnmarshall [RPCRT4.@]
2919 unsigned char * WINAPI NdrXmitOrRepAsUnmarshall(PMIDL_STUB_MESSAGE pStubMsg,
2920 unsigned char **ppMemory,
2921 PFORMAT_STRING pFormat,
2922 unsigned char fMustAlloc)
2924 FIXME("stub\n");
2925 return NULL;
2928 /***********************************************************************
2929 * NdrXmitOrRepAsBufferSize [RPCRT4.@]
2931 void WINAPI NdrXmitOrRepAsBufferSize(PMIDL_STUB_MESSAGE pStubMsg,
2932 unsigned char *pMemory,
2933 PFORMAT_STRING pFormat)
2935 FIXME("stub\n");
2938 /***********************************************************************
2939 * NdrXmitOrRepAsMemorySize [RPCRT4.@]
2941 unsigned long WINAPI NdrXmitOrRepAsMemorySize(PMIDL_STUB_MESSAGE pStubMsg,
2942 PFORMAT_STRING pFormat)
2944 FIXME("stub\n");
2945 return 0;
2948 /***********************************************************************
2949 * NdrXmitOrRepAsFree [RPCRT4.@]
2951 void WINAPI NdrXmitOrRepAsFree(PMIDL_STUB_MESSAGE pStubMsg,
2952 unsigned char *pMemory,
2953 PFORMAT_STRING pFormat)
2955 FIXME("stub\n");
2958 /***********************************************************************
2959 * NdrBaseTypeMarshall [internal]
2961 static unsigned char *WINAPI NdrBaseTypeMarshall(
2962 PMIDL_STUB_MESSAGE pStubMsg,
2963 unsigned char *pMemory,
2964 PFORMAT_STRING pFormat)
2966 TRACE("pStubMsg %p, pMemory %p, type 0x%02x\n", pStubMsg, pMemory, *pFormat);
2968 switch(*pFormat)
2970 case RPC_FC_BYTE:
2971 case RPC_FC_CHAR:
2972 case RPC_FC_SMALL:
2973 case RPC_FC_USMALL:
2974 *(UCHAR *)pStubMsg->Buffer = *(UCHAR *)pMemory;
2975 pStubMsg->Buffer += sizeof(UCHAR);
2976 TRACE("value: 0x%02x\n", *(UCHAR *)pMemory);
2977 break;
2978 case RPC_FC_WCHAR:
2979 case RPC_FC_SHORT:
2980 case RPC_FC_USHORT:
2981 ALIGN_POINTER(pStubMsg->Buffer, sizeof(USHORT) - 1);
2982 *(USHORT *)pStubMsg->Buffer = *(USHORT *)pMemory;
2983 pStubMsg->Buffer += sizeof(USHORT);
2984 TRACE("value: 0x%04x\n", *(USHORT *)pMemory);
2985 break;
2986 case RPC_FC_LONG:
2987 case RPC_FC_ULONG:
2988 case RPC_FC_ERROR_STATUS_T:
2989 case RPC_FC_ENUM32:
2990 ALIGN_POINTER(pStubMsg->Buffer, sizeof(ULONG) - 1);
2991 *(ULONG *)pStubMsg->Buffer = *(ULONG *)pMemory;
2992 pStubMsg->Buffer += sizeof(ULONG);
2993 TRACE("value: 0x%08lx\n", *(ULONG *)pMemory);
2994 break;
2995 case RPC_FC_FLOAT:
2996 ALIGN_POINTER(pStubMsg->Buffer, sizeof(float) - 1);
2997 *(float *)pStubMsg->Buffer = *(float *)pMemory;
2998 pStubMsg->Buffer += sizeof(float);
2999 break;
3000 case RPC_FC_DOUBLE:
3001 ALIGN_POINTER(pStubMsg->Buffer, sizeof(double) - 1);
3002 *(double *)pStubMsg->Buffer = *(double *)pMemory;
3003 pStubMsg->Buffer += sizeof(double);
3004 break;
3005 case RPC_FC_HYPER:
3006 ALIGN_POINTER(pStubMsg->Buffer, sizeof(ULONGLONG) - 1);
3007 *(ULONGLONG *)pStubMsg->Buffer = *(ULONGLONG *)pMemory;
3008 pStubMsg->Buffer += sizeof(ULONGLONG);
3009 TRACE("value: %s\n", wine_dbgstr_longlong(*(ULONGLONG*)pMemory));
3010 break;
3011 case RPC_FC_ENUM16:
3012 /* only 16-bits on the wire, so do a sanity check */
3013 if (*(UINT *)pMemory > USHRT_MAX)
3014 RpcRaiseException(RPC_X_ENUM_VALUE_OUT_OF_RANGE);
3015 ALIGN_POINTER(pStubMsg->Buffer, sizeof(USHORT) - 1);
3016 *(USHORT *)pStubMsg->Buffer = *(UINT *)pMemory;
3017 pStubMsg->Buffer += sizeof(USHORT);
3018 TRACE("value: 0x%04x\n", *(UINT *)pMemory);
3019 break;
3020 default:
3021 FIXME("Unhandled base type: 0x%02x\n", *pFormat);
3024 STD_OVERFLOW_CHECK(pStubMsg);
3026 /* FIXME: what is the correct return value? */
3027 return NULL;
3030 /***********************************************************************
3031 * NdrBaseTypeUnmarshall [internal]
3033 static unsigned char *WINAPI NdrBaseTypeUnmarshall(
3034 PMIDL_STUB_MESSAGE pStubMsg,
3035 unsigned char **ppMemory,
3036 PFORMAT_STRING pFormat,
3037 unsigned char fMustAlloc)
3039 TRACE("pStubMsg: %p, ppMemory: %p, type: 0x%02x, fMustAlloc: %s\n", pStubMsg, ppMemory, *pFormat, fMustAlloc ? "true" : "false");
3041 if (fMustAlloc || !*ppMemory)
3042 *ppMemory = NdrAllocate(pStubMsg, NdrBaseTypeMemorySize(pStubMsg, pFormat));
3044 TRACE("*ppMemory: %p\n", *ppMemory);
3046 switch(*pFormat)
3048 case RPC_FC_BYTE:
3049 case RPC_FC_CHAR:
3050 case RPC_FC_SMALL:
3051 case RPC_FC_USMALL:
3052 **(UCHAR **)ppMemory = *(UCHAR *)pStubMsg->Buffer;
3053 pStubMsg->Buffer += sizeof(UCHAR);
3054 TRACE("value: 0x%02x\n", **(UCHAR **)ppMemory);
3055 break;
3056 case RPC_FC_WCHAR:
3057 case RPC_FC_SHORT:
3058 case RPC_FC_USHORT:
3059 ALIGN_POINTER(pStubMsg->Buffer, sizeof(USHORT) - 1);
3060 **(USHORT **)ppMemory = *(USHORT *)pStubMsg->Buffer;
3061 pStubMsg->Buffer += sizeof(USHORT);
3062 TRACE("value: 0x%04x\n", **(USHORT **)ppMemory);
3063 break;
3064 case RPC_FC_LONG:
3065 case RPC_FC_ULONG:
3066 case RPC_FC_ERROR_STATUS_T:
3067 case RPC_FC_ENUM32:
3068 ALIGN_POINTER(pStubMsg->Buffer, sizeof(ULONG) - 1);
3069 **(ULONG **)ppMemory = *(ULONG *)pStubMsg->Buffer;
3070 pStubMsg->Buffer += sizeof(ULONG);
3071 TRACE("value: 0x%08lx\n", **(ULONG **)ppMemory);
3072 break;
3073 case RPC_FC_FLOAT:
3074 ALIGN_POINTER(pStubMsg->Buffer, sizeof(float) - 1);
3075 **(float **)ppMemory = *(float *)pStubMsg->Buffer;
3076 pStubMsg->Buffer += sizeof(float);
3077 TRACE("value: %f\n", **(float **)ppMemory);
3078 break;
3079 case RPC_FC_DOUBLE:
3080 ALIGN_POINTER(pStubMsg->Buffer, sizeof(double) - 1);
3081 **(double **)ppMemory = *(double*)pStubMsg->Buffer;
3082 pStubMsg->Buffer += sizeof(double);
3083 TRACE("value: %f\n", **(double **)ppMemory);
3084 break;
3085 case RPC_FC_HYPER:
3086 ALIGN_POINTER(pStubMsg->Buffer, sizeof(ULONGLONG) - 1);
3087 **(ULONGLONG **)ppMemory = *(ULONGLONG *)pStubMsg->Buffer;
3088 pStubMsg->Buffer += sizeof(ULONGLONG);
3089 TRACE("value: %s\n", wine_dbgstr_longlong(**(ULONGLONG **)ppMemory));
3090 break;
3091 case RPC_FC_ENUM16:
3092 ALIGN_POINTER(pStubMsg->Buffer, sizeof(USHORT) - 1);
3093 /* 16-bits on the wire, but int in memory */
3094 **(UINT **)ppMemory = *(USHORT *)pStubMsg->Buffer;
3095 pStubMsg->Buffer += sizeof(USHORT);
3096 TRACE("value: 0x%08x\n", **(UINT **)ppMemory);
3097 break;
3098 default:
3099 FIXME("Unhandled base type: 0x%02x\n", *pFormat);
3102 /* FIXME: what is the correct return value? */
3104 return NULL;
3107 /***********************************************************************
3108 * NdrBaseTypeBufferSize [internal]
3110 static void WINAPI NdrBaseTypeBufferSize(
3111 PMIDL_STUB_MESSAGE pStubMsg,
3112 unsigned char *pMemory,
3113 PFORMAT_STRING pFormat)
3115 TRACE("pStubMsg %p, pMemory %p, type 0x%02x\n", pStubMsg, pMemory, *pFormat);
3117 switch(*pFormat)
3119 case RPC_FC_BYTE:
3120 case RPC_FC_CHAR:
3121 case RPC_FC_SMALL:
3122 case RPC_FC_USMALL:
3123 pStubMsg->BufferLength += sizeof(UCHAR);
3124 break;
3125 case RPC_FC_WCHAR:
3126 case RPC_FC_SHORT:
3127 case RPC_FC_USHORT:
3128 case RPC_FC_ENUM16:
3129 ALIGN_LENGTH(pStubMsg->BufferLength, sizeof(USHORT) - 1);
3130 pStubMsg->BufferLength += sizeof(USHORT);
3131 break;
3132 case RPC_FC_LONG:
3133 case RPC_FC_ULONG:
3134 case RPC_FC_ENUM32:
3135 ALIGN_LENGTH(pStubMsg->BufferLength, sizeof(ULONG) - 1);
3136 pStubMsg->BufferLength += sizeof(ULONG);
3137 break;
3138 case RPC_FC_FLOAT:
3139 ALIGN_LENGTH(pStubMsg->BufferLength, sizeof(float) - 1);
3140 pStubMsg->BufferLength += sizeof(float);
3141 break;
3142 case RPC_FC_DOUBLE:
3143 ALIGN_LENGTH(pStubMsg->BufferLength, sizeof(double) - 1);
3144 pStubMsg->BufferLength += sizeof(double);
3145 break;
3146 case RPC_FC_HYPER:
3147 ALIGN_LENGTH(pStubMsg->BufferLength, sizeof(ULONGLONG) - 1);
3148 pStubMsg->BufferLength += sizeof(ULONGLONG);
3149 break;
3150 case RPC_FC_ERROR_STATUS_T:
3151 ALIGN_LENGTH(pStubMsg->BufferLength, sizeof(error_status_t) - 1);
3152 pStubMsg->BufferLength += sizeof(error_status_t);
3153 break;
3154 default:
3155 FIXME("Unhandled base type: 0x%02x\n", *pFormat);
3159 /***********************************************************************
3160 * NdrBaseTypeMemorySize [internal]
3162 static unsigned long WINAPI NdrBaseTypeMemorySize(
3163 PMIDL_STUB_MESSAGE pStubMsg,
3164 PFORMAT_STRING pFormat)
3166 switch(*pFormat)
3168 case RPC_FC_BYTE:
3169 case RPC_FC_CHAR:
3170 case RPC_FC_SMALL:
3171 case RPC_FC_USMALL:
3172 return sizeof(UCHAR);
3173 case RPC_FC_WCHAR:
3174 case RPC_FC_SHORT:
3175 case RPC_FC_USHORT:
3176 return sizeof(USHORT);
3177 case RPC_FC_LONG:
3178 case RPC_FC_ULONG:
3179 return sizeof(ULONG);
3180 case RPC_FC_FLOAT:
3181 return sizeof(float);
3182 case RPC_FC_DOUBLE:
3183 return sizeof(double);
3184 case RPC_FC_HYPER:
3185 return sizeof(ULONGLONG);
3186 case RPC_FC_ERROR_STATUS_T:
3187 return sizeof(error_status_t);
3188 case RPC_FC_ENUM16:
3189 case RPC_FC_ENUM32:
3190 return sizeof(INT);
3191 default:
3192 FIXME("Unhandled base type: 0x%02x\n", *pFormat);
3193 return 0;
3197 /***********************************************************************
3198 * NdrBaseTypeFree [internal]
3200 static void WINAPI NdrBaseTypeFree(PMIDL_STUB_MESSAGE pStubMsg,
3201 unsigned char *pMemory,
3202 PFORMAT_STRING pFormat)
3204 TRACE("pStubMsg %p pMemory %p type 0x%02x\n", pStubMsg, pMemory, *pFormat);
3206 /* nothing to do */
3209 /***********************************************************************
3210 * NdrClientContextMarshall
3212 void WINAPI NdrClientContextMarshall(PMIDL_STUB_MESSAGE pStubMsg,
3213 NDR_CCONTEXT ContextHandle,
3214 int fCheck)
3216 FIXME("(%p, %p, %d): stub\n", pStubMsg, ContextHandle, fCheck);
3219 /***********************************************************************
3220 * NdrClientContextUnmarshall
3222 void WINAPI NdrClientContextUnmarshall(PMIDL_STUB_MESSAGE pStubMsg,
3223 NDR_CCONTEXT * pContextHandle,
3224 RPC_BINDING_HANDLE BindHandle)
3226 FIXME("(%p, %p, %p): stub\n", pStubMsg, pContextHandle, BindHandle);
3229 void WINAPI NdrServerContextMarshall(PMIDL_STUB_MESSAGE pStubMsg,
3230 NDR_SCONTEXT ContextHandle,
3231 NDR_RUNDOWN RundownRoutine )
3233 FIXME("(%p, %p, %p): stub\n", pStubMsg, ContextHandle, RundownRoutine);
3236 NDR_SCONTEXT WINAPI NdrServerContextUnmarshall(PMIDL_STUB_MESSAGE pStubMsg)
3238 FIXME("(%p): stub\n", pStubMsg);
3239 return NULL;
3242 void WINAPI NdrContextHandleSize(PMIDL_STUB_MESSAGE pStubMsg,
3243 unsigned char* pMemory,
3244 PFORMAT_STRING pFormat)
3246 FIXME("(%p, %p, %p): stub\n", pStubMsg, pMemory, pFormat);
3249 NDR_SCONTEXT WINAPI NdrContextHandleInitialize(PMIDL_STUB_MESSAGE pStubMsg,
3250 PFORMAT_STRING pFormat)
3252 FIXME("(%p, %p): stub\n", pStubMsg, pFormat);
3253 return NULL;
3256 void WINAPI NdrServerContextNewMarshall(PMIDL_STUB_MESSAGE pStubMsg,
3257 NDR_SCONTEXT ContextHandle,
3258 NDR_RUNDOWN RundownRoutine,
3259 PFORMAT_STRING pFormat)
3261 FIXME("(%p, %p, %p, %p): stub\n", pStubMsg, ContextHandle, RundownRoutine, pFormat);
3264 NDR_SCONTEXT WINAPI NdrServerContextNewUnmarshall(PMIDL_STUB_MESSAGE pStubMsg,
3265 PFORMAT_STRING pFormat)
3267 FIXME("(%p, %p): stub\n", pStubMsg, pFormat);
3268 return NULL;
3271 RPC_BINDING_HANDLE WINAPI NDRCContextBinding(NDR_CCONTEXT CContext)
3273 FIXME("(%p): stub\n", CContext);
3274 return NULL;