[NTOS:MM] section.c: some trivial cleanup (#5651)

* [NTOS:MM] section.c: Remove unused functions

MiSetControlAreaSymbolsLoaded(),
MiLoadUserSymbols():
Added on 436edb2 (r60802). Never used.

MiSubsectionConsistent():
Added on cda03c0 (r57209). Never used.

MiGetFileObjectForSectionAddress():
Added on 635d9ca (r67810). Calls removed on 0dfd233 (r68123).

MiSetProtectionOnSection():
Added on 9f28638 (r56317). Never used.

Plus,
MmCreateArm3Section():
Add an UNIMPLEMENTED on a specific case.

* [NTOS:MM] section.c: Use static instead of NTAPI for local functions
This commit is contained in:
Serge Gautherie 2024-05-21 11:08:40 +02:00 committed by GitHub
parent 2198247bdf
commit a6298b5c7a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 15 additions and 397 deletions

View File

@ -2242,14 +2242,6 @@ MiInsertBasedSection(
IN PSECTION Section
);
NTSTATUS
NTAPI
MiUnmapViewOfSection(
IN PEPROCESS Process,
IN PVOID BaseAddress,
IN ULONG Flags
);
NTSTATUS
NTAPI
MiRosUnmapViewOfSection(
@ -2310,13 +2302,6 @@ MiSessionAddProcess(
IN PEPROCESS NewProcess
);
NTSTATUS
NTAPI
MiSessionCommitPageTables(
IN PVOID StartVa,
IN PVOID EndVa
);
ULONG
NTAPI
MiMakeProtectionMask(

View File

@ -112,8 +112,8 @@ PVOID MmHighSectionBase;
/* PRIVATE FUNCTIONS **********************************************************/
static
BOOLEAN
NTAPI
MiIsProtectionCompatible(IN ULONG SectionPageProtection,
IN ULONG NewSectionPageProtection)
{
@ -283,8 +283,8 @@ MiInitializeSystemSpaceMap(IN PMMSESSION InputSession OPTIONAL)
return TRUE;
}
static
PVOID
NTAPI
MiInsertInSystemSpace(IN PMMSESSION Session,
IN ULONG Buckets,
IN PCONTROL_AREA ControlArea)
@ -525,8 +525,8 @@ MiFillSystemPageDirectory(IN PVOID Base,
}
}
static
NTSTATUS
NTAPI
MiCheckPurgeAndUpMapCount(IN PCONTROL_AREA ControlArea,
IN BOOLEAN FailIfSystemViews)
{
@ -586,8 +586,8 @@ MiLocateSubsection(IN PMMVAD Vad,
return Subsection;
}
static
VOID
NTAPI
MiSegmentDelete(IN PSEGMENT Segment)
{
PCONTROL_AREA ControlArea;
@ -709,8 +709,8 @@ MiSegmentDelete(IN PSEGMENT Segment)
ExFreePool(Segment);
}
static
VOID
NTAPI
MiCheckControlArea(IN PCONTROL_AREA ControlArea,
IN KIRQL OldIrql)
{
@ -744,8 +744,8 @@ MiCheckControlArea(IN PCONTROL_AREA ControlArea,
}
}
static
VOID
NTAPI
MiDereferenceControlArea(IN PCONTROL_AREA ControlArea)
{
KIRQL OldIrql;
@ -798,8 +798,8 @@ MiRemoveMappedView(IN PEPROCESS CurrentProcess,
MiCheckControlArea(ControlArea, OldIrql);
}
static
NTSTATUS
NTAPI
MiUnmapViewOfSection(IN PEPROCESS Process,
IN PVOID BaseAddress,
IN ULONG Flags)
@ -919,8 +919,8 @@ Quickie:
return Status;
}
static
NTSTATUS
NTAPI
MiSessionCommitPageTables(IN PVOID StartVa,
IN PVOID EndVa)
{
@ -1147,120 +1147,8 @@ MiMapViewInSystemSpace(
return STATUS_SUCCESS;
}
VOID
NTAPI
MiSetControlAreaSymbolsLoaded(IN PCONTROL_AREA ControlArea)
{
KIRQL OldIrql;
ASSERT(KeGetCurrentIrql() <= APC_LEVEL);
OldIrql = MiAcquirePfnLock();
ControlArea->u.Flags.DebugSymbolsLoaded |= 1;
ASSERT(OldIrql <= APC_LEVEL);
MiReleasePfnLock(OldIrql);
ASSERT(KeGetCurrentIrql() <= APC_LEVEL);
}
VOID
NTAPI
MiLoadUserSymbols(IN PCONTROL_AREA ControlArea,
IN PVOID BaseAddress,
IN PEPROCESS Process)
{
NTSTATUS Status;
ANSI_STRING FileNameA;
PLIST_ENTRY NextEntry;
PUNICODE_STRING FileName;
PIMAGE_NT_HEADERS NtHeaders;
PLDR_DATA_TABLE_ENTRY LdrEntry;
FileName = &ControlArea->FilePointer->FileName;
if (FileName->Length == 0)
{
return;
}
/* Acquire module list lock */
KeEnterCriticalRegion();
ExAcquireResourceExclusiveLite(&PsLoadedModuleResource, TRUE);
/* Browse list to try to find current module */
for (NextEntry = MmLoadedUserImageList.Flink;
NextEntry != &MmLoadedUserImageList;
NextEntry = NextEntry->Flink)
{
/* Get the entry */
LdrEntry = CONTAINING_RECORD(NextEntry,
LDR_DATA_TABLE_ENTRY,
InLoadOrderLinks);
/* If already in the list, increase load count */
if (LdrEntry->DllBase == BaseAddress)
{
++LdrEntry->LoadCount;
break;
}
}
/* Not in the list, we'll add it */
if (NextEntry == &MmLoadedUserImageList)
{
/* Allocate our element, taking to the name string and its null char */
LdrEntry = ExAllocatePoolWithTag(NonPagedPool, FileName->Length + sizeof(UNICODE_NULL) + sizeof(*LdrEntry), 'bDmM');
if (LdrEntry)
{
memset(LdrEntry, 0, FileName->Length + sizeof(UNICODE_NULL) + sizeof(*LdrEntry));
_SEH2_TRY
{
/* Get image checksum and size */
NtHeaders = RtlImageNtHeader(BaseAddress);
if (NtHeaders)
{
LdrEntry->SizeOfImage = NtHeaders->OptionalHeader.SizeOfImage;
LdrEntry->CheckSum = NtHeaders->OptionalHeader.CheckSum;
}
}
_SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
{
ExFreePoolWithTag(LdrEntry, 'bDmM');
ExReleaseResourceLite(&PsLoadedModuleResource);
KeLeaveCriticalRegion();
_SEH2_YIELD(return);
}
_SEH2_END;
/* Fill all the details */
LdrEntry->DllBase = BaseAddress;
LdrEntry->FullDllName.Buffer = (PVOID)((ULONG_PTR)LdrEntry + sizeof(*LdrEntry));
LdrEntry->FullDllName.Length = FileName->Length;
LdrEntry->FullDllName.MaximumLength = FileName->Length + sizeof(UNICODE_NULL);
memcpy(LdrEntry->FullDllName.Buffer, FileName->Buffer, FileName->Length);
LdrEntry->FullDllName.Buffer[LdrEntry->FullDllName.Length / sizeof(WCHAR)] = UNICODE_NULL;
LdrEntry->LoadCount = 1;
/* Insert! */
InsertHeadList(&MmLoadedUserImageList, &LdrEntry->InLoadOrderLinks);
}
}
/* Release locks */
ExReleaseResourceLite(&PsLoadedModuleResource);
KeLeaveCriticalRegion();
/* Load symbols */
Status = RtlUnicodeStringToAnsiString(&FileNameA, FileName, TRUE);
if (NT_SUCCESS(Status))
{
DbgLoadImageSymbols(&FileNameA, BaseAddress, (ULONG_PTR)Process->UniqueProcessId);
RtlFreeAnsiString(&FileNameA);
}
}
static
NTSTATUS
NTAPI
MiMapViewOfDataSection(IN PCONTROL_AREA ControlArea,
IN PEPROCESS Process,
IN PVOID *BaseAddress,
@ -1514,25 +1402,8 @@ MiMapViewOfDataSection(IN PCONTROL_AREA ControlArea,
return STATUS_SUCCESS;
}
VOID
NTAPI
MiSubsectionConsistent(IN PSUBSECTION Subsection)
{
/* ReactOS only supports systems with 4K pages and 4K sectors */
ASSERT(Subsection->u.SubsectionFlags.SectorEndOffset == 0);
/* Therefore, then number of PTEs should be equal to the number of sectors */
if (Subsection->NumberOfFullSectors != Subsection->PtesInSubsection)
{
/* Break and warn if this is inconsistent */
DPRINT1("Mm: Subsection inconsistent (%x vs %x)\n",
Subsection->NumberOfFullSectors, Subsection->PtesInSubsection);
DbgBreakPoint();
}
}
static
NTSTATUS
NTAPI
MiCreateDataFileMap(IN PFILE_OBJECT File,
OUT PSEGMENT *Segment,
IN PSIZE_T MaximumSize,
@ -1548,7 +1419,6 @@ MiCreateDataFileMap(IN PFILE_OBJECT File,
static
NTSTATUS
NTAPI
MiCreatePagingFileMap(OUT PSEGMENT *Segment,
IN PLARGE_INTEGER MaximumSize,
IN ULONG ProtectionMask,
@ -1666,72 +1536,6 @@ MiCreatePagingFileMap(OUT PSEGMENT *Segment,
return STATUS_SUCCESS;
}
NTSTATUS
NTAPI
MiGetFileObjectForSectionAddress(
IN PVOID Address,
OUT PFILE_OBJECT *FileObject)
{
PMMVAD Vad;
PCONTROL_AREA ControlArea;
/* Get the VAD */
Vad = MiLocateAddress(Address);
if (Vad == NULL)
{
/* Fail, the address does not exist */
DPRINT1("Invalid address\n");
return STATUS_INVALID_ADDRESS;
}
/* Check if this is a RosMm memory area */
if (Vad->u.VadFlags.Spare != 0)
{
PMEMORY_AREA MemoryArea = (PMEMORY_AREA)Vad;
/* Check if it's a section view (RosMm section) */
if (MemoryArea->Type == MEMORY_AREA_SECTION_VIEW)
{
/* Get the section pointer to the SECTION_OBJECT */
*FileObject = MemoryArea->SectionData.Segment->FileObject;
}
else
{
#ifdef NEWCC
ASSERT(MemoryArea->Type == MEMORY_AREA_CACHE);
DPRINT1("Address is a cache section!\n");
return STATUS_SECTION_NOT_IMAGE;
#else
ASSERT(FALSE);
return STATUS_SECTION_NOT_IMAGE;
#endif
}
}
else
{
/* Make sure it's not a VM VAD */
if (Vad->u.VadFlags.PrivateMemory == 1)
{
DPRINT1("Address is not a section\n");
return STATUS_SECTION_NOT_IMAGE;
}
/* Get the control area */
ControlArea = Vad->ControlArea;
if (!(ControlArea) || !(ControlArea->u.Flags.Image))
{
DPRINT1("Address is not a section\n");
return STATUS_SECTION_NOT_IMAGE;
}
/* Get the file object */
*FileObject = ControlArea->FilePointer;
}
/* Return success */
return STATUS_SUCCESS;
}
PFILE_OBJECT
NTAPI
MmGetFileObjectForSection(IN PVOID SectionObject)
@ -1827,8 +1631,8 @@ MmGetImageInformation (OUT PSECTION_IMAGE_INFORMATION ImageInformation)
*ImageInformation = ((PMM_IMAGE_SECTION_OBJECT)SectionObject->Segment)->ImageInformation;
}
static
NTSTATUS
NTAPI
MmGetFileNameForFileObject(IN PFILE_OBJECT FileObject,
OUT POBJECT_NAME_INFORMATION *ModuleName)
{
@ -2111,180 +1915,8 @@ MiFlushTbAndCapture(IN PMMVAD FoundVad,
MiReleasePfnLock(OldIrql);
}
//
// NOTE: This function gets a lot more complicated if we want Copy-on-Write support
//
NTSTATUS
NTAPI
MiSetProtectionOnSection(IN PEPROCESS Process,
IN PMMVAD FoundVad,
IN PVOID StartingAddress,
IN PVOID EndingAddress,
IN ULONG NewProtect,
OUT PULONG CapturedOldProtect,
IN ULONG DontCharge,
OUT PULONG Locked)
{
PMMPTE PointerPte, LastPte;
MMPTE TempPte, PteContents;
PMMPDE PointerPde;
PMMPFN Pfn1;
ULONG ProtectionMask, QuotaCharge = 0;
PETHREAD Thread = PsGetCurrentThread();
PAGED_CODE();
//
// Tell caller nothing is being locked
//
*Locked = FALSE;
//
// This function should only be used for section VADs. Windows ASSERT */
//
ASSERT(FoundVad->u.VadFlags.PrivateMemory == 0);
//
// We don't support these features in ARM3
//
ASSERT(FoundVad->u.VadFlags.VadType != VadImageMap);
ASSERT(FoundVad->u2.VadFlags2.CopyOnWrite == 0);
//
// Convert and validate the protection mask
//
ProtectionMask = MiMakeProtectionMask(NewProtect);
if (ProtectionMask == MM_INVALID_PROTECTION)
{
DPRINT1("Invalid section protect\n");
return STATUS_INVALID_PAGE_PROTECTION;
}
//
// Get the PTE and PDE for the address, as well as the final PTE
//
MiLockProcessWorkingSetUnsafe(Process, Thread);
PointerPde = MiAddressToPde(StartingAddress);
PointerPte = MiAddressToPte(StartingAddress);
LastPte = MiAddressToPte(EndingAddress);
//
// Make the PDE valid, and check the status of the first PTE
//
MiMakePdeExistAndMakeValid(PointerPde, Process, MM_NOIRQL);
if (PointerPte->u.Long)
{
//
// Not supported in ARM3
//
ASSERT(FoundVad->u.VadFlags.VadType != VadRotatePhysical);
//
// Capture the page protection and make the PDE valid
//
*CapturedOldProtect = MiGetPageProtection(PointerPte);
MiMakePdeExistAndMakeValid(PointerPde, Process, MM_NOIRQL);
}
else
{
//
// Only pagefile-backed section VADs are supported for now
//
ASSERT(FoundVad->u.VadFlags.VadType != VadImageMap);
//
// Grab the old protection from the VAD itself
//
*CapturedOldProtect = MmProtectToValue[FoundVad->u.VadFlags.Protection];
}
//
// Loop all the PTEs now
//
MiMakePdeExistAndMakeValid(PointerPde, Process, MM_NOIRQL);
while (PointerPte <= LastPte)
{
//
// Check if we've crossed a PDE boundary and make the new PDE valid too
//
if (MiIsPteOnPdeBoundary(PointerPte))
{
PointerPde = MiPteToPde(PointerPte);
MiMakePdeExistAndMakeValid(PointerPde, Process, MM_NOIRQL);
}
//
// Capture the PTE and see what we're dealing with
//
PteContents = *PointerPte;
if (PteContents.u.Long == 0)
{
//
// This used to be a zero PTE and it no longer is, so we must add a
// reference to the pagetable.
//
MiIncrementPageTableReferences(MiPteToAddress(PointerPte));
//
// Create the demand-zero prototype PTE
//
TempPte = PrototypePte;
TempPte.u.Soft.Protection = ProtectionMask;
MI_WRITE_INVALID_PTE(PointerPte, TempPte);
}
else if (PteContents.u.Hard.Valid == 1)
{
//
// Get the PFN entry
//
Pfn1 = MiGetPfnEntry(PFN_FROM_PTE(&PteContents));
//
// We don't support these yet
//
ASSERT((NewProtect & (PAGE_NOACCESS | PAGE_GUARD)) == 0);
ASSERT(Pfn1->u3.e1.PrototypePte == 0);
//
// Write the protection mask and write it with a TLB flush
//
Pfn1->OriginalPte.u.Soft.Protection = ProtectionMask;
MiFlushTbAndCapture(FoundVad,
PointerPte,
ProtectionMask,
Pfn1,
TRUE);
}
else
{
//
// We don't support these cases yet
//
ASSERT(PteContents.u.Soft.Prototype == 0);
ASSERT(PteContents.u.Soft.Transition == 0);
//
// The PTE is already demand-zero, just update the protection mask
//
PointerPte->u.Soft.Protection = ProtectionMask;
}
PointerPte++;
}
//
// Unlock the working set and update quota charges if needed, then return
//
MiUnlockProcessWorkingSetUnsafe(Process, Thread);
if ((QuotaCharge > 0) && (!DontCharge))
{
FoundVad->u.VadFlags.CommitCharge -= QuotaCharge;
Process->CommitCharge -= QuotaCharge;
}
return STATUS_SUCCESS;
}
static
VOID
NTAPI
MiRemoveMappedPtes(IN PVOID BaseAddress,
IN ULONG NumberOfPtes,
IN PCONTROL_AREA ControlArea,
@ -2385,8 +2017,8 @@ MiRemoveMappedPtes(IN PVOID BaseAddress,
MiCheckControlArea(ControlArea, OldIrql);
}
static
ULONG
NTAPI
MiRemoveFromSystemSpace(IN PMMSESSION Session,
IN PVOID Base,
OUT PCONTROL_AREA *ControlArea)
@ -2429,8 +2061,8 @@ MiRemoveFromSystemSpace(IN PMMSESSION Session,
return Size;
}
static
NTSTATUS
NTAPI
MiUnmapViewInSystemSpace(IN PMMSESSION Session,
IN PVOID MappedBase)
{
@ -2569,6 +2201,7 @@ MmCreateArm3Section(OUT PVOID *SectionObject,
}
#else
/* ReactOS doesn't support this API yet, so do nothing */
UNIMPLEMENTED;
Status = STATUS_SUCCESS;
#endif
/* Update the top-level IRP so that drivers know what's happening */