Exemple #1
0
        public static void Close()
        {
            if (driver != null)
            {
                uint refCount = 0;
                driver.DeviceIOControl(IOCTL_OLS_GET_REFCOUNT, null, ref refCount);
                driver.Close();

                if (refCount <= 1)
                {
                    driver.Delete();
                }
                driver = null;
            }

            if (isaBusMutex != null)
            {
                isaBusMutex.Close();
                isaBusMutex = null;
            }

            // try to delete temporary driver file again if failed during open
            if (fileName != null && File.Exists(fileName))
            {
                try {
                    File.Delete(fileName);
                    fileName = null;
                } catch (IOException) { }
                catch (UnauthorizedAccessException) { }
            }
        }
Exemple #2
0
        private static bool rdmsrWindows(uint index, out ulong value, ulong threadAffinityMask = 0)
        {
            value = 0;
            if (driver == null)
            {
                return(false);
            }

            // Force current thread to run on the requested CPU core
            // This probably works because the kernel processes short running requests on
            // the CPU thread where they originated from to improve efficiency. While this
            // is probably a likely hack, changing this behavior would require significant
            // changes to the kernel driver.
            ulong mask = 0xFFFFFFFFFFFFFFFF;

            if (threadAffinityMask != 0)
            {
                mask = ThreadAffinity.Set(threadAffinityMask);
            }

            try {
                // Communicate with WinRing0 driver
                return(driver.DeviceIOControl(IOCTL_OLS_READ_MSR, index, ref value));
            } finally {
                if (threadAffinityMask != 0)
                {
                    ThreadAffinity.Set(mask);
                }
            }
        }
        public static void Close()
        {
            if (driver == null)
            {
                return;
            }

            uint refCount = 0;

            driver.DeviceIOControl(IOCTL_OLS_GET_REFCOUNT, null, ref refCount);

            driver.Close();

            if (refCount <= 1)
            {
                driver.Delete();
            }

            driver = null;

            isaBusMutex.Close();
        }