Changed the indentation to a human readable format (no code change).

svn path=/trunk/; revision=18755
This commit is contained in:
Hartmut Birr 2005-10-24 18:00:46 +00:00
parent 152111652c
commit fea86552f0

View file

@ -46,11 +46,7 @@ static ULONG SectionCharacteristicsToProtect[16] =
};
/* TODO: Intsafe should be made into a library, as it's generally useful */
static __inline BOOLEAN Intsafe_CanAddULongPtr
(
IN ULONG_PTR Addend1,
IN ULONG_PTR Addend2
)
static __inline BOOLEAN Intsafe_CanAddULongPtr(IN ULONG_PTR Addend1, IN ULONG_PTR Addend2)
{
return Addend1 <= (MAXULONG_PTR - Addend2);
}
@ -59,30 +55,17 @@ static __inline BOOLEAN Intsafe_CanAddULongPtr
#define MAXLONGLONG ((LONGLONG)((~((ULONGLONG)0)) >> 1))
#endif
static __inline BOOLEAN Intsafe_CanAddLong64
(
IN LONG64 Addend1,
IN LONG64 Addend2
)
static __inline BOOLEAN Intsafe_CanAddLong64(IN LONG64 Addend1, IN LONG64 Addend2)
{
return Addend1 <= (MAXLONGLONG - Addend2);
}
static __inline BOOLEAN Intsafe_CanAddULong32
(
IN ULONG Addend1,
IN ULONG Addend2
)
static __inline BOOLEAN Intsafe_CanAddULong32(IN ULONG Addend1, IN ULONG Addend2)
{
return Addend1 <= (MAXULONG - Addend2);
}
static __inline BOOLEAN Intsafe_AddULong32
(
OUT PULONG Result,
IN ULONG Addend1,
IN ULONG Addend2
)
static __inline BOOLEAN Intsafe_AddULong32(OUT PULONG Result, IN ULONG Addend1, IN ULONG Addend2)
{
if(!Intsafe_CanAddULong32(Addend1, Addend2))
return FALSE;
@ -91,20 +74,12 @@ static __inline BOOLEAN Intsafe_AddULong32
return TRUE;
}
static __inline BOOLEAN Intsafe_CanMulULong32
(
IN ULONG Factor1,
IN ULONG Factor2
)
static __inline BOOLEAN Intsafe_CanMulULong32(IN ULONG Factor1, IN ULONG Factor2)
{
return Factor1 <= (MAXULONG / Factor2);
}
static __inline BOOLEAN Intsafe_CanOffsetPointer
(
IN CONST VOID * Pointer,
IN SIZE_T Offset
)
static __inline BOOLEAN Intsafe_CanOffsetPointer(IN CONST VOID * Pointer, IN SIZE_T Offset)
{
/* FIXME: (PVOID)MAXULONG_PTR isn't necessarily a valid address */
return Intsafe_CanAddULongPtr((ULONG_PTR)Pointer, Offset);
@ -147,12 +122,7 @@ static __inline BOOLEAN IsAligned(IN ULONG Address, IN ULONG Alignment)
return ModPow2(Address, Alignment) == 0;
}
static __inline BOOLEAN AlignUp
(
OUT PULONG AlignedAddress,
IN ULONG Address,
IN ULONG Alignment
)
static __inline BOOLEAN AlignUp(OUT PULONG AlignedAddress, IN ULONG Address, IN ULONG Alignment)
{
ULONG nExcess = ModPow2(Address, Alignment);
@ -176,16 +146,13 @@ static __inline BOOLEAN AlignUp
[1] Microsoft Corporation, "Microsoft Portable Executable and Common Object
File Format Specification", revision 6.0 (February 1999)
*/
NTSTATUS NTAPI PeFmtCreateSection
(
IN CONST VOID * FileHeader,
NTSTATUS NTAPI PeFmtCreateSection(IN CONST VOID * FileHeader,
IN SIZE_T FileHeaderSize,
IN PVOID File,
OUT PMM_IMAGE_SECTION_OBJECT ImageSectionObject,
OUT PULONG Flags,
IN PEXEFMT_CB_READ_FILE ReadFileCb,
IN PEXEFMT_CB_ALLOCATE_SEGMENTS AllocateSegmentsCb
)
IN PEXEFMT_CB_ALLOCATE_SEGMENTS AllocateSegmentsCb)
{
NTSTATUS nStatus;
ULONG cbFileHeaderOffsetSize = 0;
@ -250,8 +217,8 @@ NTSTATUS NTAPI PeFmtCreateSection
else
{
/*
we already know that Intsafe_CanOffsetPointer(FileHeader, FileHeaderSize),
and FileHeaderSize >= cbFileHeaderOffsetSize, so this holds true too
* we already know that Intsafe_CanOffsetPointer(FileHeader, FileHeaderSize),
* and FileHeaderSize >= cbFileHeaderOffsetSize, so this holds true too
*/
ASSERT(Intsafe_CanOffsetPointer(FileHeader, pidhDosHeader->e_lfanew));
pinhNtHeader = (PVOID)((UINT_PTR)FileHeader + pidhDosHeader->e_lfanew);
@ -263,14 +230,11 @@ NTSTATUS NTAPI PeFmtCreateSection
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
* the buffer doesn't contain the NT file header, or the alignment is wrong: we
* need to read the header from the file
*/
if
(
FileHeaderSize < cbFileHeaderOffsetSize ||
(UINT_PTR)pinhNtHeader % TYPE_ALIGNMENT(IMAGE_NT_HEADERS32) != 0
)
if(FileHeaderSize < cbFileHeaderOffsetSize ||
(UINT_PTR)pinhNtHeader % TYPE_ALIGNMENT(IMAGE_NT_HEADERS32) != 0)
{
ULONG cbNtHeaderSize;
ULONG cbReadSize;
@ -281,15 +245,7 @@ l_ReadHeaderFromFile:
lnOffset.QuadPart = pidhDosHeader->e_lfanew;
/* read the header from the file */
nStatus = ReadFileCb
(
File,
&lnOffset,
sizeof(IMAGE_NT_HEADERS64),
&pData,
&pBuffer,
&cbReadSize
);
nStatus = ReadFileCb(File, &lnOffset, sizeof(IMAGE_NT_HEADERS64), &pData, &pBuffer, &cbReadSize);
if(!NT_SUCCESS(nStatus))
DIE(("ReadFile failed, status %08X\n", nStatus));
@ -376,11 +332,8 @@ l_ReadHeaderFromFile:
ASSERT(PEFMT_FIELDS_EQUAL(IMAGE_OPTIONAL_HEADER32, IMAGE_OPTIONAL_HEADER64, SectionAlignment));
ASSERT(PEFMT_FIELDS_EQUAL(IMAGE_OPTIONAL_HEADER32, IMAGE_OPTIONAL_HEADER64, FileAlignment));
if
(
RTL_CONTAINS_FIELD(piohOptHeader, cbOptHeaderSize, SectionAlignment) &&
RTL_CONTAINS_FIELD(piohOptHeader, cbOptHeaderSize, FileAlignment)
)
if (RTL_CONTAINS_FIELD(piohOptHeader, cbOptHeaderSize, SectionAlignment) &&
RTL_CONTAINS_FIELD(piohOptHeader, cbOptHeaderSize, FileAlignment))
{
/* See [1], section 3.4.2 */
if(piohOptHeader->SectionAlignment < PAGE_SIZE)
@ -470,11 +423,8 @@ l_ReadHeaderFromFile:
{
ImageSectionObject->Subsystem = piohOptHeader->Subsystem;
if
(
RTL_CONTAINS_FIELD(piohOptHeader, cbOptHeaderSize, MinorSubsystemVersion) &&
RTL_CONTAINS_FIELD(piohOptHeader, cbOptHeaderSize, MajorSubsystemVersion)
)
if(RTL_CONTAINS_FIELD(piohOptHeader, cbOptHeaderSize, MinorSubsystemVersion) &&
RTL_CONTAINS_FIELD(piohOptHeader, cbOptHeaderSize, MajorSubsystemVersion))
{
ImageSectionObject->MinorSubsystemVersion = piohOptHeader->MinorSubsystemVersion;
ImageSectionObject->MajorSubsystemVersion = piohOptHeader->MajorSubsystemVersion;
@ -507,9 +457,9 @@ l_ReadHeaderFromFile:
DIE(("Too many sections, NumberOfSections is %u\n", pinhNtHeader->FileHeader.NumberOfSections));
/*
the additional segment is for the file's headers. They need to be present for
the benefit of the dynamic loader (to locate exports, defaults for thread
parameters, resources, etc.)
* the additional segment is for the file's headers. They need to be present for
* the benefit of the dynamic loader (to locate exports, defaults for thread
* parameters, resources, etc.)
*/
ImageSectionObject->NrSegments = pinhNtHeader->FileHeader.NumberOfSections + 1;
@ -557,22 +507,19 @@ l_ReadHeaderFromFile:
else
{
/*
we already know that Intsafe_CanOffsetPointer(FileHeader, FileHeaderSize),
and FileHeaderSize >= cbSectionHeadersOffsetSize, so this holds true too
* we already know that Intsafe_CanOffsetPointer(FileHeader, FileHeaderSize),
* and FileHeaderSize >= cbSectionHeadersOffsetSize, so this holds true too
*/
ASSERT(Intsafe_CanOffsetPointer(FileHeader, cbSectionHeadersOffset));
pishSectionHeaders = (PVOID)((UINT_PTR)FileHeader + cbSectionHeadersOffset);
}
/*
the buffer doesn't contain the section headers, or the alignment is wrong:
read the headers from the file
* the buffer doesn't contain the section headers, or the alignment is wrong:
* read the headers from the file
*/
if
(
FileHeaderSize < cbSectionHeadersOffsetSize ||
(UINT_PTR)pishSectionHeaders % TYPE_ALIGNMENT(IMAGE_SECTION_HEADER) != 0
)
if(FileHeaderSize < cbSectionHeadersOffsetSize ||
(UINT_PTR)pishSectionHeaders % TYPE_ALIGNMENT(IMAGE_SECTION_HEADER) != 0)
{
PVOID pData;
ULONG cbReadSize;
@ -580,15 +527,7 @@ l_ReadHeaderFromFile:
lnOffset.QuadPart = cbSectionHeadersOffset;
/* read the header from the file */
nStatus = ReadFileCb
(
File,
&lnOffset,
cbSectionHeadersSize,
&pData,
&pBuffer,
&cbReadSize
);
nStatus = ReadFileCb(File, &lnOffset, cbSectionHeadersSize, &pData, &pBuffer, &cbReadSize);
if(!NT_SUCCESS(nStatus))
DIE(("ReadFile failed with status %08X\n", nStatus));
@ -663,8 +602,10 @@ l_ReadHeaderFromFile:
if(pishSectionHeaders[i].SizeOfRawData != 0)
{
/* validate the alignment */
#if 0 /* Yes, this should be a multiple of FileAlignment, but there's
stuff out there that isn't. We can cope with that */
#if 0
/* Yes, this should be a multiple of FileAlignment, but there's
* stuff out there that isn't. We can cope with that
*/
if(!IsAligned(pishSectionHeaders[i].SizeOfRawData, nFileAlignment))
DIE(("SizeOfRawData[%u] is not aligned\n", i));
#endif