private void CreateHeap() { // Required so that page allocations by new Thread don't create conflicts ProcessManager.EnableKernelAccessToProcessMemory(this); #if PROCESS_TRACE BasicConsole.WriteLine("Allocating memory for heap..."); #endif // Allocate memory for new heap uint heapPages = 64; // 256KiB, page-aligned FOS_System.HeapBlock *heapPtr = (FOS_System.HeapBlock *)VirtMemManager.MapFreePages( UserMode ? VirtMemImpl.PageFlags.None : VirtMemImpl.PageFlags.KernelOnly, (int)heapPages); #if PROCESS_TRACE BasicConsole.WriteLine("Generating physical addresses..."); #endif uint[] pAddrs = new uint[heapPages]; for (uint currPtr = (uint)heapPtr, i = 0; i < heapPages; currPtr += 4096, i++) { pAddrs[i] = VirtMemManager.GetPhysicalAddress(currPtr); } #if PROCESS_TRACE BasicConsole.WriteLine("Adding memory to current process (kernel task) layout..."); #endif // Add heap memory to current (kernel) process's memory // - Makes sure it won't be mapped out during initialisation ProcessManager.CurrentProcess.TheMemoryLayout.AddDataPages((uint)heapPtr, pAddrs); // Force reload of the memory layout ProcessManager.CurrentProcess.TheMemoryLayout.Load(ProcessManager.CurrentProcess.UserMode); #if PROCESS_TRACE BasicConsole.WriteLine("Initialising heap..."); #endif // Initialise the heap FOS_System.Heap.InitBlock(heapPtr, heapPages * 4096, 32); #if PROCESS_TRACE BasicConsole.WriteLine("Adding memory to layout..."); #endif // Add allocated new process's memory to layout TheMemoryLayout.AddDataPages((uint)heapPtr, pAddrs); #if PROCESS_TRACE BasicConsole.WriteLine("Removing memory from current process (kernel task) layout..."); #endif ProcessManager.DisableKernelAccessToProcessMemory(this); #if PROCESS_TRACE BasicConsole.WriteLine("Setting heap pointer..."); #endif // Set heap pointer HeapPtr = heapPtr; }
private void CreateHeap() { #if PROCESS_TRACE BasicConsole.WriteLine("Allocating memory for heap..."); #endif // Allocate memory for new heap uint heapPages = 64; // 256KiB, page-aligned FOS_System.HeapBlock* heapPtr = (FOS_System.HeapBlock*)VirtMemManager.MapFreePages( UserMode ? VirtMemImpl.PageFlags.None : VirtMemImpl.PageFlags.KernelOnly, (int)heapPages); #if PROCESS_TRACE BasicConsole.WriteLine("Generating physical addresses..."); #endif uint[] pAddrs = new uint[heapPages]; for (uint currPtr = (uint)heapPtr, i = 0; i < heapPages; currPtr += 4096, i++) { pAddrs[i] = VirtMemManager.GetPhysicalAddress(currPtr); } #if PROCESS_TRACE BasicConsole.WriteLine("Adding memory to current process (kernel task) layout..."); #endif // Add heap memory to current (kernel) process's memory // - Makes sure it won't be mapped out during initialisation ProcessManager.CurrentProcess.TheMemoryLayout.AddDataPages((uint)heapPtr, pAddrs); // Force reload of the memory layout ProcessManager.CurrentProcess.TheMemoryLayout.Load(ProcessManager.CurrentProcess.UserMode); #if PROCESS_TRACE BasicConsole.WriteLine("Initialising heap..."); #endif // Initialise the heap FOS_System.Heap.InitBlock(heapPtr, heapPages * 4096, 32); #if PROCESS_TRACE BasicConsole.WriteLine("Adding memory to layout..."); #endif // Add allocated new process's memory to layout TheMemoryLayout.AddDataPages((uint)heapPtr, pAddrs); #if PROCESS_TRACE BasicConsole.WriteLine("Removing memory from current process (kernel task) layout..."); #endif // Remove heap memory from current (kernel) process's memory ProcessManager.CurrentProcess.TheMemoryLayout.RemovePages((uint)heapPtr, heapPages); #if PROCESS_TRACE BasicConsole.WriteLine("Setting heap pointer..."); #endif // Set heap pointer HeapPtr = heapPtr; }