From 6247d82cc77c21463d77124d1ca5d0907b98bf87 Mon Sep 17 00:00:00 2001 From: Casper Hornstrup Date: Mon, 28 Apr 2003 21:32:10 +0000 Subject: [PATCH] 2003-04-28 Casper S. Hornstrup * Makefile (DLLS): Add epsapi, psapi and wsock32. * lib/ntdll/ldr/utils.c (LdrPerformRelocations): Handle the case where a relocation crosses a page boundary. (LdrFixupImports): Use image load address in calculatation of import address list. svn path=/trunk/; revision=4614 --- reactos/ChangeLog | 8 +++++++ reactos/Makefile | 4 ++-- reactos/lib/ntdll/ldr/utils.c | 43 ++++++++++++++++++++++++++++++++--- 3 files changed, 50 insertions(+), 5 deletions(-) diff --git a/reactos/ChangeLog b/reactos/ChangeLog index 055e28ffbe6..e337dd6dbb4 100644 --- a/reactos/ChangeLog +++ b/reactos/ChangeLog @@ -1,3 +1,11 @@ +2003-04-28 Casper S. Hornstrup + + * Makefile (DLLS): Add epsapi, psapi and wsock32. + * lib/ntdll/ldr/utils.c (LdrPerformRelocations): Handle the case where a + relocation crosses a page boundary. + (LdrFixupImports): Use image load address in calculatation of import + address list. + 2003-04-28 Casper S. Hornstrup * lib/fslib/vfatlib/vfatlib.h: New file. diff --git a/reactos/Makefile b/reactos/Makefile index 31c982e8000..56431ab23f3 100644 --- a/reactos/Makefile +++ b/reactos/Makefile @@ -32,9 +32,9 @@ LIB_FSLIB = vfatlib # User mode libraries # advapi32 crtdll fmifs gdi32 kernel32 libpcap packet msafd msvcrt ntdll ole32 -# oleaut32 psapi rpcrt4 secur32 shell32 user32 version ws2help ws2_32 wsock32 wshirda +# oleaut32 epsapi psapi rpcrt4 secur32 shell32 user32 version ws2help ws2_32 wsock32 wshirda DLLS = advapi32 crtdll fmifs freetype gdi32 kernel32 packet msafd msvcrt ntdll \ - secur32 user32 version winedbgc ws2help ws2_32 wshirda zlib epsapi #winmm + epsapi psapi secur32 user32 version winedbgc ws2help ws2_32 wsock32 wshirda zlib #winmm SUBSYS = smss win32k csrss ntvdm diff --git a/reactos/lib/ntdll/ldr/utils.c b/reactos/lib/ntdll/ldr/utils.c index 0f54ed6bc3a..0aa2d6fdac4 100644 --- a/reactos/lib/ntdll/ldr/utils.c +++ b/reactos/lib/ntdll/ldr/utils.c @@ -1,4 +1,4 @@ -/* $Id: utils.c,v 1.62 2003/04/26 10:05:38 gvg Exp $ +/* $Id: utils.c,v 1.63 2003/04/28 21:32:10 chorns Exp $ * * COPYRIGHT: See COPYING in the top level directory * PROJECT: ReactOS kernel @@ -712,7 +712,7 @@ LdrGetExportByName(PVOID BaseAddress, ULONG ExportDirSize; DPRINT("LdrGetExportByName %x %s %hu\n", BaseAddress, SymbolName, Hint); - + ExportDir = (PIMAGE_EXPORT_DIRECTORY) RtlImageDirectoryEntryToData(BaseAddress, TRUE, @@ -861,6 +861,7 @@ static NTSTATUS LdrPerformRelocations (PIMAGE_NT_HEADERS NTHeaders, int i; PIMAGE_DATA_DIRECTORY RelocationDDir; ULONG OldProtect; + ULONG OldProtect2; NTSTATUS Status; PIMAGE_SECTION_HEADER Sections; ULONG MaxExtend; @@ -918,6 +919,27 @@ static NTSTATUS LdrPerformRelocations (PIMAGE_NT_HEADERS NTHeaders, DPRINT1("Failed to unprotect relocation target.\n"); return(Status); } + + if (RelocationDir->VirtualAddress + PAGE_SIZE < MaxExtend) + { + Status = NtProtectVirtualMemory(NtCurrentProcess(), + ImageBase + + RelocationDir->VirtualAddress + PAGE_SIZE, + PAGE_SIZE, + PAGE_READWRITE, + &OldProtect2); + if (!NT_SUCCESS(Status)) + { + DPRINT1("Failed to unprotect relocation target (2).\n"); + NtProtectVirtualMemory(NtCurrentProcess(), + ImageBase + + RelocationDir->VirtualAddress, + PAGE_SIZE, + OldProtect, + &OldProtect); + return(Status); + } + } for (i = 0; i < NumberOfEntries; i++) { @@ -971,6 +993,21 @@ static NTSTATUS LdrPerformRelocations (PIMAGE_NT_HEADERS NTHeaders, return(Status); } + if (RelocationDir->VirtualAddress + PAGE_SIZE < MaxExtend) + { + Status = NtProtectVirtualMemory(NtCurrentProcess(), + ImageBase + + RelocationDir->VirtualAddress + PAGE_SIZE, + PAGE_SIZE, + OldProtect2, + &OldProtect2); + if (!NT_SUCCESS(Status)) + { + DPRINT1("Failed to protect relocation target2.\n"); + return(Status); + } + } + RelocationRVA += RelocationDir->SizeOfBlock; RelocationDir = (PRELOCATION_DIRECTORY) (ImageBase + RelocationRVA); @@ -1055,7 +1092,7 @@ static NTSTATUS LdrFixupImports(PIMAGE_NT_HEADERS NTHeaders, /* * Get the import address list. */ - ImportAddressList = (PVOID *)(NTHeaders->OptionalHeader.ImageBase + ImportAddressList = (PVOID *)(ImageBase + ImportModuleDirectory->dwRVAFunctionAddressList); /*