mirror of
https://github.com/reactos/reactos.git
synced 2025-04-26 16:40:27 +00:00
Implemented MmMapViewOfSection().
svn path=/trunk/; revision=2368
This commit is contained in:
parent
0de577f6cd
commit
709cd514ab
2 changed files with 181 additions and 130 deletions
|
@ -1,6 +1,6 @@
|
||||||
#ifndef _INCLUDE_DDK_MMFUNCS_H
|
#ifndef _INCLUDE_DDK_MMFUNCS_H
|
||||||
#define _INCLUDE_DDK_MMFUNCS_H
|
#define _INCLUDE_DDK_MMFUNCS_H
|
||||||
/* $Id: mmfuncs.h,v 1.10 2001/06/22 12:39:47 ekohl Exp $ */
|
/* $Id: mmfuncs.h,v 1.11 2001/11/13 22:46:24 ekohl Exp $ */
|
||||||
/* MEMORY MANAGMENT ******************************************************/
|
/* MEMORY MANAGMENT ******************************************************/
|
||||||
|
|
||||||
|
|
||||||
|
@ -366,19 +366,19 @@ MmMapViewInSystemSpace (
|
||||||
OUT PVOID * MappedBase,
|
OUT PVOID * MappedBase,
|
||||||
IN PULONG ViewSize
|
IN PULONG ViewSize
|
||||||
);
|
);
|
||||||
PVOID
|
NTSTATUS
|
||||||
STDCALL
|
STDCALL
|
||||||
MmMapViewOfSection (
|
MmMapViewOfSection (
|
||||||
DWORD Unknown0,
|
IN PVOID SectionObject,
|
||||||
DWORD Unknown1,
|
IN PEPROCESS Process,
|
||||||
DWORD Unknown2,
|
IN OUT PVOID * BaseAddress,
|
||||||
DWORD Unknown3,
|
IN ULONG ZeroBits,
|
||||||
DWORD Unknown4,
|
IN ULONG CommitSize,
|
||||||
DWORD Unknown5,
|
IN OUT PLARGE_INTEGER SectionOffset OPTIONAL,
|
||||||
DWORD Unknown6,
|
IN OUT PULONG ViewSize,
|
||||||
DWORD Unknown7,
|
IN SECTION_INHERIT InheritDisposition,
|
||||||
DWORD Unknown8,
|
IN ULONG AllocationType,
|
||||||
DWORD Unknown9
|
IN ULONG Protect
|
||||||
);
|
);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -16,7 +16,7 @@
|
||||||
* along with this program; if not, write to the Free Software
|
* along with this program; if not, write to the Free Software
|
||||||
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||||
*/
|
*/
|
||||||
/* $Id: section.c,v 1.65 2001/10/31 01:03:04 dwelch Exp $
|
/* $Id: section.c,v 1.66 2001/11/13 22:46:49 ekohl Exp $
|
||||||
*
|
*
|
||||||
* PROJECT: ReactOS kernel
|
* PROJECT: ReactOS kernel
|
||||||
* FILE: ntoskrnl/mm/section.c
|
* FILE: ntoskrnl/mm/section.c
|
||||||
|
@ -1752,7 +1752,7 @@ MmMapViewOfSegment(PEPROCESS Process,
|
||||||
* NtMapViewOfSection
|
* NtMapViewOfSection
|
||||||
*
|
*
|
||||||
* DESCRIPTION
|
* DESCRIPTION
|
||||||
* Maps a view of a section into the virtual address space of a
|
* Maps a view of a section into the virtual address space of a
|
||||||
* process.
|
* process.
|
||||||
*
|
*
|
||||||
* ARGUMENTS
|
* ARGUMENTS
|
||||||
|
@ -1783,7 +1783,7 @@ MmMapViewOfSegment(PEPROCESS Process,
|
||||||
*
|
*
|
||||||
* InheritDisposition
|
* InheritDisposition
|
||||||
* Specified how the view is to be shared with
|
* Specified how the view is to be shared with
|
||||||
* child processes.
|
* child processes.
|
||||||
*
|
*
|
||||||
* AllocateType
|
* AllocateType
|
||||||
* Type of allocation for the pages.
|
* Type of allocation for the pages.
|
||||||
|
@ -1805,11 +1805,10 @@ NtMapViewOfSection(HANDLE SectionHandle,
|
||||||
SECTION_INHERIT InheritDisposition,
|
SECTION_INHERIT InheritDisposition,
|
||||||
ULONG AllocationType,
|
ULONG AllocationType,
|
||||||
ULONG Protect)
|
ULONG Protect)
|
||||||
{
|
{
|
||||||
PSECTION_OBJECT Section;
|
PSECTION_OBJECT Section;
|
||||||
PEPROCESS Process;
|
PEPROCESS Process;
|
||||||
NTSTATUS Status;
|
NTSTATUS Status;
|
||||||
ULONG ViewOffset;
|
|
||||||
PMADDRESS_SPACE AddressSpace;
|
PMADDRESS_SPACE AddressSpace;
|
||||||
|
|
||||||
Status = ObReferenceObjectByHandle(ProcessHandle,
|
Status = ObReferenceObjectByHandle(ProcessHandle,
|
||||||
|
@ -1838,96 +1837,21 @@ NtMapViewOfSection(HANDLE SectionHandle,
|
||||||
return(Status);
|
return(Status);
|
||||||
}
|
}
|
||||||
|
|
||||||
MmLockAddressSpace(AddressSpace);
|
Status = MmMapViewOfSection(Section,
|
||||||
MmLockSection(Section);
|
Process,
|
||||||
|
BaseAddress,
|
||||||
|
ZeroBits,
|
||||||
|
CommitSize,
|
||||||
|
SectionOffset,
|
||||||
|
ViewSize,
|
||||||
|
InheritDisposition,
|
||||||
|
AllocationType,
|
||||||
|
Protect);
|
||||||
|
|
||||||
if (Section->Flags & MM_IMAGE_SECTION)
|
|
||||||
{
|
|
||||||
ULONG i;
|
|
||||||
|
|
||||||
for (i = 0; i < Section->NrSegments; i++)
|
|
||||||
{
|
|
||||||
PVOID SBaseAddress;
|
|
||||||
|
|
||||||
if (!(Section->Segments[i].Characteristics & IMAGE_SECTION_NOLOAD))
|
|
||||||
{
|
|
||||||
SBaseAddress = (PVOID)
|
|
||||||
((ULONG)Section->ImageBase +
|
|
||||||
(ULONG)Section->Segments[i].VirtualAddress);
|
|
||||||
|
|
||||||
MmLockSectionSegment(&Section->Segments[i]);
|
|
||||||
Status = MmMapViewOfSegment(Process,
|
|
||||||
&Process->AddressSpace,
|
|
||||||
Section,
|
|
||||||
&Section->Segments[i],
|
|
||||||
&SBaseAddress,
|
|
||||||
Section->Segments[i].Length,
|
|
||||||
Section->Segments[i].Protection,
|
|
||||||
Section->Segments[i].FileOffset);
|
|
||||||
MmUnlockSectionSegment(&Section->Segments[i]);
|
|
||||||
if (!NT_SUCCESS(Status))
|
|
||||||
{
|
|
||||||
MmUnlockSection(Section);
|
|
||||||
MmUnlockAddressSpace(AddressSpace);
|
|
||||||
ObDereferenceObject(Section);
|
|
||||||
ObDereferenceObject(Process);
|
|
||||||
return(Status);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
*BaseAddress = Section->ImageBase;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (SectionOffset == NULL)
|
|
||||||
{
|
|
||||||
ViewOffset = 0;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
ViewOffset = SectionOffset->u.LowPart;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((ViewOffset % PAGESIZE) != 0)
|
|
||||||
{
|
|
||||||
MmUnlockSection(Section);
|
|
||||||
MmUnlockAddressSpace(AddressSpace);
|
|
||||||
ObDereferenceObject(Section);
|
|
||||||
ObDereferenceObject(Process);
|
|
||||||
return(STATUS_MAPPED_ALIGNMENT);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (((*ViewSize)+ViewOffset) > Section->MaximumSize.u.LowPart)
|
|
||||||
{
|
|
||||||
(*ViewSize) = Section->MaximumSize.u.LowPart - ViewOffset;
|
|
||||||
}
|
|
||||||
|
|
||||||
MmLockSectionSegment(Section->Segments);
|
|
||||||
Status = MmMapViewOfSegment(Process,
|
|
||||||
&Process->AddressSpace,
|
|
||||||
Section,
|
|
||||||
Section->Segments,
|
|
||||||
BaseAddress,
|
|
||||||
*ViewSize,
|
|
||||||
Protect,
|
|
||||||
ViewOffset);
|
|
||||||
MmUnlockSectionSegment(Section->Segments);
|
|
||||||
if (!NT_SUCCESS(Status))
|
|
||||||
{
|
|
||||||
MmUnlockSection(Section);
|
|
||||||
MmUnlockAddressSpace(AddressSpace);
|
|
||||||
ObDereferenceObject(Section);
|
|
||||||
ObDereferenceObject(Process);
|
|
||||||
return(Status);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
MmUnlockSection(Section);
|
|
||||||
MmUnlockAddressSpace(AddressSpace);
|
|
||||||
ObDereferenceObject(Section);
|
ObDereferenceObject(Section);
|
||||||
ObDereferenceObject(Process);
|
ObDereferenceObject(Process);
|
||||||
|
|
||||||
return(STATUS_SUCCESS);
|
return(Status);
|
||||||
}
|
}
|
||||||
|
|
||||||
VOID STATIC
|
VOID STATIC
|
||||||
|
@ -2235,32 +2159,159 @@ MmAllocateSection (IN ULONG Length)
|
||||||
|
|
||||||
/**********************************************************************
|
/**********************************************************************
|
||||||
* NAME EXPORTED
|
* NAME EXPORTED
|
||||||
* MmMapViewOfSection@40
|
* MmMapViewOfSection
|
||||||
*
|
*
|
||||||
* DESCRIPTION
|
* DESCRIPTION
|
||||||
|
* Maps a view of a section into the virtual address space of a
|
||||||
|
* process.
|
||||||
*
|
*
|
||||||
* ARGUMENTS
|
* ARGUMENTS
|
||||||
* FIXME: stack space allocated is 40 bytes, but nothing
|
* Section
|
||||||
* is known about what they are filled with.
|
* Pointer to the section object.
|
||||||
|
*
|
||||||
|
* ProcessHandle
|
||||||
|
* Pointer to the process.
|
||||||
|
*
|
||||||
|
* BaseAddress
|
||||||
|
* Desired base address (or NULL) on entry;
|
||||||
|
* Actual base address of the view on exit.
|
||||||
|
*
|
||||||
|
* ZeroBits
|
||||||
|
* Number of high order address bits that must be zero.
|
||||||
|
*
|
||||||
|
* CommitSize
|
||||||
|
* Size in bytes of the initially committed section of
|
||||||
|
* the view.
|
||||||
|
*
|
||||||
|
* SectionOffset
|
||||||
|
* Offset in bytes from the beginning of the section
|
||||||
|
* to the beginning of the view.
|
||||||
|
*
|
||||||
|
* ViewSize
|
||||||
|
* Desired length of map (or zero to map all) on entry
|
||||||
|
* Actual length mapped on exit.
|
||||||
|
*
|
||||||
|
* InheritDisposition
|
||||||
|
* Specified how the view is to be shared with
|
||||||
|
* child processes.
|
||||||
|
*
|
||||||
|
* AllocationType
|
||||||
|
* Type of allocation for the pages.
|
||||||
|
*
|
||||||
|
* Protect
|
||||||
|
* Protection for the committed region of the view.
|
||||||
*
|
*
|
||||||
* RETURN VALUE
|
* RETURN VALUE
|
||||||
* Status.
|
* Status.
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
PVOID STDCALL
|
NTSTATUS STDCALL
|
||||||
MmMapViewOfSection (DWORD Unknown0,
|
MmMapViewOfSection(IN PVOID SectionObject,
|
||||||
DWORD Unknown1,
|
IN PEPROCESS Process,
|
||||||
DWORD Unknown2,
|
IN OUT PVOID *BaseAddress,
|
||||||
DWORD Unknown3,
|
IN ULONG ZeroBits,
|
||||||
DWORD Unknown4,
|
IN ULONG CommitSize,
|
||||||
DWORD Unknown5,
|
IN OUT PLARGE_INTEGER SectionOffset OPTIONAL,
|
||||||
DWORD Unknown6,
|
IN OUT PULONG ViewSize,
|
||||||
DWORD Unknown7,
|
IN SECTION_INHERIT InheritDisposition,
|
||||||
DWORD Unknown8,
|
IN ULONG AllocationType,
|
||||||
DWORD Unknown9)
|
IN ULONG Protect)
|
||||||
{
|
{
|
||||||
UNIMPLEMENTED;
|
PSECTION_OBJECT Section;
|
||||||
return (NULL);
|
PMADDRESS_SPACE AddressSpace;
|
||||||
|
ULONG ViewOffset;
|
||||||
|
NTSTATUS Status;
|
||||||
|
|
||||||
|
Section = (PSECTION_OBJECT)SectionObject;
|
||||||
|
AddressSpace = &Process->AddressSpace;
|
||||||
|
|
||||||
|
MmLockAddressSpace(AddressSpace);
|
||||||
|
MmLockSection(SectionObject);
|
||||||
|
|
||||||
|
if (Section->Flags & MM_IMAGE_SECTION)
|
||||||
|
{
|
||||||
|
ULONG i;
|
||||||
|
|
||||||
|
for (i = 0; i < Section->NrSegments; i++)
|
||||||
|
{
|
||||||
|
PVOID SBaseAddress;
|
||||||
|
|
||||||
|
if (!(Section->Segments[i].Characteristics & IMAGE_SECTION_NOLOAD))
|
||||||
|
{
|
||||||
|
SBaseAddress = (PVOID)
|
||||||
|
((ULONG)Section->ImageBase +
|
||||||
|
(ULONG)Section->Segments[i].VirtualAddress);
|
||||||
|
|
||||||
|
MmLockSectionSegment(&Section->Segments[i]);
|
||||||
|
Status = MmMapViewOfSegment(Process,
|
||||||
|
&Process->AddressSpace,
|
||||||
|
Section,
|
||||||
|
&Section->Segments[i],
|
||||||
|
&SBaseAddress,
|
||||||
|
Section->Segments[i].Length,
|
||||||
|
Section->Segments[i].Protection,
|
||||||
|
Section->Segments[i].FileOffset);
|
||||||
|
MmUnlockSectionSegment(&Section->Segments[i]);
|
||||||
|
if (!NT_SUCCESS(Status))
|
||||||
|
{
|
||||||
|
MmUnlockSection(Section);
|
||||||
|
MmUnlockAddressSpace(AddressSpace);
|
||||||
|
ObDereferenceObject(Section);
|
||||||
|
ObDereferenceObject(Process);
|
||||||
|
return(Status);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
*BaseAddress = Section->ImageBase;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (SectionOffset == NULL)
|
||||||
|
{
|
||||||
|
ViewOffset = 0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ViewOffset = SectionOffset->u.LowPart;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((ViewOffset % PAGESIZE) != 0)
|
||||||
|
{
|
||||||
|
MmUnlockSection(Section);
|
||||||
|
MmUnlockAddressSpace(AddressSpace);
|
||||||
|
ObDereferenceObject(Section);
|
||||||
|
ObDereferenceObject(Process);
|
||||||
|
return(STATUS_MAPPED_ALIGNMENT);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (((*ViewSize)+ViewOffset) > Section->MaximumSize.u.LowPart)
|
||||||
|
{
|
||||||
|
(*ViewSize) = Section->MaximumSize.u.LowPart - ViewOffset;
|
||||||
|
}
|
||||||
|
|
||||||
|
MmLockSectionSegment(Section->Segments);
|
||||||
|
Status = MmMapViewOfSegment(Process,
|
||||||
|
&Process->AddressSpace,
|
||||||
|
Section,
|
||||||
|
Section->Segments,
|
||||||
|
BaseAddress,
|
||||||
|
*ViewSize,
|
||||||
|
Protect,
|
||||||
|
ViewOffset);
|
||||||
|
MmUnlockSectionSegment(Section->Segments);
|
||||||
|
if (!NT_SUCCESS(Status))
|
||||||
|
{
|
||||||
|
MmUnlockSection(Section);
|
||||||
|
MmUnlockAddressSpace(AddressSpace);
|
||||||
|
ObDereferenceObject(Section);
|
||||||
|
ObDereferenceObject(Process);
|
||||||
|
return(Status);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
MmUnlockSection(Section);
|
||||||
|
MmUnlockAddressSpace(AddressSpace);
|
||||||
|
|
||||||
|
return(STATUS_SUCCESS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue