Author: ion
Date: Sun Oct 1 19:52:10 2006
New Revision: 24345
URL:
http://svn.reactos.org/svn/reactos?rev=24345&view=rev
Log:
- Implement static compile-time assertions and use them for structure field checks. Thanks
to Thomas and KJK.
Modified:
trunk/reactos/include/psdk/ntdef.h
trunk/reactos/ntoskrnl/ex/init.c
trunk/reactos/ntoskrnl/include/internal/ntoskrnl.h
Modified: trunk/reactos/include/psdk/ntdef.h
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/include/psdk/ntdef.h?rev=2…
==============================================================================
--- trunk/reactos/include/psdk/ntdef.h (original)
+++ trunk/reactos/include/psdk/ntdef.h Sun Oct 1 19:52:10 2006
@@ -106,4 +106,7 @@
#define MAXUCHAR 0xff
#define MAXUSHORT 0xffff
#define MAXULONG 0xffffffff
+
+#define C_ASSERT(e) extern char __C_ASSERT__[(e)?1:-1]
+
#endif /* _NTDEF_H */
Modified: trunk/reactos/ntoskrnl/ex/init.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/ex/init.c?rev=243…
==============================================================================
--- trunk/reactos/ntoskrnl/ex/init.c (original)
+++ trunk/reactos/ntoskrnl/ex/init.c Sun Oct 1 19:52:10 2006
@@ -249,44 +249,6 @@
__inline
VOID
STDCALL
-ExecuteRuntimeAsserts(VOID)
-{
- /*
- * Fail at runtime if someone has changed various structures without
- * updating the offsets used for the assembler code.
- */
- ASSERT(FIELD_OFFSET(KUSER_SHARED_DATA, SystemCall) == 0x300);
- ASSERT(FIELD_OFFSET(KTHREAD, InitialStack) == KTHREAD_INITIAL_STACK);
- ASSERT(FIELD_OFFSET(KTHREAD, Teb) == KTHREAD_TEB);
- ASSERT(FIELD_OFFSET(KTHREAD, KernelStack) == KTHREAD_KERNEL_STACK);
- ASSERT(FIELD_OFFSET(KTHREAD, NpxState) == KTHREAD_NPX_STATE);
- ASSERT(FIELD_OFFSET(KTHREAD, ServiceTable) == KTHREAD_SERVICE_TABLE);
- ASSERT(FIELD_OFFSET(KTHREAD, PreviousMode) == KTHREAD_PREVIOUS_MODE);
- ASSERT(FIELD_OFFSET(KTHREAD, TrapFrame) == KTHREAD_TRAP_FRAME);
- ASSERT(FIELD_OFFSET(KTHREAD, CallbackStack) == KTHREAD_CALLBACK_STACK);
- ASSERT(FIELD_OFFSET(KTHREAD, ApcState.Process) == KTHREAD_APCSTATE_PROCESS);
- ASSERT(FIELD_OFFSET(KPROCESS, DirectoryTableBase) == KPROCESS_DIRECTORY_TABLE_BASE);
- ASSERT(FIELD_OFFSET(KPROCESS, IopmOffset) == KPROCESS_IOPM_OFFSET);
- ASSERT(FIELD_OFFSET(KPROCESS, LdtDescriptor) == KPROCESS_LDT_DESCRIPTOR0);
- ASSERT(FIELD_OFFSET(KV86M_TRAP_FRAME, SavedExceptionStack) ==
TF_SAVED_EXCEPTION_STACK);
- ASSERT(FIELD_OFFSET(KV86M_TRAP_FRAME, regs) == TF_REGS);
- ASSERT(FIELD_OFFSET(KV86M_TRAP_FRAME, orig_ebp) == TF_ORIG_EBP);
- ASSERT(FIELD_OFFSET(KPCR, Tib.ExceptionList) == KPCR_EXCEPTION_LIST);
- ASSERT(FIELD_OFFSET(KPCR, Self) == KPCR_SELF);
- ASSERT(FIELD_OFFSET(KPCR, IRR) == KPCR_IRR);
- ASSERT(KeGetPcr()->IRR == 0);
- ASSERT(FIELD_OFFSET(KPCR, IDR) == KPCR_IDR);
- ASSERT(FIELD_OFFSET(KPCR, Irql) == KPCR_IRQL);
- ASSERT(FIELD_OFFSET(KIPCR, PrcbData) + FIELD_OFFSET(KPRCB, CurrentThread) ==
KPCR_CURRENT_THREAD);
- ASSERT(FIELD_OFFSET(KIPCR, PrcbData) + FIELD_OFFSET(KPRCB, NpxThread) ==
KPCR_NPX_THREAD);
- ASSERT(FIELD_OFFSET(KTSS, Esp0) == KTSS_ESP0);
- ASSERT(FIELD_OFFSET(KTSS, IoMapBase) == KTSS_IOMAPBASE);
- ASSERT(sizeof(FX_SAVE_AREA) == SIZEOF_FX_SAVE_AREA);
-}
-
-__inline
-VOID
-STDCALL
ParseAndCacheLoadedModules(VOID)
{
ULONG i;
@@ -524,9 +486,6 @@
NTAPI
ExpInitializeExecutive(VOID)
{
- /* Check if the structures match the ASM offset constants */
- ExecuteRuntimeAsserts();
-
/* Initialize HAL */
HalInitSystem (0, KeLoaderBlock);
Modified: trunk/reactos/ntoskrnl/include/internal/ntoskrnl.h
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/include/internal/…
==============================================================================
--- trunk/reactos/ntoskrnl/include/internal/ntoskrnl.h (original)
+++ trunk/reactos/ntoskrnl/include/internal/ntoskrnl.h Sun Oct 1 19:52:10 2006
@@ -294,4 +294,31 @@
#endif
+C_ASSERT(FIELD_OFFSET(KUSER_SHARED_DATA, SystemCall) == 0x300);
+C_ASSERT(FIELD_OFFSET(KTHREAD, InitialStack) == KTHREAD_INITIAL_STACK);
+C_ASSERT(FIELD_OFFSET(KTHREAD, Teb) == KTHREAD_TEB);
+C_ASSERT(FIELD_OFFSET(KTHREAD, KernelStack) == KTHREAD_KERNEL_STACK);
+C_ASSERT(FIELD_OFFSET(KTHREAD, NpxState) == KTHREAD_NPX_STATE);
+C_ASSERT(FIELD_OFFSET(KTHREAD, ServiceTable) == KTHREAD_SERVICE_TABLE);
+C_ASSERT(FIELD_OFFSET(KTHREAD, PreviousMode) == KTHREAD_PREVIOUS_MODE);
+C_ASSERT(FIELD_OFFSET(KTHREAD, TrapFrame) == KTHREAD_TRAP_FRAME);
+C_ASSERT(FIELD_OFFSET(KTHREAD, CallbackStack) == KTHREAD_CALLBACK_STACK);
+C_ASSERT(FIELD_OFFSET(KTHREAD, ApcState.Process) == KTHREAD_APCSTATE_PROCESS);
+C_ASSERT(FIELD_OFFSET(KPROCESS, DirectoryTableBase) == KPROCESS_DIRECTORY_TABLE_BASE);
+C_ASSERT(FIELD_OFFSET(KPROCESS, IopmOffset) == KPROCESS_IOPM_OFFSET);
+C_ASSERT(FIELD_OFFSET(KPROCESS, LdtDescriptor) == KPROCESS_LDT_DESCRIPTOR0);
+C_ASSERT(FIELD_OFFSET(KV86M_TRAP_FRAME, SavedExceptionStack) ==
TF_SAVED_EXCEPTION_STACK);
+C_ASSERT(FIELD_OFFSET(KV86M_TRAP_FRAME, regs) == TF_REGS);
+C_ASSERT(FIELD_OFFSET(KV86M_TRAP_FRAME, orig_ebp) == TF_ORIG_EBP);
+C_ASSERT(FIELD_OFFSET(KPCR, Tib.ExceptionList) == KPCR_EXCEPTION_LIST);
+C_ASSERT(FIELD_OFFSET(KPCR, Self) == KPCR_SELF);
+C_ASSERT(FIELD_OFFSET(KPCR, IRR) == KPCR_IRR);
+C_ASSERT(FIELD_OFFSET(KPCR, IDR) == KPCR_IDR);
+C_ASSERT(FIELD_OFFSET(KPCR, Irql) == KPCR_IRQL);
+C_ASSERT(FIELD_OFFSET(KIPCR, PrcbData) + FIELD_OFFSET(KPRCB, CurrentThread) ==
KPCR_CURRENT_THREAD);
+C_ASSERT(FIELD_OFFSET(KIPCR, PrcbData) + FIELD_OFFSET(KPRCB, NpxThread) ==
KPCR_NPX_THREAD);
+C_ASSERT(FIELD_OFFSET(KTSS, Esp0) == KTSS_ESP0);
+C_ASSERT(FIELD_OFFSET(KTSS, IoMapBase) == KTSS_IOMAPBASE);
+C_ASSERT(sizeof(FX_SAVE_AREA) == SIZEOF_FX_SAVE_AREA);
+
#endif /* INCLUDE_INTERNAL_NTOSKRNL_H */