Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches

◆ GetProcessInfos() [2/2]

static unsafe ProcessInfo[] System.Diagnostics.NtProcessInfoHelper.GetProcessInfos ( ReadOnlySpan< byte > data,
int? processIdFilter )
inlinestaticprivate

Definition at line 58 of file NtProcessInfoHelper.cs.

59 {
61 int num = 0;
62 while (true)
63 {
64 ref readonly global::Interop.NtDll.SYSTEM_PROCESS_INFORMATION reference = ref MemoryMarshal.AsRef<global::Interop.NtDll.SYSTEM_PROCESS_INFORMATION>(data.Slice(num));
65 int num2 = reference.UniqueProcessId.ToInt32();
66 if (!processIdFilter.HasValue || processIdFilter.GetValueOrDefault() == num2)
67 {
68 ProcessInfo processInfo = new ProcessInfo((int)reference.NumberOfThreads)
69 {
71 SessionId = (int)reference.SessionId,
72 PoolPagedBytes = (long)(ulong)reference.QuotaPagedPoolUsage,
73 PoolNonPagedBytes = (long)(ulong)reference.QuotaNonPagedPoolUsage,
74 VirtualBytes = (long)(ulong)reference.VirtualSize,
75 VirtualBytesPeak = (long)(ulong)reference.PeakVirtualSize,
76 WorkingSetPeak = (long)(ulong)reference.PeakWorkingSetSize,
77 WorkingSet = (long)(ulong)reference.WorkingSetSize,
78 PageFileBytesPeak = (long)(ulong)reference.PeakPagefileUsage,
79 PageFileBytes = (long)(ulong)reference.PagefileUsage,
80 PrivateBytes = (long)(ulong)reference.PrivatePageCount,
81 BasePriority = reference.BasePriority,
82 HandleCount = (int)reference.HandleCount
83 };
84 if (reference.ImageName.Buffer == IntPtr.Zero)
85 {
86 if (processInfo.ProcessId == NtProcessManager.SystemProcessID)
87 {
88 processInfo.ProcessName = "System";
89 }
90 else if (processInfo.ProcessId == 0)
91 {
92 processInfo.ProcessName = "Idle";
93 }
94 else
95 {
96 processInfo.ProcessName = processInfo.ProcessId.ToString(CultureInfo.InvariantCulture);
97 }
98 }
99 else
100 {
101 string processShortName = GetProcessShortName(new ReadOnlySpan<char>(reference.ImageName.Buffer.ToPointer(), reference.ImageName.Length / 2));
102 processInfo.ProcessName = processShortName;
103 }
105 int num3 = num + sizeof(global::Interop.NtDll.SYSTEM_PROCESS_INFORMATION);
106 for (int i = 0; i < reference.NumberOfThreads; i++)
107 {
108 ref readonly global::Interop.NtDll.SYSTEM_THREAD_INFORMATION reference2 = ref MemoryMarshal.AsRef<global::Interop.NtDll.SYSTEM_THREAD_INFORMATION>(data.Slice(num3));
109 ThreadInfo item = new ThreadInfo
110 {
111 _processId = (int)reference2.ClientId.UniqueProcess,
112 _threadId = (ulong)(long)reference2.ClientId.UniqueThread,
113 _basePriority = reference2.BasePriority,
114 _currentPriority = reference2.Priority,
115 _startAddress = reference2.StartAddress,
116 _threadState = (ThreadState)reference2.ThreadState,
117 _threadWaitReason = NtProcessManager.GetThreadWaitReason((int)reference2.WaitReason)
118 };
119 processInfo._threadInfoList.Add(item);
120 num3 += sizeof(global::Interop.NtDll.SYSTEM_THREAD_INFORMATION);
121 }
122 }
123 if (reference.NextEntryOffset == 0)
124 {
125 break;
126 }
127 num += (int)reference.NextEntryOffset;
128 }
129 ProcessInfo[] array = new ProcessInfo[dictionary.Values.Count];
130 dictionary.Values.CopyTo(array, 0);
131 return array;
132 }
void Add(TKey key, TValue value)
static string GetProcessShortName(ReadOnlySpan< char > name)
static CultureInfo InvariantCulture
ReadOnlySpan< T > Slice(int start)

References System.Collections.Generic.Dictionary< TKey, TValue >.Add(), System.array, System.dictionary, System.Diagnostics.NtProcessInfoHelper.GetProcessShortName(), System.Diagnostics.NtProcessManager.GetThreadWaitReason(), System.Globalization.CultureInfo.InvariantCulture, System.item, System.Diagnostics.ProcessId, System.Diagnostics.NtProcessManager.SystemProcessID, and System.IntPtr.Zero.