42b72e3b77aaf8175df03a3f1395d37585f72696
[reactos.git] / reactos / lib / rpcrt4 / ndr_marshall.c
1 /*
2 * NDR data marshalling
3 *
4 * Copyright 2002 Greg Turner
5 *
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.
10 *
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.
15 *
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
19 *
20 * TODO:
21 * - figure out whether we *really* got this right
22 * - check for errors and throw exceptions
23 */
24
25 #include <stdarg.h>
26 #include <stdio.h>
27 #include <string.h>
28 #include <assert.h>
29
30 #include "windef.h"
31 #include "winbase.h"
32 #include "winerror.h"
33 #include "winreg.h"
34
35 #include "ndr_misc.h"
36 #include "rpcndr.h"
37
38 #include "wine/unicode.h"
39 #include "wine/rpcfc.h"
40
41 #include "wine/debug.h"
42
43 WINE_DEFAULT_DEBUG_CHANNEL(ole);
44
45 #define BUFFER_PARANOIA 20
46
47 #if defined(__i386__)
48 # define LITTLE_ENDIAN_UINT32_WRITE(pchar, uint32) \
49 (*((UINT32 *)(pchar)) = (uint32))
50
51 # define LITTLE_ENDIAN_UINT32_READ(pchar) \
52 (*((UINT32 *)(pchar)))
53 #else
54 /* these would work for i386 too, but less efficient */
55 # define LITTLE_ENDIAN_UINT32_WRITE(pchar, uint32) \
56 (*(pchar) = LOBYTE(LOWORD(uint32)), \
57 *((pchar)+1) = HIBYTE(LOWORD(uint32)), \
58 *((pchar)+2) = LOBYTE(HIWORD(uint32)), \
59 *((pchar)+3) = HIBYTE(HIWORD(uint32)), \
60 (uint32)) /* allow as r-value */
61
62 # define LITTLE_ENDIAN_UINT32_READ(pchar) \
63 (MAKELONG( \
64 MAKEWORD(*(pchar), *((pchar)+1)), \
65 MAKEWORD(*((pchar)+2), *((pchar)+3))))
66 #endif
67
68 #define BIG_ENDIAN_UINT32_WRITE(pchar, uint32) \
69 (*((pchar)+3) = LOBYTE(LOWORD(uint32)), \
70 *((pchar)+2) = HIBYTE(LOWORD(uint32)), \
71 *((pchar)+1) = LOBYTE(HIWORD(uint32)), \
72 *(pchar) = HIBYTE(HIWORD(uint32)), \
73 (uint32)) /* allow as r-value */
74
75 #define BIG_ENDIAN_UINT32_READ(pchar) \
76 (MAKELONG( \
77 MAKEWORD(*((pchar)+3), *((pchar)+2)), \
78 MAKEWORD(*((pchar)+1), *(pchar))))
79
80 #ifdef NDR_LOCAL_IS_BIG_ENDIAN
81 # define NDR_LOCAL_UINT32_WRITE(pchar, uint32) \
82 BIG_ENDIAN_UINT32_WRITE(pchar, uint32)
83 # define NDR_LOCAL_UINT32_READ(pchar) \
84 BIG_ENDIAN_UINT32_READ(pchar)
85 #else
86 # define NDR_LOCAL_UINT32_WRITE(pchar, uint32) \
87 LITTLE_ENDIAN_UINT32_WRITE(pchar, uint32)
88 # define NDR_LOCAL_UINT32_READ(pchar) \
89 LITTLE_ENDIAN_UINT32_READ(pchar)
90 #endif
91
92 /* _Align must be the desired alignment minus 1,
93 * e.g. ALIGN_LENGTH(len, 3) to align on a dword boundary. */
94 #define ALIGNED_LENGTH(_Len, _Align) (((_Len)+(_Align))&~(_Align))
95 #define ALIGNED_POINTER(_Ptr, _Align) ((LPVOID)ALIGNED_LENGTH((ULONG_PTR)(_Ptr), _Align))
96 #define ALIGN_LENGTH(_Len, _Align) _Len = ALIGNED_LENGTH(_Len, _Align)
97 #define ALIGN_POINTER(_Ptr, _Align) _Ptr = ALIGNED_POINTER(_Ptr, _Align)
98
99 #define STD_OVERFLOW_CHECK(_Msg) do { \
100 TRACE("buffer=%d/%ld\n", _Msg->Buffer - (unsigned char *)_Msg->RpcMsg->Buffer, _Msg->BufferLength); \
101 if (_Msg->Buffer > (unsigned char *)_Msg->RpcMsg->Buffer + _Msg->BufferLength) \
102 ERR("buffer overflow %d bytes\n", _Msg->Buffer - ((unsigned char *)_Msg->RpcMsg->Buffer + _Msg->BufferLength)); \
103 } while (0)
104
105 #define NDR_TABLE_SIZE 128
106 #define NDR_TABLE_MASK 127
107
108 static unsigned char *WINAPI NdrBaseTypeMarshall(PMIDL_STUB_MESSAGE, unsigned char *, PFORMAT_STRING);
109 static unsigned char *WINAPI NdrBaseTypeUnmarshall(PMIDL_STUB_MESSAGE, unsigned char **, PFORMAT_STRING, unsigned char);
110 static void WINAPI NdrBaseTypeBufferSize(PMIDL_STUB_MESSAGE, unsigned char *, PFORMAT_STRING);
111 static void WINAPI NdrBaseTypeFree(PMIDL_STUB_MESSAGE, unsigned char *, PFORMAT_STRING);
112 static unsigned long WINAPI NdrBaseTypeMemorySize(PMIDL_STUB_MESSAGE, PFORMAT_STRING);
113
114 NDR_MARSHALL NdrMarshaller[NDR_TABLE_SIZE] = {
115 0,
116 NdrBaseTypeMarshall, NdrBaseTypeMarshall, NdrBaseTypeMarshall,
117 NdrBaseTypeMarshall, NdrBaseTypeMarshall, NdrBaseTypeMarshall, NdrBaseTypeMarshall,
118 NdrBaseTypeMarshall, NdrBaseTypeMarshall, NdrBaseTypeMarshall, NdrBaseTypeMarshall,
119 NdrBaseTypeMarshall, NdrBaseTypeMarshall, NdrBaseTypeMarshall, NdrBaseTypeMarshall,
120 /* 0x10 */
121 NdrBaseTypeMarshall,
122 /* 0x11 */
123 NdrPointerMarshall, NdrPointerMarshall,
124 NdrPointerMarshall, NdrPointerMarshall,
125 /* 0x15 */
126 NdrSimpleStructMarshall, NdrSimpleStructMarshall,
127 NdrConformantStructMarshall, NdrConformantStructMarshall,
128 NdrConformantVaryingStructMarshall,
129 NdrComplexStructMarshall,
130 /* 0x1b */
131 NdrConformantArrayMarshall,
132 NdrConformantVaryingArrayMarshall,
133 NdrFixedArrayMarshall, NdrFixedArrayMarshall,
134 NdrVaryingArrayMarshall, NdrVaryingArrayMarshall,
135 NdrComplexArrayMarshall,
136 /* 0x22 */
137 NdrConformantStringMarshall, 0, 0,
138 NdrConformantStringMarshall,
139 NdrNonConformantStringMarshall, 0, 0, 0,
140 /* 0x2a */
141 NdrEncapsulatedUnionMarshall,
142 NdrNonEncapsulatedUnionMarshall,
143 0,
144 NdrXmitOrRepAsMarshall, NdrXmitOrRepAsMarshall,
145 /* 0x2f */
146 NdrInterfacePointerMarshall,
147 /* 0xb0 */
148 0, 0, 0, 0,
149 NdrUserMarshalMarshall
150 };
151 NDR_UNMARSHALL NdrUnmarshaller[NDR_TABLE_SIZE] = {
152 0,
153 NdrBaseTypeUnmarshall, NdrBaseTypeUnmarshall, NdrBaseTypeUnmarshall,
154 NdrBaseTypeUnmarshall, NdrBaseTypeUnmarshall, NdrBaseTypeUnmarshall, NdrBaseTypeUnmarshall,
155 NdrBaseTypeUnmarshall, NdrBaseTypeUnmarshall, NdrBaseTypeUnmarshall, NdrBaseTypeUnmarshall,
156 NdrBaseTypeUnmarshall, NdrBaseTypeUnmarshall, NdrBaseTypeUnmarshall, NdrBaseTypeUnmarshall,
157 /* 0x10 */
158 NdrBaseTypeUnmarshall,
159 /* 0x11 */
160 NdrPointerUnmarshall, NdrPointerUnmarshall,
161 NdrPointerUnmarshall, NdrPointerUnmarshall,
162 /* 0x15 */
163 NdrSimpleStructUnmarshall, NdrSimpleStructUnmarshall,
164 NdrConformantStructUnmarshall, NdrConformantStructUnmarshall,
165 NdrConformantVaryingStructUnmarshall,
166 NdrComplexStructUnmarshall,
167 /* 0x1b */
168 NdrConformantArrayUnmarshall,
169 NdrConformantVaryingArrayUnmarshall,
170 NdrFixedArrayUnmarshall, NdrFixedArrayUnmarshall,
171 NdrVaryingArrayUnmarshall, NdrVaryingArrayUnmarshall,
172 NdrComplexArrayUnmarshall,
173 /* 0x22 */
174 NdrConformantStringUnmarshall, 0, 0,
175 NdrConformantStringUnmarshall,
176 NdrNonConformantStringUnmarshall, 0, 0, 0,
177 /* 0x2a */
178 NdrEncapsulatedUnionUnmarshall,
179 NdrNonEncapsulatedUnionUnmarshall,
180 0,
181 NdrXmitOrRepAsUnmarshall, NdrXmitOrRepAsUnmarshall,
182 /* 0x2f */
183 NdrInterfacePointerUnmarshall,
184 /* 0xb0 */
185 0, 0, 0, 0,
186 NdrUserMarshalUnmarshall
187 };
188 NDR_BUFFERSIZE NdrBufferSizer[NDR_TABLE_SIZE] = {
189 0,
190 NdrBaseTypeBufferSize, NdrBaseTypeBufferSize, NdrBaseTypeBufferSize,
191 NdrBaseTypeBufferSize, NdrBaseTypeBufferSize, NdrBaseTypeBufferSize, NdrBaseTypeBufferSize,
192 NdrBaseTypeBufferSize, NdrBaseTypeBufferSize, NdrBaseTypeBufferSize, NdrBaseTypeBufferSize,
193 NdrBaseTypeBufferSize, NdrBaseTypeBufferSize, NdrBaseTypeBufferSize, NdrBaseTypeBufferSize,
194 /* 0x10 */
195 NdrBaseTypeBufferSize,
196 /* 0x11 */
197 NdrPointerBufferSize, NdrPointerBufferSize,
198 NdrPointerBufferSize, NdrPointerBufferSize,
199 /* 0x15 */
200 NdrSimpleStructBufferSize, NdrSimpleStructBufferSize,
201 NdrConformantStructBufferSize, NdrConformantStructBufferSize,
202 NdrConformantVaryingStructBufferSize,
203 NdrComplexStructBufferSize,
204 /* 0x1b */
205 NdrConformantArrayBufferSize,
206 NdrConformantVaryingArrayBufferSize,
207 NdrFixedArrayBufferSize, NdrFixedArrayBufferSize,
208 NdrVaryingArrayBufferSize, NdrVaryingArrayBufferSize,
209 NdrComplexArrayBufferSize,
210 /* 0x22 */
211 NdrConformantStringBufferSize, 0, 0,
212 NdrConformantStringBufferSize,
213 NdrNonConformantStringBufferSize, 0, 0, 0,
214 /* 0x2a */
215 NdrEncapsulatedUnionBufferSize,
216 NdrNonEncapsulatedUnionBufferSize,
217 0,
218 NdrXmitOrRepAsBufferSize, NdrXmitOrRepAsBufferSize,
219 /* 0x2f */
220 NdrInterfacePointerBufferSize,
221 /* 0xb0 */
222 0, 0, 0, 0,
223 NdrUserMarshalBufferSize
224 };
225 NDR_MEMORYSIZE NdrMemorySizer[NDR_TABLE_SIZE] = {
226 0,
227 NdrBaseTypeMemorySize, NdrBaseTypeMemorySize, NdrBaseTypeMemorySize,
228 NdrBaseTypeMemorySize, NdrBaseTypeMemorySize, NdrBaseTypeMemorySize, NdrBaseTypeMemorySize,
229 NdrBaseTypeMemorySize, NdrBaseTypeMemorySize, NdrBaseTypeMemorySize, NdrBaseTypeMemorySize,
230 NdrBaseTypeMemorySize, NdrBaseTypeMemorySize, NdrBaseTypeMemorySize, NdrBaseTypeMemorySize,
231 /* 0x10 */
232 NdrBaseTypeMemorySize,
233 /* 0x11 */
234 NdrPointerMemorySize, NdrPointerMemorySize,
235 NdrPointerMemorySize, NdrPointerMemorySize,
236 /* 0x15 */
237 NdrSimpleStructMemorySize, NdrSimpleStructMemorySize,
238 0, 0, 0,
239 NdrComplexStructMemorySize,
240 /* 0x1b */
241 NdrConformantArrayMemorySize, 0, 0, 0, 0, 0,
242 NdrComplexArrayMemorySize,
243 /* 0x22 */
244 NdrConformantStringMemorySize, 0, 0,
245 NdrConformantStringMemorySize,
246 NdrNonConformantStringMemorySize, 0, 0, 0,
247 /* 0x2a */
248 0, 0, 0, 0, 0,
249 /* 0x2f */
250 NdrInterfacePointerMemorySize,
251 /* 0xb0 */
252 0, 0, 0, 0,
253 NdrUserMarshalMemorySize
254 };
255 NDR_FREE NdrFreer[NDR_TABLE_SIZE] = {
256 0,
257 NdrBaseTypeFree, NdrBaseTypeFree, NdrBaseTypeFree,
258 NdrBaseTypeFree, NdrBaseTypeFree, NdrBaseTypeFree, NdrBaseTypeFree,
259 NdrBaseTypeFree, NdrBaseTypeFree, NdrBaseTypeFree, NdrBaseTypeFree,
260 NdrBaseTypeFree, NdrBaseTypeFree, NdrBaseTypeFree, NdrBaseTypeFree,
261 /* 0x10 */
262 NdrBaseTypeFree,
263 /* 0x11 */
264 NdrPointerFree, NdrPointerFree,
265 NdrPointerFree, NdrPointerFree,
266 /* 0x15 */
267 NdrSimpleStructFree, NdrSimpleStructFree,
268 NdrConformantStructFree, NdrConformantStructFree,
269 NdrConformantVaryingStructFree,
270 NdrComplexStructFree,
271 /* 0x1b */
272 NdrConformantArrayFree,
273 NdrConformantVaryingArrayFree,
274 NdrFixedArrayFree, NdrFixedArrayFree,
275 NdrVaryingArrayFree, NdrVaryingArrayFree,
276 NdrComplexArrayFree,
277 /* 0x22 */
278 0, 0, 0,
279 0, 0, 0, 0, 0,
280 /* 0x2a */
281 NdrEncapsulatedUnionFree,
282 NdrNonEncapsulatedUnionFree,
283 0,
284 NdrXmitOrRepAsFree, NdrXmitOrRepAsFree,
285 /* 0x2f */
286 NdrInterfacePointerFree,
287 /* 0xb0 */
288 0, 0, 0, 0,
289 NdrUserMarshalFree
290 };
291
292 void * WINAPI NdrAllocate(MIDL_STUB_MESSAGE *pStubMsg, size_t len)
293 {
294 /* hmm, this is probably supposed to do more? */
295 return pStubMsg->pfnAllocate(len);
296 }
297
298 static void WINAPI NdrFree(MIDL_STUB_MESSAGE *pStubMsg, unsigned char *Pointer)
299 {
300 pStubMsg->pfnFree(Pointer);
301 }
302
303 PFORMAT_STRING ReadConformance(MIDL_STUB_MESSAGE *pStubMsg, PFORMAT_STRING pFormat)
304 {
305 pStubMsg->MaxCount = NDR_LOCAL_UINT32_READ(pStubMsg->Buffer);
306 pStubMsg->Buffer += 4;
307 TRACE("unmarshalled conformance is %ld\n", pStubMsg->MaxCount);
308 return pFormat+4;
309 }
310
311 static inline PFORMAT_STRING ReadVariance(MIDL_STUB_MESSAGE *pStubMsg, PFORMAT_STRING pFormat)
312 {
313 pStubMsg->ActualCount = NDR_LOCAL_UINT32_READ(pStubMsg->Buffer);
314 pStubMsg->Buffer += 4;
315 TRACE("unmarshalled variance is %ld\n", pStubMsg->ActualCount);
316 return pFormat+4;
317 }
318
319 PFORMAT_STRING ComputeConformanceOrVariance(
320 MIDL_STUB_MESSAGE *pStubMsg, unsigned char *pMemory,
321 PFORMAT_STRING pFormat, ULONG_PTR def, ULONG *pCount)
322 {
323 BYTE dtype = pFormat[0] & 0xf;
324 short ofs = *(short *)&pFormat[2];
325 LPVOID ptr = NULL;
326 DWORD data = 0;
327
328 /* FIXME: is this correct? */
329 if (pFormat[0] == 0xff) {
330 /* null descriptor */
331 *pCount = def;
332 goto finish_conf;
333 }
334
335 switch (pFormat[0] & 0xf0) {
336 case RPC_FC_NORMAL_CONFORMANCE:
337 TRACE("normal conformance, ofs=%d\n", ofs);
338 ptr = pMemory + ofs;
339 break;
340 case RPC_FC_POINTER_CONFORMANCE:
341 TRACE("pointer conformance, ofs=%d\n", ofs);
342 ptr = pStubMsg->Memory + ofs;
343 break;
344 case RPC_FC_TOP_LEVEL_CONFORMANCE:
345 TRACE("toplevel conformance, ofs=%d\n", ofs);
346 if (pStubMsg->StackTop) {
347 ptr = pStubMsg->StackTop + ofs;
348 }
349 else {
350 /* -Os mode, *pCount is already set */
351 goto finish_conf;
352 }
353 break;
354 case RPC_FC_CONSTANT_CONFORMANCE:
355 data = ofs | ((DWORD)pFormat[1] << 16);
356 TRACE("constant conformance, val=%ld\n", data);
357 *pCount = data;
358 goto finish_conf;
359 case RPC_FC_TOP_LEVEL_MULTID_CONFORMANCE:
360 FIXME("toplevel multidimensional conformance, ofs=%d\n", ofs);
361 if (pStubMsg->StackTop) {
362 ptr = pStubMsg->StackTop + ofs;
363 }
364 else {
365 /* ? */
366 goto done_conf_grab;
367 }
368 break;
369 default:
370 FIXME("unknown conformance type %x\n", pFormat[0] & 0xf0);
371 }
372
373 switch (pFormat[1]) {
374 case RPC_FC_DEREFERENCE:
375 ptr = *(LPVOID*)ptr;
376 break;
377 case RPC_FC_CALLBACK:
378 /* ofs is index into StubDesc->apfnExprEval */
379 FIXME("handle callback\n");
380 goto finish_conf;
381 default:
382 break;
383 }
384
385 switch (dtype) {
386 case RPC_FC_LONG:
387 case RPC_FC_ULONG:
388 data = *(DWORD*)ptr;
389 break;
390 case RPC_FC_SHORT:
391 data = *(SHORT*)ptr;
392 break;
393 case RPC_FC_USHORT:
394 data = *(USHORT*)ptr;
395 break;
396 case RPC_FC_SMALL:
397 data = *(CHAR*)ptr;
398 break;
399 case RPC_FC_USMALL:
400 data = *(UCHAR*)ptr;
401 break;
402 default:
403 FIXME("unknown conformance data type %x\n", dtype);
404 goto done_conf_grab;
405 }
406 TRACE("dereferenced data type %x at %p, got %ld\n", dtype, ptr, data);
407
408 done_conf_grab:
409 switch (pFormat[1]) {
410 case 0: /* no op */
411 *pCount = data;
412 break;
413 case RPC_FC_DEREFERENCE:
414 /* already handled */
415 break;
416 default:
417 FIXME("unknown conformance op %d\n", pFormat[1]);
418 goto finish_conf;
419 }
420
421 finish_conf:
422 TRACE("resulting conformance is %ld\n", *pCount);
423 return pFormat+4;
424 }
425
426
427 /*
428 * NdrConformantString:
429 *
430 * What MS calls a ConformantString is, in DCE terminology,
431 * a Varying-Conformant String.
432 * [
433 * maxlen: DWORD (max # of CHARTYPE characters, inclusive of '\0')
434 * offset: DWORD (actual string data begins at (offset) CHARTYPE's
435 * into unmarshalled string)
436 * length: DWORD (# of CHARTYPE characters, inclusive of '\0')
437 * [
438 * data: CHARTYPE[maxlen]
439 * ]
440 * ], where CHARTYPE is the appropriate character type (specified externally)
441 *
442 */
443
444 /***********************************************************************
445 * NdrConformantStringMarshall [RPCRT4.@]
446 */
447 unsigned char *WINAPI NdrConformantStringMarshall(MIDL_STUB_MESSAGE *pStubMsg,
448 unsigned char *pszMessage, PFORMAT_STRING pFormat)
449 {
450 unsigned long len, esize;
451 unsigned char *c;
452
453 TRACE("(pStubMsg == ^%p, pszMessage == ^%p, pFormat == ^%p)\n", pStubMsg, pszMessage, pFormat);
454
455 assert(pFormat);
456 if (pszMessage == NULL) {
457 TRACE("string=%s\n", debugstr_a(pszMessage));
458 len = 0;
459 esize = 0;
460 }
461 else if (*pFormat == RPC_FC_C_CSTRING) {
462 TRACE("string=%s\n", debugstr_a(pszMessage));
463 len = strlen(pszMessage)+1;
464 esize = 1;
465 }
466 else if (*pFormat == RPC_FC_C_WSTRING) {
467 TRACE("string=%s\n", debugstr_w((LPWSTR)pszMessage));
468 len = strlenW((LPWSTR)pszMessage)+1;
469 esize = 2;
470 }
471 else {
472 ERR("Unhandled string type: %#x\n", *pFormat);
473 /* FIXME: raise an exception. */
474 return NULL;
475 }
476
477 if (pFormat[1] != RPC_FC_PAD) {
478 FIXME("sized string format=%d\n", pFormat[1]);
479 }
480
481 assert( (pStubMsg->BufferLength >= (len*esize + 13)) && (pStubMsg->Buffer != NULL) );
482
483 c = pStubMsg->Buffer;
484 memset(c, 0, 12);
485 NDR_LOCAL_UINT32_WRITE(c, len); /* max length: strlen + 1 (for '\0') */
486 c += 8; /* offset: 0 */
487 NDR_LOCAL_UINT32_WRITE(c, len); /* actual length: (same) */
488 c += 4;
489 if (len != 0) {
490 memcpy(c, pszMessage, len*esize); /* the string itself */
491 c += len*esize;
492 }
493 pStubMsg->Buffer = c;
494
495 STD_OVERFLOW_CHECK(pStubMsg);
496
497 /* success */
498 return NULL; /* is this always right? */
499 }
500
501 /***********************************************************************
502 * NdrConformantStringBufferSize [RPCRT4.@]
503 */
504 void WINAPI NdrConformantStringBufferSize(PMIDL_STUB_MESSAGE pStubMsg,
505 unsigned char* pMemory, PFORMAT_STRING pFormat)
506 {
507 TRACE("(pStubMsg == ^%p, pMemory == ^%p, pFormat == ^%p)\n", pStubMsg, pMemory, pFormat);
508
509 assert(pFormat);
510 if (pMemory == NULL) {
511 /* we need 12 octets for the [maxlen, offset, len] DWORDS */
512 TRACE("string=NULL\n");
513 pStubMsg->BufferLength += 12 + BUFFER_PARANOIA;
514 }
515 else if (*pFormat == RPC_FC_C_CSTRING) {
516 /* we need 12 octets for the [maxlen, offset, len] DWORDS, + 1 octet for '\0' */
517 TRACE("string=%s\n", debugstr_a((char*)pMemory));
518 pStubMsg->BufferLength += strlen((char*)pMemory) + 13 + BUFFER_PARANOIA;
519 }
520 else if (*pFormat == RPC_FC_C_WSTRING) {
521 /* we need 12 octets for the [maxlen, offset, len] DWORDS, + 2 octets for L'\0' */
522 TRACE("string=%s\n", debugstr_w((LPWSTR)pMemory));
523 pStubMsg->BufferLength += strlenW((LPWSTR)pMemory)*2 + 14 + BUFFER_PARANOIA;
524 }
525 else {
526 ERR("Unhandled string type: %#x\n", *pFormat);
527 /* FIXME: raise an exception */
528 }
529
530 if (pFormat[1] != RPC_FC_PAD) {
531 FIXME("sized string format=%d\n", pFormat[1]);
532 }
533 }
534
535 /************************************************************************
536 * NdrConformantStringMemorySize [RPCRT4.@]
537 */
538 unsigned long WINAPI NdrConformantStringMemorySize( PMIDL_STUB_MESSAGE pStubMsg,
539 PFORMAT_STRING pFormat )
540 {
541 unsigned long rslt = 0;
542
543 TRACE("(pStubMsg == ^%p, pFormat == ^%p)\n", pStubMsg, pFormat);
544
545 assert(pStubMsg && pFormat);
546
547 if (*pFormat == RPC_FC_C_CSTRING) {
548 rslt = NDR_LOCAL_UINT32_READ(pStubMsg->Buffer); /* maxlen */
549 }
550 else if (*pFormat == RPC_FC_C_WSTRING) {
551 rslt = NDR_LOCAL_UINT32_READ(pStubMsg->Buffer)*2; /* maxlen */
552 }
553 else {
554 ERR("Unhandled string type: %#x\n", *pFormat);
555 /* FIXME: raise an exception */
556 }
557
558 if (pFormat[1] != RPC_FC_PAD) {
559 FIXME("sized string format=%d\n", pFormat[1]);
560 }
561
562 TRACE(" --> %lu\n", rslt);
563 return rslt;
564 }
565
566 /************************************************************************
567 * NdrConformantStringUnmarshall [RPCRT4.@]
568 */
569 unsigned char *WINAPI NdrConformantStringUnmarshall( PMIDL_STUB_MESSAGE pStubMsg,
570 unsigned char** ppMemory, PFORMAT_STRING pFormat, unsigned char fMustAlloc )
571 {
572 unsigned long len, esize, ofs;
573
574 TRACE("(pStubMsg == ^%p, *pMemory == ^%p, pFormat == ^%p, fMustAlloc == %u)\n",
575 pStubMsg, *ppMemory, pFormat, fMustAlloc);
576
577 assert(pFormat && ppMemory && pStubMsg);
578
579 pStubMsg->Buffer += 4;
580 ofs = NDR_LOCAL_UINT32_READ(pStubMsg->Buffer);
581 pStubMsg->Buffer += 4;
582 len = NDR_LOCAL_UINT32_READ(pStubMsg->Buffer);
583 pStubMsg->Buffer += 4;
584
585 if (*pFormat == RPC_FC_C_CSTRING) esize = 1;
586 else if (*pFormat == RPC_FC_C_WSTRING) esize = 2;
587 else {
588 ERR("Unhandled string type: %#x\n", *pFormat);
589 /* FIXME: raise an exception */
590 esize = 0;
591 }
592
593 if (pFormat[1] != RPC_FC_PAD) {
594 FIXME("sized string format=%d\n", pFormat[1]);
595 }
596
597 if (fMustAlloc || !*ppMemory)
598 *ppMemory = NdrAllocate(pStubMsg, len*esize + BUFFER_PARANOIA);
599
600 memcpy(*ppMemory, pStubMsg->Buffer, len*esize);
601
602 pStubMsg->Buffer += len*esize;
603
604 if (*pFormat == RPC_FC_C_CSTRING) {
605 TRACE("string=%s\n", debugstr_a((char*)*ppMemory));
606 }
607 else if (*pFormat == RPC_FC_C_WSTRING) {
608 TRACE("string=%s\n", debugstr_w((LPWSTR)*ppMemory));
609 }
610
611 return NULL; /* FIXME: is this always right? */
612 }
613
614 /***********************************************************************
615 * NdrNonConformantStringMarshall [RPCRT4.@]
616 */
617 unsigned char * WINAPI NdrNonConformantStringMarshall(PMIDL_STUB_MESSAGE pStubMsg,
618 unsigned char *pMemory,
619 PFORMAT_STRING pFormat)
620 {
621 FIXME("stub\n");
622 return NULL;
623 }
624
625 /***********************************************************************
626 * NdrNonConformantStringUnmarshall [RPCRT4.@]
627 */
628 unsigned char * WINAPI NdrNonConformantStringUnmarshall(PMIDL_STUB_MESSAGE pStubMsg,
629 unsigned char **ppMemory,
630 PFORMAT_STRING pFormat,
631 unsigned char fMustAlloc)
632 {
633 FIXME("stub\n");
634 return NULL;
635 }
636
637 /***********************************************************************
638 * NdrNonConformantStringBufferSize [RPCRT4.@]
639 */
640 void WINAPI NdrNonConformantStringBufferSize(PMIDL_STUB_MESSAGE pStubMsg,
641 unsigned char *pMemory,
642 PFORMAT_STRING pFormat)
643 {
644 FIXME("stub\n");
645 }
646
647 /***********************************************************************
648 * NdrNonConformantStringMemorySize [RPCRT4.@]
649 */
650 unsigned long WINAPI NdrNonConformantStringMemorySize(PMIDL_STUB_MESSAGE pStubMsg,
651 PFORMAT_STRING pFormat)
652 {
653 FIXME("stub\n");
654 return 0;
655 }
656
657 static inline void dump_pointer_attr(unsigned char attr)
658 {
659 if (attr & RPC_FC_P_ALLOCALLNODES)
660 TRACE(" RPC_FC_P_ALLOCALLNODES");
661 if (attr & RPC_FC_P_DONTFREE)
662 TRACE(" RPC_FC_P_DONTFREE");
663 if (attr & RPC_FC_P_ONSTACK)
664 TRACE(" RPC_FC_P_ONSTACK");
665 if (attr & RPC_FC_P_SIMPLEPOINTER)
666 TRACE(" RPC_FC_P_SIMPLEPOINTER");
667 if (attr & RPC_FC_P_DEREF)
668 TRACE(" RPC_FC_P_DEREF");
669 TRACE("\n");
670 }
671
672 /***********************************************************************
673 * PointerMarshall
674 */
675 void WINAPI PointerMarshall(PMIDL_STUB_MESSAGE pStubMsg,
676 unsigned char *Buffer,
677 unsigned char *Pointer,
678 PFORMAT_STRING pFormat)
679 {
680 unsigned type = pFormat[0], attr = pFormat[1];
681 PFORMAT_STRING desc;
682 NDR_MARSHALL m;
683
684 TRACE("(%p,%p,%p,%p)\n", pStubMsg, Buffer, Pointer, pFormat);
685 TRACE("type=0x%x, attr=", type); dump_pointer_attr(attr);
686 pFormat += 2;
687 if (attr & RPC_FC_P_SIMPLEPOINTER) desc = pFormat;
688 else desc = pFormat + *(const SHORT*)pFormat;
689 if (attr & RPC_FC_P_DEREF) {
690 Pointer = *(unsigned char**)Pointer;
691 TRACE("deref => %p\n", Pointer);
692 }
693
694 switch (type) {
695 case RPC_FC_RP: /* ref pointer (always non-null) */
696 #if 0 /* this causes problems for InstallShield so is disabled - we need more tests */
697 if (!Pointer)
698 RpcRaiseException(RPC_X_NULL_REF_POINTER);
699 #endif
700 break;
701 case RPC_FC_UP: /* unique pointer */
702 case RPC_FC_OP: /* object pointer - same as unique here */
703 TRACE("writing %p to buffer\n", Pointer);
704 NDR_LOCAL_UINT32_WRITE(pStubMsg->Buffer, (unsigned long)Pointer);
705 pStubMsg->Buffer += 4;
706 break;
707 case RPC_FC_FP:
708 default:
709 FIXME("unhandled ptr type=%02x\n", type);
710 RpcRaiseException(RPC_X_BAD_STUB_DATA);
711 }
712
713 TRACE("calling marshaller for type 0x%x\n", (int)*desc);
714
715 if (Pointer) {
716 m = NdrMarshaller[*desc & NDR_TABLE_MASK];
717 if (m) m(pStubMsg, Pointer, desc);
718 else FIXME("no marshaller for data type=%02x\n", *desc);
719 }
720
721 STD_OVERFLOW_CHECK(pStubMsg);
722 }
723
724 /***********************************************************************
725 * PointerUnmarshall
726 */
727 void WINAPI PointerUnmarshall(PMIDL_STUB_MESSAGE pStubMsg,
728 unsigned char *Buffer,
729 unsigned char **pPointer,
730 PFORMAT_STRING pFormat,
731 unsigned char fMustAlloc)
732 {
733 unsigned type = pFormat[0], attr = pFormat[1];
734 PFORMAT_STRING desc;
735 NDR_UNMARSHALL m;
736 DWORD pointer_id = 0;
737
738 TRACE("(%p,%p,%p,%p,%d)\n", pStubMsg, Buffer, pPointer, pFormat, fMustAlloc);
739 TRACE("type=0x%x, attr=", type); dump_pointer_attr(attr);
740 pFormat += 2;
741 if (attr & RPC_FC_P_SIMPLEPOINTER) desc = pFormat;
742 else desc = pFormat + *(const SHORT*)pFormat;
743 if (attr & RPC_FC_P_DEREF) {
744 pPointer = *(unsigned char***)pPointer;
745 TRACE("deref => %p\n", pPointer);
746 }
747
748 switch (type) {
749 case RPC_FC_RP: /* ref pointer (always non-null) */
750 pointer_id = ~0UL;
751 break;
752 case RPC_FC_UP: /* unique pointer */
753 pointer_id = NDR_LOCAL_UINT32_READ(pStubMsg->Buffer);
754 pStubMsg->Buffer += 4;
755 break;
756 case RPC_FC_OP: /* object pointer - we must free data before overwriting it */
757 pointer_id = NDR_LOCAL_UINT32_READ(pStubMsg->Buffer);
758 pStubMsg->Buffer += 4;
759 if (*pPointer)
760 FIXME("free object pointer %p\n", *pPointer);
761 break;
762 case RPC_FC_FP:
763 default:
764 FIXME("unhandled ptr type=%02x\n", type);
765 RpcRaiseException(RPC_X_BAD_STUB_DATA);
766 }
767
768 if (pointer_id) {
769 m = NdrUnmarshaller[*desc & NDR_TABLE_MASK];
770 if (m) m(pStubMsg, pPointer, desc, fMustAlloc);
771 else FIXME("no unmarshaller for data type=%02x\n", *desc);
772 }
773
774 TRACE("pointer=%p\n", *pPointer);
775 }
776
777 /***********************************************************************
778 * PointerBufferSize
779 */
780 void WINAPI PointerBufferSize(PMIDL_STUB_MESSAGE pStubMsg,
781 unsigned char *Pointer,
782 PFORMAT_STRING pFormat)
783 {
784 unsigned type = pFormat[0], attr = pFormat[1];
785 PFORMAT_STRING desc;
786 NDR_BUFFERSIZE m;
787
788 TRACE("(%p,%p,%p)\n", pStubMsg, Pointer, pFormat);
789 TRACE("type=%d, attr=%d\n", type, attr);
790 pFormat += 2;
791 if (attr & RPC_FC_P_SIMPLEPOINTER) desc = pFormat;
792 else desc = pFormat + *(const SHORT*)pFormat;
793 if (attr & RPC_FC_P_DEREF) {
794 Pointer = *(unsigned char**)Pointer;
795 TRACE("deref => %p\n", Pointer);
796 }
797
798 switch (type) {
799 case RPC_FC_RP: /* ref pointer (always non-null) */
800 break;
801 case RPC_FC_OP:
802 case RPC_FC_UP:
803 pStubMsg->BufferLength += 4;
804 /* NULL pointer has no further representation */
805 if (!Pointer)
806 return;
807 break;
808 case RPC_FC_FP:
809 default:
810 FIXME("unhandled ptr type=%02x\n", type);
811 RpcRaiseException(RPC_X_BAD_STUB_DATA);
812 }
813
814 m = NdrBufferSizer[*desc & NDR_TABLE_MASK];
815 if (m) m(pStubMsg, Pointer, desc);
816 else FIXME("no buffersizer for data type=%02x\n", *desc);
817 }
818
819 /***********************************************************************
820 * PointerMemorySize [RPCRT4.@]
821 */
822 unsigned long WINAPI PointerMemorySize(PMIDL_STUB_MESSAGE pStubMsg,
823 unsigned char *Buffer,
824 PFORMAT_STRING pFormat)
825 {
826 unsigned type = pFormat[0], attr = pFormat[1];
827 PFORMAT_STRING desc;
828 NDR_MEMORYSIZE m;
829
830 FIXME("(%p,%p,%p): stub\n", pStubMsg, Buffer, pFormat);
831 TRACE("type=%d, attr=", type); dump_pointer_attr(attr);
832 pFormat += 2;
833 if (attr & RPC_FC_P_SIMPLEPOINTER) desc = pFormat;
834 else desc = pFormat + *(const SHORT*)pFormat;
835 if (attr & RPC_FC_P_DEREF) {
836 TRACE("deref\n");
837 }
838
839 switch (type) {
840 case RPC_FC_RP: /* ref pointer (always non-null) */
841 break;
842 default:
843 FIXME("unhandled ptr type=%02x\n", type);
844 RpcRaiseException(RPC_X_BAD_STUB_DATA);
845 }
846
847 m = NdrMemorySizer[*desc & NDR_TABLE_MASK];
848 if (m) m(pStubMsg, desc);
849 else FIXME("no memorysizer for data type=%02x\n", *desc);
850
851 return 0;
852 }
853
854 /***********************************************************************
855 * PointerFree [RPCRT4.@]
856 */
857 void WINAPI PointerFree(PMIDL_STUB_MESSAGE pStubMsg,
858 unsigned char *Pointer,
859 PFORMAT_STRING pFormat)
860 {
861 unsigned type = pFormat[0], attr = pFormat[1];
862 PFORMAT_STRING desc;
863 NDR_FREE m;
864
865 TRACE("(%p,%p,%p)\n", pStubMsg, Pointer, pFormat);
866 TRACE("type=%d, attr=", type); dump_pointer_attr(attr);
867 if (attr & RPC_FC_P_DONTFREE) return;
868 pFormat += 2;
869 if (attr & RPC_FC_P_SIMPLEPOINTER) desc = pFormat;
870 else desc = pFormat + *(const SHORT*)pFormat;
871 if (attr & RPC_FC_P_DEREF) {
872 Pointer = *(unsigned char**)Pointer;
873 TRACE("deref => %p\n", Pointer);
874 }
875
876 if (!Pointer) return;
877
878 m = NdrFreer[*desc & NDR_TABLE_MASK];
879 if (m) m(pStubMsg, Pointer, desc);
880
881 /* hmm... is this sensible?
882 * perhaps we should check if the memory comes from NdrAllocate,
883 * and deallocate only if so - checking if the pointer is between
884 * BufferStart and BufferEnd is probably no good since the buffer
885 * may be reallocated when the server wants to marshal the reply */
886 switch (*desc) {
887 case RPC_FC_BOGUS_STRUCT:
888 case RPC_FC_BOGUS_ARRAY:
889 case RPC_FC_USER_MARSHAL:
890 break;
891 default:
892 FIXME("unhandled data type=%02x\n", *desc);
893 case RPC_FC_CARRAY:
894 case RPC_FC_C_CSTRING:
895 case RPC_FC_C_WSTRING:
896 if (pStubMsg->ReuseBuffer) goto notfree;
897 break;
898 case RPC_FC_IP:
899 goto notfree;
900 }
901
902 if (attr & RPC_FC_P_ONSTACK) {
903 TRACE("not freeing stack ptr %p\n", Pointer);
904 return;
905 }
906 TRACE("freeing %p\n", Pointer);
907 NdrFree(pStubMsg, Pointer);
908 return;
909 notfree:
910 TRACE("not freeing %p\n", Pointer);
911 }
912
913 /***********************************************************************
914 * EmbeddedPointerMarshall
915 */
916 unsigned char * WINAPI EmbeddedPointerMarshall(PMIDL_STUB_MESSAGE pStubMsg,
917 unsigned char *pMemory,
918 PFORMAT_STRING pFormat)
919 {
920 unsigned char *Mark = pStubMsg->BufferMark;
921 unsigned long Offset = pStubMsg->Offset;
922 unsigned ofs, rep, count, stride, xofs;
923
924 TRACE("(%p,%p,%p)\n", pStubMsg, pMemory, pFormat);
925
926 if (*pFormat != RPC_FC_PP) return NULL;
927 pFormat += 2;
928
929 while (pFormat[0] != RPC_FC_END) {
930 switch (pFormat[0]) {
931 default:
932 FIXME("unknown repeat type %d\n", pFormat[0]);
933 case RPC_FC_NO_REPEAT:
934 rep = 1;
935 stride = 0;
936 ofs = 0;
937 count = 1;
938 xofs = 0;
939 pFormat += 2;
940 break;
941 case RPC_FC_FIXED_REPEAT:
942 rep = *(const WORD*)&pFormat[2];
943 stride = *(const WORD*)&pFormat[4];
944 ofs = *(const WORD*)&pFormat[6];
945 count = *(const WORD*)&pFormat[8];
946 xofs = 0;
947 pFormat += 10;
948 break;
949 case RPC_FC_VARIABLE_REPEAT:
950 rep = pStubMsg->MaxCount;
951 stride = *(const WORD*)&pFormat[2];
952 ofs = *(const WORD*)&pFormat[4];
953 count = *(const WORD*)&pFormat[6];
954 xofs = (pFormat[1] == RPC_FC_VARIABLE_OFFSET) ? Offset * stride : 0;
955 pFormat += 8;
956 break;
957 }
958 /* ofs doesn't seem to matter in this context */
959 while (rep) {
960 PFORMAT_STRING info = pFormat;
961 unsigned char *membase = pMemory + xofs;
962 unsigned u;
963 for (u=0; u<count; u++,info+=8) {
964 unsigned char *memptr = membase + *(const SHORT*)&info[0];
965 unsigned char *bufptr = Mark + *(const SHORT*)&info[2];
966 PointerMarshall(pStubMsg, bufptr, *(unsigned char**)memptr, info+4);
967 }
968 rep--;
969 }
970 pFormat += 8 * count;
971 }
972
973 STD_OVERFLOW_CHECK(pStubMsg);
974
975 return NULL;
976 }
977
978 /***********************************************************************
979 * EmbeddedPointerUnmarshall
980 */
981 unsigned char * WINAPI EmbeddedPointerUnmarshall(PMIDL_STUB_MESSAGE pStubMsg,
982 unsigned char **ppMemory,
983 PFORMAT_STRING pFormat,
984 unsigned char fMustAlloc)
985 {
986 unsigned char *Mark = pStubMsg->BufferMark;
987 unsigned long Offset = pStubMsg->Offset;
988 unsigned ofs, rep, count, stride, xofs;
989
990 TRACE("(%p,%p,%p,%d)\n", pStubMsg, ppMemory, pFormat, fMustAlloc);
991
992 if (*pFormat != RPC_FC_PP) return NULL;
993 pFormat += 2;
994
995 while (pFormat[0] != RPC_FC_END) {
996 switch (pFormat[0]) {
997 default:
998 FIXME("unknown repeat type %d\n", pFormat[0]);
999 case RPC_FC_NO_REPEAT:
1000 rep = 1;
1001 stride = 0;
1002 ofs = 0;
1003 count = 1;
1004 xofs = 0;
1005 pFormat += 2;
1006 break;
1007 case RPC_FC_FIXED_REPEAT:
1008 rep = *(const WORD*)&pFormat[2];
1009 stride = *(const WORD*)&pFormat[4];
1010 ofs = *(const WORD*)&pFormat[6];
1011 count = *(const WORD*)&pFormat[8];
1012 xofs = 0;
1013 pFormat += 10;
1014 break;
1015 case RPC_FC_VARIABLE_REPEAT:
1016 rep = pStubMsg->MaxCount;
1017 stride = *(const WORD*)&pFormat[2];
1018 ofs = *(const WORD*)&pFormat[4];
1019 count = *(const WORD*)&pFormat[6];
1020 xofs = (pFormat[1] == RPC_FC_VARIABLE_OFFSET) ? Offset * stride : 0;
1021 pFormat += 8;
1022 break;
1023 }
1024 /* ofs doesn't seem to matter in this context */
1025 while (rep) {
1026 PFORMAT_STRING info = pFormat;
1027 unsigned char *membase = *ppMemory + xofs;
1028 unsigned u;
1029 for (u=0; u<count; u++,info+=8) {
1030 unsigned char *memptr = membase + *(const SHORT*)&info[0];
1031 unsigned char *bufptr = Mark + *(const SHORT*)&info[2];
1032 PointerUnmarshall(pStubMsg, bufptr, (unsigned char**)memptr, info+4, fMustAlloc);
1033 }
1034 rep--;
1035 }
1036 pFormat += 8 * count;
1037 }
1038
1039 return NULL;
1040 }
1041
1042 /***********************************************************************
1043 * EmbeddedPointerBufferSize
1044 */
1045 void WINAPI EmbeddedPointerBufferSize(PMIDL_STUB_MESSAGE pStubMsg,
1046 unsigned char *pMemory,
1047 PFORMAT_STRING pFormat)
1048 {
1049 unsigned long Offset = pStubMsg->Offset;
1050 unsigned ofs, rep, count, stride, xofs;
1051
1052 TRACE("(%p,%p,%p)\n", pStubMsg, pMemory, pFormat);
1053 if (*pFormat != RPC_FC_PP) return;
1054 pFormat += 2;
1055
1056 while (pFormat[0] != RPC_FC_END) {
1057 switch (pFormat[0]) {
1058 default:
1059 FIXME("unknown repeat type %d\n", pFormat[0]);
1060 case RPC_FC_NO_REPEAT:
1061 rep = 1;
1062 stride = 0;
1063 ofs = 0;
1064 count = 1;
1065 xofs = 0;
1066 pFormat += 2;
1067 break;
1068 case RPC_FC_FIXED_REPEAT:
1069 rep = *(const WORD*)&pFormat[2];
1070 stride = *(const WORD*)&pFormat[4];
1071 ofs = *(const WORD*)&pFormat[6];
1072 count = *(const WORD*)&pFormat[8];
1073 xofs = 0;
1074 pFormat += 10;
1075 break;
1076 case RPC_FC_VARIABLE_REPEAT:
1077 rep = pStubMsg->MaxCount;
1078 stride = *(const WORD*)&pFormat[2];
1079 ofs = *(const WORD*)&pFormat[4];
1080 count = *(const WORD*)&pFormat[6];
1081 xofs = (pFormat[1] == RPC_FC_VARIABLE_OFFSET) ? Offset * stride : 0;
1082 pFormat += 8;
1083 break;
1084 }
1085 /* ofs doesn't seem to matter in this context */
1086 while (rep) {
1087 PFORMAT_STRING info = pFormat;
1088 unsigned char *membase = pMemory + xofs;
1089 unsigned u;
1090 for (u=0; u<count; u++,info+=8) {
1091 unsigned char *memptr = membase + *(const SHORT*)&info[0];
1092 PointerBufferSize(pStubMsg, *(unsigned char**)memptr, info+4);
1093 }
1094 rep--;
1095 }
1096 pFormat += 8 * count;
1097 }
1098 }
1099
1100 /***********************************************************************
1101 * EmbeddedPointerMemorySize
1102 */
1103 unsigned long WINAPI EmbeddedPointerMemorySize(PMIDL_STUB_MESSAGE pStubMsg,
1104 PFORMAT_STRING pFormat)
1105 {
1106 unsigned long Offset = pStubMsg->Offset;
1107 unsigned char *Mark = pStubMsg->BufferMark;
1108 unsigned ofs, rep, count, stride, xofs;
1109
1110 FIXME("(%p,%p): stub\n", pStubMsg, pFormat);
1111 if (*pFormat != RPC_FC_PP) return 0;
1112 pFormat += 2;
1113
1114 while (pFormat[0] != RPC_FC_END) {
1115 switch (pFormat[0]) {
1116 default:
1117 FIXME("unknown repeat type %d\n", pFormat[0]);
1118 case RPC_FC_NO_REPEAT:
1119 rep = 1;
1120 stride = 0;
1121 ofs = 0;
1122 count = 1;
1123 xofs = 0;
1124 pFormat += 2;
1125 break;
1126 case RPC_FC_FIXED_REPEAT:
1127 rep = *(const WORD*)&pFormat[2];
1128 stride = *(const WORD*)&pFormat[4];
1129 ofs = *(const WORD*)&pFormat[6];
1130 count = *(const WORD*)&pFormat[8];
1131 xofs = 0;
1132 pFormat += 10;
1133 break;
1134 case RPC_FC_VARIABLE_REPEAT:
1135 rep = pStubMsg->MaxCount;
1136 stride = *(const WORD*)&pFormat[2];
1137 ofs = *(const WORD*)&pFormat[4];
1138 count = *(const WORD*)&pFormat[6];
1139 xofs = (pFormat[1] == RPC_FC_VARIABLE_OFFSET) ? Offset * stride : 0;
1140 pFormat += 8;
1141 break;
1142 }
1143 /* ofs doesn't seem to matter in this context */
1144 while (rep) {
1145 PFORMAT_STRING info = pFormat;
1146 unsigned u;
1147 for (u=0; u<count; u++,info+=8) {
1148 unsigned char *bufptr = Mark + *(const SHORT*)&info[2];
1149 PointerMemorySize(pStubMsg, bufptr, info+4);
1150 }
1151 rep--;
1152 }
1153 pFormat += 8 * count;
1154 }
1155
1156 return 0;
1157 }
1158
1159 /***********************************************************************
1160 * EmbeddedPointerFree
1161 */
1162 void WINAPI EmbeddedPointerFree(PMIDL_STUB_MESSAGE pStubMsg,
1163 unsigned char *pMemory,
1164 PFORMAT_STRING pFormat)
1165 {
1166 unsigned long Offset = pStubMsg->Offset;
1167 unsigned ofs, rep, count, stride, xofs;
1168
1169 TRACE("(%p,%p,%p)\n", pStubMsg, pMemory, pFormat);
1170 if (*pFormat != RPC_FC_PP) return;
1171 pFormat += 2;
1172
1173 while (pFormat[0] != RPC_FC_END) {
1174 switch (pFormat[0]) {
1175 default:
1176 FIXME("unknown repeat type %d\n", pFormat[0]);
1177 case RPC_FC_NO_REPEAT:
1178 rep = 1;
1179 stride = 0;
1180 ofs = 0;
1181 count = 1;
1182 xofs = 0;
1183 pFormat += 2;
1184 break;
1185 case RPC_FC_FIXED_REPEAT:
1186 rep = *(const WORD*)&pFormat[2];
1187 stride = *(const WORD*)&pFormat[4];
1188 ofs = *(const WORD*)&pFormat[6];
1189 count = *(const WORD*)&pFormat[8];
1190 xofs = 0;
1191 pFormat += 10;
1192 break;
1193 case RPC_FC_VARIABLE_REPEAT:
1194 rep = pStubMsg->MaxCount;
1195 stride = *(const WORD*)&pFormat[2];
1196 ofs = *(const WORD*)&pFormat[4];
1197 count = *(const WORD*)&pFormat[6];
1198 xofs = (pFormat[1] == RPC_FC_VARIABLE_OFFSET) ? Offset * stride : 0;
1199 pFormat += 8;
1200 break;
1201 }
1202 /* ofs doesn't seem to matter in this context */
1203 while (rep) {
1204 PFORMAT_STRING info = pFormat;
1205 unsigned char *membase = pMemory + xofs;
1206 unsigned u;
1207 for (u=0; u<count; u++,info+=8) {
1208 unsigned char *memptr = membase + *(const SHORT*)&info[0];
1209 PointerFree(pStubMsg, *(unsigned char**)memptr, info+4);
1210 }
1211 rep--;
1212 }
1213 pFormat += 8 * count;
1214 }
1215 }
1216
1217 /***********************************************************************
1218 * NdrPointerMarshall [RPCRT4.@]
1219 */
1220 unsigned char * WINAPI NdrPointerMarshall(PMIDL_STUB_MESSAGE pStubMsg,
1221 unsigned char *pMemory,
1222 PFORMAT_STRING pFormat)
1223 {
1224 TRACE("(%p,%p,%p)\n", pStubMsg, pMemory, pFormat);
1225
1226 pStubMsg->BufferMark = pStubMsg->Buffer;
1227 PointerMarshall(pStubMsg, pStubMsg->Buffer, pMemory, pFormat);
1228
1229 STD_OVERFLOW_CHECK(pStubMsg);
1230
1231 return NULL;
1232 }
1233
1234 /***********************************************************************
1235 * NdrPointerUnmarshall [RPCRT4.@]
1236 */
1237 unsigned char * WINAPI NdrPointerUnmarshall(PMIDL_STUB_MESSAGE pStubMsg,
1238 unsigned char **ppMemory,
1239 PFORMAT_STRING pFormat,
1240 unsigned char fMustAlloc)
1241 {
1242 TRACE("(%p,%p,%p,%d)\n", pStubMsg, ppMemory, pFormat, fMustAlloc);
1243
1244 pStubMsg->BufferMark = pStubMsg->Buffer;
1245 PointerUnmarshall(pStubMsg, pStubMsg->Buffer, ppMemory, pFormat, fMustAlloc);
1246
1247 return NULL;
1248 }
1249
1250 /***********************************************************************
1251 * NdrPointerBufferSize [RPCRT4.@]
1252 */
1253 void WINAPI NdrPointerBufferSize(PMIDL_STUB_MESSAGE pStubMsg,
1254 unsigned char *pMemory,
1255 PFORMAT_STRING pFormat)
1256 {
1257 TRACE("(%p,%p,%p)\n", pStubMsg, pMemory, pFormat);
1258 PointerBufferSize(pStubMsg, pMemory, pFormat);
1259 }
1260
1261 /***********************************************************************
1262 * NdrPointerMemorySize [RPCRT4.@]
1263 */
1264 unsigned long WINAPI NdrPointerMemorySize(PMIDL_STUB_MESSAGE pStubMsg,
1265 PFORMAT_STRING pFormat)
1266 {
1267 /* unsigned size = *(LPWORD)(pFormat+2); */
1268 FIXME("(%p,%p): stub\n", pStubMsg, pFormat);
1269 PointerMemorySize(pStubMsg, pStubMsg->Buffer, pFormat);
1270 return 0;
1271 }
1272
1273 /***********************************************************************
1274 * NdrPointerFree [RPCRT4.@]
1275 */
1276 void WINAPI NdrPointerFree(PMIDL_STUB_MESSAGE pStubMsg,
1277 unsigned char *pMemory,
1278 PFORMAT_STRING pFormat)
1279 {
1280 TRACE("(%p,%p,%p)\n", pStubMsg, pMemory, pFormat);
1281 PointerFree(pStubMsg, pMemory, pFormat);
1282 }
1283
1284 /***********************************************************************
1285 * NdrSimpleStructMarshall [RPCRT4.@]
1286 */
1287 unsigned char * WINAPI NdrSimpleStructMarshall(PMIDL_STUB_MESSAGE pStubMsg,
1288 unsigned char *pMemory,
1289 PFORMAT_STRING pFormat)
1290 {
1291 unsigned size = *(const WORD*)(pFormat+2);
1292 TRACE("(%p,%p,%p)\n", pStubMsg, pMemory, pFormat);
1293
1294 memcpy(pStubMsg->Buffer, pMemory, size);
1295 pStubMsg->BufferMark = pStubMsg->Buffer;
1296 pStubMsg->Buffer += size;
1297
1298 if (pFormat[0] != RPC_FC_STRUCT)
1299 EmbeddedPointerMarshall(pStubMsg, pMemory, pFormat+4);
1300
1301 /*
1302 * This test does not work when NdrSimpleStructMarshall is called
1303 * by an rpc-server to marshall data to return to the client because
1304 * BufferStart and BufferEnd are bogus. MIDL does not update them
1305 * when a new buffer is allocated in order to return data to the caller.
1306 */
1307 #if 0
1308 STD_OVERFLOW_CHECK(pStubMsg);
1309 #endif
1310
1311 return NULL;
1312 }
1313
1314 /***********************************************************************
1315 * NdrSimpleStructUnmarshall [RPCRT4.@]
1316 */
1317 unsigned char * WINAPI NdrSimpleStructUnmarshall(PMIDL_STUB_MESSAGE pStubMsg,
1318 unsigned char **ppMemory,
1319 PFORMAT_STRING pFormat,
1320 unsigned char fMustAlloc)
1321 {
1322 unsigned size = *(const WORD*)(pFormat+2);
1323 TRACE("(%p,%p,%p,%d)\n", pStubMsg, ppMemory, pFormat, fMustAlloc);
1324
1325 if (fMustAlloc) {
1326 *ppMemory = NdrAllocate(pStubMsg, size);
1327 memcpy(*ppMemory, pStubMsg->Buffer, size);
1328 } else {
1329 if (pStubMsg->ReuseBuffer && !*ppMemory)
1330 /* for servers, we may just point straight into the RPC buffer, I think
1331 * (I guess that's what MS does since MIDL code doesn't try to free) */
1332 *ppMemory = pStubMsg->Buffer;
1333 else
1334 /* for clients, memory should be provided by caller */
1335 memcpy(*ppMemory, pStubMsg->Buffer, size);
1336 }
1337
1338 pStubMsg->BufferMark = pStubMsg->Buffer;
1339 pStubMsg->Buffer += size;
1340
1341 if (pFormat[0] != RPC_FC_STRUCT)
1342 EmbeddedPointerUnmarshall(pStubMsg, ppMemory, pFormat+4, fMustAlloc);
1343
1344 return NULL;
1345 }
1346
1347
1348 /***********************************************************************
1349 * NdrSimpleTypeUnmarshall [RPCRT4.@]
1350 */
1351 void WINAPI NdrSimpleTypeMarshall(PMIDL_STUB_MESSAGE pStubMsg,
1352 unsigned char *pMemory,
1353 unsigned char FormatChar)
1354 {
1355 FIXME("stub\n");
1356 }
1357
1358
1359 /***********************************************************************
1360 * NdrSimpleTypeUnmarshall [RPCRT4.@]
1361 */
1362 void WINAPI NdrSimpleTypeUnmarshall(PMIDL_STUB_MESSAGE pStubMsg,
1363 unsigned char *pMemory,
1364 unsigned char FormatChar)
1365 {
1366 FIXME("stub\n");
1367 }
1368
1369
1370 /***********************************************************************
1371 * NdrSimpleStructBufferSize [RPCRT4.@]
1372 */
1373 void WINAPI NdrSimpleStructBufferSize(PMIDL_STUB_MESSAGE pStubMsg,
1374 unsigned char *pMemory,
1375 PFORMAT_STRING pFormat)
1376 {
1377 unsigned size = *(const WORD*)(pFormat+2);
1378 TRACE("(%p,%p,%p)\n", pStubMsg, pMemory, pFormat);
1379 pStubMsg->BufferLength += size;
1380 if (pFormat[0] != RPC_FC_STRUCT)
1381 EmbeddedPointerBufferSize(pStubMsg, pMemory, pFormat+4);
1382 }
1383
1384 /***********************************************************************
1385 * NdrSimpleStructMemorySize [RPCRT4.@]
1386 */
1387 unsigned long WINAPI NdrSimpleStructMemorySize(PMIDL_STUB_MESSAGE pStubMsg,
1388 PFORMAT_STRING pFormat)
1389 {
1390 /* unsigned size = *(LPWORD)(pFormat+2); */
1391 FIXME("(%p,%p): stub\n", pStubMsg, pFormat);
1392 if (pFormat[0] != RPC_FC_STRUCT)
1393 EmbeddedPointerMemorySize(pStubMsg, pFormat+4);
1394 return 0;
1395 }
1396
1397 /***********************************************************************
1398 * NdrSimpleStructFree [RPCRT4.@]
1399 */
1400 void WINAPI NdrSimpleStructFree(PMIDL_STUB_MESSAGE pStubMsg,
1401 unsigned char *pMemory,
1402 PFORMAT_STRING pFormat)
1403 {
1404 TRACE("(%p,%p,%p)\n", pStubMsg, pMemory, pFormat);
1405 if (pFormat[0] != RPC_FC_STRUCT)
1406 EmbeddedPointerFree(pStubMsg, pMemory, pFormat+4);
1407 }
1408
1409
1410 unsigned long WINAPI EmbeddedComplexSize(PMIDL_STUB_MESSAGE pStubMsg,
1411 PFORMAT_STRING pFormat)
1412 {
1413 switch (*pFormat) {
1414 case RPC_FC_STRUCT:
1415 case RPC_FC_PSTRUCT:
1416 case RPC_FC_CSTRUCT:
1417 case RPC_FC_BOGUS_STRUCT:
1418 return *(const WORD*)&pFormat[2];
1419 case RPC_FC_USER_MARSHAL:
1420 return *(const WORD*)&pFormat[4];
1421 default:
1422 FIXME("unhandled embedded type %02x\n", *pFormat);
1423 }
1424 return 0;
1425 }
1426
1427
1428 unsigned char * WINAPI ComplexMarshall(PMIDL_STUB_MESSAGE pStubMsg,
1429 unsigned char *pMemory,
1430 PFORMAT_STRING pFormat,
1431 PFORMAT_STRING pPointer)
1432 {
1433 PFORMAT_STRING desc;
1434 NDR_MARSHALL m;
1435 unsigned long size;
1436
1437 while (*pFormat != RPC_FC_END) {
1438 switch (*pFormat) {
1439 case RPC_FC_SHORT:
1440 case RPC_FC_USHORT:
1441 TRACE("short=%d <= %p\n", *(WORD*)pMemory, pMemory);
1442 memcpy(pStubMsg->Buffer, pMemory, 2);
1443 pStubMsg->Buffer += 2;
1444 pMemory += 2;
1445 break;
1446 case RPC_FC_LONG:
1447 case RPC_FC_ULONG:
1448 case RPC_FC_ENUM32:
1449 TRACE("long=%ld <= %p\n", *(DWORD*)pMemory, pMemory);
1450 memcpy(pStubMsg->Buffer, pMemory, 4);
1451 pStubMsg->Buffer += 4;
1452 pMemory += 4;
1453 break;
1454 case RPC_FC_POINTER:
1455 TRACE("pointer=%p <= %p\n", *(unsigned char**)pMemory, pMemory);
1456 NdrPointerMarshall(pStubMsg, *(unsigned char**)pMemory, pPointer);
1457 pPointer += 4;
1458 pMemory += 4;
1459 break;
1460 case RPC_FC_ALIGNM4:
1461 ALIGN_POINTER(pMemory, 3);
1462 break;
1463 case RPC_FC_ALIGNM8:
1464 ALIGN_POINTER(pMemory, 7);
1465 break;
1466 case RPC_FC_STRUCTPAD2:
1467 pMemory += 2;
1468 break;
1469 case RPC_FC_EMBEDDED_COMPLEX:
1470 pMemory += pFormat[1];
1471 pFormat += 2;
1472 desc = pFormat + *(const SHORT*)pFormat;
1473 size = EmbeddedComplexSize(pStubMsg, desc);
1474 TRACE("embedded complex (size=%ld) <= %p\n", size, pMemory);
1475 m = NdrMarshaller[*desc & NDR_TABLE_MASK];
1476 if (m) m(pStubMsg, pMemory, desc);
1477 else FIXME("no marshaller for embedded type %02x\n", *desc);
1478 pMemory += size;
1479 pFormat += 2;
1480 continue;
1481 case RPC_FC_PAD:
1482 break;
1483 default:
1484 FIXME("unhandled format %02x\n", *pFormat);
1485 }
1486 pFormat++;
1487 }
1488
1489 return pMemory;
1490 }
1491
1492 unsigned char * WINAPI ComplexUnmarshall(PMIDL_STUB_MESSAGE pStubMsg,
1493 unsigned char *pMemory,
1494 PFORMAT_STRING pFormat,
1495 PFORMAT_STRING pPointer,
1496 unsigned char fMustAlloc)
1497 {
1498 PFORMAT_STRING desc;
1499 NDR_UNMARSHALL m;
1500 unsigned long size;
1501
1502 while (*pFormat != RPC_FC_END) {
1503 switch (*pFormat) {
1504 case RPC_FC_SHORT:
1505 case RPC_FC_USHORT:
1506 memcpy(pMemory, pStubMsg->Buffer, 2);
1507 TRACE("short=%d => %p\n", *(WORD*)pMemory, pMemory);
1508 pStubMsg->Buffer += 2;
1509 pMemory += 2;
1510 break;
1511 case RPC_FC_LONG:
1512 case RPC_FC_ULONG:
1513 case RPC_FC_ENUM32:
1514 memcpy(pMemory, pStubMsg->Buffer, 4);
1515 TRACE("long=%ld => %p\n", *(DWORD*)pMemory, pMemory);
1516 pStubMsg->Buffer += 4;
1517 pMemory += 4;
1518 break;
1519 case RPC_FC_POINTER:
1520 *(unsigned char**)pMemory = NULL;
1521 TRACE("pointer => %p\n", pMemory);
1522 NdrPointerUnmarshall(pStubMsg, (unsigned char**)pMemory, pPointer, fMustAlloc);
1523 pPointer += 4;
1524 pMemory += 4;
1525 break;
1526 case RPC_FC_ALIGNM4:
1527 ALIGN_POINTER(pMemory, 3);
1528 break;
1529 case RPC_FC_ALIGNM8:
1530 ALIGN_POINTER(pMemory, 7);
1531 break;
1532 case RPC_FC_STRUCTPAD2:
1533 pMemory += 2;
1534 break;
1535 case RPC_FC_EMBEDDED_COMPLEX:
1536 pMemory += pFormat[1];
1537 pFormat += 2;
1538 desc = pFormat + *(const SHORT*)pFormat;
1539 size = EmbeddedComplexSize(pStubMsg, desc);
1540 TRACE("embedded complex (size=%ld) => %p\n", size, pMemory);
1541 m = NdrUnmarshaller[*desc & NDR_TABLE_MASK];
1542 memset(pMemory, 0, size); /* just in case */
1543 if (m) m(pStubMsg, &pMemory, desc, fMustAlloc);
1544 else FIXME("no unmarshaller for embedded type %02x\n", *desc);
1545 pMemory += size;
1546 pFormat += 2;
1547 continue;
1548 case RPC_FC_PAD:
1549 break;
1550 default:
1551 FIXME("unhandled format %d\n", *pFormat);
1552 }
1553 pFormat++;
1554 }
1555
1556 return pMemory;
1557 }
1558
1559 unsigned char * WINAPI ComplexBufferSize(PMIDL_STUB_MESSAGE pStubMsg,
1560 unsigned char *pMemory,
1561 PFORMAT_STRING pFormat,
1562 PFORMAT_STRING pPointer)
1563 {
1564 PFORMAT_STRING desc;
1565 NDR_BUFFERSIZE m;
1566 unsigned long size;
1567
1568 while (*pFormat != RPC_FC_END) {
1569 switch (*pFormat) {
1570 case RPC_FC_SHORT:
1571 case RPC_FC_USHORT:
1572 pStubMsg->BufferLength += 2;
1573 pMemory += 2;
1574 break;
1575 case RPC_FC_LONG:
1576 case RPC_FC_ULONG:
1577 case RPC_FC_ENUM32:
1578 pStubMsg->BufferLength += 4;
1579 pMemory += 4;
1580 break;
1581 case RPC_FC_POINTER:
1582 NdrPointerBufferSize(pStubMsg, *(unsigned char**)pMemory, pPointer);
1583 pPointer += 4;
1584 pMemory += 4;
1585 break;
1586 case RPC_FC_ALIGNM4:
1587 ALIGN_POINTER(pMemory, 3);
1588 break;
1589 case RPC_FC_ALIGNM8:
1590 ALIGN_POINTER(pMemory, 7);
1591 break;
1592 case RPC_FC_STRUCTPAD2:
1593 pMemory += 2;
1594 break;
1595 case RPC_FC_EMBEDDED_COMPLEX:
1596 pMemory += pFormat[1];
1597 pFormat += 2;
1598 desc = pFormat + *(const SHORT*)pFormat;
1599 size = EmbeddedComplexSize(pStubMsg, desc);
1600 m = NdrBufferSizer[*desc & NDR_TABLE_MASK];
1601 if (m) m(pStubMsg, pMemory, desc);
1602 else FIXME("no buffersizer for embedded type %02x\n", *desc);
1603 pMemory += size;
1604 pFormat += 2;
1605 continue;
1606 case RPC_FC_PAD:
1607 break;
1608 default:
1609 FIXME("unhandled format %d\n", *pFormat);
1610 }
1611 pFormat++;
1612 }
1613
1614 return pMemory;
1615 }
1616
1617 unsigned char * WINAPI ComplexFree(PMIDL_STUB_MESSAGE pStubMsg,
1618 unsigned char *pMemory,
1619 PFORMAT_STRING pFormat,
1620 PFORMAT_STRING pPointer)
1621 {
1622 PFORMAT_STRING desc;
1623 NDR_FREE m;
1624 unsigned long size;
1625
1626 while (*pFormat != RPC_FC_END) {
1627 switch (*pFormat) {
1628 case RPC_FC_SHORT:
1629 case RPC_FC_USHORT:
1630 pMemory += 2;
1631 break;
1632 case RPC_FC_LONG:
1633 case RPC_FC_ULONG:
1634 case RPC_FC_ENUM32:
1635 pMemory += 4;
1636 break;
1637 case RPC_FC_POINTER:
1638 NdrPointerFree(pStubMsg, *(unsigned char**)pMemory, pPointer);
1639 pPointer += 4;
1640 pMemory += 4;
1641 break;
1642 case RPC_FC_ALIGNM4:
1643 ALIGN_POINTER(pMemory, 3);
1644 break;
1645 case RPC_FC_ALIGNM8:
1646 ALIGN_POINTER(pMemory, 7);
1647 break;
1648 case RPC_FC_STRUCTPAD2:
1649 pMemory += 2;
1650 break;
1651 case RPC_FC_EMBEDDED_COMPLEX:
1652 pMemory += pFormat[1];
1653 pFormat += 2;
1654 desc = pFormat + *(const SHORT*)pFormat;
1655 size = EmbeddedComplexSize(pStubMsg, desc);
1656 m = NdrFreer[*desc & NDR_TABLE_MASK];
1657 if (m) m(pStubMsg, pMemory, desc);
1658 else FIXME("no freer for embedded type %02x\n", *desc);
1659 pMemory += size;
1660 pFormat += 2;
1661 continue;
1662 case RPC_FC_PAD:
1663 break;
1664 default:
1665 FIXME("unhandled format %d\n", *pFormat);
1666 }
1667 pFormat++;
1668 }
1669
1670 return pMemory;
1671 }
1672
1673 unsigned long WINAPI ComplexStructSize(PMIDL_STUB_MESSAGE pStubMsg,
1674 PFORMAT_STRING pFormat)
1675 {
1676 PFORMAT_STRING desc;
1677 unsigned long size = 0;
1678
1679 while (*pFormat != RPC_FC_END) {
1680 switch (*pFormat) {
1681 case RPC_FC_SHORT:
1682 case RPC_FC_USHORT:
1683 size += 2;
1684 break;
1685 case RPC_FC_LONG:
1686 case RPC_FC_ULONG:
1687 size += 4;
1688 break;
1689 case RPC_FC_POINTER:
1690 size += 4;
1691 break;
1692 case RPC_FC_ALIGNM4:
1693 ALIGN_LENGTH(size, 3);
1694 break;
1695 case RPC_FC_ALIGNM8:
1696 ALIGN_LENGTH(size, 7);
1697 break;
1698 case RPC_FC_STRUCTPAD2:
1699 size += 2;
1700 break;
1701 case RPC_FC_EMBEDDED_COMPLEX:
1702 size += pFormat[1];
1703 pFormat += 2;
1704 desc = pFormat + *(const SHORT*)pFormat;
1705 size += EmbeddedComplexSize(pStubMsg, desc);
1706 pFormat += 2;
1707 continue;
1708 case RPC_FC_PAD:
1709 break;
1710 default:
1711 FIXME("unhandled format %d\n", *pFormat);
1712 }
1713 pFormat++;
1714 }
1715
1716 return size;
1717 }
1718
1719 /***********************************************************************
1720 * NdrComplexStructMarshall [RPCRT4.@]
1721 */
1722 unsigned char * WINAPI NdrComplexStructMarshall(PMIDL_STUB_MESSAGE pStubMsg,
1723 unsigned char *pMemory,
1724 PFORMAT_STRING pFormat)
1725 {
1726 PFORMAT_STRING conf_array = NULL;
1727 PFORMAT_STRING pointer_desc = NULL;
1728 unsigned char *OldMemory = pStubMsg->Memory;
1729
1730 TRACE("(%p,%p,%p)\n", pStubMsg, pMemory, pFormat);
1731
1732 pFormat += 4;
1733 if (*(const WORD*)pFormat) conf_array = pFormat + *(const WORD*)pFormat;
1734 pFormat += 2;
1735 if (*(const WORD*)pFormat) pointer_desc = pFormat + *(const WORD*)pFormat;
1736 pFormat += 2;
1737
1738 pStubMsg->Memory = pMemory;
1739
1740 ComplexMarshall(pStubMsg, pMemory, pFormat, pointer_desc);
1741
1742 if (conf_array)
1743 NdrConformantArrayMarshall(pStubMsg, pMemory, conf_array);
1744
1745 pStubMsg->Memory = OldMemory;
1746
1747 STD_OVERFLOW_CHECK(pStubMsg);
1748
1749 return NULL;
1750 }
1751
1752 /***********************************************************************
1753 * NdrComplexStructUnmarshall [RPCRT4.@]
1754 */
1755 unsigned char * WINAPI NdrComplexStructUnmarshall(PMIDL_STUB_MESSAGE pStubMsg,
1756 unsigned char **ppMemory,
1757 PFORMAT_STRING pFormat,
1758 unsigned char fMustAlloc)
1759 {
1760 unsigned size = *(const WORD*)(pFormat+2);
1761 PFORMAT_STRING conf_array = NULL;
1762 PFORMAT_STRING pointer_desc = NULL;
1763 unsigned char *pMemory;
1764
1765 TRACE("(%p,%p,%p,%d)\n", pStubMsg, ppMemory, pFormat, fMustAlloc);
1766
1767 if (fMustAlloc || !*ppMemory)
1768 *ppMemory = NdrAllocate(pStubMsg, size);
1769
1770 pFormat += 4;
1771 if (*(const WORD*)pFormat) conf_array = pFormat + *(const WORD*)pFormat;
1772 pFormat += 2;
1773 if (*(const WORD*)pFormat) pointer_desc = pFormat + *(const WORD*)pFormat;
1774 pFormat += 2;
1775
1776 pMemory = ComplexUnmarshall(pStubMsg, *ppMemory, pFormat, pointer_desc, fMustAlloc);
1777
1778 if (conf_array)
1779 NdrConformantArrayUnmarshall(pStubMsg, &pMemory, conf_array, fMustAlloc);
1780
1781 return NULL;
1782 }
1783
1784 /***********************************************************************
1785 * NdrComplexStructBufferSize [RPCRT4.@]
1786 */
1787 void WINAPI NdrComplexStructBufferSize(PMIDL_STUB_MESSAGE pStubMsg,
1788 unsigned char *pMemory,
1789 PFORMAT_STRING pFormat)
1790 {
1791 PFORMAT_STRING conf_array = NULL;
1792 PFORMAT_STRING pointer_desc = NULL;
1793 unsigned char *OldMemory = pStubMsg->Memory;
1794
1795 TRACE("(%p,%p,%p)\n", pStubMsg, pMemory, pFormat);
1796
1797 pFormat += 4;
1798 if (*(const WORD*)pFormat) conf_array = pFormat + *(const WORD*)pFormat;
1799 pFormat += 2;
1800 if (*(const WORD*)pFormat) pointer_desc = pFormat + *(const WORD*)pFormat;
1801 pFormat += 2;
1802
1803 pStubMsg->Memory = pMemory;
1804
1805 pMemory = ComplexBufferSize(pStubMsg, pMemory, pFormat, pointer_desc);
1806
1807 if (conf_array)
1808 NdrConformantArrayBufferSize(pStubMsg, pMemory, conf_array);
1809
1810 pStubMsg->Memory = OldMemory;
1811 }
1812
1813 /***********************************************************************
1814 * NdrComplexStructMemorySize [RPCRT4.@]
1815 */
1816 unsigned long WINAPI NdrComplexStructMemorySize(PMIDL_STUB_MESSAGE pStubMsg,
1817 PFORMAT_STRING pFormat)
1818 {
1819 /* unsigned size = *(LPWORD)(pFormat+2); */
1820 PFORMAT_STRING conf_array = NULL;
1821 PFORMAT_STRING pointer_desc = NULL;
1822
1823 FIXME("(%p,%p): stub\n", pStubMsg, pFormat);
1824
1825 pFormat += 4;
1826 if (*(const WORD*)pFormat) conf_array = pFormat + *(const WORD*)pFormat;
1827 pFormat += 2;
1828 if (*(const WORD*)pFormat) pointer_desc = pFormat + *(const WORD*)pFormat;
1829 pFormat += 2;
1830
1831 return 0;
1832 }
1833
1834 /***********************************************************************
1835 * NdrComplexStructFree [RPCRT4.@]
1836 */
1837 void WINAPI NdrComplexStructFree(PMIDL_STUB_MESSAGE pStubMsg,
1838 unsigned char *pMemory,
1839 PFORMAT_STRING pFormat)
1840 {
1841 PFORMAT_STRING conf_array = NULL;
1842 PFORMAT_STRING pointer_desc = NULL;
1843 unsigned char *OldMemory = pStubMsg->Memory;
1844
1845 TRACE("(%p,%p,%p)\n", pStubMsg, pMemory, pFormat);
1846
1847 pFormat += 4;
1848 if (*(const WORD*)pFormat) conf_array = pFormat + *(const WORD*)pFormat;
1849 pFormat += 2;
1850 if (*(const WORD*)pFormat) pointer_desc = pFormat + *(const WORD*)pFormat;
1851 pFormat += 2;
1852
1853 pStubMsg->Memory = pMemory;
1854
1855 pMemory = ComplexFree(pStubMsg, pMemory, pFormat, pointer_desc);
1856
1857 if (conf_array)
1858 NdrConformantArrayFree(pStubMsg, pMemory, conf_array);
1859
1860 pStubMsg->Memory = OldMemory;
1861 }
1862
1863 /***********************************************************************
1864 * NdrConformantArrayMarshall [RPCRT4.@]
1865 */
1866 unsigned char * WINAPI NdrConformantArrayMarshall(PMIDL_STUB_MESSAGE pStubMsg,
1867 unsigned char *pMemory,
1868 PFORMAT_STRING pFormat)
1869 {
1870 DWORD size = 0, esize = *(const WORD*)(pFormat+2);
1871 TRACE("(%p,%p,%p)\n", pStubMsg, pMemory, pFormat);
1872 if (pFormat[0] != RPC_FC_CARRAY) FIXME("format=%d\n", pFormat[0]);
1873
1874 pFormat = ComputeConformance(pStubMsg, pMemory, pFormat+4, 0);
1875 size = pStubMsg->MaxCount;
1876
1877 NDR_LOCAL_UINT32_WRITE(pStubMsg->Buffer, size);
1878 pStubMsg->Buffer += 4;
1879
1880 memcpy(pStubMsg->Buffer, pMemory, size*esize);
1881 pStubMsg->BufferMark = pStubMsg->Buffer;
1882 pStubMsg->Buffer += size*esize;
1883
1884 EmbeddedPointerMarshall(pStubMsg, pMemory, pFormat);
1885
1886 STD_OVERFLOW_CHECK(pStubMsg);
1887
1888 return NULL;
1889 }
1890
1891 /***********************************************************************
1892 * NdrConformantArrayUnmarshall [RPCRT4.@]
1893 */
1894 unsigned char * WINAPI NdrConformantArrayUnmarshall(PMIDL_STUB_MESSAGE pStubMsg,
1895 unsigned char **ppMemory,
1896 PFORMAT_STRING pFormat,
1897 unsigned char fMustAlloc)
1898 {
1899 DWORD size = 0, esize = *(const WORD*)(pFormat+2);
1900 TRACE("(%p,%p,%p,%d)\n", pStubMsg, ppMemory, pFormat, fMustAlloc);
1901 if (pFormat[0] != RPC_FC_CARRAY) FIXME("format=%d\n", pFormat[0]);
1902
1903 pFormat = ReadConformance(pStubMsg, pFormat+4);
1904 size = pStubMsg->MaxCount;
1905
1906 if (fMustAlloc || !*ppMemory)
1907 *ppMemory = NdrAllocate(pStubMsg, size*esize);
1908
1909 memcpy(*ppMemory, pStubMsg->Buffer, size*esize);
1910
1911 pStubMsg->BufferMark = pStubMsg->Buffer;
1912 pStubMsg->Buffer += size*esize;
1913
1914 EmbeddedPointerUnmarshall(pStubMsg, ppMemory, pFormat, fMustAlloc);
1915
1916 return NULL;
1917 }
1918
1919 /***********************************************************************
1920 * NdrConformantArrayBufferSize [RPCRT4.@]
1921 */
1922 void WINAPI NdrConformantArrayBufferSize(PMIDL_STUB_MESSAGE pStubMsg,
1923 unsigned char *pMemory,
1924 PFORMAT_STRING pFormat)
1925 {
1926 DWORD size = 0, esize = *(const WORD*)(pFormat+2);
1927 TRACE("(%p,%p,%p)\n", pStubMsg, pMemory, pFormat);
1928 if (pFormat[0] != RPC_FC_CARRAY) FIXME("format=%d\n", pFormat[0]);
1929
1930 pFormat = ComputeConformance(pStubMsg, pMemory, pFormat+4, 0);
1931 size = pStubMsg->MaxCount;
1932
1933 /* conformance value plus array */
1934 pStubMsg->BufferLength += sizeof(DWORD) + size*esize;
1935
1936 EmbeddedPointerBufferSize(pStubMsg, pMemory, pFormat);
1937 }
1938
1939 /***********************************************************************
1940 * NdrConformantArrayMemorySize [RPCRT4.@]
1941 */
1942 unsigned long WINAPI NdrConformantArrayMemorySize(PMIDL_STUB_MESSAGE pStubMsg,
1943 PFORMAT_STRING pFormat)
1944 {
1945 DWORD size = 0, esize = *(const WORD*)(pFormat+2);
1946 unsigned char *buffer;
1947
1948 TRACE("(%p,%p)\n", pStubMsg, pFormat);
1949 if (pFormat[0] != RPC_FC_CARRAY) FIXME("format=%d\n", pFormat[0]);
1950
1951 buffer = pStubMsg->Buffer;
1952 pFormat = ReadConformance(pStubMsg, pFormat+4);
1953 pStubMsg->Buffer = buffer;
1954 size = pStubMsg->MaxCount;
1955
1956 return size*esize;
1957 }
1958
1959 /***********************************************************************
1960 * NdrConformantArrayFree [RPCRT4.@]
1961 */
1962 void WINAPI NdrConformantArrayFree(PMIDL_STUB_MESSAGE pStubMsg,
1963 unsigned char *pMemory,
1964 PFORMAT_STRING pFormat)
1965 {
1966 TRACE("(%p,%p,%p)\n", pStubMsg, pMemory, pFormat);
1967 if (pFormat[0] != RPC_FC_CARRAY) FIXME("format=%d\n", pFormat[0]);
1968
1969 EmbeddedPointerFree(pStubMsg, pMemory, pFormat);
1970 }
1971
1972
1973 /***********************************************************************
1974 * NdrConformantVaryingArrayMarshall [RPCRT4.@]
1975 */
1976 unsigned char* WINAPI NdrConformantVaryingArrayMarshall( PMIDL_STUB_MESSAGE pStubMsg,
1977 unsigned char* pMemory,
1978 PFORMAT_STRING pFormat )
1979 {
1980 DWORD esize = *(const WORD*)(pFormat+2);
1981
1982 TRACE("(%p, %p, %p)\n", pStubMsg, pMemory, pFormat);
1983
1984 if (pFormat[0] != RPC_FC_CVARRAY)
1985 {
1986 ERR("invalid format type %x\n", pFormat[0]);
1987 RpcRaiseException(RPC_S_INTERNAL_ERROR);
1988 return NULL;
1989 }
1990
1991 pFormat = ComputeConformance(pStubMsg, pMemory, pFormat+4, 0);
1992 pFormat = ComputeVariance(pStubMsg, pMemory, pFormat, 0);
1993
1994 NDR_LOCAL_UINT32_WRITE(pStubMsg->Buffer, pStubMsg->MaxCount);
1995 pStubMsg->Buffer += 4;
1996 NDR_LOCAL_UINT32_WRITE(pStubMsg->Buffer, pStubMsg->Offset);
1997 pStubMsg->Buffer += 4;
1998 NDR_LOCAL_UINT32_WRITE(pStubMsg->Buffer, pStubMsg->ActualCount);
1999 pStubMsg->Buffer += 4;
2000
2001 memcpy(pStubMsg->Buffer, pMemory + pStubMsg->Offset, pStubMsg->ActualCount*esize);
2002 pStubMsg->BufferMark = pStubMsg->Buffer;
2003 pStubMsg->Buffer += pStubMsg->ActualCount*esize;
2004
2005 EmbeddedPointerMarshall(pStubMsg, pMemory, pFormat);
2006
2007 STD_OVERFLOW_CHECK(pStubMsg);
2008
2009 return NULL;
2010 }
2011
2012
2013 /***********************************************************************
2014 * NdrConformantVaryingArrayUnmarshall [RPCRT4.@]
2015 */
2016 unsigned char* WINAPI NdrConformantVaryingArrayUnmarshall( PMIDL_STUB_MESSAGE pStubMsg,
2017 unsigned char** ppMemory,
2018 PFORMAT_STRING pFormat,
2019 unsigned char fMustAlloc )
2020 {
2021 DWORD offset;
2022 DWORD esize = *(const WORD*)(pFormat+2);
2023
2024 TRACE("(%p, %p, %p, %d)\n", pStubMsg, ppMemory, pFormat, fMustAlloc);
2025
2026 if (pFormat[0] != RPC_FC_CVARRAY)
2027 {
2028 ERR("invalid format type %x\n", pFormat[0]);
2029 RpcRaiseException(RPC_S_INTERNAL_ERROR);
2030 return NULL;
2031 }
2032 pFormat = ReadConformance(pStubMsg, pFormat);
2033 offset = NDR_LOCAL_UINT32_READ(pStubMsg->Buffer);
2034 pStubMsg->Buffer += 4;
2035 pFormat = ReadVariance(pStubMsg, pFormat);
2036
2037 if (!*ppMemory || fMustAlloc)
2038 *ppMemory = NdrAllocate(pStubMsg, pStubMsg->MaxCount * esize);
2039 memcpy(*ppMemory + offset, pStubMsg->Buffer, pStubMsg->ActualCount * esize);
2040 pStubMsg->Buffer += pStubMsg->ActualCount * esize;
2041
2042 EmbeddedPointerUnmarshall(pStubMsg, ppMemory, pFormat, fMustAlloc);
2043
2044 return NULL;
2045 }
2046
2047
2048 /***********************************************************************
2049 * NdrConformantVaryingArrayFree [RPCRT4.@]
2050 */
2051 void WINAPI NdrConformantVaryingArrayFree( PMIDL_STUB_MESSAGE pStubMsg,
2052 unsigned char* pMemory,
2053 PFORMAT_STRING pFormat )
2054 {
2055 FIXME( "stub\n" );
2056 }
2057
2058
2059 /***********************************************************************
2060 * NdrConformantVaryingArrayBufferSize [RPCRT4.@]
2061 */
2062 void WINAPI NdrConformantVaryingArrayBufferSize( PMIDL_STUB_MESSAGE pStubMsg,
2063 unsigned char* pMemory, PFORMAT_STRING pFormat )
2064 {
2065 DWORD esize = *(const WORD*)(pFormat+2);
2066
2067 TRACE("(%p, %p, %p)\n", pStubMsg, pMemory, pFormat);
2068
2069 if (pFormat[0] != RPC_FC_CVARRAY)
2070 {
2071 ERR("invalid format type %x\n", pFormat[0]);
2072 RpcRaiseException(RPC_S_INTERNAL_ERROR);
2073 return;
2074 }
2075
2076 /* compute size */
2077 pFormat = ComputeConformance(pStubMsg, pMemory, pFormat+4, 0);
2078 /* compute length */
2079 pFormat = ComputeVariance(pStubMsg, pMemory, pFormat, 0);
2080
2081 /* conformance + offset + variance + array */
2082 pStubMsg->BufferLength += 3*sizeof(DWORD) + pStubMsg->ActualCount*esize;
2083
2084 EmbeddedPointerBufferSize(pStubMsg, pMemory, pFormat);
2085 }
2086
2087
2088 /***********************************************************************
2089 * NdrConformantVaryingArrayMemorySize [RPCRT4.@]
2090 */
2091 unsigned long WINAPI NdrConformantVaryingArrayMemorySize( PMIDL_STUB_MESSAGE pStubMsg,
2092 PFORMAT_STRING pFormat )
2093 {
2094 FIXME( "stub\n" );
2095 return 0;
2096 }
2097
2098
2099 /***********************************************************************
2100 * NdrComplexArrayMarshall [RPCRT4.@]
2101 */
2102 unsigned char * WINAPI NdrComplexArrayMarshall(PMIDL_STUB_MESSAGE pStubMsg,
2103 unsigned char *pMemory,
2104 PFORMAT_STRING pFormat)
2105 {
2106 DWORD size = 0, count, def;
2107 TRACE("(%p,%p,%p)\n", pStubMsg, pMemory, pFormat);
2108
2109 def = *(const WORD*)&pFormat[2];
2110 pFormat += 4;
2111
2112 pFormat = ComputeConformance(pStubMsg, pMemory, pFormat, def);
2113 size = pStubMsg->MaxCount;
2114 TRACE("conformance=%ld\n", size);
2115
2116 if (*(const DWORD*)pFormat != 0xffffffff)
2117 FIXME("compute variance\n");
2118 pFormat += 4;
2119
2120 NDR_LOCAL_UINT32_WRITE(pStubMsg->Buffer, size);
2121 pStubMsg->Buffer += 4;
2122
2123 for (count=0; count<size; count++)
2124 pMemory = ComplexMarshall(pStubMsg, pMemory, pFormat, NULL);
2125
2126 STD_OVERFLOW_CHECK(pStubMsg);
2127
2128 return NULL;
2129 }
2130
2131 /***********************************************************************
2132 * NdrComplexArrayUnmarshall [RPCRT4.@]
2133 */
2134 unsigned char * WINAPI NdrComplexArrayUnmarshall(PMIDL_STUB_MESSAGE pStubMsg,
2135 unsigned char **ppMemory,
2136 PFORMAT_STRING pFormat,
2137 unsigned char fMustAlloc)
2138 {
2139 DWORD size = 0, count, esize;
2140 unsigned char *pMemory;
2141 TRACE("(%p,%p,%p,%d)\n", pStubMsg, ppMemory, pFormat, fMustAlloc);
2142
2143 pFormat += 4;
2144
2145 pFormat = ReadConformance(pStubMsg, pFormat);
2146 size = pStubMsg->MaxCount;
2147 TRACE("conformance=%ld\n", size);
2148
2149 pFormat += 4;
2150
2151 esize = ComplexStructSize(pStubMsg, pFormat);
2152
2153 if (fMustAlloc || !*ppMemory)
2154 *ppMemory = NdrAllocate(pStubMsg, size*esize);
2155
2156 pMemory = *ppMemory;
2157 for (count=0; count<size; count++)
2158 pMemory = ComplexUnmarshall(pStubMsg, pMemory, pFormat, NULL, fMustAlloc);
2159
2160 return NULL;
2161 }
2162
2163 /***********************************************************************
2164 * NdrComplexArrayBufferSize [RPCRT4.@]
2165 */
2166 void WINAPI NdrComplexArrayBufferSize(PMIDL_STUB_MESSAGE pStubMsg,
2167 unsigned char *pMemory,
2168 PFORMAT_STRING pFormat)
2169 {
2170 DWORD size = 0, count, def;
2171 TRACE("(%p,%p,%p)\n", pStubMsg, pMemory, pFormat);
2172
2173 def = *(const WORD*)&pFormat[2];
2174 pFormat += 4;
2175
2176 pFormat = ComputeConformance(pStubMsg, pMemory, pFormat, def);
2177 size = pStubMsg->MaxCount;
2178 TRACE("conformance=%ld\n", size);
2179
2180 if (*(const DWORD*)pFormat != 0xffffffff)
2181 FIXME("compute variance\n");
2182 pFormat += 4;
2183
2184 for (count=0; count<size; count++)
2185 pMemory = ComplexBufferSize(pStubMsg, pMemory, pFormat, NULL);
2186 }
2187
2188 /***********************************************************************
2189 * NdrComplexArrayMemorySize [RPCRT4.@]
2190 */
2191 unsigned long WINAPI NdrComplexArrayMemorySize(PMIDL_STUB_MESSAGE pStubMsg,
2192 PFORMAT_STRING pFormat)
2193 {
2194 DWORD size = 0;
2195 FIXME("(%p,%p): stub\n", pStubMsg, pFormat);
2196
2197 pFormat += 4;
2198
2199 pFormat = ReadConformance(pStubMsg, pFormat);
2200 size = pStubMsg->MaxCount;
2201 TRACE("conformance=%ld\n", size);
2202
2203 pFormat += 4;
2204
2205 return 0;
2206 }
2207
2208 /***********************************************************************
2209 * NdrComplexArrayFree [RPCRT4.@]
2210 */
2211 void WINAPI NdrComplexArrayFree(PMIDL_STUB_MESSAGE pStubMsg,
2212 unsigned char *pMemory,
2213 PFORMAT_STRING pFormat)
2214 {
2215 DWORD size = 0, count, def;
2216 TRACE("(%p,%p,%p)\n", pStubMsg, pMemory, pFormat);
2217
2218 def = *(const WORD*)&pFormat[2];
2219 pFormat += 4;
2220
2221 pFormat = ComputeConformance(pStubMsg, pMemory, pFormat, def);
2222 size = pStubMsg->MaxCount;
2223 TRACE("conformance=%ld\n", size);
2224
2225 if (*(const DWORD*)pFormat != 0xffffffff)
2226 FIXME("compute variance\n");
2227 pFormat += 4;
2228
2229 for (count=0; count<size; count++)
2230 pMemory = ComplexFree(pStubMsg, pMemory, pFormat, NULL);
2231 }
2232
2233 unsigned long UserMarshalFlags(PMIDL_STUB_MESSAGE pStubMsg)
2234 {
2235 return MAKELONG(pStubMsg->dwDestContext,
2236 pStubMsg->RpcMsg->DataRepresentation);
2237 }
2238
2239 /***********************************************************************
2240 * NdrUserMarshalMarshall [RPCRT4.@]
2241 */
2242 unsigned char * WINAPI NdrUserMarshalMarshall(PMIDL_STUB_MESSAGE pStubMsg,
2243 unsigned char *pMemory,
2244 PFORMAT_STRING pFormat)
2245 {
2246 /* unsigned flags = pFormat[1]; */
2247 unsigned index = *(const WORD*)&pFormat[2];
2248 unsigned long uflag = UserMarshalFlags(pStubMsg);
2249 TRACE("(%p,%p,%p)\n", pStubMsg, pMemory, pFormat);
2250 TRACE("index=%d\n", index);
2251
2252 pStubMsg->Buffer =
2253 pStubMsg->StubDesc->aUserMarshalQuadruple[index].pfnMarshall(
2254 &uflag, pStubMsg->Buffer, pMemory);
2255
2256 STD_OVERFLOW_CHECK(pStubMsg);
2257
2258 return NULL;
2259 }
2260
2261 /***********************************************************************
2262 * NdrUserMarshalUnmarshall [RPCRT4.@]
2263 */
2264 unsigned char * WINAPI NdrUserMarshalUnmarshall(PMIDL_STUB_MESSAGE pStubMsg,
2265 unsigned char **ppMemory,
2266 PFORMAT_STRING pFormat,
2267 unsigned char fMustAlloc)
2268 {
2269 /* unsigned flags = pFormat[1];*/
2270 unsigned index = *(const WORD*)&pFormat[2];
2271 DWORD memsize = *(const WORD*)&pFormat[4];
2272 unsigned long uflag = UserMarshalFlags(pStubMsg);
2273 TRACE("(%p,%p,%p,%d)\n", pStubMsg, ppMemory, pFormat, fMustAlloc);
2274 TRACE("index=%d\n", index);
2275
2276 if (fMustAlloc || !*ppMemory)
2277 *ppMemory = NdrAllocate(pStubMsg, memsize);
2278
2279 pStubMsg->Buffer =
2280 pStubMsg->StubDesc->aUserMarshalQuadruple[index].pfnUnmarshall(
2281 &uflag, pStubMsg->Buffer, *ppMemory);
2282
2283 return NULL;
2284 }
2285
2286 /***********************************************************************
2287 * NdrUserMarshalBufferSize [RPCRT4.@]
2288 */
2289 void WINAPI NdrUserMarshalBufferSize(PMIDL_STUB_MESSAGE pStubMsg,
2290 unsigned char *pMemory,
2291 PFORMAT_STRING pFormat)
2292 {
2293 /* unsigned flags = pFormat[1];*/
2294 unsigned index = *(const WORD*)&pFormat[2];
2295 DWORD bufsize = *(const WORD*)&pFormat[6];
2296 unsigned long uflag = UserMarshalFlags(pStubMsg);
2297 TRACE("(%p,%p,%p)\n", pStubMsg, pMemory, pFormat);
2298 TRACE("index=%d\n", index);
2299
2300 if (bufsize) {
2301 TRACE("size=%ld\n", bufsize);
2302 pStubMsg->BufferLength += bufsize;
2303 return;
2304 }
2305
2306 pStubMsg->BufferLength =
2307 pStubMsg->StubDesc->aUserMarshalQuadruple[index].pfnBufferSize(
2308 &uflag, pStubMsg->BufferLength, pMemory);
2309 }
2310
2311 /***********************************************************************
2312 * NdrUserMarshalMemorySize [RPCRT4.@]
2313 */
2314 unsigned long WINAPI NdrUserMarshalMemorySize(PMIDL_STUB_MESSAGE pStubMsg,
2315 PFORMAT_STRING pFormat)
2316 {
2317 unsigned index = *(const WORD*)&pFormat[2];
2318 /* DWORD memsize = *(const WORD*)&pFormat[4]; */
2319 FIXME("(%p,%p): stub\n", pStubMsg, pFormat);
2320 TRACE("index=%d\n", index);
2321
2322 return 0;
2323 }
2324
2325 /***********************************************************************
2326 * NdrUserMarshalFree [RPCRT4.@]
2327 */
2328 void WINAPI NdrUserMarshalFree(PMIDL_STUB_MESSAGE pStubMsg,
2329 unsigned char *pMemory,
2330 PFORMAT_STRING pFormat)
2331 {
2332 /* unsigned flags = pFormat[1]; */
2333 unsigned index = *(const WORD*)&pFormat[2];
2334 unsigned long uflag = UserMarshalFlags(pStubMsg);
2335 TRACE("(%p,%p,%p)\n", pStubMsg, pMemory, pFormat);
2336 TRACE("index=%d\n", index);
2337
2338 pStubMsg->StubDesc->aUserMarshalQuadruple[index].pfnFree(
2339 &uflag, pMemory);
2340 }
2341
2342 /***********************************************************************
2343 * NdrClearOutParameters [RPCRT4.@]
2344 */
2345 void WINAPI NdrClearOutParameters(PMIDL_STUB_MESSAGE pStubMsg,
2346 PFORMAT_STRING pFormat,
2347 void *ArgAddr)
2348 {
2349 FIXME("(%p,%p,%p): stub\n", pStubMsg, pFormat, ArgAddr);
2350 }
2351
2352 /***********************************************************************
2353 * NdrConvert [RPCRT4.@]
2354 */
2355 void WINAPI NdrConvert( PMIDL_STUB_MESSAGE pStubMsg, PFORMAT_STRING pFormat )
2356 {
2357 FIXME("(pStubMsg == ^%p, pFormat == ^%p): stub.\n", pStubMsg, pFormat);
2358 /* FIXME: since this stub doesn't do any converting, the proper behavior
2359 is to raise an exception */
2360 }
2361
2362 /***********************************************************************
2363 * NdrConvert2 [RPCRT4.@]
2364 */
2365 void WINAPI NdrConvert2( PMIDL_STUB_MESSAGE pStubMsg, PFORMAT_STRING pFormat, long NumberParams )
2366 {
2367 FIXME("(pStubMsg == ^%p, pFormat == ^%p, NumberParams == %ld): stub.\n",
2368 pStubMsg, pFormat, NumberParams);
2369 /* FIXME: since this stub doesn't do any converting, the proper behavior
2370 is to raise an exception */
2371 }
2372
2373 typedef struct _NDR_CSTRUCT_FORMAT
2374 {
2375 unsigned char type;
2376 unsigned char alignment;
2377 unsigned short memory_size;
2378 short offset_to_array_description;
2379 } NDR_CSTRUCT_FORMAT;
2380
2381 /***********************************************************************
2382 * NdrConformantStructMarshall [RPCRT4.@]
2383 */
2384 unsigned char * WINAPI NdrConformantStructMarshall(PMIDL_STUB_MESSAGE pStubMsg,
2385 unsigned char *pMemory,
2386 PFORMAT_STRING pFormat)
2387 {
2388 const NDR_CSTRUCT_FORMAT * pCStructFormat = (NDR_CSTRUCT_FORMAT*)pFormat;
2389 pFormat += sizeof(NDR_CSTRUCT_FORMAT);
2390
2391 TRACE("(%p, %p, %p)\n", pStubMsg, pMemory, pFormat);
2392
2393 if ((pCStructFormat->type != RPC_FC_CPSTRUCT) && (pCStructFormat->type != RPC_FC_CSTRUCT))
2394 {
2395 ERR("invalid format type %x\n", pCStructFormat->type);
2396 RpcRaiseException(RPC_S_INTERNAL_ERROR);
2397 return NULL;
2398 }
2399
2400 TRACE("memory_size = %d\n", pCStructFormat->memory_size);
2401
2402 /* copy constant sized part of struct */
2403 memcpy(pStubMsg->Buffer, pMemory, pCStructFormat->memory_size);
2404 pStubMsg->Buffer += pCStructFormat->memory_size;
2405
2406 if (pCStructFormat->offset_to_array_description)
2407 {
2408 PFORMAT_STRING pArrayFormat = (unsigned char*)&pCStructFormat->offset_to_array_description +
2409 pCStructFormat->offset_to_array_description;
2410 NdrConformantArrayMarshall(pStubMsg, pMemory + pCStructFormat->memory_size, pArrayFormat);
2411 }
2412 if (pCStructFormat->type == RPC_FC_CPSTRUCT)
2413 EmbeddedPointerMarshall(pStubMsg, pMemory, pFormat);
2414 return NULL;
2415 }
2416
2417 /***********************************************************************
2418 * NdrConformantStructUnmarshall [RPCRT4.@]
2419 */
2420 unsigned char * WINAPI NdrConformantStructUnmarshall(PMIDL_STUB_MESSAGE pStubMsg,
2421 unsigned char **ppMemory,
2422 PFORMAT_STRING pFormat,
2423 unsigned char fMustAlloc)
2424 {
2425 const NDR_CSTRUCT_FORMAT * pCStructFormat = (NDR_CSTRUCT_FORMAT*)pFormat;
2426 pFormat += sizeof(NDR_CSTRUCT_FORMAT);
2427
2428 TRACE("(%p, %p, %p, %d)\n", pStubMsg, ppMemory, pFormat, fMustAlloc);
2429
2430 if ((pCStructFormat->type != RPC_FC_CPSTRUCT) && (pCStructFormat->type != RPC_FC_CSTRUCT))
2431 {
2432 ERR("invalid format type %x\n", pCStructFormat->type);
2433 RpcRaiseException(RPC_S_INTERNAL_ERROR);
2434 return NULL;
2435 }
2436
2437 TRACE("memory_size = %d\n", pCStructFormat->memory_size);
2438
2439 /* work out how much memory to allocate if we need to do so */
2440 if (!*ppMemory || fMustAlloc)
2441 {
2442 SIZE_T size = pCStructFormat->memory_size;
2443
2444 if (pCStructFormat->offset_to_array_description)
2445 {
2446 unsigned char *buffer;
2447 PFORMAT_STRING pArrayFormat = (unsigned char*)&pCStructFormat->offset_to_array_description +
2448 pCStructFormat->offset_to_array_description;
2449 buffer = pStubMsg->Buffer;
2450 pStubMsg->Buffer += pCStructFormat->memory_size;
2451 size += NdrConformantArrayMemorySize(pStubMsg, pArrayFormat);
2452 pStubMsg->Buffer = buffer;
2453 }
2454 *ppMemory = NdrAllocate(pStubMsg, size);
2455 }
2456
2457 /* now copy the data */
2458 memcpy(*ppMemory, pStubMsg->Buffer, pCStructFormat->memory_size);
2459 pStubMsg->Buffer += pCStructFormat->memory_size;
2460 if (pCStructFormat->offset_to_array_description)
2461 {
2462 PFORMAT_STRING pArrayFormat = (unsigned char*)&pCStructFormat->offset_to_array_description +
2463 pCStructFormat->offset_to_array_description;
2464 unsigned char *pMemoryArray = *ppMemory + pCStructFormat->memory_size;
2465 /* note that we pass fMustAlloc as 0 as we have already allocated the
2466 * memory */
2467 NdrConformantArrayUnmarshall(pStubMsg, &pMemoryArray, pArrayFormat, 0);
2468 }
2469 if (pCStructFormat->type == RPC_FC_CPSTRUCT)
2470 EmbeddedPointerUnmarshall(pStubMsg, ppMemory, pFormat, fMustAlloc);
2471 return NULL;
2472 }
2473
2474 /***********************************************************************
2475 * NdrConformantStructBufferSize [RPCRT4.@]
2476 */
2477 void WINAPI NdrConformantStructBufferSize(PMIDL_STUB_MESSAGE pStubMsg,
2478 unsigned char *pMemory,
2479 PFORMAT_STRING pFormat)
2480 {
2481 const NDR_CSTRUCT_FORMAT * pCStructFormat = (NDR_CSTRUCT_FORMAT*)pFormat;
2482 pFormat += sizeof(NDR_CSTRUCT_FORMAT);
2483 TRACE("(%p, %p, %p)\n", pStubMsg, pMemory, pFormat);
2484
2485 if ((pCStructFormat->type != RPC_FC_CPSTRUCT) && (pCStructFormat->type != RPC_FC_CSTRUCT))
2486 {
2487 ERR("invalid format type %x\n", pCStructFormat->type);
2488 RpcRaiseException(RPC_S_INTERNAL_ERROR);
2489 return;
2490 }
2491
2492 TRACE("memory_size = %d\n", pCStructFormat->memory_size);
2493
2494 /* add constant sized part of struct to buffer size */
2495 pStubMsg->BufferLength += pCStructFormat->memory_size;
2496
2497 if (pCStructFormat->offset_to_array_description)
2498 {
2499 PFORMAT_STRING pArrayFormat = (unsigned char*)&pCStructFormat->offset_to_array_description +
2500 pCStructFormat->offset_to_array_description;
2501 NdrConformantArrayBufferSize(pStubMsg, pMemory + pCStructFormat->memory_size, pArrayFormat);
2502 }
2503 if (pCStructFormat->type == RPC_FC_CPSTRUCT)
2504 EmbeddedPointerBufferSize(pStubMsg, pMemory, pFormat);
2505 }
2506
2507 /***********************************************************************
2508 * NdrConformantStructMemorySize [RPCRT4.@]
2509 */
2510 unsigned long WINAPI NdrConformantStructMemorySize(PMIDL_STUB_MESSAGE pStubMsg,
2511 PFORMAT_STRING pFormat)
2512 {
2513 FIXME("stub\n");
2514 return 0;
2515 }
2516
2517 /***********************************************************************
2518 * NdrConformantStructFree [RPCRT4.@]
2519 */
2520 void WINAPI NdrConformantStructFree(PMIDL_STUB_MESSAGE pStubMsg,
2521 unsigned char *pMemory,
2522 PFORMAT_STRING pFormat)
2523 {
2524 FIXME("stub\n");
2525 }
2526
2527 /***********************************************************************
2528 * NdrConformantVaryingStructMarshall [RPCRT4.@]
2529 */
2530 unsigned char * WINAPI NdrConformantVaryingStructMarshall(PMIDL_STUB_MESSAGE pStubMsg,
2531 unsigned char *pMemory,
2532 PFORMAT_STRING pFormat)
2533 {
2534 FIXME("stub\n");
2535 return NULL;
2536 }
2537
2538 /***********************************************************************
2539 * NdrConformantVaryingStructUnmarshall [RPCRT4.@]
2540 */
2541 unsigned char * WINAPI NdrConformantVaryingStructUnmarshall(PMIDL_STUB_MESSAGE pStubMsg,
2542 unsigned char **ppMemory,
2543 PFORMAT_STRING pFormat,
2544 unsigned char fMustAlloc)
2545 {
2546 FIXME("stub\n");
2547 return NULL;
2548 }
2549
2550 /***********************************************************************
2551 * NdrConformantVaryingStructBufferSize [RPCRT4.@]
2552 */
2553 void WINAPI NdrConformantVaryingStructBufferSize(PMIDL_STUB_MESSAGE pStubMsg,
2554 unsigned char *pMemory,
2555 PFORMAT_STRING pFormat)
2556 {
2557 FIXME("stub\n");
2558 }
2559
2560 /***********************************************************************
2561 * NdrConformantVaryingStructMemorySize [RPCRT4.@]
2562 */
2563 unsigned long WINAPI NdrConformantVaryingStructMemorySize(PMIDL_STUB_MESSAGE pStubMsg,
2564 PFORMAT_STRING pFormat)
2565 {
2566 FIXME("stub\n");
2567 return 0;
2568 }
2569
2570 /***********************************************************************
2571 * NdrConformantVaryingStructFree [RPCRT4.@]
2572 */
2573 void WINAPI NdrConformantVaryingStructFree(PMIDL_STUB_MESSAGE pStubMsg,
2574 unsigned char *pMemory,
2575 PFORMAT_STRING pFormat)
2576 {
2577 FIXME("stub\n");
2578 }
2579
2580 /***********************************************************************
2581 * NdrFixedArrayMarshall [RPCRT4.@]
2582 */
2583 unsigned char * WINAPI NdrFixedArrayMarshall(PMIDL_STUB_MESSAGE pStubMsg,
2584 unsigned char *pMemory,
2585 PFORMAT_STRING pFormat)
2586 {
2587 FIXME("stub\n");
2588 return NULL;
2589 }
2590
2591 /***********************************************************************
2592 * NdrFixedArrayUnmarshall [RPCRT4.@]
2593 */
2594 unsigned char * WINAPI NdrFixedArrayUnmarshall(PMIDL_STUB_MESSAGE pStubMsg,
2595 unsigned char **ppMemory,
2596 PFORMAT_STRING pFormat,
2597 unsigned char fMustAlloc)
2598 {
2599 FIXME("stub\n");
2600 return NULL;
2601 }
2602
2603 /***********************************************************************
2604 * NdrFixedArrayBufferSize [RPCRT4.@]
2605 */
2606 void WINAPI NdrFixedArrayBufferSize(PMIDL_STUB_MESSAGE pStubMsg,
2607 unsigned char *pMemory,
2608 PFORMAT_STRING pFormat)
2609 {
2610 FIXME("stub\n");
2611 }
2612
2613 /***********************************************************************
2614 * NdrFixedArrayMemorySize [RPCRT4.@]
2615 */
2616 unsigned long WINAPI NdrFixedArrayMemorySize(PMIDL_STUB_MESSAGE pStubMsg,
2617 PFORMAT_STRING pFormat)
2618 {
2619 FIXME("stub\n");
2620 return 0;
2621 }
2622
2623 /***********************************************************************
2624 * NdrFixedArrayFree [RPCRT4.@]
2625 */
2626 void WINAPI NdrFixedArrayFree(PMIDL_STUB_MESSAGE pStubMsg,
2627 unsigned char *pMemory,
2628 PFORMAT_STRING pFormat)
2629 {
2630 FIXME("stub\n");
2631 }
2632
2633 /***********************************************************************
2634 * NdrVaryingArrayMarshall [RPCRT4.@]
2635 */
2636 unsigned char * WINAPI NdrVaryingArrayMarshall(PMIDL_STUB_MESSAGE pStubMsg,
2637 unsigned char *pMemory,
2638 PFORMAT_STRING pFormat)
2639 {
2640 FIXME("stub\n");
2641 return NULL;
2642 }
2643
2644 /***********************************************************************
2645 * NdrVaryingArrayUnmarshall [RPCRT4.@]
2646 */
2647 unsigned char * WINAPI NdrVaryingArrayUnmarshall(PMIDL_STUB_MESSAGE pStubMsg,
2648 unsigned char **ppMemory,
2649 PFORMAT_STRING pFormat,
2650 unsigned char fMustAlloc)
2651 {
2652 FIXME("stub\n");
2653 return NULL;
2654 }
2655
2656 /***********************************************************************
2657 * NdrVaryingArrayBufferSize [RPCRT4.@]
2658 */
2659 void WINAPI NdrVaryingArrayBufferSize(PMIDL_STUB_MESSAGE pStubMsg,
2660 unsigned char *pMemory,
2661 PFORMAT_STRING pFormat)
2662 {
2663 FIXME("stub\n");
2664 }
2665
2666 /***********************************************************************
2667 * NdrVaryingArrayMemorySize [RPCRT4.@]
2668 */
2669 unsigned long WINAPI NdrVaryingArrayMemorySize(PMIDL_STUB_MESSAGE pStubMsg,
2670 PFORMAT_STRING pFormat)
2671 {
2672 FIXME("stub\n");
2673 return 0;
2674 }
2675
2676 /***********************************************************************
2677 * NdrVaryingArrayFree [RPCRT4.@]
2678 */
2679 void WINAPI NdrVaryingArrayFree(PMIDL_STUB_MESSAGE pStubMsg,
2680 unsigned char *pMemory,
2681 PFORMAT_STRING pFormat)
2682 {
2683 FIXME("stub\n");
2684 }
2685
2686 /***********************************************************************
2687 * NdrEncapsulatedUnionMarshall [RPCRT4.@]
2688 */
2689 unsigned char * WINAPI NdrEncapsulatedUnionMarshall(PMIDL_STUB_MESSAGE pStubMsg,
2690 unsigned char *pMemory,
2691 PFORMAT_STRING pFormat)
2692 {
2693 FIXME("stub\n");
2694 return NULL;
2695 }
2696
2697 /***********************************************************************
2698 * NdrEncapsulatedUnionUnmarshall [RPCRT4.@]
2699 */
2700 unsigned char * WINAPI NdrEncapsulatedUnionUnmarshall(PMIDL_STUB_MESSAGE pStubMsg,
2701 unsigned char **ppMemory,
2702 PFORMAT_STRING pFormat,
2703 unsigned char fMustAlloc)
2704 {
2705 FIXME("stub\n");
2706 return NULL;
2707 }
2708
2709 /***********************************************************************
2710 * NdrEncapsulatedUnionBufferSize [RPCRT4.@]
2711 */
2712 void WINAPI NdrEncapsulatedUnionBufferSize(PMIDL_STUB_MESSAGE pStubMsg,
2713 unsigned char *pMemory,
2714 PFORMAT_STRING pFormat)
2715 {
2716 FIXME("stub\n");
2717 }
2718
2719 /***********************************************************************
2720 * NdrEncapsulatedUnionMemorySize [RPCRT4.@]
2721 */
2722 unsigned long WINAPI NdrEncapsulatedUnionMemorySize(PMIDL_STUB_MESSAGE pStubMsg,
2723 PFORMAT_STRING pFormat)
2724 {
2725 FIXME("stub\n");
2726 return 0;
2727 }
2728
2729 /***********************************************************************
2730 * NdrEncapsulatedUnionFree [RPCRT4.@]
2731 */
2732 void WINAPI NdrEncapsulatedUnionFree(PMIDL_STUB_MESSAGE pStubMsg,
2733 unsigned char *pMemory,
2734 PFORMAT_STRING pFormat)
2735 {
2736 FIXME("stub\n");
2737 }
2738
2739 /***********************************************************************
2740 * NdrNonEncapsulatedUnionMarshall [RPCRT4.@]
2741 */
2742 unsigned char * WINAPI NdrNonEncapsulatedUnionMarshall(PMIDL_STUB_MESSAGE pStubMsg,
2743 unsigned char *pMemory,
2744 PFORMAT_STRING pFormat)
2745 {
2746 FIXME("stub\n");
2747 return NULL;
2748 }
2749
2750 /***********************************************************************
2751 * NdrNonEncapsulatedUnionUnmarshall [RPCRT4.@]
2752 */
2753 unsigned char * WINAPI NdrNonEncapsulatedUnionUnmarshall(PMIDL_STUB_MESSAGE pStubMsg,
2754 unsigned char **ppMemory,
2755 PFORMAT_STRING pFormat,
2756 unsigned char fMustAlloc)
2757 {
2758 FIXME("stub\n");
2759 return NULL;
2760 }
2761
2762 /***********************************************************************
2763 * NdrNonEncapsulatedUnionBufferSize [RPCRT4.@]
2764 */
2765 void WINAPI NdrNonEncapsulatedUnionBufferSize(PMIDL_STUB_MESSAGE pStubMsg,
2766 unsigned char *pMemory,
2767 PFORMAT_STRING pFormat)
2768 {
2769 FIXME("stub\n");
2770 }
2771
2772 /***********************************************************************
2773 * NdrNonEncapsulatedUnionMemorySize [RPCRT4.@]
2774 */
2775 unsigned long WINAPI NdrNonEncapsulatedUnionMemorySize(PMIDL_STUB_MESSAGE pStubMsg,
2776 PFORMAT_STRING pFormat)
2777 {
2778 FIXME("stub\n");
2779 return 0;
2780 }
2781
2782 /***********************************************************************
2783 * NdrNonEncapsulatedUnionFree [RPCRT4.@]
2784 */
2785 void WINAPI NdrNonEncapsulatedUnionFree(PMIDL_STUB_MESSAGE pStubMsg,
2786 unsigned char *pMemory,
2787 PFORMAT_STRING pFormat)
2788 {
2789 FIXME("stub\n");
2790 }
2791
2792 /***********************************************************************
2793 * NdrByteCountPointerMarshall [RPCRT4.@]
2794 */
2795 unsigned char * WINAPI NdrByteCountPointerMarshall(PMIDL_STUB_MESSAGE pStubMsg,
2796 unsigned char *pMemory,
2797 PFORMAT_STRING pFormat)
2798 {
2799 FIXME("stub\n");
2800 return NULL;
2801 }
2802
2803 /***********************************************************************
2804 * NdrByteCountPointerUnmarshall [RPCRT4.@]
2805 */
2806 unsigned char * WINAPI NdrByteCountPointerUnmarshall(PMIDL_STUB_MESSAGE pStubMsg,
2807 unsigned char **ppMemory,
2808 PFORMAT_STRING pFormat,
2809 unsigned char fMustAlloc)
2810 {
2811 FIXME("stub\n");
2812 return NULL;
2813 }
2814
2815 /***********************************************************************
2816 * NdrByteCountPointerBufferSize [RPCRT4.@]
2817 */
2818 void WINAPI NdrByteCountPointerBufferSize(PMIDL_STUB_MESSAGE pStubMsg,
2819 unsigned char *pMemory,
2820 PFORMAT_STRING pFormat)
2821 {
2822 FIXME("stub\n");
2823 }
2824
2825 /***********************************************************************
2826 * NdrByteCountPointerMemorySize [RPCRT4.@]
2827 */
2828 unsigned long WINAPI NdrByteCountPointerMemorySize(PMIDL_STUB_MESSAGE pStubMsg,
2829 PFORMAT_STRING pFormat)
2830 {
2831 FIXME("stub\n");
2832 return 0;
2833 }
2834
2835 /***********************************************************************
2836 * NdrByteCountPointerFree [RPCRT4.@]
2837 */
2838 void WINAPI NdrByteCountPointerFree(PMIDL_STUB_MESSAGE pStubMsg,
2839 unsigned char *pMemory,
2840 PFORMAT_STRING pFormat)
2841 {
2842 FIXME("stub\n");
2843 }
2844
2845 /***********************************************************************
2846 * NdrXmitOrRepAsMarshall [RPCRT4.@]
2847 */
2848 unsigned char * WINAPI NdrXmitOrRepAsMarshall(PMIDL_STUB_MESSAGE pStubMsg,
2849 unsigned char *pMemory,
2850 PFORMAT_STRING pFormat)
2851 {
2852 FIXME("stub\n");
2853 return NULL;
2854 }
2855
2856 /***********************************************************************
2857 * NdrXmitOrRepAsUnmarshall [RPCRT4.@]
2858 */
2859 unsigned char * WINAPI NdrXmitOrRepAsUnmarshall(PMIDL_STUB_MESSAGE pStubMsg,
2860 unsigned char **ppMemory,
2861 PFORMAT_STRING pFormat,
2862 unsigned char fMustAlloc)
2863 {
2864 FIXME("stub\n");
2865 return NULL;
2866 }
2867
2868 /***********************************************************************
2869 * NdrXmitOrRepAsBufferSize [RPCRT4.@]
2870 */
2871 void WINAPI NdrXmitOrRepAsBufferSize(PMIDL_STUB_MESSAGE pStubMsg,
2872 unsigned char *pMemory,
2873 PFORMAT_STRING pFormat)
2874 {
2875 FIXME("stub\n");
2876 }
2877
2878 /***********************************************************************
2879 * NdrXmitOrRepAsMemorySize [RPCRT4.@]
2880 */
2881 unsigned long WINAPI NdrXmitOrRepAsMemorySize(PMIDL_STUB_MESSAGE pStubMsg,
2882 PFORMAT_STRING pFormat)
2883 {
2884 FIXME("stub\n");
2885 return 0;
2886 }
2887
2888 /***********************************************************************
2889 * NdrXmitOrRepAsFree [RPCRT4.@]
2890 */
2891 void WINAPI NdrXmitOrRepAsFree(PMIDL_STUB_MESSAGE pStubMsg,
2892 unsigned char *pMemory,
2893 PFORMAT_STRING pFormat)
2894 {
2895 FIXME("stub\n");
2896 }
2897
2898 /***********************************************************************
2899 * NdrBaseTypeMarshall [internal]
2900 */
2901 static unsigned char *WINAPI NdrBaseTypeMarshall(
2902 PMIDL_STUB_MESSAGE pStubMsg,
2903 unsigned char *pMemory,
2904 PFORMAT_STRING pFormat)
2905 {
2906 TRACE("pStubMsg %p, pMemory %p, type 0x%02x\n", pStubMsg, pMemory, *pFormat);
2907
2908 switch(*pFormat)
2909 {
2910 case RPC_FC_BYTE:
2911 case RPC_FC_CHAR:
2912 case RPC_FC_SMALL:
2913 case RPC_FC_USMALL:
2914 *(UCHAR *)pStubMsg->Buffer = *(UCHAR *)pMemory;
2915 pStubMsg->Buffer += sizeof(UCHAR);
2916 TRACE("value: 0x%02x\n", *(UCHAR *)pMemory);
2917 break;
2918 case RPC_FC_WCHAR:
2919 case RPC_FC_SHORT:
2920 case RPC_FC_USHORT:
2921 ALIGN_POINTER(pStubMsg->Buffer, sizeof(USHORT) - 1);
2922 *(USHORT *)pStubMsg->Buffer = *(USHORT *)pMemory;
2923 pStubMsg->Buffer += sizeof(USHORT);
2924 TRACE("value: 0x%04x\n", *(USHORT *)pMemory);
2925 break;
2926 case RPC_FC_LONG:
2927 case RPC_FC_ULONG:
2928 case RPC_FC_ERROR_STATUS_T:
2929 ALIGN_POINTER(pStubMsg->Buffer, sizeof(ULONG) - 1);
2930 *(ULONG *)pStubMsg->Buffer = *(ULONG *)pMemory;
2931 pStubMsg->Buffer += sizeof(ULONG);
2932 TRACE("value: 0x%08lx\n", *(ULONG *)pMemory);
2933 break;
2934 case RPC_FC_FLOAT:
2935 ALIGN_POINTER(pStubMsg->Buffer, sizeof(float) - 1);
2936 *(float *)pStubMsg->Buffer = *(float *)pMemory;
2937 pStubMsg->Buffer += sizeof(float);
2938 break;
2939 case RPC_FC_DOUBLE:
2940 ALIGN_POINTER(pStubMsg->Buffer, sizeof(double) - 1);
2941 *(double *)pStubMsg->Buffer = *(double *)pMemory;
2942 pStubMsg->Buffer += sizeof(double);
2943 break;
2944 case RPC_FC_HYPER:
2945 ALIGN_POINTER(pStubMsg->Buffer, sizeof(ULONGLONG) - 1);
2946 *(ULONGLONG *)pStubMsg->Buffer = *(ULONGLONG *)pMemory;
2947 pStubMsg->Buffer += sizeof(ULONGLONG);
2948 TRACE("value: %s\n", wine_dbgstr_longlong(*(ULONGLONG*)pMemory));
2949 break;
2950 case RPC_FC_ENUM16:
2951 case RPC_FC_ENUM32:
2952 default:
2953 FIXME("Unhandled base type: 0x%02x\n", *pFormat);
2954 }
2955
2956 STD_OVERFLOW_CHECK(pStubMsg);
2957
2958 /* FIXME: what is the correct return value? */
2959 return NULL;
2960 }
2961
2962 /***********************************************************************
2963 * NdrBaseTypeUnmarshall [internal]
2964 */
2965 static unsigned char *WINAPI NdrBaseTypeUnmarshall(
2966 PMIDL_STUB_MESSAGE pStubMsg,
2967 unsigned char **ppMemory,
2968 PFORMAT_STRING pFormat,
2969 unsigned char fMustAlloc)
2970 {
2971 TRACE("pStubMsg: %p, ppMemory: %p, type: 0x%02x, fMustAlloc: %s\n", pStubMsg, ppMemory, *pFormat, fMustAlloc ? "true" : "false");
2972
2973 if (fMustAlloc || !*ppMemory)
2974 *ppMemory = NdrAllocate(pStubMsg, NdrBaseTypeMemorySize(pStubMsg, pFormat));
2975
2976 TRACE("*ppMemory: %p\n", *ppMemory);
2977
2978 switch(*pFormat)
2979 {
2980 case RPC_FC_BYTE:
2981 case RPC_FC_CHAR:
2982 case RPC_FC_SMALL:
2983 case RPC_FC_USMALL:
2984 **(UCHAR **)ppMemory = *(UCHAR *)pStubMsg->Buffer;
2985 pStubMsg->Buffer += sizeof(UCHAR);
2986 TRACE("value: 0x%02x\n", **(UCHAR **)ppMemory);
2987 break;
2988 case RPC_FC_WCHAR:
2989 case RPC_FC_SHORT:
2990 case RPC_FC_USHORT:
2991 ALIGN_POINTER(pStubMsg->Buffer, sizeof(USHORT) - 1);
2992 **(USHORT **)ppMemory = *(USHORT *)pStubMsg->Buffer;
2993 pStubMsg->Buffer += sizeof(USHORT);
2994 TRACE("value: 0x%04x\n", **(USHORT **)ppMemory);
2995 break;
2996 case RPC_FC_LONG:
2997 case RPC_FC_ULONG:
2998 case RPC_FC_ERROR_STATUS_T:
2999 ALIGN_POINTER(pStubMsg->Buffer, sizeof(ULONG) - 1);
3000 **(ULONG **)ppMemory = *(ULONG *)pStubMsg->Buffer;
3001 pStubMsg->Buffer += sizeof(ULONG);
3002 TRACE("value: 0x%08lx\n", **(ULONG **)ppMemory);
3003 break;
3004 case RPC_FC_FLOAT:
3005 ALIGN_POINTER(pStubMsg->Buffer, sizeof(float) - 1);
3006 **(float **)ppMemory = *(float *)pStubMsg->Buffer;
3007 pStubMsg->Buffer += sizeof(float);
3008 TRACE("value: %f\n", **(float **)ppMemory);
3009 break;
3010 case RPC_FC_DOUBLE:
3011 ALIGN_POINTER(pStubMsg->Buffer, sizeof(double) - 1);
3012 **(double **)ppMemory = *(double*)pStubMsg->Buffer;
3013 pStubMsg->Buffer += sizeof(double);
3014 TRACE("value: %f\n", **(double **)ppMemory);
3015 break;
3016 case RPC_FC_HYPER:
3017 ALIGN_POINTER(pStubMsg->Buffer, sizeof(ULONGLONG) - 1);
3018 **(ULONGLONG **)ppMemory = *(ULONGLONG *)pStubMsg->Buffer;
3019 pStubMsg->Buffer += sizeof(ULONGLONG);
3020 TRACE("value: %s\n", wine_dbgstr_longlong(**(ULONGLONG **)ppMemory));
3021 break;
3022 case RPC_FC_ENUM16:
3023 case RPC_FC_ENUM32:
3024 default:
3025 FIXME("Unhandled base type: 0x%02x\n", *pFormat);
3026 }
3027
3028 /* FIXME: what is the correct return value? */
3029
3030 return NULL;
3031 }
3032
3033 /***********************************************************************
3034 * NdrBaseTypeBufferSize [internal]
3035 */
3036 static void WINAPI NdrBaseTypeBufferSize(
3037 PMIDL_STUB_MESSAGE pStubMsg,
3038 unsigned char *pMemory,
3039 PFORMAT_STRING pFormat)
3040 {
3041 TRACE("pStubMsg %p, pMemory %p, type 0x%02x\n", pStubMsg, pMemory, *pFormat);
3042
3043 switch(*pFormat)
3044 {
3045 case RPC_FC_BYTE:
3046 case RPC_FC_CHAR:
3047 case RPC_FC_SMALL:
3048 case RPC_FC_USMALL:
3049 pStubMsg->BufferLength += sizeof(UCHAR);
3050 break;
3051 case RPC_FC_WCHAR:
3052 case RPC_FC_SHORT:
3053 case RPC_FC_USHORT:
3054 ALIGN_LENGTH(pStubMsg->BufferLength, sizeof(USHORT) - 1);
3055 pStubMsg->BufferLength += sizeof(USHORT);
3056 break;
3057 case RPC_FC_LONG:
3058 case RPC_FC_ULONG:
3059 ALIGN_LENGTH(pStubMsg->BufferLength, sizeof(ULONG) - 1);
3060 pStubMsg->BufferLength += sizeof(ULONG);
3061 break;
3062 case RPC_FC_FLOAT:
3063 ALIGN_LENGTH(pStubMsg->BufferLength, sizeof(float) - 1);
3064 pStubMsg->BufferLength += sizeof(float);
3065 break;
3066 case RPC_FC_DOUBLE:
3067 ALIGN_LENGTH(pStubMsg->BufferLength, sizeof(double) - 1);
3068 pStubMsg->BufferLength += sizeof(double);
3069 break;
3070 case RPC_FC_HYPER:
3071 ALIGN_LENGTH(pStubMsg->BufferLength, sizeof(ULONGLONG) - 1);
3072 pStubMsg->BufferLength += sizeof(ULONGLONG);
3073 break;
3074 case RPC_FC_ERROR_STATUS_T:
3075 ALIGN_LENGTH(pStubMsg->BufferLength, sizeof(error_status_t) - 1);
3076 pStubMsg->BufferLength += sizeof(error_status_t);
3077 break;
3078 case RPC_FC_ENUM16:
3079 case RPC_FC_ENUM32:
3080 default:
3081 FIXME("Unhandled base type: 0x%02x\n", *pFormat);
3082 }
3083 }
3084
3085 /***********************************************************************
3086 * NdrBaseTypeMemorySize [internal]
3087 */
3088 static unsigned long WINAPI NdrBaseTypeMemorySize(
3089 PMIDL_STUB_MESSAGE pStubMsg,
3090 PFORMAT_STRING pFormat)
3091 {
3092 switch(*pFormat)
3093 {
3094 case RPC_FC_BYTE:
3095 case RPC_FC_CHAR:
3096 case RPC_FC_SMALL:
3097 case RPC_FC_USMALL:
3098 return sizeof(UCHAR);
3099 case RPC_FC_WCHAR:
3100 case RPC_FC_SHORT:
3101 case RPC_FC_USHORT:
3102 return sizeof(USHORT);
3103 case RPC_FC_LONG:
3104 case RPC_FC_ULONG:
3105 return sizeof(ULONG);
3106 case RPC_FC_FLOAT:
3107 return sizeof(float);
3108 case RPC_FC_DOUBLE:
3109 return sizeof(double);
3110 case RPC_FC_HYPER:
3111 return sizeof(ULONGLONG);
3112 case RPC_FC_ERROR_STATUS_T:
3113 return sizeof(error_status_t);
3114 case RPC_FC_ENUM16:
3115 case RPC_FC_ENUM32:
3116 default:
3117 FIXME("Unhandled base type: 0x%02x\n", *pFormat);
3118 return 0;
3119 }
3120 }
3121
3122 /***********************************************************************
3123 * NdrBaseTypeFree [internal]
3124 */
3125 static void WINAPI NdrBaseTypeFree(PMIDL_STUB_MESSAGE pStubMsg,
3126 unsigned char *pMemory,
3127 PFORMAT_STRING pFormat)
3128 {
3129 TRACE("pStubMsg %p pMemory %p type 0x%02x\n", pStubMsg, pMemory, *pFormat);
3130
3131 /* nothing to do */
3132 }
3133
3134 /***********************************************************************
3135 * NdrClientContextMarshall
3136 */
3137 void WINAPI NdrClientContextMarshall(PMIDL_STUB_MESSAGE pStubMsg,
3138 NDR_CCONTEXT ContextHandle,
3139 int fCheck)
3140 {
3141 FIXME("(%p, %p, %d): stub\n", pStubMsg, ContextHandle, fCheck);
3142 }
3143
3144 /***********************************************************************
3145 * NdrClientContextUnmarshall
3146 */
3147 void WINAPI NdrClientContextUnmarshall(PMIDL_STUB_MESSAGE pStubMsg,
3148 NDR_CCONTEXT * pContextHandle,
3149 RPC_BINDING_HANDLE BindHandle)
3150 {
3151 FIXME("(%p, %p, %p): stub\n", pStubMsg, pContextHandle, BindHandle);
3152 }
3153
3154 void WINAPI NdrServerContextMarshall(PMIDL_STUB_MESSAGE pStubMsg,
3155 NDR_SCONTEXT ContextHandle,
3156 NDR_RUNDOWN RundownRoutine )
3157 {
3158 FIXME("(%p, %p, %p): stub\n", pStubMsg, ContextHandle, RundownRoutine);
3159 }
3160
3161 NDR_SCONTEXT WINAPI NdrServerContextUnmarshall(PMIDL_STUB_MESSAGE pStubMsg)
3162 {
3163 FIXME("(%p): stub\n", pStubMsg);
3164 return NULL;
3165 }
3166
3167 void WINAPI NdrContextHandleSize(PMIDL_STUB_MESSAGE pStubMsg,
3168 unsigned char* pMemory,
3169 PFORMAT_STRING pFormat)
3170 {
3171 FIXME("(%p, %p, %p): stub\n", pStubMsg, pMemory, pFormat);
3172 }
3173
3174 NDR_SCONTEXT WINAPI NdrContextHandleInitialize(PMIDL_STUB_MESSAGE pStubMsg,
3175 PFORMAT_STRING pFormat)
3176 {
3177 FIXME("(%p, %p): stub\n", pStubMsg, pFormat);
3178 return NULL;
3179 }
3180
3181 void WINAPI NdrServerContextNewMarshall(PMIDL_STUB_MESSAGE pStubMsg,
3182 NDR_SCONTEXT ContextHandle,
3183 NDR_RUNDOWN RundownRoutine,
3184 PFORMAT_STRING pFormat)
3185 {
3186 FIXME("(%p, %p, %p, %p): stub\n", pStubMsg, ContextHandle, RundownRoutine, pFormat);
3187 }
3188
3189 NDR_SCONTEXT WINAPI NdrServerContextNewUnmarshall(PMIDL_STUB_MESSAGE pStubMsg,
3190 PFORMAT_STRING pFormat)
3191 {
3192 FIXME("(%p, %p): stub\n", pStubMsg, pFormat);
3193 return NULL;
3194 }
3195
3196 RPC_BINDING_HANDLE WINAPI NDRCContextBinding(NDR_CCONTEXT CContext)
3197 {
3198 FIXME("(%p): stub\n", CContext);
3199 return NULL;
3200 }