Author: sginsberg
Date: Sat Jul 25 21:38:52 2009
New Revision: 42216
URL:
http://svn.reactos.org/svn/reactos?rev=42216&view=rev
Log:
- FIELD_OFFSET returns LONG, not LONG_PTR or size_t.
- Define TYPE_ALIGNMENT for msvc.
- Define DbgPrintEx the same way in NDK and DDK
- C_ASSERT is a typedef, so don't put it inside functions as msvc doesn't allow
this.
- Kernel now *compiles* with RosBE + msvc _and_ our DDK. Linker errors from the ninth
circle of hell remains.
Modified:
trunk/reactos/include/ddk/ntdef.h
trunk/reactos/include/ddk/winddk.h
trunk/reactos/include/host/typedefs.h
trunk/reactos/include/psdk/winnt.h
trunk/reactos/ntoskrnl/ke/wait.c
trunk/reactos/ntoskrnl/mm/pe.c
Modified: trunk/reactos/include/ddk/ntdef.h
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/include/ddk/ntdef.h?rev=42…
==============================================================================
--- trunk/reactos/include/ddk/ntdef.h [iso-8859-1] (original)
+++ trunk/reactos/include/ddk/ntdef.h [iso-8859-1] Sat Jul 25 21:38:52 2009
@@ -155,20 +155,20 @@
//
// Returns the byte offset of the specified structure's member
//
-#ifndef FIELD_OFFSET
#ifndef __GNUC__
-#define FIELD_OFFSET(Type, Field) \
- ((LONG)(LONG_PTR) (&(((Type *) 0)->Field)))
+#define FIELD_OFFSET(Type, Field) ((LONG)(LONG_PTR)&(((Type*) 0)->Field))
#else
#define FIELD_OFFSET(Type, Field) __builtin_offsetof(Type, Field)
#endif
-#endif
//
// Returns the type's alignment
//
+#if defined(_MSC_VER) && (_MSC_VER >= 1300)
+#define TYPE_ALIGNMENT(t) __alignof(t)
+#else
#define TYPE_ALIGNMENT(t) FIELD_OFFSET( struct { char x; t test; }, test )
-
+#endif
//
// Calling Conventions
Modified: trunk/reactos/include/ddk/winddk.h
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/include/ddk/winddk.h?rev=4…
==============================================================================
--- trunk/reactos/include/ddk/winddk.h [iso-8859-1] (original)
+++ trunk/reactos/include/ddk/winddk.h [iso-8859-1] Sat Jul 25 21:38:52 2009
@@ -10277,6 +10277,7 @@
IN PCCH Format,
IN ...);
+NTSYSAPI
ULONG
DDKCDECLAPI
DbgPrintEx(
Modified: trunk/reactos/include/host/typedefs.h
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/include/host/typedefs.h?re…
==============================================================================
--- trunk/reactos/include/host/typedefs.h [iso-8859-1] (original)
+++ trunk/reactos/include/host/typedefs.h [iso-8859-1] Sat Jul 25 21:38:52 2009
@@ -219,9 +219,9 @@
#define NT_SUCCESS(x) ((x)>=0)
#if !defined(__GNUC__)
-#define FIELD_OFFSET(t,f) ((LONG_PTR)&(((t*)0)->f))
+#define FIELD_OFFSET(t,f) ((LONG)(LONG_PTR)&(((t*) 0)->f))
#else
-#define FIELD_OFFSET(t,f) __builtin_offsetof(t,f)
+#define FIELD_OFFSET(t,f) ((LONG)__builtin_offsetof(t,f))
#endif
#define RTL_CONSTANT_STRING(s) { sizeof(s)-sizeof((s)[0]), sizeof(s), s }
#define CONTAINING_RECORD(address, type, field) ((type *)(((ULONG_PTR)address) -
(ULONG_PTR)(&(((type *)0)->field))))
Modified: trunk/reactos/include/psdk/winnt.h
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/include/psdk/winnt.h?rev=4…
==============================================================================
--- trunk/reactos/include/psdk/winnt.h [iso-8859-1] (original)
+++ trunk/reactos/include/psdk/winnt.h [iso-8859-1] Sat Jul 25 21:38:52 2009
@@ -1311,10 +1311,10 @@
#define RTL_CRITSECT_TYPE 0
#define RTL_RESOURCE_TYPE 1
/* Also in winddk.h */
-#ifndef __GNUC__
-#define FIELD_OFFSET(t,f) ((LONG_PTR)&(((t*)0)->f))
+#if !defined(__GNUC__)
+#define FIELD_OFFSET(t,f) ((LONG)(LONG_PTR)&(((t*) 0)->f))
#else
-#define FIELD_OFFSET(t,f) __builtin_offsetof(t,f)
+#define FIELD_OFFSET(t,f) ((LONG)__builtin_offsetof(t,f))
#endif
#ifndef CONTAINING_RECORD
#define CONTAINING_RECORD(address, type, field) \
Modified: trunk/reactos/ntoskrnl/ke/wait.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/ke/wait.c?rev=422…
==============================================================================
--- trunk/reactos/ntoskrnl/ke/wait.c [iso-8859-1] (original)
+++ trunk/reactos/ntoskrnl/ke/wait.c [iso-8859-1] Sat Jul 25 21:38:52 2009
@@ -116,6 +116,9 @@
FALSE,
NULL);
}
+
+/* KiAcquireGuardedMutex depends on these bits being right */
+C_ASSERT((GM_LOCK_WAITER_WOKEN * 2) == GM_LOCK_WAITER_INC);
VOID
FASTCALL
@@ -181,9 +184,6 @@
/* Ok, the wait is done, so set the new bits */
BitsToRemove = GM_LOCK_BIT | GM_LOCK_WAITER_WOKEN;
BitsToAdd = GM_LOCK_WAITER_WOKEN;
-
- /* We depend on these bits being just right */
- C_ASSERT((GM_LOCK_WAITER_WOKEN * 2) == GM_LOCK_WAITER_INC);
}
}
Modified: trunk/reactos/ntoskrnl/mm/pe.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/mm/pe.c?rev=42216…
==============================================================================
--- trunk/reactos/ntoskrnl/mm/pe.c [iso-8859-1] (original)
+++ trunk/reactos/ntoskrnl/mm/pe.c [iso-8859-1] Sat Jul 25 21:38:52 2009
@@ -136,6 +136,84 @@
(RTL_FIELD_SIZE(TYPE1_, FIELD_) == RTL_FIELD_SIZE(TYPE2_, FIELD_)) \
)
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+//
+// FIXME: All this whitespace is "padding" so the C_ASSERTs aren't on the
same lines as asserts in other headers.
+// This is necessary because of the way we define C_ASSERT in a gcc compatible way.
+// This can be removed once we upgrade to gcc 4.3.x or later (which implements
__COUNTER__).
+//
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+//
+// PeFmtCreateSection depends on the following:
+//
+C_ASSERT(EXEFMT_LOAD_HEADER_SIZE >= sizeof(IMAGE_DOS_HEADER));
+C_ASSERT(sizeof(IMAGE_NT_HEADERS32) <= sizeof(IMAGE_NT_HEADERS64));
+
+C_ASSERT(TYPE_ALIGNMENT(IMAGE_NT_HEADERS32) == TYPE_ALIGNMENT(IMAGE_NT_HEADERS64));
+C_ASSERT(RTL_SIZEOF_THROUGH_FIELD(IMAGE_NT_HEADERS32, FileHeader) ==
RTL_SIZEOF_THROUGH_FIELD(IMAGE_NT_HEADERS64, FileHeader));
+C_ASSERT(FIELD_OFFSET(IMAGE_NT_HEADERS32, OptionalHeader) ==
FIELD_OFFSET(IMAGE_NT_HEADERS64, OptionalHeader));
+
+C_ASSERT(PEFMT_FIELDS_EQUAL(IMAGE_OPTIONAL_HEADER32, IMAGE_OPTIONAL_HEADER64, Magic));
+C_ASSERT(PEFMT_FIELDS_EQUAL(IMAGE_OPTIONAL_HEADER32, IMAGE_OPTIONAL_HEADER64,
SectionAlignment));
+C_ASSERT(PEFMT_FIELDS_EQUAL(IMAGE_OPTIONAL_HEADER32, IMAGE_OPTIONAL_HEADER64,
FileAlignment));
+C_ASSERT(PEFMT_FIELDS_EQUAL(IMAGE_OPTIONAL_HEADER32, IMAGE_OPTIONAL_HEADER64,
Subsystem));
+C_ASSERT(PEFMT_FIELDS_EQUAL(IMAGE_OPTIONAL_HEADER32, IMAGE_OPTIONAL_HEADER64,
MinorSubsystemVersion));
+C_ASSERT(PEFMT_FIELDS_EQUAL(IMAGE_OPTIONAL_HEADER32, IMAGE_OPTIONAL_HEADER64,
MajorSubsystemVersion));
+C_ASSERT(PEFMT_FIELDS_EQUAL(IMAGE_OPTIONAL_HEADER32, IMAGE_OPTIONAL_HEADER64,
AddressOfEntryPoint));
+C_ASSERT(PEFMT_FIELDS_EQUAL(IMAGE_OPTIONAL_HEADER32, IMAGE_OPTIONAL_HEADER64,
SizeOfCode));
+C_ASSERT(PEFMT_FIELDS_EQUAL(IMAGE_OPTIONAL_HEADER32, IMAGE_OPTIONAL_HEADER64,
SizeOfHeaders));
+
/*
References:
[1] Microsoft Corporation, "Microsoft Portable Executable and Common Object
@@ -178,7 +256,6 @@
ASSERT(Intsafe_CanOffsetPointer(FileHeader, FileHeaderSize));
- C_ASSERT(EXEFMT_LOAD_HEADER_SIZE >= sizeof(IMAGE_DOS_HEADER));
ASSERT(((UINT_PTR)FileHeader % TYPE_ALIGNMENT(IMAGE_DOS_HEADER)) == 0);
#define DIE(ARGS_) { DPRINT ARGS_; goto l_Return; }
@@ -219,11 +296,6 @@
pinhNtHeader = (PVOID)((UINT_PTR)FileHeader + pidhDosHeader->e_lfanew);
}
- C_ASSERT(sizeof(IMAGE_NT_HEADERS32) <= sizeof(IMAGE_NT_HEADERS64));
- C_ASSERT(TYPE_ALIGNMENT(IMAGE_NT_HEADERS32) == TYPE_ALIGNMENT(IMAGE_NT_HEADERS64));
- C_ASSERT(RTL_SIZEOF_THROUGH_FIELD(IMAGE_NT_HEADERS32, FileHeader) ==
RTL_SIZEOF_THROUGH_FIELD(IMAGE_NT_HEADERS64, FileHeader));
- C_ASSERT(FIELD_OFFSET(IMAGE_NT_HEADERS32, OptionalHeader) ==
FIELD_OFFSET(IMAGE_NT_HEADERS64, OptionalHeader));
-
/*
* the buffer doesn't contain the NT file header, or the alignment is wrong: we
* need to read the header from the file
@@ -307,8 +379,6 @@
nStatus = STATUS_INVALID_IMAGE_FORMAT;
- C_ASSERT(PEFMT_FIELDS_EQUAL(IMAGE_OPTIONAL_HEADER32, IMAGE_OPTIONAL_HEADER64,
Magic));
-
if(!RTL_CONTAINS_FIELD(piohOptHeader, cbOptHeaderSize, Magic))
DIE(("The optional header doesn't contain the Magic field, SizeOfOptionalHeader
is %X\n", cbOptHeaderSize));
@@ -323,9 +393,6 @@
default:
DIE(("Unrecognized optional header, Magic is %X\n",
piohOptHeader->Magic));
}
-
- C_ASSERT(PEFMT_FIELDS_EQUAL(IMAGE_OPTIONAL_HEADER32, IMAGE_OPTIONAL_HEADER64,
SectionAlignment));
- C_ASSERT(PEFMT_FIELDS_EQUAL(IMAGE_OPTIONAL_HEADER32, IMAGE_OPTIONAL_HEADER64,
FileAlignment));
if (RTL_CONTAINS_FIELD(piohOptHeader, cbOptHeaderSize, SectionAlignment) &&
RTL_CONTAINS_FIELD(piohOptHeader, cbOptHeaderSize, FileAlignment))
@@ -421,10 +488,6 @@
if((ULONG_PTR)ImageSectionObject->ImageBase % 0x10000)
DIE(("ImageBase is not aligned on a 64KB boundary"));
- C_ASSERT(PEFMT_FIELDS_EQUAL(IMAGE_OPTIONAL_HEADER32, IMAGE_OPTIONAL_HEADER64,
Subsystem));
- C_ASSERT(PEFMT_FIELDS_EQUAL(IMAGE_OPTIONAL_HEADER32, IMAGE_OPTIONAL_HEADER64,
MinorSubsystemVersion));
- C_ASSERT(PEFMT_FIELDS_EQUAL(IMAGE_OPTIONAL_HEADER32, IMAGE_OPTIONAL_HEADER64,
MajorSubsystemVersion));
-
if(RTL_CONTAINS_FIELD(piohOptHeader, cbOptHeaderSize, Subsystem))
{
ImageSectionObject->Subsystem = piohOptHeader->Subsystem;
@@ -437,15 +500,11 @@
}
}
- C_ASSERT(PEFMT_FIELDS_EQUAL(IMAGE_OPTIONAL_HEADER32, IMAGE_OPTIONAL_HEADER64,
AddressOfEntryPoint));
-
if(RTL_CONTAINS_FIELD(piohOptHeader, cbOptHeaderSize, AddressOfEntryPoint))
{
ImageSectionObject->EntryPoint = piohOptHeader->ImageBase +
piohOptHeader->AddressOfEntryPoint;
}
-
- C_ASSERT(PEFMT_FIELDS_EQUAL(IMAGE_OPTIONAL_HEADER32, IMAGE_OPTIONAL_HEADER64,
SizeOfCode));
if(RTL_CONTAINS_FIELD(piohOptHeader, cbOptHeaderSize, SizeOfCode))
ImageSectionObject->Executable = piohOptHeader->SizeOfCode != 0;
@@ -482,8 +541,6 @@
if(!Intsafe_AddULong32(&cbSectionHeadersOffsetSize, cbSectionHeadersOffset,
cbSectionHeadersSize))
DIE(("Section headers too large\n"));
-
- C_ASSERT(PEFMT_FIELDS_EQUAL(IMAGE_OPTIONAL_HEADER32, IMAGE_OPTIONAL_HEADER64,
SizeOfHeaders));
/* size of the executable's headers */
if(RTL_CONTAINS_FIELD(piohOptHeader, cbOptHeaderSize, SizeOfHeaders))