Author: ion
Date: Sat Aug 31 02:19:36 2013
New Revision: 59913
URL:
http://svn.reactos.org/svn/reactos?rev=59913&view=rev
Log:
[NTDLL]: Use NT-style calculation in CsrClientCallServer. In special cases, structures can
be padded at the end, causing the size of the structure - the size of last field, not to
be equal to the offset of the last field. Doing math the NT way will, in some cases (if
the CSR union is not 8-byte aligned), cause the TotalLength to be 4 bytes bigger than
really needed.
[CSRSRV]: Increase the padding to 39*4 bytes, instead of 35, to match Windows.
Modified:
trunk/reactos/dll/ntdll/csr/connect.c
trunk/reactos/include/reactos/subsys/csr/csrmsg.h
Modified: trunk/reactos/dll/ntdll/csr/connect.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/ntdll/csr/connect.c?re…
==============================================================================
--- trunk/reactos/dll/ntdll/csr/connect.c [iso-8859-1] (original)
+++ trunk/reactos/dll/ntdll/csr/connect.c [iso-8859-1] Sat Aug 31 02:19:36 2013
@@ -321,6 +321,33 @@
return Status;
}
+#if 0
+//
+// Structures can be padded at the end, causing the size of the entire structure
+// minus the size of the last field, not to be equal to the offset of the last
+// field.
+//
+typedef struct _TEST_EMBEDDED
+{
+ ULONG One;
+ ULONG Two;
+ ULONG Three;
+} TEST_EMBEDDED;
+
+typedef struct _TEST
+{
+ PORT_MESSAGE h;
+ TEST_EMBEDDED Three;
+} TEST;
+
+C_ASSERT(sizeof(PORT_MESSAGE) == 0x18);
+C_ASSERT(FIELD_OFFSET(TEST, Three) == 0x18);
+C_ASSERT(sizeof(TEST_EMBEDDED) == 0xC);
+
+C_ASSERT(sizeof(TEST) != (sizeof(TEST_EMBEDDED) + sizeof(PORT_MESSAGE)));
+C_ASSERT((sizeof(TEST) - sizeof(TEST_EMBEDDED)) != FIELD_OFFSET(TEST, Three));
+#endif
+
/*
* @implemented
*/
@@ -337,10 +364,10 @@
/* Fill out the Port Message Header */
ApiMessage->Header.u2.ZeroInit = 0;
- ApiMessage->Header.u1.s1.TotalLength =
- FIELD_OFFSET(CSR_API_MESSAGE, Data) + DataLength;
- ApiMessage->Header.u1.s1.DataLength =
- ApiMessage->Header.u1.s1.TotalLength - sizeof(PORT_MESSAGE);
+ ApiMessage->Header.u1.s1.TotalLength = DataLength +
+ sizeof(CSR_API_MESSAGE) - sizeof(ApiMessage->Data); //
FIELD_OFFSET(CSR_API_MESSAGE, Data) + DataLength;
+ ApiMessage->Header.u1.s1.DataLength = DataLength +
+ FIELD_OFFSET(CSR_API_MESSAGE, Data) - sizeof(ApiMessage->Header);//
ApiMessage->Header.u1.s1.TotalLength - sizeof(PORT_MESSAGE);
/* Fill out the CSR Header */
ApiMessage->ApiNumber = ApiNumber;
Modified: trunk/reactos/include/reactos/subsys/csr/csrmsg.h
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/include/reactos/subsys/csr…
==============================================================================
--- trunk/reactos/include/reactos/subsys/csr/csrmsg.h [iso-8859-1] (original)
+++ trunk/reactos/include/reactos/subsys/csr/csrmsg.h [iso-8859-1] Sat Aug 31 02:19:36
2013
@@ -133,7 +133,7 @@
// Finally, the overall message structure size must be at most
// equal to the maximum acceptable LPC message size.
//
- ULONG_PTR Padding[35];
+ ULONG_PTR ApiMessageData[39];
} Data;
};
};