https://git.reactos.org/?p=reactos.git;a=commitdiff;h=e6ea0bcbbf59237c5c4d2…
commit e6ea0bcbbf59237c5c4d2d270d7927a3cb49137a
Author: Mark Jansen <mark.jansen(a)reactos.org>
AuthorDate: Sun Jul 22 13:03:51 2018 +0200
Commit: Mark Jansen <mark.jansen(a)reactos.org>
CommitDate: Wed Jul 25 20:22:36 2018 +0200
[KMTESTS] Add compile time asserts for IO_STACK_LOCATION offsets
CORE-14782
---
modules/rostests/kmtests/CMakeLists.txt | 1 +
modules/rostests/kmtests/kmtest_drv/structs.c | 71 +++++++++++++++++++++++++++
2 files changed, 72 insertions(+)
diff --git a/modules/rostests/kmtests/CMakeLists.txt
b/modules/rostests/kmtests/CMakeLists.txt
index bb4ee5beba..bcc95c5e91 100644
--- a/modules/rostests/kmtests/CMakeLists.txt
+++ b/modules/rostests/kmtests/CMakeLists.txt
@@ -31,6 +31,7 @@ list(APPEND COMMON_SOURCE
list(APPEND KMTEST_DRV_SOURCE
kmtest_drv/guid.c
kmtest_drv/kmtest_drv.c
+ kmtest_drv/structs.c
kmtest_drv/testlist.c
example/Example.c
diff --git a/modules/rostests/kmtests/kmtest_drv/structs.c
b/modules/rostests/kmtests/kmtest_drv/structs.c
new file mode 100644
index 0000000000..9ee74dd64b
--- /dev/null
+++ b/modules/rostests/kmtests/kmtest_drv/structs.c
@@ -0,0 +1,71 @@
+/*
+ * PROJECT: ReactOS kernel-mode tests
+ * LICENSE: LGPL-2.1+ (
https://spdx.org/licenses/LGPL-2.1+)
+ * PURPOSE: Kernel-Mode Test Suite Struct alignment tests
+ * COPYRIGHT: Copyright 2018 Mark Jansen (mark.jansen(a)reactos.org)
+ */
+
+#include <kmt_test.h>
+
+// When searching for the correct offset,
+// this will generate a compile-time error including the offset:
+// char (*__kaboom1)[FIELD_OFFSET(IO_STACK_LOCATION, Parameters.Create.EaLength)] = 1;
+// Taken from
https://stackoverflow.com/a/35261673
+
+#if !defined(_AMD64_)
+
+C_ASSERT(sizeof(IO_STACK_LOCATION) == 36);
+
+C_ASSERT(FIELD_OFFSET(IO_STACK_LOCATION, MajorFunction) == 0);
+C_ASSERT(FIELD_OFFSET(IO_STACK_LOCATION, MinorFunction) == 1);
+C_ASSERT(FIELD_OFFSET(IO_STACK_LOCATION, Flags) == 2);
+C_ASSERT(FIELD_OFFSET(IO_STACK_LOCATION, Control) == 3);
+
+C_ASSERT(FIELD_OFFSET(IO_STACK_LOCATION, Parameters.Create.SecurityContext) == 4);
+C_ASSERT(FIELD_OFFSET(IO_STACK_LOCATION, Parameters.Create.Options) == 8);
+C_ASSERT(FIELD_OFFSET(IO_STACK_LOCATION, Parameters.Create.FileAttributes) == 12);
+C_ASSERT(FIELD_OFFSET(IO_STACK_LOCATION, Parameters.Create.ShareAccess) == 14);
+C_ASSERT(FIELD_OFFSET(IO_STACK_LOCATION, Parameters.Create.EaLength) == 16);
+
+C_ASSERT(FIELD_OFFSET(IO_STACK_LOCATION, Parameters.ReadWriteConfig.WhichSpace) == 4);
+C_ASSERT(FIELD_OFFSET(IO_STACK_LOCATION, Parameters.ReadWriteConfig.Buffer) == 8);
+C_ASSERT(FIELD_OFFSET(IO_STACK_LOCATION, Parameters.ReadWriteConfig.Offset) == 12);
+C_ASSERT(FIELD_OFFSET(IO_STACK_LOCATION, Parameters.ReadWriteConfig.Length) == 16);
+
+C_ASSERT(FIELD_OFFSET(IO_STACK_LOCATION, Parameters.SetFile.Length) == 4);
+C_ASSERT(FIELD_OFFSET(IO_STACK_LOCATION, Parameters.SetFile.FileInformationClass) == 8);
+C_ASSERT(FIELD_OFFSET(IO_STACK_LOCATION, Parameters.SetFile.FileObject) == 12);
+C_ASSERT(FIELD_OFFSET(IO_STACK_LOCATION, Parameters.SetFile.ReplaceIfExists) == 16);
+C_ASSERT(FIELD_OFFSET(IO_STACK_LOCATION, Parameters.SetFile.AdvanceOnly) == 17);
+C_ASSERT(FIELD_OFFSET(IO_STACK_LOCATION, Parameters.SetFile.ClusterCount) == 16);
+C_ASSERT(FIELD_OFFSET(IO_STACK_LOCATION, Parameters.SetFile.DeleteHandle) == 16);
+
+#else
+
+C_ASSERT(sizeof(IO_STACK_LOCATION) == 72);
+
+C_ASSERT(FIELD_OFFSET(IO_STACK_LOCATION, MajorFunction) == 0);
+C_ASSERT(FIELD_OFFSET(IO_STACK_LOCATION, MinorFunction) == 1);
+C_ASSERT(FIELD_OFFSET(IO_STACK_LOCATION, Flags) == 2);
+C_ASSERT(FIELD_OFFSET(IO_STACK_LOCATION, Control) == 3);
+
+C_ASSERT(FIELD_OFFSET(IO_STACK_LOCATION, Parameters.Create.SecurityContext) == 8);
+C_ASSERT(FIELD_OFFSET(IO_STACK_LOCATION, Parameters.Create.Options) == 16);
+C_ASSERT(FIELD_OFFSET(IO_STACK_LOCATION, Parameters.Create.FileAttributes) == 24);
+C_ASSERT(FIELD_OFFSET(IO_STACK_LOCATION, Parameters.Create.ShareAccess) == 26);
+C_ASSERT(FIELD_OFFSET(IO_STACK_LOCATION, Parameters.Create.EaLength) == 32);
+
+C_ASSERT(FIELD_OFFSET(IO_STACK_LOCATION, Parameters.ReadWriteConfig.WhichSpace) == 8);
+C_ASSERT(FIELD_OFFSET(IO_STACK_LOCATION, Parameters.ReadWriteConfig.Buffer) == 16);
+C_ASSERT(FIELD_OFFSET(IO_STACK_LOCATION, Parameters.ReadWriteConfig.Offset) == 24);
+C_ASSERT(FIELD_OFFSET(IO_STACK_LOCATION, Parameters.ReadWriteConfig.Length) == 32);
+
+C_ASSERT(FIELD_OFFSET(IO_STACK_LOCATION, Parameters.SetFile.Length) == 8);
+C_ASSERT(FIELD_OFFSET(IO_STACK_LOCATION, Parameters.SetFile.FileInformationClass) ==
16);
+C_ASSERT(FIELD_OFFSET(IO_STACK_LOCATION, Parameters.SetFile.FileObject) == 24);
+C_ASSERT(FIELD_OFFSET(IO_STACK_LOCATION, Parameters.SetFile.ReplaceIfExists) == 32);
+C_ASSERT(FIELD_OFFSET(IO_STACK_LOCATION, Parameters.SetFile.AdvanceOnly) == 33);
+C_ASSERT(FIELD_OFFSET(IO_STACK_LOCATION, Parameters.SetFile.ClusterCount) == 32);
+C_ASSERT(FIELD_OFFSET(IO_STACK_LOCATION, Parameters.SetFile.DeleteHandle) == 32);
+
+#endif