internal static Process Create(string name, ulong e_point, ulong stack_size, Virtual_Regions vreg, SymbolTable stab, object[] parameters, ulong tls_size) { Process p = new Process(); p.startup_thread = Thread.Create(name + "(Thread 1)", e_point, stack_size, tls_size, vreg, stab, parameters); p.startup_thread.owning_process = p; p.threads.Add(p.startup_thread); p.name = name; if (Program.running_processes != null) { Program.running_processes[name] = p; } return(p); }
internal static Thread Create(string name, ulong e_point, ulong stack_size, ulong tls_size, Virtual_Regions vreg, SymbolTable stab, object[] parameters) { Thread t = new Thread(); if (e_point == 0) { throw new Exception("Thread entry point is null (" + name + ")"); } t.mt = new System.Threading.Thread(System.Runtime.InteropServices.Marshal.GetDelegateForFunctionPointer <System.Threading.ThreadStart>((IntPtr)e_point)); SetTysosThread(t.mt, t); t.thread_id = next_thread_id++; t.saved_state = Program.arch.CreateTaskSwitchInfo(); t.stack = vreg.AllocRegion(stack_size, 0x1000, name + "_Stack", 0x1000, Virtual_Regions.Region.RegionType.Stack, true); t.tls = vreg.AllocRegion(tls_size, 0x1000, name + "_TLS", 0, Virtual_Regions.Region.RegionType.ModuleSection, true); t.saved_state.Init(new UIntPtr(e_point), t.stack, t.tls, new UIntPtr(stab.GetAddress("__exit")), parameters); t.name = name; t.exit_address = stab.GetAddress("__exit"); return(t); }