Changeset 124 for trunk/MacFaceLibrary/NtKernel.cs
- Timestamp:
- May 26, 2009, 3:31:47 AM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/MacFaceLibrary/NtKernel.cs
-
Property
svn:keywords
set to
Id
r121 r124 1 using System; 1 // $Id$ 2 using System; 2 3 using System.Runtime.InteropServices; 3 4 4 class NtKernel {5 public class NtKernel { 5 6 6 unsafepublic static SYSTEM_BASIC_INFORMATION QuerySystemBasicInformation()7 public static SYSTEM_BASIC_INFORMATION QuerySystemBasicInformation() 7 8 { 8 SYSTEM_BASIC_INFORMATION info = new SYSTEM_BASIC_INFORMATION();9 UInt32 len = (UInt32)Marshal.SizeOf(typeof(SYSTEM_BASIC_INFORMATION));9 int len = Marshal.SizeOf(typeof(SYSTEM_BASIC_INFORMATION)); 10 IntPtr ptr = Marshal.AllocCoTaskMem(len); 10 11 UInt32 outLen; 11 12 12 13 NtQuerySystemInformation( 13 SYSTEM_INFORMATION_CLASS.SystemBasicInformation, &info,len, out outLen14 SYSTEM_INFORMATION_CLASS.SystemBasicInformation, ptr, (UInt32)len, out outLen 14 15 ); 15 return info; 16 17 return (SYSTEM_BASIC_INFORMATION)Marshal.PtrToStructure(ptr, typeof(SYSTEM_BASIC_INFORMATION)); 16 18 } 17 19 18 unsafepublic static SYSTEM_PERFORMANCE_INFORMATION QuerySystemPerformanceInformation()20 public static SYSTEM_PERFORMANCE_INFORMATION QuerySystemPerformanceInformation() 19 21 { 20 SYSTEM_PERFORMANCE_INFORMATION info = new SYSTEM_PERFORMANCE_INFORMATION();21 UInt32 len = (UInt32)Marshal.SizeOf(typeof(SYSTEM_PERFORMANCE_INFORMATION));22 int len = Marshal.SizeOf(typeof(SYSTEM_PERFORMANCE_INFORMATION)); 23 IntPtr ptr = Marshal.AllocCoTaskMem(len); 22 24 UInt32 outLen; 23 25 24 26 NtQuerySystemInformation( 25 SYSTEM_INFORMATION_CLASS.SystemPerformanceInformation, &info,len, out outLen27 SYSTEM_INFORMATION_CLASS.SystemPerformanceInformation, ptr, (UInt32)len, out outLen 26 28 ); 27 return info; 29 30 return (SYSTEM_PERFORMANCE_INFORMATION)Marshal.PtrToStructure(ptr, typeof(SYSTEM_PERFORMANCE_INFORMATION)); 28 31 } 29 32 30 unsafe public static SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION QuerySystemProcessorPerformanceInfomation()33 public static SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION[] QuerySystemProcessorPerformanceInfomation(int processorCount) 31 34 { 32 SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION info = new SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION();33 UInt32 len = (UInt32)(Marshal.SizeOf(typeof(SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION)));35 int len = Marshal.SizeOf(typeof(SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION)) * processorCount; 36 IntPtr ptr = Marshal.AllocCoTaskMem(len); 34 37 UInt32 outLen; 38 35 39 NtQuerySystemInformation( 36 SYSTEM_INFORMATION_CLASS.SystemProcessorPerformanceInformation, &info,len, out outLen40 SYSTEM_INFORMATION_CLASS.SystemProcessorPerformanceInformation, ptr, (UInt32)len, out outLen 37 41 ); 38 return info; 42 43 SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION[] list = new SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION[processorCount]; 44 for (int i = 0; i < processorCount; i++) { 45 IntPtr p = new IntPtr(ptr.ToInt32() + Marshal.SizeOf(typeof(SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION)) * i); 46 list[i] = (SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION)Marshal.PtrToStructure(p, typeof(SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION)); 47 } 48 49 return list; 39 50 } 40 51 41 52 [DllImport("ntdll.dll")] 42 unsafeprotected extern static UInt32 NtQuerySystemInformation(53 protected extern static UInt32 NtQuerySystemInformation( 43 54 SYSTEM_INFORMATION_CLASS SystemInformationClass, 44 void*SystemInformation,55 IntPtr SystemInformation, 45 56 UInt32 SystemInformationLength, 46 57 out UInt32 ReturnLength … … 63 74 public struct SYSTEM_BASIC_INFORMATION 64 75 { 65 public UInt 64Unknown;66 public UInt 64MaximumIncrement;67 public UInt 64PhysicalPageSize;68 public UInt 64NumberOfPhysicalPages;69 public UInt 64LowestPhysicalPage;70 public UInt 64HighestPhysicalPage;71 public UInt 64AllocationGranularity;72 public UInt 64LowestUserAddress;73 public UInt 64HighestUserAddress;74 public UInt 64ActiveProcessors;76 public UInt32 Unknown; 77 public UInt32 MaximumIncrement; 78 public UInt32 PhysicalPageSize; 79 public UInt32 NumberOfPhysicalPages; 80 public UInt32 LowestPhysicalPage; 81 public UInt32 HighestPhysicalPage; 82 public UInt32 AllocationGranularity; 83 public UInt32 LowestUserAddress; 84 public UInt32 HighestUserAddress; 85 public UInt32 ActiveProcessors; 75 86 public Byte NumberProcessors; 76 87 } -
Property
svn:keywords
set to
Note: See TracChangeset
for help on using the changeset viewer.