private static void FinalizePreMonitoring() { Stacks.Finalize(); HandleTable.Finalize(); SharedHeap.Finalize(); MemoryManager.Finalize(); }
public static ExternalProcessState GetState(ProcessHandle handle) { Process process = HandleTable.GetHandle(handle.id) as Process; switch (process.State) { case InternalProcessState.Unstarted: case InternalProcessState.Running: return(ExternalProcessState.Active); case InternalProcessState.Suspending: case InternalProcessState.SuspendingRecursive: case InternalProcessState.Suspended: return(ExternalProcessState.Suspended); case InternalProcessState.Stopping: case InternalProcessState.Stopped: return(ExternalProcessState.Stopped); default: // handle new missing case DebugStub.Break(); return(ExternalProcessState.Stopped); } }
private void Unload() { if (Disposed || Threads.Count > 0) { return; } Disposed = true; foreach (object Obj in HandleTable.Clear()) { if (Obj is KSession Session) { Session.Dispose(); } } INvDrvServices.UnloadProcess(this); if (NeedsHbAbi && Executables.Count > 0 && Executables[0].FilePath.EndsWith(Homebrew.TemporaryNroSuffix)) { File.Delete(Executables[0].FilePath); } Device.Log.PrintInfo(LogClass.Loader, $"Process {ProcessId} exiting..."); }
/// Called from Binder which lives in a separate dll. public static SystemType Register(string name, long lowerHash, long upperHash, SystemType parent) { RuntimeSystemType parentrts = HandleTable.GetHandle(parent.id) as RuntimeSystemType; #if false DebugStub.WriteLine("SystemType.Register '{0}' hash0={1:x8} hash1={2:x8} Parent {3}", __arglist(name, lowerHash, upperHash, parent.TypeId)); Tracing.Log(Tracing.Debug, "Type '{0}' (parent={1:x8})", name, parent.id); Tracing.Log(Tracing.Debug, "hash0={0:x8} hash1={1:x8}", lowerHash.ToString(), upperHash.ToString()); #endif // false UIntPtr childHandle = parentrts.LookupChildHandle(name, lowerHash, upperHash); #if false Tracing.Log(Tracing.Debug, "result UIntPtr = {0:x8}", childHandle); #endif // false SystemType ret = new SystemType(childHandle); return(ret); }
public static unsafe bool BindToService( ProcessHandle handle, SystemType impType, SystemType expType, char *contractChars, int contractLen, int startState, int index) { //convert contract to string if (contractLen == 0) { return(false); } Process process = HandleTable.GetHandle(handle.id) as Process; string contract = String.StringCTOR(contractChars, 0, contractLen); if (contract == null) { return(false); } return(Binder.BindToService(process, impType, expType, contract, startState, index)); }
private static void _fire(HandleTable handles, LinkedList <EventObj> firedEvents, string eventname, object[] args) { handles.Lock(); List <Pair> lst; if (!handles.TryGetValue(eventname, out lst)) { handles.UnLock(); return; } Debug.Log("fire 1:" + eventname); for (int i = 0; i < lst.Count; i++) { var eobj = new EventObj(); eobj._info = lst[i]; eobj._args = args; firedEvents.AddLast(eobj); } handles.UnLock(); }
public static unsafe ParameterCode SetStartupStringArrayArg( ProcessHandle handle, int index, char *args, int *argLengths, int argCount) { Process process = HandleTable.GetHandle(handle.id) as Process; // // Create a kernel String[] object populated with the argument // values passed in from userland. // String[] arguments = new String[argCount]; int offset = 0; for (int argument = 0; argument < argCount; argument++) { arguments[argument] = String.StringCTOR( args, offset, argLengths[argument]); offset += argLengths[argument]; } return((ParameterCode)process.SetStartupStringArrayArg(index, arguments)); }
private static bool _unregister(HandleTable handles, string eventname, object obj, string funcname) { handles.Lock(); List <Pair> lst; if (!handles.TryGetValue(eventname, out lst)) { handles.UnLock(); return(false); } for (int i = 0; i < lst.Count; i++) { if (obj == lst[i]._obj && lst[i]._funcname == funcname) { lst.RemoveAt(i); handles.UnLock(); return(true); } } handles.UnLock(); return(false); }
internal bool IsSubtype(UIntPtr candidateHandle) { if (candidateHandle == UIntPtr.Zero) { DebugLine("RST.IsSubType {0:x8} of {1:x8} => false", __arglist(candidateHandle, handle)); return(false); } RuntimeSystemType candidate = HandleTable.GetHandle(candidateHandle) as RuntimeSystemType; if (candidate == null) { DebugLine("RST.IsSubType {0:x8} of {1:x8} => false", __arglist(candidateHandle, handle)); return(false); } RuntimeSystemType current = this; while (current != null) { if (current == candidate) { DebugLine("RST.IsSubType {0:x8} of {1:x8} => true", __arglist(candidateHandle, handle)); return(true); } current = current.parent; } DebugLine("RST.IsSubType {0:x8} of {1:x8} => false", __arglist(candidateHandle, handle)); return(false); }
public static void _process(HandleTable handles) { handles.Lock(); if (handles._fired.Count > 0) { foreach (EventObj evt in handles._fired) { handles._doing.AddLast(evt); } handles._fired.Clear(); } handles.UnLock(); while (handles._doing.Count > 0) { EventObj eobj = handles._doing.First.Value; Debug.Log("process msg : " + eobj._info._funcname); try { eobj._info._method.Invoke(eobj._info._obj, eobj._args); } catch (Exception e) { Debug.Log("Event::processOutEvents: event=" + eobj._info._funcname + "\n" + e); } handles._doing.RemoveFirst(); } }
private static void InitPreMonitoring() { Tracing.Log(0); Tracing.Log(1); Tracing.Log(2); Tracing.Log(3); DebugStub.WriteLine("-------------------------------------------------------------------------------"); ARM_PROGRESS("Kernel!001"); // Indicate that we are not booted yet hasBooted = false; // Rather than mark all bootstrap code with [NoBarriers], perform a mini- // initialization that gives us a working WriteBarrier. System.GCs.Barrier.PreInitialize(); ARM_PROGRESS("Kernel!002"); // Initialize the memory subsystem. If enabled this turns on paging MemoryManager.Initialize(); // Note for Monitoring early boot process: // if you ever want to monitor stuff before this point, you should // allocate a static memory area in BootInit.cs, init the // monitoring system earlier, hold the system at this point here, // copy over all the collected data up to now to the new // dynamically created buffer and continue Monitoring.Initialize(); // uses page memory ARM_PROGRESS("Kernel!003"); HandleTable.Initialize(); }
public static unsafe int WaitAny(SyncHandle *handles, int handleCount, TimeSpan timeout) { WaitHandle[] waits = Thread.CurrentThread.GetSyncHandles(handleCount); for (int i = 0; i < handleCount; i++) { waits[i] = HandleTable.GetHandle(handles[i].id) as WaitHandle;; } int ret = WaitHandle.WaitAny(waits, handleCount, SchedulerTime.Now + timeout); Tracing.Log(Tracing.Debug, "SyncHandle.WaitAny(handles={0:x8}, count={1}, time=) = {2}", (UIntPtr)handles, (UIntPtr) unchecked ((uint)handleCount), (UIntPtr) unchecked ((uint)ret)); for (int i = 0; i < handleCount; i++) { waits[i] = null; } return(ret); }
public void TerminateCurrentProcess() { bool shallTerminate = false; KernelContext.CriticalSection.Enter(); lock (_processLock) { if (State >= ProcessState.Started) { if (State == ProcessState.Started || State == ProcessState.Attached || State == ProcessState.DebugSuspended) { SetState(ProcessState.Exiting); shallTerminate = true; } } } KernelContext.CriticalSection.Leave(); if (shallTerminate) { UnpauseAndTerminateAllThreadsExcept(KernelStatic.GetCurrentThread()); HandleTable.Destroy(); // NOTE: this is supposed to be called in receiving of the mailbox. SignalExitToDebugExited(); SignalExit(); } }
public HashSet <ulong> Run() { // first let's see if it already exists FileInfo cachedFile = new FileInfo(_dataProvider.CacheFolder + "\\pslist_PspCidTable.gz"); if (cachedFile.Exists && !_dataProvider.IsLive) { OffsetMap cachedMap = RetrieveOffsetMap(cachedFile); if (cachedMap != null) { return(cachedMap.OffsetRecords); } } HashSet <ulong> results = new HashSet <ulong>(); uint tableOffset = (uint)_profile.GetConstant("PspCidTable"); ulong vAddr = _profile.KernelBaseAddress + tableOffset; ulong tableAddress = 0; if (_isx64) { var v = _dataProvider.ReadUInt64(vAddr); if (v == null) { return(null); } tableAddress = (ulong)v & 0xffffffffffff; } else { var v = _dataProvider.ReadUInt32(vAddr); if (v == null) { return(null); } tableAddress = (ulong)v; } HandleTable ht = new HandleTable(_profile, _dataProvider, tableAddress); List <HandleTableEntry> records = EnumerateHandles(ht.TableStartAddress, ht.Level); ulong bodyOffset = (ulong)_profile.GetOffset("_OBJECT_HEADER", "Body"); foreach (HandleTableEntry e in records) { try { vAddr = e.ObjectPointer - bodyOffset; ObjectHeader header = new ObjectHeader(_profile, _dataProvider, vAddr); string objectName = GetObjectName(header.TypeInfo); if (objectName == "Process") { results.Add(e.ObjectPointer); } } catch (Exception) { continue; } } return(TrySave(results)); }
public bool Run(bool NeedsHbAbi = false) { if (Disposed) { throw new ObjectDisposedException(nameof(Process)); } this.NeedsHbAbi = NeedsHbAbi; if (Executables.Count == 0) { return(false); } long MainStackTop = MemoryManager.CodeRegionEnd - KMemoryManager.PageSize; long MainStackSize = 1 * 1024 * 1024; long MainStackBottom = MainStackTop - MainStackSize; MemoryManager.HleMapCustom( MainStackBottom, MainStackSize, MemoryState.MappedMemory, MemoryPermission.ReadAndWrite); int Handle = MakeThread(Executables[0].ImageBase, MainStackTop, 0, 44, 0); if (Handle == -1) { return(false); } KThread MainThread = HandleTable.GetKThread(Handle); if (NeedsHbAbi) { HbAbiDataPosition = IntUtils.AlignUp(Executables[0].ImageEnd, KMemoryManager.PageSize); const long HbAbiDataSize = KMemoryManager.PageSize; MemoryManager.HleMapCustom( HbAbiDataPosition, HbAbiDataSize, MemoryState.MappedMemory, MemoryPermission.ReadAndWrite); string SwitchPath = Device.FileSystem.SystemPathToSwitchPath(Executables[0].FilePath); Homebrew.WriteHbAbiData(Memory, HbAbiDataPosition, Handle, SwitchPath); MainThread.Context.ThreadState.X0 = (ulong)HbAbiDataPosition; MainThread.Context.ThreadState.X1 = ulong.MaxValue; } MainThread.TimeUp(); return(true); }
public static PrincipalHandle GetPrincipalHandle(ProcessHandle handle) { Tracing.Log(Tracing.Debug, "ProcessHandle.GetPrincipalHandle(id={0:x8})", handle.id); Process process = HandleTable.GetHandle(handle.id) as Process; return(new PrincipalHandle(process.Principal.Val)); }
public static void Start(ThreadHandle handle) { Thread thread = HandleTable.GetHandle(handle.id) as Thread; Tracing.Log(Tracing.Debug, "ThreadHandle.Start(id={0:x8})", handle.id); thread.Start(); }
public static void SetAffinity(ThreadHandle handle, int affinity) { Tracing.Log(Tracing.Debug, "ThreadHandle.SetAffinity(id={0:x8}, affinity={1})", handle.id, (UIntPtr) unchecked (affinity)); Thread thread = HandleTable.GetHandle(handle.id) as Thread; thread.SetAffinity(affinity); }
public static TimeSpan GetExecutionTime(ThreadHandle handle) { Thread thread = HandleTable.GetHandle(handle.id) as Thread; TimeSpan ts = thread.ExecutionTime; Tracing.Log(Tracing.Debug, "ThreadHandle.GetExecutionTime(id={0:x8}, out time=)", handle.id); return(ts); }
public static ThreadState GetThreadState(ThreadHandle handle) { Thread thread = HandleTable.GetHandle(handle.id) as Thread; ThreadState state = (ThreadState)thread.ThreadState; Tracing.Log(Tracing.Debug, "ThreadHandle.GetThreadState(id={0:x8}, out state={1})", handle.id, (UIntPtr) unchecked ((uint)state)); return(state); }
public static bool Join(ThreadHandle handle, SchedulerTime stop) { Thread thread = HandleTable.GetHandle(handle.id) as Thread; bool ret = thread.Join(stop); Tracing.Log(Tracing.Debug, "ThreadHandle.Join(id={0:x8}, stop=)", handle.id); return(ret); }
public static bool WaitOneNoGC(SyncHandle handle) { WaitHandle waitHandle = HandleTable.GetHandle(handle.id) as WaitHandle; bool ret = waitHandle.WaitOne(SchedulerTime.MaxValue); Tracing.Log(Tracing.Debug, "SyncHandle.WaitOneNoGC(id={0:x8})", handle.id); return(ret); }
public static bool Join(ThreadHandle handle, TimeSpan timeout) { Thread thread = HandleTable.GetHandle(handle.id) as Thread; bool ret = thread.Join(timeout); Tracing.Log(Tracing.Debug, "ThreadHandle.Join(id={0:x8}, time=)", handle.id); return(ret); }
private static bool _hasRegister(HandleTable handles, string eventname) { bool has; handles.Lock(); has = handles.ContainsKey(eventname); handles.UnLock(); return(has); }
public static bool Join(ThreadHandle handle) { Thread thread = HandleTable.GetHandle(handle.id) as Thread; bool ret = true; thread.Join(); Tracing.Log(Tracing.Debug, "ThreadHandle.Join(id={0:x8})", handle.id); return(ret); }
public static void Join(ProcessHandle handle, out bool started) { Tracing.Log(Tracing.Debug, "ProcessHandle.Join(id={0:x8})", handle.id); // // Convert the handle to a process; call Join method. // Process process = HandleTable.GetHandle(handle.id) as Process; process.Join(out started); }
public static bool Resume(ProcessHandle handle, bool recursive) { Tracing.Log(Tracing.Debug, "ProcessHandle.Resume(id={0:x8})", handle.id); // // Convert the handle to a process; call Resume method. // Process process = HandleTable.GetHandle(handle.id) as Process; return(process.Resume(recursive)); }
public static void Stop(ProcessHandle handle, int exitcode) { Tracing.Log(Tracing.Debug, "ProcessHandle.Stop(id={0:x8})", handle.id); // // Convert the handle to a process; call Stop method. // Process process = HandleTable.GetHandle(handle.id) as Process; process.Stop(exitcode); }
public static bool WaitOne(SyncHandle handle) { // // Convert the handle to a waitHandle; wait on the waitHandle. // WaitHandle waitHandle = HandleTable.GetHandle(handle.id) as WaitHandle; bool ret = waitHandle.WaitOne(SchedulerTime.MaxValue); Tracing.Log(Tracing.Debug, "SyncHandle.WaitOne(id={0:x8})", handle.id); return(ret); }
public static int GetExitCode(ProcessHandle handle) { Tracing.Log(Tracing.Debug, "ProcessHandle.GetExitCode(id={0:x8})", handle.id); // // Convert the handle to a process; retrieve ExitCode. // Process process = HandleTable.GetHandle(handle.id) as Process; return(process.ExitCode); }
public AmqpSession(AmqpConnection connection, AmqpSessionSettings settings, ILinkFactory linkFactory) { Fx.Assert(connection != null, "connection must not be null"); Fx.Assert(settings != null, "settings must not be null"); this.connection = connection; this.settings = settings; this.linkFactory = linkFactory; this.State = AmqpObjectState.Start; this.links = new Dictionary<string, AmqpLink>(); this.linksByLocalHandle = new HandleTable<AmqpLink>(uint.MaxValue); this.linksByRemoteHandle = new HandleTable<AmqpLink>(uint.MaxValue); this.outgoingChannel = new OutgoingSessionChannel(this); this.incomingChannel = new IncomingSessionChannel(this); this.diagnostics = new Diagnostics(); }
protected AmqpSession(string type, AmqpConnection connection, AmqpSessionSettings settings, ILinkFactory linkFactory) : base(type) { Fx.Assert(connection != null, "connection must not be null"); Fx.Assert(settings != null, "settings must not be null"); this.connection = connection; this.settings = settings; this.linkFactory = linkFactory; this.State = AmqpObjectState.Start; this.links = new Dictionary<string, AmqpLink>(); this.linksByLocalHandle = new HandleTable<AmqpLink>(settings.HandleMax ?? AmqpConstants.DefaultMaxLinkHandles - 1); this.linksByRemoteHandle = new HandleTable<AmqpLink>(settings.HandleMax ?? AmqpConstants.DefaultMaxLinkHandles - 1); this.outgoingChannel = new OutgoingSessionChannel(this); this.incomingChannel = new IncomingSessionChannel(this); }
public AmqpConnection(TransportBase transport, ProtocolHeader protocolHeader, bool isInitiator, AmqpSettings amqpSettings, AmqpConnectionSettings connectionSettings) : base((isInitiator ? "out" : "in") + "-connection", transport, connectionSettings, isInitiator) { if (amqpSettings == null) { throw new ArgumentNullException("amqpSettings"); } this.initialHeader = protocolHeader; this.isInitiator = isInitiator; this.amqpSettings = amqpSettings; this.sessionsByLocalHandle = new HandleTable<AmqpSession>(this.Settings.ChannelMax ?? AmqpConstants.DefaultMaxConcurrentChannels - 1); this.sessionsByRemoteHandle = new HandleTable<AmqpSession>(this.Settings.ChannelMax ?? AmqpConstants.DefaultMaxConcurrentChannels - 1); this.SessionFactory = this; this.heartBeat = HeartBeat.None; }
public AmqpConnection(TransportBase transport, ProtocolHeader protocolHeader, bool isInitiator, AmqpSettings amqpSettings, AmqpConnectionSettings connectionSettings) : base(transport, connectionSettings) { if (amqpSettings == null) { throw new ArgumentNullException("amqpSettings"); } this.initialHeader = protocolHeader; this.isInitiator = isInitiator; this.amqpSettings = amqpSettings; this.frameDecoder = new FrameDecoder((int)this.Settings.MaxFrameSize); this.sessionsByLocalHandle = new HandleTable<AmqpSession>(this.Settings.ChannelMax.Value); this.sessionsByRemoteHandle = new HandleTable<AmqpSession>(this.Settings.ChannelMax.Value); this.SessionFactory = this; }
// private boolean enableResolve; //private SerialCallbackContext curContext; public ObjectInputStream(InputStream @in) { //verifySubclass(); bin = new BlockDataInputStream(@in); handles = new HandleTable(10); //vlist = new ValidationList(); enableOverride = false; readStreamHeader(); bin.setBlockDataMode(true); }
protected ObjectInputStream() { //SecurityManager sm = System.getSecurityManager(); //if (sm != null) { // sm.checkPermission(SUBCLASS_IMPLEMENTATION_PERMISSION); //} bin = null; handles = null; //vlist = null; enableOverride = true; }
public ObjectOutputStream(OutputStream @out) { //verifySubclass(); bout = new BlockDataOutputStream(@out); handles = new HandleTable(10, (float) 3.00); subs = new ReplaceTable(10, (float) 3.00); enableOverride = false; writeStreamHeader(); bout.setBlockDataMode(true); //if (extendedDebugInfo) { // debugInfoStack = new DebugTraceInfoStack(); //} else { // debugInfoStack = null; //} }
internal ReplaceTable(int initialCapacity, float loadFactor) { htab = new HandleTable(initialCapacity, loadFactor); reps = new Object[initialCapacity]; }
protected ObjectOutputStream() { //SecurityManager sm = System.getSecurityManager(); //if (sm != null) { // sm.checkPermission(SUBCLASS_IMPLEMENTATION_PERMISSION); //} bout = null; handles = null; subs = null; enableOverride = true; //debugInfoStack = null; }