Module: wine Branch: master Commit: 0c095ee0d3f1ed02fc30dade7361d885a70222b5 URL: http://source.winehq.org/git/wine.git/?a=commit;h=0c095ee0d3f1ed02fc30dade73...
Author: Rob Shearman robertshearman@gmail.com Date: Mon Jun 23 12:56:49 2008 +0100
rpcrt4: Fix NdrConformantVaryingStructUnmarshall to use buffer memory if applicable and to reuse memory for embedded pointers.
---
dlls/rpcrt4/ndr_marshall.c | 30 +++++++++++++++++++----------- dlls/rpcrt4/tests/server.c | 2 -- 2 files changed, 19 insertions(+), 13 deletions(-)
diff --git a/dlls/rpcrt4/ndr_marshall.c b/dlls/rpcrt4/ndr_marshall.c index 977effa..4e7643a 100644 --- a/dlls/rpcrt4/ndr_marshall.c +++ b/dlls/rpcrt4/ndr_marshall.c @@ -1562,7 +1562,7 @@ static unsigned char * EmbeddedPointerMarshall(PMIDL_STUB_MESSAGE pStubMsg, * EmbeddedPointerUnmarshall */ static unsigned char * EmbeddedPointerUnmarshall(PMIDL_STUB_MESSAGE pStubMsg, - unsigned char *pDstMemoryPtrs, + unsigned char *pDstBuffer, unsigned char *pSrcMemoryPtrs, PFORMAT_STRING pFormat, unsigned char fMustAlloc) @@ -1572,7 +1572,7 @@ static unsigned char * EmbeddedPointerUnmarshall(PMIDL_STUB_MESSAGE pStubMsg, unsigned i; unsigned char *saved_buffer = NULL;
- TRACE("(%p,%p,%p,%p,%d)\n", pStubMsg, pDstMemoryPtrs, pSrcMemoryPtrs, pFormat, fMustAlloc); + TRACE("(%p,%p,%p,%p,%d)\n", pStubMsg, pDstBuffer, pSrcMemoryPtrs, pFormat, fMustAlloc);
if (*pFormat != RPC_FC_PP) return NULL; pFormat += 2; @@ -1610,16 +1610,16 @@ static unsigned char * EmbeddedPointerUnmarshall(PMIDL_STUB_MESSAGE pStubMsg, } for (i = 0; i < rep; i++) { PFORMAT_STRING info = pFormat; - unsigned char *memdstbase = pDstMemoryPtrs + (i * stride); + unsigned char *bufdstbase = pDstBuffer + (i * stride); unsigned char *memsrcbase = pSrcMemoryPtrs + (i * stride); unsigned char *bufbase = Mark + (i * stride); unsigned u;
for (u=0; u<count; u++,info+=8) { - unsigned char **memdstptr = (unsigned char **)(memdstbase + *(const SHORT*)&info[0]); + unsigned char **bufdstptr = (unsigned char **)(bufdstbase + *(const SHORT*)&info[2]); unsigned char **memsrcptr = (unsigned char **)(memsrcbase + *(const SHORT*)&info[0]); unsigned char *bufptr = bufbase + *(const SHORT*)&info[2]; - PointerUnmarshall(pStubMsg, bufptr, memdstptr, *memsrcptr, info+4, fMustAlloc); + PointerUnmarshall(pStubMsg, bufptr, bufdstptr, *memsrcptr, info+4, fMustAlloc); } } pFormat += 8 * count; @@ -4186,6 +4186,7 @@ unsigned char * WINAPI NdrConformantVaryingStructUnmarshall(PMIDL_STUB_MESSAGE PFORMAT_STRING pCVArrayFormat; ULONG esize, bufsize; unsigned char cvarray_type; + unsigned char *saved_buffer, *saved_array_buffer;
TRACE("(%p, %p, %p, %d)\n", pStubMsg, ppMemory, pFormat, fMustAlloc);
@@ -4237,9 +4238,9 @@ unsigned char * WINAPI NdrConformantVaryingStructUnmarshall(PMIDL_STUB_MESSAGE *ppMemory = NdrAllocate(pStubMsg, size); }
- /* copy the constant data */ - pStubMsg->BufferMark = pStubMsg->Buffer; - safe_copy_from_buffer(pStubMsg, *ppMemory, pCVStructFormat->memory_size); + /* mark the start of the constant data */ + saved_buffer = pStubMsg->BufferMark = pStubMsg->Buffer; + safe_buffer_increment(pStubMsg, pCVStructFormat->memory_size);
pCVArrayFormat = ReadVariance(pStubMsg, pCVArrayFormat, pStubMsg->MaxCount);
@@ -4249,16 +4250,23 @@ unsigned char * WINAPI NdrConformantVaryingStructUnmarshall(PMIDL_STUB_MESSAGE (cvarray_type == RPC_FC_C_WSTRING)) validate_string_data(pStubMsg, bufsize, esize);
+ /* mark the start of the array data */ + saved_array_buffer = pStubMsg->Buffer; + safe_buffer_increment(pStubMsg, bufsize); + + EmbeddedPointerUnmarshall(pStubMsg, saved_buffer, *ppMemory, pFormat, fMustAlloc); + + /* copy the constant data */ + memcpy(*ppMemory, saved_buffer, pCVStructFormat->memory_size); /* copy the array data */ - safe_copy_from_buffer(pStubMsg, *ppMemory + pCVStructFormat->memory_size, bufsize); + TRACE("copying %p to %p\n", saved_array_buffer, *ppMemory + pCVStructFormat->memory_size); + memcpy(*ppMemory + pCVStructFormat->memory_size, saved_array_buffer, bufsize);
if (cvarray_type == RPC_FC_C_CSTRING) TRACE("string=%s\n", debugstr_a((char *)(*ppMemory + pCVStructFormat->memory_size))); else if (cvarray_type == RPC_FC_C_WSTRING) TRACE("string=%s\n", debugstr_w((WCHAR *)(*ppMemory + pCVStructFormat->memory_size)));
- EmbeddedPointerUnmarshall(pStubMsg, *ppMemory, *ppMemory, pFormat, TRUE /* FIXME */); - return NULL; }
diff --git a/dlls/rpcrt4/tests/server.c b/dlls/rpcrt4/tests/server.c index 91c87bf..69b9ba4 100644 --- a/dlls/rpcrt4/tests/server.c +++ b/dlls/rpcrt4/tests/server.c @@ -1208,9 +1208,7 @@ array_tests(void) ns->size = 5; ns->numbers[0].pi = pi; get_numbers_struct(&ns); - todo_wine { ok(ns->numbers[0].pi == pi, "RPC conformant varying struct embedded pointer changed from %p to %p\n", pi, ns->numbers[0].pi); - } ok(*ns->numbers[0].pi == 5, "pi unmarshalled incorrectly %d\n", *ns->numbers[0].pi);
HeapFree(GetProcessHeap(), 0, ns);