(Windows)睡眠内核驱动程序 [英] (Windows)Sleep in kernel driver

查看:200
本文介绍了(Windows)睡眠内核驱动程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,

i开始了解驱动程序编程



i想让我的驱动程序每2000毫秒做一件事,例如



和c ++我将是这样的

Hello,
i started to learn about driver programming

i want to make my driver do a thing every 2000 ms for example

and in c++ i will be like this

while(true){
Sleep(2000);//(2 Seconds)
DoSomething();
}





问题是:

如何在c驱动程序中执行此操作

它必须是这样的



the question is :
how to do like it in c driver
it must be like this

while(1)
{
SleepFunction(2000);//Which doesnt exist
DoSomething();
}

推荐答案

原理与在用户模式下创建延迟完全相同。 Sleep()的价值非常有限,您可以使用Google找出原因。最终你需要等待计时器。



(1)通过KeInitializeTimer创建一个内核计时器。



http://msdn.microsoft.com/en-us/library /windows/hardware/ff552168(v=vs.85).aspx



(2)使用KeSetTimerEx设置计时器并使用2秒的周期例如。



http://msdn.microsoft.com/en-us/library/windows/hardware/ff553292(v = vs.85).aspx



(3)在驱动程序中创建一个线程。在线程中,调用KeWaitForSingleObject来等待计时器。



http://msdn.microsoft.com/en-us/library/windows/hardware/ff553350(v=vs.85).aspx

参见:





http://www-user.tu-chemnitz.de/~heha/oney_wdm/ch04e.htm



http://www.techtalkz.com/microsoft-device-drivers /245779-kesettimer-expiration.html





之后请参考Google。
The principle is exactly the same as creating delays in user mode. Sleep() has very limited value and you can use Google to find out why. Ultimately you need waitable timers.

(1) Create a kernel timer via KeInitializeTimer.

http://msdn.microsoft.com/en-us/library/windows/hardware/ff552168(v=vs.85).aspx

(2) Set the timer with KeSetTimerEx and use a period of 2s for example.

http://msdn.microsoft.com/en-us/library/windows/hardware/ff553292(v=vs.85).aspx

(3) Create a thread in your driver. In the thread, call KeWaitForSingleObject to wait on the timer.

http://msdn.microsoft.com/en-us/library/windows/hardware/ff553350(v=vs.85).aspx
See also:


http://www-user.tu-chemnitz.de/~heha/oney_wdm/ch04e.htm

http://www.techtalkz.com/microsoft-device-drivers/245779-kesettimer-expiration.html


After that refer to Google.


你也可以使用KeDelayExcutionThread



此功能的第三个参数是100纳秒(0.01微秒)


http ://msdn.microsoft.com/en-us/library/windows/hardware/ff551986%28v=vs.85%29.aspx [ ^ ]
Also you can use KeDelayExcutionThread

Third parameter of this function is in 100 nano seconds(0.01 micro seconds)

http://msdn.microsoft.com/en-us/library/windows/hardware/ff551986%28v=vs.85%29.aspx[^]


这篇关于(Windows)睡眠内核驱动程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆