public virtual Thread CreateThread(ThreadStartMethod MainMethod, FOS_System.String Name) { #if PROCESS_TRACE BasicConsole.WriteLine("Process: CreateThread: Creating thread..."); #endif //TODO: Wrap EnableKernelAccessToProcessMemory in try-finally blocks // Required so that page allocations by new Thread don't create conflicts ProcessManager.EnableKernelAccessToProcessMemory(this); Thread newThread = new Thread(this, MainMethod, ThreadIdGenerator++, UserMode, Name); #if PROCESS_TRACE BasicConsole.WriteLine("Adding data page..."); #endif // Add the page to the processes memory layout uint threadStackVirtAddr = (uint)newThread.State->ThreadStackTop - 4092; uint threadStackPhysAddr = (uint)VirtMemManager.GetPhysicalAddress(newThread.State->ThreadStackTop - 4092); TheMemoryLayout.AddDataPage(threadStackPhysAddr, threadStackVirtAddr); ProcessManager.DisableKernelAccessToProcessMemory(this); #if PROCESS_TRACE BasicConsole.WriteLine("Adding thread..."); #endif Threads.Add(newThread); if (Registered) { Scheduler.InitThread(this, newThread); } return(newThread); }
public virtual Thread CreateThread(ThreadStartMethod MainMethod, FOS_System.String Name) { #if PROCESS_TRACE BasicConsole.WriteLine("Creating thread..."); #endif Thread newThread = new Thread(this, MainMethod, ThreadIdGenerator++, UserMode, Name); #if PROCESS_TRACE BasicConsole.WriteLine("Adding data page..."); #endif // Add the page to the processes memory layout uint threadStackVirtAddr = (uint)newThread.State->ThreadStackTop - 4092; uint threadStackPhysAddr = (uint)VirtMemManager.GetPhysicalAddress(newThread.State->ThreadStackTop - 4092); TheMemoryLayout.AddDataPage(threadStackPhysAddr, threadStackVirtAddr); if (ProcessManager.KernelProcess != null) { ProcessManager.KernelProcess.TheMemoryLayout.AddDataPage(threadStackPhysAddr, threadStackVirtAddr); } #if PROCESS_TRACE BasicConsole.WriteLine("Adding thread..."); #endif Threads.Add(newThread); if (Registered) { Scheduler.InitThread(this, newThread); } return(newThread); }