Added an option to automatically startup after Windows logon using the Task Scheduler 2.0 for Windows Vista/7 or the Registry for Windows XP.
3 Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 The contents of this file are subject to the Mozilla Public License Version
6 1.1 (the "License"); you may not use this file except in compliance with
7 the License. You may obtain a copy of the License at
9 http://www.mozilla.org/MPL/
11 Software distributed under the License is distributed on an "AS IS" basis,
12 WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13 for the specific language governing rights and limitations under the License.
15 The Original Code is the Open Hardware Monitor code.
17 The Initial Developer of the Original Code is
18 Michael Möller <m.moeller@gmx.ch>.
19 Portions created by the Initial Developer are Copyright (C) 2009-2010
20 the Initial Developer. All Rights Reserved.
24 Alternatively, the contents of this file may be used under the terms of
25 either the GNU General Public License Version 2 or later (the "GPL"), or
26 the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27 in which case the provisions of the GPL or the LGPL are applicable instead
28 of those above. If you wish to allow use of your version of this file only
29 under the terms of either the GPL or the LGPL, and not to allow others to
30 use your version of this file under the terms of the MPL, indicate your
31 decision by deleting the provisions above and replace them with the notice
32 and other provisions required by the GPL or the LGPL. If you do not delete
33 the provisions above, a recipient may use your version of this file under
34 the terms of any one of the MPL, the GPL or the LGPL.
39 using System.Collections.Generic;
41 using System.Runtime.InteropServices;
44 namespace OpenHardwareMonitor.Hardware {
46 public class WinRing0 {
48 public enum OlsDllStatus{
50 OLS_DLL_UNSUPPORTED_PLATFORM = 1,
51 OLS_DLL_DRIVER_NOT_LOADED = 2,
52 OLS_DLL_DRIVER_NOT_FOUND = 3,
53 OLS_DLL_DRIVER_UNLOADED = 4,
54 OLS_DLL_DRIVER_NOT_LOADED_ON_NETWORK = 5,
55 OLS_DLL_UNKNOWN_ERROR = 9
58 private static bool available = false;
60 private static string GetDllName() {
61 int p = (int)System.Environment.OSVersion.Platform;
62 if ((p == 4) || (p == 128)) {
63 if (IntPtr.Size == 4) {
66 return "libring0x64.so";
69 if (IntPtr.Size == 4) {
70 return "WinRing0.dll";
72 return "WinRing0x64.dll";
77 private delegate bool InitializeOlsDelegate();
78 private delegate void DeinitializeOlsDelegate();
80 public delegate uint GetDllStatusDelegate();
81 public delegate bool IsCpuidDelegate();
82 public delegate bool CpuidDelegate(uint index,
83 out uint eax, out uint ebx, out uint ecx, out uint edx);
84 public delegate bool CpuidExDelegate(uint index, uint ecxValue,
85 out uint eax, out uint ebx, out uint ecx, out uint edx);
86 public delegate bool RdmsrDelegate(uint index, out uint eax, out uint edx);
87 public delegate bool RdmsrTxDelegate(uint index, out uint eax, out uint edx,
88 UIntPtr threadAffinityMask);
89 public delegate byte ReadIoPortByteDelegate(ushort port);
90 public delegate void WriteIoPortByteDelegate(ushort port, byte value);
91 public delegate void SetPciMaxBusIndexDelegate(byte max);
92 public delegate uint FindPciDeviceByIdDelegate(ushort vendorId,
93 ushort deviceId, byte index);
94 public delegate bool ReadPciConfigDwordExDelegate(uint pciAddress,
95 uint regAddress, out uint value);
96 public delegate bool WritePciConfigDwordExDelegate(uint pciAddress,
97 uint regAddress, uint value);
98 public delegate bool RdtscTxDelegate(out uint eax, out uint edx,
99 UIntPtr threadAffinityMask);
100 public delegate bool RdtscDelegate(out uint eax, out uint edx);
102 private static InitializeOlsDelegate InitializeOls;
103 private static DeinitializeOlsDelegate DeinitializeOls;
105 public static GetDllStatusDelegate GetDllStatus;
106 public static IsCpuidDelegate IsCpuid;
107 public static CpuidDelegate Cpuid;
108 public static CpuidExDelegate CpuidEx;
109 public static RdmsrDelegate Rdmsr;
110 public static RdmsrTxDelegate RdmsrTx;
111 public static ReadIoPortByteDelegate ReadIoPortByte;
112 public static WriteIoPortByteDelegate WriteIoPortByte;
113 public static SetPciMaxBusIndexDelegate SetPciMaxBusIndex;
114 public static FindPciDeviceByIdDelegate FindPciDeviceById;
115 public static ReadPciConfigDwordExDelegate ReadPciConfigDwordEx;
116 public static WritePciConfigDwordExDelegate WritePciConfigDwordEx;
117 public static RdtscTxDelegate RdtscTx;
118 public static RdtscDelegate Rdtsc;
120 private static void GetDelegate<T>(string entryPoint, out T newDelegate)
123 DllImportAttribute attribute = new DllImportAttribute(GetDllName());
124 attribute.CallingConvention = CallingConvention.Winapi;
125 attribute.PreserveSig = true;
126 attribute.EntryPoint = entryPoint;
127 attribute.CharSet = CharSet.Auto;
128 PInvokeDelegateFactory.CreateDelegate(attribute, out newDelegate);
132 GetDelegate("InitializeOls", out InitializeOls);
133 GetDelegate("DeinitializeOls", out DeinitializeOls);
134 GetDelegate("GetDllStatus", out GetDllStatus);
135 GetDelegate("IsCpuid", out IsCpuid);
136 GetDelegate("Cpuid", out Cpuid);
137 GetDelegate("CpuidEx", out CpuidEx);
138 GetDelegate("Rdmsr", out Rdmsr);
139 GetDelegate("RdmsrTx", out RdmsrTx);
140 GetDelegate("ReadIoPortByte", out ReadIoPortByte);
141 GetDelegate("WriteIoPortByte", out WriteIoPortByte);
142 GetDelegate("SetPciMaxBusIndex", out SetPciMaxBusIndex);
143 GetDelegate("FindPciDeviceById", out FindPciDeviceById);
144 GetDelegate("ReadPciConfigDwordEx", out ReadPciConfigDwordEx);
145 GetDelegate("WritePciConfigDwordEx", out WritePciConfigDwordEx);
146 GetDelegate("RdtscTx", out RdtscTx);
147 GetDelegate("Rdtsc", out Rdtsc);
150 if (InitializeOls != null && InitializeOls())
152 } catch (DllNotFoundException) { }
155 public static bool IsAvailable {
156 get { return available; }
159 private static Deinitializer deinitializer = new Deinitializer();
160 private class Deinitializer {