{
PROS_SECTION_OBJECT Section;
PMEMORY_AREA MemoryArea;
- PMM_AVL_TABLE AddressSpace;
+ PMMSUPPORT AddressSpace;
POBJECT_NAME_INFORMATION ModuleNameInformation;
NTSTATUS Status = STATUS_ADDRESS_NOT_ASSOCIATED;
}
else
{
- AddressSpace = &PsGetCurrentProcess()->VadRoot;
+ AddressSpace = &PsGetCurrentProcess()->Vm;
}
/* Lock address space */
}
else
{
+ PEPROCESS Process;
+ KIRQL Irql;
PVOID PageAddr;
ULONG CacheSegOffset;
+
/*
* Allocate a page, this is rather complicated by the possibility
* we might have to move other things out of memory
return Status;
}
}
- PageAddr = MmCreateHyperspaceMapping(*Page);
+
+ Process = PsGetCurrentProcess();
+ PageAddr = MiMapPageInHyperSpace(Process, *Page, &Irql);
CacheSegOffset = BaseOffset + CacheSeg->Bcb->CacheSegmentSize - FileOffset;
Length = RawLength - SegOffset;
if (Length <= CacheSegOffset && Length <= PAGE_SIZE)
else
{
memcpy(PageAddr, (char*)BaseAddress + FileOffset - BaseOffset, CacheSegOffset);
+ MiUnmapPageInHyperSpace(Process, PageAddr, Irql);
CcRosReleaseCacheSegment(Bcb, CacheSeg, TRUE, FALSE, FALSE);
Status = CcRosGetCacheSegment(Bcb,
FileOffset + CacheSegOffset,
&CacheSeg);
if (!NT_SUCCESS(Status))
{
- MmDeleteHyperspaceMapping(PageAddr);
return(Status);
}
if (!UptoDate)
if (!NT_SUCCESS(Status))
{
CcRosReleaseCacheSegment(Bcb, CacheSeg, FALSE, FALSE, FALSE);
- MmDeleteHyperspaceMapping(PageAddr);
return Status;
}
}
+ PageAddr = MiMapPageInHyperSpace(Process, *Page, &Irql);
if (Length < PAGE_SIZE)
{
memcpy((char*)PageAddr + CacheSegOffset, BaseAddress, Length - CacheSegOffset);
memcpy((char*)PageAddr + CacheSegOffset, BaseAddress, PAGE_SIZE - CacheSegOffset);
}
}
+ MiUnmapPageInHyperSpace(Process, PageAddr, Irql);
CcRosReleaseCacheSegment(Bcb, CacheSeg, TRUE, FALSE, FALSE);
- MmDeleteHyperspaceMapping(PageAddr);
}
return(STATUS_SUCCESS);
}
NTSTATUS
NTAPI
-MmNotPresentFaultSectionView(PMM_AVL_TABLE AddressSpace,
+MmNotPresentFaultSectionView(PMMSUPPORT AddressSpace,
MEMORY_AREA* MemoryArea,
PVOID Address,
BOOLEAN Locked)
NTSTATUS
NTAPI
-MmAccessFaultSectionView(PMM_AVL_TABLE AddressSpace,
+MmAccessFaultSectionView(PMMSUPPORT AddressSpace,
MEMORY_AREA* MemoryArea,
PVOID Address,
BOOLEAN Locked)
PageOutContext = (MM_SECTION_PAGEOUT_CONTEXT*)Context;
if (Process)
{
- MmLockAddressSpace(&Process->VadRoot);
+ MmLockAddressSpace(&Process->Vm);
}
MmDeleteVirtualMapping(Process,
}
if (Process)
{
- MmUnlockAddressSpace(&Process->VadRoot);
+ MmUnlockAddressSpace(&Process->Vm);
}
if (PageOutContext->Private)
NTSTATUS
NTAPI
-MmPageOutSectionView(PMM_AVL_TABLE AddressSpace,
+MmPageOutSectionView(PMMSUPPORT AddressSpace,
MEMORY_AREA* MemoryArea,
PVOID Address,
PMM_PAGEOP PageOp)
NTSTATUS
NTAPI
-MmWritePageSectionView(PMM_AVL_TABLE AddressSpace,
+MmWritePageSectionView(PMMSUPPORT AddressSpace,
PMEMORY_AREA MemoryArea,
PVOID Address,
PMM_PAGEOP PageOp)
return(STATUS_SUCCESS);
}
-VOID static
-MmAlterViewAttributes(PMM_AVL_TABLE AddressSpace,
+static VOID
+MmAlterViewAttributes(PMMSUPPORT AddressSpace,
PVOID BaseAddress,
ULONG RegionSize,
ULONG OldType,
NTSTATUS
NTAPI
-MmProtectSectionView(PMM_AVL_TABLE AddressSpace,
+MmProtectSectionView(PMMSUPPORT AddressSpace,
PMEMORY_AREA MemoryArea,
PVOID BaseAddress,
ULONG Length,
return(Status);
}
-NTSTATUS STDCALL
+NTSTATUS NTAPI
MmQuerySectionView(PMEMORY_AREA MemoryArea,
PVOID Address,
PMEMORY_BASIC_INFORMATION Info,
- PULONG ResultLength)
+ PSIZE_T ResultLength)
{
PMM_REGION Region;
PVOID RegionBaseAddress;
}
}
-VOID STDCALL
+VOID NTAPI
MmpDeleteSection(PVOID ObjectBody)
{
PROS_SECTION_OBJECT Section = (PROS_SECTION_OBJECT)ObjectBody;
}
}
-VOID STDCALL
+VOID NTAPI
MmpCloseSection(IN PEPROCESS Process OPTIONAL,
IN PVOID Object,
IN ACCESS_MASK GrantedAccess,
/*
* Initialize it
*/
+ RtlZeroMemory(Section, sizeof(ROS_SECTION_OBJECT));
Section->SectionPageProtection = SectionPageProtection;
Section->AllocationAttributes = AllocationAttributes;
- Section->Segment = NULL;
- Section->FileObject = NULL;
Section->MaximumSize = MaximumSize;
Segment = ExAllocatePoolWithTag(NonPagedPool, sizeof(MM_SECTION_SEGMENT),
TAG_MM_SECTION_SEGMENT);
LARGE_INTEGER Offset;
CHAR Buffer;
FILE_STANDARD_INFORMATION FileInfo;
+ ULONG Length;
/*
* Create the section
/*
* Initialize it
*/
+ RtlZeroMemory(Section, sizeof(ROS_SECTION_OBJECT));
Section->SectionPageProtection = SectionPageProtection;
Section->AllocationAttributes = AllocationAttributes;
- Section->Segment = NULL;
/*
* Check file access required
FileStandardInformation,
sizeof(FILE_STANDARD_INFORMATION),
&FileInfo,
- &Iosb.Information);
+ &Length);
+ Iosb.Information = Length;
if (!NT_SUCCESS(Status))
{
ObDereferenceObject(Section);
/*
* Initialize it
*/
+ RtlZeroMemory(Section, sizeof(ROS_SECTION_OBJECT));
Section->SectionPageProtection = SectionPageProtection;
Section->AllocationAttributes = AllocationAttributes;
/*
* @implemented
*/
-NTSTATUS STDCALL
+NTSTATUS NTAPI
NtCreateSection (OUT PHANDLE SectionHandle,
IN ACCESS_MASK DesiredAccess,
IN POBJECT_ATTRIBUTES ObjectAttributes OPTIONAL,
PreviousMode = ExGetPreviousMode();
- if(MaximumSize != NULL && PreviousMode != KernelMode)
+ if(PreviousMode != KernelMode)
{
_SEH2_TRY
{
- /* make a copy on the stack */
- SafeMaximumSize = ProbeForReadLargeInteger(MaximumSize);
- MaximumSize = &SafeMaximumSize;
+ if (MaximumSize != NULL)
+ {
+ /* make a copy on the stack */
+ SafeMaximumSize = ProbeForReadLargeInteger(MaximumSize);
+ MaximumSize = &SafeMaximumSize;
+ }
+ ProbeForWriteHandle(SectionHandle);
}
_SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
{
*
* REVISIONS
*/
-NTSTATUS STDCALL
+NTSTATUS NTAPI
NtOpenSection(PHANDLE SectionHandle,
ACCESS_MASK DesiredAccess,
POBJECT_ATTRIBUTES ObjectAttributes)
return(Status);
}
-NTSTATUS static
-MmMapViewOfSegment(PMM_AVL_TABLE AddressSpace,
+static NTSTATUS
+MmMapViewOfSegment(PMMSUPPORT AddressSpace,
PROS_SECTION_OBJECT Section,
PMM_SECTION_SEGMENT Segment,
PVOID* BaseAddress,
*
* @implemented
*/
-NTSTATUS STDCALL
+NTSTATUS NTAPI
NtMapViewOfSection(IN HANDLE SectionHandle,
IN HANDLE ProcessHandle,
IN OUT PVOID* BaseAddress OPTIONAL,
PROS_SECTION_OBJECT Section;
PEPROCESS Process;
KPROCESSOR_MODE PreviousMode;
- PMM_AVL_TABLE AddressSpace;
+ PMMSUPPORT AddressSpace;
NTSTATUS Status = STATUS_SUCCESS;
ULONG tmpProtect;
+ ACCESS_MASK DesiredAccess;
/*
* Check the protection
return(Status);
}
- AddressSpace = &Process->VadRoot;
+ AddressSpace = &Process->Vm;
+
+ /* Convert NT Protection Attr to Access Mask */
+ if (Protect == PAGE_READONLY)
+ {
+ DesiredAccess = SECTION_MAP_READ;
+ }
+ else if (Protect == PAGE_READWRITE)
+ {
+ DesiredAccess = SECTION_MAP_WRITE;
+ }
+ else if (Protect == PAGE_WRITECOPY)
+ {
+ DesiredAccess = SECTION_QUERY;
+ }
+ /* FIXME: Handle other Protection Attributes. For now keep previous behavior */
+ else
+ {
+ DesiredAccess = SECTION_MAP_READ;
+ }
Status = ObReferenceObjectByHandle(SectionHandle,
- SECTION_MAP_READ,
+ DesiredAccess,
MmSectionObjectType,
PreviousMode,
(PVOID*)(PVOID)&Section,
return(Status);
}
-VOID static
+static VOID
MmFreeSectionPage(PVOID Context, MEMORY_AREA* MemoryArea, PVOID Address,
PFN_TYPE Page, SWAPENTRY SwapEntry, BOOLEAN Dirty)
{
NTSTATUS Status;
PROS_SECTION_OBJECT Section;
PMM_SECTION_SEGMENT Segment;
- PMM_AVL_TABLE AddressSpace;
+ PMMSUPPORT AddressSpace;
PEPROCESS Process;
- AddressSpace = (PMM_AVL_TABLE)Context;
+ AddressSpace = (PMMSUPPORT)Context;
Process = MmGetAddressSpaceOwner(AddressSpace);
Address = (PVOID)PAGE_ROUND_DOWN(Address);
}
static NTSTATUS
-MmUnmapViewOfSegment(PMM_AVL_TABLE AddressSpace,
+MmUnmapViewOfSegment(PMMSUPPORT AddressSpace,
PVOID BaseAddress)
{
NTSTATUS Status;
/*
* @implemented
*/
-NTSTATUS STDCALL
+NTSTATUS NTAPI
MmUnmapViewOfSection(PEPROCESS Process,
PVOID BaseAddress)
{
NTSTATUS Status;
PMEMORY_AREA MemoryArea;
- PMM_AVL_TABLE AddressSpace;
+ PMMSUPPORT AddressSpace;
PROS_SECTION_OBJECT Section;
PMM_PAGEOP PageOp;
ULONG_PTR Offset;
ASSERT(Process);
- AddressSpace = &Process->VadRoot;
+ AddressSpace = &Process->Vm;
MmLockAddressSpace(AddressSpace);
MemoryArea = MmLocateMemoryAreaByAddress(AddressSpace,
Status = MmUnmapViewOfSegment(AddressSpace, BaseAddress);
}
+ MmUnlockAddressSpace(AddressSpace);
+
/* Notify debugger */
if (ImageBaseAddress) DbgkUnMapViewOfSection(ImageBaseAddress);
- MmUnlockAddressSpace(AddressSpace);
return(STATUS_SUCCESS);
}
*
* REVISIONS
*/
-NTSTATUS STDCALL
+NTSTATUS NTAPI
NtUnmapViewOfSection (HANDLE ProcessHandle,
PVOID BaseAddress)
{
*
* @implemented
*/
-NTSTATUS STDCALL
+NTSTATUS NTAPI
NtQuerySection(IN HANDLE SectionHandle,
IN SECTION_INFORMATION_CLASS SectionInformationClass,
OUT PVOID SectionInformation,
- IN ULONG SectionInformationLength,
- OUT PULONG ResultLength OPTIONAL)
+ IN SIZE_T SectionInformationLength,
+ OUT PSIZE_T ResultLength OPTIONAL)
{
PROS_SECTION_OBJECT Section;
KPROCESSOR_MODE PreviousMode;
NTSTATUS Status = STATUS_SUCCESS;
+ PAGED_CODE();
PreviousMode = ExGetPreviousMode();
sizeof(ExSectionInfoClass) / sizeof(ExSectionInfoClass[0]),
SectionInformation,
SectionInformationLength,
+ NULL,
ResultLength,
PreviousMode);
* @todo Move the actual code to internal function MmExtendSection.
* @unimplemented
*/
-NTSTATUS STDCALL
+NTSTATUS NTAPI
NtExtendSection(IN HANDLE SectionHandle,
IN PLARGE_INTEGER NewMaximumSize)
{
if (!(Section->AllocationAttributes & SEC_FILE))
{
- ObfDereferenceObject(Section);
+ ObDereferenceObject(Section);
return STATUS_INVALID_PARAMETER;
}
*
* REVISIONS
*/
-PVOID STDCALL
+PVOID NTAPI
MmAllocateSection (IN ULONG Length, PVOID BaseAddress)
{
PVOID Result;
MEMORY_AREA* marea;
NTSTATUS Status;
- PMM_AVL_TABLE AddressSpace;
+ PMMSUPPORT AddressSpace;
PHYSICAL_ADDRESS BoundaryAddressMultiple;
DPRINT("MmAllocateSection(Length %x)\n",Length);
*
* @implemented
*/
-NTSTATUS STDCALL
+NTSTATUS NTAPI
MmMapViewOfSection(IN PVOID SectionObject,
IN PEPROCESS Process,
IN OUT PVOID *BaseAddress,
IN ULONG Protect)
{
PROS_SECTION_OBJECT Section;
- PMM_AVL_TABLE AddressSpace;
+ PMMSUPPORT AddressSpace;
ULONG ViewOffset;
NTSTATUS Status = STATUS_SUCCESS;
ASSERT(Process);
- if (Protect != PAGE_READONLY &&
- Protect != PAGE_READWRITE &&
- Protect != PAGE_WRITECOPY &&
- Protect != PAGE_EXECUTE &&
- Protect != PAGE_EXECUTE_READ &&
- Protect != PAGE_EXECUTE_READWRITE &&
- Protect != PAGE_EXECUTE_WRITECOPY)
+ if (!Protect || Protect & ~PAGE_FLAGS_VALID_FOR_SECTION)
{
return STATUS_INVALID_PAGE_PROTECTION;
}
Section = (PROS_SECTION_OBJECT)SectionObject;
- AddressSpace = &Process->VadRoot;
+ AddressSpace = &Process->Vm;
AllocationType |= (Section->AllocationAttributes & SEC_NO_CHANGE);
(*ViewSize) = Section->MaximumSize.u.LowPart - ViewOffset;
}
+ *ViewSize = PAGE_ROUND_UP(*ViewSize);
+
MmLockSectionSegment(Section->Segment);
Status = MmMapViewOfSegment(AddressSpace,
Section,
/*
* @unimplemented
*/
-BOOLEAN STDCALL
+BOOLEAN NTAPI
MmCanFileBeTruncated (IN PSECTION_OBJECT_POINTERS SectionObjectPointer,
IN PLARGE_INTEGER NewFileSize)
{
- UNIMPLEMENTED;
- return (FALSE);
+ /* Check whether an ImageSectionObject exists */
+ if (SectionObjectPointer->ImageSectionObject != NULL)
+ {
+ DPRINT1("ERROR: File can't be truncated because it has an image section\n");
+ return FALSE;
+ }
+
+ if (SectionObjectPointer->DataSectionObject != NULL)
+ {
+ PMM_SECTION_SEGMENT Segment;
+
+ Segment = (PMM_SECTION_SEGMENT)SectionObjectPointer->
+ DataSectionObject;
+
+ if (Segment->ReferenceCount != 0)
+ {
+ /* Check size of file */
+ if (SectionObjectPointer->SharedCacheMap)
+ {
+ PBCB Bcb = SectionObjectPointer->SharedCacheMap;
+ if (NewFileSize->QuadPart <= Bcb->FileSize.QuadPart)
+ {
+ return FALSE;
+ }
+ }
+ }
+ else
+ {
+ /* Something must gone wrong
+ * how can we have a Section but no
+ * reference? */
+ DPRINT1("ERROR: DataSectionObject without reference!\n");
+ }
+ }
+
+ DPRINT("FIXME: didn't check for outstanding write probes\n");
+
+ return TRUE;
}
/*
* @unimplemented
*/
-BOOLEAN STDCALL
+BOOLEAN NTAPI
MmDisableModifiedWriteOfSection (ULONG Unknown0)
{
UNIMPLEMENTED;
/*
* @implemented
*/
-BOOLEAN STDCALL
+BOOLEAN NTAPI
MmFlushImageSection (IN PSECTION_OBJECT_POINTERS SectionObjectPointer,
IN MMFLUSH_TYPE FlushType)
{
/*
* @unimplemented
*/
-BOOLEAN STDCALL
+BOOLEAN NTAPI
MmForceSectionClosed (
IN PSECTION_OBJECT_POINTERS SectionObjectPointer,
IN BOOLEAN DelayClose)
/*
* @implemented
*/
-NTSTATUS STDCALL
+NTSTATUS NTAPI
MmMapViewInSystemSpace (IN PVOID SectionObject,
OUT PVOID * MappedBase,
- IN OUT PULONG ViewSize)
+ IN OUT PSIZE_T ViewSize)
{
PROS_SECTION_OBJECT Section;
- PMM_AVL_TABLE AddressSpace;
+ PMMSUPPORT AddressSpace;
NTSTATUS Status;
DPRINT("MmMapViewInSystemSpace() called\n");
* @unimplemented
*/
NTSTATUS
-STDCALL
+NTAPI
MmMapViewInSessionSpace (
IN PVOID Section,
OUT PVOID *MappedBase,
/*
* @implemented
*/
-NTSTATUS STDCALL
+NTSTATUS NTAPI
MmUnmapViewInSystemSpace (IN PVOID MappedBase)
{
- PMM_AVL_TABLE AddressSpace;
+ PMMSUPPORT AddressSpace;
NTSTATUS Status;
DPRINT("MmUnmapViewInSystemSpace() called\n");
* @unimplemented
*/
NTSTATUS
-STDCALL
+NTAPI
MmUnmapViewInSessionSpace (
IN PVOID MappedBase
)
/*
* @unimplemented
*/
-NTSTATUS STDCALL
+NTSTATUS NTAPI
MmSetBankedSection (ULONG Unknown0,
ULONG Unknown1,
ULONG Unknown2,
*
* @implemented
*/
-NTSTATUS STDCALL
+NTSTATUS NTAPI
MmCreateSection (OUT PVOID * Section,
IN ACCESS_MASK DesiredAccess,
IN POBJECT_ATTRIBUTES ObjectAttributes OPTIONAL,
* Check the protection
*/
Protection = SectionPageProtection & ~(PAGE_GUARD|PAGE_NOCACHE);
- if (Protection != PAGE_NOACCESS &&
- Protection != PAGE_READONLY &&
+ if (Protection != PAGE_READONLY &&
Protection != PAGE_READWRITE &&
Protection != PAGE_WRITECOPY &&
Protection != PAGE_EXECUTE &&