From 9cea7cc06ce4344a3d0389945e14eb0868ee3577 Mon Sep 17 00:00:00 2001 From: Filip Navara Date: Sat, 26 Jun 2004 15:11:14 +0000 Subject: [PATCH] - Readded the code for unportecting second page while relocating. Some applications like OpenOffice actually depend on it. svn path=/trunk/; revision=9885 --- reactos/lib/ntdll/ldr/utils.c | 39 +++++++++++++++++++++++++++++++---- 1 file changed, 35 insertions(+), 4 deletions(-) diff --git a/reactos/lib/ntdll/ldr/utils.c b/reactos/lib/ntdll/ldr/utils.c index c152a119888..e68ef93bcaa 100644 --- a/reactos/lib/ntdll/ldr/utils.c +++ b/reactos/lib/ntdll/ldr/utils.c @@ -1,4 +1,4 @@ -/* $Id: utils.c,v 1.94 2004/06/26 14:37:05 navaraf Exp $ +/* $Id: utils.c,v 1.95 2004/06/26 15:11:14 navaraf Exp $ * * COPYRIGHT: See COPYING in the top level directory * PROJECT: ReactOS kernel @@ -1226,8 +1226,8 @@ LdrPerformRelocations(PIMAGE_NT_HEADERS NTHeaders, { PIMAGE_DATA_DIRECTORY RelocationDDir; PIMAGE_BASE_RELOCATION RelocationDir, RelocationEnd; - ULONG Count, ProtectSize, OldProtect, i; - PVOID Page, ProtectPage; + ULONG Count, ProtectSize, OldProtect, OldProtect2, i; + PVOID Page, ProtectPage, ProtectPage2; PWORD TypeOffset; ULONG Delta = (ULONG_PTR)ImageBase - NTHeaders->OptionalHeader.ImageBase; NTSTATUS Status; @@ -1258,7 +1258,7 @@ LdrPerformRelocations(PIMAGE_NT_HEADERS NTHeaders, Page = ImageBase + RelocationDir->VirtualAddress; TypeOffset = (PWORD)(RelocationDir + 1); - /* Unprotect the page we're about to relocate. */ + /* Unprotect the page(s) we're about to relocate. */ ProtectPage = Page; Status = NtProtectVirtualMemory(NtCurrentProcess(), &ProtectPage, @@ -1271,6 +1271,27 @@ LdrPerformRelocations(PIMAGE_NT_HEADERS NTHeaders, return(Status); } + if (RelocationDir->VirtualAddress + PAGE_SIZE < + NTHeaders->OptionalHeader.SizeOfImage) + { + ProtectPage2 = ProtectPage + PAGE_SIZE; + Status = NtProtectVirtualMemory(NtCurrentProcess(), + &ProtectPage2, + &ProtectSize, + PAGE_READWRITE, + &OldProtect2); + if (!NT_SUCCESS(Status)) + { + DPRINT1("Failed to unprotect relocation target (2).\n"); + NtProtectVirtualMemory(NtCurrentProcess(), + &ProtectPage, + &ProtectSize, + OldProtect, + &OldProtect); + return(Status); + } + } + /* Patch the page. */ for (i = 0; i < Count; i++) { @@ -1304,6 +1325,16 @@ LdrPerformRelocations(PIMAGE_NT_HEADERS NTHeaders, OldProtect, &OldProtect); + if (RelocationDir->VirtualAddress + PAGE_SIZE < + NTHeaders->OptionalHeader.SizeOfImage) + { + NtProtectVirtualMemory(NtCurrentProcess(), + &ProtectPage2, + &ProtectSize, + OldProtect2, + &OldProtect2); + } + RelocationDir = (IMAGE_BASE_RELOCATION*)((ULONG_PTR)RelocationDir + RelocationDir->SizeOfBlock); }