*
* Copyright (C) 1998-2005 ReactOS Team (and the authors from the programmers section)
*
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
*
- * This library is distributed in the hope that it will be useful,
+ * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
*
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
*
* PROJECT: ReactOS kernel
* Jason Filby
* Thomas Weidenmueller
* Gunnar Andre' Dalsnes
- * tamlin
+ * Mike Nordell
* Alex Ionescu
* Gregor Anich
* Steven Edwards
}
VOID
+NTAPI
MmFreeSectionSegments(PFILE_OBJECT FileObject)
{
if (FileObject->SectionObjectPointer->ImageSectionObject != NULL)
}
VOID
+NTAPI
MmLockSectionSegment(PMM_SECTION_SEGMENT Segment)
{
ExAcquireFastMutex(&Segment->Lock);
}
VOID
+NTAPI
MmUnlockSectionSegment(PMM_SECTION_SEGMENT Segment)
{
ExReleaseFastMutex(&Segment->Lock);
}
VOID
+NTAPI
MmSetPageEntrySectionSegment(PMM_SECTION_SEGMENT Segment,
ULONG Offset,
ULONG Entry)
ULONG
+NTAPI
MmGetPageEntrySectionSegment(PMM_SECTION_SEGMENT Segment,
ULONG Offset)
{
}
VOID
+NTAPI
MmSharePageEntrySectionSegment(PMM_SECTION_SEGMENT Segment,
ULONG Offset)
{
}
BOOLEAN
+NTAPI
MmUnsharePageEntrySectionSegment(PSECTION_OBJECT Section,
PMM_SECTION_SEGMENT Segment,
ULONG Offset,
}
NTSTATUS
+NTAPI
MiReadPage(PMEMORY_AREA MemoryArea,
ULONG SegOffset,
PPFN_TYPE Page)
}
NTSTATUS
+NTAPI
MmNotPresentFaultSectionView(PMADDRESS_SPACE AddressSpace,
MEMORY_AREA* MemoryArea,
PVOID Address,
}
PAddress = MM_ROUND_DOWN(Address, PAGE_SIZE);
- Offset = (ULONG_PTR)PAddress - (ULONG_PTR)MemoryArea->StartingAddress;
+ Offset = (ULONG_PTR)PAddress - (ULONG_PTR)MemoryArea->StartingAddress
+ + MemoryArea->Data.SectionData.ViewOffset;
Segment = MemoryArea->Data.SectionData.Segment;
Section = MemoryArea->Data.SectionData.Section;
/*
* Just map the desired physical page
*/
- Page = (Offset + MemoryArea->Data.SectionData.ViewOffset) >> PAGE_SHIFT;
+ Page = Offset >> PAGE_SHIFT;
Status = MmCreateVirtualMappingUnsafe(AddressSpace->Process,
Address,
Region->Protect,
/*
* Get the entry corresponding to the offset within the section
*/
- Offset += MemoryArea->Data.SectionData.ViewOffset;
Entry = MmGetPageEntrySectionSegment(Segment, Offset);
if (Entry == 0)
}
NTSTATUS
+NTAPI
MmAccessFaultSectionView(PMADDRESS_SPACE AddressSpace,
MEMORY_AREA* MemoryArea,
PVOID Address,
* Find the offset of the page
*/
PAddress = MM_ROUND_DOWN(Address, PAGE_SIZE);
- Offset = (ULONG_PTR)PAddress - (ULONG_PTR)MemoryArea->StartingAddress;
+ Offset = (ULONG_PTR)PAddress - (ULONG_PTR)MemoryArea->StartingAddress
+ + MemoryArea->Data.SectionData.ViewOffset;
Segment = MemoryArea->Data.SectionData.Segment;
Section = MemoryArea->Data.SectionData.Section;
}
NTSTATUS
+NTAPI
MmPageOutSectionView(PMADDRESS_SPACE AddressSpace,
MEMORY_AREA* MemoryArea,
PVOID Address,
Context.Segment = MemoryArea->Data.SectionData.Segment;
Context.Section = MemoryArea->Data.SectionData.Section;
- Context.Offset = (ULONG_PTR)Address - (ULONG_PTR)MemoryArea->StartingAddress;
+ Context.Offset = (ULONG_PTR)Address - (ULONG_PTR)MemoryArea->StartingAddress
+ + MemoryArea->Data.SectionData.ViewOffset;
FileOffset = Context.Offset + Context.Segment->FileOffset;
IsImageSection = Context.Section->AllocationAttributes & SEC_IMAGE ? TRUE : FALSE;
* Prepare the context structure for the rmap delete call.
*/
Context.WasDirty = FALSE;
- if (Context.Segment->Characteristics & IMAGE_SCN_LNK_OTHER ||
+ if (Context.Segment->Characteristics & IMAGE_SCN_CNT_UNINITIALIZED_DATA ||
IS_SWAP_FROM_SSE(Entry) ||
PFN_FROM_SSE(Entry) != Page)
{
}
NTSTATUS
+NTAPI
MmWritePageSectionView(PMADDRESS_SPACE AddressSpace,
PMEMORY_AREA MemoryArea,
PVOID Address,
Address = (PVOID)PAGE_ROUND_DOWN(Address);
- Offset = (ULONG_PTR)Address - (ULONG_PTR)MemoryArea->StartingAddress;
+ Offset = (ULONG_PTR)Address - (ULONG_PTR)MemoryArea->StartingAddress
+ + MemoryArea->Data.SectionData.ViewOffset;
/*
* Get the segment and section.
* memory area was mapped at an offset in the file which is page aligned
* then note this is a direct mapped page.
*/
- if ((Offset + MemoryArea->Data.SectionData.ViewOffset % PAGE_SIZE) == 0 &&
+ if (((Offset + Segment->FileOffset) % PAGE_SIZE) == 0 &&
(Offset + PAGE_SIZE <= Segment->RawLength || !IsImageSection))
{
DirectMapped = TRUE;
/*
* Check for a private (COWed) page.
*/
- if (Segment->Characteristics & IMAGE_SCN_LNK_OTHER ||
+ if (Segment->Characteristics & IMAGE_SCN_CNT_UNINITIALIZED_DATA ||
IS_SWAP_FROM_SSE(Entry) ||
PFN_FROM_SSE(Entry) != Page)
{
if (DirectMapped && !Private)
{
ASSERT(SwapEntry == 0);
- CcRosMarkDirtyCacheSegment(Bcb, Offset + MemoryArea->Data.SectionData.ViewOffset);
+ CcRosMarkDirtyCacheSegment(Bcb, Offset + Segment->FileOffset);
PageOp->Status = STATUS_SUCCESS;
MmspCompleteAndReleasePageOp(PageOp);
return(STATUS_SUCCESS);
ULONG Entry;
PFN_TYPE Page;
- Offset = (ULONG_PTR)Address - (ULONG_PTR)MemoryArea->StartingAddress;
+ Offset = (ULONG_PTR)Address - (ULONG_PTR)MemoryArea->StartingAddress
+ + MemoryArea->Data.SectionData.ViewOffset;
Entry = MmGetPageEntrySectionSegment(Segment, Offset);
Page = MmGetPfnForProcess(AddressSpace->Process, Address);
Protect = PAGE_READONLY;
- if (Segment->Characteristics & IMAGE_SCN_LNK_OTHER ||
+ if (Segment->Characteristics & IMAGE_SCN_CNT_UNINITIALIZED_DATA ||
IS_SWAP_FROM_SSE(Entry) ||
PFN_FROM_SSE(Entry) != Page)
{
}
NTSTATUS
+NTAPI
MmProtectSectionView(PMADDRESS_SPACE AddressSpace,
PMEMORY_AREA MemoryArea,
PVOID BaseAddress,
if (Section->AllocationAttributes & SEC_IMAGE)
{
Segment = MemoryArea->Data.SectionData.Segment;
- Info->AllocationBase = MemoryArea->StartingAddress - Segment->VirtualAddress;
+ Info->AllocationBase = (PBYTE)MemoryArea->StartingAddress - Segment->VirtualAddress;
Info->Type = MEM_IMAGE;
}
else
}
VOID
+NTAPI
MmpFreePageFileSegment(PMM_SECTION_SEGMENT Segment)
{
ULONG Length;
ObjectBody, HandleCount, ObGetObjectPointerCount(ObjectBody));
}
-NTSTATUS INIT_FUNCTION
+NTSTATUS
+INIT_FUNCTION
+NTAPI
MmCreatePhysicalMemorySection(VOID)
{
PSECTION_OBJECT PhysSection;
NTSTATUS Status;
OBJECT_ATTRIBUTES Obj;
- UNICODE_STRING Name = ROS_STRING_INITIALIZER(L"\\Device\\PhysicalMemory");
+ UNICODE_STRING Name = RTL_CONSTANT_STRING(L"\\Device\\PhysicalMemory");
LARGE_INTEGER SectionSize;
/*
ObDereferenceObject(PhysSection);
}
PhysSection->AllocationAttributes |= SEC_PHYSICALMEMORY;
+ PhysSection->Segment->Flags &= ~MM_PAGEFILE_SEGMENT;
return(STATUS_SUCCESS);
}
-NTSTATUS INIT_FUNCTION
+NTSTATUS
+INIT_FUNCTION
+NTAPI
MmInitSectionImplementation(VOID)
{
OBJECT_TYPE_INITIALIZER ObjectTypeInitializer;
}
NTSTATUS
+NTAPI
MmCreatePageFileSection(PSECTION_OBJECT *SectionObject,
ACCESS_MASK DesiredAccess,
POBJECT_ATTRIBUTES ObjectAttributes,
NTSTATUS
+NTAPI
MmCreateDataFileSection(PSECTION_OBJECT *SectionObject,
ACCESS_MASK DesiredAccess,
POBJECT_ATTRIBUTES ObjectAttributes,
* (as in case of the EXT2FS driver by Manoj Paul Joseph where the
* standard file information is filled on first request).
*/
- Status = NtQueryInformationFile(FileHandle,
- &Iosb,
- &FileInfo,
+ Status = IoQueryFileInformation(FileObject,
+ FileStandardInformation,
sizeof(FILE_STANDARD_INFORMATION),
- FileStandardInformation);
+ &FileInfo,
+ &Iosb.Information);
if (!NT_SUCCESS(Status))
{
ObDereferenceObject(Section);
if (MaximumSize.QuadPart > FileInfo.EndOfFile.QuadPart)
{
- Status = NtSetInformationFile(FileHandle,
- &Iosb,
- &MaximumSize,
- sizeof(LARGE_INTEGER),
- FileAllocationInformation);
+ Status = IoSetInformation(FileObject,
+ FileAllocationInformation,
+ sizeof(LARGE_INTEGER),
+ &MaximumSize);
if (!NT_SUCCESS(Status))
{
ObDereferenceObject(Section);
KEBUGCHECK(STATUS_INVALID_PARAMETER_5);
}
- ASSERT(PAGE_SIZE <= MAXULONG);
AdjustOffset = PAGE_ROUND_DOWN(FileOffset.u.LowPart);
OffsetAdjustment = FileOffset.u.LowPart - AdjustOffset;
FileOffset.u.LowPart = AdjustOffset;
ULONG i;
ULONG LastSegment;
BOOLEAN Initialized;
+ PMM_SECTION_SEGMENT EffectiveSegment;
if (Flags & EXEFMT_LOAD_ASSUME_SEGMENTS_PAGE_ALIGNED)
{
Initialized = FALSE;
LastSegment = 0;
+ EffectiveSegment = &ImageSectionObject->Segments[LastSegment];
for ( i = 0; i < ImageSectionObject->NrSegments; ++ i )
{
- PMM_SECTION_SEGMENT EffectiveSegment = &ImageSectionObject->Segments[LastSegment];
-
/*
* The first segment requires special handling
*/
EffectiveSegment = &ImageSectionObject->Segments[LastSegment];
- /*
- * Copy the current segment. If necessary, the effective segment
- * will be expanded later
- */
- *EffectiveSegment = *Segment;
+ if (LastSegment != i)
+ {
+ /*
+ * Copy the current segment. If necessary, the effective segment
+ * will be expanded later
+ */
+ *EffectiveSegment = *Segment;
+ }
/*
* Page-align the virtual size. We know for sure the virtual address
/*
* Extend the virtual size
*/
- ASSERT(PAGE_ROUND_UP(Segment->VirtualAddress + Segment->Length) > EndOfEffectiveSegment);
+ ASSERT(PAGE_ROUND_UP(Segment->VirtualAddress + Segment->Length) >= EndOfEffectiveSegment);
EffectiveSegment->Length = PAGE_ROUND_UP(Segment->VirtualAddress + Segment->Length) -
EffectiveSegment->VirtualAddress;
}
}
}
+ ImageSectionObject->NrSegments = LastSegment + 1;
return TRUE;
}
*/
if (Status == STATUS_ROS_EXEFMT_UNKNOWN_FORMAT)
{
- Status = STATUS_INVALID_IMAGE_FORMAT;
+ Status = STATUS_INVALID_IMAGE_NOT_MZ;
ASSERT(!NT_SUCCESS(Status));
}
ObDereferenceObject(Section);
return(STATUS_NO_MEMORY);
}
+
+ RtlZeroMemory(ImageSectionObject, sizeof(MM_IMAGE_SECTION_OBJECT));
StatusExeFmt = ExeFmtpCreateImageSection(FileHandle, ImageSectionObject);
{
_SEH_TRY
{
- ProbeForRead(MaximumSize,
- sizeof(LARGE_INTEGER),
- sizeof(ULONG));
/* make a copy on the stack */
- SafeMaximumSize = *MaximumSize;
+ SafeMaximumSize = ProbeForReadLargeInteger(MaximumSize);
MaximumSize = &SafeMaximumSize;
}
_SEH_HANDLE
{
_SEH_TRY
{
- ProbeForWrite(SectionHandle,
- sizeof(HANDLE),
- sizeof(ULONG));
+ ProbeForWriteHandle(SectionHandle);
}
_SEH_HANDLE
{
{
if(BaseAddress != NULL)
{
- ProbeForWrite(BaseAddress,
- sizeof(PVOID),
- sizeof(ULONG));
+ ProbeForWritePointer(BaseAddress);
SafeBaseAddress = *BaseAddress;
}
if(SectionOffset != NULL)
{
- ProbeForWrite(SectionOffset,
- sizeof(LARGE_INTEGER),
- sizeof(ULONG));
+ ProbeForWriteLargeInteger(SectionOffset);
SafeSectionOffset = *SectionOffset;
}
- ProbeForWrite(ViewSize,
- sizeof(ULONG),
- sizeof(ULONG));
+ ProbeForWriteUlong(ViewSize);
SafeViewSize = *ViewSize;
}
_SEH_HANDLE
{
FileObject = MemoryArea->Data.SectionData.Section->FileObject;
Bcb = FileObject->SectionObjectPointer->SharedCacheMap;
- CcRosMarkDirtyCacheSegment(Bcb, Offset);
+ CcRosMarkDirtyCacheSegment(Bcb, Offset + Segment->FileOffset);
ASSERT(SwapEntry == 0);
}
}
PreviousMode = ExGetPreviousMode();
- DefaultQueryInfoBufferCheck(SectionInformationClass,
- ExSectionInfoClass,
- SectionInformation,
- SectionInformationLength,
- ResultLength,
- PreviousMode,
- &Status);
+ Status = DefaultQueryInfoBufferCheck(SectionInformationClass,
+ ExSectionInfoClass,
+ sizeof(ExSectionInfoClass) / sizeof(ExSectionInfoClass[0]),
+ SectionInformation,
+ SectionInformationLength,
+ ResultLength,
+ PreviousMode);
if(!NT_SUCCESS(Status))
{
PMM_IMAGE_SECTION_OBJECT ImageSectionObject;
ImageSectionObject = Section->ImageSection;
- Sii->EntryPoint = ImageSectionObject->EntryPoint;
- Sii->StackReserve = ImageSectionObject->StackReserve;
- Sii->StackCommit = ImageSectionObject->StackCommit;
- Sii->Subsystem = ImageSectionObject->Subsystem;
- Sii->MinorSubsystemVersion = ImageSectionObject->MinorSubsystemVersion;
- Sii->MajorSubsystemVersion = ImageSectionObject->MajorSubsystemVersion;
- Sii->Characteristics = ImageSectionObject->ImageCharacteristics;
- Sii->ImageNumber = ImageSectionObject->Machine;
- Sii->Executable = ImageSectionObject->Executable;
+ Sii->TransferAddress = (PVOID)ImageSectionObject->EntryPoint;
+ Sii->MaximumStackSize = ImageSectionObject->StackReserve;
+ Sii->CommittedStackSize = ImageSectionObject->StackCommit;
+ Sii->SubsystemType = ImageSectionObject->Subsystem;
+ Sii->SubSystemMinorVersion = ImageSectionObject->MinorSubsystemVersion;
+ Sii->SubSystemMajorVersion = ImageSectionObject->MajorSubsystemVersion;
+ Sii->ImageCharacteristics = ImageSectionObject->ImageCharacteristics;
+ Sii->Machine = ImageSectionObject->Machine;
+ Sii->ImageContainsCode = ImageSectionObject->Executable;
}
if (ResultLength != NULL)
{
_SEH_TRY
{
- ProbeForRead(NewMaximumSize,
- sizeof(LARGE_INTEGER),
- sizeof(ULONG));
/* make a copy on the stack */
- SafeNewMaximumSize = *NewMaximumSize;
+ SafeNewMaximumSize = ProbeForReadLargeInteger(NewMaximumSize);
NewMaximumSize = &SafeNewMaximumSize;
}
_SEH_HANDLE