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