From 89e2e7a616a9feb204f3fab29b3175d998107832 Mon Sep 17 00:00:00 2001 From: Phillip Susi Date: Wed, 24 Jan 2001 04:43:54 +0000 Subject: [PATCH] Fixed kernel loader code also to handle uninitialized sections svn path=/trunk/; revision=1561 --- reactos/ntoskrnl/ldr/userldr.c | 45 +++++++++++++++++++++++----------- 1 file changed, 31 insertions(+), 14 deletions(-) diff --git a/reactos/ntoskrnl/ldr/userldr.c b/reactos/ntoskrnl/ldr/userldr.c index 09e4e20b0af..40ae382a021 100644 --- a/reactos/ntoskrnl/ldr/userldr.c +++ b/reactos/ntoskrnl/ldr/userldr.c @@ -187,21 +187,38 @@ NTSTATUS LdrpMapImage(HANDLE ProcessHandle, Size = Sections[i].Misc.VirtualSize; KeDetachProcess(); - Status = ZwMapViewOfSection(SectionHandle, - ProcessHandle, - (PVOID *)&Base, - 0, - Size, - &Offset, - (PULONG)&Size, - 0, - MEM_COMMIT, - PAGE_READWRITE); - if (!NT_SUCCESS(Status)) - { - DbgPrint("Image map view of secion failed (Status %x)\n", Status); - return(Status); + if( Offset.u.LowPart ) + { // map the section if it is initialized + Status = ZwMapViewOfSection(SectionHandle, + ProcessHandle, + (PVOID *)&Base, + 0, + Size, + &Offset, + (PULONG)&Size, + 0, + MEM_COMMIT, + PAGE_READWRITE); + if (!NT_SUCCESS(Status)) + { + DbgPrint("Image map view of secion failed (Status %x)\n", Status); + return(Status); + } } + else { + // allocate the section if it is uninitialized + Status = NtAllocateVirtualMemory( ProcessHandle, + (PVOID *)&Base, + 0, + &Size, + MEM_COMMIT, + PAGE_READWRITE ); + if( !NT_SUCCESS( Status ) ) + { + DPRINT1( "Failed to allocate memory for uninitialized section\n" ); + return Status; + } + } } DPRINT("Returning\n");