MCPcopy Create free account
hub / github.com/WinDurango/WinDurango / MapTitleEsramPages

Function MapTitleEsramPages

projects/WinDurango.KernelX/src/kernelx.cpp:545–587  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

543 !VirtualAddress || !VirtualQuery(VirtualAddress, &mbi, sizeof(mbi)) || mbi.State == MEM_FREE)
544 {
545 VirtualAddress = EraVirtualAlloc(VirtualAddress, NumberOfPages * PAGE_SIZE_64K, MEM_RESERVE | flAllocationType,
546 PAGE_NOACCESS);
547
548 if (!VirtualAddress)
549 {
550 return nullptr;
551 }
552 }
553
554 for (ULONG_PTR i = 0; i < NumberOfPages; i += RegionSize)
555 {
556 ULONG_PTR PhysicalOffset = PAGE_SIZE_64K * PageArray[i];
557 PVOID PageVirtualAddress = (PVOID)((ULONG_PTR)VirtualAddress + i * PAGE_SIZE_64K);
558 UnmapViewOfFile2(GetCurrentProcess(), PageVirtualAddress, MEM_PRESERVE_PLACEHOLDER);
559 MapViewOfFile3(XwpPhysicalMemory, nullptr, PageVirtualAddress, PhysicalOffset, dwPageSize,
560 MEM_REPLACE_PLACEHOLDER, PAGE_READWRITE, nullptr, 0);
561 VirtualAlloc2(nullptr, PageVirtualAddress, dwPageSize, MEM_COMMIT, flProtect & PAGE_MASK, nullptr, 0);
562 }
563
564 SetLastError(ERROR_SUCCESS);
565 return VirtualAddress;
566}
567
568EXTERN_C HRESULT __stdcall MapTitleEsramPages(PVOID VirtualAddress, UINT NumberOfPages, DWORD flAllocationType,
569 UINT const *PageArray)
570{
571 if (!VirtualAddress || (flAllocationType & (MEM_LARGE_PAGES | MEM_4MB_PAGES)) == 0 ||
572 (flAllocationType & (MEM_LARGE_PAGES | MEM_4MB_PAGES)) == (MEM_LARGE_PAGES | MEM_4MB_PAGES))
573 {
574 return E_INVALIDARG;
575 }
576
577 SIZE_T dwPageSize = (flAllocationType & MEM_LARGE_PAGES) ? PAGE_SIZE_64K : PAGE_SIZE_4MB;
578
579 if (NumberOfPages * dwPageSize > MEM_ESRAM_SIZE)
580 return E_INVALIDARG;
581
582 if ((ULONG_PTR)VirtualAddress & (dwPageSize - 1))
583 return E_INVALIDARG;
584
585 if (!PageArray)
586 {
587 for (ULONG_PTR dwOffset = 0; dwOffset < NumberOfPages * dwPageSize; dwOffset += dwPageSize)
588 {
589 PVOID PageAddress = (PVOID)((ULONG_PTR)VirtualAddress + dwOffset);
590 UnmapViewOfFile2(GetCurrentProcess(), PageAddress, MEM_PRESERVE_PLACEHOLDER);

Callers 2

D3DMapEsramMemoryFunction · 0.85
D3DMapEsramMemoryFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected