Don't include NEVER_LOAD sections in image size.
Rename SizeOfImage to ResidentSize to avoid confusion
Modified: trunk/reactos/include/ntdll/ldr.h
Modified: trunk/reactos/lib/ntdll/ldr/startup.c
Modified: trunk/reactos/lib/ntdll/ldr/utils.c
Modified: trunk/reactos/lib/ntdll/rtl/dbgbuffer.c
Modified: trunk/reactos/lib/psapi/psapi.c
Modified: trunk/reactos/ntoskrnl/dbg/kdb_symbols.c
Modified: trunk/reactos/ntoskrnl/ke/i386/usertrap.c
_____
Modified: trunk/reactos/include/ntdll/ldr.h
--- trunk/reactos/include/ntdll/ldr.h 2005-02-09 18:18:20 UTC (rev
13476)
+++ trunk/reactos/include/ntdll/ldr.h 2005-02-09 18:34:13 UTC (rev
13477)
@@ -59,7 +59,7 @@
LIST_ENTRY InInitializationOrderModuleList; /* not used */
PVOID BaseAddress;
ULONG EntryPoint;
- ULONG SizeOfImage;
+ ULONG ResidentSize;
UNICODE_STRING FullDllName;
UNICODE_STRING BaseDllName;
ULONG Flags;
@@ -92,6 +92,9 @@
#endif
+ULONG
+LdrpGetResidentSize(PIMAGE_NT_HEADERS NTHeaders);
+
PEPFUNC LdrPEStartup (PVOID ImageBase,
HANDLE SectionHandle,
PLDR_MODULE* Module,
_____
Modified: trunk/reactos/lib/ntdll/ldr/startup.c
--- trunk/reactos/lib/ntdll/ldr/startup.c 2005-02-09 18:18:20 UTC
(rev 13476)
+++ trunk/reactos/lib/ntdll/ldr/startup.c 2005-02-09 18:34:13 UTC
(rev 13477)
@@ -222,7 +222,6 @@
return FALSE;
}
-
/* FUNCTIONS
*****************************************************************/
VOID STDCALL
@@ -382,7 +381,7 @@
NtModule->CheckSum = 0;
NTHeaders = RtlImageNtHeader (NtModule->BaseAddress);
- NtModule->SizeOfImage = NTHeaders->OptionalHeader.SizeOfImage;
+ NtModule->ResidentSize = LdrpGetResidentSize(NTHeaders);
NtModule->TimeDateStamp = NTHeaders->FileHeader.TimeDateStamp;
InsertTailList(&Peb->Ldr->InLoadOrderModuleList,
@@ -430,7 +429,7 @@
ExeModule->CheckSum = 0;
NTHeaders = RtlImageNtHeader (ExeModule->BaseAddress);
- ExeModule->SizeOfImage = NTHeaders->OptionalHeader.SizeOfImage;
+ ExeModule->ResidentSize = LdrpGetResidentSize(NTHeaders);
ExeModule->TimeDateStamp = NTHeaders->FileHeader.TimeDateStamp;
InsertHeadList(&Peb->Ldr->InLoadOrderModuleList,
_____
Modified: trunk/reactos/lib/ntdll/ldr/utils.c
--- trunk/reactos/lib/ntdll/ldr/utils.c 2005-02-09 18:18:20 UTC (rev
13476)
+++ trunk/reactos/lib/ntdll/ldr/utils.c 2005-02-09 18:34:13 UTC (rev
13477)
@@ -468,7 +468,7 @@
Module->EntryPoint = NTHeaders->OptionalHeader.AddressOfEntryPoint;
if (Module->EntryPoint != 0)
Module->EntryPoint += (ULONG)Module->BaseAddress;
- Module->SizeOfImage = NTHeaders->OptionalHeader.SizeOfImage;
+ Module->ResidentSize = LdrpGetResidentSize(NTHeaders);
if (NtCurrentPeb()->Ldr->Initialized == TRUE)
{
/* loading while app is running */
@@ -799,7 +799,7 @@
DPRINT("Scanning %wZ at %p\n", &ModulePtr->BaseDllName,
ModulePtr->BaseAddress);
if ((Address >= ModulePtr->BaseAddress) &&
- (Address <= (ModulePtr->BaseAddress +
ModulePtr->SizeOfImage)))
+ (Address <= (ModulePtr->BaseAddress +
ModulePtr->ResidentSize)))
{
*Module = ModulePtr;
RtlLeaveCriticalSection(NtCurrentPeb()->LoaderLock);
@@ -1581,7 +1581,7 @@
NTHeaders = RtlImageNtHeader (ImportedModule->BaseAddress);
Start = (PVOID)NTHeaders->OptionalHeader.ImageBase;
- End = Start + ImportedModule->SizeOfImage;
+ End = Start + ImportedModule->ResidentSize;
Offset = ImportedModule->BaseAddress - Start;
/* Walk through function list and fixup addresses. */
@@ -2708,7 +2708,7 @@
{
ModulePtr->Reserved[0] = ModulePtr->Reserved[1] = 0; //
FIXME: ??
ModulePtr->Base = Module->BaseAddress;
- ModulePtr->Size = Module->SizeOfImage;
+ ModulePtr->Size = Module->ResidentSize;
ModulePtr->Flags = Module->Flags;
ModulePtr->Index = 0; // FIXME: index ??
ModulePtr->Unknown = 0; // FIXME: ??
@@ -2814,7 +2814,34 @@
return (BOOLEAN)(CalcSum == HeaderSum);
}
+/*
+ * Compute size of an image as it is actually present in virt memory
+ * (i.e. excluding NEVER_LOAD sections)
+ */
+ULONG
+LdrpGetResidentSize(PIMAGE_NT_HEADERS NTHeaders)
+{
+ PIMAGE_SECTION_HEADER SectionHeader;
+ unsigned SectionIndex;
+ ULONG ResidentSize;
+ SectionHeader = (PIMAGE_SECTION_HEADER)((char *)
&NTHeaders->OptionalHeader
+ +
NTHeaders->FileHeader.SizeOfOptionalHeader);
+ ResidentSize = 0;
+ for (SectionIndex = 0; SectionIndex <
NTHeaders->FileHeader.NumberOfSections; SectionIndex++)
+ {
+ if (0 == (SectionHeader->Characteristics & IMAGE_SCN_LNK_REMOVE)
+ && ResidentSize < SectionHeader->VirtualAddress +
SectionHeader->Misc.VirtualSize)
+ {
+ ResidentSize = SectionHeader->VirtualAddress +
SectionHeader->Misc.VirtualSize;
+ }
+ SectionHeader++;
+ }
+
+ return ResidentSize;
+}
+
+
/***********************************************************************
****
* NAME
EXPORTED
* LdrVerifyImageMatchesChecksum
_____
Modified: trunk/reactos/lib/ntdll/rtl/dbgbuffer.c
--- trunk/reactos/lib/ntdll/rtl/dbgbuffer.c 2005-02-09 18:18:20 UTC
(rev 13476)
+++ trunk/reactos/lib/ntdll/rtl/dbgbuffer.c 2005-02-09 18:34:13 UTC
(rev 13477)
@@ -219,7 +219,7 @@
{
ModulePtr->Reserved[0] = ModulePtr->Reserved[1] = 0; //
FIXME: ??
ModulePtr->Base = lmModule.BaseAddress;
- ModulePtr->Size = lmModule.SizeOfImage;
+ ModulePtr->Size = lmModule.ResidentSize;
ModulePtr->Flags = lmModule.Flags;
ModulePtr->Index = 0; // FIXME: ??
ModulePtr->Unknown = 0; // FIXME: ??
_____
Modified: trunk/reactos/lib/psapi/psapi.c
--- trunk/reactos/lib/psapi/psapi.c 2005-02-09 18:18:20 UTC (rev
13476)
+++ trunk/reactos/lib/psapi/psapi.c 2005-02-09 18:34:13 UTC (rev
13477)
@@ -521,10 +521,10 @@
}
/* image size */
- if(nSize >= sizeof(CurrentModule->SizeOfImage))
+ if(nSize >= sizeof(CurrentModule->ResidentSize))
{
- Context->lpmodinfo->SizeOfImage = CurrentModule->SizeOfImage;
- nSize -= sizeof(CurrentModule->SizeOfImage);
+ Context->lpmodinfo->SizeOfImage = CurrentModule->ResidentSize;
+ nSize -= sizeof(CurrentModule->ResidentSize);
}
/* entry point */
_____
Modified: trunk/reactos/ntoskrnl/dbg/kdb_symbols.c
--- trunk/reactos/ntoskrnl/dbg/kdb_symbols.c 2005-02-09 18:18:20 UTC
(rev 13476)
+++ trunk/reactos/ntoskrnl/dbg/kdb_symbols.c 2005-02-09 18:34:13 UTC
(rev 13477)
@@ -92,7 +92,7 @@
current = CONTAINING_RECORD(current_entry, LDR_MODULE,
InLoadOrderModuleList);
if ((Address != NULL && (Address >= (PVOID)current->BaseAddress
&&
- Address < (PVOID)((char
*)current->BaseAddress + current->SizeOfImage))) ||
+ Address < (PVOID)((char
*)current->BaseAddress + current->ResidentSize))) ||
(Name != NULL && _wcsicmp(current->BaseDllName.Buffer, Name)
== 0) ||
(Index >= 0 && Count++ == Index))
{
@@ -102,7 +102,7 @@
wcsncpy(pInfo->Name, current->BaseDllName.Buffer, Length);
pInfo->Name[Length] = L'\0';
pInfo->Base = (ULONG_PTR)current->BaseAddress;
- pInfo->Size = current->SizeOfImage;
+ pInfo->Size = current->ResidentSize;
pInfo->RosSymInfo = current->RosSymInfo;
return TRUE;
}
_____
Modified: trunk/reactos/ntoskrnl/ke/i386/usertrap.c
--- trunk/reactos/ntoskrnl/ke/i386/usertrap.c 2005-02-09 18:18:20 UTC
(rev 13476)
+++ trunk/reactos/ntoskrnl/ke/i386/usertrap.c 2005-02-09 18:34:13 UTC
(rev 13477)
@@ -1,4 +1,4 @@
-/* $Id:$
+/* $Id$
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
@@ -54,7 +54,7 @@
CONTAINING_RECORD(current_entry, LDR_MODULE,
InLoadOrderModuleList);
if (address >= (PVOID)current->BaseAddress &&
- address < (PVOID)((char*)current->BaseAddress +
current->SizeOfImage))
+ address < (PVOID)((char*)current->BaseAddress +
current->ResidentSize))
{
RelativeAddress =
(ULONG_PTR) address - (ULONG_PTR)current->BaseAddress;