- Oleg Baikalow: Finish CTE timers. CTE implementation is complete now.

svn path=/trunk/; revision=50552
This commit is contained in:
Aleksey Bragin 2011-01-29 14:03:41 +00:00
parent 10c56cc21a
commit a5dcd02b08
2 changed files with 92 additions and 37 deletions

View file

@ -10,57 +10,109 @@
#include <ntddk.h>
/* FIXME: Move to a common header! */
struct _CTE_DELAYED_EVENT;
typedef void (*CTE_WORKER_ROUTINE)(struct _CTE_DELAYED_EVENT *, void *Context);
typedef struct _CTE_TIMER
{
BOOLEAN Queued;
KSPIN_LOCK Lock;
CTE_WORKER_ROUTINE Callback;
PVOID Context;
KDPC Dpc;
KTIMER Timer;
} CTE_TIMER, *PCTE_TIMER;
LONG CteTimeIncrement;
/* FUNCTIONS *****************************************************************/
VOID
NTAPI
InternalDpcRoutine(PKDPC Dpc,
PVOID Context,
PVOID SystemArgument1,
PVOID SystemArgument2)
{
PCTE_TIMER Timer = (PCTE_TIMER)Context;
/* Call our registered callback */
Timer->Callback((struct _CTE_DELAYED_EVENT *)Timer, Timer->Context);
}
/*
* @unimplemented
* @implemented
*/
VOID
NTAPI
CTEInitTimer (
ULONG Unknown0
)
CTEInitTimer(PCTE_TIMER Timer)
{
/* Zero all fields */
RtlZeroMemory(Timer, sizeof(CTE_TIMER));
/* Create a DPC and a timer */
KeInitializeDpc(&Timer->Dpc, InternalDpcRoutine, Timer);
KeInitializeTimer(&Timer->Timer);
}
/*
* @unimplemented
* @implemented
*/
BOOLEAN
NTAPI
CTEInitialize (
VOID
)
CTEStartTimer(PCTE_TIMER Timer,
ULONG DueTimeShort,
CTE_WORKER_ROUTINE Callback,
PVOID Context)
{
/* FIXME: what should it initialize? */
LARGE_INTEGER DueTime;
/* Make sure a callback was provided */
ASSERT(Callback);
/* We need to convert due time, because DueTimeShort is in ms,
but NT timer expects 100s of ns, negative one */
DueTime.QuadPart = -Int32x32To64(DueTimeShort, 10000);
/* Set other timer members */
Timer->Callback = Callback;
Timer->Context = Context;
/* Set the timer */
KeSetTimer(&Timer->Timer, DueTime, &Timer->Dpc);
return TRUE;
}
/*
* @unimplemented
*/
BOOLEAN
NTAPI
CTEStartTimer (
ULONG Unknown0,
ULONG Unknown1,
ULONG Unknown2,
ULONG Unknown3
)
{
return FALSE;
}
/*
* @unimplemented
* @implemented
*/
ULONG
NTAPI
CTESystemUpTime (
VOID
)
CTESystemUpTime(VOID)
{
return 0;
LARGE_INTEGER Ticks;
/* Get the tick count */
KeQueryTickCount(&Ticks);
/* Convert to 100s of ns and then to ms*/
Ticks.QuadPart = (Ticks.QuadPart * CteTimeIncrement) / 10000ULL;
return Ticks.LowPart;
}
/*
* @implemented
*/
BOOLEAN
NTAPI
CTEInitialize(VOID)
{
/* Just return success */
return TRUE;
}
/* EOF */

View file

@ -1,17 +1,20 @@
/* $Id$
*
/*
* DESCRIPTION: Entry point for TDI.SYS
* (c) Captain Obvious
*/
#include <ntddk.h>
extern LONG CteTimeIncrement;
NTSTATUS
NTAPI
DriverEntry (
IN PDRIVER_OBJECT DriverObject,
IN PUNICODE_STRING RegistryPath
)
DriverEntry(IN PDRIVER_OBJECT DriverObject,
IN PUNICODE_STRING RegistryPath)
{
return STATUS_UNSUCCESSFUL;
/* Initialize the time increment for CTE timers */
CteTimeIncrement = KeQueryTimeIncrement();
return STATUS_SUCCESS;
}