The timer of Windows Driver Development technology detailed

Source: Internet
Author: User

    • I/O timers

The I/O timer is a timer provided by DDK. It calls the I/o timer routine every 1s clock system. The I/O timer routines run at the dispatch_level level, so paging memory cannot be used in this routine, otherwise it can cause a page failure and cause the system to crash. In addition, the I/O timer is run on any thread, not necessarily in the IRP-initiated threads, so the application's memory address cannot be used directly.

After the I/O timer is initialized, I/O timers can be switched on and off. Once the timer is turned on, each 1s system invokes a timer routine. The system will not enter the timer routine when listening to the specified climate. The kernel function that turns on the timer is Iostarttimer, and the kernel function that stops the I/O timer is iostoptimer.

Example code:

Now initialize the timer in DriverEntry:

Then write the corresponding dispatch function:

1 NTSTATUS Helloddkdeviceiocontrol_timer (pdevice_object pdevobj, pirp pirp) {2Dbgprint ("Enter helloddkdeviceiocontrol_timer!\n");3NTSTATUS status =status_success;4Pio_stack_location STACK =iogetcurrentirpstacklocation (PIRP);5     //ULONG cbin = stack->parameters.deviceiocontrol.inputbufferlength;6     //ULONG cbout = stack->parameters.deviceiocontrol.outputbufferlength;7ULONG Code = stack->Parameters.DeviceIoControl.IoControlCode;8Pdevice_extension Pdevext =(pdevice_extension)9Pdevobj->deviceextension;TenULONG info =0; One     Switch(Code) A     { -      CaseIoctl_start_timer: -     { theDbgprint ("ioctl_start_timer\n"); -Pdevext->ltimercount =timer_out; - Iostarttimer (pdevobj); -          Break; +     } -      CaseIoctl_stop: +     { ADbgprint ("ioctl_stop\n"); at Iostoptimer (pdevobj); -          Break; -     } -     default: -Status =status_invalid_variant; -     } inPirp->iostatus.status =status; -Pirp->iostatus.status =info; to iocompleterequest (PIRP, io_no_increment); +Dbgprint ("Leave helloddkdeviceiocontrol_timer!\n"); -     returnstatus; the}

Then write the timer routine:

The application layer code is as follows:

Send the corresponding control code to the bottom, output a "time out" every three seconds:

    • DPC Timer

The second way to use the timer in the driver is to use the DPC timer, which is more flexible and can be timed at any time of the interval. The DPC timer internally uses the Timer object Ktimer, and when the timer is set to a time interval, the operating system inserts a DPC routine into the DPC queue every other time. When the operating system reads the DPC queue, the corresponding DPC routines are executed. The DPC timer routine is equivalent to the callback function of the timer.

The timer of Windows Driver Development technology detailed

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.