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

Function EraVirtualAllocEx

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

Source from the content-addressed store, hash-verified

227 *NumberOfPages = PagesAllocated;
228 SetLastError(PagesAllocated > 0 ? ERROR_SUCCESS : ERROR_OUTOFMEMORY);
229 return PagesAllocated > 0;
230}
231
232EXTERN_C BOOL __stdcall FreeTitlePhysicalPages(HANDLE hProcess, ULONG_PTR NumberOfPages, PULONG_PTR PageArray)
233{
234 UNREFERENCED_PARAMETER(hProcess);
235
236 if (NumberOfPages && !PageArray)
237 {
238 SetLastError(ERROR_INVALID_PARAMETER);
239 return FALSE;
240 }
241
242 AcquireSRWLockExclusive(&XwpPhysicalMemoryLock);
243
244 for (ULONG_PTR i = 0; i < NumberOfPages; i++)
245 XwpPhysicalPages[PageArray[i]] = false;
246
247 ReleaseSRWLockExclusive(&XwpPhysicalMemoryLock);
248 SetLastError(ERROR_SUCCESS);
249 return TRUE;
250}
251
252EXTERN_C LPVOID __stdcall EraVirtualAllocEx(HANDLE hProcess, LPVOID lpAddress, SIZE_T dwSize, DWORD flAllocationType,
253 DWORD flProtect)
254{
255 if (flAllocationType & MEM_GRAPHICS)
256 {
257 flProtect = PAGE_READONLY;
258 }
259
260 MEM_ADDRESS_REQUIREMENTS AddrRq;
261 AddrRq.LowestStartingAddress = nullptr;
262 AddrRq.HighestEndingAddress = nullptr;
263 AddrRq.Alignment = 0;
264
265 MEM_EXTENDED_PARAMETER ExtParam;
266 ExtParam.Type = MemExtendedParameterAddressRequirements;
267 ExtParam.Reserved = 0;
268 ExtParam.Pointer = &AddrRq;
269
270 // If true, the memory can be used with MapTitlePhysicalPages and D3DMapEsramMemory.
271 // These allocations go through a file mapping and therefore get handled differently.
272 BOOL bMappable = FALSE;
273 MAPPABLE_MEM Mappable = {};
274 SIZE_T dwPageSize = PAGE_SIZE_4KB;
275
276 if (flAllocationType & (MEM_RESERVE | MEM_TOP_DOWN))
277 {
278 // If MEM_LARGE_PAGES or MEM_4MB_PAGES is specified, the memory is mappable.
279 bMappable = !!(flAllocationType & (MEM_LARGE_PAGES | MEM_4MB_PAGES));
280
281 if (!lpAddress)
282 {
283 if (flAllocationType & MEM_4MB_PAGES)
284 AddrRq.Alignment = PAGE_SIZE_4MB;
285
286 // If we're reserving memory, ERA will use specific memory ranges.

Callers 1

EraVirtualAllocFunction · 0.85

Calls 3

MappableQueryFunction · 0.85
SetLastErrorFunction · 0.85
CloseHandleFunction · 0.85

Tested by

no test coverage detected