Signed-off-by: Zebediah Figura z.figura12@gmail.com --- dlls/ntoskrnl.exe/ntoskrnl.c | 21 --------------------- dlls/ntoskrnl.exe/sync.c | 25 +++++++++++++++++++++++++ 2 files changed, 25 insertions(+), 21 deletions(-)
diff --git a/dlls/ntoskrnl.exe/ntoskrnl.c b/dlls/ntoskrnl.exe/ntoskrnl.c index 712681e0f9..be63740cf1 100644 --- a/dlls/ntoskrnl.exe/ntoskrnl.c +++ b/dlls/ntoskrnl.exe/ntoskrnl.c @@ -2285,27 +2285,6 @@ void WINAPI KeInitializeSpinLock( PKSPIN_LOCK SpinLock ) FIXME( "stub: %p\n", SpinLock ); }
- -/*********************************************************************** - * KeInitializeTimerEx (NTOSKRNL.EXE.@) - */ -void WINAPI KeInitializeTimerEx( PKTIMER Timer, TIMER_TYPE Type ) -{ - FIXME( "stub: %p %d\n", Timer, Type ); - - RtlZeroMemory(Timer, sizeof(KTIMER)); - Timer->Header.Type = Type ? 9 : 8; -} - - -/*********************************************************************** - * KeInitializeTimer (NTOSKRNL.EXE.@) - */ -void WINAPI KeInitializeTimer( PKTIMER Timer ) -{ - KeInitializeTimerEx(Timer, NotificationTimer); -} - /*********************************************************************** * KeInsertQueue (NTOSKRNL.EXE.@) */ diff --git a/dlls/ntoskrnl.exe/sync.c b/dlls/ntoskrnl.exe/sync.c index e63c7935bb..910572b0ee 100644 --- a/dlls/ntoskrnl.exe/sync.c +++ b/dlls/ntoskrnl.exe/sync.c @@ -38,6 +38,8 @@ enum object_type TYPE_AUTO_EVENT = 1, TYPE_MUTEX = 2, TYPE_SEMAPHORE = 5, + TYPE_MANUAL_TIMER = 8, + TYPE_AUTO_TIMER = 9, };
static CRITICAL_SECTION sync_cs; @@ -292,3 +294,26 @@ LONG WINAPI KeReleaseMutex( PRKMUTEX mutex, BOOLEAN wait )
return ret; } + +/*********************************************************************** + * KeInitializeTimerEx (NTOSKRNL.EXE.@) + */ +void WINAPI KeInitializeTimerEx( KTIMER *timer, TIMER_TYPE type ) +{ + TRACE("timer %p, type %u.\n", timer, type); + + RtlZeroMemory(timer, sizeof(KTIMER)); + timer->Header.Type = (type == NotificationTimer) ? TYPE_MANUAL_TIMER : TYPE_AUTO_TIMER; + timer->Header.SignalState = FALSE; + timer->Header.Inserted = FALSE; + timer->Header.WaitListHead.Blink = NULL; + timer->Header.WaitListHead.Flink = NULL; +} + +/*********************************************************************** + * KeInitializeTimer (NTOSKRNL.EXE.@) + */ +void WINAPI KeInitializeTimer( KTIMER *timer ) +{ + KeInitializeTimerEx(timer, NotificationTimer); +}
Signed-off-by: Zebediah Figura z.figura12@gmail.com --- include/ddk/wdm.h | 1 + 1 file changed, 1 insertion(+)
diff --git a/include/ddk/wdm.h b/include/ddk/wdm.h index f70b745bc8..2b773b2780 100644 --- a/include/ddk/wdm.h +++ b/include/ddk/wdm.h @@ -1425,6 +1425,7 @@ void WINAPI KeInitializeEvent(PRKEVENT,EVENT_TYPE,BOOLEAN); void WINAPI KeInitializeMutex(PRKMUTEX,ULONG); void WINAPI KeInitializeSemaphore(PRKSEMAPHORE,LONG,LONG); void WINAPI KeInitializeTimerEx(PKTIMER,TIMER_TYPE); +void WINAPI KeInitializeTimer(KTIMER*); void WINAPI KeQuerySystemTime(LARGE_INTEGER*); void WINAPI KeQueryTickCount(LARGE_INTEGER*); ULONG WINAPI KeQueryTimeIncrement(void);
Signed-off-by: Zebediah Figura z.figura12@gmail.com --- dlls/ntoskrnl.exe/ntoskrnl.c | 9 --------- dlls/ntoskrnl.exe/sync.c | 31 +++++++++++++++++++++++++++++++ include/ddk/wdm.h | 1 + 3 files changed, 32 insertions(+), 9 deletions(-)
diff --git a/dlls/ntoskrnl.exe/ntoskrnl.c b/dlls/ntoskrnl.exe/ntoskrnl.c index be63740cf1..c7b1f43cdf 100644 --- a/dlls/ntoskrnl.exe/ntoskrnl.c +++ b/dlls/ntoskrnl.exe/ntoskrnl.c @@ -3824,15 +3824,6 @@ void WINAPI IoInvalidateDeviceRelations( DEVICE_OBJECT *device_object, DEVICE_RE } }
-/*********************************************************************** - * KeSetTimerEx (NTOSKRNL.EXE.@) - */ -BOOL WINAPI KeSetTimerEx( KTIMER *timer, LARGE_INTEGER duetime, LONG period, KDPC *dpc ) -{ - FIXME("stub: %p %s %u %p\n", timer, wine_dbgstr_longlong(duetime.QuadPart), period, dpc); - return TRUE; -} - /*********************************************************************** * IoCreateFile (NTOSKRNL.EXE.@) */ diff --git a/dlls/ntoskrnl.exe/sync.c b/dlls/ntoskrnl.exe/sync.c index 910572b0ee..06db1dec63 100644 --- a/dlls/ntoskrnl.exe/sync.c +++ b/dlls/ntoskrnl.exe/sync.c @@ -94,6 +94,9 @@ NTSTATUS WINAPI KeWaitForMultipleObjects(ULONG count, void *pobjs[], semaphore->Header.SignalState, semaphore->Limit, NULL ); break; } + case TYPE_MANUAL_TIMER: + case TYPE_AUTO_TIMER: + break; } }
@@ -111,6 +114,7 @@ NTSTATUS WINAPI KeWaitForMultipleObjects(ULONG count, void *pobjs[], switch (objs[i]->Type) { case TYPE_AUTO_EVENT: + case TYPE_AUTO_TIMER: objs[i]->SignalState = FALSE; break; case TYPE_MUTEX: @@ -317,3 +321,30 @@ void WINAPI KeInitializeTimer( KTIMER *timer ) { KeInitializeTimerEx(timer, NotificationTimer); } + +/*********************************************************************** + * KeSetTimerEx (NTOSKRNL.EXE.@) + */ +BOOLEAN WINAPI KeSetTimerEx( KTIMER *timer, LARGE_INTEGER duetime, LONG period, KDPC *dpc ) +{ + BOOL manual = timer->Header.Type == TYPE_MANUAL_TIMER; + BOOL ret; + + TRACE("timer %p, duetime %s, period %d, dpc %p.\n", + timer, wine_dbgstr_longlong(duetime.QuadPart), period, dpc); + + if (dpc) + { + FIXME("Unhandled DPC %p.\n", dpc); + return FALSE; + } + + EnterCriticalSection( &sync_cs ); + ret = timer->Header.Inserted; + timer->Header.Inserted = TRUE; + timer->Header.WaitListHead.Blink = CreateWaitableTimerW( NULL, manual, NULL ); + SetWaitableTimer( timer->Header.WaitListHead.Blink, &duetime, period, NULL, NULL, FALSE ); + LeaveCriticalSection( &sync_cs ); + + return ret; +} diff --git a/include/ddk/wdm.h b/include/ddk/wdm.h index 2b773b2780..8472b09d49 100644 --- a/include/ddk/wdm.h +++ b/include/ddk/wdm.h @@ -1435,6 +1435,7 @@ LONG WINAPI KeResetEvent(PRKEVENT); LONG WINAPI KeSetEvent(PRKEVENT,KPRIORITY,BOOLEAN); KPRIORITY WINAPI KeSetPriorityThread(PKTHREAD,KPRIORITY); void WINAPI KeSetSystemAffinityThread(KAFFINITY); +BOOLEAN WINAPI KeSetTimerEx(KTIMER*,LARGE_INTEGER,LONG,KDPC*); NTSTATUS WINAPI KeWaitForMultipleObjects(ULONG,void*[],WAIT_TYPE,KWAIT_REASON,KPROCESSOR_MODE,BOOLEAN,LARGE_INTEGER*,KWAIT_BLOCK*); NTSTATUS WINAPI KeWaitForSingleObject(void*,KWAIT_REASON,KPROCESSOR_MODE,BOOLEAN,LARGE_INTEGER*);
Signed-off-by: Zebediah Figura z.figura12@gmail.com --- dlls/ntoskrnl.exe/ntoskrnl.exe.spec | 2 +- dlls/ntoskrnl.exe/sync.c | 16 ++++++++++++++++ include/ddk/wdm.h | 1 + 3 files changed, 18 insertions(+), 1 deletion(-)
diff --git a/dlls/ntoskrnl.exe/ntoskrnl.exe.spec b/dlls/ntoskrnl.exe/ntoskrnl.exe.spec index f56bde130d..a30459a039 100644 --- a/dlls/ntoskrnl.exe/ntoskrnl.exe.spec +++ b/dlls/ntoskrnl.exe/ntoskrnl.exe.spec @@ -517,7 +517,7 @@ @ stub KeAttachProcess @ stub KeBugCheck @ stub KeBugCheckEx -@ stub KeCancelTimer +@ stdcall KeCancelTimer(ptr) @ stub KeCapturePersistentThreadState @ stdcall KeClearEvent(ptr) @ stub KeConnectInterrupt diff --git a/dlls/ntoskrnl.exe/sync.c b/dlls/ntoskrnl.exe/sync.c index 06db1dec63..1cd0e5253a 100644 --- a/dlls/ntoskrnl.exe/sync.c +++ b/dlls/ntoskrnl.exe/sync.c @@ -348,3 +348,19 @@ BOOLEAN WINAPI KeSetTimerEx( KTIMER *timer, LARGE_INTEGER duetime, LONG period,
return ret; } + +BOOLEAN WINAPI KeCancelTimer( KTIMER *timer ) +{ + BOOL ret; + + TRACE("timer %p.\n", timer); + + EnterCriticalSection( &sync_cs ); + ret = timer->Header.Inserted; + timer->Header.Inserted = FALSE; + CloseHandle(timer->Header.WaitListHead.Blink); + timer->Header.WaitListHead.Blink = NULL; + LeaveCriticalSection( &sync_cs ); + + return ret; +} diff --git a/include/ddk/wdm.h b/include/ddk/wdm.h index 8472b09d49..56e1d84c3e 100644 --- a/include/ddk/wdm.h +++ b/include/ddk/wdm.h @@ -1419,6 +1419,7 @@ void WINAPI IoReleaseCancelSpinLock(KIRQL); NTSTATUS WINAPI IoSetDeviceInterfaceState(UNICODE_STRING*,BOOLEAN); NTSTATUS WINAPI IoWMIRegistrationControl(PDEVICE_OBJECT,ULONG);
+BOOLEAN WINAPI KeCancelTimer(KTIMER*); void WINAPI KeClearEvent(PRKEVENT); PKTHREAD WINAPI KeGetCurrentThread(void); void WINAPI KeInitializeEvent(PRKEVENT,EVENT_TYPE,BOOLEAN);
Signed-off-by: Zebediah Figura z.figura12@gmail.com --- dlls/ntoskrnl.exe/tests/driver.c | 51 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+)
diff --git a/dlls/ntoskrnl.exe/tests/driver.c b/dlls/ntoskrnl.exe/tests/driver.c index 82948823c5..17e54cd508 100644 --- a/dlls/ntoskrnl.exe/tests/driver.c +++ b/dlls/ntoskrnl.exe/tests/driver.c @@ -260,6 +260,8 @@ static void test_sync(void) { KSEMAPHORE semaphore, semaphore2; KEVENT manual_event, auto_event; + KTIMER timer; + LARGE_INTEGER timeout; void *objs[2]; NTSTATUS ret; int i; @@ -444,6 +446,55 @@ static void test_sync(void) ok(ret == 0, "got %#x\n", ret);
run_thread(mutex_thread, (void *)0); + + /* test timers */ + KeInitializeTimerEx(&timer, NotificationTimer); + + timeout.QuadPart = -100; + KeSetTimerEx(&timer, timeout, 0, NULL); + + ret = wait_single(&timer, 0); + ok(ret == WAIT_TIMEOUT, "got %#x\n", ret); + + ret = wait_single(&timer, -200); + ok(ret == 0, "got %#x\n", ret); + + ret = wait_single(&timer, 0); + ok(ret == 0, "got %#x\n", ret); + + KeCancelTimer(&timer); + KeInitializeTimerEx(&timer, SynchronizationTimer); + + KeSetTimerEx(&timer, timeout, 0, NULL); + + ret = wait_single(&timer, 0); + ok(ret == WAIT_TIMEOUT, "got %#x\n", ret); + + ret = wait_single(&timer, -200); + ok(ret == 0, "got %#x\n", ret); + + ret = wait_single(&timer, 0); + ok(ret == WAIT_TIMEOUT, "got %#x\n", ret); + + KeCancelTimer(&timer); + KeSetTimerEx(&timer, timeout, 10, NULL); + + ret = wait_single(&timer, 0); + ok(ret == WAIT_TIMEOUT, "got %#x\n", ret); + + ret = wait_single(&timer, -200); + ok(ret == 0, "got %#x\n", ret); + + ret = wait_single(&timer, 0); + ok(ret == WAIT_TIMEOUT, "got %#x\n", ret); + + ret = wait_single(&timer, -20 * 10000); + ok(ret == 0, "got %#x\n", ret); + + ret = wait_single(&timer, -20 * 10000); + ok(ret == 0, "got %#x\n", ret); + + KeCancelTimer(&timer); }
static NTSTATUS main_test(IRP *irp, IO_STACK_LOCATION *stack, ULONG_PTR *info)
Signed-off-by: Zebediah Figura z.figura12@gmail.com --- dlls/ntoskrnl.exe/ntoskrnl.c | 9 --------- dlls/ntoskrnl.exe/sync.c | 9 +++++++++ include/ddk/wdm.h | 1 + 3 files changed, 10 insertions(+), 9 deletions(-)
diff --git a/dlls/ntoskrnl.exe/ntoskrnl.c b/dlls/ntoskrnl.exe/ntoskrnl.c index c7b1f43cdf..81731ce355 100644 --- a/dlls/ntoskrnl.exe/ntoskrnl.c +++ b/dlls/ntoskrnl.exe/ntoskrnl.c @@ -3197,15 +3197,6 @@ NTSTATUS WINAPI CmUnRegisterCallback(LARGE_INTEGER cookie) return STATUS_NOT_IMPLEMENTED; }
-/*********************************************************************** - * KeDelayExecutionThread (NTOSKRNL.EXE.@) - */ -NTSTATUS WINAPI KeDelayExecutionThread(KPROCESSOR_MODE waitmode, BOOLEAN alertable, PLARGE_INTEGER interval) -{ - FIXME("(%u, %u, %p): stub\n", waitmode, alertable, interval); - return STATUS_NOT_IMPLEMENTED; -} - /*********************************************************************** * IoAttachDevice (NTOSKRNL.EXE.@) */ diff --git a/dlls/ntoskrnl.exe/sync.c b/dlls/ntoskrnl.exe/sync.c index 1cd0e5253a..da51ca0237 100644 --- a/dlls/ntoskrnl.exe/sync.c +++ b/dlls/ntoskrnl.exe/sync.c @@ -364,3 +364,12 @@ BOOLEAN WINAPI KeCancelTimer( KTIMER *timer )
return ret; } + +/*********************************************************************** + * KeDelayExecutionThread (NTOSKRNL.EXE.@) + */ +NTSTATUS WINAPI KeDelayExecutionThread( KPROCESSOR_MODE mode, BOOLEAN alertable, LARGE_INTEGER *timeout ) +{ + TRACE("mode %d, alertable %u, timeout %p.\n", mode, alertable, timeout); + return NtDelayExecution( alertable, timeout ); +} diff --git a/include/ddk/wdm.h b/include/ddk/wdm.h index 56e1d84c3e..077fec1319 100644 --- a/include/ddk/wdm.h +++ b/include/ddk/wdm.h @@ -1421,6 +1421,7 @@ NTSTATUS WINAPI IoWMIRegistrationControl(PDEVICE_OBJECT,ULONG);
BOOLEAN WINAPI KeCancelTimer(KTIMER*); void WINAPI KeClearEvent(PRKEVENT); +NTSTATUS WINAPI KeDelayExecutionThread(KPROCESSOR_MODE,BOOLEAN,LARGE_INTEGER*); PKTHREAD WINAPI KeGetCurrentThread(void); void WINAPI KeInitializeEvent(PRKEVENT,EVENT_TYPE,BOOLEAN); void WINAPI KeInitializeMutex(PRKMUTEX,ULONG);