[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.

svn path=/trunk/; revision=59913
This commit is contained in:
Alex Ionescu 2013-08-31 02:19:36 +00:00
parent 0b45497394
commit 084a679a6b
2 changed files with 32 additions and 5 deletions

View file

@ -321,6 +321,33 @@ CsrClientConnectToServer(IN PWSTR ObjectDirectory,
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 @@ CsrClientCallServer(IN OUT PCSR_API_MESSAGE ApiMessage,
/* 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;

View file

@ -133,7 +133,7 @@ typedef struct _CSR_API_MESSAGE
// 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;
};
};