Signed-off-by: Zebediah Figura z.figura12@gmail.com --- dlls/rpcrt4/tests/ndr_marshall.c | 67 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 66 insertions(+), 1 deletion(-)
diff --git a/dlls/rpcrt4/tests/ndr_marshall.c b/dlls/rpcrt4/tests/ndr_marshall.c index d436b42648..d77e8b598e 100644 --- a/dlls/rpcrt4/tests/ndr_marshall.c +++ b/dlls/rpcrt4/tests/ndr_marshall.c @@ -25,7 +25,6 @@
#include <stdarg.h>
-#include "wine/test.h" #include <windef.h> #include <winbase.h> #include <winnt.h> @@ -38,6 +37,9 @@ #include "midles.h" #include "ndrtypes.h"
+#include "wine/heap.h" +#include "wine/test.h" + static int my_alloc_called; static int my_free_called; static void * CALLBACK my_alloc(SIZE_T size) @@ -1174,6 +1176,68 @@ static void test_simple_struct(void) test_pointer_marshal(fmtstr_pointer_struct, &ps1, 17, wiredata, 21, ps1_cmp, 2, "pointer_struct"); }
+struct aligned +{ + int a; + LONGLONG b; +}; + +static void test_struct_align(void) +{ + RPC_MESSAGE RpcMessage; + MIDL_STUB_MESSAGE StubMsg; + MIDL_STUB_DESC StubDesc; + void *ptr; + struct aligned *memsrc_orig, *memsrc, *mem; + + /* force bogus struct so that members are marshalled individually */ + static const unsigned char fmtstr[] = + { + 0x1a, /* FC_BOGUS_STRUCT */ + 0x7, /* alignment 8 */ + NdrFcShort(0x10), /* memory size 16 */ + NdrFcShort(0x0), + NdrFcShort(0x0), + 0x08, /* FC_LONG */ + 0x39, /* FC_ALIGNM8 */ + 0x0b, /* FC_HYPER */ + 0x5b, /* FC_END */ + }; + + memsrc_orig = heap_alloc_zero(sizeof(struct aligned) + 8); + /* intentionally mis-align memsrc */ + memsrc = (struct aligned *)((((ULONG_PTR)memsrc_orig + 7) & ~7) + 4); + + memsrc->a = 0xdeadbeef; + memsrc->b = ((ULONGLONG) 0xbadefeed << 32) | 0x2468ace0; + + StubDesc = Object_StubDesc; + StubDesc.pFormatTypes = fmtstr; + NdrClientInitializeNew(&RpcMessage, &StubMsg, &StubDesc, 0); + + StubMsg.BufferLength = 0; + NdrComplexStructBufferSize(&StubMsg, (unsigned char *)memsrc, fmtstr); + + StubMsg.RpcMsg->Buffer = StubMsg.BufferStart = StubMsg.Buffer = heap_alloc(StubMsg.BufferLength); + StubMsg.BufferEnd = StubMsg.BufferStart + StubMsg.BufferLength; + + ptr = NdrComplexStructMarshall(&StubMsg, (unsigned char *)memsrc, fmtstr); + ok(ptr == NULL, "ret %p\n", ptr); + + /* Server */ + StubMsg.IsClient = 0; + mem = NULL; + StubMsg.Buffer = StubMsg.BufferStart; + ptr = NdrComplexStructUnmarshall(&StubMsg, (unsigned char **)&mem, fmtstr, 0); + ok(ptr == NULL, "ret %p\n", ptr); +todo_wine + ok(!memcmp(mem, memsrc, sizeof(*memsrc)), "struct wasn't unmarshalled correctly\n"); + StubMsg.pfnFree(mem); + + heap_free(StubMsg.RpcMsg->Buffer); + heap_free(memsrc_orig); +} + struct testiface { IPersist IPersist_iface; @@ -2908,6 +2972,7 @@ START_TEST( ndr_marshall ) test_simple_types(); test_nontrivial_pointer_types(); test_simple_struct(); + test_struct_align(); test_iface_ptr(); test_fullpointer_xlat(); test_client_init();
Signed-off-by: Zebediah Figura z.figura12@gmail.com --- dlls/rpcrt4/ndr_marshall.c | 41 ++++++++++++++++++++++++++++------------ dlls/rpcrt4/tests/ndr_marshall.c | 1 - 2 files changed, 29 insertions(+), 13 deletions(-)
diff --git a/dlls/rpcrt4/ndr_marshall.c b/dlls/rpcrt4/ndr_marshall.c index 38ead96afc..77bbf986ff 100644 --- a/dlls/rpcrt4/ndr_marshall.c +++ b/dlls/rpcrt4/ndr_marshall.c @@ -108,6 +108,19 @@ static inline void align_pointer_clear( unsigned char **ptr, unsigned int align *ptr = (unsigned char *)(((ULONG_PTR)*ptr + mask) & ~mask); }
+static inline void align_pointer_offset( unsigned char **ptr, unsigned char *base, unsigned int align ) +{ + ULONG_PTR mask = align - 1; + *ptr = base + (((ULONG_PTR)(*ptr - base) + mask) & ~mask); +} + +static inline void align_pointer_offset_clear( unsigned char **ptr, unsigned char *base, unsigned int align ) +{ + ULONG_PTR mask = align - 1; + memset( *ptr, 0, (align - (ULONG_PTR)(*ptr - base)) & mask ); + *ptr = base + (((ULONG_PTR)(*ptr - base) + mask) & ~mask); +} + #define STD_OVERFLOW_CHECK(_Msg) do { \ TRACE("buffer=%d/%d\n", (ULONG)(_Msg->Buffer - (unsigned char *)_Msg->RpcMsg->Buffer), _Msg->BufferLength); \ if (_Msg->Buffer > (unsigned char *)_Msg->RpcMsg->Buffer + _Msg->BufferLength) \ @@ -2834,6 +2847,7 @@ static unsigned char * ComplexMarshall(PMIDL_STUB_MESSAGE pStubMsg, PFORMAT_STRING pFormat, PFORMAT_STRING pPointer) { + unsigned char *mem_base = pMemory; PFORMAT_STRING desc; NDR_MARSHALL m; ULONG size; @@ -2937,13 +2951,13 @@ static unsigned char * ComplexMarshall(PMIDL_STUB_MESSAGE pStubMsg, break; } case FC_ALIGNM2: - align_pointer(&pMemory, 2); + align_pointer_offset(&pMemory, mem_base, 2); break; case FC_ALIGNM4: - align_pointer(&pMemory, 4); + align_pointer_offset(&pMemory, mem_base, 4); break; case FC_ALIGNM8: - align_pointer(&pMemory, 8); + align_pointer_offset(&pMemory, mem_base, 8); break; case FC_STRUCTPAD1: case FC_STRUCTPAD2: @@ -2993,6 +3007,7 @@ static unsigned char * ComplexUnmarshall(PMIDL_STUB_MESSAGE pStubMsg, PFORMAT_STRING pPointer, unsigned char fMustAlloc) { + unsigned char *mem_base = pMemory; PFORMAT_STRING desc; NDR_UNMARSHALL m; ULONG size; @@ -3105,13 +3120,13 @@ static unsigned char * ComplexUnmarshall(PMIDL_STUB_MESSAGE pStubMsg, break; } case FC_ALIGNM2: - align_pointer_clear(&pMemory, 2); + align_pointer_offset_clear(&pMemory, mem_base, 2); break; case FC_ALIGNM4: - align_pointer_clear(&pMemory, 4); + align_pointer_offset_clear(&pMemory, mem_base, 4); break; case FC_ALIGNM8: - align_pointer_clear(&pMemory, 8); + align_pointer_offset_clear(&pMemory, mem_base, 8); break; case FC_STRUCTPAD1: case FC_STRUCTPAD2: @@ -3168,6 +3183,7 @@ static unsigned char * ComplexBufferSize(PMIDL_STUB_MESSAGE pStubMsg, PFORMAT_STRING pFormat, PFORMAT_STRING pPointer) { + unsigned char *mem_base = pMemory; PFORMAT_STRING desc; NDR_BUFFERSIZE m; ULONG size; @@ -3238,13 +3254,13 @@ static unsigned char * ComplexBufferSize(PMIDL_STUB_MESSAGE pStubMsg, pMemory += sizeof(void*); break; case FC_ALIGNM2: - align_pointer(&pMemory, 2); + align_pointer_offset(&pMemory, mem_base, 2); break; case FC_ALIGNM4: - align_pointer(&pMemory, 4); + align_pointer_offset(&pMemory, mem_base, 4); break; case FC_ALIGNM8: - align_pointer(&pMemory, 8); + align_pointer_offset(&pMemory, mem_base, 8); break; case FC_STRUCTPAD1: case FC_STRUCTPAD2: @@ -3292,6 +3308,7 @@ static unsigned char * ComplexFree(PMIDL_STUB_MESSAGE pStubMsg, PFORMAT_STRING pFormat, PFORMAT_STRING pPointer) { + unsigned char *mem_base = pMemory; PFORMAT_STRING desc; NDR_FREE m; ULONG size; @@ -3339,13 +3356,13 @@ static unsigned char * ComplexFree(PMIDL_STUB_MESSAGE pStubMsg, pMemory += sizeof(void *); break; case FC_ALIGNM2: - align_pointer(&pMemory, 2); + align_pointer_offset(&pMemory, mem_base, 2); break; case FC_ALIGNM4: - align_pointer(&pMemory, 4); + align_pointer_offset(&pMemory, mem_base, 4); break; case FC_ALIGNM8: - align_pointer(&pMemory, 8); + align_pointer_offset(&pMemory, mem_base, 8); break; case FC_STRUCTPAD1: case FC_STRUCTPAD2: diff --git a/dlls/rpcrt4/tests/ndr_marshall.c b/dlls/rpcrt4/tests/ndr_marshall.c index d77e8b598e..2187a08394 100644 --- a/dlls/rpcrt4/tests/ndr_marshall.c +++ b/dlls/rpcrt4/tests/ndr_marshall.c @@ -1230,7 +1230,6 @@ static void test_struct_align(void) StubMsg.Buffer = StubMsg.BufferStart; ptr = NdrComplexStructUnmarshall(&StubMsg, (unsigned char **)&mem, fmtstr, 0); ok(ptr == NULL, "ret %p\n", ptr); -todo_wine ok(!memcmp(mem, memsrc, sizeof(*memsrc)), "struct wasn't unmarshalled correctly\n"); StubMsg.pfnFree(mem);
Signed-off-by: Huw Davies huw@codeweavers.com