MmQuerySectionView(PMEMORY_AREA MemoryArea,
PVOID Address,
PMEMORY_BASIC_INFORMATION Info,
- PULONG ResultLength)
+ PSIZE_T ResultLength)
{
PMM_REGION Region;
PVOID RegionBaseAddress;
/*
* 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;
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)
{
PMMSUPPORT AddressSpace;
NTSTATUS Status = STATUS_SUCCESS;
ULONG tmpProtect;
+ ACCESS_MASK DesiredAccess;
/*
* Check the protection
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,
Status = MmUnmapViewOfSegment(AddressSpace, BaseAddress);
}
+ MmUnlockAddressSpace(AddressSpace);
+
/* Notify debugger */
if (ImageBaseAddress) DbgkUnMapViewOfSection(ImageBaseAddress);
- MmUnlockAddressSpace(AddressSpace);
return(STATUS_SUCCESS);
}
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);
if (!(Section->AllocationAttributes & SEC_FILE))
{
- ObfDereferenceObject(Section);
+ ObDereferenceObject(Section);
return STATUS_INVALID_PARAMETER;
}
(*ViewSize) = Section->MaximumSize.u.LowPart - ViewOffset;
}
+ *ViewSize = PAGE_ROUND_UP(*ViewSize);
+
MmLockSectionSegment(Section->Segment);
Status = MmMapViewOfSegment(AddressSpace,
Section,
NTSTATUS NTAPI
MmMapViewInSystemSpace (IN PVOID SectionObject,
OUT PVOID * MappedBase,
- IN OUT PULONG ViewSize)
+ IN OUT PSIZE_T ViewSize)
{
PROS_SECTION_OBJECT Section;
PMMSUPPORT AddressSpace;
* 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 &&