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