time-r0drv-nt.cpp revision 1319c68f8bf1c1195c93ecf9acccf19354d91ba8
1319c68f8bf1c1195c93ecf9acccf19354d91ba8vboxsync/* $Id$ */
1319c68f8bf1c1195c93ecf9acccf19354d91ba8vboxsync/** @file
1319c68f8bf1c1195c93ecf9acccf19354d91ba8vboxsync * innotek Portable Runtime - Time, Ring-0 Driver, Nt.
1319c68f8bf1c1195c93ecf9acccf19354d91ba8vboxsync */
1319c68f8bf1c1195c93ecf9acccf19354d91ba8vboxsync
1319c68f8bf1c1195c93ecf9acccf19354d91ba8vboxsync/*
1319c68f8bf1c1195c93ecf9acccf19354d91ba8vboxsync * Copyright (C) 2007 innotek GmbH
1319c68f8bf1c1195c93ecf9acccf19354d91ba8vboxsync *
1319c68f8bf1c1195c93ecf9acccf19354d91ba8vboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
1319c68f8bf1c1195c93ecf9acccf19354d91ba8vboxsync * available from http://www.virtualbox.org. This file is free software;
1319c68f8bf1c1195c93ecf9acccf19354d91ba8vboxsync * you can redistribute it and/or modify it under the terms of the GNU
1319c68f8bf1c1195c93ecf9acccf19354d91ba8vboxsync * General Public License as published by the Free Software Foundation,
1319c68f8bf1c1195c93ecf9acccf19354d91ba8vboxsync * in version 2 as it comes in the "COPYING" file of the VirtualBox OSE
1319c68f8bf1c1195c93ecf9acccf19354d91ba8vboxsync * distribution. VirtualBox OSE is distributed in the hope that it will
1319c68f8bf1c1195c93ecf9acccf19354d91ba8vboxsync * be useful, but WITHOUT ANY WARRANTY of any kind.
1319c68f8bf1c1195c93ecf9acccf19354d91ba8vboxsync */
1319c68f8bf1c1195c93ecf9acccf19354d91ba8vboxsync
1319c68f8bf1c1195c93ecf9acccf19354d91ba8vboxsync
1319c68f8bf1c1195c93ecf9acccf19354d91ba8vboxsync/*******************************************************************************
1319c68f8bf1c1195c93ecf9acccf19354d91ba8vboxsync* Header Files *
1319c68f8bf1c1195c93ecf9acccf19354d91ba8vboxsync*******************************************************************************/
1319c68f8bf1c1195c93ecf9acccf19354d91ba8vboxsync#define LOG_GROUP RTLOGGROUP_TIME
1319c68f8bf1c1195c93ecf9acccf19354d91ba8vboxsync#include "the-nt-kernel.h"
1319c68f8bf1c1195c93ecf9acccf19354d91ba8vboxsync#include <iprt/time.h>
1319c68f8bf1c1195c93ecf9acccf19354d91ba8vboxsync
1319c68f8bf1c1195c93ecf9acccf19354d91ba8vboxsync
1319c68f8bf1c1195c93ecf9acccf19354d91ba8vboxsyncDECLINLINE(uint64_t) rtTimeGetSystemNanoTS(void)
1319c68f8bf1c1195c93ecf9acccf19354d91ba8vboxsync{
1319c68f8bf1c1195c93ecf9acccf19354d91ba8vboxsync#if 1
1319c68f8bf1c1195c93ecf9acccf19354d91ba8vboxsync ULONGLONG InterruptTime = KeQueryInterruptTime();
1319c68f8bf1c1195c93ecf9acccf19354d91ba8vboxsync return (uint64_t)InterruptTime * 100;
1319c68f8bf1c1195c93ecf9acccf19354d91ba8vboxsync#else
1319c68f8bf1c1195c93ecf9acccf19354d91ba8vboxsync LARGE_INTEGER InterruptTime;
1319c68f8bf1c1195c93ecf9acccf19354d91ba8vboxsync do
1319c68f8bf1c1195c93ecf9acccf19354d91ba8vboxsync {
1319c68f8bf1c1195c93ecf9acccf19354d91ba8vboxsync InterruptTime.HighPart = ((KUSER_SHARED_DATA volatile *)SharedUserData)->InterruptTime.High1Time;
1319c68f8bf1c1195c93ecf9acccf19354d91ba8vboxsync InterruptTime.LowPart = ((KUSER_SHARED_DATA volatile *)SharedUserData)->InterruptTime.LowPart;
1319c68f8bf1c1195c93ecf9acccf19354d91ba8vboxsync } while (((KUSER_SHARED_DATA volatile *)SharedUserData)->InterruptTime.High2Time != InterruptTime.HighPart);
1319c68f8bf1c1195c93ecf9acccf19354d91ba8vboxsync
1319c68f8bf1c1195c93ecf9acccf19354d91ba8vboxsync return (uint64_t)InterruptTime.QuadPart * 100;
1319c68f8bf1c1195c93ecf9acccf19354d91ba8vboxsync#endif
1319c68f8bf1c1195c93ecf9acccf19354d91ba8vboxsync}
1319c68f8bf1c1195c93ecf9acccf19354d91ba8vboxsync
1319c68f8bf1c1195c93ecf9acccf19354d91ba8vboxsync
1319c68f8bf1c1195c93ecf9acccf19354d91ba8vboxsyncRTDECL(uint64_t) RTTimeNanoTS(void)
1319c68f8bf1c1195c93ecf9acccf19354d91ba8vboxsync{
1319c68f8bf1c1195c93ecf9acccf19354d91ba8vboxsync return rtTimeGetSystemNanoTS();
1319c68f8bf1c1195c93ecf9acccf19354d91ba8vboxsync}
1319c68f8bf1c1195c93ecf9acccf19354d91ba8vboxsync
1319c68f8bf1c1195c93ecf9acccf19354d91ba8vboxsync
1319c68f8bf1c1195c93ecf9acccf19354d91ba8vboxsyncRTDECL(uint64_t) RTTimeMilliTS(void)
1319c68f8bf1c1195c93ecf9acccf19354d91ba8vboxsync{
1319c68f8bf1c1195c93ecf9acccf19354d91ba8vboxsync return rtTimeGetSystemNanoTS() / 1000000;
1319c68f8bf1c1195c93ecf9acccf19354d91ba8vboxsync}
1319c68f8bf1c1195c93ecf9acccf19354d91ba8vboxsync
1319c68f8bf1c1195c93ecf9acccf19354d91ba8vboxsync
1319c68f8bf1c1195c93ecf9acccf19354d91ba8vboxsyncRTDECL(uint64_t) RTTimeSystemNanoTS(void)
1319c68f8bf1c1195c93ecf9acccf19354d91ba8vboxsync{
1319c68f8bf1c1195c93ecf9acccf19354d91ba8vboxsync return rtTimeGetSystemNanoTS();
1319c68f8bf1c1195c93ecf9acccf19354d91ba8vboxsync}
1319c68f8bf1c1195c93ecf9acccf19354d91ba8vboxsync
1319c68f8bf1c1195c93ecf9acccf19354d91ba8vboxsync
1319c68f8bf1c1195c93ecf9acccf19354d91ba8vboxsyncRTDECL(uint64_t) RTTimeSystemMilliTS(void)
1319c68f8bf1c1195c93ecf9acccf19354d91ba8vboxsync{
1319c68f8bf1c1195c93ecf9acccf19354d91ba8vboxsync return rtTimeGetSystemNanoTS() / 1000000;
1319c68f8bf1c1195c93ecf9acccf19354d91ba8vboxsync}
1319c68f8bf1c1195c93ecf9acccf19354d91ba8vboxsync
1319c68f8bf1c1195c93ecf9acccf19354d91ba8vboxsync
1319c68f8bf1c1195c93ecf9acccf19354d91ba8vboxsyncRTDECL(PRTTIMESPEC) RTTimeNow(PRTTIMESPEC pTime)
1319c68f8bf1c1195c93ecf9acccf19354d91ba8vboxsync{
1319c68f8bf1c1195c93ecf9acccf19354d91ba8vboxsync LARGE_INTEGER SystemTime;
1319c68f8bf1c1195c93ecf9acccf19354d91ba8vboxsync#if 1
1319c68f8bf1c1195c93ecf9acccf19354d91ba8vboxsync KeQuerySystemTime(&SystemTime);
1319c68f8bf1c1195c93ecf9acccf19354d91ba8vboxsync#else
1319c68f8bf1c1195c93ecf9acccf19354d91ba8vboxsync do
1319c68f8bf1c1195c93ecf9acccf19354d91ba8vboxsync {
1319c68f8bf1c1195c93ecf9acccf19354d91ba8vboxsync SystemTime.HighPart = ((KUSER_SHARED_DATA volatile *)SharedUserData)->SystemTime.High1Time;
1319c68f8bf1c1195c93ecf9acccf19354d91ba8vboxsync SystemTime.LowPart = ((KUSER_SHARED_DATA volatile *)SharedUserData)->SystemTime.LowPart;
1319c68f8bf1c1195c93ecf9acccf19354d91ba8vboxsync } while (((KUSER_SHARED_DATA volatile *)SharedUserData)->SystemTime.High2Time != SystemTime.HighPart);
1319c68f8bf1c1195c93ecf9acccf19354d91ba8vboxsync#endif
1319c68f8bf1c1195c93ecf9acccf19354d91ba8vboxsync return RTTimeSpecSetNtTime(pTime, SystemTime.QuadPart);
1319c68f8bf1c1195c93ecf9acccf19354d91ba8vboxsync}
1319c68f8bf1c1195c93ecf9acccf19354d91ba8vboxsync