// Low-level routines based on the operating system interface private static unsafe UIntPtr AllocateMemoryHelper(UIntPtr startAddr, UIntPtr size) { void *result = VirtualAlloc((void *)startAddr, size, MEM_RESERVE, PAGE_READWRITE); VTable.Assert (PageTable.Page((UIntPtr)result + size - 1) < PageTable.pageTableCount, "OutOfMemory: MemoryManager: memory doesn't fit in page table"); if (result != null) { Trace.Log(Trace.Area.Page, "VirtualAlloc {0} at {1}", __arglist(size, result)); VTable.Assert((startAddr == UIntPtr.Zero) || (result == (void *)startAddr)); void *area = VirtualAlloc(result, size, MEM_COMMIT, PAGE_READWRITE); if (PageTable.halPageDescriptor != null) { PageTable.CreateNewPageTablesIfNecessary(PageTable.Page((UIntPtr)result), PageTable.PageCount(size)); PageTable.SetProcess(PageTable.Page((UIntPtr)area), PageTable.PageCount(size)); } VTable.Assert(result == area); #if HIMEM // This assertion intends only to catch bugs in Bartok. But if // the system (windows) frees memory before, the memory // may be in low memory, and if we happen to get that // memory, this assertion itself may not hold VTable.Assert((UIntPtr)result >= PageTable.HIMEMStart, ("High memory is expected to be allocated in HIMEM mode")); #endif } return(new UIntPtr(result)); }