[Wine-patches] [eterhack] ntoskrnl.exe: Make KeWaitForSingleObject yield execution to another thread if there is nothing to wait on. (eterbug #4884)
Dmitry Timoshkov
dtimoshkov на etersoft.ru
Ср Окт 3 10:36:02 MSK 2012
hardlock.sys does:
PRKEVENT global_event;
PRKTHREAD system_thread;
load_driver_entry()
{
global_event = KeInitializeEvent(SynchronizationEvent);
PsCreateSystemThread(system_thread_entry);
}
system_thread_entry()
{
system_thread = KeGetCurrentThread();
KeWaitForSingleObject(global_event);
}
unload_driver_entry()
{
KeSetEvent(global_event);
KeWaitForSingleObject(system_thread);
}
Since KeGetCurrentThread() is a stub and it returns NULL, then
KeWaitForSingleObject(system_thread) doesn't wait, and when system thread
gets control the driver PE module is already unloaded from memory => BOOM.
Instead of implementing full PRKTHREAD object synchronization support this
patch simply yields the control in the hope that the target thread wakes up
and does its job.
---
dlls/ntoskrnl.exe/ntoskrnl.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/dlls/ntoskrnl.exe/ntoskrnl.c b/dlls/ntoskrnl.exe/ntoskrnl.c
index 9daf064..09068ee 100644
--- a/dlls/ntoskrnl.exe/ntoskrnl.c
+++ b/dlls/ntoskrnl.exe/ntoskrnl.c
@@ -2798,7 +2798,11 @@ NTSTATUS WINAPI KeWaitForSingleObject(PVOID Object,
TRACE( "%p, %d, %d, %d, %p\n", Object, WaitReason, WaitMode, Alertable, Timeout );
- if (!Object) return STATUS_INVALID_PARAMETER;
+ if (!Object)
+ {
+ ZwYieldExecution();
+ return STATUS_SUCCESS;
+ }
switch (header->Type)
{
--
1.7.12.1
Подробная информация о списке рассылки Wine-patches